@master/css 2.0.0-rc.15 → 2.0.0-rc.17

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