@stylexjs/stylex 0.12.0 → 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/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} +54 -3
- 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 +15 -26
- 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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { ValueWithDefault } from './
|
|
10
|
+
import type { ValueWithDefault } from './StyleXUtils';
|
|
11
11
|
|
|
12
12
|
export type CSSSyntax =
|
|
13
13
|
| '*'
|
|
@@ -27,68 +27,66 @@ export type CSSSyntax =
|
|
|
27
27
|
| '<transform-list>';
|
|
28
28
|
|
|
29
29
|
type CSSSyntaxType = CSSSyntax;
|
|
30
|
+
type InnerValue = null | string | number;
|
|
30
31
|
|
|
31
|
-
interface ICSSType<+_T:
|
|
32
|
+
interface ICSSType<+_T: InnerValue> {
|
|
32
33
|
+value: ValueWithDefault<string>;
|
|
33
34
|
+syntax: CSSSyntaxType;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
declare export class Angle<+T: string | 0> implements ICSSType<T> {
|
|
36
|
+
declare export class Angle<+T: InnerValue> implements ICSSType<T> {
|
|
37
37
|
+value: ValueWithDefault<string>;
|
|
38
38
|
+syntax: CSSSyntaxType;
|
|
39
39
|
}
|
|
40
|
-
declare export class Color<+T:
|
|
40
|
+
declare export class Color<+T: InnerValue> implements ICSSType<T> {
|
|
41
41
|
+value: ValueWithDefault<string>;
|
|
42
42
|
+syntax: CSSSyntaxType;
|
|
43
43
|
}
|
|
44
|
-
declare export class Url<+T:
|
|
44
|
+
declare export class Url<+T: InnerValue> implements ICSSType<T> {
|
|
45
45
|
+value: ValueWithDefault<string>;
|
|
46
46
|
+syntax: CSSSyntaxType;
|
|
47
47
|
}
|
|
48
|
-
declare export class Image<+T:
|
|
48
|
+
declare export class Image<+T: InnerValue> implements ICSSType<T> {
|
|
49
49
|
+value: ValueWithDefault<string>;
|
|
50
50
|
+syntax: CSSSyntaxType;
|
|
51
51
|
}
|
|
52
|
-
declare export class Integer<+T:
|
|
52
|
+
declare export class Integer<+T: InnerValue> implements ICSSType<T> {
|
|
53
53
|
+value: ValueWithDefault<string>;
|
|
54
54
|
+syntax: CSSSyntaxType;
|
|
55
55
|
}
|
|
56
|
-
declare export class LengthPercentage<+T:
|
|
57
|
-
implements ICSSType<T>
|
|
58
|
-
{
|
|
56
|
+
declare export class LengthPercentage<+T: InnerValue> implements ICSSType<T> {
|
|
59
57
|
+value: ValueWithDefault<string>;
|
|
60
58
|
+syntax: CSSSyntaxType;
|
|
61
59
|
}
|
|
62
|
-
declare export class Length<+T:
|
|
60
|
+
declare export class Length<+T: InnerValue> implements ICSSType<T> {
|
|
63
61
|
+value: ValueWithDefault<string>;
|
|
64
62
|
+syntax: CSSSyntaxType;
|
|
65
63
|
}
|
|
66
|
-
declare export class Percentage<+T:
|
|
64
|
+
declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
|
|
67
65
|
+value: ValueWithDefault<string>;
|
|
68
66
|
+syntax: CSSSyntaxType;
|
|
69
67
|
}
|
|
70
|
-
declare export class Num<+T:
|
|
68
|
+
declare export class Num<+T: InnerValue> implements ICSSType<T> {
|
|
71
69
|
+value: ValueWithDefault<string>;
|
|
72
70
|
+syntax: CSSSyntaxType;
|
|
73
71
|
}
|
|
74
|
-
declare export class Resolution<+T:
|
|
72
|
+
declare export class Resolution<+T: InnerValue> implements ICSSType<T> {
|
|
75
73
|
+value: ValueWithDefault<string>;
|
|
76
74
|
+syntax: CSSSyntaxType;
|
|
77
75
|
}
|
|
78
|
-
declare export class Time<+T:
|
|
76
|
+
declare export class Time<+T: InnerValue> implements ICSSType<T> {
|
|
79
77
|
+value: ValueWithDefault<string>;
|
|
80
78
|
+syntax: CSSSyntaxType;
|
|
81
79
|
}
|
|
82
|
-
declare export class TransformFunction<+T:
|
|
80
|
+
declare export class TransformFunction<+T: InnerValue> implements ICSSType<T> {
|
|
83
81
|
+value: ValueWithDefault<string>;
|
|
84
82
|
+syntax: CSSSyntaxType;
|
|
85
83
|
}
|
|
86
|
-
declare export class TransformList<+T:
|
|
84
|
+
declare export class TransformList<+T: InnerValue> implements ICSSType<T> {
|
|
87
85
|
+value: ValueWithDefault<string>;
|
|
88
86
|
+syntax: CSSSyntaxType;
|
|
89
87
|
}
|
|
90
88
|
|
|
91
|
-
export type CSSType<+T:
|
|
89
|
+
export type CSSType<+T: InnerValue> =
|
|
92
90
|
| Angle<T>
|
|
93
91
|
| Color<T>
|
|
94
92
|
| Url<T>
|
|
@@ -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
|
+
declare function inject(cssText: string, priority: number): string;
|
|
11
|
+
export default inject;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 export default function inject(
|
|
11
|
+
cssText: string,
|
|
12
|
+
priority: number,
|
|
13
|
+
): string;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
2
|
+
function addSpecificityLevel(cssText, index) {
|
|
3
|
+
if (cssText.startsWith('@keyframes')) {
|
|
4
|
+
return cssText;
|
|
5
|
+
}
|
|
6
|
+
const pseudoSelector = Array.from({
|
|
7
|
+
length: index
|
|
8
|
+
}).map(() => ':not(#\\#)').join('');
|
|
9
|
+
const lastOpenCurly = cssText.includes('::') ? cssText.indexOf('::') : cssText.lastIndexOf('{');
|
|
10
|
+
const beforeCurly = cssText.slice(0, lastOpenCurly);
|
|
11
|
+
const afterCurly = cssText.slice(lastOpenCurly);
|
|
12
|
+
return `${beforeCurly}${pseudoSelector}${afterCurly}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function createCSSStyleSheet(rootNode, textContent) {
|
|
16
|
+
if (canUseDOM) {
|
|
17
|
+
const root = rootNode != null ? rootNode : document;
|
|
18
|
+
let element = root?.querySelector('[data-stylex]');
|
|
19
|
+
if (element == null) {
|
|
20
|
+
element = document.createElement('style');
|
|
21
|
+
element.setAttribute('data-stylex', 'true');
|
|
22
|
+
if (typeof textContent === 'string') {
|
|
23
|
+
element.appendChild(document.createTextNode(textContent));
|
|
24
|
+
}
|
|
25
|
+
const container = root.nodeType === Node.DOCUMENT_NODE ? root.head : root;
|
|
26
|
+
if (container) {
|
|
27
|
+
const firstChild = container.firstChild;
|
|
28
|
+
if (firstChild != null) {
|
|
29
|
+
container.insertBefore(element, firstChild);
|
|
30
|
+
} else {
|
|
31
|
+
container.appendChild(element);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return element.sheet;
|
|
36
|
+
} else {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createOrderedCSSStyleSheet(sheet) {
|
|
42
|
+
const groups = {};
|
|
43
|
+
const seenRules = {};
|
|
44
|
+
if (sheet != null) {
|
|
45
|
+
let group = 0;
|
|
46
|
+
for (let i = 0; i < sheet.cssRules.length; i++) {
|
|
47
|
+
const cssRule = sheet.cssRules[i];
|
|
48
|
+
const cssText = cssRule.cssText;
|
|
49
|
+
if (cssText.indexOf('stylesheet-group') > -1) {
|
|
50
|
+
group = decodeGroupRule(cssRule);
|
|
51
|
+
groups[group] = {
|
|
52
|
+
start: i,
|
|
53
|
+
rules: [cssText]
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
const key = getSeenRuleKey(cssText);
|
|
57
|
+
if (key != null) {
|
|
58
|
+
seenRules[key] = true;
|
|
59
|
+
groups[group].rules.push(cssText);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function sheetInsert(sheet, group, text) {
|
|
65
|
+
const orderedGroups = getOrderedGroups(groups);
|
|
66
|
+
const groupIndex = orderedGroups.indexOf(group);
|
|
67
|
+
const nextGroupIndex = groupIndex + 1;
|
|
68
|
+
const nextGroup = orderedGroups[nextGroupIndex];
|
|
69
|
+
const position = nextGroup != null && groups[nextGroup].start != null ? groups[nextGroup].start : sheet.cssRules.length;
|
|
70
|
+
const isInserted = insertRuleAt(sheet, text, position);
|
|
71
|
+
if (isInserted) {
|
|
72
|
+
if (groups[group].start == null) {
|
|
73
|
+
groups[group].start = position;
|
|
74
|
+
}
|
|
75
|
+
for (let i = nextGroupIndex; i < orderedGroups.length; i += 1) {
|
|
76
|
+
const groupNumber = orderedGroups[i];
|
|
77
|
+
const previousStart = groups[groupNumber].start || 0;
|
|
78
|
+
groups[groupNumber].start = previousStart + 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return isInserted;
|
|
82
|
+
}
|
|
83
|
+
const OrderedCSSStyleSheet = {
|
|
84
|
+
getTextContent() {
|
|
85
|
+
return getOrderedGroups(groups).map(group => {
|
|
86
|
+
const rules = groups[group].rules;
|
|
87
|
+
const marker = rules.shift();
|
|
88
|
+
rules.sort();
|
|
89
|
+
if (marker !== undefined) {
|
|
90
|
+
rules.unshift(marker);
|
|
91
|
+
}
|
|
92
|
+
return rules.join('\n');
|
|
93
|
+
}).join('\n');
|
|
94
|
+
},
|
|
95
|
+
insert(cssText, groupValue) {
|
|
96
|
+
const group = Number(groupValue);
|
|
97
|
+
if (groups[group] == null) {
|
|
98
|
+
const markerRule = encodeGroupRule(group);
|
|
99
|
+
groups[group] = {
|
|
100
|
+
start: null,
|
|
101
|
+
rules: [markerRule]
|
|
102
|
+
};
|
|
103
|
+
if (sheet != null) {
|
|
104
|
+
sheetInsert(sheet, group, markerRule);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const key = getSeenRuleKey(cssText);
|
|
108
|
+
if (key != null && seenRules[key] == null) {
|
|
109
|
+
seenRules[key] = true;
|
|
110
|
+
let shouldUpdate = true;
|
|
111
|
+
if (sheet != null) {
|
|
112
|
+
const isInserted = sheetInsert(sheet, group, cssText);
|
|
113
|
+
if (!isInserted) {
|
|
114
|
+
shouldUpdate = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (shouldUpdate) {
|
|
118
|
+
groups[group].rules.push(cssText);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return OrderedCSSStyleSheet;
|
|
124
|
+
}
|
|
125
|
+
function encodeGroupRule(group) {
|
|
126
|
+
return `[stylesheet-group="${group}"]{}`;
|
|
127
|
+
}
|
|
128
|
+
const groupPattern = /["']/g;
|
|
129
|
+
function decodeGroupRule(cssRule) {
|
|
130
|
+
return Number(cssRule.selectorText.split(groupPattern)[1]);
|
|
131
|
+
}
|
|
132
|
+
function getOrderedGroups(obj) {
|
|
133
|
+
return Object.keys(obj).map(Number).sort((a, b) => a > b ? 1 : -1);
|
|
134
|
+
}
|
|
135
|
+
const selectorPattern = /\s*([,])\s*/g;
|
|
136
|
+
const conditionalRulePattern = /^@(media|supports|container)\s*\([^)]+\)\s*{/;
|
|
137
|
+
function getSeenRuleKey(cssText) {
|
|
138
|
+
if (conditionalRulePattern.test(cssText)) {
|
|
139
|
+
const index = cssText.indexOf('{');
|
|
140
|
+
const query = cssText.substring(0, index).trim();
|
|
141
|
+
const rest = cssText.substring(index + 1).trim();
|
|
142
|
+
const next = getSeenRuleKey(rest);
|
|
143
|
+
const normalizedNext = next !== null && next !== '' ? next.replace(selectorPattern, '$1') : '';
|
|
144
|
+
return `${query} { ${normalizedNext}`;
|
|
145
|
+
} else {
|
|
146
|
+
const selector = cssText.split('{')[0].trim();
|
|
147
|
+
return selector !== '' ? selector.replace(selectorPattern, '$1') : null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function insertRuleAt(root, cssText, position) {
|
|
151
|
+
try {
|
|
152
|
+
root.insertRule(cssText, position);
|
|
153
|
+
return true;
|
|
154
|
+
} catch (e) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const roots = new WeakMap();
|
|
160
|
+
const sheets = [];
|
|
161
|
+
function createSheet(root) {
|
|
162
|
+
let sheet;
|
|
163
|
+
if (canUseDOM) {
|
|
164
|
+
const rootNode = document;
|
|
165
|
+
if (sheets.length === 0) {
|
|
166
|
+
sheet = createOrderedCSSStyleSheet(createCSSStyleSheet(rootNode));
|
|
167
|
+
roots.set(rootNode, sheets.length);
|
|
168
|
+
sheets.push(sheet);
|
|
169
|
+
} else {
|
|
170
|
+
const index = roots.get(rootNode);
|
|
171
|
+
if (index == null) {
|
|
172
|
+
const initialSheet = sheets[0];
|
|
173
|
+
const textContent = initialSheet != null ? initialSheet.getTextContent() : '';
|
|
174
|
+
sheet = createOrderedCSSStyleSheet(createCSSStyleSheet(rootNode, textContent));
|
|
175
|
+
roots.set(rootNode, sheets.length);
|
|
176
|
+
sheets.push(sheet);
|
|
177
|
+
} else {
|
|
178
|
+
sheet = sheets[index];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
if (sheets.length === 0) {
|
|
183
|
+
sheet = createOrderedCSSStyleSheet(createCSSStyleSheet());
|
|
184
|
+
sheets.push(sheet);
|
|
185
|
+
} else {
|
|
186
|
+
sheet = sheets[0];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
getTextContent() {
|
|
191
|
+
return sheet.getTextContent();
|
|
192
|
+
},
|
|
193
|
+
insert(cssText, groupValue) {
|
|
194
|
+
sheets.forEach(s => {
|
|
195
|
+
s.insert(cssText, groupValue);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const sheet = createSheet();
|
|
202
|
+
function inject(cssText, priority) {
|
|
203
|
+
const text = addSpecificityLevel(cssText, Math.floor(priority / 1000));
|
|
204
|
+
sheet.insert(text, priority);
|
|
205
|
+
return text;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { inject as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
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 function createCSSStyleSheet(
|
|
11
|
+
rootNode?: Node,
|
|
12
|
+
textContent?: string,
|
|
13
|
+
): null | undefined | CSSStyleSheet;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 export function createCSSStyleSheet(
|
|
11
|
+
rootNode?: Node,
|
|
12
|
+
textContent?: string,
|
|
13
|
+
): ?CSSStyleSheet;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 OrderedCSSStyleSheet = {
|
|
11
|
+
getTextContent: () => string;
|
|
12
|
+
insert: (cssText: string, groupValue: number) => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Order-based insertion of CSS.
|
|
16
|
+
*
|
|
17
|
+
* Each rule is associated with a numerically defined group.
|
|
18
|
+
* Groups are ordered within the style sheet according to their number, with the
|
|
19
|
+
* lowest first.
|
|
20
|
+
*
|
|
21
|
+
* Groups are implemented using marker rules. The selector of the first rule of
|
|
22
|
+
* each group is used only to encode the group number for hydration. An
|
|
23
|
+
* alternative implementation could rely on CSSMediaRule, allowing groups to be
|
|
24
|
+
* treated as a sub-sheet, but the Edge implementation of CSSMediaRule is
|
|
25
|
+
* broken.
|
|
26
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CSSMediaRule
|
|
27
|
+
* https://gist.github.com/necolas/aa0c37846ad6bd3b05b727b959e82674
|
|
28
|
+
*/
|
|
29
|
+
export declare function createOrderedCSSStyleSheet(
|
|
30
|
+
sheet: null | undefined | CSSStyleSheet,
|
|
31
|
+
): OrderedCSSStyleSheet;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 OrderedCSSStyleSheet = {|
|
|
11
|
+
getTextContent: () => string,
|
|
12
|
+
insert: (cssText: string, groupValue: number) => void,
|
|
13
|
+
|};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Order-based insertion of CSS.
|
|
17
|
+
*
|
|
18
|
+
* Each rule is associated with a numerically defined group.
|
|
19
|
+
* Groups are ordered within the style sheet according to their number, with the
|
|
20
|
+
* lowest first.
|
|
21
|
+
*
|
|
22
|
+
* Groups are implemented using marker rules. The selector of the first rule of
|
|
23
|
+
* each group is used only to encode the group number for hydration. An
|
|
24
|
+
* alternative implementation could rely on CSSMediaRule, allowing groups to be
|
|
25
|
+
* treated as a sub-sheet, but the Edge implementation of CSSMediaRule is
|
|
26
|
+
* broken.
|
|
27
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CSSMediaRule
|
|
28
|
+
* https://gist.github.com/necolas/aa0c37846ad6bd3b05b727b959e82674
|
|
29
|
+
*/
|
|
30
|
+
declare export function createOrderedCSSStyleSheet(
|
|
31
|
+
sheet: ?CSSStyleSheet,
|
|
32
|
+
): OrderedCSSStyleSheet;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { OrderedCSSStyleSheet } from './createOrderedCSSStyleSheet';
|
|
11
|
+
type Sheet = Omit<OrderedCSSStyleSheet, keyof ({})> & {};
|
|
12
|
+
export declare function createSheet(root?: HTMLElement): Sheet;
|
|
@@ -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
|
+
import type { OrderedCSSStyleSheet } from './createOrderedCSSStyleSheet';
|
|
11
|
+
|
|
12
|
+
type Sheet = {
|
|
13
|
+
...OrderedCSSStyleSheet,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare export function createSheet(root?: HTMLElement): Sheet;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 const canUseDOM: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Adds :not(#\#) to selectors to increase their specificity.
|
|
13
|
+
* This is used to polyfill @layer
|
|
14
|
+
*/
|
|
15
|
+
export declare function addSpecificityLevel(
|
|
16
|
+
cssText: string,
|
|
17
|
+
index: number,
|
|
18
|
+
): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 export const canUseDOM: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Adds :not(#\#) to selectors to increase their specificity.
|
|
14
|
+
* This is used to polyfill @layer
|
|
15
|
+
*/
|
|
16
|
+
declare export function addSpecificityLevel(
|
|
17
|
+
cssText: string,
|
|
18
|
+
index: number,
|
|
19
|
+
): string;
|
|
@@ -0,0 +1,135 @@
|
|
|
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 {
|
|
11
|
+
CompiledStyles,
|
|
12
|
+
InlineStyles,
|
|
13
|
+
Keyframes,
|
|
14
|
+
StaticStyles,
|
|
15
|
+
StaticStylesWithout,
|
|
16
|
+
StyleX$Create,
|
|
17
|
+
StyleX$CreateTheme,
|
|
18
|
+
StyleX$DefineVars,
|
|
19
|
+
StyleX$DefineConsts,
|
|
20
|
+
StyleXArray,
|
|
21
|
+
StyleXStyles,
|
|
22
|
+
StyleXStylesWithout,
|
|
23
|
+
Theme,
|
|
24
|
+
VarGroup,
|
|
25
|
+
PositionTry,
|
|
26
|
+
} from './types/StyleXTypes';
|
|
27
|
+
import type { ValueWithDefault } from './types/StyleXUtils';
|
|
28
|
+
import * as Types from './types/VarTypes';
|
|
29
|
+
export type {
|
|
30
|
+
StaticStyles,
|
|
31
|
+
StaticStylesWithout,
|
|
32
|
+
StyleXStyles,
|
|
33
|
+
StyleXStylesWithout,
|
|
34
|
+
Theme,
|
|
35
|
+
Types,
|
|
36
|
+
VarGroup,
|
|
37
|
+
};
|
|
38
|
+
export declare const create: StyleX$Create;
|
|
39
|
+
export declare const createTheme: StyleX$CreateTheme;
|
|
40
|
+
export declare const defineConsts: StyleX$DefineConsts;
|
|
41
|
+
export declare const defineVars: StyleX$DefineVars;
|
|
42
|
+
export declare const firstThatWorks: <T extends string | number>(
|
|
43
|
+
..._styles: ReadonlyArray<T>
|
|
44
|
+
) => ReadonlyArray<T>;
|
|
45
|
+
export declare const keyframes: (_keyframes: Keyframes) => string;
|
|
46
|
+
export declare const positionTry: (_positionTry: PositionTry) => string;
|
|
47
|
+
export declare function props(
|
|
48
|
+
this: null | undefined | unknown,
|
|
49
|
+
...styles: ReadonlyArray<
|
|
50
|
+
StyleXArray<
|
|
51
|
+
| (null | undefined | CompiledStyles)
|
|
52
|
+
| boolean
|
|
53
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
54
|
+
>
|
|
55
|
+
>
|
|
56
|
+
): Readonly<{
|
|
57
|
+
className?: string;
|
|
58
|
+
'data-style-src'?: string;
|
|
59
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const types: {
|
|
62
|
+
angle: <T extends string | 0 = string | 0>(
|
|
63
|
+
_v: ValueWithDefault<T>,
|
|
64
|
+
) => Types.Angle<T>;
|
|
65
|
+
color: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Color<T>;
|
|
66
|
+
url: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Url<T>;
|
|
67
|
+
image: <T extends string = string>(_v: ValueWithDefault<T>) => Types.Image<T>;
|
|
68
|
+
integer: <T extends number | string = number | string>(
|
|
69
|
+
_v: ValueWithDefault<T>,
|
|
70
|
+
) => Types.Integer<T>;
|
|
71
|
+
lengthPercentage: <T extends number | string = number | string>(
|
|
72
|
+
_v: ValueWithDefault<T>,
|
|
73
|
+
) => Types.LengthPercentage<T>;
|
|
74
|
+
length: <T extends number | string = number | string>(
|
|
75
|
+
_v: ValueWithDefault<T>,
|
|
76
|
+
) => Types.Length<T>;
|
|
77
|
+
percentage: <T extends number | string = number | string>(
|
|
78
|
+
_v: ValueWithDefault<T>,
|
|
79
|
+
) => Types.Percentage<T>;
|
|
80
|
+
number: <T extends number | string = number | string>(
|
|
81
|
+
_v: ValueWithDefault<T>,
|
|
82
|
+
) => Types.Num<T>;
|
|
83
|
+
resolution: <T extends string = string>(
|
|
84
|
+
_v: ValueWithDefault<T>,
|
|
85
|
+
) => Types.Resolution<T>;
|
|
86
|
+
time: <T extends string | 0 = string | 0>(
|
|
87
|
+
_v: ValueWithDefault<T>,
|
|
88
|
+
) => Types.Time<T>;
|
|
89
|
+
transformFunction: <T extends string = string>(
|
|
90
|
+
_v: ValueWithDefault<T>,
|
|
91
|
+
) => Types.TransformFunction<T>;
|
|
92
|
+
transformList: <T extends string = string>(
|
|
93
|
+
_v: ValueWithDefault<T>,
|
|
94
|
+
) => Types.TransformList<T>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* DO NOT USE. Legacy export for Meta
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* DO NOT USE. Legacy export for Meta
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
type IStyleX = {
|
|
105
|
+
(
|
|
106
|
+
...styles: ReadonlyArray<
|
|
107
|
+
StyleXArray<(null | undefined | CompiledStyles) | boolean>
|
|
108
|
+
>
|
|
109
|
+
): string;
|
|
110
|
+
create: StyleX$Create;
|
|
111
|
+
createTheme: StyleX$CreateTheme;
|
|
112
|
+
defineVars: StyleX$DefineVars;
|
|
113
|
+
firstThatWorks: <T extends string | number>(
|
|
114
|
+
...v: ReadonlyArray<T>
|
|
115
|
+
) => ReadonlyArray<T>;
|
|
116
|
+
keyframes: (keyframes: Keyframes) => string;
|
|
117
|
+
positionTry: (positionTry: PositionTry) => string;
|
|
118
|
+
props: (
|
|
119
|
+
this: null | undefined | unknown,
|
|
120
|
+
...styles: ReadonlyArray<
|
|
121
|
+
StyleXArray<
|
|
122
|
+
| (null | undefined | CompiledStyles)
|
|
123
|
+
| boolean
|
|
124
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
125
|
+
>
|
|
126
|
+
>
|
|
127
|
+
) => Readonly<{
|
|
128
|
+
className?: string;
|
|
129
|
+
'data-style-src'?: string;
|
|
130
|
+
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
131
|
+
}>;
|
|
132
|
+
types: typeof types;
|
|
133
|
+
__customProperties?: { [$$Key$$: string]: unknown };
|
|
134
|
+
};
|
|
135
|
+
export declare const legacyMerge: IStyleX;
|