@master/css 2.0.0-rc.6 → 2.0.0-rc.61

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 (144) hide show
  1. package/README.md +4 -43
  2. package/dist/_virtual/_commonjsHelpers.cjs +10 -0
  3. package/dist/_virtual/_commonjsHelpers.mjs +7 -0
  4. package/dist/_virtual/css-escape.cjs +5 -0
  5. package/dist/_virtual/css-escape.mjs +3 -0
  6. package/dist/bin/index.cjs +11 -0
  7. package/dist/bin/index.d.ts +0 -1
  8. package/dist/bin/index.mjs +9 -0
  9. package/dist/common.cjs +159 -0
  10. package/dist/common.d.ts +26 -0
  11. package/dist/common.mjs +137 -0
  12. package/dist/config/animations.cjs +113 -0
  13. package/dist/config/animations.mjs +111 -0
  14. package/dist/config/at.cjs +16 -0
  15. package/dist/config/at.d.ts +13 -0
  16. package/dist/config/at.mjs +14 -0
  17. package/dist/config/functions.cjs +375 -0
  18. package/dist/config/functions.d.ts +1 -1
  19. package/dist/config/functions.mjs +373 -0
  20. package/dist/config/index.cjs +37 -0
  21. package/dist/config/index.d.ts +5 -62
  22. package/dist/config/index.mjs +27 -0
  23. package/dist/config/modes.cjs +8 -0
  24. package/dist/config/modes.d.ts +3 -0
  25. package/dist/config/modes.mjs +6 -0
  26. package/dist/config/rules.cjs +2300 -0
  27. package/dist/config/rules.d.ts +278 -274
  28. package/dist/config/rules.mjs +2298 -0
  29. package/dist/config/selectors.cjs +28 -0
  30. package/dist/config/selectors.d.ts +0 -1
  31. package/dist/config/selectors.mjs +26 -0
  32. package/dist/config/styles.cjs +2 -0
  33. package/dist/config/styles.d.ts +2 -2
  34. package/dist/config/styles.mjs +1 -0
  35. package/dist/config/utilities.cjs +204 -0
  36. package/dist/config/{semantics.d.ts → utilities.d.ts} +15 -5
  37. package/dist/config/utilities.mjs +202 -0
  38. package/dist/config/variables.cjs +484 -0
  39. package/dist/config/variables.d.ts +208 -312
  40. package/dist/config/variables.mjs +482 -0
  41. package/dist/core.cjs +739 -0
  42. package/dist/core.d.ts +96 -75
  43. package/dist/core.mjs +737 -0
  44. package/dist/factories/with-syntax-layer.cjs +308 -0
  45. package/dist/factories/with-syntax-layer.d.ts +26 -0
  46. package/dist/factories/with-syntax-layer.mjs +306 -0
  47. package/dist/index.cjs +82 -0
  48. package/dist/index.d.ts +21 -9
  49. package/dist/index.mjs +27 -0
  50. package/dist/layer.cjs +50 -0
  51. package/dist/layer.d.ts +14 -10
  52. package/dist/layer.mjs +48 -0
  53. package/dist/non-layer.cjs +64 -0
  54. package/dist/non-layer.d.ts +12 -0
  55. package/dist/non-layer.mjs +62 -0
  56. package/dist/polyfills/css-escape.cjs +9 -0
  57. package/dist/polyfills/css-escape.mjs +7 -0
  58. package/dist/polyfills/css-escape2.cjs +76 -0
  59. package/dist/polyfills/css-escape2.mjs +74 -0
  60. package/dist/register-global.cjs +7 -0
  61. package/dist/register-global.d.ts +5 -0
  62. package/dist/register-global.mjs +5 -0
  63. package/dist/rule-node.cjs +18 -0
  64. package/dist/rule-node.d.ts +14 -0
  65. package/dist/rule-node.mjs +16 -0
  66. package/dist/rule.cjs +18 -0
  67. package/dist/rule.d.ts +9 -111
  68. package/dist/rule.mjs +16 -0
  69. package/dist/shared/utils/css-escape.cjs +56 -0
  70. package/dist/shared/utils/css-escape.mjs +54 -0
  71. package/dist/shared/utils/find-native-css-rule-index.cjs +12 -0
  72. package/dist/shared/utils/find-native-css-rule-index.mjs +10 -0
  73. package/dist/syntax-layer.cjs +8 -0
  74. package/dist/syntax-layer.d.ts +18 -0
  75. package/dist/syntax-layer.mjs +6 -0
  76. package/dist/syntax-rule-type.cjs +27 -0
  77. package/dist/syntax-rule-type.d.ts +28 -0
  78. package/dist/syntax-rule-type.mjs +25 -0
  79. package/dist/syntax-rule.cjs +666 -0
  80. package/dist/syntax-rule.d.ts +51 -0
  81. package/dist/syntax-rule.mjs +664 -0
  82. package/dist/types/common.cjs +2 -0
  83. package/dist/types/common.d.ts +1 -0
  84. package/dist/types/common.mjs +1 -0
  85. package/dist/types/config.cjs +2 -0
  86. package/dist/types/config.d.ts +70 -0
  87. package/dist/types/config.mjs +1 -0
  88. package/dist/types/syntax.cjs +2 -0
  89. package/dist/types/syntax.d.ts +106 -0
  90. package/dist/types/syntax.mjs +1 -0
  91. package/dist/utils/are-rule-at-equal.cjs +12 -0
  92. package/dist/utils/are-rule-at-equal.d.ts +2 -0
  93. package/dist/utils/are-rule-at-equal.mjs +10 -0
  94. package/dist/utils/are-rule-modes-equal.cjs +7 -0
  95. package/dist/utils/are-rule-modes-equal.d.ts +2 -0
  96. package/dist/utils/are-rule-modes-equal.mjs +5 -0
  97. package/dist/utils/are-rule-selectors-equal.cjs +29 -0
  98. package/dist/utils/are-rule-selectors-equal.d.ts +2 -0
  99. package/dist/utils/are-rule-selectors-equal.mjs +27 -0
  100. package/dist/utils/are-rule-states-equal.cjs +11 -0
  101. package/dist/utils/are-rule-states-equal.d.ts +2 -0
  102. package/dist/utils/are-rule-states-equal.mjs +9 -0
  103. package/dist/utils/are-rules-duplicated.cjs +17 -0
  104. package/dist/utils/are-rules-duplicated.d.ts +2 -0
  105. package/dist/utils/are-rules-duplicated.mjs +15 -0
  106. package/dist/utils/autofill-solid-style.cjs +31 -0
  107. package/dist/utils/autofill-solid-style.d.ts +3 -0
  108. package/dist/utils/autofill-solid-style.mjs +29 -0
  109. package/dist/utils/extend-config.cjs +59 -0
  110. package/dist/utils/extend-config.d.ts +2 -2
  111. package/dist/utils/extend-config.mjs +57 -0
  112. package/dist/utils/flatten-object.cjs +15 -0
  113. package/dist/utils/flatten-object.d.ts +1 -1
  114. package/dist/utils/flatten-object.mjs +13 -0
  115. package/dist/utils/generate-css.cjs +13 -0
  116. package/dist/utils/generate-css.d.ts +2 -0
  117. package/dist/utils/generate-css.mjs +11 -0
  118. package/dist/utils/hex-to-rgb.cjs +30 -0
  119. package/dist/utils/hex-to-rgb.d.ts +1 -1
  120. package/dist/utils/hex-to-rgb.mjs +28 -0
  121. package/dist/utils/is-core-rule.cjs +9 -0
  122. package/dist/utils/is-core-rule.d.ts +1 -0
  123. package/dist/utils/is-core-rule.mjs +7 -0
  124. package/dist/utils/reorder-for-readable-classes.cjs +62 -0
  125. package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +2 -6
  126. package/dist/utils/reorder-for-readable-classes.mjs +60 -0
  127. package/package.json +1 -1
  128. package/dist/bin/index.bundle.js +0 -36
  129. package/dist/config/media-queries.d.ts +0 -1
  130. package/dist/constants/base-unit-regex.d.ts +0 -1
  131. package/dist/constants/config-esm-text.d.ts +0 -1
  132. package/dist/constants/config-text.d.ts +0 -1
  133. package/dist/constants/config-ts-text.d.ts +0 -1
  134. package/dist/constants/start-symbol.d.ts +0 -6
  135. package/dist/functions/transform-color-with-opacity.d.ts +0 -1
  136. package/dist/index.bundle.js +0 -35
  137. package/dist/index.bundle.mjs +0 -35
  138. package/dist/tokens/screen-sizes.d.ts +0 -14
  139. package/dist/types/global.d.ts +0 -5
  140. package/dist/utils/concat-arrays.d.ts +0 -1
  141. package/dist/utils/get-type.d.ts +0 -7
  142. package/dist/utils/is-plain-object.d.ts +0 -8
  143. package/dist/utils/is-symbol.d.ts +0 -7
  144. package/dist/utils/rgb-to-hex.d.ts +0 -1
@@ -0,0 +1,666 @@
1
+ 'use strict';
2
+
3
+ var cssEscape = require('./shared/utils/css-escape.cjs');
4
+ var syntaxRuleType = require('./syntax-rule-type.cjs');
5
+ var common = require('./common.cjs');
6
+ var rule = require('./rule.cjs');
7
+
8
+ class SyntaxRule extends rule.Rule {
9
+ name;
10
+ css;
11
+ registeredSyntax;
12
+ fixedClass;
13
+ layerAtComponents;
14
+ supportsAtComponents;
15
+ mediaAtComponents;
16
+ containerAtComponents;
17
+ priority;
18
+ order;
19
+ type;
20
+ declarations;
21
+ layer;
22
+ supportUnknown;
23
+ animationNames;
24
+ variableNames;
25
+ constructor(name, css, registeredSyntax, fixedClass, mode){
26
+ super(name), this.name = name, this.css = css, this.registeredSyntax = registeredSyntax, this.fixedClass = fixedClass, this.priority = -1, this.order = 0, this.type = 0, this.resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
27
+ const { functions } = this.css.config;
28
+ let currentValue = '';
29
+ for (const eachValueComponent of valueComponents){
30
+ switch(eachValueComponent.type){
31
+ case 'function':
32
+ const functionDefinition = functions && functions[eachValueComponent.name];
33
+ if (functionDefinition?.transform && !eachValueComponent.bypassTransform) {
34
+ const result = functionDefinition.transform.call(this, this.resolveValue(eachValueComponent.children, functionDefinition.unit ?? unit, bypassVariableNames, bypassParsing || eachValueComponent.name === 'calc'), bypassVariableNames);
35
+ currentValue += eachValueComponent.token = eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
36
+ } else {
37
+ currentValue += eachValueComponent.token = eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + common.VALUE_DELIMITERS[eachValueComponent.symbol];
38
+ }
39
+ break;
40
+ // todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
41
+ case 'variable':
42
+ const variable = this.css.variables.get(eachValueComponent.name);
43
+ if (variable) {
44
+ const handleVariable = (normalHandler, varHandler)=>{
45
+ if (variable.modes) {
46
+ if (this.mode) {
47
+ const themeVariable = variable.modes[this.mode] ?? variable;
48
+ if (themeVariable?.value) {
49
+ normalHandler(themeVariable);
50
+ }
51
+ } else {
52
+ if (!this.variableNames) {
53
+ this.variableNames = [];
54
+ }
55
+ if (!this.variableNames.includes(eachValueComponent.name)) {
56
+ this.variableNames.push(eachValueComponent.name);
57
+ }
58
+ varHandler();
59
+ }
60
+ } else {
61
+ normalHandler(variable);
62
+ }
63
+ };
64
+ switch(variable.type){
65
+ case 'string':
66
+ handleVariable((variable)=>{
67
+ const valueComponents = [];
68
+ this.parseValues(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
69
+ ...bypassVariableNames,
70
+ eachValueComponent.name
71
+ ]);
72
+ currentValue += eachValueComponent.text = this.resolveValue(valueComponents, unit, [
73
+ ...bypassVariableNames,
74
+ eachValueComponent.name
75
+ ], bypassParsing);
76
+ }, ()=>{
77
+ currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
78
+ });
79
+ break;
80
+ case 'number':
81
+ handleVariable((variable)=>{
82
+ if (bypassParsing) {
83
+ currentValue += eachValueComponent.text = String(variable.value);
84
+ } else {
85
+ const valueComponent = this.parseValue(variable.value, unit);
86
+ currentValue += eachValueComponent.text = valueComponent.value + (valueComponent.unit ?? '');
87
+ }
88
+ }, ()=>{
89
+ currentValue += eachValueComponent.text = unit ? `calc(var(--${eachValueComponent.name}) / 16 * 1rem)` : `var(--${eachValueComponent.name})`;
90
+ });
91
+ break;
92
+ case 'color':
93
+ const alpha = eachValueComponent.alpha ? '/' + eachValueComponent.alpha : '';
94
+ handleVariable((variable)=>{
95
+ currentValue += eachValueComponent.text = `${variable['space']}(${variable.value}${alpha})`;
96
+ }, ()=>{
97
+ currentValue += eachValueComponent.text = `${variable.space}(var(--${eachValueComponent.name})${alpha})`;
98
+ });
99
+ break;
100
+ }
101
+ } else {
102
+ currentValue += eachValueComponent.text = `var(--${eachValueComponent.name}${eachValueComponent.fallback ? ',' + eachValueComponent.fallback : ''})`;
103
+ }
104
+ break;
105
+ case 'separator':
106
+ currentValue += eachValueComponent.text ? eachValueComponent.text : eachValueComponent.text = eachValueComponent.value;
107
+ break;
108
+ case 'number':
109
+ currentValue += eachValueComponent.text = eachValueComponent.value + (eachValueComponent.unit || '');
110
+ break;
111
+ default:
112
+ currentValue += eachValueComponent.text = eachValueComponent.value;
113
+ break;
114
+ }
115
+ }
116
+ return currentValue;
117
+ }, this.parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
118
+ const root = parentFunctionName === undefined;
119
+ const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
120
+ const checkIsString = (value)=>value === '\'' || value === '"';
121
+ const isString = checkIsString(endSymbol);
122
+ const separators = [
123
+ ','
124
+ ];
125
+ if (this.definition.separators?.length) {
126
+ separators.push(...this.definition.separators);
127
+ }
128
+ let currentValue = '';
129
+ const parse = ()=>{
130
+ if (currentValue) {
131
+ let handled = false;
132
+ if (!isVarFunction || currentValueComponents.length) {
133
+ const handleVariable = (variableName, alpha)=>{
134
+ const globalVariableValue = this.css.variables.get(variableName);
135
+ const variable = Object.prototype.hasOwnProperty.call(this.variables, variableName) ? this.variables[variableName] : globalVariableValue;
136
+ if (variable) {
137
+ const name = variable.name ?? variableName;
138
+ if (!bypassVariableNames.includes(name)) {
139
+ handled = true;
140
+ const valueComponent = {
141
+ type: 'variable',
142
+ name,
143
+ variable: this.css.variables.get(name),
144
+ token: currentValue
145
+ };
146
+ if (alpha) valueComponent.alpha = alpha;
147
+ currentValueComponents.push(valueComponent);
148
+ }
149
+ }
150
+ };
151
+ handleVariable(currentValue);
152
+ if (!handled) {
153
+ const [colorName, alpha] = currentValue.split('/');
154
+ handleVariable(colorName, alpha);
155
+ }
156
+ }
157
+ if (!handled) {
158
+ if (!isVarFunction) {
159
+ const result = common.BASE_UNIT_REGEX.exec(currentValue);
160
+ if (result) {
161
+ currentValue = String(+result[1] * (this.css.config.baseUnit ?? 1));
162
+ }
163
+ }
164
+ if (bypassParsing) {
165
+ currentValueComponents.push({
166
+ type: 'string',
167
+ value: currentValue,
168
+ token: currentValue
169
+ });
170
+ } else {
171
+ currentValueComponents.push({
172
+ ...this.parseValue(currentValue, unit),
173
+ token: currentValue
174
+ });
175
+ }
176
+ }
177
+ currentValue = '';
178
+ }
179
+ };
180
+ for(; i < value.length; i++){
181
+ const val = value[i];
182
+ if (val === endSymbol) {
183
+ if (isString) {
184
+ let count = 0;
185
+ for(let j = currentValue.length - 1;; j--){
186
+ if (currentValue[j] !== '\\') break;
187
+ count++;
188
+ }
189
+ if (count % 2) {
190
+ currentValue += val;
191
+ continue;
192
+ } else {
193
+ parse();
194
+ }
195
+ } else {
196
+ parse();
197
+ }
198
+ return i;
199
+ } else if (!isString && val in common.VALUE_DELIMITERS) {
200
+ const functionName = currentValue;
201
+ const newValueComponent = {
202
+ type: 'function',
203
+ name: functionName,
204
+ symbol: val,
205
+ children: [],
206
+ token: ''
207
+ };
208
+ currentValueComponents.push(newValueComponent);
209
+ currentValue = '';
210
+ const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
211
+ i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, common.VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
212
+ } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
213
+ parse();
214
+ currentValueComponents.push({
215
+ type: 'separator',
216
+ value: ' ',
217
+ token: val
218
+ });
219
+ } else {
220
+ if (!isString) {
221
+ if (val === '.') {
222
+ if (isNaN(+value[i + 1])) {
223
+ if (root) break;
224
+ } else if (value[i - 1] === '-') {
225
+ currentValue += '0';
226
+ }
227
+ } else if (separators.includes(val)) {
228
+ parse();
229
+ currentValueComponents.push({
230
+ type: 'separator',
231
+ value: val,
232
+ text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
233
+ token: val
234
+ });
235
+ continue;
236
+ } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
237
+ '!',
238
+ '*',
239
+ '>',
240
+ '+',
241
+ '~',
242
+ ':',
243
+ '[',
244
+ '@',
245
+ '_'
246
+ ].includes(val))) {
247
+ break;
248
+ }
249
+ }
250
+ currentValue += val;
251
+ }
252
+ }
253
+ parse();
254
+ return i;
255
+ };
256
+ this.mode = mode;
257
+ this.layer = css.generalLayer;
258
+ Object.assign(this, registeredSyntax);
259
+ const { id, definition } = registeredSyntax;
260
+ const { analyze, transformValue, declare, transformValueComponents, create, type, unit } = definition;
261
+ this.type = type;
262
+ const { scope, important, modes } = css.config;
263
+ const { at, animations } = css;
264
+ if (create) create.call(this, name);
265
+ // 1. value / selectorToken
266
+ this.declarations = definition.declarations;
267
+ let stateToken;
268
+ let prefixToken;
269
+ if (this.type === syntaxRuleType.Utility) {
270
+ // TODO: id 使用其他方式傳遞
271
+ stateToken = name.slice(id.length - 1);
272
+ } else {
273
+ let valueToken;
274
+ if (analyze) {
275
+ [valueToken, prefixToken] = analyze.call(this, name);
276
+ } else {
277
+ const indexOfColon = name.indexOf(':');
278
+ this.keyToken = name.slice(0, indexOfColon + 1);
279
+ valueToken = name.slice(indexOfColon + 1);
280
+ }
281
+ this.valueComponents = [];
282
+ const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ? Array.from(this.css.animations.keys()) : []);
283
+ this.valueToken = valueToken.slice(0, parsedValueIndex);
284
+ stateToken = valueToken.slice(parsedValueIndex);
285
+ }
286
+ // 2. !important
287
+ if (stateToken[0] === '!') {
288
+ this.important = true;
289
+ stateToken = stateToken.slice(1);
290
+ }
291
+ this.stateToken = stateToken;
292
+ // 3. prefix selector
293
+ if (prefixToken) {
294
+ this.vendorPrefixSelectors = css.generateVendorSelectors(prefixToken);
295
+ }
296
+ // 4. suffix selector
297
+ const stateTokens = stateToken.split('@');
298
+ const suffixSelector = stateTokens[0];
299
+ if (suffixSelector) {
300
+ this.vendorSuffixSelectors = css.generateVendorSelectors(suffixSelector);
301
+ for (const suffixSelectors of Object.values(this.vendorSuffixSelectors)){
302
+ for (const eachSuffixSelector of suffixSelectors){
303
+ const SORTED_SELECTORS = [
304
+ ':disabled',
305
+ ':active',
306
+ ':focus',
307
+ ':hover'
308
+ ];
309
+ for(let i = 0; i < SORTED_SELECTORS.length; i++){
310
+ if (eachSuffixSelector.includes(SORTED_SELECTORS[i])) {
311
+ if (this.priority === -1 || this.priority > i) {
312
+ this.priority = i;
313
+ }
314
+ break;
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ // selector combinations
321
+ const suffixSelectorVendorsByPrefixSelectorVendor = {};
322
+ if (this.vendorPrefixSelectors) {
323
+ if (this.vendorSuffixSelectors) {
324
+ for(const prefixSelectorVendor in this.vendorPrefixSelectors){
325
+ const suffixSelectorVendors = suffixSelectorVendorsByPrefixSelectorVendor[prefixSelectorVendor] = [];
326
+ if (Object.prototype.hasOwnProperty.call(this.vendorSuffixSelectors, prefixSelectorVendor)) {
327
+ suffixSelectorVendors.push(prefixSelectorVendor);
328
+ } else {
329
+ for(const suffixVendor in this.vendorSuffixSelectors){
330
+ suffixSelectorVendors.push(suffixVendor);
331
+ }
332
+ }
333
+ }
334
+ } else {
335
+ for(const vendor in this.vendorPrefixSelectors){
336
+ suffixSelectorVendorsByPrefixSelectorVendor[vendor] = [
337
+ ''
338
+ ];
339
+ }
340
+ }
341
+ } else {
342
+ suffixSelectorVendorsByPrefixSelectorVendor[''] = this.vendorSuffixSelectors ? Object.keys(this.vendorSuffixSelectors) : [
343
+ ''
344
+ ];
345
+ }
346
+ // 5. atTokens
347
+ for(let i = 1; i < stateTokens.length; i++){
348
+ const atToken = stateTokens[i];
349
+ this.atToken = (this.atToken || '') + '@' + atToken;
350
+ if (atToken) {
351
+ if (atToken === 'base' || atToken === 'preset') {
352
+ const atComponent = {
353
+ type: 'arbitrary',
354
+ value: atToken
355
+ };
356
+ if (this.layerAtComponents) {
357
+ this.layerAtComponents.push(atComponent);
358
+ } else {
359
+ this.layerAtComponents = [
360
+ atComponent
361
+ ];
362
+ }
363
+ continue;
364
+ } else if (atToken === 'rtl' || atToken === 'ltr') {
365
+ this.direction = atToken;
366
+ } else {
367
+ let queryType;
368
+ const atComponents = [];
369
+ // x font-face, counter-style, keyframes, font-feature-values, property, layer
370
+ const queryTypeRegExp = /^(media|supports|container|layer)/;
371
+ const atRuleResult = queryTypeRegExp.exec(atToken);
372
+ if (atRuleResult) {
373
+ queryType = atRuleResult[1];
374
+ atComponents.push({
375
+ type: 'arbitrary',
376
+ token: atToken,
377
+ value: atToken.slice(queryType.length).replace(/\|/g, ' ')
378
+ });
379
+ } else {
380
+ const analyzeToken = (atComponentToken)=>{
381
+ if (atComponentToken === '&') {
382
+ atComponents.push({
383
+ type: 'operator',
384
+ token: atComponentToken,
385
+ value: 'and'
386
+ });
387
+ } else if (atComponentToken.startsWith('')) {
388
+ const targetAt = at.get(atComponentToken);
389
+ if (typeof targetAt === 'string') {
390
+ const match = targetAt.match(queryTypeRegExp);
391
+ queryType = match ? match[1] : '';
392
+ if (!queryType) throw new Error(`Invalid query '${atComponentToken}': '${targetAt}'`);
393
+ atComponents.push({
394
+ type: 'arbitrary',
395
+ value: targetAt.slice(match ? match[1].length + 1 : 0)
396
+ });
397
+ } else {
398
+ // todo: container queries
399
+ queryType = 'media';
400
+ let featureName = '';
401
+ let extremumOperator = '';
402
+ let correction = 0;
403
+ if (atComponentToken.startsWith('<=')) {
404
+ extremumOperator = '<=';
405
+ featureName = 'max-width';
406
+ } else if (atComponentToken.startsWith('>') && !atComponentToken.startsWith('>=')) {
407
+ extremumOperator = '>';
408
+ featureName = 'min-width';
409
+ correction = .02;
410
+ } else if (atComponentToken.startsWith('<')) {
411
+ extremumOperator = '<';
412
+ featureName = 'max-width';
413
+ correction = -0.02;
414
+ } else if (atComponentToken.startsWith('>=') || targetAt) {
415
+ extremumOperator = '>=';
416
+ featureName = 'min-width';
417
+ }
418
+ const token = extremumOperator ? atComponentToken.replace(extremumOperator, '') : atComponentToken;
419
+ const viewport = at.get(token);
420
+ switch(featureName){
421
+ case 'max-width':
422
+ case 'min-width':
423
+ if (typeof viewport === 'number') {
424
+ atComponents.push({
425
+ type: 'feature',
426
+ name: featureName,
427
+ valueType: 'number',
428
+ value: viewport + correction,
429
+ unit: 'px'
430
+ });
431
+ } else {
432
+ const valueComponent = this.parseValue(token, 'px');
433
+ if (valueComponent.type === 'number') {
434
+ atComponents.push({
435
+ type: 'feature',
436
+ name: featureName,
437
+ valueType: 'number',
438
+ value: valueComponent.value + correction,
439
+ unit: valueComponent.unit
440
+ });
441
+ } else {
442
+ atComponents.push({
443
+ type: 'feature',
444
+ name: featureName,
445
+ valueType: 'string',
446
+ value: token
447
+ });
448
+ }
449
+ }
450
+ break;
451
+ }
452
+ }
453
+ }
454
+ };
455
+ const isAmpersandIncluded = atToken.includes('&');
456
+ if (isAmpersandIncluded) {
457
+ const typeOrFeatureTokens = atToken.split(/(&|,)/);
458
+ for (const atComponentToken of typeOrFeatureTokens){
459
+ analyzeToken(atComponentToken);
460
+ }
461
+ } else {
462
+ analyzeToken(atToken);
463
+ }
464
+ if (!atComponents.length) {
465
+ if (!isAmpersandIncluded && modes?.[atToken]) {
466
+ this.mode = atToken;
467
+ continue;
468
+ }
469
+ }
470
+ }
471
+ if (queryType) {
472
+ const targetAtComponents = this[`${queryType}AtComponents`];
473
+ if (targetAtComponents) {
474
+ targetAtComponents.push(...atComponents);
475
+ } else {
476
+ this[`${queryType}AtComponents`] = atComponents;
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ if (this.mode && modes?.[this.mode] === 'media') {
483
+ const atFeatureComponent = {
484
+ type: 'feature',
485
+ name: 'prefers-color-scheme',
486
+ valueType: 'string',
487
+ value: this.mode
488
+ };
489
+ if (this.mediaAtComponents) {
490
+ this.mediaAtComponents.push(atFeatureComponent);
491
+ } else {
492
+ this.mediaAtComponents = [
493
+ atFeatureComponent
494
+ ];
495
+ }
496
+ }
497
+ if (this.fixedClass) {
498
+ this.layer = css.componentsLayer;
499
+ } else {
500
+ const onlyLayerComponent = this.layerAtComponents?.length === 1 && this.layerAtComponents[0];
501
+ if (onlyLayerComponent) {
502
+ if (onlyLayerComponent.value === 'base') {
503
+ this.layer = css.baseLayer;
504
+ this.layerAtComponents = undefined;
505
+ } else if (onlyLayerComponent.value === 'preset') {
506
+ this.layer = css.presetLayer;
507
+ this.layerAtComponents = undefined;
508
+ }
509
+ }
510
+ }
511
+ // 7. value
512
+ let newValue;
513
+ if (this.valueComponents) {
514
+ if (transformValueComponents) {
515
+ this.valueComponents = transformValueComponents.call(this, this.valueComponents);
516
+ }
517
+ newValue = this.resolveValue(this.valueComponents, unit, [], false);
518
+ if (transformValue) {
519
+ newValue = transformValue.call(this, newValue);
520
+ }
521
+ if (declare) {
522
+ this.declarations = declare.call(this, newValue, this.valueComponents);
523
+ } else if (id) {
524
+ this.declarations = {
525
+ [id]: newValue
526
+ };
527
+ }
528
+ }
529
+ const propertiesText = [];
530
+ for(const propertyName in this.declarations){
531
+ const propertyValue = this.declarations[propertyName];
532
+ const propertyText = propertyName + ':' + String(propertyValue);
533
+ if (animations && (propertyText.startsWith('animation') || propertyText.startsWith('animation-name'))) {
534
+ const animationNames = propertyText.split(':')[1].split('!important')[0].split(' ').filter((eachValue)=>this.css.animations.has(eachValue) && (!this.animationNames || !this.animationNames.includes(eachValue)));
535
+ if (animationNames.length) {
536
+ if (!this.animationNames) {
537
+ this.animationNames = [];
538
+ }
539
+ this.animationNames = animationNames;
540
+ }
541
+ }
542
+ propertiesText.push(propertyText + ((this.important || important) && !propertyText.endsWith('!important') ? '!important' : ''));
543
+ }
544
+ // 創建 Natives
545
+ if (propertiesText.length) {
546
+ for(const prefixSelectorVendor in suffixSelectorVendorsByPrefixSelectorVendor){
547
+ for (const eachSuffixSelectorVendor of suffixSelectorVendorsByPrefixSelectorVendor[prefixSelectorVendor]){
548
+ const prefixSelectors = this.vendorPrefixSelectors?.[prefixSelectorVendor];
549
+ const suffixSelectors = this.vendorSuffixSelectors?.[eachSuffixSelectorVendor];
550
+ let prefixText = '';
551
+ if (this.direction) {
552
+ prefixText += '[dir=' + this.direction + '] ';
553
+ }
554
+ const prefixTexts = prefixSelectors ? prefixSelectors.map((eachPrefixSelector)=>eachPrefixSelector + prefixText) : [
555
+ prefixText
556
+ ];
557
+ const getCssText = (name)=>prefixTexts.map((eachPrefixText)=>{
558
+ let modePrefix = '';
559
+ if (this.mode) {
560
+ const modeSelector = this.css.getModeSelector(this.mode);
561
+ if (modeSelector) {
562
+ modePrefix = modeSelector + ' ';
563
+ }
564
+ }
565
+ return modePrefix + (scope ? scope + ' ' : '') + eachPrefixText;
566
+ }).reduce((arr, eachPrefixText)=>{
567
+ arr.push(suffixSelectors ? suffixSelectors.reduce((_arr, eachSuffixSelector)=>{
568
+ _arr.push(eachPrefixText + '.' + cssEscape(name) + eachSuffixSelector);
569
+ return _arr;
570
+ }, []).join(',') : eachPrefixText + '.' + cssEscape(name));
571
+ return arr;
572
+ }, []).join(',');
573
+ const selectorText = getCssText(fixedClass ?? name);
574
+ let cssText = selectorText + '{' + propertiesText.join(';') + '}';
575
+ const resolveAtComponents = (atComponents, separator)=>atComponents.map((atComponent, i)=>{
576
+ const value = this.resolveAtComponent(atComponent);
577
+ return (i === 0 ? value.charAt(0) !== '(' ? ' ' : '' : '') + value;
578
+ }).join(separator) + '{' + cssText + '}';
579
+ if (this.containerAtComponents) cssText = '@container' + resolveAtComponents(this.containerAtComponents, ' ');
580
+ if (this.mediaAtComponents) cssText = '@media' + resolveAtComponents(this.mediaAtComponents, ' ');
581
+ if (this.supportsAtComponents) cssText = '@supports' + resolveAtComponents(this.supportsAtComponents, ' ');
582
+ if (this.layerAtComponents) cssText = '@layer' + resolveAtComponents(this.layerAtComponents, '.');
583
+ const node = {
584
+ text: cssText,
585
+ selectorText
586
+ };
587
+ if (prefixSelectors) node.prefixSelectors = prefixSelectors;
588
+ if (suffixSelectors) node.suffixSelectors = suffixSelectors;
589
+ this.nodes.push(node);
590
+ }
591
+ }
592
+ }
593
+ }
594
+ resolveAtComponent(atComponent) {
595
+ switch(atComponent.type){
596
+ case 'feature':
597
+ return '(' + atComponent.name + ':' + atComponent.value + (atComponent.unit || '') + ')';
598
+ default:
599
+ return atComponent.value;
600
+ }
601
+ }
602
+ resolveValue;
603
+ parseValues;
604
+ parseValue(token, unit = this.definition.unit) {
605
+ const defaultUnit = unit ?? this.definition.unit;
606
+ let newUnit = '';
607
+ let value;
608
+ if (typeof token === 'number') {
609
+ /**
610
+ * 當無單位值且 defaultUnit === 'rem',
611
+ * 將 pxValue / 16 轉為 remValue
612
+ */ if (defaultUnit && !newUnit) {
613
+ if (defaultUnit === 'rem' || defaultUnit === 'em') {
614
+ value = token / (this.css.config.rootSize || 1);
615
+ }
616
+ newUnit = defaultUnit || '';
617
+ } else {
618
+ value = token;
619
+ }
620
+ return {
621
+ value,
622
+ unit: newUnit,
623
+ type: 'number'
624
+ };
625
+ } else if (defaultUnit) {
626
+ // w:1/2 -> width: 50%
627
+ if (/^\d+\/\d+/.test(token)) {
628
+ const [dividend, divisor] = token.split('/');
629
+ return {
630
+ value: +dividend / +divisor * 100,
631
+ unit: '%',
632
+ type: 'number'
633
+ };
634
+ }
635
+ const matches = token.match(common.UNIT_REGEX);
636
+ // ['0.5deg', '0.5', 'deg', index: 0, input: '0.5deg', groups: undefined]
637
+ if (matches) {
638
+ value = +matches[1];
639
+ newUnit = matches[3] || '';
640
+ /**
641
+ * 當無單位值且 defaultUnit === 'rem',
642
+ * 將 pxValue / 16 轉為 remValue
643
+ */ if (!newUnit) {
644
+ if (defaultUnit === 'rem' || defaultUnit === 'em') {
645
+ value = value / (this.css.config.rootSize || 1);
646
+ }
647
+ newUnit = defaultUnit || '';
648
+ }
649
+ return {
650
+ value,
651
+ unit: newUnit,
652
+ type: 'number'
653
+ };
654
+ }
655
+ }
656
+ return {
657
+ value: token,
658
+ type: 'string'
659
+ };
660
+ }
661
+ get key() {
662
+ return (this.fixedClass ? this.fixedClass + ' ' : '') + this.name;
663
+ }
664
+ }
665
+
666
+ exports.SyntaxRule = SyntaxRule;