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