@react-pdf/stylesheet 4.1.9 → 4.2.1

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.
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var fns = require('@react-pdf/fns');
6
- var parse$1 = require('postcss-value-parser/lib/parse');
7
- var parseUnit = require('postcss-value-parser/lib/unit');
6
+ var parse$1 = require('postcss-value-parser/lib/parse.js');
7
+ var parseUnit = require('postcss-value-parser/lib/unit.js');
8
8
  var hlsToHex = require('hsl-to-hex');
9
9
  var colorString = require('color-string');
10
10
  var _extends = require('@babel/runtime/helpers/extends');
@@ -23,8 +23,14 @@ var matchMedia__default = /*#__PURE__*/_interopDefaultLegacy(matchMedia);
23
23
 
24
24
  // TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
25
25
  var flexDefaults = [1, 1, 0];
26
+ /**
27
+ * @type {(number | 'auto')[]}
28
+ */
26
29
  var flexAuto = [1, 1, 'auto'];
27
30
  var expandFlex = function expandFlex(key, value) {
31
+ /**
32
+ * @type {(number | 'auto')[]}
33
+ */
28
34
  var defaults = flexDefaults;
29
35
  var matches = [];
30
36
  if (value === 'auto') {
@@ -47,6 +53,13 @@ var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
47
53
  var logError = function logError(style, value) {
48
54
  console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
49
55
  };
56
+
57
+ /**
58
+ * @param {Object} options
59
+ * @param {Function} [options.expandsTo]
60
+ * @param {number} [options.maxValues]
61
+ * @param {boolean} [options.autoSupported]
62
+ */
50
63
  var expandBoxModel = function expandBoxModel(_temp) {
51
64
  var _ref = _temp === void 0 ? {} : _temp,
52
65
  expandsTo = _ref.expandsTo,
@@ -326,9 +339,9 @@ var shorthands = {
326
339
  /**
327
340
  * Transforms style key-value
328
341
  *
329
- * @param {String} key style key
330
- * @param {String} value style value
331
- * @returns {String | Number} transformed style values
342
+ * @param {string} key style key
343
+ * @param {string} value style value
344
+ * @returns {string | Number} transformed style values
332
345
  */
333
346
  var expandStyle = function expandStyle(key, value) {
334
347
  var _ref;
@@ -338,8 +351,8 @@ var expandStyle = function expandStyle(key, value) {
338
351
  /**
339
352
  * Expand the shorthand properties.
340
353
  *
341
- * @param { Object } style object
342
- * @returns { Object } expanded style object
354
+ * @param {Object} style object
355
+ * @returns {Object} expanded style object
343
356
  */
344
357
  var expand = function expand(style) {
345
358
  if (!style) return style;
@@ -362,8 +375,9 @@ var expand = function expand(style) {
362
375
  /**
363
376
  * Remove nil values from array
364
377
  *
365
- * @param {Array} array
366
- * @returns {Array} array without nils
378
+ * @template T
379
+ * @param {(T | null | undefined)[]} array
380
+ * @returns {T[]} array without nils
367
381
  */
368
382
  var compact = function compact(array) {
369
383
  return array.filter(Boolean);
@@ -372,7 +386,7 @@ var compact = function compact(array) {
372
386
  /**
373
387
  * Merges style objects array
374
388
  *
375
- * @param {Array} style objects array
389
+ * @param {Object[]} styles style objects array
376
390
  * @returns {Object} merged style object
377
391
  */
378
392
  var mergeStyles = function mergeStyles(styles) {
@@ -390,21 +404,21 @@ var mergeStyles = function mergeStyles(styles) {
390
404
  /**
391
405
  * Flattens an array of style objects, into one aggregated style object.
392
406
  *
393
- * @param {Array} style objects array
394
- * @returns {Object} flatted style object
407
+ * @param {Object[]} styles style objects array
408
+ * @returns {Object} flattened style object
395
409
  */
396
410
  var flatten = fns.compose(mergeStyles, compact, fns.castArray);
397
411
 
398
412
  /**
399
413
  * Parses scalar value in value and unit pairs
400
414
  *
401
- * @param {String} scalar value
415
+ * @param {string} value scalar value
402
416
  * @returns {Object} parsed value
403
417
  */
404
418
  var parseValue = function parseValue(value) {
405
419
  var match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value);
406
420
  return match ? {
407
- value: parseFloat(match[1], 10),
421
+ value: parseFloat(match[1]),
408
422
  unit: match[2] || 'pt'
409
423
  } : {
410
424
  value: value,
@@ -416,7 +430,7 @@ var parseValue = function parseValue(value) {
416
430
  * Transform given scalar value
417
431
  *
418
432
  * @param {Object} container
419
- * @param {String} styles value
433
+ * @param {string} value styles value
420
434
  * @returns {Object} transformed value
421
435
  */
422
436
  var transformUnit = function transformUnit(container, value) {
@@ -450,7 +464,7 @@ var isHsl = function isHsl(value) {
450
464
  /**
451
465
  * Transform rgb color to hexa
452
466
  *
453
- * @param {String} styles value
467
+ * @param {string} value styles value
454
468
  * @returns {Object} transformed value
455
469
  */
456
470
  var parseRgb = function parseRgb(value) {
@@ -461,7 +475,7 @@ var parseRgb = function parseRgb(value) {
461
475
  /**
462
476
  * Transform Hsl color to hexa
463
477
  *
464
- * @param {String} styles value
478
+ * @param {string} value styles value
465
479
  * @returns {Object} transformed value
466
480
  */
467
481
  var parseHsl = function parseHsl(value) {
@@ -473,7 +487,7 @@ var parseHsl = function parseHsl(value) {
473
487
  /**
474
488
  * Transform given color to hexa
475
489
  *
476
- * @param {String} styles value
490
+ * @param {string} value styles value
477
491
  * @returns {Object} transformed value
478
492
  */
479
493
  var transformColor = function transformColor(value) {
@@ -648,7 +662,7 @@ var matchNumber = function matchNumber(value) {
648
662
  };
649
663
  var castFloat = function castFloat(value) {
650
664
  if (typeof value !== 'string') return value;
651
- if (matchNumber(value)) return parseFloat(value, 10);
665
+ if (matchNumber(value)) return parseFloat(value);
652
666
  return value;
653
667
  };
654
668
 
@@ -688,11 +702,17 @@ var transformStyle = function transformStyle(key, value, container) {
688
702
  return transformColor(transformUnit(container, castFloat(result)));
689
703
  };
690
704
 
705
+ /**
706
+ * @typedef {Function} Transform
707
+ * @param {Object} style styles object
708
+ * @returns {Object} transformed styles
709
+ */
710
+
691
711
  /**
692
712
  * Transform styles values
693
713
  *
694
- * @param {Object} styles object
695
- * @returns {Object} transformed styles
714
+ * @param {Object} container
715
+ * @returns {Transform} transform function
696
716
  */
697
717
  var transform = function transform(container) {
698
718
  return function (style) {
@@ -1,6 +1,6 @@
1
1
  import { compose, castArray } from '@react-pdf/fns';
2
- import parse$1 from 'postcss-value-parser/lib/parse';
3
- import parseUnit from 'postcss-value-parser/lib/unit';
2
+ import parse$1 from 'postcss-value-parser/lib/parse.js';
3
+ import parseUnit from 'postcss-value-parser/lib/unit.js';
4
4
  import hlsToHex from 'hsl-to-hex';
5
5
  import colorString from 'color-string';
6
6
  import _extends from '@babel/runtime/helpers/extends';
@@ -10,8 +10,14 @@ import matchMedia from 'media-engine';
10
10
 
11
11
  // TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
12
12
  var flexDefaults = [1, 1, 0];
13
+ /**
14
+ * @type {(number | 'auto')[]}
15
+ */
13
16
  var flexAuto = [1, 1, 'auto'];
14
17
  var expandFlex = function expandFlex(key, value) {
18
+ /**
19
+ * @type {(number | 'auto')[]}
20
+ */
15
21
  var defaults = flexDefaults;
16
22
  var matches = [];
17
23
  if (value === 'auto') {
@@ -34,6 +40,13 @@ var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
34
40
  var logError = function logError(style, value) {
35
41
  console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
36
42
  };
43
+
44
+ /**
45
+ * @param {Object} options
46
+ * @param {Function} [options.expandsTo]
47
+ * @param {number} [options.maxValues]
48
+ * @param {boolean} [options.autoSupported]
49
+ */
37
50
  var expandBoxModel = function expandBoxModel(_temp) {
38
51
  var _ref = _temp === void 0 ? {} : _temp,
39
52
  expandsTo = _ref.expandsTo,
@@ -313,9 +326,9 @@ var shorthands = {
313
326
  /**
314
327
  * Transforms style key-value
315
328
  *
316
- * @param {String} key style key
317
- * @param {String} value style value
318
- * @returns {String | Number} transformed style values
329
+ * @param {string} key style key
330
+ * @param {string} value style value
331
+ * @returns {string | Number} transformed style values
319
332
  */
320
333
  var expandStyle = function expandStyle(key, value) {
321
334
  var _ref;
@@ -325,8 +338,8 @@ var expandStyle = function expandStyle(key, value) {
325
338
  /**
326
339
  * Expand the shorthand properties.
327
340
  *
328
- * @param { Object } style object
329
- * @returns { Object } expanded style object
341
+ * @param {Object} style object
342
+ * @returns {Object} expanded style object
330
343
  */
331
344
  var expand = function expand(style) {
332
345
  if (!style) return style;
@@ -349,8 +362,9 @@ var expand = function expand(style) {
349
362
  /**
350
363
  * Remove nil values from array
351
364
  *
352
- * @param {Array} array
353
- * @returns {Array} array without nils
365
+ * @template T
366
+ * @param {(T | null | undefined)[]} array
367
+ * @returns {T[]} array without nils
354
368
  */
355
369
  var compact = function compact(array) {
356
370
  return array.filter(Boolean);
@@ -359,7 +373,7 @@ var compact = function compact(array) {
359
373
  /**
360
374
  * Merges style objects array
361
375
  *
362
- * @param {Array} style objects array
376
+ * @param {Object[]} styles style objects array
363
377
  * @returns {Object} merged style object
364
378
  */
365
379
  var mergeStyles = function mergeStyles(styles) {
@@ -377,21 +391,21 @@ var mergeStyles = function mergeStyles(styles) {
377
391
  /**
378
392
  * Flattens an array of style objects, into one aggregated style object.
379
393
  *
380
- * @param {Array} style objects array
381
- * @returns {Object} flatted style object
394
+ * @param {Object[]} styles style objects array
395
+ * @returns {Object} flattened style object
382
396
  */
383
397
  var flatten = compose(mergeStyles, compact, castArray);
384
398
 
385
399
  /**
386
400
  * Parses scalar value in value and unit pairs
387
401
  *
388
- * @param {String} scalar value
402
+ * @param {string} value scalar value
389
403
  * @returns {Object} parsed value
390
404
  */
391
405
  var parseValue = function parseValue(value) {
392
406
  var match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value);
393
407
  return match ? {
394
- value: parseFloat(match[1], 10),
408
+ value: parseFloat(match[1]),
395
409
  unit: match[2] || 'pt'
396
410
  } : {
397
411
  value: value,
@@ -403,7 +417,7 @@ var parseValue = function parseValue(value) {
403
417
  * Transform given scalar value
404
418
  *
405
419
  * @param {Object} container
406
- * @param {String} styles value
420
+ * @param {string} value styles value
407
421
  * @returns {Object} transformed value
408
422
  */
409
423
  var transformUnit = function transformUnit(container, value) {
@@ -437,7 +451,7 @@ var isHsl = function isHsl(value) {
437
451
  /**
438
452
  * Transform rgb color to hexa
439
453
  *
440
- * @param {String} styles value
454
+ * @param {string} value styles value
441
455
  * @returns {Object} transformed value
442
456
  */
443
457
  var parseRgb = function parseRgb(value) {
@@ -448,7 +462,7 @@ var parseRgb = function parseRgb(value) {
448
462
  /**
449
463
  * Transform Hsl color to hexa
450
464
  *
451
- * @param {String} styles value
465
+ * @param {string} value styles value
452
466
  * @returns {Object} transformed value
453
467
  */
454
468
  var parseHsl = function parseHsl(value) {
@@ -460,7 +474,7 @@ var parseHsl = function parseHsl(value) {
460
474
  /**
461
475
  * Transform given color to hexa
462
476
  *
463
- * @param {String} styles value
477
+ * @param {string} value styles value
464
478
  * @returns {Object} transformed value
465
479
  */
466
480
  var transformColor = function transformColor(value) {
@@ -635,7 +649,7 @@ var matchNumber = function matchNumber(value) {
635
649
  };
636
650
  var castFloat = function castFloat(value) {
637
651
  if (typeof value !== 'string') return value;
638
- if (matchNumber(value)) return parseFloat(value, 10);
652
+ if (matchNumber(value)) return parseFloat(value);
639
653
  return value;
640
654
  };
641
655
 
@@ -675,11 +689,17 @@ var transformStyle = function transformStyle(key, value, container) {
675
689
  return transformColor(transformUnit(container, castFloat(result)));
676
690
  };
677
691
 
692
+ /**
693
+ * @typedef {Function} Transform
694
+ * @param {Object} style styles object
695
+ * @returns {Object} transformed styles
696
+ */
697
+
678
698
  /**
679
699
  * Transform styles values
680
700
  *
681
- * @param {Object} styles object
682
- * @returns {Object} transformed styles
701
+ * @param {Object} container
702
+ * @returns {Transform} transform function
683
703
  */
684
704
  var transform = function transform(container) {
685
705
  return function (style) {
package/package.json CHANGED
@@ -1,27 +1,35 @@
1
1
  {
2
2
  "name": "@react-pdf/stylesheet",
3
- "version": "4.1.9",
3
+ "version": "4.2.1",
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.cjs.js",
9
- "module": "lib/index.es.js",
8
+ "type": "module",
9
+ "main": "./lib/index.cjs",
10
+ "module": "./lib/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./lib/index.js",
14
+ "require": "./lib/index.cjs",
15
+ "default": "./lib/index.js"
16
+ }
17
+ },
10
18
  "repository": {
11
19
  "type": "git",
12
20
  "url": "https://github.com/diegomura/react-pdf.git",
13
21
  "directory": "packages/stylesheet"
14
22
  },
15
23
  "scripts": {
16
- "test": "jest",
24
+ "test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
17
25
  "build": "rimraf ./lib && rollup -c",
18
26
  "watch": "rimraf ./lib && rollup -c -w"
19
27
  },
20
28
  "dependencies": {
21
29
  "@babel/runtime": "^7.20.13",
22
- "@react-pdf/fns": "2.0.1",
23
- "@react-pdf/types": "^2.3.5",
24
- "color-string": "^1.5.3",
30
+ "@react-pdf/fns": "2.1.0",
31
+ "@react-pdf/types": "^2.3.6",
32
+ "color-string": "^1.9.1",
25
33
  "hsl-to-hex": "^1.0.0",
26
34
  "media-engine": "^1.0.3",
27
35
  "postcss-value-parser": "^4.1.0"