@stylexjs/stylex 0.2.0-beta.20 → 0.2.0-beta.21

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.
@@ -11,8 +11,8 @@ import type { CSSProperties } from './StyleXCSSTypes';
11
11
  declare const StyleXClassNameTag: unique symbol;
12
12
  export type StyleXClassNameFor<K, V> = string & {
13
13
  _opaque: typeof StyleXClassNameTag;
14
- key: K;
15
- value: V;
14
+ _key: K;
15
+ _value: V;
16
16
  };
17
17
 
18
18
  export type StyleXClassNameForValue<V> = StyleXClassNameFor<unknown, V>;
@@ -21,162 +21,174 @@ export type StyleXClassName = StyleXClassNameFor<unknown, unknown>;
21
21
  // Type for arbitrarily nested Array.
22
22
  export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
23
23
 
24
- type lowerCaseAlphabet =
25
- | 'a'
26
- | 'b'
27
- | 'c'
28
- | 'd'
29
- | 'e'
30
- | 'f'
31
- | 'g'
32
- | 'h'
33
- | 'i'
34
- | 'j'
35
- | 'k'
36
- | 'l'
37
- | 'm'
38
- | 'n'
39
- | 'o'
40
- | 'p'
41
- | 'q'
42
- | 'r'
43
- | 's'
44
- | 't'
45
- | 'u'
46
- | 'v'
47
- | 'w'
48
- | 'x'
49
- | 'y'
50
- | 'z'
51
- | '-'
52
- | '_'
53
- | '@'
54
- | ':';
24
+ declare const StyleXVarTag: unique symbol;
25
+ export type StyleXVar<_Val> = string & typeof StyleXVarTag;
26
+
27
+ // prettier-ignore
28
+ type NonDollarChars =
29
+ | 'a' | 'A' | 'b' | 'B' | 'c' | 'C' | 'd' | 'D'
30
+ | 'e' | 'E' | 'f' | 'F' | 'g' | 'G'
31
+ | 'h' | 'H' | 'i' | 'I' | 'j' | 'J' | 'k' | 'K'
32
+ | 'l' | 'L' | 'm' | 'M' | 'n' | 'N' | 'o' | 'O' | 'p' | 'P'
33
+ | 'q' | 'Q' | 'r' | 'R' | 's' | 'S' | 't' | 'T'
34
+ | 'u' | 'U' | 'v' | 'V' | 'w' | 'W'
35
+ | 'x' | 'X' | 'y' | 'Y' | 'z' | 'Z'
36
+ | '-' | '_' | '@' | ':';
55
37
 
56
38
  // Strings that don't start with a dollar sign.
57
39
  // So that we can `&` with {$$css: true} without type errors.
58
- type NonDollarStr = `${lowerCaseAlphabet}${string}`;
59
-
60
- type CSSPropTypes = {
61
- [Key in keyof CSSProperties]: StyleXClassNameFor<Key, CSSProperties[Key]>;
62
- };
40
+ type NonDollarStr = `${NonDollarChars}${string}`;
41
+ type PseudoClassStr = `:${string}`;
42
+ type AtRuleStr = `@${string}`;
43
+
44
+ type CondStr = PseudoClassStr | AtRuleStr;
45
+
46
+ type CSSPropertiesWithExtras = Partial<
47
+ Readonly<
48
+ CSSProperties & {
49
+ '::after': CSSProperties;
50
+ '::backdrop': CSSProperties;
51
+ '::before': CSSProperties;
52
+ '::cue': CSSProperties;
53
+ '::cue-region': CSSProperties;
54
+ '::first-letter': CSSProperties;
55
+ '::first-line': CSSProperties;
56
+ '::file-selector-button': CSSProperties;
57
+ '::grammar-error': CSSProperties;
58
+ '::marker': CSSProperties;
59
+ // This is a pattern and not a static key so it cannot be typed correctly.
60
+ // '::part()': CSSProperties;
61
+ '::placeholder': CSSProperties;
62
+ '::selection': CSSProperties;
63
+ // This is a pattern and not a static key so it cannot be typed correctly.
64
+ // '::slotted()': CSSProperties;
65
+ '::spelling-error': CSSProperties;
66
+ '::target-text': CSSProperties;
67
+ }
68
+ >
69
+ >;
63
70
 
64
- export type NestedCSSPropTypes = CSSPropTypes &
71
+ export type NestedCSSPropTypes = Partial<
65
72
  Readonly<{
66
- // NOTE: the actual type should be nested objects.
67
- // fix after the types in stylex.js are fixed.
68
- ':active': StyleXClassName;
69
- ':focus': StyleXClassName;
70
- ':focus-visible': StyleXClassName;
71
- ':hover': StyleXClassName;
72
- ':disabled': StyleXClassName;
73
- ':empty': StyleXClassName;
74
- ':first-child': StyleXClassName;
75
- ':last-child': StyleXClassName;
76
- '::before': StyleXClassName;
77
- '::after': StyleXClassName;
78
- '::placeholder': StyleXClassName;
79
- '::-webkit-scrollbar': StyleXClassName;
80
-
81
- [key: `@media (max-width: ${number}px)`]: StyleXClassName;
82
- [key: `@media (min-width: ${number}px)`]: StyleXClassName;
83
- [
84
- key: `@media (min-width: ${number}px) and (max-width: ${number}px)`
85
- ]: StyleXClassName;
86
-
87
- [key: `@media (max-height: ${number}px)`]: StyleXClassName;
88
- [key: `@media (min-height: ${number}px)`]: StyleXClassName;
89
- [
90
- key: `@media (min-height: ${number}px) and (max-height: ${number}px)`
91
- ]: StyleXClassName;
92
-
93
- [
94
- key: `@media (-webkit-min-device-pixel-ratio: ${number})`
95
- ]: StyleXClassName;
96
- '@media print': StyleXClassName;
97
-
98
- // webkit styles used for Search in Safari
99
- '::-webkit-search-decoration': StyleXClassName;
100
- '::-webkit-search-cancel-button': StyleXClassName;
101
- '::-webkit-search-results-button': StyleXClassName;
102
- '::-webkit-search-results-decoration': StyleXClassName;
103
- }>;
73
+ [Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor<
74
+ Key,
75
+ CSSPropertiesWithExtras[Key]
76
+ >;
77
+ }>
78
+ >;
104
79
 
80
+ type UserAuthoredStyles = { [key: NonDollarStr]: unknown };
105
81
  export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
106
- export type XStyle<T = NestedCSSPropTypes> = StyleXArray<
107
- false | (null | undefined | T)
108
- >;
109
- export type XStyleWithout<T extends { [$$Key$$: NonDollarStr]: void }> = XStyle<
82
+ export type XStyle<T extends UserAuthoredStyles = NestedCSSPropTypes> =
83
+ StyleXArray<false | (null | undefined | Readonly<T & { $$css: true }>)>;
84
+ export type XStyleWithout<T extends UserAuthoredStyles> = XStyle<
110
85
  Readonly<Pick<NestedCSSPropTypes, Exclude<keyof NestedCSSPropTypes, keyof T>>>
111
86
  >;
112
87
 
113
88
  export type Keyframes = Readonly<{ [name: NonDollarStr]: CSSProperties }>;
114
89
  export type LegacyTheme = Readonly<{ [constantName: NonDollarStr]: string }>;
115
90
 
116
- type RawStyles = {
117
- [key: NonDollarStr]:
118
- | null
119
- | string
120
- | number
121
- | Array<string | number>
122
- | RawStyles;
123
- };
91
+ type ComplexStyleValueType<T> = T extends string | number | null
92
+ ? T
93
+ : T extends StyleXVar<infer U>
94
+ ? U
95
+ : T extends ReadonlyArray<infer U>
96
+ ? U
97
+ : T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }>
98
+ ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
99
+ : T;
100
+
101
+ type _MapNamespace<CSS> = Readonly<{
102
+ [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>;
103
+ }>;
124
104
 
125
- type CompiledNamespace<const N extends RawStyles> = {
126
- [K in keyof N]: N[K] extends string | number | null
127
- ? StyleXClassNameFor<K, N[K]>
128
- : N[K] extends ReadonlyArray<infer T>
129
- ? StyleXClassNameFor<K, T>
130
- : K extends `:${string}` | `@${string}`
131
- ? N[K] extends RawStyles
132
- ? CompiledNamespace<N[K]>
133
- : StyleXClassNameFor<K, N[K]>
134
- : N[K] extends { [key: string]: infer T }
135
- ? StyleXClassNameFor<K, T> // TODO: Handle nested objects
136
- : never;
137
- };
105
+ export type MapNamespace<CSS> = Readonly<
106
+ _MapNamespace<CSS> & Readonly<{ $$css: true }>
107
+ >;
138
108
 
139
- export type Stylex$Create = <const S extends { [n: NonDollarStr]: RawStyles }>(
140
- styles: S,
141
- ) => Readonly<{
142
- [N in keyof S]: CompiledNamespace<S[N]> & { $$css: true };
109
+ export type MapNamespaces<
110
+ S extends {
111
+ [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
112
+ },
113
+ > = Readonly<{
114
+ [Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
115
+ ? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
116
+ : MapNamespace<S[Key]>;
143
117
  }>;
144
118
 
145
- export type CompiledStyles = Readonly<{
146
- [key: NonDollarStr]:
147
- | StyleXClassName
148
- | Readonly<{ [key: NonDollarStr]: StyleXClassName }>;
149
- }> & { $$css: true };
119
+ export type Stylex$Create = <
120
+ const S extends {
121
+ [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
122
+ },
123
+ >(
124
+ styles: S,
125
+ ) => MapNamespaces<S>;
126
+
127
+ export type CompiledStyles = Readonly<
128
+ {
129
+ [key: NonDollarStr]:
130
+ | StyleXClassName
131
+ | Readonly<{ [key: NonDollarStr]: StyleXClassName }>;
132
+ } & { $$css: true }
133
+ >;
150
134
 
151
- type TTokens = {
152
- [key: NonDollarStr]: string | { default: string; [key: string]: string };
153
- };
135
+ export type InlineStyles = Readonly<
136
+ { [key: NonDollarStr]: string } & { $$css?: void }
137
+ >;
154
138
 
155
- export type FlattenTokens<
156
- T extends {
157
- [key: NonDollarStr]: string | { default: string; [key: string]: string };
158
- },
159
- > = {
160
- [Key in keyof T]: T[Key] extends { default: infer X } & {
161
- [key: Exclude<string, 'default'>]: infer Y;
162
- }
163
- ? X | Y
164
- : T[Key];
165
- };
139
+ type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
140
+ [Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
141
+ }>;
142
+ type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
143
+ _GenStylePropType<CSS> & { $$css: true } & Partial<{
144
+ [Key in Exclude<
145
+ keyof CSSPropertiesWithExtras,
146
+ keyof CSS | '$$css'
147
+ >]: never;
148
+ }>
149
+ >;
150
+
151
+ // Replace `XStyle` with this.
152
+ export type StaticStyles<
153
+ CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
154
+ > = StyleXArray<false | null | void | GenStylePropType<CSS>>;
155
+ export type StaticStylesWithout<CSS extends UserAuthoredStyles> = StaticStyles<
156
+ Omit<CSSPropertiesWithExtras, keyof CSS>
157
+ >;
158
+
159
+ export type StyleXStyles<
160
+ CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
161
+ > = StyleXArray<
162
+ | null
163
+ | void
164
+ | false
165
+ | GenStylePropType<CSS>
166
+ | Readonly<[GenStylePropType<CSS>, InlineStyles]>
167
+ >;
168
+ export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
169
+ Omit<CSSPropertiesWithExtras, keyof CSS>
170
+ >;
166
171
 
172
+ declare const StyleXThemeTag: unique symbol;
167
173
  export type Theme<
168
- Tokens extends { [key: string]: unknown },
174
+ Tokens extends { [key: NonDollarStr]: unknown },
169
175
  ID extends symbol = symbol,
170
- > = Readonly<{
171
- [_Key in Exclude<keyof Tokens, '_opaque' | '_tokens'>]: string;
172
- }> & {
173
- _opaque: ID;
174
- _tokens: Tokens;
175
- };
176
+ > = Readonly<{ [_Key in keyof Tokens]: string }> & {
177
+ $opaqueId: ID;
178
+ $tokens: Tokens;
179
+ } & typeof StyleXThemeTag;
180
+
181
+ export type TokensFromTheme<T extends Theme<TTokens>> = T['$tokens'];
176
182
 
177
- export type TokensFromTheme<T extends Theme<TTokens>> = T['_tokens'];
183
+ export type IDFromTheme<T extends Theme<TTokens>> = T['$opaqueId'];
184
+
185
+ type TTokens = {
186
+ [key: NonDollarStr]: string | { default: string; [key: AtRuleStr]: string };
187
+ };
178
188
 
179
- export type IDFromTheme<T extends Theme<TTokens>> = T['_opaque'];
189
+ export type FlattenTokens<T extends TTokens> = Readonly<{
190
+ [Key in keyof T]: T[Key] extends { [key: string]: infer X } ? X : T[Key];
191
+ }>;
180
192
 
181
193
  export type StyleX$CreateVars = <
182
194
  DefaultTokens extends TTokens,
@@ -189,14 +201,15 @@ export type Variant<
189
201
  T extends Theme<TTokens, symbol>,
190
202
  // eslint-disable-next-line no-unused-vars
191
203
  Tag extends symbol = symbol,
192
- > = Readonly<{
193
- [Key: symbol]: StyleXClassNameFor<string, IDFromTheme<T>>;
194
- }> & { _opaque: Tag };
204
+ > = Tag &
205
+ Readonly<{
206
+ theme: StyleXClassNameFor<string, IDFromTheme<T>>;
207
+ }>;
195
208
 
196
- type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
209
+ type OverridesForTokenType<Config extends { [key: string]: any }> = {
197
210
  [Key in keyof Config]:
198
211
  | Config[Key]
199
- | { default: Config[Key]; [atRule: string]: Config[Key] };
212
+ | { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
200
213
  };
201
214
 
202
215
  export type StyleX$OverrideVars = <
@@ -18,75 +18,78 @@ export type StyleXClassName = StyleXClassNameFor<mixed, mixed>;
18
18
  // Type for arbitrarily nested Array.
19
19
  export type StyleXArray<+T> = T | $ReadOnlyArray<StyleXArray<T>>;
20
20
 
21
- type CSSPropTypes = $ReadOnly<$ObjMap<CSSProperties, () => StyleXClassName>>;
22
- export type NestedCSSPropTypes = $ReadOnly<{
23
- ...$Exact<CSSPropTypes>,
24
- // NOTE: the actual type should be nested objects.
25
- // fix after the types in stylex.js are fixed.
26
- ':active'?: StyleXClassName,
27
- ':focus'?: StyleXClassName,
28
- ':focus-visible'?: StyleXClassName,
29
- ':hover'?: StyleXClassName,
30
- ':disabled'?: StyleXClassName,
31
- ':empty'?: StyleXClassName,
32
- ':first-child'?: StyleXClassName,
33
- ':last-child'?: StyleXClassName,
34
- '::before'?: StyleXClassName,
35
- '::after'?: StyleXClassName,
36
- '::placeholder'?: StyleXClassName,
37
- '::-webkit-scrollbar'?: StyleXClassName,
21
+ type CSSPropertiesWithExtras = $ReadOnly<{
22
+ ...CSSProperties,
23
+ ':active'?: CSSProperties,
24
+ ':focus'?: CSSProperties,
25
+ ':focus-visible'?: CSSProperties,
26
+ ':hover'?: CSSProperties,
27
+ ':disabled'?: CSSProperties,
28
+ ':empty'?: CSSProperties,
29
+ ':first-child'?: CSSProperties,
30
+ ':last-child'?: CSSProperties,
31
+ '::before'?: CSSProperties,
32
+ '::after'?: CSSProperties,
33
+ '::placeholder'?: CSSProperties,
34
+ '::-webkit-scrollbar'?: CSSProperties,
38
35
  // Find a better way to do this. Being forced to add every media query.
39
- '@media (max-width: 564px)'?: StyleXClassName,
40
- '@media (min-height: 700px)'?: StyleXClassName,
41
- '@media (min-height: 700px) and (max-height: 789px)'?: StyleXClassName,
42
- '@media (min-height: 753px) and (max-height: 789px)'?: StyleXClassName,
43
- '@media (min-height: 790px)'?: StyleXClassName,
44
- '@media (max-width: 648px)'?: StyleXClassName,
45
- '@media (max-width: 899px)'?: StyleXClassName,
46
- '@media (max-width: 900px)'?: StyleXClassName,
47
- '@media (min-width: 900px)'?: StyleXClassName,
48
- '@media (min-width: 900px) and (max-width: 1259px)'?: StyleXClassName,
49
- '@media (max-width: 1099px)'?: StyleXClassName,
50
- '@media (max-width: 1199px)'?: StyleXClassName,
51
- '@media (max-width: 1259px)'?: StyleXClassName,
52
- '@media (min-width: 1290px)'?: StyleXClassName,
53
- '@media (max-width: 420px)'?: StyleXClassName,
54
- '@media (max-width: 500px)'?: StyleXClassName,
55
- '@media (pointer: coarse)'?: StyleXClassName,
56
- '@media (-webkit-min-device-pixel-ratio: 0)'?: StyleXClassName,
57
- '@media print'?: StyleXClassName,
36
+ '@media (max-width: 564px)'?: CSSProperties,
37
+ '@media (min-height: 700px)'?: CSSProperties,
38
+ '@media (min-height: 700px) and (max-height: 789px)'?: CSSProperties,
39
+ '@media (min-height: 753px) and (max-height: 789px)'?: CSSProperties,
40
+ '@media (min-height: 790px)'?: CSSProperties,
41
+ '@media (max-width: 648px)'?: CSSProperties,
42
+ '@media (max-width: 899px)'?: CSSProperties,
43
+ '@media (max-width: 900px)'?: CSSProperties,
44
+ '@media (min-width: 900px)'?: CSSProperties,
45
+ '@media (min-width: 900px) and (max-width: 1259px)'?: CSSProperties,
46
+ '@media (max-width: 1099px)'?: CSSProperties,
47
+ '@media (max-width: 1199px)'?: CSSProperties,
48
+ '@media (max-width: 1259px)'?: CSSProperties,
49
+ '@media (min-width: 1290px)'?: CSSProperties,
50
+ '@media (max-width: 420px)'?: CSSProperties,
51
+ '@media (max-width: 500px)'?: CSSProperties,
52
+ '@media (pointer: coarse)'?: CSSProperties,
53
+ '@media (-webkit-min-device-pixel-ratio: 0)'?: CSSProperties,
54
+ '@media print'?: CSSProperties,
58
55
  // Media queries used for Oculus Web Design Systems (OCDS components).
59
- '@media (max-width: 767px)'?: StyleXClassName,
60
- '@media (min-width: 768px)'?: StyleXClassName,
61
- '@media (min-width: 768px) and (max-width: 1024px)'?: StyleXClassName,
62
- '@media (max-width: 1024px)'?: StyleXClassName,
63
- '@media (min-width: 1025px)'?: StyleXClassName,
64
- '@media (min-width: 1025px) and (max-width: 1920px)'?: StyleXClassName,
65
- '@media (max-width: 1920px)'?: StyleXClassName,
66
- '@media (min-width: 1921px)'?: StyleXClassName,
56
+ '@media (max-width: 767px)'?: CSSProperties,
57
+ '@media (min-width: 768px)'?: CSSProperties,
58
+ '@media (min-width: 768px) and (max-width: 1024px)'?: CSSProperties,
59
+ '@media (max-width: 1024px)'?: CSSProperties,
60
+ '@media (min-width: 1025px)'?: CSSProperties,
61
+ '@media (min-width: 1025px) and (max-width: 1920px)'?: CSSProperties,
62
+ '@media (max-width: 1920px)'?: CSSProperties,
63
+ '@media (min-width: 1921px)'?: CSSProperties,
67
64
  // Media queries used for Intern Data Products
68
- '@media (min-width: 1500px)'?: StyleXClassName,
69
- '@media (min-width: 1800px)'?: StyleXClassName,
70
- '@media (min-width: 2250px)'?: StyleXClassName,
65
+ '@media (min-width: 1500px)'?: CSSProperties,
66
+ '@media (min-width: 1800px)'?: CSSProperties,
67
+ '@media (min-width: 2250px)'?: CSSProperties,
71
68
  // webkit styles used for Search in Safari
72
- '::-webkit-search-decoration'?: StyleXClassName,
73
- '::-webkit-search-cancel-button'?: StyleXClassName,
74
- '::-webkit-search-results-button'?: StyleXClassName,
75
- '::-webkit-search-results-decoration'?: StyleXClassName,
69
+ '::-webkit-search-decoration'?: CSSProperties,
70
+ '::-webkit-search-cancel-button'?: CSSProperties,
71
+ '::-webkit-search-results-button'?: CSSProperties,
72
+ '::-webkit-search-results-decoration'?: CSSProperties,
76
73
  // Media queries used for the logged out header
77
- '@media (min-width: 950px)'?: StyleXClassName,
74
+ '@media (min-width: 950px)'?: CSSProperties,
78
75
  // Media queries used for bizweb
79
- '@media (min-width: 1440px)'?: StyleXClassName,
80
- '@media (min-width: 1920px)'?: StyleXClassName,
76
+ '@media (min-width: 1440px)'?: CSSProperties,
77
+ '@media (min-width: 1920px)'?: CSSProperties,
81
78
  // Media queries used for fbai
82
- '@media (min-width: 800px)'?: StyleXClassName,
79
+ '@media (min-width: 800px)'?: CSSProperties,
83
80
  // Media queries used for messengerkidsdotcom
84
- '@media (max-width: 1024px) and (min-width: 501px)'?: StyleXClassName,
81
+ '@media (max-width: 1024px) and (min-width: 501px)'?: CSSProperties,
82
+ }>;
83
+
84
+ export type NestedCSSPropTypes = $ReadOnly<{
85
+ [Key in keyof CSSPropertiesWithExtras]?: StyleXClassNameForKey<Key>,
85
86
  }>;
86
87
 
87
88
  export type StyleXSingleStyle = false | ?NestedCSSPropTypes;
88
- export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<false | ?T>;
89
- export type XStyleWithout<+T: { [string]: void, ... }> = XStyle<
89
+ export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<
90
+ false | ?$ReadOnly<{ ...T, $$css: true }>,
91
+ >;
92
+ export type XStyleWithout<+T: { +[string]: mixed }> = XStyle<
90
93
  $ReadOnly<$Rest<NestedCSSPropTypes, $Exact<T>>>,
91
94
  >;
92
95
 
@@ -94,28 +97,31 @@ export type Keyframes = $ReadOnly<{ [name: string]: CSSProperties, ... }>;
94
97
 
95
98
  export type LegacyTheme = $ReadOnly<{ [constantName: string]: string, ... }>;
96
99
 
97
- // type CSSValue = string | number | $ReadOnlyArray<mixed>;
98
- type MapCSSValueToClassName = <K, V>(K, V) => StyleXClassNameFor<K, V>;
99
-
100
- export type MapNamespace<CSS: { ... }> = $ReadOnly<{
101
- ...$ObjMapi<CSS, MapCSSValueToClassName>,
100
+ type ComplexStyleValueType<+T> = T extends string | number | null
101
+ ? T
102
+ : T extends StyleXVar<infer U>
103
+ ? U
104
+ : T extends $ReadOnlyArray<infer U>
105
+ ? U
106
+ : T extends $ReadOnly<{ default: infer A, +[string]: infer B }>
107
+ ? ComplexStyleValueType<A> | ComplexStyleValueType<B>
108
+ : T;
109
+
110
+ type _MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
111
+ [Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
112
+ }>;
113
+ export type MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
114
+ ..._MapNamespace<CSS>,
102
115
  $$css: true,
103
116
  }>;
104
- // NOTE: Flow was confused by nested ObjMap so for now, nested styles
105
- // are typed incorrectly to be a string. This won't matter for the time being.
106
- // type MapStyleToClassName = (<Rule: {}>(
107
- // Rule,
108
- // ) => $ObjMap<Rule, MapCSSValueToClassName>) &
109
- // MapCSSValueToClassName;
110
-
111
- export type MapNamespaces = (<CSS: { ... }>(CSS) => MapNamespace<CSS>) &
112
- (<Args: $ReadOnlyArray<mixed>, CSS: { ... }>(
113
- fn: (...args: Args) => CSS,
114
- ) => MapNamespace<CSS>);
115
-
116
- export type Stylex$Create = <S: { ... }>(
117
+ export type MapNamespaces<+S: { +[string]: mixed }> = $ReadOnly<{
118
+ [Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
119
+ ? (...args: Args) => $ReadOnly<[MapNamespace<Obj>, InlineStyles]>
120
+ : MapNamespace<S[Key]>,
121
+ }>;
122
+ export type Stylex$Create = <S: { +[string]: mixed }>(
117
123
  styles: S,
118
- ) => $ReadOnly<$ObjMap<S, MapNamespaces>>;
124
+ ) => MapNamespaces<S>;
119
125
 
120
126
  export type CompiledStyles = $ReadOnly<{
121
127
  $$css: true,
@@ -124,15 +130,47 @@ export type CompiledStyles = $ReadOnly<{
124
130
  | $ReadOnly<{ [key: string]: StyleXClassName, ... }>,
125
131
  ...
126
132
  }>;
133
+ export type InlineStyles = $ReadOnly<{
134
+ $$css?: void,
135
+ [key: string]: string,
136
+ }>;
127
137
 
138
+ type _GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
139
+ [Key in keyof CSS]: CSS[Key] extends { +[string]: mixed }
140
+ ? StyleXClassNameFor<Key, $ReadOnly<CSS[Key]>>
141
+ : StyleXClassNameFor<Key, CSS[Key]>,
142
+ }>;
143
+ type GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
144
+ ..._GenStylePropType<CSS>,
145
+ $$css: true,
146
+ }>;
147
+
148
+ // Replace `XStyle` with this.
149
+ export type StaticStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
150
+ StyleXArray<false | ?GenStylePropType<$ReadOnly<CSS>>>;
151
+
152
+ export type StaticStylesWithout<+CSS: { +[string]: mixed }> = StaticStyles<
153
+ $Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
154
+ >;
155
+
156
+ export type StyleXStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
157
+ StyleXArray<
158
+ | ?false
159
+ | GenStylePropType<$ReadOnly<CSS>>
160
+ | $ReadOnly<[GenStylePropType<$ReadOnly<CSS>>, InlineStyles]>,
161
+ >;
162
+
163
+ export type StyleXStylesWithout<+CSS: { +[string]: mixed }> = StyleXStyles<
164
+ $Rest<CSSPropertiesWithExtras, $ReadOnly<CSS>>,
165
+ >;
128
166
  // This is the type for the variables object
129
- declare export opaque type StyleXVarsTheme<+Vars: { +[string]: string }>: Vars;
167
+ declare export opaque type StyleXVar<+_Val: mixed>;
130
168
 
131
169
  declare export opaque type Theme<
132
170
  +Tokens: { +[string]: mixed },
133
171
  // eslint-disable-next-line no-unused-vars
134
172
  +ID: string = string,
135
- >: $ReadOnly<{ [$Keys<Tokens>]: string }>;
173
+ >: $ReadOnly<{ [Key in keyof Tokens]: StyleXVar<Tokens[Key]> }>;
136
174
 
137
175
  export type TokensFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
138
176
  infer Tokens,
@@ -146,22 +184,17 @@ type IDFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
146
184
  ? ID
147
185
  : empty;
148
186
 
149
- export type FlattenTokens<
150
- T: {
151
- +[string]: string | { +default: string, +[string]: string },
152
- },
153
- > = {
187
+ type TTokens = $ReadOnly<{
188
+ [string]: string | $ReadOnly<{ default: string, [string]: string }>,
189
+ }>;
190
+
191
+ export type FlattenTokens<T: TTokens> = {
154
192
  +[Key in keyof T]: T[Key] extends { +default: infer X, +[string]: infer Y }
155
193
  ? X | Y
156
194
  : T[Key],
157
195
  };
158
196
 
159
- export type StyleX$CreateVars = <
160
- +DefaultTokens: {
161
- +[string]: string | { default: string, +[string]: string },
162
- },
163
- +ID: string = string,
164
- >(
197
+ export type StyleX$CreateVars = <DefaultTokens: TTokens, ID: string = string>(
165
198
  tokens: DefaultTokens,
166
199
  ) => Theme<FlattenTokens<DefaultTokens>, ID>;
167
200
 
@@ -180,8 +213,8 @@ export type OverridesForTokenType<Config: { +[string]: mixed }> = {
180
213
  };
181
214
 
182
215
  export type StyleX$OverrideVars = <
183
- +BaseTokens: Theme<{ +[string]: mixed }>,
184
- +ID: string = string,
216
+ BaseTokens: Theme<{ +[string]: mixed }>,
217
+ ID: string = string,
185
218
  >(
186
219
  baseTokens: BaseTokens,
187
220
  overrides: OverridesForTokenType<TokensFromTheme<BaseTokens>>,
@@ -7,8 +7,20 @@
7
7
  *
8
8
  */
9
9
 
10
- export declare function isCustomPropertyValue(value: unknown): boolean;
10
+ /**
11
+ * Either create a custom property value or return null if the input is not a string
12
+ * containing a 'var(--name)' or 'var(--name, default)' sequence.
13
+ *
14
+ * Made this a single function to test and create to avoid parsing the RegExp twice.
15
+ */
16
+ export declare function createCSSCustomPropertyValue(
17
+ value: string,
18
+ ): CSSCustomPropertyValue | null;
19
+ /**
20
+ * Class representing a custom property value with an optional fallback.
21
+ */
11
22
  export declare class CSSCustomPropertyValue {
12
23
  name: string;
13
- constructor(value: string);
24
+ defaultValue: unknown;
25
+ constructor(kebabCasePropName: string, fallback: unknown);
14
26
  }