taro-css-to-react-native 3.4.11 → 3.4.14
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/dist/css-to-react-native/index.js +6 -2
- package/dist/css-to-react-native/tokenTypes.js +30 -3
- package/dist/css-to-react-native/transforms/border.js +2 -1
- package/dist/index.js +5 -0
- package/package.json +2 -2
- package/src/css-to-react-native/index.js +7 -2
- package/src/css-to-react-native/tokenTypes.js +25 -3
- package/src/css-to-react-native/transforms/border.js +2 -1
- package/src/index.js +4 -0
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
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;
|
|
@@ -11,6 +11,7 @@ var _cssColorKeywords = _interopRequireDefault(require("css-color-keywords"));
|
|
|
11
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) {
|
|
@@ -54,15 +56,39 @@ var valueForTypeToken = function valueForTypeToken(type) {
|
|
|
54
56
|
};
|
|
55
57
|
};
|
|
56
58
|
|
|
59
|
+
var functionValueForTypeToken = function functionValueForTypeToken(type) {
|
|
60
|
+
return function (node) {
|
|
61
|
+
if (node.type === type) {
|
|
62
|
+
// handle rgb(a) function value
|
|
63
|
+
if (/^rgba?$/i.test(node.value)) {
|
|
64
|
+
var result = node.nodes.filter(function (token) {
|
|
65
|
+
return token.type === 'word';
|
|
66
|
+
}).map(function (token) {
|
|
67
|
+
return token.value;
|
|
68
|
+
});
|
|
69
|
+
return "".concat(node.value, "(").concat(result.join(', '), ")");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
57
77
|
var regExpToken = function regExpToken(regExp) {
|
|
58
78
|
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String;
|
|
59
79
|
return function (node) {
|
|
80
|
+
var _node$value$match;
|
|
81
|
+
|
|
60
82
|
if (node.type !== 'word') return null;
|
|
61
83
|
var match = node.value.match(regExp);
|
|
62
84
|
if (match === null) return null;
|
|
63
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);
|
|
64
88
|
|
|
65
|
-
if (
|
|
89
|
+
if (isViewportUnit) {
|
|
90
|
+
return "scaleVu2dp(".concat(value, ", '").concat(unit, "')");
|
|
91
|
+
} else if (/(\d+)px/.test(node.value)) {
|
|
66
92
|
return "scalePx2dp(".concat(value, ")");
|
|
67
93
|
} else {
|
|
68
94
|
return value;
|
|
@@ -82,6 +108,7 @@ var tokens = {
|
|
|
82
108
|
return node.type === 'div' && node.value === ',';
|
|
83
109
|
}),
|
|
84
110
|
WORD: valueForTypeToken('word'),
|
|
111
|
+
FUNC: functionValueForTypeToken('function'),
|
|
85
112
|
NONE: regExpToken(noneRe),
|
|
86
113
|
AUTO: regExpToken(autoRe),
|
|
87
114
|
NUMBER: regExpToken(numberRe, Number),
|
|
@@ -12,6 +12,7 @@ var _util = require("./util");
|
|
|
12
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
14
|
var WORD = _tokenTypes.tokens.WORD,
|
|
15
|
+
FUNC = _tokenTypes.tokens.FUNC,
|
|
15
16
|
COLOR = _tokenTypes.tokens.COLOR,
|
|
16
17
|
LENGTH = _tokenTypes.tokens.LENGTH,
|
|
17
18
|
UNSUPPORTED_LENGTH_UNIT = _tokenTypes.tokens.UNSUPPORTED_LENGTH_UNIT;
|
|
@@ -44,7 +45,7 @@ exports.borderBottom = borderBottom;
|
|
|
44
45
|
var borderLeft = borderDirectionFactory('Left');
|
|
45
46
|
exports.borderLeft = borderLeft;
|
|
46
47
|
var borderColor = (0, _util.directionFactory)({
|
|
47
|
-
types: [WORD],
|
|
48
|
+
types: [WORD, FUNC],
|
|
48
49
|
prefix: 'border',
|
|
49
50
|
suffix: 'Color'
|
|
50
51
|
});
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,11 @@ var transformDecls = function transformDecls(styles, declarations, result) {
|
|
|
65
65
|
|
|
66
66
|
if (typeof options.scalable === 'boolean' && !options.scalable && /(\d+)px/.test(value)) {
|
|
67
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/, '');
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
if (shorthandBorderProps.indexOf(property) > -1) {
|
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.4.
|
|
4
|
+
"version": "3.4.14",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"CHANGELOG.md",
|
|
64
64
|
"README.md"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "19fa8893aafe1e4ea736d071209a86fcfbacc5fe"
|
|
67
67
|
}
|
|
@@ -5,7 +5,7 @@ import transforms from './transforms/index'
|
|
|
5
5
|
import TokenStream from './TokenStream'
|
|
6
6
|
|
|
7
7
|
// Note if this is wrong, you'll need to change tokenTypes.js too
|
|
8
|
-
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
|
|
8
|
+
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?:px)|(?:vw$)|(?:vh$)|(?:vmin$)|(?:vmax$))?$/i
|
|
9
9
|
const boolRe = /^true|false$/i
|
|
10
10
|
const nullRe = /^null$/i
|
|
11
11
|
const undefinedRe = /^undefined$/i
|
|
@@ -17,7 +17,12 @@ export const transformRawValue = input => {
|
|
|
17
17
|
const numberMatch = value.match(numberOrLengthRe)
|
|
18
18
|
if (numberMatch !== null) {
|
|
19
19
|
const num = Number(numberMatch[1])
|
|
20
|
-
|
|
20
|
+
const unit = numberMatch[2]
|
|
21
|
+
const isViewportUnit = ['vw', 'vh', 'vmin', 'vmax'].includes(unit)
|
|
22
|
+
|
|
23
|
+
if (isViewportUnit) {
|
|
24
|
+
return `scaleVu2dp(${num}, '${unit}')`
|
|
25
|
+
} else if (/(\d+)px/.test(value)) {
|
|
21
26
|
return `scalePx2dp(${num})`
|
|
22
27
|
} else {
|
|
23
28
|
return num
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
1
2
|
import { stringify } from 'postcss-value-parser'
|
|
2
3
|
import cssColorKeywords from 'css-color-keywords'
|
|
3
4
|
|
|
@@ -29,15 +30,30 @@ const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i
|
|
|
29
30
|
// Note if these are wrong, you'll need to change index.js too
|
|
30
31
|
const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/
|
|
31
32
|
// 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|
|
|
33
|
+
const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)|(?=vw$)|(?=vh$)|(?=vmin$)|(?=vmax$)))/
|
|
34
|
+
const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|cm|mm|in|pc|pt))$/
|
|
34
35
|
const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/
|
|
35
36
|
const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
|
|
37
|
+
const viewportUnitRe = /(\d+)(vw|vh|vmin|vmax)/
|
|
36
38
|
|
|
37
39
|
const noopToken = predicate => node => (predicate(node) ? '<token>' : null)
|
|
38
40
|
|
|
39
41
|
const valueForTypeToken = type => node => (node.type === type ? node.value : null)
|
|
40
42
|
|
|
43
|
+
const functionValueForTypeToken = type => node => {
|
|
44
|
+
if (node.type === type) {
|
|
45
|
+
// handle rgb(a) function value
|
|
46
|
+
if (/^rgba?$/i.test(node.value)) {
|
|
47
|
+
const result = node.nodes
|
|
48
|
+
.filter(token => token.type === 'word')
|
|
49
|
+
.map(token => token.value)
|
|
50
|
+
|
|
51
|
+
return `${node.value}(${result.join(', ')})`
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
export const regExpToken = (regExp, transform = String) => node => {
|
|
42
58
|
if (node.type !== 'word') return null
|
|
43
59
|
|
|
@@ -45,7 +61,12 @@ export const regExpToken = (regExp, transform = String) => node => {
|
|
|
45
61
|
if (match === null) return null
|
|
46
62
|
|
|
47
63
|
const value = transform(match[1])
|
|
48
|
-
|
|
64
|
+
const unit = node.value.match(viewportUnitRe)?.[2]
|
|
65
|
+
const isViewportUnit = ['vh', 'vw', 'vmin', 'vmax'].includes(unit)
|
|
66
|
+
|
|
67
|
+
if (isViewportUnit) {
|
|
68
|
+
return `scaleVu2dp(${value}, '${unit}')`
|
|
69
|
+
} else if (/(\d+)px/.test(node.value)) {
|
|
49
70
|
return `scalePx2dp(${value})`
|
|
50
71
|
} else {
|
|
51
72
|
return value
|
|
@@ -57,6 +78,7 @@ export const tokens = {
|
|
|
57
78
|
SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
|
|
58
79
|
COMMA: noopToken(node => node.type === 'div' && node.value === ','),
|
|
59
80
|
WORD: valueForTypeToken('word'),
|
|
81
|
+
FUNC: functionValueForTypeToken('function'),
|
|
60
82
|
NONE: regExpToken(noneRe),
|
|
61
83
|
AUTO: regExpToken(autoRe),
|
|
62
84
|
NUMBER: regExpToken(numberRe, Number),
|
|
@@ -3,6 +3,7 @@ import { directionFactory, anyOrderFactory } from './util'
|
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
WORD,
|
|
6
|
+
FUNC,
|
|
6
7
|
COLOR,
|
|
7
8
|
LENGTH,
|
|
8
9
|
UNSUPPORTED_LENGTH_UNIT
|
|
@@ -34,7 +35,7 @@ export const borderBottom = borderDirectionFactory('Bottom')
|
|
|
34
35
|
export const borderLeft = borderDirectionFactory('Left')
|
|
35
36
|
|
|
36
37
|
export const borderColor = directionFactory({
|
|
37
|
-
types: [WORD],
|
|
38
|
+
types: [WORD, FUNC],
|
|
38
39
|
prefix: 'border',
|
|
39
40
|
suffix: 'Color'
|
|
40
41
|
})
|
package/src/index.js
CHANGED
|
@@ -59,6 +59,10 @@ const transformDecls = (styles, declarations, result, options = {}) => {
|
|
|
59
59
|
) {
|
|
60
60
|
value = value.replace(/(\d+)px/g, '$1PX')
|
|
61
61
|
}
|
|
62
|
+
// expect value is legal so that remove !import
|
|
63
|
+
if (/!import/i.test(value)) {
|
|
64
|
+
value = value.replace(/!import/, '')
|
|
65
|
+
}
|
|
62
66
|
|
|
63
67
|
if (shorthandBorderProps.indexOf(property) > -1) {
|
|
64
68
|
// transform single value shorthand border properties back to
|