@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
package/dist/lib/ast/walk.js
CHANGED
|
@@ -110,29 +110,41 @@ var WalkerEvent;
|
|
|
110
110
|
function* walk(node, filter, reverse) {
|
|
111
111
|
const parents = [node];
|
|
112
112
|
const root = node;
|
|
113
|
-
const map = new Map;
|
|
113
|
+
const map = new Map();
|
|
114
114
|
let isNumeric = false;
|
|
115
115
|
let i = 0;
|
|
116
116
|
while ((node = parents[i++])) {
|
|
117
117
|
let option = null;
|
|
118
118
|
if (filter != null) {
|
|
119
119
|
option = filter(node);
|
|
120
|
-
isNumeric = typeof option ==
|
|
120
|
+
isNumeric = typeof option == "number";
|
|
121
121
|
if (isNumeric) {
|
|
122
|
-
if (
|
|
122
|
+
if (option & WalkerOptionEnum.Ignore) {
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
|
-
if (
|
|
125
|
+
if (option & WalkerOptionEnum.Stop) {
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
if (!isNumeric || (option & WalkerOptionEnum.Children) === 0) {
|
|
131
131
|
// @ts-ignore
|
|
132
|
-
yield {
|
|
132
|
+
yield {
|
|
133
|
+
node,
|
|
134
|
+
parent: map.get(node),
|
|
135
|
+
root,
|
|
136
|
+
// @ts-expect-error
|
|
137
|
+
parents: function* () {
|
|
138
|
+
let parent = map.get(node);
|
|
139
|
+
while (parent != null) {
|
|
140
|
+
yield parent;
|
|
141
|
+
parent = map.get(parent);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
};
|
|
133
145
|
}
|
|
134
|
-
if (
|
|
135
|
-
parents.splice(i, 0, ...node.chi[reverse ?
|
|
146
|
+
if ("chi" in node && (!isNumeric || (option & WalkerOptionEnum.IgnoreChildren) === 0)) {
|
|
147
|
+
parents.splice(i, 0, ...node.chi[reverse ? "reverse" : "slice"]());
|
|
136
148
|
for (const child of node.chi) {
|
|
137
149
|
map.set(child, node);
|
|
138
150
|
}
|
|
@@ -188,44 +200,70 @@ function* walk(node, filter, reverse) {
|
|
|
188
200
|
*/
|
|
189
201
|
function* walkValues(values, root = null, filter, reverse) {
|
|
190
202
|
const stack = values.slice();
|
|
191
|
-
const map = new Map;
|
|
203
|
+
const map = new Map();
|
|
204
|
+
const used = new Set();
|
|
192
205
|
let previous = null;
|
|
193
|
-
if (filter != null && typeof filter ==
|
|
206
|
+
if (filter != null && typeof filter == "function") {
|
|
194
207
|
filter = {
|
|
195
208
|
event: WalkerEvent.Enter,
|
|
196
|
-
fn: filter
|
|
209
|
+
fn: filter,
|
|
197
210
|
};
|
|
198
211
|
}
|
|
199
212
|
else if (filter == null) {
|
|
200
213
|
filter = {
|
|
201
|
-
event: WalkerEvent.Enter
|
|
214
|
+
event: WalkerEvent.Enter,
|
|
202
215
|
};
|
|
203
216
|
}
|
|
204
217
|
let isNumeric = false;
|
|
218
|
+
let value;
|
|
219
|
+
let option;
|
|
220
|
+
let node;
|
|
221
|
+
// const parents: Token[] = [];
|
|
205
222
|
const eventType = filter.event ?? WalkerEvent.Enter;
|
|
206
223
|
while (stack.length > 0) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
224
|
+
value = reverse ? stack.pop() : stack.shift();
|
|
225
|
+
option = null;
|
|
226
|
+
node = map.get(value) ?? null;
|
|
227
|
+
if (used.has(value)) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
used.add(value);
|
|
231
|
+
// parents.length = 0;
|
|
232
|
+
// while (node != null) {
|
|
233
|
+
// parents.push(node);
|
|
234
|
+
// node = map.get(node) ?? null;
|
|
235
|
+
// }
|
|
236
|
+
if (filter.fn != null && eventType & WalkerEvent.Enter) {
|
|
237
|
+
const isValid = filter.type == null ||
|
|
238
|
+
value.typ == filter.type ||
|
|
211
239
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
212
|
-
(typeof filter.type ==
|
|
240
|
+
(typeof filter.type == "function" && filter.type(value));
|
|
213
241
|
if (isValid) {
|
|
214
|
-
option = filter.fn(value, map.get(value) ?? root, WalkerEvent.Enter
|
|
215
|
-
|
|
216
|
-
|
|
242
|
+
option = filter.fn(value, map.get(value) ?? root, WalkerEvent.Enter,
|
|
243
|
+
// @ts-expect-error
|
|
244
|
+
function* () {
|
|
245
|
+
// @ts-expect-error
|
|
246
|
+
let parent = map.get(node);
|
|
247
|
+
console.debug({ parent });
|
|
248
|
+
while (parent != null) {
|
|
249
|
+
yield parent;
|
|
250
|
+
parent = map.get(parent);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
isNumeric = typeof option == "number";
|
|
254
|
+
if (isNumeric && option & WalkerOptionEnum.Stop) {
|
|
217
255
|
return;
|
|
218
256
|
}
|
|
219
|
-
if (isNumeric &&
|
|
257
|
+
if (isNumeric && option & WalkerOptionEnum.Ignore) {
|
|
220
258
|
continue;
|
|
221
259
|
}
|
|
222
260
|
// @ts-ignore
|
|
223
|
-
if (option != null && typeof option ==
|
|
261
|
+
if (option != null && typeof option == "object" && ("typ" in option || Array.isArray(option))) {
|
|
224
262
|
const op = Array.isArray(option) ? option : [option];
|
|
225
263
|
for (const o of op) {
|
|
226
264
|
map.set(o, map.get(value) ?? root);
|
|
227
265
|
}
|
|
228
|
-
stack[reverse ?
|
|
266
|
+
stack[reverse ? "push" : "unshift"](...op);
|
|
229
267
|
}
|
|
230
268
|
}
|
|
231
269
|
}
|
|
@@ -235,61 +273,79 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
235
273
|
previousValue: previous,
|
|
236
274
|
nextValue: stack[0] ?? null,
|
|
237
275
|
// @ts-ignore
|
|
238
|
-
root: root ?? null
|
|
276
|
+
root: root ?? null,
|
|
277
|
+
// @ts-expect-error
|
|
278
|
+
parents: function* () {
|
|
279
|
+
// @ts-expect-error
|
|
280
|
+
let result = map.get(node) ?? root;
|
|
281
|
+
let next;
|
|
282
|
+
do {
|
|
283
|
+
yield result;
|
|
284
|
+
next = map.get(result) ?? root;
|
|
285
|
+
if (next == result) {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
result = next;
|
|
289
|
+
} while (result != null);
|
|
290
|
+
},
|
|
239
291
|
};
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
else {
|
|
248
|
-
const values = [];
|
|
249
|
-
if ('l' in value && value.l != null) {
|
|
250
|
-
// @ts-ignore
|
|
251
|
-
values.push(value.l);
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
map.set(value.l, value);
|
|
254
|
-
}
|
|
255
|
-
if ('op' in value && typeof value.op == 'object') {
|
|
256
|
-
values.push(value.op);
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
map.set(value.op, value);
|
|
292
|
+
if (!isNumeric || (option & WalkerOptionEnum.IgnoreChildren) === 0) {
|
|
293
|
+
if ("chi" in value) {
|
|
294
|
+
const sliced = value.chi.slice();
|
|
295
|
+
for (const child of sliced) {
|
|
296
|
+
map.set(child, value);
|
|
297
|
+
}
|
|
298
|
+
stack[reverse ? "push" : "unshift"](...sliced);
|
|
259
299
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
300
|
+
else {
|
|
301
|
+
const values = [];
|
|
302
|
+
if ("l" in value && value.l != null) {
|
|
303
|
+
// @ts-ignore
|
|
304
|
+
values.push(value.l);
|
|
305
|
+
// @ts-ignore
|
|
306
|
+
map.set(value.l, value);
|
|
307
|
+
}
|
|
308
|
+
if ("op" in value && typeof value.op == "object") {
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
values.push(value.op);
|
|
311
|
+
// @ts-ignore
|
|
312
|
+
map.set(value.op, value);
|
|
313
|
+
}
|
|
314
|
+
if ("r" in value && value.r != null) {
|
|
315
|
+
if (Array.isArray(value.r)) {
|
|
316
|
+
for (const r of value.r) {
|
|
317
|
+
// @ts-ignore
|
|
318
|
+
values.push(r);
|
|
319
|
+
// @ts-ignore
|
|
320
|
+
map.set(r, value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
263
324
|
// @ts-ignore
|
|
264
|
-
values.push(r);
|
|
325
|
+
values.push(value.r);
|
|
265
326
|
// @ts-ignore
|
|
266
|
-
map.set(r, value);
|
|
327
|
+
map.set(value.r, value);
|
|
267
328
|
}
|
|
268
329
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
values.push(value.r);
|
|
272
|
-
// @ts-ignore
|
|
273
|
-
map.set(value.r, value);
|
|
330
|
+
if (values.length > 0) {
|
|
331
|
+
stack[reverse ? "push" : "unshift"](...values);
|
|
274
332
|
}
|
|
275
333
|
}
|
|
276
|
-
if (values.length > 0) {
|
|
277
|
-
stack[reverse ? 'push' : 'unshift'](...values);
|
|
278
|
-
}
|
|
279
334
|
}
|
|
280
|
-
if (
|
|
281
|
-
const isValid = filter.type == null ||
|
|
335
|
+
if (eventType & WalkerEvent.Leave && filter.fn != null) {
|
|
336
|
+
const isValid = filter.type == null ||
|
|
337
|
+
value.typ == filter.type ||
|
|
282
338
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
283
|
-
(typeof filter.type ==
|
|
339
|
+
(typeof filter.type == "function" && filter.type(value));
|
|
284
340
|
if (isValid) {
|
|
285
341
|
option = filter.fn(value, map.get(value), WalkerEvent.Leave);
|
|
286
342
|
// @ts-ignore
|
|
287
|
-
if (option != null && (
|
|
343
|
+
if (option != null && ("typ" in option || Array.isArray(option))) {
|
|
288
344
|
const op = Array.isArray(option) ? option : [option];
|
|
289
345
|
for (const o of op) {
|
|
290
346
|
map.set(o, map.get(value) ?? root);
|
|
291
347
|
}
|
|
292
|
-
stack[reverse ?
|
|
348
|
+
stack[reverse ? "push" : "unshift"](...op);
|
|
293
349
|
}
|
|
294
350
|
}
|
|
295
351
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const matchUrl: RegExp;
|
|
2
|
+
/**
|
|
3
|
+
* return the directory name of a path
|
|
4
|
+
* @param path
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare function dirname(path: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* resolve path
|
|
11
|
+
* @param url url or path to resolve
|
|
12
|
+
* @param currentDirectory directory used to resolve the path
|
|
13
|
+
* @param cwd current working directory
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
18
|
+
absolute: string;
|
|
19
|
+
relative: string;
|
|
20
|
+
};
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -6,30 +6,22 @@ const matchUrl = /^(https?:)?\/\//;
|
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
8
|
function dirname(path) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// return path;
|
|
12
|
-
// }
|
|
13
|
-
if (path === '') {
|
|
14
|
-
return '';
|
|
9
|
+
if (path === "") {
|
|
10
|
+
return "";
|
|
15
11
|
}
|
|
16
12
|
let i = 0;
|
|
17
|
-
let parts = [
|
|
13
|
+
let parts = [""];
|
|
18
14
|
for (; i < path.length; i++) {
|
|
19
15
|
const chr = path.charAt(i);
|
|
20
|
-
if (chr ==
|
|
21
|
-
parts.push(
|
|
16
|
+
if (chr == "/") {
|
|
17
|
+
parts.push("");
|
|
22
18
|
}
|
|
23
|
-
// else if (chr == '?' || chr == '#') {
|
|
24
|
-
//
|
|
25
|
-
// break;
|
|
26
|
-
// }
|
|
27
19
|
else {
|
|
28
20
|
parts[parts.length - 1] += chr;
|
|
29
21
|
}
|
|
30
22
|
}
|
|
31
23
|
parts.pop();
|
|
32
|
-
return parts.length == 0 ?
|
|
24
|
+
return parts.length == 0 ? "/" : parts.join("/");
|
|
33
25
|
}
|
|
34
26
|
/**
|
|
35
27
|
* split path
|
|
@@ -40,17 +32,17 @@ function splitPath(result) {
|
|
|
40
32
|
if (result.length == 0) {
|
|
41
33
|
return { parts: [], i: 0 };
|
|
42
34
|
}
|
|
43
|
-
if (result ===
|
|
44
|
-
return { parts: [
|
|
35
|
+
if (result === "/") {
|
|
36
|
+
return { parts: ["/"], i: 0 };
|
|
45
37
|
}
|
|
46
|
-
const parts = [
|
|
38
|
+
const parts = [""];
|
|
47
39
|
let i = 0;
|
|
48
40
|
for (; i < result.length; i++) {
|
|
49
41
|
const chr = result.charAt(i);
|
|
50
|
-
if (chr ==
|
|
51
|
-
parts.push(
|
|
42
|
+
if (chr == "/") {
|
|
43
|
+
parts.push("");
|
|
52
44
|
}
|
|
53
|
-
else if (chr ==
|
|
45
|
+
else if (chr == "?" || chr == "#") {
|
|
54
46
|
break;
|
|
55
47
|
}
|
|
56
48
|
else {
|
|
@@ -59,10 +51,10 @@ function splitPath(result) {
|
|
|
59
51
|
}
|
|
60
52
|
let k = -1;
|
|
61
53
|
while (++k < parts.length) {
|
|
62
|
-
if (parts[k] ==
|
|
54
|
+
if (parts[k] == ".") {
|
|
63
55
|
parts.splice(k--, 1);
|
|
64
56
|
}
|
|
65
|
-
else if (parts[k] ==
|
|
57
|
+
else if (parts[k] == "..") {
|
|
66
58
|
parts.splice(k - 1, 2);
|
|
67
59
|
k -= 2;
|
|
68
60
|
}
|
|
@@ -81,44 +73,44 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
81
73
|
if (matchUrl.test(url)) {
|
|
82
74
|
return {
|
|
83
75
|
absolute: url,
|
|
84
|
-
relative: url
|
|
76
|
+
relative: url,
|
|
85
77
|
};
|
|
86
78
|
}
|
|
87
|
-
cwd ??=
|
|
88
|
-
currentDirectory ??=
|
|
89
|
-
if (currentDirectory !==
|
|
79
|
+
cwd ??= "";
|
|
80
|
+
currentDirectory ??= "";
|
|
81
|
+
if (currentDirectory !== "" && url.startsWith(currentDirectory + "/")) {
|
|
90
82
|
return {
|
|
91
83
|
absolute: url,
|
|
92
|
-
relative: url.slice(currentDirectory.length + 1)
|
|
84
|
+
relative: url.slice(currentDirectory.length + 1),
|
|
93
85
|
};
|
|
94
86
|
}
|
|
95
|
-
if (currentDirectory ===
|
|
87
|
+
if (currentDirectory === "" && cwd !== "" && url.startsWith(cwd == "/" ? cwd : cwd + "/")) {
|
|
96
88
|
cwd = normalize(cwd);
|
|
97
89
|
const absolute = normalize(url);
|
|
98
|
-
const prefix = cwd ==
|
|
90
|
+
const prefix = cwd == "/" ? cwd : cwd + "/";
|
|
99
91
|
return {
|
|
100
92
|
absolute,
|
|
101
|
-
relative: absolute.startsWith(prefix) ? absolute.slice(prefix.length) : diff(absolute, cwd)
|
|
93
|
+
relative: absolute.startsWith(prefix) ? absolute.slice(prefix.length) : diff(absolute, cwd),
|
|
102
94
|
};
|
|
103
95
|
}
|
|
104
96
|
if (matchUrl.test(currentDirectory)) {
|
|
105
97
|
const path = new URL(url, currentDirectory).href;
|
|
106
98
|
return {
|
|
107
99
|
absolute: path,
|
|
108
|
-
relative: path
|
|
100
|
+
relative: path,
|
|
109
101
|
};
|
|
110
102
|
}
|
|
111
|
-
let result =
|
|
112
|
-
if (url.charAt(0) ==
|
|
103
|
+
let result = "";
|
|
104
|
+
if (url.charAt(0) == "/") {
|
|
113
105
|
result = url;
|
|
114
106
|
}
|
|
115
|
-
else if (currentDirectory.charAt(0) ==
|
|
116
|
-
result = dirname(currentDirectory) +
|
|
107
|
+
else if (currentDirectory.charAt(0) == "/") {
|
|
108
|
+
result = dirname(currentDirectory) + "/" + url;
|
|
117
109
|
}
|
|
118
110
|
const absolute = normalize(result);
|
|
119
111
|
return {
|
|
120
112
|
absolute,
|
|
121
|
-
relative: absolute ===
|
|
113
|
+
relative: absolute === "" ? "" : diff(absolute, cwd ?? currentDirectory),
|
|
122
114
|
};
|
|
123
115
|
}
|
|
124
116
|
function diff(path1, path2) {
|
|
@@ -129,22 +121,22 @@ function diff(path1, path2) {
|
|
|
129
121
|
parts.shift();
|
|
130
122
|
}
|
|
131
123
|
else {
|
|
132
|
-
parts.unshift(
|
|
124
|
+
parts.unshift("..");
|
|
133
125
|
}
|
|
134
126
|
}
|
|
135
|
-
return parts.join(
|
|
127
|
+
return parts.join("/");
|
|
136
128
|
}
|
|
137
129
|
function normalize(path) {
|
|
138
130
|
let parts = [];
|
|
139
131
|
let i = 0;
|
|
140
132
|
for (; i < path.length; i++) {
|
|
141
133
|
const chr = path.charAt(i);
|
|
142
|
-
if (chr ==
|
|
143
|
-
if (parts.length == 0 || parts[parts.length - 1] !==
|
|
144
|
-
parts.push(
|
|
134
|
+
if (chr == "/") {
|
|
135
|
+
if (parts.length == 0 || parts[parts.length - 1] !== "") {
|
|
136
|
+
parts.push("");
|
|
145
137
|
}
|
|
146
138
|
}
|
|
147
|
-
else if (chr ==
|
|
139
|
+
else if (chr == "?" || chr == "#") {
|
|
148
140
|
break;
|
|
149
141
|
}
|
|
150
142
|
else {
|
|
@@ -153,15 +145,15 @@ function normalize(path) {
|
|
|
153
145
|
}
|
|
154
146
|
let k = -1;
|
|
155
147
|
while (++k < parts.length) {
|
|
156
|
-
if (parts[k] ==
|
|
148
|
+
if (parts[k] == ".") {
|
|
157
149
|
parts.splice(k--, 1);
|
|
158
150
|
}
|
|
159
|
-
else if (parts[k] ==
|
|
151
|
+
else if (parts[k] == "..") {
|
|
160
152
|
parts.splice(k - 1, 2);
|
|
161
153
|
k -= 2;
|
|
162
154
|
}
|
|
163
155
|
}
|
|
164
|
-
return (path.charAt(0) ==
|
|
156
|
+
return (path.charAt(0) == "/" ? "/" : "") + parts.join("/");
|
|
165
157
|
}
|
|
166
158
|
|
|
167
159
|
export { dirname, matchUrl, resolve };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AstNode, PropertyListOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
+
import { PropertySet } from "./set.ts";
|
|
3
|
+
import { PropertyMap } from "./map.ts";
|
|
4
|
+
export declare class PropertyList {
|
|
5
|
+
protected options: PropertyListOptions;
|
|
6
|
+
protected declarations: Map<string, AstNode | PropertySet | PropertyMap>;
|
|
7
|
+
constructor(options?: PropertyListOptions);
|
|
8
|
+
set(nam: string, value: string | Token[]): this;
|
|
9
|
+
add(...declarations: AstNode[]): this;
|
|
10
|
+
[Symbol.iterator](): {
|
|
11
|
+
next(): {
|
|
12
|
+
value: AstNode;
|
|
13
|
+
done: boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { PropertySet } from './set.js';
|
|
2
2
|
import { getConfig } from '../utils/config.js';
|
|
3
|
-
import { EnumToken } from '../../ast/types.js';
|
|
4
|
-
import '../../ast/minify.js';
|
|
5
|
-
import '../../ast/walk.js';
|
|
6
|
-
import { parseString } from '../parse.js';
|
|
7
|
-
import '../tokenize.js';
|
|
8
|
-
import '../../syntax/color/utils/constants.js';
|
|
9
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
3
|
import { PropertyMap } from './map.js';
|
|
4
|
+
import { parseString } from '../parse.js';
|
|
5
|
+
import { EnumToken } from '../../ast/types.js';
|
|
11
6
|
|
|
12
7
|
const config = getConfig();
|
|
13
8
|
class PropertyList {
|
|
@@ -15,23 +10,29 @@ class PropertyList {
|
|
|
15
10
|
declarations;
|
|
16
11
|
constructor(options = {}) {
|
|
17
12
|
this.options = options;
|
|
18
|
-
this.declarations = new Map;
|
|
13
|
+
this.declarations = new Map();
|
|
19
14
|
}
|
|
20
15
|
set(nam, value) {
|
|
21
16
|
return this.add({
|
|
22
17
|
typ: EnumToken.DeclarationNodeType,
|
|
23
18
|
nam,
|
|
24
|
-
val: Array.isArray(value) ? value : parseString(String(value))
|
|
19
|
+
val: Array.isArray(value) ? value : parseString(String(value)),
|
|
25
20
|
});
|
|
26
21
|
}
|
|
27
22
|
add(...declarations) {
|
|
28
23
|
let name;
|
|
29
24
|
for (const declaration of declarations) {
|
|
30
|
-
name =
|
|
25
|
+
name =
|
|
26
|
+
declaration.typ != EnumToken.DeclarationNodeType
|
|
27
|
+
? null
|
|
28
|
+
: declaration.nam.toLowerCase();
|
|
31
29
|
if (declaration.typ != EnumToken.DeclarationNodeType ||
|
|
32
|
-
|
|
33
|
-
(typeof this.options.removeDuplicateDeclarations ===
|
|
34
|
-
|
|
30
|
+
"composes" === name ||
|
|
31
|
+
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
32
|
+
this.options.removeDuplicateDeclarations === name) ||
|
|
33
|
+
(Array.isArray(this.options.removeDuplicateDeclarations)
|
|
34
|
+
? this.options.removeDuplicateDeclarations.includes(declaration.nam)
|
|
35
|
+
: !this.options.removeDuplicateDeclarations)) {
|
|
35
36
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
36
37
|
continue;
|
|
37
38
|
}
|
|
@@ -44,24 +45,24 @@ class PropertyList {
|
|
|
44
45
|
let shorthand;
|
|
45
46
|
if (propertyName in config.properties) {
|
|
46
47
|
// @ts-ignore
|
|
47
|
-
if (
|
|
48
|
-
shortHandType =
|
|
48
|
+
if ("map" in config.properties[propertyName]) {
|
|
49
|
+
shortHandType = "map";
|
|
49
50
|
// @ts-ignore
|
|
50
51
|
shorthand = config.properties[propertyName].map;
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
|
-
shortHandType =
|
|
54
|
+
shortHandType = "set";
|
|
54
55
|
// @ts-ignore
|
|
55
56
|
shorthand = config.properties[propertyName].shorthand;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
else if (propertyName in config.map) {
|
|
59
|
-
shortHandType =
|
|
60
|
+
shortHandType = "map";
|
|
60
61
|
// @ts-ignore
|
|
61
62
|
shorthand = config.map[propertyName].shorthand;
|
|
62
63
|
}
|
|
63
64
|
// @ts-ignore
|
|
64
|
-
if (shortHandType ==
|
|
65
|
+
if (shortHandType == "map") {
|
|
65
66
|
// @ts-ignore
|
|
66
67
|
if (!this.declarations.has(shorthand)) {
|
|
67
68
|
// @ts-ignore
|
|
@@ -69,19 +70,20 @@ class PropertyList {
|
|
|
69
70
|
}
|
|
70
71
|
// @ts-ignore
|
|
71
72
|
this.declarations.get(shorthand).add(declaration);
|
|
72
|
-
// return this;
|
|
73
73
|
}
|
|
74
74
|
// @ts-ignore
|
|
75
|
-
else if (shortHandType ==
|
|
75
|
+
else if (shortHandType == "set") {
|
|
76
76
|
// @ts-ignore
|
|
77
|
-
// const shorthand: string = <string>config.properties[propertyName].shorthand;
|
|
78
77
|
if (!this.declarations.has(shorthand)) {
|
|
79
78
|
// @ts-ignore
|
|
80
|
-
this.declarations.set(
|
|
79
|
+
this.declarations.set(
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
shorthand,
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
new PropertySet(config.properties[shorthand]));
|
|
81
84
|
}
|
|
82
85
|
// @ts-ignore
|
|
83
86
|
this.declarations.get(shorthand).add(declaration);
|
|
84
|
-
// return this;
|
|
85
87
|
}
|
|
86
88
|
else {
|
|
87
89
|
this.declarations.set(propertyName, declaration);
|
|
@@ -110,7 +112,7 @@ class PropertyList {
|
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
return value;
|
|
113
|
-
}
|
|
115
|
+
},
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AstDeclaration, ShorthandMapType } from "../../../@types/index.d.ts";
|
|
2
|
+
import { PropertySet } from "./set.ts";
|
|
3
|
+
export declare class PropertyMap {
|
|
4
|
+
protected config: ShorthandMapType;
|
|
5
|
+
protected declarations: Map<string, AstDeclaration | PropertySet>;
|
|
6
|
+
protected requiredCount: any;
|
|
7
|
+
protected pattern: string[];
|
|
8
|
+
constructor(config: ShorthandMapType);
|
|
9
|
+
add(declaration: AstDeclaration): this;
|
|
10
|
+
[Symbol.iterator](): ArrayIterator<AstDeclaration> | {
|
|
11
|
+
next(): IteratorResult<AstDeclaration>;
|
|
12
|
+
};
|
|
13
|
+
private matchTypes;
|
|
14
|
+
private removeDefaults;
|
|
15
|
+
}
|