@stylexjs/stylex 0.18.2 → 0.19.0

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.
@@ -8,10 +8,14 @@
8
8
  */
9
9
 
10
10
  import type {
11
+ CSSProperties,
11
12
  CompiledStyles,
12
13
  InlineStyles,
13
14
  Keyframes,
14
15
  MapNamespaces,
16
+ NestedConstsValue,
17
+ NestedStringValue,
18
+ NestedVarsValue,
15
19
  StaticStyles,
16
20
  StaticStylesWithout,
17
21
  StyleX$Create,
@@ -35,6 +39,7 @@ import type {
35
39
  import type { ValueWithDefault } from './types/StyleXUtils';
36
40
  import * as Types from './types/VarTypes';
37
41
  export type {
42
+ CSSProperties,
38
43
  CompiledStyles,
39
44
  InlineStyles,
40
45
  Keyframes,
@@ -59,6 +64,32 @@ export declare const defineConsts: StyleX$DefineConsts;
59
64
  export declare type defineConsts = typeof defineConsts;
60
65
  export declare const defineVars: StyleX$DefineVars;
61
66
  export declare type defineVars = typeof defineVars;
67
+ export declare const unstable_conditional: <
68
+ T extends { readonly default: unknown; readonly [$$Key$$: string]: unknown },
69
+ >(
70
+ _value: T,
71
+ ) => T;
72
+ export declare type unstable_conditional = typeof unstable_conditional;
73
+ export declare const unstable_defineVarsNested: <
74
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
75
+ >(
76
+ _styles: T,
77
+ ) => T;
78
+ export declare type unstable_defineVarsNested =
79
+ typeof unstable_defineVarsNested;
80
+ export declare const unstable_defineConstsNested: <
81
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
82
+ >(
83
+ _styles: T,
84
+ ) => T;
85
+ export declare type unstable_defineConstsNested =
86
+ typeof unstable_defineConstsNested;
87
+ export declare const unstable_createThemeNested: (
88
+ _baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
89
+ _overrides: { readonly [$$Key$$: string]: NestedVarsValue },
90
+ ) => CompiledStyles;
91
+ export declare type unstable_createThemeNested =
92
+ typeof unstable_createThemeNested;
62
93
  export declare const defineMarker: StyleX$DefineMarker;
63
94
  export declare type defineMarker = typeof defineMarker;
64
95
  export declare const firstThatWorks: <T extends string | number>(
@@ -192,6 +223,28 @@ type IStyleX = {
192
223
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
193
224
  types: typeof types;
194
225
  when: typeof when;
226
+ unstable_conditional: <
227
+ T extends {
228
+ readonly default: unknown;
229
+ readonly [$$Key$$: string]: unknown;
230
+ },
231
+ >(
232
+ value: T,
233
+ ) => T;
234
+ unstable_defineVarsNested: <
235
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
236
+ >(
237
+ tokens: T,
238
+ ) => T;
239
+ unstable_defineConstsNested: <
240
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
241
+ >(
242
+ tokens: T,
243
+ ) => T;
244
+ unstable_createThemeNested: (
245
+ baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
246
+ overrides: { readonly [$$Key$$: string]: NestedVarsValue },
247
+ ) => CompiledStyles;
195
248
  __customProperties?: { [$$Key$$: string]: unknown };
196
249
  };
197
250
  export declare const legacyMerge: IStyleX;
package/lib/cjs/stylex.js CHANGED
@@ -146,6 +146,18 @@ const defineConsts = function stylexDefineConsts(_styles) {
146
146
  const defineVars = function stylexDefineVars(_styles) {
147
147
  throw errorForFn('defineVars');
148
148
  };
149
+ const unstable_conditional = function stylexConditional(_value) {
150
+ throw errorForFn('unstable_conditional');
151
+ };
152
+ const unstable_defineVarsNested = function stylexDefineVarsNested(_styles) {
153
+ throw errorForFn('unstable_defineVarsNested');
154
+ };
155
+ const unstable_defineConstsNested = function stylexDefineConstsNested(_styles) {
156
+ throw errorForFn('unstable_defineConstsNested');
157
+ };
158
+ const unstable_createThemeNested = (_baseTokens, _overrides) => {
159
+ throw errorForFn('unstable_createThemeNested');
160
+ };
149
161
  const defineMarker = () => {
150
162
  throw errorForFn('defineMarker');
151
163
  };
@@ -256,26 +268,32 @@ const types = {
256
268
  throw errorForType('transformList');
257
269
  }
258
270
  };
259
- function _legacyMerge(...styles) {
260
- const [className] = styleqExports.styleq(styles);
261
- return className;
262
- }
263
- _legacyMerge.create = create;
264
- _legacyMerge.createTheme = createTheme;
265
- _legacyMerge.defineConsts = defineConsts;
266
- _legacyMerge.defineMarker = defineMarker;
267
- _legacyMerge.defineVars = defineVars;
268
- _legacyMerge.defaultMarker = defaultMarker;
269
- _legacyMerge.firstThatWorks = firstThatWorks;
270
- _legacyMerge.keyframes = keyframes;
271
- _legacyMerge.positionTry = positionTry;
272
- _legacyMerge.props = props;
273
- _legacyMerge.attrs = attrs;
274
- _legacyMerge.types = types;
275
- _legacyMerge.when = when;
276
- _legacyMerge.viewTransitionClass = viewTransitionClass;
277
- _legacyMerge.env = env;
278
- const legacyMerge = _legacyMerge;
271
+ const legacyMerge = /*@__PURE__*/ function () {
272
+ function _legacyMerge(...styles) {
273
+ const [className] = styleqExports.styleq(styles);
274
+ return className;
275
+ }
276
+ _legacyMerge.create = create;
277
+ _legacyMerge.createTheme = createTheme;
278
+ _legacyMerge.defineConsts = defineConsts;
279
+ _legacyMerge.defineMarker = defineMarker;
280
+ _legacyMerge.defineVars = defineVars;
281
+ _legacyMerge.defaultMarker = defaultMarker;
282
+ _legacyMerge.firstThatWorks = firstThatWorks;
283
+ _legacyMerge.keyframes = keyframes;
284
+ _legacyMerge.positionTry = positionTry;
285
+ _legacyMerge.props = props;
286
+ _legacyMerge.attrs = attrs;
287
+ _legacyMerge.types = types;
288
+ _legacyMerge.when = when;
289
+ _legacyMerge.viewTransitionClass = viewTransitionClass;
290
+ _legacyMerge.env = env;
291
+ _legacyMerge.unstable_conditional = unstable_conditional;
292
+ _legacyMerge.unstable_defineVarsNested = unstable_defineVarsNested;
293
+ _legacyMerge.unstable_defineConstsNested = unstable_defineConstsNested;
294
+ _legacyMerge.unstable_createThemeNested = unstable_createThemeNested;
295
+ return _legacyMerge;
296
+ }();
279
297
 
280
298
  exports.attrs = attrs;
281
299
  exports.create = create;
@@ -291,5 +309,9 @@ exports.legacyMerge = legacyMerge;
291
309
  exports.positionTry = positionTry;
292
310
  exports.props = props;
293
311
  exports.types = types;
312
+ exports.unstable_conditional = unstable_conditional;
313
+ exports.unstable_createThemeNested = unstable_createThemeNested;
314
+ exports.unstable_defineConstsNested = unstable_defineConstsNested;
315
+ exports.unstable_defineVarsNested = unstable_defineVarsNested;
294
316
  exports.viewTransitionClass = viewTransitionClass;
295
317
  exports.when = when;
@@ -8,10 +8,14 @@
8
8
  */
9
9
 
10
10
  import type {
11
+ CSSProperties,
11
12
  CompiledStyles,
12
13
  InlineStyles,
13
14
  Keyframes,
14
15
  MapNamespaces,
16
+ NestedConstsValue,
17
+ NestedStringValue,
18
+ NestedVarsValue,
15
19
  StaticStyles,
16
20
  StaticStylesWithout,
17
21
  StyleX$Create,
@@ -36,6 +40,7 @@ import type { ValueWithDefault } from './types/StyleXUtils';
36
40
  import * as Types from './types/VarTypes';
37
41
 
38
42
  export type {
43
+ CSSProperties,
39
44
  CompiledStyles,
40
45
  InlineStyles,
41
46
  Keyframes,
@@ -61,9 +66,32 @@ declare export const defineConsts: StyleX$DefineConsts;
61
66
 
62
67
  declare export const defineVars: StyleX$DefineVars;
63
68
 
69
+ declare export const unstable_conditional: <
70
+ const T extends { readonly default: unknown, readonly [string]: unknown },
71
+ >(
72
+ _value: T,
73
+ ) => T;
74
+
75
+ declare export const unstable_defineVarsNested: <
76
+ const T extends { readonly [string]: NestedVarsValue },
77
+ >(
78
+ _styles: T,
79
+ ) => T;
80
+
81
+ declare export const unstable_defineConstsNested: <
82
+ const T extends { readonly [string]: NestedConstsValue },
83
+ >(
84
+ _styles: T,
85
+ ) => T;
86
+
87
+ declare export const unstable_createThemeNested: (
88
+ _baseTokens: { readonly [string]: NestedStringValue },
89
+ _overrides: { readonly [string]: NestedVarsValue },
90
+ ) => CompiledStyles;
91
+
64
92
  declare export const defineMarker: StyleX$DefineMarker;
65
93
 
66
- declare export const firstThatWorks: <T: string | number>(
94
+ declare export const firstThatWorks: <T extends string | number>(
67
95
  ..._styles: ReadonlyArray<T>
68
96
  ) => ReadonlyArray<T>;
69
97
 
@@ -112,31 +140,35 @@ declare export const when: StyleX$When;
112
140
  declare export const env: StyleX$Env;
113
141
 
114
142
  declare export const types: {
115
- angle: <T: string | 0 = string | 0>(
143
+ angle: <T extends string | 0 = string | 0>(
116
144
  _v: ValueWithDefault<T>,
117
145
  ) => Types.Angle<T>,
118
- color: <T: string = string>(_v: ValueWithDefault<T>) => Types.Color<T>,
119
- url: <T: string = string>(_v: ValueWithDefault<T>) => Types.Url<T>,
120
- image: <T: string = string>(_v: ValueWithDefault<T>) => Types.Image<T>,
121
- integer: <T: number = number>(_v: ValueWithDefault<T>) => Types.Integer<T>,
122
- lengthPercentage: <T: number | string = number | string>(
146
+ color: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Color<T>,
147
+ url: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Url<T>,
148
+ image: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Image<T>,
149
+ integer: <T extends number = number>(
150
+ _v: ValueWithDefault<T>,
151
+ ) => Types.Integer<T>,
152
+ lengthPercentage: <T extends number | string = number | string>(
123
153
  _v: ValueWithDefault<T>,
124
154
  ) => Types.LengthPercentage<T>,
125
- length: <T: number | string = number | string>(
155
+ length: <T extends number | string = number | string>(
126
156
  _v: ValueWithDefault<T>,
127
157
  ) => Types.Length<T>,
128
- percentage: <T: number | string = number | string>(
158
+ percentage: <T extends number | string = number | string>(
129
159
  _v: ValueWithDefault<T>,
130
160
  ) => Types.Percentage<T>,
131
- number: <T: number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
132
- resolution: <T: string = string>(
161
+ number: <T extends number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
162
+ resolution: <T extends string = string>(
133
163
  _v: ValueWithDefault<T>,
134
164
  ) => Types.Resolution<T>,
135
- time: <T: string | 0 = string | 0>(_v: ValueWithDefault<T>) => Types.Time<T>,
136
- transformFunction: <T: string = string>(
165
+ time: <T extends string | 0 = string | 0>(
166
+ _v: ValueWithDefault<T>,
167
+ ) => Types.Time<T>,
168
+ transformFunction: <T extends string = string>(
137
169
  _v: ValueWithDefault<T>,
138
170
  ) => Types.TransformFunction<T>,
139
- transformList: <T: string = string>(
171
+ transformList: <T extends string = string>(
140
172
  _v: ValueWithDefault<T>,
141
173
  ) => Types.TransformList<T>,
142
174
  };
@@ -158,7 +190,7 @@ type IStyleX = {
158
190
  }>,
159
191
  >,
160
192
  defineMarker: StyleX$DefineMarker,
161
- firstThatWorks: <T: string | number>(
193
+ firstThatWorks: <T extends string | number>(
162
194
  ...v: ReadonlyArray<T>
163
195
  ) => ReadonlyArray<T>,
164
196
  keyframes: (keyframes: Keyframes) => string,
@@ -190,6 +222,25 @@ type IStyleX = {
190
222
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
191
223
  types: typeof types,
192
224
  when: typeof when,
225
+ unstable_conditional: <
226
+ const T extends { readonly default: unknown, readonly [string]: unknown },
227
+ >(
228
+ value: T,
229
+ ) => T,
230
+ unstable_defineVarsNested: <
231
+ const T extends { readonly [string]: NestedVarsValue },
232
+ >(
233
+ tokens: T,
234
+ ) => T,
235
+ unstable_defineConstsNested: <
236
+ const T extends { readonly [string]: NestedConstsValue },
237
+ >(
238
+ tokens: T,
239
+ ) => T,
240
+ unstable_createThemeNested: (
241
+ baseTokens: { readonly [string]: NestedStringValue },
242
+ overrides: { readonly [string]: NestedVarsValue },
243
+ ) => CompiledStyles,
193
244
  __customProperties?: { [string]: unknown },
194
245
  ...
195
246
  };
@@ -1461,7 +1461,7 @@ export type CSSProperties = Readonly<{
1461
1461
  textTransform?: all | textTransform;
1462
1462
  textUnderlineOffset?: all | number | string;
1463
1463
  textUnderlinePosition?: all | textUnderlinePosition;
1464
- textWrap?: all | 'wrap' | 'nowrap' | 'balance';
1464
+ textWrap?: all | 'wrap' | 'nowrap' | 'balance' | 'pretty' | 'stable';
1465
1465
  timelineScope?: all | string;
1466
1466
  top?: all | top;
1467
1467
  touchAction?: all | touchAction;
@@ -1548,7 +1548,7 @@ export type CSSProperties = Readonly<{
1548
1548
  textTransform?: all | textTransform,
1549
1549
  textUnderlineOffset?: all | number | string,
1550
1550
  textUnderlinePosition?: all | textUnderlinePosition,
1551
- textWrap?: all | 'wrap' | 'nowrap' | 'balance',
1551
+ textWrap?: all | 'wrap' | 'nowrap' | 'balance' | 'pretty' | 'stable',
1552
1552
 
1553
1553
  timelineScope?: all | string,
1554
1554
  top?: all | top,
@@ -11,6 +11,6 @@
11
11
  // value: T;
12
12
  // }
13
13
  // This is the type for the variables object
14
- declare export opaque type StyleXVar<+_Val: unknown>: string;
14
+ declare export opaque type StyleXVar<out _Val extends unknown>: string;
15
15
 
16
- declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
16
+ declare export opaque type StyleXClassNameFor<out _K, out _V>: string;
@@ -8,6 +8,8 @@
8
8
  import type { CSSType } from './VarTypes';
9
9
  import type { CSSProperties } from './StyleXCSSTypes';
10
10
 
11
+ export type { CSSProperties } from './StyleXCSSTypes';
12
+
11
13
  // Using an opaque type to declare ClassNames generated by stylex.
12
14
  declare const StyleXClassNameTag: unique symbol;
13
15
  export type StyleXClassNameFor<K, V> = string & {
@@ -252,12 +254,17 @@ export type IDFromVarGroup<T extends VarGroup<{}>> = T['__opaqueId'];
252
254
 
253
255
  type TTokens = Readonly<{
254
256
  [key: string]:
255
- | NestedVarObject<null | string | number>
256
- | StyleXVar<null | string | number>
257
+ | NestedVarObject<
258
+ null | string | number | StyleXVar<null | string | number>
259
+ >
257
260
  | CSSType<null | string | number>;
258
261
  }>;
259
262
 
260
- type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
263
+ type UnwrapVars<T> = T extends () => infer U
264
+ ? UnwrapVars<U>
265
+ : T extends StyleXVar<infer U>
266
+ ? U
267
+ : T;
261
268
  export type FlattenTokens<T extends TTokens> = Readonly<{
262
269
  [Key in keyof T]: T[Key] extends { [key: string]: infer X }
263
270
  ? UnwrapVars<X>
@@ -266,6 +273,7 @@ export type FlattenTokens<T extends TTokens> = Readonly<{
266
273
 
267
274
  type NestedVarObject<T> =
268
275
  | T
276
+ | (() => T)
269
277
  | Readonly<{
270
278
  default: NestedVarObject<T>;
271
279
  [key: AtRuleStr]: NestedVarObject<T>;
@@ -306,10 +314,8 @@ export type StyleX$CreateTheme = <
306
314
  overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
307
315
  ) => Theme<TVars, ThemeID>;
308
316
 
309
- declare const StyleXMarkerTag: unique symbol;
310
-
311
317
  export type StyleX$DefineMarker = () => MapNamespace<{
312
- readonly marker: typeof StyleXMarkerTag;
318
+ readonly marker: symbol;
313
319
  }>;
314
320
 
315
321
  export type StyleX$When = {
@@ -360,3 +366,50 @@ export interface Register {}
360
366
  export type StyleX$Env = Register extends { env: infer TEnv }
361
367
  ? TEnv
362
368
  : Readonly<{ [key: string]: unknown }>;
369
+
370
+ // === Nested API Types ===
371
+
372
+ export type NestedVarsValue =
373
+ | string
374
+ | CSSType<string | number>
375
+ | { readonly [key: string]: NestedVarsValue };
376
+
377
+ export type NestedConstsValue =
378
+ | string
379
+ | number
380
+ | { readonly [key: string]: NestedConstsValue };
381
+
382
+ export type NestedStringValue =
383
+ | string
384
+ | { readonly [key: string]: NestedStringValue };
385
+
386
+ // unstable_defineVarsNested: preserves nested key structure in output.
387
+ // Uses generic <T> to give consumers key-level autocomplete.
388
+ // Leaf values are replaced with var(--hash) strings at compile time.
389
+ export type StyleX$DefineVarsNested = <
390
+ const T extends { [key: string]: NestedVarsValue },
391
+ >(
392
+ tokens: T,
393
+ ) => T;
394
+
395
+ // unstable_defineConstsNested: same as input — values inlined at compile time.
396
+ export type StyleX$DefineConstsNested = <
397
+ const T extends { [key: string]: NestedConstsValue },
398
+ >(
399
+ tokens: T,
400
+ ) => T;
401
+
402
+ // unstable_createThemeNested: returns a flat theme object like createTheme.
403
+ export type StyleX$CreateThemeNested = (
404
+ baseTokens: { readonly [key: string]: NestedStringValue },
405
+ overrides: { readonly [key: string]: NestedVarsValue },
406
+ ) => CompiledStyles;
407
+
408
+ // unstable_conditional: identity function for type disambiguation.
409
+ // Marks a conditional @media/@supports value so the type system can
410
+ // distinguish it from namespace objects in nested token definitions.
411
+ export type StyleX$Conditional = <
412
+ const T extends { default: unknown; [key: `@${string}`]: unknown },
413
+ >(
414
+ value: T,
415
+ ) => T;