@stylexjs/stylex 0.2.0-beta.16 → 0.2.0-beta.18
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/lib/StyleXCSSTypes.js +1 -10
- package/lib/StyleXSheet.d.ts +3 -3
- package/lib/StyleXSheet.js +19 -132
- package/lib/StyleXSheet.js.flow +2 -2
- package/lib/StyleXTypes.d.ts +143 -180
- package/lib/StyleXTypes.js +1 -10
- package/lib/StyleXTypes.js.flow +72 -23
- package/lib/native/CSSCustomPropertyValue.js +2 -11
- package/lib/native/CSSLengthUnitValue.d.ts +1 -1
- package/lib/native/CSSLengthUnitValue.js +7 -18
- package/lib/native/CSSLengthUnitValue.js.flow +1 -1
- package/lib/native/CSSMediaQuery.d.ts +1 -1
- package/lib/native/CSSMediaQuery.js +4 -18
- package/lib/native/CSSMediaQuery.js.flow +1 -1
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +81 -0
- package/lib/native/__tests__/parseTimeValue-test.js +11 -0
- package/lib/native/__tests__/stylex-test.js +186 -128
- package/lib/native/errorMsg.js +0 -9
- package/lib/native/flattenStyle.js +1 -11
- package/lib/native/parseShadow.js +4 -13
- package/lib/native/parseTimeValue.d.ts +11 -0
- package/lib/native/parseTimeValue.js +18 -0
- package/lib/native/parseTimeValue.js.flow +12 -0
- package/lib/native/stylex.d.ts +6 -5
- package/lib/native/stylex.js +60 -106
- package/lib/native/stylex.js.flow +4 -4
- package/lib/stylex-inject.d.ts +1 -1
- package/lib/stylex-inject.js +0 -9
- package/lib/stylex-inject.js.flow +1 -1
- package/lib/stylex.d.ts +23 -25
- package/lib/stylex.js +8 -17
- package/lib/stylex.js.flow +24 -27
- package/package.json +2 -2
package/lib/native/errorMsg.js
CHANGED
|
@@ -5,15 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.errorMsg = errorMsg;
|
|
7
7
|
exports.warnMsg = warnMsg;
|
|
8
|
-
/**
|
|
9
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
-
*
|
|
11
|
-
* This source code is licensed under the MIT license found in the
|
|
12
|
-
* LICENSE file in the root directory of this source tree.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
8
|
function errorMsg(msg) {
|
|
18
9
|
console.error(`stylex: ${msg}`);
|
|
19
10
|
}
|
|
@@ -4,15 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.flattenStyle = flattenStyle;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the MIT license found in the
|
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
7
|
function flattenStyle() {
|
|
17
8
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
9
|
styles[_key] = arguments[_key];
|
|
@@ -21,8 +12,7 @@ function flattenStyle() {
|
|
|
21
12
|
const result = {};
|
|
22
13
|
for (let i = 0; i < flatArray.length; i++) {
|
|
23
14
|
const style = flatArray[i];
|
|
24
|
-
if (style != null && typeof style ===
|
|
25
|
-
// $FlowFixMe
|
|
15
|
+
if (style != null && typeof style === "object") {
|
|
26
16
|
Object.assign(result, style);
|
|
27
17
|
}
|
|
28
18
|
}
|
|
@@ -4,32 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseShadow = parseShadow;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the MIT license found in the
|
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
7
|
const VALUES_REG = /,(?![^(]*\))/;
|
|
17
8
|
const PARTS_REG = /\s(?![^(]*\))/;
|
|
18
9
|
const LENGTH_REG = /^[0-9]+[a-zA-Z%]+?$/;
|
|
19
10
|
function isLength(v) {
|
|
20
|
-
return v ===
|
|
11
|
+
return v === "0" || LENGTH_REG.test(v);
|
|
21
12
|
}
|
|
22
13
|
function toMaybeNum(v) {
|
|
23
|
-
if (!/px$/.test(v) && v !==
|
|
14
|
+
if (!/px$/.test(v) && v !== "0") return v;
|
|
24
15
|
const n = parseFloat(v);
|
|
25
16
|
return !isNaN(n) ? n : v;
|
|
26
17
|
}
|
|
27
18
|
function parseValue(str) {
|
|
28
19
|
const parts = str.split(PARTS_REG);
|
|
29
|
-
const inset = parts.includes(
|
|
20
|
+
const inset = parts.includes("inset");
|
|
30
21
|
const last = parts.slice(-1)[0];
|
|
31
22
|
const color = !isLength(last) ? last : null;
|
|
32
|
-
const nums = parts.filter(n => n !==
|
|
23
|
+
const nums = parts.filter(n => n !== "inset").filter(n => n !== color).map(toMaybeNum);
|
|
33
24
|
const [offsetX, offsetY, blurRadius, spreadRadius] = nums;
|
|
34
25
|
return {
|
|
35
26
|
inset,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type Milliseconds = number;
|
|
11
|
+
export declare function parseTimeValue(timeValue: string): Milliseconds;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseTimeValue = parseTimeValue;
|
|
7
|
+
function parseTimeValue(timeValue) {
|
|
8
|
+
const trimmedTimeValue = timeValue.trim().toLowerCase();
|
|
9
|
+
if (trimmedTimeValue.endsWith("ms")) {
|
|
10
|
+
const msVal = parseFloat(trimmedTimeValue.replace(/ms$/, ""));
|
|
11
|
+
return Number.isFinite(msVal) ? msVal : 0;
|
|
12
|
+
}
|
|
13
|
+
if (trimmedTimeValue.endsWith("s")) {
|
|
14
|
+
const sVal = parseFloat(trimmedTimeValue.replace(/s$/, ""));
|
|
15
|
+
return Number.isFinite(sVal) ? sVal * 1000 : 0;
|
|
16
|
+
}
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type Milliseconds = number;
|
|
11
|
+
|
|
12
|
+
declare export function parseTimeValue(timeValue: string): Milliseconds;
|
package/lib/native/stylex.d.ts
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
* compile-time in the future).
|
|
15
15
|
*/
|
|
16
16
|
export declare function create<S extends { [$$Key$$: string]: {} }>(
|
|
17
|
-
styles: S
|
|
17
|
+
styles: S,
|
|
18
18
|
): { [$$Key$$: string]: {} };
|
|
19
|
-
export declare
|
|
19
|
+
export declare const firstThatWorks: <T extends string | number>(
|
|
20
20
|
...values: ReadonlyArray<T>
|
|
21
21
|
) => T;
|
|
22
22
|
export declare function keyframes(): void;
|
|
@@ -37,7 +37,7 @@ type SpreadOptions = {
|
|
|
37
37
|
};
|
|
38
38
|
export declare function spread(
|
|
39
39
|
style: null | undefined | { [key: string]: unknown },
|
|
40
|
-
$$PARAM_1$$: SpreadOptions
|
|
40
|
+
$$PARAM_1$$: SpreadOptions,
|
|
41
41
|
): { [$$Key$$: string]: {} };
|
|
42
42
|
export type IStyleX = {
|
|
43
43
|
create: typeof create;
|
|
@@ -45,5 +45,6 @@ export type IStyleX = {
|
|
|
45
45
|
keyframes: typeof keyframes;
|
|
46
46
|
spread: typeof spread;
|
|
47
47
|
};
|
|
48
|
-
export declare
|
|
49
|
-
|
|
48
|
+
export declare const stylex: IStyleX;
|
|
49
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
50
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/lib/native/stylex.js
CHANGED
|
@@ -14,58 +14,30 @@ var _CSSMediaQuery = require("./CSSMediaQuery");
|
|
|
14
14
|
var _errorMsg = require("./errorMsg");
|
|
15
15
|
var _flattenStyle = require("./flattenStyle");
|
|
16
16
|
var _parseShadow = require("./parseShadow");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the MIT license found in the
|
|
21
|
-
* LICENSE file in the root directory of this source tree.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const stylePropertyAllowlistSet = new Set(['alignContent', 'alignItems', 'alignSelf', 'aspectRatio', 'backfaceVisibility', 'backgroundColor', 'borderBlockColor', 'borderBlockStyle', 'borderBlockWidth', 'borderBlockEndColor', 'borderBlockEndStyle', 'borderBlockEndWidth', 'borderBlockStartColor', 'borderBlockStartStyle', 'borderBlockStartWidth', 'borderBottomColor', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStyle', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderColor', 'borderInlineColor', 'borderInlineStyle', 'borderInlineWidth', 'borderInlineEndColor', 'borderInlineEndStyle', 'borderInlineEndWidth', 'borderInlineStartColor', 'borderInlineStartStyle', 'borderInlineStartWidth', 'borderEndColor', 'borderEndStyle', 'borderEndWidth', 'borderStartColor', 'borderStartStyle', 'borderStartWidth', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRadius', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderStartEndRadius', 'borderStartStartRadius', 'borderStyle', 'borderTopColor', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStyle', 'borderTopWidth', 'borderWidth', 'bottom', 'color', 'direction', 'display', 'end', 'flex', 'flexBasis', 'flexDirection', 'flexGrow', 'flexShrink', 'flexWrap', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'fontVariant', 'gap', 'gapColumn', 'gapRow', 'height',
|
|
27
|
-
// 'includeFontPadding', Android Only
|
|
28
|
-
'inset', 'insetBlock', 'insetBlockEnd', 'insetBlockStart', 'insetInline', 'insetInlineEnd', 'insetInlineStart', 'justifyContent', 'left', 'letterSpacing', 'lineHeight', 'margin', 'marginBlock', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginEnd', 'marginInline', 'marginInlineEnd', 'marginInlineStart', 'marginLeft', 'marginRight', 'marginStart', 'marginTop', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'objectFit', 'opacity', 'overflow', 'padding', 'paddingBlock', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingEnd', 'paddingInline', 'paddingInlineEnd', 'paddingInlineStart', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingTop', 'pointerEvents', 'position', 'resizeMode', 'right', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'shadowWidth', 'start', 'textAlign', 'textDecorationLine', 'textDecorationColor',
|
|
29
|
-
// iOS Only
|
|
30
|
-
'textDecorationStyle',
|
|
31
|
-
// iOS Only
|
|
32
|
-
'textShadowColor', 'textShadowOffset', 'textShadowRadius', 'textTransform', 'tintColor', 'transform', 'top', 'userSelect', 'verticalAlign',
|
|
33
|
-
// Android Only
|
|
34
|
-
'width',
|
|
35
|
-
// 'writingDirection', // iOS Only
|
|
36
|
-
'zIndex']);
|
|
17
|
+
var _parseTimeValue = require("./parseTimeValue");
|
|
18
|
+
const stylePropertyAllowlistSet = new Set(["alignContent", "alignItems", "alignSelf", "animationDelay", "animationDuration", "aspectRatio", "backfaceVisibility", "backgroundColor", "borderBlockColor", "borderBlockStyle", "borderBlockWidth", "borderBlockEndColor", "borderBlockEndStyle", "borderBlockEndWidth", "borderBlockStartColor", "borderBlockStartStyle", "borderBlockStartWidth", "borderBottomColor", "borderBottomLeftRadius", "borderBottomRightRadius", "borderBottomStyle", "borderBottomWidth", "borderEndEndRadius", "borderEndStartRadius", "borderColor", "borderInlineColor", "borderInlineStyle", "borderInlineWidth", "borderInlineEndColor", "borderInlineEndStyle", "borderInlineEndWidth", "borderInlineStartColor", "borderInlineStartStyle", "borderInlineStartWidth", "borderEndColor", "borderEndStyle", "borderEndWidth", "borderStartColor", "borderStartStyle", "borderStartWidth", "borderLeftColor", "borderLeftStyle", "borderLeftWidth", "borderRadius", "borderRightColor", "borderRightStyle", "borderRightWidth", "borderStartEndRadius", "borderStartStartRadius", "borderStyle", "borderTopColor", "borderTopLeftRadius", "borderTopRightRadius", "borderTopStyle", "borderTopWidth", "borderWidth", "bottom", "color", "direction", "display", "end", "flex", "flexBasis", "flexDirection", "flexGrow", "flexShrink", "flexWrap", "fontFamily", "fontSize", "fontStyle", "fontWeight", "fontVariant", "gap", "gapColumn", "gapRow", "height", "inset", "insetBlock", "insetBlockEnd", "insetBlockStart", "insetInline", "insetInlineEnd", "insetInlineStart", "justifyContent", "left", "letterSpacing", "lineHeight", "margin", "marginBlock", "marginBlockEnd", "marginBlockStart", "marginBottom", "marginEnd", "marginInline", "marginInlineEnd", "marginInlineStart", "marginLeft", "marginRight", "marginStart", "marginTop", "maxHeight", "maxWidth", "minHeight", "minWidth", "objectFit", "opacity", "overflow", "padding", "paddingBlock", "paddingBlockEnd", "paddingBlockStart", "paddingBottom", "paddingEnd", "paddingInline", "paddingInlineEnd", "paddingInlineStart", "paddingLeft", "paddingRight", "paddingStart", "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"]);
|
|
37
19
|
function isReactNativeStyleProp(propName) {
|
|
38
|
-
return stylePropertyAllowlistSet.has(propName) || propName.startsWith(
|
|
20
|
+
return stylePropertyAllowlistSet.has(propName) || propName.startsWith("--");
|
|
39
21
|
}
|
|
40
22
|
function isReactNativeStyleValue(propValue) {
|
|
41
|
-
if (typeof propValue ===
|
|
42
|
-
|
|
43
|
-
if (propValue === 'inherit') {
|
|
23
|
+
if (typeof propValue === "string") {
|
|
24
|
+
if (propValue === "inherit") {
|
|
44
25
|
return false;
|
|
45
26
|
}
|
|
46
|
-
|
|
47
|
-
if (propValue === 'initial') {
|
|
27
|
+
if (propValue === "initial") {
|
|
48
28
|
return false;
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
// return false;
|
|
52
|
-
//}
|
|
53
|
-
//if (propValue.endsWith('rem')) {
|
|
54
|
-
// return false;
|
|
55
|
-
//}
|
|
56
|
-
// RN on android doesn't like explicitly specified px units
|
|
57
|
-
if (propValue.endsWith('px')) {
|
|
30
|
+
if (propValue.endsWith("px")) {
|
|
58
31
|
return false;
|
|
59
32
|
}
|
|
60
|
-
|
|
61
|
-
if (propValue.includes('calc(')) {
|
|
33
|
+
if (propValue.includes("calc(")) {
|
|
62
34
|
return false;
|
|
63
35
|
}
|
|
64
36
|
}
|
|
65
37
|
return true;
|
|
66
38
|
}
|
|
67
39
|
function preprocessPropertyValue(propValue) {
|
|
68
|
-
if (typeof propValue ===
|
|
40
|
+
if (typeof propValue === "string") {
|
|
69
41
|
if ((0, _CSSCustomPropertyValue.isCustomPropertyValue)(propValue)) {
|
|
70
42
|
return new _CSSCustomPropertyValue.CSSCustomPropertyValue(propValue);
|
|
71
43
|
}
|
|
@@ -77,26 +49,22 @@ function preprocessPropertyValue(propValue) {
|
|
|
77
49
|
return propValue;
|
|
78
50
|
}
|
|
79
51
|
function preprocessCreate(style) {
|
|
80
|
-
// eslint-disable-next-line flowtype/no-flow-fix-me-comments
|
|
81
52
|
const processedStyle = {};
|
|
82
53
|
for (const propName in style) {
|
|
83
54
|
const styleValue = style[propName];
|
|
84
|
-
if (_CSSMediaQuery.CSSMediaQuery.isMediaQueryString(propName) && typeof styleValue ===
|
|
85
|
-
// have to spread styleValue into a copied object to appease flow
|
|
55
|
+
if (_CSSMediaQuery.CSSMediaQuery.isMediaQueryString(propName) && typeof styleValue === "object" && styleValue != null) {
|
|
86
56
|
const processsedSubStyle = preprocessCreate({
|
|
87
57
|
...styleValue
|
|
88
58
|
});
|
|
89
59
|
processedStyle[propName] = new _CSSMediaQuery.CSSMediaQuery(propName, processsedSubStyle);
|
|
90
60
|
continue;
|
|
91
61
|
}
|
|
92
|
-
if (propName ===
|
|
93
|
-
(0, _errorMsg.errorMsg)(
|
|
94
|
-
}
|
|
95
|
-
// React Native only supports non-standard box-shadow styles
|
|
96
|
-
else if (propName === 'boxShadow' && typeof styleValue === 'string') {
|
|
62
|
+
if (propName === "backgroundImage") {
|
|
63
|
+
(0, _errorMsg.errorMsg)("\"backgroundImage\" is not supported in React Native.");
|
|
64
|
+
} else if (propName === "boxShadow" && typeof styleValue === "string") {
|
|
97
65
|
const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
|
|
98
66
|
if (parsedShadow.length > 1) {
|
|
99
|
-
(0, _errorMsg.errorMsg)(
|
|
67
|
+
(0, _errorMsg.errorMsg)("Multiple \"boxShadow\" values are not supported in React Native.");
|
|
100
68
|
}
|
|
101
69
|
const {
|
|
102
70
|
inset,
|
|
@@ -105,10 +73,8 @@ function preprocessCreate(style) {
|
|
|
105
73
|
blurRadius,
|
|
106
74
|
color
|
|
107
75
|
} = parsedShadow[0];
|
|
108
|
-
// TODO: parse alpha color inputs => alpha + color
|
|
109
|
-
// errorMsg('"boxShadow" opacity is not implemented in React Native.');
|
|
110
76
|
if (inset) {
|
|
111
|
-
(0, _errorMsg.errorMsg)(
|
|
77
|
+
(0, _errorMsg.errorMsg)("\"boxShadow\" value of \"inset\" is not supported in React Native.");
|
|
112
78
|
}
|
|
113
79
|
processedStyle.shadowColor = color;
|
|
114
80
|
processedStyle.shadowOffset = {
|
|
@@ -117,27 +83,22 @@ function preprocessCreate(style) {
|
|
|
117
83
|
};
|
|
118
84
|
processedStyle.shadowOpacity = 1;
|
|
119
85
|
processedStyle.shadowRadius = blurRadius;
|
|
120
|
-
}
|
|
121
|
-
// Needed by React Native for Desktop
|
|
122
|
-
else if (propName === 'fontWeight' && typeof styleValue === 'number') {
|
|
123
|
-
// $FlowFixMe
|
|
86
|
+
} else if (propName === "fontWeight" && typeof styleValue === "number") {
|
|
124
87
|
processedStyle[propName] = styleValue.toString();
|
|
125
|
-
} else if (propName ===
|
|
126
|
-
if (styleValue ===
|
|
127
|
-
processedStyle[propName] =
|
|
128
|
-
(0, _errorMsg.errorMsg)(
|
|
129
|
-
} else if (styleValue ===
|
|
130
|
-
processedStyle[propName] =
|
|
131
|
-
(0, _errorMsg.errorMsg)(
|
|
88
|
+
} else if (propName === "position") {
|
|
89
|
+
if (styleValue === "fixed") {
|
|
90
|
+
processedStyle[propName] = "absolute";
|
|
91
|
+
(0, _errorMsg.errorMsg)("\"position\" value of \"fixed\" is not supported in React Native. Falling back to \"absolute\".");
|
|
92
|
+
} else if (styleValue === "sticky") {
|
|
93
|
+
processedStyle[propName] = "relative";
|
|
94
|
+
(0, _errorMsg.errorMsg)("\"position\" value of \"sticky\" is not supported in React Native. Falling back to \"relative\".");
|
|
132
95
|
} else {
|
|
133
96
|
processedStyle[propName] = styleValue;
|
|
134
97
|
}
|
|
135
|
-
}
|
|
136
|
-
// React Native only supports non-standard text-shadow styles
|
|
137
|
-
else if (propName === 'textShadow' && typeof styleValue === 'string') {
|
|
98
|
+
} else if (propName === "textShadow" && typeof styleValue === "string") {
|
|
138
99
|
const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
|
|
139
100
|
if (parsedShadow.length > 1) {
|
|
140
|
-
(0, _errorMsg.errorMsg)(
|
|
101
|
+
(0, _errorMsg.errorMsg)("Multiple \"textShadow\" values are not supported in React Native.");
|
|
141
102
|
}
|
|
142
103
|
const {
|
|
143
104
|
offsetX,
|
|
@@ -151,37 +112,28 @@ function preprocessCreate(style) {
|
|
|
151
112
|
width: offsetX
|
|
152
113
|
};
|
|
153
114
|
processedStyle.textShadowRadius = blurRadius;
|
|
154
|
-
} else if (propName ===
|
|
155
|
-
(0, _errorMsg.warnMsg)(
|
|
115
|
+
} else if (propName === "marginHorizontal") {
|
|
116
|
+
(0, _errorMsg.warnMsg)("\"marginHorizontal\" is deprecated. Use \"marginInline\".");
|
|
156
117
|
processedStyle.marginInline = styleValue;
|
|
157
|
-
} else if (propName ===
|
|
158
|
-
(0, _errorMsg.warnMsg)(
|
|
118
|
+
} else if (propName === "marginVertical") {
|
|
119
|
+
(0, _errorMsg.warnMsg)("\"marginVertical\" is deprecated. Use \"marginBlock\".");
|
|
159
120
|
processedStyle.marginBlock = styleValue;
|
|
160
|
-
} else if (propName ===
|
|
161
|
-
(0, _errorMsg.warnMsg)(
|
|
121
|
+
} else if (propName === "paddingHorizontal") {
|
|
122
|
+
(0, _errorMsg.warnMsg)("\"paddingHorizontal\" is deprecated. Use \"paddingInline\".");
|
|
162
123
|
processedStyle.paddingInline = styleValue;
|
|
163
|
-
} else if (propName ===
|
|
164
|
-
(0, _errorMsg.warnMsg)(
|
|
124
|
+
} else if (propName === "paddingVertical") {
|
|
125
|
+
(0, _errorMsg.warnMsg)("\"paddingVertical\" is deprecated. Use \"paddingBlock\".");
|
|
165
126
|
processedStyle.paddingBlock = styleValue;
|
|
166
127
|
} else {
|
|
167
128
|
processedStyle[propName] = styleValue;
|
|
168
129
|
}
|
|
169
130
|
}
|
|
170
|
-
|
|
171
|
-
// Process values that need to be resolved during render
|
|
172
131
|
for (const prop in processedStyle) {
|
|
173
132
|
const processedStyleValue = preprocessPropertyValue(processedStyle[prop]);
|
|
174
133
|
processedStyle[prop] = processedStyleValue;
|
|
175
134
|
}
|
|
176
135
|
return processedStyle;
|
|
177
136
|
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* The create method shim should do initial transforms like
|
|
181
|
-
* renaming/expanding/validating properties, essentially all the steps
|
|
182
|
-
* which can be done at initialization-time (could potentially be done at
|
|
183
|
-
* compile-time in the future).
|
|
184
|
-
*/
|
|
185
137
|
function create(styles) {
|
|
186
138
|
const result = {};
|
|
187
139
|
for (const styleName in styles) {
|
|
@@ -194,13 +146,9 @@ const firstThatWorks = function () {
|
|
|
194
146
|
};
|
|
195
147
|
exports.firstThatWorks = firstThatWorks;
|
|
196
148
|
function keyframes() {
|
|
197
|
-
(0, _errorMsg.errorMsg)(
|
|
149
|
+
(0, _errorMsg.errorMsg)("keyframes are not supported in React Native.");
|
|
198
150
|
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* The spread method shim
|
|
202
|
-
*/
|
|
203
|
-
|
|
151
|
+
const timeValuedProperties = ["animationDelay", "animationDuration", "transitionDelay", "transitionDuration"];
|
|
204
152
|
function spread(style, _ref) {
|
|
205
153
|
let {
|
|
206
154
|
customProperties = {},
|
|
@@ -211,18 +159,13 @@ function spread(style, _ref) {
|
|
|
211
159
|
viewportWidth,
|
|
212
160
|
writingDirection
|
|
213
161
|
} = _ref;
|
|
214
|
-
/* eslint-disable prefer-const */
|
|
215
162
|
let {
|
|
216
163
|
lineClamp,
|
|
217
164
|
...flatStyle
|
|
218
165
|
} = (0, _flattenStyle.flattenStyle)(style);
|
|
219
|
-
/* eslint-enable prefer-const */
|
|
220
|
-
|
|
221
166
|
const nativeProps = {};
|
|
222
167
|
for (const styleProp in flatStyle) {
|
|
223
168
|
let styleValue = flatStyle[styleProp];
|
|
224
|
-
|
|
225
|
-
// resolve media queries
|
|
226
169
|
if (styleValue instanceof _CSSMediaQuery.CSSMediaQuery) {
|
|
227
170
|
const maybeExistingMediaQuery = flatStyle[styleProp];
|
|
228
171
|
if (maybeExistingMediaQuery instanceof _CSSMediaQuery.CSSMediaQuery) {
|
|
@@ -233,7 +176,6 @@ function spread(style, _ref) {
|
|
|
233
176
|
continue;
|
|
234
177
|
}
|
|
235
178
|
}
|
|
236
|
-
// resolve custom property references
|
|
237
179
|
if (styleValue instanceof _CSSCustomPropertyValue.CSSCustomPropertyValue) {
|
|
238
180
|
const resolvedValue = customProperties[styleValue.name];
|
|
239
181
|
if (resolvedValue == null) {
|
|
@@ -243,26 +185,15 @@ function spread(style, _ref) {
|
|
|
243
185
|
}
|
|
244
186
|
styleValue = resolvedValue;
|
|
245
187
|
}
|
|
246
|
-
// resolve viewport units
|
|
247
188
|
if (styleValue instanceof _CSSLengthUnitValue.CSSLengthUnitValue) {
|
|
248
189
|
const resolvedValue = styleValue.resolvePixelValue(viewportWidth, viewportHeight, fontScale, inheritedFontSize);
|
|
249
190
|
styleValue = resolvedValue;
|
|
250
191
|
}
|
|
251
|
-
|
|
252
|
-
// Filter out any unexpected style property names so RN doesn't crash but give
|
|
253
|
-
// the developer a warning to let them know that there's a new prop we should either
|
|
254
|
-
// explicitly ignore or process in some way.
|
|
255
|
-
// NOTE: Any kind of prop name transformations should happen before this check.
|
|
256
192
|
if (!isReactNativeStyleProp(styleProp) && passthroughProperties.indexOf(styleProp) === -1) {
|
|
257
193
|
(0, _errorMsg.errorMsg)(`Encountered unsupported style property "${styleProp}"`);
|
|
258
194
|
delete flatStyle[styleProp];
|
|
259
195
|
continue;
|
|
260
196
|
}
|
|
261
|
-
|
|
262
|
-
// Similar filter to the prop name one above but instead operates on the property's
|
|
263
|
-
// value. Similarly, any sort of prop value transformations should happen before this
|
|
264
|
-
// filter.
|
|
265
|
-
// We check this at resolve time to ensure the render-time styles are safe.
|
|
266
197
|
if (!isReactNativeStyleValue(styleValue)) {
|
|
267
198
|
(0, _errorMsg.errorMsg)(`Encounted unsupported style value "${String(styleValue)}" for property "${styleProp}"`);
|
|
268
199
|
delete flatStyle[styleProp];
|
|
@@ -276,11 +207,34 @@ function spread(style, _ref) {
|
|
|
276
207
|
height: viewportHeight,
|
|
277
208
|
direction: writingDirection
|
|
278
209
|
});
|
|
279
|
-
|
|
210
|
+
if (flatStyle.borderStyle === "none") {
|
|
211
|
+
flatStyle.borderWidth = 0;
|
|
212
|
+
delete flatStyle.borderStyle;
|
|
213
|
+
}
|
|
214
|
+
if (flatStyle.borderStartStartRadius != null) {
|
|
215
|
+
flatStyle.borderTopStartRadius = flatStyle.borderStartStartRadius;
|
|
216
|
+
delete flatStyle.borderStartStartRadius;
|
|
217
|
+
}
|
|
218
|
+
if (flatStyle.borderEndStartRadius != null) {
|
|
219
|
+
flatStyle.borderBottomStartRadius = flatStyle.borderEndStartRadius;
|
|
220
|
+
delete flatStyle.borderEndStartRadius;
|
|
221
|
+
}
|
|
222
|
+
if (flatStyle.borderStartEndRadius != null) {
|
|
223
|
+
flatStyle.borderTopEndRadius = flatStyle.borderStartEndRadius;
|
|
224
|
+
delete flatStyle.borderStartEndRadius;
|
|
225
|
+
}
|
|
226
|
+
if (flatStyle.borderEndEndRadius != null) {
|
|
227
|
+
flatStyle.borderBottomEndRadius = flatStyle.borderEndEndRadius;
|
|
228
|
+
delete flatStyle.borderEndEndRadius;
|
|
229
|
+
}
|
|
230
|
+
for (const timeValuedProperty of timeValuedProperties) {
|
|
231
|
+
if (typeof flatStyle[timeValuedProperty] === "string") {
|
|
232
|
+
flatStyle[timeValuedProperty] = (0, _parseTimeValue.parseTimeValue)(flatStyle[timeValuedProperty]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
280
235
|
nativeProps.style = flatStyle;
|
|
281
236
|
}
|
|
282
237
|
if (lineClamp != null) {
|
|
283
|
-
// $FlowFixMe
|
|
284
238
|
nativeProps.numberOfLines = lineClamp;
|
|
285
239
|
}
|
|
286
240
|
return nativeProps;
|
|
@@ -17,7 +17,7 @@ declare export function create<S: { [string]: { ... } }>(styles: S): {
|
|
|
17
17
|
[string]: { ... },
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
declare export
|
|
20
|
+
declare export const firstThatWorks: <T: string | number>(
|
|
21
21
|
...values: $ReadOnlyArray<T>
|
|
22
22
|
) => T;
|
|
23
23
|
|
|
@@ -38,7 +38,7 @@ type SpreadOptions = {|
|
|
|
38
38
|
|
|
39
39
|
declare export function spread(
|
|
40
40
|
style: ?{ [key: string]: mixed },
|
|
41
|
-
SpreadOptions
|
|
41
|
+
SpreadOptions,
|
|
42
42
|
): { [string]: { ... } };
|
|
43
43
|
|
|
44
44
|
export type IStyleX = {
|
|
@@ -48,6 +48,6 @@ export type IStyleX = {
|
|
|
48
48
|
spread: typeof spread,
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
declare export
|
|
51
|
+
declare export const stylex: IStyleX;
|
|
52
52
|
|
|
53
|
-
declare export default
|
|
53
|
+
declare export default IStyleX;
|
package/lib/stylex-inject.d.ts
CHANGED
package/lib/stylex-inject.js
CHANGED
|
@@ -5,15 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = inject;
|
|
7
7
|
var _StyleXSheet = require("./StyleXSheet");
|
|
8
|
-
/**
|
|
9
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
-
*
|
|
11
|
-
* This source code is licensed under the MIT license found in the
|
|
12
|
-
* LICENSE file in the root directory of this source tree.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
8
|
function inject(ltrRule, priority) {
|
|
18
9
|
let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
19
10
|
_StyleXSheet.styleSheet.insert(ltrRule, priority, rtlRule);
|
package/lib/stylex.d.ts
CHANGED
|
@@ -10,62 +10,60 @@
|
|
|
10
10
|
import type {
|
|
11
11
|
Keyframes,
|
|
12
12
|
Stylex$Create,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
StyleX$CreateVars,
|
|
14
|
+
StyleX$OverrideVars,
|
|
15
15
|
StyleXArray,
|
|
16
16
|
MapNamespace,
|
|
17
|
+
CompiledStyles,
|
|
17
18
|
} from './StyleXTypes';
|
|
19
|
+
export type { Theme, Variant } from './StyleXTypes';
|
|
18
20
|
import injectStyle from './stylex-inject';
|
|
19
|
-
type DedupeStyles = Readonly<{
|
|
20
|
-
$$css: true;
|
|
21
|
-
[key: string]: string | Readonly<{ [key: string]: string }>;
|
|
22
|
-
}>;
|
|
23
21
|
export declare function spread(
|
|
24
22
|
styles: StyleXArray<
|
|
25
|
-
| (null | undefined |
|
|
23
|
+
| (null | undefined | CompiledStyles)
|
|
26
24
|
| boolean
|
|
27
25
|
| Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>
|
|
28
26
|
>,
|
|
29
|
-
_options?: {}
|
|
27
|
+
_options?: {},
|
|
30
28
|
): Readonly<{
|
|
31
29
|
className: string;
|
|
32
30
|
style: Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>;
|
|
33
31
|
}>;
|
|
34
32
|
type Stylex$Include = <
|
|
35
|
-
TStyles extends { readonly [$$Key$$: string]: string | number }
|
|
33
|
+
TStyles extends { readonly [$$Key$$: string]: string | number },
|
|
36
34
|
>(
|
|
37
|
-
_styles: MapNamespace<TStyles
|
|
35
|
+
_styles: MapNamespace<TStyles>,
|
|
38
36
|
) => TStyles;
|
|
39
|
-
export declare
|
|
40
|
-
export declare
|
|
41
|
-
export declare
|
|
42
|
-
export declare
|
|
43
|
-
export declare
|
|
44
|
-
export declare
|
|
37
|
+
export declare const create: Stylex$Create;
|
|
38
|
+
export declare const unstable_createVars: StyleX$CreateVars;
|
|
39
|
+
export declare const unstable_overrideVars: StyleX$OverrideVars;
|
|
40
|
+
export declare const include: Stylex$Include;
|
|
41
|
+
export declare const keyframes: (_keyframes: Keyframes) => string;
|
|
42
|
+
export declare const firstThatWorks: <T extends string | number>(
|
|
45
43
|
..._styles: ReadonlyArray<T>
|
|
46
44
|
) => ReadonlyArray<T>;
|
|
47
|
-
export declare
|
|
48
|
-
export declare
|
|
45
|
+
export declare const inject: typeof injectStyle;
|
|
46
|
+
export declare const UNSUPPORTED_PROPERTY: <T>(_props: T) => T;
|
|
49
47
|
type IStyleX = {
|
|
50
48
|
(
|
|
51
49
|
...styles: ReadonlyArray<
|
|
52
|
-
StyleXArray<(null | undefined |
|
|
50
|
+
StyleXArray<(null | undefined | CompiledStyles) | boolean>
|
|
53
51
|
>
|
|
54
52
|
): string;
|
|
55
53
|
spread: (
|
|
56
54
|
styles: StyleXArray<
|
|
57
|
-
| (null | undefined |
|
|
55
|
+
| (null | undefined | CompiledStyles)
|
|
58
56
|
| boolean
|
|
59
57
|
| Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>
|
|
60
58
|
>,
|
|
61
|
-
_options?: {}
|
|
59
|
+
_options?: {},
|
|
62
60
|
) => Readonly<{
|
|
63
61
|
className: string;
|
|
64
62
|
style: Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>;
|
|
65
63
|
}>;
|
|
66
64
|
create: Stylex$Create;
|
|
67
|
-
unstable_createVars:
|
|
68
|
-
unstable_overrideVars:
|
|
65
|
+
unstable_createVars: StyleX$CreateVars;
|
|
66
|
+
unstable_overrideVars: StyleX$OverrideVars;
|
|
69
67
|
include: Stylex$Include;
|
|
70
68
|
firstThatWorks: <T extends string | number>(
|
|
71
69
|
...v: ReadonlyArray<T>
|
|
@@ -73,11 +71,11 @@ type IStyleX = {
|
|
|
73
71
|
inject: (
|
|
74
72
|
ltrRule: string,
|
|
75
73
|
priority: number,
|
|
76
|
-
rtlRule: null | undefined | string
|
|
74
|
+
rtlRule: null | undefined | string,
|
|
77
75
|
) => void;
|
|
78
76
|
keyframes: (keyframes: Keyframes) => string;
|
|
79
77
|
UNSUPPORTED_PROPERTY: <T>(props: T) => T;
|
|
80
78
|
};
|
|
81
79
|
declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
|
|
82
80
|
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
|
83
|
-
export declare
|
|
81
|
+
export declare const stylex: IStyleX;
|