@master/css 2.0.0-rc.68 → 2.0.0-rc.69

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 (107) hide show
  1. package/dist/common.cjs +0 -2
  2. package/dist/common.d.ts +0 -1
  3. package/dist/common.mjs +1 -2
  4. package/dist/config/functions.cjs +9 -243
  5. package/dist/config/functions.d.ts +137 -2
  6. package/dist/config/functions.mjs +9 -243
  7. package/dist/config/index.cjs +2 -2
  8. package/dist/config/index.mjs +2 -2
  9. package/dist/config/modes.cjs +307 -3
  10. package/dist/config/modes.d.ts +306 -2
  11. package/dist/config/modes.mjs +307 -3
  12. package/dist/config/rules.cjs +740 -782
  13. package/dist/config/rules.d.ts +692 -683
  14. package/dist/config/rules.mjs +741 -783
  15. package/dist/config/utilities.cjs +328 -97
  16. package/dist/config/utilities.d.ts +247 -16
  17. package/dist/config/utilities.mjs +328 -97
  18. package/dist/config/variables.cjs +88 -460
  19. package/dist/config/variables.d.ts +358 -369
  20. package/dist/config/variables.mjs +88 -460
  21. package/dist/core.cjs +234 -234
  22. package/dist/core.d.ts +5 -3
  23. package/dist/core.mjs +234 -234
  24. package/dist/create.cjs +10 -0
  25. package/dist/create.d.ts +3 -0
  26. package/dist/create.mjs +8 -0
  27. package/dist/declarers/core.group.cjs +99 -0
  28. package/dist/declarers/core.group.d.ts +2 -0
  29. package/dist/declarers/core.group.mjs +97 -0
  30. package/dist/declarers/core.variable.cjs +9 -0
  31. package/dist/declarers/core.variable.d.ts +4 -0
  32. package/dist/declarers/core.variable.mjs +7 -0
  33. package/dist/declarers/index.cjs +13 -0
  34. package/dist/declarers/index.d.ts +10 -0
  35. package/dist/declarers/index.mjs +11 -0
  36. package/dist/declarers/pair.cjs +12 -0
  37. package/dist/declarers/pair.d.ts +4 -0
  38. package/dist/declarers/pair.mjs +10 -0
  39. package/dist/factories/with-syntax-layer.cjs +0 -2
  40. package/dist/factories/with-syntax-layer.mjs +0 -2
  41. package/dist/function-transformers/core.calc.cjs +225 -0
  42. package/dist/function-transformers/core.calc.d.ts +2 -0
  43. package/dist/function-transformers/core.calc.mjs +223 -0
  44. package/dist/function-transformers/core.variable.cjs +23 -0
  45. package/dist/function-transformers/core.variable.d.ts +7 -0
  46. package/dist/function-transformers/core.variable.mjs +21 -0
  47. package/dist/function-transformers/index.cjs +11 -0
  48. package/dist/function-transformers/index.d.ts +8 -0
  49. package/dist/function-transformers/index.mjs +9 -0
  50. package/dist/index.cjs +10 -1
  51. package/dist/index.d.ts +8 -2
  52. package/dist/index.mjs +6 -1
  53. package/dist/layer.cjs +2 -4
  54. package/dist/layer.mjs +2 -4
  55. package/dist/non-layer.cjs +2 -4
  56. package/dist/non-layer.mjs +2 -4
  57. package/dist/syntax-rule-type.cjs +8 -7
  58. package/dist/syntax-rule-type.d.ts +7 -7
  59. package/dist/syntax-rule-type.mjs +8 -7
  60. package/dist/syntax-rule.cjs +305 -258
  61. package/dist/syntax-rule.d.ts +2 -2
  62. package/dist/syntax-rule.mjs +306 -259
  63. package/dist/{utils/autofill-solid-style.cjs → transformers/auto-fill-solid.cjs} +3 -3
  64. package/dist/transformers/auto-fill-solid.d.ts +2 -0
  65. package/dist/{utils/autofill-solid-style.mjs → transformers/auto-fill-solid.mjs} +3 -3
  66. package/dist/transformers/index.cjs +9 -0
  67. package/dist/transformers/index.d.ts +6 -0
  68. package/dist/transformers/index.mjs +7 -0
  69. package/dist/types/common.d.ts +0 -2
  70. package/dist/types/config.d.ts +24 -20
  71. package/dist/types/syntax.d.ts +10 -8
  72. package/dist/utils/equal-selectors.cjs +1 -2
  73. package/dist/utils/equal-selectors.mjs +1 -2
  74. package/dist/utils/extend-config.cjs +83 -44
  75. package/dist/utils/extend-config.d.ts +10 -1
  76. package/dist/utils/extend-config.mjs +83 -44
  77. package/dist/utils/flatten-meta-object.cjs +38 -0
  78. package/dist/utils/flatten-meta-object.d.ts +13 -0
  79. package/dist/utils/flatten-meta-object.mjs +36 -0
  80. package/dist/utils/flatten-object.cjs +13 -9
  81. package/dist/utils/flatten-object.d.ts +1 -1
  82. package/dist/utils/flatten-object.mjs +13 -9
  83. package/dist/utils/generate-css.cjs +2 -2
  84. package/dist/utils/generate-css.d.ts +1 -2
  85. package/dist/utils/generate-css.mjs +2 -2
  86. package/dist/utils/minify-extended-config.cjs +64 -0
  87. package/dist/utils/minify-extended-config.d.ts +9 -0
  88. package/dist/utils/minify-extended-config.mjs +62 -0
  89. package/dist/utils/nest-meta-object.cjs +25 -0
  90. package/dist/utils/nest-meta-object.d.ts +7 -0
  91. package/dist/utils/nest-meta-object.mjs +23 -0
  92. package/dist/utils/parse-at.cjs +1 -2
  93. package/dist/utils/parse-at.d.ts +2 -2
  94. package/dist/utils/parse-at.mjs +1 -2
  95. package/dist/utils/parse-pair.cjs +3 -6
  96. package/dist/utils/parse-pair.mjs +3 -6
  97. package/dist/utils/parse-selector.cjs +2 -4
  98. package/dist/utils/parse-selector.d.ts +2 -2
  99. package/dist/utils/parse-selector.mjs +2 -4
  100. package/dist/utils/sort-readable-classes.cjs +2 -2
  101. package/dist/utils/sort-readable-classes.d.ts +1 -2
  102. package/dist/utils/sort-readable-classes.mjs +2 -2
  103. package/dist/variable-rule.cjs +35 -29
  104. package/dist/variable-rule.d.ts +16 -6
  105. package/dist/variable-rule.mjs +35 -29
  106. package/package.json +1 -1
  107. package/dist/utils/autofill-solid-style.d.ts +0 -3
@@ -9,6 +9,9 @@ var generateAt = require('./utils/generate-at.cjs');
9
9
  var parseSelector = require('./utils/parse-selector.cjs');
10
10
  var generateSelector = require('./utils/generate-selector.cjs');
11
11
  var compareRulePriority = require('./utils/compare-rule-priority.cjs');
12
+ var index$1 = require('./declarers/index.cjs');
13
+ var index = require('./transformers/index.cjs');
14
+ var index$2 = require('./function-transformers/index.cjs');
12
15
 
13
16
  class SyntaxRule {
14
17
  name;
@@ -18,10 +21,10 @@ class SyntaxRule {
18
21
  native;
19
22
  atRules;
20
23
  priority;
21
- type;
24
+ type = syntaxRuleType.Normal;
22
25
  declarations;
23
26
  layer;
24
- valid;
27
+ valid = true;
25
28
  animationNames;
26
29
  variableNames;
27
30
  constructor(name, css, registeredSyntax, fixedClass, mode){
@@ -29,263 +32,24 @@ class SyntaxRule {
29
32
  this.css = css;
30
33
  this.registeredSyntax = registeredSyntax;
31
34
  this.fixedClass = fixedClass;
32
- this.type = syntaxRuleType.Normal;
33
- this.valid = true;
34
- this.resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
35
- const { functions } = this.css.config;
36
- let currentValue = '';
37
- for (const eachValueComponent of valueComponents){
38
- switch(eachValueComponent.type){
39
- case 'function':
40
- const functionDefinition = functions && functions[eachValueComponent.name];
41
- if (functionDefinition?.transform && !eachValueComponent.bypassTransform) {
42
- const result = functionDefinition.transform.call(this, this.resolveValue(eachValueComponent.children, functionDefinition.unit ?? unit, bypassVariableNames, bypassParsing || eachValueComponent.name === 'calc'), bypassVariableNames);
43
- currentValue += eachValueComponent.token = eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
44
- } else {
45
- currentValue += eachValueComponent.token = eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + common.VALUE_DELIMITERS[eachValueComponent.symbol];
46
- }
47
- break;
48
- // todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
49
- case 'variable':
50
- const variable = this.css.variables.get(eachValueComponent.name);
51
- if (variable) {
52
- const handleVariable = (normalHandler, varHandler)=>{
53
- if (variable.modes) {
54
- if (this.mode) {
55
- const themeVariable = variable.modes[this.mode] ?? variable;
56
- if (themeVariable?.value) {
57
- normalHandler(themeVariable);
58
- }
59
- } else {
60
- if (this.variableNames) {
61
- this.variableNames.add(eachValueComponent.name);
62
- } else {
63
- this.variableNames = new Set([
64
- eachValueComponent.name
65
- ]);
66
- }
67
- varHandler();
68
- }
69
- } else {
70
- normalHandler(variable);
71
- }
72
- };
73
- switch(variable.type){
74
- case 'string':
75
- handleVariable((variable)=>{
76
- const valueComponents = [];
77
- this.parseValues(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
78
- ...bypassVariableNames,
79
- eachValueComponent.name
80
- ]);
81
- currentValue += eachValueComponent.text = this.resolveValue(valueComponents, unit, [
82
- ...bypassVariableNames,
83
- eachValueComponent.name
84
- ], bypassParsing);
85
- }, ()=>{
86
- currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
87
- });
88
- break;
89
- case 'number':
90
- handleVariable((variable)=>{
91
- if (bypassParsing) {
92
- currentValue += eachValueComponent.text = String(variable.value);
93
- } else {
94
- const valueComponent = this.parseValue(variable.value, unit);
95
- currentValue += eachValueComponent.text = valueComponent.value + (valueComponent.unit ?? '');
96
- }
97
- }, ()=>{
98
- currentValue += eachValueComponent.text = unit ? `calc(var(--${eachValueComponent.name}) / 16 * 1rem)` : `var(--${eachValueComponent.name})`;
99
- });
100
- break;
101
- case 'color':
102
- const alpha = eachValueComponent.alpha ? '/' + eachValueComponent.alpha : '';
103
- handleVariable((variable)=>{
104
- currentValue += eachValueComponent.text = `${variable['space']}(${variable.value}${alpha})`;
105
- }, ()=>{
106
- currentValue += eachValueComponent.text = `${variable.space}(var(--${eachValueComponent.name})${alpha})`;
107
- });
108
- break;
109
- }
110
- } else {
111
- currentValue += eachValueComponent.text = `var(--${eachValueComponent.name}${eachValueComponent.fallback ? ',' + eachValueComponent.fallback : ''})`;
112
- }
113
- break;
114
- case 'separator':
115
- currentValue += eachValueComponent.text ? eachValueComponent.text : eachValueComponent.text = eachValueComponent.value;
116
- break;
117
- case 'number':
118
- currentValue += eachValueComponent.text = eachValueComponent.value + (eachValueComponent.unit || '');
119
- break;
120
- default:
121
- currentValue += eachValueComponent.text = eachValueComponent.value;
122
- break;
123
- }
124
- }
125
- return currentValue;
126
- };
127
- this.parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
128
- const root = parentFunctionName === undefined;
129
- const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
130
- const checkIsString = (value)=>value === '\'' || value === '"';
131
- const isString = checkIsString(endSymbol);
132
- const separators = [
133
- ','
134
- ];
135
- if (this.definition.separators?.length) {
136
- separators.push(...this.definition.separators);
137
- }
138
- let currentValue = '';
139
- const parse = ()=>{
140
- if (currentValue) {
141
- let handled = false;
142
- if (!isVarFunction || currentValueComponents.length) {
143
- const handleVariable = (variableName, alpha)=>{
144
- const globalVariableValue = this.css.variables.get(variableName);
145
- const variable = Object.prototype.hasOwnProperty.call(this.variables, variableName) ? this.variables[variableName] : globalVariableValue;
146
- if (variable) {
147
- const name = variable.name ?? variableName;
148
- if (!bypassVariableNames.includes(name)) {
149
- handled = true;
150
- const valueComponent = {
151
- type: 'variable',
152
- name,
153
- variable: this.css.variables.get(name),
154
- token: currentValue
155
- };
156
- if (alpha) valueComponent.alpha = alpha;
157
- currentValueComponents.push(valueComponent);
158
- }
159
- }
160
- };
161
- if (/^\$[a-zA-Z0-9-]+(?:\/[^\/]+)?$/.test(currentValue)) {
162
- const [raw, alpha] = currentValue.slice(1).split('/');
163
- handleVariable(raw, alpha);
164
- } else {
165
- handleVariable(currentValue);
166
- if (!handled) {
167
- const [colorName, alpha] = currentValue.split('/');
168
- handleVariable(colorName, alpha);
169
- }
170
- }
171
- }
172
- if (!handled) {
173
- if (!isVarFunction) {
174
- const result = common.BASE_UNIT_REGEX.exec(currentValue);
175
- if (result) {
176
- currentValue = String(+result[1] * (this.css.config.baseUnit ?? 1));
177
- }
178
- }
179
- if (bypassParsing) {
180
- currentValueComponents.push({
181
- type: 'string',
182
- value: currentValue,
183
- token: currentValue
184
- });
185
- } else {
186
- const parsedValue = this.parseValue(currentValue, unit);
187
- currentValueComponents.push({
188
- ...parsedValue,
189
- token: currentValue
190
- });
191
- }
192
- }
193
- currentValue = '';
194
- }
195
- };
196
- for(; i < value.length; i++){
197
- const val = value[i];
198
- if (val === endSymbol) {
199
- if (isString) {
200
- let count = 0;
201
- for(let j = currentValue.length - 1;; j--){
202
- if (currentValue[j] !== '\\') break;
203
- count++;
204
- }
205
- if (count % 2) {
206
- currentValue += val;
207
- continue;
208
- } else {
209
- parse();
210
- }
211
- } else {
212
- parse();
213
- }
214
- return i;
215
- } else if (!isString && val in common.VALUE_DELIMITERS) {
216
- const functionName = currentValue;
217
- const newValueComponent = {
218
- type: 'function',
219
- name: functionName,
220
- symbol: val,
221
- children: [],
222
- token: ''
223
- };
224
- currentValueComponents.push(newValueComponent);
225
- currentValue = '';
226
- const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
227
- i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, common.VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
228
- } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
229
- parse();
230
- currentValueComponents.push({
231
- type: 'separator',
232
- value: ' ',
233
- token: val
234
- });
235
- } else {
236
- if (!isString) {
237
- if (val === '.') {
238
- if (isNaN(+value[i + 1])) {
239
- if (root) break;
240
- } else if (value[i - 1] === '-') {
241
- currentValue += '0';
242
- }
243
- } else if (separators.includes(val)) {
244
- parse();
245
- currentValueComponents.push({
246
- type: 'separator',
247
- value: val,
248
- text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
249
- token: val
250
- });
251
- continue;
252
- } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
253
- '!',
254
- '*',
255
- '>',
256
- '+',
257
- '~',
258
- ':',
259
- '[',
260
- '@',
261
- '_'
262
- ].includes(val))) {
263
- break;
264
- }
265
- }
266
- currentValue += val;
267
- }
268
- }
269
- parse();
270
- return i;
271
- };
272
35
  this.mode = mode;
273
36
  this.layer = css.generalLayer;
274
37
  Object.assign(this, registeredSyntax);
275
38
  const { id, definition } = registeredSyntax;
276
- const { analyze, transformValue, declare, transformValueComponents, create, type, unit } = definition;
39
+ const { declarer, transformer, type, unit, sign } = definition;
277
40
  this.type = type;
278
- if (create) create.call(this, name);
279
41
  // 1. value / selectorToken
280
- this.declarations = definition.declarations;
281
42
  let stateToken;
282
43
  if (this.type === syntaxRuleType.Utility) {
283
- // TODO: id 使用其他方式傳遞
284
44
  stateToken = name.slice(id.length - 1);
285
45
  } else {
286
46
  let valueToken;
287
- if (analyze) {
288
- [valueToken] = analyze.call(this, name);
47
+ if (sign && name.startsWith(sign)) {
48
+ valueToken = name.slice(1);
49
+ } else if (id.endsWith('()')) {
50
+ valueToken = name;
51
+ } else if (id === 'group') {
52
+ valueToken = name;
289
53
  } else {
290
54
  const indexOfColon = name.indexOf(':');
291
55
  this.keyToken = name.slice(0, indexOfColon + 1);
@@ -327,7 +91,7 @@ class SyntaxRule {
327
91
  };
328
92
  }
329
93
  }
330
- if (this.mode && css.config.modes?.[this.mode] === 'media') {
94
+ if (this.mode && css.config.modeTrigger === 'media') {
331
95
  const atComp = {
332
96
  name: 'prefers-color-scheme',
333
97
  value: this.mode
@@ -359,20 +123,46 @@ class SyntaxRule {
359
123
  // 7. value
360
124
  let newValue;
361
125
  if (this.valueComponents) {
362
- if (transformValueComponents) {
363
- this.valueComponents = transformValueComponents.call(this, this.valueComponents);
126
+ if (transformer) {
127
+ if (typeof transformer === 'string') {
128
+ const transform = index[transformer];
129
+ this.valueComponents = transform.call(this, this.valueComponents);
130
+ } else {
131
+ const [name, data] = transformer;
132
+ const transform = index[name];
133
+ this.valueComponents = transform.call(this, this.valueComponents, data);
134
+ }
364
135
  }
365
136
  newValue = this.resolveValue(this.valueComponents, unit, [], false);
366
- if (transformValue) {
367
- newValue = transformValue.call(this, newValue);
368
- }
369
- if (declare) {
370
- this.declarations = declare.call(this, newValue, this.valueComponents);
137
+ if (definition.declarations) {
138
+ const declarations = {};
139
+ if (Array.isArray(definition.declarations)) {
140
+ for (const property of definition.declarations){
141
+ declarations[property] = newValue;
142
+ }
143
+ } else {
144
+ for(const propertyName in definition.declarations){
145
+ const propertyValue = definition.declarations[propertyName];
146
+ declarations[propertyName] = propertyValue === undefined ? newValue : Array.isArray(propertyValue) ? propertyValue.map((v)=>v === undefined ? newValue : v).join('') : propertyValue;
147
+ }
148
+ }
149
+ this.declarations = declarations;
150
+ } else if (declarer) {
151
+ if (typeof declarer === 'string') {
152
+ const declare = index$1[declarer];
153
+ this.declarations = declare.call(this, newValue, this.valueComponents);
154
+ } else {
155
+ const [name, data] = declarer;
156
+ const declare = index$1[name];
157
+ this.declarations = declare.call(this, newValue, this.valueComponents, data);
158
+ }
371
159
  } else if (id) {
372
160
  this.declarations = {
373
161
  [id]: newValue
374
162
  };
375
163
  }
164
+ } else {
165
+ this.declarations = definition.declarations;
376
166
  }
377
167
  if (!Object.entries(this.declarations ?? {}).length) {
378
168
  this.valid = false;
@@ -432,8 +222,265 @@ class SyntaxRule {
432
222
  const body = pre + '.' + cssEscape(this.fixedClass ?? this.name);
433
223
  return this.selectorNodes ? generateSelector(this.selectorNodes, body) : body;
434
224
  }
435
- resolveValue;
436
- parseValues;
225
+ resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
226
+ const { functions } = this.css.config;
227
+ let currentValue = '';
228
+ for (const eachValueComponent of valueComponents){
229
+ switch(eachValueComponent.type){
230
+ case 'function':
231
+ const functionDefinition = functions && functions[eachValueComponent.name];
232
+ const fnTransformer = functionDefinition?.transformer;
233
+ if (fnTransformer && !eachValueComponent.bypassTransform) {
234
+ const resolvedValue = this.resolveValue(eachValueComponent.children, functionDefinition.unit ?? unit, bypassVariableNames, bypassParsing || eachValueComponent.name === 'calc');
235
+ let result;
236
+ if (typeof fnTransformer === 'string') {
237
+ const fnTransform = index$2[fnTransformer];
238
+ result = fnTransform.call(this, resolvedValue, bypassVariableNames);
239
+ } else {
240
+ const [name, data] = fnTransformer;
241
+ const fnTransform = index$2[name];
242
+ result = fnTransform.call(this, resolvedValue, bypassVariableNames, data);
243
+ }
244
+ currentValue += eachValueComponent.token = eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
245
+ } else {
246
+ currentValue += eachValueComponent.token = eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + common.VALUE_DELIMITERS[eachValueComponent.symbol];
247
+ }
248
+ break;
249
+ // todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
250
+ case 'variable':
251
+ const variable = this.css.variables.get(eachValueComponent.name);
252
+ if (variable) {
253
+ const handleVariable = (normalHandler, varHandler)=>{
254
+ if (variable.modes) {
255
+ if (this.mode) {
256
+ const themeVariable = variable.modes[this.mode] ?? variable;
257
+ if (themeVariable?.value) {
258
+ normalHandler(themeVariable);
259
+ }
260
+ } else {
261
+ if (this.variableNames) {
262
+ this.variableNames.add(eachValueComponent.name);
263
+ } else {
264
+ this.variableNames = new Set([
265
+ eachValueComponent.name
266
+ ]);
267
+ }
268
+ varHandler();
269
+ }
270
+ } else {
271
+ normalHandler(variable);
272
+ }
273
+ };
274
+ switch(variable.type){
275
+ case 'string':
276
+ handleVariable((variable)=>{
277
+ const valueComponents = [];
278
+ this.parseValues(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
279
+ ...bypassVariableNames,
280
+ eachValueComponent.name
281
+ ]);
282
+ currentValue += eachValueComponent.text = this.resolveValue(valueComponents, unit, [
283
+ ...bypassVariableNames,
284
+ eachValueComponent.name
285
+ ], bypassParsing);
286
+ }, ()=>{
287
+ currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
288
+ });
289
+ break;
290
+ case 'number':
291
+ handleVariable((variable)=>{
292
+ if (bypassParsing) {
293
+ currentValue += eachValueComponent.text = String(variable.value);
294
+ } else {
295
+ const valueComponent = this.parseValue(variable.value, unit);
296
+ currentValue += eachValueComponent.text = valueComponent.value + (valueComponent.unit ?? '');
297
+ }
298
+ }, ()=>{
299
+ currentValue += eachValueComponent.text = unit ? `calc(var(--${eachValueComponent.name}) / 16 * 1rem)` : `var(--${eachValueComponent.name})`;
300
+ });
301
+ break;
302
+ case 'color':
303
+ let alpha = eachValueComponent.alpha;
304
+ handleVariable((variable)=>{
305
+ const colorVariable = variable;
306
+ alpha = (alpha || 1) * (colorVariable.alpha || 1);
307
+ if (alpha < 1) {
308
+ currentValue += eachValueComponent.text = `${colorVariable.space}(${colorVariable.value}/${alpha})`;
309
+ } else {
310
+ currentValue += eachValueComponent.text = `${colorVariable.space}(${colorVariable.value})`;
311
+ }
312
+ }, ()=>{
313
+ if (alpha !== undefined) {
314
+ // use color-mix
315
+ currentValue += eachValueComponent.text = `color-mix(in oklab,var(--${eachValueComponent.name}) ${Number(alpha) * 100}%,transparent)`;
316
+ } else {
317
+ currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
318
+ }
319
+ });
320
+ break;
321
+ }
322
+ } else {
323
+ currentValue += eachValueComponent.text = `var(--${eachValueComponent.name}${eachValueComponent.fallback ? ',' + eachValueComponent.fallback : ''})`;
324
+ }
325
+ break;
326
+ case 'separator':
327
+ currentValue += eachValueComponent.text ? eachValueComponent.text : eachValueComponent.text = eachValueComponent.value;
328
+ break;
329
+ case 'number':
330
+ currentValue += eachValueComponent.text = eachValueComponent.value + (eachValueComponent.unit || '');
331
+ break;
332
+ default:
333
+ currentValue += eachValueComponent.text = eachValueComponent.value;
334
+ break;
335
+ }
336
+ }
337
+ return currentValue;
338
+ };
339
+ parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
340
+ const root = parentFunctionName === undefined;
341
+ const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
342
+ const checkIsString = (value)=>value === '\'' || value === '"';
343
+ const isString = checkIsString(endSymbol);
344
+ const separators = [
345
+ ','
346
+ ];
347
+ if (this.definition.separators?.length) {
348
+ separators.push(...this.definition.separators);
349
+ }
350
+ let currentValue = '';
351
+ const parse = ()=>{
352
+ if (currentValue) {
353
+ let handled = false;
354
+ if (!isVarFunction || currentValueComponents.length) {
355
+ const handleVariable = (variableName, alpha)=>{
356
+ const globalVariableValue = this.css.variables.get(variableName);
357
+ const variable = this.variables?.get(variableName) || globalVariableValue;
358
+ if (variable) {
359
+ const name = variable.name ?? variableName;
360
+ if (!bypassVariableNames.includes(name)) {
361
+ handled = true;
362
+ const valueComponent = {
363
+ type: 'variable',
364
+ name,
365
+ variable: this.css.variables.get(name),
366
+ token: currentValue
367
+ };
368
+ if (alpha) valueComponent.alpha = Number(alpha);
369
+ currentValueComponents.push(valueComponent);
370
+ }
371
+ }
372
+ };
373
+ if (/^\$[a-zA-Z0-9-]+(?:\/[^\/]+)?$/.test(currentValue)) {
374
+ const [raw, alpha] = currentValue.slice(1).split('/');
375
+ handleVariable(raw, alpha);
376
+ } else {
377
+ handleVariable(currentValue);
378
+ if (!handled) {
379
+ const [colorName, alpha] = currentValue.split('/');
380
+ handleVariable(colorName, alpha);
381
+ }
382
+ }
383
+ }
384
+ if (!handled) {
385
+ if (!isVarFunction) {
386
+ const result = common.BASE_UNIT_REGEX.exec(currentValue);
387
+ if (result) {
388
+ currentValue = String(+result[1] * (this.css.config.baseUnit ?? 1));
389
+ }
390
+ }
391
+ if (bypassParsing) {
392
+ currentValueComponents.push({
393
+ type: 'string',
394
+ value: currentValue,
395
+ token: currentValue
396
+ });
397
+ } else {
398
+ const parsedValue = this.parseValue(currentValue, unit);
399
+ currentValueComponents.push({
400
+ ...parsedValue,
401
+ token: currentValue
402
+ });
403
+ }
404
+ }
405
+ currentValue = '';
406
+ }
407
+ };
408
+ for(; i < value.length; i++){
409
+ const val = value[i];
410
+ if (val === endSymbol) {
411
+ if (isString) {
412
+ let count = 0;
413
+ for(let j = currentValue.length - 1;; j--){
414
+ if (currentValue[j] !== '\\') break;
415
+ count++;
416
+ }
417
+ if (count % 2) {
418
+ currentValue += val;
419
+ continue;
420
+ } else {
421
+ parse();
422
+ }
423
+ } else {
424
+ parse();
425
+ }
426
+ return i;
427
+ } else if (!isString && val in common.VALUE_DELIMITERS) {
428
+ const functionName = currentValue;
429
+ const newValueComponent = {
430
+ type: 'function',
431
+ name: functionName,
432
+ symbol: val,
433
+ children: [],
434
+ token: ''
435
+ };
436
+ currentValueComponents.push(newValueComponent);
437
+ currentValue = '';
438
+ const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
439
+ i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, common.VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
440
+ } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
441
+ parse();
442
+ currentValueComponents.push({
443
+ type: 'separator',
444
+ value: ' ',
445
+ token: val
446
+ });
447
+ } else {
448
+ if (!isString) {
449
+ if (val === '.') {
450
+ if (isNaN(+value[i + 1])) {
451
+ if (root) break;
452
+ } else if (value[i - 1] === '-') {
453
+ currentValue += '0';
454
+ }
455
+ } else if (separators.includes(val)) {
456
+ parse();
457
+ currentValueComponents.push({
458
+ type: 'separator',
459
+ value: val,
460
+ text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
461
+ token: val
462
+ });
463
+ continue;
464
+ } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
465
+ '!',
466
+ '*',
467
+ '>',
468
+ '+',
469
+ '~',
470
+ ':',
471
+ '[',
472
+ '@',
473
+ '_'
474
+ ].includes(val))) {
475
+ break;
476
+ }
477
+ }
478
+ currentValue += val;
479
+ }
480
+ }
481
+ parse();
482
+ return i;
483
+ };
437
484
  parseValue(token, unit = this.definition.unit) {
438
485
  const parsed = parseValue(token, unit, this.css.config.rootSize);
439
486
  // exclude like `aspect:1/2` from being parsed as 50%
@@ -1,4 +1,5 @@
1
1
  import MasterCSS from './core';
2
+ import SyntaxRuleType from './syntax-rule-type';
2
3
  import { type PropertiesHyphen } from 'csstype';
3
4
  import Layer from './layer';
4
5
  import type { NumberValueComponent, DefinedRule, ValueComponent } from './types/syntax';
@@ -6,7 +7,6 @@ import { AtRuleNode } from './utils/parse-at';
6
7
  import { AtIdentifier } from './types/config';
7
8
  import { SelectorNode } from './utils/parse-selector';
8
9
  import { RulePriority } from './utils/compare-rule-priority';
9
- import { SyntaxRuleTypeValue } from './types/common';
10
10
  export declare class SyntaxRule {
11
11
  readonly name: string;
12
12
  css: MasterCSS;
@@ -15,7 +15,7 @@ export declare class SyntaxRule {
15
15
  native?: CSSRule;
16
16
  readonly atRules?: Partial<Record<AtIdentifier, AtRuleNode[]>>;
17
17
  readonly priority: RulePriority;
18
- readonly type: SyntaxRuleTypeValue;
18
+ readonly type: SyntaxRuleType;
19
19
  readonly declarations?: PropertiesHyphen;
20
20
  readonly layer: Layer;
21
21
  readonly valid: boolean;