@tbela99/css-parser 2.0.1 → 2.2.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 +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- 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/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 2.2.0
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Hashing and comparison of strings and of ranges of code units, without creating strings.
|
|
10
|
+
*
|
|
11
|
+
* The tokenizer reads the code units of the css source (see `toCodeUnits()`): the values of the tokens are ranges of
|
|
12
|
+
* the code units. The tables of the tokenizer and the string table of the arena are keyed by the hash of the code units:
|
|
13
|
+
* a string and a range of code units with the same content have the same hash. When the hashes are equal, the code
|
|
14
|
+
* units are compared: the hash is 30 bits, different strings may have the same hash.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* FNV-1a offset basis
|
|
21
|
+
*/
|
|
22
|
+
const FNV_OFFSET = 0x811c9dc5 | 0;
|
|
23
|
+
/**
|
|
24
|
+
* FNV-1a prime
|
|
25
|
+
*/
|
|
26
|
+
const FNV_PRIME = 0x01000193;
|
|
27
|
+
/**
|
|
28
|
+
* the hashes are 30 bits integers: small integers are not boxed
|
|
29
|
+
*/
|
|
30
|
+
const HASH_MASK = 0x3fffffff;
|
|
31
|
+
/**
|
|
32
|
+
* KELVIN SIGN: the only code unit, other than the ascii uppercase letters, lowercased to an ascii letter by
|
|
33
|
+
* `toLowerCase()` (`k`)
|
|
34
|
+
*/
|
|
35
|
+
const KELVIN_SIGN = 0x212a;
|
|
36
|
+
/**
|
|
37
|
+
* hash of a string (case sensitive). same value as {@link hashRange} for the same code units
|
|
38
|
+
* @param str
|
|
39
|
+
*/
|
|
40
|
+
function hashString(str) {
|
|
41
|
+
let hash = FNV_OFFSET;
|
|
42
|
+
for (let i = 0; i < str.length; i++) {
|
|
43
|
+
hash = Math.imul(hash ^ str.charCodeAt(i), FNV_PRIME);
|
|
44
|
+
}
|
|
45
|
+
return hash & HASH_MASK;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* hash of a range of code units (case sensitive). same value as {@link hashString} for the same code units
|
|
49
|
+
* @param codes
|
|
50
|
+
* @param start
|
|
51
|
+
* @param end
|
|
52
|
+
*/
|
|
53
|
+
function hashRange(codes, start, end) {
|
|
54
|
+
let hash = FNV_OFFSET;
|
|
55
|
+
for (let i = start; i < end; i++) {
|
|
56
|
+
hash = Math.imul(hash ^ codes[i], FNV_PRIME);
|
|
57
|
+
}
|
|
58
|
+
return hash & HASH_MASK;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* lowercase ascii code of a code unit, like `toLowerCase()` for the keys of the tokenizer tables: the ascii uppercase
|
|
62
|
+
* letters and the kelvin sign are lowercased. -1 for the other non ascii code units: they do not match an ascii key
|
|
63
|
+
* @param code
|
|
64
|
+
*/
|
|
65
|
+
function lowerAscii(code) {
|
|
66
|
+
if (code >= 0x41 && code <= 0x5a) {
|
|
67
|
+
return code + 32;
|
|
68
|
+
}
|
|
69
|
+
if (code > 0x7f) {
|
|
70
|
+
return code === KELVIN_SIGN ? 0x6b : -1;
|
|
71
|
+
}
|
|
72
|
+
return code;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* hash of a range of code units, ignoring the case (see {@link lowerAscii}). -1 when the range contains a non ascii
|
|
76
|
+
* character that cannot match an ascii key
|
|
77
|
+
* @param codes
|
|
78
|
+
* @param start
|
|
79
|
+
* @param end
|
|
80
|
+
*/
|
|
81
|
+
function hashRangeLower(codes, start, end) {
|
|
82
|
+
let hash = FNV_OFFSET;
|
|
83
|
+
for (let i = start; i < end; i++) {
|
|
84
|
+
const code = lowerAscii(codes[i]);
|
|
85
|
+
if (code === -1) {
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
hash = Math.imul(hash ^ code, FNV_PRIME);
|
|
89
|
+
}
|
|
90
|
+
return hash & HASH_MASK;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { hashRange, hashRangeLower, hashString, lowerAscii };
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import config from '../../../data/properties.json.js';
|
|
@@ -1,14 +1,14 @@
|
|
|
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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js';
|
|
9
9
|
import { TokenField } from '../../ast/arena.js';
|
|
10
|
-
import {
|
|
11
|
-
import { renamedStandardProperties, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js';
|
|
10
|
+
import { isFunctionDefType, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensfuncDefMap, tokensMap, trimTokenSpace } from '../../syntax/constants.js';
|
|
11
|
+
import { renamedStandardProperties, isColorName, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js';
|
|
12
12
|
import { getSyntaxRule, getParsedSyntax } from '../../validation/config.js';
|
|
13
13
|
import { matchDeclarationSyntax, trimArray } from '../../validation/match.js';
|
|
14
14
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
|
|
@@ -33,8 +33,8 @@ function parseGridTemplate(template) {
|
|
|
33
33
|
result += buffer + " ";
|
|
34
34
|
buffer = "";
|
|
35
35
|
}
|
|
36
|
-
else if (char
|
|
37
|
-
while (i + 1 < template.length && template[i + 1]
|
|
36
|
+
else if (char === ".") {
|
|
37
|
+
while (i + 1 < template.length && template[i + 1] === ".") {
|
|
38
38
|
i++;
|
|
39
39
|
}
|
|
40
40
|
if (isWhiteSpace(result.at(-1)?.charCodeAt(0))) {
|
|
@@ -83,7 +83,8 @@ function parseColorIdent(arena, value) {
|
|
|
83
83
|
* @param errors
|
|
84
84
|
*/
|
|
85
85
|
function createDeclarationNode(arena, name, tokens, state, errors) {
|
|
86
|
-
|
|
86
|
+
// the name is an interned string id: the string is not created
|
|
87
|
+
const node = arena.createDeclaration(EnumToken.DeclarationNodeType, arena.stringValue[name], tokens, state, errors);
|
|
87
88
|
arena.copyLocation(node, name);
|
|
88
89
|
return node;
|
|
89
90
|
}
|
|
@@ -98,10 +99,10 @@ function createDeclarationNode(arena, name, tokens, state, errors) {
|
|
|
98
99
|
function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
99
100
|
const name = tokens.shift();
|
|
100
101
|
let i;
|
|
101
|
-
let nam = arena.
|
|
102
|
+
let nam = arena.resolveString(arena.stringValue[name]);
|
|
102
103
|
// parent at-rule name
|
|
103
|
-
const isAtRule = parent != null && typeof parent
|
|
104
|
-
const parentNam = isAtRule ? arena.
|
|
104
|
+
const isAtRule = parent != null && typeof parent === "number" && arena.dataTypes[parent] === EnumToken.AtRuleNodeType;
|
|
105
|
+
const parentNam = isAtRule ? arena.resolveString(arena.name[parent]) : null;
|
|
105
106
|
let rules = null;
|
|
106
107
|
let syntaxRules = null;
|
|
107
108
|
let success = true;
|
|
@@ -114,16 +115,17 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
114
115
|
}
|
|
115
116
|
for (i = 0; i < tokens.length; i++) {
|
|
116
117
|
const token = tokens[i];
|
|
117
|
-
if (arena.dataTypes[token]
|
|
118
|
-
arena.dataTypes[token]
|
|
119
|
-
arena.dataTypes[token]
|
|
118
|
+
if (arena.dataTypes[token] === EnumToken.WhitespaceTokenType ||
|
|
119
|
+
arena.dataTypes[token] === EnumToken.CommentTokenType ||
|
|
120
|
+
arena.dataTypes[token] === EnumToken.BadCdoTokenType) {
|
|
120
121
|
continue;
|
|
121
122
|
}
|
|
122
123
|
break;
|
|
123
124
|
}
|
|
124
125
|
if (
|
|
125
126
|
// inlined: arena.typeOf(name)
|
|
126
|
-
(arena.dataTypes[name] !== EnumToken.IdenTokenType &&
|
|
127
|
+
(arena.dataTypes[name] !== EnumToken.IdenTokenType &&
|
|
128
|
+
arena.dataTypes[name] !== EnumToken.DashedIdenTokenType) ||
|
|
127
129
|
arena.dataTypes[tokens[i]] !== EnumToken.ColonTokenType) {
|
|
128
130
|
if (tokens.length > 0) {
|
|
129
131
|
arena.spanLocation(name, name, tokens[tokens.length - 1]);
|
|
@@ -145,7 +147,7 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
145
147
|
tokens = tokens.slice(start, end);
|
|
146
148
|
// inlined: arena.typeOf(name)
|
|
147
149
|
if (validate && arena.dataTypes[name] === EnumToken.IdenTokenType) {
|
|
148
|
-
if (isAtRule && parentNam
|
|
150
|
+
if (isAtRule && parentNam !== "import" && parentNam !== "supports" && parentNam !== "media") {
|
|
149
151
|
// check @at-rule description
|
|
150
152
|
// pick up the syntax or reject immediately
|
|
151
153
|
// else do this
|
|
@@ -166,13 +168,14 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
166
168
|
else {
|
|
167
169
|
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(nam));
|
|
168
170
|
}
|
|
169
|
-
// <declaration-list
|
|
171
|
+
// <declaration-list>, <declaration-rule-list> or <block-contents>
|
|
170
172
|
// else
|
|
171
173
|
if (syntaxRules == null ||
|
|
172
174
|
(syntaxRules.length === 1 &&
|
|
173
175
|
syntaxRules[0].typ === ValidationTokenEnum.PropertyType &&
|
|
174
176
|
(syntaxRules[0].val === "declaration-list" ||
|
|
175
|
-
syntaxRules[0].val === "declaration-rule-list"
|
|
177
|
+
syntaxRules[0].val === "declaration-rule-list" ||
|
|
178
|
+
syntaxRules[0].val === "block-contents"))) {
|
|
176
179
|
if (isAtRule &&
|
|
177
180
|
(parentNam === "swash" ||
|
|
178
181
|
parentNam === "annotation" ||
|
|
@@ -193,7 +196,10 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
193
196
|
}
|
|
194
197
|
}
|
|
195
198
|
// inlined: arena.typeOf(name)
|
|
196
|
-
if (tokens.length === 0 &&
|
|
199
|
+
if (tokens.length === 0 &&
|
|
200
|
+
arena.dataTypes[name] !== EnumToken.DashedIdenTokenType &&
|
|
201
|
+
// the result of a custom function may be empty: `result: <declaration-value>?`
|
|
202
|
+
!(parentNam === "function" && equalsIgnoreCase(arena.resolveString(arena.stringValue[name]), "result"))) {
|
|
197
203
|
errors.push({
|
|
198
204
|
action: "drop",
|
|
199
205
|
message: "declaration value missing",
|
|
@@ -224,25 +230,26 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
224
230
|
}
|
|
225
231
|
for (i = 0; i < tokens.length; i++) {
|
|
226
232
|
token = tokens[i];
|
|
227
|
-
if (
|
|
228
|
-
arena.dataTypes[token]
|
|
229
|
-
arena.dataTypes[token]
|
|
233
|
+
if (isFunctionDefType(arena.dataTypes[token]) ||
|
|
234
|
+
arena.dataTypes[token] === EnumToken.StartParensTokenType ||
|
|
235
|
+
arena.dataTypes[token] === EnumToken.BlockStartTokenType) {
|
|
230
236
|
stack.push(token);
|
|
231
237
|
continue;
|
|
232
238
|
}
|
|
233
|
-
if (arena.dataTypes[token] === EnumToken.ColonTokenType && stack.length
|
|
239
|
+
if (arena.dataTypes[token] === EnumToken.ColonTokenType && stack.length === 0) {
|
|
234
240
|
stack.push(token);
|
|
235
241
|
continue;
|
|
236
242
|
}
|
|
237
243
|
switch (arena.dataTypes[token]) {
|
|
238
244
|
case EnumToken.Literal:
|
|
239
245
|
// inlined: arena.typeOf(stack.at(-1))
|
|
240
|
-
if (arena.
|
|
246
|
+
if (arena.resolveString(arena.stringValue[token]) === "/" &&
|
|
247
|
+
arena.dataTypes[stack.at(-1)] === EnumToken.MathFunctionTokenDefType) {
|
|
241
248
|
arena.dataTypes[token] = EnumToken.Div;
|
|
242
249
|
}
|
|
243
|
-
else if (arena.
|
|
250
|
+
else if (arena.resolveString(arena.stringValue[token]) === "-" &&
|
|
244
251
|
// inlined: arena.typeOf(stack.at(-1))
|
|
245
|
-
arena.dataTypes[stack.at(-1)]
|
|
252
|
+
arena.dataTypes[stack.at(-1)] === EnumToken.MathFunctionTokenDefType) {
|
|
246
253
|
arena.dataTypes[token] = EnumToken.Sub;
|
|
247
254
|
}
|
|
248
255
|
break;
|
|
@@ -265,7 +272,7 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
265
272
|
case EnumToken.EndParensTokenType:
|
|
266
273
|
if (stack.length > 0 &&
|
|
267
274
|
(arena.dataTypes[stack[stack.length - 1]] === EnumToken.StartParensTokenType ||
|
|
268
|
-
|
|
275
|
+
isFunctionDefType(arena.dataTypes[stack[stack.length - 1]]))) {
|
|
269
276
|
index = tokens.indexOf(stack.at(-1));
|
|
270
277
|
tokens.splice(i, 1);
|
|
271
278
|
arena.dataTypes[tokens[index]] =
|
|
@@ -274,9 +281,9 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
274
281
|
: tokensfuncDefMap.get(arena.dataTypes[stack[stack.length - 1]]);
|
|
275
282
|
arena.setTokenList(tokens[index], trimArray(arena, tokens.splice(index + 1, i - index - 1)));
|
|
276
283
|
if (arena.dataTypes[tokens[index]] === EnumToken.WildCardFunctionTokenType &&
|
|
277
|
-
equalsIgnoreCase(arena.
|
|
284
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[tokens[index]]), "if")) {
|
|
278
285
|
const last = arena.lastToken[tokens[index]];
|
|
279
|
-
if (last
|
|
286
|
+
if (last !== 0 && arena.dataTypes[last] === EnumToken.SemiColonTokenType) {
|
|
280
287
|
arena.detach(last);
|
|
281
288
|
}
|
|
282
289
|
let foundElse = false;
|
|
@@ -290,8 +297,8 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
290
297
|
}
|
|
291
298
|
let index = -1;
|
|
292
299
|
while (++index < curr.length) {
|
|
293
|
-
if (arena.dataTypes[curr[index]]
|
|
294
|
-
equalsIgnoreCase("else", arena.
|
|
300
|
+
if (arena.dataTypes[curr[index]] === EnumToken.IdenTokenType &&
|
|
301
|
+
equalsIgnoreCase("else", arena.resolveString(arena.stringValue[curr[index]]))) {
|
|
295
302
|
foundElse = true;
|
|
296
303
|
}
|
|
297
304
|
if (arena.dataTypes[curr[index]] === EnumToken.ColonTokenType) {
|
|
@@ -326,15 +333,16 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
326
333
|
}
|
|
327
334
|
else if (arena.dataTypes[tokens[index]] === EnumToken.UrlFunctionTokenType) {
|
|
328
335
|
const url = arena.findToken(tokens[index], (arena, t) => arena.dataTypes[t] === EnumToken.StringTokenType);
|
|
329
|
-
if (url != null &&
|
|
336
|
+
if (url != null &&
|
|
337
|
+
/^[a-zA-Z0-9/_.-]+$/.test(arena.resolveString(arena.stringValue[url]).slice(1, -1))) {
|
|
330
338
|
arena.dataTypes[url] = EnumToken.UrlTokenTokenType;
|
|
331
|
-
// inlined: arena.setStr(url, arena.
|
|
332
|
-
arena.stringValue[url] = arena.internString(arena.
|
|
339
|
+
// inlined: arena.setStr(url, arena.resolveString(arena.stringValue[url]).slice(1, -1))
|
|
340
|
+
arena.stringValue[url] = arena.internString(arena.resolveString(arena.stringValue[url]).slice(1, -1));
|
|
333
341
|
}
|
|
334
342
|
}
|
|
335
343
|
i = index;
|
|
336
344
|
if (arena.dataTypes[tokens[index]] === EnumToken.MathFunctionTokenType &&
|
|
337
|
-
equalsIgnoreCase("calc", arena.
|
|
345
|
+
equalsIgnoreCase("calc", arena.resolveString(arena.stringValue[tokens[index]]))) {
|
|
338
346
|
// inlined: arena.setTokens(tokens[index], buildExpression(arena, arena.tokens(tokens[index])))
|
|
339
347
|
arena.setTokenList(tokens[index], [buildExpression(arena, arena.tokens(tokens[index]))]);
|
|
340
348
|
}
|
|
@@ -350,7 +358,10 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
350
358
|
message: `invalid color`,
|
|
351
359
|
node: tokens[index],
|
|
352
360
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[index]))
|
|
353
|
-
location: [
|
|
361
|
+
location: [
|
|
362
|
+
options.source.file,
|
|
363
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[index])),
|
|
364
|
+
],
|
|
354
365
|
});
|
|
355
366
|
}
|
|
356
367
|
}
|
|
@@ -358,11 +369,12 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
358
369
|
}
|
|
359
370
|
break;
|
|
360
371
|
case EnumToken.IdenTokenType:
|
|
361
|
-
|
|
362
|
-
|
|
372
|
+
// the identifiers that are not colors are skipped without reading the string (computed once per id)
|
|
373
|
+
if (arena.stringFlag(arena.stringValue[token], 0 /* StringFlag.Color */, isColorName)) {
|
|
374
|
+
const val = lowercase(arena.resolveString(arena.stringValue[token]));
|
|
363
375
|
if (val in COLORS_NAMES || val === "currentcolor") {
|
|
364
|
-
//
|
|
365
|
-
arena.stringValue[token] = arena.
|
|
376
|
+
// the lowercase string id: no string is created
|
|
377
|
+
arena.stringValue[token] = arena.lowerStringId(arena.stringValue[token]);
|
|
366
378
|
arena.dataTypes[token] = EnumToken.ColorTokenType;
|
|
367
379
|
// inlined: arena.setColorType(token, ColorType.LIT)
|
|
368
380
|
arena.colorType[token] = ColorType.LIT;
|
|
@@ -397,7 +409,7 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
397
409
|
i--;
|
|
398
410
|
continue;
|
|
399
411
|
}
|
|
400
|
-
if (arena.dataTypes[tokens[i - 1]]
|
|
412
|
+
if (arena.dataTypes[tokens[i - 1]] === EnumToken.WhitespaceTokenType) {
|
|
401
413
|
for (let index = i - 1; index < tokens.length - 1; index++) {
|
|
402
414
|
tokens[index] = tokens[index + 1];
|
|
403
415
|
}
|
|
@@ -412,7 +424,10 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
412
424
|
message: "unbalanced token",
|
|
413
425
|
node: stack[stack.length - 1],
|
|
414
426
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stack[stack.length - 1]))
|
|
415
|
-
location: [
|
|
427
|
+
location: [
|
|
428
|
+
options.source.file,
|
|
429
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stack[stack.length - 1])),
|
|
430
|
+
],
|
|
416
431
|
});
|
|
417
432
|
if (tokens.length > 0) {
|
|
418
433
|
arena.spanLocation(name, name, tokens[tokens.length - 1]);
|
|
@@ -427,9 +442,9 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
427
442
|
let i = 0;
|
|
428
443
|
for (; i < tokens.length; i++) {
|
|
429
444
|
if (arena.dataTypes[tokens[i]] === EnumToken.StringTokenType) {
|
|
430
|
-
if (/[\s.]/.test(arena.
|
|
431
|
-
// inlined: arena.setStr(tokens[i], parseGridTemplate(arena.
|
|
432
|
-
arena.stringValue[tokens[i]] = arena.internString(parseGridTemplate(arena.
|
|
445
|
+
if (/[\s.]/.test(arena.resolveString(arena.stringValue[tokens[i]]))) {
|
|
446
|
+
// inlined: arena.setStr(tokens[i], parseGridTemplate(arena.resolveString(arena.stringValue[tokens[i]])))
|
|
447
|
+
arena.stringValue[tokens[i]] = arena.internString(parseGridTemplate(arena.resolveString(arena.stringValue[tokens[i]])));
|
|
433
448
|
}
|
|
434
449
|
if (arena.dataTypes[tokens[i + 1]] === EnumToken.WhitespaceTokenType &&
|
|
435
450
|
arena.dataTypes[tokens[i + 2]] === EnumToken.StringTokenType) {
|
|
@@ -443,21 +458,24 @@ function parseDeclaration(arena, tokens, parent, options, errors) {
|
|
|
443
458
|
if (tokens.length > 0) {
|
|
444
459
|
arena.spanLocation(name, name, tokens[tokens.length - 1]);
|
|
445
460
|
}
|
|
446
|
-
return createDeclarationNode(arena, name, tokens, hasImportantFlag
|
|
461
|
+
return createDeclarationNode(arena, name, tokens, hasImportantFlag
|
|
462
|
+
? EnumAstNodeStatus.Unknown | EnumAstNodeStatus.ImportantDeclaration
|
|
463
|
+
: EnumAstNodeStatus.Unknown, result?.errors ?? null);
|
|
447
464
|
}
|
|
448
465
|
if (equalsIgnoreCase("composes", nam)) {
|
|
449
466
|
let index = -1;
|
|
450
467
|
for (let i = 0; i < tokens.length; i++) {
|
|
451
|
-
if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType &&
|
|
468
|
+
if (arena.dataTypes[tokens[i]] === EnumToken.IdenTokenType &&
|
|
469
|
+
equalsIgnoreCase("from", arena.resolveString(arena.stringValue[tokens[i]]))) {
|
|
452
470
|
index = i;
|
|
453
471
|
break;
|
|
454
472
|
}
|
|
455
473
|
}
|
|
456
|
-
const left = trimArray(arena, index
|
|
457
|
-
const right = index
|
|
474
|
+
const left = trimArray(arena, index === -1 ? tokens : tokens.slice(0, index));
|
|
475
|
+
const right = index === -1 ? null : trimArray(arena, tokens.slice(index + 1));
|
|
458
476
|
const composes = arena.createToken(EnumToken.ComposesSelectorNodeType);
|
|
459
477
|
const first = tokens[0];
|
|
460
|
-
const last = index
|
|
478
|
+
const last = index !== -1 && right.length > 0 ? right[right.length - 1] : left[left.length - 1];
|
|
461
479
|
// inlined: arena.setField(composes, TokenField.L, ...left)
|
|
462
480
|
arena.setTokenList(arena.fieldList(composes, TokenField.L), left);
|
|
463
481
|
if (right != null && right.length > 0) {
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -15,7 +15,7 @@ function eq(a, b) {
|
|
|
15
15
|
if (a == null || b == null) {
|
|
16
16
|
return a == b;
|
|
17
17
|
}
|
|
18
|
-
if (typeof a
|
|
18
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
19
19
|
return a === b;
|
|
20
20
|
}
|
|
21
21
|
if (a.constructor != b.constructor) {
|
|
@@ -35,7 +35,7 @@ function eq(a, b) {
|
|
|
35
35
|
}
|
|
36
36
|
const k1 = Object.keys(a);
|
|
37
37
|
const k2 = Object.keys(b);
|
|
38
|
-
if (k1.length
|
|
38
|
+
if (k1.length !== k2.length) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
let key;
|
|
@@ -54,14 +54,14 @@ function eq(a, b) {
|
|
|
54
54
|
* @param b
|
|
55
55
|
*/
|
|
56
56
|
function eqToken(arena, a, b) {
|
|
57
|
-
if (a
|
|
57
|
+
if (a === b) {
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
|
-
if (arena.dataTypes[a]
|
|
61
|
-
arena.name[a]
|
|
62
|
-
arena.stringValue[a]
|
|
63
|
-
arena.unit[a]
|
|
64
|
-
arena.colorType[a]
|
|
60
|
+
if (arena.dataTypes[a] !== arena.dataTypes[b] ||
|
|
61
|
+
arena.name[a] !== arena.name[b] ||
|
|
62
|
+
arena.stringValue[a] !== arena.stringValue[b] ||
|
|
63
|
+
arena.unit[a] !== arena.unit[b] ||
|
|
64
|
+
arena.colorType[a] !== arena.colorType[b]) {
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
const x = arena.numericValue[a];
|
|
@@ -72,26 +72,26 @@ function eqToken(arena, a, b) {
|
|
|
72
72
|
}
|
|
73
73
|
let ta = arena.firstToken[a];
|
|
74
74
|
let tb = arena.firstToken[b];
|
|
75
|
-
while (ta
|
|
75
|
+
while (ta !== 0 && tb !== 0) {
|
|
76
76
|
if (!eqToken(arena, ta, tb)) {
|
|
77
77
|
return false;
|
|
78
78
|
}
|
|
79
79
|
ta = arena.nextSibling[ta];
|
|
80
80
|
tb = arena.nextSibling[tb];
|
|
81
81
|
}
|
|
82
|
-
if (ta
|
|
82
|
+
if (ta !== tb) {
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
85
85
|
ta = arena.firstChild[a];
|
|
86
86
|
tb = arena.firstChild[b];
|
|
87
|
-
while (ta
|
|
87
|
+
while (ta !== 0 && tb !== 0) {
|
|
88
88
|
if (!eqToken(arena, ta, tb)) {
|
|
89
89
|
return false;
|
|
90
90
|
}
|
|
91
91
|
ta = arena.nextSibling[ta];
|
|
92
92
|
tb = arena.nextSibling[tb];
|
|
93
93
|
}
|
|
94
|
-
return ta
|
|
94
|
+
return ta === tb;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export { eq, eqToken };
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
// Alphabet: a-z, A-Z, 0-9, _, -
|
|
@@ -75,7 +75,7 @@ async function hash(input, length = 6, algo) {
|
|
|
75
75
|
case "base64url":
|
|
76
76
|
case "base64":
|
|
77
77
|
result = btoa(input);
|
|
78
|
-
if (algo
|
|
78
|
+
if (algo === "base64url") {
|
|
79
79
|
result = result.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
80
80
|
}
|
|
81
81
|
return result.slice(0, length);
|
|
@@ -105,7 +105,7 @@ function syncHash(input, length = 6, algo) {
|
|
|
105
105
|
case "base64url":
|
|
106
106
|
case "base64":
|
|
107
107
|
result = btoa(input);
|
|
108
|
-
if (algo
|
|
108
|
+
if (algo === "base64url") {
|
|
109
109
|
result = result.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
110
110
|
}
|
|
111
111
|
return result.slice(0, length);
|