@react-pdf/stylesheet 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@react-pdf/stylesheet",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "license": "MIT",
5
5
  "description": "A styles engine for Node and the browser",
6
6
  "author": "Diego Muracciole <diegomuracciole@gmail.com>",
7
7
  "homepage": "https://github.com/diegomura/react-pdf#readme",
8
- "main": "lib/index.js",
8
+ "main": "lib/index.cjs.js",
9
+ "module": "lib/index.es.js",
9
10
  "repository": {
10
11
  "type": "git",
11
12
  "url": "https://github.com/diegomura/react-pdf.git",
@@ -13,12 +14,12 @@
13
14
  },
14
15
  "scripts": {
15
16
  "test": "jest",
16
- "build": "rimraf ./lib && babel src --out-dir lib",
17
- "watch": "rimraf ./lib && babel src --out-dir lib --watch"
17
+ "build": "rimraf ./lib && rollup -c",
18
+ "watch": "rimraf ./lib && rollup -c -w"
18
19
  },
19
20
  "dependencies": {
20
21
  "@babel/runtime": "^7.16.4",
21
- "@react-pdf/fns": "1.0.0",
22
+ "@react-pdf/fns": "2.0.0",
22
23
  "@react-pdf/types": "^2.1.0",
23
24
  "color-string": "^1.5.3",
24
25
  "hsl-to-hex": "^1.0.0",
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
6
-
7
- var matchBorderShorthand = function matchBorderShorthand(value) {
8
- return value.match(BORDER_SHORTHAND_REGEX) || [];
9
- };
10
-
11
- var expandBorders = function expandBorders(key, value) {
12
- var match = matchBorderShorthand("" + value);
13
-
14
- if (match) {
15
- var color = match[5] || value;
16
- var style = match[4] || value;
17
- var width = match[1] || value;
18
-
19
- if (key.match(/(Top|Right|Bottom|Left)$/)) {
20
- var _ref;
21
-
22
- return _ref = {}, _ref[key + "Color"] = color, _ref[key + "Style"] = style, _ref[key + "Width"] = width, _ref;
23
- }
24
-
25
- if (key.match(/Color$/)) {
26
- return {
27
- borderTopColor: color,
28
- borderRightColor: color,
29
- borderBottomColor: color,
30
- borderLeftColor: color
31
- };
32
- }
33
-
34
- if (key.match(/Style$/)) {
35
- return {
36
- borderTopStyle: style,
37
- borderRightStyle: style,
38
- borderBottomStyle: style,
39
- borderLeftStyle: style
40
- };
41
- }
42
-
43
- if (key.match(/Width$/)) {
44
- return {
45
- borderTopWidth: width,
46
- borderRightWidth: width,
47
- borderBottomWidth: width,
48
- borderLeftWidth: width
49
- };
50
- }
51
-
52
- if (key.match(/Radius$/)) {
53
- return {
54
- borderTopLeftRadius: value,
55
- borderTopRightRadius: value,
56
- borderBottomRightRadius: value,
57
- borderBottomLeftRadius: value
58
- };
59
- }
60
-
61
- return {
62
- borderTopColor: color,
63
- borderTopStyle: style,
64
- borderTopWidth: width,
65
- borderRightColor: color,
66
- borderRightStyle: style,
67
- borderRightWidth: width,
68
- borderBottomColor: color,
69
- borderBottomStyle: style,
70
- borderBottomWidth: width,
71
- borderLeftColor: color,
72
- borderLeftStyle: style,
73
- borderLeftWidth: width
74
- };
75
- }
76
-
77
- return value;
78
- };
79
-
80
- var _default = expandBorders;
81
- exports.default = _default;
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _parse = _interopRequireDefault(require("postcss-value-parser/lib/parse"));
9
-
10
- var _unit = _interopRequireDefault(require("postcss-value-parser/lib/unit"));
11
-
12
- /* eslint-disable no-plusplus */
13
- var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
14
-
15
- var logError = function logError(style, value) {
16
- console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
17
- };
18
-
19
- var expandBoxModel = function expandBoxModel(_temp) {
20
- var _ref = _temp === void 0 ? {} : _temp,
21
- expandsTo = _ref.expandsTo,
22
- _ref$maxValues = _ref.maxValues,
23
- maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
24
- _ref$autoSupported = _ref.autoSupported,
25
- autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
26
-
27
- return function (model, value) {
28
- var _ref2;
29
-
30
- var nodes = (0, _parse.default)("" + value);
31
- var parts = [];
32
-
33
- for (var i = 0; i < nodes.length; i++) {
34
- var node = nodes[i]; // value contains `calc`, `url` or other css function
35
- // `,`, `/` or strings that unsupported by margin and padding
36
-
37
- if (node.type === 'function' || node.type === 'string' || node.type === 'div') {
38
- logError(model, value);
39
- return {};
40
- }
41
-
42
- if (node.type === 'word') {
43
- if (node.value === 'auto' && autoSupported) {
44
- parts.push(node.value);
45
- } else {
46
- var result = (0, _unit.default)(node.value); // when unit isn't specified this condition is true
47
-
48
- if (result && BOX_MODEL_UNITS.includes(result.unit)) {
49
- parts.push(node.value);
50
- } else {
51
- logError(model, value);
52
- return {};
53
- }
54
- }
55
- }
56
- } // checks that we have enough parsed values
57
-
58
-
59
- if (parts.length > maxValues) {
60
- logError(model, value);
61
- return {};
62
- }
63
-
64
- var first = parts[0];
65
-
66
- if (expandsTo) {
67
- var second = parts[1] || parts[0];
68
- var third = parts[2] || parts[0];
69
- var fourth = parts[3] || parts[1] || parts[0];
70
- return expandsTo({
71
- first: first,
72
- second: second,
73
- third: third,
74
- fourth: fourth
75
- });
76
- }
77
-
78
- return _ref2 = {}, _ref2[model] = first, _ref2;
79
- };
80
- };
81
-
82
- var _default = expandBoxModel;
83
- exports.default = _default;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var flexDefaults = [1, 1, 0];
6
-
7
- var expandFlex = function expandFlex(key, value) {
8
- var matches = ("" + value).split(' ');
9
- var flexGrow = matches[0] || flexDefaults[0];
10
- var flexShrink = matches[1] || flexDefaults[1];
11
- var flexBasis = matches[2] || flexDefaults[2];
12
- return {
13
- flexGrow: flexGrow,
14
- flexShrink: flexShrink,
15
- flexBasis: flexBasis
16
- };
17
- };
18
-
19
- var _default = expandFlex;
20
- exports.default = _default;
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _flex = _interopRequireDefault(require("./flex"));
9
-
10
- var _margins = require("./margins");
11
-
12
- var _borders = _interopRequireDefault(require("./borders"));
13
-
14
- var _paddings = require("./paddings");
15
-
16
- var _objectPosition = _interopRequireDefault(require("./objectPosition"));
17
-
18
- var _transformOrigin = _interopRequireDefault(require("./transformOrigin"));
19
-
20
- var shorthands = {
21
- flex: _flex.default,
22
- margin: _margins.processMargin,
23
- marginHorizontal: _margins.processMarginHorizontal,
24
- marginVertical: _margins.processMarginVertical,
25
- marginTop: _margins.processMarginSingle,
26
- marginRight: _margins.processMarginSingle,
27
- marginBottom: _margins.processMarginSingle,
28
- marginLeft: _margins.processMarginSingle,
29
- padding: _paddings.processPadding,
30
- paddingHorizontal: _paddings.processPaddingHorizontal,
31
- paddingVertical: _paddings.processPaddingVertical,
32
- paddingTop: _paddings.processPaddingSingle,
33
- paddingRight: _paddings.processPaddingSingle,
34
- paddingBottom: _paddings.processPaddingSingle,
35
- paddingLeft: _paddings.processPaddingSingle,
36
- border: _borders.default,
37
- borderTop: _borders.default,
38
- borderRight: _borders.default,
39
- borderBottom: _borders.default,
40
- borderLeft: _borders.default,
41
- borderColor: _borders.default,
42
- borderRadius: _borders.default,
43
- borderStyle: _borders.default,
44
- borderWidth: _borders.default,
45
- objectPosition: _objectPosition.default,
46
- transformOrigin: _transformOrigin.default
47
- };
48
- /**
49
- * Transforms style key-value
50
- *
51
- * @param {String} key style key
52
- * @param {String} value style value
53
- * @returns {String | Number} transformed style values
54
- */
55
-
56
- var expandStyle = function expandStyle(key, value) {
57
- var _ref;
58
-
59
- return shorthands[key] ? shorthands[key](key, value) : (_ref = {}, _ref[key] = value, _ref);
60
- };
61
- /**
62
- * Expand the shorthand properties.
63
- *
64
- * @param { Object } style object
65
- * @returns { Object } expanded style object
66
- */
67
-
68
-
69
- var expand = function expand(style) {
70
- if (!style) return style;
71
- var propsArray = Object.keys(style);
72
- var resolvedStyle = {};
73
-
74
- for (var i = 0; i < propsArray.length; i += 1) {
75
- var key = propsArray[i];
76
- var value = style[key];
77
- var extended = expandStyle(key, value);
78
- var keys = Object.keys(extended);
79
-
80
- for (var j = 0; j < keys.length; j += 1) {
81
- var propName = keys[j];
82
- var propValue = extended[propName];
83
- resolvedStyle[propName] = propValue;
84
- }
85
- }
86
-
87
- return resolvedStyle;
88
- };
89
-
90
- var _default = expand;
91
- exports.default = _default;
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.processMarginVertical = exports.processMarginSingle = exports.processMarginHorizontal = exports.processMargin = void 0;
7
-
8
- var _boxModel = _interopRequireDefault(require("./boxModel"));
9
-
10
- var processMargin = (0, _boxModel.default)({
11
- expandsTo: function expandsTo(_ref) {
12
- var first = _ref.first,
13
- second = _ref.second,
14
- third = _ref.third,
15
- fourth = _ref.fourth;
16
- return {
17
- marginTop: first,
18
- marginRight: second,
19
- marginBottom: third,
20
- marginLeft: fourth
21
- };
22
- },
23
- maxValues: 4,
24
- autoSupported: true
25
- });
26
- exports.processMargin = processMargin;
27
- var processMarginVertical = (0, _boxModel.default)({
28
- expandsTo: function expandsTo(_ref2) {
29
- var first = _ref2.first,
30
- second = _ref2.second;
31
- return {
32
- marginTop: first,
33
- marginBottom: second
34
- };
35
- },
36
- maxValues: 2,
37
- autoSupported: true
38
- });
39
- exports.processMarginVertical = processMarginVertical;
40
- var processMarginHorizontal = (0, _boxModel.default)({
41
- expandsTo: function expandsTo(_ref3) {
42
- var first = _ref3.first,
43
- second = _ref3.second;
44
- return {
45
- marginRight: first,
46
- marginLeft: second
47
- };
48
- },
49
- maxValues: 2,
50
- autoSupported: true
51
- });
52
- exports.processMarginHorizontal = processMarginHorizontal;
53
- var processMarginSingle = (0, _boxModel.default)({
54
- autoSupported: true
55
- });
56
- exports.processMarginSingle = processMarginSingle;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
-
6
- var expandObjectPosition = function expandObjectPosition(key, value) {
7
- var match = ("" + value).split(' ');
8
- return {
9
- objectPositionX: (match === null || match === void 0 ? void 0 : match[0]) || value,
10
- objectPositionY: (match === null || match === void 0 ? void 0 : match[1]) || value
11
- };
12
- };
13
-
14
- var _default = expandObjectPosition;
15
- exports.default = _default;
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.processPaddingVertical = exports.processPaddingSingle = exports.processPaddingHorizontal = exports.processPadding = void 0;
7
-
8
- var _boxModel = _interopRequireDefault(require("./boxModel"));
9
-
10
- var processPadding = (0, _boxModel.default)({
11
- expandsTo: function expandsTo(_ref) {
12
- var first = _ref.first,
13
- second = _ref.second,
14
- third = _ref.third,
15
- fourth = _ref.fourth;
16
- return {
17
- paddingTop: first,
18
- paddingRight: second,
19
- paddingBottom: third,
20
- paddingLeft: fourth
21
- };
22
- },
23
- maxValues: 4
24
- });
25
- exports.processPadding = processPadding;
26
- var processPaddingVertical = (0, _boxModel.default)({
27
- expandsTo: function expandsTo(_ref2) {
28
- var first = _ref2.first,
29
- second = _ref2.second;
30
- return {
31
- paddingTop: first,
32
- paddingBottom: second
33
- };
34
- },
35
- maxValues: 2
36
- });
37
- exports.processPaddingVertical = processPaddingVertical;
38
- var processPaddingHorizontal = (0, _boxModel.default)({
39
- expandsTo: function expandsTo(_ref3) {
40
- var first = _ref3.first,
41
- second = _ref3.second;
42
- return {
43
- paddingRight: first,
44
- paddingLeft: second
45
- };
46
- },
47
- maxValues: 2
48
- });
49
- exports.processPaddingHorizontal = processPaddingHorizontal;
50
- var processPaddingSingle = (0, _boxModel.default)();
51
- exports.processPaddingSingle = processPaddingSingle;
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var Y_AXIS_SHORTHANDS = {
6
- top: true,
7
- bottom: true
8
- };
9
-
10
- var sortTransformOriginPair = function sortTransformOriginPair(a, b) {
11
- if (Y_AXIS_SHORTHANDS[a]) return 1;
12
- if (Y_AXIS_SHORTHANDS[b]) return -1;
13
- return 0;
14
- };
15
-
16
- var getTransformOriginPair = function getTransformOriginPair(values) {
17
- if (!values || values.length === 0) return ['center', 'center'];
18
- var pair = values.length === 1 ? [values[0], 'center'] : values;
19
- return pair.sort(sortTransformOriginPair);
20
- }; // Transforms shorthand transformOrigin values
21
-
22
-
23
- var expandTransformOrigin = function expandTransformOrigin(key, value) {
24
- var match = ("" + value).split(' ');
25
- var pair = getTransformOriginPair(match);
26
- return {
27
- transformOriginX: pair[0],
28
- transformOriginY: pair[1]
29
- };
30
- };
31
-
32
- var _default = expandTransformOrigin;
33
- exports.default = _default;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
-
6
- var _fns = require("@react-pdf/fns");
7
-
8
- /**
9
- * Remove nil values from array
10
- *
11
- * @param {Array} array
12
- * @returns {Array} array without nils
13
- */
14
- var compact = function compact(array) {
15
- return array.filter(Boolean);
16
- };
17
- /**
18
- * Merges style objects array
19
- *
20
- * @param {Array} style objects array
21
- * @returns {Object} merged style object
22
- */
23
-
24
-
25
- var mergeStyles = function mergeStyles(styles) {
26
- return styles.reduce(function (acc, style) {
27
- var s = Array.isArray(style) ? flatten(style) : style;
28
- Object.keys(s).forEach(function (key) {
29
- if (s[key] !== null && s[key] !== undefined) {
30
- acc[key] = s[key];
31
- }
32
- });
33
- return acc;
34
- }, {});
35
- };
36
- /**
37
- * Flattens an array of style objects, into one aggregated style object.
38
- *
39
- * @param {Array} style objects array
40
- * @returns {Object} flatted style object
41
- */
42
-
43
-
44
- var flatten = (0, _fns.compose)(mergeStyles, compact, _fns.castArray);
45
- var _default = flatten;
46
- exports.default = _default;
package/lib/index.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.transformColor = exports.processTransform = exports.default = void 0;
7
-
8
- var _fns = require("@react-pdf/fns");
9
-
10
- var _expand = _interopRequireDefault(require("./expand"));
11
-
12
- var _flatten = _interopRequireDefault(require("./flatten"));
13
-
14
- var _transform = _interopRequireDefault(require("./transform"));
15
-
16
- var _mediaQueries = _interopRequireDefault(require("./mediaQueries"));
17
-
18
- var _colors = _interopRequireDefault(require("./transform/colors"));
19
-
20
- exports.transformColor = _colors.default;
21
-
22
- var _transform2 = _interopRequireDefault(require("./transform/transform"));
23
-
24
- exports.processTransform = _transform2.default;
25
-
26
- /**
27
- * Resolves styles
28
- *
29
- * @param {Object} container
30
- * @param {Object} style object
31
- * @returns {Object} resolved style object
32
- */
33
- var resolveStyles = function resolveStyles(container, style) {
34
- var computeMediaQueries = function computeMediaQueries(value) {
35
- return (0, _mediaQueries.default)(container, value);
36
- };
37
-
38
- return (0, _fns.compose)((0, _transform.default)(container), _expand.default, computeMediaQueries, _flatten.default)(style);
39
- }; // Utils exported for SVG processing
40
-
41
-
42
- var _default = resolveStyles;
43
- exports.default = _default;
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
-
10
- var _mediaEngine = _interopRequireDefault(require("media-engine"));
11
-
12
- /**
13
- * Resolves media queries in styles object
14
- *
15
- * @param {Object} container
16
- * @param {Object} styles object
17
- */
18
- var resolveMediaQueries = function resolveMediaQueries(container, styles) {
19
- return Object.keys(styles).reduce(function (acc, key) {
20
- var _extends2;
21
-
22
- if (/@media/.test(key)) {
23
- var _matchMedia;
24
-
25
- return (0, _extends3.default)({}, acc, (0, _mediaEngine.default)((_matchMedia = {}, _matchMedia[key] = styles[key], _matchMedia), container));
26
- }
27
-
28
- return (0, _extends3.default)({}, acc, (_extends2 = {}, _extends2[key] = styles[key], _extends2));
29
- }, {});
30
- };
31
-
32
- var _default = resolveMediaQueries;
33
- exports.default = _default;
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _hslToHex = _interopRequireDefault(require("hsl-to-hex"));
9
-
10
- var _colorString = _interopRequireDefault(require("color-string"));
11
-
12
- var isRgb = function isRgb(value) {
13
- return /rgba?/g.test(value);
14
- };
15
-
16
- var isHsl = function isHsl(value) {
17
- return /hsla?/g.test(value);
18
- };
19
- /**
20
- * Transform rgb color to hexa
21
- *
22
- * @param {String} styles value
23
- * @returns {Object} transformed value
24
- */
25
-
26
-
27
- var parseRgb = function parseRgb(value) {
28
- var rgb = _colorString.default.get.rgb(value);
29
-
30
- return _colorString.default.to.hex(rgb);
31
- };
32
- /**
33
- * Transform Hsl color to hexa
34
- *
35
- * @param {String} styles value
36
- * @returns {Object} transformed value
37
- */
38
-
39
-
40
- var parseHsl = function parseHsl(value) {
41
- var hsl = _colorString.default.get.hsl(value).map(Math.round);
42
-
43
- var hex = _hslToHex.default.apply(void 0, hsl);
44
-
45
- return hex.toUpperCase();
46
- };
47
- /**
48
- * Transform given color to hexa
49
- *
50
- * @param {String} styles value
51
- * @returns {Object} transformed value
52
- */
53
-
54
-
55
- var transformColor = function transformColor(value) {
56
- if (isRgb(value)) return parseRgb(value);
57
- if (isHsl(value)) return parseHsl(value);
58
- return value;
59
- };
60
-
61
- var _default = transformColor;
62
- exports.default = _default;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var FONT_WEIGHTS = {
6
- thin: 100,
7
- hairline: 100,
8
- ultralight: 200,
9
- extralight: 200,
10
- light: 300,
11
- normal: 400,
12
- medium: 500,
13
- semibold: 600,
14
- demibold: 600,
15
- bold: 700,
16
- ultrabold: 800,
17
- extrabold: 800,
18
- heavy: 900,
19
- black: 900
20
- };
21
-
22
- var processFontWeight = function processFontWeight(value) {
23
- if (!value) return FONT_WEIGHTS.normal;
24
- if (typeof value === 'number') return value;
25
- var lv = value.toLowerCase();
26
- if (FONT_WEIGHTS[lv]) return FONT_WEIGHTS[lv];
27
- return value;
28
- };
29
-
30
- var _default = processFontWeight;
31
- exports.default = _default;