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

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.
@@ -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
  }
@@ -41,9 +42,9 @@ function preprocessPropertyValue(propValue) {
41
42
  if ((0, _CSSCustomPropertyValue.isCustomPropertyValue)(propValue)) {
42
43
  return new _CSSCustomPropertyValue.CSSCustomPropertyValue(propValue);
43
44
  }
44
- const maybeViewportValue = _CSSLengthUnitValue.CSSLengthUnitValue.parse(propValue);
45
- if (maybeViewportValue != null) {
46
- return maybeViewportValue;
45
+ const maybeLengthUnitValue = _CSSLengthUnitValue.CSSLengthUnitValue.parse(propValue);
46
+ if (maybeLengthUnitValue != null) {
47
+ return new _CSSLengthUnitValue.CSSLengthUnitValue(...maybeLengthUnitValue);
47
48
  }
48
49
  }
49
50
  return propValue;
@@ -59,12 +60,10 @@ function preprocessCreate(style) {
59
60
  processedStyle[propName] = new _CSSMediaQuery.CSSMediaQuery(propName, processsedSubStyle);
60
61
  continue;
61
62
  }
62
- if (propName === "backgroundImage") {
63
- (0, _errorMsg.errorMsg)("\"backgroundImage\" is not supported in React Native.");
64
- } else if (propName === "boxShadow" && typeof styleValue === "string") {
63
+ if (propName === "boxShadow" && typeof styleValue === "string") {
65
64
  const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
66
65
  if (parsedShadow.length > 1) {
67
- (0, _errorMsg.errorMsg)("Multiple \"boxShadow\" values are not supported in React Native.");
66
+ (0, _errorMsg.warnMsg)("Multiple \"boxShadow\" values are not supported in React Native.");
68
67
  }
69
68
  const {
70
69
  inset,
@@ -74,7 +73,7 @@ function preprocessCreate(style) {
74
73
  color
75
74
  } = parsedShadow[0];
76
75
  if (inset) {
77
- (0, _errorMsg.errorMsg)("\"boxShadow\" value of \"inset\" is not supported in React Native.");
76
+ (0, _errorMsg.warnMsg)("\"boxShadow\" value of \"inset\" is not supported in React Native.");
78
77
  }
79
78
  processedStyle.shadowColor = color;
80
79
  processedStyle.shadowOffset = {
@@ -83,22 +82,10 @@ function preprocessCreate(style) {
83
82
  };
84
83
  processedStyle.shadowOpacity = 1;
85
84
  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
85
  } else if (propName === "textShadow" && typeof styleValue === "string") {
99
86
  const parsedShadow = (0, _parseShadow.parseShadow)(styleValue);
100
87
  if (parsedShadow.length > 1) {
101
- (0, _errorMsg.errorMsg)("Multiple \"textShadow\" values are not supported in React Native.");
88
+ (0, _errorMsg.warnMsg)("Multiple \"textShadow\" values are not supported in React Native.");
102
89
  }
103
90
  const {
104
91
  offsetX,
@@ -112,24 +99,18 @@ function preprocessCreate(style) {
112
99
  width: offsetX
113
100
  };
114
101
  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
102
  } else {
128
103
  processedStyle[propName] = styleValue;
129
104
  }
130
105
  }
131
106
  for (const prop in processedStyle) {
132
- const processedStyleValue = preprocessPropertyValue(processedStyle[prop]);
107
+ let value = processedStyle[prop];
108
+ if (prop === "lineHeight") {
109
+ if (typeof value === "number" || typeof value === "string" && _CSSLengthUnitValue.CSSLengthUnitValue.parse(value) == null) {
110
+ value = value + "em";
111
+ }
112
+ }
113
+ const processedStyleValue = preprocessPropertyValue(value);
133
114
  processedStyle[prop] = processedStyleValue;
134
115
  }
135
116
  return processedStyle;
@@ -163,6 +144,9 @@ function spread(style, _ref) {
163
144
  lineClamp,
164
145
  ...flatStyle
165
146
  } = (0, _flattenStyle.flattenStyle)(style);
147
+ let prevStyle = {
148
+ ...flatStyle
149
+ };
166
150
  const nativeProps = {};
167
151
  for (const styleProp in flatStyle) {
168
152
  let styleValue = flatStyle[styleProp];
@@ -190,12 +174,119 @@ function spread(style, _ref) {
190
174
  styleValue = resolvedValue;
191
175
  }
192
176
  if (!isReactNativeStyleProp(styleProp) && passthroughProperties.indexOf(styleProp) === -1) {
193
- (0, _errorMsg.errorMsg)(`Encountered unsupported style property "${styleProp}"`);
177
+ if (styleProp === "blockSize") {
178
+ flatStyle.height = flatStyle.height ?? styleValue;
179
+ } else if (styleProp === "inlineSize") {
180
+ flatStyle.width = flatStyle.width ?? styleValue;
181
+ } else if (styleProp === "maxBlockSize") {
182
+ flatStyle.maxHeight = flatStyle.maxHeight ?? styleValue;
183
+ } else if (styleProp === "minBlockSize") {
184
+ flatStyle.minHeight = flatStyle.minHeight ?? styleValue;
185
+ } else if (styleProp === "maxInlineSize") {
186
+ flatStyle.maxWidth = flatStyle.maxWidth ?? styleValue;
187
+ } else if (styleProp === "minInlineSize") {
188
+ flatStyle.minWidth = flatStyle.minWidth ?? styleValue;
189
+ } else if (styleProp === "borderBlockColor") {
190
+ flatStyle.borderTopColor = flatStyle.borderTopColor ?? styleValue;
191
+ flatStyle.borderBottomColor = flatStyle.borderBottomColor ?? styleValue;
192
+ } else if (styleProp === "borderBlockStyle") {
193
+ flatStyle.borderTopStyle = flatStyle.borderTopStyle ?? styleValue;
194
+ flatStyle.borderBottomStyle = flatStyle.borderBottomStyle ?? styleValue;
195
+ } else if (styleProp === "borderBlockWidth") {
196
+ flatStyle.borderTopWidth = flatStyle.borderTopWidth ?? styleValue;
197
+ flatStyle.borderBottomWidth = flatStyle.borderBottomWidth ?? styleValue;
198
+ } else if (styleProp === "borderBlockEndColor") {
199
+ flatStyle.borderBottomColor = prevStyle.borderBottomColor ?? styleValue;
200
+ } else if (styleProp === "borderBlockEndStyle") {
201
+ flatStyle.borderBottomStyle = prevStyle.borderBottomStyle ?? styleValue;
202
+ } else if (styleProp === "borderBlockEndWidth") {
203
+ flatStyle.borderBottomWidth = prevStyle.borderBottomWidth ?? styleValue;
204
+ } else if (styleProp === "borderBlockStartColor") {
205
+ flatStyle.borderTopColor = prevStyle.borderTopColor ?? styleValue;
206
+ } else if (styleProp === "borderBlockStartStyle") {
207
+ flatStyle.borderTopStyle = prevStyle.borderTopStyle ?? styleValue;
208
+ } else if (styleProp === "borderBlockStartWidth") {
209
+ flatStyle.borderTopWidth = prevStyle.borderTopWidth ?? styleValue;
210
+ } else if (styleProp === "borderInlineColor") {
211
+ flatStyle.borderStartColor = flatStyle.borderStartColor ?? styleValue;
212
+ flatStyle.borderEndColor = flatStyle.borderEndColor ?? styleValue;
213
+ } else if (styleProp === "borderInlineStyle") {
214
+ flatStyle.borderStartStyle = flatStyle.borderStartStyle ?? styleValue;
215
+ flatStyle.borderEndStyle = flatStyle.borderEndStyle ?? styleValue;
216
+ } else if (styleProp === "borderInlineWidth") {
217
+ flatStyle.borderStartWidth = flatStyle.borderStartWidth ?? styleValue;
218
+ flatStyle.borderEndWidth = flatStyle.borderEndWidth ?? styleValue;
219
+ } else if (styleProp === "borderInlineEndColor") {
220
+ flatStyle.borderEndColor = styleValue;
221
+ } else if (styleProp === "borderInlineEndStyle") {
222
+ flatStyle.borderEndStyle = styleValue;
223
+ } else if (styleProp === "borderInlineEndWidth") {
224
+ flatStyle.borderEndWidth = styleValue;
225
+ } else if (styleProp === "borderInlineStartColor") {
226
+ flatStyle.borderStartColor = styleValue;
227
+ } else if (styleProp === "borderInlineStartStyle") {
228
+ flatStyle.borderStartStyle = styleValue;
229
+ } else if (styleProp === "borderInlineStartWidth") {
230
+ flatStyle.borderStartWidth = styleValue;
231
+ } else if (styleProp === "borderStartStartRadius") {
232
+ flatStyle.borderTopStartRadius = styleValue;
233
+ } else if (styleProp === "borderEndStartRadius") {
234
+ flatStyle.borderBottomStartRadius = styleValue;
235
+ } else if (styleProp === "borderStartEndRadius") {
236
+ flatStyle.borderTopEndRadius = styleValue;
237
+ } else if (styleProp === "borderEndEndRadius") {
238
+ flatStyle.borderBottomEndRadius = styleValue;
239
+ } else if (styleProp === "inset") {
240
+ flatStyle.top = flatStyle.top ?? styleValue;
241
+ flatStyle.start = flatStyle.start ?? styleValue;
242
+ flatStyle.end = flatStyle.end ?? styleValue;
243
+ flatStyle.bottom = flatStyle.bottom ?? styleValue;
244
+ } else if (styleProp === "insetBlock") {
245
+ flatStyle.top = flatStyle.top ?? styleValue;
246
+ flatStyle.bottom = flatStyle.bottom ?? styleValue;
247
+ } else if (styleProp === "insetBlockEnd") {
248
+ flatStyle.bottom = prevStyle.bottom ?? styleValue;
249
+ } else if (styleProp === "insetBlockStart") {
250
+ flatStyle.top = prevStyle.top ?? styleValue;
251
+ } else if (styleProp === "insetInline") {
252
+ flatStyle.end = flatStyle.end ?? styleValue;
253
+ flatStyle.start = flatStyle.start ?? styleValue;
254
+ } else if (styleProp === "insetInlineEnd") {
255
+ flatStyle.end = prevStyle.end ?? styleValue;
256
+ } else if (styleProp === "insetInlineStart") {
257
+ flatStyle.start = prevStyle.start ?? styleValue;
258
+ } else if (styleProp === "marginBlock") {
259
+ flatStyle.marginVertical = styleValue;
260
+ } else if (styleProp === "marginBlockStart") {
261
+ flatStyle.marginTop = flatStyle.marginTop ?? styleValue;
262
+ } else if (styleProp === "marginBlockEnd") {
263
+ flatStyle.marginBottom = flatStyle.marginBottom ?? styleValue;
264
+ } else if (styleProp === "marginInline") {
265
+ flatStyle.marginHorizontal = styleValue;
266
+ } else if (styleProp === "marginInlineStart") {
267
+ flatStyle.marginStart = styleValue;
268
+ } else if (styleProp === "marginInlineEnd") {
269
+ flatStyle.marginEnd = styleValue;
270
+ } else if (styleProp === "paddingBlock") {
271
+ flatStyle.paddingVertical = styleValue;
272
+ } else if (styleProp === "paddingBlockStart") {
273
+ flatStyle.paddingTop = flatStyle.paddingTop ?? styleValue;
274
+ } else if (styleProp === "paddingBlockEnd") {
275
+ flatStyle.paddingBottom = flatStyle.paddingBottom ?? styleValue;
276
+ } else if (styleProp === "paddingInline") {
277
+ flatStyle.paddingHorizontal = styleValue;
278
+ } else if (styleProp === "paddingInlineStart") {
279
+ flatStyle.paddingStart = styleValue;
280
+ } else if (styleProp === "paddingInlineEnd") {
281
+ flatStyle.paddingEnd = styleValue;
282
+ } else {
283
+ (0, _errorMsg.warnMsg)(`Ignoring unsupported style property "${styleProp}"`);
284
+ }
194
285
  delete flatStyle[styleProp];
195
286
  continue;
196
287
  }
197
288
  if (!isReactNativeStyleValue(styleValue)) {
198
- (0, _errorMsg.errorMsg)(`Encounted unsupported style value "${String(styleValue)}" for property "${styleProp}"`);
289
+ (0, _errorMsg.warnMsg)(`Ignoring unsupported style value "${String(styleValue)}" for property "${styleProp}"`);
199
290
  delete flatStyle[styleProp];
200
291
  continue;
201
292
  }
@@ -211,21 +302,24 @@ function spread(style, _ref) {
211
302
  flatStyle.borderWidth = 0;
212
303
  delete flatStyle.borderStyle;
213
304
  }
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;
305
+ if (typeof flatStyle.fontWeight === "number") {
306
+ flatStyle.fontWeight = flatStyle.fontWeight.toString();
221
307
  }
222
- if (flatStyle.borderStartEndRadius != null) {
223
- flatStyle.borderTopEndRadius = flatStyle.borderStartEndRadius;
224
- delete flatStyle.borderStartEndRadius;
308
+ const boxSizingValue = flatStyle.boxSizing;
309
+ if (boxSizingValue === "content-box") {
310
+ flatStyle = (0, _fixContentBox.fixContentBox)(flatStyle);
225
311
  }
226
- if (flatStyle.borderEndEndRadius != null) {
227
- flatStyle.borderBottomEndRadius = flatStyle.borderEndEndRadius;
228
- delete flatStyle.borderEndEndRadius;
312
+ delete flatStyle.boxSizing;
313
+ const positionValue = flatStyle.position;
314
+ if (positionValue === "fixed") {
315
+ flatStyle.position = "absolute";
316
+ (0, _errorMsg.warnMsg)("\"position\" value of \"fixed\" is not supported in React Native. Falling back to \"absolute\".");
317
+ } else if (positionValue === "static") {
318
+ flatStyle.position = "relative";
319
+ (0, _errorMsg.warnMsg)("\"position\" value of \"static\" is not supported in React Native. Falling back to \"relative\".");
320
+ } else if (positionValue === "sticky") {
321
+ flatStyle.position = "relative";
322
+ (0, _errorMsg.warnMsg)("\"position\" value of \"sticky\" is not supported in React Native. Falling back to \"relative\".");
229
323
  }
230
324
  for (const timeValuedProperty of timeValuedProperties) {
231
325
  if (typeof flatStyle[timeValuedProperty] === "string") {
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;
@@ -44,6 +44,56 @@ declare export const unstable_overrideVars: StyleX$OverrideVars;
44
44
 
45
45
  declare export const include: Stylex$Include;
46
46
 
47
+ type ValueWithDefault<+T> =
48
+ | T
49
+ | $ReadOnly<{
50
+ +default: T,
51
+ +[string]: ValueWithDefault<T>,
52
+ }>;
53
+
54
+ type CSSSyntax =
55
+ | '*'
56
+ | '<length>'
57
+ | '<number>'
58
+ | '<percentage>'
59
+ | '<length-percentage>'
60
+ | '<color>'
61
+ | '<image>'
62
+ | '<url>'
63
+ | '<integer>'
64
+ | '<angle>'
65
+ | '<time>'
66
+ | '<resolution>'
67
+ | '<transform-function>'
68
+ | '<custom-ident>'
69
+ | '<transform-list>';
70
+
71
+ type CSSSyntaxType = CSSSyntax | $ReadOnlyArray<CSSSyntax>;
72
+
73
+ interface ICSSType<+T: string | number> {
74
+ +value: ValueWithDefault<T>;
75
+ +syntax: CSSSyntaxType;
76
+ }
77
+
78
+ declare export const types: {
79
+ angle: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
80
+ color: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
81
+ url: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
82
+ image: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
83
+ integer: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
84
+ lengthPercentage: <T: number | string>(
85
+ _v: ValueWithDefault<T>,
86
+ ) => ICSSType<T>,
87
+ length: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
88
+ percentage: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
89
+ number: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
90
+ resolution: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
91
+ time: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
92
+ transformFunction: <T: number | string>(
93
+ _v: ValueWithDefault<T>,
94
+ ) => ICSSType<T>,
95
+ transformList: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
96
+ };
47
97
  declare export const keyframes: (_keyframes: Keyframes) => string;
48
98
 
49
99
  declare export const firstThatWorks: <T: string | number>(
@@ -71,6 +121,7 @@ type IStyleX = {
71
121
  unstable_createVars: StyleX$CreateVars,
72
122
  unstable_overrideVars: StyleX$OverrideVars,
73
123
  include: Stylex$Include,
124
+ types: typeof types,
74
125
  firstThatWorks: <T: string | number>(
75
126
  ...v: $ReadOnlyArray<T>
76
127
  ) => $ReadOnlyArray<T>,
@@ -80,6 +131,5 @@ type IStyleX = {
80
131
  ...
81
132
  };
82
133
 
83
- declare export default IStyleX;
84
-
85
134
  declare export const stylex: IStyleX;
135
+ declare export default IStyleX;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.2.0-beta.19",
3
+ "version": "0.2.0-beta.20",
4
4
  "description": "A library for defining styles for optimized user interfaces.",
5
5
  "main": "lib/stylex.js",
6
6
  "react-native": "lib/native/stylex.js",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "prebuild": "gen-types -i src/ -o lib/",
12
12
  "build": "babel src/ --out-dir lib/ --copy-files",
13
- "build-haste": "HASTE=true babel src/ --out-dir lib/ --copy-files",
13
+ "build-haste": "rewrite-imports -i src/ -o lib/",
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
@@ -20,7 +20,7 @@
20
20
  "utility-types": "^3.10.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@stylexjs/scripts": "0.2.0-beta.19"
23
+ "@stylexjs/scripts": "0.2.0-beta.20"
24
24
  },
25
25
  "jest": {},
26
26
  "files": [