@tbela99/css-parser 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +196 -2
- package/README.md +68 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +18118 -15886
- package/dist/index.cjs +16838 -14611
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +64 -17
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +530 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Options for the walk function
|
|
3
3
|
*/
|
|
4
4
|
var WalkerOptionEnum;
|
|
5
5
|
(function (WalkerOptionEnum) {
|
|
@@ -21,7 +21,7 @@ var WalkerOptionEnum;
|
|
|
21
21
|
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 8] = "IgnoreChildren";
|
|
22
22
|
})(WalkerOptionEnum || (WalkerOptionEnum = {}));
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Event types for the walkValues function
|
|
25
25
|
*/
|
|
26
26
|
var WalkerEvent;
|
|
27
27
|
(function (WalkerEvent) {
|
|
@@ -35,7 +35,7 @@ var WalkerEvent;
|
|
|
35
35
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
36
36
|
})(WalkerEvent || (WalkerEvent = {}));
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Walk ast nodes
|
|
39
39
|
* @param node initial node
|
|
40
40
|
* @param filter control the walk process
|
|
41
41
|
* @param reverse walk in reverse order
|
|
@@ -152,7 +152,7 @@ function* walk(node, filter, reverse) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
155
|
+
* Walk ast node value tokens
|
|
156
156
|
* @param values
|
|
157
157
|
* @param root
|
|
158
158
|
* @param filter
|
|
@@ -244,7 +244,6 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
244
244
|
function* () {
|
|
245
245
|
// @ts-expect-error
|
|
246
246
|
let parent = map.get(node);
|
|
247
|
-
console.debug({ parent });
|
|
248
247
|
while (parent != null) {
|
|
249
248
|
yield parent;
|
|
250
249
|
parent = map.get(parent);
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { memoize } from '../parser/utils/cache.js';
|
|
2
|
+
|
|
1
3
|
const matchUrl = /^(https?:)?\/\//;
|
|
2
4
|
/**
|
|
3
5
|
* return the directory name of a path
|
|
@@ -61,6 +63,54 @@ function splitPath(result) {
|
|
|
61
63
|
}
|
|
62
64
|
return { parts, i };
|
|
63
65
|
}
|
|
66
|
+
const normalize = memoize(function (path) {
|
|
67
|
+
let parts = [];
|
|
68
|
+
let i = 0;
|
|
69
|
+
if (path.includes("\\")) {
|
|
70
|
+
path = path.replace(/(\\)/g, "/");
|
|
71
|
+
}
|
|
72
|
+
for (; i < path.length; i++) {
|
|
73
|
+
const chr = path.charAt(i);
|
|
74
|
+
if (chr == "/") {
|
|
75
|
+
if (parts.length == 0 || parts[parts.length - 1] !== "") {
|
|
76
|
+
parts.push("");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (chr == "?" || chr == "#") {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (parts.length == 0) {
|
|
84
|
+
parts.push("");
|
|
85
|
+
}
|
|
86
|
+
parts[parts.length - 1] += chr;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let k = -1;
|
|
90
|
+
while (++k < parts.length) {
|
|
91
|
+
if (parts[k] == ".") {
|
|
92
|
+
parts.splice(k--, 1);
|
|
93
|
+
}
|
|
94
|
+
else if (parts[k] == "..") {
|
|
95
|
+
parts.splice(k - 1, 2);
|
|
96
|
+
k -= 2;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return (path.charAt(0) == "/" ? "/" : "") + parts.join("/");
|
|
100
|
+
});
|
|
101
|
+
const diff = memoize(function (path1, path2) {
|
|
102
|
+
let { parts } = splitPath(path1);
|
|
103
|
+
const { parts: dirs } = splitPath(path2);
|
|
104
|
+
for (const p of dirs) {
|
|
105
|
+
if (parts[0] == p) {
|
|
106
|
+
parts.shift();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
parts.unshift("..");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return parts.join("/");
|
|
113
|
+
});
|
|
64
114
|
/**
|
|
65
115
|
* resolve path
|
|
66
116
|
* @param url url or path to resolve
|
|
@@ -69,7 +119,7 @@ function splitPath(result) {
|
|
|
69
119
|
*
|
|
70
120
|
* @private
|
|
71
121
|
*/
|
|
72
|
-
|
|
122
|
+
const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
73
123
|
if (matchUrl.test(url)) {
|
|
74
124
|
return {
|
|
75
125
|
absolute: url,
|
|
@@ -78,20 +128,26 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
78
128
|
}
|
|
79
129
|
cwd ??= "";
|
|
80
130
|
currentDirectory ??= "";
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
131
|
+
url = normalize(url);
|
|
132
|
+
if (currentDirectory !== "") {
|
|
133
|
+
currentDirectory = normalize(currentDirectory);
|
|
134
|
+
if (url.startsWith(currentDirectory + "/")) {
|
|
135
|
+
return {
|
|
136
|
+
absolute: url,
|
|
137
|
+
relative: url.slice(currentDirectory.length + 1),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
86
140
|
}
|
|
87
|
-
if (currentDirectory === "" && cwd !== ""
|
|
141
|
+
if (currentDirectory === "" && cwd !== "") {
|
|
88
142
|
cwd = normalize(cwd);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
143
|
+
if (url.startsWith(cwd == "/" ? cwd : cwd + "/")) {
|
|
144
|
+
const absolute = url;
|
|
145
|
+
const prefix = cwd == "/" ? cwd : cwd + "/";
|
|
146
|
+
return {
|
|
147
|
+
absolute,
|
|
148
|
+
relative: absolute.startsWith(prefix) ? absolute.slice(prefix.length) : diff(absolute, cwd),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
95
151
|
}
|
|
96
152
|
if (matchUrl.test(currentDirectory)) {
|
|
97
153
|
const path = new URL(url, currentDirectory).href;
|
|
@@ -112,48 +168,6 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
112
168
|
absolute,
|
|
113
169
|
relative: absolute === "" ? "" : diff(absolute, cwd ?? currentDirectory),
|
|
114
170
|
};
|
|
115
|
-
}
|
|
116
|
-
function diff(path1, path2) {
|
|
117
|
-
let { parts } = splitPath(path1);
|
|
118
|
-
const { parts: dirs } = splitPath(path2);
|
|
119
|
-
for (const p of dirs) {
|
|
120
|
-
if (parts[0] == p) {
|
|
121
|
-
parts.shift();
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
parts.unshift("..");
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return parts.join("/");
|
|
128
|
-
}
|
|
129
|
-
function normalize(path) {
|
|
130
|
-
let parts = [];
|
|
131
|
-
let i = 0;
|
|
132
|
-
for (; i < path.length; i++) {
|
|
133
|
-
const chr = path.charAt(i);
|
|
134
|
-
if (chr == "/") {
|
|
135
|
-
if (parts.length == 0 || parts[parts.length - 1] !== "") {
|
|
136
|
-
parts.push("");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (chr == "?" || chr == "#") {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
parts[parts.length - 1] += chr;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
let k = -1;
|
|
147
|
-
while (++k < parts.length) {
|
|
148
|
-
if (parts[k] == ".") {
|
|
149
|
-
parts.splice(k--, 1);
|
|
150
|
-
}
|
|
151
|
-
else if (parts[k] == "..") {
|
|
152
|
-
parts.splice(k - 1, 2);
|
|
153
|
-
k -= 2;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return (path.charAt(0) == "/" ? "/" : "") + parts.join("/");
|
|
157
|
-
}
|
|
171
|
+
});
|
|
158
172
|
|
|
159
|
-
export { dirname, matchUrl, resolve };
|
|
173
|
+
export { diff, dirname, matchUrl, normalize, resolve };
|
|
@@ -2,7 +2,11 @@ import { PropertySet } from './set.js';
|
|
|
2
2
|
import { getConfig } from '../utils/config.js';
|
|
3
3
|
import { PropertyMap } from './map.js';
|
|
4
4
|
import { parseString } from '../parse.js';
|
|
5
|
-
import { EnumToken } from '../../ast/types.js';
|
|
5
|
+
import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
|
|
6
|
+
import { getParsedSyntax } from '../../validation/config.js';
|
|
7
|
+
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
8
|
+
import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
9
|
+
import { definedPropertySettings } from '../../syntax/constants.js';
|
|
6
10
|
|
|
7
11
|
const config = getConfig();
|
|
8
12
|
class PropertyList {
|
|
@@ -21,12 +25,17 @@ class PropertyList {
|
|
|
21
25
|
}
|
|
22
26
|
add(...declarations) {
|
|
23
27
|
let name;
|
|
28
|
+
let syntaxRules = null;
|
|
29
|
+
let result;
|
|
24
30
|
for (const declaration of declarations) {
|
|
25
31
|
name =
|
|
26
32
|
declaration.typ != EnumToken.DeclarationNodeType
|
|
27
33
|
? null
|
|
28
34
|
: declaration.nam.toLowerCase();
|
|
29
|
-
if (declaration.
|
|
35
|
+
if (declaration.state == EnumAstNodeStatus.Invalid ||
|
|
36
|
+
declaration.state == EnumAstNodeStatus.Unknown ||
|
|
37
|
+
declaration.state == EnumAstNodeStatus.ValidationFailed ||
|
|
38
|
+
declaration.typ != EnumToken.DeclarationNodeType ||
|
|
30
39
|
"composes" === name ||
|
|
31
40
|
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
32
41
|
this.options.removeDuplicateDeclarations === name) ||
|
|
@@ -40,9 +49,24 @@ class PropertyList {
|
|
|
40
49
|
this.declarations.set(declaration.nam, declaration);
|
|
41
50
|
continue;
|
|
42
51
|
}
|
|
52
|
+
if (declaration.state == EnumAstNodeStatus.Unvalidated) {
|
|
53
|
+
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
|
|
54
|
+
if (syntaxRules != null) {
|
|
55
|
+
result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
|
|
56
|
+
Object.defineProperty(declaration, "state", {
|
|
57
|
+
...definedPropertySettings,
|
|
58
|
+
value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// do not compute shorthand for invalid declarations
|
|
63
|
+
if (declaration.state !== EnumAstNodeStatus.Validated) {
|
|
64
|
+
this.declarations.set(declaration.nam, declaration);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
43
67
|
let propertyName = declaration.nam;
|
|
44
68
|
let shortHandType;
|
|
45
|
-
let shorthand;
|
|
69
|
+
let shorthand = null;
|
|
46
70
|
if (propertyName in config.properties) {
|
|
47
71
|
// @ts-ignore
|
|
48
72
|
if ("map" in config.properties[propertyName]) {
|
|
@@ -61,6 +85,11 @@ class PropertyList {
|
|
|
61
85
|
// @ts-ignore
|
|
62
86
|
shorthand = config.map[propertyName].shorthand;
|
|
63
87
|
}
|
|
88
|
+
else if (propertyName in config.property) {
|
|
89
|
+
shortHandType = "single";
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
shorthand = config.property[propertyName];
|
|
92
|
+
}
|
|
64
93
|
// @ts-ignore
|
|
65
94
|
if (shortHandType == "map") {
|
|
66
95
|
// @ts-ignore
|
|
@@ -86,11 +115,71 @@ class PropertyList {
|
|
|
86
115
|
this.declarations.get(shorthand).add(declaration);
|
|
87
116
|
}
|
|
88
117
|
else {
|
|
118
|
+
if (shorthand != null) {
|
|
119
|
+
this.mapValues(declaration, shorthand);
|
|
120
|
+
}
|
|
89
121
|
this.declarations.set(propertyName, declaration);
|
|
90
122
|
}
|
|
91
123
|
}
|
|
92
124
|
return this;
|
|
93
125
|
}
|
|
126
|
+
mapValues(declaration, mapping) {
|
|
127
|
+
let name;
|
|
128
|
+
let values = declaration.val;
|
|
129
|
+
if (mapping.pattern != null) {
|
|
130
|
+
// match pattern
|
|
131
|
+
for (const patterns of mapping.pattern) {
|
|
132
|
+
const set = new Set(values.filter((v) => v.typ !== EnumToken.CommentTokenType && v.typ !== EnumToken.WhitespaceTokenType));
|
|
133
|
+
const val = [];
|
|
134
|
+
for (const pattern of patterns) {
|
|
135
|
+
switch (pattern) {
|
|
136
|
+
case "<length>":
|
|
137
|
+
for (const v of set) {
|
|
138
|
+
if (v.typ === EnumToken.LengthTokenType ||
|
|
139
|
+
(v.typ === EnumToken.NumberTokenType && v.val === 0)) {
|
|
140
|
+
val.push(v);
|
|
141
|
+
set.delete(v);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
default: {
|
|
145
|
+
for (const v of set) {
|
|
146
|
+
if (v.typ === EnumToken.IdenTokenType) {
|
|
147
|
+
const value = v.val.toLowerCase();
|
|
148
|
+
if (value === pattern || new RegExp(`(^|\|)${pattern}(\||$)`).test(value)) {
|
|
149
|
+
val.push(v);
|
|
150
|
+
set.delete(v);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (set.size === 0) {
|
|
158
|
+
values = val.reduce((acc, curr) => {
|
|
159
|
+
if (acc.length > 0) {
|
|
160
|
+
acc.push({ typ: EnumToken.WhitespaceTokenType });
|
|
161
|
+
}
|
|
162
|
+
acc.push(curr);
|
|
163
|
+
return acc;
|
|
164
|
+
}, []);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const val of declaration.val) {
|
|
170
|
+
if (val.typ === EnumToken.IdenTokenType) {
|
|
171
|
+
name = val.val.toLowerCase();
|
|
172
|
+
if (mapping.mapping[name] != null) {
|
|
173
|
+
// @ts-expect-error
|
|
174
|
+
Object.assign(val, mapping.mapping[name], { typ: EnumToken[mapping.mapping[name].typ] });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (values != declaration.val) {
|
|
179
|
+
declaration.val.length = 0;
|
|
180
|
+
declaration.val.push(...values);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
94
183
|
[Symbol.iterator]() {
|
|
95
184
|
let iterator = this.declarations.values();
|
|
96
185
|
const iterators = [];
|
|
@@ -2,7 +2,7 @@ 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 {
|
|
5
|
+
import { renderValue } from '../../renderer/render.js';
|
|
6
6
|
import { parseString } from '../parse.js';
|
|
7
7
|
import { PropertySet } from './set.js';
|
|
8
8
|
|
|
@@ -219,7 +219,7 @@ class PropertyMap {
|
|
|
219
219
|
};
|
|
220
220
|
// @ts-ignore
|
|
221
221
|
const separator = this.config.separator
|
|
222
|
-
?
|
|
222
|
+
? renderValue({
|
|
223
223
|
...this.config.separator,
|
|
224
224
|
typ: EnumToken[this.config.separator.typ],
|
|
225
225
|
})
|
|
@@ -229,7 +229,7 @@ class PropertyMap {
|
|
|
229
229
|
for (i = 0; i < declaration.val.length; i++) {
|
|
230
230
|
t = declaration.val[i];
|
|
231
231
|
if (!cache.has(t)) {
|
|
232
|
-
cache.set(t,
|
|
232
|
+
cache.set(t, renderValue(t, { minify: true }));
|
|
233
233
|
}
|
|
234
234
|
if (t.typ == typ && separator == cache.get(t)) {
|
|
235
235
|
this.removeDefaults(map, value);
|
|
@@ -430,7 +430,7 @@ class PropertyMap {
|
|
|
430
430
|
return acc;
|
|
431
431
|
}, []);
|
|
432
432
|
if (props.default.includes(curr[1][i]
|
|
433
|
-
.reduce((acc, curr) => acc +
|
|
433
|
+
.reduce((acc, curr) => acc + renderValue(curr) + " ", "")
|
|
434
434
|
.trimEnd())) {
|
|
435
435
|
if (!this.config.properties[curr[0]].required) {
|
|
436
436
|
continue;
|
|
@@ -527,7 +527,7 @@ class PropertyMap {
|
|
|
527
527
|
}, []);
|
|
528
528
|
if (this.config.mapping != null) {
|
|
529
529
|
const val = values.reduce((acc, curr) => acc +
|
|
530
|
-
|
|
530
|
+
renderValue(curr, {
|
|
531
531
|
removeComments: true,
|
|
532
532
|
minify: true,
|
|
533
533
|
}), "");
|