@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.22
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 +80 -43
- package/lib/StyleXCSSTypes.js +1 -1
- package/lib/StyleXSheet.js +18 -19
- package/lib/StyleXTypes.d.ts +26 -51
- package/lib/StyleXTypes.js +1 -1
- package/lib/StyleXTypes.js.flow +16 -16
- package/lib/native/CSSCustomPropertyValue.js +1 -1
- package/lib/native/CSSLengthUnitValue.js +7 -7
- package/lib/native/CSSMediaQuery.js +4 -4
- package/lib/native/SpreadOptions.d.ts +1 -0
- package/lib/native/SpreadOptions.js.flow +1 -0
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +16 -0
- package/lib/native/__tests__/parseTimeValue-test.js +3 -3
- package/lib/native/__tests__/stylex-css-var-test.js +60 -60
- package/lib/native/__tests__/stylex-test.js +306 -289
- package/lib/native/fixContentBox.js +7 -7
- package/lib/native/flattenStyle.js +1 -1
- package/lib/native/parseShadow.js +4 -4
- package/lib/native/parseTimeValue.js +4 -4
- package/lib/native/stylex.d.ts +15 -5
- package/lib/native/stylex.js +120 -89
- package/lib/native/stylex.js.flow +19 -5
- package/lib/stylex.d.ts +31 -22
- package/lib/stylex.js +81 -59
- package/lib/stylex.js.flow +32 -27
- package/package.json +2 -2
|
@@ -11,20 +11,20 @@ const BOTTOM = 2;
|
|
|
11
11
|
const LEFT = 3;
|
|
12
12
|
const START = LEFT;
|
|
13
13
|
const END = RIGHT;
|
|
14
|
-
const borderMapping = [[
|
|
15
|
-
const paddingMapping = [[
|
|
14
|
+
const borderMapping = [['borderWidth', [TOP, RIGHT, BOTTOM, LEFT]], ['borderTopWidth', [TOP]], ['borderRightWidth', [RIGHT]], ['borderBottomWidth', [BOTTOM]], ['borderLeftWidth', [LEFT]], ['borderStartWidth', [START]], ['borderEndWidth', [END]]];
|
|
15
|
+
const paddingMapping = [['padding', [TOP, RIGHT, BOTTOM, LEFT]], ['paddingVertical', [TOP, BOTTOM]], ['paddingHorizontal', [LEFT, RIGHT]], ['paddingTop', [TOP]], ['paddingRight', [RIGHT]], ['paddingBottom', [BOTTOM]], ['paddingLeft', [LEFT]], ['paddingStart', [START]], ['paddingEnd', [END]]];
|
|
16
16
|
function fixContentBox(flatStyle) {
|
|
17
17
|
const border = [0, 0, 0, 0];
|
|
18
18
|
const padding = [0, 0, 0, 0];
|
|
19
19
|
for (const [styleProp, directions] of borderMapping) {
|
|
20
|
-
if (typeof flatStyle[styleProp] ===
|
|
20
|
+
if (typeof flatStyle[styleProp] === 'number') {
|
|
21
21
|
for (const direction of directions) {
|
|
22
22
|
border[direction] = flatStyle[styleProp];
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
for (const [styleProp, directions] of paddingMapping) {
|
|
27
|
-
if (typeof flatStyle[styleProp] ===
|
|
27
|
+
if (typeof flatStyle[styleProp] === 'number') {
|
|
28
28
|
for (const direction of directions) {
|
|
29
29
|
padding[direction] = flatStyle[styleProp];
|
|
30
30
|
}
|
|
@@ -32,7 +32,7 @@ function fixContentBox(flatStyle) {
|
|
|
32
32
|
}
|
|
33
33
|
const correctionVertical = border[TOP] + padding[TOP] + padding[BOTTOM] + border[BOTTOM];
|
|
34
34
|
const correctionHorizontal = border[LEFT] + padding[LEFT] + padding[RIGHT] + border[RIGHT];
|
|
35
|
-
const correctionMapping = new Map([[
|
|
35
|
+
const correctionMapping = new Map([['width', correctionHorizontal], ['minWidth', correctionHorizontal], ['maxWidth', correctionHorizontal], ['height', correctionVertical], ['minHeight', correctionVertical], ['maxHeight', correctionVertical]]);
|
|
36
36
|
const nextStyle = {};
|
|
37
37
|
for (const styleProp of Object.keys(flatStyle)) {
|
|
38
38
|
const correction = correctionMapping.get(styleProp);
|
|
@@ -42,11 +42,11 @@ function fixContentBox(flatStyle) {
|
|
|
42
42
|
nextStyle[styleProp] = null;
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
|
-
if (styleValue ===
|
|
45
|
+
if (styleValue === 'auto') {
|
|
46
46
|
nextStyle[styleProp] = styleValue;
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
|
-
if (typeof styleValue !==
|
|
49
|
+
if (typeof styleValue !== 'number') {
|
|
50
50
|
(0, _errorMsg.warnMsg)(`"boxSizing:'content-box'" does not support value "${String(styleValue)}" for property "${styleProp}". Expected a value that resolves to a number. Percentage values can only be used with "boxSizing:'border-box'".`);
|
|
51
51
|
return flatStyle;
|
|
52
52
|
}
|
|
@@ -12,7 +12,7 @@ function flattenStyle() {
|
|
|
12
12
|
const result = {};
|
|
13
13
|
for (let i = 0; i < flatArray.length; i++) {
|
|
14
14
|
const style = flatArray[i];
|
|
15
|
-
if (style != null && typeof style ===
|
|
15
|
+
if (style != null && typeof style === 'object') {
|
|
16
16
|
Object.assign(result, style);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -8,19 +8,19 @@ const VALUES_REG = /,(?![^(]*\))/;
|
|
|
8
8
|
const PARTS_REG = /\s(?![^(]*\))/;
|
|
9
9
|
const LENGTH_REG = /^[0-9]+[a-zA-Z%]+?$/;
|
|
10
10
|
function isLength(v) {
|
|
11
|
-
return v ===
|
|
11
|
+
return v === '0' || LENGTH_REG.test(v);
|
|
12
12
|
}
|
|
13
13
|
function toMaybeNum(v) {
|
|
14
|
-
if (!/px$/.test(v) && v !==
|
|
14
|
+
if (!/px$/.test(v) && v !== '0') return v;
|
|
15
15
|
const n = parseFloat(v);
|
|
16
16
|
return !isNaN(n) ? n : v;
|
|
17
17
|
}
|
|
18
18
|
function parseValue(str) {
|
|
19
19
|
const parts = str.split(PARTS_REG);
|
|
20
|
-
const inset = parts.includes(
|
|
20
|
+
const inset = parts.includes('inset');
|
|
21
21
|
const last = parts.slice(-1)[0];
|
|
22
22
|
const color = !isLength(last) ? last : null;
|
|
23
|
-
const nums = parts.filter(n => n !==
|
|
23
|
+
const nums = parts.filter(n => n !== 'inset').filter(n => n !== color).map(toMaybeNum);
|
|
24
24
|
const [offsetX, offsetY, blurRadius, spreadRadius] = nums;
|
|
25
25
|
return {
|
|
26
26
|
inset,
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.parseTimeValue = parseTimeValue;
|
|
7
7
|
function parseTimeValue(timeValue) {
|
|
8
8
|
const trimmedTimeValue = timeValue.trim().toLowerCase();
|
|
9
|
-
if (trimmedTimeValue.endsWith(
|
|
10
|
-
const msVal = parseFloat(trimmedTimeValue.replace(/ms$/,
|
|
9
|
+
if (trimmedTimeValue.endsWith('ms')) {
|
|
10
|
+
const msVal = parseFloat(trimmedTimeValue.replace(/ms$/, ''));
|
|
11
11
|
return Number.isFinite(msVal) ? msVal : 0;
|
|
12
12
|
}
|
|
13
|
-
if (trimmedTimeValue.endsWith(
|
|
14
|
-
const sVal = parseFloat(trimmedTimeValue.replace(/s$/,
|
|
13
|
+
if (trimmedTimeValue.endsWith('s')) {
|
|
14
|
+
const sVal = parseFloat(trimmedTimeValue.replace(/s$/, ''));
|
|
15
15
|
return Number.isFinite(sVal) ? sVal * 1000 : 0;
|
|
16
16
|
}
|
|
17
17
|
return 0;
|
package/lib/native/stylex.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { type SpreadOptions } from './SpreadOptions';
|
|
11
|
+
import type { StyleX$CreateTheme, StyleX$DefineVars } from '../StyleXTypes';
|
|
11
12
|
/**
|
|
12
13
|
* The create method shim should do initial transforms like
|
|
13
14
|
* renaming/expanding/validating properties, essentially all the steps
|
|
@@ -20,21 +21,30 @@ export declare function create<S extends { [$$Key$$: string]: {} }>(
|
|
|
20
21
|
export declare const firstThatWorks: <T extends string | number>(
|
|
21
22
|
...values: ReadonlyArray<T>
|
|
22
23
|
) => T;
|
|
23
|
-
|
|
24
|
+
type Keyframes = {
|
|
25
|
+
readonly [key: string]: { readonly [k: string]: string | number };
|
|
26
|
+
};
|
|
27
|
+
export declare function keyframes(k: Keyframes): Keyframes;
|
|
24
28
|
/**
|
|
25
29
|
* The spread method shim
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
|
-
export declare function
|
|
32
|
+
export declare function props(
|
|
29
33
|
style: null | undefined | { [key: string]: unknown },
|
|
30
34
|
options: SpreadOptions,
|
|
31
35
|
): { [$$Key$$: string]: {} };
|
|
32
|
-
export
|
|
36
|
+
export declare const __customProperties: { [$$Key$$: string]: unknown };
|
|
37
|
+
export declare const defineVars: StyleX$DefineVars;
|
|
38
|
+
export declare const createTheme: any;
|
|
39
|
+
export type IStyleX = Readonly<{
|
|
33
40
|
create: typeof create;
|
|
34
41
|
firstThatWorks: typeof firstThatWorks;
|
|
35
42
|
keyframes: typeof keyframes;
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
props: typeof props;
|
|
44
|
+
defineVars: StyleX$DefineVars;
|
|
45
|
+
createTheme: StyleX$CreateTheme;
|
|
46
|
+
__customProperties?: { [$$Key$$: string]: unknown };
|
|
47
|
+
}>;
|
|
38
48
|
export declare const stylex: IStyleX;
|
|
39
49
|
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
40
50
|
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/native/stylex.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.__customProperties = void 0;
|
|
6
7
|
exports.create = create;
|
|
7
|
-
exports.firstThatWorks = exports.default = void 0;
|
|
8
|
+
exports.firstThatWorks = exports.defineVars = exports.default = exports.createTheme = void 0;
|
|
8
9
|
exports.keyframes = keyframes;
|
|
9
|
-
exports.
|
|
10
|
+
exports.props = props;
|
|
10
11
|
exports.stylex = void 0;
|
|
11
12
|
var _CSSCustomPropertyValue = require("./CSSCustomPropertyValue");
|
|
12
13
|
var _CSSLengthUnitValue = require("./CSSLengthUnitValue");
|
|
@@ -16,36 +17,36 @@ var _fixContentBox = require("./fixContentBox");
|
|
|
16
17
|
var _flattenStyle = require("./flattenStyle");
|
|
17
18
|
var _parseShadow = require("./parseShadow");
|
|
18
19
|
var _parseTimeValue = require("./parseTimeValue");
|
|
19
|
-
const stylePropertyAllowlistSet = new Set([
|
|
20
|
+
const stylePropertyAllowlistSet = new Set(['alignContent', 'alignItems', 'alignSelf', 'animationDelay', 'animationDuration', 'aspectRatio', 'backfaceVisibility', 'backgroundColor', 'borderBottomColor', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStyle', 'borderBottomWidth', 'borderColor', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRadius', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderStyle', 'borderTopColor', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStyle', 'borderTopWidth', 'borderWidth', 'bottom', 'boxSizing', 'color', 'direction', 'display', 'end', 'flex', 'flexBasis', 'flexDirection', 'flexGrow', 'flexShrink', 'flexWrap', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'fontVariant', 'gap', 'gapColumn', 'gapRow', 'height', 'justifyContent', 'left', 'letterSpacing', 'lineHeight', 'margin', 'marginBottom', 'marginLeft', 'marginRight', 'marginTop', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'objectFit', 'opacity', 'overflow', 'padding', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'pointerEvents', 'position', 'resizeMode', 'right', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'shadowWidth', 'start', 'textAlign', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle', 'textShadowColor', 'textShadowOffset', 'textShadowRadius', 'textTransform', 'tintColor', 'transform', 'transitionDelay', 'transitionDuration', 'top', 'userSelect', 'verticalAlign', 'width', 'zIndex']);
|
|
20
21
|
function isReactNativeStyleProp(propName) {
|
|
21
|
-
return stylePropertyAllowlistSet.has(propName) || propName.startsWith(
|
|
22
|
+
return stylePropertyAllowlistSet.has(propName) || propName.startsWith('--');
|
|
22
23
|
}
|
|
23
24
|
function isReactNativeStyleValue(propValue) {
|
|
24
|
-
if (typeof propValue ===
|
|
25
|
-
if (propValue ===
|
|
25
|
+
if (typeof propValue === 'string') {
|
|
26
|
+
if (propValue === 'inherit') {
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
28
|
-
if (propValue ===
|
|
29
|
+
if (propValue === 'initial') {
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
|
-
if (propValue.endsWith(
|
|
32
|
+
if (propValue.endsWith('px')) {
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
34
|
-
if (propValue.includes(
|
|
35
|
+
if (propValue.includes('calc(')) {
|
|
35
36
|
return false;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
return true;
|
|
39
40
|
}
|
|
40
41
|
function preprocessPropertyValue(propValue) {
|
|
41
|
-
if (typeof propValue ===
|
|
42
|
+
if (typeof propValue === 'string') {
|
|
42
43
|
const customPropValue = (0, _CSSCustomPropertyValue.createCSSCustomPropertyValue)(propValue);
|
|
43
44
|
if (customPropValue != null) {
|
|
44
45
|
return customPropValue;
|
|
45
46
|
}
|
|
46
47
|
const maybeLengthUnitValue = _CSSLengthUnitValue.CSSLengthUnitValue.parse(propValue);
|
|
47
48
|
if (maybeLengthUnitValue != null) {
|
|
48
|
-
return maybeLengthUnitValue[1] ===
|
|
49
|
+
return maybeLengthUnitValue[1] === 'px' ? maybeLengthUnitValue[0] : new _CSSLengthUnitValue.CSSLengthUnitValue(...maybeLengthUnitValue);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
return propValue;
|
|
@@ -54,17 +55,17 @@ function preprocessCreate(style) {
|
|
|
54
55
|
const processedStyle = {};
|
|
55
56
|
for (const propName in style) {
|
|
56
57
|
const styleValue = style[propName];
|
|
57
|
-
if (_CSSMediaQuery.CSSMediaQuery.isMediaQueryString(propName) && typeof styleValue ===
|
|
58
|
+
if (_CSSMediaQuery.CSSMediaQuery.isMediaQueryString(propName) && typeof styleValue === 'object' && styleValue != null) {
|
|
58
59
|
const processsedSubStyle = preprocessCreate({
|
|
59
60
|
...styleValue
|
|
60
61
|
});
|
|
61
62
|
processedStyle[propName] = new _CSSMediaQuery.CSSMediaQuery(propName, processsedSubStyle);
|
|
62
63
|
continue;
|
|
63
64
|
}
|
|
64
|
-
if (propName ===
|
|
65
|
+
if (propName === 'boxShadow' && typeof styleValue === 'string') {
|
|
65
66
|
const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
|
|
66
67
|
if (parsedShadow.length > 1) {
|
|
67
|
-
(0, _errorMsg.warnMsg)(
|
|
68
|
+
(0, _errorMsg.warnMsg)('Multiple "boxShadow" values are not supported in React Native.');
|
|
68
69
|
}
|
|
69
70
|
const {
|
|
70
71
|
inset,
|
|
@@ -74,7 +75,7 @@ function preprocessCreate(style) {
|
|
|
74
75
|
color
|
|
75
76
|
} = parsedShadow[0];
|
|
76
77
|
if (inset) {
|
|
77
|
-
(0, _errorMsg.warnMsg)("
|
|
78
|
+
(0, _errorMsg.warnMsg)('"boxShadow" value of "inset" is not supported in React Native.');
|
|
78
79
|
}
|
|
79
80
|
processedStyle.shadowColor = color;
|
|
80
81
|
processedStyle.shadowOffset = {
|
|
@@ -83,10 +84,10 @@ function preprocessCreate(style) {
|
|
|
83
84
|
};
|
|
84
85
|
processedStyle.shadowOpacity = 1;
|
|
85
86
|
processedStyle.shadowRadius = blurRadius;
|
|
86
|
-
} else if (propName ===
|
|
87
|
+
} else if (propName === 'textShadow' && typeof styleValue === 'string') {
|
|
87
88
|
const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
|
|
88
89
|
if (parsedShadow.length > 1) {
|
|
89
|
-
(0, _errorMsg.warnMsg)(
|
|
90
|
+
(0, _errorMsg.warnMsg)('Multiple "textShadow" values are not supported in React Native.');
|
|
90
91
|
}
|
|
91
92
|
const {
|
|
92
93
|
offsetX,
|
|
@@ -106,9 +107,9 @@ function preprocessCreate(style) {
|
|
|
106
107
|
}
|
|
107
108
|
for (const prop in processedStyle) {
|
|
108
109
|
let value = processedStyle[prop];
|
|
109
|
-
if (prop ===
|
|
110
|
-
if (typeof value ===
|
|
111
|
-
value = value +
|
|
110
|
+
if (prop === 'lineHeight') {
|
|
111
|
+
if (typeof value === 'number' || typeof value === 'string' && _CSSLengthUnitValue.CSSLengthUnitValue.parse(value) == null) {
|
|
112
|
+
value = value + 'em';
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
const processedStyleValue = preprocessPropertyValue(value);
|
|
@@ -118,6 +119,13 @@ function preprocessCreate(style) {
|
|
|
118
119
|
}
|
|
119
120
|
function finalizeValue(unfinalizedValue, options) {
|
|
120
121
|
let styleValue = unfinalizedValue;
|
|
122
|
+
if (typeof styleValue === 'object' && styleValue != null && Object.hasOwn(styleValue, 'default')) {
|
|
123
|
+
if (options.hover === true && Object.hasOwn(styleValue, ':hover')) {
|
|
124
|
+
styleValue = styleValue[':hover'];
|
|
125
|
+
} else {
|
|
126
|
+
styleValue = styleValue.default;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
121
129
|
while (styleValue instanceof _CSSCustomPropertyValue.CSSCustomPropertyValue) {
|
|
122
130
|
const customProperties = options.customProperties || {};
|
|
123
131
|
const resolvedValue = customProperties[styleValue.name] ?? styleValue.defaultValue;
|
|
@@ -143,11 +151,12 @@ const firstThatWorks = function () {
|
|
|
143
151
|
return arguments.length <= 0 ? undefined : arguments[0];
|
|
144
152
|
};
|
|
145
153
|
exports.firstThatWorks = firstThatWorks;
|
|
146
|
-
function keyframes() {
|
|
147
|
-
(0, _errorMsg.errorMsg)(
|
|
154
|
+
function keyframes(k) {
|
|
155
|
+
(0, _errorMsg.errorMsg)('keyframes are not supported in React Native.');
|
|
156
|
+
return k;
|
|
148
157
|
}
|
|
149
|
-
const timeValuedProperties = [
|
|
150
|
-
function
|
|
158
|
+
const timeValuedProperties = ['animationDelay', 'animationDuration', 'transitionDelay', 'transitionDuration'];
|
|
159
|
+
function props(style, options) {
|
|
151
160
|
let {
|
|
152
161
|
lineClamp,
|
|
153
162
|
...flatStyle
|
|
@@ -180,110 +189,110 @@ function spread(style, options) {
|
|
|
180
189
|
continue;
|
|
181
190
|
}
|
|
182
191
|
if (!isReactNativeStyleProp(styleProp) && passthroughProperties.indexOf(styleProp) === -1) {
|
|
183
|
-
if (styleProp ===
|
|
192
|
+
if (styleProp === 'blockSize') {
|
|
184
193
|
flatStyle.height = flatStyle.height ?? styleValue;
|
|
185
|
-
} else if (styleProp ===
|
|
194
|
+
} else if (styleProp === 'inlineSize') {
|
|
186
195
|
flatStyle.width = flatStyle.width ?? styleValue;
|
|
187
|
-
} else if (styleProp ===
|
|
196
|
+
} else if (styleProp === 'maxBlockSize') {
|
|
188
197
|
flatStyle.maxHeight = flatStyle.maxHeight ?? styleValue;
|
|
189
|
-
} else if (styleProp ===
|
|
198
|
+
} else if (styleProp === 'minBlockSize') {
|
|
190
199
|
flatStyle.minHeight = flatStyle.minHeight ?? styleValue;
|
|
191
|
-
} else if (styleProp ===
|
|
200
|
+
} else if (styleProp === 'maxInlineSize') {
|
|
192
201
|
flatStyle.maxWidth = flatStyle.maxWidth ?? styleValue;
|
|
193
|
-
} else if (styleProp ===
|
|
202
|
+
} else if (styleProp === 'minInlineSize') {
|
|
194
203
|
flatStyle.minWidth = flatStyle.minWidth ?? styleValue;
|
|
195
|
-
} else if (styleProp ===
|
|
204
|
+
} else if (styleProp === 'borderBlockColor') {
|
|
196
205
|
flatStyle.borderTopColor = flatStyle.borderTopColor ?? styleValue;
|
|
197
206
|
flatStyle.borderBottomColor = flatStyle.borderBottomColor ?? styleValue;
|
|
198
|
-
} else if (styleProp ===
|
|
207
|
+
} else if (styleProp === 'borderBlockStyle') {
|
|
199
208
|
flatStyle.borderTopStyle = flatStyle.borderTopStyle ?? styleValue;
|
|
200
209
|
flatStyle.borderBottomStyle = flatStyle.borderBottomStyle ?? styleValue;
|
|
201
|
-
} else if (styleProp ===
|
|
210
|
+
} else if (styleProp === 'borderBlockWidth') {
|
|
202
211
|
flatStyle.borderTopWidth = flatStyle.borderTopWidth ?? styleValue;
|
|
203
212
|
flatStyle.borderBottomWidth = flatStyle.borderBottomWidth ?? styleValue;
|
|
204
|
-
} else if (styleProp ===
|
|
213
|
+
} else if (styleProp === 'borderBlockEndColor') {
|
|
205
214
|
flatStyle.borderBottomColor = prevStyle.borderBottomColor ?? styleValue;
|
|
206
|
-
} else if (styleProp ===
|
|
215
|
+
} else if (styleProp === 'borderBlockEndStyle') {
|
|
207
216
|
flatStyle.borderBottomStyle = prevStyle.borderBottomStyle ?? styleValue;
|
|
208
|
-
} else if (styleProp ===
|
|
217
|
+
} else if (styleProp === 'borderBlockEndWidth') {
|
|
209
218
|
flatStyle.borderBottomWidth = prevStyle.borderBottomWidth ?? styleValue;
|
|
210
|
-
} else if (styleProp ===
|
|
219
|
+
} else if (styleProp === 'borderBlockStartColor') {
|
|
211
220
|
flatStyle.borderTopColor = prevStyle.borderTopColor ?? styleValue;
|
|
212
|
-
} else if (styleProp ===
|
|
221
|
+
} else if (styleProp === 'borderBlockStartStyle') {
|
|
213
222
|
flatStyle.borderTopStyle = prevStyle.borderTopStyle ?? styleValue;
|
|
214
|
-
} else if (styleProp ===
|
|
223
|
+
} else if (styleProp === 'borderBlockStartWidth') {
|
|
215
224
|
flatStyle.borderTopWidth = prevStyle.borderTopWidth ?? styleValue;
|
|
216
|
-
} else if (styleProp ===
|
|
225
|
+
} else if (styleProp === 'borderInlineColor') {
|
|
217
226
|
flatStyle.borderStartColor = flatStyle.borderStartColor ?? styleValue;
|
|
218
227
|
flatStyle.borderEndColor = flatStyle.borderEndColor ?? styleValue;
|
|
219
|
-
} else if (styleProp ===
|
|
228
|
+
} else if (styleProp === 'borderInlineStyle') {
|
|
220
229
|
flatStyle.borderStartStyle = flatStyle.borderStartStyle ?? styleValue;
|
|
221
230
|
flatStyle.borderEndStyle = flatStyle.borderEndStyle ?? styleValue;
|
|
222
|
-
} else if (styleProp ===
|
|
231
|
+
} else if (styleProp === 'borderInlineWidth') {
|
|
223
232
|
flatStyle.borderStartWidth = flatStyle.borderStartWidth ?? styleValue;
|
|
224
233
|
flatStyle.borderEndWidth = flatStyle.borderEndWidth ?? styleValue;
|
|
225
|
-
} else if (styleProp ===
|
|
234
|
+
} else if (styleProp === 'borderInlineEndColor') {
|
|
226
235
|
flatStyle.borderEndColor = styleValue;
|
|
227
|
-
} else if (styleProp ===
|
|
236
|
+
} else if (styleProp === 'borderInlineEndStyle') {
|
|
228
237
|
flatStyle.borderEndStyle = styleValue;
|
|
229
|
-
} else if (styleProp ===
|
|
238
|
+
} else if (styleProp === 'borderInlineEndWidth') {
|
|
230
239
|
flatStyle.borderEndWidth = styleValue;
|
|
231
|
-
} else if (styleProp ===
|
|
240
|
+
} else if (styleProp === 'borderInlineStartColor') {
|
|
232
241
|
flatStyle.borderStartColor = styleValue;
|
|
233
|
-
} else if (styleProp ===
|
|
242
|
+
} else if (styleProp === 'borderInlineStartStyle') {
|
|
234
243
|
flatStyle.borderStartStyle = styleValue;
|
|
235
|
-
} else if (styleProp ===
|
|
244
|
+
} else if (styleProp === 'borderInlineStartWidth') {
|
|
236
245
|
flatStyle.borderStartWidth = styleValue;
|
|
237
|
-
} else if (styleProp ===
|
|
246
|
+
} else if (styleProp === 'borderStartStartRadius') {
|
|
238
247
|
flatStyle.borderTopStartRadius = styleValue;
|
|
239
|
-
} else if (styleProp ===
|
|
248
|
+
} else if (styleProp === 'borderEndStartRadius') {
|
|
240
249
|
flatStyle.borderBottomStartRadius = styleValue;
|
|
241
|
-
} else if (styleProp ===
|
|
250
|
+
} else if (styleProp === 'borderStartEndRadius') {
|
|
242
251
|
flatStyle.borderTopEndRadius = styleValue;
|
|
243
|
-
} else if (styleProp ===
|
|
252
|
+
} else if (styleProp === 'borderEndEndRadius') {
|
|
244
253
|
flatStyle.borderBottomEndRadius = styleValue;
|
|
245
|
-
} else if (styleProp ===
|
|
254
|
+
} else if (styleProp === 'inset') {
|
|
246
255
|
flatStyle.top = flatStyle.top ?? styleValue;
|
|
247
256
|
flatStyle.start = flatStyle.start ?? styleValue;
|
|
248
257
|
flatStyle.end = flatStyle.end ?? styleValue;
|
|
249
258
|
flatStyle.bottom = flatStyle.bottom ?? styleValue;
|
|
250
|
-
} else if (styleProp ===
|
|
259
|
+
} else if (styleProp === 'insetBlock') {
|
|
251
260
|
flatStyle.top = flatStyle.top ?? styleValue;
|
|
252
261
|
flatStyle.bottom = flatStyle.bottom ?? styleValue;
|
|
253
|
-
} else if (styleProp ===
|
|
262
|
+
} else if (styleProp === 'insetBlockEnd') {
|
|
254
263
|
flatStyle.bottom = prevStyle.bottom ?? styleValue;
|
|
255
|
-
} else if (styleProp ===
|
|
264
|
+
} else if (styleProp === 'insetBlockStart') {
|
|
256
265
|
flatStyle.top = prevStyle.top ?? styleValue;
|
|
257
|
-
} else if (styleProp ===
|
|
266
|
+
} else if (styleProp === 'insetInline') {
|
|
258
267
|
flatStyle.end = flatStyle.end ?? styleValue;
|
|
259
268
|
flatStyle.start = flatStyle.start ?? styleValue;
|
|
260
|
-
} else if (styleProp ===
|
|
269
|
+
} else if (styleProp === 'insetInlineEnd') {
|
|
261
270
|
flatStyle.end = prevStyle.end ?? styleValue;
|
|
262
|
-
} else if (styleProp ===
|
|
271
|
+
} else if (styleProp === 'insetInlineStart') {
|
|
263
272
|
flatStyle.start = prevStyle.start ?? styleValue;
|
|
264
|
-
} else if (styleProp ===
|
|
273
|
+
} else if (styleProp === 'marginBlock') {
|
|
265
274
|
flatStyle.marginVertical = styleValue;
|
|
266
|
-
} else if (styleProp ===
|
|
275
|
+
} else if (styleProp === 'marginBlockStart') {
|
|
267
276
|
flatStyle.marginTop = flatStyle.marginTop ?? styleValue;
|
|
268
|
-
} else if (styleProp ===
|
|
277
|
+
} else if (styleProp === 'marginBlockEnd') {
|
|
269
278
|
flatStyle.marginBottom = flatStyle.marginBottom ?? styleValue;
|
|
270
|
-
} else if (styleProp ===
|
|
279
|
+
} else if (styleProp === 'marginInline') {
|
|
271
280
|
flatStyle.marginHorizontal = styleValue;
|
|
272
|
-
} else if (styleProp ===
|
|
281
|
+
} else if (styleProp === 'marginInlineStart') {
|
|
273
282
|
flatStyle.marginStart = styleValue;
|
|
274
|
-
} else if (styleProp ===
|
|
283
|
+
} else if (styleProp === 'marginInlineEnd') {
|
|
275
284
|
flatStyle.marginEnd = styleValue;
|
|
276
|
-
} else if (styleProp ===
|
|
285
|
+
} else if (styleProp === 'paddingBlock') {
|
|
277
286
|
flatStyle.paddingVertical = styleValue;
|
|
278
|
-
} else if (styleProp ===
|
|
287
|
+
} else if (styleProp === 'paddingBlockStart') {
|
|
279
288
|
flatStyle.paddingTop = flatStyle.paddingTop ?? styleValue;
|
|
280
|
-
} else if (styleProp ===
|
|
289
|
+
} else if (styleProp === 'paddingBlockEnd') {
|
|
281
290
|
flatStyle.paddingBottom = flatStyle.paddingBottom ?? styleValue;
|
|
282
|
-
} else if (styleProp ===
|
|
291
|
+
} else if (styleProp === 'paddingInline') {
|
|
283
292
|
flatStyle.paddingHorizontal = styleValue;
|
|
284
|
-
} else if (styleProp ===
|
|
293
|
+
} else if (styleProp === 'paddingInlineStart') {
|
|
285
294
|
flatStyle.paddingStart = styleValue;
|
|
286
|
-
} else if (styleProp ===
|
|
295
|
+
} else if (styleProp === 'paddingInlineEnd') {
|
|
287
296
|
flatStyle.paddingEnd = styleValue;
|
|
288
297
|
} else {
|
|
289
298
|
(0, _errorMsg.warnMsg)(`Ignoring unsupported style property "${styleProp}"`);
|
|
@@ -304,31 +313,31 @@ function spread(style, options) {
|
|
|
304
313
|
height: viewportHeight,
|
|
305
314
|
direction: writingDirection
|
|
306
315
|
});
|
|
307
|
-
if (flatStyle.borderStyle ===
|
|
316
|
+
if (flatStyle.borderStyle === 'none') {
|
|
308
317
|
flatStyle.borderWidth = 0;
|
|
309
318
|
delete flatStyle.borderStyle;
|
|
310
319
|
}
|
|
311
|
-
if (typeof flatStyle.fontWeight ===
|
|
320
|
+
if (typeof flatStyle.fontWeight === 'number') {
|
|
312
321
|
flatStyle.fontWeight = flatStyle.fontWeight.toString();
|
|
313
322
|
}
|
|
314
323
|
const boxSizingValue = flatStyle.boxSizing;
|
|
315
|
-
if (boxSizingValue ===
|
|
324
|
+
if (boxSizingValue === 'content-box') {
|
|
316
325
|
flatStyle = (0, _fixContentBox.fixContentBox)(flatStyle);
|
|
317
326
|
}
|
|
318
327
|
delete flatStyle.boxSizing;
|
|
319
328
|
const positionValue = flatStyle.position;
|
|
320
|
-
if (positionValue ===
|
|
321
|
-
flatStyle.position =
|
|
322
|
-
(0, _errorMsg.warnMsg)("
|
|
323
|
-
} else if (positionValue ===
|
|
324
|
-
flatStyle.position =
|
|
325
|
-
(0, _errorMsg.warnMsg)("
|
|
326
|
-
} else if (positionValue ===
|
|
327
|
-
flatStyle.position =
|
|
328
|
-
(0, _errorMsg.warnMsg)("
|
|
329
|
+
if (positionValue === 'fixed') {
|
|
330
|
+
flatStyle.position = 'absolute';
|
|
331
|
+
(0, _errorMsg.warnMsg)('"position" value of "fixed" is not supported in React Native. Falling back to "absolute".');
|
|
332
|
+
} else if (positionValue === 'static') {
|
|
333
|
+
flatStyle.position = 'relative';
|
|
334
|
+
(0, _errorMsg.warnMsg)('"position" value of "static" is not supported in React Native. Falling back to "relative".');
|
|
335
|
+
} else if (positionValue === 'sticky') {
|
|
336
|
+
flatStyle.position = 'relative';
|
|
337
|
+
(0, _errorMsg.warnMsg)('"position" value of "sticky" is not supported in React Native. Falling back to "relative".');
|
|
329
338
|
}
|
|
330
339
|
for (const timeValuedProperty of timeValuedProperties) {
|
|
331
|
-
if (typeof flatStyle[timeValuedProperty] ===
|
|
340
|
+
if (typeof flatStyle[timeValuedProperty] === 'string') {
|
|
332
341
|
flatStyle[timeValuedProperty] = (0, _parseTimeValue.parseTimeValue)(flatStyle[timeValuedProperty]);
|
|
333
342
|
}
|
|
334
343
|
}
|
|
@@ -339,12 +348,34 @@ function spread(style, options) {
|
|
|
339
348
|
}
|
|
340
349
|
return nativeProps;
|
|
341
350
|
}
|
|
342
|
-
const
|
|
351
|
+
const __customProperties = exports.__customProperties = {};
|
|
352
|
+
let count = 1;
|
|
353
|
+
const defineVars = tokens => {
|
|
354
|
+
const result = {};
|
|
355
|
+
for (const key in tokens) {
|
|
356
|
+
const value = tokens[key];
|
|
357
|
+
result[key] = `var(--${key}-${count++})`;
|
|
358
|
+
__customProperties[result[key]] = value;
|
|
359
|
+
}
|
|
360
|
+
return result;
|
|
361
|
+
};
|
|
362
|
+
exports.defineVars = defineVars;
|
|
363
|
+
const createTheme = (baseTokens, overrides) => {
|
|
364
|
+
const result = {};
|
|
365
|
+
for (const key in baseTokens) {
|
|
366
|
+
const varName = baseTokens[key];
|
|
367
|
+
result[varName] = overrides[key];
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
};
|
|
371
|
+
exports.createTheme = createTheme;
|
|
372
|
+
const stylex = exports.stylex = {
|
|
343
373
|
create,
|
|
344
374
|
firstThatWorks,
|
|
345
375
|
keyframes,
|
|
346
|
-
|
|
376
|
+
props,
|
|
377
|
+
defineVars,
|
|
378
|
+
createTheme,
|
|
379
|
+
__customProperties
|
|
347
380
|
};
|
|
348
|
-
exports.
|
|
349
|
-
var _default = stylex;
|
|
350
|
-
exports.default = _default;
|
|
381
|
+
var _default = exports.default = stylex;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { type SpreadOptions } from './SpreadOptions';
|
|
11
|
+
import type { StyleX$CreateTheme, StyleX$DefineVars } from '../StyleXTypes';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The create method shim should do initial transforms like
|
|
@@ -23,23 +24,36 @@ declare export const firstThatWorks: <T: string | number>(
|
|
|
23
24
|
...values: $ReadOnlyArray<T>
|
|
24
25
|
) => T;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
type Keyframes = {
|
|
28
|
+
+[key: string]: { +[k: string]: string | number },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare export function keyframes(k: Keyframes): Keyframes;
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* The spread method shim
|
|
30
35
|
*/
|
|
31
36
|
|
|
32
|
-
declare export function
|
|
37
|
+
declare export function props(
|
|
33
38
|
style: ?{ [key: string]: mixed },
|
|
34
39
|
options: SpreadOptions,
|
|
35
40
|
): { [string]: { ... } };
|
|
36
41
|
|
|
37
|
-
export
|
|
42
|
+
declare export const __customProperties: { [string]: mixed };
|
|
43
|
+
|
|
44
|
+
declare export const defineVars: StyleX$DefineVars;
|
|
45
|
+
|
|
46
|
+
declare export const createTheme: $FlowFixMe;
|
|
47
|
+
|
|
48
|
+
export type IStyleX = $ReadOnly<{
|
|
38
49
|
create: typeof create,
|
|
39
50
|
firstThatWorks: typeof firstThatWorks,
|
|
40
51
|
keyframes: typeof keyframes,
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
props: typeof props,
|
|
53
|
+
defineVars: StyleX$DefineVars,
|
|
54
|
+
createTheme: StyleX$CreateTheme,
|
|
55
|
+
__customProperties?: { [string]: mixed },
|
|
56
|
+
}>;
|
|
43
57
|
|
|
44
58
|
declare export const stylex: IStyleX;
|
|
45
59
|
|