@react-pdf/stylesheet 4.1.1 → 4.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @react-pdf/stylesheet
2
2
 
3
+ ## 4.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2205](https://github.com/diegomura/react-pdf/pull/2205) [`9a5e0be`](https://github.com/diegomura/react-pdf/commit/9a5e0befb89756db07ce053192a136df9d4ba905) Thanks [@jeetiss](https://github.com/jeetiss)! - update babel
8
+
9
+ ## 4.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2191](https://github.com/diegomura/react-pdf/pull/2191) [`37c3d74`](https://github.com/diegomura/react-pdf/commit/37c3d741fc9ad7eb91508b5caf6a5a554243f7ff) Thanks [@jeetiss](https://github.com/jeetiss)! - revert flex shorthand defaults
14
+
3
15
  ## 4.1.1
4
16
 
5
17
  ### Patch Changes
package/lib/index.cjs.js CHANGED
@@ -20,19 +20,18 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
20
20
  var matchMedia__default = /*#__PURE__*/_interopDefaultLegacy(matchMedia);
21
21
 
22
22
  // https://developer.mozilla.org/en-US/docs/Web/CSS/flex#values
23
- var flexDefaults = [0, 1, 'auto'];
24
- var flexAuto = [1, 1, 'auto'];
25
23
 
24
+ // TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
25
+ var flexDefaults = [1, 1, 0];
26
+ var flexAuto = [1, 1, 'auto'];
26
27
  var expandFlex = function expandFlex(key, value) {
27
28
  var defaults = flexDefaults;
28
29
  var matches = [];
29
-
30
30
  if (value === 'auto') {
31
31
  defaults = flexAuto;
32
32
  } else {
33
33
  matches = ("" + value).split(' ');
34
34
  }
35
-
36
35
  var flexGrow = matches[0] || defaults[0];
37
36
  var flexShrink = matches[1] || defaults[1];
38
37
  var flexBasis = matches[2] || defaults[2];
@@ -45,40 +44,36 @@ var expandFlex = function expandFlex(key, value) {
45
44
 
46
45
  /* eslint-disable no-plusplus */
47
46
  var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
48
-
49
47
  var logError = function logError(style, value) {
50
48
  console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
51
49
  };
52
-
53
50
  var expandBoxModel = function expandBoxModel(_temp) {
54
51
  var _ref = _temp === void 0 ? {} : _temp,
55
- expandsTo = _ref.expandsTo,
56
- _ref$maxValues = _ref.maxValues,
57
- maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
58
- _ref$autoSupported = _ref.autoSupported,
59
- autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
60
-
52
+ expandsTo = _ref.expandsTo,
53
+ _ref$maxValues = _ref.maxValues,
54
+ maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
55
+ _ref$autoSupported = _ref.autoSupported,
56
+ autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
61
57
  return function (model, value) {
62
58
  var _ref2;
63
-
64
59
  var nodes = parse__default["default"]("" + value);
65
60
  var parts = [];
66
-
67
61
  for (var i = 0; i < nodes.length; i++) {
68
- var node = nodes[i]; // value contains `calc`, `url` or other css function
69
- // `,`, `/` or strings that unsupported by margin and padding
62
+ var node = nodes[i];
70
63
 
64
+ // value contains `calc`, `url` or other css function
65
+ // `,`, `/` or strings that unsupported by margin and padding
71
66
  if (node.type === 'function' || node.type === 'string' || node.type === 'div') {
72
67
  logError(model, value);
73
68
  return {};
74
69
  }
75
-
76
70
  if (node.type === 'word') {
77
71
  if (node.value === 'auto' && autoSupported) {
78
72
  parts.push(node.value);
79
73
  } else {
80
- var result = parseUnit__default["default"](node.value); // when unit isn't specified this condition is true
74
+ var result = parseUnit__default["default"](node.value);
81
75
 
76
+ // when unit isn't specified this condition is true
82
77
  if (result && BOX_MODEL_UNITS.includes(result.unit)) {
83
78
  parts.push(node.value);
84
79
  } else {
@@ -87,16 +82,14 @@ var expandBoxModel = function expandBoxModel(_temp) {
87
82
  }
88
83
  }
89
84
  }
90
- } // checks that we have enough parsed values
91
-
85
+ }
92
86
 
87
+ // checks that we have enough parsed values
93
88
  if (parts.length > maxValues) {
94
89
  logError(model, value);
95
90
  return {};
96
91
  }
97
-
98
92
  var first = parts[0];
99
-
100
93
  if (expandsTo) {
101
94
  var second = parts[1] || parts[0];
102
95
  var third = parts[2] || parts[0];
@@ -108,7 +101,6 @@ var expandBoxModel = function expandBoxModel(_temp) {
108
101
  fourth: fourth
109
102
  });
110
103
  }
111
-
112
104
  return _ref2 = {}, _ref2[model] = first, _ref2;
113
105
  };
114
106
  };
@@ -116,9 +108,9 @@ var expandBoxModel = function expandBoxModel(_temp) {
116
108
  var processMargin = expandBoxModel({
117
109
  expandsTo: function expandsTo(_ref) {
118
110
  var first = _ref.first,
119
- second = _ref.second,
120
- third = _ref.third,
121
- fourth = _ref.fourth;
111
+ second = _ref.second,
112
+ third = _ref.third,
113
+ fourth = _ref.fourth;
122
114
  return {
123
115
  marginTop: first,
124
116
  marginRight: second,
@@ -132,7 +124,7 @@ var processMargin = expandBoxModel({
132
124
  var processMarginVertical = expandBoxModel({
133
125
  expandsTo: function expandsTo(_ref2) {
134
126
  var first = _ref2.first,
135
- second = _ref2.second;
127
+ second = _ref2.second;
136
128
  return {
137
129
  marginTop: first,
138
130
  marginBottom: second
@@ -144,7 +136,7 @@ var processMarginVertical = expandBoxModel({
144
136
  var processMarginHorizontal = expandBoxModel({
145
137
  expandsTo: function expandsTo(_ref3) {
146
138
  var first = _ref3.first,
147
- second = _ref3.second;
139
+ second = _ref3.second;
148
140
  return {
149
141
  marginRight: first,
150
142
  marginLeft: second
@@ -158,25 +150,19 @@ var processMarginSingle = expandBoxModel({
158
150
  });
159
151
 
160
152
  var BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
161
-
162
153
  var matchBorderShorthand = function matchBorderShorthand(value) {
163
154
  return value.match(BORDER_SHORTHAND_REGEX) || [];
164
155
  };
165
-
166
156
  var expandBorders = function expandBorders(key, value) {
167
157
  var match = matchBorderShorthand("" + value);
168
-
169
158
  if (match) {
170
159
  var color = match[5] || value;
171
160
  var style = match[4] || value;
172
161
  var width = match[1] || value;
173
-
174
162
  if (key.match(/(Top|Right|Bottom|Left)$/)) {
175
163
  var _ref;
176
-
177
164
  return _ref = {}, _ref[key + "Color"] = color, _ref[key + "Style"] = style, _ref[key + "Width"] = width, _ref;
178
165
  }
179
-
180
166
  if (key.match(/Color$/)) {
181
167
  return {
182
168
  borderTopColor: color,
@@ -185,7 +171,6 @@ var expandBorders = function expandBorders(key, value) {
185
171
  borderLeftColor: color
186
172
  };
187
173
  }
188
-
189
174
  if (key.match(/Style$/)) {
190
175
  return {
191
176
  borderTopStyle: style,
@@ -194,7 +179,6 @@ var expandBorders = function expandBorders(key, value) {
194
179
  borderLeftStyle: style
195
180
  };
196
181
  }
197
-
198
182
  if (key.match(/Width$/)) {
199
183
  return {
200
184
  borderTopWidth: width,
@@ -203,7 +187,6 @@ var expandBorders = function expandBorders(key, value) {
203
187
  borderLeftWidth: width
204
188
  };
205
189
  }
206
-
207
190
  if (key.match(/Radius$/)) {
208
191
  return {
209
192
  borderTopLeftRadius: value,
@@ -212,7 +195,6 @@ var expandBorders = function expandBorders(key, value) {
212
195
  borderBottomLeftRadius: value
213
196
  };
214
197
  }
215
-
216
198
  return {
217
199
  borderTopColor: color,
218
200
  borderTopStyle: style,
@@ -228,16 +210,15 @@ var expandBorders = function expandBorders(key, value) {
228
210
  borderLeftWidth: width
229
211
  };
230
212
  }
231
-
232
213
  return value;
233
214
  };
234
215
 
235
216
  var processPadding = expandBoxModel({
236
217
  expandsTo: function expandsTo(_ref) {
237
218
  var first = _ref.first,
238
- second = _ref.second,
239
- third = _ref.third,
240
- fourth = _ref.fourth;
219
+ second = _ref.second,
220
+ third = _ref.third,
221
+ fourth = _ref.fourth;
241
222
  return {
242
223
  paddingTop: first,
243
224
  paddingRight: second,
@@ -250,7 +231,7 @@ var processPadding = expandBoxModel({
250
231
  var processPaddingVertical = expandBoxModel({
251
232
  expandsTo: function expandsTo(_ref2) {
252
233
  var first = _ref2.first,
253
- second = _ref2.second;
234
+ second = _ref2.second;
254
235
  return {
255
236
  paddingTop: first,
256
237
  paddingBottom: second
@@ -261,7 +242,7 @@ var processPaddingVertical = expandBoxModel({
261
242
  var processPaddingHorizontal = expandBoxModel({
262
243
  expandsTo: function expandsTo(_ref3) {
263
244
  var first = _ref3.first,
264
- second = _ref3.second;
245
+ second = _ref3.second;
265
246
  return {
266
247
  paddingRight: first,
267
248
  paddingLeft: second
@@ -283,20 +264,18 @@ var Y_AXIS_SHORTHANDS = {
283
264
  top: true,
284
265
  bottom: true
285
266
  };
286
-
287
267
  var sortTransformOriginPair = function sortTransformOriginPair(a, b) {
288
268
  if (Y_AXIS_SHORTHANDS[a]) return 1;
289
269
  if (Y_AXIS_SHORTHANDS[b]) return -1;
290
270
  return 0;
291
271
  };
292
-
293
272
  var getTransformOriginPair = function getTransformOriginPair(values) {
294
273
  if (!values || values.length === 0) return ['center', 'center'];
295
274
  var pair = values.length === 1 ? [values[0], 'center'] : values;
296
275
  return pair.sort(sortTransformOriginPair);
297
- }; // Transforms shorthand transformOrigin values
298
-
276
+ };
299
277
 
278
+ // Transforms shorthand transformOrigin values
300
279
  var expandTransformOrigin = function expandTransformOrigin(key, value) {
301
280
  var match = ("" + value).split(' ');
302
281
  var pair = getTransformOriginPair(match);
@@ -343,6 +322,7 @@ var shorthands = {
343
322
  objectPosition: expandObjectPosition,
344
323
  transformOrigin: expandTransformOrigin
345
324
  };
325
+
346
326
  /**
347
327
  * Transforms style key-value
348
328
  *
@@ -350,38 +330,32 @@ var shorthands = {
350
330
  * @param {String} value style value
351
331
  * @returns {String | Number} transformed style values
352
332
  */
353
-
354
333
  var expandStyle = function expandStyle(key, value) {
355
334
  var _ref;
356
-
357
335
  return shorthands[key] ? shorthands[key](key, value) : (_ref = {}, _ref[key] = value, _ref);
358
336
  };
337
+
359
338
  /**
360
339
  * Expand the shorthand properties.
361
340
  *
362
341
  * @param { Object } style object
363
342
  * @returns { Object } expanded style object
364
343
  */
365
-
366
-
367
344
  var expand = function expand(style) {
368
345
  if (!style) return style;
369
346
  var propsArray = Object.keys(style);
370
347
  var resolvedStyle = {};
371
-
372
348
  for (var i = 0; i < propsArray.length; i += 1) {
373
349
  var key = propsArray[i];
374
350
  var value = style[key];
375
351
  var extended = expandStyle(key, value);
376
352
  var keys = Object.keys(extended);
377
-
378
353
  for (var j = 0; j < keys.length; j += 1) {
379
354
  var propName = keys[j];
380
355
  var propValue = extended[propName];
381
356
  resolvedStyle[propName] = propValue;
382
357
  }
383
358
  }
384
-
385
359
  return resolvedStyle;
386
360
  };
387
361
 
@@ -391,18 +365,16 @@ var expand = function expand(style) {
391
365
  * @param {Array} array
392
366
  * @returns {Array} array without nils
393
367
  */
394
-
395
368
  var compact = function compact(array) {
396
369
  return array.filter(Boolean);
397
370
  };
371
+
398
372
  /**
399
373
  * Merges style objects array
400
374
  *
401
375
  * @param {Array} style objects array
402
376
  * @returns {Object} merged style object
403
377
  */
404
-
405
-
406
378
  var mergeStyles = function mergeStyles(styles) {
407
379
  return styles.reduce(function (acc, style) {
408
380
  var s = Array.isArray(style) ? flatten(style) : style;
@@ -414,14 +386,13 @@ var mergeStyles = function mergeStyles(styles) {
414
386
  return acc;
415
387
  }, {});
416
388
  };
389
+
417
390
  /**
418
391
  * Flattens an array of style objects, into one aggregated style object.
419
392
  *
420
393
  * @param {Array} style objects array
421
394
  * @returns {Object} flatted style object
422
395
  */
423
-
424
-
425
396
  var flatten = fns.compose(mergeStyles, compact, fns.castArray);
426
397
 
427
398
  /**
@@ -440,6 +411,7 @@ var parseValue = function parseValue(value) {
440
411
  unit: undefined
441
412
  };
442
413
  };
414
+
443
415
  /**
444
416
  * Transform given scalar value
445
417
  *
@@ -447,30 +419,22 @@ var parseValue = function parseValue(value) {
447
419
  * @param {String} styles value
448
420
  * @returns {Object} transformed value
449
421
  */
450
-
451
-
452
422
  var transformUnit = function transformUnit(container, value) {
453
423
  var scalar = parseValue(value);
454
424
  var dpi = container.dpi || 72;
455
425
  var mmFactor = 1 / 25.4 * dpi;
456
426
  var cmFactor = 1 / 2.54 * dpi;
457
-
458
427
  switch (scalar.unit) {
459
428
  case 'in':
460
429
  return scalar.value * dpi;
461
-
462
430
  case 'mm':
463
431
  return scalar.value * mmFactor;
464
-
465
432
  case 'cm':
466
433
  return scalar.value * cmFactor;
467
-
468
434
  case 'vh':
469
435
  return scalar.value * (container.height / 100);
470
-
471
436
  case 'vw':
472
437
  return scalar.value * (container.width / 100);
473
-
474
438
  default:
475
439
  return scalar.value;
476
440
  }
@@ -479,43 +443,39 @@ var transformUnit = function transformUnit(container, value) {
479
443
  var isRgb = function isRgb(value) {
480
444
  return /rgba?/g.test(value);
481
445
  };
482
-
483
446
  var isHsl = function isHsl(value) {
484
447
  return /hsla?/g.test(value);
485
448
  };
449
+
486
450
  /**
487
451
  * Transform rgb color to hexa
488
452
  *
489
453
  * @param {String} styles value
490
454
  * @returns {Object} transformed value
491
455
  */
492
-
493
-
494
456
  var parseRgb = function parseRgb(value) {
495
457
  var rgb = colorString__default["default"].get.rgb(value);
496
458
  return colorString__default["default"].to.hex(rgb);
497
459
  };
460
+
498
461
  /**
499
462
  * Transform Hsl color to hexa
500
463
  *
501
464
  * @param {String} styles value
502
465
  * @returns {Object} transformed value
503
466
  */
504
-
505
-
506
467
  var parseHsl = function parseHsl(value) {
507
468
  var hsl = colorString__default["default"].get.hsl(value).map(Math.round);
508
469
  var hex = hlsToHex__default["default"].apply(void 0, hsl);
509
470
  return hex.toUpperCase();
510
471
  };
472
+
511
473
  /**
512
474
  * Transform given color to hexa
513
475
  *
514
476
  * @param {String} styles value
515
477
  * @returns {Object} transformed value
516
478
  */
517
-
518
-
519
479
  var transformColor = function transformColor(value) {
520
480
  if (isRgb(value)) return parseRgb(value);
521
481
  if (isHsl(value)) return parseHsl(value);
@@ -523,22 +483,19 @@ var transformColor = function transformColor(value) {
523
483
  };
524
484
 
525
485
  var parse = function parse(transformString) {
526
- var transforms = transformString.trim().split(/\) |\)/); // Handle "initial", "inherit", "unset".
486
+ var transforms = transformString.trim().split(/\) |\)/);
527
487
 
488
+ // Handle "initial", "inherit", "unset".
528
489
  if (transforms.length === 1) {
529
490
  return [[transforms[0], true]];
530
491
  }
531
-
532
492
  var parsed = [];
533
-
534
493
  for (var i = 0; i < transforms.length; i += 1) {
535
494
  var transform = transforms[i];
536
-
537
495
  if (transform) {
538
496
  var _transform$split = transform.split('('),
539
- name = _transform$split[0],
540
- rawValue = _transform$split[1];
541
-
497
+ name = _transform$split[0],
498
+ rawValue = _transform$split[1];
542
499
  var splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
543
500
  var value = rawValue.split(splitChar).map(function (val) {
544
501
  return val.trim();
@@ -549,41 +506,33 @@ var parse = function parse(transformString) {
549
506
  });
550
507
  }
551
508
  }
552
-
553
509
  return parsed;
554
510
  };
555
-
556
511
  var parseAngle = function parseAngle(value) {
557
512
  var unitsRegexp = /(-?\d*\.?\d*)(\w*)?/i;
558
-
559
513
  var _unitsRegexp$exec = unitsRegexp.exec(value),
560
- angle = _unitsRegexp$exec[1],
561
- unit = _unitsRegexp$exec[2];
562
-
514
+ angle = _unitsRegexp$exec[1],
515
+ unit = _unitsRegexp$exec[2];
563
516
  var number = Number.parseFloat(angle);
564
517
  return unit === 'rad' ? number * 180 / Math.PI : number;
565
518
  };
566
-
567
519
  var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
568
520
  var operation = _ref.operation,
569
- value = _ref.value;
570
-
521
+ value = _ref.value;
571
522
  switch (operation) {
572
523
  case 'scale':
573
524
  {
574
525
  var _value$map = value.map(function (num) {
575
- return Number.parseFloat(num);
576
- }),
577
- scaleX = _value$map[0],
578
- _value$map$ = _value$map[1],
579
- scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
580
-
526
+ return Number.parseFloat(num);
527
+ }),
528
+ scaleX = _value$map[0],
529
+ _value$map$ = _value$map[1],
530
+ scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
581
531
  return {
582
532
  operation: 'scale',
583
533
  value: [scaleX, scaleY]
584
534
  };
585
535
  }
586
-
587
536
  case 'scaleX':
588
537
  {
589
538
  return {
@@ -591,7 +540,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
591
540
  value: [Number.parseFloat(value), 1]
592
541
  };
593
542
  }
594
-
595
543
  case 'scaleY':
596
544
  {
597
545
  return {
@@ -599,7 +547,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
599
547
  value: [1, Number.parseFloat(value)]
600
548
  };
601
549
  }
602
-
603
550
  case 'rotate':
604
551
  {
605
552
  return {
@@ -607,7 +554,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
607
554
  value: [parseAngle(value)]
608
555
  };
609
556
  }
610
-
611
557
  case 'translate':
612
558
  {
613
559
  return {
@@ -617,7 +563,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
617
563
  })
618
564
  };
619
565
  }
620
-
621
566
  case 'translateX':
622
567
  {
623
568
  return {
@@ -625,7 +570,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
625
570
  value: [Number.parseFloat(value), 0]
626
571
  };
627
572
  }
628
-
629
573
  case 'translateY':
630
574
  {
631
575
  return {
@@ -633,7 +577,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
633
577
  value: [0, Number.parseFloat(value)]
634
578
  };
635
579
  }
636
-
637
580
  case 'skew':
638
581
  {
639
582
  return {
@@ -641,7 +584,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
641
584
  value: value.map(parseAngle)
642
585
  };
643
586
  }
644
-
645
587
  case 'skewX':
646
588
  {
647
589
  return {
@@ -649,7 +591,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
649
591
  value: [parseAngle(value), 0]
650
592
  };
651
593
  }
652
-
653
594
  case 'skewY':
654
595
  {
655
596
  return {
@@ -657,7 +598,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
657
598
  value: [0, parseAngle(value)]
658
599
  };
659
600
  }
660
-
661
601
  default:
662
602
  {
663
603
  return {
@@ -669,13 +609,11 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
669
609
  }
670
610
  }
671
611
  };
672
-
673
612
  var normalize = function normalize(operations) {
674
613
  return operations.map(function (operation) {
675
614
  return normalizeTransformOperation(operation);
676
615
  });
677
616
  };
678
-
679
617
  var processTransform = function processTransform(value) {
680
618
  if (typeof value !== 'string') return value;
681
619
  return normalize(parse(value));
@@ -697,7 +635,6 @@ var FONT_WEIGHTS = {
697
635
  heavy: 900,
698
636
  black: 900
699
637
  };
700
-
701
638
  var processFontWeight = function processFontWeight(value) {
702
639
  if (!value) return FONT_WEIGHTS.normal;
703
640
  if (typeof value === 'number') return value;
@@ -709,7 +646,6 @@ var processFontWeight = function processFontWeight(value) {
709
646
  var matchNumber = function matchNumber(value) {
710
647
  return typeof value === 'string' && /^-?\d*\.?\d*$/.test(value);
711
648
  };
712
-
713
649
  var castFloat = function castFloat(value) {
714
650
  if (typeof value !== 'string') return value;
715
651
  if (matchNumber(value)) return parseFloat(value, 10);
@@ -721,14 +657,11 @@ var offsetKeyword = function offsetKeyword(value) {
721
657
  case 'top':
722
658
  case 'left':
723
659
  return '0%';
724
-
725
660
  case 'right':
726
661
  case 'bottom':
727
662
  return '100%';
728
-
729
663
  case 'center':
730
664
  return '50%';
731
-
732
665
  default:
733
666
  return null;
734
667
  }
@@ -750,32 +683,28 @@ var handlers = {
750
683
  transformOriginX: transformTransformOrigin,
751
684
  transformOriginY: transformTransformOrigin
752
685
  };
753
-
754
686
  var transformStyle = function transformStyle(key, value, container) {
755
687
  var result = handlers[key] ? handlers[key](value) : value;
756
688
  return transformColor(transformUnit(container, castFloat(result)));
757
689
  };
690
+
758
691
  /**
759
692
  * Transform styles values
760
693
  *
761
694
  * @param {Object} styles object
762
695
  * @returns {Object} transformed styles
763
696
  */
764
-
765
-
766
697
  var transform = function transform(container) {
767
698
  return function (style) {
768
699
  if (!style) return style;
769
700
  var propsArray = Object.keys(style);
770
701
  var resolvedStyle = {};
771
-
772
702
  for (var i = 0; i < propsArray.length; i += 1) {
773
703
  var key = propsArray[i];
774
704
  var value = style[key];
775
705
  var transformed = transformStyle(key, value, container);
776
706
  resolvedStyle[key] = transformed;
777
707
  }
778
-
779
708
  return resolvedStyle;
780
709
  };
781
710
  };
@@ -786,17 +715,13 @@ var transform = function transform(container) {
786
715
  * @param {Object} container
787
716
  * @param {Object} styles object
788
717
  */
789
-
790
718
  var resolveMediaQueries = function resolveMediaQueries(container, styles) {
791
719
  return Object.keys(styles).reduce(function (acc, key) {
792
720
  var _extends2;
793
-
794
721
  if (/@media/.test(key)) {
795
722
  var _matchMedia;
796
-
797
723
  return _extends__default["default"]({}, acc, matchMedia__default["default"]((_matchMedia = {}, _matchMedia[key] = styles[key], _matchMedia), container));
798
724
  }
799
-
800
725
  return _extends__default["default"]({}, acc, (_extends2 = {}, _extends2[key] = styles[key], _extends2));
801
726
  }, {});
802
727
  };
@@ -808,14 +733,12 @@ var resolveMediaQueries = function resolveMediaQueries(container, styles) {
808
733
  * @param {Object} style object
809
734
  * @returns {Object} resolved style object
810
735
  */
811
-
812
736
  var resolveStyles = function resolveStyles(container, style) {
813
737
  var computeMediaQueries = function computeMediaQueries(value) {
814
738
  return resolveMediaQueries(container, value);
815
739
  };
816
-
817
740
  return fns.compose(transform(container), expand, computeMediaQueries, flatten)(style);
818
- }; // Utils exported for SVG processing
741
+ };
819
742
 
820
743
  exports["default"] = resolveStyles;
821
744
  exports.flatten = flatten;
package/lib/index.es.js CHANGED
@@ -7,19 +7,18 @@ import _extends from '@babel/runtime/helpers/extends';
7
7
  import matchMedia from 'media-engine';
8
8
 
9
9
  // https://developer.mozilla.org/en-US/docs/Web/CSS/flex#values
10
- var flexDefaults = [0, 1, 'auto'];
11
- var flexAuto = [1, 1, 'auto'];
12
10
 
11
+ // TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
12
+ var flexDefaults = [1, 1, 0];
13
+ var flexAuto = [1, 1, 'auto'];
13
14
  var expandFlex = function expandFlex(key, value) {
14
15
  var defaults = flexDefaults;
15
16
  var matches = [];
16
-
17
17
  if (value === 'auto') {
18
18
  defaults = flexAuto;
19
19
  } else {
20
20
  matches = ("" + value).split(' ');
21
21
  }
22
-
23
22
  var flexGrow = matches[0] || defaults[0];
24
23
  var flexShrink = matches[1] || defaults[1];
25
24
  var flexBasis = matches[2] || defaults[2];
@@ -32,40 +31,36 @@ var expandFlex = function expandFlex(key, value) {
32
31
 
33
32
  /* eslint-disable no-plusplus */
34
33
  var BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
35
-
36
34
  var logError = function logError(style, value) {
37
35
  console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
38
36
  };
39
-
40
37
  var expandBoxModel = function expandBoxModel(_temp) {
41
38
  var _ref = _temp === void 0 ? {} : _temp,
42
- expandsTo = _ref.expandsTo,
43
- _ref$maxValues = _ref.maxValues,
44
- maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
45
- _ref$autoSupported = _ref.autoSupported,
46
- autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
47
-
39
+ expandsTo = _ref.expandsTo,
40
+ _ref$maxValues = _ref.maxValues,
41
+ maxValues = _ref$maxValues === void 0 ? 1 : _ref$maxValues,
42
+ _ref$autoSupported = _ref.autoSupported,
43
+ autoSupported = _ref$autoSupported === void 0 ? false : _ref$autoSupported;
48
44
  return function (model, value) {
49
45
  var _ref2;
50
-
51
46
  var nodes = parse$1("" + value);
52
47
  var parts = [];
53
-
54
48
  for (var i = 0; i < nodes.length; i++) {
55
- var node = nodes[i]; // value contains `calc`, `url` or other css function
56
- // `,`, `/` or strings that unsupported by margin and padding
49
+ var node = nodes[i];
57
50
 
51
+ // value contains `calc`, `url` or other css function
52
+ // `,`, `/` or strings that unsupported by margin and padding
58
53
  if (node.type === 'function' || node.type === 'string' || node.type === 'div') {
59
54
  logError(model, value);
60
55
  return {};
61
56
  }
62
-
63
57
  if (node.type === 'word') {
64
58
  if (node.value === 'auto' && autoSupported) {
65
59
  parts.push(node.value);
66
60
  } else {
67
- var result = parseUnit(node.value); // when unit isn't specified this condition is true
61
+ var result = parseUnit(node.value);
68
62
 
63
+ // when unit isn't specified this condition is true
69
64
  if (result && BOX_MODEL_UNITS.includes(result.unit)) {
70
65
  parts.push(node.value);
71
66
  } else {
@@ -74,16 +69,14 @@ var expandBoxModel = function expandBoxModel(_temp) {
74
69
  }
75
70
  }
76
71
  }
77
- } // checks that we have enough parsed values
78
-
72
+ }
79
73
 
74
+ // checks that we have enough parsed values
80
75
  if (parts.length > maxValues) {
81
76
  logError(model, value);
82
77
  return {};
83
78
  }
84
-
85
79
  var first = parts[0];
86
-
87
80
  if (expandsTo) {
88
81
  var second = parts[1] || parts[0];
89
82
  var third = parts[2] || parts[0];
@@ -95,7 +88,6 @@ var expandBoxModel = function expandBoxModel(_temp) {
95
88
  fourth: fourth
96
89
  });
97
90
  }
98
-
99
91
  return _ref2 = {}, _ref2[model] = first, _ref2;
100
92
  };
101
93
  };
@@ -103,9 +95,9 @@ var expandBoxModel = function expandBoxModel(_temp) {
103
95
  var processMargin = expandBoxModel({
104
96
  expandsTo: function expandsTo(_ref) {
105
97
  var first = _ref.first,
106
- second = _ref.second,
107
- third = _ref.third,
108
- fourth = _ref.fourth;
98
+ second = _ref.second,
99
+ third = _ref.third,
100
+ fourth = _ref.fourth;
109
101
  return {
110
102
  marginTop: first,
111
103
  marginRight: second,
@@ -119,7 +111,7 @@ var processMargin = expandBoxModel({
119
111
  var processMarginVertical = expandBoxModel({
120
112
  expandsTo: function expandsTo(_ref2) {
121
113
  var first = _ref2.first,
122
- second = _ref2.second;
114
+ second = _ref2.second;
123
115
  return {
124
116
  marginTop: first,
125
117
  marginBottom: second
@@ -131,7 +123,7 @@ var processMarginVertical = expandBoxModel({
131
123
  var processMarginHorizontal = expandBoxModel({
132
124
  expandsTo: function expandsTo(_ref3) {
133
125
  var first = _ref3.first,
134
- second = _ref3.second;
126
+ second = _ref3.second;
135
127
  return {
136
128
  marginRight: first,
137
129
  marginLeft: second
@@ -145,25 +137,19 @@ var processMarginSingle = expandBoxModel({
145
137
  });
146
138
 
147
139
  var BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
148
-
149
140
  var matchBorderShorthand = function matchBorderShorthand(value) {
150
141
  return value.match(BORDER_SHORTHAND_REGEX) || [];
151
142
  };
152
-
153
143
  var expandBorders = function expandBorders(key, value) {
154
144
  var match = matchBorderShorthand("" + value);
155
-
156
145
  if (match) {
157
146
  var color = match[5] || value;
158
147
  var style = match[4] || value;
159
148
  var width = match[1] || value;
160
-
161
149
  if (key.match(/(Top|Right|Bottom|Left)$/)) {
162
150
  var _ref;
163
-
164
151
  return _ref = {}, _ref[key + "Color"] = color, _ref[key + "Style"] = style, _ref[key + "Width"] = width, _ref;
165
152
  }
166
-
167
153
  if (key.match(/Color$/)) {
168
154
  return {
169
155
  borderTopColor: color,
@@ -172,7 +158,6 @@ var expandBorders = function expandBorders(key, value) {
172
158
  borderLeftColor: color
173
159
  };
174
160
  }
175
-
176
161
  if (key.match(/Style$/)) {
177
162
  return {
178
163
  borderTopStyle: style,
@@ -181,7 +166,6 @@ var expandBorders = function expandBorders(key, value) {
181
166
  borderLeftStyle: style
182
167
  };
183
168
  }
184
-
185
169
  if (key.match(/Width$/)) {
186
170
  return {
187
171
  borderTopWidth: width,
@@ -190,7 +174,6 @@ var expandBorders = function expandBorders(key, value) {
190
174
  borderLeftWidth: width
191
175
  };
192
176
  }
193
-
194
177
  if (key.match(/Radius$/)) {
195
178
  return {
196
179
  borderTopLeftRadius: value,
@@ -199,7 +182,6 @@ var expandBorders = function expandBorders(key, value) {
199
182
  borderBottomLeftRadius: value
200
183
  };
201
184
  }
202
-
203
185
  return {
204
186
  borderTopColor: color,
205
187
  borderTopStyle: style,
@@ -215,16 +197,15 @@ var expandBorders = function expandBorders(key, value) {
215
197
  borderLeftWidth: width
216
198
  };
217
199
  }
218
-
219
200
  return value;
220
201
  };
221
202
 
222
203
  var processPadding = expandBoxModel({
223
204
  expandsTo: function expandsTo(_ref) {
224
205
  var first = _ref.first,
225
- second = _ref.second,
226
- third = _ref.third,
227
- fourth = _ref.fourth;
206
+ second = _ref.second,
207
+ third = _ref.third,
208
+ fourth = _ref.fourth;
228
209
  return {
229
210
  paddingTop: first,
230
211
  paddingRight: second,
@@ -237,7 +218,7 @@ var processPadding = expandBoxModel({
237
218
  var processPaddingVertical = expandBoxModel({
238
219
  expandsTo: function expandsTo(_ref2) {
239
220
  var first = _ref2.first,
240
- second = _ref2.second;
221
+ second = _ref2.second;
241
222
  return {
242
223
  paddingTop: first,
243
224
  paddingBottom: second
@@ -248,7 +229,7 @@ var processPaddingVertical = expandBoxModel({
248
229
  var processPaddingHorizontal = expandBoxModel({
249
230
  expandsTo: function expandsTo(_ref3) {
250
231
  var first = _ref3.first,
251
- second = _ref3.second;
232
+ second = _ref3.second;
252
233
  return {
253
234
  paddingRight: first,
254
235
  paddingLeft: second
@@ -270,20 +251,18 @@ var Y_AXIS_SHORTHANDS = {
270
251
  top: true,
271
252
  bottom: true
272
253
  };
273
-
274
254
  var sortTransformOriginPair = function sortTransformOriginPair(a, b) {
275
255
  if (Y_AXIS_SHORTHANDS[a]) return 1;
276
256
  if (Y_AXIS_SHORTHANDS[b]) return -1;
277
257
  return 0;
278
258
  };
279
-
280
259
  var getTransformOriginPair = function getTransformOriginPair(values) {
281
260
  if (!values || values.length === 0) return ['center', 'center'];
282
261
  var pair = values.length === 1 ? [values[0], 'center'] : values;
283
262
  return pair.sort(sortTransformOriginPair);
284
- }; // Transforms shorthand transformOrigin values
285
-
263
+ };
286
264
 
265
+ // Transforms shorthand transformOrigin values
287
266
  var expandTransformOrigin = function expandTransformOrigin(key, value) {
288
267
  var match = ("" + value).split(' ');
289
268
  var pair = getTransformOriginPair(match);
@@ -330,6 +309,7 @@ var shorthands = {
330
309
  objectPosition: expandObjectPosition,
331
310
  transformOrigin: expandTransformOrigin
332
311
  };
312
+
333
313
  /**
334
314
  * Transforms style key-value
335
315
  *
@@ -337,38 +317,32 @@ var shorthands = {
337
317
  * @param {String} value style value
338
318
  * @returns {String | Number} transformed style values
339
319
  */
340
-
341
320
  var expandStyle = function expandStyle(key, value) {
342
321
  var _ref;
343
-
344
322
  return shorthands[key] ? shorthands[key](key, value) : (_ref = {}, _ref[key] = value, _ref);
345
323
  };
324
+
346
325
  /**
347
326
  * Expand the shorthand properties.
348
327
  *
349
328
  * @param { Object } style object
350
329
  * @returns { Object } expanded style object
351
330
  */
352
-
353
-
354
331
  var expand = function expand(style) {
355
332
  if (!style) return style;
356
333
  var propsArray = Object.keys(style);
357
334
  var resolvedStyle = {};
358
-
359
335
  for (var i = 0; i < propsArray.length; i += 1) {
360
336
  var key = propsArray[i];
361
337
  var value = style[key];
362
338
  var extended = expandStyle(key, value);
363
339
  var keys = Object.keys(extended);
364
-
365
340
  for (var j = 0; j < keys.length; j += 1) {
366
341
  var propName = keys[j];
367
342
  var propValue = extended[propName];
368
343
  resolvedStyle[propName] = propValue;
369
344
  }
370
345
  }
371
-
372
346
  return resolvedStyle;
373
347
  };
374
348
 
@@ -378,18 +352,16 @@ var expand = function expand(style) {
378
352
  * @param {Array} array
379
353
  * @returns {Array} array without nils
380
354
  */
381
-
382
355
  var compact = function compact(array) {
383
356
  return array.filter(Boolean);
384
357
  };
358
+
385
359
  /**
386
360
  * Merges style objects array
387
361
  *
388
362
  * @param {Array} style objects array
389
363
  * @returns {Object} merged style object
390
364
  */
391
-
392
-
393
365
  var mergeStyles = function mergeStyles(styles) {
394
366
  return styles.reduce(function (acc, style) {
395
367
  var s = Array.isArray(style) ? flatten(style) : style;
@@ -401,14 +373,13 @@ var mergeStyles = function mergeStyles(styles) {
401
373
  return acc;
402
374
  }, {});
403
375
  };
376
+
404
377
  /**
405
378
  * Flattens an array of style objects, into one aggregated style object.
406
379
  *
407
380
  * @param {Array} style objects array
408
381
  * @returns {Object} flatted style object
409
382
  */
410
-
411
-
412
383
  var flatten = compose(mergeStyles, compact, castArray);
413
384
 
414
385
  /**
@@ -427,6 +398,7 @@ var parseValue = function parseValue(value) {
427
398
  unit: undefined
428
399
  };
429
400
  };
401
+
430
402
  /**
431
403
  * Transform given scalar value
432
404
  *
@@ -434,30 +406,22 @@ var parseValue = function parseValue(value) {
434
406
  * @param {String} styles value
435
407
  * @returns {Object} transformed value
436
408
  */
437
-
438
-
439
409
  var transformUnit = function transformUnit(container, value) {
440
410
  var scalar = parseValue(value);
441
411
  var dpi = container.dpi || 72;
442
412
  var mmFactor = 1 / 25.4 * dpi;
443
413
  var cmFactor = 1 / 2.54 * dpi;
444
-
445
414
  switch (scalar.unit) {
446
415
  case 'in':
447
416
  return scalar.value * dpi;
448
-
449
417
  case 'mm':
450
418
  return scalar.value * mmFactor;
451
-
452
419
  case 'cm':
453
420
  return scalar.value * cmFactor;
454
-
455
421
  case 'vh':
456
422
  return scalar.value * (container.height / 100);
457
-
458
423
  case 'vw':
459
424
  return scalar.value * (container.width / 100);
460
-
461
425
  default:
462
426
  return scalar.value;
463
427
  }
@@ -466,43 +430,39 @@ var transformUnit = function transformUnit(container, value) {
466
430
  var isRgb = function isRgb(value) {
467
431
  return /rgba?/g.test(value);
468
432
  };
469
-
470
433
  var isHsl = function isHsl(value) {
471
434
  return /hsla?/g.test(value);
472
435
  };
436
+
473
437
  /**
474
438
  * Transform rgb color to hexa
475
439
  *
476
440
  * @param {String} styles value
477
441
  * @returns {Object} transformed value
478
442
  */
479
-
480
-
481
443
  var parseRgb = function parseRgb(value) {
482
444
  var rgb = colorString.get.rgb(value);
483
445
  return colorString.to.hex(rgb);
484
446
  };
447
+
485
448
  /**
486
449
  * Transform Hsl color to hexa
487
450
  *
488
451
  * @param {String} styles value
489
452
  * @returns {Object} transformed value
490
453
  */
491
-
492
-
493
454
  var parseHsl = function parseHsl(value) {
494
455
  var hsl = colorString.get.hsl(value).map(Math.round);
495
456
  var hex = hlsToHex.apply(void 0, hsl);
496
457
  return hex.toUpperCase();
497
458
  };
459
+
498
460
  /**
499
461
  * Transform given color to hexa
500
462
  *
501
463
  * @param {String} styles value
502
464
  * @returns {Object} transformed value
503
465
  */
504
-
505
-
506
466
  var transformColor = function transformColor(value) {
507
467
  if (isRgb(value)) return parseRgb(value);
508
468
  if (isHsl(value)) return parseHsl(value);
@@ -510,22 +470,19 @@ var transformColor = function transformColor(value) {
510
470
  };
511
471
 
512
472
  var parse = function parse(transformString) {
513
- var transforms = transformString.trim().split(/\) |\)/); // Handle "initial", "inherit", "unset".
473
+ var transforms = transformString.trim().split(/\) |\)/);
514
474
 
475
+ // Handle "initial", "inherit", "unset".
515
476
  if (transforms.length === 1) {
516
477
  return [[transforms[0], true]];
517
478
  }
518
-
519
479
  var parsed = [];
520
-
521
480
  for (var i = 0; i < transforms.length; i += 1) {
522
481
  var transform = transforms[i];
523
-
524
482
  if (transform) {
525
483
  var _transform$split = transform.split('('),
526
- name = _transform$split[0],
527
- rawValue = _transform$split[1];
528
-
484
+ name = _transform$split[0],
485
+ rawValue = _transform$split[1];
529
486
  var splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
530
487
  var value = rawValue.split(splitChar).map(function (val) {
531
488
  return val.trim();
@@ -536,41 +493,33 @@ var parse = function parse(transformString) {
536
493
  });
537
494
  }
538
495
  }
539
-
540
496
  return parsed;
541
497
  };
542
-
543
498
  var parseAngle = function parseAngle(value) {
544
499
  var unitsRegexp = /(-?\d*\.?\d*)(\w*)?/i;
545
-
546
500
  var _unitsRegexp$exec = unitsRegexp.exec(value),
547
- angle = _unitsRegexp$exec[1],
548
- unit = _unitsRegexp$exec[2];
549
-
501
+ angle = _unitsRegexp$exec[1],
502
+ unit = _unitsRegexp$exec[2];
550
503
  var number = Number.parseFloat(angle);
551
504
  return unit === 'rad' ? number * 180 / Math.PI : number;
552
505
  };
553
-
554
506
  var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
555
507
  var operation = _ref.operation,
556
- value = _ref.value;
557
-
508
+ value = _ref.value;
558
509
  switch (operation) {
559
510
  case 'scale':
560
511
  {
561
512
  var _value$map = value.map(function (num) {
562
- return Number.parseFloat(num);
563
- }),
564
- scaleX = _value$map[0],
565
- _value$map$ = _value$map[1],
566
- scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
567
-
513
+ return Number.parseFloat(num);
514
+ }),
515
+ scaleX = _value$map[0],
516
+ _value$map$ = _value$map[1],
517
+ scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
568
518
  return {
569
519
  operation: 'scale',
570
520
  value: [scaleX, scaleY]
571
521
  };
572
522
  }
573
-
574
523
  case 'scaleX':
575
524
  {
576
525
  return {
@@ -578,7 +527,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
578
527
  value: [Number.parseFloat(value), 1]
579
528
  };
580
529
  }
581
-
582
530
  case 'scaleY':
583
531
  {
584
532
  return {
@@ -586,7 +534,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
586
534
  value: [1, Number.parseFloat(value)]
587
535
  };
588
536
  }
589
-
590
537
  case 'rotate':
591
538
  {
592
539
  return {
@@ -594,7 +541,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
594
541
  value: [parseAngle(value)]
595
542
  };
596
543
  }
597
-
598
544
  case 'translate':
599
545
  {
600
546
  return {
@@ -604,7 +550,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
604
550
  })
605
551
  };
606
552
  }
607
-
608
553
  case 'translateX':
609
554
  {
610
555
  return {
@@ -612,7 +557,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
612
557
  value: [Number.parseFloat(value), 0]
613
558
  };
614
559
  }
615
-
616
560
  case 'translateY':
617
561
  {
618
562
  return {
@@ -620,7 +564,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
620
564
  value: [0, Number.parseFloat(value)]
621
565
  };
622
566
  }
623
-
624
567
  case 'skew':
625
568
  {
626
569
  return {
@@ -628,7 +571,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
628
571
  value: value.map(parseAngle)
629
572
  };
630
573
  }
631
-
632
574
  case 'skewX':
633
575
  {
634
576
  return {
@@ -636,7 +578,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
636
578
  value: [parseAngle(value), 0]
637
579
  };
638
580
  }
639
-
640
581
  case 'skewY':
641
582
  {
642
583
  return {
@@ -644,7 +585,6 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
644
585
  value: [0, parseAngle(value)]
645
586
  };
646
587
  }
647
-
648
588
  default:
649
589
  {
650
590
  return {
@@ -656,13 +596,11 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
656
596
  }
657
597
  }
658
598
  };
659
-
660
599
  var normalize = function normalize(operations) {
661
600
  return operations.map(function (operation) {
662
601
  return normalizeTransformOperation(operation);
663
602
  });
664
603
  };
665
-
666
604
  var processTransform = function processTransform(value) {
667
605
  if (typeof value !== 'string') return value;
668
606
  return normalize(parse(value));
@@ -684,7 +622,6 @@ var FONT_WEIGHTS = {
684
622
  heavy: 900,
685
623
  black: 900
686
624
  };
687
-
688
625
  var processFontWeight = function processFontWeight(value) {
689
626
  if (!value) return FONT_WEIGHTS.normal;
690
627
  if (typeof value === 'number') return value;
@@ -696,7 +633,6 @@ var processFontWeight = function processFontWeight(value) {
696
633
  var matchNumber = function matchNumber(value) {
697
634
  return typeof value === 'string' && /^-?\d*\.?\d*$/.test(value);
698
635
  };
699
-
700
636
  var castFloat = function castFloat(value) {
701
637
  if (typeof value !== 'string') return value;
702
638
  if (matchNumber(value)) return parseFloat(value, 10);
@@ -708,14 +644,11 @@ var offsetKeyword = function offsetKeyword(value) {
708
644
  case 'top':
709
645
  case 'left':
710
646
  return '0%';
711
-
712
647
  case 'right':
713
648
  case 'bottom':
714
649
  return '100%';
715
-
716
650
  case 'center':
717
651
  return '50%';
718
-
719
652
  default:
720
653
  return null;
721
654
  }
@@ -737,32 +670,28 @@ var handlers = {
737
670
  transformOriginX: transformTransformOrigin,
738
671
  transformOriginY: transformTransformOrigin
739
672
  };
740
-
741
673
  var transformStyle = function transformStyle(key, value, container) {
742
674
  var result = handlers[key] ? handlers[key](value) : value;
743
675
  return transformColor(transformUnit(container, castFloat(result)));
744
676
  };
677
+
745
678
  /**
746
679
  * Transform styles values
747
680
  *
748
681
  * @param {Object} styles object
749
682
  * @returns {Object} transformed styles
750
683
  */
751
-
752
-
753
684
  var transform = function transform(container) {
754
685
  return function (style) {
755
686
  if (!style) return style;
756
687
  var propsArray = Object.keys(style);
757
688
  var resolvedStyle = {};
758
-
759
689
  for (var i = 0; i < propsArray.length; i += 1) {
760
690
  var key = propsArray[i];
761
691
  var value = style[key];
762
692
  var transformed = transformStyle(key, value, container);
763
693
  resolvedStyle[key] = transformed;
764
694
  }
765
-
766
695
  return resolvedStyle;
767
696
  };
768
697
  };
@@ -773,17 +702,13 @@ var transform = function transform(container) {
773
702
  * @param {Object} container
774
703
  * @param {Object} styles object
775
704
  */
776
-
777
705
  var resolveMediaQueries = function resolveMediaQueries(container, styles) {
778
706
  return Object.keys(styles).reduce(function (acc, key) {
779
707
  var _extends2;
780
-
781
708
  if (/@media/.test(key)) {
782
709
  var _matchMedia;
783
-
784
710
  return _extends({}, acc, matchMedia((_matchMedia = {}, _matchMedia[key] = styles[key], _matchMedia), container));
785
711
  }
786
-
787
712
  return _extends({}, acc, (_extends2 = {}, _extends2[key] = styles[key], _extends2));
788
713
  }, {});
789
714
  };
@@ -795,13 +720,11 @@ var resolveMediaQueries = function resolveMediaQueries(container, styles) {
795
720
  * @param {Object} style object
796
721
  * @returns {Object} resolved style object
797
722
  */
798
-
799
723
  var resolveStyles = function resolveStyles(container, style) {
800
724
  var computeMediaQueries = function computeMediaQueries(value) {
801
725
  return resolveMediaQueries(container, value);
802
726
  };
803
-
804
727
  return compose(transform(container), expand, computeMediaQueries, flatten)(style);
805
- }; // Utils exported for SVG processing
728
+ };
806
729
 
807
730
  export { resolveStyles as default, flatten, processTransform, transformColor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf/stylesheet",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "license": "MIT",
5
5
  "description": "A styles engine for Node and the browser",
6
6
  "author": "Diego Muracciole <diegomuracciole@gmail.com>",
@@ -18,7 +18,7 @@
18
18
  "watch": "rimraf ./lib && rollup -c -w"
19
19
  },
20
20
  "dependencies": {
21
- "@babel/runtime": "^7.16.4",
21
+ "@babel/runtime": "^7.20.13",
22
22
  "@react-pdf/fns": "2.0.0",
23
23
  "@react-pdf/types": "^2.2.0",
24
24
  "color-string": "^1.5.3",