@stylexjs/stylex 0.2.0-beta.19 → 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.
- package/lib/StyleXCSSTypes.d.ts +396 -9
- package/lib/StyleXCSSTypes.js.flow +397 -391
- package/lib/StyleXTypes.d.ts +156 -100
- package/lib/StyleXTypes.js.flow +125 -88
- package/lib/native/CSSCustomPropertyValue.d.ts +14 -2
- package/lib/native/CSSCustomPropertyValue.js +12 -10
- package/lib/native/CSSCustomPropertyValue.js.flow +14 -2
- package/lib/native/CSSLengthUnitValue.d.ts +3 -7
- package/lib/native/CSSLengthUnitValue.js +8 -2
- package/lib/native/CSSLengthUnitValue.js.flow +4 -7
- package/lib/native/SpreadOptions.d.ts +18 -0
- package/lib/native/SpreadOptions.js +1 -0
- package/lib/native/SpreadOptions.js.flow +18 -0
- package/lib/native/__tests__/__snapshots__/stylex-css-var-test.js.snap +48 -0
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +570 -51
- package/lib/native/__tests__/stylex-css-var-test.js +148 -0
- package/lib/native/__tests__/stylex-test.js +325 -32
- package/lib/native/fixContentBox.d.ts +11 -0
- package/lib/native/fixContentBox.js +59 -0
- package/lib/native/fixContentBox.js.flow +11 -0
- package/lib/native/stylex.d.ts +3 -13
- package/lib/native/stylex.js +173 -73
- package/lib/native/stylex.js.flow +3 -10
- package/lib/stylex.d.ts +54 -1
- package/lib/stylex.js +48 -4
- package/lib/stylex.js.flow +52 -2
- package/package.json +3 -3
package/lib/StyleXTypes.d.ts
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
14
|
+
_key: K;
|
|
15
|
+
_value: V;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export type StyleXClassNameForValue<V> = StyleXClassNameFor<unknown, V>;
|
|
@@ -21,119 +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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
| '-' | '_' | '@' | ':';
|
|
37
|
+
|
|
38
|
+
// Strings that don't start with a dollar sign.
|
|
39
|
+
// So that we can `&` with {$$css: true} without type errors.
|
|
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
|
+
>;
|
|
27
70
|
|
|
28
|
-
export type NestedCSSPropTypes =
|
|
71
|
+
export type NestedCSSPropTypes = Partial<
|
|
29
72
|
Readonly<{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
':disabled': StyleXClassName;
|
|
37
|
-
':empty': StyleXClassName;
|
|
38
|
-
':first-child': StyleXClassName;
|
|
39
|
-
':last-child': StyleXClassName;
|
|
40
|
-
'::before': StyleXClassName;
|
|
41
|
-
'::after': StyleXClassName;
|
|
42
|
-
'::placeholder': StyleXClassName;
|
|
43
|
-
'::-webkit-scrollbar': StyleXClassName;
|
|
44
|
-
|
|
45
|
-
[key: `@media (max-width: ${number}px)`]: StyleXClassName;
|
|
46
|
-
[key: `@media (min-width: ${number}px)`]: StyleXClassName;
|
|
47
|
-
[
|
|
48
|
-
key: `@media (min-width: ${number}px) and (max-width: ${number}px)`
|
|
49
|
-
]: StyleXClassName;
|
|
50
|
-
|
|
51
|
-
[key: `@media (max-height: ${number}px)`]: StyleXClassName;
|
|
52
|
-
[key: `@media (min-height: ${number}px)`]: StyleXClassName;
|
|
53
|
-
[
|
|
54
|
-
key: `@media (min-height: ${number}px) and (max-height: ${number}px)`
|
|
55
|
-
]: StyleXClassName;
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
key: `@media (-webkit-min-device-pixel-ratio: ${number})`
|
|
59
|
-
]: StyleXClassName;
|
|
60
|
-
'@media print': StyleXClassName;
|
|
61
|
-
|
|
62
|
-
// webkit styles used for Search in Safari
|
|
63
|
-
'::-webkit-search-decoration': StyleXClassName;
|
|
64
|
-
'::-webkit-search-cancel-button': StyleXClassName;
|
|
65
|
-
'::-webkit-search-results-button': StyleXClassName;
|
|
66
|
-
'::-webkit-search-results-decoration': StyleXClassName;
|
|
67
|
-
}>;
|
|
73
|
+
[Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor<
|
|
74
|
+
Key,
|
|
75
|
+
CSSPropertiesWithExtras[Key]
|
|
76
|
+
>;
|
|
77
|
+
}>
|
|
78
|
+
>;
|
|
68
79
|
|
|
80
|
+
type UserAuthoredStyles = { [key: NonDollarStr]: unknown };
|
|
69
81
|
export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
|
|
70
|
-
export type XStyle<T = NestedCSSPropTypes> =
|
|
71
|
-
false | (null | undefined | T)
|
|
72
|
-
|
|
73
|
-
export type XStyleWithout<T extends { [$$Key$$: string]: 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<
|
|
74
85
|
Readonly<Pick<NestedCSSPropTypes, Exclude<keyof NestedCSSPropTypes, keyof T>>>
|
|
75
86
|
>;
|
|
76
87
|
|
|
77
|
-
export type Keyframes = Readonly<{ [name:
|
|
78
|
-
export type LegacyTheme = Readonly<{ [constantName:
|
|
88
|
+
export type Keyframes = Readonly<{ [name: NonDollarStr]: CSSProperties }>;
|
|
89
|
+
export type LegacyTheme = Readonly<{ [constantName: NonDollarStr]: string }>;
|
|
90
|
+
|
|
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
|
+
}>;
|
|
79
104
|
|
|
80
|
-
type
|
|
81
|
-
|
|
82
|
-
|
|
105
|
+
export type MapNamespace<CSS> = Readonly<
|
|
106
|
+
_MapNamespace<CSS> & Readonly<{ $$css: true }>
|
|
107
|
+
>;
|
|
83
108
|
|
|
84
|
-
type
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
?
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
: N[K] extends { [key: string]: infer T }
|
|
94
|
-
? StyleXClassNameFor<K, T> // TODO: Handle nested objects
|
|
95
|
-
: never;
|
|
96
|
-
};
|
|
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]>;
|
|
117
|
+
}>;
|
|
97
118
|
|
|
98
|
-
export type Stylex$Create = <
|
|
119
|
+
export type Stylex$Create = <
|
|
120
|
+
const S extends {
|
|
121
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
122
|
+
},
|
|
123
|
+
>(
|
|
99
124
|
styles: S,
|
|
100
|
-
) =>
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
) => MapNamespaces<S>;
|
|
126
|
+
|
|
127
|
+
export type CompiledStyles = Readonly<
|
|
128
|
+
{
|
|
129
|
+
[key: NonDollarStr]:
|
|
130
|
+
| StyleXClassName
|
|
131
|
+
| Readonly<{ [key: NonDollarStr]: StyleXClassName }>;
|
|
132
|
+
} & { $$css: true }
|
|
133
|
+
>;
|
|
134
|
+
|
|
135
|
+
export type InlineStyles = Readonly<
|
|
136
|
+
{ [key: NonDollarStr]: string } & { $$css?: void }
|
|
137
|
+
>;
|
|
103
138
|
|
|
104
|
-
|
|
105
|
-
[
|
|
139
|
+
type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
|
|
140
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
|
|
106
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
|
+
>;
|
|
107
150
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
>;
|
|
111
158
|
|
|
112
|
-
export type
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
>;
|
|
123
171
|
|
|
172
|
+
declare const StyleXThemeTag: unique symbol;
|
|
124
173
|
export type Theme<
|
|
125
|
-
Tokens extends { [key:
|
|
174
|
+
Tokens extends { [key: NonDollarStr]: unknown },
|
|
126
175
|
ID extends symbol = symbol,
|
|
127
|
-
> = Readonly<{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
_tokens: Tokens;
|
|
132
|
-
};
|
|
176
|
+
> = Readonly<{ [_Key in keyof Tokens]: string }> & {
|
|
177
|
+
$opaqueId: ID;
|
|
178
|
+
$tokens: Tokens;
|
|
179
|
+
} & typeof StyleXThemeTag;
|
|
133
180
|
|
|
134
|
-
export type TokensFromTheme<T extends Theme<TTokens>> = T['
|
|
181
|
+
export type TokensFromTheme<T extends Theme<TTokens>> = T['$tokens'];
|
|
135
182
|
|
|
136
|
-
export type IDFromTheme<T extends Theme<TTokens>> = T['
|
|
183
|
+
export type IDFromTheme<T extends Theme<TTokens>> = T['$opaqueId'];
|
|
184
|
+
|
|
185
|
+
type TTokens = {
|
|
186
|
+
[key: NonDollarStr]: string | { default: string; [key: AtRuleStr]: string };
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type FlattenTokens<T extends TTokens> = Readonly<{
|
|
190
|
+
[Key in keyof T]: T[Key] extends { [key: string]: infer X } ? X : T[Key];
|
|
191
|
+
}>;
|
|
137
192
|
|
|
138
193
|
export type StyleX$CreateVars = <
|
|
139
194
|
DefaultTokens extends TTokens,
|
|
@@ -146,14 +201,15 @@ export type Variant<
|
|
|
146
201
|
T extends Theme<TTokens, symbol>,
|
|
147
202
|
// eslint-disable-next-line no-unused-vars
|
|
148
203
|
Tag extends symbol = symbol,
|
|
149
|
-
> =
|
|
150
|
-
|
|
151
|
-
|
|
204
|
+
> = Tag &
|
|
205
|
+
Readonly<{
|
|
206
|
+
theme: StyleXClassNameFor<string, IDFromTheme<T>>;
|
|
207
|
+
}>;
|
|
152
208
|
|
|
153
|
-
type OverridesForTokenType<Config extends { [key: string]:
|
|
209
|
+
type OverridesForTokenType<Config extends { [key: string]: any }> = {
|
|
154
210
|
[Key in keyof Config]:
|
|
155
211
|
| Config[Key]
|
|
156
|
-
| { default: Config[Key]; [atRule:
|
|
212
|
+
| { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
|
|
157
213
|
};
|
|
158
214
|
|
|
159
215
|
export type StyleX$OverrideVars = <
|
package/lib/StyleXTypes.js.flow
CHANGED
|
@@ -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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
':
|
|
27
|
-
':
|
|
28
|
-
':
|
|
29
|
-
':
|
|
30
|
-
':
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
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)'?:
|
|
40
|
-
'@media (min-height: 700px)'?:
|
|
41
|
-
'@media (min-height: 700px) and (max-height: 789px)'?:
|
|
42
|
-
'@media (min-height: 753px) and (max-height: 789px)'?:
|
|
43
|
-
'@media (min-height: 790px)'?:
|
|
44
|
-
'@media (max-width: 648px)'?:
|
|
45
|
-
'@media (max-width: 899px)'?:
|
|
46
|
-
'@media (max-width: 900px)'?:
|
|
47
|
-
'@media (min-width: 900px)'?:
|
|
48
|
-
'@media (min-width: 900px) and (max-width: 1259px)'?:
|
|
49
|
-
'@media (max-width: 1099px)'?:
|
|
50
|
-
'@media (max-width: 1199px)'?:
|
|
51
|
-
'@media (max-width: 1259px)'?:
|
|
52
|
-
'@media (min-width: 1290px)'?:
|
|
53
|
-
'@media (max-width: 420px)'?:
|
|
54
|
-
'@media (max-width: 500px)'?:
|
|
55
|
-
'@media (pointer: coarse)'?:
|
|
56
|
-
'@media (-webkit-min-device-pixel-ratio: 0)'?:
|
|
57
|
-
'@media print'?:
|
|
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)'?:
|
|
60
|
-
'@media (min-width: 768px)'?:
|
|
61
|
-
'@media (min-width: 768px) and (max-width: 1024px)'?:
|
|
62
|
-
'@media (max-width: 1024px)'?:
|
|
63
|
-
'@media (min-width: 1025px)'?:
|
|
64
|
-
'@media (min-width: 1025px) and (max-width: 1920px)'?:
|
|
65
|
-
'@media (max-width: 1920px)'?:
|
|
66
|
-
'@media (min-width: 1921px)'?:
|
|
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)'?:
|
|
69
|
-
'@media (min-width: 1800px)'?:
|
|
70
|
-
'@media (min-width: 2250px)'?:
|
|
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'?:
|
|
73
|
-
'::-webkit-search-cancel-button'?:
|
|
74
|
-
'::-webkit-search-results-button'?:
|
|
75
|
-
'::-webkit-search-results-decoration'?:
|
|
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)'?:
|
|
74
|
+
'@media (min-width: 950px)'?: CSSProperties,
|
|
78
75
|
// Media queries used for bizweb
|
|
79
|
-
'@media (min-width: 1440px)'?:
|
|
80
|
-
'@media (min-width: 1920px)'?:
|
|
76
|
+
'@media (min-width: 1440px)'?: CSSProperties,
|
|
77
|
+
'@media (min-width: 1920px)'?: CSSProperties,
|
|
81
78
|
// Media queries used for fbai
|
|
82
|
-
'@media (min-width: 800px)'?:
|
|
79
|
+
'@media (min-width: 800px)'?: CSSProperties,
|
|
83
80
|
// Media queries used for messengerkidsdotcom
|
|
84
|
-
'@media (max-width: 1024px) and (min-width: 501px)'?:
|
|
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<
|
|
89
|
-
|
|
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,24 +97,31 @@ export type Keyframes = $ReadOnly<{ [name: string]: CSSProperties, ... }>;
|
|
|
94
97
|
|
|
95
98
|
export type LegacyTheme = $ReadOnly<{ [constantName: string]: string, ... }>;
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
export type MapNamespaces = <CSS: { ... }>(CSS) => MapNamespace<CSS>;
|
|
111
|
-
|
|
112
|
-
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 }>(
|
|
113
123
|
styles: S,
|
|
114
|
-
) =>
|
|
124
|
+
) => MapNamespaces<S>;
|
|
115
125
|
|
|
116
126
|
export type CompiledStyles = $ReadOnly<{
|
|
117
127
|
$$css: true,
|
|
@@ -120,15 +130,47 @@ export type CompiledStyles = $ReadOnly<{
|
|
|
120
130
|
| $ReadOnly<{ [key: string]: StyleXClassName, ... }>,
|
|
121
131
|
...
|
|
122
132
|
}>;
|
|
133
|
+
export type InlineStyles = $ReadOnly<{
|
|
134
|
+
$$css?: void,
|
|
135
|
+
[key: string]: string,
|
|
136
|
+
}>;
|
|
123
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
|
+
>;
|
|
124
166
|
// This is the type for the variables object
|
|
125
|
-
declare export opaque type
|
|
167
|
+
declare export opaque type StyleXVar<+_Val: mixed>;
|
|
126
168
|
|
|
127
169
|
declare export opaque type Theme<
|
|
128
170
|
+Tokens: { +[string]: mixed },
|
|
129
171
|
// eslint-disable-next-line no-unused-vars
|
|
130
172
|
+ID: string = string,
|
|
131
|
-
>: $ReadOnly<{ [
|
|
173
|
+
>: $ReadOnly<{ [Key in keyof Tokens]: StyleXVar<Tokens[Key]> }>;
|
|
132
174
|
|
|
133
175
|
export type TokensFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
|
|
134
176
|
infer Tokens,
|
|
@@ -142,22 +184,17 @@ type IDFromTheme<T: Theme<{ +[string]: mixed }>> = T extends Theme<
|
|
|
142
184
|
? ID
|
|
143
185
|
: empty;
|
|
144
186
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
> = {
|
|
187
|
+
type TTokens = $ReadOnly<{
|
|
188
|
+
[string]: string | $ReadOnly<{ default: string, [string]: string }>,
|
|
189
|
+
}>;
|
|
190
|
+
|
|
191
|
+
export type FlattenTokens<T: TTokens> = {
|
|
150
192
|
+[Key in keyof T]: T[Key] extends { +default: infer X, +[string]: infer Y }
|
|
151
193
|
? X | Y
|
|
152
194
|
: T[Key],
|
|
153
195
|
};
|
|
154
196
|
|
|
155
|
-
export type StyleX$CreateVars = <
|
|
156
|
-
+DefaultTokens: {
|
|
157
|
-
+[string]: string | { default: string, +[string]: string },
|
|
158
|
-
},
|
|
159
|
-
+ID: string = string,
|
|
160
|
-
>(
|
|
197
|
+
export type StyleX$CreateVars = <DefaultTokens: TTokens, ID: string = string>(
|
|
161
198
|
tokens: DefaultTokens,
|
|
162
199
|
) => Theme<FlattenTokens<DefaultTokens>, ID>;
|
|
163
200
|
|
|
@@ -176,8 +213,8 @@ export type OverridesForTokenType<Config: { +[string]: mixed }> = {
|
|
|
176
213
|
};
|
|
177
214
|
|
|
178
215
|
export type StyleX$OverrideVars = <
|
|
179
|
-
|
|
180
|
-
|
|
216
|
+
BaseTokens: Theme<{ +[string]: mixed }>,
|
|
217
|
+
ID: string = string,
|
|
181
218
|
>(
|
|
182
219
|
baseTokens: BaseTokens,
|
|
183
220
|
overrides: OverridesForTokenType<TokensFromTheme<BaseTokens>>,
|
|
@@ -7,8 +7,20 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
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
|
-
|
|
24
|
+
defaultValue: unknown;
|
|
25
|
+
constructor(kebabCasePropName: string, fallback: unknown);
|
|
14
26
|
}
|
|
@@ -4,22 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CSSCustomPropertyValue = void 0;
|
|
7
|
-
exports.
|
|
8
|
-
const CUSTOM_PROPERTY_REGEX = /^var\(--(.+)\)$/;
|
|
7
|
+
exports.createCSSCustomPropertyValue = createCSSCustomPropertyValue;
|
|
8
|
+
const CUSTOM_PROPERTY_REGEX = /^var\(--([\w-]+) *(?:\)|, *(.+)\))$/;
|
|
9
9
|
function camelize(s) {
|
|
10
10
|
return s.replace(/-./g, x => x.toUpperCase()[1]);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function createCSSCustomPropertyValue(value) {
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
const match = CUSTOM_PROPERTY_REGEX.exec(value);
|
|
15
|
+
if (match) {
|
|
16
|
+
return new CSSCustomPropertyValue(match[1], match[2]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
14
20
|
}
|
|
15
21
|
class CSSCustomPropertyValue {
|
|
16
|
-
constructor(
|
|
17
|
-
const found = value.match(CUSTOM_PROPERTY_REGEX);
|
|
18
|
-
if (found == null) {
|
|
19
|
-
throw new Error("[stylex]: Unable to find custom property reference in input string");
|
|
20
|
-
}
|
|
21
|
-
const [, kebabCasePropName] = found;
|
|
22
|
+
constructor(kebabCasePropName, fallback) {
|
|
22
23
|
this.name = camelize(kebabCasePropName);
|
|
24
|
+
this.defaultValue = fallback ?? null;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
exports.CSSCustomPropertyValue = CSSCustomPropertyValue;
|
|
@@ -7,9 +7,21 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
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
|
+
declare export function createCSSCustomPropertyValue(
|
|
17
|
+
value: string,
|
|
18
|
+
): CSSCustomPropertyValue | null;
|
|
11
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Class representing a custom property value with an optional fallback.
|
|
22
|
+
*/
|
|
12
23
|
declare export class CSSCustomPropertyValue {
|
|
13
24
|
name: string;
|
|
14
|
-
|
|
25
|
+
defaultValue: mixed;
|
|
26
|
+
constructor(kebabCasePropName: string, fallback: mixed): void;
|
|
15
27
|
}
|