@react-pdf/stylesheet 4.2.5 → 4.3.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/lib/index.cjs +205 -220
- package/lib/index.js +205 -219
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -7,7 +7,6 @@ var parse$1 = require('postcss-value-parser/lib/parse.js');
|
|
|
7
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
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
11
10
|
var matchMedia = require('media-engine');
|
|
12
11
|
|
|
13
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -16,43 +15,42 @@ var parse__default = /*#__PURE__*/_interopDefaultCompat(parse$1);
|
|
|
16
15
|
var parseUnit__default = /*#__PURE__*/_interopDefaultCompat(parseUnit);
|
|
17
16
|
var hlsToHex__default = /*#__PURE__*/_interopDefaultCompat(hlsToHex);
|
|
18
17
|
var colorString__default = /*#__PURE__*/_interopDefaultCompat(colorString);
|
|
19
|
-
var _extends__default = /*#__PURE__*/_interopDefaultCompat(_extends);
|
|
20
18
|
var matchMedia__default = /*#__PURE__*/_interopDefaultCompat(matchMedia);
|
|
21
19
|
|
|
22
20
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/flex#values
|
|
23
21
|
|
|
24
22
|
// TODO: change flex defaults to [0, 1, 'auto'] as in spec in next major release
|
|
25
|
-
|
|
23
|
+
const flexDefaults = [1, 1, 0];
|
|
26
24
|
/**
|
|
27
25
|
* @type {(number | 'auto')[]}
|
|
28
26
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const flexAuto = [1, 1, 'auto'];
|
|
28
|
+
const expandFlex = (key, value) => {
|
|
31
29
|
/**
|
|
32
30
|
* @type {(number | 'auto')[]}
|
|
33
31
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
let defaults = flexDefaults;
|
|
33
|
+
let matches = [];
|
|
36
34
|
if (value === 'auto') {
|
|
37
35
|
defaults = flexAuto;
|
|
38
36
|
} else {
|
|
39
37
|
matches = ("" + value).split(' ');
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const flexGrow = matches[0] || defaults[0];
|
|
40
|
+
const flexShrink = matches[1] || defaults[1];
|
|
41
|
+
const flexBasis = matches[2] || defaults[2];
|
|
44
42
|
return {
|
|
45
|
-
flexGrow
|
|
46
|
-
flexShrink
|
|
47
|
-
flexBasis
|
|
43
|
+
flexGrow,
|
|
44
|
+
flexShrink,
|
|
45
|
+
flexBasis
|
|
48
46
|
};
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
/* eslint-disable no-plusplus */
|
|
52
50
|
// This file is ran directly with Node - needs to have .js extension
|
|
53
51
|
// eslint-disable-next-line import/extensions
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const BOX_MODEL_UNITS = 'px,in,mm,cm,pt,%,vw,vh';
|
|
53
|
+
const logError = (style, value) => {
|
|
56
54
|
console.error("\n @react-pdf/stylesheet parsing error:\n\n " + style + ": " + value + ",\n " + ' '.repeat(style.length + 2) + "^\n Unsupported " + style + " value format\n ");
|
|
57
55
|
};
|
|
58
56
|
|
|
@@ -62,19 +60,17 @@ var logError = function logError(style, value) {
|
|
|
62
60
|
* @param {number} [options.maxValues]
|
|
63
61
|
* @param {boolean} [options.autoSupported]
|
|
64
62
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expandsTo
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (var i = 0; i < nodes.length; i++) {
|
|
77
|
-
var node = nodes[i];
|
|
63
|
+
const expandBoxModel = function (_temp) {
|
|
64
|
+
let {
|
|
65
|
+
expandsTo,
|
|
66
|
+
maxValues = 1,
|
|
67
|
+
autoSupported = false
|
|
68
|
+
} = _temp === void 0 ? {} : _temp;
|
|
69
|
+
return (model, value) => {
|
|
70
|
+
const nodes = parse__default.default("" + value);
|
|
71
|
+
const parts = [];
|
|
72
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
73
|
+
const node = nodes[i];
|
|
78
74
|
|
|
79
75
|
// value contains `calc`, `url` or other css function
|
|
80
76
|
// `,`, `/` or strings that unsupported by margin and padding
|
|
@@ -86,7 +82,7 @@ var expandBoxModel = function expandBoxModel(_temp) {
|
|
|
86
82
|
if (node.value === 'auto' && autoSupported) {
|
|
87
83
|
parts.push(node.value);
|
|
88
84
|
} else {
|
|
89
|
-
|
|
85
|
+
const result = parseUnit__default.default(node.value);
|
|
90
86
|
|
|
91
87
|
// when unit isn't specified this condition is true
|
|
92
88
|
if (result && BOX_MODEL_UNITS.includes(result.unit)) {
|
|
@@ -104,28 +100,32 @@ var expandBoxModel = function expandBoxModel(_temp) {
|
|
|
104
100
|
logError(model, value);
|
|
105
101
|
return {};
|
|
106
102
|
}
|
|
107
|
-
|
|
103
|
+
const first = parts[0];
|
|
108
104
|
if (expandsTo) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
const second = parts[1] || parts[0];
|
|
106
|
+
const third = parts[2] || parts[0];
|
|
107
|
+
const fourth = parts[3] || parts[1] || parts[0];
|
|
112
108
|
return expandsTo({
|
|
113
|
-
first
|
|
114
|
-
second
|
|
115
|
-
third
|
|
116
|
-
fourth
|
|
109
|
+
first,
|
|
110
|
+
second,
|
|
111
|
+
third,
|
|
112
|
+
fourth
|
|
117
113
|
});
|
|
118
114
|
}
|
|
119
|
-
return
|
|
115
|
+
return {
|
|
116
|
+
[model]: first
|
|
117
|
+
};
|
|
120
118
|
};
|
|
121
119
|
};
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
expandsTo:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
const processMargin = expandBoxModel({
|
|
122
|
+
expandsTo: _ref => {
|
|
123
|
+
let {
|
|
124
|
+
first,
|
|
125
|
+
second,
|
|
126
|
+
third,
|
|
127
|
+
fourth
|
|
128
|
+
} = _ref;
|
|
129
129
|
return {
|
|
130
130
|
marginTop: first,
|
|
131
131
|
marginRight: second,
|
|
@@ -136,10 +136,12 @@ var processMargin = expandBoxModel({
|
|
|
136
136
|
maxValues: 4,
|
|
137
137
|
autoSupported: true
|
|
138
138
|
});
|
|
139
|
-
|
|
140
|
-
expandsTo:
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
const processMarginVertical = expandBoxModel({
|
|
140
|
+
expandsTo: _ref2 => {
|
|
141
|
+
let {
|
|
142
|
+
first,
|
|
143
|
+
second
|
|
144
|
+
} = _ref2;
|
|
143
145
|
return {
|
|
144
146
|
marginTop: first,
|
|
145
147
|
marginBottom: second
|
|
@@ -148,10 +150,12 @@ var processMarginVertical = expandBoxModel({
|
|
|
148
150
|
maxValues: 2,
|
|
149
151
|
autoSupported: true
|
|
150
152
|
});
|
|
151
|
-
|
|
152
|
-
expandsTo:
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const processMarginHorizontal = expandBoxModel({
|
|
154
|
+
expandsTo: _ref3 => {
|
|
155
|
+
let {
|
|
156
|
+
first,
|
|
157
|
+
second
|
|
158
|
+
} = _ref3;
|
|
155
159
|
return {
|
|
156
160
|
marginRight: first,
|
|
157
161
|
marginLeft: second
|
|
@@ -160,23 +164,24 @@ var processMarginHorizontal = expandBoxModel({
|
|
|
160
164
|
maxValues: 2,
|
|
161
165
|
autoSupported: true
|
|
162
166
|
});
|
|
163
|
-
|
|
167
|
+
const processMarginSingle = expandBoxModel({
|
|
164
168
|
autoSupported: true
|
|
165
169
|
});
|
|
166
170
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var expandBorders = function expandBorders(key, value) {
|
|
172
|
-
var match = matchBorderShorthand("" + value);
|
|
171
|
+
const BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
|
|
172
|
+
const matchBorderShorthand = value => value.match(BORDER_SHORTHAND_REGEX) || [];
|
|
173
|
+
const expandBorders = (key, value) => {
|
|
174
|
+
const match = matchBorderShorthand("" + value);
|
|
173
175
|
if (match) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
const color = match[5] || value;
|
|
177
|
+
const style = match[4] || value;
|
|
178
|
+
const width = match[1] || value;
|
|
177
179
|
if (key.match(/(Top|Right|Bottom|Left)$/)) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
return {
|
|
181
|
+
[key + "Color"]: color,
|
|
182
|
+
[key + "Style"]: style,
|
|
183
|
+
[key + "Width"]: width
|
|
184
|
+
};
|
|
180
185
|
}
|
|
181
186
|
if (key.match(/Color$/)) {
|
|
182
187
|
return {
|
|
@@ -228,12 +233,14 @@ var expandBorders = function expandBorders(key, value) {
|
|
|
228
233
|
return value;
|
|
229
234
|
};
|
|
230
235
|
|
|
231
|
-
|
|
232
|
-
expandsTo:
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
const processPadding = expandBoxModel({
|
|
237
|
+
expandsTo: _ref => {
|
|
238
|
+
let {
|
|
239
|
+
first,
|
|
240
|
+
second,
|
|
241
|
+
third,
|
|
242
|
+
fourth
|
|
243
|
+
} = _ref;
|
|
237
244
|
return {
|
|
238
245
|
paddingTop: first,
|
|
239
246
|
paddingRight: second,
|
|
@@ -243,10 +250,12 @@ var processPadding = expandBoxModel({
|
|
|
243
250
|
},
|
|
244
251
|
maxValues: 4
|
|
245
252
|
});
|
|
246
|
-
|
|
247
|
-
expandsTo:
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
const processPaddingVertical = expandBoxModel({
|
|
254
|
+
expandsTo: _ref2 => {
|
|
255
|
+
let {
|
|
256
|
+
first,
|
|
257
|
+
second
|
|
258
|
+
} = _ref2;
|
|
250
259
|
return {
|
|
251
260
|
paddingTop: first,
|
|
252
261
|
paddingBottom: second
|
|
@@ -254,10 +263,12 @@ var processPaddingVertical = expandBoxModel({
|
|
|
254
263
|
},
|
|
255
264
|
maxValues: 2
|
|
256
265
|
});
|
|
257
|
-
|
|
258
|
-
expandsTo:
|
|
259
|
-
|
|
260
|
-
|
|
266
|
+
const processPaddingHorizontal = expandBoxModel({
|
|
267
|
+
expandsTo: _ref3 => {
|
|
268
|
+
let {
|
|
269
|
+
first,
|
|
270
|
+
second
|
|
271
|
+
} = _ref3;
|
|
261
272
|
return {
|
|
262
273
|
paddingRight: first,
|
|
263
274
|
paddingLeft: second
|
|
@@ -265,50 +276,50 @@ var processPaddingHorizontal = expandBoxModel({
|
|
|
265
276
|
},
|
|
266
277
|
maxValues: 2
|
|
267
278
|
});
|
|
268
|
-
|
|
279
|
+
const processPaddingSingle = expandBoxModel();
|
|
269
280
|
|
|
270
|
-
|
|
271
|
-
|
|
281
|
+
const expandObjectPosition = (key, value) => {
|
|
282
|
+
const match = ("" + value).split(' ');
|
|
272
283
|
return {
|
|
273
284
|
objectPositionX: (match === null || match === void 0 ? void 0 : match[0]) || value,
|
|
274
285
|
objectPositionY: (match === null || match === void 0 ? void 0 : match[1]) || value
|
|
275
286
|
};
|
|
276
287
|
};
|
|
277
288
|
|
|
278
|
-
|
|
289
|
+
const Y_AXIS_SHORTHANDS = {
|
|
279
290
|
top: true,
|
|
280
291
|
bottom: true
|
|
281
292
|
};
|
|
282
|
-
|
|
293
|
+
const sortTransformOriginPair = (a, b) => {
|
|
283
294
|
if (Y_AXIS_SHORTHANDS[a]) return 1;
|
|
284
295
|
if (Y_AXIS_SHORTHANDS[b]) return -1;
|
|
285
296
|
return 0;
|
|
286
297
|
};
|
|
287
|
-
|
|
298
|
+
const getTransformOriginPair = values => {
|
|
288
299
|
if (!values || values.length === 0) return ['center', 'center'];
|
|
289
|
-
|
|
300
|
+
const pair = values.length === 1 ? [values[0], 'center'] : values;
|
|
290
301
|
return pair.sort(sortTransformOriginPair);
|
|
291
302
|
};
|
|
292
303
|
|
|
293
304
|
// Transforms shorthand transformOrigin values
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
305
|
+
const expandTransformOrigin = (key, value) => {
|
|
306
|
+
const match = ("" + value).split(' ');
|
|
307
|
+
const pair = getTransformOriginPair(match);
|
|
297
308
|
return {
|
|
298
309
|
transformOriginX: pair[0],
|
|
299
310
|
transformOriginY: pair[1]
|
|
300
311
|
};
|
|
301
312
|
};
|
|
302
313
|
|
|
303
|
-
|
|
304
|
-
|
|
314
|
+
const expandGap = (key, value) => {
|
|
315
|
+
const match = ("" + value).split(' ');
|
|
305
316
|
return {
|
|
306
317
|
rowGap: (match === null || match === void 0 ? void 0 : match[0]) || value,
|
|
307
318
|
columnGap: (match === null || match === void 0 ? void 0 : match[1]) || value
|
|
308
319
|
};
|
|
309
320
|
};
|
|
310
321
|
|
|
311
|
-
|
|
322
|
+
const shorthands = {
|
|
312
323
|
flex: expandFlex,
|
|
313
324
|
gap: expandGap,
|
|
314
325
|
margin: processMargin,
|
|
@@ -345,9 +356,10 @@ var shorthands = {
|
|
|
345
356
|
* @param {string} value style value
|
|
346
357
|
* @returns {string | Number} transformed style values
|
|
347
358
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
359
|
+
const expandStyle = (key, value) => {
|
|
360
|
+
return shorthands[key] ? shorthands[key](key, value) : {
|
|
361
|
+
[key]: value
|
|
362
|
+
};
|
|
351
363
|
};
|
|
352
364
|
|
|
353
365
|
/**
|
|
@@ -356,18 +368,18 @@ var expandStyle = function expandStyle(key, value) {
|
|
|
356
368
|
* @param {Object} style object
|
|
357
369
|
* @returns {Object} expanded style object
|
|
358
370
|
*/
|
|
359
|
-
|
|
371
|
+
const expand = style => {
|
|
360
372
|
if (!style) return style;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
for (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
for (
|
|
369
|
-
|
|
370
|
-
|
|
373
|
+
const propsArray = Object.keys(style);
|
|
374
|
+
const resolvedStyle = {};
|
|
375
|
+
for (let i = 0; i < propsArray.length; i += 1) {
|
|
376
|
+
const key = propsArray[i];
|
|
377
|
+
const value = style[key];
|
|
378
|
+
const extended = expandStyle(key, value);
|
|
379
|
+
const keys = Object.keys(extended);
|
|
380
|
+
for (let j = 0; j < keys.length; j += 1) {
|
|
381
|
+
const propName = keys[j];
|
|
382
|
+
const propValue = extended[propName];
|
|
371
383
|
resolvedStyle[propName] = propValue;
|
|
372
384
|
}
|
|
373
385
|
}
|
|
@@ -381,9 +393,7 @@ var expand = function expand(style) {
|
|
|
381
393
|
* @param {(T | null | undefined)[]} array
|
|
382
394
|
* @returns {T[]} array without nils
|
|
383
395
|
*/
|
|
384
|
-
|
|
385
|
-
return array.filter(Boolean);
|
|
386
|
-
};
|
|
396
|
+
const compact = array => array.filter(Boolean);
|
|
387
397
|
|
|
388
398
|
/**
|
|
389
399
|
* Merges style objects array
|
|
@@ -391,17 +401,15 @@ var compact = function compact(array) {
|
|
|
391
401
|
* @param {Object[]} styles style objects array
|
|
392
402
|
* @returns {Object} merged style object
|
|
393
403
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}, {});
|
|
404
|
-
};
|
|
404
|
+
const mergeStyles = styles => styles.reduce((acc, style) => {
|
|
405
|
+
const s = Array.isArray(style) ? flatten(style) : style;
|
|
406
|
+
Object.keys(s).forEach(key => {
|
|
407
|
+
if (s[key] !== null && s[key] !== undefined) {
|
|
408
|
+
acc[key] = s[key];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return acc;
|
|
412
|
+
}, {});
|
|
405
413
|
|
|
406
414
|
/**
|
|
407
415
|
* Flattens an array of style objects, into one aggregated style object.
|
|
@@ -409,7 +417,7 @@ var mergeStyles = function mergeStyles(styles) {
|
|
|
409
417
|
* @param {Object[]} styles style objects array
|
|
410
418
|
* @returns {Object} flattened style object
|
|
411
419
|
*/
|
|
412
|
-
|
|
420
|
+
const flatten = fns.compose(mergeStyles, compact, fns.castArray);
|
|
413
421
|
|
|
414
422
|
/**
|
|
415
423
|
* Parses scalar value in value and unit pairs
|
|
@@ -417,13 +425,13 @@ var flatten = fns.compose(mergeStyles, compact, fns.castArray);
|
|
|
417
425
|
* @param {string} value scalar value
|
|
418
426
|
* @returns {Object} parsed value
|
|
419
427
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
428
|
+
const parseValue = value => {
|
|
429
|
+
const match = /^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw|px)?$/g.exec(value);
|
|
422
430
|
return match ? {
|
|
423
431
|
value: parseFloat(match[1]),
|
|
424
432
|
unit: match[2] || 'pt'
|
|
425
433
|
} : {
|
|
426
|
-
value
|
|
434
|
+
value,
|
|
427
435
|
unit: undefined
|
|
428
436
|
};
|
|
429
437
|
};
|
|
@@ -435,11 +443,11 @@ var parseValue = function parseValue(value) {
|
|
|
435
443
|
* @param {string} value styles value
|
|
436
444
|
* @returns {Object} transformed value
|
|
437
445
|
*/
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
446
|
+
const transformUnit = (container, value) => {
|
|
447
|
+
const scalar = parseValue(value);
|
|
448
|
+
const dpi = 72; // Removed: container.dpi || 72
|
|
449
|
+
const mmFactor = 1 / 25.4 * dpi;
|
|
450
|
+
const cmFactor = 1 / 2.54 * dpi;
|
|
443
451
|
switch (scalar.unit) {
|
|
444
452
|
case 'in':
|
|
445
453
|
return scalar.value * dpi;
|
|
@@ -456,12 +464,8 @@ var transformUnit = function transformUnit(container, value) {
|
|
|
456
464
|
}
|
|
457
465
|
};
|
|
458
466
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
};
|
|
462
|
-
var isHsl = function isHsl(value) {
|
|
463
|
-
return /hsla?/g.test(value);
|
|
464
|
-
};
|
|
467
|
+
const isRgb = value => /rgba?/g.test(value);
|
|
468
|
+
const isHsl = value => /hsla?/g.test(value);
|
|
465
469
|
|
|
466
470
|
/**
|
|
467
471
|
* Transform rgb color to hexa
|
|
@@ -469,8 +473,8 @@ var isHsl = function isHsl(value) {
|
|
|
469
473
|
* @param {string} value styles value
|
|
470
474
|
* @returns {Object} transformed value
|
|
471
475
|
*/
|
|
472
|
-
|
|
473
|
-
|
|
476
|
+
const parseRgb = value => {
|
|
477
|
+
const rgb = colorString__default.default.get.rgb(value);
|
|
474
478
|
return colorString__default.default.to.hex(rgb);
|
|
475
479
|
};
|
|
476
480
|
|
|
@@ -480,9 +484,9 @@ var parseRgb = function parseRgb(value) {
|
|
|
480
484
|
* @param {string} value styles value
|
|
481
485
|
* @returns {Object} transformed value
|
|
482
486
|
*/
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
487
|
+
const parseHsl = value => {
|
|
488
|
+
const hsl = colorString__default.default.get.hsl(value).map(Math.round);
|
|
489
|
+
const hex = hlsToHex__default.default(...hsl);
|
|
486
490
|
return hex.toUpperCase();
|
|
487
491
|
};
|
|
488
492
|
|
|
@@ -492,58 +496,49 @@ var parseHsl = function parseHsl(value) {
|
|
|
492
496
|
* @param {string} value styles value
|
|
493
497
|
* @returns {Object} transformed value
|
|
494
498
|
*/
|
|
495
|
-
|
|
499
|
+
const transformColor = value => {
|
|
496
500
|
if (isRgb(value)) return parseRgb(value);
|
|
497
501
|
if (isHsl(value)) return parseHsl(value);
|
|
498
502
|
return value;
|
|
499
503
|
};
|
|
500
504
|
|
|
501
|
-
|
|
502
|
-
|
|
505
|
+
const parse = transformString => {
|
|
506
|
+
const transforms = transformString.trim().split(/\) |\)/);
|
|
503
507
|
|
|
504
508
|
// Handle "initial", "inherit", "unset".
|
|
505
509
|
if (transforms.length === 1) {
|
|
506
510
|
return [[transforms[0], true]];
|
|
507
511
|
}
|
|
508
|
-
|
|
509
|
-
for (
|
|
510
|
-
|
|
512
|
+
const parsed = [];
|
|
513
|
+
for (let i = 0; i < transforms.length; i += 1) {
|
|
514
|
+
const transform = transforms[i];
|
|
511
515
|
if (transform) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
var splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
|
|
516
|
-
var value = rawValue.split(splitChar).map(function (val) {
|
|
517
|
-
return val.trim();
|
|
518
|
-
});
|
|
516
|
+
const [name, rawValue] = transform.split('(');
|
|
517
|
+
const splitChar = rawValue.indexOf(',') >= 0 ? ',' : ' ';
|
|
518
|
+
const value = rawValue.split(splitChar).map(val => val.trim());
|
|
519
519
|
parsed.push({
|
|
520
520
|
operation: name,
|
|
521
|
-
value
|
|
521
|
+
value
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
return parsed;
|
|
526
526
|
};
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
unit = _unitsRegexp$exec[2];
|
|
532
|
-
var number = Number.parseFloat(angle);
|
|
527
|
+
const parseAngle = value => {
|
|
528
|
+
const unitsRegexp = /(-?\d*\.?\d*)(\w*)?/i;
|
|
529
|
+
const [, angle, unit] = unitsRegexp.exec(value);
|
|
530
|
+
const number = Number.parseFloat(angle);
|
|
533
531
|
return unit === 'rad' ? number * 180 / Math.PI : number;
|
|
534
532
|
};
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
533
|
+
const normalizeTransformOperation = _ref => {
|
|
534
|
+
let {
|
|
535
|
+
operation,
|
|
536
|
+
value
|
|
537
|
+
} = _ref;
|
|
538
538
|
switch (operation) {
|
|
539
539
|
case 'scale':
|
|
540
540
|
{
|
|
541
|
-
|
|
542
|
-
return Number.parseFloat(num);
|
|
543
|
-
}),
|
|
544
|
-
scaleX = _value$map[0],
|
|
545
|
-
_value$map$ = _value$map[1],
|
|
546
|
-
scaleY = _value$map$ === void 0 ? scaleX : _value$map$;
|
|
541
|
+
const [scaleX, scaleY = scaleX] = value.map(num => Number.parseFloat(num));
|
|
547
542
|
return {
|
|
548
543
|
operation: 'scale',
|
|
549
544
|
value: [scaleX, scaleY]
|
|
@@ -574,9 +569,7 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
|
|
|
574
569
|
{
|
|
575
570
|
return {
|
|
576
571
|
operation: 'translate',
|
|
577
|
-
value: value.map(
|
|
578
|
-
return Number.parseFloat(num);
|
|
579
|
-
})
|
|
572
|
+
value: value.map(num => Number.parseFloat(num))
|
|
580
573
|
};
|
|
581
574
|
}
|
|
582
575
|
case 'translateX':
|
|
@@ -617,25 +610,21 @@ var normalizeTransformOperation = function normalizeTransformOperation(_ref) {
|
|
|
617
610
|
default:
|
|
618
611
|
{
|
|
619
612
|
return {
|
|
620
|
-
operation
|
|
621
|
-
value: value.map(
|
|
622
|
-
return Number.parseFloat(num);
|
|
623
|
-
})
|
|
613
|
+
operation,
|
|
614
|
+
value: value.map(num => Number.parseFloat(num))
|
|
624
615
|
};
|
|
625
616
|
}
|
|
626
617
|
}
|
|
627
618
|
};
|
|
628
|
-
|
|
629
|
-
return operations.map(
|
|
630
|
-
return normalizeTransformOperation(operation);
|
|
631
|
-
});
|
|
619
|
+
const normalize = operations => {
|
|
620
|
+
return operations.map(operation => normalizeTransformOperation(operation));
|
|
632
621
|
};
|
|
633
|
-
|
|
622
|
+
const processTransform = value => {
|
|
634
623
|
if (typeof value !== 'string') return value;
|
|
635
624
|
return normalize(parse(value));
|
|
636
625
|
};
|
|
637
626
|
|
|
638
|
-
|
|
627
|
+
const FONT_WEIGHTS = {
|
|
639
628
|
thin: 100,
|
|
640
629
|
hairline: 100,
|
|
641
630
|
ultralight: 200,
|
|
@@ -651,24 +640,22 @@ var FONT_WEIGHTS = {
|
|
|
651
640
|
heavy: 900,
|
|
652
641
|
black: 900
|
|
653
642
|
};
|
|
654
|
-
|
|
643
|
+
const processFontWeight = value => {
|
|
655
644
|
if (!value) return FONT_WEIGHTS.normal;
|
|
656
645
|
if (typeof value === 'number') return value;
|
|
657
|
-
|
|
646
|
+
const lv = value.toLowerCase();
|
|
658
647
|
if (FONT_WEIGHTS[lv]) return FONT_WEIGHTS[lv];
|
|
659
648
|
return value;
|
|
660
649
|
};
|
|
661
650
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
};
|
|
665
|
-
var castFloat = function castFloat(value) {
|
|
651
|
+
const matchNumber = value => typeof value === 'string' && /^-?\d*\.?\d*$/.test(value);
|
|
652
|
+
const castFloat = value => {
|
|
666
653
|
if (typeof value !== 'string') return value;
|
|
667
654
|
if (matchNumber(value)) return parseFloat(value);
|
|
668
655
|
return value;
|
|
669
656
|
};
|
|
670
657
|
|
|
671
|
-
|
|
658
|
+
const offsetKeyword = value => {
|
|
672
659
|
switch (value) {
|
|
673
660
|
case 'top':
|
|
674
661
|
case 'left':
|
|
@@ -683,15 +670,11 @@ var offsetKeyword = function offsetKeyword(value) {
|
|
|
683
670
|
}
|
|
684
671
|
};
|
|
685
672
|
|
|
686
|
-
|
|
687
|
-
return offsetKeyword(value) || castFloat(value);
|
|
688
|
-
};
|
|
673
|
+
const transformObjectPosition = value => offsetKeyword(value) || castFloat(value);
|
|
689
674
|
|
|
690
|
-
|
|
691
|
-
return offsetKeyword(value) || castFloat(value);
|
|
692
|
-
};
|
|
675
|
+
const transformTransformOrigin = value => offsetKeyword(value) || castFloat(value);
|
|
693
676
|
|
|
694
|
-
|
|
677
|
+
const handlers = {
|
|
695
678
|
transform: processTransform,
|
|
696
679
|
fontWeight: processFontWeight,
|
|
697
680
|
objectPositionX: transformObjectPosition,
|
|
@@ -699,8 +682,8 @@ var handlers = {
|
|
|
699
682
|
transformOriginX: transformTransformOrigin,
|
|
700
683
|
transformOriginY: transformTransformOrigin
|
|
701
684
|
};
|
|
702
|
-
|
|
703
|
-
|
|
685
|
+
const transformStyle = (key, value, container) => {
|
|
686
|
+
const result = handlers[key] ? handlers[key](value) : value;
|
|
704
687
|
return transformColor(transformUnit(container, castFloat(result)));
|
|
705
688
|
};
|
|
706
689
|
|
|
@@ -716,19 +699,17 @@ var transformStyle = function transformStyle(key, value, container) {
|
|
|
716
699
|
* @param {Object} container
|
|
717
700
|
* @returns {Transform} transform function
|
|
718
701
|
*/
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
return resolvedStyle;
|
|
731
|
-
};
|
|
702
|
+
const transform = container => style => {
|
|
703
|
+
if (!style) return style;
|
|
704
|
+
const propsArray = Object.keys(style);
|
|
705
|
+
const resolvedStyle = {};
|
|
706
|
+
for (let i = 0; i < propsArray.length; i += 1) {
|
|
707
|
+
const key = propsArray[i];
|
|
708
|
+
const value = style[key];
|
|
709
|
+
const transformed = transformStyle(key, value, container);
|
|
710
|
+
resolvedStyle[key] = transformed;
|
|
711
|
+
}
|
|
712
|
+
return resolvedStyle;
|
|
732
713
|
};
|
|
733
714
|
|
|
734
715
|
/**
|
|
@@ -737,14 +718,20 @@ var transform = function transform(container) {
|
|
|
737
718
|
* @param {Object} container
|
|
738
719
|
* @param {Object} styles object
|
|
739
720
|
*/
|
|
740
|
-
|
|
741
|
-
return Object.keys(styles).reduce(
|
|
742
|
-
var _extends2;
|
|
721
|
+
const resolveMediaQueries = (container, styles) => {
|
|
722
|
+
return Object.keys(styles).reduce((acc, key) => {
|
|
743
723
|
if (/@media/.test(key)) {
|
|
744
|
-
|
|
745
|
-
|
|
724
|
+
return {
|
|
725
|
+
...acc,
|
|
726
|
+
...matchMedia__default.default({
|
|
727
|
+
[key]: styles[key]
|
|
728
|
+
}, container)
|
|
729
|
+
};
|
|
746
730
|
}
|
|
747
|
-
return
|
|
731
|
+
return {
|
|
732
|
+
...acc,
|
|
733
|
+
[key]: styles[key]
|
|
734
|
+
};
|
|
748
735
|
}, {});
|
|
749
736
|
};
|
|
750
737
|
|
|
@@ -755,10 +742,8 @@ var resolveMediaQueries = function resolveMediaQueries(container, styles) {
|
|
|
755
742
|
* @param {Object} style object
|
|
756
743
|
* @returns {Object} resolved style object
|
|
757
744
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
return resolveMediaQueries(container, value);
|
|
761
|
-
};
|
|
745
|
+
const resolveStyles = (container, style) => {
|
|
746
|
+
const computeMediaQueries = value => resolveMediaQueries(container, value);
|
|
762
747
|
return fns.compose(transform(container), expand, computeMediaQueries, flatten)(style);
|
|
763
748
|
};
|
|
764
749
|
|