@react-pdf/stylesheet
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -1,2 +0,2 @@ | ||
import { compose, castArray } from '@react-pdf/fns'; | ||
import { compose, castArray, matchPercent } from '@react-pdf/fns'; | ||
import parse$1 from 'postcss-value-parser/lib/parse.js'; | ||
@@ -423,3 +423,3 @@ import parseUnit from 'postcss-value-parser/lib/unit.js'; | ||
const parseValue = value => { | ||
const match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value); | ||
const match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px|rem)?$/g.exec(value); | ||
return match ? { | ||
@@ -447,2 +447,4 @@ value: parseFloat(match[1]), | ||
switch (scalar.unit) { | ||
case 'rem': | ||
return scalar.value * (container.remBase || 18); | ||
case 'in': | ||
@@ -647,2 +649,20 @@ return scalar.value * dpi; | ||
/* eslint-disable no-restricted-globals */ | ||
const processLineHeight = (value, styles) => { | ||
if (value === '') return value; | ||
const { | ||
fontSize = 18 | ||
} = styles; | ||
// Percent values: use this number multiplied by the element's font size | ||
const { | ||
percent | ||
} = matchPercent(value) || {}; | ||
if (percent) return percent * fontSize; | ||
// Unitless values: use this number multiplied by the element's font size | ||
return isNaN(value) ? value : value * fontSize; | ||
}; | ||
const matchNumber = value => typeof value === 'string' && /^-?\d*\.?\d*$/.test(value); | ||
@@ -677,2 +697,3 @@ const castFloat = value => { | ||
fontWeight: processFontWeight, | ||
lineHeight: processLineHeight, | ||
objectPositionX: transformObjectPosition, | ||
@@ -683,4 +704,4 @@ objectPositionY: transformObjectPosition, | ||
}; | ||
const transformStyle = (key, value, container) => { | ||
const result = handlers[key] ? handlers[key](value) : value; | ||
const transformStyle = (key, value, styles, container) => { | ||
const result = handlers[key] ? handlers[key](value, styles) : value; | ||
return transformColor(transformUnit(container, castFloat(result))); | ||
@@ -701,10 +722,10 @@ }; | ||
*/ | ||
const transform = container => style => { | ||
if (!style) return style; | ||
const propsArray = Object.keys(style); | ||
const transform = container => styles => { | ||
if (!styles) return styles; | ||
const propsArray = Object.keys(styles); | ||
const resolvedStyle = {}; | ||
for (let i = 0; i < propsArray.length; i += 1) { | ||
const key = propsArray[i]; | ||
const value = style[key]; | ||
const transformed = transformStyle(key, value, container); | ||
const value = styles[key]; | ||
const transformed = transformStyle(key, value, styles, container); | ||
resolvedStyle[key] = transformed; | ||
@@ -711,0 +732,0 @@ } |
{ | ||
"name": "@react-pdf/stylesheet", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A styles engine for Node and the browser", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21287
721