@tbela99/css-parser 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -2
- package/dist/config.json.js +611 -4
- package/dist/index-umd-web.js +2898 -1223
- package/dist/index.cjs +2898 -1223
- package/dist/lib/ast/expand.js +11 -11
- package/dist/lib/ast/features/calc.js +33 -224
- package/dist/lib/ast/features/index.js +3 -3
- package/dist/lib/ast/features/inlinecssvariables.js +46 -31
- package/dist/lib/ast/features/shorthand.js +7 -7
- package/dist/lib/ast/features/utils/math.js +95 -0
- package/dist/lib/ast/math/expression.js +185 -0
- package/dist/lib/ast/math/math.js +95 -0
- package/dist/lib/ast/minify.js +34 -29
- package/dist/lib/ast/types.js +108 -78
- package/dist/lib/ast/walk.js +42 -9
- package/dist/lib/fs/resolve.js +4 -3
- package/dist/lib/iterable/set.js +48 -0
- package/dist/lib/iterable/weakmap.js +53 -0
- package/dist/lib/iterable/weakset.js +48 -0
- package/dist/lib/parser/declaration/list.js +7 -3
- package/dist/lib/parser/declaration/map.js +86 -7
- package/dist/lib/parser/declaration/set.js +43 -23
- package/dist/lib/parser/parse.js +561 -387
- package/dist/lib/parser/tokenize.js +42 -13
- package/dist/lib/parser/utils/declaration.js +67 -0
- package/dist/lib/parser/utils/syntax.js +32 -2
- package/dist/lib/parser/utils/type.js +7 -2
- package/dist/lib/renderer/render.js +163 -47
- package/dist/lib/renderer/utils/calccolor.js +238 -0
- package/dist/lib/renderer/utils/color.js +36 -164
- package/dist/lib/renderer/utils/hex.js +124 -0
- package/dist/lib/renderer/utils/hsl.js +49 -0
- package/dist/lib/renderer/utils/hsv.js +15 -0
- package/dist/lib/renderer/utils/hwb.js +50 -0
- package/dist/lib/renderer/utils/rgb.js +66 -0
- package/dist/node/index.js +8 -12
- package/dist/web/index.js +8 -12
- package/package.json +9 -7
- package/dist/index.d.ts +0 -1056
- /package/dist/lib/ast/{utiles → utils}/minifyfeature.js +0 -0
package/dist/lib/ast/types.js
CHANGED
|
@@ -1,88 +1,118 @@
|
|
|
1
|
-
var NodeType;
|
|
2
|
-
(function (NodeType) {
|
|
3
|
-
NodeType[NodeType["CommentNodeType"] = 0] = "CommentNodeType";
|
|
4
|
-
NodeType[NodeType["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
|
5
|
-
NodeType[NodeType["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
6
|
-
NodeType[NodeType["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
7
|
-
NodeType[NodeType["RuleNodeType"] = 4] = "RuleNodeType";
|
|
8
|
-
NodeType[NodeType["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
9
|
-
})(NodeType || (NodeType = {}));
|
|
10
1
|
var EnumToken;
|
|
11
2
|
(function (EnumToken) {
|
|
12
3
|
EnumToken[EnumToken["CommentTokenType"] = 0] = "CommentTokenType";
|
|
13
4
|
EnumToken[EnumToken["CDOCOMMTokenType"] = 1] = "CDOCOMMTokenType";
|
|
14
|
-
EnumToken[EnumToken["
|
|
15
|
-
EnumToken[EnumToken["
|
|
16
|
-
EnumToken[EnumToken["
|
|
17
|
-
EnumToken[EnumToken["
|
|
18
|
-
EnumToken[EnumToken["
|
|
19
|
-
EnumToken[EnumToken["
|
|
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["
|
|
5
|
+
EnumToken[EnumToken["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
6
|
+
EnumToken[EnumToken["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
7
|
+
EnumToken[EnumToken["RuleNodeType"] = 4] = "RuleNodeType";
|
|
8
|
+
EnumToken[EnumToken["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
9
|
+
EnumToken[EnumToken["LiteralTokenType"] = 6] = "LiteralTokenType";
|
|
10
|
+
EnumToken[EnumToken["IdenTokenType"] = 7] = "IdenTokenType";
|
|
11
|
+
EnumToken[EnumToken["DashedIdenTokenType"] = 8] = "DashedIdenTokenType";
|
|
12
|
+
EnumToken[EnumToken["CommaTokenType"] = 9] = "CommaTokenType";
|
|
13
|
+
EnumToken[EnumToken["ColonTokenType"] = 10] = "ColonTokenType";
|
|
14
|
+
EnumToken[EnumToken["SemiColonTokenType"] = 11] = "SemiColonTokenType";
|
|
15
|
+
EnumToken[EnumToken["NumberTokenType"] = 12] = "NumberTokenType";
|
|
16
|
+
EnumToken[EnumToken["AtRuleTokenType"] = 13] = "AtRuleTokenType";
|
|
17
|
+
EnumToken[EnumToken["PercentageTokenType"] = 14] = "PercentageTokenType";
|
|
18
|
+
EnumToken[EnumToken["FunctionTokenType"] = 15] = "FunctionTokenType";
|
|
19
|
+
EnumToken[EnumToken["TimelineFunctionTokenType"] = 16] = "TimelineFunctionTokenType";
|
|
20
|
+
EnumToken[EnumToken["TimingFunctionTokenType"] = 17] = "TimingFunctionTokenType";
|
|
21
|
+
EnumToken[EnumToken["UrlFunctionTokenType"] = 18] = "UrlFunctionTokenType";
|
|
22
|
+
EnumToken[EnumToken["ImageFunctionTokenType"] = 19] = "ImageFunctionTokenType";
|
|
23
|
+
EnumToken[EnumToken["StringTokenType"] = 20] = "StringTokenType";
|
|
24
|
+
EnumToken[EnumToken["UnclosedStringTokenType"] = 21] = "UnclosedStringTokenType";
|
|
25
|
+
EnumToken[EnumToken["DimensionTokenType"] = 22] = "DimensionTokenType";
|
|
26
|
+
EnumToken[EnumToken["LengthTokenType"] = 23] = "LengthTokenType";
|
|
27
|
+
EnumToken[EnumToken["AngleTokenType"] = 24] = "AngleTokenType";
|
|
28
|
+
EnumToken[EnumToken["TimeTokenType"] = 25] = "TimeTokenType";
|
|
29
|
+
EnumToken[EnumToken["FrequencyTokenType"] = 26] = "FrequencyTokenType";
|
|
30
|
+
EnumToken[EnumToken["ResolutionTokenType"] = 27] = "ResolutionTokenType";
|
|
31
|
+
EnumToken[EnumToken["HashTokenType"] = 28] = "HashTokenType";
|
|
32
|
+
EnumToken[EnumToken["BlockStartTokenType"] = 29] = "BlockStartTokenType";
|
|
33
|
+
EnumToken[EnumToken["BlockEndTokenType"] = 30] = "BlockEndTokenType";
|
|
34
|
+
EnumToken[EnumToken["AttrStartTokenType"] = 31] = "AttrStartTokenType";
|
|
35
|
+
EnumToken[EnumToken["AttrEndTokenType"] = 32] = "AttrEndTokenType";
|
|
36
|
+
EnumToken[EnumToken["StartParensTokenType"] = 33] = "StartParensTokenType";
|
|
37
|
+
EnumToken[EnumToken["EndParensTokenType"] = 34] = "EndParensTokenType";
|
|
38
|
+
EnumToken[EnumToken["ParensTokenType"] = 35] = "ParensTokenType";
|
|
39
|
+
EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
|
|
40
|
+
EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
|
|
41
|
+
EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
|
|
42
|
+
EnumToken[EnumToken["LtTokenType"] = 39] = "LtTokenType";
|
|
43
|
+
EnumToken[EnumToken["LteTokenType"] = 40] = "LteTokenType";
|
|
44
|
+
EnumToken[EnumToken["GtTokenType"] = 41] = "GtTokenType";
|
|
45
|
+
EnumToken[EnumToken["GteTokenType"] = 42] = "GteTokenType";
|
|
46
|
+
EnumToken[EnumToken["PseudoClassTokenType"] = 43] = "PseudoClassTokenType";
|
|
47
|
+
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 44] = "PseudoClassFuncTokenType";
|
|
48
|
+
EnumToken[EnumToken["DelimTokenType"] = 45] = "DelimTokenType";
|
|
49
|
+
EnumToken[EnumToken["UrlTokenTokenType"] = 46] = "UrlTokenTokenType";
|
|
50
|
+
EnumToken[EnumToken["EOFTokenType"] = 47] = "EOFTokenType";
|
|
51
|
+
EnumToken[EnumToken["ImportantTokenType"] = 48] = "ImportantTokenType";
|
|
52
|
+
EnumToken[EnumToken["ColorTokenType"] = 49] = "ColorTokenType";
|
|
53
|
+
EnumToken[EnumToken["AttrTokenType"] = 50] = "AttrTokenType";
|
|
54
|
+
EnumToken[EnumToken["BadCommentTokenType"] = 51] = "BadCommentTokenType";
|
|
55
|
+
EnumToken[EnumToken["BadCdoTokenType"] = 52] = "BadCdoTokenType";
|
|
56
|
+
EnumToken[EnumToken["BadUrlTokenType"] = 53] = "BadUrlTokenType";
|
|
57
|
+
EnumToken[EnumToken["BadStringTokenType"] = 54] = "BadStringTokenType";
|
|
58
|
+
EnumToken[EnumToken["BinaryExpressionTokenType"] = 55] = "BinaryExpressionTokenType";
|
|
59
|
+
EnumToken[EnumToken["UnaryExpressionTokenType"] = 56] = "UnaryExpressionTokenType";
|
|
60
|
+
EnumToken[EnumToken["FlexTokenType"] = 57] = "FlexTokenType";
|
|
61
61
|
/* catch all */
|
|
62
|
-
EnumToken[EnumToken["ListToken"] =
|
|
62
|
+
EnumToken[EnumToken["ListToken"] = 58] = "ListToken";
|
|
63
63
|
/* arithmetic tokens */
|
|
64
|
-
EnumToken[EnumToken["Add"] =
|
|
65
|
-
EnumToken[EnumToken["Mul"] =
|
|
66
|
-
EnumToken[EnumToken["Div"] =
|
|
67
|
-
EnumToken[EnumToken["Sub"] =
|
|
64
|
+
EnumToken[EnumToken["Add"] = 59] = "Add";
|
|
65
|
+
EnumToken[EnumToken["Mul"] = 60] = "Mul";
|
|
66
|
+
EnumToken[EnumToken["Div"] = 61] = "Div";
|
|
67
|
+
EnumToken[EnumToken["Sub"] = 62] = "Sub";
|
|
68
|
+
/* new tokens */
|
|
69
|
+
EnumToken[EnumToken["ColumnCombinatorTokenType"] = 63] = "ColumnCombinatorTokenType";
|
|
70
|
+
EnumToken[EnumToken["ContainMatchTokenType"] = 64] = "ContainMatchTokenType";
|
|
71
|
+
EnumToken[EnumToken["StartMatchTokenType"] = 65] = "StartMatchTokenType";
|
|
72
|
+
EnumToken[EnumToken["EndMatchTokenType"] = 66] = "EndMatchTokenType";
|
|
73
|
+
EnumToken[EnumToken["MatchExpressionTokenType"] = 67] = "MatchExpressionTokenType";
|
|
74
|
+
EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 68] = "NameSpaceAttributeTokenType";
|
|
75
|
+
EnumToken[EnumToken["FractionTokenType"] = 69] = "FractionTokenType";
|
|
76
|
+
EnumToken[EnumToken["IdenListTokenType"] = 70] = "IdenListTokenType";
|
|
77
|
+
EnumToken[EnumToken["GridTemplateFuncTokenType"] = 71] = "GridTemplateFuncTokenType";
|
|
68
78
|
/* aliases */
|
|
69
|
-
EnumToken[EnumToken["Time"] =
|
|
70
|
-
EnumToken[EnumToken["Iden"] =
|
|
71
|
-
EnumToken[EnumToken["Hash"] =
|
|
72
|
-
EnumToken[EnumToken["
|
|
73
|
-
EnumToken[EnumToken["
|
|
74
|
-
EnumToken[EnumToken["
|
|
75
|
-
EnumToken[EnumToken["
|
|
76
|
-
EnumToken[EnumToken["
|
|
77
|
-
EnumToken[EnumToken["
|
|
78
|
-
EnumToken[EnumToken["
|
|
79
|
-
EnumToken[EnumToken["
|
|
79
|
+
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
80
|
+
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
81
|
+
EnumToken[EnumToken["Hash"] = 28] = "Hash";
|
|
82
|
+
EnumToken[EnumToken["Flex"] = 57] = "Flex";
|
|
83
|
+
EnumToken[EnumToken["Angle"] = 24] = "Angle";
|
|
84
|
+
EnumToken[EnumToken["Color"] = 49] = "Color";
|
|
85
|
+
EnumToken[EnumToken["Comma"] = 9] = "Comma";
|
|
86
|
+
EnumToken[EnumToken["String"] = 20] = "String";
|
|
87
|
+
EnumToken[EnumToken["Length"] = 23] = "Length";
|
|
88
|
+
EnumToken[EnumToken["Number"] = 12] = "Number";
|
|
89
|
+
EnumToken[EnumToken["Perc"] = 14] = "Perc";
|
|
90
|
+
EnumToken[EnumToken["Literal"] = 6] = "Literal";
|
|
80
91
|
EnumToken[EnumToken["Comment"] = 0] = "Comment";
|
|
81
|
-
EnumToken[EnumToken["UrlFunc"] =
|
|
82
|
-
EnumToken[EnumToken["Dimension"] =
|
|
83
|
-
EnumToken[EnumToken["Frequency"] =
|
|
84
|
-
EnumToken[EnumToken["Resolution"] =
|
|
85
|
-
EnumToken[EnumToken["Whitespace"] =
|
|
92
|
+
EnumToken[EnumToken["UrlFunc"] = 18] = "UrlFunc";
|
|
93
|
+
EnumToken[EnumToken["Dimension"] = 22] = "Dimension";
|
|
94
|
+
EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
|
|
95
|
+
EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
|
|
96
|
+
EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
|
|
97
|
+
EnumToken[EnumToken["IdenList"] = 70] = "IdenList";
|
|
98
|
+
EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
|
|
99
|
+
EnumToken[EnumToken["GridTemplateFunc"] = 71] = "GridTemplateFunc";
|
|
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";
|
|
86
105
|
})(EnumToken || (EnumToken = {}));
|
|
106
|
+
const funcLike = [
|
|
107
|
+
EnumToken.ParensTokenType,
|
|
108
|
+
EnumToken.FunctionTokenType,
|
|
109
|
+
EnumToken.UrlFunctionTokenType,
|
|
110
|
+
EnumToken.StartParensTokenType,
|
|
111
|
+
EnumToken.ImageFunctionTokenType,
|
|
112
|
+
EnumToken.TimingFunctionTokenType,
|
|
113
|
+
EnumToken.TimingFunctionTokenType,
|
|
114
|
+
EnumToken.PseudoClassFuncTokenType,
|
|
115
|
+
EnumToken.GridTemplateFuncTokenType
|
|
116
|
+
];
|
|
87
117
|
|
|
88
|
-
export { EnumToken,
|
|
118
|
+
export { EnumToken, funcLike };
|
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,33 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
import { EnumToken } from './types.js';
|
|
2
|
+
|
|
3
|
+
function* walk(node, filter) {
|
|
2
4
|
const parents = [node];
|
|
3
5
|
const root = node;
|
|
4
6
|
const weakMap = new WeakMap;
|
|
5
7
|
while (parents.length > 0) {
|
|
6
8
|
node = parents.shift();
|
|
9
|
+
let option = null;
|
|
10
|
+
if (filter != null) {
|
|
11
|
+
option = filter(node);
|
|
12
|
+
if (option === 'ignore') {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (option === 'stop') {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
// @ts-ignore
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
if (option !== 'children') {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
yield { node, parent: weakMap.get(node), root };
|
|
23
|
+
}
|
|
24
|
+
if (option !== 'ignore-children' && 'chi' in node) {
|
|
25
|
+
parents.unshift(...node.chi);
|
|
26
|
+
for (const child of node.chi.slice()) {
|
|
11
27
|
weakMap.set(child, node);
|
|
12
28
|
}
|
|
13
|
-
parents.unshift(...node.chi);
|
|
14
29
|
}
|
|
15
30
|
}
|
|
16
31
|
}
|
|
17
|
-
function* walkValues(values) {
|
|
32
|
+
function* walkValues(values, root = null, filter) {
|
|
18
33
|
const stack = values.slice();
|
|
19
34
|
const weakMap = new WeakMap;
|
|
20
35
|
let value;
|
|
21
36
|
while (stack.length > 0) {
|
|
22
37
|
value = stack.shift();
|
|
38
|
+
let option = null;
|
|
39
|
+
if (filter != null) {
|
|
40
|
+
option = filter(value);
|
|
41
|
+
if (option === 'ignore') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (option === 'stop') {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
23
48
|
// @ts-ignore
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
if (option !== 'children') {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
yield { value, parent: weakMap.get(value), root };
|
|
52
|
+
}
|
|
53
|
+
if (option !== 'ignore-children' && 'chi' in value) {
|
|
54
|
+
for (const child of value.chi.slice()) {
|
|
27
55
|
weakMap.set(child, value);
|
|
28
56
|
}
|
|
29
57
|
stack.unshift(...value.chi);
|
|
30
58
|
}
|
|
59
|
+
else if (value.typ == EnumToken.BinaryExpressionTokenType) {
|
|
60
|
+
weakMap.set(value.l, value);
|
|
61
|
+
weakMap.set(value.r, value);
|
|
62
|
+
stack.unshift(value.l, value.r);
|
|
63
|
+
}
|
|
31
64
|
}
|
|
32
65
|
}
|
|
33
66
|
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -35,13 +35,14 @@ function splitPath(result) {
|
|
|
35
35
|
parts[parts.length - 1] += chr;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
let k =
|
|
39
|
-
while (k
|
|
38
|
+
let k = -1;
|
|
39
|
+
while (++k < parts.length) {
|
|
40
40
|
if (parts[k] == '.') {
|
|
41
|
-
parts.splice(k
|
|
41
|
+
parts.splice(k--, 1);
|
|
42
42
|
}
|
|
43
43
|
else if (parts[k] == '..') {
|
|
44
44
|
parts.splice(k - 1, 2);
|
|
45
|
+
k -= 2;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
return { parts, i };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class IterableWeakSet {
|
|
2
|
+
#weakset = new WeakSet;
|
|
3
|
+
#set = new Set;
|
|
4
|
+
constructor(iterable) {
|
|
5
|
+
if (iterable) {
|
|
6
|
+
for (const value of iterable) {
|
|
7
|
+
const ref = new WeakRef(value);
|
|
8
|
+
this.#weakset.add(value);
|
|
9
|
+
this.#set.add(ref);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
has(value) {
|
|
14
|
+
return this.#weakset.has(value);
|
|
15
|
+
}
|
|
16
|
+
delete(value) {
|
|
17
|
+
if (this.#weakset.has(value)) {
|
|
18
|
+
for (const ref of this.#set) {
|
|
19
|
+
if (ref.deref() === value) {
|
|
20
|
+
this.#set.delete(ref);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this.#weakset.delete(value);
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
add(value) {
|
|
29
|
+
if (!this.#weakset.has(value)) {
|
|
30
|
+
this.#weakset.add(value);
|
|
31
|
+
this.#set.add(new WeakRef(value));
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
*[Symbol.iterator]() {
|
|
36
|
+
for (const ref of new Set(this.#set)) {
|
|
37
|
+
const key = ref.deref();
|
|
38
|
+
if (key != null) {
|
|
39
|
+
yield key;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.#set.delete(ref);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { IterableWeakSet };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class IterableWeakMap {
|
|
2
|
+
#map;
|
|
3
|
+
#set;
|
|
4
|
+
constructor(iterable) {
|
|
5
|
+
this.#map = new WeakMap;
|
|
6
|
+
this.#set = new Set;
|
|
7
|
+
if (iterable) {
|
|
8
|
+
for (const [key, value] of iterable) {
|
|
9
|
+
const ref = new WeakRef(key);
|
|
10
|
+
this.#set.add(ref);
|
|
11
|
+
this.#map.set(key, value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
has(key) {
|
|
16
|
+
return this.#map.has(key);
|
|
17
|
+
}
|
|
18
|
+
set(key, value) {
|
|
19
|
+
if (!this.#map.has(key)) {
|
|
20
|
+
this.#set.add(new WeakRef(key));
|
|
21
|
+
}
|
|
22
|
+
this.#map.set(key, value);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
get(key) {
|
|
26
|
+
return this.#map.get(key);
|
|
27
|
+
}
|
|
28
|
+
delete(key) {
|
|
29
|
+
if (this.#map.has(key)) {
|
|
30
|
+
for (const ref of this.#set) {
|
|
31
|
+
if (ref.deref() === key) {
|
|
32
|
+
this.#set.delete(ref);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return this.#map.delete(key);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
*[Symbol.iterator]() {
|
|
41
|
+
for (const ref of new Set(this.#set)) {
|
|
42
|
+
const key = ref.deref();
|
|
43
|
+
if (key == null) {
|
|
44
|
+
this.#set.delete(ref);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
yield [key, this.#map.get(key)];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { IterableWeakMap };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class IterableWeakSet {
|
|
2
|
+
#weakset = new WeakSet;
|
|
3
|
+
#set = new Set;
|
|
4
|
+
constructor(iterable) {
|
|
5
|
+
if (iterable) {
|
|
6
|
+
for (const value of iterable) {
|
|
7
|
+
const ref = new WeakRef(value);
|
|
8
|
+
this.#weakset.add(value);
|
|
9
|
+
this.#set.add(ref);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
has(value) {
|
|
14
|
+
return this.#weakset.has(value);
|
|
15
|
+
}
|
|
16
|
+
delete(value) {
|
|
17
|
+
if (this.#weakset.has(value)) {
|
|
18
|
+
for (const ref of this.#set) {
|
|
19
|
+
if (ref.deref() === value) {
|
|
20
|
+
this.#set.delete(ref);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this.#weakset.delete(value);
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
add(value) {
|
|
29
|
+
if (!this.#weakset.has(value)) {
|
|
30
|
+
this.#weakset.add(value);
|
|
31
|
+
this.#set.add(new WeakRef(value));
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
*[Symbol.iterator]() {
|
|
36
|
+
for (const ref of new Set(this.#set)) {
|
|
37
|
+
const key = ref.deref();
|
|
38
|
+
if (key != null) {
|
|
39
|
+
yield key;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.#set.delete(ref);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { IterableWeakSet };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropertySet } from './set.js';
|
|
2
2
|
import '../../renderer/utils/color.js';
|
|
3
|
-
import '../../ast/types.js';
|
|
3
|
+
import { EnumToken } from '../../ast/types.js';
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
5
|
import { parseString } from '../parse.js';
|
|
6
6
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
@@ -21,10 +21,14 @@ class PropertyList {
|
|
|
21
21
|
this.declarations = new Map;
|
|
22
22
|
}
|
|
23
23
|
set(nam, value) {
|
|
24
|
-
return this.add({
|
|
24
|
+
return this.add({
|
|
25
|
+
typ: EnumToken.DeclarationNodeType,
|
|
26
|
+
nam,
|
|
27
|
+
val: Array.isArray(value) ? value : parseString(String(value))
|
|
28
|
+
});
|
|
25
29
|
}
|
|
26
30
|
add(declaration) {
|
|
27
|
-
if (declaration.typ !=
|
|
31
|
+
if (declaration.typ != EnumToken.DeclarationNodeType || !this.options.removeDuplicateDeclarations) {
|
|
28
32
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
29
33
|
return this;
|
|
30
34
|
}
|
|
@@ -128,7 +128,7 @@ class PropertyMap {
|
|
|
128
128
|
if (values.length == 0) {
|
|
129
129
|
this.declarations = Object.entries(tokens).reduce((acc, curr) => {
|
|
130
130
|
acc.set(curr[0], {
|
|
131
|
-
typ:
|
|
131
|
+
typ: EnumToken.DeclarationNodeType,
|
|
132
132
|
nam: curr[0],
|
|
133
133
|
val: curr[1].reduce((acc, curr) => {
|
|
134
134
|
if (acc.length > 0) {
|
|
@@ -192,6 +192,69 @@ class PropertyMap {
|
|
|
192
192
|
requiredCount = this.declarations.size;
|
|
193
193
|
}
|
|
194
194
|
if (!isShorthand || requiredCount < this.requiredCount) {
|
|
195
|
+
if (isShorthand && this.declarations.has(this.config.shorthand)) {
|
|
196
|
+
const cache = new Map();
|
|
197
|
+
const removeDefaults = (declaration) => {
|
|
198
|
+
let config = this.config.shorthand == declaration.nam ? this.config : this.config.properties[declaration.nam];
|
|
199
|
+
if (config == null && declaration.nam in propertiesConfig.properties) {
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
const shorthand = propertiesConfig.properties[declaration.nam].shorthand;
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
config = propertiesConfig.properties[shorthand];
|
|
204
|
+
}
|
|
205
|
+
declaration.val = declaration.val.map((t) => {
|
|
206
|
+
if (!cache.has(t)) {
|
|
207
|
+
cache.set(t, renderToken(t, { minify: true }));
|
|
208
|
+
}
|
|
209
|
+
const value = cache.get(t);
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
if (config?.mapping?.[value] != null) {
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
t = parseString(config.mapping[value])[0];
|
|
214
|
+
cache.set(t, renderToken(t, { minify: true }));
|
|
215
|
+
}
|
|
216
|
+
return t;
|
|
217
|
+
}).filter((val) => {
|
|
218
|
+
return !config?.default?.includes(cache.get(val));
|
|
219
|
+
})
|
|
220
|
+
.filter((val, index, array) => !(index > 0 &&
|
|
221
|
+
val.typ == EnumToken.WhitespaceTokenType &&
|
|
222
|
+
array[index - 1].typ == EnumToken.WhitespaceTokenType));
|
|
223
|
+
if (declaration.val.at(-1)?.typ == EnumToken.WhitespaceTokenType) {
|
|
224
|
+
declaration.val.pop();
|
|
225
|
+
}
|
|
226
|
+
return declaration;
|
|
227
|
+
};
|
|
228
|
+
const values = [...this.declarations.values()].reduce((acc, curr) => {
|
|
229
|
+
if (curr instanceof PropertySet) {
|
|
230
|
+
acc.push(...curr);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
acc.push(curr);
|
|
234
|
+
}
|
|
235
|
+
return acc;
|
|
236
|
+
}, []);
|
|
237
|
+
let isImportant = false;
|
|
238
|
+
const filtered = values.map(removeDefaults).filter((x) => x.val.filter((t) => {
|
|
239
|
+
if (t.typ == EnumToken.ImportantTokenType) {
|
|
240
|
+
isImportant = true;
|
|
241
|
+
}
|
|
242
|
+
return ![EnumToken.WhitespaceTokenType, EnumToken.ImportantTokenType].includes(t.typ);
|
|
243
|
+
}).length > 0);
|
|
244
|
+
if (filtered.length == 0 && this.config.default.length > 0) {
|
|
245
|
+
filtered.push({
|
|
246
|
+
typ: EnumToken.DeclarationNodeType,
|
|
247
|
+
nam: this.config.shorthand,
|
|
248
|
+
val: parseString(this.config.default[0])
|
|
249
|
+
});
|
|
250
|
+
if (isImportant) {
|
|
251
|
+
filtered[0].val.push({
|
|
252
|
+
typ: EnumToken.ImportantTokenType
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
|
|
257
|
+
}
|
|
195
258
|
// @ts-ignore
|
|
196
259
|
iterable = this.declarations.values();
|
|
197
260
|
}
|
|
@@ -204,7 +267,6 @@ class PropertyMap {
|
|
|
204
267
|
} : null;
|
|
205
268
|
const tokens = {};
|
|
206
269
|
// @ts-ignore
|
|
207
|
-
/* const valid: string[] =*/
|
|
208
270
|
Object.entries(this.config.properties).reduce((acc, curr) => {
|
|
209
271
|
if (!this.declarations.has(curr[0])) {
|
|
210
272
|
if (curr[1].required) {
|
|
@@ -270,7 +332,7 @@ class PropertyMap {
|
|
|
270
332
|
iterable = this.declarations.values();
|
|
271
333
|
}
|
|
272
334
|
else {
|
|
273
|
-
|
|
335
|
+
let values = Object.entries(tokens).reduce((acc, curr) => {
|
|
274
336
|
const props = this.config.properties[curr[0]];
|
|
275
337
|
for (let i = 0; i < curr[1].length; i++) {
|
|
276
338
|
if (acc.length == i) {
|
|
@@ -285,8 +347,11 @@ class PropertyMap {
|
|
|
285
347
|
}, []);
|
|
286
348
|
// @todo remove renderToken call
|
|
287
349
|
if (props.default.includes(curr[1][i].reduce((acc, curr) => acc + renderToken(curr) + ' ', '').trimEnd())) {
|
|
288
|
-
|
|
350
|
+
if (!this.config.properties[curr[0]].required) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
289
353
|
}
|
|
354
|
+
// remove default values
|
|
290
355
|
let doFilterDefault = true;
|
|
291
356
|
if (curr[0] in propertiesConfig.properties) {
|
|
292
357
|
for (let v of values) {
|
|
@@ -298,12 +363,15 @@ class PropertyMap {
|
|
|
298
363
|
}
|
|
299
364
|
}
|
|
300
365
|
// remove default values
|
|
301
|
-
|
|
366
|
+
const filtered = values.filter((val) => {
|
|
302
367
|
if (val.typ == EnumToken.WhitespaceTokenType || val.typ == EnumToken.CommentTokenType) {
|
|
303
368
|
return false;
|
|
304
369
|
}
|
|
305
370
|
return !doFilterDefault || !(val.typ == EnumToken.IdenTokenType && props.default.includes(val.val));
|
|
306
371
|
});
|
|
372
|
+
if (filtered.length > 0 || !(this.requiredCount == requiredCount && this.config.properties[curr[0]].required)) {
|
|
373
|
+
values = filtered;
|
|
374
|
+
}
|
|
307
375
|
if (values.length > 0) {
|
|
308
376
|
if ('mapping' in props) {
|
|
309
377
|
// @ts-ignore
|
|
@@ -359,7 +427,10 @@ class PropertyMap {
|
|
|
359
427
|
return acc;
|
|
360
428
|
}, []);
|
|
361
429
|
if (this.config.mapping != null) {
|
|
362
|
-
const val = values.reduce((acc, curr) => acc + renderToken(curr, {
|
|
430
|
+
const val = values.reduce((acc, curr) => acc + renderToken(curr, {
|
|
431
|
+
removeComments: true,
|
|
432
|
+
minify: true
|
|
433
|
+
}), '');
|
|
363
434
|
if (val in this.config.mapping) {
|
|
364
435
|
values.length = 0;
|
|
365
436
|
values.push({
|
|
@@ -369,8 +440,16 @@ class PropertyMap {
|
|
|
369
440
|
});
|
|
370
441
|
}
|
|
371
442
|
}
|
|
443
|
+
// @ts-ignore
|
|
444
|
+
if (values.length == 1 &&
|
|
445
|
+
typeof values[0].val == 'string' &&
|
|
446
|
+
this.config.default.includes(values[0].val.toLowerCase()) &&
|
|
447
|
+
this.config.default[0] != values[0].val.toLowerCase()) {
|
|
448
|
+
// @ts-ignore/
|
|
449
|
+
values = parseString(this.config.default[0]);
|
|
450
|
+
}
|
|
372
451
|
iterable = [{
|
|
373
|
-
typ:
|
|
452
|
+
typ: EnumToken.DeclarationNodeType,
|
|
374
453
|
nam: this.config.shorthand,
|
|
375
454
|
val: values
|
|
376
455
|
}][Symbol.iterator]();
|