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