@stylexjs/stylex 0.2.0-beta.16 → 0.2.0-beta.17
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.js +1 -10
- package/lib/StyleXSheet.d.ts +3 -3
- package/lib/StyleXSheet.js +19 -132
- package/lib/StyleXSheet.js.flow +2 -2
- package/lib/StyleXTypes.d.ts +143 -180
- package/lib/StyleXTypes.js +1 -10
- package/lib/StyleXTypes.js.flow +72 -23
- package/lib/native/CSSCustomPropertyValue.js +2 -11
- package/lib/native/CSSLengthUnitValue.d.ts +1 -1
- package/lib/native/CSSLengthUnitValue.js +7 -18
- package/lib/native/CSSLengthUnitValue.js.flow +1 -1
- package/lib/native/CSSMediaQuery.d.ts +1 -1
- package/lib/native/CSSMediaQuery.js +4 -18
- package/lib/native/CSSMediaQuery.js.flow +1 -1
- package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +81 -0
- package/lib/native/__tests__/parseTimeValue-test.js +11 -0
- package/lib/native/__tests__/stylex-test.js +186 -128
- package/lib/native/errorMsg.js +0 -9
- package/lib/native/flattenStyle.js +1 -11
- package/lib/native/parseShadow.js +4 -13
- package/lib/native/parseTimeValue.d.ts +11 -0
- package/lib/native/parseTimeValue.js +18 -0
- package/lib/native/parseTimeValue.js.flow +12 -0
- package/lib/native/stylex.d.ts +6 -5
- package/lib/native/stylex.js +60 -106
- package/lib/native/stylex.js.flow +4 -4
- package/lib/stylex-inject.d.ts +1 -1
- package/lib/stylex-inject.js +0 -9
- package/lib/stylex-inject.js.flow +1 -1
- package/lib/stylex.d.ts +23 -25
- package/lib/stylex.js +8 -17
- package/lib/stylex.js.flow +24 -27
- package/package.json +2 -2
package/lib/StyleXCSSTypes.js
CHANGED
package/lib/StyleXSheet.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { Theme } from './StyleXTypes';
|
|
10
|
+
import type { LegacyTheme as Theme } from './StyleXTypes';
|
|
11
11
|
type SheetOptions = Readonly<{
|
|
12
12
|
rootDarkTheme?: Theme;
|
|
13
13
|
rootTheme?: Theme;
|
|
@@ -43,7 +43,7 @@ export declare class StyleXSheet {
|
|
|
43
43
|
insert(
|
|
44
44
|
rawLTRRule: string,
|
|
45
45
|
priority: number,
|
|
46
|
-
rawRTLRule: null | undefined | string
|
|
46
|
+
rawRTLRule: null | undefined | string,
|
|
47
47
|
): void;
|
|
48
48
|
}
|
|
49
|
-
export declare
|
|
49
|
+
export declare const styleSheet: StyleXSheet;
|
package/lib/StyleXSheet.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
'use strict';
|
|
1
|
+
"use strict";
|
|
11
2
|
|
|
12
3
|
Object.defineProperty(exports, "__esModule", {
|
|
13
4
|
value: true
|
|
@@ -15,13 +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
|
-
|
|
19
|
-
|
|
20
|
-
const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
|
|
21
|
-
const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
|
|
22
|
-
/**
|
|
23
|
-
* Take a theme and generate it's accompanying CSS variables
|
|
24
|
-
*/
|
|
9
|
+
const LIGHT_MODE_CLASS_NAME = "__fb-light-mode";
|
|
10
|
+
const DARK_MODE_CLASS_NAME = "__fb-dark-mode";
|
|
25
11
|
function buildTheme(selector, theme) {
|
|
26
12
|
const lines = [];
|
|
27
13
|
lines.push(`${selector} {`);
|
|
@@ -29,39 +15,22 @@ function buildTheme(selector, theme) {
|
|
|
29
15
|
const value = theme[key];
|
|
30
16
|
lines.push(` --${key}: ${value};`);
|
|
31
17
|
}
|
|
32
|
-
lines.push(
|
|
33
|
-
return lines.join(
|
|
18
|
+
lines.push("}");
|
|
19
|
+
return lines.join("\n");
|
|
34
20
|
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Create a <style> tag and add it to the head.
|
|
38
|
-
*/
|
|
39
21
|
function makeStyleTag() {
|
|
40
|
-
const tag = document.createElement(
|
|
41
|
-
tag.setAttribute(
|
|
42
|
-
tag.setAttribute(
|
|
43
|
-
const head = document.head || document.getElementsByTagName(
|
|
44
|
-
(0, _invariant.default)(head,
|
|
22
|
+
const tag = document.createElement("style");
|
|
23
|
+
tag.setAttribute("type", "text/css");
|
|
24
|
+
tag.setAttribute("data-stylex", "true");
|
|
25
|
+
const head = document.head || document.getElementsByTagName("head")[0];
|
|
26
|
+
(0, _invariant.default)(head, "expected head");
|
|
45
27
|
head.appendChild(tag);
|
|
46
28
|
return tag;
|
|
47
29
|
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if the browser supports CSS variables
|
|
51
|
-
*/
|
|
52
30
|
function doesSupportCSSVariables() {
|
|
53
|
-
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports(
|
|
31
|
+
return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports("--fake-var:0");
|
|
54
32
|
}
|
|
55
|
-
|
|
56
|
-
// Regex to replace var(--foo) with an inlined version
|
|
57
33
|
const VARIABLE_MATCH = /var\(--(.*?)\)/g;
|
|
58
|
-
|
|
59
|
-
// Stylesheet options
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* This class manages the CSS stylesheet for the page and the injection of new
|
|
63
|
-
* CSS rules.
|
|
64
|
-
*/
|
|
65
34
|
class StyleXSheet {
|
|
66
35
|
static LIGHT_MODE_CLASS_NAME = LIGHT_MODE_CLASS_NAME;
|
|
67
36
|
static DARK_MODE_CLASS_NAME = DARK_MODE_CLASS_NAME;
|
|
@@ -77,71 +46,37 @@ class StyleXSheet {
|
|
|
77
46
|
getVariableMatch() {
|
|
78
47
|
return VARIABLE_MATCH;
|
|
79
48
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Check if we have don't have access to the dom
|
|
83
|
-
*/
|
|
84
49
|
isHeadless() {
|
|
85
|
-
|
|
86
|
-
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;
|
|
87
51
|
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Get the stylesheet tag. Throw if none exists.
|
|
91
|
-
*/
|
|
92
52
|
getTag() {
|
|
93
53
|
const {
|
|
94
54
|
tag
|
|
95
55
|
} = this;
|
|
96
|
-
(0, _invariant.default)(tag != null,
|
|
56
|
+
(0, _invariant.default)(tag != null, "expected tag");
|
|
97
57
|
return tag;
|
|
98
58
|
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the current stylesheet CSS.
|
|
102
|
-
*/
|
|
103
59
|
getCSS() {
|
|
104
|
-
return this.rules.join(
|
|
60
|
+
return this.rules.join("\n");
|
|
105
61
|
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get the position of the rule in the stylesheet.
|
|
109
|
-
*/
|
|
110
62
|
getRulePosition(rule) {
|
|
111
63
|
return this.rules.indexOf(rule);
|
|
112
64
|
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Count of the current rules in the stylesheet. Used in tests.
|
|
116
|
-
*/
|
|
117
65
|
getRuleCount() {
|
|
118
66
|
return this.rules.length;
|
|
119
67
|
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Inject a style tag into the document head
|
|
123
|
-
*/
|
|
124
68
|
inject() {
|
|
125
|
-
var _globalThis$document2;
|
|
126
69
|
if (this.injected) {
|
|
127
70
|
return;
|
|
128
71
|
}
|
|
129
72
|
this.injected = true;
|
|
130
|
-
|
|
131
|
-
// Running in a server environment
|
|
132
|
-
if (((_globalThis$document2 = globalThis.document) === null || _globalThis$document2 === void 0 ? void 0 : _globalThis$document2.body) == null) {
|
|
73
|
+
if (globalThis.document?.body == null) {
|
|
133
74
|
this.injectTheme();
|
|
134
75
|
return;
|
|
135
76
|
}
|
|
136
|
-
|
|
137
|
-
// Create style tag if in browser
|
|
138
77
|
this.tag = makeStyleTag();
|
|
139
78
|
this.injectTheme();
|
|
140
79
|
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Inject the theme styles
|
|
144
|
-
*/
|
|
145
80
|
injectTheme() {
|
|
146
81
|
if (this.rootTheme != null) {
|
|
147
82
|
this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
|
|
@@ -150,38 +85,23 @@ class StyleXSheet {
|
|
|
150
85
|
this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
|
|
151
86
|
}
|
|
152
87
|
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Inject custom theme styles (only for internal testing)
|
|
156
|
-
*/
|
|
157
88
|
__injectCustomThemeForTesting(selector, theme) {
|
|
158
89
|
if (theme != null) {
|
|
159
90
|
this.insert(buildTheme(selector, theme), 0);
|
|
160
91
|
}
|
|
161
92
|
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Delete the requested rule from the stylesheet
|
|
165
|
-
*/
|
|
166
93
|
delete(rule) {
|
|
167
|
-
// Get the index of this rule
|
|
168
94
|
const index = this.rules.indexOf(rule);
|
|
169
95
|
(0, _invariant.default)(index >= 0, "Couldn't find the index for rule %s", rule);
|
|
170
|
-
|
|
171
|
-
// Remove the rule from our index
|
|
172
96
|
this.rules.splice(index, 1);
|
|
173
97
|
if (this.isHeadless()) {
|
|
174
98
|
return;
|
|
175
99
|
}
|
|
176
100
|
const tag = this.getTag();
|
|
177
101
|
const sheet = tag.sheet;
|
|
178
|
-
(0, _invariant.default)(sheet,
|
|
102
|
+
(0, _invariant.default)(sheet, "expected sheet");
|
|
179
103
|
sheet.deleteRule(index);
|
|
180
104
|
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
*
|
|
184
|
-
*/
|
|
185
105
|
normalizeRule(rule) {
|
|
186
106
|
const {
|
|
187
107
|
rootTheme
|
|
@@ -193,39 +113,19 @@ class StyleXSheet {
|
|
|
193
113
|
return rootTheme[name];
|
|
194
114
|
});
|
|
195
115
|
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Get the rule position a rule should be inserted at according to the
|
|
199
|
-
* specified priority.
|
|
200
|
-
*/
|
|
201
116
|
getInsertPositionForPriority(priority) {
|
|
202
|
-
// If there's an end rule associated with this priority, then get the next
|
|
203
|
-
// rule which will belong to the next priority
|
|
204
|
-
// The rule will be inserted before it and assigned to the current priority
|
|
205
117
|
const priorityRule = this.ruleForPriority.get(priority);
|
|
206
118
|
if (priorityRule != null) {
|
|
207
119
|
return this.rules.indexOf(priorityRule) + 1;
|
|
208
120
|
}
|
|
209
|
-
|
|
210
|
-
// If we've never created this priority before, then let's find the highest
|
|
211
|
-
// priority to target
|
|
212
121
|
const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
|
|
213
|
-
|
|
214
|
-
// If there's no priorities then place us at the start
|
|
215
122
|
if (priorities.length === 0) {
|
|
216
123
|
return this.getRuleCount();
|
|
217
124
|
}
|
|
218
|
-
|
|
219
|
-
// Place us next to the next highest priority
|
|
220
125
|
const lastPriority = priorities.pop();
|
|
221
126
|
return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
|
|
222
127
|
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Insert a rule into the stylesheet.
|
|
226
|
-
*/
|
|
227
128
|
insert(rawLTRRule, priority, rawRTLRule) {
|
|
228
|
-
// Inject the stylesheet if it hasn't already been
|
|
229
129
|
if (this.injected === false) {
|
|
230
130
|
this.inject();
|
|
231
131
|
}
|
|
@@ -235,18 +135,12 @@ class StyleXSheet {
|
|
|
235
135
|
return;
|
|
236
136
|
}
|
|
237
137
|
const rawRule = rawLTRRule;
|
|
238
|
-
|
|
239
|
-
// Don't insert this rule if it already exists
|
|
240
138
|
if (this.rules.includes(rawRule)) {
|
|
241
139
|
return;
|
|
242
140
|
}
|
|
243
141
|
const rule = this.normalizeRule(rawRule);
|
|
244
|
-
|
|
245
|
-
// Get the position where we should insert the rule
|
|
246
142
|
const insertPos = this.getInsertPositionForPriority(priority);
|
|
247
143
|
this.rules.splice(insertPos, 0, rule);
|
|
248
|
-
|
|
249
|
-
// Set this rule as the end of the priority group
|
|
250
144
|
this.ruleForPriority.set(priority, rule);
|
|
251
145
|
if (this.isHeadless()) {
|
|
252
146
|
return;
|
|
@@ -256,23 +150,16 @@ class StyleXSheet {
|
|
|
256
150
|
if (sheet != null) {
|
|
257
151
|
try {
|
|
258
152
|
sheet.insertRule(rule, insertPos);
|
|
259
|
-
} catch {
|
|
260
|
-
// Ignore: error likely due to inserting prefixed rules (e.g. `::-moz-range-thumb`).
|
|
261
|
-
}
|
|
153
|
+
} catch {}
|
|
262
154
|
}
|
|
263
|
-
// Ignore the case where sheet == null. It's an edge-case Edge 17 bug.
|
|
264
155
|
}
|
|
265
156
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Adds an ancestor selector in a media-query-aware way.
|
|
269
|
-
*/
|
|
270
157
|
exports.StyleXSheet = StyleXSheet;
|
|
271
158
|
function addAncestorSelector(selector, ancestorSelector) {
|
|
272
|
-
if (!selector.startsWith(
|
|
159
|
+
if (!selector.startsWith("@")) {
|
|
273
160
|
return `${ancestorSelector} ${selector}`;
|
|
274
161
|
}
|
|
275
|
-
const firstBracketIndex = selector.indexOf(
|
|
162
|
+
const firstBracketIndex = selector.indexOf("{");
|
|
276
163
|
const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
|
|
277
164
|
const rest = selector.slice(firstBracketIndex + 1);
|
|
278
165
|
return `${mediaQueryPart}${ancestorSelector} ${rest}`;
|
package/lib/StyleXSheet.js.flow
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { Theme } from './StyleXTypes';
|
|
10
|
+
import type { LegacyTheme as Theme } from './StyleXTypes';
|
|
11
11
|
|
|
12
12
|
// Stylesheet options
|
|
13
13
|
type SheetOptions = $ReadOnly<{
|
|
@@ -46,4 +46,4 @@ declare export class StyleXSheet {
|
|
|
46
46
|
insert(rawLTRRule: string, priority: number, rawRTLRule: ?string): void;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
declare export
|
|
49
|
+
declare export const styleSheet: StyleXSheet;
|
package/lib/StyleXTypes.d.ts
CHANGED
|
@@ -3,131 +3,69 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
import type { CSSProperties } from './StyleXCSSTypes';
|
|
11
|
-
|
|
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
|
+
|
|
12
18
|
export type StyleXClassNameForValue<V> = StyleXClassNameFor<unknown, V>;
|
|
13
19
|
export type StyleXClassNameForKey<K> = StyleXClassNameFor<K, unknown>;
|
|
14
20
|
export type StyleXClassName = StyleXClassNameFor<unknown, unknown>;
|
|
21
|
+
// Type for arbitrarily nested Array.
|
|
15
22
|
export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export type NestedCSSPropTypes =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'@media (max-width: 1920px)'?: StyleXClassName;
|
|
63
|
-
'@media (min-width: 1921px)'?: StyleXClassName;
|
|
64
|
-
'@media (min-width: 1500px)'?: StyleXClassName;
|
|
65
|
-
'@media (min-width: 1800px)'?: StyleXClassName;
|
|
66
|
-
'@media (min-width: 2250px)'?: StyleXClassName;
|
|
67
|
-
'::-webkit-search-decoration'?: StyleXClassName;
|
|
68
|
-
'::-webkit-search-cancel-button'?: StyleXClassName;
|
|
69
|
-
'::-webkit-search-results-button'?: StyleXClassName;
|
|
70
|
-
'::-webkit-search-results-decoration'?: StyleXClassName;
|
|
71
|
-
'@media (min-width: 950px)'?: StyleXClassName;
|
|
72
|
-
'@media (min-width: 1440px)'?: StyleXClassName;
|
|
73
|
-
'@media (min-width: 1920px)'?: StyleXClassName;
|
|
74
|
-
'@media (min-width: 800px)'?: StyleXClassName;
|
|
75
|
-
'@media (max-width: 1024px) and (min-width: 501px)'?: StyleXClassName;
|
|
76
|
-
})
|
|
77
|
-
> & {
|
|
78
|
-
':active'?: StyleXClassName;
|
|
79
|
-
':focus'?: StyleXClassName;
|
|
80
|
-
':focus-visible'?: StyleXClassName;
|
|
81
|
-
':hover'?: StyleXClassName;
|
|
82
|
-
':disabled'?: StyleXClassName;
|
|
83
|
-
':empty'?: StyleXClassName;
|
|
84
|
-
':first-child'?: StyleXClassName;
|
|
85
|
-
':last-child'?: StyleXClassName;
|
|
86
|
-
'::before'?: StyleXClassName;
|
|
87
|
-
'::after'?: StyleXClassName;
|
|
88
|
-
'::placeholder'?: StyleXClassName;
|
|
89
|
-
'::-webkit-scrollbar'?: StyleXClassName;
|
|
90
|
-
'@media (max-width: 564px)'?: StyleXClassName;
|
|
91
|
-
'@media (min-height: 700px)'?: StyleXClassName;
|
|
92
|
-
'@media (min-height: 700px) and (max-height: 789px)'?: StyleXClassName;
|
|
93
|
-
'@media (min-height: 753px) and (max-height: 789px)'?: StyleXClassName;
|
|
94
|
-
'@media (min-height: 790px)'?: StyleXClassName;
|
|
95
|
-
'@media (max-width: 648px)'?: StyleXClassName;
|
|
96
|
-
'@media (max-width: 899px)'?: StyleXClassName;
|
|
97
|
-
'@media (max-width: 900px)'?: StyleXClassName;
|
|
98
|
-
'@media (min-width: 900px)'?: StyleXClassName;
|
|
99
|
-
'@media (min-width: 900px) and (max-width: 1259px)'?: StyleXClassName;
|
|
100
|
-
'@media (max-width: 1099px)'?: StyleXClassName;
|
|
101
|
-
'@media (max-width: 1199px)'?: StyleXClassName;
|
|
102
|
-
'@media (max-width: 1259px)'?: StyleXClassName;
|
|
103
|
-
'@media (min-width: 1290px)'?: StyleXClassName;
|
|
104
|
-
'@media (max-width: 420px)'?: StyleXClassName;
|
|
105
|
-
'@media (max-width: 500px)'?: StyleXClassName;
|
|
106
|
-
'@media (pointer: coarse)'?: StyleXClassName;
|
|
107
|
-
'@media (-webkit-min-device-pixel-ratio: 0)'?: StyleXClassName;
|
|
108
|
-
'@media print'?: StyleXClassName;
|
|
109
|
-
'@media (max-width: 767px)'?: StyleXClassName;
|
|
110
|
-
'@media (min-width: 768px)'?: StyleXClassName;
|
|
111
|
-
'@media (min-width: 768px) and (max-width: 1024px)'?: StyleXClassName;
|
|
112
|
-
'@media (max-width: 1024px)'?: StyleXClassName;
|
|
113
|
-
'@media (min-width: 1025px)'?: StyleXClassName;
|
|
114
|
-
'@media (min-width: 1025px) and (max-width: 1920px)'?: StyleXClassName;
|
|
115
|
-
'@media (max-width: 1920px)'?: StyleXClassName;
|
|
116
|
-
'@media (min-width: 1921px)'?: StyleXClassName;
|
|
117
|
-
'@media (min-width: 1500px)'?: StyleXClassName;
|
|
118
|
-
'@media (min-width: 1800px)'?: StyleXClassName;
|
|
119
|
-
'@media (min-width: 2250px)'?: StyleXClassName;
|
|
120
|
-
'::-webkit-search-decoration'?: StyleXClassName;
|
|
121
|
-
'::-webkit-search-cancel-button'?: StyleXClassName;
|
|
122
|
-
'::-webkit-search-results-button'?: StyleXClassName;
|
|
123
|
-
'::-webkit-search-results-decoration'?: StyleXClassName;
|
|
124
|
-
'@media (min-width: 950px)'?: StyleXClassName;
|
|
125
|
-
'@media (min-width: 1440px)'?: StyleXClassName;
|
|
126
|
-
'@media (min-width: 1920px)'?: StyleXClassName;
|
|
127
|
-
'@media (min-width: 800px)'?: StyleXClassName;
|
|
128
|
-
'@media (max-width: 1024px) and (min-width: 501px)'?: StyleXClassName;
|
|
129
|
-
}
|
|
130
|
-
>;
|
|
23
|
+
|
|
24
|
+
type CSSPropTypes = {
|
|
25
|
+
[Key in keyof CSSProperties]: StyleXClassNameFor<Key, CSSProperties[Key]>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type NestedCSSPropTypes = CSSPropTypes &
|
|
29
|
+
Readonly<{
|
|
30
|
+
// NOTE: the actual type should be nested objects.
|
|
31
|
+
// fix after the types in stylex.js are fixed.
|
|
32
|
+
':active': StyleXClassName;
|
|
33
|
+
':focus': StyleXClassName;
|
|
34
|
+
':focus-visible': StyleXClassName;
|
|
35
|
+
':hover': StyleXClassName;
|
|
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
|
+
}>;
|
|
68
|
+
|
|
131
69
|
export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
|
|
132
70
|
export type XStyle<T = NestedCSSPropTypes> = StyleXArray<
|
|
133
71
|
false | (null | undefined | T)
|
|
@@ -135,68 +73,93 @@ export type XStyle<T = NestedCSSPropTypes> = StyleXArray<
|
|
|
135
73
|
export type XStyleWithout<T extends { [$$Key$$: string]: void }> = XStyle<
|
|
136
74
|
Readonly<Pick<NestedCSSPropTypes, Exclude<keyof NestedCSSPropTypes, keyof T>>>
|
|
137
75
|
>;
|
|
138
|
-
|
|
139
|
-
export type Style = Readonly</**
|
|
140
|
-
* > 95 | export type Style = $ReadOnly<{
|
|
141
|
-
* | ^
|
|
142
|
-
* > 96 | ...CSSProperties,
|
|
143
|
-
* | ^^^^^^^^^^^^^^^^^^^
|
|
144
|
-
* > 97 | [pseudo: string]: CSSProperties,
|
|
145
|
-
* | ^^^^^^^^^^^^^^^^^^^
|
|
146
|
-
* > 98 | ...
|
|
147
|
-
* | ^^^^^^^^^^^^^^^^^^^
|
|
148
|
-
* > 99 | }>;
|
|
149
|
-
* | ^^ Unsupported feature: Translating "object types with spreads, indexers and/or call properties at the same time" is currently not supported.
|
|
150
|
-
**/
|
|
151
|
-
any>;
|
|
152
|
-
export type Rules = Style | CSSProperties;
|
|
76
|
+
|
|
153
77
|
export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
|
|
154
|
-
export type
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
78
|
+
export type LegacyTheme = Readonly<{ [constantName: string]: string }>;
|
|
79
|
+
|
|
80
|
+
type RawStyles = {
|
|
81
|
+
[key: string]: null | string | number | Array<string | number> | RawStyles;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
type CompiledNamespace<N extends RawStyles> = {
|
|
85
|
+
[K in keyof N]: N[K] extends string | number | null
|
|
86
|
+
? StyleXClassNameFor<K, N[K]>
|
|
87
|
+
: N[K] extends ReadonlyArray<infer T>
|
|
88
|
+
? StyleXClassNameFor<K, T>
|
|
89
|
+
: K extends `:${string}` | `@${string}`
|
|
90
|
+
? N[K] extends RawStyles
|
|
91
|
+
? CompiledNamespace<N[K]>
|
|
92
|
+
: StyleXClassNameFor<K, N[K]>
|
|
93
|
+
: N[K] extends { [key: string]: infer T }
|
|
94
|
+
? StyleXClassNameFor<K, T> // TODO: Handle nested objects
|
|
95
|
+
: never;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type Stylex$Create = <const S extends { [n: string]: RawStyles }>(
|
|
99
|
+
styles: S,
|
|
100
|
+
) => Readonly<{
|
|
101
|
+
[N in keyof S]: CompiledNamespace<S[N]>;
|
|
102
|
+
}>;
|
|
103
|
+
|
|
104
|
+
export type CompiledStyles = Readonly<{
|
|
105
|
+
[key: string]: StyleXClassName | Readonly<{ [key: string]: StyleXClassName }>;
|
|
106
|
+
}>;
|
|
107
|
+
|
|
108
|
+
type TTokens = {
|
|
109
|
+
[key: string]: string | { default: string; [key: string]: string };
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type FlattenTokens<
|
|
113
|
+
T extends {
|
|
114
|
+
[key: string]: string | { default: string; [key: string]: string };
|
|
115
|
+
},
|
|
116
|
+
> = {
|
|
117
|
+
[Key in keyof T]: T[Key] extends { default: infer X } & {
|
|
118
|
+
[key: Exclude<string, 'default'>]: infer Y;
|
|
119
|
+
}
|
|
120
|
+
? X | Y
|
|
121
|
+
: T[Key];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type Theme<
|
|
125
|
+
Tokens extends { [key: string]: unknown },
|
|
126
|
+
ID extends symbol = symbol,
|
|
127
|
+
> = Readonly<{
|
|
128
|
+
[_Key in Exclude<keyof Tokens, '_opaque' | '_tokens'>]: string;
|
|
129
|
+
}> & {
|
|
130
|
+
_opaque: ID;
|
|
131
|
+
_tokens: Tokens;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type TokensFromTheme<T extends Theme<TTokens>> = T['_tokens'];
|
|
135
|
+
|
|
136
|
+
export type IDFromTheme<T extends Theme<TTokens>> = T['_opaque'];
|
|
137
|
+
|
|
138
|
+
export type StyleX$CreateVars = <
|
|
139
|
+
DefaultTokens extends TTokens,
|
|
140
|
+
ID extends symbol = symbol,
|
|
180
141
|
>(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
142
|
+
tokens: DefaultTokens,
|
|
143
|
+
) => Theme<FlattenTokens<DefaultTokens>, ID>;
|
|
144
|
+
|
|
145
|
+
export type Variant<
|
|
146
|
+
T extends Theme<TTokens, symbol>,
|
|
147
|
+
// eslint-disable-next-line no-unused-vars
|
|
148
|
+
Tag extends symbol = symbol,
|
|
149
|
+
> = Readonly<{
|
|
150
|
+
[Key: symbol]: StyleXClassNameFor<string, IDFromTheme<T>>;
|
|
151
|
+
}> & { _opaque: Tag };
|
|
152
|
+
|
|
153
|
+
type OverridesForTokenType<Config extends { [key: string]: unknown }> = {
|
|
154
|
+
[Key in keyof Config]:
|
|
155
|
+
| Config[Key]
|
|
156
|
+
| { default: Config[Key]; [atRule: string]: Config[Key] };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export type StyleX$OverrideVars = <
|
|
160
|
+
BaseTokens extends Theme<any>,
|
|
161
|
+
ID extends symbol = symbol,
|
|
192
162
|
>(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
) => StyleXVarsTheme<
|
|
197
|
-
Readonly</**
|
|
198
|
-
* > 135 | ) => StyleXVarsTheme<$ReadOnly<$ObjMapConst<Vars, string>>>;
|
|
199
|
-
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "$ObjMapConst" is currently not supported.
|
|
200
|
-
**/
|
|
201
|
-
any>
|
|
202
|
-
>;
|
|
163
|
+
baseTokens: BaseTokens,
|
|
164
|
+
overrides: OverridesForTokenType<TokensFromTheme<BaseTokens>>,
|
|
165
|
+
) => Variant<BaseTokens, ID>;
|