@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
|
import { EnumAstNodeStatus, EnumToken } from '../types.js';
|
|
@@ -45,7 +45,7 @@ function replaceAstNodes(arena, tokens) {
|
|
|
45
45
|
.fieldTokens(value, TokenField.L)
|
|
46
46
|
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
47
47
|
if (token != null) {
|
|
48
|
-
let val = arena.
|
|
48
|
+
let val = arena.resolveString(arena.stringValue[token]);
|
|
49
49
|
if (val in pseudoAliasMap) {
|
|
50
50
|
val = pseudoAliasMap[val];
|
|
51
51
|
// inlined: arena.setStr(token, val)
|
|
@@ -75,7 +75,7 @@ function replaceAstNodes(arena, tokens) {
|
|
|
75
75
|
typ === EnumToken.PseudoClassFuncTokenType ||
|
|
76
76
|
typ === EnumToken.PseudoClassTokenType ||
|
|
77
77
|
typ === EnumToken.PseudoElementTokenType) {
|
|
78
|
-
let key = arena.
|
|
78
|
+
let key = arena.resolveString(arena.stringValue[value]) + (typ === EnumToken.PseudoClassFuncTokenType ? "()" : "");
|
|
79
79
|
if (key in pseudoAliasMap) {
|
|
80
80
|
const isPseudClass = pseudoAliasMap[key].startsWith("::");
|
|
81
81
|
// inlined: arena.setStr(value, pseudoAliasMap[key])
|
|
@@ -133,8 +133,8 @@ class ComputePrefixFeature {
|
|
|
133
133
|
}
|
|
134
134
|
const typ = arena.dataTypes[node];
|
|
135
135
|
if (typ === EnumToken.RuleNodeType) {
|
|
136
|
-
// inlined: arena.setSelector(node, replacePseudo(splitRule(arena.
|
|
137
|
-
arena.name[node] = arena.internString(replacePseudo(splitRule(arena.
|
|
136
|
+
// inlined: arena.setSelector(node, replacePseudo(splitRule(arena.resolveString(arena.name[node]))).reduce((acc, curr, index) => acc + (index > 0 ? "," : "") + curr.join(""), ""))
|
|
137
|
+
arena.name[node] = arena.internString(replacePseudo(splitRule(arena.resolveString(arena.name[node]))).reduce((acc, curr, index) => acc + (index > 0 ? "," : "") + curr.join(""), ""));
|
|
138
138
|
if (arena.firstToken[node] !== 0) {
|
|
139
139
|
const tokens = arena.tokens(node);
|
|
140
140
|
replaceAstNodes(arena, tokens);
|
|
@@ -142,7 +142,7 @@ class ComputePrefixFeature {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
else if (typ === EnumToken.DeclarationNodeType) {
|
|
145
|
-
const name = arena.
|
|
145
|
+
const name = arena.resolveString(arena.name[node]);
|
|
146
146
|
if (name.charAt(0) === "-") {
|
|
147
147
|
const match = name.match(/^-([^-]+)-(.+)$/);
|
|
148
148
|
if (match != null) {
|
|
@@ -161,7 +161,7 @@ class ComputePrefixFeature {
|
|
|
161
161
|
// inlined: arena.walkValues(node)
|
|
162
162
|
for (const value of new ValueWalker(arena, node)) {
|
|
163
163
|
const typ = arena.dataTypes[value];
|
|
164
|
-
const val = arena.
|
|
164
|
+
const val = arena.resolveString(arena.stringValue[value]);
|
|
165
165
|
if ((typ === EnumToken.IdenTokenType ||
|
|
166
166
|
(typ !== EnumToken.ParensTokenType && funcLike.includes(typ))) &&
|
|
167
167
|
val.match(/^-([^-]+)-(.+)$/) != null) {
|
|
@@ -187,7 +187,7 @@ class ComputePrefixFeature {
|
|
|
187
187
|
for (const value of new ValueWalker(arena, node)) {
|
|
188
188
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType ||
|
|
189
189
|
funcLike.includes(arena.dataTypes[value])) {
|
|
190
|
-
const match = arena.
|
|
190
|
+
const match = arena.resolveString(arena.stringValue[value]).match(/^-([^-]+)-(.+)$/);
|
|
191
191
|
if (match != null) {
|
|
192
192
|
// inlined: arena.setStr(value, match[2])
|
|
193
193
|
arena.stringValue[value] = arena.internString(match[2]);
|
|
@@ -197,7 +197,7 @@ class ComputePrefixFeature {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
else if (typ === EnumToken.AtRuleNodeType || typ === EnumToken.KeyframesAtRuleNodeType) {
|
|
200
|
-
const name = arena.
|
|
200
|
+
const name = arena.resolveString(arena.name[node]);
|
|
201
201
|
if (name.startsWith("-")) {
|
|
202
202
|
const match = name.match(/^-([^-]+)-(.+)$/);
|
|
203
203
|
if (match != null && "@" + match[2] in config.atRules) {
|
|
@@ -255,7 +255,7 @@ class ComputePrefixFeature {
|
|
|
255
255
|
360;
|
|
256
256
|
}
|
|
257
257
|
else if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType) {
|
|
258
|
-
key = arena.
|
|
258
|
+
key = arena.resolveString(arena.stringValue[tokens[i]]).toLowerCase();
|
|
259
259
|
switch (key) {
|
|
260
260
|
case "right":
|
|
261
261
|
case "left":
|
|
@@ -273,10 +273,10 @@ class ComputePrefixFeature {
|
|
|
273
273
|
}
|
|
274
274
|
if (arena.dataTypes[tokens[k]] === EnumToken.IdenTokenType) {
|
|
275
275
|
val = "";
|
|
276
|
-
if (equalsIgnoreCase(arena.
|
|
276
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[k]]), "left")) {
|
|
277
277
|
val = "right";
|
|
278
278
|
}
|
|
279
|
-
if (equalsIgnoreCase(arena.
|
|
279
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[k]]), "right")) {
|
|
280
280
|
val = "left";
|
|
281
281
|
}
|
|
282
282
|
if (val !== "") {
|
|
@@ -291,8 +291,8 @@ class ComputePrefixFeature {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
// inlined: arena.setStr(token, equalsIgnoreCase(arena.
|
|
295
|
-
arena.stringValue[token] = arena.internString(equalsIgnoreCase(arena.
|
|
294
|
+
// inlined: arena.setStr(token, equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "-webkit-repeating-linear-gradient") ? "repeating-linear-gradient" : "linear-gradient")
|
|
295
|
+
arena.stringValue[token] = arena.internString(equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "-webkit-repeating-linear-gradient")
|
|
296
296
|
? "repeating-linear-gradient"
|
|
297
297
|
: "linear-gradient");
|
|
298
298
|
arena.setTokenList(token, tokens);
|
|
@@ -311,7 +311,7 @@ class ComputePrefixFeature {
|
|
|
311
311
|
let type = "";
|
|
312
312
|
let tokens = arena.tokens(token);
|
|
313
313
|
// linear or radial
|
|
314
|
-
if (equalsIgnoreCase(arena.
|
|
314
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "linear")) {
|
|
315
315
|
type = "linear-gradient";
|
|
316
316
|
i++;
|
|
317
317
|
}
|
|
@@ -325,7 +325,7 @@ class ComputePrefixFeature {
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType) {
|
|
328
|
-
key += (key.length > 0 ? " " : "") + arena.
|
|
328
|
+
key += (key.length > 0 ? " " : "") + arena.resolveString(arena.stringValue[tokens[i]]);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
// mapping keywords
|
|
@@ -372,7 +372,7 @@ class ComputePrefixFeature {
|
|
|
372
372
|
continue;
|
|
373
373
|
}
|
|
374
374
|
if (arena.dataTypes[tokens[i]] === EnumToken.FunctionTokenType) {
|
|
375
|
-
if (equalsIgnoreCase(arena.
|
|
375
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "to")) {
|
|
376
376
|
colorStop.push(tokens[checkStopIndex]);
|
|
377
377
|
for (const token of arena.tokens(tokens[i])) {
|
|
378
378
|
colorStop.push(token);
|
|
@@ -381,12 +381,12 @@ class ComputePrefixFeature {
|
|
|
381
381
|
i = checkStopIndex;
|
|
382
382
|
checkStop = false;
|
|
383
383
|
}
|
|
384
|
-
else if (equalsIgnoreCase(arena.
|
|
384
|
+
else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "from")) {
|
|
385
385
|
k = arena.tokens(tokens[i]).length + 1;
|
|
386
386
|
tokens.splice(i, 1, ...arena.tokens(tokens[i]), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 0));
|
|
387
387
|
i += k;
|
|
388
388
|
}
|
|
389
|
-
else if (equalsIgnoreCase(arena.
|
|
389
|
+
else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "color-stop")) {
|
|
390
390
|
k = arena.tokens(tokens[i]).length - 1;
|
|
391
391
|
tokens.splice(i, 1, ...arena
|
|
392
392
|
.tokens(tokens[i])
|
|
@@ -432,11 +432,11 @@ class ComputePrefixFeature {
|
|
|
432
432
|
if (arena.dataTypes[tokens[i]] === EnumToken.PercentageTokenType ||
|
|
433
433
|
(arena.dataTypes[tokens[i]] === EnumToken.NumberTokenType && 0 === arena.numericValue[tokens[i]]) ||
|
|
434
434
|
(arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType &&
|
|
435
|
-
(equalsIgnoreCase(arena.
|
|
436
|
-
equalsIgnoreCase(arena.
|
|
437
|
-
equalsIgnoreCase(arena.
|
|
438
|
-
equalsIgnoreCase(arena.
|
|
439
|
-
equalsIgnoreCase(arena.
|
|
435
|
+
(equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "center") ||
|
|
436
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "top") ||
|
|
437
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "bottom") ||
|
|
438
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "left") ||
|
|
439
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "right")))) {
|
|
440
440
|
do {
|
|
441
441
|
positions.push(tokens[i]);
|
|
442
442
|
i++;
|
|
@@ -446,14 +446,14 @@ class ComputePrefixFeature {
|
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType) {
|
|
449
|
-
if (equalsIgnoreCase(arena.
|
|
450
|
-
equalsIgnoreCase(arena.
|
|
451
|
-
equalsIgnoreCase(arena.
|
|
452
|
-
equalsIgnoreCase(arena.
|
|
449
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "closest-side") ||
|
|
450
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "closest-corner") ||
|
|
451
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "farthest-side") ||
|
|
452
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "farthest-corner")) {
|
|
453
453
|
size.push(tokens[i++]);
|
|
454
454
|
}
|
|
455
|
-
else if (equalsIgnoreCase(arena.
|
|
456
|
-
equalsIgnoreCase(arena.
|
|
455
|
+
else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "circle") ||
|
|
456
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "ellipse")) {
|
|
457
457
|
form.push(tokens[i++]);
|
|
458
458
|
}
|
|
459
459
|
while (arena.dataTypes[tokens[i]] === EnumToken.WhitespaceTokenType ||
|
|
@@ -465,14 +465,14 @@ class ComputePrefixFeature {
|
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType) {
|
|
468
|
-
if (equalsIgnoreCase(arena.
|
|
469
|
-
equalsIgnoreCase(arena.
|
|
470
|
-
equalsIgnoreCase(arena.
|
|
471
|
-
equalsIgnoreCase(arena.
|
|
468
|
+
if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "closest-side") ||
|
|
469
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "closest-corner") ||
|
|
470
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "farthest-side") ||
|
|
471
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "farthest-corner")) {
|
|
472
472
|
size.push(tokens[i++]);
|
|
473
473
|
}
|
|
474
|
-
else if (equalsIgnoreCase(arena.
|
|
475
|
-
equalsIgnoreCase(arena.
|
|
474
|
+
else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "circle") ||
|
|
475
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[i]]), "ellipse")) {
|
|
476
476
|
form.push(tokens[i++]);
|
|
477
477
|
}
|
|
478
478
|
while (arena.dataTypes[tokens[i]] === EnumToken.WhitespaceTokenType ||
|
|
@@ -508,8 +508,8 @@ class ComputePrefixFeature {
|
|
|
508
508
|
}
|
|
509
509
|
tokens.push(arena.createToken(EnumToken.CommaTokenType));
|
|
510
510
|
}
|
|
511
|
-
// inlined: arena.setStr(token, equalsIgnoreCase(arena.
|
|
512
|
-
arena.stringValue[token] = arena.internString(equalsIgnoreCase(arena.
|
|
511
|
+
// inlined: arena.setStr(token, equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "-webkit-repeating-radial-gradient") ? "repeating-radial-gradient" : "radial-gradient")
|
|
512
|
+
arena.stringValue[token] = arena.internString(equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "-webkit-repeating-radial-gradient")
|
|
513
513
|
? "repeating-radial-gradient"
|
|
514
514
|
: "radial-gradient");
|
|
515
515
|
for (const colorStop of colorStops) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 2.3.0
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
8
|
+
import { DeclarationMemo, PropertyList } from '../../parser/declaration/list.js';
|
|
9
|
+
import { EnumToken, EnumAstNodeStatus } from '../types.js';
|
|
10
|
+
import { FeatureWalkMode } from './type.js';
|
|
11
|
+
import { moveResult } from '../mixins/utils.js';
|
|
12
|
+
import { getSyntaxRule } from '../../validation/config.js';
|
|
13
|
+
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
14
|
+
|
|
15
|
+
class ComputeShorthandFeature {
|
|
16
|
+
accept = new Set([
|
|
17
|
+
EnumToken.RuleNodeType,
|
|
18
|
+
EnumToken.AtRuleNodeType,
|
|
19
|
+
EnumToken.KeyframesRuleNodeType,
|
|
20
|
+
]);
|
|
21
|
+
get ordering() {
|
|
22
|
+
return 5;
|
|
23
|
+
}
|
|
24
|
+
get processMode() {
|
|
25
|
+
return FeatureWalkMode.Post;
|
|
26
|
+
}
|
|
27
|
+
static register(options) {
|
|
28
|
+
if (options.computeShorthand) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
options.features.push(new ComputeShorthandFeature(options));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param arena
|
|
36
|
+
* @param ast
|
|
37
|
+
* @param options
|
|
38
|
+
* @param _parent
|
|
39
|
+
* @param context
|
|
40
|
+
*/
|
|
41
|
+
run(arena, ast, options, _parent, context) {
|
|
42
|
+
if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren) || arena.firstChild[ast] === 0) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
// the keys of the declarations are shared by the rules of the minification
|
|
46
|
+
const memo = context == null ? null : (context.declarations ??= new DeclarationMemo());
|
|
47
|
+
let doNotSort = false;
|
|
48
|
+
// the descriptors of a custom function: the `result` descriptors are deduplicated when the declarations are
|
|
49
|
+
// not validated by the parser
|
|
50
|
+
let descriptors = null;
|
|
51
|
+
let isFunction = false;
|
|
52
|
+
if (arena.dataTypes[ast] === EnumToken.AtRuleNodeType) {
|
|
53
|
+
switch (arena.resolveString(arena.name[ast])) {
|
|
54
|
+
case "function":
|
|
55
|
+
doNotSort = true;
|
|
56
|
+
isFunction = true;
|
|
57
|
+
descriptors =
|
|
58
|
+
getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@function")?.getPropertyDescriptors() ?? null;
|
|
59
|
+
break;
|
|
60
|
+
case "mixin":
|
|
61
|
+
doNotSort = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// the children are processed by segments: an at-rule without a block or an `@apply` rule inserts declarations
|
|
66
|
+
// at its position, the declarations are not moved across it
|
|
67
|
+
let child = arena.firstChild[ast];
|
|
68
|
+
while (child !== 0) {
|
|
69
|
+
const list = new PropertyList(arena, options, memo, descriptors);
|
|
70
|
+
let hasDeclarations = false;
|
|
71
|
+
// first node of the segment that is not moved into the property list
|
|
72
|
+
let first = 0;
|
|
73
|
+
// at-rule without a block that ends the segment
|
|
74
|
+
let boundary = 0;
|
|
75
|
+
// the declarations (with their leading comments) are moved into the property list,
|
|
76
|
+
// the rules (with their leading comments) stay in place
|
|
77
|
+
while (child !== 0) {
|
|
78
|
+
let last = child;
|
|
79
|
+
if (!doNotSort) {
|
|
80
|
+
// capture comments with the next node
|
|
81
|
+
while (arena.nextSibling[last] !== 0 && arena.dataTypes[last] === EnumToken.CommentNodeType) {
|
|
82
|
+
last = arena.nextSibling[last];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const next = arena.nextSibling[last];
|
|
86
|
+
if (arena.dataTypes[last] === EnumToken.AtRuleNodeType &&
|
|
87
|
+
(!(arena.flags[last] & EnumAstNodeStatus.HasChildren) ||
|
|
88
|
+
arena.stringEquals(arena.name[last], "apply"))) {
|
|
89
|
+
boundary = child;
|
|
90
|
+
child = next;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
// https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
|
|
94
|
+
if (doNotSort || arena.dataTypes[last] === EnumToken.DeclarationNodeType) {
|
|
95
|
+
hasDeclarations = true;
|
|
96
|
+
for (let node = child; node !== next;) {
|
|
97
|
+
const nextNode = arena.nextSibling[node];
|
|
98
|
+
arena.detach(node);
|
|
99
|
+
list.addDeclaration(node);
|
|
100
|
+
node = nextNode;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (first === 0) {
|
|
104
|
+
first = child;
|
|
105
|
+
}
|
|
106
|
+
child = next;
|
|
107
|
+
}
|
|
108
|
+
if (hasDeclarations) {
|
|
109
|
+
// the declarations are inserted before the rules of the segment
|
|
110
|
+
const reference = first !== 0 ? first : boundary;
|
|
111
|
+
for (const node of list) {
|
|
112
|
+
if (reference === 0) {
|
|
113
|
+
arena.appendChild(ast, node);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
arena.insertBefore(reference, node);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// the deduplicated result keeps the position of the first result: it is moved after the conditional rules
|
|
122
|
+
if (isFunction) {
|
|
123
|
+
moveResult(arena, ast);
|
|
124
|
+
}
|
|
125
|
+
return ast;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { ComputeShorthandFeature };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 2.3.0
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
8
|
+
import { EnumToken, EnumAstNodeStatus } from '../types.js';
|
|
9
|
+
import { transformKind, compute } from '../transform/compute.js';
|
|
10
|
+
import { filterValues, renderValue } from '../../printer/render.js';
|
|
11
|
+
import { minifyTransformFunctions, eqMatrix } from '../transform/minify.js';
|
|
12
|
+
import { FeatureWalkMode } from './type.js';
|
|
13
|
+
import { StructuralMemo } from '../cache.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* outcome of the minification of a transform value that is not a list of new tokens, see {@link TransformMemo}
|
|
17
|
+
*/
|
|
18
|
+
var Outcome;
|
|
19
|
+
(function (Outcome) {
|
|
20
|
+
/**
|
|
21
|
+
* the matrix cannot be computed: the transform functions are minified one by one
|
|
22
|
+
*/
|
|
23
|
+
Outcome[Outcome["Failed"] = 0] = "Failed";
|
|
24
|
+
/**
|
|
25
|
+
* the transform functions minified one by one are the shortest form
|
|
26
|
+
*/
|
|
27
|
+
Outcome[Outcome["Functions"] = 1] = "Functions";
|
|
28
|
+
/**
|
|
29
|
+
* the shortest form reuses tokens of the value: it is computed for every declaration
|
|
30
|
+
*/
|
|
31
|
+
Outcome[Outcome["Uncached"] = 2] = "Uncached";
|
|
32
|
+
})(Outcome || (Outcome = {}));
|
|
33
|
+
/**
|
|
34
|
+
* Results of the minification of the transform values, shared by the rules of a minification and valid for the arena
|
|
35
|
+
* they were computed for. Identical values are common (`transform: translate3d(0, 0, 0)`, the keyframes of the
|
|
36
|
+
* animation libraries, ...): the matrix of a value is computed once per distinct value. A value whose shortest form
|
|
37
|
+
* only contains new tokens (`none`, `matrix()`, the minified functions) is stored as detached tokens that are cloned.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
class TransformMemo {
|
|
42
|
+
/**
|
|
43
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
44
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
45
|
+
*/
|
|
46
|
+
static shape = new TransformMemo();
|
|
47
|
+
/**
|
|
48
|
+
* the outcome or the detached tokens of the shortest form, by value structure
|
|
49
|
+
*/
|
|
50
|
+
values = new StructuralMemo();
|
|
51
|
+
}
|
|
52
|
+
class TransformCssFeature {
|
|
53
|
+
accept = new Set([
|
|
54
|
+
EnumToken.RuleNodeType,
|
|
55
|
+
EnumToken.AtRuleNodeType,
|
|
56
|
+
EnumToken.KeyframesRuleNodeType,
|
|
57
|
+
]);
|
|
58
|
+
get ordering() {
|
|
59
|
+
return 4;
|
|
60
|
+
}
|
|
61
|
+
get processMode() {
|
|
62
|
+
return FeatureWalkMode.Post;
|
|
63
|
+
}
|
|
64
|
+
static register(options) {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
if (options.computeTransform) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
options.features.push(new TransformCssFeature());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param arena
|
|
74
|
+
* @param ast
|
|
75
|
+
* @param _options
|
|
76
|
+
* @param _parent
|
|
77
|
+
* @param context minification context: the results are shared by the rules of the minification
|
|
78
|
+
*/
|
|
79
|
+
run(arena, ast, _options, _parent, context) {
|
|
80
|
+
if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
let memo = null;
|
|
84
|
+
let node;
|
|
85
|
+
for (node = arena.firstChild[ast]; node !== 0; node = arena.nextSibling[node]) {
|
|
86
|
+
if (arena.flags[node] & (EnumAstNodeStatus.Invalid | EnumAstNodeStatus.ValidationFailed)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (arena.dataTypes[node] !== EnumToken.DeclarationNodeType ||
|
|
90
|
+
(transformKind(arena, arena.name[node]) & 255 /* TransformKind.KindMask */) !== 22 /* TransformKind.Property */) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
let slot = -1;
|
|
94
|
+
let outcome;
|
|
95
|
+
if (context != null) {
|
|
96
|
+
// created with the first transform declaration of the minification
|
|
97
|
+
if (memo === null) {
|
|
98
|
+
memo = (context.transforms ??= new TransformMemo()).values;
|
|
99
|
+
}
|
|
100
|
+
slot = memo.list(arena, arena.firstToken[node]);
|
|
101
|
+
// inlined: memo.get(slot)
|
|
102
|
+
outcome = memo.values[slot];
|
|
103
|
+
if (Array.isArray(outcome)) {
|
|
104
|
+
const tokens = new Array(outcome.length);
|
|
105
|
+
for (let i = 0; i < outcome.length; i++) {
|
|
106
|
+
tokens[i] = arena.clone(outcome[i], true);
|
|
107
|
+
}
|
|
108
|
+
arena.setTokenList(node, tokens);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const children = [];
|
|
113
|
+
for (let child = arena.firstToken[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
114
|
+
children.push(arena.dataTypes[child] === EnumToken.TransformFunctionTokenType
|
|
115
|
+
? minifyTransformFunctions(arena, child)
|
|
116
|
+
: child);
|
|
117
|
+
}
|
|
118
|
+
if (outcome === 0 /* Outcome.Failed */) {
|
|
119
|
+
arena.setTokenList(node, children);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (outcome === 1 /* Outcome.Functions */) {
|
|
123
|
+
arena.setTokenList(node, filterValues(arena, children));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const computed = compute(arena, children);
|
|
127
|
+
if (computed == null) {
|
|
128
|
+
if (slot !== -1) {
|
|
129
|
+
memo.values[slot] = 0 /* Outcome.Failed */;
|
|
130
|
+
}
|
|
131
|
+
arena.setTokenList(node, children);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
// the shortest form: the functions minified one by one, the cumulative list, the minified matrix. a
|
|
135
|
+
// candidate replaces the matrix if its rendered value is shorter
|
|
136
|
+
const length = renderValue(arena, computed.matrix).length;
|
|
137
|
+
let result = null;
|
|
138
|
+
if (renderedLength(arena, filterValues(arena, children)) < length) {
|
|
139
|
+
result = children;
|
|
140
|
+
}
|
|
141
|
+
if (eqMatrix(arena, computed.values, computed.cumulative) &&
|
|
142
|
+
renderedLength(arena, computed.cumulative) < length) {
|
|
143
|
+
result = computed.cumulative;
|
|
144
|
+
}
|
|
145
|
+
if (eqMatrix(arena, computed.values, computed.minified) &&
|
|
146
|
+
renderedLength(arena, computed.minified) < length) {
|
|
147
|
+
result = computed.minified;
|
|
148
|
+
}
|
|
149
|
+
if (slot !== -1) {
|
|
150
|
+
if (result === children) {
|
|
151
|
+
memo.values[slot] = 1 /* Outcome.Functions */;
|
|
152
|
+
}
|
|
153
|
+
else if (result === computed.cumulative && !computed.created) {
|
|
154
|
+
memo.values[slot] = 2 /* Outcome.Uncached */;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// detached copies: the tokens of the declaration may be modified by the next features
|
|
158
|
+
const template = result === null ? [arena.clone(computed.matrix, true)] : new Array(result.length);
|
|
159
|
+
for (let i = 0; result !== null && i < result.length; i++) {
|
|
160
|
+
template[i] = arena.clone(result[i], true);
|
|
161
|
+
}
|
|
162
|
+
memo.values[slot] = template;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (result === null) {
|
|
166
|
+
arena.setTokenList(node, [computed.matrix]);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
arena.setTokenList(node, result);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* length of the rendered tokens
|
|
177
|
+
* @param arena
|
|
178
|
+
* @param tokens
|
|
179
|
+
*/
|
|
180
|
+
function renderedLength(arena, tokens) {
|
|
181
|
+
let length = 0;
|
|
182
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
183
|
+
length += renderValue(arena, tokens[i]).length;
|
|
184
|
+
}
|
|
185
|
+
return length;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { TransformCssFeature };
|