taro-css-to-react-native 3.5.0-beta.5 → 3.5.0-beta.8

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.
@@ -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 (/(\d+)px/.test(value)) {
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 _postcssValueParser = require("postcss-value-parser");
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|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/;
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 (/(\d+)px/.test(node.value)) {
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;
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-beta.5",
4
+ "version": "3.5.0-beta.8",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -6,7 +6,7 @@ import TokenStream from './TokenStream'
6
6
  import transforms from './transforms/index'
7
7
 
8
8
  // Note if this is wrong, you'll need to change tokenTypes.js too
9
- const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
9
+ const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?:px)|(?:vw$)|(?:vh$)|(?:vmin$)|(?:vmax$))?$/i
10
10
  const boolRe = /^true|false$/i
11
11
  const nullRe = /^null$/i
12
12
  const undefinedRe = /^undefined$/i
@@ -18,7 +18,12 @@ export const transformRawValue = (input) => {
18
18
  const numberMatch = value.match(numberOrLengthRe)
19
19
  if (numberMatch !== null) {
20
20
  const num = Number(numberMatch[1])
21
- if (/(\d+)px/.test(value)) {
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)) {
22
27
  return `scalePx2dp(${num})`
23
28
  } else {
24
29
  return num
@@ -1,3 +1,4 @@
1
+ /* eslint-disable react/display-name */
1
2
  import cssColorKeywords from 'css-color-keywords'
2
3
  import { stringify } from 'postcss-value-parser'
3
4
 
@@ -33,12 +34,11 @@ const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i
33
34
  // Note if these are wrong, you'll need to change index.js too
34
35
  const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/
35
36
  // Note lengthRe is sneaky: you can omit units for 0
36
- const lengthRe =
37
- /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)))/
38
- const unsupportedUnitRe =
39
- /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/
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))$/
40
39
  const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/
41
40
  const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
41
+ const viewportUnitRe = /(\d+)(vw|vh|vmin|vmax)/
42
42
 
43
43
  const noopToken = (predicate) => (node) => predicate(node) ? '<token>' : null
44
44
 
@@ -68,7 +68,12 @@ export const regExpToken =
68
68
  if (match === null) return null
69
69
 
70
70
  const value = transform(match[1])
71
- if (/(\d+)px/.test(node.value)) {
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)) {
72
77
  return `scalePx2dp(${value})`
73
78
  } else {
74
79
  return value