@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.
- package/LICENSE.md +21 -0
- package/README.md +115 -0
- package/index.d.ts +17 -0
- package/index.js +930 -0
- package/package.json +68 -0
- package/src/TokenStream.js +74 -0
- package/src/__tests__/aspectRatio.js +23 -0
- package/src/__tests__/border.js +141 -0
- package/src/__tests__/borderColor.js +92 -0
- package/src/__tests__/boxModel.js +136 -0
- package/src/__tests__/boxShadow.js +167 -0
- package/src/__tests__/colors.js +31 -0
- package/src/__tests__/flex.js +122 -0
- package/src/__tests__/flexFlow.js +22 -0
- package/src/__tests__/font.js +117 -0
- package/src/__tests__/fontFamily.js +43 -0
- package/src/__tests__/fontVariant.js +15 -0
- package/src/__tests__/fontWeight.js +8 -0
- package/src/__tests__/index.js +238 -0
- package/src/__tests__/placeContent.js +19 -0
- package/src/__tests__/shadowOffsets.js +13 -0
- package/src/__tests__/textDecoration.js +165 -0
- package/src/__tests__/textDecorationLine.js +23 -0
- package/src/__tests__/textShadow.js +107 -0
- package/src/__tests__/transform.js +69 -0
- package/src/__tests__/units.js +132 -0
- package/src/devPropertiesWithoutUnitsRegExp.js +19 -0
- package/src/index.js +90 -0
- package/src/tokenTypes.js +112 -0
- package/src/transforms/aspectRatio.js +12 -0
- package/src/transforms/border.js +57 -0
- package/src/transforms/boxShadow.js +11 -0
- package/src/transforms/flex.js +65 -0
- package/src/transforms/flexFlow.js +37 -0
- package/src/transforms/font.js +63 -0
- package/src/transforms/fontFamily.js +20 -0
- package/src/transforms/fontVariant.js +14 -0
- package/src/transforms/index.js +78 -0
- package/src/transforms/placeContent.js +24 -0
- package/src/transforms/textDecoration.js +56 -0
- package/src/transforms/textDecorationLine.js +18 -0
- package/src/transforms/textShadow.js +10 -0
- package/src/transforms/transform.js +74 -0
- package/src/transforms/util.js +103 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Jacob Parker and Maximilian Stoiber
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# css-to-react-native
|
|
2
|
+
|
|
3
|
+
Converts CSS text to a React Native stylesheet object.
|
|
4
|
+
|
|
5
|
+
[Try it here](https://csstox.surge.sh)
|
|
6
|
+
|
|
7
|
+
```css
|
|
8
|
+
font-size: 18px;
|
|
9
|
+
line-height: 24px;
|
|
10
|
+
color: red;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
{
|
|
15
|
+
fontSize: 18,
|
|
16
|
+
lineHeight: 24,
|
|
17
|
+
color: 'red',
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Converts all number-like values to numbers, and string-like to strings.
|
|
22
|
+
|
|
23
|
+
Automatically converts indirect values to their React Native equivalents.
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
text-shadow-offset: 10px 5px;
|
|
27
|
+
font-variant: small-caps;
|
|
28
|
+
transform: translate(10px, 5px) scale(5);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
{
|
|
33
|
+
textShadowOffset: { width: 10, height: 5 },
|
|
34
|
+
fontVariant: ['small-caps'],
|
|
35
|
+
// Fixes backwards transform order
|
|
36
|
+
transform: [
|
|
37
|
+
{ translateY: 5 },
|
|
38
|
+
{ translateX: 10 },
|
|
39
|
+
{ scale: 5 },
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Also allows shorthand values.
|
|
45
|
+
|
|
46
|
+
```css
|
|
47
|
+
font: bold 14px/16px "Helvetica";
|
|
48
|
+
margin: 5px 7px 2px;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
{
|
|
53
|
+
fontFamily: 'Helvetica',
|
|
54
|
+
fontSize: 14,
|
|
55
|
+
fontWeight: 'bold',
|
|
56
|
+
fontStyle: 'normal',
|
|
57
|
+
fontVariant: [],
|
|
58
|
+
lineHeight: 16,
|
|
59
|
+
marginTop: 5,
|
|
60
|
+
marginRight: 7,
|
|
61
|
+
marginBottom: 2,
|
|
62
|
+
marginLeft: 7,
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Shorthands will only accept values that are supported in React, so `background` will only accept a colour, `backgroundColor`
|
|
67
|
+
|
|
68
|
+
There is also support for the `box-shadow` shorthand, and this converts into `shadow-` properties. Note that these only work on iOS.
|
|
69
|
+
|
|
70
|
+
#### Shorthand Notes
|
|
71
|
+
|
|
72
|
+
`border{Top,Right,Bottom,Left}` shorthands are not supported, because `borderStyle` cannot be applied to individual border sides.
|
|
73
|
+
|
|
74
|
+
# API
|
|
75
|
+
|
|
76
|
+
The API is mostly for implementors. However, the main API may be useful for non-implementors. The main API is an array of `[property, value]` tuples.
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import transform from 'css-to-react-native';
|
|
80
|
+
// or const transform = require('css-to-react-native').default;
|
|
81
|
+
|
|
82
|
+
transform([
|
|
83
|
+
['font', 'bold 14px/16px "Helvetica"'],
|
|
84
|
+
['margin', '5px 7px 2px'],
|
|
85
|
+
['border-left-width', '5px'],
|
|
86
|
+
]); // => { fontFamily: 'Helvetica', ... }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
We don't provide a way to get these style tuples in this library, so you'll need to do that yourself. I expect most people will use postCSS or another CSS parser. You should try avoid getting these with `string.split`, as that has a lot of edge cases (colons and semi-colons appearing in comments etc.)
|
|
90
|
+
|
|
91
|
+
For implementors, there is also a few extra APIs available.
|
|
92
|
+
|
|
93
|
+
These are for specific use-cases, and most people should just be using the API above.
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
import { getPropertyName, getStylesForProperty } from 'css-to-react-native';
|
|
97
|
+
|
|
98
|
+
getPropertyName('border-width'); // => 'borderWidth'
|
|
99
|
+
getStylesForProperty('borderWidth', '1px 0px 2px 0px'); // => { borderTopWidth: 1, ... }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Should you wish to opt-out of transforming certain shorthands, an array of property names in camelCase can be passed as a second argument to `transform`.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
transform([['border-radius', '50px']], ['borderRadius']);
|
|
106
|
+
// { borderRadius: 50 } rather than { borderTopLeft: ... }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This can also be done by passing a third argument, `false` to `getStylesForProperty`.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
Licensed under the MIT License, Copyright © 2019 Krister Kari, Jacob Parker, and Maximilian Stoiber.
|
|
114
|
+
|
|
115
|
+
See [LICENSE.md](./LICENSE.md) for more information.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type StyleTuple = [string, string]
|
|
2
|
+
|
|
3
|
+
export interface Style {
|
|
4
|
+
[key: string]: string | number | Style
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getPropertyName(name: string): string
|
|
8
|
+
export function getStylesForProperty(
|
|
9
|
+
name: string,
|
|
10
|
+
value: string,
|
|
11
|
+
allowShorthand?: boolean
|
|
12
|
+
): Style
|
|
13
|
+
|
|
14
|
+
export default function transform(
|
|
15
|
+
styleTuples: StyleTuple[],
|
|
16
|
+
shorthandBlacklist?: string[]
|
|
17
|
+
): Style
|