@stylexjs/stylex 0.18.2 → 0.18.3

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,6 +12,9 @@ import type {
12
12
  InlineStyles,
13
13
  Keyframes,
14
14
  MapNamespaces,
15
+ NestedConstsValue,
16
+ NestedStringValue,
17
+ NestedVarsValue,
15
18
  StaticStyles,
16
19
  StaticStylesWithout,
17
20
  StyleX$Create,
@@ -59,6 +62,32 @@ export declare const defineConsts: StyleX$DefineConsts;
59
62
  export declare type defineConsts = typeof defineConsts;
60
63
  export declare const defineVars: StyleX$DefineVars;
61
64
  export declare type defineVars = typeof defineVars;
65
+ export declare const unstable_conditional: <
66
+ T extends { readonly default: unknown; readonly [$$Key$$: string]: unknown },
67
+ >(
68
+ _value: T,
69
+ ) => T;
70
+ export declare type unstable_conditional = typeof unstable_conditional;
71
+ export declare const unstable_defineVarsNested: <
72
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
73
+ >(
74
+ _styles: T,
75
+ ) => T;
76
+ export declare type unstable_defineVarsNested =
77
+ typeof unstable_defineVarsNested;
78
+ export declare const unstable_defineConstsNested: <
79
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
80
+ >(
81
+ _styles: T,
82
+ ) => T;
83
+ export declare type unstable_defineConstsNested =
84
+ typeof unstable_defineConstsNested;
85
+ export declare const unstable_createThemeNested: (
86
+ _baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
87
+ _overrides: { readonly [$$Key$$: string]: NestedVarsValue },
88
+ ) => CompiledStyles;
89
+ export declare type unstable_createThemeNested =
90
+ typeof unstable_createThemeNested;
62
91
  export declare const defineMarker: StyleX$DefineMarker;
63
92
  export declare type defineMarker = typeof defineMarker;
64
93
  export declare const firstThatWorks: <T extends string | number>(
@@ -192,6 +221,28 @@ type IStyleX = {
192
221
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
193
222
  types: typeof types;
194
223
  when: typeof when;
224
+ unstable_conditional: <
225
+ T extends {
226
+ readonly default: unknown;
227
+ readonly [$$Key$$: string]: unknown;
228
+ },
229
+ >(
230
+ value: T,
231
+ ) => T;
232
+ unstable_defineVarsNested: <
233
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
234
+ >(
235
+ tokens: T,
236
+ ) => T;
237
+ unstable_defineConstsNested: <
238
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
239
+ >(
240
+ tokens: T,
241
+ ) => T;
242
+ unstable_createThemeNested: (
243
+ baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
244
+ overrides: { readonly [$$Key$$: string]: NestedVarsValue },
245
+ ) => CompiledStyles;
195
246
  __customProperties?: { [$$Key$$: string]: unknown };
196
247
  };
197
248
  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;
@@ -12,6 +12,9 @@ import type {
12
12
  InlineStyles,
13
13
  Keyframes,
14
14
  MapNamespaces,
15
+ NestedConstsValue,
16
+ NestedStringValue,
17
+ NestedVarsValue,
15
18
  StaticStyles,
16
19
  StaticStylesWithout,
17
20
  StyleX$Create,
@@ -61,9 +64,32 @@ declare export const defineConsts: StyleX$DefineConsts;
61
64
 
62
65
  declare export const defineVars: StyleX$DefineVars;
63
66
 
67
+ declare export const unstable_conditional: <
68
+ const T extends { +default: unknown, +[string]: unknown },
69
+ >(
70
+ _value: T,
71
+ ) => T;
72
+
73
+ declare export const unstable_defineVarsNested: <
74
+ const T extends { +[string]: NestedVarsValue },
75
+ >(
76
+ _styles: T,
77
+ ) => T;
78
+
79
+ declare export const unstable_defineConstsNested: <
80
+ const T extends { +[string]: NestedConstsValue },
81
+ >(
82
+ _styles: T,
83
+ ) => T;
84
+
85
+ declare export const unstable_createThemeNested: (
86
+ _baseTokens: { +[string]: NestedStringValue },
87
+ _overrides: { +[string]: NestedVarsValue },
88
+ ) => CompiledStyles;
89
+
64
90
  declare export const defineMarker: StyleX$DefineMarker;
65
91
 
66
- declare export const firstThatWorks: <T: string | number>(
92
+ declare export const firstThatWorks: <T extends string | number>(
67
93
  ..._styles: ReadonlyArray<T>
68
94
  ) => ReadonlyArray<T>;
69
95
 
@@ -112,31 +138,35 @@ declare export const when: StyleX$When;
112
138
  declare export const env: StyleX$Env;
113
139
 
114
140
  declare export const types: {
115
- angle: <T: string | 0 = string | 0>(
141
+ angle: <T extends string | 0 = string | 0>(
116
142
  _v: ValueWithDefault<T>,
117
143
  ) => 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>(
144
+ color: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Color<T>,
145
+ url: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Url<T>,
146
+ image: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Image<T>,
147
+ integer: <T extends number = number>(
148
+ _v: ValueWithDefault<T>,
149
+ ) => Types.Integer<T>,
150
+ lengthPercentage: <T extends number | string = number | string>(
123
151
  _v: ValueWithDefault<T>,
124
152
  ) => Types.LengthPercentage<T>,
125
- length: <T: number | string = number | string>(
153
+ length: <T extends number | string = number | string>(
126
154
  _v: ValueWithDefault<T>,
127
155
  ) => Types.Length<T>,
128
- percentage: <T: number | string = number | string>(
156
+ percentage: <T extends number | string = number | string>(
129
157
  _v: ValueWithDefault<T>,
130
158
  ) => Types.Percentage<T>,
131
- number: <T: number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
132
- resolution: <T: string = string>(
159
+ number: <T extends number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
160
+ resolution: <T extends string = string>(
133
161
  _v: ValueWithDefault<T>,
134
162
  ) => Types.Resolution<T>,
135
- time: <T: string | 0 = string | 0>(_v: ValueWithDefault<T>) => Types.Time<T>,
136
- transformFunction: <T: string = string>(
163
+ time: <T extends string | 0 = string | 0>(
164
+ _v: ValueWithDefault<T>,
165
+ ) => Types.Time<T>,
166
+ transformFunction: <T extends string = string>(
137
167
  _v: ValueWithDefault<T>,
138
168
  ) => Types.TransformFunction<T>,
139
- transformList: <T: string = string>(
169
+ transformList: <T extends string = string>(
140
170
  _v: ValueWithDefault<T>,
141
171
  ) => Types.TransformList<T>,
142
172
  };
@@ -158,7 +188,7 @@ type IStyleX = {
158
188
  }>,
159
189
  >,
160
190
  defineMarker: StyleX$DefineMarker,
161
- firstThatWorks: <T: string | number>(
191
+ firstThatWorks: <T extends string | number>(
162
192
  ...v: ReadonlyArray<T>
163
193
  ) => ReadonlyArray<T>,
164
194
  keyframes: (keyframes: Keyframes) => string,
@@ -190,6 +220,23 @@ type IStyleX = {
190
220
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
191
221
  types: typeof types,
192
222
  when: typeof when,
223
+ unstable_conditional: <
224
+ const T extends { +default: unknown, +[string]: unknown },
225
+ >(
226
+ value: T,
227
+ ) => T,
228
+ unstable_defineVarsNested: <const T extends { +[string]: NestedVarsValue }>(
229
+ tokens: T,
230
+ ) => T,
231
+ unstable_defineConstsNested: <
232
+ const T extends { +[string]: NestedConstsValue },
233
+ >(
234
+ tokens: T,
235
+ ) => T,
236
+ unstable_createThemeNested: (
237
+ baseTokens: { +[string]: NestedStringValue },
238
+ overrides: { +[string]: NestedVarsValue },
239
+ ) => CompiledStyles,
193
240
  __customProperties?: { [string]: unknown },
194
241
  ...
195
242
  };
@@ -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<+_Val extends unknown>: string;
15
15
 
16
16
  declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
@@ -252,12 +252,17 @@ export type IDFromVarGroup<T extends VarGroup<{}>> = T['__opaqueId'];
252
252
 
253
253
  type TTokens = Readonly<{
254
254
  [key: string]:
255
- | NestedVarObject<null | string | number>
256
- | StyleXVar<null | string | number>
255
+ | NestedVarObject<
256
+ null | string | number | StyleXVar<null | string | number>
257
+ >
257
258
  | CSSType<null | string | number>;
258
259
  }>;
259
260
 
260
- type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
261
+ type UnwrapVars<T> = T extends () => infer U
262
+ ? UnwrapVars<U>
263
+ : T extends StyleXVar<infer U>
264
+ ? U
265
+ : T;
261
266
  export type FlattenTokens<T extends TTokens> = Readonly<{
262
267
  [Key in keyof T]: T[Key] extends { [key: string]: infer X }
263
268
  ? UnwrapVars<X>
@@ -266,6 +271,7 @@ export type FlattenTokens<T extends TTokens> = Readonly<{
266
271
 
267
272
  type NestedVarObject<T> =
268
273
  | T
274
+ | (() => T)
269
275
  | Readonly<{
270
276
  default: NestedVarObject<T>;
271
277
  [key: AtRuleStr]: NestedVarObject<T>;
@@ -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;
@@ -54,8 +54,9 @@ export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<
54
54
  false | ?Readonly<{ ...T, $$css: true }>,
55
55
  >;
56
56
 
57
- export type XStyleWithout<+T: { +[_K in keyof NestedCSSPropTypes]?: unknown }> =
58
- XStyle<Readonly<Omit<NestedCSSPropTypes, keyof T>>>;
57
+ export type XStyleWithout<
58
+ +T extends { +[_K in keyof NestedCSSPropTypes]?: unknown },
59
+ > = XStyle<Readonly<Omit<NestedCSSPropTypes, keyof T>>>;
59
60
 
60
61
  export type Keyframes = Readonly<{ [name: string]: CSSProperties, ... }>;
61
62
 
@@ -131,19 +132,19 @@ type ComplexStyleValueType<+T> =
131
132
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
132
133
  : Readonly<T>;
133
134
 
134
- type _MapNamespace<+CSS: { +[string]: unknown }> = Readonly<{
135
+ type _MapNamespace<+CSS extends { +[string]: unknown }> = Readonly<{
135
136
  [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
136
137
  }>;
137
- export type MapNamespace<+CSS: { +[string]: unknown }> = Readonly<{
138
+ export type MapNamespace<+CSS extends { +[string]: unknown }> = Readonly<{
138
139
  ..._MapNamespace<CSS>,
139
140
  $$css: true,
140
141
  }>;
141
- export type MapNamespaces<+S: { +[string]: unknown }> = Readonly<{
142
+ export type MapNamespaces<+S extends { +[string]: unknown }> = Readonly<{
142
143
  [Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
143
144
  ? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
144
145
  : MapNamespace<S[Key]>,
145
146
  }>;
146
- export type StyleX$Create = <const S: { +[string]: { ... } }>(
147
+ export type StyleX$Create = <const S extends { +[string]: { ... } }>(
147
148
  styles: S,
148
149
  ) => MapNamespaces<S>;
149
150
 
@@ -156,51 +157,53 @@ export type InlineStyles = Readonly<{
156
157
  [key: string]: string,
157
158
  }>;
158
159
 
159
- type _GenStylePropType<+CSS: { +[string]: unknown }> = Readonly<{
160
+ type _GenStylePropType<+CSS extends { +[string]: unknown }> = Readonly<{
160
161
  [Key in keyof CSS]: CSS[Key] extends { +[string]: unknown }
161
162
  ? StyleXClassNameFor<Key, Readonly<CSS[Key]>>
162
163
  : StyleXClassNameFor<Key, CSS[Key]>,
163
164
  }>;
164
- type GenStylePropType<+CSS: { +[string]: unknown }> = Readonly<{
165
+ type GenStylePropType<+CSS extends { +[string]: unknown }> = Readonly<{
165
166
  ..._GenStylePropType<CSS>,
166
167
  $$css: true,
167
168
  }>;
168
169
 
169
170
  // Replace `XStyle` with this.
170
171
  export type StaticStyles<
171
- +CSS: { +[string]: unknown } = CSSPropertiesWithExtras,
172
+ +CSS extends { +[string]: unknown } = CSSPropertiesWithExtras,
172
173
  > = StyleXArray<false | ?GenStylePropType<Readonly<CSS>>>;
173
174
 
174
- export type StaticStylesWithout<+CSS: { +[string]: unknown }> = StaticStyles<
175
- Omit<CSSPropertiesWithExtras, keyof CSS>,
176
- >;
175
+ export type StaticStylesWithout<+CSS extends { +[string]: unknown }> =
176
+ StaticStyles<Omit<CSSPropertiesWithExtras, keyof CSS>>;
177
177
 
178
178
  export type StyleXStyles<
179
- +CSS: { +[string]: unknown } = CSSPropertiesWithExtras,
179
+ +CSS extends { +[string]: unknown } = CSSPropertiesWithExtras,
180
180
  > = StyleXArray<
181
181
  | ?false
182
182
  | GenStylePropType<Readonly<CSS>>
183
183
  | Readonly<[GenStylePropType<Readonly<CSS>>, InlineStyles]>,
184
184
  >;
185
185
 
186
- export type StyleXStylesWithout<+CSS: { +[string]: unknown }> = StyleXStyles<
187
- Omit<CSSPropertiesWithExtras, keyof CSS>,
188
- >;
186
+ export type StyleXStylesWithout<+CSS extends { +[string]: unknown }> =
187
+ StyleXStyles<Omit<CSSPropertiesWithExtras, keyof CSS>>;
189
188
 
190
- export type VarGroup<+Tokens: { +[string]: unknown }, +_ID: string = string> = {
189
+ export type VarGroup<
190
+ +Tokens extends { +[string]: unknown },
191
+ +_ID extends string = string,
192
+ > = {
191
193
  +[Key in keyof Tokens]: StyleXVar<Tokens[Key]>,
192
194
  };
193
195
 
194
- export type TokensFromVarGroup<+T: VarGroup<{ +[string]: unknown }>> =
196
+ export type TokensFromVarGroup<+T extends VarGroup<{ +[string]: unknown }>> =
195
197
  Readonly<{
196
198
  [Key in keyof T]: UnwrapVar<T[Key]>,
197
199
  }>;
198
200
 
199
- type IDFromVarGroup<+T: VarGroup<{ +[string]: unknown }>> =
201
+ type IDFromVarGroup<+T extends VarGroup<{ +[string]: unknown }>> =
200
202
  T extends VarGroup<{ +[string]: unknown }, infer ID> ? ID : empty;
201
203
 
202
204
  type NestedVarObject<+T> =
203
205
  | T
206
+ | (() => T)
204
207
  | Readonly<{
205
208
  default: NestedVarObject<T>,
206
209
  [string]: NestedVarObject<T>,
@@ -208,13 +211,31 @@ type NestedVarObject<+T> =
208
211
 
209
212
  type TTokens = Readonly<{
210
213
  [string]:
211
- | NestedVarObject<null | string | number>
212
- | StyleXVar<null | string | number>
214
+ | NestedVarObject<
215
+ null | string | number | StyleXVar<null | string | number>,
216
+ >
213
217
  | CSSType<null | string | number>,
214
218
  }>;
215
219
 
216
- type UnwrapVar<+T> = T extends StyleXVar<infer U> ? U : T;
217
- export type FlattenTokens<+T: TTokens> = {
220
+ export type NestedVarsValue =
221
+ | string
222
+ | CSSType<string | number>
223
+ | { +[string]: NestedVarsValue };
224
+
225
+ export type NestedConstsValue =
226
+ | string
227
+ | number
228
+ | { +[string]: NestedConstsValue };
229
+
230
+ export type NestedStringValue = string | { +[string]: NestedStringValue };
231
+
232
+ type UnwrapVar<+T> = T extends () => infer U
233
+ ? UnwrapVar<U>
234
+ : T extends StyleXVar<infer U>
235
+ ? U
236
+ : T;
237
+
238
+ export type FlattenTokens<+T extends TTokens> = {
218
239
  +[Key in keyof T]: T[Key] extends CSSType<string | number>
219
240
  ? UnwrapVar<T[Key]>
220
241
  : T[Key] extends { +default: infer X, +[string]: infer Y }
@@ -222,32 +243,35 @@ export type FlattenTokens<+T: TTokens> = {
222
243
  : UnwrapVar<T[Key]>,
223
244
  };
224
245
 
225
- export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
246
+ export type StyleX$DefineVars = <
247
+ DefaultTokens extends TTokens,
248
+ ID extends string = string,
249
+ >(
226
250
  tokens: DefaultTokens,
227
251
  ) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
228
252
 
229
253
  export type StyleX$DefineConsts = <
230
- const DefaultTokens: { +[string]: number | string },
254
+ const DefaultTokens extends { +[string]: number | string },
231
255
  >(
232
256
  tokens: DefaultTokens,
233
257
  ) => DefaultTokens;
234
258
 
235
259
  // opaque type ThemeKey<+_VG: VarGroup<{ +[string]: unknown }>>: string = string;
236
260
  declare export opaque type Theme<
237
- +T: VarGroup<{ +[string]: unknown }, string>,
238
- +_Tag: string = string,
261
+ +T extends VarGroup<{ +[string]: unknown }, string>,
262
+ +_Tag extends string = string,
239
263
  >: Readonly<{
240
264
  $$css: true,
241
265
  theme: StyleXClassNameFor<'theme', IDFromVarGroup<T>>,
242
266
  }>;
243
267
 
244
- export type OverridesForTokenType<+Config: { +[string]: unknown }> = {
268
+ export type OverridesForTokenType<+Config extends { +[string]: unknown }> = {
245
269
  [Key in keyof Config]?: NestedVarObject<Config[Key]>,
246
270
  };
247
271
 
248
272
  export type StyleX$CreateTheme = <
249
- BaseTokens: VarGroup<{ +[string]: unknown }>,
250
- ID: string = string,
273
+ BaseTokens extends VarGroup<{ +[string]: unknown }>,
274
+ ID extends string = string,
251
275
  >(
252
276
  baseTokens: BaseTokens,
253
277
  overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
@@ -280,4 +304,4 @@ export type StyleX$When = {
280
304
  ) => ':where-any-sibling',
281
305
  };
282
306
 
283
- export type StyleX$Env = $ReadOnly<{ [string]: mixed }>;
307
+ export type StyleX$Env = Readonly<{ [string]: unknown }>;
@@ -29,64 +29,70 @@ export type CSSSyntax =
29
29
  type CSSSyntaxType = CSSSyntax;
30
30
  type InnerValue = null | string | number;
31
31
 
32
- interface ICSSType<+_T: InnerValue> {
32
+ interface ICSSType<+_T extends InnerValue> {
33
33
  +value: ValueWithDefault<string>;
34
34
  +syntax: CSSSyntaxType;
35
35
  }
36
- declare export class Angle<+T: InnerValue> implements ICSSType<T> {
36
+ declare export class Angle<+T extends InnerValue> implements ICSSType<T> {
37
37
  +value: ValueWithDefault<string>;
38
38
  +syntax: CSSSyntaxType;
39
39
  }
40
- declare export class Color<+T: InnerValue> implements ICSSType<T> {
40
+ declare export class Color<+T extends InnerValue> implements ICSSType<T> {
41
41
  +value: ValueWithDefault<string>;
42
42
  +syntax: CSSSyntaxType;
43
43
  }
44
- declare export class Url<+T: InnerValue> implements ICSSType<T> {
44
+ declare export class Url<+T extends InnerValue> implements ICSSType<T> {
45
45
  +value: ValueWithDefault<string>;
46
46
  +syntax: CSSSyntaxType;
47
47
  }
48
- declare export class Image<+T: InnerValue> implements ICSSType<T> {
48
+ declare export class Image<+T extends InnerValue> implements ICSSType<T> {
49
49
  +value: ValueWithDefault<string>;
50
50
  +syntax: CSSSyntaxType;
51
51
  }
52
- declare export class Integer<+T: InnerValue> implements ICSSType<T> {
52
+ declare export class Integer<+T extends InnerValue> implements ICSSType<T> {
53
53
  +value: ValueWithDefault<string>;
54
54
  +syntax: CSSSyntaxType;
55
55
  }
56
- declare export class LengthPercentage<+T: InnerValue> implements ICSSType<T> {
56
+ declare export class LengthPercentage<+T extends InnerValue>
57
+ implements ICSSType<T>
58
+ {
57
59
  +value: ValueWithDefault<string>;
58
60
  +syntax: CSSSyntaxType;
59
61
  }
60
- declare export class Length<+T: InnerValue> implements ICSSType<T> {
62
+ declare export class Length<+T extends InnerValue> implements ICSSType<T> {
61
63
  +value: ValueWithDefault<string>;
62
64
  +syntax: CSSSyntaxType;
63
65
  }
64
- declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
66
+ declare export class Percentage<+T extends InnerValue> implements ICSSType<T> {
65
67
  +value: ValueWithDefault<string>;
66
68
  +syntax: CSSSyntaxType;
67
69
  }
68
- declare export class Num<+T: InnerValue> implements ICSSType<T> {
70
+ declare export class Num<+T extends InnerValue> implements ICSSType<T> {
69
71
  +value: ValueWithDefault<string>;
70
72
  +syntax: CSSSyntaxType;
71
73
  }
72
- declare export class Resolution<+T: InnerValue> implements ICSSType<T> {
74
+ declare export class Resolution<+T extends InnerValue> implements ICSSType<T> {
73
75
  +value: ValueWithDefault<string>;
74
76
  +syntax: CSSSyntaxType;
75
77
  }
76
- declare export class Time<+T: InnerValue> implements ICSSType<T> {
78
+ declare export class Time<+T extends InnerValue> implements ICSSType<T> {
77
79
  +value: ValueWithDefault<string>;
78
80
  +syntax: CSSSyntaxType;
79
81
  }
80
- declare export class TransformFunction<+T: InnerValue> implements ICSSType<T> {
82
+ declare export class TransformFunction<+T extends InnerValue>
83
+ implements ICSSType<T>
84
+ {
81
85
  +value: ValueWithDefault<string>;
82
86
  +syntax: CSSSyntaxType;
83
87
  }
84
- declare export class TransformList<+T: InnerValue> implements ICSSType<T> {
88
+ declare export class TransformList<+T extends InnerValue>
89
+ implements ICSSType<T>
90
+ {
85
91
  +value: ValueWithDefault<string>;
86
92
  +syntax: CSSSyntaxType;
87
93
  }
88
94
 
89
- export type CSSType<+T: InnerValue> =
95
+ export type CSSType<+T extends InnerValue> =
90
96
  | Angle<T>
91
97
  | Color<T>
92
98
  | Url<T>
@@ -12,6 +12,9 @@ import type {
12
12
  InlineStyles,
13
13
  Keyframes,
14
14
  MapNamespaces,
15
+ NestedConstsValue,
16
+ NestedStringValue,
17
+ NestedVarsValue,
15
18
  StaticStyles,
16
19
  StaticStylesWithout,
17
20
  StyleX$Create,
@@ -59,6 +62,32 @@ export declare const defineConsts: StyleX$DefineConsts;
59
62
  export declare type defineConsts = typeof defineConsts;
60
63
  export declare const defineVars: StyleX$DefineVars;
61
64
  export declare type defineVars = typeof defineVars;
65
+ export declare const unstable_conditional: <
66
+ T extends { readonly default: unknown; readonly [$$Key$$: string]: unknown },
67
+ >(
68
+ _value: T,
69
+ ) => T;
70
+ export declare type unstable_conditional = typeof unstable_conditional;
71
+ export declare const unstable_defineVarsNested: <
72
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
73
+ >(
74
+ _styles: T,
75
+ ) => T;
76
+ export declare type unstable_defineVarsNested =
77
+ typeof unstable_defineVarsNested;
78
+ export declare const unstable_defineConstsNested: <
79
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
80
+ >(
81
+ _styles: T,
82
+ ) => T;
83
+ export declare type unstable_defineConstsNested =
84
+ typeof unstable_defineConstsNested;
85
+ export declare const unstable_createThemeNested: (
86
+ _baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
87
+ _overrides: { readonly [$$Key$$: string]: NestedVarsValue },
88
+ ) => CompiledStyles;
89
+ export declare type unstable_createThemeNested =
90
+ typeof unstable_createThemeNested;
62
91
  export declare const defineMarker: StyleX$DefineMarker;
63
92
  export declare type defineMarker = typeof defineMarker;
64
93
  export declare const firstThatWorks: <T extends string | number>(
@@ -192,6 +221,28 @@ type IStyleX = {
192
221
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
193
222
  types: typeof types;
194
223
  when: typeof when;
224
+ unstable_conditional: <
225
+ T extends {
226
+ readonly default: unknown;
227
+ readonly [$$Key$$: string]: unknown;
228
+ },
229
+ >(
230
+ value: T,
231
+ ) => T;
232
+ unstable_defineVarsNested: <
233
+ T extends { readonly [$$Key$$: string]: NestedVarsValue },
234
+ >(
235
+ tokens: T,
236
+ ) => T;
237
+ unstable_defineConstsNested: <
238
+ T extends { readonly [$$Key$$: string]: NestedConstsValue },
239
+ >(
240
+ tokens: T,
241
+ ) => T;
242
+ unstable_createThemeNested: (
243
+ baseTokens: { readonly [$$Key$$: string]: NestedStringValue },
244
+ overrides: { readonly [$$Key$$: string]: NestedVarsValue },
245
+ ) => CompiledStyles;
195
246
  __customProperties?: { [$$Key$$: string]: unknown };
196
247
  };
197
248
  export declare const legacyMerge: IStyleX;
@@ -12,6 +12,9 @@ import type {
12
12
  InlineStyles,
13
13
  Keyframes,
14
14
  MapNamespaces,
15
+ NestedConstsValue,
16
+ NestedStringValue,
17
+ NestedVarsValue,
15
18
  StaticStyles,
16
19
  StaticStylesWithout,
17
20
  StyleX$Create,
@@ -61,9 +64,32 @@ declare export const defineConsts: StyleX$DefineConsts;
61
64
 
62
65
  declare export const defineVars: StyleX$DefineVars;
63
66
 
67
+ declare export const unstable_conditional: <
68
+ const T extends { +default: unknown, +[string]: unknown },
69
+ >(
70
+ _value: T,
71
+ ) => T;
72
+
73
+ declare export const unstable_defineVarsNested: <
74
+ const T extends { +[string]: NestedVarsValue },
75
+ >(
76
+ _styles: T,
77
+ ) => T;
78
+
79
+ declare export const unstable_defineConstsNested: <
80
+ const T extends { +[string]: NestedConstsValue },
81
+ >(
82
+ _styles: T,
83
+ ) => T;
84
+
85
+ declare export const unstable_createThemeNested: (
86
+ _baseTokens: { +[string]: NestedStringValue },
87
+ _overrides: { +[string]: NestedVarsValue },
88
+ ) => CompiledStyles;
89
+
64
90
  declare export const defineMarker: StyleX$DefineMarker;
65
91
 
66
- declare export const firstThatWorks: <T: string | number>(
92
+ declare export const firstThatWorks: <T extends string | number>(
67
93
  ..._styles: ReadonlyArray<T>
68
94
  ) => ReadonlyArray<T>;
69
95
 
@@ -112,31 +138,35 @@ declare export const when: StyleX$When;
112
138
  declare export const env: StyleX$Env;
113
139
 
114
140
  declare export const types: {
115
- angle: <T: string | 0 = string | 0>(
141
+ angle: <T extends string | 0 = string | 0>(
116
142
  _v: ValueWithDefault<T>,
117
143
  ) => 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>(
144
+ color: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Color<T>,
145
+ url: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Url<T>,
146
+ image: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Image<T>,
147
+ integer: <T extends number = number>(
148
+ _v: ValueWithDefault<T>,
149
+ ) => Types.Integer<T>,
150
+ lengthPercentage: <T extends number | string = number | string>(
123
151
  _v: ValueWithDefault<T>,
124
152
  ) => Types.LengthPercentage<T>,
125
- length: <T: number | string = number | string>(
153
+ length: <T extends number | string = number | string>(
126
154
  _v: ValueWithDefault<T>,
127
155
  ) => Types.Length<T>,
128
- percentage: <T: number | string = number | string>(
156
+ percentage: <T extends number | string = number | string>(
129
157
  _v: ValueWithDefault<T>,
130
158
  ) => Types.Percentage<T>,
131
- number: <T: number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
132
- resolution: <T: string = string>(
159
+ number: <T extends number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
160
+ resolution: <T extends string = string>(
133
161
  _v: ValueWithDefault<T>,
134
162
  ) => Types.Resolution<T>,
135
- time: <T: string | 0 = string | 0>(_v: ValueWithDefault<T>) => Types.Time<T>,
136
- transformFunction: <T: string = string>(
163
+ time: <T extends string | 0 = string | 0>(
164
+ _v: ValueWithDefault<T>,
165
+ ) => Types.Time<T>,
166
+ transformFunction: <T extends string = string>(
137
167
  _v: ValueWithDefault<T>,
138
168
  ) => Types.TransformFunction<T>,
139
- transformList: <T: string = string>(
169
+ transformList: <T extends string = string>(
140
170
  _v: ValueWithDefault<T>,
141
171
  ) => Types.TransformList<T>,
142
172
  };
@@ -158,7 +188,7 @@ type IStyleX = {
158
188
  }>,
159
189
  >,
160
190
  defineMarker: StyleX$DefineMarker,
161
- firstThatWorks: <T: string | number>(
191
+ firstThatWorks: <T extends string | number>(
162
192
  ...v: ReadonlyArray<T>
163
193
  ) => ReadonlyArray<T>,
164
194
  keyframes: (keyframes: Keyframes) => string,
@@ -190,6 +220,23 @@ type IStyleX = {
190
220
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
191
221
  types: typeof types,
192
222
  when: typeof when,
223
+ unstable_conditional: <
224
+ const T extends { +default: unknown, +[string]: unknown },
225
+ >(
226
+ value: T,
227
+ ) => T,
228
+ unstable_defineVarsNested: <const T extends { +[string]: NestedVarsValue }>(
229
+ tokens: T,
230
+ ) => T,
231
+ unstable_defineConstsNested: <
232
+ const T extends { +[string]: NestedConstsValue },
233
+ >(
234
+ tokens: T,
235
+ ) => T,
236
+ unstable_createThemeNested: (
237
+ baseTokens: { +[string]: NestedStringValue },
238
+ overrides: { +[string]: NestedVarsValue },
239
+ ) => CompiledStyles,
193
240
  __customProperties?: { [string]: unknown },
194
241
  ...
195
242
  };
package/lib/es/stylex.mjs CHANGED
@@ -144,6 +144,18 @@ const defineConsts = function stylexDefineConsts(_styles) {
144
144
  const defineVars = function stylexDefineVars(_styles) {
145
145
  throw errorForFn('defineVars');
146
146
  };
147
+ const unstable_conditional = function stylexConditional(_value) {
148
+ throw errorForFn('unstable_conditional');
149
+ };
150
+ const unstable_defineVarsNested = function stylexDefineVarsNested(_styles) {
151
+ throw errorForFn('unstable_defineVarsNested');
152
+ };
153
+ const unstable_defineConstsNested = function stylexDefineConstsNested(_styles) {
154
+ throw errorForFn('unstable_defineConstsNested');
155
+ };
156
+ const unstable_createThemeNested = (_baseTokens, _overrides) => {
157
+ throw errorForFn('unstable_createThemeNested');
158
+ };
147
159
  const defineMarker = () => {
148
160
  throw errorForFn('defineMarker');
149
161
  };
@@ -254,25 +266,31 @@ const types = {
254
266
  throw errorForType('transformList');
255
267
  }
256
268
  };
257
- function _legacyMerge(...styles) {
258
- const [className] = styleqExports.styleq(styles);
259
- return className;
260
- }
261
- _legacyMerge.create = create;
262
- _legacyMerge.createTheme = createTheme;
263
- _legacyMerge.defineConsts = defineConsts;
264
- _legacyMerge.defineMarker = defineMarker;
265
- _legacyMerge.defineVars = defineVars;
266
- _legacyMerge.defaultMarker = defaultMarker;
267
- _legacyMerge.firstThatWorks = firstThatWorks;
268
- _legacyMerge.keyframes = keyframes;
269
- _legacyMerge.positionTry = positionTry;
270
- _legacyMerge.props = props;
271
- _legacyMerge.attrs = attrs;
272
- _legacyMerge.types = types;
273
- _legacyMerge.when = when;
274
- _legacyMerge.viewTransitionClass = viewTransitionClass;
275
- _legacyMerge.env = env;
276
- const legacyMerge = _legacyMerge;
269
+ const legacyMerge = /*@__PURE__*/ function () {
270
+ function _legacyMerge(...styles) {
271
+ const [className] = styleqExports.styleq(styles);
272
+ return className;
273
+ }
274
+ _legacyMerge.create = create;
275
+ _legacyMerge.createTheme = createTheme;
276
+ _legacyMerge.defineConsts = defineConsts;
277
+ _legacyMerge.defineMarker = defineMarker;
278
+ _legacyMerge.defineVars = defineVars;
279
+ _legacyMerge.defaultMarker = defaultMarker;
280
+ _legacyMerge.firstThatWorks = firstThatWorks;
281
+ _legacyMerge.keyframes = keyframes;
282
+ _legacyMerge.positionTry = positionTry;
283
+ _legacyMerge.props = props;
284
+ _legacyMerge.attrs = attrs;
285
+ _legacyMerge.types = types;
286
+ _legacyMerge.when = when;
287
+ _legacyMerge.viewTransitionClass = viewTransitionClass;
288
+ _legacyMerge.env = env;
289
+ _legacyMerge.unstable_conditional = unstable_conditional;
290
+ _legacyMerge.unstable_defineVarsNested = unstable_defineVarsNested;
291
+ _legacyMerge.unstable_defineConstsNested = unstable_defineConstsNested;
292
+ _legacyMerge.unstable_createThemeNested = unstable_createThemeNested;
293
+ return _legacyMerge;
294
+ }();
277
295
 
278
- export { attrs, create, createTheme, defaultMarker, defineConsts, defineMarker, defineVars, env, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, viewTransitionClass, when };
296
+ export { attrs, create, createTheme, defaultMarker, defineConsts, defineMarker, defineVars, env, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, unstable_conditional, unstable_createThemeNested, unstable_defineConstsNested, unstable_defineVarsNested, viewTransitionClass, when };
@@ -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<+_Val extends unknown>: string;
15
15
 
16
16
  declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
@@ -252,12 +252,17 @@ export type IDFromVarGroup<T extends VarGroup<{}>> = T['__opaqueId'];
252
252
 
253
253
  type TTokens = Readonly<{
254
254
  [key: string]:
255
- | NestedVarObject<null | string | number>
256
- | StyleXVar<null | string | number>
255
+ | NestedVarObject<
256
+ null | string | number | StyleXVar<null | string | number>
257
+ >
257
258
  | CSSType<null | string | number>;
258
259
  }>;
259
260
 
260
- type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
261
+ type UnwrapVars<T> = T extends () => infer U
262
+ ? UnwrapVars<U>
263
+ : T extends StyleXVar<infer U>
264
+ ? U
265
+ : T;
261
266
  export type FlattenTokens<T extends TTokens> = Readonly<{
262
267
  [Key in keyof T]: T[Key] extends { [key: string]: infer X }
263
268
  ? UnwrapVars<X>
@@ -266,6 +271,7 @@ export type FlattenTokens<T extends TTokens> = Readonly<{
266
271
 
267
272
  type NestedVarObject<T> =
268
273
  | T
274
+ | (() => T)
269
275
  | Readonly<{
270
276
  default: NestedVarObject<T>;
271
277
  [key: AtRuleStr]: NestedVarObject<T>;
@@ -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;
@@ -54,8 +54,9 @@ export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<
54
54
  false | ?Readonly<{ ...T, $$css: true }>,
55
55
  >;
56
56
 
57
- export type XStyleWithout<+T: { +[_K in keyof NestedCSSPropTypes]?: unknown }> =
58
- XStyle<Readonly<Omit<NestedCSSPropTypes, keyof T>>>;
57
+ export type XStyleWithout<
58
+ +T extends { +[_K in keyof NestedCSSPropTypes]?: unknown },
59
+ > = XStyle<Readonly<Omit<NestedCSSPropTypes, keyof T>>>;
59
60
 
60
61
  export type Keyframes = Readonly<{ [name: string]: CSSProperties, ... }>;
61
62
 
@@ -131,19 +132,19 @@ type ComplexStyleValueType<+T> =
131
132
  ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
132
133
  : Readonly<T>;
133
134
 
134
- type _MapNamespace<+CSS: { +[string]: unknown }> = Readonly<{
135
+ type _MapNamespace<+CSS extends { +[string]: unknown }> = Readonly<{
135
136
  [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
136
137
  }>;
137
- export type MapNamespace<+CSS: { +[string]: unknown }> = Readonly<{
138
+ export type MapNamespace<+CSS extends { +[string]: unknown }> = Readonly<{
138
139
  ..._MapNamespace<CSS>,
139
140
  $$css: true,
140
141
  }>;
141
- export type MapNamespaces<+S: { +[string]: unknown }> = Readonly<{
142
+ export type MapNamespaces<+S extends { +[string]: unknown }> = Readonly<{
142
143
  [Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
143
144
  ? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
144
145
  : MapNamespace<S[Key]>,
145
146
  }>;
146
- export type StyleX$Create = <const S: { +[string]: { ... } }>(
147
+ export type StyleX$Create = <const S extends { +[string]: { ... } }>(
147
148
  styles: S,
148
149
  ) => MapNamespaces<S>;
149
150
 
@@ -156,51 +157,53 @@ export type InlineStyles = Readonly<{
156
157
  [key: string]: string,
157
158
  }>;
158
159
 
159
- type _GenStylePropType<+CSS: { +[string]: unknown }> = Readonly<{
160
+ type _GenStylePropType<+CSS extends { +[string]: unknown }> = Readonly<{
160
161
  [Key in keyof CSS]: CSS[Key] extends { +[string]: unknown }
161
162
  ? StyleXClassNameFor<Key, Readonly<CSS[Key]>>
162
163
  : StyleXClassNameFor<Key, CSS[Key]>,
163
164
  }>;
164
- type GenStylePropType<+CSS: { +[string]: unknown }> = Readonly<{
165
+ type GenStylePropType<+CSS extends { +[string]: unknown }> = Readonly<{
165
166
  ..._GenStylePropType<CSS>,
166
167
  $$css: true,
167
168
  }>;
168
169
 
169
170
  // Replace `XStyle` with this.
170
171
  export type StaticStyles<
171
- +CSS: { +[string]: unknown } = CSSPropertiesWithExtras,
172
+ +CSS extends { +[string]: unknown } = CSSPropertiesWithExtras,
172
173
  > = StyleXArray<false | ?GenStylePropType<Readonly<CSS>>>;
173
174
 
174
- export type StaticStylesWithout<+CSS: { +[string]: unknown }> = StaticStyles<
175
- Omit<CSSPropertiesWithExtras, keyof CSS>,
176
- >;
175
+ export type StaticStylesWithout<+CSS extends { +[string]: unknown }> =
176
+ StaticStyles<Omit<CSSPropertiesWithExtras, keyof CSS>>;
177
177
 
178
178
  export type StyleXStyles<
179
- +CSS: { +[string]: unknown } = CSSPropertiesWithExtras,
179
+ +CSS extends { +[string]: unknown } = CSSPropertiesWithExtras,
180
180
  > = StyleXArray<
181
181
  | ?false
182
182
  | GenStylePropType<Readonly<CSS>>
183
183
  | Readonly<[GenStylePropType<Readonly<CSS>>, InlineStyles]>,
184
184
  >;
185
185
 
186
- export type StyleXStylesWithout<+CSS: { +[string]: unknown }> = StyleXStyles<
187
- Omit<CSSPropertiesWithExtras, keyof CSS>,
188
- >;
186
+ export type StyleXStylesWithout<+CSS extends { +[string]: unknown }> =
187
+ StyleXStyles<Omit<CSSPropertiesWithExtras, keyof CSS>>;
189
188
 
190
- export type VarGroup<+Tokens: { +[string]: unknown }, +_ID: string = string> = {
189
+ export type VarGroup<
190
+ +Tokens extends { +[string]: unknown },
191
+ +_ID extends string = string,
192
+ > = {
191
193
  +[Key in keyof Tokens]: StyleXVar<Tokens[Key]>,
192
194
  };
193
195
 
194
- export type TokensFromVarGroup<+T: VarGroup<{ +[string]: unknown }>> =
196
+ export type TokensFromVarGroup<+T extends VarGroup<{ +[string]: unknown }>> =
195
197
  Readonly<{
196
198
  [Key in keyof T]: UnwrapVar<T[Key]>,
197
199
  }>;
198
200
 
199
- type IDFromVarGroup<+T: VarGroup<{ +[string]: unknown }>> =
201
+ type IDFromVarGroup<+T extends VarGroup<{ +[string]: unknown }>> =
200
202
  T extends VarGroup<{ +[string]: unknown }, infer ID> ? ID : empty;
201
203
 
202
204
  type NestedVarObject<+T> =
203
205
  | T
206
+ | (() => T)
204
207
  | Readonly<{
205
208
  default: NestedVarObject<T>,
206
209
  [string]: NestedVarObject<T>,
@@ -208,13 +211,31 @@ type NestedVarObject<+T> =
208
211
 
209
212
  type TTokens = Readonly<{
210
213
  [string]:
211
- | NestedVarObject<null | string | number>
212
- | StyleXVar<null | string | number>
214
+ | NestedVarObject<
215
+ null | string | number | StyleXVar<null | string | number>,
216
+ >
213
217
  | CSSType<null | string | number>,
214
218
  }>;
215
219
 
216
- type UnwrapVar<+T> = T extends StyleXVar<infer U> ? U : T;
217
- export type FlattenTokens<+T: TTokens> = {
220
+ export type NestedVarsValue =
221
+ | string
222
+ | CSSType<string | number>
223
+ | { +[string]: NestedVarsValue };
224
+
225
+ export type NestedConstsValue =
226
+ | string
227
+ | number
228
+ | { +[string]: NestedConstsValue };
229
+
230
+ export type NestedStringValue = string | { +[string]: NestedStringValue };
231
+
232
+ type UnwrapVar<+T> = T extends () => infer U
233
+ ? UnwrapVar<U>
234
+ : T extends StyleXVar<infer U>
235
+ ? U
236
+ : T;
237
+
238
+ export type FlattenTokens<+T extends TTokens> = {
218
239
  +[Key in keyof T]: T[Key] extends CSSType<string | number>
219
240
  ? UnwrapVar<T[Key]>
220
241
  : T[Key] extends { +default: infer X, +[string]: infer Y }
@@ -222,32 +243,35 @@ export type FlattenTokens<+T: TTokens> = {
222
243
  : UnwrapVar<T[Key]>,
223
244
  };
224
245
 
225
- export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
246
+ export type StyleX$DefineVars = <
247
+ DefaultTokens extends TTokens,
248
+ ID extends string = string,
249
+ >(
226
250
  tokens: DefaultTokens,
227
251
  ) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
228
252
 
229
253
  export type StyleX$DefineConsts = <
230
- const DefaultTokens: { +[string]: number | string },
254
+ const DefaultTokens extends { +[string]: number | string },
231
255
  >(
232
256
  tokens: DefaultTokens,
233
257
  ) => DefaultTokens;
234
258
 
235
259
  // opaque type ThemeKey<+_VG: VarGroup<{ +[string]: unknown }>>: string = string;
236
260
  declare export opaque type Theme<
237
- +T: VarGroup<{ +[string]: unknown }, string>,
238
- +_Tag: string = string,
261
+ +T extends VarGroup<{ +[string]: unknown }, string>,
262
+ +_Tag extends string = string,
239
263
  >: Readonly<{
240
264
  $$css: true,
241
265
  theme: StyleXClassNameFor<'theme', IDFromVarGroup<T>>,
242
266
  }>;
243
267
 
244
- export type OverridesForTokenType<+Config: { +[string]: unknown }> = {
268
+ export type OverridesForTokenType<+Config extends { +[string]: unknown }> = {
245
269
  [Key in keyof Config]?: NestedVarObject<Config[Key]>,
246
270
  };
247
271
 
248
272
  export type StyleX$CreateTheme = <
249
- BaseTokens: VarGroup<{ +[string]: unknown }>,
250
- ID: string = string,
273
+ BaseTokens extends VarGroup<{ +[string]: unknown }>,
274
+ ID extends string = string,
251
275
  >(
252
276
  baseTokens: BaseTokens,
253
277
  overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
@@ -280,4 +304,4 @@ export type StyleX$When = {
280
304
  ) => ':where-any-sibling',
281
305
  };
282
306
 
283
- export type StyleX$Env = $ReadOnly<{ [string]: mixed }>;
307
+ export type StyleX$Env = Readonly<{ [string]: unknown }>;
@@ -29,64 +29,70 @@ export type CSSSyntax =
29
29
  type CSSSyntaxType = CSSSyntax;
30
30
  type InnerValue = null | string | number;
31
31
 
32
- interface ICSSType<+_T: InnerValue> {
32
+ interface ICSSType<+_T extends InnerValue> {
33
33
  +value: ValueWithDefault<string>;
34
34
  +syntax: CSSSyntaxType;
35
35
  }
36
- declare export class Angle<+T: InnerValue> implements ICSSType<T> {
36
+ declare export class Angle<+T extends InnerValue> implements ICSSType<T> {
37
37
  +value: ValueWithDefault<string>;
38
38
  +syntax: CSSSyntaxType;
39
39
  }
40
- declare export class Color<+T: InnerValue> implements ICSSType<T> {
40
+ declare export class Color<+T extends InnerValue> implements ICSSType<T> {
41
41
  +value: ValueWithDefault<string>;
42
42
  +syntax: CSSSyntaxType;
43
43
  }
44
- declare export class Url<+T: InnerValue> implements ICSSType<T> {
44
+ declare export class Url<+T extends InnerValue> implements ICSSType<T> {
45
45
  +value: ValueWithDefault<string>;
46
46
  +syntax: CSSSyntaxType;
47
47
  }
48
- declare export class Image<+T: InnerValue> implements ICSSType<T> {
48
+ declare export class Image<+T extends InnerValue> implements ICSSType<T> {
49
49
  +value: ValueWithDefault<string>;
50
50
  +syntax: CSSSyntaxType;
51
51
  }
52
- declare export class Integer<+T: InnerValue> implements ICSSType<T> {
52
+ declare export class Integer<+T extends InnerValue> implements ICSSType<T> {
53
53
  +value: ValueWithDefault<string>;
54
54
  +syntax: CSSSyntaxType;
55
55
  }
56
- declare export class LengthPercentage<+T: InnerValue> implements ICSSType<T> {
56
+ declare export class LengthPercentage<+T extends InnerValue>
57
+ implements ICSSType<T>
58
+ {
57
59
  +value: ValueWithDefault<string>;
58
60
  +syntax: CSSSyntaxType;
59
61
  }
60
- declare export class Length<+T: InnerValue> implements ICSSType<T> {
62
+ declare export class Length<+T extends InnerValue> implements ICSSType<T> {
61
63
  +value: ValueWithDefault<string>;
62
64
  +syntax: CSSSyntaxType;
63
65
  }
64
- declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
66
+ declare export class Percentage<+T extends InnerValue> implements ICSSType<T> {
65
67
  +value: ValueWithDefault<string>;
66
68
  +syntax: CSSSyntaxType;
67
69
  }
68
- declare export class Num<+T: InnerValue> implements ICSSType<T> {
70
+ declare export class Num<+T extends InnerValue> implements ICSSType<T> {
69
71
  +value: ValueWithDefault<string>;
70
72
  +syntax: CSSSyntaxType;
71
73
  }
72
- declare export class Resolution<+T: InnerValue> implements ICSSType<T> {
74
+ declare export class Resolution<+T extends InnerValue> implements ICSSType<T> {
73
75
  +value: ValueWithDefault<string>;
74
76
  +syntax: CSSSyntaxType;
75
77
  }
76
- declare export class Time<+T: InnerValue> implements ICSSType<T> {
78
+ declare export class Time<+T extends InnerValue> implements ICSSType<T> {
77
79
  +value: ValueWithDefault<string>;
78
80
  +syntax: CSSSyntaxType;
79
81
  }
80
- declare export class TransformFunction<+T: InnerValue> implements ICSSType<T> {
82
+ declare export class TransformFunction<+T extends InnerValue>
83
+ implements ICSSType<T>
84
+ {
81
85
  +value: ValueWithDefault<string>;
82
86
  +syntax: CSSSyntaxType;
83
87
  }
84
- declare export class TransformList<+T: InnerValue> implements ICSSType<T> {
88
+ declare export class TransformList<+T extends InnerValue>
89
+ implements ICSSType<T>
90
+ {
85
91
  +value: ValueWithDefault<string>;
86
92
  +syntax: CSSSyntaxType;
87
93
  }
88
94
 
89
- export type CSSType<+T: InnerValue> =
95
+ export type CSSType<+T extends InnerValue> =
90
96
  | Angle<T>
91
97
  | Color<T>
92
98
  | Url<T>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.18.2",
3
+ "version": "0.18.3",
4
4
  "description": "A library for defining styles for optimized user interfaces.",
5
5
  "main": "./lib/cjs/stylex.js",
6
6
  "module": "./lib/es/stylex.mjs",
@@ -60,9 +60,10 @@
60
60
  "babel-plugin-syntax-hermes-parser": "^0.32.1",
61
61
  "cross-env": "^10.1.0",
62
62
  "rollup": "^4.59.0",
63
- "scripts": "0.18.2"
63
+ "scripts": "0.18.3"
64
64
  },
65
65
  "files": [
66
66
  "lib/*"
67
- ]
67
+ ],
68
+ "sideEffects": false
68
69
  }