@tbela99/css-parser 0.1.0 → 0.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/README.md +205 -2
- package/dist/config.json.js +386 -4
- package/dist/index-umd-web.js +1540 -665
- package/dist/index.cjs +1540 -665
- package/dist/index.d.ts +498 -692
- package/dist/lib/ast/expand.js +11 -11
- package/dist/lib/ast/features/calc.js +17 -48
- package/dist/lib/ast/features/inlinecssvariables.js +42 -27
- package/dist/lib/ast/features/shorthand.js +4 -3
- package/dist/lib/ast/features/utils/math.js +95 -0
- package/dist/lib/ast/minify.js +34 -29
- package/dist/lib/ast/types.js +91 -78
- package/dist/lib/ast/walk.js +18 -5
- package/dist/lib/iterable/set.js +48 -0
- package/dist/lib/iterable/weakmap.js +53 -0
- package/dist/lib/parser/declaration/list.js +3 -3
- package/dist/lib/parser/declaration/map.js +53 -5
- package/dist/lib/parser/declaration/set.js +2 -2
- package/dist/lib/parser/parse.js +561 -361
- package/dist/lib/parser/tokenize.js +42 -13
- package/dist/lib/parser/utils/type.js +7 -2
- package/dist/lib/renderer/render.js +88 -41
- package/dist/node/index.js +8 -12
- package/dist/web/index.js +8 -12
- package/package.json +7 -5
- /package/dist/lib/ast/{utiles → utils}/minifyfeature.js +0 -0
package/dist/index-umd-web.js
CHANGED
|
@@ -4,91 +4,104 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CSSParser = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
exports.NodeType = void 0;
|
|
8
|
-
(function (NodeType) {
|
|
9
|
-
NodeType[NodeType["CommentNodeType"] = 0] = "CommentNodeType";
|
|
10
|
-
NodeType[NodeType["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
|
11
|
-
NodeType[NodeType["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
12
|
-
NodeType[NodeType["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
13
|
-
NodeType[NodeType["RuleNodeType"] = 4] = "RuleNodeType";
|
|
14
|
-
NodeType[NodeType["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
15
|
-
})(exports.NodeType || (exports.NodeType = {}));
|
|
16
7
|
exports.EnumToken = void 0;
|
|
17
8
|
(function (EnumToken) {
|
|
18
9
|
EnumToken[EnumToken["CommentTokenType"] = 0] = "CommentTokenType";
|
|
19
10
|
EnumToken[EnumToken["CDOCOMMTokenType"] = 1] = "CDOCOMMTokenType";
|
|
20
|
-
EnumToken[EnumToken["
|
|
21
|
-
EnumToken[EnumToken["
|
|
22
|
-
EnumToken[EnumToken["
|
|
23
|
-
EnumToken[EnumToken["
|
|
24
|
-
EnumToken[EnumToken["
|
|
25
|
-
EnumToken[EnumToken["
|
|
26
|
-
EnumToken[EnumToken["
|
|
27
|
-
EnumToken[EnumToken["
|
|
28
|
-
EnumToken[EnumToken["
|
|
29
|
-
EnumToken[EnumToken["
|
|
30
|
-
EnumToken[EnumToken["
|
|
31
|
-
EnumToken[EnumToken["
|
|
32
|
-
EnumToken[EnumToken["
|
|
33
|
-
EnumToken[EnumToken["
|
|
34
|
-
EnumToken[EnumToken["
|
|
35
|
-
EnumToken[EnumToken["
|
|
36
|
-
EnumToken[EnumToken["
|
|
37
|
-
EnumToken[EnumToken["
|
|
38
|
-
EnumToken[EnumToken["
|
|
39
|
-
EnumToken[EnumToken["
|
|
40
|
-
EnumToken[EnumToken["
|
|
41
|
-
EnumToken[EnumToken["
|
|
42
|
-
EnumToken[EnumToken["
|
|
43
|
-
EnumToken[EnumToken["
|
|
44
|
-
EnumToken[EnumToken["
|
|
45
|
-
EnumToken[EnumToken["
|
|
46
|
-
EnumToken[EnumToken["
|
|
47
|
-
EnumToken[EnumToken["
|
|
48
|
-
EnumToken[EnumToken["
|
|
49
|
-
EnumToken[EnumToken["
|
|
50
|
-
EnumToken[EnumToken["
|
|
51
|
-
EnumToken[EnumToken["
|
|
52
|
-
EnumToken[EnumToken["
|
|
53
|
-
EnumToken[EnumToken["
|
|
54
|
-
EnumToken[EnumToken["
|
|
55
|
-
EnumToken[EnumToken["
|
|
56
|
-
EnumToken[EnumToken["
|
|
57
|
-
EnumToken[EnumToken["
|
|
58
|
-
EnumToken[EnumToken["
|
|
59
|
-
EnumToken[EnumToken["
|
|
60
|
-
EnumToken[EnumToken["
|
|
61
|
-
EnumToken[EnumToken["
|
|
62
|
-
EnumToken[EnumToken["
|
|
63
|
-
EnumToken[EnumToken["
|
|
64
|
-
EnumToken[EnumToken["
|
|
65
|
-
EnumToken[EnumToken["
|
|
66
|
-
EnumToken[EnumToken["
|
|
11
|
+
EnumToken[EnumToken["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
12
|
+
EnumToken[EnumToken["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
13
|
+
EnumToken[EnumToken["RuleNodeType"] = 4] = "RuleNodeType";
|
|
14
|
+
EnumToken[EnumToken["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
15
|
+
EnumToken[EnumToken["LiteralTokenType"] = 6] = "LiteralTokenType";
|
|
16
|
+
EnumToken[EnumToken["IdenTokenType"] = 7] = "IdenTokenType";
|
|
17
|
+
EnumToken[EnumToken["DashedIdenTokenType"] = 8] = "DashedIdenTokenType";
|
|
18
|
+
EnumToken[EnumToken["CommaTokenType"] = 9] = "CommaTokenType";
|
|
19
|
+
EnumToken[EnumToken["ColonTokenType"] = 10] = "ColonTokenType";
|
|
20
|
+
EnumToken[EnumToken["SemiColonTokenType"] = 11] = "SemiColonTokenType";
|
|
21
|
+
EnumToken[EnumToken["NumberTokenType"] = 12] = "NumberTokenType";
|
|
22
|
+
EnumToken[EnumToken["AtRuleTokenType"] = 13] = "AtRuleTokenType";
|
|
23
|
+
EnumToken[EnumToken["PercentageTokenType"] = 14] = "PercentageTokenType";
|
|
24
|
+
EnumToken[EnumToken["FunctionTokenType"] = 15] = "FunctionTokenType";
|
|
25
|
+
EnumToken[EnumToken["TimelineFunctionTokenType"] = 16] = "TimelineFunctionTokenType";
|
|
26
|
+
EnumToken[EnumToken["TimingFunctionTokenType"] = 17] = "TimingFunctionTokenType";
|
|
27
|
+
EnumToken[EnumToken["UrlFunctionTokenType"] = 18] = "UrlFunctionTokenType";
|
|
28
|
+
EnumToken[EnumToken["ImageFunctionTokenType"] = 19] = "ImageFunctionTokenType";
|
|
29
|
+
EnumToken[EnumToken["StringTokenType"] = 20] = "StringTokenType";
|
|
30
|
+
EnumToken[EnumToken["UnclosedStringTokenType"] = 21] = "UnclosedStringTokenType";
|
|
31
|
+
EnumToken[EnumToken["DimensionTokenType"] = 22] = "DimensionTokenType";
|
|
32
|
+
EnumToken[EnumToken["LengthTokenType"] = 23] = "LengthTokenType";
|
|
33
|
+
EnumToken[EnumToken["AngleTokenType"] = 24] = "AngleTokenType";
|
|
34
|
+
EnumToken[EnumToken["TimeTokenType"] = 25] = "TimeTokenType";
|
|
35
|
+
EnumToken[EnumToken["FrequencyTokenType"] = 26] = "FrequencyTokenType";
|
|
36
|
+
EnumToken[EnumToken["ResolutionTokenType"] = 27] = "ResolutionTokenType";
|
|
37
|
+
EnumToken[EnumToken["HashTokenType"] = 28] = "HashTokenType";
|
|
38
|
+
EnumToken[EnumToken["BlockStartTokenType"] = 29] = "BlockStartTokenType";
|
|
39
|
+
EnumToken[EnumToken["BlockEndTokenType"] = 30] = "BlockEndTokenType";
|
|
40
|
+
EnumToken[EnumToken["AttrStartTokenType"] = 31] = "AttrStartTokenType";
|
|
41
|
+
EnumToken[EnumToken["AttrEndTokenType"] = 32] = "AttrEndTokenType";
|
|
42
|
+
EnumToken[EnumToken["StartParensTokenType"] = 33] = "StartParensTokenType";
|
|
43
|
+
EnumToken[EnumToken["EndParensTokenType"] = 34] = "EndParensTokenType";
|
|
44
|
+
EnumToken[EnumToken["ParensTokenType"] = 35] = "ParensTokenType";
|
|
45
|
+
EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
|
|
46
|
+
EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
|
|
47
|
+
EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
|
|
48
|
+
EnumToken[EnumToken["LtTokenType"] = 39] = "LtTokenType";
|
|
49
|
+
EnumToken[EnumToken["LteTokenType"] = 40] = "LteTokenType";
|
|
50
|
+
EnumToken[EnumToken["GtTokenType"] = 41] = "GtTokenType";
|
|
51
|
+
EnumToken[EnumToken["GteTokenType"] = 42] = "GteTokenType";
|
|
52
|
+
EnumToken[EnumToken["PseudoClassTokenType"] = 43] = "PseudoClassTokenType";
|
|
53
|
+
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 44] = "PseudoClassFuncTokenType";
|
|
54
|
+
EnumToken[EnumToken["DelimTokenType"] = 45] = "DelimTokenType";
|
|
55
|
+
EnumToken[EnumToken["UrlTokenTokenType"] = 46] = "UrlTokenTokenType";
|
|
56
|
+
EnumToken[EnumToken["EOFTokenType"] = 47] = "EOFTokenType";
|
|
57
|
+
EnumToken[EnumToken["ImportantTokenType"] = 48] = "ImportantTokenType";
|
|
58
|
+
EnumToken[EnumToken["ColorTokenType"] = 49] = "ColorTokenType";
|
|
59
|
+
EnumToken[EnumToken["AttrTokenType"] = 50] = "AttrTokenType";
|
|
60
|
+
EnumToken[EnumToken["BadCommentTokenType"] = 51] = "BadCommentTokenType";
|
|
61
|
+
EnumToken[EnumToken["BadCdoTokenType"] = 52] = "BadCdoTokenType";
|
|
62
|
+
EnumToken[EnumToken["BadUrlTokenType"] = 53] = "BadUrlTokenType";
|
|
63
|
+
EnumToken[EnumToken["BadStringTokenType"] = 54] = "BadStringTokenType";
|
|
64
|
+
EnumToken[EnumToken["BinaryExpressionTokenType"] = 55] = "BinaryExpressionTokenType";
|
|
65
|
+
EnumToken[EnumToken["UnaryExpressionTokenType"] = 56] = "UnaryExpressionTokenType";
|
|
67
66
|
/* catch all */
|
|
68
|
-
EnumToken[EnumToken["ListToken"] =
|
|
67
|
+
EnumToken[EnumToken["ListToken"] = 57] = "ListToken";
|
|
69
68
|
/* arithmetic tokens */
|
|
70
|
-
EnumToken[EnumToken["Add"] =
|
|
71
|
-
EnumToken[EnumToken["Mul"] =
|
|
72
|
-
EnumToken[EnumToken["Div"] =
|
|
73
|
-
EnumToken[EnumToken["Sub"] =
|
|
69
|
+
EnumToken[EnumToken["Add"] = 58] = "Add";
|
|
70
|
+
EnumToken[EnumToken["Mul"] = 59] = "Mul";
|
|
71
|
+
EnumToken[EnumToken["Div"] = 60] = "Div";
|
|
72
|
+
EnumToken[EnumToken["Sub"] = 61] = "Sub";
|
|
73
|
+
/* new tokens */
|
|
74
|
+
EnumToken[EnumToken["ColumnCombinatorTokenType"] = 62] = "ColumnCombinatorTokenType";
|
|
75
|
+
EnumToken[EnumToken["ContainMatchTokenType"] = 63] = "ContainMatchTokenType";
|
|
76
|
+
EnumToken[EnumToken["StartMatchTokenType"] = 64] = "StartMatchTokenType";
|
|
77
|
+
EnumToken[EnumToken["EndMatchTokenType"] = 65] = "EndMatchTokenType";
|
|
78
|
+
EnumToken[EnumToken["MatchExpressionTokenType"] = 66] = "MatchExpressionTokenType";
|
|
79
|
+
EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 67] = "NameSpaceAttributeTokenType";
|
|
80
|
+
EnumToken[EnumToken["FractionTokenType"] = 68] = "FractionTokenType";
|
|
74
81
|
/* aliases */
|
|
75
|
-
EnumToken[EnumToken["Time"] =
|
|
76
|
-
EnumToken[EnumToken["Iden"] =
|
|
77
|
-
EnumToken[EnumToken["Hash"] =
|
|
78
|
-
EnumToken[EnumToken["Angle"] =
|
|
79
|
-
EnumToken[EnumToken["Color"] =
|
|
80
|
-
EnumToken[EnumToken["Comma"] =
|
|
81
|
-
EnumToken[EnumToken["String"] =
|
|
82
|
-
EnumToken[EnumToken["Length"] =
|
|
83
|
-
EnumToken[EnumToken["Number"] =
|
|
84
|
-
EnumToken[EnumToken["Perc"] =
|
|
85
|
-
EnumToken[EnumToken["Literal"] =
|
|
82
|
+
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
83
|
+
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
84
|
+
EnumToken[EnumToken["Hash"] = 28] = "Hash";
|
|
85
|
+
EnumToken[EnumToken["Angle"] = 24] = "Angle";
|
|
86
|
+
EnumToken[EnumToken["Color"] = 49] = "Color";
|
|
87
|
+
EnumToken[EnumToken["Comma"] = 9] = "Comma";
|
|
88
|
+
EnumToken[EnumToken["String"] = 20] = "String";
|
|
89
|
+
EnumToken[EnumToken["Length"] = 23] = "Length";
|
|
90
|
+
EnumToken[EnumToken["Number"] = 12] = "Number";
|
|
91
|
+
EnumToken[EnumToken["Perc"] = 14] = "Perc";
|
|
92
|
+
EnumToken[EnumToken["Literal"] = 6] = "Literal";
|
|
86
93
|
EnumToken[EnumToken["Comment"] = 0] = "Comment";
|
|
87
|
-
EnumToken[EnumToken["UrlFunc"] =
|
|
88
|
-
EnumToken[EnumToken["Dimension"] =
|
|
89
|
-
EnumToken[EnumToken["Frequency"] =
|
|
90
|
-
EnumToken[EnumToken["Resolution"] =
|
|
91
|
-
EnumToken[EnumToken["Whitespace"] =
|
|
94
|
+
EnumToken[EnumToken["UrlFunc"] = 18] = "UrlFunc";
|
|
95
|
+
EnumToken[EnumToken["Dimension"] = 22] = "Dimension";
|
|
96
|
+
EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
|
|
97
|
+
EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
|
|
98
|
+
EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
|
|
99
|
+
EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
|
|
100
|
+
EnumToken[EnumToken["ImageFunc"] = 19] = "ImageFunc";
|
|
101
|
+
EnumToken[EnumToken["CommentNodeType"] = 0] = "CommentNodeType";
|
|
102
|
+
EnumToken[EnumToken["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
|
103
|
+
EnumToken[EnumToken["TimingFunction"] = 17] = "TimingFunction";
|
|
104
|
+
EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
|
|
92
105
|
})(exports.EnumToken || (exports.EnumToken = {}));
|
|
93
106
|
|
|
94
107
|
// name to color
|
|
@@ -745,21 +758,19 @@
|
|
|
745
758
|
}
|
|
746
759
|
if (sourcemap != null) {
|
|
747
760
|
result.map = sourcemap.toJSON();
|
|
748
|
-
// @ts-ignore
|
|
749
|
-
// result.map.sources = result.map.sources?.map(s => <string>options?.resolve(s, <string>options?.cwd)?.relative)
|
|
750
761
|
}
|
|
751
762
|
return result;
|
|
752
763
|
}
|
|
753
764
|
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
754
|
-
if ([
|
|
765
|
+
if ([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType].includes(node.typ)) {
|
|
755
766
|
let src = node.loc?.src ?? '';
|
|
756
767
|
let output = options.output ?? '';
|
|
757
|
-
if (src !== '') {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}
|
|
768
|
+
// if (src !== '') {
|
|
769
|
+
if (!(src in cache)) {
|
|
770
|
+
// @ts-ignore
|
|
771
|
+
cache[src] = options.resolve(src, options.cwd ?? '').relative;
|
|
762
772
|
}
|
|
773
|
+
// }
|
|
763
774
|
if (!(output in cache)) {
|
|
764
775
|
// @ts-ignore
|
|
765
776
|
cache[output] = options.resolve(output, options.cwd).relative;
|
|
@@ -784,16 +795,16 @@
|
|
|
784
795
|
const indent = indents[level];
|
|
785
796
|
const indentSub = indents[level + 1];
|
|
786
797
|
switch (data.typ) {
|
|
787
|
-
case
|
|
798
|
+
case exports.EnumToken.DeclarationNodeType:
|
|
788
799
|
return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
|
|
789
|
-
case
|
|
790
|
-
case
|
|
800
|
+
case exports.EnumToken.CommentNodeType:
|
|
801
|
+
case exports.EnumToken.CDOCOMMNodeType:
|
|
791
802
|
if (data.val.startsWith('# sourceMappingURL=')) {
|
|
792
803
|
// ignore sourcemap
|
|
793
804
|
return '';
|
|
794
805
|
}
|
|
795
806
|
return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
|
|
796
|
-
case
|
|
807
|
+
case exports.EnumToken.StyleSheetNodeType:
|
|
797
808
|
return data.chi.reduce((css, node) => {
|
|
798
809
|
const str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level, indents);
|
|
799
810
|
if (str === '') {
|
|
@@ -811,18 +822,18 @@
|
|
|
811
822
|
}
|
|
812
823
|
return `${css}${options.newLine}${str}`;
|
|
813
824
|
}, '');
|
|
814
|
-
case
|
|
815
|
-
case
|
|
816
|
-
if (data.typ ==
|
|
825
|
+
case exports.EnumToken.AtRuleNodeType:
|
|
826
|
+
case exports.EnumToken.RuleNodeType:
|
|
827
|
+
if (data.typ == exports.EnumToken.AtRuleNodeType && !('chi' in data)) {
|
|
817
828
|
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
818
829
|
}
|
|
819
830
|
// @ts-ignore
|
|
820
831
|
let children = data.chi.reduce((css, node) => {
|
|
821
832
|
let str;
|
|
822
|
-
if (node.typ ==
|
|
833
|
+
if (node.typ == exports.EnumToken.CommentNodeType) {
|
|
823
834
|
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
824
835
|
}
|
|
825
|
-
else if (node.typ ==
|
|
836
|
+
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
826
837
|
if (node.val.length == 0) {
|
|
827
838
|
// @ts-ignore
|
|
828
839
|
errors.push({
|
|
@@ -834,7 +845,7 @@
|
|
|
834
845
|
}
|
|
835
846
|
str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
|
|
836
847
|
}
|
|
837
|
-
else if (node.typ ==
|
|
848
|
+
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
838
849
|
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
839
850
|
}
|
|
840
851
|
else {
|
|
@@ -851,7 +862,7 @@
|
|
|
851
862
|
if (children.endsWith(';')) {
|
|
852
863
|
children = children.slice(0, -1);
|
|
853
864
|
}
|
|
854
|
-
if (data.typ ==
|
|
865
|
+
if (data.typ == exports.EnumToken.AtRuleNodeType) {
|
|
855
866
|
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
856
867
|
}
|
|
857
868
|
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
@@ -874,7 +885,35 @@
|
|
|
874
885
|
case exports.EnumToken.ListToken:
|
|
875
886
|
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
876
887
|
case exports.EnumToken.BinaryExpressionTokenType:
|
|
888
|
+
if ([exports.EnumToken.Mul, exports.EnumToken.Div].includes(token.op)) {
|
|
889
|
+
let result = '';
|
|
890
|
+
if (token.l.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
891
|
+
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.l.op)) {
|
|
892
|
+
result = '(' + renderToken(token.l, options, cache) + ')';
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
result = renderToken(token.l, options, cache);
|
|
896
|
+
}
|
|
897
|
+
result += token.op == exports.EnumToken.Mul ? '*' : '/';
|
|
898
|
+
if (token.r.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
899
|
+
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.r.op)) {
|
|
900
|
+
result += '(' + renderToken(token.r, options, cache) + ')';
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
result += renderToken(token.r, options, cache);
|
|
904
|
+
}
|
|
905
|
+
return result;
|
|
906
|
+
}
|
|
877
907
|
return renderToken(token.l, options, cache) + (token.op == exports.EnumToken.Add ? ' + ' : (token.op == exports.EnumToken.Sub ? ' - ' : (token.op == exports.EnumToken.Mul ? '*' : '/'))) + renderToken(token.r, options, cache);
|
|
908
|
+
case exports.EnumToken.FractionTokenType:
|
|
909
|
+
const fraction = renderToken(token.l) + '/' + renderToken(token.r);
|
|
910
|
+
if (+token.r.val != 0) {
|
|
911
|
+
const value = reduceNumber(+token.l.val / +token.r.val);
|
|
912
|
+
if (value.length <= fraction.length) {
|
|
913
|
+
return value;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return fraction;
|
|
878
917
|
case exports.EnumToken.Add:
|
|
879
918
|
return ' + ';
|
|
880
919
|
case exports.EnumToken.Sub:
|
|
@@ -927,21 +966,45 @@
|
|
|
927
966
|
case exports.EnumToken.ParensTokenType:
|
|
928
967
|
case exports.EnumToken.FunctionTokenType:
|
|
929
968
|
case exports.EnumToken.UrlFunctionTokenType:
|
|
969
|
+
case exports.EnumToken.ImageFunctionTokenType:
|
|
930
970
|
case exports.EnumToken.PseudoClassFuncTokenType:
|
|
971
|
+
case exports.EnumToken.TimingFunctionTokenType:
|
|
972
|
+
case exports.EnumToken.TimelineFunctionTokenType:
|
|
931
973
|
if (token.typ == exports.EnumToken.FunctionTokenType &&
|
|
932
974
|
token.val == 'calc' &&
|
|
933
|
-
token.chi.length == 1
|
|
975
|
+
token.chi.length == 1 &&
|
|
976
|
+
token.chi[0].typ != exports.EnumToken.BinaryExpressionTokenType &&
|
|
977
|
+
token.chi[0].typ != exports.EnumToken.FractionTokenType &&
|
|
978
|
+
token.chi[0].val?.typ != exports.EnumToken.FractionTokenType) {
|
|
934
979
|
// calc(200px) => 200px
|
|
935
980
|
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer), '');
|
|
936
981
|
}
|
|
937
982
|
// @ts-ignore
|
|
938
983
|
return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
|
|
984
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
985
|
+
return renderToken(token.l, options, cache, reducer, errors) +
|
|
986
|
+
renderToken({ typ: token.op }, options, cache, reducer, errors) +
|
|
987
|
+
renderToken(token.r, options, cache, reducer, errors) +
|
|
988
|
+
(token.attr ? ' ' + token.attr : '');
|
|
989
|
+
case exports.EnumToken.NameSpaceAttributeTokenType:
|
|
990
|
+
return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors) + '|') +
|
|
991
|
+
renderToken(token.r, options, cache, reducer, errors);
|
|
992
|
+
case exports.EnumToken.BlockStartTokenType:
|
|
993
|
+
return '{';
|
|
994
|
+
case exports.EnumToken.BlockEndTokenType:
|
|
995
|
+
return '}';
|
|
939
996
|
case exports.EnumToken.StartParensTokenType:
|
|
940
997
|
return '(';
|
|
941
|
-
case exports.EnumToken.
|
|
998
|
+
case exports.EnumToken.IncludeMatchTokenType:
|
|
942
999
|
return '~=';
|
|
943
1000
|
case exports.EnumToken.DashMatchTokenType:
|
|
944
1001
|
return '|=';
|
|
1002
|
+
case exports.EnumToken.StartMatchTokenType:
|
|
1003
|
+
return '^=';
|
|
1004
|
+
case exports.EnumToken.EndMatchTokenType:
|
|
1005
|
+
return '$=';
|
|
1006
|
+
case exports.EnumToken.ContainMatchTokenType:
|
|
1007
|
+
return '*=';
|
|
945
1008
|
case exports.EnumToken.LtTokenType:
|
|
946
1009
|
return '<';
|
|
947
1010
|
case exports.EnumToken.LteTokenType:
|
|
@@ -950,6 +1013,8 @@
|
|
|
950
1013
|
return '>';
|
|
951
1014
|
case exports.EnumToken.GteTokenType:
|
|
952
1015
|
return '>=';
|
|
1016
|
+
case exports.EnumToken.ColumnCombinatorTokenType:
|
|
1017
|
+
return '||';
|
|
953
1018
|
case exports.EnumToken.EndParensTokenType:
|
|
954
1019
|
return ')';
|
|
955
1020
|
case exports.EnumToken.AttrStartTokenType:
|
|
@@ -974,19 +1039,9 @@
|
|
|
974
1039
|
case exports.EnumToken.DimensionTokenType:
|
|
975
1040
|
case exports.EnumToken.FrequencyTokenType:
|
|
976
1041
|
case exports.EnumToken.ResolutionTokenType:
|
|
977
|
-
|
|
978
|
-
const result = renderToken(token.val, options, cache);
|
|
979
|
-
if (!('unit' in token)) {
|
|
980
|
-
return result;
|
|
981
|
-
}
|
|
982
|
-
if (!result.includes(' ')) {
|
|
983
|
-
return result + token.unit;
|
|
984
|
-
}
|
|
985
|
-
return `(${result})*1${token.unit}`;
|
|
986
|
-
}
|
|
987
|
-
let val = reduceNumber(token.val);
|
|
1042
|
+
let val = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
988
1043
|
let unit = token.unit;
|
|
989
|
-
if (token.typ == exports.EnumToken.AngleTokenType) {
|
|
1044
|
+
if (token.typ == exports.EnumToken.AngleTokenType && !val.includes('/')) {
|
|
990
1045
|
const angle = getAngle(token);
|
|
991
1046
|
let v;
|
|
992
1047
|
let value = val + unit;
|
|
@@ -1043,16 +1098,21 @@
|
|
|
1043
1098
|
}
|
|
1044
1099
|
return '0';
|
|
1045
1100
|
}
|
|
1046
|
-
return val + unit;
|
|
1101
|
+
return val.includes('/') ? val.replace('/', unit + '/') : val + unit;
|
|
1047
1102
|
case exports.EnumToken.PercentageTokenType:
|
|
1048
|
-
const perc = reduceNumber(token.val);
|
|
1049
|
-
return options.minify && perc == '0' ? '0' : perc + '%';
|
|
1103
|
+
const perc = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
1104
|
+
return options.minify && perc == '0' ? '0' : (perc.includes('/') ? perc.replace('/', '%/') : perc + '%');
|
|
1050
1105
|
case exports.EnumToken.NumberTokenType:
|
|
1051
|
-
return reduceNumber(token.val);
|
|
1106
|
+
return token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
1052
1107
|
case exports.EnumToken.CommentTokenType:
|
|
1053
1108
|
if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
|
|
1054
1109
|
return '';
|
|
1055
1110
|
}
|
|
1111
|
+
case exports.EnumToken.PseudoClassTokenType:
|
|
1112
|
+
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
1113
|
+
if (token.typ == exports.EnumToken.PseudoClassTokenType && ['::before', '::after', '::first-line', '::first-letter'].includes(token.val)) {
|
|
1114
|
+
return token.val.slice(1);
|
|
1115
|
+
}
|
|
1056
1116
|
case exports.EnumToken.UrlTokenTokenType:
|
|
1057
1117
|
if (token.typ == exports.EnumToken.UrlTokenTokenType) {
|
|
1058
1118
|
if (options.output != null) {
|
|
@@ -1076,13 +1136,13 @@
|
|
|
1076
1136
|
token.val = cache[token.original];
|
|
1077
1137
|
}
|
|
1078
1138
|
}
|
|
1079
|
-
case exports.EnumToken.AtRuleTokenType:
|
|
1080
1139
|
case exports.EnumToken.HashTokenType:
|
|
1081
|
-
case exports.EnumToken.PseudoClassTokenType:
|
|
1082
|
-
case exports.EnumToken.LiteralTokenType:
|
|
1083
|
-
case exports.EnumToken.StringTokenType:
|
|
1084
1140
|
case exports.EnumToken.IdenTokenType:
|
|
1085
1141
|
case exports.EnumToken.DelimTokenType:
|
|
1142
|
+
case exports.EnumToken.AtRuleTokenType:
|
|
1143
|
+
case exports.EnumToken.StringTokenType:
|
|
1144
|
+
case exports.EnumToken.LiteralTokenType:
|
|
1145
|
+
case exports.EnumToken.DashedIdenTokenType:
|
|
1086
1146
|
return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
|
|
1087
1147
|
}
|
|
1088
1148
|
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
@@ -1586,6 +1646,317 @@
|
|
|
1586
1646
|
}
|
|
1587
1647
|
};
|
|
1588
1648
|
var map = {
|
|
1649
|
+
transition: {
|
|
1650
|
+
shorthand: "transition",
|
|
1651
|
+
multiple: true,
|
|
1652
|
+
separator: ",",
|
|
1653
|
+
pattern: "transition-property transition-duration transition-timing-function transition-delay transition-behavior",
|
|
1654
|
+
keywords: [
|
|
1655
|
+
"none",
|
|
1656
|
+
"all"
|
|
1657
|
+
],
|
|
1658
|
+
"default": [
|
|
1659
|
+
"0s",
|
|
1660
|
+
"0ms",
|
|
1661
|
+
"all",
|
|
1662
|
+
"ease",
|
|
1663
|
+
"none",
|
|
1664
|
+
"normal"
|
|
1665
|
+
],
|
|
1666
|
+
properties: {
|
|
1667
|
+
"transition-property": {
|
|
1668
|
+
keywords: [
|
|
1669
|
+
"none",
|
|
1670
|
+
"all"
|
|
1671
|
+
],
|
|
1672
|
+
"default": [
|
|
1673
|
+
],
|
|
1674
|
+
types: [
|
|
1675
|
+
"Iden"
|
|
1676
|
+
]
|
|
1677
|
+
},
|
|
1678
|
+
"transition-duration": {
|
|
1679
|
+
keywords: [
|
|
1680
|
+
],
|
|
1681
|
+
"default": [
|
|
1682
|
+
"0s",
|
|
1683
|
+
"0ms",
|
|
1684
|
+
"normal"
|
|
1685
|
+
],
|
|
1686
|
+
types: [
|
|
1687
|
+
"Time"
|
|
1688
|
+
]
|
|
1689
|
+
},
|
|
1690
|
+
"transition-timing-function": {
|
|
1691
|
+
keywords: [
|
|
1692
|
+
"ease",
|
|
1693
|
+
"ease-in",
|
|
1694
|
+
"ease-out",
|
|
1695
|
+
"ease-in-out",
|
|
1696
|
+
"linear",
|
|
1697
|
+
"step-start",
|
|
1698
|
+
"step-end"
|
|
1699
|
+
],
|
|
1700
|
+
"default": [
|
|
1701
|
+
"ease"
|
|
1702
|
+
],
|
|
1703
|
+
types: [
|
|
1704
|
+
"TimingFunction"
|
|
1705
|
+
],
|
|
1706
|
+
mapping: {
|
|
1707
|
+
"cubic-bezier(.25,.1,.25,1)": "ease",
|
|
1708
|
+
"cubic-bezier(0,0,1,1)": "linear",
|
|
1709
|
+
"cubic-bezier(.42,0,1,1)": "ease-in",
|
|
1710
|
+
"cubic-bezier(0,0,.58,1)": "ease-out",
|
|
1711
|
+
"cubic-bezier(.42,0,.58,.42)": "ease-in-out"
|
|
1712
|
+
}
|
|
1713
|
+
},
|
|
1714
|
+
"transition-delay": {
|
|
1715
|
+
keywords: [
|
|
1716
|
+
],
|
|
1717
|
+
"default": [
|
|
1718
|
+
"0s"
|
|
1719
|
+
],
|
|
1720
|
+
types: [
|
|
1721
|
+
"Time"
|
|
1722
|
+
]
|
|
1723
|
+
},
|
|
1724
|
+
"transition-behavior": {
|
|
1725
|
+
keywords: [
|
|
1726
|
+
"normal",
|
|
1727
|
+
"allow-discrete"
|
|
1728
|
+
],
|
|
1729
|
+
"default": [
|
|
1730
|
+
"normal"
|
|
1731
|
+
],
|
|
1732
|
+
types: [
|
|
1733
|
+
]
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
},
|
|
1737
|
+
"transition-property": {
|
|
1738
|
+
shorthand: "transition"
|
|
1739
|
+
},
|
|
1740
|
+
"transition-duration": {
|
|
1741
|
+
shorthand: "transition"
|
|
1742
|
+
},
|
|
1743
|
+
"transition-timing-function": {
|
|
1744
|
+
shorthand: "transition"
|
|
1745
|
+
},
|
|
1746
|
+
"transition-delay": {
|
|
1747
|
+
shorthand: "transition"
|
|
1748
|
+
},
|
|
1749
|
+
"transition-behavior": {
|
|
1750
|
+
shorthand: "transition"
|
|
1751
|
+
},
|
|
1752
|
+
animation: {
|
|
1753
|
+
shorthand: "animation",
|
|
1754
|
+
pattern: "animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode animation-play-state animation-timeline",
|
|
1755
|
+
"default": [
|
|
1756
|
+
"1",
|
|
1757
|
+
"0s",
|
|
1758
|
+
"0ms",
|
|
1759
|
+
"none",
|
|
1760
|
+
"ease",
|
|
1761
|
+
"normal",
|
|
1762
|
+
"running",
|
|
1763
|
+
"auto"
|
|
1764
|
+
],
|
|
1765
|
+
properties: {
|
|
1766
|
+
"animation-name": {
|
|
1767
|
+
keywords: [
|
|
1768
|
+
"none"
|
|
1769
|
+
],
|
|
1770
|
+
"default": [
|
|
1771
|
+
"none"
|
|
1772
|
+
],
|
|
1773
|
+
types: [
|
|
1774
|
+
"Iden"
|
|
1775
|
+
]
|
|
1776
|
+
},
|
|
1777
|
+
"animation-duration": {
|
|
1778
|
+
keywords: [
|
|
1779
|
+
"auto"
|
|
1780
|
+
],
|
|
1781
|
+
"default": [
|
|
1782
|
+
"0s",
|
|
1783
|
+
"0ms",
|
|
1784
|
+
"auto"
|
|
1785
|
+
],
|
|
1786
|
+
types: [
|
|
1787
|
+
"Time"
|
|
1788
|
+
],
|
|
1789
|
+
mapping: {
|
|
1790
|
+
auto: "0s"
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
"animation-timing-function": {
|
|
1794
|
+
keywords: [
|
|
1795
|
+
"ease",
|
|
1796
|
+
"ease-in",
|
|
1797
|
+
"ease-out",
|
|
1798
|
+
"ease-in-out",
|
|
1799
|
+
"linear",
|
|
1800
|
+
"step-start",
|
|
1801
|
+
"step-end"
|
|
1802
|
+
],
|
|
1803
|
+
"default": [
|
|
1804
|
+
"ease"
|
|
1805
|
+
],
|
|
1806
|
+
types: [
|
|
1807
|
+
"TimingFunction"
|
|
1808
|
+
],
|
|
1809
|
+
mapping: {
|
|
1810
|
+
"cubic-bezier(.25,.1,.25,1)": "ease",
|
|
1811
|
+
"cubic-bezier(0,0,1,1)": "linear",
|
|
1812
|
+
"cubic-bezier(.42,0,1,1)": "ease-in",
|
|
1813
|
+
"cubic-bezier(0,0,.58,1)": "ease-out",
|
|
1814
|
+
"cubic-bezier(.42,0,.58,.42)": "ease-in-out"
|
|
1815
|
+
}
|
|
1816
|
+
},
|
|
1817
|
+
"animation-delay": {
|
|
1818
|
+
keywords: [
|
|
1819
|
+
],
|
|
1820
|
+
"default": [
|
|
1821
|
+
"0s",
|
|
1822
|
+
"0ms"
|
|
1823
|
+
],
|
|
1824
|
+
types: [
|
|
1825
|
+
"Time"
|
|
1826
|
+
]
|
|
1827
|
+
},
|
|
1828
|
+
"animation-iteration-count": {
|
|
1829
|
+
keywords: [
|
|
1830
|
+
"infinite"
|
|
1831
|
+
],
|
|
1832
|
+
"default": [
|
|
1833
|
+
"1"
|
|
1834
|
+
],
|
|
1835
|
+
types: [
|
|
1836
|
+
"Number"
|
|
1837
|
+
]
|
|
1838
|
+
},
|
|
1839
|
+
"animation-direction": {
|
|
1840
|
+
keywords: [
|
|
1841
|
+
"normal",
|
|
1842
|
+
"reverse",
|
|
1843
|
+
"alternate",
|
|
1844
|
+
"alternate-reverse"
|
|
1845
|
+
],
|
|
1846
|
+
"default": [
|
|
1847
|
+
"normal"
|
|
1848
|
+
],
|
|
1849
|
+
types: [
|
|
1850
|
+
]
|
|
1851
|
+
},
|
|
1852
|
+
"animation-fill-mode": {
|
|
1853
|
+
keywords: [
|
|
1854
|
+
"none",
|
|
1855
|
+
"forwards",
|
|
1856
|
+
"backwards",
|
|
1857
|
+
"both"
|
|
1858
|
+
],
|
|
1859
|
+
"default": [
|
|
1860
|
+
"none"
|
|
1861
|
+
],
|
|
1862
|
+
types: [
|
|
1863
|
+
]
|
|
1864
|
+
},
|
|
1865
|
+
"animation-play-state": {
|
|
1866
|
+
keywords: [
|
|
1867
|
+
"running",
|
|
1868
|
+
"paused"
|
|
1869
|
+
],
|
|
1870
|
+
"default": [
|
|
1871
|
+
"running"
|
|
1872
|
+
],
|
|
1873
|
+
types: [
|
|
1874
|
+
]
|
|
1875
|
+
},
|
|
1876
|
+
"animation-timeline": {
|
|
1877
|
+
keywords: [
|
|
1878
|
+
"none",
|
|
1879
|
+
"auto"
|
|
1880
|
+
],
|
|
1881
|
+
"default": [
|
|
1882
|
+
"auto"
|
|
1883
|
+
],
|
|
1884
|
+
types: [
|
|
1885
|
+
"DashedIden",
|
|
1886
|
+
"TimelineFunction"
|
|
1887
|
+
]
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
},
|
|
1891
|
+
"animation-name": {
|
|
1892
|
+
shorthand: "animation"
|
|
1893
|
+
},
|
|
1894
|
+
"animation-duration": {
|
|
1895
|
+
shorthand: "animation"
|
|
1896
|
+
},
|
|
1897
|
+
"animation-timing-function": {
|
|
1898
|
+
shorthand: "animation"
|
|
1899
|
+
},
|
|
1900
|
+
"animation-delay": {
|
|
1901
|
+
shorthand: "animation"
|
|
1902
|
+
},
|
|
1903
|
+
"animation-iteration-count": {
|
|
1904
|
+
shorthand: "animation"
|
|
1905
|
+
},
|
|
1906
|
+
"animation-direction": {
|
|
1907
|
+
shorthand: "animation"
|
|
1908
|
+
},
|
|
1909
|
+
"animation-fill-mode": {
|
|
1910
|
+
shorthand: "animation"
|
|
1911
|
+
},
|
|
1912
|
+
"animation-play-state": {
|
|
1913
|
+
shorthand: "animation"
|
|
1914
|
+
},
|
|
1915
|
+
"animation-timeline": {
|
|
1916
|
+
shorthand: "animation"
|
|
1917
|
+
},
|
|
1918
|
+
"text-emphasis": {
|
|
1919
|
+
shorthand: "text-emphasis",
|
|
1920
|
+
pattern: "text-emphasis-color text-emphasis-style",
|
|
1921
|
+
"default": [
|
|
1922
|
+
"none",
|
|
1923
|
+
"currentcolor"
|
|
1924
|
+
],
|
|
1925
|
+
properties: {
|
|
1926
|
+
"text-emphasis-style": {
|
|
1927
|
+
keywords: [
|
|
1928
|
+
"none",
|
|
1929
|
+
"filled",
|
|
1930
|
+
"open",
|
|
1931
|
+
"dot",
|
|
1932
|
+
"circle",
|
|
1933
|
+
"double-circle",
|
|
1934
|
+
"triangle",
|
|
1935
|
+
"sesame"
|
|
1936
|
+
],
|
|
1937
|
+
"default": [
|
|
1938
|
+
"none"
|
|
1939
|
+
],
|
|
1940
|
+
types: [
|
|
1941
|
+
"String"
|
|
1942
|
+
]
|
|
1943
|
+
},
|
|
1944
|
+
"text-emphasis-color": {
|
|
1945
|
+
"default": [
|
|
1946
|
+
"currentcolor"
|
|
1947
|
+
],
|
|
1948
|
+
types: [
|
|
1949
|
+
"Color"
|
|
1950
|
+
]
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
"text-emphasis-style": {
|
|
1955
|
+
shorthand: "text-emphasis"
|
|
1956
|
+
},
|
|
1957
|
+
"text-emphasis-color": {
|
|
1958
|
+
shorthand: "text-emphasis"
|
|
1959
|
+
},
|
|
1589
1960
|
border: {
|
|
1590
1961
|
shorthand: "border",
|
|
1591
1962
|
pattern: "border-color border-style border-width",
|
|
@@ -1651,6 +2022,75 @@
|
|
|
1651
2022
|
"border-width": {
|
|
1652
2023
|
shorthand: "border"
|
|
1653
2024
|
},
|
|
2025
|
+
"list-style": {
|
|
2026
|
+
shorthand: "list-style",
|
|
2027
|
+
pattern: "list-style-type list-style-position list-style-image",
|
|
2028
|
+
keywords: [
|
|
2029
|
+
"none",
|
|
2030
|
+
"outside"
|
|
2031
|
+
],
|
|
2032
|
+
"default": [
|
|
2033
|
+
"none",
|
|
2034
|
+
"outside"
|
|
2035
|
+
],
|
|
2036
|
+
properties: {
|
|
2037
|
+
"list-style-position": {
|
|
2038
|
+
types: [
|
|
2039
|
+
],
|
|
2040
|
+
"default": [
|
|
2041
|
+
"outside"
|
|
2042
|
+
],
|
|
2043
|
+
keywords: [
|
|
2044
|
+
"inside",
|
|
2045
|
+
"outside"
|
|
2046
|
+
]
|
|
2047
|
+
},
|
|
2048
|
+
"list-style-image": {
|
|
2049
|
+
"default": [
|
|
2050
|
+
"none"
|
|
2051
|
+
],
|
|
2052
|
+
keywords: [
|
|
2053
|
+
"node"
|
|
2054
|
+
],
|
|
2055
|
+
types: [
|
|
2056
|
+
"UrlFunc",
|
|
2057
|
+
"ImageFunc"
|
|
2058
|
+
]
|
|
2059
|
+
},
|
|
2060
|
+
"list-style-type": {
|
|
2061
|
+
types: [
|
|
2062
|
+
"String",
|
|
2063
|
+
"Iden",
|
|
2064
|
+
"Symbols"
|
|
2065
|
+
],
|
|
2066
|
+
"default": [
|
|
2067
|
+
"disc"
|
|
2068
|
+
],
|
|
2069
|
+
keywords: [
|
|
2070
|
+
"disc",
|
|
2071
|
+
"circle",
|
|
2072
|
+
"square",
|
|
2073
|
+
"decimal",
|
|
2074
|
+
"decimal-leading-zero",
|
|
2075
|
+
"lower-roman",
|
|
2076
|
+
"upper-roman",
|
|
2077
|
+
"lower-greek",
|
|
2078
|
+
"lower-latin",
|
|
2079
|
+
"upper-latin",
|
|
2080
|
+
"none"
|
|
2081
|
+
]
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
},
|
|
2085
|
+
"list-style-position": {
|
|
2086
|
+
shorthand: "list-style"
|
|
2087
|
+
},
|
|
2088
|
+
"list-style-image": {
|
|
2089
|
+
shorthand: "list-style"
|
|
2090
|
+
},
|
|
2091
|
+
"list-style-type": {
|
|
2092
|
+
shorthand: "list-style"
|
|
2093
|
+
},
|
|
1654
2094
|
overflow: {
|
|
1655
2095
|
shorthand: "overflow",
|
|
1656
2096
|
pattern: "overflow-x overflow-y",
|
|
@@ -1708,7 +2148,8 @@
|
|
|
1708
2148
|
],
|
|
1709
2149
|
"default": [
|
|
1710
2150
|
"0",
|
|
1711
|
-
"none"
|
|
2151
|
+
"none",
|
|
2152
|
+
"currentcolor"
|
|
1712
2153
|
],
|
|
1713
2154
|
properties: {
|
|
1714
2155
|
"outline-color": {
|
|
@@ -1716,10 +2157,10 @@
|
|
|
1716
2157
|
"Color"
|
|
1717
2158
|
],
|
|
1718
2159
|
"default": [
|
|
1719
|
-
"
|
|
2160
|
+
"currentcolor"
|
|
1720
2161
|
],
|
|
1721
2162
|
keywords: [
|
|
1722
|
-
"
|
|
2163
|
+
"currentcolor"
|
|
1723
2164
|
]
|
|
1724
2165
|
},
|
|
1725
2166
|
"outline-style": {
|
|
@@ -2063,7 +2504,8 @@
|
|
|
2063
2504
|
},
|
|
2064
2505
|
"background-image": {
|
|
2065
2506
|
types: [
|
|
2066
|
-
"UrlFunc"
|
|
2507
|
+
"UrlFunc",
|
|
2508
|
+
"ImageFunc"
|
|
2067
2509
|
],
|
|
2068
2510
|
"default": [
|
|
2069
2511
|
"none"
|
|
@@ -2201,6 +2643,7 @@
|
|
|
2201
2643
|
|
|
2202
2644
|
const getConfig = () => config$1;
|
|
2203
2645
|
|
|
2646
|
+
// https://www.w3.org/TR/css-values-4/#math-function
|
|
2204
2647
|
const funcList = ['clamp', 'calc'];
|
|
2205
2648
|
function matchType(val, properties) {
|
|
2206
2649
|
if (val.typ == exports.EnumToken.IdenTokenType && properties.keywords.includes(val.val) ||
|
|
@@ -2216,8 +2659,12 @@
|
|
|
2216
2659
|
return typ == exports.EnumToken.LengthTokenType || typ == exports.EnumToken.AngleTokenType;
|
|
2217
2660
|
});
|
|
2218
2661
|
}
|
|
2219
|
-
if (val.typ == exports.EnumToken.FunctionTokenType
|
|
2220
|
-
|
|
2662
|
+
if (val.typ == exports.EnumToken.FunctionTokenType) {
|
|
2663
|
+
if (funcList.includes(val.val)) {
|
|
2664
|
+
return val.chi.every((t => [exports.EnumToken.LiteralTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType].includes(t.typ) || matchType(t, properties)));
|
|
2665
|
+
}
|
|
2666
|
+
// match type defined like function 'symbols()', 'url()', 'attr()' etc.
|
|
2667
|
+
// return properties.types.includes((<FunctionToken>val).val + '()')
|
|
2221
2668
|
}
|
|
2222
2669
|
return false;
|
|
2223
2670
|
}
|
|
@@ -2233,7 +2680,6 @@
|
|
|
2233
2680
|
};
|
|
2234
2681
|
let value;
|
|
2235
2682
|
let buffer = '';
|
|
2236
|
-
// let input: string = '';
|
|
2237
2683
|
function consumeWhiteSpace() {
|
|
2238
2684
|
let count = 0;
|
|
2239
2685
|
while (isWhiteSpace(stream.charAt(count + ind + 1).charCodeAt(0))) {
|
|
@@ -2243,7 +2689,7 @@
|
|
|
2243
2689
|
return count;
|
|
2244
2690
|
}
|
|
2245
2691
|
function pushToken(token, hint) {
|
|
2246
|
-
const result = { token, hint, position: { ...position }, bytesIn: ind };
|
|
2692
|
+
const result = { token, hint, position: { ...position }, bytesIn: ind + 1 };
|
|
2247
2693
|
position.ind = ind;
|
|
2248
2694
|
position.lin = lin;
|
|
2249
2695
|
position.col = col == 0 ? 1 : col;
|
|
@@ -2440,8 +2886,10 @@
|
|
|
2440
2886
|
// EOF
|
|
2441
2887
|
if (!(value = next())) {
|
|
2442
2888
|
// end of stream ignore \\
|
|
2443
|
-
|
|
2444
|
-
|
|
2889
|
+
if (buffer.length > 0) {
|
|
2890
|
+
yield pushToken(buffer);
|
|
2891
|
+
buffer = '';
|
|
2892
|
+
}
|
|
2445
2893
|
break;
|
|
2446
2894
|
}
|
|
2447
2895
|
buffer += prev() + value;
|
|
@@ -2450,29 +2898,51 @@
|
|
|
2450
2898
|
case "'":
|
|
2451
2899
|
yield* consumeString(value);
|
|
2452
2900
|
break;
|
|
2901
|
+
case '^':
|
|
2453
2902
|
case '~':
|
|
2454
2903
|
case '|':
|
|
2904
|
+
case '$':
|
|
2905
|
+
if (value == '|' && peek() == '|') {
|
|
2906
|
+
next();
|
|
2907
|
+
yield pushToken('', exports.EnumToken.ColumnCombinatorTokenType);
|
|
2908
|
+
buffer = '';
|
|
2909
|
+
break;
|
|
2910
|
+
}
|
|
2455
2911
|
if (buffer.length > 0) {
|
|
2456
2912
|
yield pushToken(buffer);
|
|
2457
2913
|
buffer = '';
|
|
2458
2914
|
}
|
|
2459
2915
|
buffer += value;
|
|
2460
|
-
if (!(value =
|
|
2916
|
+
if (!(value = peek())) {
|
|
2461
2917
|
yield pushToken(buffer);
|
|
2462
2918
|
buffer = '';
|
|
2463
2919
|
break;
|
|
2464
2920
|
}
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2921
|
+
// ~=
|
|
2922
|
+
// ^=
|
|
2923
|
+
// $=
|
|
2924
|
+
// |=
|
|
2925
|
+
if (peek() == '=') {
|
|
2926
|
+
next();
|
|
2927
|
+
switch (buffer.charAt(0)) {
|
|
2928
|
+
case '~':
|
|
2929
|
+
yield pushToken(buffer, exports.EnumToken.IncludeMatchTokenType);
|
|
2930
|
+
break;
|
|
2931
|
+
case '^':
|
|
2932
|
+
yield pushToken(buffer, exports.EnumToken.StartMatchTokenType);
|
|
2933
|
+
break;
|
|
2934
|
+
case '$':
|
|
2935
|
+
yield pushToken(buffer, exports.EnumToken.EndMatchTokenType);
|
|
2936
|
+
break;
|
|
2937
|
+
case '|':
|
|
2938
|
+
yield pushToken(buffer, exports.EnumToken.DashMatchTokenType);
|
|
2939
|
+
break;
|
|
2940
|
+
}
|
|
2941
|
+
buffer = '';
|
|
2942
|
+
break;
|
|
2943
|
+
}
|
|
2944
|
+
yield pushToken(buffer);
|
|
2945
|
+
buffer = '';
|
|
2476
2946
|
break;
|
|
2477
2947
|
case '>':
|
|
2478
2948
|
if (buffer !== '') {
|
|
@@ -2506,7 +2976,13 @@
|
|
|
2506
2976
|
yield pushToken(buffer);
|
|
2507
2977
|
buffer = '';
|
|
2508
2978
|
}
|
|
2509
|
-
|
|
2979
|
+
const val = peek();
|
|
2980
|
+
if (val == '=') {
|
|
2981
|
+
next();
|
|
2982
|
+
yield pushToken(value + val, exports.EnumToken.ContainMatchTokenType);
|
|
2983
|
+
break;
|
|
2984
|
+
}
|
|
2985
|
+
if (value == ':' && ':' == val) {
|
|
2510
2986
|
buffer += value + next();
|
|
2511
2987
|
break;
|
|
2512
2988
|
}
|
|
@@ -2722,251 +3198,236 @@
|
|
|
2722
3198
|
}
|
|
2723
3199
|
|
|
2724
3200
|
const urlTokenMatcher = /^(["']?)[a-zA-Z0-9_/.-][a-zA-Z0-9_/:.#?-]+(\1)$/;
|
|
2725
|
-
const trimWhiteSpace = [exports.EnumToken.GtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.LteTokenType];
|
|
2726
|
-
const funcLike = [
|
|
2727
|
-
|
|
3201
|
+
const trimWhiteSpace = [exports.EnumToken.CommentTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ColumnCombinatorTokenType];
|
|
3202
|
+
const funcLike = [
|
|
3203
|
+
exports.EnumToken.ParensTokenType,
|
|
3204
|
+
exports.EnumToken.FunctionTokenType,
|
|
3205
|
+
exports.EnumToken.UrlFunctionTokenType,
|
|
3206
|
+
exports.EnumToken.StartParensTokenType,
|
|
3207
|
+
exports.EnumToken.ImageFunctionTokenType,
|
|
3208
|
+
exports.EnumToken.PseudoClassFuncTokenType,
|
|
3209
|
+
exports.EnumToken.TimingFunctionTokenType,
|
|
3210
|
+
exports.EnumToken.TimingFunctionTokenType
|
|
3211
|
+
];
|
|
3212
|
+
const BadTokensTypes = [
|
|
3213
|
+
exports.EnumToken.BadCommentTokenType,
|
|
2728
3214
|
exports.EnumToken.BadCdoTokenType,
|
|
2729
3215
|
exports.EnumToken.BadUrlTokenType,
|
|
2730
|
-
exports.EnumToken.BadStringTokenType
|
|
3216
|
+
exports.EnumToken.BadStringTokenType
|
|
3217
|
+
];
|
|
3218
|
+
const webkitPseudoAliasMap = {
|
|
3219
|
+
'-webkit-autofill': 'autofill'
|
|
3220
|
+
};
|
|
2731
3221
|
async function doParse(iterator, options = {}) {
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
if (options.resolveImport) {
|
|
2751
|
-
options.resolveUrls = true;
|
|
2752
|
-
}
|
|
2753
|
-
const startTime = performance.now();
|
|
2754
|
-
const errors = [];
|
|
2755
|
-
const src = options.src;
|
|
2756
|
-
const stack = [];
|
|
2757
|
-
let ast = {
|
|
2758
|
-
typ: 2 /* NodeType.StyleSheetNodeType */,
|
|
2759
|
-
chi: []
|
|
2760
|
-
};
|
|
2761
|
-
let tokens = [];
|
|
2762
|
-
let map = new Map;
|
|
2763
|
-
let bytesIn = 0;
|
|
2764
|
-
let context = ast;
|
|
2765
|
-
if (options.sourcemap) {
|
|
2766
|
-
ast.loc = {
|
|
2767
|
-
sta: {
|
|
2768
|
-
ind: 0,
|
|
2769
|
-
lin: 1,
|
|
2770
|
-
col: 1
|
|
2771
|
-
},
|
|
2772
|
-
src: ''
|
|
3222
|
+
return new Promise(async (resolve, reject) => {
|
|
3223
|
+
if (options.signal != null) {
|
|
3224
|
+
options.signal.addEventListener('abort', reject);
|
|
3225
|
+
}
|
|
3226
|
+
options = {
|
|
3227
|
+
src: '',
|
|
3228
|
+
sourcemap: false,
|
|
3229
|
+
minify: true,
|
|
3230
|
+
nestingRules: false,
|
|
3231
|
+
resolveImport: false,
|
|
3232
|
+
resolveUrls: false,
|
|
3233
|
+
removeCharset: false,
|
|
3234
|
+
removeEmpty: true,
|
|
3235
|
+
removeDuplicateDeclarations: true,
|
|
3236
|
+
computeShorthand: true,
|
|
3237
|
+
computeCalcExpression: true,
|
|
3238
|
+
inlineCssVariables: false,
|
|
3239
|
+
...options
|
|
2773
3240
|
};
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
3241
|
+
if (options.expandNestingRules) {
|
|
3242
|
+
options.nestingRules = false;
|
|
3243
|
+
}
|
|
3244
|
+
if (options.resolveImport) {
|
|
3245
|
+
options.resolveUrls = true;
|
|
3246
|
+
}
|
|
3247
|
+
const startTime = performance.now();
|
|
3248
|
+
const errors = [];
|
|
3249
|
+
const src = options.src;
|
|
3250
|
+
const stack = [];
|
|
3251
|
+
let ast = {
|
|
3252
|
+
typ: exports.EnumToken.StyleSheetNodeType,
|
|
3253
|
+
chi: []
|
|
3254
|
+
};
|
|
3255
|
+
let tokens = [];
|
|
3256
|
+
let map = new Map;
|
|
3257
|
+
let bytesIn = 0;
|
|
3258
|
+
let context = ast;
|
|
3259
|
+
if (options.sourcemap) {
|
|
3260
|
+
ast.loc = {
|
|
3261
|
+
sta: {
|
|
3262
|
+
ind: 0,
|
|
3263
|
+
lin: 1,
|
|
3264
|
+
col: 1
|
|
3265
|
+
},
|
|
3266
|
+
src: ''
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
async function parseNode(results) {
|
|
3270
|
+
let tokens = results.map(mapToken);
|
|
3271
|
+
let i;
|
|
3272
|
+
let loc;
|
|
3273
|
+
for (i = 0; i < tokens.length; i++) {
|
|
3274
|
+
if (tokens[i].typ == exports.EnumToken.CommentTokenType || tokens[i].typ == exports.EnumToken.CDOCOMMTokenType) {
|
|
3275
|
+
const position = map.get(tokens[i]);
|
|
3276
|
+
if (tokens[i].typ == exports.EnumToken.CDOCOMMTokenType && context.typ != exports.EnumToken.StyleSheetNodeType) {
|
|
3277
|
+
errors.push({
|
|
3278
|
+
action: 'drop',
|
|
3279
|
+
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
3280
|
+
location: { src, ...position }
|
|
3281
|
+
});
|
|
3282
|
+
continue;
|
|
3283
|
+
}
|
|
3284
|
+
loc = {
|
|
3285
|
+
sta: position,
|
|
3286
|
+
src
|
|
3287
|
+
};
|
|
3288
|
+
// @ts-ignore
|
|
3289
|
+
context.chi.push(tokens[i]);
|
|
3290
|
+
if (options.sourcemap) {
|
|
3291
|
+
tokens[i].loc = loc;
|
|
3292
|
+
}
|
|
2789
3293
|
}
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
src
|
|
2793
|
-
};
|
|
2794
|
-
// @ts-ignore
|
|
2795
|
-
context.chi.push(tokens[i]);
|
|
2796
|
-
if (options.sourcemap) {
|
|
2797
|
-
tokens[i].loc = loc;
|
|
3294
|
+
else if (tokens[i].typ != exports.EnumToken.WhitespaceTokenType) {
|
|
3295
|
+
break;
|
|
2798
3296
|
}
|
|
2799
3297
|
}
|
|
2800
|
-
|
|
2801
|
-
|
|
3298
|
+
tokens = tokens.slice(i);
|
|
3299
|
+
if (tokens.length == 0) {
|
|
3300
|
+
return null;
|
|
2802
3301
|
}
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
if (delim.typ == exports.EnumToken.SemiColonTokenType || delim.typ == exports.EnumToken.BlockStartTokenType || delim.typ == exports.EnumToken.BlockEndTokenType) {
|
|
2810
|
-
tokens.pop();
|
|
2811
|
-
}
|
|
2812
|
-
else {
|
|
2813
|
-
delim = { typ: exports.EnumToken.SemiColonTokenType };
|
|
2814
|
-
}
|
|
2815
|
-
// @ts-ignore
|
|
2816
|
-
while ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.BadStringTokenType, exports.EnumToken.BadCommentTokenType].includes(tokens.at(-1)?.typ)) {
|
|
2817
|
-
tokens.pop();
|
|
2818
|
-
}
|
|
2819
|
-
if (tokens.length == 0) {
|
|
2820
|
-
return null;
|
|
2821
|
-
}
|
|
2822
|
-
if (tokens[0]?.typ == exports.EnumToken.AtRuleTokenType) {
|
|
2823
|
-
const atRule = tokens.shift();
|
|
2824
|
-
const position = map.get(atRule);
|
|
2825
|
-
if (atRule.val == 'charset') {
|
|
2826
|
-
if (position.ind > 0) {
|
|
2827
|
-
errors.push({ action: 'drop', message: 'doParse: invalid @charset', location: { src, ...position } });
|
|
2828
|
-
return null;
|
|
2829
|
-
}
|
|
2830
|
-
if (options.removeCharset) {
|
|
2831
|
-
return null;
|
|
2832
|
-
}
|
|
3302
|
+
let delim = tokens.at(-1);
|
|
3303
|
+
if (delim.typ == exports.EnumToken.SemiColonTokenType || delim.typ == exports.EnumToken.BlockStartTokenType || delim.typ == exports.EnumToken.BlockEndTokenType) {
|
|
3304
|
+
tokens.pop();
|
|
3305
|
+
}
|
|
3306
|
+
else {
|
|
3307
|
+
delim = { typ: exports.EnumToken.SemiColonTokenType };
|
|
2833
3308
|
}
|
|
2834
3309
|
// @ts-ignore
|
|
2835
|
-
while ([exports.EnumToken.WhitespaceTokenType].includes(tokens
|
|
2836
|
-
tokens.
|
|
3310
|
+
while ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.BadStringTokenType, exports.EnumToken.BadCommentTokenType].includes(tokens.at(-1)?.typ)) {
|
|
3311
|
+
tokens.pop();
|
|
2837
3312
|
}
|
|
2838
|
-
if (
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
}
|
|
2856
|
-
break;
|
|
3313
|
+
if (tokens.length == 0) {
|
|
3314
|
+
return null;
|
|
3315
|
+
}
|
|
3316
|
+
if (tokens[0]?.typ == exports.EnumToken.AtRuleTokenType) {
|
|
3317
|
+
const atRule = tokens.shift();
|
|
3318
|
+
const position = map.get(atRule);
|
|
3319
|
+
if (atRule.val == 'charset') {
|
|
3320
|
+
if (position.ind > 0) {
|
|
3321
|
+
errors.push({
|
|
3322
|
+
action: 'drop',
|
|
3323
|
+
message: 'doParse: invalid @charset',
|
|
3324
|
+
location: { src, ...position }
|
|
3325
|
+
});
|
|
3326
|
+
return null;
|
|
3327
|
+
}
|
|
3328
|
+
if (options.removeCharset) {
|
|
3329
|
+
return null;
|
|
2857
3330
|
}
|
|
2858
3331
|
}
|
|
2859
3332
|
// @ts-ignore
|
|
2860
|
-
|
|
2861
|
-
errors.push({ action: 'drop', message: 'doParse: invalid @import', location: { src, ...position } });
|
|
2862
|
-
return null;
|
|
2863
|
-
}
|
|
2864
|
-
// @ts-ignore
|
|
2865
|
-
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType && tokens[1]?.typ != exports.EnumToken.UrlTokenTokenType && tokens[1]?.typ != exports.EnumToken.StringTokenType) {
|
|
2866
|
-
errors.push({ action: 'drop', message: 'doParse: invalid @import', location: { src, ...position } });
|
|
2867
|
-
return null;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
if (atRule.val == 'import') {
|
|
2871
|
-
// @ts-ignore
|
|
2872
|
-
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType && tokens[1].typ == exports.EnumToken.UrlTokenTokenType) {
|
|
3333
|
+
while ([exports.EnumToken.WhitespaceTokenType].includes(tokens[0]?.typ)) {
|
|
2873
3334
|
tokens.shift();
|
|
2874
|
-
// @ts-ignore
|
|
2875
|
-
tokens[0].typ = exports.EnumToken.StringTokenType;
|
|
2876
|
-
// @ts-ignore
|
|
2877
|
-
tokens[0].val = `"${tokens[0].val}"`;
|
|
2878
3335
|
}
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
if (
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
minify: false,
|
|
2888
|
-
// @ts-ignore
|
|
2889
|
-
src: options.resolve(url, options.src).absolute
|
|
2890
|
-
}));
|
|
2891
|
-
});
|
|
2892
|
-
bytesIn += root.stats.bytesIn;
|
|
2893
|
-
if (root.ast.chi.length > 0) {
|
|
2894
|
-
// @todo - filter charset, layer and scope
|
|
2895
|
-
context.chi.push(...root.ast.chi);
|
|
3336
|
+
if (atRule.val == 'import') {
|
|
3337
|
+
// only @charset and @layer are accepted before @import
|
|
3338
|
+
if (context.chi.length > 0) {
|
|
3339
|
+
let i = context.chi.length;
|
|
3340
|
+
while (i--) {
|
|
3341
|
+
const type = context.chi[i].typ;
|
|
3342
|
+
if (type == exports.EnumToken.CommentNodeType) {
|
|
3343
|
+
continue;
|
|
2896
3344
|
}
|
|
2897
|
-
if (
|
|
2898
|
-
errors.push(...
|
|
3345
|
+
if (type != exports.EnumToken.AtRuleNodeType) {
|
|
3346
|
+
errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
|
|
3347
|
+
return null;
|
|
2899
3348
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
3349
|
+
const name = context.chi[i].nam;
|
|
3350
|
+
if (name != 'charset' && name != 'import' && name != 'layer') {
|
|
3351
|
+
errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
|
|
3352
|
+
return null;
|
|
3353
|
+
}
|
|
3354
|
+
break;
|
|
2905
3355
|
}
|
|
2906
3356
|
}
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
}, []);
|
|
2916
|
-
const node = {
|
|
2917
|
-
typ: 3 /* NodeType.AtRuleNodeType */,
|
|
2918
|
-
nam: renderToken(atRule, { removeComments: true }),
|
|
2919
|
-
val: raw.join('')
|
|
2920
|
-
};
|
|
2921
|
-
Object.defineProperty(node, 'raw', { enumerable: false, configurable: true, writable: true, value: raw });
|
|
2922
|
-
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
2923
|
-
node.chi = [];
|
|
2924
|
-
}
|
|
2925
|
-
loc = {
|
|
2926
|
-
sta: position,
|
|
2927
|
-
src
|
|
2928
|
-
};
|
|
2929
|
-
if (options.sourcemap) {
|
|
2930
|
-
node.loc = loc;
|
|
2931
|
-
}
|
|
2932
|
-
// @ts-ignore
|
|
2933
|
-
context.chi.push(node);
|
|
2934
|
-
return delim.typ == exports.EnumToken.BlockStartTokenType ? node : null;
|
|
2935
|
-
}
|
|
2936
|
-
else {
|
|
2937
|
-
// rule
|
|
2938
|
-
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
2939
|
-
const position = map.get(tokens[0]);
|
|
2940
|
-
const uniq = new Map;
|
|
2941
|
-
parseTokens(tokens, { minify: true }).reduce((acc, curr, index, array) => {
|
|
2942
|
-
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
2943
|
-
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
2944
|
-
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
2945
|
-
combinators.includes(array[index - 1]?.val) ||
|
|
2946
|
-
combinators.includes(array[index + 1]?.val)) {
|
|
2947
|
-
return acc;
|
|
2948
|
-
}
|
|
3357
|
+
// @ts-ignore
|
|
3358
|
+
if (tokens[0]?.typ != exports.EnumToken.StringTokenType && tokens[0]?.typ != exports.EnumToken.UrlFunctionTokenType) {
|
|
3359
|
+
errors.push({
|
|
3360
|
+
action: 'drop',
|
|
3361
|
+
message: 'doParse: invalid @import',
|
|
3362
|
+
location: { src, ...position }
|
|
3363
|
+
});
|
|
3364
|
+
return null;
|
|
2949
3365
|
}
|
|
2950
|
-
|
|
2951
|
-
if (
|
|
2952
|
-
|
|
3366
|
+
// @ts-ignore
|
|
3367
|
+
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType && tokens[1]?.typ != exports.EnumToken.UrlTokenTokenType && tokens[1]?.typ != exports.EnumToken.StringTokenType) {
|
|
3368
|
+
errors.push({
|
|
3369
|
+
action: 'drop',
|
|
3370
|
+
message: 'doParse: invalid @import',
|
|
3371
|
+
location: { src, ...position }
|
|
3372
|
+
});
|
|
3373
|
+
return null;
|
|
2953
3374
|
}
|
|
2954
|
-
|
|
2955
|
-
|
|
3375
|
+
}
|
|
3376
|
+
if (atRule.val == 'import') {
|
|
3377
|
+
// @ts-ignore
|
|
3378
|
+
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType && tokens[1].typ == exports.EnumToken.UrlTokenTokenType) {
|
|
3379
|
+
tokens.shift();
|
|
3380
|
+
// @ts-ignore
|
|
3381
|
+
tokens[0].typ = exports.EnumToken.StringTokenType;
|
|
3382
|
+
// @ts-ignore
|
|
3383
|
+
tokens[0].val = `"${tokens[0].val}"`;
|
|
2956
3384
|
}
|
|
3385
|
+
// @ts-ignore
|
|
3386
|
+
if (tokens[0].typ == exports.EnumToken.StringTokenType) {
|
|
3387
|
+
if (options.resolveImport) {
|
|
3388
|
+
const url = tokens[0].val.slice(1, -1);
|
|
3389
|
+
try {
|
|
3390
|
+
// @ts-ignore
|
|
3391
|
+
const root = await options.load(url, options.src).then((src) => {
|
|
3392
|
+
return doParse(src, Object.assign({}, options, {
|
|
3393
|
+
minify: false,
|
|
3394
|
+
// @ts-ignore
|
|
3395
|
+
src: options.resolve(url, options.src).absolute
|
|
3396
|
+
}));
|
|
3397
|
+
});
|
|
3398
|
+
bytesIn += root.stats.bytesIn;
|
|
3399
|
+
if (root.ast.chi.length > 0) {
|
|
3400
|
+
// @todo - filter charset, layer and scope
|
|
3401
|
+
context.chi.push(...root.ast.chi);
|
|
3402
|
+
}
|
|
3403
|
+
if (root.errors.length > 0) {
|
|
3404
|
+
errors.push(...root.errors);
|
|
3405
|
+
}
|
|
3406
|
+
return null;
|
|
3407
|
+
}
|
|
3408
|
+
catch (error) {
|
|
3409
|
+
// @ts-ignore
|
|
3410
|
+
errors.push({ action: 'ignore', message: 'doParse: ' + error.message, error });
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
// https://www.w3.org/TR/css-nesting-1/#conditionals
|
|
3416
|
+
// allowed nesting at-rules
|
|
3417
|
+
// there must be a top level rule in the stack
|
|
3418
|
+
const raw = parseTokens(tokens, { minify: options.minify }).reduce((acc, curr) => {
|
|
3419
|
+
acc.push(renderToken(curr, { removeComments: true }));
|
|
2957
3420
|
return acc;
|
|
2958
|
-
}, [
|
|
2959
|
-
acc.set(curr.join(''), curr);
|
|
2960
|
-
return acc;
|
|
2961
|
-
}, uniq);
|
|
3421
|
+
}, []);
|
|
2962
3422
|
const node = {
|
|
2963
|
-
typ:
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
chi: []
|
|
3423
|
+
typ: exports.EnumToken.AtRuleNodeType,
|
|
3424
|
+
nam: renderToken(atRule, { removeComments: true }),
|
|
3425
|
+
val: raw.join('')
|
|
2967
3426
|
};
|
|
2968
|
-
let raw = [...uniq.values()];
|
|
2969
3427
|
Object.defineProperty(node, 'raw', { enumerable: false, configurable: true, writable: true, value: raw });
|
|
3428
|
+
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
3429
|
+
node.chi = [];
|
|
3430
|
+
}
|
|
2970
3431
|
loc = {
|
|
2971
3432
|
sta: position,
|
|
2972
3433
|
src
|
|
@@ -2976,166 +3437,255 @@
|
|
|
2976
3437
|
}
|
|
2977
3438
|
// @ts-ignore
|
|
2978
3439
|
context.chi.push(node);
|
|
2979
|
-
return node;
|
|
3440
|
+
return delim.typ == exports.EnumToken.BlockStartTokenType ? node : null;
|
|
2980
3441
|
}
|
|
2981
3442
|
else {
|
|
2982
|
-
//
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3443
|
+
// rule
|
|
3444
|
+
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
3445
|
+
const position = map.get(tokens[0]);
|
|
3446
|
+
const uniq = new Map;
|
|
3447
|
+
parseTokens(tokens, { minify: true }).reduce((acc, curr, index, array) => {
|
|
3448
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
3449
|
+
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
3450
|
+
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
3451
|
+
combinators.includes(array[index - 1]?.val) ||
|
|
3452
|
+
combinators.includes(array[index + 1]?.val)) {
|
|
3453
|
+
return acc;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
let t = renderToken(curr, { minify: false });
|
|
3457
|
+
if (t == ',') {
|
|
3458
|
+
acc.push([]);
|
|
3459
|
+
}
|
|
3460
|
+
else {
|
|
3461
|
+
acc[acc.length - 1].push(t);
|
|
3462
|
+
}
|
|
3463
|
+
return acc;
|
|
3464
|
+
}, [[]]).reduce((acc, curr) => {
|
|
3465
|
+
acc.set(curr.join(''), curr);
|
|
3466
|
+
return acc;
|
|
3467
|
+
}, uniq);
|
|
3468
|
+
const node = {
|
|
3469
|
+
typ: exports.EnumToken.RuleNodeType,
|
|
3470
|
+
// @ts-ignore
|
|
3471
|
+
sel: [...uniq.keys()].join(','),
|
|
3472
|
+
chi: []
|
|
3473
|
+
};
|
|
3474
|
+
let raw = [...uniq.values()];
|
|
3475
|
+
Object.defineProperty(node, 'raw', {
|
|
3476
|
+
enumerable: false,
|
|
3477
|
+
configurable: true,
|
|
3478
|
+
writable: true,
|
|
3479
|
+
value: raw
|
|
3480
|
+
});
|
|
3481
|
+
loc = {
|
|
3482
|
+
sta: position,
|
|
3483
|
+
src
|
|
3484
|
+
};
|
|
3485
|
+
if (options.sourcemap) {
|
|
3486
|
+
node.loc = loc;
|
|
3000
3487
|
}
|
|
3488
|
+
// @ts-ignore
|
|
3489
|
+
context.chi.push(node);
|
|
3490
|
+
return node;
|
|
3001
3491
|
}
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3492
|
+
else {
|
|
3493
|
+
// declaration
|
|
3494
|
+
// @ts-ignore
|
|
3495
|
+
let name = null;
|
|
3496
|
+
// @ts-ignore
|
|
3497
|
+
let value = null;
|
|
3498
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
3499
|
+
if (tokens[i].typ == exports.EnumToken.CommentTokenType) {
|
|
3500
|
+
continue;
|
|
3501
|
+
}
|
|
3502
|
+
if (tokens[i].typ == exports.EnumToken.ColonTokenType) {
|
|
3503
|
+
name = tokens.slice(0, i);
|
|
3504
|
+
value = parseTokens(tokens.slice(i + 1), {
|
|
3505
|
+
parseColor: true,
|
|
3506
|
+
src: options.src,
|
|
3507
|
+
resolveUrls: options.resolveUrls,
|
|
3508
|
+
resolve: options.resolve,
|
|
3509
|
+
cwd: options.cwd
|
|
3013
3510
|
});
|
|
3014
|
-
return null;
|
|
3015
3511
|
}
|
|
3016
3512
|
}
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3513
|
+
if (name == null) {
|
|
3514
|
+
name = tokens;
|
|
3515
|
+
}
|
|
3516
|
+
const position = map.get(name[0]);
|
|
3517
|
+
if (name.length > 0) {
|
|
3518
|
+
for (let i = 1; i < name.length; i++) {
|
|
3519
|
+
if (name[i].typ != exports.EnumToken.WhitespaceTokenType && name[i].typ != exports.EnumToken.CommentTokenType) {
|
|
3520
|
+
errors.push({
|
|
3521
|
+
action: 'drop',
|
|
3522
|
+
message: 'doParse: invalid declaration',
|
|
3523
|
+
location: { src, ...position }
|
|
3524
|
+
});
|
|
3525
|
+
return null;
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
if (value == null || value.length == 0) {
|
|
3530
|
+
errors.push({
|
|
3531
|
+
action: 'drop',
|
|
3532
|
+
message: 'doParse: invalid declaration',
|
|
3533
|
+
location: { src, ...position }
|
|
3534
|
+
});
|
|
3535
|
+
return null;
|
|
3536
|
+
}
|
|
3537
|
+
const node = {
|
|
3538
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
3539
|
+
// @ts-ignore
|
|
3540
|
+
nam: renderToken(name.shift(), { removeComments: true }),
|
|
3541
|
+
// @ts-ignore
|
|
3542
|
+
val: value
|
|
3543
|
+
};
|
|
3544
|
+
while (node.val[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
3545
|
+
node.val.shift();
|
|
3546
|
+
}
|
|
3547
|
+
if (node.val.length == 0) {
|
|
3548
|
+
errors.push({
|
|
3549
|
+
action: 'drop',
|
|
3550
|
+
message: 'doParse: invalid declaration',
|
|
3551
|
+
location: { src, ...position }
|
|
3552
|
+
});
|
|
3553
|
+
return null;
|
|
3554
|
+
}
|
|
3030
3555
|
// @ts-ignore
|
|
3031
|
-
|
|
3032
|
-
};
|
|
3033
|
-
while (node.val[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
3034
|
-
node.val.shift();
|
|
3035
|
-
}
|
|
3036
|
-
if (node.val.length == 0) {
|
|
3037
|
-
errors.push({
|
|
3038
|
-
action: 'drop',
|
|
3039
|
-
message: 'doParse: invalid declaration',
|
|
3040
|
-
location: { src, ...position }
|
|
3041
|
-
});
|
|
3556
|
+
context.chi.push(node);
|
|
3042
3557
|
return null;
|
|
3043
3558
|
}
|
|
3044
|
-
// @ts-ignore
|
|
3045
|
-
context.chi.push(node);
|
|
3046
|
-
return null;
|
|
3047
3559
|
}
|
|
3048
3560
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
return node;
|
|
3054
|
-
}
|
|
3055
|
-
const iter = tokenize(iterator);
|
|
3056
|
-
let item;
|
|
3057
|
-
while (item = iter.next().value) {
|
|
3058
|
-
bytesIn = item.bytesIn;
|
|
3059
|
-
// doParse error
|
|
3060
|
-
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
3061
|
-
// bad token
|
|
3062
|
-
continue;
|
|
3561
|
+
function mapToken(token) {
|
|
3562
|
+
const node = getTokenType(token.token, token.hint);
|
|
3563
|
+
map.set(node, token.position);
|
|
3564
|
+
return node;
|
|
3063
3565
|
}
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3566
|
+
const iter = tokenize(iterator);
|
|
3567
|
+
let item;
|
|
3568
|
+
while (item = iter.next().value) {
|
|
3569
|
+
bytesIn = item.bytesIn;
|
|
3570
|
+
// doParse error
|
|
3571
|
+
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
3572
|
+
// bad token
|
|
3573
|
+
continue;
|
|
3574
|
+
}
|
|
3575
|
+
tokens.push(item);
|
|
3576
|
+
if (item.token == ';' || item.token == '{') {
|
|
3577
|
+
let node = await parseNode(tokens);
|
|
3578
|
+
if (node != null) {
|
|
3579
|
+
stack.push(node);
|
|
3580
|
+
// @ts-ignore
|
|
3581
|
+
context = node;
|
|
3582
|
+
}
|
|
3583
|
+
else if (item.token == '{') {
|
|
3584
|
+
// node == null
|
|
3585
|
+
// consume and throw away until the closing '}' or EOF
|
|
3586
|
+
let inBlock = 1;
|
|
3587
|
+
do {
|
|
3588
|
+
item = iter.next().value;
|
|
3589
|
+
if (item == null) {
|
|
3590
|
+
break;
|
|
3591
|
+
}
|
|
3592
|
+
if (item.token == '{') {
|
|
3593
|
+
inBlock++;
|
|
3594
|
+
}
|
|
3595
|
+
else if (item.token == '}') {
|
|
3596
|
+
inBlock--;
|
|
3597
|
+
}
|
|
3598
|
+
} while (inBlock != 0);
|
|
3599
|
+
}
|
|
3600
|
+
tokens = [];
|
|
3601
|
+
map = new Map;
|
|
3602
|
+
}
|
|
3603
|
+
else if (item.token == '}') {
|
|
3604
|
+
await parseNode(tokens);
|
|
3605
|
+
const previousNode = stack.pop();
|
|
3069
3606
|
// @ts-ignore
|
|
3070
|
-
context =
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
item = iter.next().value;
|
|
3078
|
-
if (item == null) {
|
|
3079
|
-
break;
|
|
3080
|
-
}
|
|
3081
|
-
if (item.token == '{') {
|
|
3082
|
-
inBlock++;
|
|
3083
|
-
}
|
|
3084
|
-
else if (item.token == '}') {
|
|
3085
|
-
inBlock--;
|
|
3086
|
-
}
|
|
3087
|
-
} while (inBlock != 0);
|
|
3607
|
+
context = stack[stack.length - 1] || ast;
|
|
3608
|
+
// @ts-ignore
|
|
3609
|
+
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
|
|
3610
|
+
context.chi.pop();
|
|
3611
|
+
}
|
|
3612
|
+
tokens = [];
|
|
3613
|
+
map = new Map;
|
|
3088
3614
|
}
|
|
3089
|
-
tokens = [];
|
|
3090
|
-
map = new Map;
|
|
3091
3615
|
}
|
|
3092
|
-
|
|
3616
|
+
if (tokens.length > 0) {
|
|
3093
3617
|
await parseNode(tokens);
|
|
3618
|
+
}
|
|
3619
|
+
while (stack.length > 0 && context != ast) {
|
|
3094
3620
|
const previousNode = stack.pop();
|
|
3095
3621
|
// @ts-ignore
|
|
3096
3622
|
context = stack[stack.length - 1] || ast;
|
|
3097
3623
|
// @ts-ignore
|
|
3098
3624
|
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
|
|
3099
3625
|
context.chi.pop();
|
|
3626
|
+
continue;
|
|
3100
3627
|
}
|
|
3101
|
-
|
|
3102
|
-
map = new Map;
|
|
3628
|
+
break;
|
|
3103
3629
|
}
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
}
|
|
3108
|
-
while (stack.length > 0 && context != ast) {
|
|
3109
|
-
const previousNode = stack.pop();
|
|
3110
|
-
// @ts-ignore
|
|
3111
|
-
context = stack[stack.length - 1] || ast;
|
|
3112
|
-
// @ts-ignore
|
|
3113
|
-
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
|
|
3114
|
-
context.chi.pop();
|
|
3115
|
-
continue;
|
|
3630
|
+
const endParseTime = performance.now();
|
|
3631
|
+
if (options.expandNestingRules) {
|
|
3632
|
+
ast = expand(ast);
|
|
3116
3633
|
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3634
|
+
if (options.visitor != null) {
|
|
3635
|
+
for (const result of walk(ast)) {
|
|
3636
|
+
if (result.node.typ == exports.EnumToken.DeclarationNodeType &&
|
|
3637
|
+
// @ts-ignore
|
|
3638
|
+
(typeof options.visitor.Declaration == 'function' || options.visitor.Declaration?.[result.node.nam] != null)) {
|
|
3639
|
+
const callable = typeof options.visitor.Declaration == 'function' ? options.visitor.Declaration : options.visitor.Declaration[result.node.nam];
|
|
3640
|
+
const results = callable(result.node);
|
|
3641
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
3642
|
+
continue;
|
|
3643
|
+
}
|
|
3644
|
+
// @ts-ignore
|
|
3645
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
3646
|
+
}
|
|
3647
|
+
else if (options.visitor.Rule != null && result.node.typ == exports.EnumToken.RuleNodeType) {
|
|
3648
|
+
const results = options.visitor.Rule(result.node);
|
|
3649
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
3650
|
+
continue;
|
|
3651
|
+
}
|
|
3652
|
+
// @ts-ignore
|
|
3653
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
3654
|
+
}
|
|
3655
|
+
else if (options.visitor.AtRule != null &&
|
|
3656
|
+
result.node.typ == exports.EnumToken.AtRuleNodeType &&
|
|
3657
|
+
// @ts-ignore
|
|
3658
|
+
(typeof options.visitor.AtRule == 'function' || options.visitor.AtRule?.[result.node.nam] != null)) {
|
|
3659
|
+
const callable = typeof options.visitor.AtRule == 'function' ? options.visitor.AtRule : options.visitor.AtRule[result.node.nam];
|
|
3660
|
+
const results = callable(result.node);
|
|
3661
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
3662
|
+
continue;
|
|
3663
|
+
}
|
|
3664
|
+
// @ts-ignore
|
|
3665
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3126
3668
|
}
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
errors,
|
|
3132
|
-
stats: {
|
|
3133
|
-
bytesIn,
|
|
3134
|
-
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
3135
|
-
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
3136
|
-
total: `${(endTime - startTime).toFixed(2)}ms`
|
|
3669
|
+
if (options.minify) {
|
|
3670
|
+
if (ast.chi.length > 0) {
|
|
3671
|
+
minify(ast, options, true, errors, false);
|
|
3672
|
+
}
|
|
3137
3673
|
}
|
|
3138
|
-
|
|
3674
|
+
const endTime = performance.now();
|
|
3675
|
+
if (options.signal != null) {
|
|
3676
|
+
options.signal.removeEventListener('abort', reject);
|
|
3677
|
+
}
|
|
3678
|
+
resolve({
|
|
3679
|
+
ast,
|
|
3680
|
+
errors,
|
|
3681
|
+
stats: {
|
|
3682
|
+
bytesIn,
|
|
3683
|
+
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
3684
|
+
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
3685
|
+
total: `${(endTime - startTime).toFixed(2)}ms`
|
|
3686
|
+
}
|
|
3687
|
+
});
|
|
3688
|
+
});
|
|
3139
3689
|
}
|
|
3140
3690
|
function parseString(src, options = { location: false }) {
|
|
3141
3691
|
return parseTokens([...tokenize(src)].map(t => {
|
|
@@ -3154,7 +3704,9 @@
|
|
|
3154
3704
|
return ([
|
|
3155
3705
|
exports.EnumToken.WhitespaceTokenType, exports.EnumToken.SemiColonTokenType, exports.EnumToken.ColonTokenType, exports.EnumToken.BlockStartTokenType,
|
|
3156
3706
|
exports.EnumToken.BlockStartTokenType, exports.EnumToken.AttrStartTokenType, exports.EnumToken.AttrEndTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType,
|
|
3157
|
-
exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.
|
|
3707
|
+
exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.CommaTokenType,
|
|
3708
|
+
exports.EnumToken.StartMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DashMatchTokenType, exports.EnumToken.ContainMatchTokenType,
|
|
3709
|
+
exports.EnumToken.EOFTokenType
|
|
3158
3710
|
].includes(hint) ? { typ: hint } : { typ: hint, val });
|
|
3159
3711
|
}
|
|
3160
3712
|
if (val == ' ') {
|
|
@@ -3218,8 +3770,36 @@
|
|
|
3218
3770
|
}
|
|
3219
3771
|
if (isFunction(val)) {
|
|
3220
3772
|
val = val.slice(0, -1);
|
|
3773
|
+
if (val == 'url') {
|
|
3774
|
+
return {
|
|
3775
|
+
typ: exports.EnumToken.UrlFunctionTokenType,
|
|
3776
|
+
val,
|
|
3777
|
+
chi: []
|
|
3778
|
+
};
|
|
3779
|
+
}
|
|
3780
|
+
if (['linear-gradient', 'radial-gradient', 'repeating-linear-gradient', 'repeating-radial-gradient', 'conic-gradient', 'image', 'image-set', 'element', 'cross-fade'].includes(val)) {
|
|
3781
|
+
return {
|
|
3782
|
+
typ: exports.EnumToken.ImageFunctionTokenType,
|
|
3783
|
+
val,
|
|
3784
|
+
chi: []
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
if (['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end', 'steps', 'cubic-bezier'].includes(val)) {
|
|
3788
|
+
return {
|
|
3789
|
+
typ: exports.EnumToken.TimingFunctionTokenType,
|
|
3790
|
+
val,
|
|
3791
|
+
chi: []
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3794
|
+
if (['view', 'scroll'].includes(val)) {
|
|
3795
|
+
return {
|
|
3796
|
+
typ: exports.EnumToken.TimelineFunctionTokenType,
|
|
3797
|
+
val,
|
|
3798
|
+
chi: []
|
|
3799
|
+
};
|
|
3800
|
+
}
|
|
3221
3801
|
return {
|
|
3222
|
-
typ:
|
|
3802
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
3223
3803
|
val,
|
|
3224
3804
|
chi: []
|
|
3225
3805
|
};
|
|
@@ -3249,7 +3829,7 @@
|
|
|
3249
3829
|
}
|
|
3250
3830
|
if (isIdent(val)) {
|
|
3251
3831
|
return {
|
|
3252
|
-
typ: exports.EnumToken.IdenTokenType,
|
|
3832
|
+
typ: val.startsWith('--') ? exports.EnumToken.DashedIdenTokenType : exports.EnumToken.IdenTokenType,
|
|
3253
3833
|
val
|
|
3254
3834
|
};
|
|
3255
3835
|
}
|
|
@@ -3282,7 +3862,7 @@
|
|
|
3282
3862
|
const t = tokens[i];
|
|
3283
3863
|
if (t.typ == exports.EnumToken.WhitespaceTokenType && ((i == 0 ||
|
|
3284
3864
|
i + 1 == tokens.length ||
|
|
3285
|
-
[exports.EnumToken.CommaTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType].includes(tokens[i + 1].typ)) ||
|
|
3865
|
+
[exports.EnumToken.CommaTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ColumnCombinatorTokenType].includes(tokens[i + 1].typ)) ||
|
|
3286
3866
|
(i > 0 &&
|
|
3287
3867
|
// tokens[i + 1]?.typ != Literal ||
|
|
3288
3868
|
// funcLike.includes(tokens[i - 1].typ) &&
|
|
@@ -3299,15 +3879,18 @@
|
|
|
3299
3879
|
tokens[i + 1].typ = exports.EnumToken.PseudoClassFuncTokenType;
|
|
3300
3880
|
}
|
|
3301
3881
|
else if (typ == exports.EnumToken.IdenTokenType) {
|
|
3882
|
+
if (tokens[i + 1].val in webkitPseudoAliasMap) {
|
|
3883
|
+
tokens[i + 1].val = webkitPseudoAliasMap[tokens[i + 1].val];
|
|
3884
|
+
}
|
|
3302
3885
|
tokens[i + 1].val = ':' + tokens[i + 1].val;
|
|
3303
3886
|
tokens[i + 1].typ = exports.EnumToken.PseudoClassTokenType;
|
|
3304
3887
|
}
|
|
3305
3888
|
if (typ == exports.EnumToken.FunctionTokenType || typ == exports.EnumToken.IdenTokenType) {
|
|
3306
3889
|
tokens.splice(i, 1);
|
|
3307
3890
|
i--;
|
|
3308
|
-
continue;
|
|
3309
3891
|
}
|
|
3310
3892
|
}
|
|
3893
|
+
continue;
|
|
3311
3894
|
}
|
|
3312
3895
|
if (t.typ == exports.EnumToken.AttrStartTokenType) {
|
|
3313
3896
|
let k = i;
|
|
@@ -3328,21 +3911,114 @@
|
|
|
3328
3911
|
if (t.chi.at(-1).typ == exports.EnumToken.AttrEndTokenType) {
|
|
3329
3912
|
// @ts-ignore
|
|
3330
3913
|
t.chi.pop();
|
|
3914
|
+
}
|
|
3915
|
+
// @ts-ignore
|
|
3916
|
+
if (t.chi.length > 1) {
|
|
3917
|
+
/*(<AttrToken>t).chi =*/
|
|
3331
3918
|
// @ts-ignore
|
|
3332
|
-
|
|
3333
|
-
|
|
3919
|
+
parseTokens(t.chi, t.typ);
|
|
3920
|
+
}
|
|
3921
|
+
// @ts-ignore
|
|
3922
|
+
// t.chi.forEach(val => {
|
|
3923
|
+
// if (val.typ == EnumToken.StringTokenType) {
|
|
3924
|
+
// const slice = val.val.slice(1, -1);
|
|
3925
|
+
// if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
3926
|
+
// Object.assign(val, {typ: EnumToken.IdenTokenType, val: slice});
|
|
3927
|
+
// }
|
|
3928
|
+
// }
|
|
3929
|
+
// });
|
|
3930
|
+
let m = t.chi.length;
|
|
3931
|
+
let val;
|
|
3932
|
+
for (m = 0; m < t.chi.length; m++) {
|
|
3933
|
+
val = t.chi[m];
|
|
3934
|
+
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
3935
|
+
const slice = val.val.slice(1, -1);
|
|
3936
|
+
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
3937
|
+
Object.assign(val, { typ: exports.EnumToken.IdenTokenType, val: slice });
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
else if (val.typ == exports.EnumToken.LiteralTokenType && val.val == '|') {
|
|
3941
|
+
let upper = m;
|
|
3942
|
+
let lower = m;
|
|
3943
|
+
while (++upper < t.chi.length) {
|
|
3944
|
+
if (t.chi[upper].typ == exports.EnumToken.CommentTokenType) {
|
|
3945
|
+
continue;
|
|
3946
|
+
}
|
|
3947
|
+
break;
|
|
3948
|
+
}
|
|
3949
|
+
while (lower-- > 0) {
|
|
3950
|
+
if (t.chi[lower].typ == exports.EnumToken.CommentTokenType) {
|
|
3951
|
+
continue;
|
|
3952
|
+
}
|
|
3953
|
+
break;
|
|
3954
|
+
}
|
|
3334
3955
|
// @ts-ignore
|
|
3335
|
-
|
|
3956
|
+
t.chi[m] = {
|
|
3957
|
+
typ: exports.EnumToken.NameSpaceAttributeTokenType,
|
|
3958
|
+
l: t.chi[lower],
|
|
3959
|
+
r: t.chi[upper]
|
|
3960
|
+
};
|
|
3961
|
+
t.chi.splice(upper, 1);
|
|
3962
|
+
if (lower >= 0) {
|
|
3963
|
+
t.chi.splice(lower, 1);
|
|
3964
|
+
m--;
|
|
3965
|
+
}
|
|
3336
3966
|
}
|
|
3337
|
-
|
|
3338
|
-
|
|
3967
|
+
else if ([
|
|
3968
|
+
exports.EnumToken.DashMatchTokenType, exports.EnumToken.StartMatchTokenType, exports.EnumToken.ContainMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType
|
|
3969
|
+
].includes(t.chi[m].typ)) {
|
|
3970
|
+
let upper = m;
|
|
3971
|
+
let lower = m;
|
|
3972
|
+
while (++upper < t.chi.length) {
|
|
3973
|
+
if (t.chi[upper].typ == exports.EnumToken.CommentTokenType) {
|
|
3974
|
+
continue;
|
|
3975
|
+
}
|
|
3976
|
+
break;
|
|
3977
|
+
}
|
|
3978
|
+
while (lower-- > 0) {
|
|
3979
|
+
if (t.chi[lower].typ == exports.EnumToken.CommentTokenType) {
|
|
3980
|
+
continue;
|
|
3981
|
+
}
|
|
3982
|
+
break;
|
|
3983
|
+
}
|
|
3984
|
+
val = t.chi[lower];
|
|
3339
3985
|
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
3340
3986
|
const slice = val.val.slice(1, -1);
|
|
3341
3987
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
3342
3988
|
Object.assign(val, { typ: exports.EnumToken.IdenTokenType, val: slice });
|
|
3343
3989
|
}
|
|
3344
3990
|
}
|
|
3345
|
-
|
|
3991
|
+
val = t.chi[upper];
|
|
3992
|
+
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
3993
|
+
const slice = val.val.slice(1, -1);
|
|
3994
|
+
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
3995
|
+
Object.assign(val, { typ: exports.EnumToken.IdenTokenType, val: slice });
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
t.chi[m] = {
|
|
3999
|
+
typ: exports.EnumToken.MatchExpressionTokenType,
|
|
4000
|
+
op: t.chi[m].typ,
|
|
4001
|
+
l: t.chi[lower],
|
|
4002
|
+
r: t.chi[upper]
|
|
4003
|
+
};
|
|
4004
|
+
t.chi.splice(upper, 1);
|
|
4005
|
+
t.chi.splice(lower, 1);
|
|
4006
|
+
upper = m;
|
|
4007
|
+
m--;
|
|
4008
|
+
while (upper < t.chi.length && t.chi[upper].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4009
|
+
upper++;
|
|
4010
|
+
}
|
|
4011
|
+
if (upper < t.chi.length &&
|
|
4012
|
+
t.chi[upper].typ == exports.EnumToken.Iden &&
|
|
4013
|
+
['i', 's'].includes(t.chi[upper].val.toLowerCase())) {
|
|
4014
|
+
t.chi[m].attr = t.chi[upper].val;
|
|
4015
|
+
t.chi.splice(upper, 1);
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
m = t.chi.length;
|
|
4020
|
+
while (t.chi.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4021
|
+
t.chi.pop();
|
|
3346
4022
|
}
|
|
3347
4023
|
continue;
|
|
3348
4024
|
}
|
|
@@ -3537,19 +4213,32 @@
|
|
|
3537
4213
|
return true;
|
|
3538
4214
|
}
|
|
3539
4215
|
|
|
3540
|
-
function* walk(node) {
|
|
4216
|
+
function* walk(node, filter) {
|
|
3541
4217
|
const parents = [node];
|
|
3542
4218
|
const root = node;
|
|
3543
4219
|
const weakMap = new WeakMap;
|
|
3544
4220
|
while (parents.length > 0) {
|
|
3545
4221
|
node = parents.shift();
|
|
4222
|
+
let option = null;
|
|
4223
|
+
if (filter != null) {
|
|
4224
|
+
option = filter(node);
|
|
4225
|
+
if (option === 'ignore') {
|
|
4226
|
+
continue;
|
|
4227
|
+
}
|
|
4228
|
+
if (option === 'stop') {
|
|
4229
|
+
break;
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
3546
4232
|
// @ts-ignore
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
4233
|
+
if (option !== 'children') {
|
|
4234
|
+
// @ts-ignore
|
|
4235
|
+
yield { node, parent: weakMap.get(node), root };
|
|
4236
|
+
}
|
|
4237
|
+
if (option !== 'ignore-children' && 'chi' in node) {
|
|
4238
|
+
parents.unshift(...node.chi);
|
|
4239
|
+
for (const child of node.chi.slice()) {
|
|
3550
4240
|
weakMap.set(child, node);
|
|
3551
4241
|
}
|
|
3552
|
-
parents.unshift(...node.chi);
|
|
3553
4242
|
}
|
|
3554
4243
|
}
|
|
3555
4244
|
}
|
|
@@ -3572,12 +4261,12 @@
|
|
|
3572
4261
|
|
|
3573
4262
|
function expand(ast) {
|
|
3574
4263
|
//
|
|
3575
|
-
if (![
|
|
4264
|
+
if (![exports.EnumToken.RuleNodeType, exports.EnumToken.StyleSheetNodeType, exports.EnumToken.AtRuleNodeType].includes(ast.typ)) {
|
|
3576
4265
|
return ast;
|
|
3577
4266
|
}
|
|
3578
|
-
if (
|
|
4267
|
+
if (exports.EnumToken.RuleNodeType == ast.typ) {
|
|
3579
4268
|
return {
|
|
3580
|
-
typ:
|
|
4269
|
+
typ: exports.EnumToken.StyleSheetNodeType,
|
|
3581
4270
|
chi: expandRule(ast)
|
|
3582
4271
|
};
|
|
3583
4272
|
}
|
|
@@ -3589,16 +4278,16 @@
|
|
|
3589
4278
|
for (let i = 0; i < ast.chi.length; i++) {
|
|
3590
4279
|
// @ts-ignore
|
|
3591
4280
|
const node = ast.chi[i];
|
|
3592
|
-
if (node.typ ==
|
|
4281
|
+
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
3593
4282
|
// @ts-ignore
|
|
3594
4283
|
result.chi.push(...expandRule(node));
|
|
3595
4284
|
// i += expanded.length - 1;
|
|
3596
4285
|
}
|
|
3597
|
-
else if (node.typ ==
|
|
4286
|
+
else if (node.typ == exports.EnumToken.AtRuleNodeType && 'chi' in node) {
|
|
3598
4287
|
let hasRule = false;
|
|
3599
4288
|
let j = node.chi.length;
|
|
3600
4289
|
while (j--) {
|
|
3601
|
-
if (node.chi[j].typ ==
|
|
4290
|
+
if (node.chi[j].typ == exports.EnumToken.RuleNodeType || node.chi[j].typ == exports.EnumToken.AtRuleNodeType) {
|
|
3602
4291
|
hasRule = true;
|
|
3603
4292
|
break;
|
|
3604
4293
|
}
|
|
@@ -3616,10 +4305,10 @@
|
|
|
3616
4305
|
function expandRule(node) {
|
|
3617
4306
|
const ast = { ...node, chi: node.chi.slice() };
|
|
3618
4307
|
const result = [];
|
|
3619
|
-
if (ast.typ ==
|
|
4308
|
+
if (ast.typ == exports.EnumToken.RuleNodeType) {
|
|
3620
4309
|
let i = 0;
|
|
3621
4310
|
for (; i < ast.chi.length; i++) {
|
|
3622
|
-
if (ast.chi[i].typ ==
|
|
4311
|
+
if (ast.chi[i].typ == exports.EnumToken.RuleNodeType) {
|
|
3623
4312
|
const rule = ast.chi[i];
|
|
3624
4313
|
if (!rule.sel.includes('&')) {
|
|
3625
4314
|
const selRule = splitRule(rule.sel);
|
|
@@ -3635,7 +4324,7 @@
|
|
|
3635
4324
|
ast.chi.splice(i--, 1);
|
|
3636
4325
|
result.push(...expandRule(rule));
|
|
3637
4326
|
}
|
|
3638
|
-
else if (ast.chi[i].typ ==
|
|
4327
|
+
else if (ast.chi[i].typ == exports.EnumToken.AtRuleNodeType) {
|
|
3639
4328
|
let astAtRule = ast.chi[i];
|
|
3640
4329
|
const values = [];
|
|
3641
4330
|
if (astAtRule.nam == 'scope') {
|
|
@@ -3650,7 +4339,7 @@
|
|
|
3650
4339
|
// @ts-ignore
|
|
3651
4340
|
astAtRule.chi.length = 0;
|
|
3652
4341
|
for (const r of expandRule(clone)) {
|
|
3653
|
-
if (r.typ ==
|
|
4342
|
+
if (r.typ == exports.EnumToken.AtRuleNodeType && 'chi' in r) {
|
|
3654
4343
|
if (astAtRule.val !== '' && r.val !== '') {
|
|
3655
4344
|
if (astAtRule.nam == 'media' && r.nam == 'media') {
|
|
3656
4345
|
r.val = astAtRule.val + ' and ' + r.val;
|
|
@@ -3662,7 +4351,7 @@
|
|
|
3662
4351
|
// @ts-ignore
|
|
3663
4352
|
values.push(r);
|
|
3664
4353
|
}
|
|
3665
|
-
else if (r.typ ==
|
|
4354
|
+
else if (r.typ == exports.EnumToken.RuleNodeType) {
|
|
3666
4355
|
// @ts-ignore
|
|
3667
4356
|
astAtRule.chi.push(...expandRule(r));
|
|
3668
4357
|
}
|
|
@@ -3722,6 +4411,128 @@
|
|
|
3722
4411
|
}
|
|
3723
4412
|
}
|
|
3724
4413
|
|
|
4414
|
+
class IterableWeakSet {
|
|
4415
|
+
#weakset = new WeakSet;
|
|
4416
|
+
#set = new Set;
|
|
4417
|
+
constructor(iterable) {
|
|
4418
|
+
if (iterable) {
|
|
4419
|
+
for (const value of iterable) {
|
|
4420
|
+
const ref = new WeakRef(value);
|
|
4421
|
+
this.#weakset.add(value);
|
|
4422
|
+
this.#set.add(ref);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
has(value) {
|
|
4427
|
+
return this.#weakset.has(value);
|
|
4428
|
+
}
|
|
4429
|
+
delete(value) {
|
|
4430
|
+
if (this.#weakset.has(value)) {
|
|
4431
|
+
for (const ref of this.#set) {
|
|
4432
|
+
if (ref.deref() === value) {
|
|
4433
|
+
this.#set.delete(ref);
|
|
4434
|
+
break;
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
return this.#weakset.delete(value);
|
|
4438
|
+
}
|
|
4439
|
+
return false;
|
|
4440
|
+
}
|
|
4441
|
+
add(value) {
|
|
4442
|
+
if (!this.#weakset.has(value)) {
|
|
4443
|
+
this.#weakset.add(value);
|
|
4444
|
+
this.#set.add(new WeakRef(value));
|
|
4445
|
+
}
|
|
4446
|
+
return this;
|
|
4447
|
+
}
|
|
4448
|
+
*[Symbol.iterator]() {
|
|
4449
|
+
for (const ref of new Set(this.#set)) {
|
|
4450
|
+
const key = ref.deref();
|
|
4451
|
+
if (key != null) {
|
|
4452
|
+
yield key;
|
|
4453
|
+
}
|
|
4454
|
+
else {
|
|
4455
|
+
this.#set.delete(ref);
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
class IterableWeakMap {
|
|
4462
|
+
#map;
|
|
4463
|
+
#set;
|
|
4464
|
+
constructor(iterable) {
|
|
4465
|
+
this.#map = new WeakMap;
|
|
4466
|
+
this.#set = new Set;
|
|
4467
|
+
if (iterable) {
|
|
4468
|
+
for (const [key, value] of iterable) {
|
|
4469
|
+
const ref = new WeakRef(key);
|
|
4470
|
+
this.#set.add(ref);
|
|
4471
|
+
this.#map.set(key, value);
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
has(key) {
|
|
4476
|
+
return this.#map.has(key);
|
|
4477
|
+
}
|
|
4478
|
+
set(key, value) {
|
|
4479
|
+
if (!this.#map.has(key)) {
|
|
4480
|
+
this.#set.add(new WeakRef(key));
|
|
4481
|
+
}
|
|
4482
|
+
this.#map.set(key, value);
|
|
4483
|
+
return this;
|
|
4484
|
+
}
|
|
4485
|
+
get(key) {
|
|
4486
|
+
return this.#map.get(key);
|
|
4487
|
+
}
|
|
4488
|
+
delete(key) {
|
|
4489
|
+
if (this.#map.has(key)) {
|
|
4490
|
+
for (const ref of this.#set) {
|
|
4491
|
+
if (ref.deref() === key) {
|
|
4492
|
+
this.#set.delete(ref);
|
|
4493
|
+
break;
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
return this.#map.delete(key);
|
|
4497
|
+
}
|
|
4498
|
+
return false;
|
|
4499
|
+
}
|
|
4500
|
+
*[Symbol.iterator]() {
|
|
4501
|
+
for (const ref of new Set(this.#set)) {
|
|
4502
|
+
const key = ref.deref();
|
|
4503
|
+
if (key == null) {
|
|
4504
|
+
this.#set.delete(ref);
|
|
4505
|
+
continue;
|
|
4506
|
+
}
|
|
4507
|
+
// @ts-ignore
|
|
4508
|
+
yield [key, this.#map.get(key)];
|
|
4509
|
+
}
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
function replace(node, variableScope) {
|
|
4514
|
+
for (const { value, parent: parentValue } of walkValues(node.val)) {
|
|
4515
|
+
if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
|
|
4516
|
+
if (value.chi.length == 1 && value.chi[0].typ == exports.EnumToken.DashedIdenTokenType) {
|
|
4517
|
+
const info = variableScope.get(value.chi[0].val);
|
|
4518
|
+
if (info?.replaceable) {
|
|
4519
|
+
if (parentValue != null) {
|
|
4520
|
+
let i = 0;
|
|
4521
|
+
for (; i < parentValue.chi.length; i++) {
|
|
4522
|
+
if (parentValue.chi[i] == value) {
|
|
4523
|
+
parentValue.chi.splice(i, 1, ...info.node.val);
|
|
4524
|
+
break;
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
else {
|
|
4529
|
+
node.val = info.node.val.slice();
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
3725
4536
|
class InlineCssVariables extends MinifyFeature {
|
|
3726
4537
|
static get ordering() {
|
|
3727
4538
|
return 0;
|
|
@@ -3741,14 +4552,14 @@
|
|
|
3741
4552
|
if (!('variableScope' in context)) {
|
|
3742
4553
|
context.variableScope = new Map;
|
|
3743
4554
|
}
|
|
3744
|
-
const isRoot = parent.typ ==
|
|
4555
|
+
const isRoot = parent.typ == exports.EnumToken.StyleSheetNodeType && ast.typ == exports.EnumToken.RuleNodeType && ast.sel == ':root';
|
|
3745
4556
|
const variableScope = context.variableScope;
|
|
3746
4557
|
// @ts-ignore
|
|
3747
4558
|
for (const node of ast.chi) {
|
|
3748
|
-
if (node.typ ==
|
|
4559
|
+
if (node.typ == exports.EnumToken.CDOCOMMNodeType || node.typ == exports.EnumToken.CommentNodeType) {
|
|
3749
4560
|
continue;
|
|
3750
4561
|
}
|
|
3751
|
-
if (node.typ !=
|
|
4562
|
+
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
3752
4563
|
break;
|
|
3753
4564
|
}
|
|
3754
4565
|
// css variable
|
|
@@ -3757,13 +4568,23 @@
|
|
|
3757
4568
|
const info = {
|
|
3758
4569
|
globalScope: isRoot,
|
|
3759
4570
|
// @ts-ignore
|
|
3760
|
-
parent: new
|
|
4571
|
+
parent: new IterableWeakSet(),
|
|
3761
4572
|
declarationCount: 1,
|
|
3762
4573
|
replaceable: isRoot,
|
|
3763
4574
|
node: node
|
|
3764
4575
|
};
|
|
3765
4576
|
info.parent.add(ast);
|
|
3766
4577
|
variableScope.set(node.nam, info);
|
|
4578
|
+
let recursive = false;
|
|
4579
|
+
for (const { value, parent: parentValue } of walkValues(node.val)) {
|
|
4580
|
+
if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
|
|
4581
|
+
recursive = true;
|
|
4582
|
+
break;
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
if (recursive) {
|
|
4586
|
+
replace(node, variableScope);
|
|
4587
|
+
}
|
|
3767
4588
|
}
|
|
3768
4589
|
else {
|
|
3769
4590
|
const info = variableScope.get(node.nam);
|
|
@@ -3779,27 +4600,7 @@
|
|
|
3779
4600
|
}
|
|
3780
4601
|
}
|
|
3781
4602
|
else {
|
|
3782
|
-
|
|
3783
|
-
if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
|
|
3784
|
-
if (value.chi.length == 1 && value.chi[0].typ == exports.EnumToken.IdenTokenType) {
|
|
3785
|
-
const info = variableScope.get(value.chi[0].val);
|
|
3786
|
-
if (info?.replaceable) {
|
|
3787
|
-
if (parentValue != null) {
|
|
3788
|
-
let i = 0;
|
|
3789
|
-
for (; i < parentValue.chi.length; i++) {
|
|
3790
|
-
if (parentValue.chi[i] == value) {
|
|
3791
|
-
parentValue.chi.splice(i, 1, ...info.node.val);
|
|
3792
|
-
break;
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
else {
|
|
3797
|
-
node.val = info.node.val.slice();
|
|
3798
|
-
}
|
|
3799
|
-
}
|
|
3800
|
-
}
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
4603
|
+
replace(node, variableScope);
|
|
3803
4604
|
}
|
|
3804
4605
|
}
|
|
3805
4606
|
}
|
|
@@ -3808,10 +4609,11 @@
|
|
|
3808
4609
|
for (const info of variableScope.values()) {
|
|
3809
4610
|
if (info.replaceable) {
|
|
3810
4611
|
let i;
|
|
4612
|
+
// drop declarations from :root{}
|
|
3811
4613
|
for (const parent of info.parent) {
|
|
3812
4614
|
i = parent.chi?.length ?? 0;
|
|
3813
4615
|
while (i--) {
|
|
3814
|
-
if (parent.chi[i].typ ==
|
|
4616
|
+
if (parent.chi[i].typ == exports.EnumToken.DeclarationNodeType && parent.chi[i].nam == info.node.nam) {
|
|
3815
4617
|
parent.chi.splice(i, 1);
|
|
3816
4618
|
}
|
|
3817
4619
|
}
|
|
@@ -3886,7 +4688,7 @@
|
|
|
3886
4688
|
this.config.properties.forEach((property, index) => {
|
|
3887
4689
|
if (!this.declarations.has(property)) {
|
|
3888
4690
|
this.declarations.set(property, {
|
|
3889
|
-
typ:
|
|
4691
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
3890
4692
|
nam: property,
|
|
3891
4693
|
val: []
|
|
3892
4694
|
});
|
|
@@ -3965,7 +4767,7 @@
|
|
|
3965
4767
|
}
|
|
3966
4768
|
}
|
|
3967
4769
|
iterator = [{
|
|
3968
|
-
typ:
|
|
4770
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
3969
4771
|
nam: this.config.shorthand,
|
|
3970
4772
|
val: values.reduce((acc, curr) => {
|
|
3971
4773
|
if (curr.length > 1) {
|
|
@@ -4000,6 +4802,7 @@
|
|
|
4000
4802
|
}
|
|
4001
4803
|
}
|
|
4002
4804
|
|
|
4805
|
+
const cache = new IterableWeakMap();
|
|
4003
4806
|
const propertiesConfig = getConfig();
|
|
4004
4807
|
class PropertyMap {
|
|
4005
4808
|
config;
|
|
@@ -4120,7 +4923,7 @@
|
|
|
4120
4923
|
if (values.length == 0) {
|
|
4121
4924
|
this.declarations = Object.entries(tokens).reduce((acc, curr) => {
|
|
4122
4925
|
acc.set(curr[0], {
|
|
4123
|
-
typ:
|
|
4926
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
4124
4927
|
nam: curr[0],
|
|
4125
4928
|
val: curr[1].reduce((acc, curr) => {
|
|
4126
4929
|
if (acc.length > 0) {
|
|
@@ -4184,6 +4987,44 @@
|
|
|
4184
4987
|
requiredCount = this.declarations.size;
|
|
4185
4988
|
}
|
|
4186
4989
|
if (!isShorthand || requiredCount < this.requiredCount) {
|
|
4990
|
+
if (isShorthand && this.declarations.has(this.config.shorthand)) {
|
|
4991
|
+
// console.debug(...this.declarations.values());
|
|
4992
|
+
const removeDefaults = (declaration) => {
|
|
4993
|
+
// const dec: AstDeclaration = {...declaration};
|
|
4994
|
+
const config = this.config.shorthand == declaration.nam ? this.config : this.config.properties[declaration.nam];
|
|
4995
|
+
declaration.val = declaration.val.filter((val) => {
|
|
4996
|
+
if (!cache.has(val)) {
|
|
4997
|
+
cache.set(val, renderToken(val, { minify: true }));
|
|
4998
|
+
}
|
|
4999
|
+
return !config.default.includes(cache.get(val));
|
|
5000
|
+
})
|
|
5001
|
+
.filter((val, index, array) => !(index > 0 &&
|
|
5002
|
+
val.typ == exports.EnumToken.WhitespaceTokenType &&
|
|
5003
|
+
array[index - 1].typ == exports.EnumToken.WhitespaceTokenType));
|
|
5004
|
+
if (declaration.val.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
5005
|
+
declaration.val.pop();
|
|
5006
|
+
}
|
|
5007
|
+
return declaration;
|
|
5008
|
+
};
|
|
5009
|
+
const values = [...this.declarations.values()].reduce((acc, curr) => {
|
|
5010
|
+
if (curr instanceof PropertySet) {
|
|
5011
|
+
acc.push(...curr);
|
|
5012
|
+
}
|
|
5013
|
+
else {
|
|
5014
|
+
acc.push(curr);
|
|
5015
|
+
}
|
|
5016
|
+
return acc;
|
|
5017
|
+
}, []);
|
|
5018
|
+
const filtered = values.map(removeDefaults).filter((x) => x.val.length > 0);
|
|
5019
|
+
if (filtered.length == 0 && this.config.default.length > 0) {
|
|
5020
|
+
filtered.push({
|
|
5021
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
5022
|
+
nam: this.config.shorthand,
|
|
5023
|
+
val: parseString(this.config.default[0])
|
|
5024
|
+
});
|
|
5025
|
+
}
|
|
5026
|
+
return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
|
|
5027
|
+
}
|
|
4187
5028
|
// @ts-ignore
|
|
4188
5029
|
iterable = this.declarations.values();
|
|
4189
5030
|
}
|
|
@@ -4196,7 +5037,6 @@
|
|
|
4196
5037
|
} : null;
|
|
4197
5038
|
const tokens = {};
|
|
4198
5039
|
// @ts-ignore
|
|
4199
|
-
/* const valid: string[] =*/
|
|
4200
5040
|
Object.entries(this.config.properties).reduce((acc, curr) => {
|
|
4201
5041
|
if (!this.declarations.has(curr[0])) {
|
|
4202
5042
|
if (curr[1].required) {
|
|
@@ -4262,7 +5102,7 @@
|
|
|
4262
5102
|
iterable = this.declarations.values();
|
|
4263
5103
|
}
|
|
4264
5104
|
else {
|
|
4265
|
-
|
|
5105
|
+
let values = Object.entries(tokens).reduce((acc, curr) => {
|
|
4266
5106
|
const props = this.config.properties[curr[0]];
|
|
4267
5107
|
for (let i = 0; i < curr[1].length; i++) {
|
|
4268
5108
|
if (acc.length == i) {
|
|
@@ -4279,6 +5119,7 @@
|
|
|
4279
5119
|
if (props.default.includes(curr[1][i].reduce((acc, curr) => acc + renderToken(curr) + ' ', '').trimEnd())) {
|
|
4280
5120
|
continue;
|
|
4281
5121
|
}
|
|
5122
|
+
// remove default values
|
|
4282
5123
|
let doFilterDefault = true;
|
|
4283
5124
|
if (curr[0] in propertiesConfig.properties) {
|
|
4284
5125
|
for (let v of values) {
|
|
@@ -4351,7 +5192,7 @@
|
|
|
4351
5192
|
return acc;
|
|
4352
5193
|
}, []);
|
|
4353
5194
|
if (this.config.mapping != null) {
|
|
4354
|
-
const val = values.reduce((acc, curr) => acc + renderToken(curr, { removeComments: true }), '');
|
|
5195
|
+
const val = values.reduce((acc, curr) => acc + renderToken(curr, { removeComments: true, minify: true }), '');
|
|
4355
5196
|
if (val in this.config.mapping) {
|
|
4356
5197
|
values.length = 0;
|
|
4357
5198
|
values.push({
|
|
@@ -4361,8 +5202,16 @@
|
|
|
4361
5202
|
});
|
|
4362
5203
|
}
|
|
4363
5204
|
}
|
|
5205
|
+
// @ts-ignore
|
|
5206
|
+
if (values.length == 1 &&
|
|
5207
|
+
typeof values[0].val == 'string' &&
|
|
5208
|
+
this.config.default.includes(values[0].val.toLowerCase()) &&
|
|
5209
|
+
this.config.default[0] != values[0].val.toLowerCase()) {
|
|
5210
|
+
// @ts-ignore/
|
|
5211
|
+
values = parseString(this.config.default[0]);
|
|
5212
|
+
}
|
|
4364
5213
|
iterable = [{
|
|
4365
|
-
typ:
|
|
5214
|
+
typ: exports.EnumToken.DeclarationNodeType,
|
|
4366
5215
|
nam: this.config.shorthand,
|
|
4367
5216
|
val: values
|
|
4368
5217
|
}][Symbol.iterator]();
|
|
@@ -4411,10 +5260,10 @@
|
|
|
4411
5260
|
this.declarations = new Map;
|
|
4412
5261
|
}
|
|
4413
5262
|
set(nam, value) {
|
|
4414
|
-
return this.add({ typ:
|
|
5263
|
+
return this.add({ typ: exports.EnumToken.DeclarationNodeType, nam, val: Array.isArray(value) ? value : parseString(String(value)) });
|
|
4415
5264
|
}
|
|
4416
5265
|
add(declaration) {
|
|
4417
|
-
if (declaration.typ !=
|
|
5266
|
+
if (declaration.typ != exports.EnumToken.DeclarationNodeType || !this.options.removeDuplicateDeclarations) {
|
|
4418
5267
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
4419
5268
|
return this;
|
|
4420
5269
|
}
|
|
@@ -4521,7 +5370,7 @@
|
|
|
4521
5370
|
for (; k < j; k++) {
|
|
4522
5371
|
// @ts-ignore
|
|
4523
5372
|
const node = ast.chi[k];
|
|
4524
|
-
if (node.typ ==
|
|
5373
|
+
if (node.typ == exports.EnumToken.CommentNodeType || node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
4525
5374
|
properties.add(node);
|
|
4526
5375
|
continue;
|
|
4527
5376
|
}
|
|
@@ -4533,6 +5382,97 @@
|
|
|
4533
5382
|
}
|
|
4534
5383
|
}
|
|
4535
5384
|
|
|
5385
|
+
const gcd = (x, y) => {
|
|
5386
|
+
x = Math.abs(x);
|
|
5387
|
+
y = Math.abs(y);
|
|
5388
|
+
let t;
|
|
5389
|
+
if (x == 0 || y == 0) {
|
|
5390
|
+
return 1;
|
|
5391
|
+
}
|
|
5392
|
+
while (y) {
|
|
5393
|
+
t = y;
|
|
5394
|
+
y = x % y;
|
|
5395
|
+
x = t;
|
|
5396
|
+
}
|
|
5397
|
+
return x;
|
|
5398
|
+
};
|
|
5399
|
+
function compute(a, b, op) {
|
|
5400
|
+
if (typeof a == 'number' && typeof b == 'number') {
|
|
5401
|
+
switch (op) {
|
|
5402
|
+
case exports.EnumToken.Add:
|
|
5403
|
+
return a + b;
|
|
5404
|
+
case exports.EnumToken.Sub:
|
|
5405
|
+
return a - b;
|
|
5406
|
+
case exports.EnumToken.Mul:
|
|
5407
|
+
return a * b;
|
|
5408
|
+
case exports.EnumToken.Div:
|
|
5409
|
+
const r = simplify(a, b);
|
|
5410
|
+
if (r[1] == 1) {
|
|
5411
|
+
return r[0];
|
|
5412
|
+
}
|
|
5413
|
+
const result = a / b;
|
|
5414
|
+
const r2 = reduceNumber(r[0]) + '/' + reduceNumber(r[1]);
|
|
5415
|
+
return reduceNumber(result).length <= r2.length ? result : {
|
|
5416
|
+
typ: exports.EnumToken.FractionTokenType,
|
|
5417
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(r[0]) },
|
|
5418
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(r[1]) }
|
|
5419
|
+
};
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5422
|
+
let l1 = typeof a == 'number' ? {
|
|
5423
|
+
typ: exports.EnumToken.FractionTokenType,
|
|
5424
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(a) },
|
|
5425
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: '1' }
|
|
5426
|
+
} : a;
|
|
5427
|
+
let r1 = typeof b == 'number' ? {
|
|
5428
|
+
typ: exports.EnumToken.FractionTokenType,
|
|
5429
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(b) },
|
|
5430
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: '1' }
|
|
5431
|
+
} : b;
|
|
5432
|
+
let l2;
|
|
5433
|
+
let r2;
|
|
5434
|
+
switch (op) {
|
|
5435
|
+
case exports.EnumToken.Add:
|
|
5436
|
+
// @ts-ignore
|
|
5437
|
+
l2 = l1.l.val * r1.r.val + l1.r.val * r1.l.val;
|
|
5438
|
+
// @ts-ignore
|
|
5439
|
+
r2 = l1.r.val * r1.r.val;
|
|
5440
|
+
break;
|
|
5441
|
+
case exports.EnumToken.Sub:
|
|
5442
|
+
// @ts-ignore
|
|
5443
|
+
l2 = l1.l.val * r1.r.val - l1.r.val * r1.l.val;
|
|
5444
|
+
// @ts-ignore
|
|
5445
|
+
r2 = l1.r.val * r1.r.val;
|
|
5446
|
+
break;
|
|
5447
|
+
case exports.EnumToken.Mul:
|
|
5448
|
+
// @ts-ignore
|
|
5449
|
+
l2 = l1.l.val * r1.l.val;
|
|
5450
|
+
// @ts-ignore
|
|
5451
|
+
r2 = l1.r.val * r1.r.val;
|
|
5452
|
+
break;
|
|
5453
|
+
case exports.EnumToken.Div:
|
|
5454
|
+
// @ts-ignore
|
|
5455
|
+
l2 = l1.l.val * r1.r.val;
|
|
5456
|
+
// @ts-ignore
|
|
5457
|
+
r2 = l1.r.val * r1.l.val;
|
|
5458
|
+
break;
|
|
5459
|
+
}
|
|
5460
|
+
const a2 = simplify(l2, r2);
|
|
5461
|
+
if (a2[1] == 1) {
|
|
5462
|
+
return a2[0];
|
|
5463
|
+
}
|
|
5464
|
+
const result = a2[0] / a2[1];
|
|
5465
|
+
return reduceNumber(result).length <= reduceNumber(a2[0]).length + 1 + reduceNumber(a2[1]).length ? result : {
|
|
5466
|
+
typ: exports.EnumToken.FractionTokenType,
|
|
5467
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(a2[0]) },
|
|
5468
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: reduceNumber(a2[1]) }
|
|
5469
|
+
};
|
|
5470
|
+
}
|
|
5471
|
+
function simplify(a, b) {
|
|
5472
|
+
const g = gcd(a, b);
|
|
5473
|
+
return g > 1 ? [a / g, b / g] : [a, b];
|
|
5474
|
+
}
|
|
5475
|
+
|
|
4536
5476
|
class ComputeCalcExpression extends MinifyFeature {
|
|
4537
5477
|
static get ordering() {
|
|
4538
5478
|
return 1;
|
|
@@ -4554,10 +5494,10 @@
|
|
|
4554
5494
|
}
|
|
4555
5495
|
// @ts-ignore
|
|
4556
5496
|
for (const node of ast.chi) {
|
|
4557
|
-
if (node.typ !=
|
|
5497
|
+
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
4558
5498
|
continue;
|
|
4559
5499
|
}
|
|
4560
|
-
const set = new
|
|
5500
|
+
const set = new IterableWeakSet;
|
|
4561
5501
|
for (const { parent } of walkValues(node.val)) {
|
|
4562
5502
|
if (parent != null && parent.typ == exports.EnumToken.FunctionTokenType && parent.val == 'calc') {
|
|
4563
5503
|
if (!set.has(parent)) {
|
|
@@ -4588,39 +5528,14 @@
|
|
|
4588
5528
|
}
|
|
4589
5529
|
if ((op == exports.EnumToken.Add || op == exports.EnumToken.Sub)) {
|
|
4590
5530
|
// @ts-ignore
|
|
4591
|
-
if (l.typ != r.typ
|
|
5531
|
+
if (l.typ != r.typ) {
|
|
4592
5532
|
return defaultReturn;
|
|
4593
5533
|
}
|
|
4594
|
-
// @ts-ignore
|
|
4595
|
-
return { ...l, val: reduceNumber(+l.val + (op == exports.EnumToken.Add ? +r.val : -1 * r.val)) };
|
|
4596
|
-
}
|
|
4597
|
-
else {
|
|
4598
|
-
// @ts-ignore
|
|
4599
|
-
let val;
|
|
4600
|
-
if (op == exports.EnumToken.Div) {
|
|
4601
|
-
if (r.typ != exports.EnumToken.NumberTokenType || r.val == '0') {
|
|
4602
|
-
return defaultReturn;
|
|
4603
|
-
}
|
|
4604
|
-
// @ts-ignore
|
|
4605
|
-
val = reduceNumber(l.val / r.val);
|
|
4606
|
-
}
|
|
4607
|
-
else {
|
|
4608
|
-
// @ts-ignore
|
|
4609
|
-
val = reduceNumber(r.val * l.val);
|
|
4610
|
-
}
|
|
4611
|
-
let result;
|
|
4612
|
-
if (r.typ == exports.EnumToken.NumberTokenType || op == exports.EnumToken.Div) {
|
|
4613
|
-
result = { ...l, val };
|
|
4614
|
-
}
|
|
4615
|
-
else {
|
|
4616
|
-
// @ts-ignore
|
|
4617
|
-
result = { ...r, val };
|
|
4618
|
-
}
|
|
4619
|
-
if (renderToken(result).length <= renderToken(defaultReturn).length) {
|
|
4620
|
-
return result;
|
|
4621
|
-
}
|
|
4622
5534
|
}
|
|
4623
|
-
|
|
5535
|
+
const typ = l.typ == exports.EnumToken.NumberTokenType ? r.typ : l.typ;
|
|
5536
|
+
// @ts-ignore
|
|
5537
|
+
const val = compute(typeof l.val == 'string' ? +l.val : l.val, typeof r.val == 'string' ? +r.val : r.val, op);
|
|
5538
|
+
return { ...(l.typ == exports.EnumToken.NumberTokenType ? r : l), typ, val: typeof val == 'number' ? reduceNumber(val) : val };
|
|
4624
5539
|
}
|
|
4625
5540
|
/**
|
|
4626
5541
|
* evaluate an array of tokens
|
|
@@ -4676,7 +5591,10 @@
|
|
|
4676
5591
|
*/
|
|
4677
5592
|
function inlineExpression(token) {
|
|
4678
5593
|
const result = [];
|
|
4679
|
-
if (token.typ == exports.EnumToken.
|
|
5594
|
+
if (token.typ == exports.EnumToken.ParensTokenType && token.chi.length == 1) {
|
|
5595
|
+
result.push(token.chi[0]);
|
|
5596
|
+
}
|
|
5597
|
+
else if (token.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
4680
5598
|
if ([exports.EnumToken.Mul, exports.EnumToken.Div].includes(token.op)) {
|
|
4681
5599
|
result.push(token);
|
|
4682
5600
|
}
|
|
@@ -4703,18 +5621,7 @@
|
|
|
4703
5621
|
if (token.l.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
4704
5622
|
token.l = evaluateExpression(token.l);
|
|
4705
5623
|
}
|
|
4706
|
-
|
|
4707
|
-
if (result.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
4708
|
-
[exports.EnumToken.Mul, exports.EnumToken.Div].includes(result.op)) {
|
|
4709
|
-
// wrap expression
|
|
4710
|
-
if (result.l.typ == exports.EnumToken.BinaryExpressionTokenType && [exports.EnumToken.Sub, exports.EnumToken.Add].includes(result.l.op)) {
|
|
4711
|
-
result.l = { typ: exports.EnumToken.ParensTokenType, chi: [result.l] };
|
|
4712
|
-
}
|
|
4713
|
-
else if (result.r.typ == exports.EnumToken.BinaryExpressionTokenType && [exports.EnumToken.Sub, exports.EnumToken.Add].includes(result.r.op)) {
|
|
4714
|
-
result.r = { typ: exports.EnumToken.ParensTokenType, chi: [result.r] };
|
|
4715
|
-
}
|
|
4716
|
-
}
|
|
4717
|
-
return result;
|
|
5624
|
+
return doEvaluate(token.l, token.r, token.op);
|
|
4718
5625
|
}
|
|
4719
5626
|
function isScalarToken(token) {
|
|
4720
5627
|
return token.typ != exports.EnumToken.BinaryExpressionTokenType && token.typ != exports.EnumToken.ParensTokenType && token.typ != exports.EnumToken.FunctionTokenType;
|
|
@@ -4762,7 +5669,7 @@
|
|
|
4762
5669
|
*/
|
|
4763
5670
|
function factor(tokens, ops) {
|
|
4764
5671
|
let isOp;
|
|
4765
|
-
const opList =
|
|
5672
|
+
const opList = ops.map(x => getArithmeticOperation(x));
|
|
4766
5673
|
if (tokens.length == 1) {
|
|
4767
5674
|
return [factorToken(tokens[0])];
|
|
4768
5675
|
}
|
|
@@ -4790,7 +5697,7 @@
|
|
|
4790
5697
|
InlineCssVariables: InlineCssVariables
|
|
4791
5698
|
});
|
|
4792
5699
|
|
|
4793
|
-
const combinators = ['+', '>', '~'];
|
|
5700
|
+
const combinators = ['+', '>', '~', '||'];
|
|
4794
5701
|
const notEndingWith = ['(', '['].concat(combinators);
|
|
4795
5702
|
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
4796
5703
|
// @ts-ignore
|
|
@@ -4806,7 +5713,12 @@
|
|
|
4806
5713
|
context.nodes.add(ast);
|
|
4807
5714
|
if (!('features' in options)) {
|
|
4808
5715
|
// @ts-ignore
|
|
4809
|
-
options = {
|
|
5716
|
+
options = {
|
|
5717
|
+
removeDuplicateDeclarations: true,
|
|
5718
|
+
computeShorthand: true,
|
|
5719
|
+
computeCalcExpression: true,
|
|
5720
|
+
features: [], ...options
|
|
5721
|
+
};
|
|
4810
5722
|
// @ts-ignore
|
|
4811
5723
|
for (const feature of features) {
|
|
4812
5724
|
feature.register(options);
|
|
@@ -4825,7 +5737,7 @@
|
|
|
4825
5737
|
curr.splice(0, 1);
|
|
4826
5738
|
}
|
|
4827
5739
|
}
|
|
4828
|
-
else if (ast.typ ==
|
|
5740
|
+
else if (ast.typ == exports.EnumToken.RuleNodeType && (isIdent(curr[0]) || isFunction(curr[0]))) {
|
|
4829
5741
|
curr.unshift('&', ' ');
|
|
4830
5742
|
}
|
|
4831
5743
|
acc.push(curr.join(''));
|
|
@@ -4834,7 +5746,7 @@
|
|
|
4834
5746
|
// @ts-ignore
|
|
4835
5747
|
if ('chi' in ast && ast.chi.length > 0) {
|
|
4836
5748
|
if (!nestingContent) {
|
|
4837
|
-
nestingContent = options.nestingRules && ast.typ ==
|
|
5749
|
+
nestingContent = options.nestingRules && ast.typ == exports.EnumToken.RuleNodeType;
|
|
4838
5750
|
}
|
|
4839
5751
|
let i = 0;
|
|
4840
5752
|
let previous;
|
|
@@ -4843,7 +5755,7 @@
|
|
|
4843
5755
|
// @ts-ignore
|
|
4844
5756
|
for (; i < ast.chi.length; i++) {
|
|
4845
5757
|
// @ts-ignore
|
|
4846
|
-
if (ast.chi[i].typ ==
|
|
5758
|
+
if (ast.chi[i].typ == exports.EnumToken.CommentNodeType) {
|
|
4847
5759
|
continue;
|
|
4848
5760
|
}
|
|
4849
5761
|
// @ts-ignore
|
|
@@ -4855,10 +5767,10 @@
|
|
|
4855
5767
|
i--;
|
|
4856
5768
|
continue;
|
|
4857
5769
|
}
|
|
4858
|
-
if (node.typ ==
|
|
5770
|
+
if (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'font-face') {
|
|
4859
5771
|
continue;
|
|
4860
5772
|
}
|
|
4861
|
-
if (node.typ ==
|
|
5773
|
+
if (node.typ == exports.EnumToken.AtRuleNodeType) {
|
|
4862
5774
|
if (node.nam == 'media' && node.val == 'all') {
|
|
4863
5775
|
// @ts-ignore
|
|
4864
5776
|
ast.chi?.splice(i, 1, ...node.chi);
|
|
@@ -4866,7 +5778,7 @@
|
|
|
4866
5778
|
continue;
|
|
4867
5779
|
}
|
|
4868
5780
|
// @ts-ignore
|
|
4869
|
-
if (previous?.typ ==
|
|
5781
|
+
if (previous?.typ == exports.EnumToken.AtRuleNodeType &&
|
|
4870
5782
|
previous.nam == node.nam &&
|
|
4871
5783
|
previous.val == node.val) {
|
|
4872
5784
|
if ('chi' in node) {
|
|
@@ -4885,14 +5797,14 @@
|
|
|
4885
5797
|
continue;
|
|
4886
5798
|
}
|
|
4887
5799
|
// @ts-ignore
|
|
4888
|
-
if (node.typ ==
|
|
5800
|
+
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
4889
5801
|
reduceRuleSelector(node);
|
|
4890
5802
|
let wrapper;
|
|
4891
5803
|
let match;
|
|
4892
5804
|
// @ts-ignore
|
|
4893
5805
|
if (options.nestingRules) {
|
|
4894
5806
|
// @ts-ignore
|
|
4895
|
-
if (previous?.typ ==
|
|
5807
|
+
if (previous?.typ == exports.EnumToken.RuleNodeType) {
|
|
4896
5808
|
// @ts-ignore
|
|
4897
5809
|
reduceRuleSelector(previous);
|
|
4898
5810
|
// @ts-ignore
|
|
@@ -4913,7 +5825,7 @@
|
|
|
4913
5825
|
// @ts-ignore
|
|
4914
5826
|
const nextNode = ast.chi[i];
|
|
4915
5827
|
// @ts-ignore
|
|
4916
|
-
if (nextNode.typ !=
|
|
5828
|
+
if (nextNode.typ != exports.EnumToken.RuleNodeType) {
|
|
4917
5829
|
break;
|
|
4918
5830
|
}
|
|
4919
5831
|
reduceRuleSelector(nextNode);
|
|
@@ -4967,7 +5879,7 @@
|
|
|
4967
5879
|
curr.splice(0, 2);
|
|
4968
5880
|
}
|
|
4969
5881
|
else {
|
|
4970
|
-
if (ast.typ !=
|
|
5882
|
+
if (ast.typ != exports.EnumToken.RuleNodeType && combinators.includes(curr[1])) {
|
|
4971
5883
|
wrap = false;
|
|
4972
5884
|
}
|
|
4973
5885
|
else {
|
|
@@ -5015,18 +5927,18 @@
|
|
|
5015
5927
|
let k = previous.chi.length;
|
|
5016
5928
|
while (k-- > 0) {
|
|
5017
5929
|
// @ts-ignore
|
|
5018
|
-
if (previous.chi[k].typ ==
|
|
5930
|
+
if (previous.chi[k].typ == exports.EnumToken.CommentNodeType) {
|
|
5019
5931
|
continue;
|
|
5020
5932
|
}
|
|
5021
5933
|
// @ts-ignore
|
|
5022
|
-
shouldMerge = previous.chi[k].typ ==
|
|
5934
|
+
shouldMerge = previous.chi[k].typ == exports.EnumToken.DeclarationNodeType;
|
|
5023
5935
|
break;
|
|
5024
5936
|
}
|
|
5025
5937
|
if (shouldMerge) {
|
|
5026
5938
|
// @ts-ignore
|
|
5027
|
-
if ((node.typ ==
|
|
5939
|
+
if ((node.typ == exports.EnumToken.RuleNodeType && node.sel == previous.sel) ||
|
|
5028
5940
|
// @ts-ignore
|
|
5029
|
-
(node.typ ==
|
|
5941
|
+
(node.typ == exports.EnumToken.AtRuleNodeType) && node.val != 'font-face' && node.val == previous.val) {
|
|
5030
5942
|
// @ts-ignore
|
|
5031
5943
|
node.chi.unshift(...previous.chi);
|
|
5032
5944
|
// @ts-ignore
|
|
@@ -5043,7 +5955,7 @@
|
|
|
5043
5955
|
nodeIndex = i;
|
|
5044
5956
|
continue;
|
|
5045
5957
|
}
|
|
5046
|
-
else if (node.typ ==
|
|
5958
|
+
else if (node.typ == exports.EnumToken.RuleNodeType && previous?.typ == exports.EnumToken.RuleNodeType) {
|
|
5047
5959
|
const intersect = diff(previous, node, reducer, options);
|
|
5048
5960
|
if (intersect != null) {
|
|
5049
5961
|
if (intersect.node1.chi.length == 0) {
|
|
@@ -5100,7 +6012,7 @@
|
|
|
5100
6012
|
// @ts-ignore
|
|
5101
6013
|
previous != null &&
|
|
5102
6014
|
// previous.optimized != null &&
|
|
5103
|
-
previous.typ ==
|
|
6015
|
+
previous.typ == exports.EnumToken.RuleNodeType &&
|
|
5104
6016
|
previous.sel.includes('&')) {
|
|
5105
6017
|
fixSelector(previous);
|
|
5106
6018
|
}
|
|
@@ -5110,9 +6022,9 @@
|
|
|
5110
6022
|
// @ts-ignore
|
|
5111
6023
|
if (recursive && node != null && ('chi' in node)) {
|
|
5112
6024
|
// @ts-ignore
|
|
5113
|
-
if (!node.chi.some(n => n.typ ==
|
|
6025
|
+
if (!node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
5114
6026
|
// @ts-ignore
|
|
5115
|
-
if (!(node.typ ==
|
|
6027
|
+
if (!(node.typ == exports.EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
|
|
5116
6028
|
minify(node, options, recursive, errors, nestingContent, context);
|
|
5117
6029
|
}
|
|
5118
6030
|
}
|
|
@@ -5121,12 +6033,12 @@
|
|
|
5121
6033
|
// @ts-ignore
|
|
5122
6034
|
node != null &&
|
|
5123
6035
|
// previous.optimized != null &&
|
|
5124
|
-
node.typ ==
|
|
6036
|
+
node.typ == exports.EnumToken.RuleNodeType &&
|
|
5125
6037
|
node.sel.includes('&')) {
|
|
5126
6038
|
fixSelector(node);
|
|
5127
6039
|
}
|
|
5128
6040
|
}
|
|
5129
|
-
if (ast.typ ==
|
|
6041
|
+
if (ast.typ == exports.EnumToken.StyleSheetNodeType) {
|
|
5130
6042
|
let parent;
|
|
5131
6043
|
let parents = [ast];
|
|
5132
6044
|
while (parents.length > 0) {
|
|
@@ -5135,7 +6047,7 @@
|
|
|
5135
6047
|
for (let k = 0; k < parent.chi.length; k++) {
|
|
5136
6048
|
// @ts-ignore
|
|
5137
6049
|
const node = parent.chi[k];
|
|
5138
|
-
if (!('chi' in node) || node.typ ==
|
|
6050
|
+
if (!('chi' in node) || node.typ == exports.EnumToken.StyleSheetNodeType || (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'font-face')) {
|
|
5139
6051
|
continue;
|
|
5140
6052
|
}
|
|
5141
6053
|
// @ts-ignore
|
|
@@ -5246,11 +6158,11 @@
|
|
|
5246
6158
|
// @ts-ignore
|
|
5247
6159
|
for (let i = 0; i < node.chi?.length; i++) {
|
|
5248
6160
|
// @ts-ignore
|
|
5249
|
-
if (node.chi[i].typ ==
|
|
6161
|
+
if (node.chi[i].typ == exports.EnumToken.CommentNodeType) {
|
|
5250
6162
|
continue;
|
|
5251
6163
|
}
|
|
5252
6164
|
// @ts-ignore
|
|
5253
|
-
return node.chi[i].typ ==
|
|
6165
|
+
return node.chi[i].typ == exports.EnumToken.DeclarationNodeType;
|
|
5254
6166
|
}
|
|
5255
6167
|
return true;
|
|
5256
6168
|
}
|
|
@@ -5396,7 +6308,7 @@
|
|
|
5396
6308
|
if (matchFunction != 0 || inAttr != 0) {
|
|
5397
6309
|
return null;
|
|
5398
6310
|
}
|
|
5399
|
-
if (parentType !=
|
|
6311
|
+
if (parentType != exports.EnumToken.RuleNodeType) {
|
|
5400
6312
|
for (const part of match) {
|
|
5401
6313
|
if (part.length > 0 && combinators.includes(part[0].charAt(0))) {
|
|
5402
6314
|
return null;
|
|
@@ -5602,7 +6514,7 @@
|
|
|
5602
6514
|
}
|
|
5603
6515
|
const intersect = [];
|
|
5604
6516
|
while (i--) {
|
|
5605
|
-
if (node1.chi[i].typ ==
|
|
6517
|
+
if (node1.chi[i].typ == exports.EnumToken.CommentNodeType) {
|
|
5606
6518
|
continue;
|
|
5607
6519
|
}
|
|
5608
6520
|
j = node2.chi.length;
|
|
@@ -5610,7 +6522,7 @@
|
|
|
5610
6522
|
break;
|
|
5611
6523
|
}
|
|
5612
6524
|
while (j--) {
|
|
5613
|
-
if (node2.chi[j].typ ==
|
|
6525
|
+
if (node2.chi[j].typ == exports.EnumToken.CommentNodeType) {
|
|
5614
6526
|
continue;
|
|
5615
6527
|
}
|
|
5616
6528
|
if (node1.chi[i].nam == node2.chi[j].nam) {
|
|
@@ -5822,54 +6734,17 @@
|
|
|
5822
6734
|
});
|
|
5823
6735
|
}
|
|
5824
6736
|
|
|
5825
|
-
exports.colorsFunc = colorsFunc;
|
|
5826
|
-
exports.combinators = combinators;
|
|
5827
6737
|
exports.dirname = dirname;
|
|
5828
|
-
exports.doParse = doParse;
|
|
5829
|
-
exports.doRender = doRender;
|
|
5830
6738
|
exports.expand = expand;
|
|
5831
|
-
exports.funcList = funcList;
|
|
5832
|
-
exports.getConfig = getConfig;
|
|
5833
|
-
exports.hasDeclaration = hasDeclaration;
|
|
5834
|
-
exports.isAngle = isAngle;
|
|
5835
|
-
exports.isAtKeyword = isAtKeyword;
|
|
5836
|
-
exports.isColor = isColor;
|
|
5837
|
-
exports.isDigit = isDigit;
|
|
5838
|
-
exports.isDimension = isDimension;
|
|
5839
|
-
exports.isFrequency = isFrequency;
|
|
5840
|
-
exports.isFunction = isFunction;
|
|
5841
|
-
exports.isHash = isHash;
|
|
5842
|
-
exports.isHexColor = isHexColor;
|
|
5843
|
-
exports.isIdent = isIdent;
|
|
5844
|
-
exports.isIdentCodepoint = isIdentCodepoint;
|
|
5845
|
-
exports.isIdentStart = isIdentStart;
|
|
5846
|
-
exports.isLength = isLength;
|
|
5847
|
-
exports.isNewLine = isNewLine;
|
|
5848
|
-
exports.isNonPrintable = isNonPrintable;
|
|
5849
|
-
exports.isNumber = isNumber;
|
|
5850
|
-
exports.isPercentage = isPercentage;
|
|
5851
|
-
exports.isPseudo = isPseudo;
|
|
5852
|
-
exports.isResolution = isResolution;
|
|
5853
|
-
exports.isTime = isTime;
|
|
5854
|
-
exports.isWhiteSpace = isWhiteSpace;
|
|
5855
6739
|
exports.load = load;
|
|
5856
|
-
exports.matchType = matchType;
|
|
5857
|
-
exports.matchUrl = matchUrl;
|
|
5858
6740
|
exports.minify = minify;
|
|
5859
6741
|
exports.parse = parse;
|
|
5860
|
-
exports.parseDimension = parseDimension;
|
|
5861
6742
|
exports.parseString = parseString;
|
|
5862
6743
|
exports.parseTokens = parseTokens;
|
|
5863
|
-
exports.reduceNumber = reduceNumber;
|
|
5864
|
-
exports.reduceSelector = reduceSelector;
|
|
5865
6744
|
exports.render = render;
|
|
5866
6745
|
exports.renderToken = renderToken;
|
|
5867
|
-
exports.replaceCompound = replaceCompound;
|
|
5868
6746
|
exports.resolve = resolve;
|
|
5869
|
-
exports.splitRule = splitRule;
|
|
5870
|
-
exports.tokenize = tokenize;
|
|
5871
6747
|
exports.transform = transform;
|
|
5872
|
-
exports.urlTokenMatcher = urlTokenMatcher;
|
|
5873
6748
|
exports.walk = walk;
|
|
5874
6749
|
exports.walkValues = walkValues;
|
|
5875
6750
|
|