taro-css-to-react-native 3.6.0-beta.1 → 3.6.0-beta.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.
@@ -4,22 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
+
8
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
+
10
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
13
+
13
14
  var SYMBOL_MATCH = 'SYMBOL_MATCH';
15
+
14
16
  var TokenStream = /*#__PURE__*/function () {
15
17
  function TokenStream(nodes, parent) {
16
18
  _classCallCheck(this, TokenStream);
19
+
17
20
  this.index = 0;
18
21
  this.nodes = nodes;
19
22
  this.functionName = parent != null ? parent.value : null;
20
23
  this.lastValue = null;
21
24
  this.rewindIndex = -1;
22
25
  }
26
+
23
27
  _createClass(TokenStream, [{
24
28
  key: "node",
25
29
  get: function get() {
@@ -40,15 +44,18 @@ var TokenStream = /*#__PURE__*/function () {
40
44
  value: function value() {
41
45
  if (!this.hasTokens()) return null;
42
46
  var node = this.node;
47
+
43
48
  for (var i = 0; i < arguments.length; i += 1) {
44
49
  var tokenDescriptor = i < 0 || arguments.length <= i ? undefined : arguments[i];
45
50
  var value = tokenDescriptor(node);
51
+
46
52
  if (value !== null) {
47
53
  this.index += 1;
48
54
  this.lastValue = value;
49
55
  return value;
50
56
  }
51
57
  }
58
+
52
59
  return null;
53
60
  }
54
61
  }, {
@@ -87,6 +94,7 @@ var TokenStream = /*#__PURE__*/function () {
87
94
  key: "throw",
88
95
  value: function _throw() {
89
96
  var _this$node;
97
+
90
98
  throw new Error("Unexpected token type: ".concat((_this$node = this.node) === null || _this$node === void 0 ? void 0 : _this$node.type));
91
99
  }
92
100
  }, {
@@ -102,6 +110,8 @@ var TokenStream = /*#__PURE__*/function () {
102
110
  this.lastValue = null;
103
111
  }
104
112
  }]);
113
+
105
114
  return TokenStream;
106
115
  }();
116
+
107
117
  exports["default"] = TokenStream;
@@ -4,29 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.transformRawValue = exports.getStylesForProperty = exports.getPropertyName = exports["default"] = void 0;
7
+
7
8
  var _camelize = _interopRequireDefault(require("camelize"));
9
+
8
10
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
+
9
12
  var _TokenStream = _interopRequireDefault(require("./TokenStream"));
13
+
10
14
  var _index = _interopRequireDefault(require("./transforms/index"));
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
13
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
16
20
  // Note if this is wrong, you'll need to change tokenTypes.js too
17
21
  var numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?:px)|(?:vw$)|(?:vh$)|(?:vmin$)|(?:vmax$))?$/i;
18
22
  var boolRe = /^true|false$/i;
19
23
  var nullRe = /^null$/i;
20
- var undefinedRe = /^undefined$/i;
24
+ var undefinedRe = /^undefined$/i; // Undocumented export
21
25
 
22
- // Undocumented export
23
26
  var transformRawValue = function transformRawValue(input) {
24
27
  var value = input.trim();
25
28
  var numberMatch = value.match(numberOrLengthRe);
29
+
26
30
  if (numberMatch !== null) {
27
31
  var num = Number(numberMatch[1]);
28
32
  var unit = numberMatch[2];
29
33
  var isViewportUnit = ['vw', 'vh', 'vmin', 'vmax'].includes(unit);
34
+
30
35
  if (isViewportUnit) {
31
36
  return "scaleVu2dp(".concat(num, ", '").concat(unit, "')");
32
37
  } else if (/(\d+)px/.test(value)) {
@@ -35,6 +40,7 @@ var transformRawValue = function transformRawValue(input) {
35
40
  return num;
36
41
  }
37
42
  }
43
+
38
44
  var boolMatch = input.match(boolRe);
39
45
  if (boolMatch !== null) return boolMatch[0].toLowerCase() === 'true';
40
46
  var nullMatch = input.match(nullRe);
@@ -43,13 +49,16 @@ var transformRawValue = function transformRawValue(input) {
43
49
  if (undefinedMatch !== null) return undefined;
44
50
  return value;
45
51
  };
52
+
46
53
  exports.transformRawValue = transformRawValue;
54
+
47
55
  var baseTransformShorthandValue = function baseTransformShorthandValue(propName, inputValue) {
48
56
  // const ast = parse(inputValue.trim().replace(/PX|Px|pX$/g, ""));
49
57
  var ast = (0, _postcssValueParser["default"])(inputValue);
50
58
  var tokenStream = new _TokenStream["default"](ast.nodes);
51
59
  return _index["default"][propName](tokenStream);
52
60
  };
61
+
53
62
  var checkBaseTransformShorthandValue = function checkBaseTransformShorthandValue(propName, inputValue) {
54
63
  try {
55
64
  return baseTransformShorthandValue(propName, inputValue);
@@ -57,21 +66,29 @@ var checkBaseTransformShorthandValue = function checkBaseTransformShorthandValue
57
66
  throw new Error("".concat(e.message, " Failed to parse declaration \"").concat(propName, ": ").concat(inputValue, "\""));
58
67
  }
59
68
  };
69
+
60
70
  var transformShorthandValue = process.env.NODE_ENV === 'production' ? baseTransformShorthandValue : checkBaseTransformShorthandValue;
71
+
61
72
  var getStylesForProperty = function getStylesForProperty(propName, inputValue, allowShorthand) {
62
73
  var isRawValue = allowShorthand === false || !(propName in _index["default"]);
63
74
  var propValue = isRawValue ? transformRawValue(inputValue) : transformShorthandValue(propName, inputValue.trim());
64
75
  return propValue && propValue.$merge ? propValue.$merge : _defineProperty({}, propName, propValue);
65
76
  };
77
+
66
78
  exports.getStylesForProperty = getStylesForProperty;
79
+
67
80
  var getPropertyName = function getPropertyName(propName) {
68
81
  var isCustomProp = /^--\w+/.test(propName);
82
+
69
83
  if (isCustomProp) {
70
84
  return propName;
71
85
  }
86
+
72
87
  return (0, _camelize["default"])(propName);
73
88
  };
89
+
74
90
  exports.getPropertyName = getPropertyName;
91
+
75
92
  var _default = function _default(rules) {
76
93
  var shorthandBlacklist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
77
94
  return rules.reduce(function (accum, rule) {
@@ -81,4 +98,5 @@ var _default = function _default(rules) {
81
98
  return Object.assign(accum, getStylesForProperty(propertyName, value, allowShorthand));
82
99
  }, {});
83
100
  };
101
+
84
102
  exports["default"] = _default;
@@ -4,48 +4,58 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.tokens = exports.regExpToken = void 0;
7
+
7
8
  var _cssColorKeywords = _interopRequireDefault(require("css-color-keywords"));
9
+
8
10
  var _postcssValueParser = require("postcss-value-parser");
11
+
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- /* eslint-disable react/display-name */
11
13
 
14
+ /* eslint-disable react/display-name */
12
15
  var matchString = function matchString(node) {
13
16
  if (node.type !== 'string') return null;
14
17
  return node.value.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, function (match, charCode) {
15
18
  return String.fromCharCode(parseInt(charCode, 16));
16
19
  }).replace(/\\/g, '');
17
20
  };
21
+
18
22
  var hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i;
19
23
  var cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/;
24
+
20
25
  var matchColor = function matchColor(node) {
21
26
  if (node.type === 'word' && (hexColorRe.test(node.value) || node.value in _cssColorKeywords["default"] || node.value === 'transparent')) {
22
27
  return node.value;
23
28
  } else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {
24
29
  return (0, _postcssValueParser.stringify)(node);
25
30
  }
31
+
26
32
  return null;
27
33
  };
34
+
28
35
  var noneRe = /^(none)$/i;
29
36
  var autoRe = /^(auto)$/i;
30
- var identRe = /(^-?[_a-z][_a-z0-9-]*$)/i;
31
- // Note if these are wrong, you'll need to change index.js too
32
- var numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/;
33
- // Note lengthRe is sneaky: you can omit units for 0
37
+ var identRe = /(^-?[_a-z][_a-z0-9-]*$)/i; // Note if these are wrong, you'll need to change index.js too
38
+
39
+ var numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/; // Note lengthRe is sneaky: you can omit units for 0
40
+
34
41
  var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)|(?=vw$)|(?=vh$)|(?=vmin$)|(?=vmax$)))/;
35
42
  var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|cm|mm|in|pc|pt))$/;
36
43
  var angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/;
37
44
  var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
38
45
  var viewportUnitRe = /(\d+)(vw|vh|vmin|vmax)/;
46
+
39
47
  var noopToken = function noopToken(predicate) {
40
48
  return function (node) {
41
49
  return predicate(node) ? '<token>' : null;
42
50
  };
43
51
  };
52
+
44
53
  var valueForTypeToken = function valueForTypeToken(type) {
45
54
  return function (node) {
46
55
  return node.type === type ? node.value : null;
47
56
  };
48
57
  };
58
+
49
59
  var functionValueForTypeToken = function functionValueForTypeToken(type) {
50
60
  return function (node) {
51
61
  if (node.type === type) {
@@ -59,19 +69,23 @@ var functionValueForTypeToken = function functionValueForTypeToken(type) {
59
69
  return "".concat(node.value, "(").concat(result.join(', '), ")");
60
70
  }
61
71
  }
72
+
62
73
  return null;
63
74
  };
64
75
  };
76
+
65
77
  var regExpToken = function regExpToken(regExp) {
66
78
  var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String;
67
79
  return function (node) {
68
80
  var _node$value$match;
81
+
69
82
  if (node.type !== 'word') return null;
70
83
  var match = node.value.match(regExp);
71
84
  if (match === null) return null;
72
85
  var value = transform(match[1]);
73
86
  var unit = (_node$value$match = node.value.match(viewportUnitRe)) === null || _node$value$match === void 0 ? void 0 : _node$value$match[2];
74
87
  var isViewportUnit = ['vh', 'vw', 'vmin', 'vmax'].includes(unit);
88
+
75
89
  if (isViewportUnit) {
76
90
  return "scaleVu2dp(".concat(value, ", '").concat(unit, "')");
77
91
  } else if (/(\d+)px/.test(node.value)) {
@@ -81,6 +95,7 @@ var regExpToken = function regExpToken(regExp) {
81
95
  }
82
96
  };
83
97
  };
98
+
84
99
  exports.regExpToken = regExpToken;
85
100
  var tokens = {
86
101
  SPACE: noopToken(function (node) {
@@ -4,19 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.borderWidth = exports.borderTop = exports.borderRight = exports.borderRadius = exports.borderLeft = exports.borderColor = exports.borderBottom = exports.border = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var _util = require("./util");
9
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+
13
14
  var WORD = _tokenTypes.tokens.WORD,
14
- FUNC = _tokenTypes.tokens.FUNC,
15
- COLOR = _tokenTypes.tokens.COLOR,
16
- LENGTH = _tokenTypes.tokens.LENGTH,
17
- UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT;
15
+ FUNC = _tokenTypes.tokens.FUNC,
16
+ COLOR = _tokenTypes.tokens.COLOR,
17
+ LENGTH = _tokenTypes.tokens.LENGTH,
18
+ UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT;
19
+
18
20
  function borderDirectionFactory() {
19
21
  var _anyOrderFactory;
22
+
20
23
  var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
21
24
  var prefix = "border".concat(direction);
22
25
  return (0, _util.anyOrderFactory)((_anyOrderFactory = {}, _defineProperty(_anyOrderFactory, "".concat(prefix, "Width"), {
@@ -30,6 +33,7 @@ function borderDirectionFactory() {
30
33
  "default": 'solid'
31
34
  }), _anyOrderFactory));
32
35
  }
36
+
33
37
  var border = borderDirectionFactory();
34
38
  exports.border = border;
35
39
  var borderTop = borderDirectionFactory('Top');
@@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _util = require("./util");
9
+
8
10
  var _default = function _default(tokenStream) {
9
11
  var _parseShadow = (0, _util.parseShadow)(tokenStream),
10
- offset = _parseShadow.offset,
11
- radius = _parseShadow.radius,
12
- color = _parseShadow.color;
12
+ offset = _parseShadow.offset,
13
+ radius = _parseShadow.radius,
14
+ color = _parseShadow.color;
15
+
13
16
  return {
14
17
  $merge: {
15
18
  shadowOffset: offset,
@@ -19,4 +22,5 @@ var _default = function _default(tokenStream) {
19
22
  }
20
23
  };
21
24
  };
25
+
22
26
  exports["default"] = _default;
@@ -4,19 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var NONE = _tokenTypes.tokens.NONE,
9
- AUTO = _tokenTypes.tokens.AUTO,
10
- NUMBER = _tokenTypes.tokens.NUMBER,
11
- LENGTH = _tokenTypes.tokens.LENGTH,
12
- SPACE = _tokenTypes.tokens.SPACE;
11
+ AUTO = _tokenTypes.tokens.AUTO,
12
+ NUMBER = _tokenTypes.tokens.NUMBER,
13
+ LENGTH = _tokenTypes.tokens.LENGTH,
14
+ SPACE = _tokenTypes.tokens.SPACE;
13
15
  var defaultFlexGrow = 1;
14
16
  var defaultFlexShrink = 1;
15
17
  var defaultFlexBasis = 0;
18
+
16
19
  var _default = function _default(tokenStream) {
17
20
  var flexGrow;
18
21
  var flexShrink;
19
22
  var flexBasis;
23
+
20
24
  if (tokenStream.matches(NONE)) {
21
25
  tokenStream.expectEmpty();
22
26
  return {
@@ -27,7 +31,9 @@ var _default = function _default(tokenStream) {
27
31
  }
28
32
  };
29
33
  }
34
+
30
35
  tokenStream.saveRewindPoint();
36
+
31
37
  if (tokenStream.matches(AUTO) && !tokenStream.hasTokens()) {
32
38
  return {
33
39
  $merge: {
@@ -37,13 +43,17 @@ var _default = function _default(tokenStream) {
37
43
  }
38
44
  };
39
45
  }
46
+
40
47
  tokenStream.rewind();
41
48
  var partsParsed = 0;
49
+
42
50
  while (partsParsed < 2 && tokenStream.hasTokens()) {
43
51
  if (partsParsed !== 0) tokenStream.expect(SPACE);
52
+
44
53
  if (typeof flexGrow === 'undefined' && tokenStream.matches(NUMBER)) {
45
54
  flexGrow = tokenStream.lastValue;
46
55
  tokenStream.saveRewindPoint();
56
+
47
57
  if (tokenStream.matches(SPACE) && tokenStream.matches(NUMBER)) {
48
58
  flexShrink = tokenStream.lastValue;
49
59
  } else {
@@ -56,8 +66,10 @@ var _default = function _default(tokenStream) {
56
66
  } else {
57
67
  tokenStream["throw"]();
58
68
  }
69
+
59
70
  partsParsed += 1;
60
71
  }
72
+
61
73
  tokenStream.expectEmpty();
62
74
  if (typeof flexGrow === 'undefined') flexGrow = defaultFlexGrow;
63
75
  if (typeof flexShrink === 'undefined') flexShrink = defaultFlexShrink;
@@ -70,4 +82,5 @@ var _default = function _default(tokenStream) {
70
82
  }
71
83
  };
72
84
  };
85
+
73
86
  exports["default"] = _default;
@@ -4,14 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var _fontFamily = _interopRequireDefault(require("./fontFamily"));
11
+
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
10
14
  var SPACE = _tokenTypes.tokens.SPACE,
11
- LENGTH = _tokenTypes.tokens.LENGTH,
12
- UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
13
- NUMBER = _tokenTypes.tokens.NUMBER,
14
- SLASH = _tokenTypes.tokens.SLASH;
15
+ LENGTH = _tokenTypes.tokens.LENGTH,
16
+ UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
17
+ NUMBER = _tokenTypes.tokens.NUMBER,
18
+ SLASH = _tokenTypes.tokens.SLASH;
15
19
  var NORMAL = (0, _tokenTypes.regExpToken)(/^(normal)$/);
16
20
  var STYLE = (0, _tokenTypes.regExpToken)(/^(italic)$/);
17
21
  var WEIGHT = (0, _tokenTypes.regExpToken)(/^([1-9]00|bold)$/);
@@ -19,15 +23,16 @@ var VARIANT = (0, _tokenTypes.regExpToken)(/^(small-caps)$/);
19
23
  var defaultFontStyle = 'normal';
20
24
  var defaultFontWeight = 'normal';
21
25
  var defaultFontVariant = [];
26
+
22
27
  var _default = function _default(tokenStream) {
23
28
  var fontStyle;
24
29
  var fontWeight;
25
- var fontVariant;
26
- // let fontSize;
27
- var lineHeight;
28
- // let fontFamily;
30
+ var fontVariant; // let fontSize;
31
+
32
+ var lineHeight; // let fontFamily;
29
33
 
30
34
  var numStyleWeightVariantMatched = 0;
35
+
31
36
  while (numStyleWeightVariantMatched < 3 && tokenStream.hasTokens()) {
32
37
  if (tokenStream.matches(NORMAL)) {
33
38
  /* pass */
@@ -40,10 +45,13 @@ var _default = function _default(tokenStream) {
40
45
  } else {
41
46
  break;
42
47
  }
48
+
43
49
  tokenStream.expect(SPACE);
44
50
  numStyleWeightVariantMatched += 1;
45
51
  }
52
+
46
53
  var fontSize = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
54
+
47
55
  if (tokenStream.matches(SLASH)) {
48
56
  if (tokenStream.matches(NUMBER)) {
49
57
  var size = typeof fontSize === 'string' ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') : fontSize;
@@ -52,6 +60,7 @@ var _default = function _default(tokenStream) {
52
60
  lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
53
61
  }
54
62
  }
63
+
55
64
  tokenStream.expect(SPACE);
56
65
  var fontFamily = (0, _fontFamily["default"])(tokenStream);
57
66
  if (typeof fontStyle === 'undefined') fontStyle = defaultFontStyle;
@@ -69,4 +78,5 @@ var _default = function _default(tokenStream) {
69
78
  $merge: out
70
79
  };
71
80
  };
81
+
72
82
  exports["default"] = _default;
@@ -4,23 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var SPACE = _tokenTypes.tokens.SPACE,
9
- IDENT = _tokenTypes.tokens.IDENT,
10
- STRING = _tokenTypes.tokens.STRING;
11
+ IDENT = _tokenTypes.tokens.IDENT,
12
+ STRING = _tokenTypes.tokens.STRING;
13
+
11
14
  var _default = function _default(tokenStream) {
12
15
  var fontFamily;
16
+
13
17
  if (tokenStream.matches(STRING)) {
14
18
  fontFamily = tokenStream.lastValue;
15
19
  } else {
16
20
  fontFamily = tokenStream.expect(IDENT);
21
+
17
22
  while (tokenStream.hasTokens()) {
18
23
  tokenStream.expect(SPACE);
19
24
  var nextIdent = tokenStream.expect(IDENT);
20
25
  fontFamily += " ".concat(nextIdent);
21
26
  }
22
27
  }
28
+
23
29
  tokenStream.expectEmpty();
24
30
  return fontFamily;
25
31
  };
32
+
26
33
  exports["default"] = _default;
@@ -4,25 +4,39 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var _border = require("./border");
11
+
9
12
  var _boxShadow = _interopRequireDefault(require("./boxShadow"));
13
+
10
14
  var _flex = _interopRequireDefault(require("./flex"));
15
+
11
16
  var _font = _interopRequireDefault(require("./font"));
17
+
12
18
  var _fontFamily = _interopRequireDefault(require("./fontFamily"));
19
+
13
20
  var _textDecoration = _interopRequireDefault(require("./textDecoration"));
21
+
14
22
  var _textDecorationLine = _interopRequireDefault(require("./textDecorationLine"));
23
+
15
24
  var _textShadow = _interopRequireDefault(require("./textShadow"));
25
+
16
26
  var _transform = _interopRequireDefault(require("./transform"));
27
+
17
28
  var _util = require("./util");
29
+
18
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
+
19
32
  var IDENT = _tokenTypes.tokens.IDENT,
20
- WORD = _tokenTypes.tokens.WORD,
21
- COLOR = _tokenTypes.tokens.COLOR,
22
- LENGTH = _tokenTypes.tokens.LENGTH,
23
- UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
24
- PERCENT = _tokenTypes.tokens.PERCENT,
25
- AUTO = _tokenTypes.tokens.AUTO;
33
+ WORD = _tokenTypes.tokens.WORD,
34
+ COLOR = _tokenTypes.tokens.COLOR,
35
+ LENGTH = _tokenTypes.tokens.LENGTH,
36
+ UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
37
+ PERCENT = _tokenTypes.tokens.PERCENT,
38
+ AUTO = _tokenTypes.tokens.AUTO;
39
+
26
40
  var background = function background(tokenStream) {
27
41
  return {
28
42
  $merge: {
@@ -30,6 +44,7 @@ var background = function background(tokenStream) {
30
44
  }
31
45
  };
32
46
  };
47
+
33
48
  var margin = (0, _util.directionFactory)({
34
49
  types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
35
50
  prefix: 'margin'
@@ -47,12 +62,16 @@ var flexFlow = (0, _util.anyOrderFactory)({
47
62
  "default": 'row'
48
63
  }
49
64
  });
65
+
50
66
  var fontVariant = function fontVariant(tokenStream) {
51
67
  return [tokenStream.expect(IDENT)];
52
68
  };
69
+
53
70
  var fontWeight = function fontWeight(tokenStream) {
54
71
  return tokenStream.expect(WORD);
55
72
  }; // Also match numbers as strings
73
+
74
+
56
75
  var shadowOffset = (0, _util.shadowOffsetFactory)();
57
76
  var textShadowOffset = (0, _util.shadowOffsetFactory)();
58
77
  var _default = {
@@ -4,31 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var SPACE = _tokenTypes.tokens.SPACE,
9
- LINE = _tokenTypes.tokens.LINE,
10
- COLOR = _tokenTypes.tokens.COLOR;
11
+ LINE = _tokenTypes.tokens.LINE,
12
+ COLOR = _tokenTypes.tokens.COLOR;
11
13
  var STYLE = (0, _tokenTypes.regExpToken)(/^(solid|double|dotted|dashed)$/);
12
14
  var defaultTextDecorationLine = 'none';
13
15
  var defaultTextDecorationStyle = 'solid';
14
16
  var defaultTextDecorationColor = 'black';
17
+
15
18
  var _default = function _default(tokenStream) {
16
19
  var line;
17
20
  var style;
18
21
  var color;
19
22
  var didParseFirst = false;
23
+
20
24
  while (tokenStream.hasTokens()) {
21
25
  if (didParseFirst) tokenStream.expect(SPACE);
26
+
22
27
  if (typeof line === 'undefined' && tokenStream.matches(LINE)) {
23
28
  var lines = [tokenStream.lastValue.toLowerCase()];
24
29
  tokenStream.saveRewindPoint();
30
+
25
31
  if (lines[0] !== 'none' && tokenStream.matches(SPACE) && tokenStream.matches(LINE)) {
26
- lines.push(tokenStream.lastValue.toLowerCase());
27
- // Underline comes before line-through
32
+ lines.push(tokenStream.lastValue.toLowerCase()); // Underline comes before line-through
33
+
28
34
  lines.sort().reverse();
29
35
  } else {
30
36
  tokenStream.rewind();
31
37
  }
38
+
32
39
  line = lines.join(' ');
33
40
  } else if (typeof style === 'undefined' && tokenStream.matches(STYLE)) {
34
41
  style = tokenStream.lastValue;
@@ -37,8 +44,10 @@ var _default = function _default(tokenStream) {
37
44
  } else {
38
45
  tokenStream["throw"]();
39
46
  }
47
+
40
48
  didParseFirst = true;
41
49
  }
50
+
42
51
  var $merge = {
43
52
  textDecorationLine: typeof line !== 'undefined' ? line : defaultTextDecorationLine,
44
53
  textDecorationColor: typeof color !== 'undefined' ? color : defaultTextDecorationColor,
@@ -48,4 +57,5 @@ var _default = function _default(tokenStream) {
48
57
  $merge: $merge
49
58
  };
50
59
  };
60
+
51
61
  exports["default"] = _default;
@@ -4,18 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
9
+
8
10
  var SPACE = _tokenTypes.tokens.SPACE,
9
- LINE = _tokenTypes.tokens.LINE;
11
+ LINE = _tokenTypes.tokens.LINE;
12
+
10
13
  var _default = function _default(tokenStream) {
11
14
  var lines = [];
12
15
  var didParseFirst = false;
16
+
13
17
  while (tokenStream.hasTokens()) {
14
18
  if (didParseFirst) tokenStream.expect(SPACE);
15
19
  lines.push(tokenStream.expect(LINE).toLowerCase());
16
20
  didParseFirst = true;
17
21
  }
22
+
18
23
  lines.sort().reverse();
19
24
  return lines.join(' ');
20
25
  };
26
+
21
27
  exports["default"] = _default;
@@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _util = require("./util");
9
+
8
10
  var _default = function _default(tokenStream) {
9
11
  var _parseShadow = (0, _util.parseShadow)(tokenStream),
10
- offset = _parseShadow.offset,
11
- radius = _parseShadow.radius,
12
- color = _parseShadow.color;
12
+ offset = _parseShadow.offset,
13
+ radius = _parseShadow.radius,
14
+ color = _parseShadow.color;
15
+
13
16
  return {
14
17
  $merge: {
15
18
  textShadowOffset: offset,
@@ -18,4 +21,5 @@ var _default = function _default(tokenStream) {
18
21
  }
19
22
  };
20
23
  };
24
+
21
25
  exports["default"] = _default;
@@ -4,16 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+
7
8
  var _tokenTypes = require("../tokenTypes");
8
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
12
  var SPACE = _tokenTypes.tokens.SPACE,
13
- COMMA = _tokenTypes.tokens.COMMA,
14
- LENGTH = _tokenTypes.tokens.LENGTH,
15
- NUMBER = _tokenTypes.tokens.NUMBER,
16
- ANGLE = _tokenTypes.tokens.ANGLE;
13
+ COMMA = _tokenTypes.tokens.COMMA,
14
+ LENGTH = _tokenTypes.tokens.LENGTH,
15
+ NUMBER = _tokenTypes.tokens.NUMBER,
16
+ ANGLE = _tokenTypes.tokens.ANGLE;
17
+
17
18
  var oneOfType = function oneOfType(tokenType) {
18
19
  return function (functionStream) {
19
20
  var value = functionStream.expect(tokenType);
@@ -21,14 +22,17 @@ var oneOfType = function oneOfType(tokenType) {
21
22
  return value;
22
23
  };
23
24
  };
25
+
24
26
  var singleNumber = oneOfType(NUMBER);
25
27
  var singleLength = oneOfType(LENGTH);
26
28
  var singleAngle = oneOfType(ANGLE);
29
+
27
30
  var xyTransformFactory = function xyTransformFactory(tokenType) {
28
31
  return function (key, valueIfOmitted) {
29
32
  return function (functionStream) {
30
33
  var x = functionStream.expect(tokenType);
31
34
  var y;
35
+
32
36
  if (functionStream.hasTokens()) {
33
37
  functionStream.expect(COMMA);
34
38
  y = functionStream.expect(tokenType);
@@ -39,11 +43,13 @@ var xyTransformFactory = function xyTransformFactory(tokenType) {
39
43
  // I.e. scale(5) => [{ scale: 5 }] rather than [{ scaleX: 5 }, { scaleY: 5 }]
40
44
  return x;
41
45
  }
46
+
42
47
  functionStream.expectEmpty();
43
48
  return [_defineProperty({}, "".concat(key, "Y"), y), _defineProperty({}, "".concat(key, "X"), x)];
44
49
  };
45
50
  };
46
51
  };
52
+
47
53
  var xyNumber = xyTransformFactory(NUMBER);
48
54
  var xyLength = xyTransformFactory(LENGTH);
49
55
  var xyAngle = xyTransformFactory(ANGLE);
@@ -63,20 +69,26 @@ var partTransforms = {
63
69
  skewY: singleAngle,
64
70
  skew: xyAngle('skew', '0deg')
65
71
  };
72
+
66
73
  var _default = function _default(tokenStream) {
67
74
  var transforms = [];
68
75
  var didParseFirst = false;
76
+
69
77
  while (tokenStream.hasTokens()) {
70
78
  if (didParseFirst) tokenStream.expect(SPACE);
71
79
  var functionStream = tokenStream.expectFunction();
72
80
  var functionName = functionStream.functionName;
73
81
  var transformedValues = partTransforms[functionName](functionStream);
82
+
74
83
  if (!Array.isArray(transformedValues)) {
75
84
  transformedValues = [_defineProperty({}, functionName, transformedValues)];
76
85
  }
86
+
77
87
  transforms = transformedValues.concat(transforms);
78
88
  didParseFirst = true;
79
89
  }
90
+
80
91
  return transforms;
81
92
  };
93
+
82
94
  exports["default"] = _default;
@@ -1,72 +1,87 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.shadowOffsetFactory = exports.parseShadow = exports.directionFactory = exports.anyOrderFactory = void 0;
7
+
8
8
  var _tokenTypes = require("../tokenTypes");
9
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
12
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+
13
14
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+
14
16
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+
15
18
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
+
16
20
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
21
+
17
22
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
+
18
24
  var LENGTH = _tokenTypes.tokens.LENGTH,
19
- UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
20
- PERCENT = _tokenTypes.tokens.PERCENT,
21
- COLOR = _tokenTypes.tokens.COLOR,
22
- SPACE = _tokenTypes.tokens.SPACE,
23
- NONE = _tokenTypes.tokens.NONE;
25
+ UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT,
26
+ PERCENT = _tokenTypes.tokens.PERCENT,
27
+ COLOR = _tokenTypes.tokens.COLOR,
28
+ SPACE = _tokenTypes.tokens.SPACE,
29
+ NONE = _tokenTypes.tokens.NONE;
30
+
24
31
  var directionFactory = function directionFactory(_ref) {
25
32
  var _ref$types = _ref.types,
26
- types = _ref$types === void 0 ? [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT] : _ref$types,
27
- _ref$directions = _ref.directions,
28
- directions = _ref$directions === void 0 ? ['Top', 'Right', 'Bottom', 'Left'] : _ref$directions,
29
- _ref$prefix = _ref.prefix,
30
- prefix = _ref$prefix === void 0 ? '' : _ref$prefix,
31
- _ref$suffix = _ref.suffix,
32
- suffix = _ref$suffix === void 0 ? '' : _ref$suffix;
33
+ types = _ref$types === void 0 ? [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT] : _ref$types,
34
+ _ref$directions = _ref.directions,
35
+ directions = _ref$directions === void 0 ? ['Top', 'Right', 'Bottom', 'Left'] : _ref$directions,
36
+ _ref$prefix = _ref.prefix,
37
+ prefix = _ref$prefix === void 0 ? '' : _ref$prefix,
38
+ _ref$suffix = _ref.suffix,
39
+ suffix = _ref$suffix === void 0 ? '' : _ref$suffix;
33
40
  return function (tokenStream) {
34
41
  var _output;
35
- var values = [];
36
42
 
37
- // borderWidth doesn't currently allow a percent value, but may do in the future
43
+ var values = []; // borderWidth doesn't currently allow a percent value, but may do in the future
44
+
38
45
  values.push(tokenStream.expect.apply(tokenStream, _toConsumableArray(types)));
46
+
39
47
  while (values.length < 4 && tokenStream.hasTokens()) {
40
48
  tokenStream.expect(SPACE);
41
49
  values.push(tokenStream.expect.apply(tokenStream, _toConsumableArray(types)));
42
50
  }
51
+
43
52
  tokenStream.expectEmpty();
44
53
  var top = values[0],
45
- _values$ = values[1],
46
- right = _values$ === void 0 ? top : _values$,
47
- _values$2 = values[2],
48
- bottom = _values$2 === void 0 ? top : _values$2,
49
- _values$3 = values[3],
50
- left = _values$3 === void 0 ? right : _values$3;
54
+ _values$ = values[1],
55
+ right = _values$ === void 0 ? top : _values$,
56
+ _values$2 = values[2],
57
+ bottom = _values$2 === void 0 ? top : _values$2,
58
+ _values$3 = values[3],
59
+ left = _values$3 === void 0 ? right : _values$3;
60
+
51
61
  var keyFor = function keyFor(n) {
52
62
  return "".concat(prefix).concat(directions[n]).concat(suffix);
53
63
  };
64
+
54
65
  var output = (_output = {}, _defineProperty(_output, keyFor(0), top), _defineProperty(_output, keyFor(1), right), _defineProperty(_output, keyFor(2), bottom), _defineProperty(_output, keyFor(3), left), _output);
55
66
  return {
56
67
  $merge: output
57
68
  };
58
69
  };
59
70
  };
71
+
60
72
  exports.directionFactory = directionFactory;
73
+
61
74
  var anyOrderFactory = function anyOrderFactory(properties) {
62
75
  var delim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SPACE;
63
76
  return function (tokenStream) {
64
77
  var propertyNames = Object.keys(properties);
65
78
  var values = propertyNames.reduce(function (accum, propertyName) {
66
79
  typeof accum[propertyName] === 'undefined'; // eslint-disable-line
80
+
67
81
  return accum;
68
82
  }, {});
69
83
  var numParsed = 0;
84
+
70
85
  while (numParsed < propertyNames.length && tokenStream.hasTokens()) {
71
86
  if (numParsed) tokenStream.expect(delim);
72
87
  var matchedPropertyName = propertyNames.find(function (propertyName) {
@@ -74,13 +89,16 @@ var anyOrderFactory = function anyOrderFactory(properties) {
74
89
  return tokenStream.matches(token);
75
90
  });
76
91
  });
92
+
77
93
  if (!matchedPropertyName) {
78
94
  tokenStream["throw"]();
79
95
  } else {
80
96
  values[matchedPropertyName] = tokenStream.lastValue;
81
97
  }
98
+
82
99
  numParsed += 1;
83
100
  }
101
+
84
102
  tokenStream.expectEmpty();
85
103
  propertyNames.forEach(function (propertyName) {
86
104
  if (typeof values[propertyName] === 'undefined') {
@@ -92,7 +110,9 @@ var anyOrderFactory = function anyOrderFactory(properties) {
92
110
  };
93
111
  };
94
112
  };
113
+
95
114
  exports.anyOrderFactory = anyOrderFactory;
115
+
96
116
  var shadowOffsetFactory = function shadowOffsetFactory() {
97
117
  return function (tokenStream) {
98
118
  var width = tokenStream.expect(LENGTH);
@@ -104,12 +124,15 @@ var shadowOffsetFactory = function shadowOffsetFactory() {
104
124
  };
105
125
  };
106
126
  };
127
+
107
128
  exports.shadowOffsetFactory = shadowOffsetFactory;
129
+
108
130
  var parseShadow = function parseShadow(tokenStream) {
109
131
  var offsetX;
110
132
  var offsetY;
111
133
  var radius;
112
134
  var color;
135
+
113
136
  if (tokenStream.matches(NONE)) {
114
137
  tokenStream.expectEmpty();
115
138
  return {
@@ -121,27 +144,34 @@ var parseShadow = function parseShadow(tokenStream) {
121
144
  color: 'black'
122
145
  };
123
146
  }
147
+
124
148
  var didParseFirst = false;
149
+
125
150
  while (tokenStream.hasTokens()) {
126
151
  if (didParseFirst) tokenStream.expect(SPACE);
152
+
127
153
  if (typeof offsetX === 'undefined' && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
128
154
  offsetX = tokenStream.lastValue;
155
+
129
156
  if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
130
157
  offsetY = tokenStream.lastValue;
131
158
  } else {
132
159
  offsetY = offsetX;
133
160
  tokenStream.rewind();
134
161
  }
162
+
135
163
  tokenStream.saveRewindPoint();
164
+
136
165
  if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
137
166
  // blur-radius
138
167
  radius = tokenStream.lastValue;
139
168
  } else {
140
169
  tokenStream.rewind();
141
170
  }
171
+
142
172
  tokenStream.saveRewindPoint();
143
- if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
144
- // spread-radius
173
+
174
+ if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {// spread-radius
145
175
  // 兼容web写法,防止报错
146
176
  } else {
147
177
  tokenStream.rewind();
@@ -151,8 +181,10 @@ var parseShadow = function parseShadow(tokenStream) {
151
181
  } else {
152
182
  tokenStream["throw"]();
153
183
  }
184
+
154
185
  didParseFirst = true;
155
186
  }
187
+
156
188
  if (typeof offsetX === 'undefined') tokenStream["throw"]();
157
189
  return {
158
190
  offset: {
@@ -163,4 +195,5 @@ var parseShadow = function parseShadow(tokenStream) {
163
195
  color: typeof color !== 'undefined' ? color : 'black'
164
196
  };
165
197
  };
198
+
166
199
  exports.parseShadow = parseShadow;
package/dist/index.js CHANGED
@@ -10,24 +10,38 @@ Object.defineProperty(exports, "transformCSS", {
10
10
  return _cssToReactNative["default"];
11
11
  }
12
12
  });
13
+
13
14
  var _parse = _interopRequireDefault(require("css/lib/parse"));
15
+
14
16
  var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
17
+
15
18
  var _cssToReactNative = _interopRequireDefault(require("./css-to-react-native"));
19
+
16
20
  var _features = require("./transforms/media-queries/features");
21
+
17
22
  var _types = require("./transforms/media-queries/types");
23
+
18
24
  var _rem = require("./transforms/rem");
25
+
19
26
  var _allEqual = require("./utils/allEqual");
27
+
20
28
  var _camelCase = require("./utils/camelCase");
29
+
21
30
  var _sortRules = require("./utils/sortRules");
31
+
22
32
  var _values = require("./utils/values");
33
+
23
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
35
+
24
36
  var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px|rem$))/;
25
37
  var viewportUnitRe = /^([+-]?[0-9.]+)(vh|vw|vmin|vmax)$/;
26
38
  var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
27
39
  var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/;
28
40
  var shorthandBorderProps = ['border-radius', 'border-width', 'border-color', 'border-style'];
41
+
29
42
  var transformDecls = function transformDecls(styles, declarations, result) {
30
43
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
44
+
31
45
  for (var d in declarations) {
32
46
  var declaration = declarations[d];
33
47
  if (declaration.type !== 'declaration') continue;
@@ -37,27 +51,33 @@ var transformDecls = function transformDecls(styles, declarations, result) {
37
51
  var isViewportUnit = viewportUnitRe.test(value);
38
52
  var isPercent = percentRe.test(value);
39
53
  var isUnsupportedUnit = unsupportedUnitRe.test(value);
54
+
40
55
  if (property === 'line-height' && !isLengthUnit && !isViewportUnit && !isPercent && !isUnsupportedUnit) {
41
56
  // ignore invalid value avoid throw error cause app crash
42
57
  continue;
43
58
  }
59
+
44
60
  if (!result.__viewportUnits && isViewportUnit) {
45
61
  result.__viewportUnits = true;
46
- }
47
- // scalable option, when it is false, transform single value 'px' unit to 'PX'
62
+ } // scalable option, when it is false, transform single value 'px' unit to 'PX'
48
63
  // do not be wrapped by scalePx2dp function
64
+
65
+
49
66
  if (typeof options.scalable === 'boolean' && !options.scalable && /(\d+)px/.test(value)) {
50
67
  value = value.replace(/(\d+)px/g, '$1PX');
51
- }
52
- // expect value is legal so that remove !import
68
+ } // expect value is legal so that remove !import
69
+
70
+
53
71
  if (/!import/i.test(value)) {
54
72
  value = value.replace(/!import/, '');
55
73
  }
74
+
56
75
  if (shorthandBorderProps.indexOf(property) > -1) {
57
76
  // transform single value shorthand border properties back to
58
77
  // shorthand form to support styling `Image`.
59
78
  var transformed = (0, _cssToReactNative["default"])([[property, value]]);
60
79
  var vals = (0, _values.values)(transformed);
80
+
61
81
  if ((0, _allEqual.allEqual)(vals)) {
62
82
  var replacement = {};
63
83
  replacement[(0, _camelCase.camelCase)(property)] = vals[0];
@@ -70,48 +90,62 @@ var transformDecls = function transformDecls(styles, declarations, result) {
70
90
  }
71
91
  }
72
92
  };
93
+
73
94
  var transform = function transform(css, options) {
74
95
  var _parseCSS = (0, _parse["default"])(css),
75
- stylesheet = _parseCSS.stylesheet;
96
+ stylesheet = _parseCSS.stylesheet;
97
+
76
98
  var rules = (0, _sortRules.sortRules)(stylesheet.rules);
77
99
  var result = {};
100
+
78
101
  for (var r in rules) {
79
102
  var rule = rules[r];
103
+
80
104
  for (var s in rule.selectors) {
81
105
  if (rule.selectors[s] === ':export') {
82
106
  if (!result.__exportProps) {
83
107
  result.__exportProps = {};
84
108
  }
109
+
85
110
  rule.declarations.forEach(function (_ref) {
86
111
  var property = _ref.property,
87
- value = _ref.value;
112
+ value = _ref.value;
88
113
  var isAlreadyDefinedAsClass = typeof result[property] !== 'undefined' && typeof result.__exportProps[property] === 'undefined';
114
+
89
115
  if (isAlreadyDefinedAsClass) {
90
116
  throw new Error("Failed to parse :export block because a CSS class in the same file is already using the name \"".concat(property, "\""));
91
117
  }
118
+
92
119
  result.__exportProps[property] = value;
93
120
  });
94
121
  continue;
95
122
  }
123
+
96
124
  if (rule.selectors[s].indexOf('.') !== 0 || rule.selectors[s].indexOf(':') !== -1 || rule.selectors[s].indexOf('[') !== -1 || rule.selectors[s].indexOf('~') !== -1 || rule.selectors[s].indexOf('>') !== -1 || rule.selectors[s].indexOf('+') !== -1 || rule.selectors[s].indexOf(' ') !== -1) {
97
125
  continue;
98
126
  }
127
+
99
128
  var selector = rule.selectors[s].replace(/^\./, '');
100
129
  var styles = result[selector] = result[selector] || {};
101
130
  transformDecls(styles, rule.declarations, result, options);
102
131
  }
132
+
103
133
  if (rule.type === 'media' && options != null && options.parseMediaQueries === true) {
104
134
  var parsed = _cssMediaquery["default"].parse(rule.media);
135
+
105
136
  parsed.forEach(function (mq) {
106
137
  if (_types.mediaQueryTypes.indexOf(mq.type) === -1) {
107
138
  throw new Error("Failed to parse media query type \"".concat(mq.type, "\""));
108
139
  }
140
+
109
141
  mq.expressions.forEach(function (e) {
110
142
  var mf = e.modifier ? "".concat(e.modifier, "-").concat(e.feature) : e.feature;
111
143
  var val = e.value ? ": ".concat(e.value) : '';
144
+
112
145
  if (_features.mediaQueryFeatures.indexOf(e.feature) === -1) {
113
146
  throw new Error("Failed to parse media query feature \"".concat(mf, "\""));
114
147
  }
148
+
115
149
  if (_features.dimensionFeatures.indexOf(e.feature) > -1 && lengthRe.test(e.value) === false) {
116
150
  throw new Error("Failed to parse media query expression \"(".concat(mf).concat(val, ")\""));
117
151
  }
@@ -120,22 +154,29 @@ var transform = function transform(css, options) {
120
154
  var media = '@media ' + rule.media;
121
155
  result.__mediaQueries = result.__mediaQueries || {};
122
156
  result.__mediaQueries[media] = parsed;
157
+
123
158
  for (var _r in rule.rules) {
124
159
  var ruleRule = rule.rules[_r];
160
+
125
161
  for (var _s in ruleRule.selectors) {
126
162
  result[media] = result[media] || {};
163
+
127
164
  var _selector = ruleRule.selectors[_s].replace(/^\./, '');
165
+
128
166
  var mediaStyles = result[media][_selector] = result[media][_selector] || {};
129
167
  transformDecls(mediaStyles, ruleRule.declarations, result, options);
130
168
  }
131
169
  }
132
170
  }
133
171
  }
172
+
134
173
  if (result.__exportProps) {
135
174
  Object.assign(result, result.__exportProps);
136
175
  delete result.__exportProps;
137
176
  }
177
+
138
178
  return result;
139
179
  };
180
+
140
181
  var _default = transform;
141
182
  exports["default"] = _default;
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.remToPx = void 0;
7
+
7
8
  var remToPx = function remToPx(value) {
8
9
  return value.replace(/(\d*\.?\d+)rem/g, function (match, m1) {
9
10
  return parseFloat(m1, 10) * 16 + 'px';
10
11
  });
11
12
  };
13
+
12
14
  exports.remToPx = remToPx;
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.allEqual = void 0;
7
+
7
8
  var allEqual = function allEqual(arr) {
8
9
  return arr.every(function (v) {
9
10
  return v === arr[0];
10
11
  });
11
12
  };
13
+
12
14
  exports.allEqual = allEqual;
@@ -4,18 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.camelCase = camelCase;
7
+
7
8
  function camelCase(str) {
8
9
  // Lower cases the string
9
- return str.toLowerCase()
10
- // Replaces any - or _ characters with a space
11
- .replace(/[-_]+/g, ' ')
12
- // Removes any non alphanumeric characters
13
- .replace(/[^\w\s]/g, '')
14
- // Uppercase the first character in each group immediately following a space
10
+ return str.toLowerCase() // Replaces any - or _ characters with a space
11
+ .replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters
12
+ .replace(/[^\w\s]/g, '') // Uppercase the first character in each group immediately following a space
15
13
  // (delimited by spaces)
16
14
  .replace(/ (.)/g, function ($1) {
17
15
  return $1.toUpperCase();
18
- })
19
- // Removes spaces
16
+ }) // Removes spaces
20
17
  .replace(/ /g, '');
21
18
  }
@@ -4,29 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sortRules = sortRules;
7
+
7
8
  function isExport(n) {
8
9
  return Array.isArray(n) && n[0] === ':export';
9
10
  }
11
+
10
12
  function byExport(a, b) {
11
13
  if (!isExport(a.selectors) && isExport(b.selectors)) {
12
14
  return -1;
13
15
  }
16
+
14
17
  if (isExport(a.selectors) && !isExport(b.selectors)) {
15
18
  return 1;
16
19
  }
20
+
17
21
  return 0;
18
22
  }
23
+
19
24
  function byLine(a, b) {
20
25
  if (isExport(a.selectors) && isExport(b.selectors)) {
21
26
  if (a.position.start.line > b.position.start.line) {
22
27
  return 1;
23
28
  }
29
+
24
30
  if (a.position.start.line < b.position.start.line) {
25
31
  return -1;
26
32
  }
27
33
  }
34
+
28
35
  return 0;
29
36
  }
37
+
30
38
  function sortRules(rules) {
31
39
  return rules.sort(byExport).sort(byLine);
32
40
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _sortRules = require("./sortRules");
4
+
4
5
  describe('sortRules', function () {
5
6
  it('should sort :export to be the last rule', function () {
6
7
  expect((0, _sortRules.sortRules)([{
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.values = void 0;
7
+
7
8
  var values = function values(obj) {
8
9
  return Object.keys(obj).map(function (key) {
9
10
  return obj[key];
10
11
  });
11
12
  };
13
+
12
14
  exports.values = values;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "taro-css-to-react-native",
3
3
  "description": "Convert CSS text to a React Native stylesheet object",
4
- "version": "3.6.0-beta.1",
4
+ "version": "3.6.0-beta.3",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {