@master/css 2.0.0-rc.67 → 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 (109) 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 +242 -260
  22. package/dist/core.d.ts +5 -3
  23. package/dist/core.mjs +242 -260
  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 -253
  61. package/dist/syntax-rule.d.ts +2 -2
  62. package/dist/syntax-rule.mjs +306 -254
  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/generate-selector.cjs +2 -1
  87. package/dist/utils/generate-selector.mjs +2 -1
  88. package/dist/utils/minify-extended-config.cjs +64 -0
  89. package/dist/utils/minify-extended-config.d.ts +9 -0
  90. package/dist/utils/minify-extended-config.mjs +62 -0
  91. package/dist/utils/nest-meta-object.cjs +25 -0
  92. package/dist/utils/nest-meta-object.d.ts +7 -0
  93. package/dist/utils/nest-meta-object.mjs +23 -0
  94. package/dist/utils/parse-at.cjs +1 -2
  95. package/dist/utils/parse-at.d.ts +2 -2
  96. package/dist/utils/parse-at.mjs +1 -2
  97. package/dist/utils/parse-pair.cjs +3 -6
  98. package/dist/utils/parse-pair.mjs +3 -6
  99. package/dist/utils/parse-selector.cjs +6 -6
  100. package/dist/utils/parse-selector.d.ts +3 -3
  101. package/dist/utils/parse-selector.mjs +6 -6
  102. package/dist/utils/sort-readable-classes.cjs +2 -2
  103. package/dist/utils/sort-readable-classes.d.ts +1 -2
  104. package/dist/utils/sort-readable-classes.mjs +2 -2
  105. package/dist/variable-rule.cjs +35 -29
  106. package/dist/variable-rule.d.ts +16 -6
  107. package/dist/variable-rule.mjs +35 -29
  108. package/package.json +1 -1
  109. 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,258 +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
- handleVariable(currentValue);
162
- if (!handled) {
163
- const [colorName, alpha] = currentValue.split('/');
164
- handleVariable(colorName, alpha);
165
- }
166
- }
167
- if (!handled) {
168
- if (!isVarFunction) {
169
- const result = common.BASE_UNIT_REGEX.exec(currentValue);
170
- if (result) {
171
- currentValue = String(+result[1] * (this.css.config.baseUnit ?? 1));
172
- }
173
- }
174
- if (bypassParsing) {
175
- currentValueComponents.push({
176
- type: 'string',
177
- value: currentValue,
178
- token: currentValue
179
- });
180
- } else {
181
- const parsedValue = this.parseValue(currentValue, unit);
182
- currentValueComponents.push({
183
- ...parsedValue,
184
- token: currentValue
185
- });
186
- }
187
- }
188
- currentValue = '';
189
- }
190
- };
191
- for(; i < value.length; i++){
192
- const val = value[i];
193
- if (val === endSymbol) {
194
- if (isString) {
195
- let count = 0;
196
- for(let j = currentValue.length - 1;; j--){
197
- if (currentValue[j] !== '\\') break;
198
- count++;
199
- }
200
- if (count % 2) {
201
- currentValue += val;
202
- continue;
203
- } else {
204
- parse();
205
- }
206
- } else {
207
- parse();
208
- }
209
- return i;
210
- } else if (!isString && val in common.VALUE_DELIMITERS) {
211
- const functionName = currentValue;
212
- const newValueComponent = {
213
- type: 'function',
214
- name: functionName,
215
- symbol: val,
216
- children: [],
217
- token: ''
218
- };
219
- currentValueComponents.push(newValueComponent);
220
- currentValue = '';
221
- const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
222
- i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, common.VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
223
- } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
224
- parse();
225
- currentValueComponents.push({
226
- type: 'separator',
227
- value: ' ',
228
- token: val
229
- });
230
- } else {
231
- if (!isString) {
232
- if (val === '.') {
233
- if (isNaN(+value[i + 1])) {
234
- if (root) break;
235
- } else if (value[i - 1] === '-') {
236
- currentValue += '0';
237
- }
238
- } else if (separators.includes(val)) {
239
- parse();
240
- currentValueComponents.push({
241
- type: 'separator',
242
- value: val,
243
- text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
244
- token: val
245
- });
246
- continue;
247
- } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
248
- '!',
249
- '*',
250
- '>',
251
- '+',
252
- '~',
253
- ':',
254
- '[',
255
- '@',
256
- '_'
257
- ].includes(val))) {
258
- break;
259
- }
260
- }
261
- currentValue += val;
262
- }
263
- }
264
- parse();
265
- return i;
266
- };
267
35
  this.mode = mode;
268
36
  this.layer = css.generalLayer;
269
37
  Object.assign(this, registeredSyntax);
270
38
  const { id, definition } = registeredSyntax;
271
- const { analyze, transformValue, declare, transformValueComponents, create, type, unit } = definition;
39
+ const { declarer, transformer, type, unit, sign } = definition;
272
40
  this.type = type;
273
- if (create) create.call(this, name);
274
41
  // 1. value / selectorToken
275
- this.declarations = definition.declarations;
276
42
  let stateToken;
277
43
  if (this.type === syntaxRuleType.Utility) {
278
- // TODO: id 使用其他方式傳遞
279
44
  stateToken = name.slice(id.length - 1);
280
45
  } else {
281
46
  let valueToken;
282
- if (analyze) {
283
- [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;
284
53
  } else {
285
54
  const indexOfColon = name.indexOf(':');
286
55
  this.keyToken = name.slice(0, indexOfColon + 1);
@@ -322,7 +91,7 @@ class SyntaxRule {
322
91
  };
323
92
  }
324
93
  }
325
- if (this.mode && css.config.modes?.[this.mode] === 'media') {
94
+ if (this.mode && css.config.modeTrigger === 'media') {
326
95
  const atComp = {
327
96
  name: 'prefers-color-scheme',
328
97
  value: this.mode
@@ -354,20 +123,46 @@ class SyntaxRule {
354
123
  // 7. value
355
124
  let newValue;
356
125
  if (this.valueComponents) {
357
- if (transformValueComponents) {
358
- 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
+ }
359
135
  }
360
136
  newValue = this.resolveValue(this.valueComponents, unit, [], false);
361
- if (transformValue) {
362
- newValue = transformValue.call(this, newValue);
363
- }
364
- if (declare) {
365
- 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
+ }
366
159
  } else if (id) {
367
160
  this.declarations = {
368
161
  [id]: newValue
369
162
  };
370
163
  }
164
+ } else {
165
+ this.declarations = definition.declarations;
371
166
  }
372
167
  if (!Object.entries(this.declarations ?? {}).length) {
373
168
  this.valid = false;
@@ -427,8 +222,265 @@ class SyntaxRule {
427
222
  const body = pre + '.' + cssEscape(this.fixedClass ?? this.name);
428
223
  return this.selectorNodes ? generateSelector(this.selectorNodes, body) : body;
429
224
  }
430
- resolveValue;
431
- 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
+ };
432
484
  parseValue(token, unit = this.definition.unit) {
433
485
  const parsed = parseValue(token, unit, this.css.config.rootSize);
434
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;