@stylexjs/stylex 0.11.1 → 0.13.0
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/README.md +0 -27
- package/lib/{stylex-inject.d.ts → cjs/inject.d.ts} +1 -5
- package/lib/cjs/inject.js +210 -0
- package/lib/{stylex-inject.js.flow → cjs/inject.js.flow} +2 -3
- package/lib/cjs/stylesheet/createCSSStyleSheet.d.ts +13 -0
- package/lib/cjs/stylesheet/createCSSStyleSheet.js.flow +13 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
- package/lib/cjs/stylesheet/createSheet.d.ts +12 -0
- package/lib/cjs/stylesheet/createSheet.js.flow +16 -0
- package/lib/cjs/stylesheet/utils.d.ts +18 -0
- package/lib/cjs/stylesheet/utils.js.flow +19 -0
- package/lib/{stylex.d.ts → cjs/stylex.d.ts} +8 -21
- package/lib/cjs/stylex.js +242 -0
- package/lib/{stylex.js.flow → cjs/stylex.js.flow} +10 -26
- package/lib/{StyleXCSSTypes.d.ts → cjs/types/StyleXCSSTypes.d.ts} +22 -0
- package/lib/{StyleXCSSTypes.js.flow → cjs/types/StyleXCSSTypes.js.flow} +25 -0
- package/lib/{StyleXTypes.d.ts → cjs/types/StyleXTypes.d.ts} +60 -5
- package/lib/{StyleXTypes.js.flow → cjs/types/StyleXTypes.js.flow} +56 -5
- package/lib/{VarTypes.d.ts → cjs/types/VarTypes.d.ts} +19 -18
- package/lib/{VarTypes.js.flow → cjs/types/VarTypes.js.flow} +17 -19
- package/lib/es/inject.d.ts +11 -0
- package/lib/es/inject.js.flow +13 -0
- package/lib/es/inject.mjs +208 -0
- package/lib/es/stylesheet/createCSSStyleSheet.d.ts +13 -0
- package/lib/es/stylesheet/createCSSStyleSheet.js.flow +13 -0
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
- package/lib/es/stylesheet/createSheet.d.ts +12 -0
- package/lib/es/stylesheet/createSheet.js.flow +16 -0
- package/lib/es/stylesheet/utils.d.ts +18 -0
- package/lib/es/stylesheet/utils.js.flow +19 -0
- package/lib/es/stylex.d.ts +135 -0
- package/lib/es/stylex.js.flow +134 -0
- package/lib/es/stylex.mjs +8 -20
- package/lib/es/types/StyleXCSSTypes.d.ts +1487 -0
- package/lib/es/types/StyleXCSSTypes.js.flow +1580 -0
- package/lib/es/types/StyleXOpaqueTypes.d.ts +11 -0
- package/lib/es/types/StyleXOpaqueTypes.js.flow +16 -0
- package/lib/es/types/StyleXTypes.d.ts +292 -0
- package/lib/es/types/StyleXTypes.js.flow +240 -0
- package/lib/es/types/StyleXUtils.d.ts +15 -0
- package/lib/es/types/StyleXUtils.js.flow +15 -0
- package/lib/es/types/VarTypes.d.ts +104 -0
- package/lib/es/types/VarTypes.js.flow +102 -0
- package/package.json +20 -28
- package/lib/StyleXCSSTypes.js +0 -1
- package/lib/StyleXOpaqueTypes.js +0 -1
- package/lib/StyleXSheet.d.ts +0 -49
- package/lib/StyleXSheet.js +0 -188
- package/lib/StyleXSheet.js.flow +0 -49
- package/lib/StyleXTypes.js +0 -1
- package/lib/VarTypes.js +0 -1
- package/lib/es/StyleXCSSTypes.mjs +0 -1
- package/lib/es/StyleXOpaqueTypes.mjs +0 -0
- package/lib/es/StyleXSheet.mjs +0 -247
- package/lib/es/StyleXTypes.mjs +0 -1
- package/lib/es/VarTypes.mjs +0 -0
- package/lib/es/stylex-inject.mjs +0 -5
- package/lib/es/util-types.mjs +0 -0
- package/lib/stylex-inject.js +0 -11
- package/lib/stylex.js +0 -125
- package/lib/util-types.js +0 -1
- /package/lib/{StyleXOpaqueTypes.d.ts → cjs/types/StyleXOpaqueTypes.d.ts} +0 -0
- /package/lib/{StyleXOpaqueTypes.js.flow → cjs/types/StyleXOpaqueTypes.js.flow} +0 -0
- /package/lib/{util-types.d.ts → cjs/types/StyleXUtils.d.ts} +0 -0
- /package/lib/{util-types.js.flow → cjs/types/StyleXUtils.js.flow} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export declare type StyleXVar<_Val extends unknown> = string;
|
|
11
|
+
export declare type StyleXClassNameFor<_K, _V> = string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// declare class Var<+T> {
|
|
11
|
+
// value: T;
|
|
12
|
+
// }
|
|
13
|
+
// This is the type for the variables object
|
|
14
|
+
declare export opaque type StyleXVar<+_Val: mixed>: string;
|
|
15
|
+
|
|
16
|
+
declare export opaque type StyleXClassNameFor<+_K, +_V>: string;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CSSType } from './VarTypes';
|
|
9
|
+
import type { CSSProperties } from './StyleXCSSTypes';
|
|
10
|
+
|
|
11
|
+
// Using an opaque type to declare ClassNames generated by stylex.
|
|
12
|
+
declare const StyleXClassNameTag: unique symbol;
|
|
13
|
+
export type StyleXClassNameFor<K, V> = string & {
|
|
14
|
+
_opaque: typeof StyleXClassNameTag;
|
|
15
|
+
_key: K;
|
|
16
|
+
_value: V;
|
|
17
|
+
};
|
|
18
|
+
declare const StyleXVarTag: unique symbol;
|
|
19
|
+
declare class _StyleXVar<out Val> {
|
|
20
|
+
private _opaque: typeof StyleXVarTag;
|
|
21
|
+
private _value: Val;
|
|
22
|
+
}
|
|
23
|
+
export type StyleXVar<Val> = _StyleXVar<Val> & string;
|
|
24
|
+
|
|
25
|
+
export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
|
|
26
|
+
export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
|
|
27
|
+
export type StyleXClassName = StyleXClassNameFor<any, any>;
|
|
28
|
+
// Type for arbitrarily nested Array.
|
|
29
|
+
export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
|
|
30
|
+
|
|
31
|
+
type PseudoClassStr = `:${string}`;
|
|
32
|
+
type AtRuleStr = `@${string}`;
|
|
33
|
+
|
|
34
|
+
type CondStr = PseudoClassStr | AtRuleStr;
|
|
35
|
+
|
|
36
|
+
type CSSPropertiesWithExtras = Partial<
|
|
37
|
+
Readonly<
|
|
38
|
+
CSSProperties & {
|
|
39
|
+
'::after': CSSProperties;
|
|
40
|
+
'::backdrop': CSSProperties;
|
|
41
|
+
'::before': CSSProperties;
|
|
42
|
+
'::cue': CSSProperties;
|
|
43
|
+
'::cue-region': CSSProperties;
|
|
44
|
+
'::first-letter': CSSProperties;
|
|
45
|
+
'::first-line': CSSProperties;
|
|
46
|
+
'::file-selector-button': CSSProperties;
|
|
47
|
+
'::grammar-error': CSSProperties;
|
|
48
|
+
'::marker': CSSProperties;
|
|
49
|
+
// This is a pattern and not a static key so it cannot be typed correctly.
|
|
50
|
+
// [key: `::part(${string})` | `::slotted(${string})`]: CSSProperties;
|
|
51
|
+
'::placeholder': CSSProperties;
|
|
52
|
+
'::selection': CSSProperties;
|
|
53
|
+
// This is a pattern and not a static key so it cannot be typed correctly.
|
|
54
|
+
// '::slotted()': CSSProperties;
|
|
55
|
+
'::spelling-error': CSSProperties;
|
|
56
|
+
'::target-text': CSSProperties;
|
|
57
|
+
'::-webkit-scrollbar'?: CSSProperties;
|
|
58
|
+
'::-webkit-scrollbar-button'?: CSSProperties;
|
|
59
|
+
'::-webkit-scrollbar-thumb'?: CSSProperties;
|
|
60
|
+
'::-webkit-scrollbar-track'?: CSSProperties;
|
|
61
|
+
'::-webkit-scrollbar-track-piece'?: CSSProperties;
|
|
62
|
+
'::-webkit-scrollbar-corner'?: CSSProperties;
|
|
63
|
+
'::-webkit-resizer'?: CSSProperties;
|
|
64
|
+
// webkit styles used for Search in Safari
|
|
65
|
+
'::-webkit-search-decoration'?: CSSProperties;
|
|
66
|
+
'::-webkit-search-cancel-button'?: CSSProperties;
|
|
67
|
+
'::-webkit-search-results-button'?: CSSProperties;
|
|
68
|
+
'::-webkit-search-results-decoration'?: CSSProperties;
|
|
69
|
+
// For input ranges in Chromium
|
|
70
|
+
'::-webkit-slider-thumb'?: CSSProperties;
|
|
71
|
+
'::-webkit-slider-runnable-track'?: CSSProperties;
|
|
72
|
+
// For input ranges in Firefox
|
|
73
|
+
'::-moz-range-thumb'?: CSSProperties;
|
|
74
|
+
'::-moz-range-track'?: CSSProperties;
|
|
75
|
+
'::-moz-range-progress'?: CSSProperties;
|
|
76
|
+
}
|
|
77
|
+
>
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
export type NestedCSSPropTypes = Partial<
|
|
81
|
+
Readonly<{
|
|
82
|
+
[Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor<
|
|
83
|
+
Key,
|
|
84
|
+
CSSPropertiesWithExtras[Key]
|
|
85
|
+
>;
|
|
86
|
+
}>
|
|
87
|
+
>;
|
|
88
|
+
|
|
89
|
+
type UserAuthoredStyles = CSSPropertiesWithExtras | { [key: string]: unknown };
|
|
90
|
+
export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
|
|
91
|
+
// NOTE: `XStyle` has been deprecated in favor of `StaticStyles` and `StyleXStyles`.
|
|
92
|
+
|
|
93
|
+
export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
|
|
94
|
+
|
|
95
|
+
export type PositionTry = Readonly<{
|
|
96
|
+
// Anchor Positioning Properties
|
|
97
|
+
positionAnchor?: CSSProperties['positionAnchor'],
|
|
98
|
+
positionArea?: CSSProperties['positionArea'],
|
|
99
|
+
// inset Properties
|
|
100
|
+
top?: CSSProperties['top'],
|
|
101
|
+
right?: CSSProperties['right'],
|
|
102
|
+
bottom?: CSSProperties['bottom'],
|
|
103
|
+
left?: CSSProperties['left'],
|
|
104
|
+
inset?: CSSProperties['inset'],
|
|
105
|
+
insetBlock?: CSSProperties['insetBlock'],
|
|
106
|
+
insetBlockEnd?: CSSProperties['insetBlockEnd'],
|
|
107
|
+
insetBlockStart?: CSSProperties['insetBlockStart'],
|
|
108
|
+
insetInline?: CSSProperties['insetInline'],
|
|
109
|
+
insetInlineEnd?: CSSProperties['insetInlineEnd'],
|
|
110
|
+
insetInlineStart?: CSSProperties['insetInlineStart'],
|
|
111
|
+
// margin Properties
|
|
112
|
+
margin?: CSSProperties['margin'],
|
|
113
|
+
marginBlock?: CSSProperties['marginBlock'],
|
|
114
|
+
marginBlockEnd?: CSSProperties['marginBlockEnd'],
|
|
115
|
+
marginBlockStart?: CSSProperties['marginBlockStart'],
|
|
116
|
+
marginInline?: CSSProperties['marginInline'],
|
|
117
|
+
marginInlineEnd?: CSSProperties['marginInlineEnd'],
|
|
118
|
+
marginInlineStart?: CSSProperties['marginInlineStart'],
|
|
119
|
+
marginTop?: CSSProperties['marginTop'],
|
|
120
|
+
marginBottom?: CSSProperties['marginBottom'],
|
|
121
|
+
marginLeft?: CSSProperties['marginLeft'],
|
|
122
|
+
marginRight?: CSSProperties['marginRight'],
|
|
123
|
+
// size properties
|
|
124
|
+
width?: CSSProperties['width'],
|
|
125
|
+
height?: CSSProperties['height'],
|
|
126
|
+
minWidth?: CSSProperties['minWidth'],
|
|
127
|
+
minHeight?: CSSProperties['minHeight'],
|
|
128
|
+
maxWidth?: CSSProperties['maxWidth'],
|
|
129
|
+
maxHeight?: CSSProperties['maxHeight'],
|
|
130
|
+
blockSize?: CSSProperties['blockSize'],
|
|
131
|
+
inlineSize?: CSSProperties['inlineSize'],
|
|
132
|
+
minBlockSize?: CSSProperties['minBlockSize'],
|
|
133
|
+
minInlineSize?: CSSProperties['minInlineSize'],
|
|
134
|
+
maxBlockSize?: CSSProperties['maxBlockSize'],
|
|
135
|
+
maxInlineSize?: CSSProperties['maxInlineSize'],
|
|
136
|
+
// self alignment properties
|
|
137
|
+
alignSelf?: CSSProperties['alignSelf'],
|
|
138
|
+
justifySelf?: CSSProperties['justifySelf'],
|
|
139
|
+
placeSelf?: CSSProperties['placeSelf'],
|
|
140
|
+
}>;
|
|
141
|
+
|
|
142
|
+
export type LegacyThemeStyles = Readonly<{ [constantName: string]: string }>;
|
|
143
|
+
|
|
144
|
+
type ComplexStyleValueType<T> =
|
|
145
|
+
T extends StyleXVar<infer U>
|
|
146
|
+
? U
|
|
147
|
+
: T extends string | number | null
|
|
148
|
+
? T
|
|
149
|
+
: T extends ReadonlyArray<infer U>
|
|
150
|
+
? ComplexStyleValueType<U>
|
|
151
|
+
: T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }>
|
|
152
|
+
? ComplexStyleValueType<A> | ComplexStyleValueType<B>
|
|
153
|
+
: T;
|
|
154
|
+
|
|
155
|
+
export type MapNamespace<CSS> = Readonly<{
|
|
156
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>;
|
|
157
|
+
}>;
|
|
158
|
+
|
|
159
|
+
export type MapNamespaces<
|
|
160
|
+
S extends {
|
|
161
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
162
|
+
},
|
|
163
|
+
> = Readonly<{
|
|
164
|
+
[Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
|
|
165
|
+
? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
|
|
166
|
+
: MapNamespace<S[Key]>;
|
|
167
|
+
}>;
|
|
168
|
+
|
|
169
|
+
export type StyleX$Create = <
|
|
170
|
+
const S extends {
|
|
171
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
172
|
+
},
|
|
173
|
+
>(
|
|
174
|
+
styles: S,
|
|
175
|
+
) => MapNamespaces<S>;
|
|
176
|
+
|
|
177
|
+
export type CompiledStyles =
|
|
178
|
+
| Readonly<{
|
|
179
|
+
[key: string]: StyleXClassName | null | void | never;
|
|
180
|
+
}>
|
|
181
|
+
| Readonly<{
|
|
182
|
+
theme: StyleXClassName;
|
|
183
|
+
}>;
|
|
184
|
+
|
|
185
|
+
declare const StyleXInlineStylesTag: unique symbol;
|
|
186
|
+
|
|
187
|
+
export type InlineStyles = typeof StyleXInlineStylesTag;
|
|
188
|
+
|
|
189
|
+
type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
|
|
190
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
|
|
191
|
+
}>;
|
|
192
|
+
type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
|
|
193
|
+
_GenStylePropType<CSS> &
|
|
194
|
+
Partial<{
|
|
195
|
+
[Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
|
|
196
|
+
}>
|
|
197
|
+
>;
|
|
198
|
+
|
|
199
|
+
// Replace `XStyle` with this.
|
|
200
|
+
export type StaticStyles<
|
|
201
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
202
|
+
> = StyleXArray<false | null | undefined | GenStylePropType<CSS>>;
|
|
203
|
+
|
|
204
|
+
export type StaticStylesWithout<CSS extends UserAuthoredStyles> = StaticStyles<
|
|
205
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
206
|
+
>;
|
|
207
|
+
|
|
208
|
+
export type StyleXStyles<
|
|
209
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
210
|
+
> = StyleXArray<
|
|
211
|
+
| null
|
|
212
|
+
| undefined
|
|
213
|
+
| false
|
|
214
|
+
| GenStylePropType<CSS>
|
|
215
|
+
| Readonly<[GenStylePropType<CSS>, InlineStyles]>
|
|
216
|
+
>;
|
|
217
|
+
export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
|
|
218
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
219
|
+
>;
|
|
220
|
+
|
|
221
|
+
declare const StyleXVarGroupTag: unique symbol;
|
|
222
|
+
export type VarGroup<
|
|
223
|
+
Tokens extends { [key: string]: any },
|
|
224
|
+
ID extends symbol = symbol,
|
|
225
|
+
> = Readonly<{
|
|
226
|
+
[Key in keyof Tokens]: StyleXVar<Tokens[Key]>;
|
|
227
|
+
}> &
|
|
228
|
+
Readonly<{
|
|
229
|
+
__opaqueId: ID;
|
|
230
|
+
__tokens: Tokens;
|
|
231
|
+
}> &
|
|
232
|
+
typeof StyleXVarGroupTag;
|
|
233
|
+
|
|
234
|
+
export type TokensFromVarGroup<T extends VarGroup<{}>> = T['__tokens'];
|
|
235
|
+
|
|
236
|
+
export type IDFromVarGroup<T extends VarGroup<{}>> =
|
|
237
|
+
T['__opaqueId'];
|
|
238
|
+
|
|
239
|
+
type TTokens = Readonly<{
|
|
240
|
+
[key: string]: CSSType<null | string | number> | string | { [key: string]: string };
|
|
241
|
+
}>;
|
|
242
|
+
|
|
243
|
+
type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
|
|
244
|
+
export type FlattenTokens<T extends TTokens> = Readonly<{
|
|
245
|
+
[Key in keyof T]: T[Key] extends { [key: string]: infer X }
|
|
246
|
+
? UnwrapVars<X>
|
|
247
|
+
: UnwrapVars<T[Key]>;
|
|
248
|
+
}>;
|
|
249
|
+
|
|
250
|
+
type NestedVarObject<T> =
|
|
251
|
+
| T
|
|
252
|
+
| Readonly<{
|
|
253
|
+
default: NestedVarObject<T>;
|
|
254
|
+
[key: `@${string}`]: NestedVarObject<T>;
|
|
255
|
+
}>;
|
|
256
|
+
|
|
257
|
+
export type StyleX$DefineConsts = <
|
|
258
|
+
DefaultTokens extends TTokens,
|
|
259
|
+
ID extends symbol = symbol,
|
|
260
|
+
>(
|
|
261
|
+
tokens: DefaultTokens,
|
|
262
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
263
|
+
|
|
264
|
+
export type StyleX$DefineVars = <
|
|
265
|
+
DefaultTokens extends TTokens,
|
|
266
|
+
ID extends symbol = symbol,
|
|
267
|
+
>(
|
|
268
|
+
tokens: DefaultTokens,
|
|
269
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
270
|
+
|
|
271
|
+
declare class ThemeKey<out VG extends VarGroup<{}>> extends String {
|
|
272
|
+
private varGroup: VG;
|
|
273
|
+
}
|
|
274
|
+
export type Theme<
|
|
275
|
+
T extends VarGroup<{}>,
|
|
276
|
+
Tag extends symbol = symbol,
|
|
277
|
+
> = Tag &
|
|
278
|
+
Readonly<{
|
|
279
|
+
theme: StyleXClassNameFor<ThemeKey<T>, IDFromVarGroup<T>>;
|
|
280
|
+
}>;
|
|
281
|
+
|
|
282
|
+
type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
|
|
283
|
+
[Key in keyof Config]?: NestedVarObject<Config[Key]>;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export type StyleX$CreateTheme = <
|
|
287
|
+
TVars extends VarGroup<{}>,
|
|
288
|
+
ThemeID extends symbol = symbol,
|
|
289
|
+
>(
|
|
290
|
+
baseTokens: TVars,
|
|
291
|
+
overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
|
|
292
|
+
) => Theme<TVars, ThemeID>;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CSSProperties } from './StyleXCSSTypes';
|
|
11
|
+
import type { StyleXClassNameFor, StyleXVar } from './StyleXOpaqueTypes';
|
|
12
|
+
import type { CSSType } from './VarTypes';
|
|
13
|
+
|
|
14
|
+
export type { StyleXClassNameFor, StyleXVar } from './StyleXOpaqueTypes';
|
|
15
|
+
|
|
16
|
+
// Using an opaque type to declare ClassNames generated by stylex.
|
|
17
|
+
export type StyleXClassNameForValue<+V> = StyleXClassNameFor<mixed, V>;
|
|
18
|
+
export type StyleXClassNameForKey<+K> = StyleXClassNameFor<K, mixed>;
|
|
19
|
+
export type StyleXClassName = StyleXClassNameFor<mixed, mixed>;
|
|
20
|
+
|
|
21
|
+
// Type for arbitrarily nested Array.
|
|
22
|
+
export type StyleXArray<+T> = T | $ReadOnlyArray<StyleXArray<T>>;
|
|
23
|
+
|
|
24
|
+
type CSSPropertiesWithExtras = $ReadOnly<{
|
|
25
|
+
...CSSProperties,
|
|
26
|
+
'::before'?: CSSProperties,
|
|
27
|
+
'::after'?: CSSProperties,
|
|
28
|
+
'::backdrop'?: CSSProperties,
|
|
29
|
+
'::cue'?: CSSProperties,
|
|
30
|
+
'::cue-region'?: CSSProperties,
|
|
31
|
+
'::first-letter'?: CSSProperties,
|
|
32
|
+
'::first-line'?: CSSProperties,
|
|
33
|
+
'::file-selector-button'?: CSSProperties,
|
|
34
|
+
'::grammar-error'?: CSSProperties,
|
|
35
|
+
'::marker'?: CSSProperties,
|
|
36
|
+
'::placeholder'?: CSSProperties,
|
|
37
|
+
'::selection'?: CSSProperties,
|
|
38
|
+
'::spelling-error'?: CSSProperties,
|
|
39
|
+
'::target-text'?: CSSProperties,
|
|
40
|
+
'::-webkit-scrollbar'?: CSSProperties,
|
|
41
|
+
// webkit styles used for Search in Safari
|
|
42
|
+
'::-webkit-search-decoration'?: CSSProperties,
|
|
43
|
+
'::-webkit-search-cancel-button'?: CSSProperties,
|
|
44
|
+
'::-webkit-search-results-button'?: CSSProperties,
|
|
45
|
+
'::-webkit-search-results-decoration'?: CSSProperties,
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
export type NestedCSSPropTypes = $ReadOnly<{
|
|
49
|
+
[Key in keyof CSSPropertiesWithExtras]?: StyleXClassNameForKey<Key>,
|
|
50
|
+
}>;
|
|
51
|
+
|
|
52
|
+
export type StyleXSingleStyle = false | ?NestedCSSPropTypes;
|
|
53
|
+
export type XStyle<+T = NestedCSSPropTypes> = StyleXArray<
|
|
54
|
+
false | ?$ReadOnly<{ ...T, $$css: true }>,
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
export type XStyleWithout<+T: { +[_K in keyof NestedCSSPropTypes]?: mixed }> =
|
|
58
|
+
XStyle<$ReadOnly<Omit<NestedCSSPropTypes, $Keys<T>>>>;
|
|
59
|
+
|
|
60
|
+
export type Keyframes = $ReadOnly<{ [name: string]: CSSProperties, ... }>;
|
|
61
|
+
|
|
62
|
+
export type PositionTry = $ReadOnly<{
|
|
63
|
+
// Anchor Positioning Properties
|
|
64
|
+
positionAnchor?: CSSProperties['positionAnchor'],
|
|
65
|
+
positionArea?: CSSProperties['positionArea'],
|
|
66
|
+
// inset Properties
|
|
67
|
+
top?: CSSProperties['top'],
|
|
68
|
+
right?: CSSProperties['right'],
|
|
69
|
+
bottom?: CSSProperties['bottom'],
|
|
70
|
+
left?: CSSProperties['left'],
|
|
71
|
+
inset?: CSSProperties['inset'],
|
|
72
|
+
insetBlock?: CSSProperties['insetBlock'],
|
|
73
|
+
insetBlockEnd?: CSSProperties['insetBlockEnd'],
|
|
74
|
+
insetBlockStart?: CSSProperties['insetBlockStart'],
|
|
75
|
+
insetInline?: CSSProperties['insetInline'],
|
|
76
|
+
insetInlineEnd?: CSSProperties['insetInlineEnd'],
|
|
77
|
+
insetInlineStart?: CSSProperties['insetInlineStart'],
|
|
78
|
+
// margin Properties
|
|
79
|
+
margin?: CSSProperties['margin'],
|
|
80
|
+
marginBlock?: CSSProperties['marginBlock'],
|
|
81
|
+
marginBlockEnd?: CSSProperties['marginBlockEnd'],
|
|
82
|
+
marginBlockStart?: CSSProperties['marginBlockStart'],
|
|
83
|
+
marginInline?: CSSProperties['marginInline'],
|
|
84
|
+
marginInlineEnd?: CSSProperties['marginInlineEnd'],
|
|
85
|
+
marginInlineStart?: CSSProperties['marginInlineStart'],
|
|
86
|
+
marginTop?: CSSProperties['marginTop'],
|
|
87
|
+
marginBottom?: CSSProperties['marginBottom'],
|
|
88
|
+
marginLeft?: CSSProperties['marginLeft'],
|
|
89
|
+
marginRight?: CSSProperties['marginRight'],
|
|
90
|
+
// size properties
|
|
91
|
+
width?: CSSProperties['width'],
|
|
92
|
+
height?: CSSProperties['height'],
|
|
93
|
+
minWidth?: CSSProperties['minWidth'],
|
|
94
|
+
minHeight?: CSSProperties['minHeight'],
|
|
95
|
+
maxWidth?: CSSProperties['maxWidth'],
|
|
96
|
+
maxHeight?: CSSProperties['maxHeight'],
|
|
97
|
+
blockSize?: CSSProperties['blockSize'],
|
|
98
|
+
inlineSize?: CSSProperties['inlineSize'],
|
|
99
|
+
minBlockSize?: CSSProperties['minBlockSize'],
|
|
100
|
+
minInlineSize?: CSSProperties['minInlineSize'],
|
|
101
|
+
maxBlockSize?: CSSProperties['maxBlockSize'],
|
|
102
|
+
maxInlineSize?: CSSProperties['maxInlineSize'],
|
|
103
|
+
// self alignment properties
|
|
104
|
+
alignSelf?: CSSProperties['alignSelf'],
|
|
105
|
+
justifySelf?: CSSProperties['justifySelf'],
|
|
106
|
+
placeSelf?: CSSProperties['placeSelf'],
|
|
107
|
+
}>;
|
|
108
|
+
|
|
109
|
+
export type LegacyThemeStyles = $ReadOnly<{
|
|
110
|
+
[constantName: string]: string,
|
|
111
|
+
...
|
|
112
|
+
}>;
|
|
113
|
+
|
|
114
|
+
type ComplexStyleValueType<+T> =
|
|
115
|
+
T extends StyleXVar<infer U>
|
|
116
|
+
? U
|
|
117
|
+
: T extends string | number | null
|
|
118
|
+
? T
|
|
119
|
+
: T extends $ReadOnlyArray<infer U>
|
|
120
|
+
? ComplexStyleValueType<U>
|
|
121
|
+
: T extends { +default: infer A, +[string]: infer B }
|
|
122
|
+
? ComplexStyleValueType<A> | ComplexStyleValueType<B>
|
|
123
|
+
: $ReadOnly<T>;
|
|
124
|
+
|
|
125
|
+
type _MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
126
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>,
|
|
127
|
+
}>;
|
|
128
|
+
export type MapNamespace<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
129
|
+
..._MapNamespace<CSS>,
|
|
130
|
+
$$css: true,
|
|
131
|
+
}>;
|
|
132
|
+
export type MapNamespaces<+S: { +[string]: mixed }> = $ReadOnly<{
|
|
133
|
+
[Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
|
|
134
|
+
? (...args: Args) => $ReadOnly<[MapNamespace<Obj>, InlineStyles]>
|
|
135
|
+
: MapNamespace<S[Key]>,
|
|
136
|
+
}>;
|
|
137
|
+
export type StyleX$Create = <S: { +[string]: mixed }>(
|
|
138
|
+
styles: S,
|
|
139
|
+
) => MapNamespaces<S>;
|
|
140
|
+
|
|
141
|
+
export type CompiledStyles = $ReadOnly<{
|
|
142
|
+
$$css: true,
|
|
143
|
+
[key: string]: StyleXClassName,
|
|
144
|
+
}>;
|
|
145
|
+
export type InlineStyles = $ReadOnly<{
|
|
146
|
+
$$css?: void,
|
|
147
|
+
[key: string]: string,
|
|
148
|
+
}>;
|
|
149
|
+
|
|
150
|
+
type _GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
151
|
+
[Key in keyof CSS]: CSS[Key] extends { +[string]: mixed }
|
|
152
|
+
? StyleXClassNameFor<Key, $ReadOnly<CSS[Key]>>
|
|
153
|
+
: StyleXClassNameFor<Key, CSS[Key]>,
|
|
154
|
+
}>;
|
|
155
|
+
type GenStylePropType<+CSS: { +[string]: mixed }> = $ReadOnly<{
|
|
156
|
+
..._GenStylePropType<CSS>,
|
|
157
|
+
$$css: true,
|
|
158
|
+
}>;
|
|
159
|
+
|
|
160
|
+
// Replace `XStyle` with this.
|
|
161
|
+
export type StaticStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
|
|
162
|
+
StyleXArray<false | ?GenStylePropType<$ReadOnly<CSS>>>;
|
|
163
|
+
|
|
164
|
+
export type StaticStylesWithout<+CSS: { +[string]: mixed }> = StaticStyles<
|
|
165
|
+
Omit<CSSPropertiesWithExtras, $Keys<CSS>>,
|
|
166
|
+
>;
|
|
167
|
+
|
|
168
|
+
export type StyleXStyles<+CSS: { +[string]: mixed } = CSSPropertiesWithExtras> =
|
|
169
|
+
StyleXArray<
|
|
170
|
+
| ?false
|
|
171
|
+
| GenStylePropType<$ReadOnly<CSS>>
|
|
172
|
+
| $ReadOnly<[GenStylePropType<$ReadOnly<CSS>>, InlineStyles]>,
|
|
173
|
+
>;
|
|
174
|
+
|
|
175
|
+
export type StyleXStylesWithout<+CSS: { +[string]: mixed }> = StyleXStyles<
|
|
176
|
+
Omit<CSSPropertiesWithExtras, $Keys<CSS>>,
|
|
177
|
+
>;
|
|
178
|
+
|
|
179
|
+
export type VarGroup<+Tokens: { +[string]: mixed }, +_ID: string = string> = {
|
|
180
|
+
+[Key in keyof Tokens]: StyleXVar<Tokens[Key]>,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export type TokensFromVarGroup<+T: VarGroup<{ +[string]: mixed }>> = $ReadOnly<{
|
|
184
|
+
[Key in keyof T]: UnwrapVar<T[Key]>,
|
|
185
|
+
}>;
|
|
186
|
+
|
|
187
|
+
type IDFromVarGroup<+T: VarGroup<{ +[string]: mixed }>> =
|
|
188
|
+
T extends VarGroup<{ +[string]: mixed }, infer ID> ? ID : empty;
|
|
189
|
+
|
|
190
|
+
type NestedVarObject<+T> =
|
|
191
|
+
| T
|
|
192
|
+
| $ReadOnly<{
|
|
193
|
+
default: NestedVarObject<T>,
|
|
194
|
+
[string]: NestedVarObject<T>,
|
|
195
|
+
}>;
|
|
196
|
+
|
|
197
|
+
type TTokens = $ReadOnly<{
|
|
198
|
+
[string]:
|
|
199
|
+
| NestedVarObject<null | string | number>
|
|
200
|
+
| StyleXVar<null | string | number>
|
|
201
|
+
| CSSType<null | string | number>,
|
|
202
|
+
}>;
|
|
203
|
+
|
|
204
|
+
type UnwrapVar<+T> = T extends StyleXVar<infer U> ? U : T;
|
|
205
|
+
export type FlattenTokens<+T: TTokens> = {
|
|
206
|
+
+[Key in keyof T]: T[Key] extends CSSType<string | number>
|
|
207
|
+
? UnwrapVar<T[Key]>
|
|
208
|
+
: T[Key] extends { +default: infer X, +[string]: infer Y }
|
|
209
|
+
? UnwrapVar<X | Y>
|
|
210
|
+
: UnwrapVar<T[Key]>,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
|
|
214
|
+
tokens: DefaultTokens,
|
|
215
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
216
|
+
|
|
217
|
+
export type StyleX$DefineConsts = <DefaultTokens: TTokens, ID: string = string>(
|
|
218
|
+
tokens: DefaultTokens,
|
|
219
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
220
|
+
|
|
221
|
+
// opaque type ThemeKey<+_VG: VarGroup<{ +[string]: mixed }>>: string = string;
|
|
222
|
+
declare export opaque type Theme<
|
|
223
|
+
+T: VarGroup<{ +[string]: mixed }, string>,
|
|
224
|
+
+_Tag: string = string,
|
|
225
|
+
>: $ReadOnly<{
|
|
226
|
+
$$css: true,
|
|
227
|
+
theme: StyleXClassNameFor<'theme', IDFromVarGroup<T>>,
|
|
228
|
+
}>;
|
|
229
|
+
|
|
230
|
+
export type OverridesForTokenType<+Config: { +[string]: mixed }> = {
|
|
231
|
+
[Key in keyof Config]?: NestedVarObject<Config[Key]>,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export type StyleX$CreateTheme = <
|
|
235
|
+
BaseTokens: VarGroup<{ +[string]: mixed }>,
|
|
236
|
+
ID: string = string,
|
|
237
|
+
>(
|
|
238
|
+
baseTokens: BaseTokens,
|
|
239
|
+
overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
|
|
240
|
+
) => Theme<BaseTokens, ID>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type ValueWithDefault<T> =
|
|
11
|
+
| T
|
|
12
|
+
| Readonly<{
|
|
13
|
+
default: ValueWithDefault<T>;
|
|
14
|
+
[$$Key$$: string]: ValueWithDefault<T>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type ValueWithDefault<+T> =
|
|
11
|
+
| T
|
|
12
|
+
| $ReadOnly<{
|
|
13
|
+
default: ValueWithDefault<T>,
|
|
14
|
+
[string]: ValueWithDefault<T>,
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ValueWithDefault } from './StyleXUtils';
|
|
11
|
+
export type CSSSyntax =
|
|
12
|
+
| '*'
|
|
13
|
+
| '<length>'
|
|
14
|
+
| '<number>'
|
|
15
|
+
| '<percentage>'
|
|
16
|
+
| '<length-percentage>'
|
|
17
|
+
| '<color>'
|
|
18
|
+
| '<image>'
|
|
19
|
+
| '<url>'
|
|
20
|
+
| '<integer>'
|
|
21
|
+
| '<angle>'
|
|
22
|
+
| '<time>'
|
|
23
|
+
| '<resolution>'
|
|
24
|
+
| '<transform-function>'
|
|
25
|
+
| '<custom-ident>'
|
|
26
|
+
| '<transform-list>';
|
|
27
|
+
type CSSSyntaxType = CSSSyntax;
|
|
28
|
+
type InnerValue = null | string | number;
|
|
29
|
+
interface ICSSType<_T extends InnerValue> {
|
|
30
|
+
readonly value: ValueWithDefault<string>;
|
|
31
|
+
readonly syntax: CSSSyntaxType;
|
|
32
|
+
}
|
|
33
|
+
export declare class Angle<T extends InnerValue> implements ICSSType<T> {
|
|
34
|
+
readonly value: ValueWithDefault<string>;
|
|
35
|
+
readonly syntax: CSSSyntaxType;
|
|
36
|
+
}
|
|
37
|
+
export declare class Color<T extends InnerValue> implements ICSSType<T> {
|
|
38
|
+
readonly value: ValueWithDefault<string>;
|
|
39
|
+
readonly syntax: CSSSyntaxType;
|
|
40
|
+
}
|
|
41
|
+
export declare class Url<T extends InnerValue> implements ICSSType<T> {
|
|
42
|
+
readonly value: ValueWithDefault<string>;
|
|
43
|
+
readonly syntax: CSSSyntaxType;
|
|
44
|
+
}
|
|
45
|
+
export declare class Image<T extends InnerValue> implements ICSSType<T> {
|
|
46
|
+
readonly value: ValueWithDefault<string>;
|
|
47
|
+
readonly syntax: CSSSyntaxType;
|
|
48
|
+
}
|
|
49
|
+
export declare class Integer<T extends InnerValue> implements ICSSType<T> {
|
|
50
|
+
readonly value: ValueWithDefault<string>;
|
|
51
|
+
readonly syntax: CSSSyntaxType;
|
|
52
|
+
}
|
|
53
|
+
export declare class LengthPercentage<T extends InnerValue>
|
|
54
|
+
implements ICSSType<T>
|
|
55
|
+
{
|
|
56
|
+
readonly value: ValueWithDefault<string>;
|
|
57
|
+
readonly syntax: CSSSyntaxType;
|
|
58
|
+
}
|
|
59
|
+
export declare class Length<T extends InnerValue> implements ICSSType<T> {
|
|
60
|
+
readonly value: ValueWithDefault<string>;
|
|
61
|
+
readonly syntax: CSSSyntaxType;
|
|
62
|
+
}
|
|
63
|
+
export declare class Percentage<T extends InnerValue> implements ICSSType<T> {
|
|
64
|
+
readonly value: ValueWithDefault<string>;
|
|
65
|
+
readonly syntax: CSSSyntaxType;
|
|
66
|
+
}
|
|
67
|
+
export declare class Num<T extends InnerValue> implements ICSSType<T> {
|
|
68
|
+
readonly value: ValueWithDefault<string>;
|
|
69
|
+
readonly syntax: CSSSyntaxType;
|
|
70
|
+
}
|
|
71
|
+
export declare class Resolution<T extends InnerValue> implements ICSSType<T> {
|
|
72
|
+
readonly value: ValueWithDefault<string>;
|
|
73
|
+
readonly syntax: CSSSyntaxType;
|
|
74
|
+
}
|
|
75
|
+
export declare class Time<T extends InnerValue> implements ICSSType<T> {
|
|
76
|
+
readonly value: ValueWithDefault<string>;
|
|
77
|
+
readonly syntax: CSSSyntaxType;
|
|
78
|
+
}
|
|
79
|
+
export declare class TransformFunction<T extends InnerValue>
|
|
80
|
+
implements ICSSType<T>
|
|
81
|
+
{
|
|
82
|
+
readonly value: ValueWithDefault<string>;
|
|
83
|
+
readonly syntax: CSSSyntaxType;
|
|
84
|
+
}
|
|
85
|
+
export declare class TransformList<T extends InnerValue>
|
|
86
|
+
implements ICSSType<T>
|
|
87
|
+
{
|
|
88
|
+
readonly value: ValueWithDefault<string>;
|
|
89
|
+
readonly syntax: CSSSyntaxType;
|
|
90
|
+
}
|
|
91
|
+
export type CSSType<T extends InnerValue> =
|
|
92
|
+
| Angle<T>
|
|
93
|
+
| Color<T>
|
|
94
|
+
| Url<T>
|
|
95
|
+
| Image<T>
|
|
96
|
+
| Integer<T>
|
|
97
|
+
| LengthPercentage<T>
|
|
98
|
+
| Length<T>
|
|
99
|
+
| Percentage<T>
|
|
100
|
+
| Num<T>
|
|
101
|
+
| Resolution<T>
|
|
102
|
+
| Time<T>
|
|
103
|
+
| TransformFunction<T>
|
|
104
|
+
| TransformList<T>;
|