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

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