@cssxjs/css-to-react-native 3.2.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +115 -0
  3. package/index.d.ts +17 -0
  4. package/index.js +930 -0
  5. package/package.json +68 -0
  6. package/src/TokenStream.js +74 -0
  7. package/src/__tests__/aspectRatio.js +23 -0
  8. package/src/__tests__/border.js +141 -0
  9. package/src/__tests__/borderColor.js +92 -0
  10. package/src/__tests__/boxModel.js +136 -0
  11. package/src/__tests__/boxShadow.js +167 -0
  12. package/src/__tests__/colors.js +31 -0
  13. package/src/__tests__/flex.js +122 -0
  14. package/src/__tests__/flexFlow.js +22 -0
  15. package/src/__tests__/font.js +117 -0
  16. package/src/__tests__/fontFamily.js +43 -0
  17. package/src/__tests__/fontVariant.js +15 -0
  18. package/src/__tests__/fontWeight.js +8 -0
  19. package/src/__tests__/index.js +238 -0
  20. package/src/__tests__/placeContent.js +19 -0
  21. package/src/__tests__/shadowOffsets.js +13 -0
  22. package/src/__tests__/textDecoration.js +165 -0
  23. package/src/__tests__/textDecorationLine.js +23 -0
  24. package/src/__tests__/textShadow.js +107 -0
  25. package/src/__tests__/transform.js +69 -0
  26. package/src/__tests__/units.js +132 -0
  27. package/src/devPropertiesWithoutUnitsRegExp.js +19 -0
  28. package/src/index.js +90 -0
  29. package/src/tokenTypes.js +112 -0
  30. package/src/transforms/aspectRatio.js +12 -0
  31. package/src/transforms/border.js +57 -0
  32. package/src/transforms/boxShadow.js +11 -0
  33. package/src/transforms/flex.js +65 -0
  34. package/src/transforms/flexFlow.js +37 -0
  35. package/src/transforms/font.js +63 -0
  36. package/src/transforms/fontFamily.js +20 -0
  37. package/src/transforms/fontVariant.js +14 -0
  38. package/src/transforms/index.js +78 -0
  39. package/src/transforms/placeContent.js +24 -0
  40. package/src/transforms/textDecoration.js +56 -0
  41. package/src/transforms/textDecorationLine.js +18 -0
  42. package/src/transforms/textShadow.js +10 -0
  43. package/src/transforms/transform.js +74 -0
  44. package/src/transforms/util.js +103 -0
package/index.js ADDED
@@ -0,0 +1,930 @@
1
+ 'use strict';
2
+
3
+ function _templateObject() {
4
+ var data = _taggedTemplateLiteralLoose([", "]);
5
+
6
+ _templateObject = function _templateObject() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
14
+
15
+ Object.defineProperty(exports, '__esModule', {
16
+ value: true
17
+ });
18
+
19
+ function _interopDefault(ex) {
20
+ return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
21
+ }
22
+
23
+ var parse = require('postcss-value-parser');
24
+
25
+ var parse__default = _interopDefault(parse);
26
+
27
+ var camelizeStyleName = _interopDefault(require('camelize'));
28
+
29
+ var cssColorKeywords = _interopDefault(require('css-color-keywords'));
30
+
31
+ var matchString = function matchString(node) {
32
+ if (node.type !== 'string') return null;
33
+ return node.value.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, function (match, charCode) {
34
+ return String.fromCharCode(parseInt(charCode, 16));
35
+ }).replace(/\\/g, '');
36
+ };
37
+
38
+ var hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i;
39
+ var cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/;
40
+
41
+ var matchColor = function matchColor(node) {
42
+ if (node.type === 'word' && (hexColorRe.test(node.value) || node.value in cssColorKeywords || node.value === 'transparent')) {
43
+ return node.value;
44
+ } else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {
45
+ return parse.stringify(node);
46
+ }
47
+
48
+ return null;
49
+ };
50
+
51
+ var matchVariable = function matchVariable(node) {
52
+ if (node.type !== 'function' && node.value !== 'var' || node.nodes.length === 0) return null;
53
+ var variableName = node.nodes[0].value;
54
+
55
+ if (node.nodes.length === 1) {
56
+ return "var(" + variableName + ")";
57
+ }
58
+
59
+ var defaultValues = node.nodes.slice(1).filter(function (subnode) {
60
+ return subnode.type !== 'div';
61
+ }).map(function (subnode) {
62
+ if (subnode.type === 'string') {
63
+ return "'" + matchString(subnode) + "'";
64
+ }
65
+
66
+ if (subnode.type === 'function' && ['rgb', 'rgba', 'hls', 'hlsa'].includes(subnode.value)) {
67
+ return subnode.value + "(" + subnode.nodes.map(function (n) {
68
+ return n.value;
69
+ }).join('') + ")";
70
+ }
71
+
72
+ return subnode.value;
73
+ });
74
+
75
+ if (defaultValues.length !== (node.nodes.length - 1) / 2) {
76
+ return null;
77
+ }
78
+
79
+ return "var(" + variableName + ", " + defaultValues.join(_templateObject()) + ")";
80
+ };
81
+
82
+ var noneRe = /^(none)$/i;
83
+ var autoRe = /^(auto)$/i;
84
+ var identRe = /(^-?[_a-z][_a-z0-9-]*$)/i; // Note if these are wrong, you'll need to change index.js too
85
+
86
+ var numberRe = /^([+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?)$/i; // Note lengthRe is sneaky: you can omit units for 0
87
+
88
+ var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?)(?=px$))/i;
89
+ var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?(ch|em|ex|rem|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/i;
90
+ var angleRe = /^([+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?(?:deg|rad|grad|turn))$/i;
91
+ var percentRe = /^([+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?%)$/i;
92
+
93
+ var noopToken = function noopToken(predicate) {
94
+ return function (node) {
95
+ return predicate(node) ? '<token>' : null;
96
+ };
97
+ };
98
+
99
+ var valueForTypeToken = function valueForTypeToken(type) {
100
+ return function (node) {
101
+ return node.type === type ? node.value : null;
102
+ };
103
+ };
104
+
105
+ var regExpToken = function regExpToken(regExp, transform) {
106
+ if (transform === void 0) {
107
+ transform = String;
108
+ }
109
+
110
+ return function (node) {
111
+ if (node.type !== 'word') return null;
112
+ var match = node.value.match(regExp);
113
+ if (match === null) return null;
114
+ var value = transform(match[1]);
115
+ return value;
116
+ };
117
+ };
118
+
119
+ var SPACE = noopToken(function (node) {
120
+ return node.type === 'space';
121
+ });
122
+ var SLASH = noopToken(function (node) {
123
+ return node.type === 'div' && node.value === '/';
124
+ });
125
+ var COMMA = noopToken(function (node) {
126
+ return node.type === 'div' && node.value === ',';
127
+ });
128
+ var WORD = valueForTypeToken('word');
129
+ var NONE = regExpToken(noneRe);
130
+ var AUTO = regExpToken(autoRe);
131
+ var NUMBER = regExpToken(numberRe, Number);
132
+ var LENGTH = regExpToken(lengthRe, Number);
133
+ var UNSUPPORTED_LENGTH_UNIT = regExpToken(unsupportedUnitRe);
134
+ var ANGLE = regExpToken(angleRe, function (angle) {
135
+ return angle.toLowerCase();
136
+ });
137
+ var PERCENT = regExpToken(percentRe);
138
+ var IDENT = regExpToken(identRe);
139
+ var STRING = matchString;
140
+ var COLOR = matchColor;
141
+ var LINE = regExpToken(/^(none|underline|line-through)$/i);
142
+ var VARIABLE = matchVariable;
143
+
144
+ var aspectRatio = function aspectRatio(tokenStream) {
145
+ var aspectRatio = tokenStream.expect(NUMBER);
146
+
147
+ if (tokenStream.hasTokens()) {
148
+ tokenStream.expect(SLASH);
149
+ aspectRatio /= tokenStream.expect(NUMBER);
150
+ }
151
+
152
+ return {
153
+ aspectRatio: aspectRatio
154
+ };
155
+ };
156
+
157
+ var BORDER_STYLE = regExpToken(/^(solid|dashed|dotted)$/);
158
+ var defaultBorderWidth = 1;
159
+ var defaultBorderColor = 'black';
160
+ var defaultBorderStyle = 'solid';
161
+
162
+ var border = function border(tokenStream) {
163
+ var borderWidth;
164
+ var borderColor;
165
+ var borderStyle;
166
+
167
+ if (tokenStream.matches(NONE)) {
168
+ tokenStream.expectEmpty();
169
+ return {
170
+ borderWidth: 0,
171
+ borderColor: 'black',
172
+ borderStyle: 'solid'
173
+ };
174
+ }
175
+
176
+ var partsParsed = 0;
177
+
178
+ while (partsParsed < 3 && tokenStream.hasTokens()) {
179
+ if (partsParsed !== 0) tokenStream.expect(SPACE);
180
+
181
+ if (borderWidth === undefined && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
182
+ borderWidth = tokenStream.lastValue;
183
+ } else if (borderColor === undefined && (tokenStream.matches(COLOR) || tokenStream.matches(VARIABLE))) {
184
+ borderColor = tokenStream.lastValue;
185
+ } else if (borderStyle === undefined && tokenStream.matches(BORDER_STYLE)) {
186
+ borderStyle = tokenStream.lastValue;
187
+ } else {
188
+ tokenStream["throw"]();
189
+ }
190
+
191
+ partsParsed += 1;
192
+ }
193
+
194
+ tokenStream.expectEmpty();
195
+ if (borderWidth === undefined) borderWidth = defaultBorderWidth;
196
+ if (borderColor === undefined) borderColor = defaultBorderColor;
197
+ if (borderStyle === undefined) borderStyle = defaultBorderStyle;
198
+ return {
199
+ borderWidth: borderWidth,
200
+ borderColor: borderColor,
201
+ borderStyle: borderStyle
202
+ };
203
+ };
204
+
205
+ var directionFactory = function directionFactory(_ref) {
206
+ var _ref$types = _ref.types,
207
+ types = _ref$types === void 0 ? [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT] : _ref$types,
208
+ _ref$directions = _ref.directions,
209
+ directions = _ref$directions === void 0 ? ['Top', 'Right', 'Bottom', 'Left'] : _ref$directions,
210
+ _ref$prefix = _ref.prefix,
211
+ prefix = _ref$prefix === void 0 ? '' : _ref$prefix,
212
+ _ref$suffix = _ref.suffix,
213
+ suffix = _ref$suffix === void 0 ? '' : _ref$suffix;
214
+ return function (tokenStream) {
215
+ var _ref2;
216
+
217
+ var values = []; // borderWidth doesn't currently allow a percent value, but may do in the future
218
+
219
+ values.push(tokenStream.expect.apply(tokenStream, types));
220
+
221
+ while (values.length < 4 && tokenStream.hasTokens()) {
222
+ tokenStream.expect(SPACE);
223
+ values.push(tokenStream.expect.apply(tokenStream, types));
224
+ }
225
+
226
+ tokenStream.expectEmpty();
227
+ var top = values[0],
228
+ _values$ = values[1],
229
+ right = _values$ === void 0 ? top : _values$,
230
+ _values$2 = values[2],
231
+ bottom = _values$2 === void 0 ? top : _values$2,
232
+ _values$3 = values[3],
233
+ left = _values$3 === void 0 ? right : _values$3;
234
+
235
+ var keyFor = function keyFor(n) {
236
+ return "" + prefix + directions[n] + suffix;
237
+ };
238
+
239
+ return _ref2 = {}, _ref2[keyFor(0)] = top, _ref2[keyFor(1)] = right, _ref2[keyFor(2)] = bottom, _ref2[keyFor(3)] = left, _ref2;
240
+ };
241
+ };
242
+
243
+ var parseShadowOffset = function parseShadowOffset(tokenStream) {
244
+ var width = tokenStream.expect(LENGTH);
245
+ var height = tokenStream.matches(SPACE) ? tokenStream.expect(LENGTH) : width;
246
+ tokenStream.expectEmpty();
247
+ return {
248
+ width: width,
249
+ height: height
250
+ };
251
+ };
252
+
253
+ var parseShadow = function parseShadow(tokenStream) {
254
+ var offsetX;
255
+ var offsetY;
256
+ var radius;
257
+ var color;
258
+
259
+ if (tokenStream.matches(NONE)) {
260
+ tokenStream.expectEmpty();
261
+ return {
262
+ offset: {
263
+ width: 0,
264
+ height: 0
265
+ },
266
+ radius: 0,
267
+ color: 'black'
268
+ };
269
+ }
270
+
271
+ var didParseFirst = false;
272
+
273
+ while (tokenStream.hasTokens()) {
274
+ if (didParseFirst) tokenStream.expect(SPACE);
275
+
276
+ if (offsetX === undefined && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
277
+ offsetX = tokenStream.lastValue;
278
+ tokenStream.expect(SPACE);
279
+ offsetY = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
280
+ tokenStream.saveRewindPoint();
281
+
282
+ if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
283
+ radius = tokenStream.lastValue;
284
+ } else {
285
+ tokenStream.rewind();
286
+ }
287
+ } else if (color === undefined && (tokenStream.matches(COLOR) || tokenStream.matches(VARIABLE))) {
288
+ color = tokenStream.lastValue;
289
+ } else {
290
+ tokenStream["throw"]();
291
+ }
292
+
293
+ didParseFirst = true;
294
+ }
295
+
296
+ if (offsetX === undefined) tokenStream["throw"]();
297
+ return {
298
+ offset: {
299
+ width: offsetX,
300
+ height: offsetY
301
+ },
302
+ radius: radius !== undefined ? radius : 0,
303
+ color: color !== undefined ? color : 'black'
304
+ };
305
+ };
306
+
307
+ var boxShadow = function boxShadow(tokenStream) {
308
+ var _parseShadow = parseShadow(tokenStream),
309
+ offset = _parseShadow.offset,
310
+ radius = _parseShadow.radius,
311
+ color = _parseShadow.color;
312
+
313
+ return {
314
+ shadowOffset: offset,
315
+ shadowRadius: radius,
316
+ shadowColor: color,
317
+ shadowOpacity: 1
318
+ };
319
+ };
320
+
321
+ var defaultFlexGrow = 1;
322
+ var defaultFlexShrink = 1;
323
+ var defaultFlexBasis = 0;
324
+
325
+ var flex = function flex(tokenStream) {
326
+ var flexGrow;
327
+ var flexShrink;
328
+ var flexBasis;
329
+
330
+ if (tokenStream.matches(NONE)) {
331
+ tokenStream.expectEmpty();
332
+ return {
333
+ flexGrow: 0,
334
+ flexShrink: 0,
335
+ flexBasis: 'auto'
336
+ };
337
+ }
338
+
339
+ tokenStream.saveRewindPoint();
340
+
341
+ if (tokenStream.matches(AUTO) && !tokenStream.hasTokens()) {
342
+ return {
343
+ flexGrow: 1,
344
+ flexShrink: 1,
345
+ flexBasis: 'auto'
346
+ };
347
+ }
348
+
349
+ tokenStream.rewind();
350
+ var partsParsed = 0;
351
+
352
+ while (partsParsed < 2 && tokenStream.hasTokens()) {
353
+ if (partsParsed !== 0) tokenStream.expect(SPACE);
354
+
355
+ if (flexGrow === undefined && tokenStream.matches(NUMBER)) {
356
+ flexGrow = tokenStream.lastValue;
357
+ tokenStream.saveRewindPoint();
358
+
359
+ if (tokenStream.matches(SPACE) && tokenStream.matches(NUMBER)) {
360
+ flexShrink = tokenStream.lastValue;
361
+ } else {
362
+ tokenStream.rewind();
363
+ }
364
+ } else if (flexBasis === undefined && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT)) {
365
+ flexBasis = tokenStream.lastValue;
366
+ } else if (flexBasis === undefined && tokenStream.matches(AUTO)) {
367
+ flexBasis = 'auto';
368
+ } else {
369
+ tokenStream["throw"]();
370
+ }
371
+
372
+ partsParsed += 1;
373
+ }
374
+
375
+ tokenStream.expectEmpty();
376
+ if (flexGrow === undefined) flexGrow = defaultFlexGrow;
377
+ if (flexShrink === undefined) flexShrink = defaultFlexShrink;
378
+ if (flexBasis === undefined) flexBasis = defaultFlexBasis;
379
+ return {
380
+ flexGrow: flexGrow,
381
+ flexShrink: flexShrink,
382
+ flexBasis: flexBasis
383
+ };
384
+ };
385
+
386
+ var FLEX_WRAP = regExpToken(/(nowrap|wrap|wrap-reverse)/);
387
+ var FLEX_DIRECTION = regExpToken(/(row|row-reverse|column|column-reverse)/);
388
+ var defaultFlexWrap = 'nowrap';
389
+ var defaultFlexDirection = 'row';
390
+
391
+ var flexFlow = function flexFlow(tokenStream) {
392
+ var flexWrap;
393
+ var flexDirection;
394
+ var partsParsed = 0;
395
+
396
+ while (partsParsed < 2 && tokenStream.hasTokens()) {
397
+ if (partsParsed !== 0) tokenStream.expect(SPACE);
398
+
399
+ if (flexWrap === undefined && tokenStream.matches(FLEX_WRAP)) {
400
+ flexWrap = tokenStream.lastValue;
401
+ } else if (flexDirection === undefined && tokenStream.matches(FLEX_DIRECTION)) {
402
+ flexDirection = tokenStream.lastValue;
403
+ } else {
404
+ tokenStream["throw"]();
405
+ }
406
+
407
+ partsParsed += 1;
408
+ }
409
+
410
+ tokenStream.expectEmpty();
411
+ if (flexWrap === undefined) flexWrap = defaultFlexWrap;
412
+ if (flexDirection === undefined) flexDirection = defaultFlexDirection;
413
+ return {
414
+ flexWrap: flexWrap,
415
+ flexDirection: flexDirection
416
+ };
417
+ };
418
+
419
+ var fontFamily = function fontFamily(tokenStream) {
420
+ var fontFamily;
421
+
422
+ if (tokenStream.matches(STRING)) {
423
+ fontFamily = tokenStream.lastValue;
424
+ } else {
425
+ fontFamily = tokenStream.expect(IDENT);
426
+
427
+ while (tokenStream.hasTokens()) {
428
+ tokenStream.expect(SPACE);
429
+ var nextIdent = tokenStream.expect(IDENT);
430
+ fontFamily += " " + nextIdent;
431
+ }
432
+ }
433
+
434
+ tokenStream.expectEmpty();
435
+ return {
436
+ fontFamily: fontFamily
437
+ };
438
+ };
439
+
440
+ var NORMAL = regExpToken(/^(normal)$/);
441
+ var STYLE = regExpToken(/^(italic)$/);
442
+ var WEIGHT = regExpToken(/^([1-9]00|bold)$/);
443
+ var VARIANT = regExpToken(/^(small-caps)$/);
444
+ var defaultFontStyle = 'normal';
445
+ var defaultFontWeight = 'normal';
446
+ var defaultFontVariant = [];
447
+
448
+ var font = function font(tokenStream) {
449
+ var fontStyle;
450
+ var fontWeight;
451
+ var fontVariant; // let fontSize;
452
+
453
+ var lineHeight; // let fontFamily;
454
+
455
+ var numStyleWeightVariantMatched = 0;
456
+
457
+ while (numStyleWeightVariantMatched < 3 && tokenStream.hasTokens()) {
458
+ if (tokenStream.matches(NORMAL)) ;else if (fontStyle === undefined && tokenStream.matches(STYLE)) {
459
+ fontStyle = tokenStream.lastValue;
460
+ } else if (fontWeight === undefined && tokenStream.matches(WEIGHT)) {
461
+ fontWeight = tokenStream.lastValue;
462
+ } else if (fontVariant === undefined && tokenStream.matches(VARIANT)) {
463
+ fontVariant = [tokenStream.lastValue];
464
+ } else {
465
+ break;
466
+ }
467
+ tokenStream.expect(SPACE);
468
+ numStyleWeightVariantMatched += 1;
469
+ }
470
+
471
+ var fontSize = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
472
+
473
+ if (tokenStream.matches(SLASH)) {
474
+ lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
475
+ }
476
+
477
+ tokenStream.expect(SPACE);
478
+
479
+ var _fontFamily = fontFamily(tokenStream),
480
+ fontFamily$1 = _fontFamily.fontFamily;
481
+
482
+ if (fontStyle === undefined) fontStyle = defaultFontStyle;
483
+ if (fontWeight === undefined) fontWeight = defaultFontWeight;
484
+ if (fontVariant === undefined) fontVariant = defaultFontVariant;
485
+ var out = {
486
+ fontStyle: fontStyle,
487
+ fontWeight: fontWeight,
488
+ fontVariant: fontVariant,
489
+ fontSize: fontSize,
490
+ fontFamily: fontFamily$1
491
+ };
492
+ if (lineHeight !== undefined) out.lineHeight = lineHeight;
493
+ return out;
494
+ };
495
+
496
+ var fontVariant = function fontVariant(tokenStream) {
497
+ var values = [tokenStream.expect(IDENT)];
498
+
499
+ while (tokenStream.hasTokens()) {
500
+ tokenStream.expect(SPACE);
501
+ values.push(tokenStream.expect(IDENT));
502
+ }
503
+
504
+ return {
505
+ fontVariant: values
506
+ };
507
+ };
508
+
509
+ var ALIGN_CONTENT = regExpToken(/(flex-(?:start|end)|center|stretch|space-(?:between|around))/);
510
+ var JUSTIFY_CONTENT = regExpToken(/(flex-(?:start|end)|center|space-(?:between|around|evenly))/);
511
+
512
+ var placeContent = function placeContent(tokenStream) {
513
+ var alignContent = tokenStream.expect(ALIGN_CONTENT);
514
+ var justifyContent;
515
+
516
+ if (tokenStream.hasTokens()) {
517
+ tokenStream.expect(SPACE);
518
+ justifyContent = tokenStream.expect(JUSTIFY_CONTENT);
519
+ } else {
520
+ justifyContent = 'stretch';
521
+ }
522
+
523
+ tokenStream.expectEmpty();
524
+ return {
525
+ alignContent: alignContent,
526
+ justifyContent: justifyContent
527
+ };
528
+ };
529
+
530
+ var STYLE$1 = regExpToken(/^(solid|double|dotted|dashed)$/);
531
+ var defaultTextDecorationLine = 'none';
532
+ var defaultTextDecorationStyle = 'solid';
533
+ var defaultTextDecorationColor = 'black';
534
+
535
+ var textDecoration = function textDecoration(tokenStream) {
536
+ var line;
537
+ var style;
538
+ var color;
539
+ var didParseFirst = false;
540
+
541
+ while (tokenStream.hasTokens()) {
542
+ if (didParseFirst) tokenStream.expect(SPACE);
543
+
544
+ if (line === undefined && tokenStream.matches(LINE)) {
545
+ var lines = [tokenStream.lastValue.toLowerCase()];
546
+ tokenStream.saveRewindPoint();
547
+
548
+ if (lines[0] !== 'none' && tokenStream.matches(SPACE) && tokenStream.matches(LINE)) {
549
+ lines.push(tokenStream.lastValue.toLowerCase()); // Underline comes before line-through
550
+
551
+ lines.sort().reverse();
552
+ } else {
553
+ tokenStream.rewind();
554
+ }
555
+
556
+ line = lines.join(' ');
557
+ } else if (style === undefined && tokenStream.matches(STYLE$1)) {
558
+ style = tokenStream.lastValue;
559
+ } else if (color === undefined && (tokenStream.matches(COLOR) || tokenStream.matches(VARIABLE))) {
560
+ color = tokenStream.lastValue;
561
+ } else {
562
+ tokenStream["throw"]();
563
+ }
564
+
565
+ didParseFirst = true;
566
+ }
567
+
568
+ return {
569
+ textDecorationLine: line !== undefined ? line : defaultTextDecorationLine,
570
+ textDecorationColor: color !== undefined ? color : defaultTextDecorationColor,
571
+ textDecorationStyle: style !== undefined ? style : defaultTextDecorationStyle
572
+ };
573
+ };
574
+
575
+ var textDecorationLine = function textDecorationLine(tokenStream) {
576
+ var lines = [];
577
+ var didParseFirst = false;
578
+
579
+ while (tokenStream.hasTokens()) {
580
+ if (didParseFirst) tokenStream.expect(SPACE);
581
+ lines.push(tokenStream.expect(LINE).toLowerCase());
582
+ didParseFirst = true;
583
+ }
584
+
585
+ lines.sort().reverse();
586
+ return {
587
+ textDecorationLine: lines.join(' ')
588
+ };
589
+ };
590
+
591
+ var textShadow = function textShadow(tokenStream) {
592
+ var _parseShadow2 = parseShadow(tokenStream),
593
+ offset = _parseShadow2.offset,
594
+ radius = _parseShadow2.radius,
595
+ color = _parseShadow2.color;
596
+
597
+ return {
598
+ textShadowOffset: offset,
599
+ textShadowRadius: radius,
600
+ textShadowColor: color
601
+ };
602
+ };
603
+
604
+ var oneOfTypes = function oneOfTypes(tokenTypes) {
605
+ return function (functionStream) {
606
+ var value = functionStream.expect.apply(functionStream, tokenTypes);
607
+ functionStream.expectEmpty();
608
+ return value;
609
+ };
610
+ };
611
+
612
+ var singleNumber = oneOfTypes([NUMBER]);
613
+ var singleLengthOrPercent = oneOfTypes([LENGTH, PERCENT]);
614
+ var singleAngle = oneOfTypes([ANGLE]);
615
+
616
+ var xyTransformFactory = function xyTransformFactory(tokenTypes) {
617
+ return function (key, valueIfOmitted) {
618
+ return function (functionStream) {
619
+ var _ref3, _ref4;
620
+
621
+ var x = functionStream.expect.apply(functionStream, tokenTypes);
622
+ var y;
623
+
624
+ if (functionStream.hasTokens()) {
625
+ functionStream.expect(COMMA);
626
+ y = functionStream.expect.apply(functionStream, tokenTypes);
627
+ } else if (valueIfOmitted !== undefined) {
628
+ y = valueIfOmitted;
629
+ } else {
630
+ // Assumption, if x === y, then we can omit XY
631
+ // I.e. scale(5) => [{ scale: 5 }] rather than [{ scaleX: 5 }, { scaleY: 5 }]
632
+ return x;
633
+ }
634
+
635
+ functionStream.expectEmpty();
636
+ return [(_ref3 = {}, _ref3[key + "Y"] = y, _ref3), (_ref4 = {}, _ref4[key + "X"] = x, _ref4)];
637
+ };
638
+ };
639
+ };
640
+
641
+ var xyNumber = xyTransformFactory([NUMBER]);
642
+ var xyLengthOrPercent = xyTransformFactory([LENGTH, PERCENT]);
643
+ var xyAngle = xyTransformFactory([ANGLE]);
644
+ var partTransforms = {
645
+ perspective: singleNumber,
646
+ scale: xyNumber('scale'),
647
+ scaleX: singleNumber,
648
+ scaleY: singleNumber,
649
+ translate: xyLengthOrPercent('translate', 0),
650
+ translateX: singleLengthOrPercent,
651
+ translateY: singleLengthOrPercent,
652
+ rotate: singleAngle,
653
+ rotateX: singleAngle,
654
+ rotateY: singleAngle,
655
+ rotateZ: singleAngle,
656
+ skewX: singleAngle,
657
+ skewY: singleAngle,
658
+ skew: xyAngle('skew', '0deg')
659
+ };
660
+
661
+ var transform = function transform(tokenStream) {
662
+ var transforms = [];
663
+ var didParseFirst = false;
664
+
665
+ while (tokenStream.hasTokens()) {
666
+ if (didParseFirst) tokenStream.expect(SPACE);
667
+ var functionStream = tokenStream.expectFunction();
668
+ var functionName = functionStream.functionName;
669
+ var transformedValues = partTransforms[functionName](functionStream);
670
+
671
+ if (!Array.isArray(transformedValues)) {
672
+ var _ref5;
673
+
674
+ transformedValues = [(_ref5 = {}, _ref5[functionName] = transformedValues, _ref5)];
675
+ }
676
+
677
+ transforms = transformedValues.concat(transforms);
678
+ didParseFirst = true;
679
+ }
680
+
681
+ return {
682
+ transform: transforms
683
+ };
684
+ };
685
+
686
+ var background = function background(tokenStream) {
687
+ return {
688
+ backgroundColor: tokenStream.expect(COLOR, VARIABLE)
689
+ };
690
+ };
691
+
692
+ var borderColor = directionFactory({
693
+ types: [COLOR, VARIABLE],
694
+ prefix: 'border',
695
+ suffix: 'Color'
696
+ });
697
+ var borderRadius = directionFactory({
698
+ directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
699
+ prefix: 'border',
700
+ suffix: 'Radius'
701
+ });
702
+ var borderWidth = directionFactory({
703
+ prefix: 'border',
704
+ suffix: 'Width'
705
+ });
706
+ var margin = directionFactory({
707
+ types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
708
+ prefix: 'margin'
709
+ });
710
+ var padding = directionFactory({
711
+ prefix: 'padding'
712
+ });
713
+
714
+ var fontWeight = function fontWeight(tokenStream) {
715
+ return {
716
+ fontWeight: tokenStream.expect(WORD) // Also match numbers as strings
717
+
718
+ };
719
+ };
720
+
721
+ var shadowOffset = function shadowOffset(tokenStream) {
722
+ return {
723
+ shadowOffset: parseShadowOffset(tokenStream)
724
+ };
725
+ };
726
+
727
+ var textShadowOffset = function textShadowOffset(tokenStream) {
728
+ return {
729
+ textShadowOffset: parseShadowOffset(tokenStream)
730
+ };
731
+ };
732
+
733
+ var transforms = {
734
+ aspectRatio: aspectRatio,
735
+ background: background,
736
+ border: border,
737
+ borderColor: borderColor,
738
+ borderRadius: borderRadius,
739
+ borderWidth: borderWidth,
740
+ boxShadow: boxShadow,
741
+ flex: flex,
742
+ flexFlow: flexFlow,
743
+ font: font,
744
+ fontFamily: fontFamily,
745
+ fontVariant: fontVariant,
746
+ fontWeight: fontWeight,
747
+ margin: margin,
748
+ padding: padding,
749
+ placeContent: placeContent,
750
+ shadowOffset: shadowOffset,
751
+ textShadow: textShadow,
752
+ textShadowOffset: textShadowOffset,
753
+ textDecoration: textDecoration,
754
+ textDecorationLine: textDecorationLine,
755
+ transform: transform
756
+ };
757
+ var propertiesWithoutUnits;
758
+
759
+ if (process.env.NODE_ENV !== 'production') {
760
+ propertiesWithoutUnits = ['aspectRatio', 'elevation', 'flexGrow', 'flexShrink', 'opacity', 'shadowOpacity', 'zIndex'];
761
+ }
762
+
763
+ var devPropertiesWithUnitsRegExp = propertiesWithoutUnits != null ? new RegExp(propertiesWithoutUnits.join('|')) : null;
764
+ var SYMBOL_MATCH = 'SYMBOL_MATCH';
765
+
766
+ var TokenStream =
767
+ /*#__PURE__*/
768
+ function () {
769
+ function TokenStream(nodes, parent) {
770
+ this.index = 0;
771
+ this.nodes = nodes;
772
+ this.functionName = parent != null ? parent.value : null;
773
+ this.lastValue = null;
774
+ this.rewindIndex = -1;
775
+ }
776
+
777
+ var _proto = TokenStream.prototype;
778
+
779
+ _proto.hasTokens = function hasTokens() {
780
+ return this.index <= this.nodes.length - 1;
781
+ };
782
+
783
+ _proto[SYMBOL_MATCH] = function () {
784
+ if (!this.hasTokens()) return null;
785
+ var node = this.nodes[this.index];
786
+
787
+ for (var i = 0; i < arguments.length; i += 1) {
788
+ var tokenDescriptor = i < 0 || arguments.length <= i ? undefined : arguments[i];
789
+ var value = tokenDescriptor(node);
790
+
791
+ if (value !== null) {
792
+ this.index += 1;
793
+ this.lastValue = value;
794
+ return value;
795
+ }
796
+ }
797
+
798
+ return null;
799
+ };
800
+
801
+ _proto.matches = function matches() {
802
+ return this[SYMBOL_MATCH].apply(this, arguments) !== null;
803
+ };
804
+
805
+ _proto.expect = function expect() {
806
+ var value = this[SYMBOL_MATCH].apply(this, arguments);
807
+ return value !== null ? value : this["throw"]();
808
+ };
809
+
810
+ _proto.matchesFunction = function matchesFunction() {
811
+ var node = this.nodes[this.index];
812
+ if (node.type !== 'function') return null;
813
+ var value = new TokenStream(node.nodes, node);
814
+ this.index += 1;
815
+ this.lastValue = null;
816
+ return value;
817
+ };
818
+
819
+ _proto.expectFunction = function expectFunction() {
820
+ var value = this.matchesFunction();
821
+ return value !== null ? value : this["throw"]();
822
+ };
823
+
824
+ _proto.expectEmpty = function expectEmpty() {
825
+ if (this.hasTokens()) this["throw"]();
826
+ };
827
+
828
+ _proto["throw"] = function _throw() {
829
+ throw new Error("Unexpected token type: " + this.nodes[this.index].type);
830
+ };
831
+
832
+ _proto.saveRewindPoint = function saveRewindPoint() {
833
+ this.rewindIndex = this.index;
834
+ };
835
+
836
+ _proto.rewind = function rewind() {
837
+ if (this.rewindIndex === -1) throw new Error('Internal error');
838
+ this.index = this.rewindIndex;
839
+ this.lastValue = null;
840
+ };
841
+
842
+ return TokenStream;
843
+ }();
844
+ /* eslint-disable no-param-reassign */
845
+ // Note if this is wrong, you'll need to change tokenTypes.js too
846
+
847
+
848
+ var numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?)(?:px)?$/i;
849
+ var numberOnlyRe = /^[+-]?(?:\d*\.\d*|[1-9]\d*)(?:e[+-]?\d+)?$/i;
850
+ var boolRe = /^true|false$/i;
851
+ var nullRe = /^null$/i;
852
+ var undefinedRe = /^undefined$/i; // Undocumented export
853
+
854
+ var transformRawValue = function transformRawValue(propName, value) {
855
+ if (process.env.NODE_ENV !== 'production') {
856
+ var needsUnit = !devPropertiesWithUnitsRegExp.test(propName);
857
+ var isNumberWithoutUnit = numberOnlyRe.test(value);
858
+
859
+ if (needsUnit && isNumberWithoutUnit) {
860
+ // eslint-disable-next-line no-console
861
+ console.warn("Expected style \"" + propName + ": " + value + "\" to contain units");
862
+ }
863
+
864
+ if (!needsUnit && value !== '0' && !isNumberWithoutUnit) {
865
+ // eslint-disable-next-line no-console
866
+ console.warn("Expected style \"" + propName + ": " + value + "\" to be unitless");
867
+ }
868
+ }
869
+
870
+ var numberMatch = value.match(numberOrLengthRe);
871
+ if (numberMatch !== null) return Number(numberMatch[1]);
872
+ var boolMatch = value.match(boolRe);
873
+ if (boolMatch !== null) return boolMatch[0].toLowerCase() === 'true';
874
+ var nullMatch = value.match(nullRe);
875
+ if (nullMatch !== null) return null;
876
+ var undefinedMatch = value.match(undefinedRe);
877
+ if (undefinedMatch !== null) return undefined;
878
+ return value;
879
+ };
880
+
881
+ var baseTransformShorthandValue = function baseTransformShorthandValue(propName, value) {
882
+ var ast = parse__default(value);
883
+ var tokenStream = new TokenStream(ast.nodes);
884
+ return transforms[propName](tokenStream);
885
+ };
886
+
887
+ var transformShorthandValue = process.env.NODE_ENV === 'production' ? baseTransformShorthandValue : function (propName, value) {
888
+ try {
889
+ return baseTransformShorthandValue(propName, value);
890
+ } catch (e) {
891
+ throw new Error("Failed to parse declaration \"" + propName + ": " + value + "\"");
892
+ }
893
+ };
894
+
895
+ var getStylesForProperty = function getStylesForProperty(propName, inputValue, allowShorthand) {
896
+ var _ref6;
897
+
898
+ var isRawValue = allowShorthand === false || !(propName in transforms);
899
+ var value = inputValue.trim();
900
+ var propValues = isRawValue ? (_ref6 = {}, _ref6[propName] = transformRawValue(propName, value), _ref6) : transformShorthandValue(propName, value);
901
+ return propValues;
902
+ };
903
+
904
+ var getPropertyName = function getPropertyName(propName) {
905
+ var isCustomProp = /^--\w+/.test(propName);
906
+
907
+ if (isCustomProp) {
908
+ return propName;
909
+ }
910
+
911
+ return camelizeStyleName(propName);
912
+ };
913
+
914
+ var index = function index(rules, shorthandBlacklist) {
915
+ if (shorthandBlacklist === void 0) {
916
+ shorthandBlacklist = [];
917
+ }
918
+
919
+ return rules.reduce(function (accum, rule) {
920
+ var propertyName = getPropertyName(rule[0]);
921
+ var value = rule[1];
922
+ var allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1;
923
+ return Object.assign(accum, getStylesForProperty(propertyName, value, allowShorthand));
924
+ }, {});
925
+ };
926
+
927
+ exports["default"] = index;
928
+ exports.getPropertyName = getPropertyName;
929
+ exports.getStylesForProperty = getStylesForProperty;
930
+ exports.transformRawValue = transformRawValue;