Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-pdf/stylesheet

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/stylesheet - npm Package Compare versions

Comparing version 4.2.5 to 4.3.0

424

lib/index.js

@@ -6,3 +6,2 @@ import { compose, castArray } from '@react-pdf/fns';

import colorString from 'color-string';
import _extends from '@babel/runtime/helpers/extends';
import matchMedia from 'media-engine';

@@ -13,13 +12,13 @@

// TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
var flexDefaults = [1, 1, 0];
const flexDefaults = [1, 1, 0];
/**
* @type {(number | 'auto')[]}
*/
var flexAuto = [1, 1, 'auto'];
var expandFlex = function expandFlex(key, value) {
const flexAuto = [1, 1, 'auto'];
const expandFlex = (key, value) => {
/**
* @type {(number | 'auto')[]}
*/
var defaults = flexDefaults;
var matches = [];
let defaults = flexDefaults;
let matches = [];
if (value === 'auto') {

@@ -30,9 +29,9 @@ defaults = flexAuto;

}
var flexGrow = matches[0] || defaults[0];
var flexShrink = matches[1] || defaults[1];
var flexBasis = matches[2] || defaults[2];
const flexGrow = matches[0] || defaults[0];
const flexShrink = matches[1] || defaults[1];
const flexBasis = matches[2] || defaults[2];
return {
flexGrow: flexGrow,
flexShrink: flexShrink,
flexBasis: flexBasis
flexGrow,
flexShrink,
flexBasis
};

@@ -44,4 +43,4 @@ };

// eslint-disable-next-line import/extensions
var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
var logError = function logError(style, value) {
const BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
const logError = (style, value) => {
console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");

@@ -56,15 +55,13 @@ };

*/
var expandBoxModel = function expandBoxModel(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
expandsTo = _ref.expandsTo,
_ref$maxValues = _ref.maxValues,
maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
_ref$autoSupported = _ref.autoSupported,
autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
return function (model, value) {
var _ref2;
var nodes = parse$1("" + value);
var parts = [];
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
const expandBoxModel = function (_temp) {
let {
expandsTo,
maxValues = 1,
autoSupported = false
} = _temp === void 0 ? {} : _temp;
return (model, value) => {
const nodes = parse$1("" + value);
const parts = [];
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];

@@ -81,3 +78,3 @@ // value contains `calc`, `url` or other css function

} else {
var result = parseUnit(node.value);
const result = parseUnit(node.value);

@@ -100,24 +97,28 @@ // when unit isn't specified this condition is true

}
var first = parts[0];
const first = parts[0];
if (expandsTo) {
var second = parts[1] || parts[0];
var third = parts[2] || parts[0];
var fourth = parts[3] || parts[1] || parts[0];
const second = parts[1] || parts[0];
const third = parts[2] || parts[0];
const fourth = parts[3] || parts[1] || parts[0];
return expandsTo({
first: first,
second: second,
third: third,
fourth: fourth
first,
second,
third,
fourth
});
}
return _ref2 = {}, _ref2[model] = first, _ref2;
return {
[model]: first
};
};
};
var processMargin = expandBoxModel({
expandsTo: function expandsTo(_ref) {
var first = _ref.first,
second = _ref.second,
third = _ref.third,
fourth = _ref.fourth;
const processMargin = expandBoxModel({
expandsTo: _ref => {
let {
first,
second,
third,
fourth
} = _ref;
return {

@@ -133,6 +134,8 @@ marginTop: first,

});
var processMarginVertical = expandBoxModel({
expandsTo: function expandsTo(_ref2) {
var first = _ref2.first,
second = _ref2.second;
const processMarginVertical = expandBoxModel({
expandsTo: _ref2 => {
let {
first,
second
} = _ref2;
return {

@@ -146,6 +149,8 @@ marginTop: first,

});
var processMarginHorizontal = expandBoxModel({
expandsTo: function expandsTo(_ref3) {
var first = _ref3.first,
second = _ref3.second;
const processMarginHorizontal = expandBoxModel({
expandsTo: _ref3 => {
let {
first,
second
} = _ref3;
return {

@@ -159,19 +164,20 @@ marginRight: first,

});
var processMarginSingle = expandBoxModel({
const processMarginSingle = expandBoxModel({
autoSupported: true
});
var BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
var matchBorderShorthand = function matchBorderShorthand(value) {
return value.match(BORDER_SHORTHAND_REGEX) || [];
};
var expandBorders = function expandBorders(key, value) {
var match = matchBorderShorthand("" + value);
const BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
const matchBorderShorthand = value => value.match(BORDER_SHORTHAND_REGEX) || [];
const expandBorders = (key, value) => {
const match = matchBorderShorthand("" + value);
if (match) {
var color = match[5] || value;
var style = match[4] || value;
var width = match[1] || value;
const color = match[5] || value;
const style = match[4] || value;
const width = match[1] || value;
if (key.match(/(Top|Right|Bottom|Left)$/)) {
var _ref;
return _ref = {}, _ref[key + "Color"] = color, _ref[key + "Style"] = style, _ref[key + "Width"] = width, _ref;
return {
[key + "Color"]: color,
[key + "Style"]: style,
[key + "Width"]: width
};
}

@@ -228,8 +234,10 @@ if (key.match(/Color$/)) {

var processPadding = expandBoxModel({
expandsTo: function expandsTo(_ref) {
var first = _ref.first,
second = _ref.second,
third = _ref.third,
fourth = _ref.fourth;
const processPadding = expandBoxModel({
expandsTo: _ref => {
let {
first,
second,
third,
fourth
} = _ref;
return {

@@ -244,6 +252,8 @@ paddingTop: first,

});
var processPaddingVertical = expandBoxModel({
expandsTo: function expandsTo(_ref2) {
var first = _ref2.first,
second = _ref2.second;
const processPaddingVertical = expandBoxModel({
expandsTo: _ref2 => {
let {
first,
second
} = _ref2;
return {

@@ -256,6 +266,8 @@ paddingTop: first,

});
var processPaddingHorizontal = expandBoxModel({
expandsTo: function expandsTo(_ref3) {
var first = _ref3.first,
second = _ref3.second;
const processPaddingHorizontal = expandBoxModel({
expandsTo: _ref3 => {
let {
first,
second
} = _ref3;
return {

@@ -268,6 +280,6 @@ paddingRight: first,

});
var processPaddingSingle = expandBoxModel();
const processPaddingSingle = expandBoxModel();
var expandObjectPosition = function expandObjectPosition(key, value) {
var match = ("" + value).split(' ');
const expandObjectPosition = (key, value) => {
const match = ("" + value).split(' ');
return {

@@ -279,7 +291,7 @@ objectPositionX: (match === null || match === void 0 ? void 0 : match[0]) || value,

var Y_AXIS_SHORTHANDS = {
const Y_AXIS_SHORTHANDS = {
top: true,
bottom: true
};
var sortTransformOriginPair = function sortTransformOriginPair(a, b) {
const sortTransformOriginPair = (a, b) => {
if (Y_AXIS_SHORTHANDS[a]) return 1;

@@ -289,5 +301,5 @@ if (Y_AXIS_SHORTHANDS[b]) return -1;

};
var getTransformOriginPair = function getTransformOriginPair(values) {
const getTransformOriginPair = values => {
if (!values || values.length === 0) return ['center', 'center'];
var pair = values.length === 1 ? [values[0], 'center'] : values;
const pair = values.length === 1 ? [values[0], 'center'] : values;
return pair.sort(sortTransformOriginPair);

@@ -297,5 +309,5 @@ };

// Transforms shorthand transformOrigin values
var expandTransformOrigin = function expandTransformOrigin(key, value) {
var match = ("" + value).split(' ');
var pair = getTransformOriginPair(match);
const expandTransformOrigin = (key, value) => {
const match = ("" + value).split(' ');
const pair = getTransformOriginPair(match);
return {

@@ -307,4 +319,4 @@ transformOriginX: pair[0],

var expandGap = function expandGap(key, value) {
var match = ("" + value).split(' ');
const expandGap = (key, value) => {
const match = ("" + value).split(' ');
return {

@@ -316,3 +328,3 @@ rowGap: (match === null || match === void 0 ? void 0 : match[0]) || value,

var shorthands = {
const shorthands = {
flex: expandFlex,

@@ -354,5 +366,6 @@ gap: expandGap,

*/
var expandStyle = function expandStyle(key, value) {
var _ref;
return shorthands[key] ? shorthands[key](key, value) : (_ref = {}, _ref[key] = value, _ref);
const expandStyle = (key, value) => {
return shorthands[key] ? shorthands[key](key, value) : {
[key]: value
};
};

@@ -366,14 +379,14 @@

*/
var expand = function expand(style) {
const expand = style => {
if (!style) return style;
var propsArray = Object.keys(style);
var resolvedStyle = {};
for (var i = 0; i < propsArray.length; i += 1) {
var key = propsArray[i];
var value = style[key];
var extended = expandStyle(key, value);
var keys = Object.keys(extended);
for (var j = 0; j < keys.length; j += 1) {
var propName = keys[j];
var propValue = extended[propName];
const propsArray = Object.keys(style);
const resolvedStyle = {};
for (let i = 0; i < propsArray.length; i += 1) {
const key = propsArray[i];
const value = style[key];
const extended = expandStyle(key, value);
const keys = Object.keys(extended);
for (let j = 0; j < keys.length; j += 1) {
const propName = keys[j];
const propValue = extended[propName];
resolvedStyle[propName] = propValue;

@@ -392,5 +405,3 @@ }

*/
var compact = function compact(array) {
return array.filter(Boolean);
};
const compact = array => array.filter(Boolean);

@@ -403,13 +414,11 @@ /**

*/
var mergeStyles = function mergeStyles(styles) {
return styles.reduce(function (acc, style) {
var s = Array.isArray(style) ? flatten(style) : style;
Object.keys(s).forEach(function (key) {
if (s[key] !== null && s[key] !== undefined) {
acc[key] = s[key];
}
});
return acc;
}, {});
};
const mergeStyles = styles => styles.reduce((acc, style) => {
const s = Array.isArray(style) ? flatten(style) : style;
Object.keys(s).forEach(key => {
if (s[key] !== null && s[key] !== undefined) {
acc[key] = s[key];
}
});
return acc;
}, {});

@@ -422,3 +431,3 @@ /**

*/
var flatten = compose(mergeStyles, compact, castArray);
const flatten = compose(mergeStyles, compact, castArray);

@@ -431,4 +440,4 @@ /**

*/
var parseValue = function parseValue(value) {
var match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value);
const parseValue = value => {
const match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value);
return match ? {

@@ -438,3 +447,3 @@ value: parseFloat(match[1]),

} : {
value: value,
value,
unit: undefined

@@ -451,7 +460,7 @@ };

*/
var transformUnit = function transformUnit(container, value) {
var scalar = parseValue(value);
var dpi = container.dpi || 72;
var mmFactor = 1 / 25.4 * dpi;
var cmFactor = 1 / 2.54 * dpi;
const transformUnit = (container, value) => {
const scalar = parseValue(value);
const dpi = 72; // Removed: container.dpi || 72
const mmFactor = 1 / 25.4 * dpi;
const cmFactor = 1 / 2.54 * dpi;
switch (scalar.unit) {

@@ -473,8 +482,4 @@ case 'in':

var isRgb = function isRgb(value) {
return /rgba?/g.test(value);
};
var isHsl = function isHsl(value) {
return /hsla?/g.test(value);
};
const isRgb = value => /rgba?/g.test(value);
const isHsl = value => /hsla?/g.test(value);

@@ -487,4 +492,4 @@ /**

*/
var parseRgb = function parseRgb(value) {
var rgb = colorString.get.rgb(value);
const parseRgb = value => {
const rgb = colorString.get.rgb(value);
return colorString.to.hex(rgb);

@@ -499,5 +504,5 @@ };

*/
var parseHsl = function parseHsl(value) {
var hsl = colorString.get.hsl(value).map(Math.round);
var hex = hlsToHex.apply(void 0, hsl);
const parseHsl = value => {
const hsl = colorString.get.hsl(value).map(Math.round);
const hex = hlsToHex(...hsl);
return hex.toUpperCase();

@@ -512,3 +517,3 @@ };

*/
var transformColor = function transformColor(value) {
const transformColor = value => {
if (isRgb(value)) return parseRgb(value);

@@ -519,4 +524,4 @@ if (isHsl(value)) return parseHsl(value);

var parse = function parse(transformString) {
var transforms = transformString.trim().split(/\) |\)/);
const parse = transformString => {
const transforms = transformString.trim().split(/\) |\)/);

@@ -527,16 +532,12 @@ // Handle "initial", "inherit", "unset".

}
var parsed = [];
for (var i = 0; i < transforms.length; i += 1) {
var transform = transforms[i];
const parsed = [];
for (let i = 0; i < transforms.length; i += 1) {
const transform = transforms[i];
if (transform) {
var _transform$split = transform.split('('),
name = _transform$split[0],
rawValue = _transform$split[1];
var splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
var value = rawValue.split(splitChar).map(function (val) {
return val.trim();
});
const [name, rawValue] = transform.split('(');
const splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
const value = rawValue.split(splitChar).map(val => val.trim());
parsed.push({
operation: name,
value: value
value
});

@@ -547,22 +548,17 @@ }

};
var parseAngle = function parseAngle(value) {
var unitsRegexp = /(-?\d*\.?\d*)(\w*)?/i;
var _unitsRegexp$exec = unitsRegexp.exec(value),
angle = _unitsRegexp$exec[1],
unit = _unitsRegexp$exec[2];
var number = Number.parseFloat(angle);
const parseAngle = value => {
const unitsRegexp = /(-?\d*\.?\d*)(\w*)?/i;
const [, angle, unit] = unitsRegexp.exec(value);
const number = Number.parseFloat(angle);
return unit === 'rad' ? number * 180 / Math.PI : number;
};
var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
var operation = _ref.operation,
value = _ref.value;
const normalizeTransformOperation = _ref => {
let {
operation,
value
} = _ref;
switch (operation) {
case 'scale':
{
var _value$map = value.map(function (num) {
return Number.parseFloat(num);
}),
scaleX = _value$map[0],
_value$map$ = _value$map[1],
scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
const [scaleX, scaleY = scaleX] = value.map(num => Number.parseFloat(num));
return {

@@ -598,5 +594,3 @@ operation: 'scale',

operation: 'translate',
value: value.map(function (num) {
return Number.parseFloat(num);
})
value: value.map(num => Number.parseFloat(num))
};

@@ -642,6 +636,4 @@ }

return {
operation: operation,
value: value.map(function (num) {
return Number.parseFloat(num);
})
operation,
value: value.map(num => Number.parseFloat(num))
};

@@ -651,8 +643,6 @@ }

};
var normalize = function normalize(operations) {
return operations.map(function (operation) {
return normalizeTransformOperation(operation);
});
const normalize = operations => {
return operations.map(operation => normalizeTransformOperation(operation));
};
var processTransform = function processTransform(value) {
const processTransform = value => {
if (typeof value !== 'string') return value;

@@ -662,3 +652,3 @@ return normalize(parse(value));

var FONT_WEIGHTS = {
const FONT_WEIGHTS = {
thin: 100,

@@ -679,6 +669,6 @@ hairline: 100,

};
var processFontWeight = function processFontWeight(value) {
const processFontWeight = value => {
if (!value) return FONT_WEIGHTS.normal;
if (typeof value === 'number') return value;
var lv = value.toLowerCase();
const lv = value.toLowerCase();
if (FONT_WEIGHTS[lv]) return FONT_WEIGHTS[lv];

@@ -688,6 +678,4 @@ return value;

var matchNumber = function matchNumber(value) {
return typeof value === 'string' && /^-?\d*\.?\d*$/.test(value);
};
var castFloat = function castFloat(value) {
const matchNumber = value => typeof value === 'string' && /^-?\d*\.?\d*$/.test(value);
const castFloat = value => {
if (typeof value !== 'string') return value;

@@ -698,3 +686,3 @@ if (matchNumber(value)) return parseFloat(value);

var offsetKeyword = function offsetKeyword(value) {
const offsetKeyword = value => {
switch (value) {

@@ -714,11 +702,7 @@ case 'top':

var transformObjectPosition = function transformObjectPosition(value) {
return offsetKeyword(value) || castFloat(value);
};
const transformObjectPosition = value => offsetKeyword(value) || castFloat(value);
var transformTransformOrigin = function transformTransformOrigin(value) {
return offsetKeyword(value) || castFloat(value);
};
const transformTransformOrigin = value => offsetKeyword(value) || castFloat(value);
var handlers = {
const handlers = {
transform: processTransform,

@@ -731,4 +715,4 @@ fontWeight: processFontWeight,

};
var transformStyle = function transformStyle(key, value, container) {
var result = handlers[key] ? handlers[key](value) : value;
const transformStyle = (key, value, container) => {
const result = handlers[key] ? handlers[key](value) : value;
return transformColor(transformUnit(container, castFloat(result)));

@@ -749,15 +733,13 @@ };

*/
var transform = function transform(container) {
return function (style) {
if (!style) return style;
var propsArray = Object.keys(style);
var resolvedStyle = {};
for (var i = 0; i < propsArray.length; i += 1) {
var key = propsArray[i];
var value = style[key];
var transformed = transformStyle(key, value, container);
resolvedStyle[key] = transformed;
}
return resolvedStyle;
};
const transform = container => style => {
if (!style) return style;
const propsArray = Object.keys(style);
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);
resolvedStyle[key] = transformed;
}
return resolvedStyle;
};

@@ -771,10 +753,16 @@

*/
var resolveMediaQueries = function resolveMediaQueries(container, styles) {
return Object.keys(styles).reduce(function (acc, key) {
var _extends2;
const resolveMediaQueries = (container, styles) => {
return Object.keys(styles).reduce((acc, key) => {
if (/@media/.test(key)) {
var _matchMedia;
return _extends({}, acc, matchMedia((_matchMedia = {}, _matchMedia[key] = styles[key], _matchMedia), container));
return {
...acc,
...matchMedia({
[key]: styles[key]
}, container)
};
}
return _extends({}, acc, (_extends2 = {}, _extends2[key] = styles[key], _extends2));
return {
...acc,
[key]: styles[key]
};
}, {});

@@ -790,6 +778,4 @@ };

*/
var resolveStyles = function resolveStyles(container, style) {
var computeMediaQueries = function computeMediaQueries(value) {
return resolveMediaQueries(container, value);
};
const resolveStyles = (container, style) => {
const computeMediaQueries = value => resolveMediaQueries(container, value);
return compose(transform(container), expand, computeMediaQueries, flatten)(style);

@@ -796,0 +782,0 @@ };

{
"name": "@react-pdf/stylesheet",
"version": "4.2.5",
"version": "4.3.0",
"license": "MIT",

@@ -31,3 +31,3 @@ "description": "A styles engine for Node and the browser",

"@react-pdf/fns": "2.2.1",
"@react-pdf/types": "^2.5.0",
"@react-pdf/types": "^2.6.0",
"color-string": "^1.9.1",

@@ -34,0 +34,0 @@ "hsl-to-hex": "^1.0.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc