@master/css 2.0.0-rc.47 → 2.0.0-rc.48

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 (72) hide show
  1. package/dist/common.cjs +1 -1
  2. package/dist/common.mjs +1 -1
  3. package/dist/config/functions.d.ts +1 -1
  4. package/dist/config/index.cjs +3 -3
  5. package/dist/config/index.d.ts +3 -48
  6. package/dist/config/index.mjs +3 -3
  7. package/dist/config/modes.d.ts +1 -1
  8. package/dist/config/{syntaxes.cjs → rules.cjs} +282 -282
  9. package/dist/config/rules.d.ts +282 -0
  10. package/dist/config/{syntaxes.mjs → rules.mjs} +282 -282
  11. package/dist/core.cjs +225 -607
  12. package/dist/core.d.ts +36 -67
  13. package/dist/core.mjs +225 -607
  14. package/dist/index.cjs +14 -6
  15. package/dist/index.d.ts +8 -4
  16. package/dist/index.mjs +7 -3
  17. package/dist/layer.cjs +107 -23
  18. package/dist/layer.d.ts +13 -27
  19. package/dist/layer.mjs +107 -23
  20. package/dist/non-layer.cjs +65 -0
  21. package/dist/non-layer.d.ts +12 -0
  22. package/dist/non-layer.mjs +63 -0
  23. package/dist/rule.cjs +8 -708
  24. package/dist/rule.d.ts +6 -147
  25. package/dist/rule.mjs +8 -708
  26. package/dist/shared/utils/find-native-css-rule-index.cjs +12 -0
  27. package/dist/shared/utils/find-native-css-rule-index.mjs +10 -0
  28. package/dist/syntax-layer.cjs +291 -0
  29. package/dist/syntax-layer.d.ts +17 -0
  30. package/dist/syntax-layer.mjs +289 -0
  31. package/dist/syntax-rule-type.cjs +27 -0
  32. package/dist/syntax-rule-type.d.ts +28 -0
  33. package/dist/syntax-rule-type.mjs +25 -0
  34. package/dist/syntax-rule.cjs +717 -0
  35. package/dist/syntax-rule.d.ts +47 -0
  36. package/dist/syntax-rule.mjs +715 -0
  37. package/dist/types/config.cjs +2 -0
  38. package/dist/types/config.d.ts +70 -0
  39. package/dist/types/config.mjs +1 -0
  40. package/dist/types/syntax.cjs +2 -0
  41. package/dist/types/syntax.d.ts +106 -0
  42. package/dist/types/syntax.mjs +1 -0
  43. package/dist/utils/are-rule-at-equal.cjs +7 -7
  44. package/dist/utils/are-rule-at-equal.d.ts +2 -2
  45. package/dist/utils/are-rule-at-equal.mjs +7 -7
  46. package/dist/utils/are-rule-modes-equal.cjs +2 -2
  47. package/dist/utils/are-rule-modes-equal.d.ts +2 -2
  48. package/dist/utils/are-rule-modes-equal.mjs +2 -2
  49. package/dist/utils/are-rule-selectors-equal.cjs +11 -11
  50. package/dist/utils/are-rule-selectors-equal.d.ts +2 -2
  51. package/dist/utils/are-rule-selectors-equal.mjs +11 -11
  52. package/dist/utils/are-rule-states-equal.cjs +2 -2
  53. package/dist/utils/are-rule-states-equal.d.ts +2 -2
  54. package/dist/utils/are-rule-states-equal.mjs +2 -2
  55. package/dist/utils/are-rules-duplicated.cjs +17 -0
  56. package/dist/utils/are-rules-duplicated.d.ts +2 -0
  57. package/dist/utils/are-rules-duplicated.mjs +15 -0
  58. package/dist/utils/autofill-solid-style.d.ts +2 -2
  59. package/dist/utils/extend-config.cjs +5 -5
  60. package/dist/utils/extend-config.d.ts +1 -1
  61. package/dist/utils/extend-config.mjs +5 -5
  62. package/dist/utils/generate-css.cjs +1 -1
  63. package/dist/utils/generate-css.mjs +1 -1
  64. package/dist/utils/is-core-rule.cjs +2 -2
  65. package/dist/utils/is-core-rule.mjs +2 -2
  66. package/dist/utils/reorder-for-readable-classes.cjs +11 -11
  67. package/dist/utils/reorder-for-readable-classes.mjs +11 -11
  68. package/package.json +1 -1
  69. package/dist/config/syntaxes.d.ts +0 -282
  70. package/dist/utils/are-syntaxes-duplicated.cjs +0 -17
  71. package/dist/utils/are-syntaxes-duplicated.d.ts +0 -2
  72. package/dist/utils/are-syntaxes-duplicated.mjs +0 -15
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ function findNativeCSSRuleIndex(cssRules, nativeRule) {
4
+ for(let i = 0; i < cssRules.length; i++){
5
+ if (cssRules[i] === nativeRule) {
6
+ return i;
7
+ }
8
+ }
9
+ return -1;
10
+ }
11
+
12
+ module.exports = findNativeCSSRuleIndex;
@@ -0,0 +1,10 @@
1
+ function findNativeCSSRuleIndex(cssRules, nativeRule) {
2
+ for(let i = 0; i < cssRules.length; i++){
3
+ if (cssRules[i] === nativeRule) {
4
+ return i;
5
+ }
6
+ }
7
+ return -1;
8
+ }
9
+
10
+ export { findNativeCSSRuleIndex as default };
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ var layer = require('./layer.cjs');
4
+ var rule = require('./rule.cjs');
5
+
6
+ class SyntaxLayer extends layer {
7
+ rules = [];
8
+ /**
9
+ * normal
10
+ * normal selectors
11
+ * media normal
12
+ * media selectors
13
+ * media width
14
+ * media width selectors
15
+ */ insert(syntaxRule) {
16
+ if (this.rules.includes(syntaxRule)) return;
17
+ let index;
18
+ /**
19
+ * 必須按斷點值遞增,並透過索引插入,
20
+ * 以實現響應式先後套用的規則
21
+ * @example <1 <2 <3 ALL >=1 >=2 >=3
22
+ * @description
23
+ */ const endIndex = this.rules.length - 1;
24
+ const { at, atToken, order, priority } = syntaxRule;
25
+ const findIndex = (startIndex, stopCheck, matchCheck)=>{
26
+ let i = startIndex;
27
+ for(; i <= endIndex; i++){
28
+ const eachSyntaxRule = this.rules[i];
29
+ if (stopCheck?.(eachSyntaxRule)) return matchCheck ? -1 : i - 1;
30
+ if (matchCheck?.(eachSyntaxRule)) return i;
31
+ }
32
+ return matchCheck ? -1 : i - 1;
33
+ };
34
+ let matchStartIndex;
35
+ let matchEndIndex;
36
+ if (atToken) {
37
+ const mediaStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media);
38
+ if (mediaStartIndex === -1) {
39
+ index = endIndex + 1;
40
+ } else {
41
+ const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
42
+ const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
43
+ if (maxWidthFeature || minWidthFeature) {
44
+ const mediaWidthStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
45
+ if (mediaWidthStartIndex === -1) {
46
+ index = endIndex + 1;
47
+ } else {
48
+ if (maxWidthFeature && minWidthFeature) {
49
+ /**
50
+ * 範圍越小 ( 越限定 越侷限 ) 越優先,
51
+ * 按照範圍 max-width - min-width 遞減排序
52
+ * find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
53
+ * 並插入在該 rule 之後,讓自己優先被套用
54
+ */ if (priority === -1) {
55
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
56
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
57
+ } else {
58
+ matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
59
+ matchEndIndex = endIndex;
60
+ }
61
+ if (matchStartIndex !== -1) {
62
+ const range = maxWidthFeature.value - minWidthFeature.value;
63
+ let i = matchEndIndex;
64
+ const endI = matchStartIndex;
65
+ matchStartIndex = matchEndIndex + 1;
66
+ for(; i >= endI; i--){
67
+ const eachSyntaxRule = this.rules[i];
68
+ const eachMaxWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width');
69
+ const eachMinWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width');
70
+ if (!eachMaxWidthFeature || !eachMinWidthFeature) {
71
+ break;
72
+ } else {
73
+ const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
74
+ if (eachRange < range) {
75
+ matchEndIndex = i - 1;
76
+ } else if (eachRange === range) {
77
+ matchStartIndex = i;
78
+ } else {
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ } else if (minWidthFeature) {
85
+ /**
86
+ * find 第一個所遇到同樣 feature 且值比自己大的 rule,
87
+ * 並插入在該 rule 之後,讓自己優先被套用
88
+ */ if (priority === -1) {
89
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
90
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
91
+ } else {
92
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
93
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
94
+ }
95
+ if (matchStartIndex !== -1) {
96
+ for(let i = matchEndIndex; i >= matchStartIndex; i--){
97
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
98
+ if (value > minWidthFeature.value) {
99
+ matchEndIndex = i - 1;
100
+ } else if (value < minWidthFeature.value) {
101
+ matchStartIndex = i + 1;
102
+ break;
103
+ }
104
+ }
105
+ }
106
+ } else {
107
+ /**
108
+ * find 第一個所遇到同樣 feature 且值比自己大的 rule,
109
+ * 並插入在該 rule 之後,讓自己優先被套用
110
+ */ if (priority === -1) {
111
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width'));
112
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
113
+ } else {
114
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.priority !== -1);
115
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
116
+ }
117
+ if (matchStartIndex !== -1) {
118
+ for(let i = matchEndIndex; i >= matchStartIndex; i--){
119
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
120
+ if (value < maxWidthFeature.value) {
121
+ matchEndIndex = i - 1;
122
+ } else if (value > maxWidthFeature.value) {
123
+ matchStartIndex = i + 1;
124
+ break;
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ } else {
131
+ if (priority === -1) {
132
+ matchStartIndex = mediaStartIndex;
133
+ matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntaxRule.priority !== -1);
134
+ } else {
135
+ matchStartIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
136
+ matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
137
+ }
138
+ }
139
+ }
140
+ } else {
141
+ if (priority === -1) {
142
+ matchStartIndex = 0;
143
+ matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
144
+ } else {
145
+ matchStartIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
146
+ matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken);
147
+ }
148
+ }
149
+ if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
150
+ if (matchStartIndex === -1) {
151
+ index = matchEndIndex + 1;
152
+ } else {
153
+ if (priority === -1) {
154
+ for(let i = matchStartIndex; i <= matchEndIndex; i++){
155
+ const currentSyntaxRule = this.rules[i];
156
+ if (currentSyntaxRule.order >= order) {
157
+ index = i;
158
+ break;
159
+ }
160
+ }
161
+ } else {
162
+ for(let i = matchStartIndex; i <= matchEndIndex; i++){
163
+ const currentSyntaxRule = this.rules[i];
164
+ if (currentSyntaxRule.priority < priority) {
165
+ index = i;
166
+ break;
167
+ } else if (currentSyntaxRule.priority === priority) {
168
+ if (currentSyntaxRule.order >= order) {
169
+ index = i;
170
+ break;
171
+ }
172
+ } else {
173
+ index = i + 1;
174
+ }
175
+ }
176
+ }
177
+ if (index === undefined) {
178
+ index = matchEndIndex + 1;
179
+ }
180
+ }
181
+ }
182
+ super.insert(syntaxRule, index);
183
+ this.insertVariables(syntaxRule);
184
+ this.insertAnimations(syntaxRule);
185
+ syntaxRule.definition.insert?.call(syntaxRule);
186
+ return index;
187
+ }
188
+ delete(key) {
189
+ const syntaxRule = super.delete(key);
190
+ if (!syntaxRule) return;
191
+ if (syntaxRule.variableNames) {
192
+ for (const eachVariableName of syntaxRule.variableNames){
193
+ if (!--this.css.themeLayer.usages[eachVariableName]) {
194
+ this.css.themeLayer.delete(eachVariableName);
195
+ delete this.css.themeLayer.usages[eachVariableName];
196
+ }
197
+ }
198
+ }
199
+ if (syntaxRule.animationNames) {
200
+ for (const eachKeyframeName of syntaxRule.animationNames){
201
+ if (!--this.css.animationsNonLayer.usages[eachKeyframeName]) {
202
+ this.css.animationsNonLayer.delete(eachKeyframeName);
203
+ delete this.css.animationsNonLayer.usages[eachKeyframeName];
204
+ }
205
+ }
206
+ }
207
+ syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
208
+ return syntaxRule;
209
+ }
210
+ insertVariables(syntaxRule) {
211
+ if (syntaxRule.variableNames) {
212
+ for (const eachVariableName of syntaxRule.variableNames){
213
+ const variable = this.css.variables[eachVariableName];
214
+ if (this.css.themeLayer.rules.find(({ name })=>name === eachVariableName)) {
215
+ this.css.themeLayer.usages[eachVariableName]++;
216
+ } else {
217
+ const newRule = new rule.Rule(eachVariableName);
218
+ const addNative = (mode, _variable)=>{
219
+ let isDefaultMode = false;
220
+ let preifxCssRuleText;
221
+ let endCurlyBracketCount = 1;
222
+ if (mode) {
223
+ switch(this.css.config.modes?.[mode]){
224
+ case 'media':
225
+ preifxCssRuleText = `@media(prefers-color-scheme:${mode}){:root`;
226
+ endCurlyBracketCount++;
227
+ break;
228
+ case 'host':
229
+ preifxCssRuleText = `:host(.${mode})`;
230
+ if (!variable.value && this.css.config.defaultMode === mode) {
231
+ preifxCssRuleText += ',:host';
232
+ isDefaultMode = true;
233
+ }
234
+ break;
235
+ case 'class':
236
+ preifxCssRuleText = `.${mode}`;
237
+ if (!variable.value && this.css.config.defaultMode === mode) {
238
+ preifxCssRuleText += ',:root';
239
+ isDefaultMode = true;
240
+ }
241
+ break;
242
+ default:
243
+ return;
244
+ }
245
+ } else {
246
+ preifxCssRuleText = ':root';
247
+ }
248
+ const cssRuleText = `${preifxCssRuleText}{--${eachVariableName}:${String(_variable.value)}${'}'.repeat(endCurlyBracketCount)}`;
249
+ if (isDefaultMode) {
250
+ newRule.nodes.unshift({
251
+ text: cssRuleText
252
+ });
253
+ } else {
254
+ newRule.nodes.push({
255
+ text: cssRuleText
256
+ });
257
+ }
258
+ };
259
+ if (variable.value) {
260
+ addNative('', variable);
261
+ }
262
+ if (variable.modes) {
263
+ for(const mode in variable.modes){
264
+ addNative(mode, variable.modes[mode]);
265
+ }
266
+ }
267
+ this.css.themeLayer.insert(newRule);
268
+ this.css.themeLayer.usages[eachVariableName] = 1;
269
+ }
270
+ }
271
+ }
272
+ }
273
+ insertAnimations(syntaxRule) {
274
+ if (syntaxRule.animationNames) {
275
+ for (const eachAnimationName of syntaxRule.animationNames){
276
+ if (this.css.animationsNonLayer.rules.find(({ name })=>name === eachAnimationName)) {
277
+ this.css.animationsNonLayer.usages[eachAnimationName]++;
278
+ } else {
279
+ this.css.animationsNonLayer.insert(new rule.Rule(eachAnimationName, [
280
+ {
281
+ text: `@keyframes ${eachAnimationName}{` + Object.entries(this.css.animations[eachAnimationName]).map(([key, variables])=>`${key}{${Object.entries(variables).map(([name, value])=>name + ':' + value).join(';')}}`).join('') + '}'
282
+ }
283
+ ]));
284
+ this.css.animationsNonLayer.usages[eachAnimationName] = 1;
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ module.exports = SyntaxLayer;
@@ -0,0 +1,17 @@
1
+ import Layer from './layer';
2
+ import { SyntaxRule } from './syntax-rule';
3
+ export default class SyntaxLayer extends Layer {
4
+ rules: SyntaxRule[];
5
+ /**
6
+ * normal
7
+ * normal selectors
8
+ * media normal
9
+ * media selectors
10
+ * media width
11
+ * media width selectors
12
+ */
13
+ insert(syntaxRule: SyntaxRule): number | undefined;
14
+ delete(key: string): SyntaxRule | undefined;
15
+ insertVariables(syntaxRule: SyntaxRule): void;
16
+ insertAnimations(syntaxRule: SyntaxRule): void;
17
+ }
@@ -0,0 +1,289 @@
1
+ import Layer from './layer.mjs';
2
+ import { Rule } from './rule.mjs';
3
+
4
+ class SyntaxLayer extends Layer {
5
+ rules = [];
6
+ /**
7
+ * normal
8
+ * normal selectors
9
+ * media normal
10
+ * media selectors
11
+ * media width
12
+ * media width selectors
13
+ */ insert(syntaxRule) {
14
+ if (this.rules.includes(syntaxRule)) return;
15
+ let index;
16
+ /**
17
+ * 必須按斷點值遞增,並透過索引插入,
18
+ * 以實現響應式先後套用的規則
19
+ * @example <1 <2 <3 ALL >=1 >=2 >=3
20
+ * @description
21
+ */ const endIndex = this.rules.length - 1;
22
+ const { at, atToken, order, priority } = syntaxRule;
23
+ const findIndex = (startIndex, stopCheck, matchCheck)=>{
24
+ let i = startIndex;
25
+ for(; i <= endIndex; i++){
26
+ const eachSyntaxRule = this.rules[i];
27
+ if (stopCheck?.(eachSyntaxRule)) return matchCheck ? -1 : i - 1;
28
+ if (matchCheck?.(eachSyntaxRule)) return i;
29
+ }
30
+ return matchCheck ? -1 : i - 1;
31
+ };
32
+ let matchStartIndex;
33
+ let matchEndIndex;
34
+ if (atToken) {
35
+ const mediaStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media);
36
+ if (mediaStartIndex === -1) {
37
+ index = endIndex + 1;
38
+ } else {
39
+ const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
40
+ const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
41
+ if (maxWidthFeature || minWidthFeature) {
42
+ const mediaWidthStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
43
+ if (mediaWidthStartIndex === -1) {
44
+ index = endIndex + 1;
45
+ } else {
46
+ if (maxWidthFeature && minWidthFeature) {
47
+ /**
48
+ * 範圍越小 ( 越限定 越侷限 ) 越優先,
49
+ * 按照範圍 max-width - min-width 遞減排序
50
+ * find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
51
+ * 並插入在該 rule 之後,讓自己優先被套用
52
+ */ if (priority === -1) {
53
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
54
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
55
+ } else {
56
+ matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
57
+ matchEndIndex = endIndex;
58
+ }
59
+ if (matchStartIndex !== -1) {
60
+ const range = maxWidthFeature.value - minWidthFeature.value;
61
+ let i = matchEndIndex;
62
+ const endI = matchStartIndex;
63
+ matchStartIndex = matchEndIndex + 1;
64
+ for(; i >= endI; i--){
65
+ const eachSyntaxRule = this.rules[i];
66
+ const eachMaxWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width');
67
+ const eachMinWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width');
68
+ if (!eachMaxWidthFeature || !eachMinWidthFeature) {
69
+ break;
70
+ } else {
71
+ const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
72
+ if (eachRange < range) {
73
+ matchEndIndex = i - 1;
74
+ } else if (eachRange === range) {
75
+ matchStartIndex = i;
76
+ } else {
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ } else if (minWidthFeature) {
83
+ /**
84
+ * find 第一個所遇到同樣 feature 且值比自己大的 rule,
85
+ * 並插入在該 rule 之後,讓自己優先被套用
86
+ */ if (priority === -1) {
87
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
88
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
89
+ } else {
90
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
91
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
92
+ }
93
+ if (matchStartIndex !== -1) {
94
+ for(let i = matchEndIndex; i >= matchStartIndex; i--){
95
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
96
+ if (value > minWidthFeature.value) {
97
+ matchEndIndex = i - 1;
98
+ } else if (value < minWidthFeature.value) {
99
+ matchStartIndex = i + 1;
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ } else {
105
+ /**
106
+ * find 第一個所遇到同樣 feature 且值比自己大的 rule,
107
+ * 並插入在該 rule 之後,讓自己優先被套用
108
+ */ if (priority === -1) {
109
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width'));
110
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
111
+ } else {
112
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.priority !== -1);
113
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
114
+ }
115
+ if (matchStartIndex !== -1) {
116
+ for(let i = matchEndIndex; i >= matchStartIndex; i--){
117
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
118
+ if (value < maxWidthFeature.value) {
119
+ matchEndIndex = i - 1;
120
+ } else if (value > maxWidthFeature.value) {
121
+ matchStartIndex = i + 1;
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ } else {
129
+ if (priority === -1) {
130
+ matchStartIndex = mediaStartIndex;
131
+ matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntaxRule.priority !== -1);
132
+ } else {
133
+ matchStartIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
134
+ matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
135
+ }
136
+ }
137
+ }
138
+ } else {
139
+ if (priority === -1) {
140
+ matchStartIndex = 0;
141
+ matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
142
+ } else {
143
+ matchStartIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
144
+ matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken);
145
+ }
146
+ }
147
+ if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
148
+ if (matchStartIndex === -1) {
149
+ index = matchEndIndex + 1;
150
+ } else {
151
+ if (priority === -1) {
152
+ for(let i = matchStartIndex; i <= matchEndIndex; i++){
153
+ const currentSyntaxRule = this.rules[i];
154
+ if (currentSyntaxRule.order >= order) {
155
+ index = i;
156
+ break;
157
+ }
158
+ }
159
+ } else {
160
+ for(let i = matchStartIndex; i <= matchEndIndex; i++){
161
+ const currentSyntaxRule = this.rules[i];
162
+ if (currentSyntaxRule.priority < priority) {
163
+ index = i;
164
+ break;
165
+ } else if (currentSyntaxRule.priority === priority) {
166
+ if (currentSyntaxRule.order >= order) {
167
+ index = i;
168
+ break;
169
+ }
170
+ } else {
171
+ index = i + 1;
172
+ }
173
+ }
174
+ }
175
+ if (index === undefined) {
176
+ index = matchEndIndex + 1;
177
+ }
178
+ }
179
+ }
180
+ super.insert(syntaxRule, index);
181
+ this.insertVariables(syntaxRule);
182
+ this.insertAnimations(syntaxRule);
183
+ syntaxRule.definition.insert?.call(syntaxRule);
184
+ return index;
185
+ }
186
+ delete(key) {
187
+ const syntaxRule = super.delete(key);
188
+ if (!syntaxRule) return;
189
+ if (syntaxRule.variableNames) {
190
+ for (const eachVariableName of syntaxRule.variableNames){
191
+ if (!--this.css.themeLayer.usages[eachVariableName]) {
192
+ this.css.themeLayer.delete(eachVariableName);
193
+ delete this.css.themeLayer.usages[eachVariableName];
194
+ }
195
+ }
196
+ }
197
+ if (syntaxRule.animationNames) {
198
+ for (const eachKeyframeName of syntaxRule.animationNames){
199
+ if (!--this.css.animationsNonLayer.usages[eachKeyframeName]) {
200
+ this.css.animationsNonLayer.delete(eachKeyframeName);
201
+ delete this.css.animationsNonLayer.usages[eachKeyframeName];
202
+ }
203
+ }
204
+ }
205
+ syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
206
+ return syntaxRule;
207
+ }
208
+ insertVariables(syntaxRule) {
209
+ if (syntaxRule.variableNames) {
210
+ for (const eachVariableName of syntaxRule.variableNames){
211
+ const variable = this.css.variables[eachVariableName];
212
+ if (this.css.themeLayer.rules.find(({ name })=>name === eachVariableName)) {
213
+ this.css.themeLayer.usages[eachVariableName]++;
214
+ } else {
215
+ const newRule = new Rule(eachVariableName);
216
+ const addNative = (mode, _variable)=>{
217
+ let isDefaultMode = false;
218
+ let preifxCssRuleText;
219
+ let endCurlyBracketCount = 1;
220
+ if (mode) {
221
+ switch(this.css.config.modes?.[mode]){
222
+ case 'media':
223
+ preifxCssRuleText = `@media(prefers-color-scheme:${mode}){:root`;
224
+ endCurlyBracketCount++;
225
+ break;
226
+ case 'host':
227
+ preifxCssRuleText = `:host(.${mode})`;
228
+ if (!variable.value && this.css.config.defaultMode === mode) {
229
+ preifxCssRuleText += ',:host';
230
+ isDefaultMode = true;
231
+ }
232
+ break;
233
+ case 'class':
234
+ preifxCssRuleText = `.${mode}`;
235
+ if (!variable.value && this.css.config.defaultMode === mode) {
236
+ preifxCssRuleText += ',:root';
237
+ isDefaultMode = true;
238
+ }
239
+ break;
240
+ default:
241
+ return;
242
+ }
243
+ } else {
244
+ preifxCssRuleText = ':root';
245
+ }
246
+ const cssRuleText = `${preifxCssRuleText}{--${eachVariableName}:${String(_variable.value)}${'}'.repeat(endCurlyBracketCount)}`;
247
+ if (isDefaultMode) {
248
+ newRule.nodes.unshift({
249
+ text: cssRuleText
250
+ });
251
+ } else {
252
+ newRule.nodes.push({
253
+ text: cssRuleText
254
+ });
255
+ }
256
+ };
257
+ if (variable.value) {
258
+ addNative('', variable);
259
+ }
260
+ if (variable.modes) {
261
+ for(const mode in variable.modes){
262
+ addNative(mode, variable.modes[mode]);
263
+ }
264
+ }
265
+ this.css.themeLayer.insert(newRule);
266
+ this.css.themeLayer.usages[eachVariableName] = 1;
267
+ }
268
+ }
269
+ }
270
+ }
271
+ insertAnimations(syntaxRule) {
272
+ if (syntaxRule.animationNames) {
273
+ for (const eachAnimationName of syntaxRule.animationNames){
274
+ if (this.css.animationsNonLayer.rules.find(({ name })=>name === eachAnimationName)) {
275
+ this.css.animationsNonLayer.usages[eachAnimationName]++;
276
+ } else {
277
+ this.css.animationsNonLayer.insert(new Rule(eachAnimationName, [
278
+ {
279
+ text: `@keyframes ${eachAnimationName}{` + Object.entries(this.css.animations[eachAnimationName]).map(([key, variables])=>`${key}{${Object.entries(variables).map(([name, value])=>name + ':' + value).join(';')}}`).join('') + '}'
280
+ }
281
+ ]));
282
+ this.css.animationsNonLayer.usages[eachAnimationName] = 1;
283
+ }
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ export { SyntaxLayer as default };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var SyntaxRuleType = /*#__PURE__*/ function(SyntaxRuleType) {
4
+ /**
5
+ * utility classes
6
+ * @example block, inline
7
+ */ SyntaxRuleType[SyntaxRuleType["Utility"] = -4] = "Utility";
8
+ /**
9
+ * native shorthand
10
+ * @example border, padding, margin
11
+ */ SyntaxRuleType[SyntaxRuleType["NativeShorthand"] = -3] = "NativeShorthand";
12
+ /**
13
+ * shorthand
14
+ * @example px, py, mx, my
15
+ */ SyntaxRuleType[SyntaxRuleType["Shorthand"] = -2] = "Shorthand";
16
+ /**
17
+ * native properties
18
+ * @example color, background-color, font-size
19
+ */ SyntaxRuleType[SyntaxRuleType["Native"] = -1] = "Native";
20
+ /**
21
+ * normal
22
+ * @example grid-cols
23
+ */ SyntaxRuleType[SyntaxRuleType["Normal"] = 0] = "Normal";
24
+ return SyntaxRuleType;
25
+ }(SyntaxRuleType || {});
26
+
27
+ module.exports = SyntaxRuleType;