@tbela99/css-parser 1.6.6 → 1.6.8
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 +106 -0
- package/README.md +1 -58
- package/architecture.png +0 -0
- package/dist/index-umd-web.js +731 -459
- package/dist/index.cjs +724 -459
- package/dist/index.d.ts +67 -11
- package/dist/package.json.js +10 -0
- package/dist/{data → src/data}/properties.json.js +7 -0
- package/dist/{data → src/data}/validation.json.js +7 -0
- package/dist/{lib → src/lib}/ast/clone.js +7 -0
- package/dist/{lib → src/lib}/ast/expand.js +19 -10
- package/dist/{lib → src/lib}/ast/features/calc.js +7 -0
- package/dist/{lib → src/lib}/ast/features/if.js +7 -0
- package/dist/{lib → src/lib}/ast/features/index.js +7 -0
- package/dist/{lib → src/lib}/ast/features/inlinecssvariables.js +7 -0
- package/dist/{lib → src/lib}/ast/features/prefix.js +8 -3
- package/dist/{lib → src/lib}/ast/features/shorthand.js +7 -0
- package/dist/{lib → src/lib}/ast/features/transform.js +8 -1
- package/dist/{lib → src/lib}/ast/features/type.js +7 -0
- package/dist/{lib → src/lib}/ast/find.js +7 -0
- package/dist/{lib → src/lib}/ast/math/expression.js +7 -0
- package/dist/{lib → src/lib}/ast/math/math.js +7 -0
- package/dist/{lib → src/lib}/ast/minify.js +7 -0
- package/dist/{lib → src/lib}/ast/node.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/compute.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/matrix.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/minify.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/perspective.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/rotate.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/scale.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/skew.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/translate.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/utils.js +7 -0
- package/dist/{lib → src/lib}/ast/types.js +28 -9
- package/dist/{lib → src/lib}/ast/walk.js +16 -0
- package/dist/{lib → src/lib}/fs/resolve.js +7 -0
- package/dist/{lib → src/lib}/parser/declaration/list.js +24 -8
- package/dist/{lib → src/lib}/parser/declaration/map.js +9 -1
- package/dist/{lib → src/lib}/parser/declaration/set.js +7 -0
- package/dist/{lib → src/lib}/parser/linesmap.js +7 -0
- package/dist/{lib → src/lib}/parser/parse.js +93 -49
- package/dist/{lib → src/lib}/parser/source.js +7 -0
- package/dist/{lib → src/lib}/parser/tokenize.js +24 -3
- package/dist/{lib → src/lib}/parser/utils/angle.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-container.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-font-feature-values.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-generic.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-import.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-media.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-support.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-when-else.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/base64.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/cache.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/config.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/declaration.js +17 -0
- package/dist/{lib → src/lib}/parser/utils/eq.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/hash.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/selector.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/text.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/token.js +15 -4
- package/dist/{lib → src/lib}/parser/utils/type.js +7 -0
- package/dist/{lib → src/lib}/printer/render.js +20 -9
- package/dist/{lib → src/lib}/printer/sourcemap/lib/codec.js +7 -0
- package/dist/{lib → src/lib}/printer/sourcemap/sourcemap.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/a98rgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/alpha.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/cmyk.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/color-mix.js +139 -48
- package/dist/{lib → src/lib}/syntax/color/color.js +7 -1
- package/dist/{lib → src/lib}/syntax/color/hex.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/hsl.js +52 -38
- package/dist/{lib → src/lib}/syntax/color/hwb.js +90 -53
- package/dist/{lib → src/lib}/syntax/color/lab.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/lch.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/oklab.js +8 -1
- package/dist/{lib → src/lib}/syntax/color/oklch.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/p3.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/prophotorgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/rec2020.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/relative-color.js +36 -0
- package/dist/{lib → src/lib}/syntax/color/rgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/srgb.js +88 -58
- package/dist/{lib → src/lib}/syntax/color/utils/color-type.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/colorspace.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/components.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/distance.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/make-color.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/matrix.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/xyz.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/xyzd50.js +7 -0
- package/dist/{lib → src/lib}/syntax/constants.js +7 -0
- package/dist/{lib → src/lib}/syntax/syntax.js +7 -0
- package/dist/{lib → src/lib}/validation/config.js +7 -0
- package/dist/{lib → src/lib}/validation/match.js +37 -19
- package/dist/{lib → src/lib}/validation/parser/parse.js +7 -0
- package/dist/{lib → src/lib}/validation/parser/typedef.js +7 -0
- package/dist/{lib → src/lib}/validation/utils/list.js +7 -0
- package/dist/{node.js → src/node.js} +8 -0
- package/dist/{types.js → src/types.js} +7 -0
- package/dist/{utils → src/utils}/sync.js +7 -0
- package/dist/{web.js → src/web.js} +8 -0
- package/package.json +7 -6
- package/dist/lib/syntax/color/hsv.js +0 -20
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { PARENT, TOKENS } from '../syntax/constants.js';
|
|
2
9
|
|
|
3
10
|
/**
|
|
@@ -36,6 +43,7 @@ var WalkerEvent;
|
|
|
36
43
|
*/
|
|
37
44
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
38
45
|
})(WalkerEvent || (WalkerEvent = {}));
|
|
46
|
+
const maxQueueLength = 25000;
|
|
39
47
|
/**
|
|
40
48
|
* Walk ast nodes
|
|
41
49
|
* @param node initial node
|
|
@@ -139,6 +147,10 @@ function* walk(node, filter, reverse) {
|
|
|
139
147
|
},
|
|
140
148
|
};
|
|
141
149
|
while ((node = parents[i++])) {
|
|
150
|
+
if (i > maxQueueLength) {
|
|
151
|
+
parents.splice(0, maxQueueLength);
|
|
152
|
+
i -= maxQueueLength;
|
|
153
|
+
}
|
|
142
154
|
let option = null;
|
|
143
155
|
if (filter != null) {
|
|
144
156
|
// @ts-expect-error
|
|
@@ -282,6 +294,10 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
282
294
|
while (++i < stack.length) {
|
|
283
295
|
value = stack[i];
|
|
284
296
|
option = null;
|
|
297
|
+
if (i > maxQueueLength) {
|
|
298
|
+
stack.splice(0, maxQueueLength);
|
|
299
|
+
i -= maxQueueLength;
|
|
300
|
+
}
|
|
285
301
|
if (filter.fn != null && eventType & WalkerEvent.Enter) {
|
|
286
302
|
const isValid = filter.type == null ||
|
|
287
303
|
value.typ == filter.type ||
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { PropertySet } from './set.js';
|
|
2
9
|
import { getConfig } from '../utils/config.js';
|
|
3
10
|
import { PropertyMap } from './map.js';
|
|
@@ -26,9 +33,8 @@ class PropertyList {
|
|
|
26
33
|
let result;
|
|
27
34
|
for (const declaration of declarations) {
|
|
28
35
|
name = declaration.typ != EnumToken.DeclarationNodeType ? null : declaration.nam;
|
|
29
|
-
if (declaration[STATE]
|
|
30
|
-
|
|
31
|
-
declaration[STATE] == EnumAstNodeStatus.ValidationFailed ||
|
|
36
|
+
if (declaration[STATE] &
|
|
37
|
+
(EnumAstNodeStatus.Invalid | EnumAstNodeStatus.Unknown | EnumAstNodeStatus.ValidationFailed) ||
|
|
32
38
|
declaration.typ != EnumToken.DeclarationNodeType ||
|
|
33
39
|
equalsIgnoreCase("composes", name) ||
|
|
34
40
|
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
@@ -47,17 +53,17 @@ class PropertyList {
|
|
|
47
53
|
this.declarations.set(declaration.nam, declaration);
|
|
48
54
|
continue;
|
|
49
55
|
}
|
|
50
|
-
if (declaration[STATE]
|
|
56
|
+
if (declaration[STATE] & EnumAstNodeStatus.Unvalidated) {
|
|
51
57
|
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
|
|
52
58
|
if (syntaxRules != null) {
|
|
53
59
|
result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
|
|
54
|
-
declaration[STATE]
|
|
55
|
-
? EnumAstNodeStatus.Validated
|
|
56
|
-
|
|
60
|
+
declaration[STATE] |=
|
|
61
|
+
(result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed) &
|
|
62
|
+
~EnumAstNodeStatus.Unvalidated;
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
// do not compute shorthand for invalid declarations
|
|
60
|
-
if (declaration[STATE]
|
|
66
|
+
if (!(declaration[STATE] & EnumAstNodeStatus.Validated)) {
|
|
61
67
|
this.declarations.set(objectHash(declaration), declaration);
|
|
62
68
|
continue;
|
|
63
69
|
}
|
|
@@ -87,6 +93,16 @@ class PropertyList {
|
|
|
87
93
|
// @ts-ignore
|
|
88
94
|
shorthand = config.property[propertyName];
|
|
89
95
|
}
|
|
96
|
+
if (this.declarations.has(shorthand)) {
|
|
97
|
+
let existing = this.declarations.get(shorthand);
|
|
98
|
+
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
99
|
+
existing = existing.declarations.get(declaration.nam);
|
|
100
|
+
}
|
|
101
|
+
if (existing?.[STATE] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
102
|
+
declaration[STATE] & ~EnumAstNodeStatus.ImportantDeclaration) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
90
106
|
// @ts-ignore
|
|
91
107
|
if (shortHandType == "map") {
|
|
92
108
|
let owner = this;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { eq } from '../utils/eq.js';
|
|
2
9
|
import { getConfig } from '../utils/config.js';
|
|
3
10
|
import { matchType } from '../utils/type.js';
|
|
@@ -42,7 +49,8 @@ class PropertyMap {
|
|
|
42
49
|
const tokens = {};
|
|
43
50
|
const values = [];
|
|
44
51
|
const val = [[]];
|
|
45
|
-
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
52
|
+
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
53
|
+
// @ts-ignore
|
|
46
54
|
// @ts-ignore
|
|
47
55
|
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
48
56
|
val.push([]);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { eq } from '../utils/eq.js';
|
|
2
9
|
import { EnumToken } from '../../ast/types.js';
|
|
3
10
|
import { isLength } from '../../syntax/syntax.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
|
|
2
9
|
import { camelize, equalsIgnoreCase, dasherize } from './utils/text.js';
|
|
3
10
|
import { renderValue } from '../printer/render.js';
|
|
@@ -304,6 +311,9 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
304
311
|
let key;
|
|
305
312
|
let value;
|
|
306
313
|
let i;
|
|
314
|
+
const allVisitorsHandlers = new Set();
|
|
315
|
+
const preAllVisitorsHandlers = new Set();
|
|
316
|
+
const postAllVisitorsHandlers = new Set();
|
|
307
317
|
const valuesHandlers = new Map();
|
|
308
318
|
const preValuesHandlers = new Map();
|
|
309
319
|
const postValuesHandlers = new Map();
|
|
@@ -404,6 +414,21 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
404
414
|
errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
|
|
405
415
|
}
|
|
406
416
|
}
|
|
417
|
+
else if (key == "All" || key == "visitor") {
|
|
418
|
+
if (typeof value == "function") {
|
|
419
|
+
allVisitorsHandlers.add(value);
|
|
420
|
+
}
|
|
421
|
+
else if (typeof value == "object") {
|
|
422
|
+
if ("type" in value && "handler" in value && value.type in WalkerEvent) {
|
|
423
|
+
if (value.type == WalkerEvent.Enter) {
|
|
424
|
+
preAllVisitorsHandlers.add(value.handler);
|
|
425
|
+
}
|
|
426
|
+
else if (value.type == WalkerEvent.Leave) {
|
|
427
|
+
postAllVisitorsHandlers.add(value.handler);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
407
432
|
else {
|
|
408
433
|
errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
|
|
409
434
|
}
|
|
@@ -427,10 +452,25 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
427
452
|
if (postValuesHandlers.size > 0) {
|
|
428
453
|
allHandlers.push(postValuesHandlers);
|
|
429
454
|
}
|
|
430
|
-
|
|
455
|
+
const result = {
|
|
431
456
|
allHandlers,
|
|
432
|
-
includeTokens: preValuesHandlers.size > 0 ||
|
|
457
|
+
includeTokens: preValuesHandlers.size > 0 ||
|
|
458
|
+
valuesHandlers.size > 0 ||
|
|
459
|
+
postValuesHandlers.size > 0 ||
|
|
460
|
+
allVisitorsHandlers.size > 0 ||
|
|
461
|
+
preAllVisitorsHandlers.size > 0 ||
|
|
462
|
+
postAllVisitorsHandlers.size > 0,
|
|
433
463
|
};
|
|
464
|
+
if (allVisitorsHandlers.size > 0) {
|
|
465
|
+
result.allVisitorsHandlers = allVisitorsHandlers;
|
|
466
|
+
}
|
|
467
|
+
if (preAllVisitorsHandlers.size > 0) {
|
|
468
|
+
result.preAllVisitorsHandlers = preAllVisitorsHandlers;
|
|
469
|
+
}
|
|
470
|
+
if (postAllVisitorsHandlers.size > 0) {
|
|
471
|
+
result.postAllVisitorsHandlers = postAllVisitorsHandlers;
|
|
472
|
+
}
|
|
473
|
+
return result;
|
|
434
474
|
}
|
|
435
475
|
/**
|
|
436
476
|
* Parse css string
|
|
@@ -503,12 +543,10 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
503
543
|
// @ts-ignore ignore error
|
|
504
544
|
let parensMatch = 0;
|
|
505
545
|
let curlyBracketMatch = 0;
|
|
506
|
-
// let currentItemIndex: number;
|
|
507
546
|
ast[LOCSRCID] = options.source.id;
|
|
508
547
|
ast[LOCSTA] = 0;
|
|
509
548
|
while (!tokenizer.done()) {
|
|
510
549
|
tokenizer.next();
|
|
511
|
-
// item = (iter as Array<TokenizeResult>)[currentItemIndex];
|
|
512
550
|
if (tokenizer.unit != null) {
|
|
513
551
|
item = {
|
|
514
552
|
typ: tokenizer.typ,
|
|
@@ -654,7 +692,6 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
654
692
|
parensMatch = 0;
|
|
655
693
|
curlyBracketMatch = 0;
|
|
656
694
|
}
|
|
657
|
-
// }
|
|
658
695
|
}
|
|
659
696
|
if (tokens.length > 0) {
|
|
660
697
|
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
@@ -724,6 +761,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
724
761
|
}
|
|
725
762
|
parens = null;
|
|
726
763
|
handlers.length = 0;
|
|
764
|
+
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
765
|
+
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
766
|
+
}
|
|
727
767
|
genericKey =
|
|
728
768
|
nodes[i].typ == EnumToken.DeclarationNodeType
|
|
729
769
|
? "Declaration"
|
|
@@ -743,6 +783,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
743
783
|
: nodes[i].typ == EnumToken.KeyframesAtRuleNodeType
|
|
744
784
|
? camelize(nodes[i].val)
|
|
745
785
|
: null;
|
|
786
|
+
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
787
|
+
handlers.push(...visitors.allVisitorsHandlers);
|
|
788
|
+
}
|
|
746
789
|
for (const map of visitors.allHandlers) {
|
|
747
790
|
// @ts-ignore
|
|
748
791
|
if (genericKey != null && map.has(genericKey)) {
|
|
@@ -751,20 +794,6 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
751
794
|
if (typeof handler == "function") {
|
|
752
795
|
handlers.push(handler);
|
|
753
796
|
}
|
|
754
|
-
// else if (Array.isArray(handler)) {
|
|
755
|
-
// for (const h of handler) {
|
|
756
|
-
// if (typeof h == "function") {
|
|
757
|
-
// handlers.push(h);
|
|
758
|
-
// }
|
|
759
|
-
// // @ts-ignore
|
|
760
|
-
// else if (h[keyName] != null) {
|
|
761
|
-
// // @ts-ignore
|
|
762
|
-
// handlers.push(h[keyName]);
|
|
763
|
-
// }
|
|
764
|
-
// }
|
|
765
|
-
// } else if (typeof handler.handler! == "function") {
|
|
766
|
-
// handlers.push(handler.handler);
|
|
767
|
-
// }
|
|
768
797
|
// @ts-ignore
|
|
769
798
|
else if (typeof handler[keyName] == "function") {
|
|
770
799
|
// @ts-ignore
|
|
@@ -797,6 +826,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
797
826
|
}
|
|
798
827
|
}
|
|
799
828
|
}
|
|
829
|
+
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
830
|
+
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
831
|
+
}
|
|
800
832
|
if (handlers.length == 0) {
|
|
801
833
|
continue;
|
|
802
834
|
}
|
|
@@ -836,14 +868,14 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
836
868
|
if (invalidNodes.length > 0) {
|
|
837
869
|
let count = invalidNodes.length;
|
|
838
870
|
for (const { node, parent } of walk(ast)) {
|
|
839
|
-
if (options.lenient && node[STATE]
|
|
871
|
+
if (options.lenient && node[STATE] & EnumAstNodeStatus.Unknown) {
|
|
840
872
|
continue;
|
|
841
873
|
}
|
|
842
|
-
if (node[STATE]
|
|
843
|
-
node[STATE]
|
|
844
|
-
node[STATE]
|
|
845
|
-
node[STATE]
|
|
846
|
-
node[STATE]
|
|
874
|
+
if (node[STATE] & EnumAstNodeStatus.Invalid ||
|
|
875
|
+
node[STATE] & EnumAstNodeStatus.Unknown ||
|
|
876
|
+
node[STATE] & EnumAstNodeStatus.Unparsed ||
|
|
877
|
+
node[STATE] & EnumAstNodeStatus.Malformed ||
|
|
878
|
+
node[STATE] & EnumAstNodeStatus.Disallowed) {
|
|
847
879
|
// @ts-ignore
|
|
848
880
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
849
881
|
node[PARENT] = null;
|
|
@@ -1716,6 +1748,9 @@ async function doParse(iter, options = {}) {
|
|
|
1716
1748
|
}
|
|
1717
1749
|
parens = null;
|
|
1718
1750
|
handlers.length = 0;
|
|
1751
|
+
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
1752
|
+
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
1753
|
+
}
|
|
1719
1754
|
genericKey =
|
|
1720
1755
|
nodes[i].typ == EnumToken.DeclarationNodeType
|
|
1721
1756
|
? "Declaration"
|
|
@@ -1735,6 +1770,9 @@ async function doParse(iter, options = {}) {
|
|
|
1735
1770
|
: nodes[i].typ == EnumToken.KeyframesAtRuleNodeType
|
|
1736
1771
|
? camelize(nodes[i].val)
|
|
1737
1772
|
: null;
|
|
1773
|
+
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
1774
|
+
handlers.push(...visitors.allVisitorsHandlers);
|
|
1775
|
+
}
|
|
1738
1776
|
for (const map of visitors.allHandlers) {
|
|
1739
1777
|
// @ts-ignore
|
|
1740
1778
|
if (genericKey != null && map.has(genericKey)) {
|
|
@@ -1789,6 +1827,9 @@ async function doParse(iter, options = {}) {
|
|
|
1789
1827
|
}
|
|
1790
1828
|
}
|
|
1791
1829
|
}
|
|
1830
|
+
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
1831
|
+
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
1832
|
+
}
|
|
1792
1833
|
if (handlers.length == 0) {
|
|
1793
1834
|
continue;
|
|
1794
1835
|
}
|
|
@@ -1831,14 +1872,14 @@ async function doParse(iter, options = {}) {
|
|
|
1831
1872
|
if (invalidNodes.length > 0) {
|
|
1832
1873
|
let count = invalidNodes.length;
|
|
1833
1874
|
for (const { node, parent } of walk(ast)) {
|
|
1834
|
-
if (options.lenient && node[STATE]
|
|
1875
|
+
if (options.lenient && node[STATE] & EnumAstNodeStatus.Unknown) {
|
|
1835
1876
|
continue;
|
|
1836
1877
|
}
|
|
1837
|
-
if (node[STATE]
|
|
1838
|
-
node[STATE]
|
|
1839
|
-
node[STATE]
|
|
1840
|
-
node[STATE]
|
|
1841
|
-
node[STATE]
|
|
1878
|
+
if (node[STATE] & EnumAstNodeStatus.Invalid ||
|
|
1879
|
+
node[STATE] & EnumAstNodeStatus.Unknown ||
|
|
1880
|
+
node[STATE] & EnumAstNodeStatus.Unparsed ||
|
|
1881
|
+
node[STATE] & EnumAstNodeStatus.Malformed ||
|
|
1882
|
+
node[STATE] & EnumAstNodeStatus.Disallowed) {
|
|
1842
1883
|
// @ts-ignore
|
|
1843
1884
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
1844
1885
|
node[PARENT] = null;
|
|
@@ -2569,11 +2610,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2569
2610
|
if (node == null) {
|
|
2570
2611
|
return null;
|
|
2571
2612
|
}
|
|
2572
|
-
if (node[STATE]
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2613
|
+
if (node[STATE] &
|
|
2614
|
+
(EnumAstNodeStatus.Invalid |
|
|
2615
|
+
EnumAstNodeStatus.Disallowed |
|
|
2616
|
+
EnumAstNodeStatus.Unknown |
|
|
2617
|
+
EnumAstNodeStatus.Unparsed |
|
|
2618
|
+
EnumAstNodeStatus.Malformed)) {
|
|
2577
2619
|
invalidNodes.push(node);
|
|
2578
2620
|
}
|
|
2579
2621
|
stats.nodesCount++;
|
|
@@ -2591,11 +2633,11 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2591
2633
|
context.chi.push(node);
|
|
2592
2634
|
node[PARENT] = context;
|
|
2593
2635
|
node[ROOT] = context[ROOT];
|
|
2594
|
-
if (node[STATE]
|
|
2595
|
-
node[STATE]
|
|
2596
|
-
node[STATE]
|
|
2597
|
-
node[STATE]
|
|
2598
|
-
node[STATE]
|
|
2636
|
+
if (node[STATE] & EnumAstNodeStatus.Invalid ||
|
|
2637
|
+
node[STATE] & EnumAstNodeStatus.Disallowed ||
|
|
2638
|
+
node[STATE] & EnumAstNodeStatus.Unknown ||
|
|
2639
|
+
node[STATE] & EnumAstNodeStatus.Unparsed ||
|
|
2640
|
+
node[STATE] & EnumAstNodeStatus.Malformed) {
|
|
2599
2641
|
invalidNodes.push(node);
|
|
2600
2642
|
}
|
|
2601
2643
|
return node;
|
|
@@ -2605,7 +2647,9 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2605
2647
|
node[PARENT] = context;
|
|
2606
2648
|
node[ROOT] = context[ROOT];
|
|
2607
2649
|
if (context.typ === EnumToken.StyleSheetNodeType && node.typ === EnumToken.DeclarationNodeType) {
|
|
2608
|
-
node[STATE]
|
|
2650
|
+
node[STATE] |=
|
|
2651
|
+
EnumAstNodeStatus.Invalid &
|
|
2652
|
+
~(EnumAstNodeStatus.Validated | EnumAstNodeStatus.Unvalidated | EnumAstNodeStatus.Unparsed);
|
|
2609
2653
|
errors.push({
|
|
2610
2654
|
message: "<declaration> not allowed in <stylesheet>",
|
|
2611
2655
|
action: "drop",
|
|
@@ -2616,11 +2660,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2616
2660
|
else if (options.lenient || node.typ === EnumToken.DeclarationNodeType) {
|
|
2617
2661
|
context.chi.push(node);
|
|
2618
2662
|
}
|
|
2619
|
-
if (node[STATE]
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2663
|
+
if (node[STATE] &
|
|
2664
|
+
(EnumAstNodeStatus.Invalid |
|
|
2665
|
+
EnumAstNodeStatus.Disallowed |
|
|
2666
|
+
EnumAstNodeStatus.Unknown |
|
|
2667
|
+
EnumAstNodeStatus.Unparsed |
|
|
2668
|
+
EnumAstNodeStatus.Malformed)) {
|
|
2624
2669
|
invalidNodes.push(node);
|
|
2625
2670
|
}
|
|
2626
2671
|
}
|
|
@@ -2645,7 +2690,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2645
2690
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
2646
2691
|
const blockAllowed = syntaxRules?.getBlockRules() != null;
|
|
2647
2692
|
if (syntaxRules == null) {
|
|
2648
|
-
// if (!options.lenient) {
|
|
2649
2693
|
errors.push({
|
|
2650
2694
|
action: "drop",
|
|
2651
2695
|
node: atRule,
|
|
@@ -3362,7 +3406,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3362
3406
|
stream[index][LOCEND] = stream[i][LOCEND];
|
|
3363
3407
|
Object.assign(stream[index], {
|
|
3364
3408
|
typ: tokensfuncDefMap.get(stream[index].typ),
|
|
3365
|
-
chi: stream.splice(index + 1, i - index - 1),
|
|
3409
|
+
chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)),
|
|
3366
3410
|
});
|
|
3367
3411
|
i = index;
|
|
3368
3412
|
stream.splice(index + 1, 1);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
2
9
|
import { wildCardFuncs, whenElseFunc, mathFuncs, timingFunc, supportFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc, colorsFunc, transformFunctions, pseudoElements } from '../syntax/constants.js';
|
|
3
10
|
import { isWhiteSpace, isNewLine, isDigit, isLetter, isIdentStart, isIdentCodepoint, isNonPrintable, timeUnits, angleUnits, flexUnits, dimensionUnits, resolutionUnits, frequencyUnits } from '../syntax/syntax.js';
|
|
@@ -41,7 +48,7 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) {
|
|
|
41
48
|
SymbolsMapTokens[""] = EnumToken.DelimTokenType;
|
|
42
49
|
SymbolsMapTokens["+"] = EnumToken.Plus;
|
|
43
50
|
SymbolsMapTokens["="] = EnumToken.DelimTokenType;
|
|
44
|
-
SymbolsMapTokens["|"] = EnumToken.
|
|
51
|
+
SymbolsMapTokens["|"] = EnumToken.PipeTokenType;
|
|
45
52
|
SymbolsMapTokens["||"] = EnumToken.ColumnCombinatorTokenType;
|
|
46
53
|
SymbolsMapTokens["|="] = EnumToken.DashMatchTokenType;
|
|
47
54
|
SymbolsMapTokens["&"] = EnumToken.NestingSelectorTokenType;
|
|
@@ -700,7 +707,6 @@ class Tokenizer {
|
|
|
700
707
|
if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
701
708
|
// eof
|
|
702
709
|
if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) {
|
|
703
|
-
// this.next(parseInfo, position);
|
|
704
710
|
return 0;
|
|
705
711
|
}
|
|
706
712
|
// \n \r \f \v
|
|
@@ -1473,7 +1479,7 @@ class Tokenizer {
|
|
|
1473
1479
|
return this.makeToken(parseInfo, EnumToken.DashMatchTokenType);
|
|
1474
1480
|
}
|
|
1475
1481
|
this.advance(parseInfo);
|
|
1476
|
-
return this.makeToken(parseInfo, EnumToken.
|
|
1482
|
+
return this.makeToken(parseInfo, EnumToken.PipeTokenType);
|
|
1477
1483
|
case 33 /* TokenMap.EXCLAMATION */:
|
|
1478
1484
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
1479
1485
|
return this.makeToken(parseInfo);
|
|
@@ -1539,6 +1545,21 @@ class Tokenizer {
|
|
|
1539
1545
|
return this.makeToken(parseInfo, EnumToken.CDOCOMMTokenType);
|
|
1540
1546
|
}
|
|
1541
1547
|
}
|
|
1548
|
+
{
|
|
1549
|
+
const startPosition = parseInfo.position - parseInfo.offset;
|
|
1550
|
+
let offset = 1;
|
|
1551
|
+
let charCode = parseInfo.stream.charCodeAt(startPosition + offset);
|
|
1552
|
+
if (isLetter(charCode)) {
|
|
1553
|
+
charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
|
|
1554
|
+
while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) {
|
|
1555
|
+
charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
|
|
1556
|
+
}
|
|
1557
|
+
if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) {
|
|
1558
|
+
this.advance(parseInfo, offset);
|
|
1559
|
+
return this.makeToken(parseInfo, EnumToken.CssTypeTokenType);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1542
1563
|
break;
|
|
1543
1564
|
case 35 /* TokenMap.HASH */:
|
|
1544
1565
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { tokensfuncDefMap, LOCSTA, mFGT, mFLT, LOCEND, LOCSRCID } from '../../syntax/constants.js';
|
|
3
10
|
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
2
9
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
3
10
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { tokensfuncDefMap, LOCSTA } from '../../syntax/constants.js';
|
|
3
10
|
import { equalsIgnoreCase } from './text.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
3
10
|
import { trimArray } from '../../validation/match.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { evaluate } from '../../ast/math/expression.js';
|
|
3
10
|
import { gcd } from '../../ast/math/math.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { pseudoElements, LOCEND, tokensfuncDefMap, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
|
|
3
10
|
import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { EnumToken } from '../../ast/types.js';
|
|
2
9
|
import { trimArray } from '../../validation/match.js';
|
|
3
10
|
import { tokensfuncDefMap, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
2
9
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
3
10
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|