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

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.
@@ -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 _index = _interopRequireDefault(require("./transforms/index"));
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; }
@@ -5,10 +5,10 @@ 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) {
@@ -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),
@@ -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
  });
@@ -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 _transform = _interopRequireDefault(require("./transform"));
24
+ var _textShadow = _interopRequireDefault(require("./textShadow"));
25
25
 
26
- var _border = require("./border");
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");
@@ -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) {
@@ -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, '') // Uppercases the first character in each group immediately following a space
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.0-beta.2",
4
+ "version": "3.5.0-beta.5",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "camelize": "^1.0.0",
9
- "css": "^2.2.4",
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,15 +43,6 @@
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",
@@ -63,5 +50,8 @@
63
50
  "CHANGELOG.md",
64
51
  "README.md"
65
52
  ],
66
- "gitHead": "c85adaa45959e6cafc15e6531f4735a7dfa2aab0"
67
- }
53
+ "scripts": {
54
+ "build": "babel src --ignore *.spec.js --out-dir ./dist",
55
+ "test": "jest"
56
+ }
57
+ }
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable no-param-reassign */
2
- import parse from 'postcss-value-parser'
3
2
  import camelizeStyleName from 'camelize'
4
- import transforms from './transforms/index'
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
9
  const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
@@ -11,7 +12,7 @@ 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)
@@ -47,7 +48,9 @@ const checkBaseTransformShorthandValue = (propName, inputValue) => {
47
48
  try {
48
49
  return baseTransformShorthandValue(propName, inputValue)
49
50
  } catch (e) {
50
- throw new Error(`${e.message} Failed to parse declaration "${propName}: ${inputValue}"`)
51
+ throw new Error(
52
+ `${e.message} Failed to parse declaration "${propName}: ${inputValue}"`,
53
+ )
51
54
  }
52
55
  }
53
56
 
@@ -58,11 +61,15 @@ const transformShorthandValue =
58
61
 
59
62
  export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
60
63
  const isRawValue = allowShorthand === false || !(propName in transforms)
61
- const propValue = isRawValue ? transformRawValue(inputValue) : transformShorthandValue(propName, inputValue.trim())
62
- return propValue && propValue.$merge ? propValue.$merge : { [propName]: propValue }
64
+ const propValue = isRawValue
65
+ ? transformRawValue(inputValue)
66
+ : transformShorthandValue(propName, inputValue.trim())
67
+ return propValue && propValue.$merge
68
+ ? propValue.$merge
69
+ : { [propName]: propValue }
63
70
  }
64
71
 
65
- export const getPropertyName = propName => {
72
+ export const getPropertyName = (propName) => {
66
73
  const isCustomProp = /^--\w+/.test(propName)
67
74
  if (isCustomProp) {
68
75
  return propName
@@ -75,5 +82,8 @@ export default (rules, shorthandBlacklist = []) =>
75
82
  const propertyName = getPropertyName(rule[0])
76
83
  const value = rule[1]
77
84
  const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1
78
- return Object.assign(accum, getStylesForProperty(propertyName, value, allowShorthand))
85
+ return Object.assign(
86
+ accum,
87
+ getStylesForProperty(propertyName, value, allowShorthand),
88
+ )
79
89
  }, {})
@@ -1,20 +1,24 @@
1
- import { stringify } from 'postcss-value-parser'
2
1
  import cssColorKeywords from 'css-color-keywords'
2
+ import { stringify } from 'postcss-value-parser'
3
3
 
4
- const matchString = node => {
4
+ const matchString = (node) => {
5
5
  if (node.type !== 'string') return null
6
6
  return node.value
7
- .replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) => String.fromCharCode(parseInt(charCode, 16)))
7
+ .replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) =>
8
+ String.fromCharCode(parseInt(charCode, 16)),
9
+ )
8
10
  .replace(/\\/g, '')
9
11
  }
10
12
 
11
13
  const hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i
12
14
  const cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/
13
15
 
14
- const matchColor = node => {
16
+ const matchColor = (node) => {
15
17
  if (
16
18
  node.type === 'word' &&
17
- (hexColorRe.test(node.value) || node.value in cssColorKeywords || node.value === 'transparent')
19
+ (hexColorRe.test(node.value) ||
20
+ node.value in cssColorKeywords ||
21
+ node.value === 'transparent')
18
22
  ) {
19
23
  return node.value
20
24
  } else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {
@@ -29,34 +33,54 @@ const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i
29
33
  // Note if these are wrong, you'll need to change index.js too
30
34
  const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/
31
35
  // 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|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/
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))$/
34
40
  const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/
35
41
  const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
36
42
 
37
- const noopToken = predicate => node => (predicate(node) ? '<token>' : null)
43
+ const noopToken = (predicate) => (node) => predicate(node) ? '<token>' : null
38
44
 
39
- const valueForTypeToken = type => node => (node.type === type ? node.value : null)
45
+ const valueForTypeToken = (type) => (node) =>
46
+ node.type === type ? node.value : null
40
47
 
41
- export const regExpToken = (regExp, transform = String) => node => {
42
- if (node.type !== 'word') return null
48
+ const functionValueForTypeToken = (type) => (node) => {
49
+ if (node.type === type) {
50
+ // handle rgb(a) function value
51
+ if (/^rgba?$/i.test(node.value)) {
52
+ const result = node.nodes
53
+ .filter((token) => token.type === 'word')
54
+ .map((token) => token.value)
43
55
 
44
- const match = node.value.match(regExp)
45
- if (match === null) return null
46
-
47
- const value = transform(match[1])
48
- if (/(\d+)px/.test(node.value)) {
49
- return `scalePx2dp(${value})`
50
- } else {
51
- return value
56
+ return `${node.value}(${result.join(', ')})`
57
+ }
52
58
  }
59
+ return null
53
60
  }
54
61
 
62
+ export const regExpToken =
63
+ (regExp, transform = String) =>
64
+ (node) => {
65
+ if (node.type !== 'word') return null
66
+
67
+ const match = node.value.match(regExp)
68
+ if (match === null) return null
69
+
70
+ const value = transform(match[1])
71
+ if (/(\d+)px/.test(node.value)) {
72
+ return `scalePx2dp(${value})`
73
+ } else {
74
+ return value
75
+ }
76
+ }
77
+
55
78
  export const tokens = {
56
- SPACE: noopToken(node => node.type === 'space'),
57
- SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
58
- COMMA: noopToken(node => node.type === 'div' && node.value === ','),
79
+ SPACE: noopToken((node) => node.type === 'space'),
80
+ SLASH: noopToken((node) => node.type === 'div' && node.value === '/'),
81
+ COMMA: noopToken((node) => node.type === 'div' && node.value === ','),
59
82
  WORD: valueForTypeToken('word'),
83
+ FUNC: functionValueForTypeToken('function'),
60
84
  NONE: regExpToken(noneRe),
61
85
  AUTO: regExpToken(autoRe),
62
86
  NUMBER: regExpToken(numberRe, Number),
@@ -67,5 +91,5 @@ export const tokens = {
67
91
  IDENT: regExpToken(identRe),
68
92
  STRING: matchString,
69
93
  COLOR: matchColor,
70
- LINE: regExpToken(/^(none|underline|line-through)$/i)
94
+ LINE: regExpToken(/^(none|underline|line-through)$/i),
71
95
  }
@@ -1,28 +1,23 @@
1
1
  import { regExpToken, tokens } from '../tokenTypes'
2
- import { directionFactory, anyOrderFactory } from './util'
2
+ import { anyOrderFactory, directionFactory } from './util'
3
3
 
4
- const {
5
- WORD,
6
- COLOR,
7
- LENGTH,
8
- UNSUPPORTED_LENGTH_UNIT
9
- } = tokens
4
+ const { WORD, FUNC, COLOR, LENGTH, UNSUPPORTED_LENGTH_UNIT } = tokens
10
5
 
11
6
  function borderDirectionFactory (direction = '') {
12
7
  const prefix = `border${direction}`
13
8
  return anyOrderFactory({
14
9
  [`${prefix}Width`]: {
15
10
  tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
16
- default: 1
11
+ default: 1,
17
12
  },
18
13
  [`${prefix}Color`]: {
19
14
  tokens: [COLOR],
20
- default: 'black'
15
+ default: 'black',
21
16
  },
22
17
  [`${prefix}Style`]: {
23
18
  tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
24
- default: 'solid'
25
- }
19
+ default: 'solid',
20
+ },
26
21
  })
27
22
  }
28
23
 
@@ -34,15 +29,18 @@ export const borderBottom = borderDirectionFactory('Bottom')
34
29
  export const borderLeft = borderDirectionFactory('Left')
35
30
 
36
31
  export const borderColor = directionFactory({
37
- types: [WORD],
32
+ types: [WORD, FUNC],
38
33
  prefix: 'border',
39
- suffix: 'Color'
34
+ suffix: 'Color',
40
35
  })
41
36
 
42
37
  export const borderRadius = directionFactory({
43
38
  directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'],
44
39
  prefix: 'border',
45
- suffix: 'Radius'
40
+ suffix: 'Radius',
46
41
  })
47
42
 
48
- export const borderWidth = directionFactory({ prefix: 'border', suffix: 'Width' })
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 (typeof fontWeight === 'undefined' && tokenStream.matches(WEIGHT)) {
28
+ } else if (
29
+ typeof fontWeight === 'undefined' &&
30
+ tokenStream.matches(WEIGHT)
31
+ ) {
29
32
  fontWeight = tokenStream.lastValue
30
- } else if (typeof fontVariant === 'undefined' && tokenStream.matches(VARIANT)) {
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 = typeof fontSize === 'string' ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') : fontSize
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 { border, borderTop, borderRight, borderBottom, borderLeft, borderColor, borderRadius, borderWidth } from './border'
11
- import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'
20
+ import { anyOrderFactory, directionFactory, shadowOffsetFactory } from './util'
12
21
 
13
- const {
14
- IDENT,
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 = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/
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 = {}) => {
@@ -59,6 +61,10 @@ const transformDecls = (styles, declarations, result, options = {}) => {
59
61
  ) {
60
62
  value = value.replace(/(\d+)px/g, '$1PX')
61
63
  }
64
+ // expect value is legal so that remove !import
65
+ if (/!import/i.test(value)) {
66
+ value = value.replace(/!import/, '')
67
+ }
62
68
 
63
69
  if (shorthandBorderProps.indexOf(property) > -1) {
64
70
  // transform single value shorthand border properties back to
@@ -99,7 +105,7 @@ const transform = (css, options) => {
99
105
 
100
106
  if (isAlreadyDefinedAsClass) {
101
107
  throw new Error(
102
- `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}"`,
103
109
  )
104
110
  }
105
111
 
@@ -132,12 +138,12 @@ const transform = (css, options) => {
132
138
  ) {
133
139
  const parsed = mediaQuery.parse(rule.media)
134
140
 
135
- parsed.forEach(mq => {
141
+ parsed.forEach((mq) => {
136
142
  if (mediaQueryTypes.indexOf(mq.type) === -1) {
137
143
  throw new Error(`Failed to parse media query type "${mq.type}"`)
138
144
  }
139
145
 
140
- mq.expressions.forEach(e => {
146
+ mq.expressions.forEach((e) => {
141
147
  const mf = e.modifier ? `${e.modifier}-${e.feature}` : e.feature
142
148
  const val = e.value ? `: ${e.value}` : ''
143
149
 
@@ -150,7 +156,7 @@ const transform = (css, options) => {
150
156
  lengthRe.test(e.value) === false
151
157
  ) {
152
158
  throw new Error(
153
- `Failed to parse media query expression "(${mf}${val})"`
159
+ `Failed to parse media query expression "(${mf}${val})"`,
154
160
  )
155
161
  }
156
162
  })
@@ -182,8 +188,6 @@ const transform = (css, options) => {
182
188
  return result
183
189
  }
184
190
 
185
- export {
186
- transformCSS
187
- }
191
+ export { transformCSS }
188
192
 
189
193
  export default transform
@@ -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
- // Uppercases the first character in each group immediately following a space
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()