@tbela99/css-parser 0.7.1 → 0.9.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/.editorconfig +484 -0
- package/README.md +140 -84
- package/dist/index-umd-web.js +8461 -51655
- package/dist/index.cjs +8437 -51636
- package/dist/index.d.ts +220 -68
- package/dist/lib/ast/expand.js +46 -9
- package/dist/lib/ast/features/calc.js +76 -12
- package/dist/lib/ast/features/inlinecssvariables.js +6 -1
- package/dist/lib/ast/features/prefix.js +17 -9
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/math/expression.js +299 -11
- package/dist/lib/ast/math/math.js +7 -1
- package/dist/lib/ast/minify.js +30 -16
- package/dist/lib/ast/types.js +59 -49
- package/dist/lib/ast/walk.js +92 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +60 -52
- package/dist/lib/parser/declaration/set.js +1 -12
- package/dist/lib/parser/parse.js +371 -119
- package/dist/lib/parser/tokenize.js +31 -6
- package/dist/lib/parser/utils/declaration.js +2 -2
- package/dist/lib/parser/utils/type.js +6 -6
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +1 -0
- package/dist/lib/renderer/color/hex.js +2 -1
- package/dist/lib/renderer/color/hsl.js +2 -1
- package/dist/lib/renderer/color/hwb.js +3 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/lch.js +2 -1
- package/dist/lib/renderer/color/oklab.js +3 -2
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- package/dist/lib/renderer/color/prophotorgb.js +1 -1
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +52 -28
- package/dist/lib/renderer/color/rgb.js +2 -1
- package/dist/lib/renderer/color/srgb.js +3 -2
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +2 -1
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +62 -12
- package/dist/lib/syntax/syntax.js +362 -4
- package/dist/lib/validation/at-rules/container.js +353 -0
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/custom-media.js +52 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/else.js +5 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
- package/dist/lib/validation/at-rules/import.js +199 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +30 -0
- package/dist/lib/validation/at-rules/media.js +254 -0
- package/dist/lib/validation/at-rules/namespace.js +85 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
- package/dist/lib/validation/at-rules/page.js +88 -0
- package/dist/lib/validation/at-rules/supports.js +262 -0
- package/dist/lib/validation/at-rules/when.js +178 -0
- package/dist/lib/validation/atrule.js +187 -0
- package/dist/lib/validation/config.js +35 -2
- package/dist/lib/validation/config.json.js +1683 -50905
- package/dist/lib/validation/declaration.js +102 -0
- package/dist/lib/validation/parser/parse.js +1137 -7
- package/dist/lib/validation/parser/types.js +28 -12
- package/dist/lib/validation/selector.js +26 -444
- package/dist/lib/validation/syntax.js +1475 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
- package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -0
- package/dist/lib/validation/syntaxes/image.js +29 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
- package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
- package/dist/lib/validation/syntaxes/layer-name.js +67 -0
- package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
- package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
- package/dist/lib/validation/syntaxes/selector-list.js +5 -0
- package/dist/lib/validation/syntaxes/selector.js +5 -0
- package/dist/lib/validation/syntaxes/url.js +75 -0
- package/dist/lib/validation/utils/list.js +24 -0
- package/dist/lib/validation/utils/whitespace.js +22 -0
- package/dist/node/index.js +5 -5
- package/dist/web/index.js +5 -1
- package/dist/web/load.js +1 -0
- package/package.json +16 -14
- package/dist/lib/ast/utils/minifyfeature.js +0 -9
- package/dist/lib/iterable/weakset.js +0 -58
- package/dist/lib/parser/utils/syntax.js +0 -450
package/dist/lib/ast/types.js
CHANGED
|
@@ -2,6 +2,7 @@ var ValidationLevel;
|
|
|
2
2
|
(function (ValidationLevel) {
|
|
3
3
|
ValidationLevel[ValidationLevel["Valid"] = 0] = "Valid";
|
|
4
4
|
ValidationLevel[ValidationLevel["Drop"] = 1] = "Drop";
|
|
5
|
+
ValidationLevel[ValidationLevel["Lenient"] = 2] = "Lenient"; /* preserve unknown at-rules, declarations and pseudo-classes */
|
|
5
6
|
})(ValidationLevel || (ValidationLevel = {}));
|
|
6
7
|
var EnumToken;
|
|
7
8
|
(function (EnumToken) {
|
|
@@ -44,61 +45,70 @@ var EnumToken;
|
|
|
44
45
|
EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
|
|
45
46
|
EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
|
|
46
47
|
EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
|
|
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["
|
|
48
|
+
EnumToken[EnumToken["EqualMatchTokenType"] = 39] = "EqualMatchTokenType";
|
|
49
|
+
EnumToken[EnumToken["LtTokenType"] = 40] = "LtTokenType";
|
|
50
|
+
EnumToken[EnumToken["LteTokenType"] = 41] = "LteTokenType";
|
|
51
|
+
EnumToken[EnumToken["GtTokenType"] = 42] = "GtTokenType";
|
|
52
|
+
EnumToken[EnumToken["GteTokenType"] = 43] = "GteTokenType";
|
|
53
|
+
EnumToken[EnumToken["PseudoClassTokenType"] = 44] = "PseudoClassTokenType";
|
|
54
|
+
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 45] = "PseudoClassFuncTokenType";
|
|
55
|
+
EnumToken[EnumToken["DelimTokenType"] = 46] = "DelimTokenType";
|
|
56
|
+
EnumToken[EnumToken["UrlTokenTokenType"] = 47] = "UrlTokenTokenType";
|
|
57
|
+
EnumToken[EnumToken["EOFTokenType"] = 48] = "EOFTokenType";
|
|
58
|
+
EnumToken[EnumToken["ImportantTokenType"] = 49] = "ImportantTokenType";
|
|
59
|
+
EnumToken[EnumToken["ColorTokenType"] = 50] = "ColorTokenType";
|
|
60
|
+
EnumToken[EnumToken["AttrTokenType"] = 51] = "AttrTokenType";
|
|
61
|
+
EnumToken[EnumToken["BadCommentTokenType"] = 52] = "BadCommentTokenType";
|
|
62
|
+
EnumToken[EnumToken["BadCdoTokenType"] = 53] = "BadCdoTokenType";
|
|
63
|
+
EnumToken[EnumToken["BadUrlTokenType"] = 54] = "BadUrlTokenType";
|
|
64
|
+
EnumToken[EnumToken["BadStringTokenType"] = 55] = "BadStringTokenType";
|
|
65
|
+
EnumToken[EnumToken["BinaryExpressionTokenType"] = 56] = "BinaryExpressionTokenType";
|
|
66
|
+
EnumToken[EnumToken["UnaryExpressionTokenType"] = 57] = "UnaryExpressionTokenType";
|
|
67
|
+
EnumToken[EnumToken["FlexTokenType"] = 58] = "FlexTokenType";
|
|
66
68
|
/* catch all */
|
|
67
|
-
EnumToken[EnumToken["ListToken"] =
|
|
69
|
+
EnumToken[EnumToken["ListToken"] = 59] = "ListToken";
|
|
68
70
|
/* arithmetic tokens */
|
|
69
|
-
EnumToken[EnumToken["Add"] =
|
|
70
|
-
EnumToken[EnumToken["Mul"] =
|
|
71
|
-
EnumToken[EnumToken["Div"] =
|
|
72
|
-
EnumToken[EnumToken["Sub"] =
|
|
71
|
+
EnumToken[EnumToken["Add"] = 60] = "Add";
|
|
72
|
+
EnumToken[EnumToken["Mul"] = 61] = "Mul";
|
|
73
|
+
EnumToken[EnumToken["Div"] = 62] = "Div";
|
|
74
|
+
EnumToken[EnumToken["Sub"] = 63] = "Sub";
|
|
73
75
|
/* new tokens */
|
|
74
|
-
EnumToken[EnumToken["ColumnCombinatorTokenType"] =
|
|
75
|
-
EnumToken[EnumToken["ContainMatchTokenType"] =
|
|
76
|
-
EnumToken[EnumToken["StartMatchTokenType"] =
|
|
77
|
-
EnumToken[EnumToken["EndMatchTokenType"] =
|
|
78
|
-
EnumToken[EnumToken["MatchExpressionTokenType"] =
|
|
79
|
-
EnumToken[EnumToken["NameSpaceAttributeTokenType"] =
|
|
80
|
-
EnumToken[EnumToken["FractionTokenType"] =
|
|
81
|
-
EnumToken[EnumToken["IdenListTokenType"] =
|
|
82
|
-
EnumToken[EnumToken["GridTemplateFuncTokenType"] =
|
|
83
|
-
EnumToken[EnumToken["KeyFrameRuleNodeType"] =
|
|
84
|
-
EnumToken[EnumToken["ClassSelectorTokenType"] =
|
|
85
|
-
EnumToken[EnumToken["UniversalSelectorTokenType"] =
|
|
86
|
-
EnumToken[EnumToken["ChildCombinatorTokenType"] =
|
|
87
|
-
EnumToken[EnumToken["DescendantCombinatorTokenType"] =
|
|
88
|
-
EnumToken[EnumToken["NextSiblingCombinatorTokenType"] =
|
|
89
|
-
EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] =
|
|
90
|
-
EnumToken[EnumToken["NestingSelectorTokenType"] =
|
|
91
|
-
EnumToken[EnumToken["InvalidRuleTokenType"] =
|
|
92
|
-
EnumToken[EnumToken["InvalidClassSelectorTokenType"] =
|
|
93
|
-
EnumToken[EnumToken["InvalidAttrTokenType"] =
|
|
76
|
+
EnumToken[EnumToken["ColumnCombinatorTokenType"] = 64] = "ColumnCombinatorTokenType";
|
|
77
|
+
EnumToken[EnumToken["ContainMatchTokenType"] = 65] = "ContainMatchTokenType";
|
|
78
|
+
EnumToken[EnumToken["StartMatchTokenType"] = 66] = "StartMatchTokenType";
|
|
79
|
+
EnumToken[EnumToken["EndMatchTokenType"] = 67] = "EndMatchTokenType";
|
|
80
|
+
EnumToken[EnumToken["MatchExpressionTokenType"] = 68] = "MatchExpressionTokenType";
|
|
81
|
+
EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 69] = "NameSpaceAttributeTokenType";
|
|
82
|
+
EnumToken[EnumToken["FractionTokenType"] = 70] = "FractionTokenType";
|
|
83
|
+
EnumToken[EnumToken["IdenListTokenType"] = 71] = "IdenListTokenType";
|
|
84
|
+
EnumToken[EnumToken["GridTemplateFuncTokenType"] = 72] = "GridTemplateFuncTokenType";
|
|
85
|
+
EnumToken[EnumToken["KeyFrameRuleNodeType"] = 73] = "KeyFrameRuleNodeType";
|
|
86
|
+
EnumToken[EnumToken["ClassSelectorTokenType"] = 74] = "ClassSelectorTokenType";
|
|
87
|
+
EnumToken[EnumToken["UniversalSelectorTokenType"] = 75] = "UniversalSelectorTokenType";
|
|
88
|
+
EnumToken[EnumToken["ChildCombinatorTokenType"] = 76] = "ChildCombinatorTokenType";
|
|
89
|
+
EnumToken[EnumToken["DescendantCombinatorTokenType"] = 77] = "DescendantCombinatorTokenType";
|
|
90
|
+
EnumToken[EnumToken["NextSiblingCombinatorTokenType"] = 78] = "NextSiblingCombinatorTokenType";
|
|
91
|
+
EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] = 79] = "SubsequentSiblingCombinatorTokenType";
|
|
92
|
+
EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
|
|
93
|
+
EnumToken[EnumToken["InvalidRuleTokenType"] = 81] = "InvalidRuleTokenType";
|
|
94
|
+
EnumToken[EnumToken["InvalidClassSelectorTokenType"] = 82] = "InvalidClassSelectorTokenType";
|
|
95
|
+
EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
|
|
96
|
+
EnumToken[EnumToken["InvalidAtRuleTokenType"] = 84] = "InvalidAtRuleTokenType";
|
|
97
|
+
EnumToken[EnumToken["MediaQueryConditionTokenType"] = 85] = "MediaQueryConditionTokenType";
|
|
98
|
+
EnumToken[EnumToken["MediaFeatureTokenType"] = 86] = "MediaFeatureTokenType";
|
|
99
|
+
EnumToken[EnumToken["MediaFeatureOnlyTokenType"] = 87] = "MediaFeatureOnlyTokenType";
|
|
100
|
+
EnumToken[EnumToken["MediaFeatureNotTokenType"] = 88] = "MediaFeatureNotTokenType";
|
|
101
|
+
EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
|
|
102
|
+
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
103
|
+
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
94
104
|
/* aliases */
|
|
95
105
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
96
106
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
97
|
-
EnumToken[EnumToken["EOF"] =
|
|
107
|
+
EnumToken[EnumToken["EOF"] = 48] = "EOF";
|
|
98
108
|
EnumToken[EnumToken["Hash"] = 28] = "Hash";
|
|
99
|
-
EnumToken[EnumToken["Flex"] =
|
|
109
|
+
EnumToken[EnumToken["Flex"] = 58] = "Flex";
|
|
100
110
|
EnumToken[EnumToken["Angle"] = 24] = "Angle";
|
|
101
|
-
EnumToken[EnumToken["Color"] =
|
|
111
|
+
EnumToken[EnumToken["Color"] = 50] = "Color";
|
|
102
112
|
EnumToken[EnumToken["Comma"] = 9] = "Comma";
|
|
103
113
|
EnumToken[EnumToken["String"] = 20] = "String";
|
|
104
114
|
EnumToken[EnumToken["Length"] = 23] = "Length";
|
|
@@ -111,9 +121,9 @@ var EnumToken;
|
|
|
111
121
|
EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
|
|
112
122
|
EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
|
|
113
123
|
EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
|
|
114
|
-
EnumToken[EnumToken["IdenList"] =
|
|
124
|
+
EnumToken[EnumToken["IdenList"] = 71] = "IdenList";
|
|
115
125
|
EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
|
|
116
|
-
EnumToken[EnumToken["GridTemplateFunc"] =
|
|
126
|
+
EnumToken[EnumToken["GridTemplateFunc"] = 72] = "GridTemplateFunc";
|
|
117
127
|
EnumToken[EnumToken["ImageFunc"] = 19] = "ImageFunc";
|
|
118
128
|
EnumToken[EnumToken["CommentNodeType"] = 0] = "CommentNodeType";
|
|
119
129
|
EnumToken[EnumToken["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { EnumToken } from './types.js';
|
|
2
2
|
|
|
3
|
+
var WalkerValueEvent;
|
|
4
|
+
(function (WalkerValueEvent) {
|
|
5
|
+
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
6
|
+
WalkerValueEvent[WalkerValueEvent["Leave"] = 1] = "Leave";
|
|
7
|
+
})(WalkerValueEvent || (WalkerValueEvent = {}));
|
|
8
|
+
/**
|
|
9
|
+
* walk ast nodes
|
|
10
|
+
* @param node
|
|
11
|
+
* @param filter
|
|
12
|
+
*/
|
|
3
13
|
function* walk(node, filter) {
|
|
4
14
|
const parents = [node];
|
|
5
15
|
const root = node;
|
|
@@ -28,40 +38,104 @@ function* walk(node, filter) {
|
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
|
-
|
|
41
|
+
/**
|
|
42
|
+
* walk ast values
|
|
43
|
+
* @param values
|
|
44
|
+
* @param root
|
|
45
|
+
* @param filter
|
|
46
|
+
* @param reverse
|
|
47
|
+
*/
|
|
48
|
+
function* walkValues(values, root = null, filter, reverse) {
|
|
49
|
+
// const set = new Set<Token>();
|
|
32
50
|
const stack = values.slice();
|
|
33
51
|
const map = new Map;
|
|
34
|
-
let value;
|
|
35
52
|
let previous = null;
|
|
36
|
-
|
|
53
|
+
// let parent: FunctionToken | ParensToken | BinaryExpressionToken | null = null;
|
|
54
|
+
if (filter != null && typeof filter == 'function') {
|
|
55
|
+
filter = {
|
|
56
|
+
event: WalkerValueEvent.Enter,
|
|
57
|
+
fn: filter
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else if (filter == null) {
|
|
61
|
+
filter = {
|
|
62
|
+
event: WalkerValueEvent.Enter
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
while (stack.length > 0) {
|
|
66
|
+
let value = reverse ? stack.pop() : stack.shift();
|
|
37
67
|
let option = null;
|
|
38
|
-
if (filter != null) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
if (filter.fn != null && filter.event == WalkerValueEvent.Enter) {
|
|
69
|
+
const isValid = filter.type == null || value.typ == filter.type ||
|
|
70
|
+
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
71
|
+
(typeof filter.type == 'function' && filter.type(value));
|
|
72
|
+
if (isValid) {
|
|
73
|
+
option = filter.fn(value, map.get(value) ?? root, WalkerValueEvent.Enter);
|
|
74
|
+
if (option === 'ignore') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (option === 'stop') {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
if (option != null && typeof option == 'object' && 'typ' in option) {
|
|
82
|
+
map.set(option, map.get(value) ?? root);
|
|
83
|
+
}
|
|
45
84
|
}
|
|
46
85
|
}
|
|
47
86
|
// @ts-ignore
|
|
48
|
-
if (option !== 'children') {
|
|
49
|
-
|
|
50
|
-
|
|
87
|
+
if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
|
|
88
|
+
yield {
|
|
89
|
+
value,
|
|
90
|
+
parent: map.get(value) ?? root,
|
|
91
|
+
previousValue: previous,
|
|
92
|
+
nextValue: stack[0] ?? null,
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
root: root ?? null
|
|
95
|
+
};
|
|
51
96
|
}
|
|
52
97
|
if (option !== 'ignore-children' && 'chi' in value) {
|
|
53
|
-
|
|
98
|
+
const sliced = value.chi.slice();
|
|
99
|
+
for (const child of sliced) {
|
|
54
100
|
map.set(child, value);
|
|
55
101
|
}
|
|
56
|
-
|
|
102
|
+
if (reverse) {
|
|
103
|
+
stack.push(...sliced);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
stack.unshift(...sliced);
|
|
107
|
+
}
|
|
57
108
|
}
|
|
58
109
|
else if (value.typ == EnumToken.BinaryExpressionTokenType) {
|
|
59
|
-
map.set(value.l, value);
|
|
60
|
-
map.set(value.r, value);
|
|
110
|
+
map.set(value.l, map.get(value) ?? root);
|
|
111
|
+
map.set(value.r, map.get(value) ?? root);
|
|
61
112
|
stack.unshift(value.l, value.r);
|
|
62
113
|
}
|
|
114
|
+
if (filter.event == WalkerValueEvent.Leave && filter.fn != null) {
|
|
115
|
+
const isValid = filter.type == null || value.typ == filter.type ||
|
|
116
|
+
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
117
|
+
(typeof filter.type == 'function' && filter.type(value));
|
|
118
|
+
if (isValid) {
|
|
119
|
+
option = filter.fn(value, map.get(value), WalkerValueEvent.Leave);
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
if (option != null && 'typ' in option) {
|
|
122
|
+
map.set(option, map.get(value) ?? root);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
|
|
128
|
+
yield {
|
|
129
|
+
value,
|
|
130
|
+
parent: map.get(value) ?? root,
|
|
131
|
+
previousValue: previous,
|
|
132
|
+
nextValue: stack[0] ?? null,
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
root: root ?? null
|
|
135
|
+
};
|
|
136
|
+
}
|
|
63
137
|
previous = value;
|
|
64
138
|
}
|
|
65
139
|
}
|
|
66
140
|
|
|
67
|
-
export { walk, walkValues };
|
|
141
|
+
export { WalkerValueEvent, walk, walkValues };
|
|
@@ -2,6 +2,7 @@ import { PropertySet } from './set.js';
|
|
|
2
2
|
import { getConfig } from '../utils/config.js';
|
|
3
3
|
import { EnumToken } from '../../ast/types.js';
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
|
+
import '../../ast/walk.js';
|
|
5
6
|
import { parseString } from '../parse.js';
|
|
6
7
|
import '../../renderer/color/utils/constants.js';
|
|
7
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
@@ -3,6 +3,7 @@ import { getConfig } from '../utils/config.js';
|
|
|
3
3
|
import { matchType } from '../utils/type.js';
|
|
4
4
|
import { EnumToken } from '../../ast/types.js';
|
|
5
5
|
import '../../ast/minify.js';
|
|
6
|
+
import '../../ast/walk.js';
|
|
6
7
|
import { parseString } from '../parse.js';
|
|
7
8
|
import { renderToken } from '../../renderer/render.js';
|
|
8
9
|
import '../../renderer/color/utils/constants.js';
|
|
@@ -161,55 +162,6 @@ class PropertyMap {
|
|
|
161
162
|
}
|
|
162
163
|
return this;
|
|
163
164
|
}
|
|
164
|
-
matchTypes(declaration) {
|
|
165
|
-
const patterns = this.pattern.slice();
|
|
166
|
-
const values = [...declaration.val];
|
|
167
|
-
let i;
|
|
168
|
-
let j;
|
|
169
|
-
const map = new Map;
|
|
170
|
-
for (i = 0; i < patterns.length; i++) {
|
|
171
|
-
for (j = 0; j < values.length; j++) {
|
|
172
|
-
if (!map.has(patterns[i])) {
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
map.set(patterns[i], this.config.properties?.[patterns[i]]?.constraints?.mapping?.max ?? 1);
|
|
175
|
-
}
|
|
176
|
-
let count = map.get(patterns[i]);
|
|
177
|
-
if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
|
|
178
|
-
Object.defineProperty(values[j], 'propertyName', {
|
|
179
|
-
enumerable: false,
|
|
180
|
-
writable: true,
|
|
181
|
-
value: patterns[i]
|
|
182
|
-
});
|
|
183
|
-
map.set(patterns[i], --count);
|
|
184
|
-
values.splice(j--, 1);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (this.config.set != null) {
|
|
189
|
-
for (const [key, val] of Object.entries(this.config.set)) {
|
|
190
|
-
if (map.has(key)) {
|
|
191
|
-
for (const v of val) {
|
|
192
|
-
// missing
|
|
193
|
-
if (map.get(v) == 1) {
|
|
194
|
-
let i = declaration.val.length;
|
|
195
|
-
while (i--) {
|
|
196
|
-
// @ts-ignore
|
|
197
|
-
if (declaration.val[i].propertyName == key) {
|
|
198
|
-
const val = { ...declaration.val[i] };
|
|
199
|
-
Object.defineProperty(val, 'propertyName', {
|
|
200
|
-
enumerable: false,
|
|
201
|
-
writable: true,
|
|
202
|
-
value: v
|
|
203
|
-
});
|
|
204
|
-
declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
165
|
[Symbol.iterator]() {
|
|
214
166
|
let iterable;
|
|
215
167
|
let requiredCount = 0;
|
|
@@ -248,9 +200,15 @@ class PropertyMap {
|
|
|
248
200
|
// @ts-ignore
|
|
249
201
|
let typ = (EnumToken[this.config.separator?.typ] ?? EnumToken.CommaTokenType);
|
|
250
202
|
// @ts-ignore
|
|
251
|
-
const sep = this.config.separator == null ? null : {
|
|
203
|
+
const sep = this.config.separator == null ? null : {
|
|
204
|
+
...this.config.separator,
|
|
205
|
+
typ: EnumToken[this.config.separator.typ]
|
|
206
|
+
};
|
|
252
207
|
// @ts-ignore
|
|
253
|
-
const separator = this.config.separator ? renderToken({
|
|
208
|
+
const separator = this.config.separator ? renderToken({
|
|
209
|
+
...this.config.separator,
|
|
210
|
+
typ: EnumToken[this.config.separator.typ]
|
|
211
|
+
}) : ',';
|
|
254
212
|
this.matchTypes(declaration);
|
|
255
213
|
values.push(value);
|
|
256
214
|
for (i = 0; i < declaration.val.length; i++) {
|
|
@@ -445,7 +403,6 @@ class PropertyMap {
|
|
|
445
403
|
acc.push(curr);
|
|
446
404
|
return acc;
|
|
447
405
|
}, []);
|
|
448
|
-
// @todo remove renderToken call
|
|
449
406
|
if (props.default.includes(curr[1][i].reduce((acc, curr) => acc + renderToken(curr) + ' ', '').trimEnd())) {
|
|
450
407
|
if (!this.config.properties[curr[0]].required) {
|
|
451
408
|
continue;
|
|
@@ -543,6 +500,7 @@ class PropertyMap {
|
|
|
543
500
|
}
|
|
544
501
|
// @ts-ignore
|
|
545
502
|
if (values.length == 1 &&
|
|
503
|
+
// @ts-ignore
|
|
546
504
|
typeof values[0].val == 'string' &&
|
|
547
505
|
this.config.default.includes(values[0].val.toLowerCase()) &&
|
|
548
506
|
this.config.default[0] != values[0].val.toLowerCase()) {
|
|
@@ -561,6 +519,7 @@ class PropertyMap {
|
|
|
561
519
|
// @ts-ignore
|
|
562
520
|
next() {
|
|
563
521
|
let v = iterable.next();
|
|
522
|
+
// @ts-ignore
|
|
564
523
|
while (v.done || v.value instanceof PropertySet) {
|
|
565
524
|
if (v.value instanceof PropertySet) {
|
|
566
525
|
// @ts-ignore
|
|
@@ -583,6 +542,55 @@ class PropertyMap {
|
|
|
583
542
|
}
|
|
584
543
|
};
|
|
585
544
|
}
|
|
545
|
+
matchTypes(declaration) {
|
|
546
|
+
const patterns = this.pattern.slice();
|
|
547
|
+
const values = [...declaration.val];
|
|
548
|
+
let i;
|
|
549
|
+
let j;
|
|
550
|
+
const map = new Map;
|
|
551
|
+
for (i = 0; i < patterns.length; i++) {
|
|
552
|
+
for (j = 0; j < values.length; j++) {
|
|
553
|
+
if (!map.has(patterns[i])) {
|
|
554
|
+
// @ts-ignore
|
|
555
|
+
map.set(patterns[i], this.config.properties?.[patterns[i]]?.constraints?.mapping?.max ?? 1);
|
|
556
|
+
}
|
|
557
|
+
let count = map.get(patterns[i]);
|
|
558
|
+
if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
|
|
559
|
+
Object.defineProperty(values[j], 'propertyName', {
|
|
560
|
+
enumerable: false,
|
|
561
|
+
writable: true,
|
|
562
|
+
value: patterns[i]
|
|
563
|
+
});
|
|
564
|
+
map.set(patterns[i], --count);
|
|
565
|
+
values.splice(j--, 1);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (this.config.set != null) {
|
|
570
|
+
for (const [key, val] of Object.entries(this.config.set)) {
|
|
571
|
+
if (map.has(key)) {
|
|
572
|
+
for (const v of val) {
|
|
573
|
+
// missing
|
|
574
|
+
if (map.get(v) == 1) {
|
|
575
|
+
let i = declaration.val.length;
|
|
576
|
+
while (i--) {
|
|
577
|
+
// @ts-ignore
|
|
578
|
+
if (declaration.val[i].propertyName == key) {
|
|
579
|
+
const val = { ...declaration.val[i] };
|
|
580
|
+
Object.defineProperty(val, 'propertyName', {
|
|
581
|
+
enumerable: false,
|
|
582
|
+
writable: true,
|
|
583
|
+
value: v
|
|
584
|
+
});
|
|
585
|
+
declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
586
594
|
removeDefaults(map, value) {
|
|
587
595
|
for (const [key, val] of map) {
|
|
588
596
|
const config = this.config.properties[key];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { eq } from '../utils/eq.js';
|
|
2
2
|
import { EnumToken } from '../../ast/types.js';
|
|
3
3
|
import '../../ast/minify.js';
|
|
4
|
+
import '../../ast/walk.js';
|
|
4
5
|
import '../parse.js';
|
|
5
6
|
import { isLength } from '../../syntax/syntax.js';
|
|
6
7
|
import '../utils/config.js';
|
|
@@ -180,20 +181,8 @@ class PropertySet {
|
|
|
180
181
|
return acc;
|
|
181
182
|
}, [])
|
|
182
183
|
}][Symbol.iterator]();
|
|
183
|
-
// return {
|
|
184
|
-
// next() {
|
|
185
|
-
//
|
|
186
|
-
// return iterator.next();
|
|
187
|
-
// }
|
|
188
|
-
// }
|
|
189
184
|
}
|
|
190
185
|
return iterator;
|
|
191
|
-
// return {
|
|
192
|
-
// next() {
|
|
193
|
-
//
|
|
194
|
-
// return iterator.next();
|
|
195
|
-
// }
|
|
196
|
-
// }
|
|
197
186
|
}
|
|
198
187
|
}
|
|
199
188
|
|