@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
|
@@ -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 } from '../../ast/types.js';
|
|
9
9
|
import { LOC } from '../../syntax/constants.js';
|
|
10
10
|
import { ValidationTokenEnum } from './typedef.js';
|
|
11
|
-
import { isIdentStart,
|
|
11
|
+
import { isIdentStart, parseDimension, isPseudo, isIdent } from '../../syntax/syntax.js';
|
|
12
12
|
|
|
13
13
|
const SymbolsMapTokens = {
|
|
14
14
|
"&&": ValidationTokenEnum.Ampersand,
|
|
@@ -48,7 +48,7 @@ const makeBinaryOp = new Map([
|
|
|
48
48
|
*/
|
|
49
49
|
const symbolTypes = new Map();
|
|
50
50
|
for (const [key, type] of Object.entries(SymbolsMapTokens)) {
|
|
51
|
-
if (key.length
|
|
51
|
+
if (key.length === 1) {
|
|
52
52
|
symbolTypes.set(key.charCodeAt(0), type);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ for (const [key, type] of Object.entries(SymbolsMapTokens)) {
|
|
|
57
57
|
*/
|
|
58
58
|
const pairSymbols = new Map();
|
|
59
59
|
for (const [key, type] of Object.entries(SymbolsMapTokens)) {
|
|
60
|
-
if (key.length
|
|
60
|
+
if (key.length === 2) {
|
|
61
61
|
const list = pairSymbols.get(key.charCodeAt(0)) ?? [];
|
|
62
62
|
list.push([key.charCodeAt(1), type]);
|
|
63
63
|
pairSymbols.set(key.charCodeAt(0), list);
|
|
@@ -76,7 +76,7 @@ function pairSymbolType(syntax, index) {
|
|
|
76
76
|
if (list != null) {
|
|
77
77
|
const next = syntax.charCodeAt(index + 1);
|
|
78
78
|
for (let k = 0; k < list.length; k++) {
|
|
79
|
-
if (list[k][0]
|
|
79
|
+
if (list[k][0] === next) {
|
|
80
80
|
return list[k][1];
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -109,7 +109,7 @@ function codePoints(str, start, end) {
|
|
|
109
109
|
* @param str
|
|
110
110
|
*/
|
|
111
111
|
function isDigits(str) {
|
|
112
|
-
if (str.length
|
|
112
|
+
if (str.length === 0) {
|
|
113
113
|
return false;
|
|
114
114
|
}
|
|
115
115
|
for (let k = 0; k < str.length; k++) {
|
|
@@ -135,14 +135,15 @@ function getTokenType(token, loc) {
|
|
|
135
135
|
}
|
|
136
136
|
const first = token.charCodeAt(0);
|
|
137
137
|
// " or '
|
|
138
|
-
if (first
|
|
138
|
+
if (first === 34 || first === 39) {
|
|
139
139
|
return {
|
|
140
140
|
typ: ValidationTokenEnum.StringToken,
|
|
141
141
|
val: token,
|
|
142
142
|
[LOC]: loc,
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
// integer, optionally negative: range bounds such as `<integer [-∞,-1]>`
|
|
146
|
+
if (isDigits(token) || (first === 45 && isDigits(token.slice(1)))) {
|
|
146
147
|
return {
|
|
147
148
|
typ: ValidationTokenEnum.Number,
|
|
148
149
|
val: Number(token),
|
|
@@ -168,7 +169,7 @@ function getTokenType(token, loc) {
|
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
171
|
// @
|
|
171
|
-
if (first
|
|
172
|
+
if (first === 64 && isIdent(token.slice(1))) {
|
|
172
173
|
return {
|
|
173
174
|
typ: ValidationTokenEnum.AtRule,
|
|
174
175
|
val: token.slice(1),
|
|
@@ -234,9 +235,9 @@ function tokenizeSyntax(syntax, position = {
|
|
|
234
235
|
let code;
|
|
235
236
|
let type;
|
|
236
237
|
const bufferLength = () => prefix.length + bufferEnd - bufferStart;
|
|
237
|
-
const buffer = () => prefix.length
|
|
238
|
+
const buffer = () => prefix.length === 0 ? syntax.slice(bufferStart, bufferEnd) : prefix + syntax.slice(bufferStart, bufferEnd);
|
|
238
239
|
const append = (index) => {
|
|
239
|
-
if (bufferEnd
|
|
240
|
+
if (bufferEnd === bufferStart) {
|
|
240
241
|
bufferStart = index;
|
|
241
242
|
}
|
|
242
243
|
bufferEnd = index + 1;
|
|
@@ -258,7 +259,7 @@ function tokenizeSyntax(syntax, position = {
|
|
|
258
259
|
curCol++;
|
|
259
260
|
curInd++;
|
|
260
261
|
// <an+b>
|
|
261
|
-
if (code
|
|
262
|
+
if (code === 60 && syntax.startsWith("an+b>", i + 1)) {
|
|
262
263
|
if (bufferLength() > 0) {
|
|
263
264
|
prefix = buffer();
|
|
264
265
|
bufferStart = bufferEnd = 0;
|
|
@@ -288,17 +289,17 @@ function tokenizeSyntax(syntax, position = {
|
|
|
288
289
|
continue;
|
|
289
290
|
}
|
|
290
291
|
// :
|
|
291
|
-
if (code
|
|
292
|
-
if (syntax.charCodeAt(i + 1)
|
|
292
|
+
if (code === 58) {
|
|
293
|
+
if (syntax.charCodeAt(i + 1) === 58) {
|
|
293
294
|
if (isIdentStart(syntax.charCodeAt(i + 2)) ||
|
|
294
|
-
(syntax.charCodeAt(i + 2)
|
|
295
|
+
(syntax.charCodeAt(i + 2) === 45 && isIdentStart(syntax.charCodeAt(i + 3)))) {
|
|
295
296
|
append(i);
|
|
296
297
|
append(++i);
|
|
297
298
|
continue;
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
if (isIdentStart(syntax.charCodeAt(i + 1)) ||
|
|
301
|
-
(syntax.charCodeAt(i + 1)
|
|
302
|
+
(syntax.charCodeAt(i + 1) === 45 && isIdentStart(syntax.charCodeAt(i + 2)))) {
|
|
302
303
|
append(i);
|
|
303
304
|
continue;
|
|
304
305
|
}
|
|
@@ -310,7 +311,7 @@ function tokenizeSyntax(syntax, position = {
|
|
|
310
311
|
while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === ValidationTokenEnum.Whitespace) {
|
|
311
312
|
k++;
|
|
312
313
|
}
|
|
313
|
-
if (k
|
|
314
|
+
if (k !== i) {
|
|
314
315
|
curCol += k - i;
|
|
315
316
|
curInd += k - i;
|
|
316
317
|
i = k;
|
|
@@ -329,20 +330,19 @@ function tokenizeSyntax(syntax, position = {
|
|
|
329
330
|
}
|
|
330
331
|
switch (code) {
|
|
331
332
|
// :
|
|
332
|
-
case 58:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
[LOC]: { ind: posInd, lin: posLin, col: posCol },
|
|
338
|
-
});
|
|
333
|
+
case 58: {
|
|
334
|
+
// `<ident-token> : <declaration-value>?`, `name: <value>`: the colon is a token
|
|
335
|
+
const loc = startToken();
|
|
336
|
+
if (bufferLength() > 0) {
|
|
337
|
+
tokens.push(getTokenType(buffer(), startToken()));
|
|
339
338
|
clear();
|
|
340
|
-
curCol++;
|
|
341
|
-
curInd++;
|
|
342
|
-
break;
|
|
343
339
|
}
|
|
344
|
-
|
|
340
|
+
tokens.push({
|
|
341
|
+
typ: ValidationTokenEnum.Colon,
|
|
342
|
+
[LOC]: loc,
|
|
343
|
+
});
|
|
345
344
|
break;
|
|
345
|
+
}
|
|
346
346
|
// " and '
|
|
347
347
|
case 34:
|
|
348
348
|
case 39:
|
|
@@ -351,7 +351,7 @@ function tokenizeSyntax(syntax, position = {
|
|
|
351
351
|
append(i);
|
|
352
352
|
while (i + 1 < length) {
|
|
353
353
|
append(++i);
|
|
354
|
-
if (syntax.charCodeAt(i)
|
|
354
|
+
if (syntax.charCodeAt(i) === quote) {
|
|
355
355
|
break;
|
|
356
356
|
}
|
|
357
357
|
}
|
|
@@ -383,7 +383,7 @@ function tokenizeSyntax(syntax, position = {
|
|
|
383
383
|
return tokens;
|
|
384
384
|
}
|
|
385
385
|
/**
|
|
386
|
-
* parse
|
|
386
|
+
* parse a css value definition syntax (webref)
|
|
387
387
|
* @param syntax
|
|
388
388
|
* @returns
|
|
389
389
|
*/
|
|
@@ -398,17 +398,17 @@ function parseSyntax(syntax) {
|
|
|
398
398
|
tokens.push(token);
|
|
399
399
|
switch (token.typ) {
|
|
400
400
|
case ValidationTokenEnum.EOF:
|
|
401
|
-
if (stack.at(-1)?.typ
|
|
401
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
402
402
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
403
403
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
404
404
|
stack.pop();
|
|
405
405
|
}
|
|
406
|
-
else if (stack.at(-1)?.typ
|
|
406
|
+
else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
|
|
407
407
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
408
408
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
409
409
|
stack.pop();
|
|
410
410
|
}
|
|
411
|
-
else if (stack.at(-1)?.typ
|
|
411
|
+
else if (stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
|
|
412
412
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
413
413
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
414
414
|
stack.pop();
|
|
@@ -417,10 +417,10 @@ function parseSyntax(syntax) {
|
|
|
417
417
|
break;
|
|
418
418
|
case ValidationTokenEnum.Pipe:
|
|
419
419
|
{
|
|
420
|
-
while (stack.at(-1)?.typ
|
|
421
|
-
stack.at(-1)?.typ
|
|
420
|
+
while (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken ||
|
|
421
|
+
stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
|
|
422
422
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
423
|
-
if (stack.at(-1)?.typ
|
|
423
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
|
|
424
424
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
425
425
|
}
|
|
426
426
|
else {
|
|
@@ -428,8 +428,8 @@ function parseSyntax(syntax) {
|
|
|
428
428
|
}
|
|
429
429
|
stack.pop();
|
|
430
430
|
}
|
|
431
|
-
let index = stack.length
|
|
432
|
-
if (stack.at(-1)?.typ
|
|
431
|
+
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
432
|
+
if (stack.at(-1)?.typ !== ValidationTokenEnum.PipeToken) {
|
|
433
433
|
stack.push(Object.assign(token, {
|
|
434
434
|
typ: ValidationTokenEnum.PipeToken,
|
|
435
435
|
chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
|
|
@@ -442,7 +442,7 @@ function parseSyntax(syntax) {
|
|
|
442
442
|
break;
|
|
443
443
|
case ValidationTokenEnum.Ampersand:
|
|
444
444
|
{
|
|
445
|
-
let index = stack.length
|
|
445
|
+
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
446
446
|
if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
|
|
447
447
|
if (token.typ === ValidationTokenEnum.Ampersand) {
|
|
448
448
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
@@ -478,13 +478,13 @@ function parseSyntax(syntax) {
|
|
|
478
478
|
break;
|
|
479
479
|
case ValidationTokenEnum.Column:
|
|
480
480
|
{
|
|
481
|
-
let index = stack.length
|
|
481
|
+
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
482
482
|
if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
|
|
483
483
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
484
484
|
tokens.pop();
|
|
485
485
|
}
|
|
486
486
|
else {
|
|
487
|
-
if (index
|
|
487
|
+
if (index !== -1) {
|
|
488
488
|
stack.push(Object.assign(token, {
|
|
489
489
|
typ: makeBinaryOp.get(token.typ),
|
|
490
490
|
chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
|
|
@@ -500,7 +500,7 @@ function parseSyntax(syntax) {
|
|
|
500
500
|
}
|
|
501
501
|
break;
|
|
502
502
|
case ValidationTokenEnum.OpenParenthesis:
|
|
503
|
-
if (tokens.at(-2)?.typ
|
|
503
|
+
if (tokens.at(-2)?.typ === ValidationTokenEnum.Keyword) {
|
|
504
504
|
stack.push(Object.assign(tokens.at(-2), {
|
|
505
505
|
typ: ValidationTokenEnum.Function,
|
|
506
506
|
chi: [],
|
|
@@ -508,7 +508,7 @@ function parseSyntax(syntax) {
|
|
|
508
508
|
tokens.pop();
|
|
509
509
|
break;
|
|
510
510
|
}
|
|
511
|
-
if (tokens.at(-2)?.typ
|
|
511
|
+
if (tokens.at(-2)?.typ === ValidationTokenEnum.PseudoClassToken) {
|
|
512
512
|
stack.push(Object.assign(tokens.at(-2), {
|
|
513
513
|
typ: ValidationTokenEnum.PseudoClassFunctionToken,
|
|
514
514
|
chi: [],
|
|
@@ -519,13 +519,13 @@ function parseSyntax(syntax) {
|
|
|
519
519
|
stack.push(token);
|
|
520
520
|
break;
|
|
521
521
|
case ValidationTokenEnum.CloseParenthesis:
|
|
522
|
-
if (stack.at(-1)?.typ
|
|
522
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
523
523
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
524
524
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
525
525
|
stack.pop();
|
|
526
526
|
}
|
|
527
|
-
if (stack.at(-1)?.typ
|
|
528
|
-
(stack.at(-1)?.typ
|
|
527
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.OpenParenthesis ||
|
|
528
|
+
(stack.at(-1)?.typ === ValidationTokenEnum.PropertyType &&
|
|
529
529
|
stack.at(-1).val === "function-token")) {
|
|
530
530
|
stack.pop();
|
|
531
531
|
}
|
|
@@ -561,7 +561,7 @@ function parseSyntax(syntax) {
|
|
|
561
561
|
tokens[tokens.length - 3].range = tokens[tokens.length - 2].range;
|
|
562
562
|
}
|
|
563
563
|
tokens.splice(tokens.length - 2, 2);
|
|
564
|
-
if (tokens.at(-1).val
|
|
564
|
+
if (tokens.at(-1).val === "function-token") {
|
|
565
565
|
// consume the closing ')'
|
|
566
566
|
stack.push(tokens.at(-1));
|
|
567
567
|
}
|
|
@@ -587,19 +587,19 @@ function parseSyntax(syntax) {
|
|
|
587
587
|
break;
|
|
588
588
|
case ValidationTokenEnum.CloseBracket:
|
|
589
589
|
while (true) {
|
|
590
|
-
if (stack.at(-1).typ
|
|
590
|
+
if (stack.at(-1).typ === ValidationTokenEnum.AmpersandToken) {
|
|
591
591
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
592
592
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
593
593
|
stack.pop();
|
|
594
594
|
continue;
|
|
595
595
|
}
|
|
596
|
-
else if (stack.at(-1).typ
|
|
596
|
+
else if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
|
|
597
597
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
598
598
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
599
599
|
stack.pop();
|
|
600
600
|
continue;
|
|
601
601
|
}
|
|
602
|
-
if (stack.at(-1).typ
|
|
602
|
+
if (stack.at(-1).typ === ValidationTokenEnum.PipeToken) {
|
|
603
603
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
604
604
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
605
605
|
stack.pop();
|
|
@@ -614,6 +614,32 @@ function parseSyntax(syntax) {
|
|
|
614
614
|
// }
|
|
615
615
|
{
|
|
616
616
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
617
|
+
// the lower bound of a range may be '-∞': <integer [-∞,-1]>
|
|
618
|
+
const isNegativeInfinity = tokens[index + 1]?.typ === ValidationTokenEnum.Keyword &&
|
|
619
|
+
tokens[index + 1].val === "-" &&
|
|
620
|
+
tokens[index + 2]?.typ === ValidationTokenEnum.InfinityToken;
|
|
621
|
+
if (isNegativeInfinity &&
|
|
622
|
+
(tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
|
|
623
|
+
tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
|
|
624
|
+
tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
|
|
625
|
+
tokens[index + 3]?.typ === ValidationTokenEnum.Comma &&
|
|
626
|
+
(tokens[index + 4]?.typ === ValidationTokenEnum.Number ||
|
|
627
|
+
tokens[index + 4]?.typ === ValidationTokenEnum.Dimension ||
|
|
628
|
+
tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken) &&
|
|
629
|
+
tokens[index + 5]?.typ === ValidationTokenEnum.CloseBracket) {
|
|
630
|
+
stack.pop();
|
|
631
|
+
// a null bound is unbounded
|
|
632
|
+
Object.assign(tokens[index - 2], {
|
|
633
|
+
range: {
|
|
634
|
+
min: null,
|
|
635
|
+
max: tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken
|
|
636
|
+
? null
|
|
637
|
+
: tokens[index + 4],
|
|
638
|
+
},
|
|
639
|
+
});
|
|
640
|
+
tokens.splice(index - 1, 8);
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
617
643
|
if ((tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
|
|
618
644
|
tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
|
|
619
645
|
tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
|
|
@@ -672,13 +698,13 @@ function parseSyntax(syntax) {
|
|
|
672
698
|
// stack.pop();
|
|
673
699
|
// continue;
|
|
674
700
|
// } else
|
|
675
|
-
if (stack.at(-1).typ
|
|
701
|
+
if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
|
|
676
702
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
677
703
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
678
704
|
stack.pop();
|
|
679
705
|
continue;
|
|
680
706
|
}
|
|
681
|
-
if (stack.at(-1)?.typ
|
|
707
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
682
708
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
683
709
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
684
710
|
stack.pop();
|
|
@@ -693,7 +719,7 @@ function parseSyntax(syntax) {
|
|
|
693
719
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
694
720
|
const slice = tokens.slice(index + 1, -1);
|
|
695
721
|
if (slice.length === 1 || slice.length === 3) {
|
|
696
|
-
if (slice[0].typ
|
|
722
|
+
if (slice[0].typ === ValidationTokenEnum.Number) {
|
|
697
723
|
Object.assign(tokens[index - 1], {
|
|
698
724
|
match: {
|
|
699
725
|
min: slice[0],
|
|
@@ -715,7 +741,7 @@ function parseSyntax(syntax) {
|
|
|
715
741
|
Object.assign(tokens[index - 1], {
|
|
716
742
|
match: {
|
|
717
743
|
min: slice[0],
|
|
718
|
-
max: slice[2].typ
|
|
744
|
+
max: slice[2].typ === ValidationTokenEnum.InfinityToken
|
|
719
745
|
? Number.POSITIVE_INFINITY
|
|
720
746
|
: slice[2],
|
|
721
747
|
},
|
|
@@ -743,7 +769,7 @@ function parseSyntax(syntax) {
|
|
|
743
769
|
// sliceIndex = tokens.length - 2;
|
|
744
770
|
// } else
|
|
745
771
|
// {
|
|
746
|
-
isGroup = tokens.at(-3)?.typ
|
|
772
|
+
isGroup = tokens.at(-3)?.typ === ValidationTokenEnum.Comma;
|
|
747
773
|
if (isGroup) {
|
|
748
774
|
sliceIndex = tokens.length - 3;
|
|
749
775
|
}
|
|
@@ -766,12 +792,12 @@ function parseSyntax(syntax) {
|
|
|
766
792
|
// if (tokens.at(-2)?.isOptional && tokens.at(-2)!.typ !== ValidationTokenEnum.OptionalGroupToken) {
|
|
767
793
|
// sliceIndex = tokens.length - 2;
|
|
768
794
|
// } else
|
|
769
|
-
if (tokens.at(-2).typ
|
|
795
|
+
if (tokens.at(-2).typ === ValidationTokenEnum.Whitespace &&
|
|
770
796
|
tokens.at(-3)?.isOptional &&
|
|
771
797
|
tokens.at(-3).typ !== ValidationTokenEnum.OptionalGroupToken) {
|
|
772
798
|
sliceIndex = tokens.length - 3;
|
|
773
799
|
}
|
|
774
|
-
if (sliceIndex
|
|
800
|
+
if (sliceIndex !== -1) {
|
|
775
801
|
if (tokens[sliceIndex].isList) {
|
|
776
802
|
tokens.pop();
|
|
777
803
|
}
|
|
@@ -801,7 +827,7 @@ function parseSyntax(syntax) {
|
|
|
801
827
|
}
|
|
802
828
|
}
|
|
803
829
|
if (stack.length > 0) {
|
|
804
|
-
if (stack.at(-1)?.typ
|
|
830
|
+
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
805
831
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
806
832
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
|
|
807
833
|
stack.pop();
|
|
@@ -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
|
var ValidationTokenEnum;
|
|
@@ -89,6 +89,10 @@ var ValidationSyntaxGroupEnum;
|
|
|
89
89
|
ValidationSyntaxGroupEnum["Declarations"] = "declarations";
|
|
90
90
|
ValidationSyntaxGroupEnum["Functions"] = "functions";
|
|
91
91
|
ValidationSyntaxGroupEnum["Syntaxes"] = "syntaxes";
|
|
92
|
+
/**
|
|
93
|
+
* value types, keyed by their name without the angle brackets (`color` for `<color>`). referenced as {@link Syntaxes}
|
|
94
|
+
*/
|
|
95
|
+
ValidationSyntaxGroupEnum["Types"] = "types";
|
|
92
96
|
ValidationSyntaxGroupEnum["Selectors"] = "selectors";
|
|
93
97
|
ValidationSyntaxGroupEnum["AtRules"] = "atRules";
|
|
94
98
|
ValidationSyntaxGroupEnum["Units"] = "units";
|
|
@@ -1,28 +1,12 @@
|
|
|
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 } from '../../ast/types.js';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* remove comma and comment tokens
|
|
12
|
-
* @param arena
|
|
13
|
-
* @param tokenList
|
|
14
|
-
*/
|
|
15
|
-
function stripCommaToken(arena, tokenList) {
|
|
16
|
-
let result = [];
|
|
17
|
-
for (let i = 0; i < tokenList.length; i++) {
|
|
18
|
-
const typ = arena.dataTypes[tokenList[i]];
|
|
19
|
-
if (typ == EnumToken.CommentTokenType || typ == EnumToken.CommaTokenType) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
result.push(tokenList[i]);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
10
|
/**
|
|
27
11
|
* split a token list
|
|
28
12
|
* @param arena
|
|
@@ -47,4 +31,4 @@ function splitTokenList(arena, tokenList, split = [EnumToken.CommaTokenType], in
|
|
|
47
31
|
return result;
|
|
48
32
|
}
|
|
49
33
|
|
|
50
|
-
export { splitTokenList
|
|
34
|
+
export { splitTokenList };
|