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