@tbela99/css-parser 1.4.2 → 1.4.3
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/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.repl_history +4 -0
- package/CHANGELOG.md +164 -4
- package/README.md +43 -0
- package/badges/coverage.svg +20 -0
- package/deno.lock +2861 -0
- package/dist/config.json.js +33 -1
- package/dist/index-umd-web.js +24382 -18476
- package/dist/index.cjs +24522 -18618
- package/dist/index.d.ts +1396 -929
- package/dist/lib/ast/clone.d.ts +10 -0
- package/dist/lib/ast/clone.js +45 -0
- package/dist/lib/ast/expand.d.ts +14 -0
- package/dist/lib/ast/expand.js +89 -64
- package/dist/lib/ast/features/calc.d.ts +10 -0
- package/dist/lib/ast/features/calc.js +62 -24
- package/dist/lib/ast/features/if.d.ts +10 -0
- package/dist/lib/ast/features/if.js +215 -0
- package/dist/lib/ast/features/index.d.ts +6 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
- package/dist/lib/ast/features/inlinecssvariables.js +32 -27
- package/dist/lib/ast/features/prefix.d.ts +8 -0
- package/dist/lib/ast/features/prefix.js +68 -43
- package/dist/lib/ast/features/shorthand.d.ts +12 -0
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.d.ts +10 -0
- package/dist/lib/ast/features/transform.js +9 -13
- package/dist/lib/ast/features/type.d.ts +15 -0
- package/dist/lib/ast/find.d.ts +165 -0
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.d.ts +18 -0
- package/dist/lib/ast/math/expression.js +140 -98
- package/dist/lib/ast/math/math.d.ts +6 -0
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.d.ts +19 -0
- package/dist/lib/ast/minify.js +541 -217
- package/dist/lib/ast/transform/compute.d.ts +8 -0
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.d.ts +22 -0
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.d.ts +5 -0
- package/dist/lib/ast/transform/minify.js +20 -20
- package/dist/lib/ast/transform/perspective.d.ts +3 -0
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.d.ts +12 -0
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.d.ts +6 -0
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.d.ts +4 -0
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.d.ts +6 -0
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.d.ts +9 -0
- package/dist/lib/ast/types.d.ts +903 -0
- package/dist/lib/ast/types.js +277 -23
- package/dist/lib/ast/walk.d.ts +162 -0
- package/dist/lib/ast/walk.js +116 -60
- package/dist/lib/fs/resolve.d.ts +20 -0
- package/dist/lib/fs/resolve.js +37 -45
- package/dist/lib/parser/declaration/list.d.ts +16 -0
- package/dist/lib/parser/declaration/list.js +26 -24
- package/dist/lib/parser/declaration/map.d.ts +15 -0
- package/dist/lib/parser/declaration/map.js +140 -95
- package/dist/lib/parser/declaration/set.d.ts +9 -0
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/node.d.ts +7 -0
- package/dist/lib/parser/parse.d.ts +107 -0
- package/dist/lib/parser/parse.js +1454 -1445
- package/dist/lib/parser/tokenize.d.ts +57 -0
- package/dist/lib/parser/tokenize.js +557 -404
- package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-page.js +28 -0
- package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-support.js +366 -0
- package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.d.ts +13 -0
- package/dist/lib/parser/utils/at-rule.js +37 -0
- package/dist/lib/parser/utils/cache.d.ts +6 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.d.ts +2 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
- package/dist/lib/parser/utils/declaration.d.ts +18 -0
- package/dist/lib/parser/utils/declaration.js +569 -91
- package/dist/lib/parser/utils/eq.d.ts +1 -0
- package/dist/lib/parser/utils/hash.d.ts +21 -0
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.d.ts +5 -0
- package/dist/lib/parser/utils/selector.js +476 -0
- package/dist/lib/parser/utils/text.d.ts +3 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.d.ts +14 -0
- package/dist/lib/parser/utils/token.js +102 -0
- package/dist/lib/parser/utils/type.d.ts +2 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.d.ts +28 -0
- package/dist/lib/renderer/render.js +421 -262
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/cmyk.d.ts +10 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.d.ts +2 -0
- package/dist/lib/syntax/color/color-mix.js +88 -77
- package/dist/lib/syntax/color/color.d.ts +42 -0
- package/dist/lib/syntax/color/color.js +65 -68
- package/dist/lib/syntax/color/hex.d.ts +16 -0
- package/dist/lib/syntax/color/hex.js +27 -31
- package/dist/lib/syntax/color/hsl.d.ts +20 -0
- package/dist/lib/syntax/color/hsl.js +5 -12
- package/dist/lib/syntax/color/hsv.d.ts +2 -0
- package/dist/lib/syntax/color/hwb.d.ts +21 -0
- package/dist/lib/syntax/color/hwb.js +8 -21
- package/dist/lib/syntax/color/lab.d.ts +25 -0
- package/dist/lib/syntax/color/lab.js +20 -21
- package/dist/lib/syntax/color/lch.d.ts +23 -0
- package/dist/lib/syntax/color/lch.js +13 -15
- package/dist/lib/syntax/color/oklab.d.ts +22 -0
- package/dist/lib/syntax/color/oklab.js +20 -39
- package/dist/lib/syntax/color/oklch.d.ts +20 -0
- package/dist/lib/syntax/color/oklch.js +14 -16
- package/dist/lib/syntax/color/p3.d.ts +6 -0
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
- package/dist/lib/syntax/color/relativecolor.js +68 -41
- package/dist/lib/syntax/color/rgb.d.ts +20 -0
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.d.ts +23 -0
- package/dist/lib/syntax/color/srgb.js +27 -26
- package/dist/lib/syntax/color/utils/components.d.ts +2 -0
- package/dist/lib/syntax/color/utils/components.js +30 -14
- package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
- package/dist/lib/syntax/color/utils/distance.js +1 -8
- package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
- package/dist/lib/syntax/color/xyz.d.ts +5 -0
- package/dist/lib/syntax/color/xyz.js +8 -20
- package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.d.ts +67 -0
- package/dist/lib/syntax/constants.js +436 -0
- package/dist/lib/syntax/syntax.d.ts +38 -0
- package/dist/lib/syntax/syntax.js +533 -568
- package/dist/lib/validation/config.d.ts +14 -0
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1159 -74
- package/dist/lib/validation/json.d.ts +2 -0
- package/dist/lib/validation/match.d.ts +38 -0
- package/dist/lib/validation/match.js +2985 -0
- package/dist/lib/validation/parser/parse.d.ts +8 -0
- package/dist/lib/validation/parser/parse.js +684 -935
- package/dist/lib/validation/parser/typedef.d.ts +95 -0
- package/dist/lib/validation/parser/typedef.js +100 -0
- package/dist/lib/validation/utils/list.d.ts +4 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.d.ts +2 -0
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.d.ts +207 -0
- package/dist/node.js +42 -39
- package/dist/web.d.ts +169 -0
- package/dist/web.js +38 -33
- package/package.json +15 -12
- package/playground/index.html +1328 -0
- package/playground/sw.js +55 -0
- package/playground/tree.js +176 -0
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -2,13 +2,8 @@ import { eq } from '../utils/eq.js';
|
|
|
2
2
|
import { getConfig } from '../utils/config.js';
|
|
3
3
|
import { matchType } from '../utils/type.js';
|
|
4
4
|
import { EnumToken } from '../../ast/types.js';
|
|
5
|
-
import '../../ast/minify.js';
|
|
6
|
-
import '../../ast/walk.js';
|
|
7
|
-
import { parseString } from '../parse.js';
|
|
8
|
-
import '../tokenize.js';
|
|
9
5
|
import { renderToken } from '../../renderer/render.js';
|
|
10
|
-
import '
|
|
11
|
-
import '../../syntax/color/utils/constants.js';
|
|
6
|
+
import { parseString } from '../parse.js';
|
|
12
7
|
import { PropertySet } from './set.js';
|
|
13
8
|
|
|
14
9
|
const propertiesConfig = getConfig();
|
|
@@ -19,29 +14,37 @@ class PropertyMap {
|
|
|
19
14
|
pattern;
|
|
20
15
|
constructor(config) {
|
|
21
16
|
const values = Object.values(config.properties);
|
|
22
|
-
this.requiredCount =
|
|
17
|
+
this.requiredCount =
|
|
18
|
+
values.reduce((acc, curr) => (curr.required ? ++acc : acc), 0) ||
|
|
19
|
+
values.length;
|
|
23
20
|
this.config = config;
|
|
24
|
-
this.declarations = new Map;
|
|
21
|
+
this.declarations = new Map();
|
|
25
22
|
this.pattern = config.pattern.split(/\s/);
|
|
26
23
|
}
|
|
27
24
|
add(declaration) {
|
|
28
25
|
if (declaration.nam == this.config.shorthand) {
|
|
29
|
-
this.declarations = new Map;
|
|
26
|
+
this.declarations = new Map();
|
|
30
27
|
this.declarations.set(declaration.nam, declaration);
|
|
31
28
|
this.matchTypes(declaration);
|
|
32
29
|
}
|
|
33
30
|
else {
|
|
34
|
-
const separator = this.config.separator != null
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const separator = this.config.separator != null
|
|
32
|
+
? {
|
|
33
|
+
...this.config.separator,
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
typ: EnumToken[this.config.separator.typ],
|
|
36
|
+
}
|
|
37
|
+
: null;
|
|
39
38
|
// expand shorthand
|
|
40
|
-
if (
|
|
39
|
+
if (this.declarations.has(this.config.shorthand)) {
|
|
41
40
|
const tokens = {};
|
|
42
41
|
const values = [];
|
|
43
42
|
// @ts-ignore
|
|
44
|
-
this.declarations
|
|
43
|
+
this.declarations
|
|
44
|
+
.get(this.config.shorthand)
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
.val.slice()
|
|
47
|
+
.reduce((acc, curr) => {
|
|
45
48
|
// @ts-ignore
|
|
46
49
|
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
47
50
|
acc.push([]);
|
|
@@ -50,21 +53,26 @@ class PropertyMap {
|
|
|
50
53
|
// @ts-ignore
|
|
51
54
|
acc.at(-1).push(curr);
|
|
52
55
|
return acc;
|
|
53
|
-
}, [[]])
|
|
56
|
+
}, [[]])
|
|
54
57
|
// @ts-ignore
|
|
55
|
-
reduce((acc, list, current) => {
|
|
58
|
+
.reduce((acc, list, current) => {
|
|
56
59
|
values.push(...this.pattern.reduce((acc, property) => {
|
|
57
60
|
// let current: number = 0;
|
|
58
61
|
const props = this.config.properties[property];
|
|
59
62
|
for (let i = 0; i < acc.length; i++) {
|
|
60
|
-
if (acc[i].typ == EnumToken.CommentTokenType ||
|
|
63
|
+
if (acc[i].typ == EnumToken.CommentTokenType ||
|
|
64
|
+
acc[i].typ == EnumToken.WhitespaceTokenType) {
|
|
61
65
|
acc.splice(i, 1);
|
|
62
66
|
i--;
|
|
63
67
|
continue;
|
|
64
68
|
}
|
|
69
|
+
if (
|
|
65
70
|
// @ts-ignore
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
("propertyName" in acc[i] && acc[i].propertyName == property) ||
|
|
72
|
+
matchType(acc[i], props)) {
|
|
73
|
+
if ("prefix" in props &&
|
|
74
|
+
props.previous != null &&
|
|
75
|
+
!(props.previous in tokens)) {
|
|
68
76
|
return acc;
|
|
69
77
|
}
|
|
70
78
|
if (!(property in tokens)) {
|
|
@@ -81,9 +89,12 @@ class PropertyMap {
|
|
|
81
89
|
acc.splice(i, 1);
|
|
82
90
|
i--;
|
|
83
91
|
// @ts-ignore
|
|
84
|
-
if (
|
|
92
|
+
if ("prefix" in props && acc[i]?.typ == EnumToken[props.prefix.typ]) {
|
|
93
|
+
if (
|
|
85
94
|
// @ts-ignore
|
|
86
|
-
|
|
95
|
+
acc[i].typ == EnumToken[props.prefix.typ] &&
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
acc[i].val == this.config.properties[property].prefix.val) {
|
|
87
98
|
acc.splice(i, 1);
|
|
88
99
|
i--;
|
|
89
100
|
}
|
|
@@ -106,9 +117,7 @@ class PropertyMap {
|
|
|
106
117
|
if (props.default.length > 0) {
|
|
107
118
|
const defaults = parseString(props.default[0]);
|
|
108
119
|
if (!(property in tokens)) {
|
|
109
|
-
tokens[property] = [
|
|
110
|
-
[...defaults]
|
|
111
|
-
];
|
|
120
|
+
tokens[property] = [[...defaults]];
|
|
112
121
|
}
|
|
113
122
|
else {
|
|
114
123
|
if (current == tokens[property].length) {
|
|
@@ -135,10 +144,10 @@ class PropertyMap {
|
|
|
135
144
|
}
|
|
136
145
|
acc.push(...curr);
|
|
137
146
|
return acc;
|
|
138
|
-
}, [])
|
|
147
|
+
}, []),
|
|
139
148
|
});
|
|
140
149
|
return acc;
|
|
141
|
-
}, new Map);
|
|
150
|
+
}, new Map());
|
|
142
151
|
}
|
|
143
152
|
}
|
|
144
153
|
// @ts-ignore
|
|
@@ -176,7 +185,7 @@ class PropertyMap {
|
|
|
176
185
|
break;
|
|
177
186
|
}
|
|
178
187
|
else {
|
|
179
|
-
const val = this.declarations.get(property);
|
|
188
|
+
const val = (this.declarations.get(property));
|
|
180
189
|
if (val instanceof PropertySet && !val.isShortHand()) {
|
|
181
190
|
isShorthand = false;
|
|
182
191
|
break;
|
|
@@ -187,7 +196,7 @@ class PropertyMap {
|
|
|
187
196
|
}
|
|
188
197
|
}
|
|
189
198
|
}
|
|
190
|
-
if (requiredCount
|
|
199
|
+
if (requiredCount === 0) {
|
|
191
200
|
requiredCount = this.declarations.size;
|
|
192
201
|
}
|
|
193
202
|
if (!isShorthand || requiredCount < this.requiredCount) {
|
|
@@ -202,15 +211,19 @@ class PropertyMap {
|
|
|
202
211
|
// @ts-ignore
|
|
203
212
|
let typ = (EnumToken[this.config.separator?.typ] ?? EnumToken.CommaTokenType);
|
|
204
213
|
// @ts-ignore
|
|
205
|
-
const sep = this.config.separator == null
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
214
|
+
const sep = this.config.separator == null
|
|
215
|
+
? null
|
|
216
|
+
: {
|
|
217
|
+
...this.config.separator,
|
|
218
|
+
typ: EnumToken[this.config.separator.typ],
|
|
219
|
+
};
|
|
209
220
|
// @ts-ignore
|
|
210
|
-
const separator = this.config.separator
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
221
|
+
const separator = this.config.separator
|
|
222
|
+
? renderToken({
|
|
223
|
+
...this.config.separator,
|
|
224
|
+
typ: EnumToken[this.config.separator.typ],
|
|
225
|
+
})
|
|
226
|
+
: ",";
|
|
214
227
|
this.matchTypes(declaration);
|
|
215
228
|
values.push(value);
|
|
216
229
|
for (i = 0; i < declaration.val.length; i++) {
|
|
@@ -227,7 +240,7 @@ class PropertyMap {
|
|
|
227
240
|
}
|
|
228
241
|
value.push(t);
|
|
229
242
|
// @ts-ignore
|
|
230
|
-
if (
|
|
243
|
+
if ("propertyName" in t) {
|
|
231
244
|
// @ts-ignore
|
|
232
245
|
if (!map.has(t.propertyName)) {
|
|
233
246
|
// @ts-ignore
|
|
@@ -282,11 +295,11 @@ class PropertyMap {
|
|
|
282
295
|
filtered.push({
|
|
283
296
|
typ: EnumToken.DeclarationNodeType,
|
|
284
297
|
nam: this.config.shorthand,
|
|
285
|
-
val: parseString(this.config.default[0])
|
|
298
|
+
val: parseString(this.config.default[0]),
|
|
286
299
|
});
|
|
287
300
|
if (isImportant) {
|
|
288
301
|
filtered[0].val.push({
|
|
289
|
-
typ: EnumToken.ImportantTokenType
|
|
302
|
+
typ: EnumToken.ImportantTokenType,
|
|
290
303
|
});
|
|
291
304
|
}
|
|
292
305
|
}
|
|
@@ -296,8 +309,10 @@ class PropertyMap {
|
|
|
296
309
|
if (declaration instanceof PropertySet) {
|
|
297
310
|
continue;
|
|
298
311
|
}
|
|
299
|
-
const config = declaration.nam == this.config.shorthand
|
|
300
|
-
|
|
312
|
+
const config = declaration.nam == this.config.shorthand
|
|
313
|
+
? this.config
|
|
314
|
+
: (this.config.properties[declaration.nam] ?? this.config);
|
|
315
|
+
if (!("mapping" in config)) {
|
|
301
316
|
continue;
|
|
302
317
|
}
|
|
303
318
|
// @ts-ignore
|
|
@@ -318,11 +333,13 @@ class PropertyMap {
|
|
|
318
333
|
else {
|
|
319
334
|
let count = 0;
|
|
320
335
|
let match;
|
|
321
|
-
const separator = this.config.separator != null
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
336
|
+
const separator = this.config.separator != null
|
|
337
|
+
? {
|
|
338
|
+
...this.config.separator,
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
typ: EnumToken[this.config.separator.typ],
|
|
341
|
+
}
|
|
342
|
+
: null;
|
|
326
343
|
const tokens = {};
|
|
327
344
|
// @ts-ignore
|
|
328
345
|
Object.entries(this.config.properties).reduce((acc, curr) => {
|
|
@@ -334,8 +351,10 @@ class PropertyMap {
|
|
|
334
351
|
}
|
|
335
352
|
let current = 0;
|
|
336
353
|
const props = this.config.properties[curr[0]];
|
|
337
|
-
const properties = this.declarations.get(curr[0]);
|
|
338
|
-
for (const declaration of [
|
|
354
|
+
const properties = (this.declarations.get(curr[0]));
|
|
355
|
+
for (const declaration of [
|
|
356
|
+
properties instanceof PropertySet ? [...properties][0] : properties,
|
|
357
|
+
]) {
|
|
339
358
|
// @ts-ignore
|
|
340
359
|
for (const val of declaration.val) {
|
|
341
360
|
// @ts-ignore
|
|
@@ -350,11 +369,12 @@ class PropertyMap {
|
|
|
350
369
|
continue;
|
|
351
370
|
}
|
|
352
371
|
// @ts-ignore
|
|
353
|
-
if (props.multiple &&
|
|
372
|
+
if (props.multiple &&
|
|
373
|
+
props.separator != null &&
|
|
354
374
|
// @ts-ignore
|
|
355
|
-
EnumToken[props.separator.typ]
|
|
375
|
+
EnumToken[props.separator.typ] === val.typ &&
|
|
356
376
|
// @ts-ignore
|
|
357
|
-
props.separator.val == val.val) {
|
|
377
|
+
(val.typ === EnumToken.CommaTokenType || props.separator.val == val.val)) {
|
|
358
378
|
continue;
|
|
359
379
|
}
|
|
360
380
|
// @ts-ignore
|
|
@@ -363,7 +383,7 @@ class PropertyMap {
|
|
|
363
383
|
isShorthand = match;
|
|
364
384
|
}
|
|
365
385
|
// @ts-ignore
|
|
366
|
-
if ((
|
|
386
|
+
if (("propertyName" in val && val.propertyName == property) || match) {
|
|
367
387
|
if (!(curr[0] in tokens)) {
|
|
368
388
|
tokens[curr[0]] = [[]];
|
|
369
389
|
}
|
|
@@ -376,23 +396,27 @@ class PropertyMap {
|
|
|
376
396
|
}
|
|
377
397
|
}
|
|
378
398
|
}
|
|
379
|
-
if (count
|
|
399
|
+
if (count === 0) {
|
|
380
400
|
count = current;
|
|
381
401
|
}
|
|
382
402
|
return acc;
|
|
383
403
|
}, []);
|
|
384
404
|
count++;
|
|
385
|
-
if (!isShorthand ||
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
405
|
+
if (!isShorthand ||
|
|
406
|
+
Object.entries(this.config.properties).some((entry) => {
|
|
407
|
+
// missing required property
|
|
408
|
+
return entry[1].required && !(entry[0] in tokens);
|
|
409
|
+
}) ||
|
|
389
410
|
// @ts-ignore
|
|
390
|
-
!Object.values(tokens).every((v) =>
|
|
411
|
+
!Object.values(tokens).every((v) =>
|
|
412
|
+
// @ts-expect-error
|
|
413
|
+
v.filter((t) => t.typ != EnumToken.CommentTokenType).length === count)) {
|
|
391
414
|
// @ts-ignore
|
|
392
415
|
iterable = this.declarations.values();
|
|
393
416
|
}
|
|
394
417
|
else {
|
|
395
|
-
let values = Object.entries(tokens)
|
|
418
|
+
let values = Object.entries(tokens)
|
|
419
|
+
.reduce((acc, curr) => {
|
|
396
420
|
const props = this.config.properties[curr[0]];
|
|
397
421
|
for (let i = 0; i < curr[1].length; i++) {
|
|
398
422
|
if (acc.length == i) {
|
|
@@ -405,7 +429,9 @@ class PropertyMap {
|
|
|
405
429
|
acc.push(curr);
|
|
406
430
|
return acc;
|
|
407
431
|
}, []);
|
|
408
|
-
if (props.default.includes(curr[1][i]
|
|
432
|
+
if (props.default.includes(curr[1][i]
|
|
433
|
+
.reduce((acc, curr) => acc + renderToken(curr) + " ", "")
|
|
434
|
+
.trimEnd())) {
|
|
409
435
|
if (!this.config.properties[curr[0]].required) {
|
|
410
436
|
continue;
|
|
411
437
|
}
|
|
@@ -414,8 +440,13 @@ class PropertyMap {
|
|
|
414
440
|
let doFilterDefault = true;
|
|
415
441
|
if (curr[0] in propertiesConfig.properties) {
|
|
416
442
|
for (let v of values) {
|
|
417
|
-
if (![
|
|
418
|
-
|
|
443
|
+
if (![
|
|
444
|
+
EnumToken.WhitespaceTokenType,
|
|
445
|
+
EnumToken.CommentTokenType,
|
|
446
|
+
EnumToken.IdenTokenType,
|
|
447
|
+
].includes(v.typ) ||
|
|
448
|
+
(v.typ == EnumToken.IdenTokenType &&
|
|
449
|
+
!this.config.properties[curr[0]].default.includes(v.val))) {
|
|
419
450
|
doFilterDefault = false;
|
|
420
451
|
break;
|
|
421
452
|
}
|
|
@@ -423,29 +454,36 @@ class PropertyMap {
|
|
|
423
454
|
}
|
|
424
455
|
// remove default values
|
|
425
456
|
const filtered = values.filter((val) => {
|
|
426
|
-
if (val.typ == EnumToken.WhitespaceTokenType ||
|
|
457
|
+
if (val.typ == EnumToken.WhitespaceTokenType ||
|
|
458
|
+
val.typ == EnumToken.CommentTokenType) {
|
|
427
459
|
return false;
|
|
428
460
|
}
|
|
429
|
-
return !doFilterDefault ||
|
|
461
|
+
return (!doFilterDefault ||
|
|
462
|
+
!(val.typ == EnumToken.IdenTokenType &&
|
|
463
|
+
props.default.includes(val.val)));
|
|
430
464
|
});
|
|
431
|
-
if (filtered.length > 0 ||
|
|
465
|
+
if (filtered.length > 0 ||
|
|
466
|
+
!(this.requiredCount == requiredCount && this.config.properties[curr[0]].required)) {
|
|
432
467
|
values = filtered;
|
|
433
468
|
}
|
|
434
469
|
if (values.length > 0) {
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
470
|
+
if ("mapping" in props) {
|
|
471
|
+
if (!("constraints" in props) ||
|
|
472
|
+
// @ts-ignore
|
|
473
|
+
!("max" in props.constraints) ||
|
|
474
|
+
values.length <= props.constraints.mapping.max) {
|
|
438
475
|
let i = values.length;
|
|
439
476
|
while (i--) {
|
|
440
|
-
|
|
441
|
-
|
|
477
|
+
if (values[i].typ == EnumToken.IdenTokenType &&
|
|
478
|
+
// @ts-expect-error
|
|
479
|
+
values[i].val in props.mapping) {
|
|
442
480
|
// @ts-ignore
|
|
443
481
|
values.splice(i, 1, ...parseString(props.mapping[values[i].val]));
|
|
444
482
|
}
|
|
445
483
|
}
|
|
446
484
|
}
|
|
447
485
|
}
|
|
448
|
-
if (
|
|
486
|
+
if ("prefix" in props) {
|
|
449
487
|
// @ts-ignore
|
|
450
488
|
acc[i].push({ ...props.prefix, typ: EnumToken[props.prefix.typ] });
|
|
451
489
|
}
|
|
@@ -459,8 +497,8 @@ class PropertyMap {
|
|
|
459
497
|
...((props.separator && {
|
|
460
498
|
...props.separator,
|
|
461
499
|
// @ts-ignore
|
|
462
|
-
typ: EnumToken[props.separator.typ]
|
|
463
|
-
}) ?? { typ: EnumToken.WhitespaceTokenType })
|
|
500
|
+
typ: EnumToken[props.separator.typ],
|
|
501
|
+
}) ?? { typ: EnumToken.WhitespaceTokenType }),
|
|
464
502
|
});
|
|
465
503
|
}
|
|
466
504
|
// @ts-ignore
|
|
@@ -470,7 +508,8 @@ class PropertyMap {
|
|
|
470
508
|
}
|
|
471
509
|
}
|
|
472
510
|
return acc;
|
|
473
|
-
}, [])
|
|
511
|
+
}, [])
|
|
512
|
+
.reduce((acc, curr) => {
|
|
474
513
|
if (acc.length > 0) {
|
|
475
514
|
acc.push({ ...separator });
|
|
476
515
|
}
|
|
@@ -487,33 +526,38 @@ class PropertyMap {
|
|
|
487
526
|
return acc;
|
|
488
527
|
}, []);
|
|
489
528
|
if (this.config.mapping != null) {
|
|
490
|
-
const val = values.reduce((acc, curr) => acc +
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
529
|
+
const val = values.reduce((acc, curr) => acc +
|
|
530
|
+
renderToken(curr, {
|
|
531
|
+
removeComments: true,
|
|
532
|
+
minify: true,
|
|
533
|
+
}), "");
|
|
494
534
|
if (val in this.config.mapping) {
|
|
495
535
|
values.length = 0;
|
|
496
536
|
values.push({
|
|
497
|
-
typ: ['"', "'"].includes(val.charAt(0))
|
|
537
|
+
typ: ['"', "'"].includes(val.charAt(0))
|
|
538
|
+
? EnumToken.StringTokenType
|
|
539
|
+
: EnumToken.IdenTokenType,
|
|
498
540
|
// @ts-ignore
|
|
499
|
-
val: this.config.mapping[val]
|
|
541
|
+
val: this.config.mapping[val],
|
|
500
542
|
});
|
|
501
543
|
}
|
|
502
544
|
}
|
|
503
545
|
// @ts-ignore
|
|
504
546
|
if (values.length == 1 &&
|
|
505
547
|
// @ts-ignore
|
|
506
|
-
typeof values[0].val ==
|
|
548
|
+
typeof values[0].val == "string" &&
|
|
507
549
|
this.config.default.includes(values[0].val.toLowerCase()) &&
|
|
508
550
|
this.config.default[0] != values[0].val.toLowerCase()) {
|
|
509
551
|
// @ts-ignore/
|
|
510
552
|
values = parseString(this.config.default[0]);
|
|
511
553
|
}
|
|
512
|
-
iterable = [
|
|
554
|
+
iterable = [
|
|
555
|
+
{
|
|
513
556
|
typ: EnumToken.DeclarationNodeType,
|
|
514
557
|
nam: this.config.shorthand,
|
|
515
|
-
val: values
|
|
516
|
-
}
|
|
558
|
+
val: values,
|
|
559
|
+
},
|
|
560
|
+
][Symbol.iterator]();
|
|
517
561
|
}
|
|
518
562
|
}
|
|
519
563
|
const iterators = [];
|
|
@@ -541,7 +585,7 @@ class PropertyMap {
|
|
|
541
585
|
}
|
|
542
586
|
}
|
|
543
587
|
return v;
|
|
544
|
-
}
|
|
588
|
+
},
|
|
545
589
|
};
|
|
546
590
|
}
|
|
547
591
|
matchTypes(declaration) {
|
|
@@ -549,7 +593,7 @@ class PropertyMap {
|
|
|
549
593
|
const values = [...declaration.val];
|
|
550
594
|
let i;
|
|
551
595
|
let j;
|
|
552
|
-
const map = new Map;
|
|
596
|
+
const map = new Map();
|
|
553
597
|
for (i = 0; i < patterns.length; i++) {
|
|
554
598
|
for (j = 0; j < values.length; j++) {
|
|
555
599
|
if (!map.has(patterns[i])) {
|
|
@@ -558,10 +602,10 @@ class PropertyMap {
|
|
|
558
602
|
}
|
|
559
603
|
let count = map.get(patterns[i]);
|
|
560
604
|
if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
|
|
561
|
-
Object.defineProperty(values[j],
|
|
605
|
+
Object.defineProperty(values[j], "propertyName", {
|
|
562
606
|
enumerable: false,
|
|
563
607
|
writable: true,
|
|
564
|
-
value: patterns[i]
|
|
608
|
+
value: patterns[i],
|
|
565
609
|
});
|
|
566
610
|
map.set(patterns[i], --count);
|
|
567
611
|
values.splice(j--, 1);
|
|
@@ -579,10 +623,10 @@ class PropertyMap {
|
|
|
579
623
|
// @ts-ignore
|
|
580
624
|
if (declaration.val[i].propertyName == key) {
|
|
581
625
|
const val = { ...declaration.val[i] };
|
|
582
|
-
Object.defineProperty(val,
|
|
626
|
+
Object.defineProperty(val, "propertyName", {
|
|
583
627
|
enumerable: false,
|
|
584
628
|
writable: true,
|
|
585
|
-
value: v
|
|
629
|
+
value: v,
|
|
586
630
|
});
|
|
587
631
|
declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
|
|
588
632
|
}
|
|
@@ -599,7 +643,7 @@ class PropertyMap {
|
|
|
599
643
|
if (config == null) {
|
|
600
644
|
continue;
|
|
601
645
|
}
|
|
602
|
-
const v = val.value.join(
|
|
646
|
+
const v = val.value.join(" ");
|
|
603
647
|
if (config.default.includes(v) || (value.length == 1 && this.config.default.includes(v))) {
|
|
604
648
|
for (const token of value) {
|
|
605
649
|
if (val.t.includes(token)) {
|
|
@@ -610,8 +654,9 @@ class PropertyMap {
|
|
|
610
654
|
if (value[index].typ == EnumToken.WhitespaceTokenType) {
|
|
611
655
|
continue;
|
|
612
656
|
}
|
|
613
|
-
|
|
614
|
-
|
|
657
|
+
if (
|
|
658
|
+
// @ts-expect-error
|
|
659
|
+
value[index].typ == EnumToken[config.prefix.typ] &&
|
|
615
660
|
// @ts-ignore
|
|
616
661
|
value[index].val == config.prefix.val) {
|
|
617
662
|
value.splice(index, 1);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AstDeclaration, ShorthandPropertyType } from "../../../@types/index.d.ts";
|
|
2
|
+
export declare class PropertySet {
|
|
3
|
+
protected config: ShorthandPropertyType;
|
|
4
|
+
protected declarations: Map<string, AstDeclaration>;
|
|
5
|
+
constructor(config: ShorthandPropertyType);
|
|
6
|
+
add(declaration: AstDeclaration): this;
|
|
7
|
+
isShortHand(): boolean;
|
|
8
|
+
[Symbol.iterator](): IterableIterator<AstDeclaration>;
|
|
9
|
+
}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { eq } from '../utils/eq.js';
|
|
2
2
|
import { EnumToken } from '../../ast/types.js';
|
|
3
|
-
import '../../ast/minify.js';
|
|
4
|
-
import '../../ast/walk.js';
|
|
5
|
-
import '../parse.js';
|
|
6
|
-
import '../tokenize.js';
|
|
7
|
-
import '../utils/config.js';
|
|
8
3
|
import { isLength } from '../../syntax/syntax.js';
|
|
9
|
-
import '../../syntax/color/utils/constants.js';
|
|
10
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
11
4
|
|
|
12
5
|
function dedup(values) {
|
|
13
6
|
for (const value of values) {
|
|
@@ -18,7 +11,8 @@ function dedup(values) {
|
|
|
18
11
|
if (t.val == k.val && t.val == 0) {
|
|
19
12
|
if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
|
|
20
13
|
(k.typ == EnumToken.NumberTokenType && isLength(t)) ||
|
|
21
|
-
|
|
14
|
+
isLength(k) ||
|
|
15
|
+
isLength(t)) {
|
|
22
16
|
value.splice(i, 1);
|
|
23
17
|
continue;
|
|
24
18
|
}
|
|
@@ -37,25 +31,28 @@ class PropertySet {
|
|
|
37
31
|
declarations;
|
|
38
32
|
constructor(config) {
|
|
39
33
|
this.config = config;
|
|
40
|
-
this.declarations = new Map;
|
|
34
|
+
this.declarations = new Map();
|
|
41
35
|
}
|
|
42
36
|
add(declaration) {
|
|
43
37
|
if (declaration.nam == this.config.shorthand) {
|
|
44
|
-
this.declarations = new Map;
|
|
38
|
+
this.declarations = new Map();
|
|
45
39
|
}
|
|
46
40
|
else {
|
|
47
41
|
// expand shorthand
|
|
48
|
-
if (
|
|
42
|
+
if (this.declarations.has(this.config.shorthand)) {
|
|
49
43
|
let isValid = true;
|
|
50
44
|
let current = -1;
|
|
51
45
|
const tokens = [];
|
|
52
46
|
// @ts-ignore
|
|
53
47
|
for (let token of this.declarations.get(this.config.shorthand).val) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
if (
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
this.config.types.some((t) => token.typ == EnumToken[t]) ||
|
|
51
|
+
(token.typ == EnumToken.NumberTokenType &&
|
|
52
|
+
token.val == 0 &&
|
|
53
|
+
(this.config.types.includes("Length") ||
|
|
54
|
+
this.config.types.includes("Angle") ||
|
|
55
|
+
this.config.types.includes("Dimension")))) {
|
|
59
56
|
if (tokens.length == 0) {
|
|
60
57
|
tokens.push([]);
|
|
61
58
|
current++;
|
|
@@ -64,7 +61,8 @@ class PropertySet {
|
|
|
64
61
|
continue;
|
|
65
62
|
}
|
|
66
63
|
if (token.typ != EnumToken.WhitespaceTokenType && token.typ != EnumToken.CommentTokenType) {
|
|
67
|
-
if (token.typ == EnumToken.IdenTokenType &&
|
|
64
|
+
if (token.typ == EnumToken.IdenTokenType &&
|
|
65
|
+
this.config.keywords.includes(token.val)) {
|
|
68
66
|
if (tokens.length == 0) {
|
|
69
67
|
tokens.push([]);
|
|
70
68
|
current++;
|
|
@@ -72,7 +70,7 @@ class PropertySet {
|
|
|
72
70
|
tokens[current].push(token);
|
|
73
71
|
}
|
|
74
72
|
// @ts-ignore
|
|
75
|
-
if (token.typ == EnumToken.LiteralTokenType && token.val == this.config.separator) {
|
|
73
|
+
if (token.typ == EnumToken.LiteralTokenType && token.val == this.config.separator?.val) {
|
|
76
74
|
tokens.push([]);
|
|
77
75
|
current++;
|
|
78
76
|
continue;
|
|
@@ -89,7 +87,7 @@ class PropertySet {
|
|
|
89
87
|
this.declarations.set(property, {
|
|
90
88
|
typ: EnumToken.DeclarationNodeType,
|
|
91
89
|
nam: property,
|
|
92
|
-
val: []
|
|
90
|
+
val: [],
|
|
93
91
|
});
|
|
94
92
|
}
|
|
95
93
|
while (index > 0 && index >= values.length) {
|
|
@@ -150,7 +148,10 @@ class PropertySet {
|
|
|
150
148
|
this.config.properties.forEach((property) => {
|
|
151
149
|
let index = 0;
|
|
152
150
|
// @ts-ignore
|
|
153
|
-
for (const token of this.declarations.get(property)
|
|
151
|
+
for (const token of this.declarations.get(property)?.val ?? []) {
|
|
152
|
+
if (token == null) {
|
|
153
|
+
return this.declarations.values()[Symbol.iterator]();
|
|
154
|
+
}
|
|
154
155
|
if (token.typ == EnumToken.WhitespaceTokenType) {
|
|
155
156
|
continue;
|
|
156
157
|
}
|
|
@@ -161,8 +162,11 @@ class PropertySet {
|
|
|
161
162
|
index++;
|
|
162
163
|
}
|
|
163
164
|
});
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
if (this.config.valueSeparator == null) {
|
|
166
|
+
dedup(values);
|
|
167
|
+
}
|
|
168
|
+
iterator = [
|
|
169
|
+
{
|
|
166
170
|
typ: EnumToken.DeclarationNodeType,
|
|
167
171
|
nam: this.config.shorthand,
|
|
168
172
|
val: values.reduce((acc, curr) => {
|
|
@@ -176,12 +180,13 @@ class PropertySet {
|
|
|
176
180
|
}
|
|
177
181
|
if (acc.length > 0) {
|
|
178
182
|
// @ts-ignore
|
|
179
|
-
acc.push({ typ: EnumToken.LiteralTokenType
|
|
183
|
+
acc.push({ ...this.config.separator, typ: EnumToken.LiteralTokenType });
|
|
180
184
|
}
|
|
181
185
|
acc.push(...curr);
|
|
182
186
|
return acc;
|
|
183
|
-
}, [])
|
|
184
|
-
}
|
|
187
|
+
}, []),
|
|
188
|
+
},
|
|
189
|
+
][Symbol.iterator]();
|
|
185
190
|
}
|
|
186
191
|
return iterator;
|
|
187
192
|
}
|