taro-css-to-react-native 3.5.0-theta.0 → 3.5.0-theta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/css-to-react-native/index.js +5 -5
- package/dist/css-to-react-native/tokenTypes.js +15 -15
- package/dist/css-to-react-native/transforms/border.js +14 -14
- package/dist/css-to-react-native/transforms/font.js +12 -12
- package/dist/css-to-react-native/transforms/index.js +8 -8
- package/dist/index.js +16 -16
- package/package.json +7 -7
- package/src/css-to-react-native/index.js +53 -43
- package/src/css-to-react-native/tokenTypes.js +49 -44
- package/src/css-to-react-native/transforms/border.js +26 -29
- package/src/css-to-react-native/transforms/font.js +46 -37
- package/src/css-to-react-native/transforms/index.js +37 -28
- package/src/index.js +92 -93
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformRawValue = exports.getStylesForProperty = exports.getPropertyName = exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
9
|
-
|
|
10
8
|
var _camelize = _interopRequireDefault(require("camelize"));
|
|
11
9
|
|
|
12
|
-
var
|
|
10
|
+
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
13
11
|
|
|
14
12
|
var _TokenStream = _interopRequireDefault(require("./TokenStream"));
|
|
15
13
|
|
|
14
|
+
var _index = _interopRequireDefault(require("./transforms/index"));
|
|
15
|
+
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
17
|
|
|
18
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; }
|
|
@@ -38,7 +38,7 @@ var transformRawValue = function transformRawValue(input) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
var boolMatch = input.match(boolRe);
|
|
41
|
-
if (boolMatch !== null) return boolMatch[0].toLowerCase() ===
|
|
41
|
+
if (boolMatch !== null) return boolMatch[0].toLowerCase() === "true";
|
|
42
42
|
var nullMatch = input.match(nullRe);
|
|
43
43
|
if (nullMatch !== null) return null;
|
|
44
44
|
var undefinedMatch = input.match(undefinedRe);
|
|
@@ -63,7 +63,7 @@ var checkBaseTransformShorthandValue = function checkBaseTransformShorthandValue
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
var transformShorthandValue = process.env.NODE_ENV ===
|
|
66
|
+
var transformShorthandValue = process.env.NODE_ENV === "production" ? baseTransformShorthandValue : checkBaseTransformShorthandValue;
|
|
67
67
|
|
|
68
68
|
var getStylesForProperty = function getStylesForProperty(propName, inputValue, allowShorthand) {
|
|
69
69
|
var isRawValue = allowShorthand === false || !(propName in _index["default"]);
|
|
@@ -5,26 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.tokens = exports.regExpToken = void 0;
|
|
7
7
|
|
|
8
|
-
var _postcssValueParser = require("postcss-value-parser");
|
|
9
|
-
|
|
10
8
|
var _cssColorKeywords = _interopRequireDefault(require("css-color-keywords"));
|
|
11
9
|
|
|
10
|
+
var _postcssValueParser = require("postcss-value-parser");
|
|
11
|
+
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
14
|
var matchString = function matchString(node) {
|
|
15
|
-
if (node.type !==
|
|
15
|
+
if (node.type !== "string") return null;
|
|
16
16
|
return node.value.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, function (match, charCode) {
|
|
17
17
|
return String.fromCharCode(parseInt(charCode, 16));
|
|
18
|
-
}).replace(/\\/g,
|
|
18
|
+
}).replace(/\\/g, "");
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
var hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i;
|
|
22
22
|
var cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/;
|
|
23
23
|
|
|
24
24
|
var matchColor = function matchColor(node) {
|
|
25
|
-
if (node.type ===
|
|
25
|
+
if (node.type === "word" && (hexColorRe.test(node.value) || node.value in _cssColorKeywords["default"] || node.value === "transparent")) {
|
|
26
26
|
return node.value;
|
|
27
|
-
} else if (node.type ===
|
|
27
|
+
} else if (node.type === "function" && cssFunctionNameRe.test(node.value)) {
|
|
28
28
|
return (0, _postcssValueParser.stringify)(node);
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -44,7 +44,7 @@ var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
|
|
|
44
44
|
|
|
45
45
|
var noopToken = function noopToken(predicate) {
|
|
46
46
|
return function (node) {
|
|
47
|
-
return predicate(node) ?
|
|
47
|
+
return predicate(node) ? "<token>" : null;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -60,11 +60,11 @@ var functionValueForTypeToken = function functionValueForTypeToken(type) {
|
|
|
60
60
|
// handle rgb(a) function value
|
|
61
61
|
if (/^rgba?$/i.test(node.value)) {
|
|
62
62
|
var result = node.nodes.filter(function (token) {
|
|
63
|
-
return token.type ===
|
|
63
|
+
return token.type === "word";
|
|
64
64
|
}).map(function (token) {
|
|
65
65
|
return token.value;
|
|
66
66
|
});
|
|
67
|
-
return "".concat(node.value, "(").concat(result.join(
|
|
67
|
+
return "".concat(node.value, "(").concat(result.join(", "), ")");
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -75,7 +75,7 @@ var functionValueForTypeToken = function functionValueForTypeToken(type) {
|
|
|
75
75
|
var regExpToken = function regExpToken(regExp) {
|
|
76
76
|
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String;
|
|
77
77
|
return function (node) {
|
|
78
|
-
if (node.type !==
|
|
78
|
+
if (node.type !== "word") return null;
|
|
79
79
|
var match = node.value.match(regExp);
|
|
80
80
|
if (match === null) return null;
|
|
81
81
|
var value = transform(match[1]);
|
|
@@ -91,16 +91,16 @@ var regExpToken = function regExpToken(regExp) {
|
|
|
91
91
|
exports.regExpToken = regExpToken;
|
|
92
92
|
var tokens = {
|
|
93
93
|
SPACE: noopToken(function (node) {
|
|
94
|
-
return node.type ===
|
|
94
|
+
return node.type === "space";
|
|
95
95
|
}),
|
|
96
96
|
SLASH: noopToken(function (node) {
|
|
97
|
-
return node.type ===
|
|
97
|
+
return node.type === "div" && node.value === "/";
|
|
98
98
|
}),
|
|
99
99
|
COMMA: noopToken(function (node) {
|
|
100
|
-
return node.type ===
|
|
100
|
+
return node.type === "div" && node.value === ",";
|
|
101
101
|
}),
|
|
102
|
-
WORD: valueForTypeToken(
|
|
103
|
-
FUNC: functionValueForTypeToken(
|
|
102
|
+
WORD: valueForTypeToken("word"),
|
|
103
|
+
FUNC: functionValueForTypeToken("function"),
|
|
104
104
|
NONE: regExpToken(noneRe),
|
|
105
105
|
AUTO: regExpToken(autoRe),
|
|
106
106
|
NUMBER: regExpToken(numberRe, Number),
|
|
@@ -20,44 +20,44 @@ var WORD = _tokenTypes.tokens.WORD,
|
|
|
20
20
|
function borderDirectionFactory() {
|
|
21
21
|
var _anyOrderFactory;
|
|
22
22
|
|
|
23
|
-
var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
23
|
+
var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
24
24
|
var prefix = "border".concat(direction);
|
|
25
25
|
return (0, _util.anyOrderFactory)((_anyOrderFactory = {}, _defineProperty(_anyOrderFactory, "".concat(prefix, "Width"), {
|
|
26
26
|
tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
|
|
27
27
|
"default": 1
|
|
28
28
|
}), _defineProperty(_anyOrderFactory, "".concat(prefix, "Color"), {
|
|
29
29
|
tokens: [COLOR],
|
|
30
|
-
"default":
|
|
30
|
+
"default": "black"
|
|
31
31
|
}), _defineProperty(_anyOrderFactory, "".concat(prefix, "Style"), {
|
|
32
32
|
tokens: [(0, _tokenTypes.regExpToken)(/^(solid|dashed|dotted)$/)],
|
|
33
|
-
"default":
|
|
33
|
+
"default": "solid"
|
|
34
34
|
}), _anyOrderFactory));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
var border = borderDirectionFactory();
|
|
38
38
|
exports.border = border;
|
|
39
|
-
var borderTop = borderDirectionFactory(
|
|
39
|
+
var borderTop = borderDirectionFactory("Top");
|
|
40
40
|
exports.borderTop = borderTop;
|
|
41
|
-
var borderRight = borderDirectionFactory(
|
|
41
|
+
var borderRight = borderDirectionFactory("Right");
|
|
42
42
|
exports.borderRight = borderRight;
|
|
43
|
-
var borderBottom = borderDirectionFactory(
|
|
43
|
+
var borderBottom = borderDirectionFactory("Bottom");
|
|
44
44
|
exports.borderBottom = borderBottom;
|
|
45
|
-
var borderLeft = borderDirectionFactory(
|
|
45
|
+
var borderLeft = borderDirectionFactory("Left");
|
|
46
46
|
exports.borderLeft = borderLeft;
|
|
47
47
|
var borderColor = (0, _util.directionFactory)({
|
|
48
48
|
types: [WORD, FUNC],
|
|
49
|
-
prefix:
|
|
50
|
-
suffix:
|
|
49
|
+
prefix: "border",
|
|
50
|
+
suffix: "Color"
|
|
51
51
|
});
|
|
52
52
|
exports.borderColor = borderColor;
|
|
53
53
|
var borderRadius = (0, _util.directionFactory)({
|
|
54
|
-
directions: [
|
|
55
|
-
prefix:
|
|
56
|
-
suffix:
|
|
54
|
+
directions: ["TopLeft", "TopRight", "BottomRight", "BottomLeft"],
|
|
55
|
+
prefix: "border",
|
|
56
|
+
suffix: "Radius"
|
|
57
57
|
});
|
|
58
58
|
exports.borderRadius = borderRadius;
|
|
59
59
|
var borderWidth = (0, _util.directionFactory)({
|
|
60
|
-
prefix:
|
|
61
|
-
suffix:
|
|
60
|
+
prefix: "border",
|
|
61
|
+
suffix: "Width"
|
|
62
62
|
});
|
|
63
63
|
exports.borderWidth = borderWidth;
|
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
var _fontFamily = _interopRequireDefault(require("./fontFamily"));
|
|
9
|
-
|
|
10
8
|
var _tokenTypes = require("../tokenTypes");
|
|
11
9
|
|
|
10
|
+
var _fontFamily = _interopRequireDefault(require("./fontFamily"));
|
|
11
|
+
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
14
|
var SPACE = _tokenTypes.tokens.SPACE,
|
|
@@ -20,8 +20,8 @@ var NORMAL = (0, _tokenTypes.regExpToken)(/^(normal)$/);
|
|
|
20
20
|
var STYLE = (0, _tokenTypes.regExpToken)(/^(italic)$/);
|
|
21
21
|
var WEIGHT = (0, _tokenTypes.regExpToken)(/^([1-9]00|bold)$/);
|
|
22
22
|
var VARIANT = (0, _tokenTypes.regExpToken)(/^(small-caps)$/);
|
|
23
|
-
var defaultFontStyle =
|
|
24
|
-
var defaultFontWeight =
|
|
23
|
+
var defaultFontStyle = "normal";
|
|
24
|
+
var defaultFontWeight = "normal";
|
|
25
25
|
var defaultFontVariant = [];
|
|
26
26
|
|
|
27
27
|
var _default = function _default(tokenStream) {
|
|
@@ -36,11 +36,11 @@ var _default = function _default(tokenStream) {
|
|
|
36
36
|
while (numStyleWeightVariantMatched < 3 && tokenStream.hasTokens()) {
|
|
37
37
|
if (tokenStream.matches(NORMAL)) {
|
|
38
38
|
/* pass */
|
|
39
|
-
} else if (typeof fontStyle ===
|
|
39
|
+
} else if (typeof fontStyle === "undefined" && tokenStream.matches(STYLE)) {
|
|
40
40
|
fontStyle = tokenStream.lastValue;
|
|
41
|
-
} else if (typeof fontWeight ===
|
|
41
|
+
} else if (typeof fontWeight === "undefined" && tokenStream.matches(WEIGHT)) {
|
|
42
42
|
fontWeight = tokenStream.lastValue;
|
|
43
|
-
} else if (typeof fontVariant ===
|
|
43
|
+
} else if (typeof fontVariant === "undefined" && tokenStream.matches(VARIANT)) {
|
|
44
44
|
fontVariant = [tokenStream.lastValue];
|
|
45
45
|
} else {
|
|
46
46
|
break;
|
|
@@ -54,7 +54,7 @@ var _default = function _default(tokenStream) {
|
|
|
54
54
|
|
|
55
55
|
if (tokenStream.matches(SLASH)) {
|
|
56
56
|
if (tokenStream.matches(NUMBER)) {
|
|
57
|
-
var size = typeof fontSize ===
|
|
57
|
+
var size = typeof fontSize === "string" ? fontSize.replace(/scalePx2dp\((\d+)\)/, "$1") : fontSize;
|
|
58
58
|
lineHeight = size * tokenStream.lastValue;
|
|
59
59
|
} else {
|
|
60
60
|
lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
|
|
@@ -63,9 +63,9 @@ var _default = function _default(tokenStream) {
|
|
|
63
63
|
|
|
64
64
|
tokenStream.expect(SPACE);
|
|
65
65
|
var fontFamily = (0, _fontFamily["default"])(tokenStream);
|
|
66
|
-
if (typeof fontStyle ===
|
|
67
|
-
if (typeof fontWeight ===
|
|
68
|
-
if (typeof fontVariant ===
|
|
66
|
+
if (typeof fontStyle === "undefined") fontStyle = defaultFontStyle;
|
|
67
|
+
if (typeof fontWeight === "undefined") fontWeight = defaultFontWeight;
|
|
68
|
+
if (typeof fontVariant === "undefined") fontVariant = defaultFontVariant;
|
|
69
69
|
var out = {
|
|
70
70
|
fontStyle: fontStyle,
|
|
71
71
|
fontWeight: fontWeight,
|
|
@@ -73,7 +73,7 @@ var _default = function _default(tokenStream) {
|
|
|
73
73
|
fontSize: fontSize,
|
|
74
74
|
fontFamily: fontFamily
|
|
75
75
|
};
|
|
76
|
-
if (typeof lineHeight !==
|
|
76
|
+
if (typeof lineHeight !== "undefined") out.lineHeight = lineHeight;
|
|
77
77
|
return {
|
|
78
78
|
$merge: out
|
|
79
79
|
};
|
|
@@ -7,6 +7,8 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _tokenTypes = require("../tokenTypes");
|
|
9
9
|
|
|
10
|
+
var _border = require("./border");
|
|
11
|
+
|
|
10
12
|
var _boxShadow = _interopRequireDefault(require("./boxShadow"));
|
|
11
13
|
|
|
12
14
|
var _flex = _interopRequireDefault(require("./flex"));
|
|
@@ -15,15 +17,13 @@ var _font = _interopRequireDefault(require("./font"));
|
|
|
15
17
|
|
|
16
18
|
var _fontFamily = _interopRequireDefault(require("./fontFamily"));
|
|
17
19
|
|
|
18
|
-
var _textShadow = _interopRequireDefault(require("./textShadow"));
|
|
19
|
-
|
|
20
20
|
var _textDecoration = _interopRequireDefault(require("./textDecoration"));
|
|
21
21
|
|
|
22
22
|
var _textDecorationLine = _interopRequireDefault(require("./textDecorationLine"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _textShadow = _interopRequireDefault(require("./textShadow"));
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _transform = _interopRequireDefault(require("./transform"));
|
|
27
27
|
|
|
28
28
|
var _util = require("./util");
|
|
29
29
|
|
|
@@ -47,19 +47,19 @@ var background = function background(tokenStream) {
|
|
|
47
47
|
|
|
48
48
|
var margin = (0, _util.directionFactory)({
|
|
49
49
|
types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
|
|
50
|
-
prefix:
|
|
50
|
+
prefix: "margin"
|
|
51
51
|
});
|
|
52
52
|
var padding = (0, _util.directionFactory)({
|
|
53
|
-
prefix:
|
|
53
|
+
prefix: "padding"
|
|
54
54
|
});
|
|
55
55
|
var flexFlow = (0, _util.anyOrderFactory)({
|
|
56
56
|
flexWrap: {
|
|
57
57
|
tokens: [(0, _tokenTypes.regExpToken)(/(nowrap|wrap|wrap-reverse)/)],
|
|
58
|
-
"default":
|
|
58
|
+
"default": "nowrap"
|
|
59
59
|
},
|
|
60
60
|
flexDirection: {
|
|
61
61
|
tokens: [(0, _tokenTypes.regExpToken)(/(row|row-reverse|column|column-reverse)/)],
|
|
62
|
-
"default":
|
|
62
|
+
"default": "row"
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
|
package/dist/index.js
CHANGED
|
@@ -11,12 +11,12 @@ Object.defineProperty(exports, "transformCSS", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
var _parse = _interopRequireDefault(require("css/lib/parse"));
|
|
15
|
+
|
|
14
16
|
var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
|
|
15
17
|
|
|
16
18
|
var _cssToReactNative = _interopRequireDefault(require("./css-to-react-native"));
|
|
17
19
|
|
|
18
|
-
var _parse = _interopRequireDefault(require("css/lib/parse"));
|
|
19
|
-
|
|
20
20
|
var _features = require("./transforms/media-queries/features");
|
|
21
21
|
|
|
22
22
|
var _types = require("./transforms/media-queries/types");
|
|
@@ -37,14 +37,14 @@ var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px|rem$))/;
|
|
|
37
37
|
var viewportUnitRe = /^([+-]?[0-9.]+)(vh|vw|vmin|vmax)$/;
|
|
38
38
|
var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
|
|
39
39
|
var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/;
|
|
40
|
-
var shorthandBorderProps = [
|
|
40
|
+
var shorthandBorderProps = ["border-radius", "border-width", "border-color", "border-style"];
|
|
41
41
|
|
|
42
42
|
var transformDecls = function transformDecls(styles, declarations, result) {
|
|
43
43
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
44
44
|
|
|
45
45
|
for (var d in declarations) {
|
|
46
46
|
var declaration = declarations[d];
|
|
47
|
-
if (declaration.type !==
|
|
47
|
+
if (declaration.type !== "declaration") continue;
|
|
48
48
|
var property = declaration.property;
|
|
49
49
|
var value = (0, _rem.remToPx)(declaration.value);
|
|
50
50
|
var isLengthUnit = lengthRe.test(value);
|
|
@@ -52,7 +52,7 @@ var transformDecls = function transformDecls(styles, declarations, result) {
|
|
|
52
52
|
var isPercent = percentRe.test(value);
|
|
53
53
|
var isUnsupportedUnit = unsupportedUnitRe.test(value);
|
|
54
54
|
|
|
55
|
-
if (property ===
|
|
55
|
+
if (property === "line-height" && !isLengthUnit && !isViewportUnit && !isPercent && !isUnsupportedUnit) {
|
|
56
56
|
// ignore invalid value avoid throw error cause app crash
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
@@ -63,13 +63,13 @@ var transformDecls = function transformDecls(styles, declarations, result) {
|
|
|
63
63
|
// do not be wrapped by scalePx2dp function
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
if (typeof options.scalable ===
|
|
67
|
-
value = value.replace(/(\d+)px/g,
|
|
66
|
+
if (typeof options.scalable === "boolean" && !options.scalable && /(\d+)px/.test(value)) {
|
|
67
|
+
value = value.replace(/(\d+)px/g, "$1PX");
|
|
68
68
|
} // expect value is legal so that remove !import
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
if (/!import/i.test(value)) {
|
|
72
|
-
value = value.replace(/!import/,
|
|
72
|
+
value = value.replace(/!import/, "");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (shorthandBorderProps.indexOf(property) > -1) {
|
|
@@ -102,7 +102,7 @@ var transform = function transform(css, options) {
|
|
|
102
102
|
var rule = rules[r];
|
|
103
103
|
|
|
104
104
|
for (var s in rule.selectors) {
|
|
105
|
-
if (rule.selectors[s] ===
|
|
105
|
+
if (rule.selectors[s] === ":export") {
|
|
106
106
|
if (!result.__exportProps) {
|
|
107
107
|
result.__exportProps = {};
|
|
108
108
|
}
|
|
@@ -110,7 +110,7 @@ var transform = function transform(css, options) {
|
|
|
110
110
|
rule.declarations.forEach(function (_ref) {
|
|
111
111
|
var property = _ref.property,
|
|
112
112
|
value = _ref.value;
|
|
113
|
-
var isAlreadyDefinedAsClass = typeof result[property] !==
|
|
113
|
+
var isAlreadyDefinedAsClass = typeof result[property] !== "undefined" && typeof result.__exportProps[property] === "undefined";
|
|
114
114
|
|
|
115
115
|
if (isAlreadyDefinedAsClass) {
|
|
116
116
|
throw new Error("Failed to parse :export block because a CSS class in the same file is already using the name \"".concat(property, "\""));
|
|
@@ -121,16 +121,16 @@ var transform = function transform(css, options) {
|
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
if (rule.selectors[s].indexOf(
|
|
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) {
|
|
125
125
|
continue;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
var selector = rule.selectors[s].replace(/^\./,
|
|
128
|
+
var selector = rule.selectors[s].replace(/^\./, "");
|
|
129
129
|
var styles = result[selector] = result[selector] || {};
|
|
130
130
|
transformDecls(styles, rule.declarations, result, options);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
if (rule.type ===
|
|
133
|
+
if (rule.type === "media" && options != null && options.parseMediaQueries === true) {
|
|
134
134
|
var parsed = _cssMediaquery["default"].parse(rule.media);
|
|
135
135
|
|
|
136
136
|
parsed.forEach(function (mq) {
|
|
@@ -140,7 +140,7 @@ var transform = function transform(css, options) {
|
|
|
140
140
|
|
|
141
141
|
mq.expressions.forEach(function (e) {
|
|
142
142
|
var mf = e.modifier ? "".concat(e.modifier, "-").concat(e.feature) : e.feature;
|
|
143
|
-
var val = e.value ? ": ".concat(e.value) :
|
|
143
|
+
var val = e.value ? ": ".concat(e.value) : "";
|
|
144
144
|
|
|
145
145
|
if (_features.mediaQueryFeatures.indexOf(e.feature) === -1) {
|
|
146
146
|
throw new Error("Failed to parse media query feature \"".concat(mf, "\""));
|
|
@@ -151,7 +151,7 @@ var transform = function transform(css, options) {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
});
|
|
154
|
-
var media =
|
|
154
|
+
var media = "@media " + rule.media;
|
|
155
155
|
result.__mediaQueries = result.__mediaQueries || {};
|
|
156
156
|
result.__mediaQueries[media] = parsed;
|
|
157
157
|
|
|
@@ -161,7 +161,7 @@ var transform = function transform(css, options) {
|
|
|
161
161
|
for (var _s in ruleRule.selectors) {
|
|
162
162
|
result[media] = result[media] || {};
|
|
163
163
|
|
|
164
|
-
var _selector = ruleRule.selectors[_s].replace(/^\./,
|
|
164
|
+
var _selector = ruleRule.selectors[_s].replace(/^\./, "");
|
|
165
165
|
|
|
166
166
|
var mediaStyles = result[media][_selector] = result[media][_selector] || {};
|
|
167
167
|
transformDecls(mediaStyles, ruleRule.declarations, result, options);
|
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-theta.
|
|
4
|
+
"version": "3.5.0-theta.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
"css-mediaquery": "^0.1.2",
|
|
12
12
|
"postcss-value-parser": "^3.3.0"
|
|
13
13
|
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "babel src --ignore *.spec.js --out-dir ./dist",
|
|
16
|
-
"test": "jest"
|
|
17
|
-
},
|
|
18
14
|
"repository": {
|
|
19
15
|
"type": "git",
|
|
20
16
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
@@ -62,5 +58,9 @@
|
|
|
62
58
|
"index.d.ts",
|
|
63
59
|
"CHANGELOG.md",
|
|
64
60
|
"README.md"
|
|
65
|
-
]
|
|
66
|
-
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "babel src --ignore *.spec.js --out-dir ./dist",
|
|
64
|
+
"test": "jest"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,79 +1,89 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import TokenStream from
|
|
2
|
+
import camelizeStyleName from "camelize";
|
|
3
|
+
import parse from "postcss-value-parser";
|
|
4
|
+
|
|
5
|
+
import TokenStream from "./TokenStream";
|
|
6
|
+
import transforms from "./transforms/index";
|
|
6
7
|
|
|
7
8
|
// Note if this is wrong, you'll need to change tokenTypes.js too
|
|
8
|
-
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
|
|
9
|
-
const boolRe = /^true|false$/i
|
|
10
|
-
const nullRe = /^null$/i
|
|
11
|
-
const undefinedRe = /^undefined$/i
|
|
9
|
+
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i;
|
|
10
|
+
const boolRe = /^true|false$/i;
|
|
11
|
+
const nullRe = /^null$/i;
|
|
12
|
+
const undefinedRe = /^undefined$/i;
|
|
12
13
|
|
|
13
14
|
// Undocumented export
|
|
14
15
|
export const transformRawValue = input => {
|
|
15
|
-
const value = input.trim()
|
|
16
|
+
const value = input.trim();
|
|
16
17
|
|
|
17
|
-
const numberMatch = value.match(numberOrLengthRe)
|
|
18
|
+
const numberMatch = value.match(numberOrLengthRe);
|
|
18
19
|
if (numberMatch !== null) {
|
|
19
|
-
const num = Number(numberMatch[1])
|
|
20
|
+
const num = Number(numberMatch[1]);
|
|
20
21
|
if (/(\d+)px/.test(value)) {
|
|
21
|
-
return `scalePx2dp(${num})
|
|
22
|
+
return `scalePx2dp(${num})`;
|
|
22
23
|
} else {
|
|
23
|
-
return num
|
|
24
|
+
return num;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const boolMatch = input.match(boolRe)
|
|
28
|
-
if (boolMatch !== null) return boolMatch[0].toLowerCase() ===
|
|
28
|
+
const boolMatch = input.match(boolRe);
|
|
29
|
+
if (boolMatch !== null) return boolMatch[0].toLowerCase() === "true";
|
|
29
30
|
|
|
30
|
-
const nullMatch = input.match(nullRe)
|
|
31
|
-
if (nullMatch !== null) return null
|
|
31
|
+
const nullMatch = input.match(nullRe);
|
|
32
|
+
if (nullMatch !== null) return null;
|
|
32
33
|
|
|
33
|
-
const undefinedMatch = input.match(undefinedRe)
|
|
34
|
-
if (undefinedMatch !== null) return undefined
|
|
34
|
+
const undefinedMatch = input.match(undefinedRe);
|
|
35
|
+
if (undefinedMatch !== null) return undefined;
|
|
35
36
|
|
|
36
|
-
return value
|
|
37
|
-
}
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
38
39
|
|
|
39
40
|
const baseTransformShorthandValue = (propName, inputValue) => {
|
|
40
41
|
// const ast = parse(inputValue.trim().replace(/PX|Px|pX$/g, ""));
|
|
41
|
-
const ast = parse(inputValue)
|
|
42
|
-
const tokenStream = new TokenStream(ast.nodes)
|
|
43
|
-
return transforms[propName](tokenStream)
|
|
44
|
-
}
|
|
42
|
+
const ast = parse(inputValue);
|
|
43
|
+
const tokenStream = new TokenStream(ast.nodes);
|
|
44
|
+
return transforms[propName](tokenStream);
|
|
45
|
+
};
|
|
45
46
|
|
|
46
47
|
const checkBaseTransformShorthandValue = (propName, inputValue) => {
|
|
47
48
|
try {
|
|
48
|
-
return baseTransformShorthandValue(propName, inputValue)
|
|
49
|
+
return baseTransformShorthandValue(propName, inputValue);
|
|
49
50
|
} catch (e) {
|
|
50
|
-
throw new Error(
|
|
51
|
+
throw new Error(
|
|
52
|
+
`${e.message} Failed to parse declaration "${propName}: ${inputValue}"`,
|
|
53
|
+
);
|
|
51
54
|
}
|
|
52
|
-
}
|
|
55
|
+
};
|
|
53
56
|
|
|
54
57
|
const transformShorthandValue =
|
|
55
|
-
process.env.NODE_ENV ===
|
|
58
|
+
process.env.NODE_ENV === "production"
|
|
56
59
|
? baseTransformShorthandValue
|
|
57
|
-
: checkBaseTransformShorthandValue
|
|
60
|
+
: checkBaseTransformShorthandValue;
|
|
58
61
|
|
|
59
62
|
export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
|
|
60
|
-
const isRawValue = allowShorthand === false || !(propName in transforms)
|
|
61
|
-
const propValue = isRawValue
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const isRawValue = allowShorthand === false || !(propName in transforms);
|
|
64
|
+
const propValue = isRawValue
|
|
65
|
+
? transformRawValue(inputValue)
|
|
66
|
+
: transformShorthandValue(propName, inputValue.trim());
|
|
67
|
+
return propValue && propValue.$merge
|
|
68
|
+
? propValue.$merge
|
|
69
|
+
: { [propName]: propValue };
|
|
70
|
+
};
|
|
64
71
|
|
|
65
72
|
export const getPropertyName = propName => {
|
|
66
|
-
const isCustomProp = /^--\w+/.test(propName)
|
|
73
|
+
const isCustomProp = /^--\w+/.test(propName);
|
|
67
74
|
if (isCustomProp) {
|
|
68
|
-
return propName
|
|
75
|
+
return propName;
|
|
69
76
|
}
|
|
70
|
-
return camelizeStyleName(propName)
|
|
71
|
-
}
|
|
77
|
+
return camelizeStyleName(propName);
|
|
78
|
+
};
|
|
72
79
|
|
|
73
80
|
export default (rules, shorthandBlacklist = []) =>
|
|
74
81
|
rules.reduce((accum, rule) => {
|
|
75
|
-
const propertyName = getPropertyName(rule[0])
|
|
76
|
-
const value = rule[1]
|
|
77
|
-
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1
|
|
78
|
-
return Object.assign(
|
|
79
|
-
|
|
82
|
+
const propertyName = getPropertyName(rule[0]);
|
|
83
|
+
const value = rule[1];
|
|
84
|
+
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1;
|
|
85
|
+
return Object.assign(
|
|
86
|
+
accum,
|
|
87
|
+
getStylesForProperty(propertyName, value, allowShorthand),
|
|
88
|
+
);
|
|
89
|
+
}, {});
|