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

@react-pdf/stylesheet

Package Overview
Dependencies
Maintainers
1
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 2.0.0-beta.14 to 2.0.0-beta.15

20

lib/colors.js

@@ -16,6 +16,6 @@ "use strict";

const isRgb = R.test(/rgb/g);
const isRgba = R.test(/rgba/g);
const isHsl = R.test(/hsl/g);
const isHsla = R.test(/hsla/g);
var isRgb = R.test(/rgb/g);
var isRgba = R.test(/rgba/g);
var isHsl = R.test(/hsl/g);
var isHsla = R.test(/hsla/g);
/**

@@ -28,3 +28,3 @@ * Transform rgb color to hexa

const parseRgb = R.compose(_colorString.default.to.hex, _colorString.default.get.rgb);
var parseRgb = R.compose(_colorString.default.to.hex, _colorString.default.get.rgb);
/**

@@ -37,3 +37,3 @@ * Transform Hsl color to hexa

const parseHsl = R.compose(R.toUpper, R.apply(_hslToHex.default), R.map(Math.round), _colorString.default.get.hsl);
var parseHsl = R.compose(R.toUpper, R.apply(_hslToHex.default), R.map(Math.round), _colorString.default.get.hsl);
/**

@@ -46,3 +46,5 @@ * Transform given color to hexa

const transformColor = value => R.cond([[isRgba, parseRgb], [isRgb, parseRgb], [isHsla, parseHsl], [isHsl, parseHsl], [R.T, R.always(value)]])(value);
var transformColor = function transformColor(value) {
return R.cond([[isRgba, parseRgb], [isRgb, parseRgb], [isHsla, parseHsl], [isHsl, parseHsl], [R.T, R.always(value)]])(value);
};
/**

@@ -58,5 +60,7 @@ * Transform rbg and cmyk colors to hexa

const transformColors = styles => R.map(transformColor, styles);
var transformColors = function transformColors(styles) {
return R.map(transformColor, styles);
};
var _default = transformColors;
exports.default = _default;

132

lib/expand.js

@@ -14,7 +14,7 @@ "use strict";

const BOX_MODEL_REGEX = /\d+(px|in|mm|cm|pt|%|vw|vh|px)?/g;
const OBJECT_POSITION_REGEX = /\d+(px|in|mm|cm|pt|%|vw|vh|px)?/g;
const BORDER_SHORTHAND_REGEX = /(\d+(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
const TRANSFORM_ORIGIN_REGEX = /(-?\d+(px|in|mm|cm|pt|%|vw|vh|px)?)|top|right|bottom|left|center/g;
const FONT_WEIGHTS = {
var BOX_MODEL_REGEX = /\d+(px|in|mm|cm|pt|%|vw|vh|px)?/g;
var OBJECT_POSITION_REGEX = /\d+(px|in|mm|cm|pt|%|vw|vh|px)?/g;
var BORDER_SHORTHAND_REGEX = /(\d+(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
var TRANSFORM_ORIGIN_REGEX = /(-?\d+(px|in|mm|cm|pt|%|vw|vh|px)?)|top|right|bottom|left|center/g;
var FONT_WEIGHTS = {
thin: 100,

@@ -35,33 +35,49 @@ hairline: 100,

};
const matchBoxModel = R.match(BOX_MODEL_REGEX);
const matchObjectPosition = R.match(OBJECT_POSITION_REGEX);
const matchBorderShorthand = R.match(BORDER_SHORTHAND_REGEX);
const matchTransformOrigin = R.match(TRANSFORM_ORIGIN_REGEX);
const isNumber = R.is(Number);
const FONT_WEIGHT_REGEX = /^fontWeight/;
var matchBoxModel = R.match(BOX_MODEL_REGEX);
var matchObjectPosition = R.match(OBJECT_POSITION_REGEX);
var matchBorderShorthand = R.match(BORDER_SHORTHAND_REGEX);
var matchTransformOrigin = R.match(TRANSFORM_ORIGIN_REGEX);
var isNumber = R.is(Number);
var FONT_WEIGHT_REGEX = /^fontWeight/;
const isFontWeightStyle = key => key.match(FONT_WEIGHT_REGEX);
var isFontWeightStyle = function isFontWeightStyle(key) {
return key.match(FONT_WEIGHT_REGEX);
};
const BORDER_STYLE_REGEX = /^border(Top|Right|Bottom|Left)(Color|Width|Style)/;
var BORDER_STYLE_REGEX = /^border(Top|Right|Bottom|Left)(Color|Width|Style)/;
const isBorderStyle = (key, value) => key.match(BORDER_STYLE_REGEX) && typeof value === 'string';
var isBorderStyle = function isBorderStyle(key, value) {
return key.match(BORDER_STYLE_REGEX) && typeof value === 'string';
};
const BOX_MODEL_STYLE_REGEX = /^(margin)|(padding)/;
var BOX_MODEL_STYLE_REGEX = /^(margin)|(padding)/;
const isBoxModelStyle = (key, value) => key.match(BOX_MODEL_STYLE_REGEX) && typeof value === 'string';
var isBoxModelStyle = function isBoxModelStyle(key, value) {
return key.match(BOX_MODEL_STYLE_REGEX) && typeof value === 'string';
};
const OBJECT_POSITION_STYLE_REGEX = /^objectPosition/;
var OBJECT_POSITION_STYLE_REGEX = /^objectPosition/;
const isObjectPositionStyle = (key, value) => key.match(OBJECT_POSITION_STYLE_REGEX) && typeof value === 'string';
var isObjectPositionStyle = function isObjectPositionStyle(key, value) {
return key.match(OBJECT_POSITION_STYLE_REGEX) && typeof value === 'string';
};
const isTransformOriginStyle = (key, value) => key.match(/^transformOrigin/) && typeof value === 'string';
var isTransformOriginStyle = function isTransformOriginStyle(key, value) {
return key.match(/^transformOrigin/) && typeof value === 'string';
};
const isFlexGrow = key => key === 'flexGrow';
var isFlexGrow = function isFlexGrow(key) {
return key === 'flexGrow';
};
const isFlexShrink = key => key === 'flexShrink';
var isFlexShrink = function isFlexShrink(key) {
return key === 'flexShrink';
};
const isFlexBasis = key => key === 'flexBasis';
var isFlexBasis = function isFlexBasis(key) {
return key === 'flexBasis';
};
const processBorders = (key, value) => {
const match = matchBorderShorthand(value);
var processBorders = function processBorders(key, value) {
var match = matchBorderShorthand(value);

@@ -81,3 +97,3 @@ if (match) {

throw new Error(`StyleSheet: Invalid '${value}' for '${key}'`);
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'");
}

@@ -88,4 +104,4 @@

const processBoxModel = (key, value) => {
const match = matchBoxModel(value);
var processBoxModel = function processBoxModel(key, value) {
var match = matchBoxModel(value);

@@ -109,3 +125,3 @@ if (match) {

throw new Error(`StyleSheet: Invalid '${value}' for '${key}'`);
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'");
}

@@ -116,3 +132,3 @@

const processFontWeight = (key, value) => {
var processFontWeight = function processFontWeight(key, value) {
if (!value) return FONT_WEIGHTS.normal;

@@ -125,4 +141,4 @@ if (typeof value === 'number') return value;

const processObjectPosition = (key, value) => {
const match = matchObjectPosition(value);
var processObjectPosition = function processObjectPosition(key, value) {
var match = matchObjectPosition(value);

@@ -138,3 +154,3 @@ if (match) {

throw new Error(`StyleSheet: Invalid '${value}' for '${key}'`);
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'");
}

@@ -147,3 +163,3 @@

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

@@ -167,7 +183,7 @@ case 'top':

const processTransformOrigin = (key, value) => {
const match = matchTransformOrigin(value);
var processTransformOrigin = function processTransformOrigin(key, value) {
var match = matchTransformOrigin(value);
if (match) {
let result;
var result;

@@ -179,3 +195,3 @@ if (key.match(/X$/)) {

} else {
throw new Error(`StyleSheet: Invalid '${value}' for '${key}'`);
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'");
}

@@ -189,24 +205,28 @@

const processFlexGrow = (key, value) => {
var processFlexGrow = function processFlexGrow(key, value) {
if (isNumber(value)) return value;
const matches = value.split(' ');
var matches = value.split(' ');
return matches[0];
};
const processFlexShrink = (key, value) => {
var processFlexShrink = function processFlexShrink(key, value) {
if (isNumber(value)) return value;
const matches = value.split(' ');
var matches = value.split(' ');
return matches[1];
};
const processFlexBasis = (key, value) => {
var processFlexBasis = function processFlexBasis(key, value) {
if (isNumber(value)) return value;
const matches = value.split(' ');
var matches = value.split(' ');
return matches[2];
};
const keepSame = (key, value) => value;
var keepSame = function keepSame(key, value) {
return value;
};
const matchNumber = R.when(R.is(String), R.test(/^-?\d*\.?\d*$/));
const castFloat = R.when(matchNumber, v => parseFloat(v, 10));
var matchNumber = R.when(R.is(String), R.test(/^-?\d*\.?\d*$/));
var castFloat = R.when(matchNumber, function (v) {
return parseFloat(v, 10);
});
/**

@@ -220,3 +240,3 @@ * Transforms style key-value

const transformStyle = R.compose(castFloat, R.cond([[isBorderStyle, processBorders], [isBoxModelStyle, processBoxModel], [isObjectPositionStyle, processObjectPosition], [isTransformOriginStyle, processTransformOrigin], [isFontWeightStyle, processFontWeight], [isFlexGrow, processFlexGrow], [isFlexShrink, processFlexShrink], [isFlexBasis, processFlexBasis], [R.T, keepSame]]));
var transformStyle = R.compose(castFloat, R.cond([[isBorderStyle, processBorders], [isBoxModelStyle, processBoxModel], [isObjectPositionStyle, processObjectPosition], [isTransformOriginStyle, processTransformOrigin], [isFontWeightStyle, processFontWeight], [isFlexGrow, processFlexGrow], [isFlexShrink, processFlexShrink], [isFlexBasis, processFlexBasis], [R.T, keepSame]]));
/**

@@ -229,16 +249,16 @@ * Expand the shorthand properties to isolate every declaration from the others.

const expand = style => {
var expand = function expand(style) {
if (!style) return style;
const propsArray = Object.keys(style);
const resolvedStyle = {};
var propsArray = Object.keys(style);
var resolvedStyle = {};
for (let i = 0; i < propsArray.length; i += 1) {
const key = propsArray[i];
const value = style[key];
for (var i = 0; i < propsArray.length; i += 1) {
var key = propsArray[i];
var value = style[key];
if (_shorthands.default[key]) {
const expandedProps = _shorthands.default[key];
var expandedProps = _shorthands.default[key];
for (let j = 0; j < expandedProps.length; j += 1) {
const propName = expandedProps[j];
for (var j = 0; j < expandedProps.length; j += 1) {
var propName = expandedProps[j];
resolvedStyle[propName] = transformStyle(propName, value);

@@ -245,0 +265,0 @@ }

@@ -10,4 +10,6 @@ "use strict";

const isNotArray = R.complement(R.is(Array));
const castArray = R.when(isNotArray, v => [v]);
var isNotArray = R.complement(R.is(Array));
var castArray = R.when(isNotArray, function (v) {
return [v];
});
/**

@@ -20,3 +22,3 @@ * Remove nil values from array

const compact = R.filter(Boolean);
var compact = R.filter(Boolean);
/**

@@ -29,3 +31,3 @@ * Checks if value is array

const isArray = R.is(Array);
var isArray = R.is(Array);
/**

@@ -38,11 +40,13 @@ * Merges style objects array

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

@@ -56,4 +60,4 @@ * Flattens an array of style objects, into one aggregated style object.

const flatten = R.compose(mergeStyles, compact, castArray);
var flatten = R.compose(mergeStyles, compact, castArray);
var _default = flatten;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
exports.__esModule = true;
exports.default = void 0;
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var R = _interopRequireWildcard(require("ramda"));

@@ -20,15 +22,13 @@

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

@@ -35,0 +35,0 @@ };

@@ -28,3 +28,3 @@ "use strict";

*/
const filterNoneValues = R.reject(R.equals('none'));
var filterNoneValues = R.reject(R.equals('none'));
/**

@@ -38,3 +38,5 @@ * Resolves styles

const resolveStyles = (container, style) => R.compose((0, _units.default)(container), _colors.default, _expand.default, (0, _mediaQueries.default)(container), filterNoneValues, _flatten.default)(style);
var resolveStyles = function resolveStyles(container, style) {
return R.compose((0, _units.default)(container), _colors.default, _expand.default, (0, _mediaQueries.default)(container), filterNoneValues, _flatten.default)(style);
};

@@ -41,0 +43,0 @@ var _default = R.curryN(2, resolveStyles);

@@ -5,3 +5,3 @@ "use strict";

exports.default = void 0;
const shorthands = {
var shorthands = {
margin: ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'],

@@ -8,0 +8,0 @@ marginHorizontal: ['marginLeft', 'marginRight'],

@@ -10,6 +10,6 @@ "use strict";

const DPI = 72; // 72pt per inch.
var DPI = 72; // 72pt per inch.
const MM_FACTOR = 1 / 25.4 * DPI;
const CM_FACTOR = 1 / 2.54 * DPI;
var MM_FACTOR = 1 / 25.4 * DPI;
var CM_FACTOR = 1 / 2.54 * DPI;
/**

@@ -22,4 +22,4 @@ * Parses scalar value in value and unit pairs

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

@@ -29,3 +29,3 @@ value: parseFloat(match[1], 10),

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

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

const transformUnit = R.curryN(2, (container, value) => {
const scalar = parseValue(value);
var transformUnit = R.curryN(2, function (container, value) {
var scalar = parseValue(value);

@@ -76,3 +76,5 @@ switch (scalar.unit) {

const transformUnits = (container, styles) => R.map(transformUnit(container), styles);
var transformUnits = function transformUnits(container, styles) {
return R.map(transformUnit(container), styles);
};

@@ -79,0 +81,0 @@ var _default = R.curryN(2, transformUnits);

{
"name": "@react-pdf/stylesheet",
"version": "2.0.0-beta.14",
"version": "2.0.0-beta.15",
"license": "MIT",

@@ -15,3 +15,3 @@ "author": "Diego Muracciole <diegomuracciole@gmail.com>",

"dependencies": {
"@react-pdf/types": "^2.0.0-beta.14",
"@react-pdf/types": "^2.0.0-beta.15",
"color-string": "^1.5.3",

@@ -25,3 +25,3 @@ "hsl-to-hex": "^1.0.0",

],
"gitHead": "d9441d47a47f5296ba1d23fb3bb6a7f6acbe2ae5"
"gitHead": "d89c1d7f3add422aafe9a9cd6e712e280eee76e7"
}
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