@tbela99/css-parser 1.4.6 → 1.4.8
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 +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +284 -283
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -298
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
package/dist/lib/ast/minify.js
CHANGED
|
@@ -6,7 +6,7 @@ import { EnumToken } from './types.js';
|
|
|
6
6
|
import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/syntax.js';
|
|
7
7
|
import { FeatureWalkMode } from './features/type.js';
|
|
8
8
|
import { trimArray } from '../validation/match.js';
|
|
9
|
-
import {
|
|
9
|
+
import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOC } from '../syntax/constants.js';
|
|
10
10
|
import { replaceNodeOrValue } from '../parser/utils/token.js';
|
|
11
11
|
import { parseString } from '../parser/parse.js';
|
|
12
12
|
import { tokenize } from '../parser/tokenize.js';
|
|
@@ -71,31 +71,24 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
71
71
|
(feature.accept != null && !feature.accept.has(parent.typ))) {
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
74
|
-
if (rules.includes(replacement.typ) && !Array.isArray(replacement
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
replacement.typ === EnumToken.KeyFramesRuleNodeType
|
|
79
|
-
? replacement.sel
|
|
80
|
-
: replacement.nam),
|
|
81
|
-
});
|
|
74
|
+
if (rules.includes(replacement.typ) && !Array.isArray(replacement[TOKENS])) {
|
|
75
|
+
replacement[TOKENS] = parseString(replacement.typ == EnumToken.RuleNodeType || replacement.typ === EnumToken.KeyFramesRuleNodeType
|
|
76
|
+
? replacement.sel
|
|
77
|
+
: replacement.nam);
|
|
82
78
|
}
|
|
83
|
-
const result = feature.run(replacement, options, parent
|
|
79
|
+
const result = feature.run(replacement, options, parent[PARENT] ?? ast, context, FeatureWalkMode.Pre);
|
|
84
80
|
if (result != null) {
|
|
85
81
|
replacement = result;
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
if (replacement != parent && parent
|
|
89
|
-
|
|
90
|
-
replaceNodeOrValue(parent.parent, parent, replacement);
|
|
84
|
+
if (replacement != parent && parent[PARENT] != null) {
|
|
85
|
+
replaceNodeOrValue(parent[PARENT], parent, replacement);
|
|
91
86
|
}
|
|
92
87
|
if ("chi" in replacement) {
|
|
93
88
|
// @ts-ignore
|
|
94
89
|
for (const node of replacement.chi) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
value: replacement,
|
|
98
|
-
}));
|
|
90
|
+
node[PARENT] = replacement;
|
|
91
|
+
parents.add(node);
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
}
|
|
@@ -119,22 +112,20 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
119
112
|
(feature.accept != null && !feature.accept.has(parent.typ))) {
|
|
120
113
|
continue;
|
|
121
114
|
}
|
|
122
|
-
const result = feature.run(replacement, options, parent
|
|
115
|
+
const result = feature.run(replacement, options, parent[PARENT] ?? ast, context, FeatureWalkMode.Post);
|
|
123
116
|
if (result != null) {
|
|
124
117
|
replacement = result;
|
|
125
118
|
}
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
|
-
if (replacement != null && replacement != parent && parent
|
|
121
|
+
if (replacement != null && replacement != parent && parent[PARENT] != null) {
|
|
129
122
|
// @ts-ignore
|
|
130
|
-
replaceNodeOrValue(parent
|
|
123
|
+
replaceNodeOrValue(parent[PARENT], parent, replacement);
|
|
131
124
|
}
|
|
132
125
|
if ("chi" in replacement) {
|
|
133
126
|
for (const node of replacement.chi) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
value: replacement,
|
|
137
|
-
}));
|
|
127
|
+
node[PARENT] = replacement;
|
|
128
|
+
parents.add(node);
|
|
138
129
|
}
|
|
139
130
|
}
|
|
140
131
|
}
|
|
@@ -211,7 +202,7 @@ function transformAtRuleMediaPrelude(values) {
|
|
|
211
202
|
},
|
|
212
203
|
l: val1,
|
|
213
204
|
r: val2,
|
|
214
|
-
|
|
205
|
+
[LOC]: value[LOC],
|
|
215
206
|
},
|
|
216
207
|
],
|
|
217
208
|
};
|
|
@@ -382,12 +373,12 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
382
373
|
}
|
|
383
374
|
else if (node.typ == EnumToken.AtRuleNodeType) {
|
|
384
375
|
if (node.nam == "media") {
|
|
385
|
-
if (Array.isArray(node
|
|
386
|
-
const slice = node.
|
|
376
|
+
if (Array.isArray(node[TOKENS])) {
|
|
377
|
+
const slice = node[TOKENS].slice();
|
|
387
378
|
minifyAtRuleMedia(slice);
|
|
388
|
-
if (slice.length !== node.
|
|
389
|
-
node.
|
|
390
|
-
node.
|
|
379
|
+
if (slice.length !== node[TOKENS].length) {
|
|
380
|
+
node[TOKENS].length = 0;
|
|
381
|
+
node[TOKENS].push(...slice);
|
|
391
382
|
node.val = slice.reduce((acc, curr, index, arr) => acc +
|
|
392
383
|
(curr.typ === EnumToken.CommentTokenType ||
|
|
393
384
|
(curr.typ === EnumToken.WhitespaceTokenType &&
|
|
@@ -403,21 +394,21 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
403
394
|
continue;
|
|
404
395
|
}
|
|
405
396
|
}
|
|
406
|
-
else if (node.nam === "import" && Array.isArray(node
|
|
397
|
+
else if (node.nam === "import" && Array.isArray(node[TOKENS])) {
|
|
407
398
|
let l = 0;
|
|
408
399
|
let token;
|
|
409
|
-
for (; l < node.
|
|
410
|
-
token = node
|
|
400
|
+
for (; l < node[TOKENS].length; l++) {
|
|
401
|
+
token = node[TOKENS][l];
|
|
411
402
|
if (token.typ === EnumToken.ParensTokenType ||
|
|
412
403
|
token.typ === EnumToken.MediaQueryConditionTokenType ||
|
|
413
404
|
(token.typ === EnumToken.IdenTokenType && "layer" !== token.val)) {
|
|
414
405
|
break;
|
|
415
406
|
}
|
|
416
407
|
}
|
|
417
|
-
if (l < node.
|
|
418
|
-
const slice = node
|
|
419
|
-
node.
|
|
420
|
-
node.val = trimArray(node
|
|
408
|
+
if (l < node[TOKENS].length) {
|
|
409
|
+
const slice = node[TOKENS]?.slice(l);
|
|
410
|
+
node[TOKENS].splice(l, slice.length, ...minifyAtRuleMedia(slice));
|
|
411
|
+
node.val = trimArray(node[TOKENS]).reduce((acc, curr, index, arr) => acc +
|
|
421
412
|
(curr.typ === EnumToken.CommentTokenType ||
|
|
422
413
|
(curr.typ === EnumToken.WhitespaceTokenType &&
|
|
423
414
|
arr[index + 1]?.typ === EnumToken.CommentTokenType &&
|
|
@@ -457,7 +448,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
457
448
|
if (previous?.typ == EnumToken.RuleNodeType) {
|
|
458
449
|
reduceRuleSelector(previous);
|
|
459
450
|
// @ts-ignore
|
|
460
|
-
match = matchSelectors(previous
|
|
451
|
+
match = matchSelectors(previous[RAW], node[RAW]);
|
|
461
452
|
if (match != null) {
|
|
462
453
|
wrapper = wrapNodes(previous, node, match, ast, reducer, i, nodeIndex);
|
|
463
454
|
nodeIndex = i - 1;
|
|
@@ -471,7 +462,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
471
462
|
break;
|
|
472
463
|
}
|
|
473
464
|
reduceRuleSelector(nextNode);
|
|
474
|
-
match = matchSelectors(wrapper
|
|
465
|
+
match = matchSelectors(wrapper[RAW], nextNode[RAW]);
|
|
475
466
|
if (match == null) {
|
|
476
467
|
break;
|
|
477
468
|
}
|
|
@@ -483,51 +474,50 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
483
474
|
continue;
|
|
484
475
|
}
|
|
485
476
|
// @ts-ignore
|
|
486
|
-
else if (node
|
|
487
|
-
// @ts-ignore
|
|
488
|
-
node.optimized.match &&
|
|
477
|
+
else if (node[OPTIMIZED] != null &&
|
|
489
478
|
// @ts-ignore
|
|
490
|
-
node.
|
|
479
|
+
node[OPTIMIZED].match &&
|
|
491
480
|
// @ts-ignore
|
|
492
|
-
|
|
481
|
+
node[OPTIMIZED].selector.length > 1) {
|
|
493
482
|
// @ts-ignore
|
|
494
|
-
|
|
495
|
-
...
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
483
|
+
wrapper = {
|
|
484
|
+
...node,
|
|
485
|
+
chi: [],
|
|
486
|
+
sel: node[OPTIMIZED].optimized[0],
|
|
487
|
+
[RAW]: [[node[OPTIMIZED].optimized[0]]],
|
|
488
|
+
};
|
|
499
489
|
// @ts-ignore
|
|
500
|
-
node.sel = node.
|
|
490
|
+
node.sel = node[OPTIMIZED].selector.reduce(reducer, []).join(",");
|
|
501
491
|
// @ts-ignore
|
|
502
|
-
node
|
|
492
|
+
node[RAW] = node[OPTIMIZED].selector.slice();
|
|
503
493
|
// @ts-ignore
|
|
504
494
|
wrapper.chi.push(node);
|
|
505
495
|
// @ts-ignore
|
|
506
496
|
ast.chi.splice(i, 1, wrapper);
|
|
507
497
|
node = wrapper;
|
|
508
498
|
}
|
|
509
|
-
else if (node
|
|
510
|
-
if (node.optimized.
|
|
511
|
-
const sel1 = node.optimized
|
|
499
|
+
else if (node[OPTIMIZED]?.reducible) {
|
|
500
|
+
if (node[OPTIMIZED].optimized.length === 1) {
|
|
501
|
+
const sel1 = node[OPTIMIZED].optimized[0] +
|
|
512
502
|
":is(" +
|
|
513
|
-
node.
|
|
503
|
+
node[OPTIMIZED].selector.reduce(reducer, []).join(",") +
|
|
514
504
|
")";
|
|
515
|
-
const sel2 = node.
|
|
505
|
+
const sel2 = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node[OPTIMIZED].optimized[0] + curr.join(""), "");
|
|
516
506
|
node.sel = sel1.length < sel2.length ? sel1 : sel2;
|
|
517
507
|
}
|
|
518
|
-
else if (node.optimized.
|
|
508
|
+
else if (node[OPTIMIZED].optimized.length === 0) {
|
|
519
509
|
const testIdent = /^[a-zA-Z]/;
|
|
520
|
-
node.sel = node.
|
|
510
|
+
node.sel = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
|
|
521
511
|
(nestingContent && testIdent.test(curr[0]) ? "& " : "") +
|
|
522
512
|
curr.join(""), "");
|
|
523
513
|
}
|
|
524
514
|
}
|
|
525
515
|
}
|
|
526
516
|
// @ts-ignore
|
|
527
|
-
else if (node
|
|
517
|
+
else if (node[OPTIMIZED]?.match) {
|
|
528
518
|
let wrap = true;
|
|
529
519
|
// @ts-ignore
|
|
530
|
-
const selector = node.
|
|
520
|
+
const selector = node[OPTIMIZED].selector.reduce((acc, curr) => {
|
|
531
521
|
if (curr[0] == "&" && curr.length > 1) {
|
|
532
522
|
if (curr[1] == " ") {
|
|
533
523
|
curr.splice(0, 2);
|
|
@@ -547,7 +537,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
547
537
|
wrap = selector.some((s) => s[0] != "&");
|
|
548
538
|
}
|
|
549
539
|
let rule = null;
|
|
550
|
-
const optimized = node.optimized.
|
|
540
|
+
const optimized = node[OPTIMIZED].optimized.slice();
|
|
551
541
|
if (optimized.length > 1) {
|
|
552
542
|
const check = optimized.at(-2);
|
|
553
543
|
if (!combinators.includes(check)) {
|
|
@@ -572,38 +562,38 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
572
562
|
rule = selector
|
|
573
563
|
.map((s) => {
|
|
574
564
|
if (s[0] == "&") {
|
|
575
|
-
s.splice(0, 1, ...node.optimized
|
|
565
|
+
s.splice(0, 1, ...node[OPTIMIZED].optimized);
|
|
576
566
|
}
|
|
577
567
|
return s.join("");
|
|
578
568
|
})
|
|
579
569
|
.join(",");
|
|
580
570
|
}
|
|
581
|
-
let sel = wrap ? node.optimized.
|
|
571
|
+
let sel = wrap ? node[OPTIMIZED].optimized.join("") + `:is(${rule})` : rule;
|
|
582
572
|
if (sel.length < node.sel.length) {
|
|
583
573
|
node.sel = sel;
|
|
584
574
|
}
|
|
585
575
|
}
|
|
586
|
-
else if (node
|
|
587
|
-
if (node.optimized.
|
|
588
|
-
const sel1 = node.optimized
|
|
576
|
+
else if (node[OPTIMIZED]?.reducible) {
|
|
577
|
+
if (node[OPTIMIZED].optimized.length === 1) {
|
|
578
|
+
const sel1 = node[OPTIMIZED].optimized[0] +
|
|
589
579
|
":is(" +
|
|
590
|
-
node.
|
|
580
|
+
node[OPTIMIZED].selector.reduce(reducer, []).join(",") +
|
|
591
581
|
")";
|
|
592
|
-
const sel2 = node.
|
|
582
|
+
const sel2 = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node[OPTIMIZED].optimized[0] + curr.join(""), "");
|
|
593
583
|
node.sel = sel1.length < sel2.length ? sel1 : sel2;
|
|
594
584
|
}
|
|
595
|
-
else if (node.optimized.
|
|
585
|
+
else if (node[OPTIMIZED].optimized.length === 0) {
|
|
596
586
|
const testIdent = /^[a-zA-Z]/;
|
|
597
|
-
node.sel = node.
|
|
587
|
+
node.sel = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
|
|
598
588
|
(nestingContent && testIdent.test(curr[0]) ? "& " : "") +
|
|
599
589
|
curr.join(""), "");
|
|
600
590
|
}
|
|
601
591
|
}
|
|
602
|
-
else if (node
|
|
603
|
-
const sel = node.optimized.
|
|
592
|
+
else if (node[OPTIMIZED]?.optimized.length > 0) {
|
|
593
|
+
const sel = node[OPTIMIZED].optimized.join("");
|
|
604
594
|
if (sel.length < node.sel.length) {
|
|
605
595
|
node.sel = sel;
|
|
606
|
-
node
|
|
596
|
+
node[RAW] = [node[OPTIMIZED].optimized.slice()];
|
|
607
597
|
}
|
|
608
598
|
}
|
|
609
599
|
doMinify(node, options, recursive, errors, nestingContent, context);
|
|
@@ -638,7 +628,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
638
628
|
}
|
|
639
629
|
else if (node.typ == previous?.typ &&
|
|
640
630
|
[EnumToken.KeyFramesRuleNodeType, EnumToken.RuleNodeType].includes(node.typ)) {
|
|
641
|
-
const intersect = diff(previous, node,
|
|
631
|
+
const intersect = diff(previous, node, options);
|
|
642
632
|
if (intersect != null) {
|
|
643
633
|
if (intersect.node1.chi.length == 0) {
|
|
644
634
|
ast.chi.splice(i--, 1);
|
|
@@ -647,14 +637,24 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
647
637
|
ast.chi.splice(i--, 1, intersect.node1);
|
|
648
638
|
}
|
|
649
639
|
if (intersect.node2.chi.length == 0) {
|
|
650
|
-
|
|
640
|
+
if (intersect.result != null) {
|
|
641
|
+
ast.chi.splice(nodeIndex, 1, intersect.result);
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
ast.chi.splice(nodeIndex, 1);
|
|
645
|
+
}
|
|
651
646
|
i--;
|
|
652
647
|
if (nodeIndex == i) {
|
|
653
648
|
nodeIndex = i;
|
|
654
649
|
}
|
|
655
650
|
}
|
|
656
651
|
else {
|
|
657
|
-
|
|
652
|
+
if (intersect.result != null) {
|
|
653
|
+
ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
ast.chi.splice(nodeIndex, 1, intersect.node2);
|
|
657
|
+
}
|
|
658
658
|
i = (nodeIndex ?? 0) + 1;
|
|
659
659
|
}
|
|
660
660
|
if (node != ast.chi[i]) {
|
|
@@ -1126,12 +1126,13 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
|
|
|
1126
1126
|
let pSel = match.selector1.reduce(reducer, []).join(",");
|
|
1127
1127
|
// @ts-ignore
|
|
1128
1128
|
let nSel = match.selector2.reduce(reducer, []).join(",");
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1129
|
+
const wrapper = {
|
|
1130
|
+
...previous,
|
|
1131
|
+
chi: [],
|
|
1132
|
+
// @ts-ignore
|
|
1133
|
+
sel: match.match.reduce(reducer, []).join(","),
|
|
1134
|
+
[RAW]: match.match.map((t) => t.slice()),
|
|
1135
|
+
};
|
|
1135
1136
|
if (pSel == "&" || pSel === "") {
|
|
1136
1137
|
wrapper.chi.push(...previous.chi);
|
|
1137
1138
|
if (nSel == "&" || nSel === "") {
|
|
@@ -1147,9 +1148,9 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
|
|
|
1147
1148
|
ast.chi.splice(i, 1, wrapper);
|
|
1148
1149
|
ast.chi.splice(nodeIndex, 1);
|
|
1149
1150
|
previous.sel = pSel;
|
|
1150
|
-
previous
|
|
1151
|
+
previous[RAW] = match.selector1;
|
|
1151
1152
|
node.sel = nSel;
|
|
1152
|
-
node
|
|
1153
|
+
node[RAW] = match.selector2;
|
|
1153
1154
|
reduceRuleSelector(wrapper);
|
|
1154
1155
|
return wrapper;
|
|
1155
1156
|
}
|
|
@@ -1162,7 +1163,7 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
|
|
|
1162
1163
|
*
|
|
1163
1164
|
* @private
|
|
1164
1165
|
*/
|
|
1165
|
-
function diff(n1, n2,
|
|
1166
|
+
function diff(n1, n2, options = {}) {
|
|
1166
1167
|
if (!("cache" in options)) {
|
|
1167
1168
|
options.cache = new WeakMap();
|
|
1168
1169
|
}
|
|
@@ -1177,8 +1178,8 @@ function diff(n1, n2, reducer, options = {}) {
|
|
|
1177
1178
|
}
|
|
1178
1179
|
let i = node1.chi.length;
|
|
1179
1180
|
let j = node2.chi.length;
|
|
1180
|
-
const raw1 = node1
|
|
1181
|
-
const raw2 = node2
|
|
1181
|
+
const raw1 = node1[RAW];
|
|
1182
|
+
const raw2 = node2[RAW];
|
|
1182
1183
|
if (raw1 != null && raw2 != null) {
|
|
1183
1184
|
const prefixes1 = new Set();
|
|
1184
1185
|
const prefixes2 = new Set();
|
|
@@ -1236,10 +1237,10 @@ function diff(n1, n2, reducer, options = {}) {
|
|
|
1236
1237
|
options.cache.set(node2, css2);
|
|
1237
1238
|
}
|
|
1238
1239
|
if (raw1 != null) {
|
|
1239
|
-
|
|
1240
|
+
node1[RAW] = raw1;
|
|
1240
1241
|
}
|
|
1241
1242
|
if (raw2 != null) {
|
|
1242
|
-
|
|
1243
|
+
node2[RAW] = raw2;
|
|
1243
1244
|
}
|
|
1244
1245
|
const intersect = [];
|
|
1245
1246
|
while (i--) {
|
|
@@ -1294,6 +1295,8 @@ function diff(n1, n2, reducer, options = {}) {
|
|
|
1294
1295
|
}
|
|
1295
1296
|
}
|
|
1296
1297
|
if (result != null) {
|
|
1298
|
+
result[TOKENS] = null;
|
|
1299
|
+
result[RAW] = null;
|
|
1297
1300
|
const optimized = optimizeSelector(splitRule(result.sel));
|
|
1298
1301
|
if (optimized?.match) {
|
|
1299
1302
|
const rule = optimized.selector.reduce((acc, curr) => {
|
|
@@ -1324,15 +1327,15 @@ function diff(n1, n2, reducer, options = {}) {
|
|
|
1324
1327
|
* @private
|
|
1325
1328
|
*/
|
|
1326
1329
|
function reduceRuleSelector(node) {
|
|
1327
|
-
if (node
|
|
1328
|
-
|
|
1330
|
+
if (node[RAW] == null) {
|
|
1331
|
+
node[RAW] = splitRule(node.sel);
|
|
1329
1332
|
}
|
|
1330
|
-
let optimized = optimizeSelector(node.
|
|
1333
|
+
let optimized = optimizeSelector(node[RAW].reduce((acc, curr) => {
|
|
1331
1334
|
acc.push(curr.slice());
|
|
1332
1335
|
return acc;
|
|
1333
1336
|
}, []));
|
|
1334
1337
|
if (optimized != null) {
|
|
1335
|
-
|
|
1338
|
+
node[OPTIMIZED] = optimized;
|
|
1336
1339
|
}
|
|
1337
1340
|
if (optimized != null && optimized.match && optimized.reducible && optimized.selector.length > 1) {
|
|
1338
1341
|
for (const selector of optimized.selector) {
|
|
@@ -1360,7 +1363,7 @@ function reduceRuleSelector(node) {
|
|
|
1360
1363
|
const sel = raw[0].join("");
|
|
1361
1364
|
if (sel.length < node.sel.length) {
|
|
1362
1365
|
node.sel = sel;
|
|
1363
|
-
|
|
1366
|
+
node[RAW] = raw;
|
|
1364
1367
|
}
|
|
1365
1368
|
}
|
|
1366
1369
|
}
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -568,8 +568,8 @@ var EnumToken;
|
|
|
568
568
|
EnumToken[EnumToken["RawNodeTokenType"] = 117] = "RawNodeTokenType";
|
|
569
569
|
/**
|
|
570
570
|
* media query boolean token type
|
|
571
|
-
*
|
|
572
|
-
*
|
|
571
|
+
* at-rule media not ()
|
|
572
|
+
* at-rule media only ()
|
|
573
573
|
*/
|
|
574
574
|
EnumToken[EnumToken["MediaQueryUnaryFeatureTokenType"] = 118] = "MediaQueryUnaryFeatureTokenType";
|
|
575
575
|
/**
|
|
@@ -656,6 +656,10 @@ var EnumToken;
|
|
|
656
656
|
* if-Else condition token
|
|
657
657
|
*/
|
|
658
658
|
EnumToken[EnumToken["IfElseConditionTokenType"] = 139] = "IfElseConditionTokenType";
|
|
659
|
+
/**
|
|
660
|
+
* wrapped values token type like {Arial, sans-serif}
|
|
661
|
+
*/
|
|
662
|
+
EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
|
|
659
663
|
/* aliases */
|
|
660
664
|
/**
|
|
661
665
|
* alias for time token type
|
|
@@ -875,6 +879,10 @@ var ColorType;
|
|
|
875
879
|
* alpha() color function
|
|
876
880
|
*/
|
|
877
881
|
ColorType[ColorType["ALPHA"] = 25] = "ALPHA";
|
|
882
|
+
/**
|
|
883
|
+
* color using display-p3-linear
|
|
884
|
+
*/
|
|
885
|
+
ColorType[ColorType["DISPLAY_P3_LINEAR"] = 26] = "DISPLAY_P3_LINEAR";
|
|
878
886
|
/**
|
|
879
887
|
* alias for rgba
|
|
880
888
|
*/
|
package/dist/lib/ast/walk.js
CHANGED
|
@@ -144,7 +144,7 @@ function* walk(node, filter, reverse) {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
if ("chi" in node && (!isNumeric || (option & WalkerOptionEnum.IgnoreChildren) === 0)) {
|
|
147
|
-
parents.splice(i, 0, ...node.chi[reverse ? "
|
|
147
|
+
parents.splice(i, 0, ...node.chi[reverse ? "toReversed" : "slice"]());
|
|
148
148
|
for (const child of node.chi) {
|
|
149
149
|
map.set(child, node);
|
|
150
150
|
}
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -23,7 +23,7 @@ function dirname(path) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
parts.pop();
|
|
26
|
-
return parts.
|
|
26
|
+
return parts.join("/");
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* split path
|
|
@@ -34,9 +34,9 @@ function splitPath(result) {
|
|
|
34
34
|
if (result.length == 0) {
|
|
35
35
|
return { parts: [], i: 0 };
|
|
36
36
|
}
|
|
37
|
-
if (result === "/") {
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
// if (result === "/") {
|
|
38
|
+
// return { parts: ["/"], i: 0 };
|
|
39
|
+
// }
|
|
40
40
|
const parts = [""];
|
|
41
41
|
let i = 0;
|
|
42
42
|
for (; i < result.length; i++) {
|
|
@@ -44,25 +44,27 @@ function splitPath(result) {
|
|
|
44
44
|
if (chr == "/") {
|
|
45
45
|
parts.push("");
|
|
46
46
|
}
|
|
47
|
-
else if (chr == "?" || chr == "#") {
|
|
48
|
-
|
|
49
|
-
}
|
|
47
|
+
// else if (chr == "?" || chr == "#") {
|
|
48
|
+
// break;
|
|
49
|
+
// }
|
|
50
50
|
else {
|
|
51
51
|
parts[parts.length - 1] += chr;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
let k = -1;
|
|
55
|
-
while (++k < parts.length) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
54
|
+
// let k: number = -1;
|
|
55
|
+
// while (++k < parts.length) {
|
|
56
|
+
// if (parts[k] == ".") {
|
|
57
|
+
// parts.splice(k--, 1);
|
|
58
|
+
// } else if (parts[k] == "..") {
|
|
59
|
+
// parts.splice(k - 1, 2);
|
|
60
|
+
// k -= 2;
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
64
63
|
return { parts, i };
|
|
65
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Nomalize path
|
|
67
|
+
*/
|
|
66
68
|
const normalize = memoize(function (path) {
|
|
67
69
|
let parts = [];
|
|
68
70
|
let i = 0;
|
|
@@ -88,10 +90,10 @@ const normalize = memoize(function (path) {
|
|
|
88
90
|
}
|
|
89
91
|
let k = -1;
|
|
90
92
|
while (++k < parts.length) {
|
|
91
|
-
if (parts[k] == ".") {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
93
|
+
// if (parts[k] == ".") {
|
|
94
|
+
// parts.splice(k--, 1);
|
|
95
|
+
// } else
|
|
96
|
+
if (parts[k] == "..") {
|
|
95
97
|
parts.splice(k - 1, 2);
|
|
96
98
|
k -= 2;
|
|
97
99
|
}
|
|
@@ -120,12 +122,12 @@ const diff = memoize(function (path1, path2) {
|
|
|
120
122
|
* @private
|
|
121
123
|
*/
|
|
122
124
|
const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
123
|
-
if (matchUrl.test(url)) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
125
|
+
// if (matchUrl.test(url)) {
|
|
126
|
+
// return {
|
|
127
|
+
// absolute: url,
|
|
128
|
+
// relative: url,
|
|
129
|
+
// };
|
|
130
|
+
// }
|
|
129
131
|
cwd ??= "";
|
|
130
132
|
currentDirectory ??= "";
|
|
131
133
|
url = normalize(url);
|
|
@@ -138,7 +140,7 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
|
138
140
|
};
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
|
-
if (currentDirectory === "" && cwd !== "") {
|
|
143
|
+
if ((currentDirectory === "" || currentDirectory === ".") && cwd !== "") {
|
|
142
144
|
cwd = normalize(cwd);
|
|
143
145
|
if (url.startsWith(cwd == "/" ? cwd : cwd + "/")) {
|
|
144
146
|
const absolute = url;
|
|
@@ -149,24 +151,24 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
|
149
151
|
};
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
|
-
if (matchUrl.test(currentDirectory)) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
let result = "";
|
|
160
|
-
if (url.charAt(0) == "/") {
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
else if (currentDirectory.charAt(0) == "/") {
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
const absolute = normalize(result);
|
|
154
|
+
// if (matchUrl.test(currentDirectory)) {
|
|
155
|
+
// const path: string = new URL(url, currentDirectory).href;
|
|
156
|
+
// return {
|
|
157
|
+
// absolute: path,
|
|
158
|
+
// relative: path,
|
|
159
|
+
// };
|
|
160
|
+
// }
|
|
161
|
+
// let result: string = "";
|
|
162
|
+
// if (url.charAt(0) == "/") {
|
|
163
|
+
// result = url;
|
|
164
|
+
// }
|
|
165
|
+
// else if (currentDirectory.charAt(0) == "/") {
|
|
166
|
+
// result = dirname(currentDirectory) + "/" + url;
|
|
167
|
+
// }
|
|
168
|
+
// const absolute = url; // normalize(result);
|
|
167
169
|
return {
|
|
168
|
-
absolute,
|
|
169
|
-
relative:
|
|
170
|
+
absolute: url,
|
|
171
|
+
relative: url === "" ? "" : diff(url, cwd ?? currentDirectory),
|
|
170
172
|
};
|
|
171
173
|
});
|
|
172
174
|
|