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