taro-css-to-react-native 3.5.0-canary.1 → 3.5.0-theta.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.
@@ -9,7 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
9
9
 
10
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
11
 
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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; }
13
13
 
14
14
  var SYMBOL_MATCH = 'SYMBOL_MATCH';
15
15
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.getPropertyName = exports.getStylesForProperty = exports.transformRawValue = void 0;
6
+ exports.transformRawValue = exports.getStylesForProperty = exports.getPropertyName = exports["default"] = void 0;
7
7
 
8
8
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
9
 
@@ -54,6 +54,24 @@ var valueForTypeToken = function valueForTypeToken(type) {
54
54
  };
55
55
  };
56
56
 
57
+ var functionValueForTypeToken = function functionValueForTypeToken(type) {
58
+ return function (node) {
59
+ if (node.type === type) {
60
+ // handle rgb(a) function value
61
+ if (/^rgba?$/i.test(node.value)) {
62
+ var result = node.nodes.filter(function (token) {
63
+ return token.type === 'word';
64
+ }).map(function (token) {
65
+ return token.value;
66
+ });
67
+ return "".concat(node.value, "(").concat(result.join(', '), ")");
68
+ }
69
+ }
70
+
71
+ return null;
72
+ };
73
+ };
74
+
57
75
  var regExpToken = function regExpToken(regExp) {
58
76
  var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String;
59
77
  return function (node) {
@@ -82,6 +100,7 @@ var tokens = {
82
100
  return node.type === 'div' && node.value === ',';
83
101
  }),
84
102
  WORD: valueForTypeToken('word'),
103
+ FUNC: functionValueForTypeToken('function'),
85
104
  NONE: regExpToken(noneRe),
86
105
  AUTO: regExpToken(autoRe),
87
106
  NUMBER: regExpToken(numberRe, Number),
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.borderWidth = exports.borderTop = exports.borderRight = exports.borderRadius = exports.borderLeft = exports.borderColor = exports.borderBottom = exports.border = void 0;
7
+
8
+ var _tokenTypes = require("../tokenTypes");
9
+
10
+ var _util = require("./util");
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
+
14
+ var WORD = _tokenTypes.tokens.WORD,
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
+
20
+ function borderDirectionFactory() {
21
+ var _anyOrderFactory;
22
+
23
+ var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
24
+ var prefix = "border".concat(direction);
25
+ return (0, _util.anyOrderFactory)((_anyOrderFactory = {}, _defineProperty(_anyOrderFactory, "".concat(prefix, "Width"), {
26
+ tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
27
+ "default": 1
28
+ }), _defineProperty(_anyOrderFactory, "".concat(prefix, "Color"), {
29
+ tokens: [COLOR],
30
+ "default": 'black'
31
+ }), _defineProperty(_anyOrderFactory, "".concat(prefix, "Style"), {
32
+ tokens: [(0, _tokenTypes.regExpToken)(/^(solid|dashed|dotted)$/)],
33
+ "default": 'solid'
34
+ }), _anyOrderFactory));
35
+ }
36
+
37
+ var border = borderDirectionFactory();
38
+ exports.border = border;
39
+ var borderTop = borderDirectionFactory('Top');
40
+ exports.borderTop = borderTop;
41
+ var borderRight = borderDirectionFactory('Right');
42
+ exports.borderRight = borderRight;
43
+ var borderBottom = borderDirectionFactory('Bottom');
44
+ exports.borderBottom = borderBottom;
45
+ var borderLeft = borderDirectionFactory('Left');
46
+ exports.borderLeft = borderLeft;
47
+ var borderColor = (0, _util.directionFactory)({
48
+ types: [WORD, FUNC],
49
+ prefix: 'border',
50
+ suffix: 'Color'
51
+ });
52
+ exports.borderColor = borderColor;
53
+ var borderRadius = (0, _util.directionFactory)({
54
+ directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
55
+ prefix: 'border',
56
+ suffix: 'Radius'
57
+ });
58
+ exports.borderRadius = borderRadius;
59
+ var borderWidth = (0, _util.directionFactory)({
60
+ prefix: 'border',
61
+ suffix: 'Width'
62
+ });
63
+ exports.borderWidth = borderWidth;
@@ -23,6 +23,8 @@ var _textDecorationLine = _interopRequireDefault(require("./textDecorationLine")
23
23
 
24
24
  var _transform = _interopRequireDefault(require("./transform"));
25
25
 
26
+ var _border = require("./border");
27
+
26
28
  var _util = require("./util");
27
29
 
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -43,34 +45,6 @@ var background = function background(tokenStream) {
43
45
  };
44
46
  };
45
47
 
46
- var border = (0, _util.anyOrderFactory)({
47
- borderWidth: {
48
- tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
49
- "default": 1
50
- },
51
- borderColor: {
52
- tokens: [COLOR],
53
- "default": 'black'
54
- },
55
- borderStyle: {
56
- tokens: [(0, _tokenTypes.regExpToken)(/^(solid|dashed|dotted)$/)],
57
- "default": 'solid'
58
- }
59
- });
60
- var borderColor = (0, _util.directionFactory)({
61
- types: [WORD],
62
- prefix: 'border',
63
- suffix: 'Color'
64
- });
65
- var borderRadius = (0, _util.directionFactory)({
66
- directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
67
- prefix: 'border',
68
- suffix: 'Radius'
69
- });
70
- var borderWidth = (0, _util.directionFactory)({
71
- prefix: 'border',
72
- suffix: 'Width'
73
- });
74
48
  var margin = (0, _util.directionFactory)({
75
49
  types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
76
50
  prefix: 'margin'
@@ -102,10 +76,14 @@ var shadowOffset = (0, _util.shadowOffsetFactory)();
102
76
  var textShadowOffset = (0, _util.shadowOffsetFactory)();
103
77
  var _default = {
104
78
  background: background,
105
- border: border,
106
- borderColor: borderColor,
107
- borderRadius: borderRadius,
108
- borderWidth: borderWidth,
79
+ border: _border.border,
80
+ borderTop: _border.borderTop,
81
+ borderRight: _border.borderRight,
82
+ borderBottom: _border.borderBottom,
83
+ borderLeft: _border.borderLeft,
84
+ borderColor: _border.borderColor,
85
+ borderRadius: _border.borderRadius,
86
+ borderWidth: _border.borderWidth,
109
87
  boxShadow: _boxShadow["default"],
110
88
  flex: _flex["default"],
111
89
  flexFlow: flexFlow,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.parseShadow = exports.shadowOffsetFactory = exports.anyOrderFactory = exports.directionFactory = void 0;
6
+ exports.shadowOffsetFactory = exports.parseShadow = exports.directionFactory = exports.anyOrderFactory = void 0;
7
7
 
8
8
  var _tokenTypes = require("../tokenTypes");
9
9
 
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports["default"] = void 0;
6
7
  Object.defineProperty(exports, "transformCSS", {
7
8
  enumerable: true,
8
9
  get: function get() {
9
10
  return _cssToReactNative["default"];
10
11
  }
11
12
  });
12
- exports["default"] = void 0;
13
13
 
14
14
  var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
15
15
 
@@ -53,7 +53,8 @@ var transformDecls = function transformDecls(styles, declarations, result) {
53
53
  var isUnsupportedUnit = unsupportedUnitRe.test(value);
54
54
 
55
55
  if (property === 'line-height' && !isLengthUnit && !isViewportUnit && !isPercent && !isUnsupportedUnit) {
56
- throw new Error("Failed to parse declaration \"".concat(property, ": ").concat(value, "\""));
56
+ // ignore invalid value avoid throw error cause app crash
57
+ continue;
57
58
  }
58
59
 
59
60
  if (!result.__viewportUnits && isViewportUnit) {
@@ -62,8 +63,13 @@ var transformDecls = function transformDecls(styles, declarations, result) {
62
63
  // do not be wrapped by scalePx2dp function
63
64
 
64
65
 
65
- if (isLengthUnit && typeof options.scalable === 'boolean' && !options.scalable && /(\d+)px/.test(value)) {
66
- value = value.replace(/(\d+)px/, '$1PX');
66
+ if (typeof options.scalable === 'boolean' && !options.scalable && /(\d+)px/.test(value)) {
67
+ value = value.replace(/(\d+)px/g, '$1PX');
68
+ } // expect value is legal so that remove !import
69
+
70
+
71
+ if (/!import/i.test(value)) {
72
+ value = value.replace(/!import/, '');
67
73
  }
68
74
 
69
75
  if (shorthandBorderProps.indexOf(property) > -1) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mediaQueryTypes = exports.reactNativeMediaQueryTypes = exports.cssnextMediaQueryTypes = exports.defaultTypes = void 0;
6
+ exports.reactNativeMediaQueryTypes = exports.mediaQueryTypes = exports.defaultTypes = exports.cssnextMediaQueryTypes = void 0;
7
7
  var defaultTypes = ['all', 'braille', 'embossed', 'handheld', 'print', 'projection', 'screen', 'speech', 'tty', 'tv'];
8
8
  exports.defaultTypes = defaultTypes;
9
9
  var cssnextMediaQueryTypes = ['pointer', 'hover', 'block-overflow'];
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.5.0-canary.1",
4
+ "version": "3.5.0-theta.0",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -62,6 +62,5 @@
62
62
  "index.d.ts",
63
63
  "CHANGELOG.md",
64
64
  "README.md"
65
- ],
66
- "gitHead": "c61624d2f763e6d31e67d6cf9c564efc8b0d0887"
65
+ ]
67
66
  }
@@ -38,6 +38,20 @@ const noopToken = predicate => node => (predicate(node) ? '<token>' : null)
38
38
 
39
39
  const valueForTypeToken = type => node => (node.type === type ? node.value : null)
40
40
 
41
+ const functionValueForTypeToken = type => node => {
42
+ if (node.type === type) {
43
+ // handle rgb(a) function value
44
+ if (/^rgba?$/i.test(node.value)) {
45
+ const result = node.nodes
46
+ .filter(token => token.type === 'word')
47
+ .map(token => token.value)
48
+
49
+ return `${node.value}(${result.join(', ')})`
50
+ }
51
+ }
52
+ return null
53
+ }
54
+
41
55
  export const regExpToken = (regExp, transform = String) => node => {
42
56
  if (node.type !== 'word') return null
43
57
 
@@ -57,6 +71,7 @@ export const tokens = {
57
71
  SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
58
72
  COMMA: noopToken(node => node.type === 'div' && node.value === ','),
59
73
  WORD: valueForTypeToken('word'),
74
+ FUNC: functionValueForTypeToken('function'),
60
75
  NONE: regExpToken(noneRe),
61
76
  AUTO: regExpToken(autoRe),
62
77
  NUMBER: regExpToken(numberRe, Number),
@@ -0,0 +1,49 @@
1
+ import { regExpToken, tokens } from '../tokenTypes'
2
+ import { directionFactory, anyOrderFactory } from './util'
3
+
4
+ const {
5
+ WORD,
6
+ FUNC,
7
+ COLOR,
8
+ LENGTH,
9
+ UNSUPPORTED_LENGTH_UNIT
10
+ } = tokens
11
+
12
+ function borderDirectionFactory (direction = '') {
13
+ const prefix = `border${direction}`
14
+ return anyOrderFactory({
15
+ [`${prefix}Width`]: {
16
+ tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
17
+ default: 1
18
+ },
19
+ [`${prefix}Color`]: {
20
+ tokens: [COLOR],
21
+ default: 'black'
22
+ },
23
+ [`${prefix}Style`]: {
24
+ tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
25
+ default: 'solid'
26
+ }
27
+ })
28
+ }
29
+
30
+ export const border = borderDirectionFactory()
31
+
32
+ export const borderTop = borderDirectionFactory('Top')
33
+ export const borderRight = borderDirectionFactory('Right')
34
+ export const borderBottom = borderDirectionFactory('Bottom')
35
+ export const borderLeft = borderDirectionFactory('Left')
36
+
37
+ export const borderColor = directionFactory({
38
+ types: [WORD, FUNC],
39
+ prefix: 'border',
40
+ suffix: 'Color'
41
+ })
42
+
43
+ export const borderRadius = directionFactory({
44
+ directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
45
+ prefix: 'border',
46
+ suffix: 'Radius'
47
+ })
48
+
49
+ export const borderWidth = directionFactory({ prefix: 'border', suffix: 'Width' })
@@ -7,6 +7,7 @@ import textShadow from './textShadow'
7
7
  import textDecoration from './textDecoration'
8
8
  import textDecorationLine from './textDecorationLine'
9
9
  import transform from './transform'
10
+ import { border, borderTop, borderRight, borderBottom, borderLeft, borderColor, borderRadius, borderWidth } from './border'
10
11
  import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'
11
12
 
12
13
  const {
@@ -22,31 +23,6 @@ const {
22
23
  const background = tokenStream => ({
23
24
  $merge: { backgroundColor: tokenStream.expect(COLOR) }
24
25
  })
25
- const border = anyOrderFactory({
26
- borderWidth: {
27
- tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
28
- default: 1
29
- },
30
- borderColor: {
31
- tokens: [COLOR],
32
- default: 'black'
33
- },
34
- borderStyle: {
35
- tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
36
- default: 'solid'
37
- }
38
- })
39
- const borderColor = directionFactory({
40
- types: [WORD],
41
- prefix: 'border',
42
- suffix: 'Color'
43
- })
44
- const borderRadius = directionFactory({
45
- directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
46
- prefix: 'border',
47
- suffix: 'Radius'
48
- })
49
- const borderWidth = directionFactory({ prefix: 'border', suffix: 'Width' })
50
26
  const margin = directionFactory({
51
27
  types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
52
28
  prefix: 'margin'
@@ -70,6 +46,10 @@ const textShadowOffset = shadowOffsetFactory()
70
46
  export default {
71
47
  background,
72
48
  border,
49
+ borderTop,
50
+ borderRight,
51
+ borderBottom,
52
+ borderLeft,
73
53
  borderColor,
74
54
  borderRadius,
75
55
  borderWidth,
package/src/index.js CHANGED
@@ -43,7 +43,8 @@ const transformDecls = (styles, declarations, result, options = {}) => {
43
43
  !isPercent &&
44
44
  !isUnsupportedUnit
45
45
  ) {
46
- throw new Error(`Failed to parse declaration "${property}: ${value}"`)
46
+ // ignore invalid value avoid throw error cause app crash
47
+ continue
47
48
  }
48
49
 
49
50
  if (!result.__viewportUnits && isViewportUnit) {
@@ -52,12 +53,15 @@ const transformDecls = (styles, declarations, result, options = {}) => {
52
53
  // scalable option, when it is false, transform single value 'px' unit to 'PX'
53
54
  // do not be wrapped by scalePx2dp function
54
55
  if (
55
- isLengthUnit &&
56
56
  typeof options.scalable === 'boolean' &&
57
57
  !options.scalable &&
58
58
  /(\d+)px/.test(value)
59
59
  ) {
60
- value = value.replace(/(\d+)px/, '$1PX')
60
+ value = value.replace(/(\d+)px/g, '$1PX')
61
+ }
62
+ // expect value is legal so that remove !import
63
+ if (/!import/i.test(value)) {
64
+ value = value.replace(/!import/, '')
61
65
  }
62
66
 
63
67
  if (shorthandBorderProps.indexOf(property) > -1) {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.