@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.
@@ -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>
@@ -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,
@@ -30,6 +33,7 @@ import type {
30
33
  StyleX$When,
31
34
  MapNamespace,
32
35
  StyleX$DefineMarker,
36
+ StyleX$Env,
33
37
  } from './types/StyleXTypes';
34
38
  import type { ValueWithDefault } from './types/StyleXUtils';
35
39
  import * as Types from './types/VarTypes';
@@ -58,6 +62,32 @@ export declare const defineConsts: StyleX$DefineConsts;
58
62
  export declare type defineConsts = typeof defineConsts;
59
63
  export declare const defineVars: StyleX$DefineVars;
60
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;
61
91
  export declare const defineMarker: StyleX$DefineMarker;
62
92
  export declare type defineMarker = typeof defineMarker;
63
93
  export declare const firstThatWorks: <T extends string | number>(
@@ -82,6 +112,16 @@ export declare function props(
82
112
  'data-style-src'?: string;
83
113
  style?: Readonly<{ [$$Key$$: string]: string | number }>;
84
114
  }>;
115
+ export declare function attrs(
116
+ this: null | undefined | unknown,
117
+ ...styles: ReadonlyArray<
118
+ StyleXArray<
119
+ | (null | undefined | CompiledStyles)
120
+ | boolean
121
+ | Readonly<[CompiledStyles, InlineStyles]>
122
+ >
123
+ >
124
+ ): Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
85
125
  export declare const viewTransitionClass: (
86
126
  _viewTransitionClass: ViewTransitionClass,
87
127
  ) => string;
@@ -92,7 +132,7 @@ export declare const defaultMarker: () => MapNamespace<
92
132
  export declare type defaultMarker = typeof defaultMarker;
93
133
  export declare const when: StyleX$When;
94
134
  export declare type when = typeof when;
95
- export declare const env: Readonly<{ [$$Key$$: string]: unknown }>;
135
+ export declare const env: StyleX$Env;
96
136
  export declare type env = typeof env;
97
137
  export declare const types: {
98
138
  angle: <T extends string | 0 = string | 0>(
@@ -146,7 +186,7 @@ type IStyleX = {
146
186
  createTheme: StyleX$CreateTheme;
147
187
  defineConsts: StyleX$DefineConsts;
148
188
  defineVars: StyleX$DefineVars;
149
- env: Readonly<{ [$$Key$$: string]: unknown }>;
189
+ env: StyleX$Env;
150
190
  defaultMarker: () => MapNamespace<Readonly<{ marker: 'default-marker' }>>;
151
191
  defineMarker: StyleX$DefineMarker;
152
192
  firstThatWorks: <T extends string | number>(
@@ -168,9 +208,41 @@ type IStyleX = {
168
208
  'data-style-src'?: string;
169
209
  style?: Readonly<{ [$$Key$$: string]: string | number }>;
170
210
  }>;
211
+ attrs: (
212
+ this: null | undefined | unknown,
213
+ ...styles: ReadonlyArray<
214
+ StyleXArray<
215
+ | (null | undefined | CompiledStyles)
216
+ | boolean
217
+ | Readonly<[CompiledStyles, InlineStyles]>
218
+ >
219
+ >
220
+ ) => Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
171
221
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
172
222
  types: typeof types;
173
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;
174
246
  __customProperties?: { [$$Key$$: string]: unknown };
175
247
  };
176
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,
@@ -30,6 +33,7 @@ import type {
30
33
  StyleX$When,
31
34
  MapNamespace,
32
35
  StyleX$DefineMarker,
36
+ StyleX$Env,
33
37
  } from './types/StyleXTypes';
34
38
  import type { ValueWithDefault } from './types/StyleXUtils';
35
39
  import * as Types from './types/VarTypes';
@@ -60,9 +64,32 @@ declare export const defineConsts: StyleX$DefineConsts;
60
64
 
61
65
  declare export const defineVars: StyleX$DefineVars;
62
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
+
63
90
  declare export const defineMarker: StyleX$DefineMarker;
64
91
 
65
- declare export const firstThatWorks: <T: string | number>(
92
+ declare export const firstThatWorks: <T extends string | number>(
66
93
  ..._styles: ReadonlyArray<T>
67
94
  ) => ReadonlyArray<T>;
68
95
 
@@ -83,6 +110,19 @@ declare export function props(
83
110
  style?: Readonly<{ [string]: string | number }>,
84
111
  }>;
85
112
 
113
+ declare export function attrs(
114
+ this: ?unknown,
115
+ ...styles: ReadonlyArray<
116
+ StyleXArray<
117
+ ?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
118
+ >,
119
+ >
120
+ ): Readonly<{
121
+ class?: string,
122
+ 'data-style-src'?: string,
123
+ style?: string,
124
+ }>;
125
+
86
126
  declare export const viewTransitionClass: (
87
127
  _viewTransitionClass: ViewTransitionClass,
88
128
  ) => string;
@@ -95,34 +135,38 @@ declare export const defaultMarker: () => MapNamespace<
95
135
 
96
136
  declare export const when: StyleX$When;
97
137
 
98
- declare export const env: $ReadOnly<{ [string]: mixed }>;
138
+ declare export const env: StyleX$Env;
99
139
 
100
140
  declare export const types: {
101
- angle: <T: string | 0 = string | 0>(
141
+ angle: <T extends string | 0 = string | 0>(
102
142
  _v: ValueWithDefault<T>,
103
143
  ) => Types.Angle<T>,
104
- color: <T: string = string>(_v: ValueWithDefault<T>) => Types.Color<T>,
105
- url: <T: string = string>(_v: ValueWithDefault<T>) => Types.Url<T>,
106
- image: <T: string = string>(_v: ValueWithDefault<T>) => Types.Image<T>,
107
- integer: <T: number = number>(_v: ValueWithDefault<T>) => Types.Integer<T>,
108
- 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>(
109
151
  _v: ValueWithDefault<T>,
110
152
  ) => Types.LengthPercentage<T>,
111
- length: <T: number | string = number | string>(
153
+ length: <T extends number | string = number | string>(
112
154
  _v: ValueWithDefault<T>,
113
155
  ) => Types.Length<T>,
114
- percentage: <T: number | string = number | string>(
156
+ percentage: <T extends number | string = number | string>(
115
157
  _v: ValueWithDefault<T>,
116
158
  ) => Types.Percentage<T>,
117
- number: <T: number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
118
- resolution: <T: string = string>(
159
+ number: <T extends number = number>(_v: ValueWithDefault<T>) => Types.Num<T>,
160
+ resolution: <T extends string = string>(
119
161
  _v: ValueWithDefault<T>,
120
162
  ) => Types.Resolution<T>,
121
- time: <T: string | 0 = string | 0>(_v: ValueWithDefault<T>) => Types.Time<T>,
122
- 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>(
123
167
  _v: ValueWithDefault<T>,
124
168
  ) => Types.TransformFunction<T>,
125
- transformList: <T: string = string>(
169
+ transformList: <T extends string = string>(
126
170
  _v: ValueWithDefault<T>,
127
171
  ) => Types.TransformList<T>,
128
172
  };
@@ -137,14 +181,14 @@ type IStyleX = {
137
181
  createTheme: StyleX$CreateTheme,
138
182
  defineConsts: StyleX$DefineConsts,
139
183
  defineVars: StyleX$DefineVars,
140
- env: $ReadOnly<{ [string]: mixed }>,
184
+ env: StyleX$Env,
141
185
  defaultMarker: () => MapNamespace<
142
186
  Readonly<{
143
187
  marker: 'default-marker',
144
188
  }>,
145
189
  >,
146
190
  defineMarker: StyleX$DefineMarker,
147
- firstThatWorks: <T: string | number>(
191
+ firstThatWorks: <T extends string | number>(
148
192
  ...v: ReadonlyArray<T>
149
193
  ) => ReadonlyArray<T>,
150
194
  keyframes: (keyframes: Keyframes) => string,
@@ -161,9 +205,38 @@ type IStyleX = {
161
205
  'data-style-src'?: string,
162
206
  style?: Readonly<{ [string]: string | number }>,
163
207
  }>,
208
+ attrs: (
209
+ this: ?unknown,
210
+ ...styles: ReadonlyArray<
211
+ StyleXArray<
212
+ ?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
213
+ >,
214
+ >
215
+ ) => Readonly<{
216
+ class?: string,
217
+ 'data-style-src'?: string,
218
+ style?: string,
219
+ }>,
164
220
  viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
165
221
  types: typeof types,
166
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,
167
240
  __customProperties?: { [string]: unknown },
168
241
  ...
169
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
  };
@@ -170,6 +182,25 @@ function props(...styles) {
170
182
  }
171
183
  return result;
172
184
  }
185
+ const toKebabCase = str => str.replace(/([A-Z])/g, '-$1').toLowerCase();
186
+ function attrs(...styles) {
187
+ const {
188
+ className,
189
+ style,
190
+ 'data-style-src': dataStyleSrc
191
+ } = props.apply(this, styles);
192
+ const result = {};
193
+ if (className != null) {
194
+ result.class = className;
195
+ }
196
+ if (style != null) {
197
+ result.style = Object.entries(style).map(([key, value]) => `${toKebabCase(key)}:${value}`).join(';');
198
+ }
199
+ if (dataStyleSrc != null) {
200
+ result['data-style-src'] = dataStyleSrc;
201
+ }
202
+ return result;
203
+ }
173
204
  const viewTransitionClass = _viewTransitionClass => {
174
205
  throw errorForFn('viewTransitionClass');
175
206
  };
@@ -235,24 +266,31 @@ const types = {
235
266
  throw errorForType('transformList');
236
267
  }
237
268
  };
238
- function _legacyMerge(...styles) {
239
- const [className] = styleqExports.styleq(styles);
240
- return className;
241
- }
242
- _legacyMerge.create = create;
243
- _legacyMerge.createTheme = createTheme;
244
- _legacyMerge.defineConsts = defineConsts;
245
- _legacyMerge.defineMarker = defineMarker;
246
- _legacyMerge.defineVars = defineVars;
247
- _legacyMerge.defaultMarker = defaultMarker;
248
- _legacyMerge.firstThatWorks = firstThatWorks;
249
- _legacyMerge.keyframes = keyframes;
250
- _legacyMerge.positionTry = positionTry;
251
- _legacyMerge.props = props;
252
- _legacyMerge.types = types;
253
- _legacyMerge.when = when;
254
- _legacyMerge.viewTransitionClass = viewTransitionClass;
255
- _legacyMerge.env = env;
256
- 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
+ }();
257
295
 
258
- export { 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;