rn-css 1.8.13 → 1.9.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/README.md +16 -0
- package/dist/app.json +4 -0
- package/dist/cssToRN/convert.js +26 -6
- package/dist/index.d.ts +3 -1439
- package/dist/index.js +166 -56
- package/dist/src/convertStyle.d.ts +5 -0
- package/dist/src/convertStyle.js +56 -0
- package/dist/src/convertUnits.d.ts +5 -0
- package/dist/src/convertUnits.js +71 -0
- package/dist/src/cssToRN/convert.d.ts +55 -0
- package/dist/src/cssToRN/convert.js +418 -0
- package/dist/src/cssToRN/index.d.ts +8 -0
- package/dist/src/cssToRN/index.js +134 -0
- package/dist/src/cssToRN/maths.d.ts +4 -0
- package/dist/src/cssToRN/maths.js +86 -0
- package/dist/src/cssToRN/mediaQueries.d.ts +7 -0
- package/dist/src/cssToRN/mediaQueries.js +161 -0
- package/dist/src/features.d.ts +34 -0
- package/dist/src/features.js +102 -0
- package/dist/src/generateHash.d.ts +2 -0
- package/dist/src/generateHash.js +8 -0
- package/dist/src/index.d.ts +1805 -0
- package/dist/src/index.js +60 -0
- package/dist/src/polyfill.d.ts +3 -0
- package/dist/src/polyfill.js +23 -0
- package/dist/src/rnToCss.d.ts +3 -0
- package/dist/src/rnToCss.js +8 -0
- package/dist/src/styleComponent.d.ts +45 -0
- package/dist/src/styleComponent.js +163 -0
- package/dist/src/types.d.ts +85 -0
- package/dist/src/types.js +2 -0
- package/dist/src/useTheme.d.ts +18 -0
- package/dist/src/useTheme.js +33 -0
- package/package.json +1 -1
- package/src/cssToRN/convert.ts +25 -6
- package/src/cssToRN/index.ts +7 -1
- package/src/features.tsx +15 -1
- package/src/styleComponent.tsx +15 -8
- package/src/types.ts +1 -0
- package/CHANGELOG.md +0 -25
package/dist/index.js
CHANGED
|
@@ -1,60 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const app_json_1 = require("./app.json");
|
|
11
|
+
const src_1 = __importDefault(require("./src"));
|
|
12
|
+
const value = 100;
|
|
13
|
+
const View = src_1.default.View `
|
|
14
|
+
background: green;
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
width: 200px;
|
|
17
|
+
height: 200px;
|
|
18
|
+
`;
|
|
19
|
+
const Dot = (0, src_1.default)(react_native_1.Animated.View) `
|
|
20
|
+
width: 5em;
|
|
21
|
+
height: 5em;
|
|
22
|
+
margin: 2em;
|
|
23
|
+
border-radius: 50%;
|
|
24
|
+
z-index: 10;
|
|
25
|
+
`;
|
|
26
|
+
const StyledText = src_1.default.Text `
|
|
27
|
+
color: ${props => props.col || 'black'}
|
|
28
|
+
font-size: 1em;
|
|
29
|
+
@media (max-width: 40em) {
|
|
30
|
+
color: blue;
|
|
31
|
+
font-size: 2em;
|
|
32
|
+
}
|
|
33
|
+
@media (max-width: 20em) {
|
|
34
|
+
color: red;
|
|
35
|
+
font-size: 3em;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const Box = src_1.default.View `
|
|
39
|
+
width: ${value}em;
|
|
40
|
+
max-width: 50vw;
|
|
41
|
+
`;
|
|
42
|
+
const Box2 = src_1.default.View `
|
|
43
|
+
width: 100vw;
|
|
44
|
+
height: 2em;
|
|
45
|
+
background: blue;
|
|
46
|
+
`;
|
|
47
|
+
const Popup = src_1.default.View `
|
|
48
|
+
z-index: 20;
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: calc(100% + 2px);
|
|
51
|
+
background-color: black;
|
|
52
|
+
`;
|
|
53
|
+
const Hoverable = src_1.default.View `
|
|
54
|
+
width: 100px;
|
|
55
|
+
height: 100px;
|
|
56
|
+
background: red;
|
|
57
|
+
&:hover {
|
|
58
|
+
background: blue;
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
const HoverableText = src_1.default.Text `
|
|
62
|
+
&:hover {
|
|
63
|
+
fontSize: 2em
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
const Options = src_1.default.FlatList.attrs(props => ({ pressed: props.selected || props.pressed })) `
|
|
67
|
+
position: absolute;
|
|
68
|
+
top: 100%;
|
|
69
|
+
z-index: 1;
|
|
70
|
+
`;
|
|
71
|
+
const ColorCircle = src_1.default.TouchableOpacity `
|
|
72
|
+
background-color: ${props => props.color};
|
|
73
|
+
width: ${props => props.size || 2}em;
|
|
74
|
+
height: ${props => props.size || 2}em;
|
|
75
|
+
opacity: 1;
|
|
76
|
+
border-radius: 50%;
|
|
77
|
+
&:hover {
|
|
78
|
+
background-color: red;
|
|
79
|
+
opacity: 0.5;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
const FlatList = () => {
|
|
83
|
+
return react_1.default.createElement(Options, { data: ['teset'], selected: true, pressed: true, renderItem: ({ item }) => (react_1.default.createElement(StyledText, { col: 'blue' }, item)) });
|
|
84
|
+
};
|
|
85
|
+
const Comp = ({ style, text }) => {
|
|
86
|
+
return react_1.default.createElement(View, { style: style },
|
|
87
|
+
react_1.default.createElement(react_native_1.Text, null, text));
|
|
88
|
+
};
|
|
89
|
+
const ExtendedComp = (0, src_1.default)(Comp).attrs({ text: 'test' }) ``;
|
|
90
|
+
// const ExtendedComp2 = styled(Comp)<{ small: boolean }>`
|
|
91
|
+
// ${props => props.small ? 'font-size: 0.8em' : ''}
|
|
92
|
+
// `
|
|
93
|
+
const CustomTouchable = src_1.default.TouchableOpacity.attrs({ activeOpacity: 1 }) ``;
|
|
94
|
+
const Touchable = src_1.default.TouchableOpacity `
|
|
95
|
+
background-color: ${props => props.pressed ? 'blue' : 'red'};
|
|
96
|
+
&:active {
|
|
97
|
+
background-color: purple;
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
// const CustomSelectContainer = styled.TouchableOpacity.attrs({ activeOpacity: 1 })`
|
|
101
|
+
// padding: 2px;
|
|
102
|
+
// margin: 0.2em;
|
|
103
|
+
// border-radius: 0.6em;
|
|
104
|
+
// width: 8em;
|
|
105
|
+
// height: 3.6em;
|
|
106
|
+
// flex-direction: row;
|
|
107
|
+
// background-color: white;
|
|
108
|
+
// border-width: 1px;
|
|
109
|
+
// border-style: solid;
|
|
110
|
+
// `
|
|
111
|
+
const Forward = react_1.default.forwardRef((props, ref) => {
|
|
112
|
+
return react_1.default.createElement(Touchable, { ref: ref, ...props, pressed: true });
|
|
13
113
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return result;
|
|
114
|
+
Forward.displayName = 'Forward';
|
|
115
|
+
const Button = ({ color, style }) => {
|
|
116
|
+
const [pressed, setPressed] = react_1.default.useState(false);
|
|
117
|
+
return react_1.default.createElement(Touchable, { pressed: pressed, onPress: () => setPressed(!pressed) },
|
|
118
|
+
react_1.default.createElement(StyledText, { style: style, col: color }, "Press Me!"));
|
|
20
119
|
};
|
|
21
|
-
|
|
22
|
-
|
|
120
|
+
const StyledButton = (0, src_1.default)(Button).attrs(({ color: 'black' })) ``;
|
|
121
|
+
const StyledButton2 = (0, src_1.default)(Button).attrs(({ color: 'black' })) ``;
|
|
122
|
+
const App = () => {
|
|
123
|
+
const ref = react_1.default.useRef(null);
|
|
124
|
+
const ref2 = react_1.default.useRef(null);
|
|
125
|
+
react_1.default.useLayoutEffect(() => console.log(ref), []);
|
|
126
|
+
const dotLeft = react_1.default.useRef(new react_native_1.Animated.Value(0));
|
|
127
|
+
const dotStyle = react_1.default.useMemo(() => ({
|
|
128
|
+
left: dotLeft.current.interpolate({
|
|
129
|
+
inputRange: [0, 50],
|
|
130
|
+
outputRange: ['0%', '50%']
|
|
131
|
+
})
|
|
132
|
+
}), []);
|
|
133
|
+
// const LangDropdownItem = styled.View.attrs<{ label: string; value: number }>(
|
|
134
|
+
// ({ label }) => ({
|
|
135
|
+
// label: label + 2
|
|
136
|
+
// })
|
|
137
|
+
// )`
|
|
138
|
+
// z-index: ${props => props.value + ''};
|
|
139
|
+
// `
|
|
140
|
+
const touchableProps = { activeOpacity: 0 };
|
|
141
|
+
return (react_1.default.createElement(Box, { ref: ref2 },
|
|
142
|
+
react_1.default.createElement(View, { style: { flexDirection: 'column' } },
|
|
143
|
+
react_1.default.createElement(StyledText, { ref: ref, col: 'black', numberOfLines: 1, style: { flexGrow: 1, flexBasis: 'auto' } }, "Welcome to ReactNativeStyledComponents")),
|
|
144
|
+
react_1.default.createElement(Box, null,
|
|
145
|
+
react_1.default.createElement(Box, null,
|
|
146
|
+
react_1.default.createElement(Box, null,
|
|
147
|
+
react_1.default.createElement(StyledText, { col: 'red' }, "Placeholder"),
|
|
148
|
+
react_1.default.createElement(Popup, null,
|
|
149
|
+
react_1.default.createElement(StyledText, { col: 'green' }, "Should be over")))),
|
|
150
|
+
react_1.default.createElement(Box, null,
|
|
151
|
+
react_1.default.createElement(StyledText, { col: 'red' }, "Placeholder"))),
|
|
152
|
+
react_1.default.createElement(Hoverable, null,
|
|
153
|
+
react_1.default.createElement(StyledText, { col: 'white' }, "Hover me !")),
|
|
154
|
+
react_1.default.createElement(HoverableText, null, "Hover me !"),
|
|
155
|
+
react_1.default.createElement(StyledButton, { fallbackColor: 'white' }),
|
|
156
|
+
react_1.default.createElement(StyledButton2, { color: 'white' }),
|
|
157
|
+
react_1.default.createElement(FlatList, null),
|
|
158
|
+
react_1.default.createElement(Box2, null),
|
|
159
|
+
react_1.default.createElement(ColorCircle, { color: "#236AFF", onLayout: (e) => { console.log(e.nativeEvent.layout); } }),
|
|
160
|
+
react_1.default.createElement(Dot, { style: dotStyle }),
|
|
161
|
+
react_1.default.createElement(CustomTouchable, { style: {}, ...touchableProps, activeOpacity: 0, extra: 'test' },
|
|
162
|
+
react_1.default.createElement(ExtendedComp, { style: {}, text: 'notest' }))));
|
|
23
163
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var styleComponent_2 = require("./styleComponent");
|
|
32
|
-
Object.defineProperty(exports, "SharedValue", { enumerable: true, get: function () { return styleComponent_2.SharedValue; } });
|
|
33
|
-
Object.defineProperty(exports, "FontSizeContext", { enumerable: true, get: function () { return styleComponent_2.FontSizeContext; } });
|
|
34
|
-
Object.defineProperty(exports, "RemContext", { enumerable: true, get: function () { return styleComponent_2.RemContext; } });
|
|
35
|
-
__exportStar(require("./useTheme"), exports);
|
|
36
|
-
const styled = (Component) => (0, styleComponent_1.default)(Component);
|
|
37
|
-
styled.ActivityIndicator = styled(RN.ActivityIndicator);
|
|
38
|
-
styled.DrawerLayoutAndroid = styled(RN.DrawerLayoutAndroid);
|
|
39
|
-
styled.Image = styled(RN.Image);
|
|
40
|
-
styled.ImageBackground = styled(RN.ImageBackground);
|
|
41
|
-
styled.KeyboardAvoidingView = styled(RN.KeyboardAvoidingView);
|
|
42
|
-
styled.Modal = styled(RN.Modal);
|
|
43
|
-
styled.NavigatorIOS = styled(RN.NavigatorIOS);
|
|
44
|
-
styled.ScrollView = styled(RN.ScrollView);
|
|
45
|
-
styled.SnapshotViewIOS = styled(RN.SnapshotViewIOS);
|
|
46
|
-
styled.Switch = styled(RN.Switch);
|
|
47
|
-
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView);
|
|
48
|
-
styled.RefreshControl = styled(RN.RefreshControl);
|
|
49
|
-
styled.SafeAreaView = styled(RN.SafeAreaView);
|
|
50
|
-
styled.Text = styled(RN.Text);
|
|
51
|
-
styled.TextInput = styled(RN.TextInput);
|
|
52
|
-
styled.TouchableHighlight = styled(RN.TouchableHighlight);
|
|
53
|
-
styled.TouchableNativeFeedback = styled(RN.TouchableNativeFeedback);
|
|
54
|
-
styled.TouchableOpacity = styled(RN.TouchableOpacity);
|
|
55
|
-
styled.TouchableWithoutFeedback = styled(RN.TouchableWithoutFeedback);
|
|
56
|
-
styled.View = styled(RN.View);
|
|
57
|
-
styled.FlatList = styleComponent_1.styledFlatList;
|
|
58
|
-
styled.SectionList = styleComponent_1.styledSectionList;
|
|
59
|
-
styled.VirtualizedList = styleComponent_1.styledVirtualizedList;
|
|
60
|
-
exports.default = styled;
|
|
164
|
+
react_native_1.AppRegistry.registerComponent(app_json_1.name, () => App);
|
|
165
|
+
if (react_native_1.Platform.OS === 'web') {
|
|
166
|
+
react_native_1.AppRegistry.runApplication(app_json_1.name, {
|
|
167
|
+
rootTag: document.getElementsByTagName('body')[0]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
exports.default = App;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { /* StyleSheet, */ Animated, TextStyle } from 'react-native';
|
|
2
|
+
import type { AnyStyle, PartialStyle, Units } from './types';
|
|
3
|
+
/** Mix the calculated RN style within the object style */
|
|
4
|
+
declare const convertStyle: <T extends AnyStyle | Animated.WithAnimatedObject<import("react-native").ViewStyle> | Animated.WithAnimatedObject<TextStyle> | Animated.WithAnimatedObject<import("react-native").ImageStyle> = AnyStyle>(rnStyle: PartialStyle, units: Units) => T;
|
|
5
|
+
export default convertStyle;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const convertUnits_1 = require("./convertUnits");
|
|
4
|
+
/** Mix the calculated RN style within the object style */
|
|
5
|
+
const convertStyle = (rnStyle, units) => {
|
|
6
|
+
/** This is the result of the convertions from css style into RN style */
|
|
7
|
+
const convertedStyle = {};
|
|
8
|
+
// If width and height are specified, we can use those values for the first render
|
|
9
|
+
['width', 'height'].forEach(key => {
|
|
10
|
+
if (!units[key] && rnStyle[key]) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
+
const converted = (0, convertUnits_1.convertValue)(key, rnStyle[key], units);
|
|
13
|
+
if (!Number.isNaN(converted))
|
|
14
|
+
units[key] = converted;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.keys(rnStyle).forEach(key => {
|
|
18
|
+
const value = rnStyle[key] || '0';
|
|
19
|
+
// Handle object values
|
|
20
|
+
if (key === 'transform' && rnStyle.transform) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
|
+
convertedStyle.transform = rnStyle.transform.map(transformation => {
|
|
23
|
+
const result = {};
|
|
24
|
+
Object.keys(transformation).forEach(k => (result[k] = (0, convertUnits_1.convertValue)(k, transformation[k], units)));
|
|
25
|
+
return result;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else if (key === 'shadowOffset' && rnStyle.shadowOffset) {
|
|
29
|
+
convertedStyle.shadowOffset = {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
+
width: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.width || '0', units),
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
+
height: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.height || '0', units)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else if (key === 'textShadowOffset' && rnStyle.textShadowOffset) {
|
|
37
|
+
convertedStyle.textShadowOffset = {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
width: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.width || '0', units),
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
41
|
+
height: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.height || '0', units)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Font family should not be transformed (same as cursor for web in case of base64 value)
|
|
45
|
+
else if (['cursor', 'fontFamily'].includes(key)) {
|
|
46
|
+
convertedStyle[key] = value;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
convertedStyle[key] = (0, convertUnits_1.convertValue)(key, value, units);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return convertedStyle;
|
|
55
|
+
};
|
|
56
|
+
exports.default = convertStyle;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PartialStyle, Transform, Units } from './types';
|
|
2
|
+
/** Take a css value like 12em and return [12, 'em'] */
|
|
3
|
+
export declare function parseValue(value: string): [number, string | undefined];
|
|
4
|
+
/** Convert a value using the provided unit transform table */
|
|
5
|
+
export declare function convertValue(key: keyof PartialStyle | keyof Transform, value: string, units: Units): string | number;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertValue = exports.parseValue = void 0;
|
|
4
|
+
const maths_1 = require("./cssToRN/maths");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
/** Take a css value like 12em and return [12, 'em'] */
|
|
7
|
+
function parseValue(value) {
|
|
8
|
+
// Match a single unit
|
|
9
|
+
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i);
|
|
10
|
+
return [parseFloat(unit[1]), unit[3]];
|
|
11
|
+
}
|
|
12
|
+
exports.parseValue = parseValue;
|
|
13
|
+
/** Convert a value using the provided unit transform table */
|
|
14
|
+
function convertValue(key, value, units) {
|
|
15
|
+
if (typeof value !== 'string') {
|
|
16
|
+
console.error(`Failed to parse CSS instruction: ${key}=${value}. We expect a string, but ${value} was of type ${typeof value}.`);
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
// colors should be left untouched
|
|
20
|
+
if (value.startsWith('#'))
|
|
21
|
+
return value;
|
|
22
|
+
// Percentage values need to rely on an other unit as reference
|
|
23
|
+
const finalUnits = { ...units };
|
|
24
|
+
if (value.includes('%')) {
|
|
25
|
+
if (react_native_1.Platform.OS === 'web')
|
|
26
|
+
return value;
|
|
27
|
+
if (['marginTop', 'marginBottom', 'translateY'].includes(key))
|
|
28
|
+
finalUnits['%'] = units.height / 100;
|
|
29
|
+
else if (['marginLeft', 'marginRight', 'translateX'].includes(key))
|
|
30
|
+
finalUnits['%'] = units.width / 100;
|
|
31
|
+
else if (key.startsWith('border') && key.endsWith('Radius'))
|
|
32
|
+
finalUnits['%'] = (units.width + units.height) / 200;
|
|
33
|
+
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
34
|
+
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
|
35
|
+
if (['height', 'minHeight', 'maxHeight', 'top', 'bottom'].includes(key))
|
|
36
|
+
finalUnits['%'] = units.height / 100;
|
|
37
|
+
else
|
|
38
|
+
finalUnits['%'] = units.width / 100;
|
|
39
|
+
}
|
|
40
|
+
// width: 100%, height: 100% are supported
|
|
41
|
+
else
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
else if (['lineHeight'].includes(key))
|
|
45
|
+
finalUnits['%'] = units.em / 100;
|
|
46
|
+
else
|
|
47
|
+
finalUnits['%'] = 0.01;
|
|
48
|
+
}
|
|
49
|
+
// We replace all units within the value
|
|
50
|
+
const convertedValue = value.replace(/(\b\d+(\.\d+)?)([a-z]+\b|%)/ig, occ => {
|
|
51
|
+
const [val, unit] = parseValue(occ);
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
+
if (['deg', 'rad', 'turn', 's'].includes(unit))
|
|
54
|
+
return occ; // We don't want to convert deg, rad, turn, second units
|
|
55
|
+
return val * (finalUnits[unit || 'px']) + '';
|
|
56
|
+
});
|
|
57
|
+
// We handle extra calculations (calc, min, max, parsing...)
|
|
58
|
+
if (convertedValue.startsWith('calc('))
|
|
59
|
+
return (0, maths_1.calculate)(convertedValue.substring(4)); // remove calc. We can keep the parenthesis
|
|
60
|
+
else if (convertedValue.startsWith('max('))
|
|
61
|
+
return (0, maths_1.max)(convertedValue.substring(4, convertedValue.length - 1)); // Remove max()
|
|
62
|
+
else if (convertedValue.startsWith('min('))
|
|
63
|
+
return (0, maths_1.min)(convertedValue.substring(4, convertedValue.length - 1)); // remove min()
|
|
64
|
+
else if (key === 'fontWeight')
|
|
65
|
+
return convertedValue; // fontWeight must be a string even when it is an integer value.
|
|
66
|
+
else if (parseFloat(convertedValue) + '' === convertedValue)
|
|
67
|
+
return parseFloat(convertedValue);
|
|
68
|
+
else
|
|
69
|
+
return convertedValue;
|
|
70
|
+
}
|
|
71
|
+
exports.convertValue = convertValue;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Style, Transform } from '../types';
|
|
2
|
+
/** Parse a css value for border */
|
|
3
|
+
export declare function border(value: string): {
|
|
4
|
+
[x: string]: string;
|
|
5
|
+
};
|
|
6
|
+
/** Parse a css value for border-like elements */
|
|
7
|
+
export declare function borderLike(prefixKey: 'outline' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function shadow(prefix: 'textShadow' | 'shadow', value: string): {
|
|
11
|
+
[x: string]: string | {
|
|
12
|
+
width: string;
|
|
13
|
+
height: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function flex(value: string): {
|
|
17
|
+
flexBasis: string;
|
|
18
|
+
flexGrow?: undefined;
|
|
19
|
+
flexShrink?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
flexGrow: string;
|
|
22
|
+
flexBasis: string;
|
|
23
|
+
flexShrink?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
flexGrow: string;
|
|
26
|
+
flexShrink: string;
|
|
27
|
+
flexBasis: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function flexFlow(value: string): {
|
|
30
|
+
[prop: string]: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function placeContent(value: string): {
|
|
33
|
+
alignContent: string;
|
|
34
|
+
justifyContent: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function background(value: string): {
|
|
37
|
+
backgroundColor: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
export declare function textDecoration(value: string): {
|
|
40
|
+
textDecorationLine: string;
|
|
41
|
+
textDecorationStyle: string;
|
|
42
|
+
textDecorationColor: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function transform(value: string): {
|
|
45
|
+
transform: Transform[];
|
|
46
|
+
};
|
|
47
|
+
export declare function font(value: string): Style;
|
|
48
|
+
/** Parses a css value for the side of an element (border-width, margin, padding) */
|
|
49
|
+
export declare function sideValue<T extends 'padding' | 'margin' | 'border'>(prefixKey: T, value: string, postFix?: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : ''): {
|
|
50
|
+
[x: string]: string;
|
|
51
|
+
};
|
|
52
|
+
/** Parses a css value for the corner of an element (border-radius) */
|
|
53
|
+
export declare function cornerValue(prefixKey: 'border', value: string, postFix: 'Radius'): {
|
|
54
|
+
[x: string]: string;
|
|
55
|
+
};
|