@master/css-engine 2.0.0-rc.70

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 (68) hide show
  1. package/README.md +57 -0
  2. package/dist/animation-rule.d.ts +12 -0
  3. package/dist/animation-rule.mjs +38 -0
  4. package/dist/common.d.ts +40 -0
  5. package/dist/common.mjs +114 -0
  6. package/dist/compile-manifest.d.ts +54 -0
  7. package/dist/compile-manifest.mjs +451 -0
  8. package/dist/compiler.d.ts +32 -0
  9. package/dist/compiler.mjs +38 -0
  10. package/dist/core.d.ts +141 -0
  11. package/dist/core.mjs +848 -0
  12. package/dist/emitted-globals.d.ts +4 -0
  13. package/dist/emitted-globals.mjs +1 -0
  14. package/dist/hydration-manifest.d.ts +4 -0
  15. package/dist/hydration-manifest.mjs +61 -0
  16. package/dist/index.d.ts +22 -0
  17. package/dist/index.mjs +15 -0
  18. package/dist/key-aliases.d.ts +4 -0
  19. package/dist/key-aliases.mjs +95 -0
  20. package/dist/layer.d.ts +17 -0
  21. package/dist/layer.mjs +78 -0
  22. package/dist/namespaces.d.ts +5 -0
  23. package/dist/namespaces.mjs +28 -0
  24. package/dist/native-value-namespaces.d.ts +9 -0
  25. package/dist/native-value-namespaces.mjs +346 -0
  26. package/dist/non-layer.d.ts +12 -0
  27. package/dist/non-layer.mjs +53 -0
  28. package/dist/rule.d.ts +7 -0
  29. package/dist/rule.mjs +14 -0
  30. package/dist/theme-layer.d.ts +21 -0
  31. package/dist/theme-layer.mjs +52 -0
  32. package/dist/utility-layer.d.ts +10 -0
  33. package/dist/utility-layer.mjs +118 -0
  34. package/dist/utility.d.ts +102 -0
  35. package/dist/utility.mjs +1263 -0
  36. package/dist/utils/collect-animation-names.d.ts +10 -0
  37. package/dist/utils/collect-animation-names.mjs +61 -0
  38. package/dist/utils/collect-variable-names.d.ts +3 -0
  39. package/dist/utils/collect-variable-names.mjs +18 -0
  40. package/dist/utils/compare-rule-priority.d.ts +14 -0
  41. package/dist/utils/compare-rule-priority.mjs +136 -0
  42. package/dist/utils/css-variables.d.ts +12 -0
  43. package/dist/utils/css-variables.mjs +197 -0
  44. package/dist/utils/find-native-css-rule-index.d.ts +1 -0
  45. package/dist/utils/find-native-css-rule-index.mjs +10 -0
  46. package/dist/utils/generate-at.d.ts +2 -0
  47. package/dist/utils/generate-at.mjs +32 -0
  48. package/dist/utils/generate-selector.d.ts +2 -0
  49. package/dist/utils/generate-selector.mjs +48 -0
  50. package/dist/utils/natural-compare.d.ts +2 -0
  51. package/dist/utils/natural-compare.mjs +6 -0
  52. package/dist/utils/parse-at.d.ts +44 -0
  53. package/dist/utils/parse-at.mjs +179 -0
  54. package/dist/utils/parse-pair.d.ts +8 -0
  55. package/dist/utils/parse-pair.mjs +46 -0
  56. package/dist/utils/parse-selector.d.ts +19 -0
  57. package/dist/utils/parse-selector.mjs +124 -0
  58. package/dist/utils/parse-value.d.ts +2 -0
  59. package/dist/utils/parse-value.mjs +37 -0
  60. package/dist/utils/replace-char-outside-quotes.d.ts +1 -0
  61. package/dist/utils/replace-char-outside-quotes.mjs +19 -0
  62. package/dist/utils/split-char-outside-quotes.d.ts +1 -0
  63. package/dist/utils/split-char-outside-quotes.mjs +27 -0
  64. package/dist/utils/wrap-at-rules.d.ts +1 -0
  65. package/dist/utils/wrap-at-rules.mjs +10 -0
  66. package/dist/variable-rule.d.ts +26 -0
  67. package/dist/variable-rule.mjs +105 -0
  68. package/package.json +1 -0
@@ -0,0 +1,346 @@
1
+ import { builtinNamespaceRef } from './namespaces.mjs';
2
+
3
+ function freezeNamespace(namespace) {
4
+ Object.freeze(namespace.properties);
5
+ Object.freeze(namespace.variableAliasRefs);
6
+ return Object.freeze(namespace);
7
+ }
8
+ const spacingProperties = Object.freeze([
9
+ 'background-position',
10
+ 'bottom',
11
+ 'border-spacing',
12
+ 'column-gap',
13
+ 'gap',
14
+ 'inset',
15
+ 'inset-block',
16
+ 'inset-block-end',
17
+ 'inset-block-start',
18
+ 'inset-inline',
19
+ 'inset-inline-end',
20
+ 'inset-inline-start',
21
+ 'left',
22
+ 'margin',
23
+ 'margin-block',
24
+ 'margin-block-end',
25
+ 'margin-block-start',
26
+ 'margin-bottom',
27
+ 'margin-inline',
28
+ 'margin-inline-end',
29
+ 'margin-inline-start',
30
+ 'margin-left',
31
+ 'margin-right',
32
+ 'margin-top',
33
+ 'mask-position',
34
+ 'object-position',
35
+ 'outline-offset',
36
+ 'padding',
37
+ 'padding-block',
38
+ 'padding-block-end',
39
+ 'padding-block-start',
40
+ 'padding-bottom',
41
+ 'padding-inline',
42
+ 'padding-inline-end',
43
+ 'padding-inline-start',
44
+ 'padding-left',
45
+ 'padding-right',
46
+ 'padding-top',
47
+ 'perspective',
48
+ 'perspective-origin',
49
+ 'right',
50
+ 'row-gap',
51
+ 'scroll-margin',
52
+ 'scroll-margin-block',
53
+ 'scroll-margin-block-end',
54
+ 'scroll-margin-block-start',
55
+ 'scroll-margin-bottom',
56
+ 'scroll-margin-inline',
57
+ 'scroll-margin-inline-end',
58
+ 'scroll-margin-inline-start',
59
+ 'scroll-margin-left',
60
+ 'scroll-margin-right',
61
+ 'scroll-margin-top',
62
+ 'scroll-padding',
63
+ 'scroll-padding-block',
64
+ 'scroll-padding-block-end',
65
+ 'scroll-padding-block-start',
66
+ 'scroll-padding-bottom',
67
+ 'scroll-padding-inline',
68
+ 'scroll-padding-inline-end',
69
+ 'scroll-padding-inline-start',
70
+ 'scroll-padding-left',
71
+ 'scroll-padding-right',
72
+ 'scroll-padding-top',
73
+ 'shape-margin',
74
+ 'text-indent',
75
+ 'text-underline-offset',
76
+ 'top',
77
+ 'translate',
78
+ 'transform-origin',
79
+ 'word-spacing'
80
+ ]);
81
+ const spacingUnitlessProperties = Object.freeze([
82
+ 'cx',
83
+ 'cy',
84
+ 'stroke-dashoffset',
85
+ 'x',
86
+ 'y'
87
+ ]);
88
+ const containerProperties = Object.freeze([
89
+ 'background-size',
90
+ 'block-size',
91
+ 'contain-intrinsic-block-size',
92
+ 'contain-intrinsic-inline-size',
93
+ 'flex-basis',
94
+ 'height',
95
+ 'inline-size',
96
+ 'max-block-size',
97
+ 'max-height',
98
+ 'max-inline-size',
99
+ 'max-width',
100
+ 'min-block-size',
101
+ 'min-height',
102
+ 'min-inline-size',
103
+ 'min-width',
104
+ 'mask-size',
105
+ 'width'
106
+ ]);
107
+ const radiusProperties = Object.freeze([
108
+ 'border-bottom-left-radius',
109
+ 'border-bottom-right-radius',
110
+ 'border-end-end-radius',
111
+ 'border-end-start-radius',
112
+ 'border-radius',
113
+ 'border-start-end-radius',
114
+ 'border-start-start-radius',
115
+ 'border-top-left-radius',
116
+ 'border-top-right-radius'
117
+ ]);
118
+ const borderColorProperties = Object.freeze([
119
+ 'border',
120
+ 'border-block',
121
+ 'border-block-color',
122
+ 'border-block-end',
123
+ 'border-block-end-color',
124
+ 'border-block-start',
125
+ 'border-block-start-color',
126
+ 'border-bottom',
127
+ 'border-bottom-color',
128
+ 'border-color',
129
+ 'border-inline',
130
+ 'border-inline-color',
131
+ 'border-inline-end',
132
+ 'border-inline-end-color',
133
+ 'border-inline-start',
134
+ 'border-inline-start-color',
135
+ 'border-left',
136
+ 'border-left-color',
137
+ 'border-right',
138
+ 'border-right-color',
139
+ 'border-top',
140
+ 'border-top-color',
141
+ 'outline',
142
+ 'outline-color'
143
+ ]);
144
+ const nativeValueNamespaces = Object.freeze([
145
+ freezeNamespace({
146
+ properties: spacingProperties,
147
+ variableAliasRefs: [
148
+ builtinNamespaceRef('spacing')
149
+ ]
150
+ }),
151
+ freezeNamespace({
152
+ properties: spacingUnitlessProperties,
153
+ variableAliasRefs: [
154
+ builtinNamespaceRef('spacing')
155
+ ]
156
+ }),
157
+ freezeNamespace({
158
+ properties: containerProperties,
159
+ variableAliasRefs: [
160
+ builtinNamespaceRef('container')
161
+ ]
162
+ }),
163
+ freezeNamespace({
164
+ properties: radiusProperties,
165
+ variableAliasRefs: [
166
+ builtinNamespaceRef('radius')
167
+ ]
168
+ }),
169
+ freezeNamespace({
170
+ properties: borderColorProperties,
171
+ variableAliasRefs: [
172
+ builtinNamespaceRef('color-line'),
173
+ builtinNamespaceRef('color')
174
+ ]
175
+ }),
176
+ freezeNamespace({
177
+ properties: Object.freeze([
178
+ 'accent-color',
179
+ 'background-color',
180
+ 'fill',
181
+ 'filter'
182
+ ]),
183
+ variableAliasRefs: [
184
+ builtinNamespaceRef('color')
185
+ ]
186
+ }),
187
+ freezeNamespace({
188
+ properties: Object.freeze([
189
+ 'caret-color'
190
+ ]),
191
+ variableAliasRefs: [
192
+ builtinNamespaceRef('color-text'),
193
+ builtinNamespaceRef('color')
194
+ ]
195
+ }),
196
+ freezeNamespace({
197
+ properties: Object.freeze([
198
+ 'stroke'
199
+ ]),
200
+ variableAliasRefs: [
201
+ builtinNamespaceRef('color-line'),
202
+ builtinNamespaceRef('color')
203
+ ]
204
+ }),
205
+ freezeNamespace({
206
+ properties: Object.freeze([
207
+ 'color'
208
+ ]),
209
+ variableAliasRefs: [
210
+ builtinNamespaceRef('color', true),
211
+ builtinNamespaceRef('color-text'),
212
+ builtinNamespaceRef('color')
213
+ ]
214
+ }),
215
+ freezeNamespace({
216
+ properties: Object.freeze([
217
+ '-webkit-text-fill-color',
218
+ 'text-decoration-color'
219
+ ]),
220
+ variableAliasRefs: [
221
+ builtinNamespaceRef('color-text'),
222
+ builtinNamespaceRef('color')
223
+ ]
224
+ }),
225
+ freezeNamespace({
226
+ properties: Object.freeze([
227
+ '-webkit-text-stroke-color'
228
+ ]),
229
+ variableAliasRefs: [
230
+ builtinNamespaceRef('color')
231
+ ]
232
+ }),
233
+ freezeNamespace({
234
+ properties: Object.freeze([
235
+ 'text-shadow'
236
+ ]),
237
+ variableAliasRefs: [
238
+ builtinNamespaceRef('color')
239
+ ]
240
+ }),
241
+ freezeNamespace({
242
+ properties: Object.freeze([
243
+ 'box-shadow'
244
+ ]),
245
+ variableAliasRefs: [
246
+ builtinNamespaceRef('shadow'),
247
+ builtinNamespaceRef('color')
248
+ ]
249
+ }),
250
+ freezeNamespace({
251
+ properties: Object.freeze([
252
+ 'animation-delay',
253
+ 'animation-duration',
254
+ 'transition-delay',
255
+ 'transition-duration'
256
+ ]),
257
+ variableAliasRefs: [
258
+ builtinNamespaceRef('duration')
259
+ ]
260
+ }),
261
+ freezeNamespace({
262
+ properties: Object.freeze([
263
+ 'animation-timing-function',
264
+ 'transition-timing-function'
265
+ ]),
266
+ variableAliasRefs: [
267
+ builtinNamespaceRef('easing')
268
+ ]
269
+ }),
270
+ freezeNamespace({
271
+ properties: Object.freeze([
272
+ 'animation',
273
+ 'transition'
274
+ ]),
275
+ variableAliasRefs: [
276
+ builtinNamespaceRef('duration'),
277
+ builtinNamespaceRef('easing')
278
+ ]
279
+ }),
280
+ freezeNamespace({
281
+ properties: Object.freeze([
282
+ 'content'
283
+ ]),
284
+ variableAliasRefs: [
285
+ builtinNamespaceRef('content', true)
286
+ ]
287
+ }),
288
+ freezeNamespace({
289
+ properties: Object.freeze([
290
+ 'font-feature-settings'
291
+ ]),
292
+ variableAliasRefs: [
293
+ builtinNamespaceRef('font-feature', true)
294
+ ]
295
+ }),
296
+ freezeNamespace({
297
+ properties: Object.freeze([
298
+ 'font-family'
299
+ ]),
300
+ variableAliasRefs: [
301
+ builtinNamespaceRef('font-family', true)
302
+ ]
303
+ }),
304
+ freezeNamespace({
305
+ properties: Object.freeze([
306
+ 'font-size'
307
+ ]),
308
+ variableAliasRefs: [
309
+ builtinNamespaceRef('font-size', true)
310
+ ]
311
+ }),
312
+ freezeNamespace({
313
+ properties: Object.freeze([
314
+ 'font-weight'
315
+ ]),
316
+ variableAliasRefs: [
317
+ builtinNamespaceRef('font-weight', true)
318
+ ]
319
+ }),
320
+ freezeNamespace({
321
+ properties: Object.freeze([
322
+ 'letter-spacing'
323
+ ]),
324
+ variableAliasRefs: [
325
+ builtinNamespaceRef('tracking')
326
+ ]
327
+ }),
328
+ freezeNamespace({
329
+ properties: Object.freeze([
330
+ 'line-height'
331
+ ]),
332
+ variableAliasRefs: [
333
+ builtinNamespaceRef('leading')
334
+ ]
335
+ }),
336
+ freezeNamespace({
337
+ properties: Object.freeze([
338
+ 'order'
339
+ ]),
340
+ variableAliasRefs: [
341
+ builtinNamespaceRef('order', true)
342
+ ]
343
+ })
344
+ ]);
345
+
346
+ export { nativeValueNamespaces as builtinNativeValueNamespaces, nativeValueNamespaces as default };
@@ -0,0 +1,12 @@
1
+ import MasterCSS from './core';
2
+ import { Rule } from './rule';
3
+ export default class NonLayer {
4
+ css: MasterCSS;
5
+ readonly rules: Rule[];
6
+ readonly tokenCounts: Map<string, number>;
7
+ constructor(css: MasterCSS);
8
+ insert(rule: Rule): void;
9
+ delete(name: string): Rule | undefined;
10
+ get text(): string;
11
+ reset(): void;
12
+ }
@@ -0,0 +1,53 @@
1
+ import findNativeCSSRuleIndex from './utils/find-native-css-rule-index.mjs';
2
+
3
+ class NonLayer {
4
+ css;
5
+ rules = [];
6
+ tokenCounts = new Map();
7
+ constructor(css){
8
+ this.css = css;
9
+ }
10
+ insert(rule) {
11
+ if (this.rules.includes(rule)) return;
12
+ const sheet = this.css.style?.sheet;
13
+ if (sheet) {
14
+ try {
15
+ const insertedIndex = sheet.insertRule(rule.text, sheet.cssRules.length);
16
+ rule.native = sheet.cssRules[insertedIndex];
17
+ } catch (error) {
18
+ console.error(error);
19
+ }
20
+ }
21
+ this.rules.push(rule);
22
+ this.css.rules.push(rule);
23
+ }
24
+ delete(name) {
25
+ const rule = this.rules.find((rule)=>rule.name === name);
26
+ if (!rule) return;
27
+ const sheet = this.css.style?.sheet;
28
+ if (sheet) {
29
+ const foundIndex = findNativeCSSRuleIndex(sheet.cssRules, rule.native);
30
+ if (foundIndex !== -1) {
31
+ sheet.deleteRule(foundIndex);
32
+ }
33
+ }
34
+ this.rules.splice(this.rules.indexOf(rule), 1);
35
+ this.css.rules.splice(this.css.rules.indexOf(rule), 1);
36
+ return rule;
37
+ }
38
+ get text() {
39
+ return this.rules.map(({ text })=>text).join('');
40
+ }
41
+ reset() {
42
+ for (const rule of this.rules){
43
+ const foundIndex = this.css.rules.indexOf(rule);
44
+ if (foundIndex !== -1) {
45
+ this.css.rules.splice(foundIndex, 1);
46
+ }
47
+ }
48
+ this.rules.length = 0;
49
+ this.tokenCounts.clear();
50
+ }
51
+ }
52
+
53
+ export { NonLayer as default };
package/dist/rule.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare class Rule {
2
+ readonly name: string;
3
+ readonly text: string;
4
+ native?: CSSRule;
5
+ constructor(name: string, text: string);
6
+ get key(): string;
7
+ }
package/dist/rule.mjs ADDED
@@ -0,0 +1,14 @@
1
+ class Rule {
2
+ name;
3
+ text;
4
+ native;
5
+ constructor(name, text){
6
+ this.name = name;
7
+ this.text = text;
8
+ }
9
+ get key() {
10
+ return this.name;
11
+ }
12
+ }
13
+
14
+ export { Rule };
@@ -0,0 +1,21 @@
1
+ import MasterCSS from './core';
2
+ import Layer from './layer';
3
+ import VariableRule, { VariableRuleNode } from './variable-rule';
4
+ export interface VariableRuleBucket {
5
+ mediaText: string;
6
+ selectorText: string;
7
+ order: number;
8
+ nodes: VariableRuleNode[];
9
+ }
10
+ export default class ThemeLayer extends Layer {
11
+ name: string;
12
+ css: MasterCSS;
13
+ readonly rules: VariableRule[];
14
+ constructor(name: string, css: MasterCSS);
15
+ protected getBucketRank(bucket: Pick<VariableRuleBucket, 'mediaText' | 'selectorText'>): 0 | 1 | 2;
16
+ protected compareBuckets(a: VariableRuleBucket, b: VariableRuleBucket): number;
17
+ protected shouldInsertBucketBefore(bucket: Pick<VariableRuleBucket, 'mediaText' | 'selectorText'>, existingBucket: Pick<VariableRuleBucket, 'mediaText' | 'selectorText'>): boolean;
18
+ getBuckets(): VariableRuleBucket[];
19
+ getBucketText(bucket: VariableRuleBucket): string;
20
+ get text(): string;
21
+ }
@@ -0,0 +1,52 @@
1
+ import Layer from './layer.mjs';
2
+
3
+ class ThemeLayer extends Layer {
4
+ name;
5
+ css;
6
+ rules = [];
7
+ constructor(name, css){
8
+ super(name, css), this.name = name, this.css = css;
9
+ }
10
+ getBucketRank(bucket) {
11
+ if (bucket.mediaText) return 2;
12
+ const selectors = bucket.selectorText.split(',').map((selector)=>selector.trim());
13
+ return selectors.includes(':root') || selectors.includes(':host') ? 0 : 1;
14
+ }
15
+ compareBuckets(a, b) {
16
+ return this.getBucketRank(a) - this.getBucketRank(b) || a.order - b.order;
17
+ }
18
+ shouldInsertBucketBefore(bucket, existingBucket) {
19
+ return this.getBucketRank(bucket) < this.getBucketRank(existingBucket);
20
+ }
21
+ getBuckets() {
22
+ const buckets = new Map();
23
+ for (const rule of this.rules){
24
+ for (const node of rule.nodes){
25
+ const key = node.mediaText + '\n' + node.selectorText;
26
+ let bucket = buckets.get(key);
27
+ if (!bucket) {
28
+ bucket = {
29
+ mediaText: node.mediaText,
30
+ selectorText: node.selectorText,
31
+ order: buckets.size,
32
+ nodes: []
33
+ };
34
+ buckets.set(key, bucket);
35
+ }
36
+ bucket.nodes.push(node);
37
+ }
38
+ }
39
+ return Array.from(buckets.values()).sort((a, b)=>this.compareBuckets(a, b));
40
+ }
41
+ getBucketText(bucket) {
42
+ const text = `${bucket.selectorText}{${bucket.nodes.map(({ declarationText })=>declarationText).join(';')}}`;
43
+ return bucket.mediaText ? `${bucket.mediaText}{${text}}` : text;
44
+ }
45
+ get text() {
46
+ const ruleText = this.getBuckets().map((bucket)=>this.getBucketText(bucket)).join('');
47
+ if (!ruleText) return '';
48
+ return '@layer ' + this.name + '{' + ruleText + '}';
49
+ }
50
+ }
51
+
52
+ export { ThemeLayer as default };
@@ -0,0 +1,10 @@
1
+ import Layer from './layer';
2
+ import { Rule } from './rule';
3
+ import { Utility } from './utility';
4
+ export default class UtilityLayer extends Layer {
5
+ rules: (Utility | Rule)[];
6
+ insert(utility: Utility | Rule): number | undefined;
7
+ delete(key: string): Rule | Utility | undefined;
8
+ insertVariables(utility: Utility | Rule): void;
9
+ insertAnimations(utility: Utility | Rule): void;
10
+ }
@@ -0,0 +1,118 @@
1
+ import AnimationRule from './animation-rule.mjs';
2
+ import Layer from './layer.mjs';
3
+ import { Utility } from './utility.mjs';
4
+ import compareRulePriority from './utils/compare-rule-priority.mjs';
5
+ import VariableRule from './variable-rule.mjs';
6
+
7
+ function findUtilityInsertIndex(rules, utility) {
8
+ let low = 0;
9
+ let high = rules.length;
10
+ while(low < high){
11
+ const mid = low + high >> 1;
12
+ const rule = rules[mid];
13
+ if (!(rule instanceof Utility)) {
14
+ return findUtilityInsertIndexLinear(rules, utility);
15
+ }
16
+ if (compareRulePriority(utility, rule) < 0) {
17
+ high = mid;
18
+ } else {
19
+ low = mid + 1;
20
+ }
21
+ }
22
+ return low;
23
+ }
24
+ function findUtilityInsertIndexLinear(rules, utility) {
25
+ for(let i = 0; i < rules.length; i++){
26
+ const rule = rules[i];
27
+ if (!(rule instanceof Utility)) continue;
28
+ if (compareRulePriority(utility, rule) < 0) {
29
+ return i;
30
+ }
31
+ }
32
+ return rules.length;
33
+ }
34
+ class UtilityLayer extends Layer {
35
+ rules = [];
36
+ insert(utility) {
37
+ if (this.get(utility.key)) return;
38
+ if ('valid' in utility && !utility.valid) return;
39
+ let index = this.rules.length;
40
+ if (utility instanceof Utility) {
41
+ index = findUtilityInsertIndex(this.rules, utility);
42
+ }
43
+ const insertedIndex = super.insert(utility, index);
44
+ if (insertedIndex === undefined) return;
45
+ this.insertVariables(utility);
46
+ this.insertAnimations(utility);
47
+ return insertedIndex;
48
+ }
49
+ delete(key) {
50
+ const utility = super.delete(key);
51
+ if (!utility) return;
52
+ const deleteLayerToken = (layerToken, layer, visited = new Set())=>{
53
+ if (visited.has(layerToken)) return;
54
+ visited.add(layerToken);
55
+ const count = layer.tokenCounts.get(layerToken) ?? 0;
56
+ const variable = layer === this.css.themeLayer ? this.css.variables.get(layerToken) : undefined;
57
+ if (count <= 1) {
58
+ const deletedRule = layer.delete(layerToken);
59
+ layer.tokenCounts.delete(layerToken);
60
+ variable?.dependencies?.forEach((dependency)=>deleteLayerToken(dependency, layer, visited));
61
+ return deletedRule;
62
+ } else {
63
+ layer.tokenCounts.set(layerToken, count - 1);
64
+ variable?.dependencies?.forEach((dependency)=>deleteLayerToken(dependency, layer, visited));
65
+ }
66
+ };
67
+ if ('variableNames' in utility) utility.variableNames?.forEach((eachVariableName)=>{
68
+ deleteLayerToken(eachVariableName, this.css.themeLayer);
69
+ });
70
+ if ('animationNames' in utility) utility.animationNames?.forEach((eachAnimationName)=>{
71
+ const deletedAnimationRule = deleteLayerToken(eachAnimationName, this.css.animationsNonLayer);
72
+ const variableNames = deletedAnimationRule && 'variableNames' in deletedAnimationRule ? deletedAnimationRule.variableNames : undefined;
73
+ if (variableNames) {
74
+ variableNames.forEach((eachVariableName)=>{
75
+ deleteLayerToken(eachVariableName, this.css.themeLayer);
76
+ });
77
+ }
78
+ });
79
+ return utility;
80
+ }
81
+ insertVariables(utility) {
82
+ if (!('variableNames' in utility)) return;
83
+ const insertVariable = (eachVariableName, visited = new Set())=>{
84
+ if (visited.has(eachVariableName)) return;
85
+ visited.add(eachVariableName);
86
+ const variable = this.css.variables.get(eachVariableName);
87
+ if (!variable || variable.inline) return;
88
+ if (this.css.themeLayer.rules.find(({ name })=>name === eachVariableName) || this.css.isEmittedGlobalsVariable(eachVariableName)) {
89
+ const count = this.css.themeLayer.tokenCounts.get(eachVariableName) || 0;
90
+ this.css.themeLayer.tokenCounts.set(eachVariableName, count + 1);
91
+ } else {
92
+ const newRule = new VariableRule(eachVariableName, variable, this.css);
93
+ this.css.themeLayer.insert(newRule);
94
+ this.css.themeLayer.tokenCounts.set(eachVariableName, 1);
95
+ }
96
+ variable.dependencies?.forEach((dependency)=>insertVariable(dependency, visited));
97
+ };
98
+ utility.variableNames?.forEach((eachVariableName)=>insertVariable(eachVariableName));
99
+ }
100
+ insertAnimations(utility) {
101
+ if (!('animationNames' in utility)) return;
102
+ utility.animationNames?.forEach((eachAnimationName)=>{
103
+ if (this.css.animationsNonLayer.rules.find(({ name })=>name === eachAnimationName) || this.css.isEmittedGlobalsAnimation(eachAnimationName)) {
104
+ const count = this.css.animationsNonLayer.tokenCounts.get(eachAnimationName) || 0;
105
+ this.css.animationsNonLayer.tokenCounts.set(eachAnimationName, count + 1);
106
+ } else {
107
+ const keyframes = this.css.animations.get(eachAnimationName);
108
+ if (!keyframes) return;
109
+ const newRule = new AnimationRule(eachAnimationName, keyframes, this.css);
110
+ this.css.animationsNonLayer.insert(newRule);
111
+ this.css.animationsNonLayer.tokenCounts.set(eachAnimationName, 1);
112
+ this.insertVariables(newRule);
113
+ }
114
+ });
115
+ }
116
+ }
117
+
118
+ export { UtilityLayer as default };