@cssxjs/css-to-react-native 3.2.0-0

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.
Files changed (44) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +115 -0
  3. package/index.d.ts +17 -0
  4. package/index.js +930 -0
  5. package/package.json +68 -0
  6. package/src/TokenStream.js +74 -0
  7. package/src/__tests__/aspectRatio.js +23 -0
  8. package/src/__tests__/border.js +141 -0
  9. package/src/__tests__/borderColor.js +92 -0
  10. package/src/__tests__/boxModel.js +136 -0
  11. package/src/__tests__/boxShadow.js +167 -0
  12. package/src/__tests__/colors.js +31 -0
  13. package/src/__tests__/flex.js +122 -0
  14. package/src/__tests__/flexFlow.js +22 -0
  15. package/src/__tests__/font.js +117 -0
  16. package/src/__tests__/fontFamily.js +43 -0
  17. package/src/__tests__/fontVariant.js +15 -0
  18. package/src/__tests__/fontWeight.js +8 -0
  19. package/src/__tests__/index.js +238 -0
  20. package/src/__tests__/placeContent.js +19 -0
  21. package/src/__tests__/shadowOffsets.js +13 -0
  22. package/src/__tests__/textDecoration.js +165 -0
  23. package/src/__tests__/textDecorationLine.js +23 -0
  24. package/src/__tests__/textShadow.js +107 -0
  25. package/src/__tests__/transform.js +69 -0
  26. package/src/__tests__/units.js +132 -0
  27. package/src/devPropertiesWithoutUnitsRegExp.js +19 -0
  28. package/src/index.js +90 -0
  29. package/src/tokenTypes.js +112 -0
  30. package/src/transforms/aspectRatio.js +12 -0
  31. package/src/transforms/border.js +57 -0
  32. package/src/transforms/boxShadow.js +11 -0
  33. package/src/transforms/flex.js +65 -0
  34. package/src/transforms/flexFlow.js +37 -0
  35. package/src/transforms/font.js +63 -0
  36. package/src/transforms/fontFamily.js +20 -0
  37. package/src/transforms/fontVariant.js +14 -0
  38. package/src/transforms/index.js +78 -0
  39. package/src/transforms/placeContent.js +24 -0
  40. package/src/transforms/textDecoration.js +56 -0
  41. package/src/transforms/textDecorationLine.js +18 -0
  42. package/src/transforms/textShadow.js +10 -0
  43. package/src/transforms/transform.js +74 -0
  44. package/src/transforms/util.js +103 -0
@@ -0,0 +1,103 @@
1
+ import {
2
+ LENGTH,
3
+ UNSUPPORTED_LENGTH_UNIT,
4
+ PERCENT,
5
+ COLOR,
6
+ SPACE,
7
+ NONE,
8
+ VARIABLE,
9
+ } from '../tokenTypes'
10
+
11
+ export const directionFactory = ({
12
+ types = [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT],
13
+ directions = ['Top', 'Right', 'Bottom', 'Left'],
14
+ prefix = '',
15
+ suffix = '',
16
+ }) => tokenStream => {
17
+ const values = []
18
+
19
+ // borderWidth doesn't currently allow a percent value, but may do in the future
20
+ values.push(tokenStream.expect(...types))
21
+
22
+ while (values.length < 4 && tokenStream.hasTokens()) {
23
+ tokenStream.expect(SPACE)
24
+ values.push(tokenStream.expect(...types))
25
+ }
26
+
27
+ tokenStream.expectEmpty()
28
+
29
+ const [top, right = top, bottom = top, left = right] = values
30
+
31
+ const keyFor = n => `${prefix}${directions[n]}${suffix}`
32
+
33
+ return {
34
+ [keyFor(0)]: top,
35
+ [keyFor(1)]: right,
36
+ [keyFor(2)]: bottom,
37
+ [keyFor(3)]: left,
38
+ }
39
+ }
40
+
41
+ export const parseShadowOffset = tokenStream => {
42
+ const width = tokenStream.expect(LENGTH)
43
+ const height = tokenStream.matches(SPACE) ? tokenStream.expect(LENGTH) : width
44
+ tokenStream.expectEmpty()
45
+ return { width, height }
46
+ }
47
+
48
+ export const parseShadow = tokenStream => {
49
+ let offsetX
50
+ let offsetY
51
+ let radius
52
+ let color
53
+
54
+ if (tokenStream.matches(NONE)) {
55
+ tokenStream.expectEmpty()
56
+ return {
57
+ offset: { width: 0, height: 0 },
58
+ radius: 0,
59
+ color: 'black',
60
+ }
61
+ }
62
+
63
+ let didParseFirst = false
64
+ while (tokenStream.hasTokens()) {
65
+ if (didParseFirst) tokenStream.expect(SPACE)
66
+
67
+ if (
68
+ offsetX === undefined &&
69
+ tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
70
+ ) {
71
+ offsetX = tokenStream.lastValue
72
+ tokenStream.expect(SPACE)
73
+ offsetY = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT)
74
+
75
+ tokenStream.saveRewindPoint()
76
+ if (
77
+ tokenStream.matches(SPACE) &&
78
+ tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
79
+ ) {
80
+ radius = tokenStream.lastValue
81
+ } else {
82
+ tokenStream.rewind()
83
+ }
84
+ } else if (
85
+ color === undefined &&
86
+ (tokenStream.matches(COLOR) || tokenStream.matches(VARIABLE))
87
+ ) {
88
+ color = tokenStream.lastValue
89
+ } else {
90
+ tokenStream.throw()
91
+ }
92
+
93
+ didParseFirst = true
94
+ }
95
+
96
+ if (offsetX === undefined) tokenStream.throw()
97
+
98
+ return {
99
+ offset: { width: offsetX, height: offsetY },
100
+ radius: radius !== undefined ? radius : 0,
101
+ color: color !== undefined ? color : 'black',
102
+ }
103
+ }