@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.
- package/lib/cjs/stylex.d.ts +74 -2
- package/lib/cjs/stylex.js +62 -19
- package/lib/cjs/stylex.js.flow +90 -17
- package/lib/cjs/types/StyleXOpaqueTypes.js.flow +1 -1
- package/lib/cjs/types/StyleXTypes.d.ts +62 -3
- package/lib/cjs/types/StyleXTypes.js.flow +56 -30
- package/lib/cjs/types/VarTypes.js.flow +21 -15
- package/lib/es/stylex.d.ts +74 -2
- package/lib/es/stylex.js.flow +90 -17
- package/lib/es/stylex.mjs +58 -20
- package/lib/es/types/StyleXOpaqueTypes.js.flow +1 -1
- package/lib/es/types/StyleXTypes.d.ts +62 -3
- package/lib/es/types/StyleXTypes.js.flow +56 -30
- package/lib/es/types/VarTypes.js.flow +21 -15
- package/package.json +4 -3
|
@@ -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<
|
|
256
|
-
|
|
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
|
|
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
|
|
58
|
-
|
|
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
|
|
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
|
|
138
|
+
export type MapNamespace<+CSS extends { +[string]: unknown }> = Readonly<{
|
|
138
139
|
..._MapNamespace<CSS>,
|
|
139
140
|
$$css: true,
|
|
140
141
|
}>;
|
|
141
|
-
export type MapNamespaces<+S
|
|
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
|
|
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
|
|
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
|
|
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
|
|
172
|
+
+CSS extends { +[string]: unknown } = CSSPropertiesWithExtras,
|
|
172
173
|
> = StyleXArray<false | ?GenStylePropType<Readonly<CSS>>>;
|
|
173
174
|
|
|
174
|
-
export type StaticStylesWithout<+CSS
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
212
|
-
|
|
214
|
+
| NestedVarObject<
|
|
215
|
+
null | string | number | StyleXVar<null | string | number>,
|
|
216
|
+
>
|
|
213
217
|
| CSSType<null | string | number>,
|
|
214
218
|
}>;
|
|
215
219
|
|
|
216
|
-
type
|
|
217
|
-
|
|
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 = <
|
|
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
|
|
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
|
|
238
|
-
+_Tag
|
|
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
|
|
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
|
|
250
|
-
ID
|
|
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
|
|
32
|
+
interface ICSSType<+_T extends InnerValue> {
|
|
33
33
|
+value: ValueWithDefault<string>;
|
|
34
34
|
+syntax: CSSSyntaxType;
|
|
35
35
|
}
|
|
36
|
-
declare export class Angle<+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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
63
|
+
"scripts": "0.18.3"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"lib/*"
|
|
67
|
-
]
|
|
67
|
+
],
|
|
68
|
+
"sideEffects": false
|
|
68
69
|
}
|