@stylexjs/stylex 0.2.0-beta.9 → 0.4.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 +81 -67
- package/lib/StyleXCSSTypes.d.ts +1416 -0
- package/lib/StyleXCSSTypes.js +0 -9
- package/lib/StyleXCSSTypes.js.flow +1505 -0
- package/lib/StyleXSheet.d.ts +49 -0
- package/lib/StyleXSheet.js +22 -121
- package/lib/StyleXSheet.js.flow +49 -0
- package/lib/StyleXTypes.d.ts +218 -0
- package/lib/StyleXTypes.js +0 -9
- package/lib/StyleXTypes.js.flow +187 -0
- package/lib/stylex-inject.d.ts +15 -0
- package/lib/stylex-inject.js +0 -9
- package/lib/stylex-inject.js.flow +14 -0
- package/lib/stylex.d.ts +131 -63
- package/lib/stylex.js +116 -49
- package/lib/stylex.js.flow +147 -0
- package/package.json +11 -7
|
@@ -0,0 +1,49 @@
|
|
|
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 { LegacyThemeStyles as Theme } from './StyleXTypes';
|
|
11
|
+
type SheetOptions = Readonly<{
|
|
12
|
+
rootDarkTheme?: Theme;
|
|
13
|
+
rootTheme?: Theme;
|
|
14
|
+
supportsVariables?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* This class manages the CSS stylesheet for the page and the injection of new
|
|
18
|
+
* CSS rules.
|
|
19
|
+
*/
|
|
20
|
+
export declare class StyleXSheet {
|
|
21
|
+
static LIGHT_MODE_CLASS_NAME: string;
|
|
22
|
+
static DARK_MODE_CLASS_NAME: string;
|
|
23
|
+
constructor(opts: SheetOptions);
|
|
24
|
+
rootTheme: null | undefined | Theme;
|
|
25
|
+
rootDarkTheme: null | undefined | Theme;
|
|
26
|
+
supportsVariables: boolean;
|
|
27
|
+
rules: Array<string>;
|
|
28
|
+
injected: boolean;
|
|
29
|
+
tag: null | undefined | HTMLStyleElement;
|
|
30
|
+
ruleForPriority: Map<number, string>;
|
|
31
|
+
getVariableMatch(): RegExp;
|
|
32
|
+
isHeadless(): boolean;
|
|
33
|
+
getTag(): HTMLStyleElement;
|
|
34
|
+
getCSS(): string;
|
|
35
|
+
getRulePosition(rule: string): number;
|
|
36
|
+
getRuleCount(): number;
|
|
37
|
+
inject(): void;
|
|
38
|
+
injectTheme(): void;
|
|
39
|
+
__injectCustomThemeForTesting(selector: string, theme: Theme): void;
|
|
40
|
+
delete(rule: string): void;
|
|
41
|
+
normalizeRule(rule: string): string;
|
|
42
|
+
getInsertPositionForPriority(priority: number): number;
|
|
43
|
+
insert(
|
|
44
|
+
rawLTRRule: string,
|
|
45
|
+
priority: number,
|
|
46
|
+
rawRTLRule: null | undefined | string,
|
|
47
|
+
): void;
|
|
48
|
+
}
|
|
49
|
+
export declare const styleSheet: StyleXSheet;
|
package/lib/StyleXSheet.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
11
2
|
|
|
12
3
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -15,12 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
6
|
exports.styleSheet = exports.StyleXSheet = void 0;
|
|
16
7
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
17
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
9
|
const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
|
|
20
10
|
const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
|
|
21
|
-
/**
|
|
22
|
-
* Take a theme and generate it's accompanying CSS variables
|
|
23
|
-
*/
|
|
24
11
|
function buildTheme(selector, theme) {
|
|
25
12
|
const lines = [];
|
|
26
13
|
lines.push(`${selector} {`);
|
|
@@ -31,10 +18,6 @@ function buildTheme(selector, theme) {
|
|
|
31
18
|
lines.push('}');
|
|
32
19
|
return lines.join('\n');
|
|
33
20
|
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a <style> tag and add it to the head.
|
|
37
|
-
*/
|
|
38
21
|
function makeStyleTag() {
|
|
39
22
|
const tag = document.createElement('style');
|
|
40
23
|
tag.setAttribute('type', 'text/css');
|
|
@@ -44,24 +27,13 @@ function makeStyleTag() {
|
|
|
44
27
|
head.appendChild(tag);
|
|
45
28
|
return tag;
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Check if the browser supports CSS variables
|
|
50
|
-
*/
|
|
51
30
|
function doesSupportCSSVariables() {
|
|
52
31
|
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
|
|
53
32
|
}
|
|
54
|
-
|
|
55
|
-
// Regex to replace var(--foo) with an inlined version
|
|
56
33
|
const VARIABLE_MATCH = /var\(--(.*?)\)/g;
|
|
57
|
-
|
|
58
|
-
// Stylesheet options
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* This class manages the CSS stylesheet for the page and the injection of new
|
|
62
|
-
* CSS rules.
|
|
63
|
-
*/
|
|
64
34
|
class StyleXSheet {
|
|
35
|
+
static LIGHT_MODE_CLASS_NAME = LIGHT_MODE_CLASS_NAME;
|
|
36
|
+
static DARK_MODE_CLASS_NAME = DARK_MODE_CLASS_NAME;
|
|
65
37
|
constructor(opts) {
|
|
66
38
|
this.tag = null;
|
|
67
39
|
this.injected = false;
|
|
@@ -74,18 +46,9 @@ class StyleXSheet {
|
|
|
74
46
|
getVariableMatch() {
|
|
75
47
|
return VARIABLE_MATCH;
|
|
76
48
|
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Check if we have don't have access to the dom
|
|
80
|
-
*/
|
|
81
49
|
isHeadless() {
|
|
82
|
-
|
|
83
|
-
return this.tag == null || (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.body) == null;
|
|
50
|
+
return this.tag == null || globalThis?.document?.body == null;
|
|
84
51
|
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get the stylesheet tag. Throw if none exists.
|
|
88
|
-
*/
|
|
89
52
|
getTag() {
|
|
90
53
|
const {
|
|
91
54
|
tag
|
|
@@ -93,52 +56,27 @@ class StyleXSheet {
|
|
|
93
56
|
(0, _invariant.default)(tag != null, 'expected tag');
|
|
94
57
|
return tag;
|
|
95
58
|
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Get the current stylesheet CSS.
|
|
99
|
-
*/
|
|
100
59
|
getCSS() {
|
|
101
60
|
return this.rules.join('\n');
|
|
102
61
|
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get the position of the rule in the stylesheet.
|
|
106
|
-
*/
|
|
107
62
|
getRulePosition(rule) {
|
|
108
63
|
return this.rules.indexOf(rule);
|
|
109
64
|
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Count of the current rules in the stylesheet. Used in tests.
|
|
113
|
-
*/
|
|
114
65
|
getRuleCount() {
|
|
115
66
|
return this.rules.length;
|
|
116
67
|
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Inject a style tag into the document head
|
|
120
|
-
*/
|
|
121
68
|
inject() {
|
|
122
|
-
var _globalThis$document2;
|
|
123
69
|
if (this.injected) {
|
|
124
70
|
return;
|
|
125
71
|
}
|
|
126
72
|
this.injected = true;
|
|
127
|
-
|
|
128
|
-
// Running in a server environment
|
|
129
|
-
if (((_globalThis$document2 = globalThis.document) === null || _globalThis$document2 === void 0 ? void 0 : _globalThis$document2.body) == null) {
|
|
73
|
+
if (globalThis.document?.body == null) {
|
|
130
74
|
this.injectTheme();
|
|
131
75
|
return;
|
|
132
76
|
}
|
|
133
|
-
|
|
134
|
-
// Create style tag if in browser
|
|
135
77
|
this.tag = makeStyleTag();
|
|
136
78
|
this.injectTheme();
|
|
137
79
|
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Inject the theme styles
|
|
141
|
-
*/
|
|
142
80
|
injectTheme() {
|
|
143
81
|
if (this.rootTheme != null) {
|
|
144
82
|
this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
|
|
@@ -147,25 +85,14 @@ class StyleXSheet {
|
|
|
147
85
|
this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
|
|
148
86
|
}
|
|
149
87
|
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Inject custom theme styles (only for internal testing)
|
|
153
|
-
*/
|
|
154
88
|
__injectCustomThemeForTesting(selector, theme) {
|
|
155
89
|
if (theme != null) {
|
|
156
90
|
this.insert(buildTheme(selector, theme), 0);
|
|
157
91
|
}
|
|
158
92
|
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Delete the requested rule from the stylesheet
|
|
162
|
-
*/
|
|
163
93
|
delete(rule) {
|
|
164
|
-
// Get the index of this rule
|
|
165
94
|
const index = this.rules.indexOf(rule);
|
|
166
95
|
(0, _invariant.default)(index >= 0, "Couldn't find the index for rule %s", rule);
|
|
167
|
-
|
|
168
|
-
// Remove the rule from our index
|
|
169
96
|
this.rules.splice(index, 1);
|
|
170
97
|
if (this.isHeadless()) {
|
|
171
98
|
return;
|
|
@@ -175,10 +102,6 @@ class StyleXSheet {
|
|
|
175
102
|
(0, _invariant.default)(sheet, 'expected sheet');
|
|
176
103
|
sheet.deleteRule(index);
|
|
177
104
|
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
*
|
|
181
|
-
*/
|
|
182
105
|
normalizeRule(rule) {
|
|
183
106
|
const {
|
|
184
107
|
rootTheme
|
|
@@ -190,39 +113,19 @@ class StyleXSheet {
|
|
|
190
113
|
return rootTheme[name];
|
|
191
114
|
});
|
|
192
115
|
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Get the rule position a rule should be inserted at according to the
|
|
196
|
-
* specified priority.
|
|
197
|
-
*/
|
|
198
116
|
getInsertPositionForPriority(priority) {
|
|
199
|
-
// If there's an end rule associated with this priority, then get the next
|
|
200
|
-
// rule which will belong to the next priority
|
|
201
|
-
// The rule will be inserted before it and assigned to the current priority
|
|
202
117
|
const priorityRule = this.ruleForPriority.get(priority);
|
|
203
118
|
if (priorityRule != null) {
|
|
204
119
|
return this.rules.indexOf(priorityRule) + 1;
|
|
205
120
|
}
|
|
206
|
-
|
|
207
|
-
// If we've never created this priority before, then let's find the highest
|
|
208
|
-
// priority to target
|
|
209
121
|
const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
|
|
210
|
-
|
|
211
|
-
// If there's no priorities then place us at the start
|
|
212
122
|
if (priorities.length === 0) {
|
|
213
123
|
return this.getRuleCount();
|
|
214
124
|
}
|
|
215
|
-
|
|
216
|
-
// Place us next to the next highest priority
|
|
217
125
|
const lastPriority = priorities.pop();
|
|
218
126
|
return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
|
|
219
127
|
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Insert a rule into the stylesheet.
|
|
223
|
-
*/
|
|
224
128
|
insert(rawLTRRule, priority, rawRTLRule) {
|
|
225
|
-
// Inject the stylesheet if it hasn't already been
|
|
226
129
|
if (this.injected === false) {
|
|
227
130
|
this.inject();
|
|
228
131
|
}
|
|
@@ -232,18 +135,12 @@ class StyleXSheet {
|
|
|
232
135
|
return;
|
|
233
136
|
}
|
|
234
137
|
const rawRule = rawLTRRule;
|
|
235
|
-
|
|
236
|
-
// Don't insert this rule if it already exists
|
|
237
138
|
if (this.rules.includes(rawRule)) {
|
|
238
139
|
return;
|
|
239
140
|
}
|
|
240
|
-
const rule = this.normalizeRule(rawRule);
|
|
241
|
-
|
|
242
|
-
// Get the position where we should insert the rule
|
|
141
|
+
const rule = this.normalizeRule(addSpecificityLevel(rawRule, Math.floor(priority / 1000)));
|
|
243
142
|
const insertPos = this.getInsertPositionForPriority(priority);
|
|
244
143
|
this.rules.splice(insertPos, 0, rule);
|
|
245
|
-
|
|
246
|
-
// Set this rule as the end of the priority group
|
|
247
144
|
this.ruleForPriority.set(priority, rule);
|
|
248
145
|
if (this.isHeadless()) {
|
|
249
146
|
return;
|
|
@@ -252,21 +149,14 @@ class StyleXSheet {
|
|
|
252
149
|
const sheet = tag.sheet;
|
|
253
150
|
if (sheet != null) {
|
|
254
151
|
try {
|
|
255
|
-
sheet.insertRule(rule, insertPos);
|
|
256
|
-
} catch {
|
|
257
|
-
|
|
152
|
+
sheet.insertRule(rule, Math.min(insertPos, sheet.cssRules.length));
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error('insertRule error', err, rule, insertPos);
|
|
258
155
|
}
|
|
259
156
|
}
|
|
260
|
-
// Ignore the case where sheet == null. It's an edge-case Edge 17 bug.
|
|
261
157
|
}
|
|
262
158
|
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Adds an ancestor selector in a media-query-aware way.
|
|
266
|
-
*/
|
|
267
159
|
exports.StyleXSheet = StyleXSheet;
|
|
268
|
-
_defineProperty(StyleXSheet, "LIGHT_MODE_CLASS_NAME", LIGHT_MODE_CLASS_NAME);
|
|
269
|
-
_defineProperty(StyleXSheet, "DARK_MODE_CLASS_NAME", DARK_MODE_CLASS_NAME);
|
|
270
160
|
function addAncestorSelector(selector, ancestorSelector) {
|
|
271
161
|
if (!selector.startsWith('@')) {
|
|
272
162
|
return `${ancestorSelector} ${selector}`;
|
|
@@ -276,9 +166,20 @@ function addAncestorSelector(selector, ancestorSelector) {
|
|
|
276
166
|
const rest = selector.slice(firstBracketIndex + 1);
|
|
277
167
|
return `${mediaQueryPart}${ancestorSelector} ${rest}`;
|
|
278
168
|
}
|
|
279
|
-
|
|
169
|
+
function addSpecificityLevel(selector, index) {
|
|
170
|
+
if (selector.startsWith('@keyframes')) {
|
|
171
|
+
return selector;
|
|
172
|
+
}
|
|
173
|
+
const pseudo = Array.from({
|
|
174
|
+
length: index
|
|
175
|
+
}).map(() => ':not(#\\#)').join('');
|
|
176
|
+
const lastOpenCurly = selector.includes('::') ? selector.indexOf('::') : selector.lastIndexOf('{');
|
|
177
|
+
const beforeCurly = selector.slice(0, lastOpenCurly);
|
|
178
|
+
const afterCurly = selector.slice(lastOpenCurly);
|
|
179
|
+
return `${beforeCurly}${pseudo}${afterCurly}`;
|
|
180
|
+
}
|
|
181
|
+
const styleSheet = exports.styleSheet = new StyleXSheet({
|
|
280
182
|
supportsVariables: true,
|
|
281
183
|
rootTheme: {},
|
|
282
184
|
rootDarkTheme: {}
|
|
283
|
-
});
|
|
284
|
-
exports.styleSheet = styleSheet;
|
|
185
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { LegacyThemeStyles as Theme } from './StyleXTypes';
|
|
11
|
+
|
|
12
|
+
// Stylesheet options
|
|
13
|
+
type SheetOptions = $ReadOnly<{
|
|
14
|
+
rootDarkTheme?: Theme,
|
|
15
|
+
rootTheme?: Theme,
|
|
16
|
+
supportsVariables?: boolean,
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This class manages the CSS stylesheet for the page and the injection of new
|
|
21
|
+
* CSS rules.
|
|
22
|
+
*/
|
|
23
|
+
declare export class StyleXSheet {
|
|
24
|
+
static LIGHT_MODE_CLASS_NAME: string;
|
|
25
|
+
static DARK_MODE_CLASS_NAME: string;
|
|
26
|
+
constructor(opts: SheetOptions): void;
|
|
27
|
+
rootTheme: ?Theme;
|
|
28
|
+
rootDarkTheme: ?Theme;
|
|
29
|
+
supportsVariables: boolean;
|
|
30
|
+
rules: Array<string>;
|
|
31
|
+
injected: boolean;
|
|
32
|
+
tag: ?HTMLStyleElement;
|
|
33
|
+
ruleForPriority: Map<number, string>;
|
|
34
|
+
getVariableMatch(): RegExp;
|
|
35
|
+
isHeadless(): boolean;
|
|
36
|
+
getTag(): HTMLStyleElement;
|
|
37
|
+
getCSS(): string;
|
|
38
|
+
getRulePosition(rule: string): number;
|
|
39
|
+
getRuleCount(): number;
|
|
40
|
+
inject(): void;
|
|
41
|
+
injectTheme(): void;
|
|
42
|
+
__injectCustomThemeForTesting(selector: string, theme: Theme): void;
|
|
43
|
+
delete(rule: string): void;
|
|
44
|
+
normalizeRule(rule: string): string;
|
|
45
|
+
getInsertPositionForPriority(priority: number): number;
|
|
46
|
+
insert(rawLTRRule: string, priority: number, rawRTLRule: ?string): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare export const styleSheet: StyleXSheet;
|
|
@@ -0,0 +1,218 @@
|
|
|
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 { CSSProperties } from './StyleXCSSTypes';
|
|
9
|
+
|
|
10
|
+
// Using an opaque type to declare ClassNames generated by stylex.
|
|
11
|
+
declare const StyleXClassNameTag: unique symbol;
|
|
12
|
+
export type StyleXClassNameFor<K, V> = string & {
|
|
13
|
+
_opaque: typeof StyleXClassNameTag;
|
|
14
|
+
_key: K;
|
|
15
|
+
_value: V;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type StyleXClassNameForValue<V> = StyleXClassNameFor<any, V>;
|
|
19
|
+
export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, any>;
|
|
20
|
+
export type StyleXClassName = StyleXClassNameFor<any, any>;
|
|
21
|
+
// Type for arbitrarily nested Array.
|
|
22
|
+
export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
|
|
23
|
+
|
|
24
|
+
declare const StyleXVarTag: unique symbol;
|
|
25
|
+
declare class _StyleXVar<out Val> {
|
|
26
|
+
private _opaque: typeof StyleXVarTag;
|
|
27
|
+
private _value: Val;
|
|
28
|
+
}
|
|
29
|
+
export type StyleXVar<Val> = _StyleXVar<Val> & string;
|
|
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 styles used for Search in Safari
|
|
59
|
+
'::-webkit-search-decoration'?: CSSProperties;
|
|
60
|
+
'::-webkit-search-cancel-button'?: CSSProperties;
|
|
61
|
+
'::-webkit-search-results-button'?: CSSProperties;
|
|
62
|
+
'::-webkit-search-results-decoration'?: CSSProperties;
|
|
63
|
+
}
|
|
64
|
+
>
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export type NestedCSSPropTypes = Partial<
|
|
68
|
+
Readonly<{
|
|
69
|
+
[Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor<
|
|
70
|
+
Key,
|
|
71
|
+
CSSPropertiesWithExtras[Key]
|
|
72
|
+
>;
|
|
73
|
+
}>
|
|
74
|
+
>;
|
|
75
|
+
|
|
76
|
+
type UserAuthoredStyles = CSSPropertiesWithExtras | { [key: string]: unknown };
|
|
77
|
+
export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
|
|
78
|
+
// NOTE: `XStyle` has been deprecated in favor of `StaticStyles` and `StyleXStyles`.
|
|
79
|
+
|
|
80
|
+
export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
|
|
81
|
+
export type LegacyThemeStyles = Readonly<{ [constantName: string]: string }>;
|
|
82
|
+
|
|
83
|
+
type ComplexStyleValueType<T> = T extends StyleXVar<infer U>
|
|
84
|
+
? U
|
|
85
|
+
: T extends string | number | null
|
|
86
|
+
? T
|
|
87
|
+
: T extends ReadonlyArray<infer U>
|
|
88
|
+
? U
|
|
89
|
+
: T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }>
|
|
90
|
+
? ComplexStyleValueType<A> | ComplexStyleValueType<B>
|
|
91
|
+
: T;
|
|
92
|
+
|
|
93
|
+
export type MapNamespace<CSS> = Readonly<{
|
|
94
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, ComplexStyleValueType<CSS[Key]>>;
|
|
95
|
+
}>;
|
|
96
|
+
|
|
97
|
+
export type MapNamespaces<
|
|
98
|
+
S extends {
|
|
99
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
100
|
+
},
|
|
101
|
+
> = Readonly<{
|
|
102
|
+
[Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj
|
|
103
|
+
? (...args: Args) => Readonly<[MapNamespace<Obj>, InlineStyles]>
|
|
104
|
+
: MapNamespace<S[Key]>;
|
|
105
|
+
}>;
|
|
106
|
+
|
|
107
|
+
export type Stylex$Create = <
|
|
108
|
+
const S extends {
|
|
109
|
+
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
|
|
110
|
+
},
|
|
111
|
+
>(
|
|
112
|
+
styles: S,
|
|
113
|
+
) => MapNamespaces<S>;
|
|
114
|
+
|
|
115
|
+
export type CompiledStyles =
|
|
116
|
+
| Readonly<{
|
|
117
|
+
[key: string]: StyleXClassName | null | void | never;
|
|
118
|
+
}>
|
|
119
|
+
| Readonly<{
|
|
120
|
+
theme: StyleXClassName;
|
|
121
|
+
}>;
|
|
122
|
+
|
|
123
|
+
declare const StyleXInlineStylesTag: unique symbol;
|
|
124
|
+
|
|
125
|
+
export type InlineStyles = typeof StyleXInlineStylesTag;
|
|
126
|
+
|
|
127
|
+
type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
|
|
128
|
+
[Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
|
|
129
|
+
}>;
|
|
130
|
+
type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
|
|
131
|
+
_GenStylePropType<CSS> &
|
|
132
|
+
Partial<{
|
|
133
|
+
[Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
|
|
134
|
+
}>
|
|
135
|
+
>;
|
|
136
|
+
|
|
137
|
+
// Replace `XStyle` with this.
|
|
138
|
+
export type StaticStyles<
|
|
139
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
140
|
+
> = StyleXArray<false | null | GenStylePropType<CSS>>;
|
|
141
|
+
|
|
142
|
+
export type StaticStylesWithout<CSS extends UserAuthoredStyles> = StaticStyles<
|
|
143
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
144
|
+
>;
|
|
145
|
+
|
|
146
|
+
export type StyleXStyles<
|
|
147
|
+
CSS extends UserAuthoredStyles = CSSPropertiesWithExtras,
|
|
148
|
+
> = StyleXArray<
|
|
149
|
+
| null
|
|
150
|
+
| false
|
|
151
|
+
| GenStylePropType<CSS>
|
|
152
|
+
| Readonly<[GenStylePropType<CSS>, InlineStyles]>
|
|
153
|
+
>;
|
|
154
|
+
export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
|
|
155
|
+
Omit<CSSPropertiesWithExtras, keyof CSS>
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
declare const StyleXVarGroupTag: unique symbol;
|
|
159
|
+
export type VarGroup<
|
|
160
|
+
Tokens extends { [key: string]: any },
|
|
161
|
+
ID extends symbol = symbol,
|
|
162
|
+
> = Readonly<{
|
|
163
|
+
[Key in keyof Tokens]: StyleXVar<Tokens[Key]>;
|
|
164
|
+
}> &
|
|
165
|
+
Readonly<{
|
|
166
|
+
__opaqueId: ID;
|
|
167
|
+
__tokens: Tokens;
|
|
168
|
+
}> &
|
|
169
|
+
typeof StyleXVarGroupTag;
|
|
170
|
+
|
|
171
|
+
export type TokensFromVarGroup<T extends VarGroup<unknown, unknown>> =
|
|
172
|
+
T['__tokens'];
|
|
173
|
+
|
|
174
|
+
export type IDFromVarGroup<T extends VarGroup<unknown, unknown>> =
|
|
175
|
+
T['__opaqueId'];
|
|
176
|
+
|
|
177
|
+
type TTokens = Readonly<{
|
|
178
|
+
[key: string]: string | { [key: string]: string };
|
|
179
|
+
}>;
|
|
180
|
+
|
|
181
|
+
type UnwrapVars<T> = T extends StyleXVar<infer U> ? U : T;
|
|
182
|
+
export type FlattenTokens<T extends TTokens> = Readonly<{
|
|
183
|
+
[Key in keyof T]: T[Key] extends { [key: string]: infer X }
|
|
184
|
+
? UnwrapVars<X>
|
|
185
|
+
: UnwrapVars<T[Key]>;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
export type StyleX$DefineVars = <
|
|
189
|
+
DefaultTokens extends TTokens,
|
|
190
|
+
ID extends symbol = symbol,
|
|
191
|
+
>(
|
|
192
|
+
tokens: DefaultTokens,
|
|
193
|
+
) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
|
|
194
|
+
|
|
195
|
+
declare class ThemeKey<out VG extends VarGroup> extends String {
|
|
196
|
+
private varGroup: VG;
|
|
197
|
+
}
|
|
198
|
+
export type Theme<
|
|
199
|
+
T extends VarGroup<unknown, symbol>,
|
|
200
|
+
Tag extends symbol = symbol,
|
|
201
|
+
> = Tag &
|
|
202
|
+
Readonly<{
|
|
203
|
+
theme: StyleXClassNameFor<ThemeKey<T>, IDFromVarGroup<T>>;
|
|
204
|
+
}>;
|
|
205
|
+
|
|
206
|
+
type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
|
|
207
|
+
[Key in keyof Config]?:
|
|
208
|
+
| Config[Key]
|
|
209
|
+
| { default: Config[Key]; [atRule: AtRuleStr]: Config[Key] };
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export type StyleX$CreateTheme = <
|
|
213
|
+
TVars extends VarGroup<unknown, unknown>,
|
|
214
|
+
ThemeID extends symbol = symbol,
|
|
215
|
+
>(
|
|
216
|
+
baseTokens: TVars,
|
|
217
|
+
overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
|
|
218
|
+
) => Theme<TVars, ThemeID>;
|