taro-css-to-react-native 3.5.0-theta.0 → 3.5.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 +9 -5
- package/dist/css-to-react-native/tokenTypes.js +13 -5
- package/dist/css-to-react-native/transforms/font.js +2 -2
- package/dist/css-to-react-native/transforms/index.js +4 -4
- package/dist/index.js +2 -2
- package/dist/utils/camelCase.js +1 -1
- package/package.json +8 -17
- package/src/css-to-react-native/index.js +25 -10
- package/src/css-to-react-native/tokenTypes.js +41 -27
- package/src/css-to-react-native/transforms/border.js +12 -15
- package/src/css-to-react-native/transforms/font.js +14 -5
- package/src/css-to-react-native/transforms/index.js +23 -21
- package/src/index.js +11 -11
- package/src/utils/camelCase.js +1 -1
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,20 +5,20 @@ 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; }
|
|
19
19
|
|
|
20
20
|
// Note if this is wrong, you'll need to change tokenTypes.js too
|
|
21
|
-
var numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i;
|
|
21
|
+
var numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?:px)|(?:vw$)|(?:vh$)|(?:vmin$)|(?:vmax$))?$/i;
|
|
22
22
|
var boolRe = /^true|false$/i;
|
|
23
23
|
var nullRe = /^null$/i;
|
|
24
24
|
var undefinedRe = /^undefined$/i; // Undocumented export
|
|
@@ -29,8 +29,12 @@ var transformRawValue = function transformRawValue(input) {
|
|
|
29
29
|
|
|
30
30
|
if (numberMatch !== null) {
|
|
31
31
|
var num = Number(numberMatch[1]);
|
|
32
|
+
var unit = numberMatch[2];
|
|
33
|
+
var isViewportUnit = ['vw', 'vh', 'vmin', 'vmax'].includes(unit);
|
|
32
34
|
|
|
33
|
-
if (
|
|
35
|
+
if (isViewportUnit) {
|
|
36
|
+
return "scaleVu2dp(".concat(num, ", '").concat(unit, "')");
|
|
37
|
+
} else if (/(\d+)px/.test(value)) {
|
|
34
38
|
return "scalePx2dp(".concat(num, ")");
|
|
35
39
|
} else {
|
|
36
40
|
return num;
|
|
@@ -5,12 +5,13 @@ 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
|
+
/* eslint-disable react/display-name */
|
|
14
15
|
var matchString = function matchString(node) {
|
|
15
16
|
if (node.type !== 'string') return null;
|
|
16
17
|
return node.value.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, function (match, charCode) {
|
|
@@ -37,10 +38,11 @@ var identRe = /(^-?[_a-z][_a-z0-9-]*$)/i; // Note if these are wrong, you'll nee
|
|
|
37
38
|
|
|
38
39
|
var numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/; // Note lengthRe is sneaky: you can omit units for 0
|
|
39
40
|
|
|
40
|
-
var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)))/;
|
|
41
|
-
var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|
|
|
41
|
+
var lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)|(?=vw$)|(?=vh$)|(?=vmin$)|(?=vmax$)))/;
|
|
42
|
+
var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|cm|mm|in|pc|pt))$/;
|
|
42
43
|
var angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/;
|
|
43
44
|
var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
|
|
45
|
+
var viewportUnitRe = /(\d+)(vw|vh|vmin|vmax)/;
|
|
44
46
|
|
|
45
47
|
var noopToken = function noopToken(predicate) {
|
|
46
48
|
return function (node) {
|
|
@@ -75,12 +77,18 @@ var functionValueForTypeToken = function functionValueForTypeToken(type) {
|
|
|
75
77
|
var regExpToken = function regExpToken(regExp) {
|
|
76
78
|
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String;
|
|
77
79
|
return function (node) {
|
|
80
|
+
var _node$value$match;
|
|
81
|
+
|
|
78
82
|
if (node.type !== 'word') return null;
|
|
79
83
|
var match = node.value.match(regExp);
|
|
80
84
|
if (match === null) return null;
|
|
81
85
|
var value = transform(match[1]);
|
|
86
|
+
var unit = (_node$value$match = node.value.match(viewportUnitRe)) === null || _node$value$match === void 0 ? void 0 : _node$value$match[2];
|
|
87
|
+
var isViewportUnit = ['vh', 'vw', 'vmin', 'vmax'].includes(unit);
|
|
82
88
|
|
|
83
|
-
if (
|
|
89
|
+
if (isViewportUnit) {
|
|
90
|
+
return "scaleVu2dp(".concat(value, ", '").concat(unit, "')");
|
|
91
|
+
} else if (/(\d+)px/.test(node.value)) {
|
|
84
92
|
return "scalePx2dp(".concat(value, ")");
|
|
85
93
|
} else {
|
|
86
94
|
return value;
|
|
@@ -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,
|
|
@@ -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
|
|
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");
|
package/dist/utils/camelCase.js
CHANGED
|
@@ -9,7 +9,7 @@ function camelCase(str) {
|
|
|
9
9
|
// Lower cases the string
|
|
10
10
|
return str.toLowerCase() // Replaces any - or _ characters with a space
|
|
11
11
|
.replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters
|
|
12
|
-
.replace(/[^\w\s]/g, '') //
|
|
12
|
+
.replace(/[^\w\s]/g, '') // Uppercase the first character in each group immediately following a space
|
|
13
13
|
// (delimited by spaces)
|
|
14
14
|
.replace(/ (.)/g, function ($1) {
|
|
15
15
|
return $1.toUpperCase();
|
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
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.
|
|
4
|
+
"version": "3.5.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"camelize": "^1.0.0",
|
|
9
|
-
"css": "^
|
|
9
|
+
"css": "^3.0.0",
|
|
10
10
|
"css-color-keywords": "^1.0.0",
|
|
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"
|
|
@@ -47,20 +43,15 @@
|
|
|
47
43
|
"<rootDir>/node_modules"
|
|
48
44
|
]
|
|
49
45
|
},
|
|
50
|
-
"lint-staged": {
|
|
51
|
-
"*.{js,json,md}": [
|
|
52
|
-
"prettier --write",
|
|
53
|
-
"git add"
|
|
54
|
-
]
|
|
55
|
-
},
|
|
56
|
-
"prettier": {
|
|
57
|
-
"trailingComma": "all"
|
|
58
|
-
},
|
|
59
46
|
"files": [
|
|
60
47
|
"dist",
|
|
61
48
|
"src",
|
|
62
49
|
"index.d.ts",
|
|
63
50
|
"CHANGELOG.md",
|
|
64
51
|
"README.md"
|
|
65
|
-
]
|
|
66
|
-
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "babel src --ignore *.spec.js --out-dir ./dist",
|
|
55
|
+
"test": "jest"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import parse from 'postcss-value-parser'
|
|
3
2
|
import camelizeStyleName from 'camelize'
|
|
4
|
-
import
|
|
3
|
+
import parse from 'postcss-value-parser'
|
|
4
|
+
|
|
5
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 numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?:px)|(?:vw$)|(?:vh$)|(?:vmin$)|(?:vmax$))?$/i
|
|
9
10
|
const boolRe = /^true|false$/i
|
|
10
11
|
const nullRe = /^null$/i
|
|
11
12
|
const undefinedRe = /^undefined$/i
|
|
12
13
|
|
|
13
14
|
// Undocumented export
|
|
14
|
-
export const transformRawValue = input => {
|
|
15
|
+
export const transformRawValue = (input) => {
|
|
15
16
|
const value = input.trim()
|
|
16
17
|
|
|
17
18
|
const numberMatch = value.match(numberOrLengthRe)
|
|
18
19
|
if (numberMatch !== null) {
|
|
19
20
|
const num = Number(numberMatch[1])
|
|
20
|
-
|
|
21
|
+
const unit = numberMatch[2]
|
|
22
|
+
const isViewportUnit = ['vw', 'vh', 'vmin', 'vmax'].includes(unit)
|
|
23
|
+
|
|
24
|
+
if (isViewportUnit) {
|
|
25
|
+
return `scaleVu2dp(${num}, '${unit}')`
|
|
26
|
+
} else if (/(\d+)px/.test(value)) {
|
|
21
27
|
return `scalePx2dp(${num})`
|
|
22
28
|
} else {
|
|
23
29
|
return num
|
|
@@ -47,7 +53,9 @@ const checkBaseTransformShorthandValue = (propName, inputValue) => {
|
|
|
47
53
|
try {
|
|
48
54
|
return baseTransformShorthandValue(propName, inputValue)
|
|
49
55
|
} catch (e) {
|
|
50
|
-
throw new Error(
|
|
56
|
+
throw new Error(
|
|
57
|
+
`${e.message} Failed to parse declaration "${propName}: ${inputValue}"`,
|
|
58
|
+
)
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
|
|
@@ -58,11 +66,15 @@ const transformShorthandValue =
|
|
|
58
66
|
|
|
59
67
|
export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
|
|
60
68
|
const isRawValue = allowShorthand === false || !(propName in transforms)
|
|
61
|
-
const propValue = isRawValue
|
|
62
|
-
|
|
69
|
+
const propValue = isRawValue
|
|
70
|
+
? transformRawValue(inputValue)
|
|
71
|
+
: transformShorthandValue(propName, inputValue.trim())
|
|
72
|
+
return propValue && propValue.$merge
|
|
73
|
+
? propValue.$merge
|
|
74
|
+
: { [propName]: propValue }
|
|
63
75
|
}
|
|
64
76
|
|
|
65
|
-
export const getPropertyName = propName => {
|
|
77
|
+
export const getPropertyName = (propName) => {
|
|
66
78
|
const isCustomProp = /^--\w+/.test(propName)
|
|
67
79
|
if (isCustomProp) {
|
|
68
80
|
return propName
|
|
@@ -75,5 +87,8 @@ export default (rules, shorthandBlacklist = []) =>
|
|
|
75
87
|
const propertyName = getPropertyName(rule[0])
|
|
76
88
|
const value = rule[1]
|
|
77
89
|
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1
|
|
78
|
-
return Object.assign(
|
|
90
|
+
return Object.assign(
|
|
91
|
+
accum,
|
|
92
|
+
getStylesForProperty(propertyName, value, allowShorthand),
|
|
93
|
+
)
|
|
79
94
|
}, {})
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
2
2
|
import cssColorKeywords from 'css-color-keywords'
|
|
3
|
+
import { stringify } from 'postcss-value-parser'
|
|
3
4
|
|
|
4
|
-
const matchString = node => {
|
|
5
|
+
const matchString = (node) => {
|
|
5
6
|
if (node.type !== 'string') return null
|
|
6
7
|
return node.value
|
|
7
|
-
.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) =>
|
|
8
|
+
.replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) =>
|
|
9
|
+
String.fromCharCode(parseInt(charCode, 16)),
|
|
10
|
+
)
|
|
8
11
|
.replace(/\\/g, '')
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
const hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i
|
|
12
15
|
const cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/
|
|
13
16
|
|
|
14
|
-
const matchColor = node => {
|
|
17
|
+
const matchColor = (node) => {
|
|
15
18
|
if (
|
|
16
19
|
node.type === 'word' &&
|
|
17
|
-
(hexColorRe.test(node.value) ||
|
|
20
|
+
(hexColorRe.test(node.value) ||
|
|
21
|
+
node.value in cssColorKeywords ||
|
|
22
|
+
node.value === 'transparent')
|
|
18
23
|
) {
|
|
19
24
|
return node.value
|
|
20
25
|
} else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {
|
|
@@ -29,22 +34,24 @@ const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i
|
|
|
29
34
|
// Note if these are wrong, you'll need to change index.js too
|
|
30
35
|
const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/
|
|
31
36
|
// Note lengthRe is sneaky: you can omit units for 0
|
|
32
|
-
const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)))/
|
|
33
|
-
const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|
|
|
37
|
+
const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)|(?=vw$)|(?=vh$)|(?=vmin$)|(?=vmax$)))/
|
|
38
|
+
const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|cm|mm|in|pc|pt))$/
|
|
34
39
|
const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/
|
|
35
40
|
const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
|
|
41
|
+
const viewportUnitRe = /(\d+)(vw|vh|vmin|vmax)/
|
|
36
42
|
|
|
37
|
-
const noopToken = predicate => node =>
|
|
43
|
+
const noopToken = (predicate) => (node) => predicate(node) ? '<token>' : null
|
|
38
44
|
|
|
39
|
-
const valueForTypeToken = type => node =>
|
|
45
|
+
const valueForTypeToken = (type) => (node) =>
|
|
46
|
+
node.type === type ? node.value : null
|
|
40
47
|
|
|
41
|
-
const functionValueForTypeToken = type => node => {
|
|
48
|
+
const functionValueForTypeToken = (type) => (node) => {
|
|
42
49
|
if (node.type === type) {
|
|
43
50
|
// handle rgb(a) function value
|
|
44
51
|
if (/^rgba?$/i.test(node.value)) {
|
|
45
52
|
const result = node.nodes
|
|
46
|
-
.filter(token => token.type === 'word')
|
|
47
|
-
.map(token => token.value)
|
|
53
|
+
.filter((token) => token.type === 'word')
|
|
54
|
+
.map((token) => token.value)
|
|
48
55
|
|
|
49
56
|
return `${node.value}(${result.join(', ')})`
|
|
50
57
|
}
|
|
@@ -52,24 +59,31 @@ const functionValueForTypeToken = type => node => {
|
|
|
52
59
|
return null
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
export const regExpToken =
|
|
56
|
-
|
|
62
|
+
export const regExpToken =
|
|
63
|
+
(regExp, transform = String) =>
|
|
64
|
+
(node) => {
|
|
65
|
+
if (node.type !== 'word') return null
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
const match = node.value.match(regExp)
|
|
68
|
+
if (match === null) return null
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
70
|
+
const value = transform(match[1])
|
|
71
|
+
const unit = node.value.match(viewportUnitRe)?.[2]
|
|
72
|
+
const isViewportUnit = ['vh', 'vw', 'vmin', 'vmax'].includes(unit)
|
|
73
|
+
|
|
74
|
+
if (isViewportUnit) {
|
|
75
|
+
return `scaleVu2dp(${value}, '${unit}')`
|
|
76
|
+
} else if (/(\d+)px/.test(node.value)) {
|
|
77
|
+
return `scalePx2dp(${value})`
|
|
78
|
+
} else {
|
|
79
|
+
return value
|
|
80
|
+
}
|
|
81
|
+
}
|
|
68
82
|
|
|
69
83
|
export const tokens = {
|
|
70
|
-
SPACE: noopToken(node => node.type === 'space'),
|
|
71
|
-
SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
|
|
72
|
-
COMMA: noopToken(node => node.type === 'div' && node.value === ','),
|
|
84
|
+
SPACE: noopToken((node) => node.type === 'space'),
|
|
85
|
+
SLASH: noopToken((node) => node.type === 'div' && node.value === '/'),
|
|
86
|
+
COMMA: noopToken((node) => node.type === 'div' && node.value === ','),
|
|
73
87
|
WORD: valueForTypeToken('word'),
|
|
74
88
|
FUNC: functionValueForTypeToken('function'),
|
|
75
89
|
NONE: regExpToken(noneRe),
|
|
@@ -82,5 +96,5 @@ export const tokens = {
|
|
|
82
96
|
IDENT: regExpToken(identRe),
|
|
83
97
|
STRING: matchString,
|
|
84
98
|
COLOR: matchColor,
|
|
85
|
-
LINE: regExpToken(/^(none|underline|line-through)$/i)
|
|
99
|
+
LINE: regExpToken(/^(none|underline|line-through)$/i),
|
|
86
100
|
}
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
import { regExpToken, tokens } from '../tokenTypes'
|
|
2
|
-
import {
|
|
2
|
+
import { anyOrderFactory, directionFactory } from './util'
|
|
3
3
|
|
|
4
|
-
const {
|
|
5
|
-
WORD,
|
|
6
|
-
FUNC,
|
|
7
|
-
COLOR,
|
|
8
|
-
LENGTH,
|
|
9
|
-
UNSUPPORTED_LENGTH_UNIT
|
|
10
|
-
} = tokens
|
|
4
|
+
const { WORD, FUNC, COLOR, LENGTH, UNSUPPORTED_LENGTH_UNIT } = tokens
|
|
11
5
|
|
|
12
6
|
function borderDirectionFactory (direction = '') {
|
|
13
7
|
const prefix = `border${direction}`
|
|
14
8
|
return anyOrderFactory({
|
|
15
9
|
[`${prefix}Width`]: {
|
|
16
10
|
tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
|
|
17
|
-
default: 1
|
|
11
|
+
default: 1,
|
|
18
12
|
},
|
|
19
13
|
[`${prefix}Color`]: {
|
|
20
14
|
tokens: [COLOR],
|
|
21
|
-
default: 'black'
|
|
15
|
+
default: 'black',
|
|
22
16
|
},
|
|
23
17
|
[`${prefix}Style`]: {
|
|
24
18
|
tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
|
|
25
|
-
default: 'solid'
|
|
26
|
-
}
|
|
19
|
+
default: 'solid',
|
|
20
|
+
},
|
|
27
21
|
})
|
|
28
22
|
}
|
|
29
23
|
|
|
@@ -37,13 +31,16 @@ export const borderLeft = borderDirectionFactory('Left')
|
|
|
37
31
|
export const borderColor = directionFactory({
|
|
38
32
|
types: [WORD, FUNC],
|
|
39
33
|
prefix: 'border',
|
|
40
|
-
suffix: 'Color'
|
|
34
|
+
suffix: 'Color',
|
|
41
35
|
})
|
|
42
36
|
|
|
43
37
|
export const borderRadius = directionFactory({
|
|
44
38
|
directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
|
|
45
39
|
prefix: 'border',
|
|
46
|
-
suffix: 'Radius'
|
|
40
|
+
suffix: 'Radius',
|
|
47
41
|
})
|
|
48
42
|
|
|
49
|
-
export const borderWidth = directionFactory({
|
|
43
|
+
export const borderWidth = directionFactory({
|
|
44
|
+
prefix: 'border',
|
|
45
|
+
suffix: 'Width',
|
|
46
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import parseFontFamily from './fontFamily'
|
|
2
1
|
import { regExpToken, tokens } from '../tokenTypes'
|
|
2
|
+
import parseFontFamily from './fontFamily'
|
|
3
3
|
|
|
4
4
|
const { SPACE, LENGTH, UNSUPPORTED_LENGTH_UNIT, NUMBER, SLASH } = tokens
|
|
5
5
|
const NORMAL = regExpToken(/^(normal)$/)
|
|
@@ -11,7 +11,7 @@ const defaultFontStyle = 'normal'
|
|
|
11
11
|
const defaultFontWeight = 'normal'
|
|
12
12
|
const defaultFontVariant = []
|
|
13
13
|
|
|
14
|
-
export default tokenStream => {
|
|
14
|
+
export default (tokenStream) => {
|
|
15
15
|
let fontStyle
|
|
16
16
|
let fontWeight
|
|
17
17
|
let fontVariant
|
|
@@ -25,9 +25,15 @@ export default tokenStream => {
|
|
|
25
25
|
/* pass */
|
|
26
26
|
} else if (typeof fontStyle === 'undefined' && tokenStream.matches(STYLE)) {
|
|
27
27
|
fontStyle = tokenStream.lastValue
|
|
28
|
-
} else if (
|
|
28
|
+
} else if (
|
|
29
|
+
typeof fontWeight === 'undefined' &&
|
|
30
|
+
tokenStream.matches(WEIGHT)
|
|
31
|
+
) {
|
|
29
32
|
fontWeight = tokenStream.lastValue
|
|
30
|
-
} else if (
|
|
33
|
+
} else if (
|
|
34
|
+
typeof fontVariant === 'undefined' &&
|
|
35
|
+
tokenStream.matches(VARIANT)
|
|
36
|
+
) {
|
|
31
37
|
fontVariant = [tokenStream.lastValue]
|
|
32
38
|
} else {
|
|
33
39
|
break
|
|
@@ -41,7 +47,10 @@ export default tokenStream => {
|
|
|
41
47
|
|
|
42
48
|
if (tokenStream.matches(SLASH)) {
|
|
43
49
|
if (tokenStream.matches(NUMBER)) {
|
|
44
|
-
const size =
|
|
50
|
+
const size =
|
|
51
|
+
typeof fontSize === 'string'
|
|
52
|
+
? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1')
|
|
53
|
+
: fontSize
|
|
45
54
|
lineHeight = size * tokenStream.lastValue
|
|
46
55
|
} else {
|
|
47
56
|
lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT)
|
|
@@ -1,45 +1,47 @@
|
|
|
1
1
|
import { regExpToken, tokens } from '../tokenTypes'
|
|
2
|
+
import {
|
|
3
|
+
border,
|
|
4
|
+
borderBottom,
|
|
5
|
+
borderColor,
|
|
6
|
+
borderLeft,
|
|
7
|
+
borderRadius,
|
|
8
|
+
borderRight,
|
|
9
|
+
borderTop,
|
|
10
|
+
borderWidth,
|
|
11
|
+
} from './border'
|
|
2
12
|
import boxShadow from './boxShadow'
|
|
3
13
|
import flex from './flex'
|
|
4
14
|
import font from './font'
|
|
5
15
|
import fontFamily from './fontFamily'
|
|
6
|
-
import textShadow from './textShadow'
|
|
7
16
|
import textDecoration from './textDecoration'
|
|
8
17
|
import textDecorationLine from './textDecorationLine'
|
|
18
|
+
import textShadow from './textShadow'
|
|
9
19
|
import transform from './transform'
|
|
10
|
-
import {
|
|
11
|
-
import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'
|
|
20
|
+
import { anyOrderFactory, directionFactory, shadowOffsetFactory } from './util'
|
|
12
21
|
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
WORD,
|
|
16
|
-
COLOR,
|
|
17
|
-
LENGTH,
|
|
18
|
-
UNSUPPORTED_LENGTH_UNIT,
|
|
19
|
-
PERCENT,
|
|
20
|
-
AUTO
|
|
21
|
-
} = tokens
|
|
22
|
+
const { IDENT, WORD, COLOR, LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO } =
|
|
23
|
+
tokens
|
|
22
24
|
|
|
23
|
-
const background = tokenStream => ({
|
|
24
|
-
$merge: { backgroundColor: tokenStream.expect(COLOR) }
|
|
25
|
+
const background = (tokenStream) => ({
|
|
26
|
+
$merge: { backgroundColor: tokenStream.expect(COLOR) },
|
|
25
27
|
})
|
|
26
28
|
const margin = directionFactory({
|
|
27
29
|
types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO],
|
|
28
|
-
prefix: 'margin'
|
|
30
|
+
prefix: 'margin',
|
|
29
31
|
})
|
|
30
32
|
const padding = directionFactory({ prefix: 'padding' })
|
|
31
33
|
const flexFlow = anyOrderFactory({
|
|
32
34
|
flexWrap: {
|
|
33
35
|
tokens: [regExpToken(/(nowrap|wrap|wrap-reverse)/)],
|
|
34
|
-
default: 'nowrap'
|
|
36
|
+
default: 'nowrap',
|
|
35
37
|
},
|
|
36
38
|
flexDirection: {
|
|
37
39
|
tokens: [regExpToken(/(row|row-reverse|column|column-reverse)/)],
|
|
38
|
-
default: 'row'
|
|
39
|
-
}
|
|
40
|
+
default: 'row',
|
|
41
|
+
},
|
|
40
42
|
})
|
|
41
|
-
const fontVariant = tokenStream => [tokenStream.expect(IDENT)]
|
|
42
|
-
const fontWeight = tokenStream => tokenStream.expect(WORD) // Also match numbers as strings
|
|
43
|
+
const fontVariant = (tokenStream) => [tokenStream.expect(IDENT)]
|
|
44
|
+
const fontWeight = (tokenStream) => tokenStream.expect(WORD) // Also match numbers as strings
|
|
43
45
|
const shadowOffset = shadowOffsetFactory()
|
|
44
46
|
const textShadowOffset = shadowOffsetFactory()
|
|
45
47
|
|
|
@@ -67,5 +69,5 @@ export default {
|
|
|
67
69
|
textShadowOffset,
|
|
68
70
|
textDecoration,
|
|
69
71
|
textDecorationLine,
|
|
70
|
-
transform
|
|
72
|
+
transform,
|
|
71
73
|
}
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import parseCSS from 'css/lib/parse'
|
|
1
2
|
import mediaQuery from 'css-mediaquery'
|
|
3
|
+
|
|
2
4
|
import transformCSS from './css-to-react-native'
|
|
3
|
-
import parseCSS from 'css/lib/parse'
|
|
4
5
|
import {
|
|
5
6
|
dimensionFeatures,
|
|
6
|
-
mediaQueryFeatures
|
|
7
|
+
mediaQueryFeatures,
|
|
7
8
|
} from './transforms/media-queries/features'
|
|
8
9
|
import { mediaQueryTypes } from './transforms/media-queries/types'
|
|
9
10
|
import { remToPx } from './transforms/rem'
|
|
@@ -15,12 +16,13 @@ import { values } from './utils/values'
|
|
|
15
16
|
const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px|rem$))/
|
|
16
17
|
const viewportUnitRe = /^([+-]?[0-9.]+)(vh|vw|vmin|vmax)$/
|
|
17
18
|
const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
|
|
18
|
-
const unsupportedUnitRe =
|
|
19
|
+
const unsupportedUnitRe =
|
|
20
|
+
/^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/
|
|
19
21
|
const shorthandBorderProps = [
|
|
20
22
|
'border-radius',
|
|
21
23
|
'border-width',
|
|
22
24
|
'border-color',
|
|
23
|
-
'border-style'
|
|
25
|
+
'border-style',
|
|
24
26
|
]
|
|
25
27
|
|
|
26
28
|
const transformDecls = (styles, declarations, result, options = {}) => {
|
|
@@ -103,7 +105,7 @@ const transform = (css, options) => {
|
|
|
103
105
|
|
|
104
106
|
if (isAlreadyDefinedAsClass) {
|
|
105
107
|
throw new Error(
|
|
106
|
-
`Failed to parse :export block because a CSS class in the same file is already using the name "${property}"
|
|
108
|
+
`Failed to parse :export block because a CSS class in the same file is already using the name "${property}"`,
|
|
107
109
|
)
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -136,12 +138,12 @@ const transform = (css, options) => {
|
|
|
136
138
|
) {
|
|
137
139
|
const parsed = mediaQuery.parse(rule.media)
|
|
138
140
|
|
|
139
|
-
parsed.forEach(mq => {
|
|
141
|
+
parsed.forEach((mq) => {
|
|
140
142
|
if (mediaQueryTypes.indexOf(mq.type) === -1) {
|
|
141
143
|
throw new Error(`Failed to parse media query type "${mq.type}"`)
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
mq.expressions.forEach(e => {
|
|
146
|
+
mq.expressions.forEach((e) => {
|
|
145
147
|
const mf = e.modifier ? `${e.modifier}-${e.feature}` : e.feature
|
|
146
148
|
const val = e.value ? `: ${e.value}` : ''
|
|
147
149
|
|
|
@@ -154,7 +156,7 @@ const transform = (css, options) => {
|
|
|
154
156
|
lengthRe.test(e.value) === false
|
|
155
157
|
) {
|
|
156
158
|
throw new Error(
|
|
157
|
-
`Failed to parse media query expression "(${mf}${val})"
|
|
159
|
+
`Failed to parse media query expression "(${mf}${val})"`,
|
|
158
160
|
)
|
|
159
161
|
}
|
|
160
162
|
})
|
|
@@ -186,8 +188,6 @@ const transform = (css, options) => {
|
|
|
186
188
|
return result
|
|
187
189
|
}
|
|
188
190
|
|
|
189
|
-
export {
|
|
190
|
-
transformCSS
|
|
191
|
-
}
|
|
191
|
+
export { transformCSS }
|
|
192
192
|
|
|
193
193
|
export default transform
|
package/src/utils/camelCase.js
CHANGED
|
@@ -7,7 +7,7 @@ export function camelCase (str) {
|
|
|
7
7
|
.replace(/[-_]+/g, ' ')
|
|
8
8
|
// Removes any non alphanumeric characters
|
|
9
9
|
.replace(/[^\w\s]/g, '')
|
|
10
|
-
//
|
|
10
|
+
// Uppercase the first character in each group immediately following a space
|
|
11
11
|
// (delimited by spaces)
|
|
12
12
|
.replace(/ (.)/g, function ($1) {
|
|
13
13
|
return $1.toUpperCase()
|