@tbela99/css-parser 1.6.0 → 1.6.1
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 +26 -0
- package/README.md +3 -3
- package/dist/index-umd-web.js +425 -230
- package/dist/index.cjs +425 -230
- package/dist/index.d.ts +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/math/expression.js +19 -4
- package/dist/lib/ast/minify.js +84 -10
- package/dist/lib/ast/transform/compute.js +28 -55
- package/dist/lib/ast/transform/minify.js +1 -1
- package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
- package/dist/lib/{validation/config.json.js → data/validation.json.js} +11 -8
- package/dist/lib/parser/parse.js +6 -5
- package/dist/lib/parser/tokenize.js +40 -41
- package/dist/lib/parser/utils/config.js +1 -1
- package/dist/lib/parser/utils/declaration.js +11 -3
- package/dist/lib/parser/utils/selector.js +98 -88
- package/dist/lib/renderer/render.js +2 -2
- package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
- package/dist/lib/syntax/color/cmyk.js +4 -3
- package/dist/lib/syntax/color/srgb.js +4 -3
- package/dist/lib/syntax/constants.js +1 -1
- package/dist/lib/validation/config.js +1 -1
- package/dist/lib/validation/parser/parse.js +7 -3
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -6247,7 +6247,7 @@ declare function expand(ast: AstStyleSheet | AstAtRule | AstRule): AstNode$1;
|
|
|
6247
6247
|
* console.log(declarations);
|
|
6248
6248
|
* ```
|
|
6249
6249
|
*/
|
|
6250
|
-
declare function parseDeclarations(declaration: string):
|
|
6250
|
+
declare function parseDeclarations(declaration: string): Array<AstDeclaration | AstComment>;
|
|
6251
6251
|
/**
|
|
6252
6252
|
* Parse css string and return an array of tokens
|
|
6253
6253
|
* @param src
|
|
@@ -53,7 +53,7 @@ class TransformCssFeature {
|
|
|
53
53
|
minified: null,
|
|
54
54
|
};
|
|
55
55
|
if (matrix == null || cumulative == null || minified == null) {
|
|
56
|
-
node.val = children;
|
|
56
|
+
node.val = children.map((t) => t.typ == EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t);
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
let r = [filterValues(children)];
|
|
@@ -293,7 +293,9 @@ function evaluateFunc(token) {
|
|
|
293
293
|
}
|
|
294
294
|
const value = evaluate(values);
|
|
295
295
|
// @ts-ignore
|
|
296
|
-
let val = value[0].typ == EnumToken.NumberTokenType ||
|
|
296
|
+
let val = value[0].typ == EnumToken.NumberTokenType ||
|
|
297
|
+
value[0].typ == EnumToken.AngleTokenType ||
|
|
298
|
+
value[0].typ == EnumToken.PercentageTokenType
|
|
297
299
|
? +value[0].val
|
|
298
300
|
: // @ts-expect-error
|
|
299
301
|
value[0].l.val / value[0].r.val;
|
|
@@ -308,7 +310,7 @@ function evaluateFunc(token) {
|
|
|
308
310
|
[LOCEND]: value[0][LOCEND],
|
|
309
311
|
}
|
|
310
312
|
: {
|
|
311
|
-
typ: EnumToken.NumberTokenType,
|
|
313
|
+
typ: token.val == "sign" ? EnumToken.NumberTokenType : value[0].typ,
|
|
312
314
|
val: Math[token.val](val),
|
|
313
315
|
[LOCSRCID]: value[0][LOCSRCID],
|
|
314
316
|
[LOCSTA]: value[0][LOCSTA],
|
|
@@ -338,10 +340,23 @@ function evaluateFunc(token) {
|
|
|
338
340
|
},
|
|
339
341
|
];
|
|
340
342
|
}
|
|
343
|
+
case "mod":
|
|
341
344
|
case "atan2":
|
|
342
345
|
case "pow":
|
|
343
|
-
case "rem":
|
|
344
|
-
|
|
346
|
+
case "rem": {
|
|
347
|
+
{
|
|
348
|
+
let typ = token.chi[0]?.typ;
|
|
349
|
+
for (let i = 1; i < token.chi.length; i++) {
|
|
350
|
+
if (token.chi[i].typ == EnumToken.WhitespaceTokenType ||
|
|
351
|
+
token.chi[i].typ == EnumToken.CommaTokenType ||
|
|
352
|
+
token.chi[i].typ == EnumToken.CommentTokenType) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (token.chi[i].typ != typ) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
345
360
|
const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
346
361
|
if (token.val == "atan2") {
|
|
347
362
|
for (let i = 0; i < chi.length; i++) {
|
package/dist/lib/ast/minify.js
CHANGED
|
@@ -307,7 +307,15 @@ function reduce(acc, curr) {
|
|
|
307
307
|
// trim :is()
|
|
308
308
|
if (curr[0] == "&") {
|
|
309
309
|
if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) {
|
|
310
|
-
curr.
|
|
310
|
+
const all = new Array(Math.max(curr.length - 2, 0));
|
|
311
|
+
let write = 0;
|
|
312
|
+
for (let read = 2; read < curr.length; read++) {
|
|
313
|
+
all[write++] = curr[read];
|
|
314
|
+
}
|
|
315
|
+
curr.length = 0;
|
|
316
|
+
for (let index = 0; index < write; index++) {
|
|
317
|
+
curr[index] = all[index];
|
|
318
|
+
}
|
|
311
319
|
}
|
|
312
320
|
}
|
|
313
321
|
acc.push(curr.join(""));
|
|
@@ -585,19 +593,40 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
585
593
|
if (optimized.length > 1) {
|
|
586
594
|
const check = optimized.at(-2);
|
|
587
595
|
if (!combinators.includes(check)) {
|
|
588
|
-
|
|
596
|
+
const last = optimized[optimized.length - 1];
|
|
597
|
+
const all = new Array(Math.max(optimized.length - 1, 0));
|
|
598
|
+
let write = 0;
|
|
599
|
+
for (let read = 0; read < optimized.length - 1; read++) {
|
|
600
|
+
all[write++] = optimized[read];
|
|
601
|
+
}
|
|
602
|
+
optimized.length = 0;
|
|
603
|
+
for (let index = 0; index < write; index++) {
|
|
604
|
+
optimized[index] = all[index];
|
|
605
|
+
}
|
|
589
606
|
wrap = false;
|
|
590
607
|
rule =
|
|
591
608
|
optimized.join("") +
|
|
592
609
|
`:is(${selector
|
|
593
610
|
.map((s) => {
|
|
611
|
+
const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1);
|
|
612
|
+
let write = 0;
|
|
594
613
|
if (s[0] == "&") {
|
|
595
|
-
|
|
614
|
+
next[write++] = last;
|
|
615
|
+
for (let read = 1; read < s.length; read++) {
|
|
616
|
+
next[write++] = s[read];
|
|
617
|
+
}
|
|
596
618
|
}
|
|
597
619
|
else {
|
|
598
|
-
|
|
620
|
+
next[write++] = last;
|
|
621
|
+
for (let read = 0; read < s.length; read++) {
|
|
622
|
+
next[write++] = s[read];
|
|
623
|
+
}
|
|
599
624
|
}
|
|
600
|
-
|
|
625
|
+
const rebuilt = new Array(write);
|
|
626
|
+
for (let index = 0; index < write; index++) {
|
|
627
|
+
rebuilt[index] = next[index];
|
|
628
|
+
}
|
|
629
|
+
return rebuilt.join("");
|
|
601
630
|
})
|
|
602
631
|
.join(",")})`;
|
|
603
632
|
}
|
|
@@ -606,7 +635,20 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
606
635
|
rule = selector
|
|
607
636
|
.map((s) => {
|
|
608
637
|
if (s[0] == "&") {
|
|
609
|
-
|
|
638
|
+
const replacement = node[OPTIMIZED].optimized;
|
|
639
|
+
const all = new Array(Math.max(s.length - 1 + replacement.length, 0));
|
|
640
|
+
let write = 0;
|
|
641
|
+
for (let read = 0; read < replacement.length; read++) {
|
|
642
|
+
all[write++] = replacement[read];
|
|
643
|
+
}
|
|
644
|
+
for (let read = 1; read < s.length; read++) {
|
|
645
|
+
all[write++] = s[read];
|
|
646
|
+
}
|
|
647
|
+
const rebuilt = new Array(write);
|
|
648
|
+
for (let index = 0; index < write; index++) {
|
|
649
|
+
rebuilt[index] = all[index];
|
|
650
|
+
}
|
|
651
|
+
return rebuilt.join("");
|
|
610
652
|
}
|
|
611
653
|
return s.join("");
|
|
612
654
|
})
|
|
@@ -838,18 +880,42 @@ function optimizeSelector(selector) {
|
|
|
838
880
|
while (optimized.length > 0) {
|
|
839
881
|
const last = optimized.at(-1);
|
|
840
882
|
if (last == " " || combinators.includes(last)) {
|
|
841
|
-
optimized.
|
|
883
|
+
const all = new Array(Math.max(optimized.length - 1, 0));
|
|
884
|
+
let write = 0;
|
|
885
|
+
for (let read = 0; read < optimized.length - 1; read++) {
|
|
886
|
+
all[write++] = optimized[read];
|
|
887
|
+
}
|
|
888
|
+
optimized.length = 0;
|
|
889
|
+
for (let index = 0; index < write; index++) {
|
|
890
|
+
optimized[index] = all[index];
|
|
891
|
+
}
|
|
842
892
|
continue;
|
|
843
893
|
}
|
|
844
894
|
break;
|
|
845
895
|
}
|
|
846
896
|
for (let i1 = 0; i1 < selector.length; i1++) {
|
|
847
|
-
selector[i1].
|
|
897
|
+
const all = new Array(Math.max(selector[i1].length - optimized.length, 0));
|
|
898
|
+
let write = 0;
|
|
899
|
+
for (let read = optimized.length; read < selector[i1].length; read++) {
|
|
900
|
+
all[write++] = selector[i1][read];
|
|
901
|
+
}
|
|
902
|
+
selector[i1].length = 0;
|
|
903
|
+
for (let index = 0; index < write; index++) {
|
|
904
|
+
selector[i1][index] = all[index];
|
|
905
|
+
}
|
|
848
906
|
}
|
|
849
907
|
let reducible = optimized.length == 1;
|
|
850
908
|
if (optimized[0] == "&") {
|
|
851
909
|
if (optimized[1] == " ") {
|
|
852
|
-
optimized.
|
|
910
|
+
const all = new Array(Math.max(optimized.length - 2, 0));
|
|
911
|
+
let write = 0;
|
|
912
|
+
for (let read = 2; read < optimized.length; read++) {
|
|
913
|
+
all[write++] = optimized[read];
|
|
914
|
+
}
|
|
915
|
+
optimized.length = 0;
|
|
916
|
+
for (let index = 0; index < write; index++) {
|
|
917
|
+
optimized[index] = all[index];
|
|
918
|
+
}
|
|
853
919
|
}
|
|
854
920
|
}
|
|
855
921
|
if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) {
|
|
@@ -1436,7 +1502,15 @@ function reduceRuleSelector(node) {
|
|
|
1436
1502
|
if (selector.length > 1 &&
|
|
1437
1503
|
selector[0] == "&" &&
|
|
1438
1504
|
(combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) {
|
|
1439
|
-
selector.
|
|
1505
|
+
const all = new Array(Math.max(selector.length - 1, 0));
|
|
1506
|
+
let write = 0;
|
|
1507
|
+
for (let read = 1; read < selector.length; read++) {
|
|
1508
|
+
all[write++] = selector[read];
|
|
1509
|
+
}
|
|
1510
|
+
selector.length = 0;
|
|
1511
|
+
for (let index = 0; index < write; index++) {
|
|
1512
|
+
selector[index] = all[index];
|
|
1513
|
+
}
|
|
1440
1514
|
}
|
|
1441
1515
|
}
|
|
1442
1516
|
const unique = new Set();
|
|
@@ -18,9 +18,36 @@ function compute(transformLists) {
|
|
|
18
18
|
let matrix = identity();
|
|
19
19
|
let mat;
|
|
20
20
|
let transforms;
|
|
21
|
+
let shouldComputeMatrix = true;
|
|
21
22
|
const cumulative = [];
|
|
23
|
+
// all transform function arguments must be 0 or scale(1)
|
|
24
|
+
for (const transform of transformLists) {
|
|
25
|
+
switch (transform.val) {
|
|
26
|
+
case "rotate":
|
|
27
|
+
case "rotateX":
|
|
28
|
+
case "rotateY":
|
|
29
|
+
case "rotateZ":
|
|
30
|
+
case "rotate3d":
|
|
31
|
+
for (const child of transform.chi) {
|
|
32
|
+
if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if ((child.typ != EnumToken.AngleTokenType &&
|
|
36
|
+
child.typ != EnumToken.NumberTokenType &&
|
|
37
|
+
child.typ != EnumToken.PercentageTokenType) ||
|
|
38
|
+
// angle >= 360deg, do not transform
|
|
39
|
+
Math.abs(getAngle(child)) >= 1) {
|
|
40
|
+
shouldComputeMatrix = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (!shouldComputeMatrix) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
22
49
|
for (const transformList of splitTransformList(transformLists)) {
|
|
23
|
-
mat = computeMatrix(transformList, identity());
|
|
50
|
+
mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null;
|
|
24
51
|
if (mat == null) {
|
|
25
52
|
return null;
|
|
26
53
|
}
|
|
@@ -49,60 +76,6 @@ function compute(transformLists) {
|
|
|
49
76
|
cumulative,
|
|
50
77
|
minified: minify(matrix) ?? [serialized],
|
|
51
78
|
};
|
|
52
|
-
// valid identity matrix
|
|
53
|
-
if ((result.minified.length == 1 &&
|
|
54
|
-
result.minified[0].typ == EnumToken.IdenTokenType &&
|
|
55
|
-
result.minified[0].val == "none") ||
|
|
56
|
-
(result.cumulative.length == 1 &&
|
|
57
|
-
result.cumulative[0].typ == EnumToken.IdenTokenType &&
|
|
58
|
-
result.cumulative[0].val == "none") ||
|
|
59
|
-
(result.matrix?.typ == EnumToken.IdenTokenType && result.matrix.val == "none")) {
|
|
60
|
-
// all transform function arguments must be 0 or scale(1)
|
|
61
|
-
for (const transform of transformLists) {
|
|
62
|
-
switch (transform.val) {
|
|
63
|
-
case "translate":
|
|
64
|
-
case "translateX":
|
|
65
|
-
case "translateY":
|
|
66
|
-
case "translateZ":
|
|
67
|
-
case "translate3d":
|
|
68
|
-
case "rotate":
|
|
69
|
-
case "rotateX":
|
|
70
|
-
case "rotateY":
|
|
71
|
-
case "rotateZ":
|
|
72
|
-
case "rotate3d":
|
|
73
|
-
case "skew":
|
|
74
|
-
case "skewX":
|
|
75
|
-
case "skewY":
|
|
76
|
-
for (const child of transform.chi) {
|
|
77
|
-
if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if ((child.typ != EnumToken.AngleTokenType &&
|
|
81
|
-
child.typ != EnumToken.NumberTokenType &&
|
|
82
|
-
child.typ != EnumToken.PercentageTokenType) ||
|
|
83
|
-
getNumber(child) != 0) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
case "scale":
|
|
89
|
-
case "scaleX":
|
|
90
|
-
case "scaleY":
|
|
91
|
-
case "scaleZ":
|
|
92
|
-
case "scale3d":
|
|
93
|
-
for (const child of transform.chi) {
|
|
94
|
-
if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if ((child.typ != EnumToken.NumberTokenType && child.typ != EnumToken.PercentageTokenType) ||
|
|
98
|
-
getNumber(child) != 1) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
79
|
return result;
|
|
107
80
|
}
|
|
108
81
|
function computeMatrix(transformList, matrixVar) {
|
|
@@ -266,7 +266,7 @@ function eqMatrix(a, b) {
|
|
|
266
266
|
return true;
|
|
267
267
|
}
|
|
268
268
|
function minifyTransformFunctions(transform) {
|
|
269
|
-
const name = transform.val
|
|
269
|
+
const name = transform.val;
|
|
270
270
|
if ("skewX" == name) {
|
|
271
271
|
transform.val = "skew";
|
|
272
272
|
return transform;
|
|
@@ -108,6 +108,65 @@ var properties = {
|
|
|
108
108
|
"padding-left": {
|
|
109
109
|
shorthand: "padding"
|
|
110
110
|
},
|
|
111
|
+
"scroll-margin": {
|
|
112
|
+
shorthand: "scroll-margin",
|
|
113
|
+
properties: [
|
|
114
|
+
"scroll-margin-top",
|
|
115
|
+
"scroll-margin-right",
|
|
116
|
+
"scroll-margin-bottom",
|
|
117
|
+
"scroll-margin-left"
|
|
118
|
+
],
|
|
119
|
+
types: [
|
|
120
|
+
"Length",
|
|
121
|
+
"Perc"
|
|
122
|
+
],
|
|
123
|
+
"default": [
|
|
124
|
+
"0"
|
|
125
|
+
],
|
|
126
|
+
keywords: [
|
|
127
|
+
"auto"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"scroll-margin-top": {
|
|
131
|
+
shorthand: "scroll-margin"
|
|
132
|
+
},
|
|
133
|
+
"scroll-margin-right": {
|
|
134
|
+
shorthand: "scroll-margin"
|
|
135
|
+
},
|
|
136
|
+
"scroll-margin-bottom": {
|
|
137
|
+
shorthand: "scroll-margin"
|
|
138
|
+
},
|
|
139
|
+
"scroll-margin-left": {
|
|
140
|
+
shorthand: "scroll-margin"
|
|
141
|
+
},
|
|
142
|
+
"scroll-padding": {
|
|
143
|
+
shorthand: "scroll-padding",
|
|
144
|
+
properties: [
|
|
145
|
+
"scroll-padding-top",
|
|
146
|
+
"scroll-padding-right",
|
|
147
|
+
"scroll-padding-bottom",
|
|
148
|
+
"scroll-padding-left"
|
|
149
|
+
],
|
|
150
|
+
types: [
|
|
151
|
+
"Length",
|
|
152
|
+
"Perc"
|
|
153
|
+
],
|
|
154
|
+
keywords: [
|
|
155
|
+
"auto"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
"scroll-padding-top": {
|
|
159
|
+
shorthand: "scroll-padding"
|
|
160
|
+
},
|
|
161
|
+
"scroll-padding-right": {
|
|
162
|
+
shorthand: "scroll-padding"
|
|
163
|
+
},
|
|
164
|
+
"scroll-padding-bottom": {
|
|
165
|
+
shorthand: "scroll-padding"
|
|
166
|
+
},
|
|
167
|
+
"scroll-padding-left": {
|
|
168
|
+
shorthand: "scroll-padding"
|
|
169
|
+
},
|
|
111
170
|
"border-radius": {
|
|
112
171
|
shorthand: "border-radius",
|
|
113
172
|
properties: [
|
|
@@ -329,6 +388,53 @@ var map = {
|
|
|
329
388
|
"flex-wrap": {
|
|
330
389
|
shorthand: "flex-flow"
|
|
331
390
|
},
|
|
391
|
+
"scroll-timeline": {
|
|
392
|
+
shorthand: "scroll-timeline",
|
|
393
|
+
pattern: "scroll-timeline-name scroll-timeline-axis",
|
|
394
|
+
keywords: [
|
|
395
|
+
"none",
|
|
396
|
+
"block",
|
|
397
|
+
"inline",
|
|
398
|
+
"x",
|
|
399
|
+
"y"
|
|
400
|
+
],
|
|
401
|
+
"default": [
|
|
402
|
+
"none",
|
|
403
|
+
"block"
|
|
404
|
+
],
|
|
405
|
+
properties: {
|
|
406
|
+
"scroll-timeline-name": {
|
|
407
|
+
keywords: [
|
|
408
|
+
"none"
|
|
409
|
+
],
|
|
410
|
+
"default": [
|
|
411
|
+
"none"
|
|
412
|
+
],
|
|
413
|
+
types: [
|
|
414
|
+
"DashedIden"
|
|
415
|
+
]
|
|
416
|
+
},
|
|
417
|
+
"scroll-timeline-axis": {
|
|
418
|
+
keywords: [
|
|
419
|
+
"block",
|
|
420
|
+
"inline",
|
|
421
|
+
"x",
|
|
422
|
+
"y"
|
|
423
|
+
],
|
|
424
|
+
"default": [
|
|
425
|
+
"block"
|
|
426
|
+
],
|
|
427
|
+
types: [
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
"scroll-timeline-name": {
|
|
433
|
+
shorthand: "scroll-timeline"
|
|
434
|
+
},
|
|
435
|
+
"scroll-timeline-axis": {
|
|
436
|
+
shorthand: "scroll-timeline"
|
|
437
|
+
},
|
|
332
438
|
container: {
|
|
333
439
|
shorthand: "container",
|
|
334
440
|
pattern: "container-name container-type",
|
|
@@ -1584,7 +1584,7 @@ var declarations = {
|
|
|
1584
1584
|
syntax: "none | nearest"
|
|
1585
1585
|
},
|
|
1586
1586
|
"scroll-margin": {
|
|
1587
|
-
syntax: "<length>{1,4}"
|
|
1587
|
+
syntax: " <length>{1,4}"
|
|
1588
1588
|
},
|
|
1589
1589
|
"scroll-margin-block": {
|
|
1590
1590
|
syntax: "<length>{1,2}"
|
|
@@ -1596,7 +1596,7 @@ var declarations = {
|
|
|
1596
1596
|
syntax: "<length>"
|
|
1597
1597
|
},
|
|
1598
1598
|
"scroll-margin-bottom": {
|
|
1599
|
-
syntax: "<length>"
|
|
1599
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
1600
1600
|
},
|
|
1601
1601
|
"scroll-margin-inline": {
|
|
1602
1602
|
syntax: "<length>{1,2}"
|
|
@@ -1608,13 +1608,13 @@ var declarations = {
|
|
|
1608
1608
|
syntax: "<length>"
|
|
1609
1609
|
},
|
|
1610
1610
|
"scroll-margin-left": {
|
|
1611
|
-
syntax: "<length>"
|
|
1611
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
1612
1612
|
},
|
|
1613
1613
|
"scroll-margin-right": {
|
|
1614
|
-
syntax: "<length>"
|
|
1614
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
1615
1615
|
},
|
|
1616
1616
|
"scroll-margin-top": {
|
|
1617
|
-
syntax: "<length>"
|
|
1617
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
1618
1618
|
},
|
|
1619
1619
|
"scroll-marker-group": {
|
|
1620
1620
|
syntax: "none | before | after"
|
|
@@ -1683,13 +1683,13 @@ var declarations = {
|
|
|
1683
1683
|
syntax: "none | auto"
|
|
1684
1684
|
},
|
|
1685
1685
|
"scroll-timeline": {
|
|
1686
|
-
syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
|
|
1686
|
+
syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
|
|
1687
1687
|
},
|
|
1688
1688
|
"scroll-timeline-axis": {
|
|
1689
|
-
syntax: "[ block | inline | x | y ]#"
|
|
1689
|
+
syntax: " [ block | inline | x | y ]#"
|
|
1690
1690
|
},
|
|
1691
1691
|
"scroll-timeline-name": {
|
|
1692
|
-
syntax: "[ none | <dashed-ident> ]#"
|
|
1692
|
+
syntax: " [ none | <dashed-ident> ]#"
|
|
1693
1693
|
},
|
|
1694
1694
|
"scrollbar-color": {
|
|
1695
1695
|
syntax: "auto | <color>{2}"
|
|
@@ -2182,6 +2182,9 @@ var functions = {
|
|
|
2182
2182
|
acos: {
|
|
2183
2183
|
syntax: "acos( <calc-sum> )"
|
|
2184
2184
|
},
|
|
2185
|
+
alpha: {
|
|
2186
|
+
syntax: "alpha( from <color> / [ <alpha-value> | none ] )"
|
|
2187
|
+
},
|
|
2185
2188
|
anchor: {
|
|
2186
2189
|
syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
|
|
2187
2190
|
},
|
package/dist/lib/parser/parse.js
CHANGED
|
@@ -3393,17 +3393,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3393
3393
|
* console.log(declarations);
|
|
3394
3394
|
* ```
|
|
3395
3395
|
*/
|
|
3396
|
-
|
|
3396
|
+
function parseDeclarations(declaration) {
|
|
3397
3397
|
const stream = `.x{${declaration}}`;
|
|
3398
|
-
|
|
3398
|
+
const result = doParseSync(new Tokenizer({
|
|
3399
3399
|
stream,
|
|
3400
3400
|
offset: 0,
|
|
3401
3401
|
position: 0,
|
|
3402
3402
|
source: new SourceFile(stream, [], ""),
|
|
3403
3403
|
currentPosition: 0,
|
|
3404
|
-
}), { setParent: false, minify: false, validation: false })
|
|
3405
|
-
|
|
3406
|
-
|
|
3404
|
+
}), { setParent: false, minify: false, validation: false });
|
|
3405
|
+
// .then((result) => {
|
|
3406
|
+
return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType);
|
|
3407
|
+
// });
|
|
3407
3408
|
}
|
|
3408
3409
|
/**
|
|
3409
3410
|
* Parse css string and return an array of tokens
|
|
@@ -324,7 +324,7 @@ class Tokenizer {
|
|
|
324
324
|
* @param parseInfo
|
|
325
325
|
* @returns
|
|
326
326
|
*/
|
|
327
|
-
|
|
327
|
+
consumeStringAsURLToken(parseInfo) {
|
|
328
328
|
const quote = this.advance(parseInfo).charCodeAt(0);
|
|
329
329
|
let charCode;
|
|
330
330
|
let decodeSegments = false;
|
|
@@ -766,7 +766,7 @@ class Tokenizer {
|
|
|
766
766
|
}
|
|
767
767
|
return 0;
|
|
768
768
|
}
|
|
769
|
-
|
|
769
|
+
consumeURLToken(parseInfo, endPosition) {
|
|
770
770
|
let charCode;
|
|
771
771
|
// consume an <url>
|
|
772
772
|
while (isWhiteSpace(this.peekCharCode(parseInfo))) {
|
|
@@ -774,7 +774,7 @@ class Tokenizer {
|
|
|
774
774
|
}
|
|
775
775
|
charCode = this.peekCharCode(parseInfo);
|
|
776
776
|
if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
|
|
777
|
-
return this.
|
|
777
|
+
return this.consumeStringAsURLToken(parseInfo);
|
|
778
778
|
}
|
|
779
779
|
do {
|
|
780
780
|
this.advance(parseInfo);
|
|
@@ -1038,27 +1038,24 @@ class Tokenizer {
|
|
|
1038
1038
|
* @param end
|
|
1039
1039
|
* @returns
|
|
1040
1040
|
*/
|
|
1041
|
-
isIdentToken(parseInfo, start, end) {
|
|
1041
|
+
isIdentToken(parseInfo /* , start?: number, end?: number */) {
|
|
1042
1042
|
let j = parseInfo.currentPosition - parseInfo.offset;
|
|
1043
1043
|
let i = parseInfo.position - parseInfo.offset;
|
|
1044
|
-
if (start != null) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1044
|
+
// if (start != null) {
|
|
1045
|
+
// if (end == null) {
|
|
1046
|
+
// if (start < 0) {
|
|
1047
|
+
// j += start;
|
|
1048
|
+
// } else {
|
|
1049
|
+
// i += start;
|
|
1050
|
+
// }
|
|
1051
|
+
// } else {
|
|
1052
|
+
// if (end < 0) {
|
|
1053
|
+
// j += end;
|
|
1054
|
+
// } else {
|
|
1055
|
+
// j = parseInfo.position + end;
|
|
1056
|
+
// }
|
|
1057
|
+
// }
|
|
1058
|
+
// }
|
|
1062
1059
|
j--;
|
|
1063
1060
|
let codepoint = parseInfo.stream.charCodeAt(i);
|
|
1064
1061
|
// -
|
|
@@ -1101,18 +1098,18 @@ class Tokenizer {
|
|
|
1101
1098
|
* @param parseInfo
|
|
1102
1099
|
* @returns
|
|
1103
1100
|
*/
|
|
1104
|
-
isPseudo(parseInfo) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
}
|
|
1101
|
+
// isPseudo(parseInfo: ParseInfo): boolean {
|
|
1102
|
+
// let position: number = parseInfo.currentPosition - parseInfo.offset;
|
|
1103
|
+
// let endPosition: number = parseInfo.currentPosition - parseInfo.offset;
|
|
1104
|
+
// return (parseInfo.stream.charAt(position) == ":" &&
|
|
1105
|
+
// parseInfo.stream.charAt(endPosition - 1) == "(" &&
|
|
1106
|
+
// (parseInfo.stream.charAt(position + 1) == ":"
|
|
1107
|
+
// ? this.isIdentToken(parseInfo, 2, -1)
|
|
1108
|
+
// : this.isIdentToken(parseInfo, 1, -1))) ||
|
|
1109
|
+
// parseInfo.stream.charAt(position + 1) == ":"
|
|
1110
|
+
// ? this.isIdentToken(parseInfo, 2)
|
|
1111
|
+
// : this.isIdentToken(parseInfo, 1);
|
|
1112
|
+
// }
|
|
1116
1113
|
/**
|
|
1117
1114
|
*
|
|
1118
1115
|
* @param parseInfo
|
|
@@ -1185,7 +1182,7 @@ class Tokenizer {
|
|
|
1185
1182
|
while ((charCode = this.peekCharCode(parseInfo)) == charCode) {
|
|
1186
1183
|
if (this.state === EnumToken.UrlFunctionTokenDefType) {
|
|
1187
1184
|
this.state = null;
|
|
1188
|
-
return this.
|
|
1185
|
+
return this.consumeURLToken(parseInfo, endPosition);
|
|
1189
1186
|
}
|
|
1190
1187
|
if (parseInfo.position == parseInfo.currentPosition) {
|
|
1191
1188
|
if (charCode == 45 /* TokenMap.MINUS */ ||
|
|
@@ -1305,12 +1302,14 @@ class Tokenizer {
|
|
|
1305
1302
|
// '('
|
|
1306
1303
|
case 40 /* TokenMap.LEFT_PARENTHESIS */:
|
|
1307
1304
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
1308
|
-
if (
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1305
|
+
// if (
|
|
1306
|
+
// parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
|
|
1307
|
+
// this.isPseudo(parseInfo)
|
|
1308
|
+
// ) {
|
|
1309
|
+
// this.advance(parseInfo);
|
|
1310
|
+
// return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
|
|
1311
|
+
// } else
|
|
1312
|
+
if (this.isIdentToken(parseInfo)) {
|
|
1314
1313
|
const hint = this.startsWith(parseInfo, "--")
|
|
1315
1314
|
? EnumToken.CustomFunctionTokenDefType
|
|
1316
1315
|
: (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? EnumToken.FunctionTokenDefType);
|