@master/css 2.0.0-rc.3 → 2.0.0-rc.30
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.
- package/README.md +4 -43
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.mjs +3 -0
- package/dist/_virtual/css-escape.cjs +5 -0
- package/dist/_virtual/css-escape.mjs +3 -0
- package/dist/bin/index.cjs +11 -0
- package/dist/bin/index.d.ts +0 -1
- package/dist/bin/index.mjs +9 -0
- package/dist/common.cjs +145 -0
- package/dist/common.d.ts +25 -0
- package/dist/common.mjs +124 -0
- package/dist/config/animations.cjs +113 -0
- package/dist/config/animations.mjs +111 -0
- package/dist/config/functions.cjs +351 -0
- package/dist/config/functions.mjs +349 -0
- package/dist/config/index.cjs +36 -0
- package/dist/config/index.d.ts +15 -12
- package/dist/config/index.mjs +26 -0
- package/dist/config/modes.cjs +8 -0
- package/dist/config/modes.d.ts +3 -0
- package/dist/config/modes.mjs +6 -0
- package/dist/config/queries.cjs +17 -0
- package/dist/config/queries.d.ts +22 -0
- package/dist/config/queries.mjs +15 -0
- package/dist/config/rules.cjs +2303 -0
- package/dist/config/rules.d.ts +8 -5
- package/dist/config/rules.mjs +2298 -0
- package/dist/config/selectors.cjs +28 -0
- package/dist/config/selectors.d.ts +0 -1
- package/dist/config/selectors.mjs +26 -0
- package/dist/config/styles.cjs +2 -0
- package/dist/config/styles.mjs +1 -0
- package/dist/config/utilities.cjs +191 -0
- package/dist/config/{semantics.d.ts → utilities.d.ts} +2 -5
- package/dist/config/utilities.mjs +189 -0
- package/dist/config/variables.cjs +116 -0
- package/dist/config/variables.d.ts +132 -177
- package/dist/config/variables.mjs +114 -0
- package/dist/core.cjs +1046 -0
- package/dist/core.d.ts +35 -31
- package/dist/core.mjs +1041 -0
- package/dist/index.cjs +72 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.mjs +22 -0
- package/dist/layer.cjs +28 -0
- package/dist/layer.d.ts +26 -9
- package/dist/layer.mjs +26 -0
- package/dist/polyfills/css-escape.cjs +8 -0
- package/dist/polyfills/css-escape.mjs +2 -0
- package/dist/polyfills/css-escape2.cjs +68 -0
- package/dist/polyfills/css-escape2.mjs +64 -0
- package/dist/rule.cjs +722 -0
- package/dist/rule.d.ts +60 -22
- package/dist/rule.mjs +720 -0
- package/dist/shared/utils/css-escape.cjs +56 -0
- package/dist/shared/utils/css-escape.mjs +54 -0
- package/dist/tokens/screen-sizes.cjs +17 -0
- package/dist/tokens/screen-sizes.mjs +15 -0
- package/dist/types/global.cjs +2 -0
- package/dist/types/global.d.ts +3 -3
- package/dist/types/global.mjs +1 -0
- package/dist/utils/are-rule-modes-equal.cjs +7 -0
- package/dist/utils/are-rule-modes-equal.d.ts +2 -0
- package/dist/utils/are-rule-modes-equal.mjs +5 -0
- package/dist/utils/are-rule-queries-equal.cjs +22 -0
- package/dist/utils/are-rule-queries-equal.d.ts +2 -0
- package/dist/utils/are-rule-queries-equal.mjs +20 -0
- package/dist/utils/are-rule-selectors-equal.cjs +29 -0
- package/dist/utils/are-rule-selectors-equal.d.ts +2 -0
- package/dist/utils/are-rule-selectors-equal.mjs +27 -0
- package/dist/utils/are-rule-states-equal.cjs +11 -0
- package/dist/utils/are-rule-states-equal.d.ts +2 -0
- package/dist/utils/are-rule-states-equal.mjs +9 -0
- package/dist/utils/are-rules-duplicated.cjs +17 -0
- package/dist/utils/are-rules-duplicated.d.ts +2 -0
- package/dist/utils/are-rules-duplicated.mjs +15 -0
- package/dist/utils/extend-config.cjs +72 -0
- package/dist/utils/extend-config.d.ts +1 -1
- package/dist/utils/extend-config.mjs +70 -0
- package/dist/utils/flatten-object.cjs +15 -0
- package/dist/utils/flatten-object.mjs +13 -0
- package/dist/utils/generate-css.cjs +13 -0
- package/dist/utils/generate-css.d.ts +2 -0
- package/dist/utils/generate-css.mjs +11 -0
- package/dist/utils/hex-to-rgb.cjs +30 -0
- package/dist/utils/hex-to-rgb.d.ts +1 -1
- package/dist/utils/hex-to-rgb.mjs +28 -0
- package/dist/utils/is-core-rule.cjs +9 -0
- package/dist/utils/is-core-rule.d.ts +1 -0
- package/dist/utils/is-core-rule.mjs +7 -0
- package/dist/utils/reorder-for-readable-classes.cjs +62 -0
- package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +2 -6
- package/dist/utils/reorder-for-readable-classes.mjs +60 -0
- package/package.json +1 -1
- package/dist/bin/index.bundle.js +0 -36
- package/dist/config/media-queries.d.ts +0 -1
- package/dist/constants/base-unit-regex.d.ts +0 -1
- package/dist/constants/config-esm-text.d.ts +0 -1
- package/dist/constants/config-text.d.ts +0 -1
- package/dist/constants/config-ts-text.d.ts +0 -1
- package/dist/constants/start-symbol.d.ts +0 -6
- package/dist/functions/transform-color-with-opacity.d.ts +0 -1
- package/dist/index.bundle.js +0 -35
- package/dist/index.bundle.mjs +0 -35
- package/dist/utils/concat-arrays.d.ts +0 -1
- package/dist/utils/get-type.d.ts +0 -7
- package/dist/utils/is-plain-object.d.ts +0 -8
- package/dist/utils/is-symbol.d.ts +0 -7
- package/dist/utils/rgb-to-hex.d.ts +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var common = require('../common.cjs');
|
|
4
|
+
|
|
5
|
+
const functions = {
|
|
6
|
+
$: {
|
|
7
|
+
transform (value) {
|
|
8
|
+
let name;
|
|
9
|
+
let fallback;
|
|
10
|
+
const firstCommaIndex = value.indexOf(',');
|
|
11
|
+
if (firstCommaIndex !== -1) {
|
|
12
|
+
name = value.slice(0, firstCommaIndex);
|
|
13
|
+
fallback = value.slice(firstCommaIndex + 1);
|
|
14
|
+
} else {
|
|
15
|
+
name = value;
|
|
16
|
+
}
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
type: 'variable',
|
|
20
|
+
name,
|
|
21
|
+
fallback,
|
|
22
|
+
token: value
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
calc: {
|
|
28
|
+
transform (value, bypassVariableNames) {
|
|
29
|
+
const valueComponents = [];
|
|
30
|
+
let i = 0;
|
|
31
|
+
const anaylzeDeeply = (currentValueComponents, bypassHandlingSeparator, parentBypassParsing, parentUnitChecking, isVarFunction)=>{
|
|
32
|
+
const isChildHandler = valueComponents !== currentValueComponents;
|
|
33
|
+
const unparsedValueComponents = [];
|
|
34
|
+
let bypassParsing = false;
|
|
35
|
+
let hasUnit = false;
|
|
36
|
+
let currentHasUnit = false;
|
|
37
|
+
let unitChecking = false;
|
|
38
|
+
let childHasUnit = undefined;
|
|
39
|
+
let current = '';
|
|
40
|
+
const clear = (separator, prefix = '', suffix = '')=>{
|
|
41
|
+
if (childHasUnit === false && separator !== ' ' && this.definition.unit) {
|
|
42
|
+
childHasUnit = undefined;
|
|
43
|
+
if (!unitChecking) {
|
|
44
|
+
pushUnitValueComponents();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (current) {
|
|
48
|
+
if (!isVarFunction) {
|
|
49
|
+
const result = common.BASE_UNIT_REGEX.exec(current);
|
|
50
|
+
if (result) {
|
|
51
|
+
current = (+result[1] * (this.css.config.baseUnit ?? 1)).toString();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!bypassParsing && !parentBypassParsing) {
|
|
55
|
+
const valueComponent = {
|
|
56
|
+
...this.parseValue(current),
|
|
57
|
+
token: current
|
|
58
|
+
};
|
|
59
|
+
if (!hasUnit && isNaN(+current) && valueComponent.type === 'number') {
|
|
60
|
+
hasUnit = true;
|
|
61
|
+
}
|
|
62
|
+
if (unitChecking) {
|
|
63
|
+
if (isNaN(+current)) {
|
|
64
|
+
if (valueComponent.type === 'number') {
|
|
65
|
+
currentValueComponents.push(valueComponent);
|
|
66
|
+
currentHasUnit = true;
|
|
67
|
+
} else {
|
|
68
|
+
currentValueComponents.push(valueComponent);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
currentValueComponents.push({
|
|
72
|
+
type: 'number',
|
|
73
|
+
value: +current,
|
|
74
|
+
token: current
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
if (isChildHandler) {
|
|
79
|
+
const newValueComponent = {
|
|
80
|
+
type: 'string',
|
|
81
|
+
value: current,
|
|
82
|
+
token: current
|
|
83
|
+
};
|
|
84
|
+
unparsedValueComponents.push(newValueComponent);
|
|
85
|
+
currentValueComponents.push(newValueComponent);
|
|
86
|
+
} else {
|
|
87
|
+
currentValueComponents.push(valueComponent);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
currentValueComponents.push({
|
|
92
|
+
type: 'string',
|
|
93
|
+
value: current,
|
|
94
|
+
token: current
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
current = '';
|
|
98
|
+
}
|
|
99
|
+
if (separator) {
|
|
100
|
+
if (separator === '+' || separator === '-') {
|
|
101
|
+
handleUnitChecking();
|
|
102
|
+
}
|
|
103
|
+
if (prefix && value[i - 1] === ' ') {
|
|
104
|
+
prefix = '';
|
|
105
|
+
}
|
|
106
|
+
if (suffix && value[i + 1] === ' ') {
|
|
107
|
+
suffix = '';
|
|
108
|
+
}
|
|
109
|
+
if (bypassHandlingSeparator) {
|
|
110
|
+
currentValueComponents.push({
|
|
111
|
+
type: 'separator',
|
|
112
|
+
value: separator,
|
|
113
|
+
text: separator,
|
|
114
|
+
token: separator
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
currentValueComponents.push({
|
|
118
|
+
type: 'separator',
|
|
119
|
+
value: separator,
|
|
120
|
+
text: prefix + separator + suffix,
|
|
121
|
+
token: separator
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
bypassParsing = false;
|
|
126
|
+
};
|
|
127
|
+
const pushUnitValueComponents = ()=>{
|
|
128
|
+
if (this.definition.unit === 'rem' || this.definition.unit === 'em') {
|
|
129
|
+
currentValueComponents.push({
|
|
130
|
+
type: 'separator',
|
|
131
|
+
value: '/',
|
|
132
|
+
text: ' / ',
|
|
133
|
+
token: '/'
|
|
134
|
+
}, {
|
|
135
|
+
type: 'number',
|
|
136
|
+
value: this.css.config.rootSize,
|
|
137
|
+
token: String(this.css.config.rootSize)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
currentValueComponents.push({
|
|
141
|
+
type: 'separator',
|
|
142
|
+
value: '*',
|
|
143
|
+
text: ' * ',
|
|
144
|
+
token: '*'
|
|
145
|
+
}, {
|
|
146
|
+
type: 'number',
|
|
147
|
+
value: 1,
|
|
148
|
+
unit: this.definition.unit,
|
|
149
|
+
token: this.definition.unit
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const handleUnitChecking = ()=>{
|
|
153
|
+
if (unitChecking && !currentHasUnit && !parentUnitChecking && (!isChildHandler || hasUnit)) {
|
|
154
|
+
pushUnitValueComponents();
|
|
155
|
+
}
|
|
156
|
+
unitChecking = false;
|
|
157
|
+
currentHasUnit = false;
|
|
158
|
+
};
|
|
159
|
+
for(; i < value.length; i++){
|
|
160
|
+
const char = value[i];
|
|
161
|
+
if (char === '(') {
|
|
162
|
+
const symbolResult = /^([+-])/.exec(current);
|
|
163
|
+
if (symbolResult) {
|
|
164
|
+
currentValueComponents.push({
|
|
165
|
+
type: 'string',
|
|
166
|
+
value: symbolResult[1],
|
|
167
|
+
token: symbolResult[1]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const functionName = symbolResult ? current.slice(1) : current;
|
|
171
|
+
const newValueComponent = {
|
|
172
|
+
type: 'function',
|
|
173
|
+
name: functionName,
|
|
174
|
+
symbol: char,
|
|
175
|
+
children: [],
|
|
176
|
+
bypassTransform: functionName === 'calc',
|
|
177
|
+
token: current
|
|
178
|
+
};
|
|
179
|
+
currentValueComponents.push(newValueComponent);
|
|
180
|
+
current = '';
|
|
181
|
+
i++;
|
|
182
|
+
const isVarFunction = functionName === '$' || functionName === 'var';
|
|
183
|
+
childHasUnit = anaylzeDeeply(newValueComponent.children, functionName !== '' && functionName !== 'calc' && (isVarFunction || Object.prototype.hasOwnProperty.call(functions, functionName)), bypassParsing || isVarFunction || unitChecking && currentHasUnit, unitChecking, isVarFunction) || functionName === 'var';
|
|
184
|
+
if (!childHasUnit && functionName === '$') {
|
|
185
|
+
const variableType = this.css.variables[newValueComponent.children[0].value]?.type;
|
|
186
|
+
childHasUnit = !variableType || variableType === 'string';
|
|
187
|
+
}
|
|
188
|
+
if (childHasUnit) {
|
|
189
|
+
hasUnit = true;
|
|
190
|
+
currentHasUnit = true;
|
|
191
|
+
}
|
|
192
|
+
} else if (char === ')') {
|
|
193
|
+
clear('');
|
|
194
|
+
if (hasUnit) {
|
|
195
|
+
for (const eachUnparsedValueComponent of unparsedValueComponents){
|
|
196
|
+
Object.assign(eachUnparsedValueComponent, this.parseValue(eachUnparsedValueComponent.value));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return hasUnit;
|
|
200
|
+
} else if (char === ',') {
|
|
201
|
+
clear(char, '', ' ');
|
|
202
|
+
} else if (char === ' ') {
|
|
203
|
+
clear(char);
|
|
204
|
+
} else {
|
|
205
|
+
const previousChar = value[i - 1];
|
|
206
|
+
switch(char){
|
|
207
|
+
case '+':
|
|
208
|
+
if (!current && previousChar !== ')') {
|
|
209
|
+
current += char;
|
|
210
|
+
} else {
|
|
211
|
+
clear(char, ' ', ' ');
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
case '-':
|
|
215
|
+
if (!current && previousChar !== ')') {
|
|
216
|
+
current += char;
|
|
217
|
+
} else {
|
|
218
|
+
clear(char, ' ', ' ');
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case '*':
|
|
222
|
+
if (this.definition.unit) {
|
|
223
|
+
unitChecking = true;
|
|
224
|
+
}
|
|
225
|
+
clear(char, ' ', ' ');
|
|
226
|
+
break;
|
|
227
|
+
case '/':
|
|
228
|
+
if (this.definition.unit) {
|
|
229
|
+
unitChecking = true;
|
|
230
|
+
}
|
|
231
|
+
clear(char, ' ', ' ');
|
|
232
|
+
bypassParsing = true;
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
current += char;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
clear('');
|
|
241
|
+
handleUnitChecking();
|
|
242
|
+
};
|
|
243
|
+
anaylzeDeeply(valueComponents, false, false, false, false);
|
|
244
|
+
return 'calc(' + this.resolveValue(valueComponents, functions.calc.unit ?? this.definition.unit, bypassVariableNames, true) + ')';
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
translate: {
|
|
248
|
+
unit: 'rem'
|
|
249
|
+
},
|
|
250
|
+
translateX: {
|
|
251
|
+
unit: 'rem'
|
|
252
|
+
},
|
|
253
|
+
translateY: {
|
|
254
|
+
unit: 'rem'
|
|
255
|
+
},
|
|
256
|
+
translateZ: {
|
|
257
|
+
unit: 'rem'
|
|
258
|
+
},
|
|
259
|
+
translate3d: {
|
|
260
|
+
unit: 'rem'
|
|
261
|
+
},
|
|
262
|
+
skew: {
|
|
263
|
+
unit: 'deg'
|
|
264
|
+
},
|
|
265
|
+
skewX: {
|
|
266
|
+
unit: 'deg'
|
|
267
|
+
},
|
|
268
|
+
skewY: {
|
|
269
|
+
unit: 'deg'
|
|
270
|
+
},
|
|
271
|
+
skewZ: {
|
|
272
|
+
unit: 'deg'
|
|
273
|
+
},
|
|
274
|
+
skew3d: {
|
|
275
|
+
unit: 'deg'
|
|
276
|
+
},
|
|
277
|
+
rotate: {
|
|
278
|
+
unit: 'deg'
|
|
279
|
+
},
|
|
280
|
+
rotateX: {
|
|
281
|
+
unit: 'deg'
|
|
282
|
+
},
|
|
283
|
+
rotateY: {
|
|
284
|
+
unit: 'deg'
|
|
285
|
+
},
|
|
286
|
+
rotateZ: {
|
|
287
|
+
unit: 'deg'
|
|
288
|
+
},
|
|
289
|
+
rotate3d: {
|
|
290
|
+
unit: 'deg'
|
|
291
|
+
},
|
|
292
|
+
blur: {
|
|
293
|
+
unit: 'rem'
|
|
294
|
+
},
|
|
295
|
+
'drop-shadow': {
|
|
296
|
+
unit: 'rem'
|
|
297
|
+
},
|
|
298
|
+
'hue-rotate': {
|
|
299
|
+
unit: 'deg'
|
|
300
|
+
},
|
|
301
|
+
rgb: {
|
|
302
|
+
unit: ''
|
|
303
|
+
},
|
|
304
|
+
rgba: {
|
|
305
|
+
unit: ''
|
|
306
|
+
},
|
|
307
|
+
hsl: {
|
|
308
|
+
unit: ''
|
|
309
|
+
},
|
|
310
|
+
hsla: {
|
|
311
|
+
unit: ''
|
|
312
|
+
},
|
|
313
|
+
color: {
|
|
314
|
+
unit: ''
|
|
315
|
+
},
|
|
316
|
+
'color-contrast': {
|
|
317
|
+
unit: ''
|
|
318
|
+
},
|
|
319
|
+
'color-mix': {
|
|
320
|
+
unit: ''
|
|
321
|
+
},
|
|
322
|
+
hwb: {
|
|
323
|
+
unit: ''
|
|
324
|
+
},
|
|
325
|
+
lab: {
|
|
326
|
+
unit: ''
|
|
327
|
+
},
|
|
328
|
+
lch: {
|
|
329
|
+
unit: ''
|
|
330
|
+
},
|
|
331
|
+
oklab: {
|
|
332
|
+
unit: ''
|
|
333
|
+
},
|
|
334
|
+
oklch: {
|
|
335
|
+
unit: ''
|
|
336
|
+
},
|
|
337
|
+
clamp: {
|
|
338
|
+
unit: ''
|
|
339
|
+
},
|
|
340
|
+
repeat: {
|
|
341
|
+
unit: ''
|
|
342
|
+
},
|
|
343
|
+
'linear-gradient': {},
|
|
344
|
+
'radial-gradient': {},
|
|
345
|
+
'conic-gradient': {},
|
|
346
|
+
'repeating-linear-gradient': {},
|
|
347
|
+
'repeating-radial-gradient': {},
|
|
348
|
+
'repeating-conic-gradient': {}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
module.exports = functions;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { BASE_UNIT_REGEX } from '../common.mjs';
|
|
2
|
+
|
|
3
|
+
const functions = {
|
|
4
|
+
$: {
|
|
5
|
+
transform (value) {
|
|
6
|
+
let name;
|
|
7
|
+
let fallback;
|
|
8
|
+
const firstCommaIndex = value.indexOf(',');
|
|
9
|
+
if (firstCommaIndex !== -1) {
|
|
10
|
+
name = value.slice(0, firstCommaIndex);
|
|
11
|
+
fallback = value.slice(firstCommaIndex + 1);
|
|
12
|
+
} else {
|
|
13
|
+
name = value;
|
|
14
|
+
}
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
type: 'variable',
|
|
18
|
+
name,
|
|
19
|
+
fallback,
|
|
20
|
+
token: value
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
calc: {
|
|
26
|
+
transform (value, bypassVariableNames) {
|
|
27
|
+
const valueComponents = [];
|
|
28
|
+
let i = 0;
|
|
29
|
+
const anaylzeDeeply = (currentValueComponents, bypassHandlingSeparator, parentBypassParsing, parentUnitChecking, isVarFunction)=>{
|
|
30
|
+
const isChildHandler = valueComponents !== currentValueComponents;
|
|
31
|
+
const unparsedValueComponents = [];
|
|
32
|
+
let bypassParsing = false;
|
|
33
|
+
let hasUnit = false;
|
|
34
|
+
let currentHasUnit = false;
|
|
35
|
+
let unitChecking = false;
|
|
36
|
+
let childHasUnit = undefined;
|
|
37
|
+
let current = '';
|
|
38
|
+
const clear = (separator, prefix = '', suffix = '')=>{
|
|
39
|
+
if (childHasUnit === false && separator !== ' ' && this.definition.unit) {
|
|
40
|
+
childHasUnit = undefined;
|
|
41
|
+
if (!unitChecking) {
|
|
42
|
+
pushUnitValueComponents();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (current) {
|
|
46
|
+
if (!isVarFunction) {
|
|
47
|
+
const result = BASE_UNIT_REGEX.exec(current);
|
|
48
|
+
if (result) {
|
|
49
|
+
current = (+result[1] * (this.css.config.baseUnit ?? 1)).toString();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!bypassParsing && !parentBypassParsing) {
|
|
53
|
+
const valueComponent = {
|
|
54
|
+
...this.parseValue(current),
|
|
55
|
+
token: current
|
|
56
|
+
};
|
|
57
|
+
if (!hasUnit && isNaN(+current) && valueComponent.type === 'number') {
|
|
58
|
+
hasUnit = true;
|
|
59
|
+
}
|
|
60
|
+
if (unitChecking) {
|
|
61
|
+
if (isNaN(+current)) {
|
|
62
|
+
if (valueComponent.type === 'number') {
|
|
63
|
+
currentValueComponents.push(valueComponent);
|
|
64
|
+
currentHasUnit = true;
|
|
65
|
+
} else {
|
|
66
|
+
currentValueComponents.push(valueComponent);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
currentValueComponents.push({
|
|
70
|
+
type: 'number',
|
|
71
|
+
value: +current,
|
|
72
|
+
token: current
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
if (isChildHandler) {
|
|
77
|
+
const newValueComponent = {
|
|
78
|
+
type: 'string',
|
|
79
|
+
value: current,
|
|
80
|
+
token: current
|
|
81
|
+
};
|
|
82
|
+
unparsedValueComponents.push(newValueComponent);
|
|
83
|
+
currentValueComponents.push(newValueComponent);
|
|
84
|
+
} else {
|
|
85
|
+
currentValueComponents.push(valueComponent);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
currentValueComponents.push({
|
|
90
|
+
type: 'string',
|
|
91
|
+
value: current,
|
|
92
|
+
token: current
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
current = '';
|
|
96
|
+
}
|
|
97
|
+
if (separator) {
|
|
98
|
+
if (separator === '+' || separator === '-') {
|
|
99
|
+
handleUnitChecking();
|
|
100
|
+
}
|
|
101
|
+
if (prefix && value[i - 1] === ' ') {
|
|
102
|
+
prefix = '';
|
|
103
|
+
}
|
|
104
|
+
if (suffix && value[i + 1] === ' ') {
|
|
105
|
+
suffix = '';
|
|
106
|
+
}
|
|
107
|
+
if (bypassHandlingSeparator) {
|
|
108
|
+
currentValueComponents.push({
|
|
109
|
+
type: 'separator',
|
|
110
|
+
value: separator,
|
|
111
|
+
text: separator,
|
|
112
|
+
token: separator
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
currentValueComponents.push({
|
|
116
|
+
type: 'separator',
|
|
117
|
+
value: separator,
|
|
118
|
+
text: prefix + separator + suffix,
|
|
119
|
+
token: separator
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
bypassParsing = false;
|
|
124
|
+
};
|
|
125
|
+
const pushUnitValueComponents = ()=>{
|
|
126
|
+
if (this.definition.unit === 'rem' || this.definition.unit === 'em') {
|
|
127
|
+
currentValueComponents.push({
|
|
128
|
+
type: 'separator',
|
|
129
|
+
value: '/',
|
|
130
|
+
text: ' / ',
|
|
131
|
+
token: '/'
|
|
132
|
+
}, {
|
|
133
|
+
type: 'number',
|
|
134
|
+
value: this.css.config.rootSize,
|
|
135
|
+
token: String(this.css.config.rootSize)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
currentValueComponents.push({
|
|
139
|
+
type: 'separator',
|
|
140
|
+
value: '*',
|
|
141
|
+
text: ' * ',
|
|
142
|
+
token: '*'
|
|
143
|
+
}, {
|
|
144
|
+
type: 'number',
|
|
145
|
+
value: 1,
|
|
146
|
+
unit: this.definition.unit,
|
|
147
|
+
token: this.definition.unit
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const handleUnitChecking = ()=>{
|
|
151
|
+
if (unitChecking && !currentHasUnit && !parentUnitChecking && (!isChildHandler || hasUnit)) {
|
|
152
|
+
pushUnitValueComponents();
|
|
153
|
+
}
|
|
154
|
+
unitChecking = false;
|
|
155
|
+
currentHasUnit = false;
|
|
156
|
+
};
|
|
157
|
+
for(; i < value.length; i++){
|
|
158
|
+
const char = value[i];
|
|
159
|
+
if (char === '(') {
|
|
160
|
+
const symbolResult = /^([+-])/.exec(current);
|
|
161
|
+
if (symbolResult) {
|
|
162
|
+
currentValueComponents.push({
|
|
163
|
+
type: 'string',
|
|
164
|
+
value: symbolResult[1],
|
|
165
|
+
token: symbolResult[1]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const functionName = symbolResult ? current.slice(1) : current;
|
|
169
|
+
const newValueComponent = {
|
|
170
|
+
type: 'function',
|
|
171
|
+
name: functionName,
|
|
172
|
+
symbol: char,
|
|
173
|
+
children: [],
|
|
174
|
+
bypassTransform: functionName === 'calc',
|
|
175
|
+
token: current
|
|
176
|
+
};
|
|
177
|
+
currentValueComponents.push(newValueComponent);
|
|
178
|
+
current = '';
|
|
179
|
+
i++;
|
|
180
|
+
const isVarFunction = functionName === '$' || functionName === 'var';
|
|
181
|
+
childHasUnit = anaylzeDeeply(newValueComponent.children, functionName !== '' && functionName !== 'calc' && (isVarFunction || Object.prototype.hasOwnProperty.call(functions, functionName)), bypassParsing || isVarFunction || unitChecking && currentHasUnit, unitChecking, isVarFunction) || functionName === 'var';
|
|
182
|
+
if (!childHasUnit && functionName === '$') {
|
|
183
|
+
const variableType = this.css.variables[newValueComponent.children[0].value]?.type;
|
|
184
|
+
childHasUnit = !variableType || variableType === 'string';
|
|
185
|
+
}
|
|
186
|
+
if (childHasUnit) {
|
|
187
|
+
hasUnit = true;
|
|
188
|
+
currentHasUnit = true;
|
|
189
|
+
}
|
|
190
|
+
} else if (char === ')') {
|
|
191
|
+
clear('');
|
|
192
|
+
if (hasUnit) {
|
|
193
|
+
for (const eachUnparsedValueComponent of unparsedValueComponents){
|
|
194
|
+
Object.assign(eachUnparsedValueComponent, this.parseValue(eachUnparsedValueComponent.value));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return hasUnit;
|
|
198
|
+
} else if (char === ',') {
|
|
199
|
+
clear(char, '', ' ');
|
|
200
|
+
} else if (char === ' ') {
|
|
201
|
+
clear(char);
|
|
202
|
+
} else {
|
|
203
|
+
const previousChar = value[i - 1];
|
|
204
|
+
switch(char){
|
|
205
|
+
case '+':
|
|
206
|
+
if (!current && previousChar !== ')') {
|
|
207
|
+
current += char;
|
|
208
|
+
} else {
|
|
209
|
+
clear(char, ' ', ' ');
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case '-':
|
|
213
|
+
if (!current && previousChar !== ')') {
|
|
214
|
+
current += char;
|
|
215
|
+
} else {
|
|
216
|
+
clear(char, ' ', ' ');
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
case '*':
|
|
220
|
+
if (this.definition.unit) {
|
|
221
|
+
unitChecking = true;
|
|
222
|
+
}
|
|
223
|
+
clear(char, ' ', ' ');
|
|
224
|
+
break;
|
|
225
|
+
case '/':
|
|
226
|
+
if (this.definition.unit) {
|
|
227
|
+
unitChecking = true;
|
|
228
|
+
}
|
|
229
|
+
clear(char, ' ', ' ');
|
|
230
|
+
bypassParsing = true;
|
|
231
|
+
break;
|
|
232
|
+
default:
|
|
233
|
+
current += char;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
clear('');
|
|
239
|
+
handleUnitChecking();
|
|
240
|
+
};
|
|
241
|
+
anaylzeDeeply(valueComponents, false, false, false, false);
|
|
242
|
+
return 'calc(' + this.resolveValue(valueComponents, functions.calc.unit ?? this.definition.unit, bypassVariableNames, true) + ')';
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
translate: {
|
|
246
|
+
unit: 'rem'
|
|
247
|
+
},
|
|
248
|
+
translateX: {
|
|
249
|
+
unit: 'rem'
|
|
250
|
+
},
|
|
251
|
+
translateY: {
|
|
252
|
+
unit: 'rem'
|
|
253
|
+
},
|
|
254
|
+
translateZ: {
|
|
255
|
+
unit: 'rem'
|
|
256
|
+
},
|
|
257
|
+
translate3d: {
|
|
258
|
+
unit: 'rem'
|
|
259
|
+
},
|
|
260
|
+
skew: {
|
|
261
|
+
unit: 'deg'
|
|
262
|
+
},
|
|
263
|
+
skewX: {
|
|
264
|
+
unit: 'deg'
|
|
265
|
+
},
|
|
266
|
+
skewY: {
|
|
267
|
+
unit: 'deg'
|
|
268
|
+
},
|
|
269
|
+
skewZ: {
|
|
270
|
+
unit: 'deg'
|
|
271
|
+
},
|
|
272
|
+
skew3d: {
|
|
273
|
+
unit: 'deg'
|
|
274
|
+
},
|
|
275
|
+
rotate: {
|
|
276
|
+
unit: 'deg'
|
|
277
|
+
},
|
|
278
|
+
rotateX: {
|
|
279
|
+
unit: 'deg'
|
|
280
|
+
},
|
|
281
|
+
rotateY: {
|
|
282
|
+
unit: 'deg'
|
|
283
|
+
},
|
|
284
|
+
rotateZ: {
|
|
285
|
+
unit: 'deg'
|
|
286
|
+
},
|
|
287
|
+
rotate3d: {
|
|
288
|
+
unit: 'deg'
|
|
289
|
+
},
|
|
290
|
+
blur: {
|
|
291
|
+
unit: 'rem'
|
|
292
|
+
},
|
|
293
|
+
'drop-shadow': {
|
|
294
|
+
unit: 'rem'
|
|
295
|
+
},
|
|
296
|
+
'hue-rotate': {
|
|
297
|
+
unit: 'deg'
|
|
298
|
+
},
|
|
299
|
+
rgb: {
|
|
300
|
+
unit: ''
|
|
301
|
+
},
|
|
302
|
+
rgba: {
|
|
303
|
+
unit: ''
|
|
304
|
+
},
|
|
305
|
+
hsl: {
|
|
306
|
+
unit: ''
|
|
307
|
+
},
|
|
308
|
+
hsla: {
|
|
309
|
+
unit: ''
|
|
310
|
+
},
|
|
311
|
+
color: {
|
|
312
|
+
unit: ''
|
|
313
|
+
},
|
|
314
|
+
'color-contrast': {
|
|
315
|
+
unit: ''
|
|
316
|
+
},
|
|
317
|
+
'color-mix': {
|
|
318
|
+
unit: ''
|
|
319
|
+
},
|
|
320
|
+
hwb: {
|
|
321
|
+
unit: ''
|
|
322
|
+
},
|
|
323
|
+
lab: {
|
|
324
|
+
unit: ''
|
|
325
|
+
},
|
|
326
|
+
lch: {
|
|
327
|
+
unit: ''
|
|
328
|
+
},
|
|
329
|
+
oklab: {
|
|
330
|
+
unit: ''
|
|
331
|
+
},
|
|
332
|
+
oklch: {
|
|
333
|
+
unit: ''
|
|
334
|
+
},
|
|
335
|
+
clamp: {
|
|
336
|
+
unit: ''
|
|
337
|
+
},
|
|
338
|
+
repeat: {
|
|
339
|
+
unit: ''
|
|
340
|
+
},
|
|
341
|
+
'linear-gradient': {},
|
|
342
|
+
'radial-gradient': {},
|
|
343
|
+
'conic-gradient': {},
|
|
344
|
+
'repeating-linear-gradient': {},
|
|
345
|
+
'repeating-radial-gradient': {},
|
|
346
|
+
'repeating-conic-gradient': {}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export { functions as default };
|