@stylexjs/stylex 0.2.0-beta.19 → 0.2.0-beta.21

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.
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fixContentBox = fixContentBox;
7
+ var _errorMsg = require("./errorMsg");
8
+ const TOP = 0;
9
+ const RIGHT = 1;
10
+ const BOTTOM = 2;
11
+ const LEFT = 3;
12
+ const START = LEFT;
13
+ const END = RIGHT;
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
+ function fixContentBox(flatStyle) {
17
+ const border = [0, 0, 0, 0];
18
+ const padding = [0, 0, 0, 0];
19
+ for (const [styleProp, directions] of borderMapping) {
20
+ if (typeof flatStyle[styleProp] === "number") {
21
+ for (const direction of directions) {
22
+ border[direction] = flatStyle[styleProp];
23
+ }
24
+ }
25
+ }
26
+ for (const [styleProp, directions] of paddingMapping) {
27
+ if (typeof flatStyle[styleProp] === "number") {
28
+ for (const direction of directions) {
29
+ padding[direction] = flatStyle[styleProp];
30
+ }
31
+ }
32
+ }
33
+ const correctionVertical = border[TOP] + padding[TOP] + padding[BOTTOM] + border[BOTTOM];
34
+ const correctionHorizontal = border[LEFT] + padding[LEFT] + padding[RIGHT] + border[RIGHT];
35
+ const correctionMapping = new Map([["width", correctionHorizontal], ["minWidth", correctionHorizontal], ["maxWidth", correctionHorizontal], ["height", correctionVertical], ["minHeight", correctionVertical], ["maxHeight", correctionVertical]]);
36
+ const nextStyle = {};
37
+ for (const styleProp of Object.keys(flatStyle)) {
38
+ const correction = correctionMapping.get(styleProp);
39
+ const styleValue = flatStyle[styleProp];
40
+ if (correction != null) {
41
+ if (styleValue == null) {
42
+ nextStyle[styleProp] = null;
43
+ continue;
44
+ }
45
+ if (styleValue === "auto") {
46
+ nextStyle[styleProp] = styleValue;
47
+ continue;
48
+ }
49
+ if (typeof styleValue !== "number") {
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
+ return flatStyle;
52
+ }
53
+ nextStyle[styleProp] = styleValue + correction;
54
+ } else {
55
+ nextStyle[styleProp] = styleValue;
56
+ }
57
+ }
58
+ return nextStyle;
59
+ }
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ type FlatStyle = { [key: string]: mixed };
11
+ declare export function fixContentBox(flatStyle: FlatStyle): FlatStyle;
@@ -7,6 +7,7 @@
7
7
  *
8
8
  */
9
9
 
10
+ import { type SpreadOptions } from './SpreadOptions';
10
11
  /**
11
12
  * The create method shim should do initial transforms like
12
13
  * renaming/expanding/validating properties, essentially all the steps
@@ -23,21 +24,10 @@ export declare function keyframes(): void;
23
24
  /**
24
25
  * The spread method shim
25
26
  */
26
- /**
27
- * The spread method shim
28
- */
29
- type SpreadOptions = {
30
- customProperties: {};
31
- inheritedFontSize: null | undefined | number;
32
- fontScale: number | void;
33
- passthroughProperties: Array<string>;
34
- viewportHeight: number;
35
- viewportWidth: number;
36
- writingDirection: 'ltr' | 'rtl';
37
- };
27
+
38
28
  export declare function spread(
39
29
  style: null | undefined | { [key: string]: unknown },
40
- $$PARAM_1$$: SpreadOptions,
30
+ options: SpreadOptions,
41
31
  ): { [$$Key$$: string]: {} };
42
32
  export type IStyleX = {
43
33
  create: typeof create;
@@ -12,10 +12,11 @@ var _CSSCustomPropertyValue = require("./CSSCustomPropertyValue");
12
12
  var _CSSLengthUnitValue = require("./CSSLengthUnitValue");
13
13
  var _CSSMediaQuery = require("./CSSMediaQuery");
14
14
  var _errorMsg = require("./errorMsg");
15
+ var _fixContentBox = require("./fixContentBox");
15
16
  var _flattenStyle = require("./flattenStyle");
16
17
  var _parseShadow = require("./parseShadow");
17
18
  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"]);
19
+ 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"]);
19
20
  function isReactNativeStyleProp(propName) {
20
21
  return stylePropertyAllowlistSet.has(propName) || propName.startsWith("--");
21
22
  }
@@ -38,12 +39,13 @@ function isReactNativeStyleValue(propValue) {
38
39
  }
39
40
  function preprocessPropertyValue(propValue) {
40
41
  if (typeof propValue === "string") {
41
- if ((0, _CSSCustomPropertyValue.isCustomPropertyValue)(propValue)) {
42
- return new _CSSCustomPropertyValue.CSSCustomPropertyValue(propValue);
42
+ const customPropValue = (0, _CSSCustomPropertyValue.createCSSCustomPropertyValue)(propValue);
43
+ if (customPropValue != null) {
44
+ return customPropValue;
43
45
  }
44
- const maybeViewportValue = _CSSLengthUnitValue.CSSLengthUnitValue.parse(propValue);
45
- if (maybeViewportValue != null) {
46
- return maybeViewportValue;
46
+ const maybeLengthUnitValue = _CSSLengthUnitValue.CSSLengthUnitValue.parse(propValue);
47
+ if (maybeLengthUnitValue != null) {
48
+ return maybeLengthUnitValue[1] === "px" ? maybeLengthUnitValue[0] : new _CSSLengthUnitValue.CSSLengthUnitValue(...maybeLengthUnitValue);
47
49
  }
48
50
  }
49
51
  return propValue;
@@ -59,12 +61,10 @@ function preprocessCreate(style) {
59
61
  processedStyle[propName] = new _CSSMediaQuery.CSSMediaQuery(propName, processsedSubStyle);
60
62
  continue;
61
63
  }
62
- if (propName === "backgroundImage") {
63
- (0, _errorMsg.errorMsg)("\"backgroundImage\" is not supported in React Native.");
64
- } else if (propName === "boxShadow" && typeof styleValue === "string") {
64
+ if (propName === "boxShadow" && typeof styleValue === "string") {
65
65
  const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
66
66
  if (parsedShadow.length > 1) {
67
- (0, _errorMsg.errorMsg)("Multiple \"boxShadow\" values are not supported in React Native.");
67
+ (0, _errorMsg.warnMsg)("Multiple \"boxShadow\" values are not supported in React Native.");
68
68
  }
69
69
  const {
70
70
  inset,
@@ -74,7 +74,7 @@ function preprocessCreate(style) {
74
74
  color
75
75
  } = parsedShadow[0];
76
76
  if (inset) {
77
- (0, _errorMsg.errorMsg)("\"boxShadow\" value of \"inset\" is not supported in React Native.");
77
+ (0, _errorMsg.warnMsg)("\"boxShadow\" value of \"inset\" is not supported in React Native.");
78
78
  }
79
79
  processedStyle.shadowColor = color;
80
80
  processedStyle.shadowOffset = {
@@ -83,22 +83,10 @@ function preprocessCreate(style) {
83
83
  };
84
84
  processedStyle.shadowOpacity = 1;
85
85
  processedStyle.shadowRadius = blurRadius;
86
- } else if (propName === "fontWeight" && typeof styleValue === "number") {
87
- processedStyle[propName] = styleValue.toString();
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\".");
95
- } else {
96
- processedStyle[propName] = styleValue;
97
- }
98
86
  } else if (propName === "textShadow" && typeof styleValue === "string") {
99
87
  const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
100
88
  if (parsedShadow.length > 1) {
101
- (0, _errorMsg.errorMsg)("Multiple \"textShadow\" values are not supported in React Native.");
89
+ (0, _errorMsg.warnMsg)("Multiple \"textShadow\" values are not supported in React Native.");
102
90
  }
103
91
  const {
104
92
  offsetX,
@@ -112,28 +100,38 @@ function preprocessCreate(style) {
112
100
  width: offsetX
113
101
  };
114
102
  processedStyle.textShadowRadius = blurRadius;
115
- } else if (propName === "marginHorizontal") {
116
- (0, _errorMsg.warnMsg)("\"marginHorizontal\" is deprecated. Use \"marginInline\".");
117
- processedStyle.marginInline = styleValue;
118
- } else if (propName === "marginVertical") {
119
- (0, _errorMsg.warnMsg)("\"marginVertical\" is deprecated. Use \"marginBlock\".");
120
- processedStyle.marginBlock = styleValue;
121
- } else if (propName === "paddingHorizontal") {
122
- (0, _errorMsg.warnMsg)("\"paddingHorizontal\" is deprecated. Use \"paddingInline\".");
123
- processedStyle.paddingInline = styleValue;
124
- } else if (propName === "paddingVertical") {
125
- (0, _errorMsg.warnMsg)("\"paddingVertical\" is deprecated. Use \"paddingBlock\".");
126
- processedStyle.paddingBlock = styleValue;
127
103
  } else {
128
104
  processedStyle[propName] = styleValue;
129
105
  }
130
106
  }
131
107
  for (const prop in processedStyle) {
132
- const processedStyleValue = preprocessPropertyValue(processedStyle[prop]);
108
+ let value = processedStyle[prop];
109
+ if (prop === "lineHeight") {
110
+ if (typeof value === "number" || typeof value === "string" && _CSSLengthUnitValue.CSSLengthUnitValue.parse(value) == null) {
111
+ value = value + "em";
112
+ }
113
+ }
114
+ const processedStyleValue = preprocessPropertyValue(value);
133
115
  processedStyle[prop] = processedStyleValue;
134
116
  }
135
117
  return processedStyle;
136
118
  }
119
+ function finalizeValue(unfinalizedValue, options) {
120
+ let styleValue = unfinalizedValue;
121
+ while (styleValue instanceof _CSSCustomPropertyValue.CSSCustomPropertyValue) {
122
+ const customProperties = options.customProperties || {};
123
+ const resolvedValue = customProperties[styleValue.name] ?? styleValue.defaultValue;
124
+ if (resolvedValue == null) {
125
+ (0, _errorMsg.errorMsg)(`Unrecognized custom property "--${styleValue.name}"`);
126
+ return null;
127
+ }
128
+ styleValue = preprocessPropertyValue(resolvedValue);
129
+ }
130
+ if (styleValue instanceof _CSSLengthUnitValue.CSSLengthUnitValue) {
131
+ styleValue = styleValue.resolvePixelValue(options);
132
+ }
133
+ return styleValue;
134
+ }
137
135
  function create(styles) {
138
136
  const result = {};
139
137
  for (const styleName in styles) {
@@ -149,20 +147,20 @@ function keyframes() {
149
147
  (0, _errorMsg.errorMsg)("keyframes are not supported in React Native.");
150
148
  }
151
149
  const timeValuedProperties = ["animationDelay", "animationDuration", "transitionDelay", "transitionDuration"];
152
- function spread(style, _ref) {
150
+ function spread(style, options) {
153
151
  let {
154
- customProperties = {},
155
- inheritedFontSize,
156
- fontScale = 1,
152
+ lineClamp,
153
+ ...flatStyle
154
+ } = (0, _flattenStyle.flattenStyle)(style);
155
+ let prevStyle = {
156
+ ...flatStyle
157
+ };
158
+ const {
157
159
  passthroughProperties = [],
158
160
  viewportHeight,
159
161
  viewportWidth,
160
162
  writingDirection
161
- } = _ref;
162
- let {
163
- lineClamp,
164
- ...flatStyle
165
- } = (0, _flattenStyle.flattenStyle)(style);
163
+ } = options;
166
164
  const nativeProps = {};
167
165
  for (const styleProp in flatStyle) {
168
166
  let styleValue = flatStyle[styleProp];
@@ -176,26 +174,125 @@ function spread(style, _ref) {
176
174
  continue;
177
175
  }
178
176
  }
179
- if (styleValue instanceof _CSSCustomPropertyValue.CSSCustomPropertyValue) {
180
- const resolvedValue = customProperties[styleValue.name];
181
- if (resolvedValue == null) {
182
- (0, _errorMsg.errorMsg)(`Unrecognized custom property "--${styleValue.name}"`);
183
- delete flatStyle[styleProp];
184
- continue;
185
- }
186
- styleValue = resolvedValue;
187
- }
188
- if (styleValue instanceof _CSSLengthUnitValue.CSSLengthUnitValue) {
189
- const resolvedValue = styleValue.resolvePixelValue(viewportWidth, viewportHeight, fontScale, inheritedFontSize);
190
- styleValue = resolvedValue;
177
+ styleValue = finalizeValue(styleValue, options);
178
+ if (styleValue == null) {
179
+ delete flatStyle[styleProp];
180
+ continue;
191
181
  }
192
182
  if (!isReactNativeStyleProp(styleProp) && passthroughProperties.indexOf(styleProp) === -1) {
193
- (0, _errorMsg.errorMsg)(`Encountered unsupported style property "${styleProp}"`);
183
+ if (styleProp === "blockSize") {
184
+ flatStyle.height = flatStyle.height ?? styleValue;
185
+ } else if (styleProp === "inlineSize") {
186
+ flatStyle.width = flatStyle.width ?? styleValue;
187
+ } else if (styleProp === "maxBlockSize") {
188
+ flatStyle.maxHeight = flatStyle.maxHeight ?? styleValue;
189
+ } else if (styleProp === "minBlockSize") {
190
+ flatStyle.minHeight = flatStyle.minHeight ?? styleValue;
191
+ } else if (styleProp === "maxInlineSize") {
192
+ flatStyle.maxWidth = flatStyle.maxWidth ?? styleValue;
193
+ } else if (styleProp === "minInlineSize") {
194
+ flatStyle.minWidth = flatStyle.minWidth ?? styleValue;
195
+ } else if (styleProp === "borderBlockColor") {
196
+ flatStyle.borderTopColor = flatStyle.borderTopColor ?? styleValue;
197
+ flatStyle.borderBottomColor = flatStyle.borderBottomColor ?? styleValue;
198
+ } else if (styleProp === "borderBlockStyle") {
199
+ flatStyle.borderTopStyle = flatStyle.borderTopStyle ?? styleValue;
200
+ flatStyle.borderBottomStyle = flatStyle.borderBottomStyle ?? styleValue;
201
+ } else if (styleProp === "borderBlockWidth") {
202
+ flatStyle.borderTopWidth = flatStyle.borderTopWidth ?? styleValue;
203
+ flatStyle.borderBottomWidth = flatStyle.borderBottomWidth ?? styleValue;
204
+ } else if (styleProp === "borderBlockEndColor") {
205
+ flatStyle.borderBottomColor = prevStyle.borderBottomColor ?? styleValue;
206
+ } else if (styleProp === "borderBlockEndStyle") {
207
+ flatStyle.borderBottomStyle = prevStyle.borderBottomStyle ?? styleValue;
208
+ } else if (styleProp === "borderBlockEndWidth") {
209
+ flatStyle.borderBottomWidth = prevStyle.borderBottomWidth ?? styleValue;
210
+ } else if (styleProp === "borderBlockStartColor") {
211
+ flatStyle.borderTopColor = prevStyle.borderTopColor ?? styleValue;
212
+ } else if (styleProp === "borderBlockStartStyle") {
213
+ flatStyle.borderTopStyle = prevStyle.borderTopStyle ?? styleValue;
214
+ } else if (styleProp === "borderBlockStartWidth") {
215
+ flatStyle.borderTopWidth = prevStyle.borderTopWidth ?? styleValue;
216
+ } else if (styleProp === "borderInlineColor") {
217
+ flatStyle.borderStartColor = flatStyle.borderStartColor ?? styleValue;
218
+ flatStyle.borderEndColor = flatStyle.borderEndColor ?? styleValue;
219
+ } else if (styleProp === "borderInlineStyle") {
220
+ flatStyle.borderStartStyle = flatStyle.borderStartStyle ?? styleValue;
221
+ flatStyle.borderEndStyle = flatStyle.borderEndStyle ?? styleValue;
222
+ } else if (styleProp === "borderInlineWidth") {
223
+ flatStyle.borderStartWidth = flatStyle.borderStartWidth ?? styleValue;
224
+ flatStyle.borderEndWidth = flatStyle.borderEndWidth ?? styleValue;
225
+ } else if (styleProp === "borderInlineEndColor") {
226
+ flatStyle.borderEndColor = styleValue;
227
+ } else if (styleProp === "borderInlineEndStyle") {
228
+ flatStyle.borderEndStyle = styleValue;
229
+ } else if (styleProp === "borderInlineEndWidth") {
230
+ flatStyle.borderEndWidth = styleValue;
231
+ } else if (styleProp === "borderInlineStartColor") {
232
+ flatStyle.borderStartColor = styleValue;
233
+ } else if (styleProp === "borderInlineStartStyle") {
234
+ flatStyle.borderStartStyle = styleValue;
235
+ } else if (styleProp === "borderInlineStartWidth") {
236
+ flatStyle.borderStartWidth = styleValue;
237
+ } else if (styleProp === "borderStartStartRadius") {
238
+ flatStyle.borderTopStartRadius = styleValue;
239
+ } else if (styleProp === "borderEndStartRadius") {
240
+ flatStyle.borderBottomStartRadius = styleValue;
241
+ } else if (styleProp === "borderStartEndRadius") {
242
+ flatStyle.borderTopEndRadius = styleValue;
243
+ } else if (styleProp === "borderEndEndRadius") {
244
+ flatStyle.borderBottomEndRadius = styleValue;
245
+ } else if (styleProp === "inset") {
246
+ flatStyle.top = flatStyle.top ?? styleValue;
247
+ flatStyle.start = flatStyle.start ?? styleValue;
248
+ flatStyle.end = flatStyle.end ?? styleValue;
249
+ flatStyle.bottom = flatStyle.bottom ?? styleValue;
250
+ } else if (styleProp === "insetBlock") {
251
+ flatStyle.top = flatStyle.top ?? styleValue;
252
+ flatStyle.bottom = flatStyle.bottom ?? styleValue;
253
+ } else if (styleProp === "insetBlockEnd") {
254
+ flatStyle.bottom = prevStyle.bottom ?? styleValue;
255
+ } else if (styleProp === "insetBlockStart") {
256
+ flatStyle.top = prevStyle.top ?? styleValue;
257
+ } else if (styleProp === "insetInline") {
258
+ flatStyle.end = flatStyle.end ?? styleValue;
259
+ flatStyle.start = flatStyle.start ?? styleValue;
260
+ } else if (styleProp === "insetInlineEnd") {
261
+ flatStyle.end = prevStyle.end ?? styleValue;
262
+ } else if (styleProp === "insetInlineStart") {
263
+ flatStyle.start = prevStyle.start ?? styleValue;
264
+ } else if (styleProp === "marginBlock") {
265
+ flatStyle.marginVertical = styleValue;
266
+ } else if (styleProp === "marginBlockStart") {
267
+ flatStyle.marginTop = flatStyle.marginTop ?? styleValue;
268
+ } else if (styleProp === "marginBlockEnd") {
269
+ flatStyle.marginBottom = flatStyle.marginBottom ?? styleValue;
270
+ } else if (styleProp === "marginInline") {
271
+ flatStyle.marginHorizontal = styleValue;
272
+ } else if (styleProp === "marginInlineStart") {
273
+ flatStyle.marginStart = styleValue;
274
+ } else if (styleProp === "marginInlineEnd") {
275
+ flatStyle.marginEnd = styleValue;
276
+ } else if (styleProp === "paddingBlock") {
277
+ flatStyle.paddingVertical = styleValue;
278
+ } else if (styleProp === "paddingBlockStart") {
279
+ flatStyle.paddingTop = flatStyle.paddingTop ?? styleValue;
280
+ } else if (styleProp === "paddingBlockEnd") {
281
+ flatStyle.paddingBottom = flatStyle.paddingBottom ?? styleValue;
282
+ } else if (styleProp === "paddingInline") {
283
+ flatStyle.paddingHorizontal = styleValue;
284
+ } else if (styleProp === "paddingInlineStart") {
285
+ flatStyle.paddingStart = styleValue;
286
+ } else if (styleProp === "paddingInlineEnd") {
287
+ flatStyle.paddingEnd = styleValue;
288
+ } else {
289
+ (0, _errorMsg.warnMsg)(`Ignoring unsupported style property "${styleProp}"`);
290
+ }
194
291
  delete flatStyle[styleProp];
195
292
  continue;
196
293
  }
197
294
  if (!isReactNativeStyleValue(styleValue)) {
198
- (0, _errorMsg.errorMsg)(`Encounted unsupported style value "${String(styleValue)}" for property "${styleProp}"`);
295
+ (0, _errorMsg.warnMsg)(`Ignoring unsupported style value "${String(styleValue)}" for property "${styleProp}"`);
199
296
  delete flatStyle[styleProp];
200
297
  continue;
201
298
  }
@@ -211,21 +308,24 @@ function spread(style, _ref) {
211
308
  flatStyle.borderWidth = 0;
212
309
  delete flatStyle.borderStyle;
213
310
  }
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;
311
+ if (typeof flatStyle.fontWeight === "number") {
312
+ flatStyle.fontWeight = flatStyle.fontWeight.toString();
221
313
  }
222
- if (flatStyle.borderStartEndRadius != null) {
223
- flatStyle.borderTopEndRadius = flatStyle.borderStartEndRadius;
224
- delete flatStyle.borderStartEndRadius;
314
+ const boxSizingValue = flatStyle.boxSizing;
315
+ if (boxSizingValue === "content-box") {
316
+ flatStyle = (0, _fixContentBox.fixContentBox)(flatStyle);
225
317
  }
226
- if (flatStyle.borderEndEndRadius != null) {
227
- flatStyle.borderBottomEndRadius = flatStyle.borderEndEndRadius;
228
- delete flatStyle.borderEndEndRadius;
318
+ delete flatStyle.boxSizing;
319
+ const positionValue = flatStyle.position;
320
+ if (positionValue === "fixed") {
321
+ flatStyle.position = "absolute";
322
+ (0, _errorMsg.warnMsg)("\"position\" value of \"fixed\" is not supported in React Native. Falling back to \"absolute\".");
323
+ } else if (positionValue === "static") {
324
+ flatStyle.position = "relative";
325
+ (0, _errorMsg.warnMsg)("\"position\" value of \"static\" is not supported in React Native. Falling back to \"relative\".");
326
+ } else if (positionValue === "sticky") {
327
+ flatStyle.position = "relative";
328
+ (0, _errorMsg.warnMsg)("\"position\" value of \"sticky\" is not supported in React Native. Falling back to \"relative\".");
229
329
  }
230
330
  for (const timeValuedProperty of timeValuedProperties) {
231
331
  if (typeof flatStyle[timeValuedProperty] === "string") {
@@ -7,6 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import { type SpreadOptions } from './SpreadOptions';
11
+
10
12
  /**
11
13
  * The create method shim should do initial transforms like
12
14
  * renaming/expanding/validating properties, essentially all the steps
@@ -26,19 +28,10 @@ declare export function keyframes(): void;
26
28
  /**
27
29
  * The spread method shim
28
30
  */
29
- type SpreadOptions = {|
30
- customProperties: {},
31
- inheritedFontSize: ?number,
32
- fontScale: number | void,
33
- passthroughProperties: Array<string>,
34
- viewportHeight: number,
35
- viewportWidth: number,
36
- writingDirection: 'ltr' | 'rtl',
37
- |};
38
31
 
39
32
  declare export function spread(
40
33
  style: ?{ [key: string]: mixed },
41
- SpreadOptions,
34
+ options: SpreadOptions,
42
35
  ): { [string]: { ... } };
43
36
 
44
37
  export type IStyleX = {
package/lib/stylex.d.ts CHANGED
@@ -38,6 +38,58 @@ export declare const create: Stylex$Create;
38
38
  export declare const unstable_createVars: StyleX$CreateVars;
39
39
  export declare const unstable_overrideVars: StyleX$OverrideVars;
40
40
  export declare const include: Stylex$Include;
41
+ type ValueWithDefault<T> =
42
+ | T
43
+ | Readonly<{
44
+ readonly default: T;
45
+ readonly [$$Key$$: string]: ValueWithDefault<T>;
46
+ }>;
47
+ type CSSSyntax =
48
+ | '*'
49
+ | '<length>'
50
+ | '<number>'
51
+ | '<percentage>'
52
+ | '<length-percentage>'
53
+ | '<color>'
54
+ | '<image>'
55
+ | '<url>'
56
+ | '<integer>'
57
+ | '<angle>'
58
+ | '<time>'
59
+ | '<resolution>'
60
+ | '<transform-function>'
61
+ | '<custom-ident>'
62
+ | '<transform-list>';
63
+ type CSSSyntaxType = CSSSyntax | ReadonlyArray<CSSSyntax>;
64
+ interface ICSSType<T extends string | number> {
65
+ readonly value: ValueWithDefault<T>;
66
+ readonly syntax: CSSSyntaxType;
67
+ }
68
+ export declare const types: {
69
+ angle: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
70
+ color: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
71
+ url: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
72
+ image: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
73
+ integer: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
74
+ lengthPercentage: <T extends number | string>(
75
+ _v: ValueWithDefault<T>,
76
+ ) => ICSSType<T>;
77
+ length: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
78
+ percentage: <T extends number | string>(
79
+ _v: ValueWithDefault<T>,
80
+ ) => ICSSType<T>;
81
+ number: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
82
+ resolution: <T extends number | string>(
83
+ _v: ValueWithDefault<T>,
84
+ ) => ICSSType<T>;
85
+ time: <T extends number | string>(_v: ValueWithDefault<T>) => ICSSType<T>;
86
+ transformFunction: <T extends number | string>(
87
+ _v: ValueWithDefault<T>,
88
+ ) => ICSSType<T>;
89
+ transformList: <T extends number | string>(
90
+ _v: ValueWithDefault<T>,
91
+ ) => ICSSType<T>;
92
+ };
41
93
  export declare const keyframes: (_keyframes: Keyframes) => string;
42
94
  export declare const firstThatWorks: <T extends string | number>(
43
95
  ..._styles: ReadonlyArray<T>
@@ -65,6 +117,7 @@ type IStyleX = {
65
117
  unstable_createVars: StyleX$CreateVars;
66
118
  unstable_overrideVars: StyleX$OverrideVars;
67
119
  include: Stylex$Include;
120
+ types: typeof types;
68
121
  firstThatWorks: <T extends string | number>(
69
122
  ...v: ReadonlyArray<T>
70
123
  ) => ReadonlyArray<T>;
@@ -76,6 +129,6 @@ type IStyleX = {
76
129
  keyframes: (keyframes: Keyframes) => string;
77
130
  UNSUPPORTED_PROPERTY: <T>(props: T) => T;
78
131
  };
132
+ export declare const stylex: IStyleX;
79
133
  declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
80
134
  export default $$EXPORT_DEFAULT_DECLARATION$$;
81
- export declare const stylex: IStyleX;
package/lib/stylex.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.keyframes = exports.inject = exports.include = exports.firstThatWorks = exports.default = exports.create = exports.UNSUPPORTED_PROPERTY = void 0;
7
7
  exports.spread = spread;
8
- exports.unstable_overrideVars = exports.unstable_createVars = exports.stylex = void 0;
8
+ exports.unstable_overrideVars = exports.unstable_createVars = exports.types = exports.stylex = void 0;
9
9
  var _stylexInject = _interopRequireDefault(require("./stylex-inject"));
10
10
  var _styleq = require("styleq");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -36,6 +36,49 @@ const unstable_overrideVars = stylexOverrideVars;
36
36
  exports.unstable_overrideVars = unstable_overrideVars;
37
37
  const include = stylexIncludes;
38
38
  exports.include = include;
39
+ const types = {
40
+ angle: _v => {
41
+ throw new Error(errorForType("angle"));
42
+ },
43
+ color: _v => {
44
+ throw new Error(errorForType("color"));
45
+ },
46
+ url: _v => {
47
+ throw new Error(errorForType("url"));
48
+ },
49
+ image: _v => {
50
+ throw new Error(errorForType("image"));
51
+ },
52
+ integer: _v => {
53
+ throw new Error(errorForType("integer"));
54
+ },
55
+ lengthPercentage: _v => {
56
+ throw new Error(errorForType("lengthPercentage"));
57
+ },
58
+ length: _v => {
59
+ throw new Error(errorForType("length"));
60
+ },
61
+ percentage: _v => {
62
+ throw new Error(errorForType("percentage"));
63
+ },
64
+ number: _v => {
65
+ throw new Error(errorForType("number"));
66
+ },
67
+ resolution: _v => {
68
+ throw new Error(errorForType("resolution"));
69
+ },
70
+ time: _v => {
71
+ throw new Error(errorForType("time"));
72
+ },
73
+ transformFunction: _v => {
74
+ throw new Error(errorForType("transformFunction"));
75
+ },
76
+ transformList: _v => {
77
+ throw new Error(errorForType("transformList"));
78
+ }
79
+ };
80
+ exports.types = types;
81
+ const errorForType = type => `stylex.types.${type} should be compiled away by @stylexjs/babel-plugin`;
39
82
  const keyframes = _keyframes => {
40
83
  throw new Error("stylex.keyframes should never be called");
41
84
  };
@@ -66,7 +109,8 @@ _stylex.keyframes = keyframes;
66
109
  _stylex.firstThatWorks = firstThatWorks;
67
110
  _stylex.inject = inject;
68
111
  _stylex.UNSUPPORTED_PROPERTY = UNSUPPORTED_PROPERTY;
69
- var _default = _stylex;
70
- exports.default = _default;
112
+ _stylex.types = types;
71
113
  const stylex = _stylex;
72
- exports.stylex = stylex;
114
+ exports.stylex = stylex;
115
+ var _default = _stylex;
116
+ exports.default = _default;