@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.
Files changed (67) hide show
  1. package/README.md +0 -27
  2. package/lib/{stylex-inject.d.ts → cjs/inject.d.ts} +1 -5
  3. package/lib/cjs/inject.js +210 -0
  4. package/lib/{stylex-inject.js.flow → cjs/inject.js.flow} +2 -3
  5. package/lib/cjs/stylesheet/createCSSStyleSheet.d.ts +13 -0
  6. package/lib/cjs/stylesheet/createCSSStyleSheet.js.flow +13 -0
  7. package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
  8. package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
  9. package/lib/cjs/stylesheet/createSheet.d.ts +12 -0
  10. package/lib/cjs/stylesheet/createSheet.js.flow +16 -0
  11. package/lib/cjs/stylesheet/utils.d.ts +18 -0
  12. package/lib/cjs/stylesheet/utils.js.flow +19 -0
  13. package/lib/{stylex.d.ts → cjs/stylex.d.ts} +8 -21
  14. package/lib/cjs/stylex.js +242 -0
  15. package/lib/{stylex.js.flow → cjs/stylex.js.flow} +10 -26
  16. package/lib/{StyleXCSSTypes.d.ts → cjs/types/StyleXCSSTypes.d.ts} +22 -0
  17. package/lib/{StyleXCSSTypes.js.flow → cjs/types/StyleXCSSTypes.js.flow} +25 -0
  18. package/lib/{StyleXTypes.d.ts → cjs/types/StyleXTypes.d.ts} +60 -5
  19. package/lib/{StyleXTypes.js.flow → cjs/types/StyleXTypes.js.flow} +56 -5
  20. package/lib/{VarTypes.d.ts → cjs/types/VarTypes.d.ts} +19 -18
  21. package/lib/{VarTypes.js.flow → cjs/types/VarTypes.js.flow} +17 -19
  22. package/lib/es/inject.d.ts +11 -0
  23. package/lib/es/inject.js.flow +13 -0
  24. package/lib/es/inject.mjs +208 -0
  25. package/lib/es/stylesheet/createCSSStyleSheet.d.ts +13 -0
  26. package/lib/es/stylesheet/createCSSStyleSheet.js.flow +13 -0
  27. package/lib/es/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
  28. package/lib/es/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
  29. package/lib/es/stylesheet/createSheet.d.ts +12 -0
  30. package/lib/es/stylesheet/createSheet.js.flow +16 -0
  31. package/lib/es/stylesheet/utils.d.ts +18 -0
  32. package/lib/es/stylesheet/utils.js.flow +19 -0
  33. package/lib/es/stylex.d.ts +135 -0
  34. package/lib/es/stylex.js.flow +134 -0
  35. package/lib/es/stylex.mjs +8 -20
  36. package/lib/es/types/StyleXCSSTypes.d.ts +1487 -0
  37. package/lib/es/types/StyleXCSSTypes.js.flow +1580 -0
  38. package/lib/es/types/StyleXOpaqueTypes.d.ts +11 -0
  39. package/lib/es/types/StyleXOpaqueTypes.js.flow +16 -0
  40. package/lib/es/types/StyleXTypes.d.ts +292 -0
  41. package/lib/es/types/StyleXTypes.js.flow +240 -0
  42. package/lib/es/types/StyleXUtils.d.ts +15 -0
  43. package/lib/es/types/StyleXUtils.js.flow +15 -0
  44. package/lib/es/types/VarTypes.d.ts +104 -0
  45. package/lib/es/types/VarTypes.js.flow +102 -0
  46. package/package.json +20 -28
  47. package/lib/StyleXCSSTypes.js +0 -1
  48. package/lib/StyleXOpaqueTypes.js +0 -1
  49. package/lib/StyleXSheet.d.ts +0 -49
  50. package/lib/StyleXSheet.js +0 -188
  51. package/lib/StyleXSheet.js.flow +0 -49
  52. package/lib/StyleXTypes.js +0 -1
  53. package/lib/VarTypes.js +0 -1
  54. package/lib/es/StyleXCSSTypes.mjs +0 -1
  55. package/lib/es/StyleXOpaqueTypes.mjs +0 -0
  56. package/lib/es/StyleXSheet.mjs +0 -247
  57. package/lib/es/StyleXTypes.mjs +0 -1
  58. package/lib/es/VarTypes.mjs +0 -0
  59. package/lib/es/stylex-inject.mjs +0 -5
  60. package/lib/es/util-types.mjs +0 -0
  61. package/lib/stylex-inject.js +0 -11
  62. package/lib/stylex.js +0 -125
  63. package/lib/util-types.js +0 -1
  64. /package/lib/{StyleXOpaqueTypes.d.ts → cjs/types/StyleXOpaqueTypes.d.ts} +0 -0
  65. /package/lib/{StyleXOpaqueTypes.js.flow → cjs/types/StyleXOpaqueTypes.js.flow} +0 -0
  66. /package/lib/{util-types.d.ts → cjs/types/StyleXUtils.d.ts} +0 -0
  67. /package/lib/{util-types.js.flow → cjs/types/StyleXUtils.js.flow} +0 -0
@@ -7,7 +7,7 @@
7
7
  *
8
8
  */
9
9
 
10
- import type { ValueWithDefault } from './util-types';
10
+ import type { ValueWithDefault } from './StyleXUtils';
11
11
  export type CSSSyntax =
12
12
  | '*'
13
13
  | '<length>'
@@ -25,69 +25,70 @@ export type CSSSyntax =
25
25
  | '<custom-ident>'
26
26
  | '<transform-list>';
27
27
  type CSSSyntaxType = CSSSyntax;
28
- interface ICSSType<_T extends string | number> {
28
+ type InnerValue = null | string | number;
29
+ interface ICSSType<_T extends InnerValue> {
29
30
  readonly value: ValueWithDefault<string>;
30
31
  readonly syntax: CSSSyntaxType;
31
32
  }
32
- export declare class Angle<T extends string | 0> implements ICSSType<T> {
33
+ export declare class Angle<T extends InnerValue> implements ICSSType<T> {
33
34
  readonly value: ValueWithDefault<string>;
34
35
  readonly syntax: CSSSyntaxType;
35
36
  }
36
- export declare class Color<T extends string> implements ICSSType<T> {
37
+ export declare class Color<T extends InnerValue> implements ICSSType<T> {
37
38
  readonly value: ValueWithDefault<string>;
38
39
  readonly syntax: CSSSyntaxType;
39
40
  }
40
- export declare class Url<T extends string> implements ICSSType<T> {
41
+ export declare class Url<T extends InnerValue> implements ICSSType<T> {
41
42
  readonly value: ValueWithDefault<string>;
42
43
  readonly syntax: CSSSyntaxType;
43
44
  }
44
- export declare class Image<T extends string> implements ICSSType<T> {
45
+ export declare class Image<T extends InnerValue> implements ICSSType<T> {
45
46
  readonly value: ValueWithDefault<string>;
46
47
  readonly syntax: CSSSyntaxType;
47
48
  }
48
- export declare class Integer<T extends string | number> implements ICSSType<T> {
49
+ export declare class Integer<T extends InnerValue> implements ICSSType<T> {
49
50
  readonly value: ValueWithDefault<string>;
50
51
  readonly syntax: CSSSyntaxType;
51
52
  }
52
- export declare class LengthPercentage<T extends string | number>
53
+ export declare class LengthPercentage<T extends InnerValue>
53
54
  implements ICSSType<T>
54
55
  {
55
56
  readonly value: ValueWithDefault<string>;
56
57
  readonly syntax: CSSSyntaxType;
57
58
  }
58
- export declare class Length<T extends string | number> implements ICSSType<T> {
59
+ export declare class Length<T extends InnerValue> implements ICSSType<T> {
59
60
  readonly value: ValueWithDefault<string>;
60
61
  readonly syntax: CSSSyntaxType;
61
62
  }
62
- export declare class Percentage<T extends string | number>
63
- implements ICSSType<T>
64
- {
63
+ export declare class Percentage<T extends InnerValue> implements ICSSType<T> {
65
64
  readonly value: ValueWithDefault<string>;
66
65
  readonly syntax: CSSSyntaxType;
67
66
  }
68
- export declare class Num<T extends string | number> implements ICSSType<T> {
67
+ export declare class Num<T extends InnerValue> implements ICSSType<T> {
69
68
  readonly value: ValueWithDefault<string>;
70
69
  readonly syntax: CSSSyntaxType;
71
70
  }
72
- export declare class Resolution<T extends string> implements ICSSType<T> {
71
+ export declare class Resolution<T extends InnerValue> implements ICSSType<T> {
73
72
  readonly value: ValueWithDefault<string>;
74
73
  readonly syntax: CSSSyntaxType;
75
74
  }
76
- export declare class Time<T extends string | 0> implements ICSSType<T> {
75
+ export declare class Time<T extends InnerValue> implements ICSSType<T> {
77
76
  readonly value: ValueWithDefault<string>;
78
77
  readonly syntax: CSSSyntaxType;
79
78
  }
80
- export declare class TransformFunction<T extends string>
79
+ export declare class TransformFunction<T extends InnerValue>
81
80
  implements ICSSType<T>
82
81
  {
83
82
  readonly value: ValueWithDefault<string>;
84
83
  readonly syntax: CSSSyntaxType;
85
84
  }
86
- export declare class TransformList<T extends string> implements ICSSType<T> {
85
+ export declare class TransformList<T extends InnerValue>
86
+ implements ICSSType<T>
87
+ {
87
88
  readonly value: ValueWithDefault<string>;
88
89
  readonly syntax: CSSSyntaxType;
89
90
  }
90
- export type CSSType<T extends null | string | number> =
91
+ export type CSSType<T extends InnerValue> =
91
92
  | Angle<T>
92
93
  | Color<T>
93
94
  | Url<T>
@@ -7,7 +7,7 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { ValueWithDefault } from './util-types';
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: string | number> {
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: string> implements ICSSType<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: string> implements ICSSType<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: string> implements ICSSType<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: string | number> implements ICSSType<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: string | number>
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: string | number> implements ICSSType<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: string | number> implements ICSSType<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: string | number> implements ICSSType<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: string> implements ICSSType<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: string | 0> implements ICSSType<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: string> implements ICSSType<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: string> implements ICSSType<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: null | string | number> =
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;