@stylexjs/stylex 0.18.1 → 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.
@@ -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>;
@@ -354,3 +360,56 @@ export type StyleX$When = {
354
360
  // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
355
361
  ) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`;
356
362
  };
363
+
364
+ export interface Register {}
365
+
366
+ export type StyleX$Env = Register extends { env: infer TEnv }
367
+ ? TEnv
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>>,
@@ -279,3 +303,5 @@ export type StyleX$When = {
279
303
  _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
280
304
  ) => ':where-any-sibling',
281
305
  };
306
+
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.1",
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.1"
63
+ "scripts": "0.18.3"
64
64
  },
65
65
  "files": [
66
66
  "lib/*"
67
- ]
67
+ ],
68
+ "sideEffects": false
68
69
  }