@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.23
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 +3 -2
- package/lib/native/SpreadOptions.js.flow +3 -2
- 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 +310 -293
- 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 +17 -7
- package/lib/native/stylex.js +124 -89
- package/lib/native/stylex.js.flow +21 -7
- package/lib/stylex.d.ts +45 -32
- package/lib/stylex.js +87 -61
- package/lib/stylex.js.flow +42 -33
- 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
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
export declare function props(
|
|
33
|
+
this: SpreadOptions,
|
|
34
|
+
...style: ReadonlyArray<null | undefined | { [key: string]: unknown }>
|
|
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,16 @@ 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() {
|
|
160
|
+
const options = this;
|
|
161
|
+
for (var _len = arguments.length, style = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
162
|
+
style[_key] = arguments[_key];
|
|
163
|
+
}
|
|
151
164
|
let {
|
|
152
165
|
lineClamp,
|
|
153
166
|
...flatStyle
|
|
@@ -180,110 +193,110 @@ function spread(style, options) {
|
|
|
180
193
|
continue;
|
|
181
194
|
}
|
|
182
195
|
if (!isReactNativeStyleProp(styleProp) && passthroughProperties.indexOf(styleProp) === -1) {
|
|
183
|
-
if (styleProp ===
|
|
196
|
+
if (styleProp === 'blockSize') {
|
|
184
197
|
flatStyle.height = flatStyle.height ?? styleValue;
|
|
185
|
-
} else if (styleProp ===
|
|
198
|
+
} else if (styleProp === 'inlineSize') {
|
|
186
199
|
flatStyle.width = flatStyle.width ?? styleValue;
|
|
187
|
-
} else if (styleProp ===
|
|
200
|
+
} else if (styleProp === 'maxBlockSize') {
|
|
188
201
|
flatStyle.maxHeight = flatStyle.maxHeight ?? styleValue;
|
|
189
|
-
} else if (styleProp ===
|
|
202
|
+
} else if (styleProp === 'minBlockSize') {
|
|
190
203
|
flatStyle.minHeight = flatStyle.minHeight ?? styleValue;
|
|
191
|
-
} else if (styleProp ===
|
|
204
|
+
} else if (styleProp === 'maxInlineSize') {
|
|
192
205
|
flatStyle.maxWidth = flatStyle.maxWidth ?? styleValue;
|
|
193
|
-
} else if (styleProp ===
|
|
206
|
+
} else if (styleProp === 'minInlineSize') {
|
|
194
207
|
flatStyle.minWidth = flatStyle.minWidth ?? styleValue;
|
|
195
|
-
} else if (styleProp ===
|
|
208
|
+
} else if (styleProp === 'borderBlockColor') {
|
|
196
209
|
flatStyle.borderTopColor = flatStyle.borderTopColor ?? styleValue;
|
|
197
210
|
flatStyle.borderBottomColor = flatStyle.borderBottomColor ?? styleValue;
|
|
198
|
-
} else if (styleProp ===
|
|
211
|
+
} else if (styleProp === 'borderBlockStyle') {
|
|
199
212
|
flatStyle.borderTopStyle = flatStyle.borderTopStyle ?? styleValue;
|
|
200
213
|
flatStyle.borderBottomStyle = flatStyle.borderBottomStyle ?? styleValue;
|
|
201
|
-
} else if (styleProp ===
|
|
214
|
+
} else if (styleProp === 'borderBlockWidth') {
|
|
202
215
|
flatStyle.borderTopWidth = flatStyle.borderTopWidth ?? styleValue;
|
|
203
216
|
flatStyle.borderBottomWidth = flatStyle.borderBottomWidth ?? styleValue;
|
|
204
|
-
} else if (styleProp ===
|
|
217
|
+
} else if (styleProp === 'borderBlockEndColor') {
|
|
205
218
|
flatStyle.borderBottomColor = prevStyle.borderBottomColor ?? styleValue;
|
|
206
|
-
} else if (styleProp ===
|
|
219
|
+
} else if (styleProp === 'borderBlockEndStyle') {
|
|
207
220
|
flatStyle.borderBottomStyle = prevStyle.borderBottomStyle ?? styleValue;
|
|
208
|
-
} else if (styleProp ===
|
|
221
|
+
} else if (styleProp === 'borderBlockEndWidth') {
|
|
209
222
|
flatStyle.borderBottomWidth = prevStyle.borderBottomWidth ?? styleValue;
|
|
210
|
-
} else if (styleProp ===
|
|
223
|
+
} else if (styleProp === 'borderBlockStartColor') {
|
|
211
224
|
flatStyle.borderTopColor = prevStyle.borderTopColor ?? styleValue;
|
|
212
|
-
} else if (styleProp ===
|
|
225
|
+
} else if (styleProp === 'borderBlockStartStyle') {
|
|
213
226
|
flatStyle.borderTopStyle = prevStyle.borderTopStyle ?? styleValue;
|
|
214
|
-
} else if (styleProp ===
|
|
227
|
+
} else if (styleProp === 'borderBlockStartWidth') {
|
|
215
228
|
flatStyle.borderTopWidth = prevStyle.borderTopWidth ?? styleValue;
|
|
216
|
-
} else if (styleProp ===
|
|
229
|
+
} else if (styleProp === 'borderInlineColor') {
|
|
217
230
|
flatStyle.borderStartColor = flatStyle.borderStartColor ?? styleValue;
|
|
218
231
|
flatStyle.borderEndColor = flatStyle.borderEndColor ?? styleValue;
|
|
219
|
-
} else if (styleProp ===
|
|
232
|
+
} else if (styleProp === 'borderInlineStyle') {
|
|
220
233
|
flatStyle.borderStartStyle = flatStyle.borderStartStyle ?? styleValue;
|
|
221
234
|
flatStyle.borderEndStyle = flatStyle.borderEndStyle ?? styleValue;
|
|
222
|
-
} else if (styleProp ===
|
|
235
|
+
} else if (styleProp === 'borderInlineWidth') {
|
|
223
236
|
flatStyle.borderStartWidth = flatStyle.borderStartWidth ?? styleValue;
|
|
224
237
|
flatStyle.borderEndWidth = flatStyle.borderEndWidth ?? styleValue;
|
|
225
|
-
} else if (styleProp ===
|
|
238
|
+
} else if (styleProp === 'borderInlineEndColor') {
|
|
226
239
|
flatStyle.borderEndColor = styleValue;
|
|
227
|
-
} else if (styleProp ===
|
|
240
|
+
} else if (styleProp === 'borderInlineEndStyle') {
|
|
228
241
|
flatStyle.borderEndStyle = styleValue;
|
|
229
|
-
} else if (styleProp ===
|
|
242
|
+
} else if (styleProp === 'borderInlineEndWidth') {
|
|
230
243
|
flatStyle.borderEndWidth = styleValue;
|
|
231
|
-
} else if (styleProp ===
|
|
244
|
+
} else if (styleProp === 'borderInlineStartColor') {
|
|
232
245
|
flatStyle.borderStartColor = styleValue;
|
|
233
|
-
} else if (styleProp ===
|
|
246
|
+
} else if (styleProp === 'borderInlineStartStyle') {
|
|
234
247
|
flatStyle.borderStartStyle = styleValue;
|
|
235
|
-
} else if (styleProp ===
|
|
248
|
+
} else if (styleProp === 'borderInlineStartWidth') {
|
|
236
249
|
flatStyle.borderStartWidth = styleValue;
|
|
237
|
-
} else if (styleProp ===
|
|
250
|
+
} else if (styleProp === 'borderStartStartRadius') {
|
|
238
251
|
flatStyle.borderTopStartRadius = styleValue;
|
|
239
|
-
} else if (styleProp ===
|
|
252
|
+
} else if (styleProp === 'borderEndStartRadius') {
|
|
240
253
|
flatStyle.borderBottomStartRadius = styleValue;
|
|
241
|
-
} else if (styleProp ===
|
|
254
|
+
} else if (styleProp === 'borderStartEndRadius') {
|
|
242
255
|
flatStyle.borderTopEndRadius = styleValue;
|
|
243
|
-
} else if (styleProp ===
|
|
256
|
+
} else if (styleProp === 'borderEndEndRadius') {
|
|
244
257
|
flatStyle.borderBottomEndRadius = styleValue;
|
|
245
|
-
} else if (styleProp ===
|
|
258
|
+
} else if (styleProp === 'inset') {
|
|
246
259
|
flatStyle.top = flatStyle.top ?? styleValue;
|
|
247
260
|
flatStyle.start = flatStyle.start ?? styleValue;
|
|
248
261
|
flatStyle.end = flatStyle.end ?? styleValue;
|
|
249
262
|
flatStyle.bottom = flatStyle.bottom ?? styleValue;
|
|
250
|
-
} else if (styleProp ===
|
|
263
|
+
} else if (styleProp === 'insetBlock') {
|
|
251
264
|
flatStyle.top = flatStyle.top ?? styleValue;
|
|
252
265
|
flatStyle.bottom = flatStyle.bottom ?? styleValue;
|
|
253
|
-
} else if (styleProp ===
|
|
266
|
+
} else if (styleProp === 'insetBlockEnd') {
|
|
254
267
|
flatStyle.bottom = prevStyle.bottom ?? styleValue;
|
|
255
|
-
} else if (styleProp ===
|
|
268
|
+
} else if (styleProp === 'insetBlockStart') {
|
|
256
269
|
flatStyle.top = prevStyle.top ?? styleValue;
|
|
257
|
-
} else if (styleProp ===
|
|
270
|
+
} else if (styleProp === 'insetInline') {
|
|
258
271
|
flatStyle.end = flatStyle.end ?? styleValue;
|
|
259
272
|
flatStyle.start = flatStyle.start ?? styleValue;
|
|
260
|
-
} else if (styleProp ===
|
|
273
|
+
} else if (styleProp === 'insetInlineEnd') {
|
|
261
274
|
flatStyle.end = prevStyle.end ?? styleValue;
|
|
262
|
-
} else if (styleProp ===
|
|
275
|
+
} else if (styleProp === 'insetInlineStart') {
|
|
263
276
|
flatStyle.start = prevStyle.start ?? styleValue;
|
|
264
|
-
} else if (styleProp ===
|
|
277
|
+
} else if (styleProp === 'marginBlock') {
|
|
265
278
|
flatStyle.marginVertical = styleValue;
|
|
266
|
-
} else if (styleProp ===
|
|
279
|
+
} else if (styleProp === 'marginBlockStart') {
|
|
267
280
|
flatStyle.marginTop = flatStyle.marginTop ?? styleValue;
|
|
268
|
-
} else if (styleProp ===
|
|
281
|
+
} else if (styleProp === 'marginBlockEnd') {
|
|
269
282
|
flatStyle.marginBottom = flatStyle.marginBottom ?? styleValue;
|
|
270
|
-
} else if (styleProp ===
|
|
283
|
+
} else if (styleProp === 'marginInline') {
|
|
271
284
|
flatStyle.marginHorizontal = styleValue;
|
|
272
|
-
} else if (styleProp ===
|
|
285
|
+
} else if (styleProp === 'marginInlineStart') {
|
|
273
286
|
flatStyle.marginStart = styleValue;
|
|
274
|
-
} else if (styleProp ===
|
|
287
|
+
} else if (styleProp === 'marginInlineEnd') {
|
|
275
288
|
flatStyle.marginEnd = styleValue;
|
|
276
|
-
} else if (styleProp ===
|
|
289
|
+
} else if (styleProp === 'paddingBlock') {
|
|
277
290
|
flatStyle.paddingVertical = styleValue;
|
|
278
|
-
} else if (styleProp ===
|
|
291
|
+
} else if (styleProp === 'paddingBlockStart') {
|
|
279
292
|
flatStyle.paddingTop = flatStyle.paddingTop ?? styleValue;
|
|
280
|
-
} else if (styleProp ===
|
|
293
|
+
} else if (styleProp === 'paddingBlockEnd') {
|
|
281
294
|
flatStyle.paddingBottom = flatStyle.paddingBottom ?? styleValue;
|
|
282
|
-
} else if (styleProp ===
|
|
295
|
+
} else if (styleProp === 'paddingInline') {
|
|
283
296
|
flatStyle.paddingHorizontal = styleValue;
|
|
284
|
-
} else if (styleProp ===
|
|
297
|
+
} else if (styleProp === 'paddingInlineStart') {
|
|
285
298
|
flatStyle.paddingStart = styleValue;
|
|
286
|
-
} else if (styleProp ===
|
|
299
|
+
} else if (styleProp === 'paddingInlineEnd') {
|
|
287
300
|
flatStyle.paddingEnd = styleValue;
|
|
288
301
|
} else {
|
|
289
302
|
(0, _errorMsg.warnMsg)(`Ignoring unsupported style property "${styleProp}"`);
|
|
@@ -304,31 +317,31 @@ function spread(style, options) {
|
|
|
304
317
|
height: viewportHeight,
|
|
305
318
|
direction: writingDirection
|
|
306
319
|
});
|
|
307
|
-
if (flatStyle.borderStyle ===
|
|
320
|
+
if (flatStyle.borderStyle === 'none') {
|
|
308
321
|
flatStyle.borderWidth = 0;
|
|
309
322
|
delete flatStyle.borderStyle;
|
|
310
323
|
}
|
|
311
|
-
if (typeof flatStyle.fontWeight ===
|
|
324
|
+
if (typeof flatStyle.fontWeight === 'number') {
|
|
312
325
|
flatStyle.fontWeight = flatStyle.fontWeight.toString();
|
|
313
326
|
}
|
|
314
327
|
const boxSizingValue = flatStyle.boxSizing;
|
|
315
|
-
if (boxSizingValue ===
|
|
328
|
+
if (boxSizingValue === 'content-box') {
|
|
316
329
|
flatStyle = (0, _fixContentBox.fixContentBox)(flatStyle);
|
|
317
330
|
}
|
|
318
331
|
delete flatStyle.boxSizing;
|
|
319
332
|
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)("
|
|
333
|
+
if (positionValue === 'fixed') {
|
|
334
|
+
flatStyle.position = 'absolute';
|
|
335
|
+
(0, _errorMsg.warnMsg)('"position" value of "fixed" is not supported in React Native. Falling back to "absolute".');
|
|
336
|
+
} else if (positionValue === 'static') {
|
|
337
|
+
flatStyle.position = 'relative';
|
|
338
|
+
(0, _errorMsg.warnMsg)('"position" value of "static" is not supported in React Native. Falling back to "relative".');
|
|
339
|
+
} else if (positionValue === 'sticky') {
|
|
340
|
+
flatStyle.position = 'relative';
|
|
341
|
+
(0, _errorMsg.warnMsg)('"position" value of "sticky" is not supported in React Native. Falling back to "relative".');
|
|
329
342
|
}
|
|
330
343
|
for (const timeValuedProperty of timeValuedProperties) {
|
|
331
|
-
if (typeof flatStyle[timeValuedProperty] ===
|
|
344
|
+
if (typeof flatStyle[timeValuedProperty] === 'string') {
|
|
332
345
|
flatStyle[timeValuedProperty] = (0, _parseTimeValue.parseTimeValue)(flatStyle[timeValuedProperty]);
|
|
333
346
|
}
|
|
334
347
|
}
|
|
@@ -339,12 +352,34 @@ function spread(style, options) {
|
|
|
339
352
|
}
|
|
340
353
|
return nativeProps;
|
|
341
354
|
}
|
|
342
|
-
const
|
|
355
|
+
const __customProperties = exports.__customProperties = {};
|
|
356
|
+
let count = 1;
|
|
357
|
+
const defineVars = tokens => {
|
|
358
|
+
const result = {};
|
|
359
|
+
for (const key in tokens) {
|
|
360
|
+
const value = tokens[key];
|
|
361
|
+
result[key] = `var(--${key}-${count++})`;
|
|
362
|
+
__customProperties[result[key]] = value;
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
};
|
|
366
|
+
exports.defineVars = defineVars;
|
|
367
|
+
const createTheme = (baseTokens, overrides) => {
|
|
368
|
+
const result = {};
|
|
369
|
+
for (const key in baseTokens) {
|
|
370
|
+
const varName = baseTokens[key];
|
|
371
|
+
result[varName] = overrides[key];
|
|
372
|
+
}
|
|
373
|
+
return result;
|
|
374
|
+
};
|
|
375
|
+
exports.createTheme = createTheme;
|
|
376
|
+
const stylex = exports.stylex = {
|
|
343
377
|
create,
|
|
344
378
|
firstThatWorks,
|
|
345
379
|
keyframes,
|
|
346
|
-
|
|
380
|
+
props,
|
|
381
|
+
defineVars,
|
|
382
|
+
createTheme,
|
|
383
|
+
__customProperties
|
|
347
384
|
};
|
|
348
|
-
exports.
|
|
349
|
-
var _default = stylex;
|
|
350
|
-
exports.default = _default;
|
|
385
|
+
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
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
declare export function props(
|
|
38
|
+
this: SpreadOptions,
|
|
39
|
+
...style: $ReadOnlyArray<?{ [key: string]: mixed }>
|
|
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
|
|