@tbela99/css-parser 2.1.0 → 2.3.0
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/CHANGELOG.md +66 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
- package/dist/{src/lib/ast → ast}/arena.js +304 -139
- package/dist/{src/lib/ast → ast}/cache.js +40 -24
- package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
- package/dist/{src/lib/ast → ast}/features/if.js +6 -6
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{src/lib/ast → ast}/features/index.js +3 -2
- package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
- package/dist/ast/features/mixin.js +953 -0
- package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
- package/dist/ast/features/shorthand.js +129 -0
- package/dist/ast/features/transform.js +188 -0
- package/dist/{src/lib/ast → ast}/features/type.js +2 -2
- package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
- package/dist/{src/lib/ast → ast}/math/math.js +2 -2
- package/dist/{src/lib/ast → ast}/minify.js +745 -201
- package/dist/ast/mixins/custom-function.js +393 -0
- package/dist/ast/mixins/utils.js +53 -0
- package/dist/ast/mixins/variables.js +678 -0
- package/dist/ast/strings.js +910 -0
- package/dist/ast/transform/compute.js +560 -0
- package/dist/ast/transform/matrix.js +67 -0
- package/dist/ast/transform/minify.js +325 -0
- package/dist/ast/transform/perspective.js +24 -0
- package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
- package/dist/ast/transform/scale.js +43 -0
- package/dist/ast/transform/skew.js +38 -0
- package/dist/ast/transform/translate.js +56 -0
- package/dist/ast/transform/utils.js +390 -0
- package/dist/{src/lib/ast → ast}/types.js +2 -2
- package/dist/{src/lib/ast → ast}/walk.js +2 -2
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +30 -21
- package/dist/{src/lib/fs → fs}/resolve.js +2 -2
- package/dist/index-umd-web.js +19727 -10719
- package/dist/index.d.ts +738 -100
- package/dist/{src/node.js → node.js} +70 -52
- package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
- package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
- package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
- package/dist/{src/lib/parser → parser}/input.js +18 -3
- package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
- package/dist/{src/lib/parser → parser}/parse.js +444 -278
- package/dist/{src/lib/parser → parser}/source.js +3 -3
- package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
- package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
- package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
- package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
- package/dist/parser/utils/cache.js +53 -0
- package/dist/parser/utils/canonical.js +78 -0
- package/dist/parser/utils/codes.js +93 -0
- package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
- package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
- package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
- package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
- package/dist/{src/lib/printer → printer}/render.js +582 -153
- package/dist/printer/result.js +148 -0
- package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
- package/dist/printer/writer.js +252 -0
- package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
- package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
- package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
- package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +12 -7
- package/dist/validation/compiled/builtins.js +32 -0
- package/dist/validation/compiled/runtime.js +705 -0
- package/dist/validation/compiled/syntaxes.js +1620 -0
- package/dist/{src/lib/validation → validation}/config.js +63 -16
- package/dist/validation/first.js +574 -0
- package/dist/{src/lib/validation → validation}/match.js +376 -161
- package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
- package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
- package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +68 -55
- package/package.json +15 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -95
- package/dist/src/lib/ast/features/transform.js +0 -90
- package/dist/src/lib/ast/transform/compute.js +0 -362
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -105,6 +105,8 @@ class StructuralMemo {
|
|
|
105
105
|
* end of the key being looked up in the pool
|
|
106
106
|
*/
|
|
107
107
|
used = 0;
|
|
108
|
+
// hash of the key being serialized, see serialize() and lookup()
|
|
109
|
+
hash = 0x811c9dc5;
|
|
108
110
|
/**
|
|
109
111
|
* @param numericEquality compare the numeric values with `==` semantics (`0` and `-0` are equal) and consider
|
|
110
112
|
* all the `NaN` values equal. the raw bits are compared otherwise
|
|
@@ -130,6 +132,7 @@ class StructuralMemo {
|
|
|
130
132
|
this.growPool(used + 1);
|
|
131
133
|
}
|
|
132
134
|
this.pool[used++] = prefix;
|
|
135
|
+
this.hash = Math.imul(0x811c9dc5 ^ prefix, 0x01000193);
|
|
133
136
|
for (let token = first; token !== 0; token = arena.nextSibling[token]) {
|
|
134
137
|
used = this.serialize(arena, token, used);
|
|
135
138
|
}
|
|
@@ -142,6 +145,7 @@ class StructuralMemo {
|
|
|
142
145
|
* @param token
|
|
143
146
|
*/
|
|
144
147
|
token(arena, token) {
|
|
148
|
+
this.hash = 0x811c9dc5;
|
|
145
149
|
this.used = this.serialize(arena, token, this.poolSize);
|
|
146
150
|
return this.lookup();
|
|
147
151
|
}
|
|
@@ -188,50 +192,63 @@ class StructuralMemo {
|
|
|
188
192
|
const firstToken = arena.firstToken[token];
|
|
189
193
|
const firstChild = arena.firstChild[token];
|
|
190
194
|
let value = arena.numericValue[token];
|
|
191
|
-
// type and color type are 8 bits values
|
|
195
|
+
// type and color type are 8 bits values. the header is computed before its fields are written: the key is
|
|
196
|
+
// hashed while it is written, in order (see lookup())
|
|
192
197
|
let header = arena.dataTypes[token] | (arena.colorType[token] << 8);
|
|
193
|
-
|
|
198
|
+
let hash = this.hash;
|
|
194
199
|
if (name !== 0) {
|
|
195
200
|
header |= 65536 /* Field.Name */;
|
|
196
|
-
buffer[used++] = name;
|
|
197
201
|
}
|
|
198
202
|
if (str !== 0) {
|
|
199
203
|
header |= 131072 /* Field.String */;
|
|
200
|
-
buffer[used++] = str;
|
|
201
204
|
}
|
|
202
205
|
if (unit !== 0) {
|
|
203
206
|
header |= 262144 /* Field.Unit */;
|
|
204
|
-
buffer[used++] = unit;
|
|
205
207
|
}
|
|
206
208
|
if (this.numericEquality) {
|
|
207
209
|
value = normalize(value);
|
|
208
210
|
}
|
|
209
211
|
// 0 is not serialized. -0 is not an integer: its raw bits are serialized
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
header |= 524288 /* Field.Integer */;
|
|
213
|
-
buffer[used++] = value;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
header |= 1048576 /* Field.Number */;
|
|
217
|
-
f64[0] = value;
|
|
218
|
-
buffer[used++] = bits[0];
|
|
219
|
-
buffer[used++] = bits[1];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
212
|
+
const numeric = value !== 0 || 1 / value < 0 ? ((value | 0) === value && value !== 0 ? 524288 /* Field.Integer */ : 1048576 /* Field.Number */) : 0;
|
|
213
|
+
header |= numeric;
|
|
222
214
|
if (firstToken !== 0) {
|
|
223
215
|
header |= 2097152 /* Field.Tokens */;
|
|
224
216
|
}
|
|
225
217
|
if (firstChild !== 0) {
|
|
226
218
|
header |= 4194304 /* Field.Children */;
|
|
227
219
|
}
|
|
228
|
-
buffer[
|
|
220
|
+
buffer[used++] = header;
|
|
221
|
+
hash = Math.imul(hash ^ header, 0x01000193);
|
|
222
|
+
if (name !== 0) {
|
|
223
|
+
buffer[used++] = name;
|
|
224
|
+
hash = Math.imul(hash ^ name, 0x01000193);
|
|
225
|
+
}
|
|
226
|
+
if (str !== 0) {
|
|
227
|
+
buffer[used++] = str;
|
|
228
|
+
hash = Math.imul(hash ^ str, 0x01000193);
|
|
229
|
+
}
|
|
230
|
+
if (unit !== 0) {
|
|
231
|
+
buffer[used++] = unit;
|
|
232
|
+
hash = Math.imul(hash ^ unit, 0x01000193);
|
|
233
|
+
}
|
|
234
|
+
if (numeric === 524288 /* Field.Integer */) {
|
|
235
|
+
buffer[used++] = value;
|
|
236
|
+
hash = Math.imul(hash ^ value, 0x01000193);
|
|
237
|
+
}
|
|
238
|
+
else if (numeric === 1048576 /* Field.Number */) {
|
|
239
|
+
f64[0] = value;
|
|
240
|
+
buffer[used++] = bits[0];
|
|
241
|
+
buffer[used++] = bits[1];
|
|
242
|
+
hash = Math.imul(Math.imul(hash ^ bits[0], 0x01000193) ^ bits[1], 0x01000193);
|
|
243
|
+
}
|
|
244
|
+
this.hash = hash;
|
|
229
245
|
if (firstToken !== 0) {
|
|
230
246
|
for (let child = firstToken; child !== 0; child = arena.nextSibling[child]) {
|
|
231
247
|
used = this.serialize(arena, child, used);
|
|
232
248
|
}
|
|
233
249
|
buffer = used + 1 > this.poolLength ? this.growPool(used + 1) : this.pool;
|
|
234
250
|
buffer[used++] = End;
|
|
251
|
+
this.hash = Math.imul(this.hash ^ End, 0x01000193);
|
|
235
252
|
}
|
|
236
253
|
if (firstChild !== 0) {
|
|
237
254
|
for (let child = firstChild; child !== 0; child = arena.nextSibling[child]) {
|
|
@@ -239,6 +256,7 @@ class StructuralMemo {
|
|
|
239
256
|
}
|
|
240
257
|
buffer = used + 1 > this.poolLength ? this.growPool(used + 1) : this.pool;
|
|
241
258
|
buffer[used++] = End;
|
|
259
|
+
this.hash = Math.imul(this.hash ^ End, 0x01000193);
|
|
242
260
|
}
|
|
243
261
|
return used;
|
|
244
262
|
}
|
|
@@ -258,10 +276,8 @@ class StructuralMemo {
|
|
|
258
276
|
const pool = this.pool;
|
|
259
277
|
const base = this.poolSize;
|
|
260
278
|
const length = this.used - base;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
hash = Math.imul(hash ^ pool[i], 0x01000193);
|
|
264
|
-
}
|
|
279
|
+
// the key was hashed while it was serialized: the length is mixed in
|
|
280
|
+
let hash = Math.imul(this.hash ^ length, 0x01000193);
|
|
265
281
|
// the multiplications only propagate the bits upwards: the low bits, used as the table index, are mixed with
|
|
266
282
|
// the high bits (murmur3 finalizer)
|
|
267
283
|
hash ^= hash >>> 16;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField, numericTokenTypes } from '../arena.js';
|
|
9
9
|
import { EnumToken, EnumAstNodeStatus } from '../types.js';
|
|
10
10
|
import { evaluate } from '../math/expression.js';
|
|
11
11
|
import { FeatureWalkMode } from './type.js';
|
|
12
|
-
import {
|
|
12
|
+
import { isFunctionType, mathFuncs } from '../../syntax/constants.js';
|
|
13
13
|
import { ValueWalker } from '../walk.js';
|
|
14
|
+
import { isInTemplate } from '../mixins/utils.js';
|
|
14
15
|
|
|
15
16
|
class ComputeCalcExpressionFeature {
|
|
16
17
|
accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
|
|
@@ -32,7 +33,8 @@ class ComputeCalcExpressionFeature {
|
|
|
32
33
|
* @param ast
|
|
33
34
|
*/
|
|
34
35
|
run(arena, ast) {
|
|
35
|
-
|
|
36
|
+
// the mixin and custom function bodies are templates: the expressions are computed once they are used
|
|
37
|
+
if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren) || isInTemplate(arena, ast)) {
|
|
36
38
|
return null;
|
|
37
39
|
}
|
|
38
40
|
for (let node = arena.firstChild[ast]; node !== 0; node = arena.nextSibling[node]) {
|
|
@@ -62,12 +64,12 @@ class ComputeCalcExpressionFeature {
|
|
|
62
64
|
catch (e) { }
|
|
63
65
|
continue;
|
|
64
66
|
}
|
|
65
|
-
if (
|
|
67
|
+
if (isFunctionType(typ)) {
|
|
66
68
|
set ??= new Set();
|
|
67
69
|
if (!set.has(value)) {
|
|
68
70
|
set.add(value);
|
|
69
71
|
if (parent != null) {
|
|
70
|
-
const name = arena.
|
|
72
|
+
const name = arena.resolveString(arena.stringValue[value]);
|
|
71
73
|
const shouldEvaluate = typ === EnumToken.MathFunctionTokenType ||
|
|
72
74
|
(typ === EnumToken.FunctionTokenType && mathFuncs.includes(name));
|
|
73
75
|
if (shouldEvaluate) {
|
|
@@ -96,13 +98,13 @@ class ComputeCalcExpressionFeature {
|
|
|
96
98
|
const parentType = arena.dataTypes[parent];
|
|
97
99
|
const wrap = !(parentType === EnumToken.MathFunctionTokenType ||
|
|
98
100
|
(parentType === EnumToken.FunctionTokenType &&
|
|
99
|
-
arena.
|
|
101
|
+
arena.resolveString(arena.stringValue[parent]) === "calc")) &&
|
|
100
102
|
// inlined: arena.isNumeric(values[0])
|
|
101
103
|
(!numericTokenTypes.has(arena.dataTypes[values[0]]) ||
|
|
102
104
|
arena.hasFraction(values[0])) &&
|
|
103
105
|
!(arena.dataTypes[values[0]] === EnumToken.MathFunctionTokenType ||
|
|
104
106
|
(arena.dataTypes[values[0]] === EnumToken.FunctionTokenType &&
|
|
105
|
-
mathFuncs.includes(arena.
|
|
107
|
+
mathFuncs.includes(arena.resolveString(arena.stringValue[values[0]]))));
|
|
106
108
|
arena.replaceToken(value, wrap ? createCalc(arena, value, values) : values[0]);
|
|
107
109
|
}
|
|
108
110
|
else {
|
|
@@ -137,7 +139,7 @@ function createCalc(arena, source, values) {
|
|
|
137
139
|
function hasExpression(arena, node) {
|
|
138
140
|
for (let token = arena.firstToken[node]; token !== 0; token = arena.nextSibling[token]) {
|
|
139
141
|
if (arena.dataTypes[token] === EnumToken.BinaryExpressionTokenType ||
|
|
140
|
-
|
|
142
|
+
isFunctionType(arena.dataTypes[token]) ||
|
|
141
143
|
arena.firstToken[token] !== 0 ||
|
|
142
144
|
arena.firstChild[token] !== 0) {
|
|
143
145
|
return true;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../types.js';
|
|
@@ -21,7 +21,7 @@ import { TokenField } from '../arena.js';
|
|
|
21
21
|
function isIfToken(arena, value) {
|
|
22
22
|
return (arena.dataTypes[value] === EnumToken.IfConditionTokenType ||
|
|
23
23
|
(arena.dataTypes[value] === EnumToken.WildCardFunctionTokenType &&
|
|
24
|
-
equalsIgnoreCase("if", arena.
|
|
24
|
+
equalsIgnoreCase("if", arena.resolveString(arena.stringValue[value]))));
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* deep clone a declaration. the clone map is filled with the cloned value tokens
|
|
@@ -94,7 +94,7 @@ function substituteIfElseNode(arena, declaration, node, wrapper, parentWrapper,
|
|
|
94
94
|
//
|
|
95
95
|
if (target != null &&
|
|
96
96
|
arena.dataTypes[target] === EnumToken.IdenTokenType &&
|
|
97
|
-
equalsIgnoreCase("else", arena.
|
|
97
|
+
equalsIgnoreCase("else", arena.resolveString(arena.stringValue[target]))) {
|
|
98
98
|
arena.replaceToken(mapped(targetWrapper), ...conditionValue(arena, elseCondition, nodeMap));
|
|
99
99
|
if (targetParentWrapper !== declaration) {
|
|
100
100
|
const siblings = arena.tokens(targetParentWrapper);
|
|
@@ -132,13 +132,13 @@ function substituteIfElseNode(arena, declaration, node, wrapper, parentWrapper,
|
|
|
132
132
|
return result;
|
|
133
133
|
}
|
|
134
134
|
const leftType = arena.dataTypes[left];
|
|
135
|
-
if (leftType === EnumToken.IdenTokenType && equalsIgnoreCase("else", arena.
|
|
135
|
+
if (leftType === EnumToken.IdenTokenType && equalsIgnoreCase("else", arena.resolveString(arena.stringValue[left]))) {
|
|
136
136
|
clonedDeclaration = cloneDeclaration(arena, declaration, nodeMap);
|
|
137
137
|
arena.replaceToken(mapped(targetWrapper === declaration ? node : targetWrapper), ...conditionValue(arena, node, nodeMap));
|
|
138
138
|
result.push(clonedDeclaration);
|
|
139
139
|
}
|
|
140
140
|
else if (leftType === EnumToken.WhenElseFunctionTokenType) {
|
|
141
|
-
const name = arena.
|
|
141
|
+
const name = arena.resolveString(arena.stringValue[left]);
|
|
142
142
|
const minify = name !== "supports";
|
|
143
143
|
const atRule = createAtRule(arena, declaration, parent, name, [
|
|
144
144
|
arena.createList(EnumToken.ParensTokenType, arena.tokens(left).map((t) => arena.clone(t, true))),
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
export { ComputePrefixFeature } from './prefix.js';
|
|
9
9
|
export { InlineCssVariablesFeature } from './inlinecssvariables.js';
|
|
10
|
+
export { EvaluateMixinFeature } from './mixin.js';
|
|
10
11
|
export { ComputeShorthandFeature } from './shorthand.js';
|
|
11
12
|
export { ComputeCalcExpressionFeature } from './calc.js';
|
|
12
13
|
export { TransformCssFeature } from './transform.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, EnumAstNodeStatus } from '../types.js';
|
|
@@ -12,6 +12,7 @@ import { FeatureWalkMode } from './type.js';
|
|
|
12
12
|
import { mathFuncs } from '../../syntax/constants.js';
|
|
13
13
|
import { TokenField } from '../arena.js';
|
|
14
14
|
import { ValueWalker } from '../walk.js';
|
|
15
|
+
import { isInTemplate } from '../mixins/utils.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* inline a binary expression into a parens token: (l op r)
|
|
@@ -50,12 +51,12 @@ function replace(arena, node, variableScope) {
|
|
|
50
51
|
for (const value of new ValueWalker(arena, node)) {
|
|
51
52
|
const typ = arena.dataTypes[value];
|
|
52
53
|
if (typ === EnumToken.MathFunctionTokenType ||
|
|
53
|
-
(typ === EnumToken.WildCardFunctionTokenType && arena.
|
|
54
|
+
(typ === EnumToken.WildCardFunctionTokenType && arena.resolveString(arena.stringValue[value]) === "var")) {
|
|
54
55
|
const first = arena.firstToken[value];
|
|
55
56
|
if (first !== 0 &&
|
|
56
57
|
arena.nextSibling[first] === 0 &&
|
|
57
58
|
arena.dataTypes[first] === EnumToken.DashedIdenTokenType) {
|
|
58
|
-
const info = (variableScope.get(arena.
|
|
59
|
+
const info = (variableScope.get(arena.resolveString(arena.stringValue[first])));
|
|
59
60
|
// the variable declaration may have been released
|
|
60
61
|
if (info?.replaceable && arena.name[info.node] !== 0 && arena.parents[value] !== 0) {
|
|
61
62
|
arena.replaceToken(value, ...arena.tokens(info.node).map((t) => arena.clone(t, true)));
|
|
@@ -87,7 +88,8 @@ class InlineCssVariablesFeature {
|
|
|
87
88
|
* @param context
|
|
88
89
|
*/
|
|
89
90
|
run(arena, ast, _options = {}, parent, context) {
|
|
90
|
-
|
|
91
|
+
// the variables of a mixin or a custom function body are private variables
|
|
92
|
+
if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren) || isInTemplate(arena, ast)) {
|
|
91
93
|
return null;
|
|
92
94
|
}
|
|
93
95
|
if (!("variableScope" in context)) {
|
|
@@ -96,13 +98,13 @@ class InlineCssVariablesFeature {
|
|
|
96
98
|
// [':root', 'html']
|
|
97
99
|
const isRoot = arena.dataTypes[parent] === EnumToken.StyleSheetNodeType &&
|
|
98
100
|
arena.dataTypes[ast] === EnumToken.RuleNodeType &&
|
|
99
|
-
(arena.raw
|
|
101
|
+
(arena.raw.get(ast) ?? splitRule(arena.resolveString(arena.name[ast]))).some((segment) => segment.some((s) => s === ":root" || s === "html"));
|
|
100
102
|
const variableScope = context.variableScope;
|
|
101
103
|
for (let node = arena.firstChild[ast]; node !== 0; node = arena.nextSibling[node]) {
|
|
102
104
|
if (arena.dataTypes[node] !== EnumToken.DeclarationNodeType) {
|
|
103
105
|
continue;
|
|
104
106
|
}
|
|
105
|
-
const name = arena.
|
|
107
|
+
const name = arena.resolveString(arena.name[node]);
|
|
106
108
|
// css variable
|
|
107
109
|
if (name.startsWith("--")) {
|
|
108
110
|
// the last declaration wins
|
|
@@ -122,8 +124,8 @@ class InlineCssVariablesFeature {
|
|
|
122
124
|
for (const value of new ValueWalker(arena, node)) {
|
|
123
125
|
if (arena.dataTypes[value] === EnumToken.MathFunctionTokenDefType ||
|
|
124
126
|
(arena.dataTypes[value] === EnumToken.WildCardFunctionTokenType &&
|
|
125
|
-
(mathFuncs.includes(arena.
|
|
126
|
-
arena.
|
|
127
|
+
(mathFuncs.includes(arena.resolveString(arena.stringValue[value])) ||
|
|
128
|
+
arena.resolveString(arena.stringValue[value]) === "var"))) {
|
|
127
129
|
recursive = true;
|
|
128
130
|
break;
|
|
129
131
|
}
|
|
@@ -155,7 +157,7 @@ class InlineCssVariablesFeature {
|
|
|
155
157
|
// drop declarations from :root{}
|
|
156
158
|
for (const parent of info.parent) {
|
|
157
159
|
if (arena.parents[info.node] === parent) {
|
|
158
|
-
const comment = arena.createComment(EnumToken.CommentTokenType, `/* ${arena.
|
|
160
|
+
const comment = arena.createComment(EnumToken.CommentTokenType, `/* ${arena.resolveString(arena.name[info.node])}: ${info.values.reduce((acc, curr) => acc + renderValue(arena, curr, { convertColor: false }), "")} */`);
|
|
159
161
|
arena.replaceChild(info.node, comment);
|
|
160
162
|
arena.detach(info.node);
|
|
161
163
|
}
|