@tbela99/css-parser 2.0.1 → 2.2.0
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 +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
function toDegrees(arena, angle) {
|
|
15
|
-
switch (arena.
|
|
15
|
+
switch (arena.resolveString(arena.unit[angle])) {
|
|
16
16
|
// case "deg":
|
|
17
17
|
// return angle;
|
|
18
18
|
case "rad":
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../../ast/arena.js';
|
|
9
9
|
import { EnumToken } from '../../ast/types.js';
|
|
10
|
-
import {
|
|
10
|
+
import { isFunctionDefType, mFGT, mFLT, tokensfuncDefMap } from '../../syntax/constants.js';
|
|
11
11
|
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
12
12
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
13
13
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
@@ -16,7 +16,7 @@ import { equalsIgnoreCase } from './text.js';
|
|
|
16
16
|
function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
17
17
|
let matchCount = 0;
|
|
18
18
|
const errors = [];
|
|
19
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.
|
|
19
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[context]));
|
|
20
20
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
21
21
|
const parts = [[]];
|
|
22
22
|
for (const token of stream) {
|
|
@@ -26,7 +26,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
28
|
parts[parts.length - 1].push(token);
|
|
29
|
-
if (type === EnumToken.StartParensTokenType ||
|
|
29
|
+
if (type === EnumToken.StartParensTokenType || isFunctionDefType(type)) {
|
|
30
30
|
matchCount++;
|
|
31
31
|
}
|
|
32
32
|
else if (type === EnumToken.EndParensTokenType && matchCount > 0) {
|
|
@@ -54,13 +54,15 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
54
54
|
let expectAndOr = false;
|
|
55
55
|
i = 0;
|
|
56
56
|
while (i < stream.length &&
|
|
57
|
-
(arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
57
|
+
(arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
58
|
+
arena.dataTypes[stream[i]] === EnumToken.CommentTokenType)) {
|
|
58
59
|
tokens.push(stream[i++]);
|
|
59
60
|
}
|
|
60
61
|
if (arena.dataTypes[stream[i]] === EnumToken.IdenTokenType) {
|
|
61
62
|
tokens.push(stream[i++]);
|
|
62
63
|
}
|
|
63
|
-
while (arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
64
|
+
while (arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
65
|
+
arena.dataTypes[stream[i]] === EnumToken.CommentTokenType) {
|
|
64
66
|
tokens.push(stream[i++]);
|
|
65
67
|
}
|
|
66
68
|
if (i < stream.length &&
|
|
@@ -73,7 +75,10 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
73
75
|
action: "drop",
|
|
74
76
|
node: stream[i],
|
|
75
77
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
76
|
-
location: [
|
|
78
|
+
location: [
|
|
79
|
+
options.source.file,
|
|
80
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
81
|
+
],
|
|
77
82
|
message: `expecting <container-condition>`,
|
|
78
83
|
},
|
|
79
84
|
],
|
|
@@ -81,13 +86,14 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
81
86
|
}
|
|
82
87
|
for (; i < stream.length; i++) {
|
|
83
88
|
tokens.push(stream[i]);
|
|
84
|
-
if (arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
89
|
+
if (arena.dataTypes[stream[i]] === EnumToken.WhitespaceTokenType ||
|
|
90
|
+
arena.dataTypes[stream[i]] === EnumToken.CommentTokenType) {
|
|
85
91
|
continue;
|
|
86
92
|
}
|
|
87
93
|
if (expectAndOr) {
|
|
88
94
|
let valid = true;
|
|
89
95
|
// if (arena.dataTypes[stream[i]] === EnumToken.IdenTokenType) {
|
|
90
|
-
// const val: string = arena.
|
|
96
|
+
// const val: string = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
91
97
|
// valid = val === "and" || val === "or";
|
|
92
98
|
// } else {
|
|
93
99
|
valid = arena.dataTypes[stream[i]] !== EnumToken.CommaTokenType;
|
|
@@ -99,12 +105,16 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
99
105
|
node: stream[i],
|
|
100
106
|
message: `expecting <and>, <or> or comma`,
|
|
101
107
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
102
|
-
location: [
|
|
108
|
+
location: [
|
|
109
|
+
options.source.file,
|
|
110
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
111
|
+
],
|
|
103
112
|
});
|
|
104
113
|
break;
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
|
-
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
116
|
+
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
117
|
+
isFunctionDefType(arena.dataTypes[stream[i]])) {
|
|
108
118
|
scopes.push((currentScope = new Set()));
|
|
109
119
|
stack.push(stream[i]);
|
|
110
120
|
continue;
|
|
@@ -120,20 +130,24 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
120
130
|
break;
|
|
121
131
|
case EnumToken.IdenTokenType:
|
|
122
132
|
{
|
|
123
|
-
const val = arena.
|
|
133
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
124
134
|
if (val === "not") {
|
|
125
135
|
arena.dataTypes[stream[i]] = EnumToken.NotTokenType;
|
|
126
136
|
stack.push(stream[i]);
|
|
127
137
|
}
|
|
128
138
|
else if (val === "and" || val === "or") {
|
|
129
|
-
arena.dataTypes[stream[i]] =
|
|
139
|
+
arena.dataTypes[stream[i]] =
|
|
140
|
+
val === "and" ? EnumToken.AndTokenType : EnumToken.OrTokenType;
|
|
130
141
|
if (val === "or" && scopes.length <= 1) {
|
|
131
142
|
success = false;
|
|
132
143
|
errors.push({
|
|
133
144
|
action: "drop",
|
|
134
145
|
node: stream[i],
|
|
135
146
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
136
|
-
location: [
|
|
147
|
+
location: [
|
|
148
|
+
options.source.file,
|
|
149
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
150
|
+
],
|
|
137
151
|
message: `<or> is not allowed outside of parentheses`,
|
|
138
152
|
});
|
|
139
153
|
break;
|
|
@@ -168,7 +182,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
168
182
|
if (arena.dataTypes[op] === EnumToken.ColonTokenType) {
|
|
169
183
|
const name = names.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
170
184
|
if (name != null) {
|
|
171
|
-
const val = arena.
|
|
185
|
+
const val = arena.resolveString(arena.stringValue[name]);
|
|
172
186
|
if (val.startsWith("min-")) {
|
|
173
187
|
// inlined: arena.setStr(name, val.substring(4))
|
|
174
188
|
arena.stringValue[name] = arena.internString(val.substring(4));
|
|
@@ -183,19 +197,25 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
183
197
|
}
|
|
184
198
|
// check <style()> or <scroll-state()>
|
|
185
199
|
}
|
|
186
|
-
if (stack.length > 0 &&
|
|
200
|
+
if (stack.length > 0 && isFunctionDefType(arena.dataTypes[stack[stack.length - 1]])) {
|
|
187
201
|
const index = tokens.indexOf(stack[stack.length - 1]);
|
|
188
202
|
arena.dataTypes[tokens[index]] = tokensfuncDefMap.get(arena.dataTypes[tokens[index]]);
|
|
189
203
|
arena.setTokenList(tokens[index], trimArray(arena, tokens.slice(index + 1, tokens.length - 1)));
|
|
190
204
|
arena.spanLocation(tokens[index], tokens[index], stream[i]);
|
|
191
|
-
if (arena
|
|
205
|
+
if (arena
|
|
206
|
+
.tokens(tokens[index])
|
|
207
|
+
.every((t) => arena.dataTypes[t] === EnumToken.WhitespaceTokenType ||
|
|
208
|
+
arena.dataTypes[t] === EnumToken.CommentTokenType)) {
|
|
192
209
|
success = false;
|
|
193
210
|
errors.push({
|
|
194
211
|
action: "drop",
|
|
195
212
|
node: stream[i],
|
|
196
213
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
197
|
-
location: [
|
|
198
|
-
|
|
214
|
+
location: [
|
|
215
|
+
options.source.file,
|
|
216
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
217
|
+
],
|
|
218
|
+
message: `expecting '<${arena.resolveString(arena.stringValue[tokens[index]])}-query>'`,
|
|
199
219
|
});
|
|
200
220
|
break;
|
|
201
221
|
}
|
|
@@ -209,13 +229,19 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
209
229
|
arena.dataTypes[tokens[index]] = EnumToken.ParensTokenType;
|
|
210
230
|
arena.setTokenList(tokens[index], tokens.slice(index + 1, tokens.length - 1));
|
|
211
231
|
arena.spanLocation(tokens[index], tokens[index], stream[i]);
|
|
212
|
-
if (arena
|
|
232
|
+
if (arena
|
|
233
|
+
.tokens(tokens[index])
|
|
234
|
+
.every((t) => arena.dataTypes[t] === EnumToken.WhitespaceTokenType ||
|
|
235
|
+
arena.dataTypes[t] === EnumToken.CommentTokenType)) {
|
|
213
236
|
success = false;
|
|
214
237
|
errors.push({
|
|
215
238
|
action: "drop",
|
|
216
239
|
node: stream[i],
|
|
217
240
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
218
|
-
location: [
|
|
241
|
+
location: [
|
|
242
|
+
options.source.file,
|
|
243
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
244
|
+
],
|
|
219
245
|
message: `expecting '<query-in-parens>'`,
|
|
220
246
|
});
|
|
221
247
|
break;
|
|
@@ -239,7 +265,10 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
239
265
|
action: "drop",
|
|
240
266
|
node: tokens[k],
|
|
241
267
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[k]))
|
|
242
|
-
location: [
|
|
268
|
+
location: [
|
|
269
|
+
options.source.file,
|
|
270
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[k])),
|
|
271
|
+
],
|
|
243
272
|
message: `unexpected token 'not'`,
|
|
244
273
|
});
|
|
245
274
|
break;
|
|
@@ -275,33 +304,33 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
275
304
|
tokens.length = l + 1;
|
|
276
305
|
expectAndOr = true;
|
|
277
306
|
if (arena.dataTypes[op] === EnumToken.AndTokenType) {
|
|
278
|
-
const notNameOrSpace = (t) => arena.dataTypes[t]
|
|
279
|
-
arena.dataTypes[t]
|
|
307
|
+
const notNameOrSpace = (t) => arena.dataTypes[t] !== EnumToken.WhitespaceTokenType &&
|
|
308
|
+
arena.dataTypes[t] !== EnumToken.IdenTokenType;
|
|
280
309
|
let leftCondition = left.find(notNameOrSpace);
|
|
281
310
|
let rightCondition = right.find(notNameOrSpace);
|
|
282
311
|
if (leftCondition != null &&
|
|
283
312
|
rightCondition != null &&
|
|
284
|
-
arena.dataTypes[leftCondition]
|
|
285
|
-
arena.dataTypes[rightCondition]
|
|
313
|
+
arena.dataTypes[leftCondition] === EnumToken.ParensTokenType &&
|
|
314
|
+
arena.dataTypes[rightCondition] === EnumToken.ParensTokenType) {
|
|
286
315
|
leftCondition = arena.tokens(leftCondition).find(notNameOrSpace);
|
|
287
316
|
rightCondition = arena.tokens(rightCondition).find(notNameOrSpace);
|
|
288
317
|
if (leftCondition != null &&
|
|
289
318
|
rightCondition != null &&
|
|
290
|
-
arena.dataTypes[leftCondition]
|
|
291
|
-
arena.dataTypes[rightCondition]
|
|
319
|
+
arena.dataTypes[leftCondition] === EnumToken.MediaQueryConditionTokenType &&
|
|
320
|
+
arena.dataTypes[rightCondition] === EnumToken.MediaQueryConditionTokenType) {
|
|
292
321
|
const leftOp = arena.field(leftCondition, TokenField.Op);
|
|
293
322
|
const rightOp = arena.field(rightCondition, TokenField.Op);
|
|
294
323
|
if ((mFLT.has(arena.dataTypes[leftOp]) || mFGT.has(arena.dataTypes[leftOp])) &&
|
|
295
324
|
(mFLT.has(arena.dataTypes[rightOp]) || mFGT.has(arena.dataTypes[rightOp]))) {
|
|
296
325
|
const name = arena
|
|
297
326
|
.fieldTokens(leftCondition, TokenField.L)
|
|
298
|
-
.find((t) => arena.dataTypes[t]
|
|
327
|
+
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
299
328
|
const name2 = arena
|
|
300
329
|
.fieldTokens(rightCondition, TokenField.L)
|
|
301
|
-
.find((t) => arena.dataTypes[t]
|
|
330
|
+
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
302
331
|
if (name != null &&
|
|
303
332
|
name2 != null &&
|
|
304
|
-
equalsIgnoreCase(arena.
|
|
333
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[name]), arena.resolveString(arena.stringValue[name2]))) {
|
|
305
334
|
switch (arena.dataTypes[leftOp]) {
|
|
306
335
|
case EnumToken.LtTokenType:
|
|
307
336
|
arena.dataTypes[leftOp] = EnumToken.GtTokenType;
|
|
@@ -322,9 +351,13 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
322
351
|
// inlined: arena.setField(rangeQuery, TokenField.Val, name)
|
|
323
352
|
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.Val), [name]);
|
|
324
353
|
// inlined: arena.setField(rangeQuery, TokenField.Op, leftOp)
|
|
325
|
-
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.Op), [
|
|
354
|
+
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.Op), [
|
|
355
|
+
leftOp,
|
|
356
|
+
]);
|
|
326
357
|
// inlined: arena.setField(rangeQuery, TokenField.Op2, rightOp)
|
|
327
|
-
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.Op2), [
|
|
358
|
+
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.Op2), [
|
|
359
|
+
rightOp,
|
|
360
|
+
]);
|
|
328
361
|
// inlined: arena.setField(rangeQuery, TokenField.R, ...arena.fieldTokens(rightCondition, TokenField.R))
|
|
329
362
|
arena.setTokenList(arena.fieldList(rangeQuery, TokenField.R), arena.fieldTokens(rightCondition, TokenField.R));
|
|
330
363
|
arena.spanLocation(rangeQuery, leftCondition, rightCondition);
|
|
@@ -359,7 +392,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
359
392
|
}
|
|
360
393
|
stream.length = 0;
|
|
361
394
|
for (const part of parts) {
|
|
362
|
-
if (part.length
|
|
395
|
+
if (part.length === 0) {
|
|
363
396
|
continue;
|
|
364
397
|
}
|
|
365
398
|
for (const token of part) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
@@ -10,7 +10,7 @@ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../vali
|
|
|
10
10
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
11
11
|
|
|
12
12
|
function parseAtRuleFontFeatureValues(arena, stream, context, options = {}) {
|
|
13
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.
|
|
13
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[context]));
|
|
14
14
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
15
15
|
trimArray(arena, stream);
|
|
16
16
|
const { success, errors /* , ...all */ } = matchAllSyntaxes(arena, syntax, createValidationContext(arena, stream), options);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
|
-
import {
|
|
9
|
+
import { isFunctionDefType } from '../../syntax/constants.js';
|
|
10
10
|
import { equalsIgnoreCase } from './text.js';
|
|
11
11
|
|
|
12
12
|
function matchGenericSyntax(arena, stream, options) {
|
|
@@ -19,10 +19,11 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
19
19
|
const scopes = [new Set()];
|
|
20
20
|
for (; i < stream.length; i++) {
|
|
21
21
|
const token = stream[i];
|
|
22
|
-
if (arena.dataTypes[token] === EnumToken.WhitespaceTokenType ||
|
|
22
|
+
if (arena.dataTypes[token] === EnumToken.WhitespaceTokenType ||
|
|
23
|
+
arena.dataTypes[token] === EnumToken.CommentTokenType) {
|
|
23
24
|
continue;
|
|
24
25
|
}
|
|
25
|
-
if (arena.dataTypes[token] === EnumToken.StartParensTokenType ||
|
|
26
|
+
if (arena.dataTypes[token] === EnumToken.StartParensTokenType || isFunctionDefType(arena.dataTypes[token])) {
|
|
26
27
|
stack.push(token);
|
|
27
28
|
scopes.push(new Set());
|
|
28
29
|
expectAndOr = false;
|
|
@@ -31,13 +32,16 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
31
32
|
if (arena.dataTypes[token] === EnumToken.EndParensTokenType) {
|
|
32
33
|
if (stack.length === 0 ||
|
|
33
34
|
(arena.dataTypes[stack[stack.length - 1]] !== EnumToken.StartParensTokenType &&
|
|
34
|
-
!
|
|
35
|
+
!isFunctionDefType(arena.dataTypes[stack[stack.length - 1]]))) {
|
|
35
36
|
errors.push({
|
|
36
37
|
action: "drop",
|
|
37
38
|
message: `unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
38
39
|
node: token,
|
|
39
40
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
40
|
-
location: [
|
|
41
|
+
location: [
|
|
42
|
+
options.source.file,
|
|
43
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(token)),
|
|
44
|
+
],
|
|
41
45
|
});
|
|
42
46
|
success = false;
|
|
43
47
|
break;
|
|
@@ -46,14 +50,18 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
46
50
|
scopes.pop();
|
|
47
51
|
continue;
|
|
48
52
|
}
|
|
49
|
-
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
53
|
+
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
54
|
+
equalsIgnoreCase("and", arena.resolveString(arena.stringValue[token]))) {
|
|
50
55
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.OrTokenType)) {
|
|
51
56
|
errors.push({
|
|
52
57
|
action: "drop",
|
|
53
58
|
message: `unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
54
59
|
node: token,
|
|
55
60
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
56
|
-
location: [
|
|
61
|
+
location: [
|
|
62
|
+
options.source.file,
|
|
63
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(token)),
|
|
64
|
+
],
|
|
57
65
|
});
|
|
58
66
|
success = false;
|
|
59
67
|
break;
|
|
@@ -63,14 +71,18 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
63
71
|
expectComma = false;
|
|
64
72
|
continue;
|
|
65
73
|
}
|
|
66
|
-
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
74
|
+
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
75
|
+
equalsIgnoreCase("or", arena.resolveString(arena.stringValue[token]))) {
|
|
67
76
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.AndTokenType)) {
|
|
68
77
|
errors.push({
|
|
69
78
|
action: "drop",
|
|
70
79
|
message: `unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
71
80
|
node: token,
|
|
72
81
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
73
|
-
location: [
|
|
82
|
+
location: [
|
|
83
|
+
options.source.file,
|
|
84
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(token)),
|
|
85
|
+
],
|
|
74
86
|
});
|
|
75
87
|
success = false;
|
|
76
88
|
break;
|
|
@@ -87,7 +99,10 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
87
99
|
message: `unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
88
100
|
node: token,
|
|
89
101
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
90
|
-
location: [
|
|
102
|
+
location: [
|
|
103
|
+
options.source.file,
|
|
104
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(token)),
|
|
105
|
+
],
|
|
91
106
|
});
|
|
92
107
|
success = false;
|
|
93
108
|
break;
|
|
@@ -109,7 +124,10 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
109
124
|
message: `unexpected token ${EnumToken[arena.dataTypes[stack[stack.length - 1]]]}`,
|
|
110
125
|
node: stack[stack.length - 1],
|
|
111
126
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stack[stack.length - 1]))
|
|
112
|
-
location: [
|
|
127
|
+
location: [
|
|
128
|
+
options.source.file,
|
|
129
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stack[stack.length - 1])),
|
|
130
|
+
],
|
|
113
131
|
});
|
|
114
132
|
success = false;
|
|
115
133
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
9
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
10
10
|
import { trimArray } from '../../validation/match.js';
|
|
11
11
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
12
|
-
import { tokensfuncDefMap } from '../../syntax/constants.js';
|
|
12
|
+
import { tokensfuncDefMap, isFunctionDefType } from '../../syntax/constants.js';
|
|
13
13
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
14
14
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
15
15
|
|
|
@@ -37,7 +37,8 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
37
37
|
if (arena.dataTypes[stream[k]] === EnumToken.EndParensTokenType) {
|
|
38
38
|
matchCount--;
|
|
39
39
|
}
|
|
40
|
-
else if (arena.dataTypes[stream[k]] === EnumToken.StartParensTokenType ||
|
|
40
|
+
else if (arena.dataTypes[stream[k]] === EnumToken.StartParensTokenType ||
|
|
41
|
+
isFunctionDefType(arena.dataTypes[stream[k]])) {
|
|
41
42
|
matchCount++;
|
|
42
43
|
}
|
|
43
44
|
if (matchCount === 0) {
|
|
@@ -61,22 +62,26 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
61
62
|
syntax: "@import",
|
|
62
63
|
node: stream[0],
|
|
63
64
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[0]))
|
|
64
|
-
location: [
|
|
65
|
+
location: [
|
|
66
|
+
options.source.file,
|
|
67
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[0])),
|
|
68
|
+
],
|
|
65
69
|
},
|
|
66
70
|
],
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
73
|
while (index + 1 < prelude.length &&
|
|
70
|
-
(arena.dataTypes[stream[index]]
|
|
74
|
+
(arena.dataTypes[stream[index]] === EnumToken.WhitespaceTokenType ||
|
|
75
|
+
arena.dataTypes[stream[index]] === EnumToken.CommentTokenType)) {
|
|
71
76
|
tokens.push(stream[index++]);
|
|
72
77
|
}
|
|
73
78
|
// layer | layer(<layer-name>)
|
|
74
79
|
if (arena.dataTypes[stream[index]] === EnumToken.IdenTokenType &&
|
|
75
|
-
"layer".localeCompare(arena.
|
|
80
|
+
"layer".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
76
81
|
tokens.push(stream[index++]);
|
|
77
82
|
}
|
|
78
|
-
else if (
|
|
79
|
-
"layer".localeCompare(arena.
|
|
83
|
+
else if (isFunctionDefType(arena.dataTypes[stream[index]]) &&
|
|
84
|
+
"layer".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
80
85
|
stack.push(stream[index]);
|
|
81
86
|
tokens.push(stream[index++]);
|
|
82
87
|
// <layer-name">
|
|
@@ -91,14 +96,17 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
91
96
|
syntax: "@import",
|
|
92
97
|
node: stream[index],
|
|
93
98
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[index]))
|
|
94
|
-
location: [
|
|
99
|
+
location: [
|
|
100
|
+
options.source.file,
|
|
101
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[index])),
|
|
102
|
+
],
|
|
95
103
|
},
|
|
96
104
|
],
|
|
97
105
|
};
|
|
98
106
|
}
|
|
99
107
|
else if (arena.dataTypes[stream[index]] === EnumToken.IdenTokenType) {
|
|
100
108
|
tokens.push(stream[index++]);
|
|
101
|
-
while (arena.dataTypes[stream[index]]
|
|
109
|
+
while (arena.dataTypes[stream[index]] === EnumToken.ClassSelectorTokenType) {
|
|
102
110
|
tokens.push(stream[index++]);
|
|
103
111
|
}
|
|
104
112
|
i = tokens.indexOf(stack[stack.length - 1]);
|
|
@@ -117,19 +125,23 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
117
125
|
syntax: "@import",
|
|
118
126
|
node: stream[index],
|
|
119
127
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[index]))
|
|
120
|
-
location: [
|
|
128
|
+
location: [
|
|
129
|
+
options.source.file,
|
|
130
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[index])),
|
|
131
|
+
],
|
|
121
132
|
},
|
|
122
133
|
],
|
|
123
134
|
};
|
|
124
135
|
}
|
|
125
136
|
}
|
|
126
|
-
while (arena.dataTypes[stream[index]] === EnumToken.WhitespaceTokenType ||
|
|
137
|
+
while (arena.dataTypes[stream[index]] === EnumToken.WhitespaceTokenType ||
|
|
138
|
+
arena.dataTypes[stream[index]] === EnumToken.CommentTokenType) {
|
|
127
139
|
tokens.push(stream[index++]);
|
|
128
140
|
}
|
|
129
141
|
// supports([ <supports-condition> | <declaration> ])
|
|
130
142
|
if (index < stream.length &&
|
|
131
|
-
|
|
132
|
-
"supports".localeCompare(arena.
|
|
143
|
+
isFunctionDefType(arena.dataTypes[stream[index]]) &&
|
|
144
|
+
"supports".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
133
145
|
stack.push(stream[index]);
|
|
134
146
|
tokens.push(stream[index++]);
|
|
135
147
|
matchCount = 1;
|
|
@@ -137,7 +149,8 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
137
149
|
// else {
|
|
138
150
|
// match the next ')'
|
|
139
151
|
while (index < stream.length && matchCount > 0) {
|
|
140
|
-
if (arena.dataTypes[stream[index]] === EnumToken.StartParensTokenType ||
|
|
152
|
+
if (arena.dataTypes[stream[index]] === EnumToken.StartParensTokenType ||
|
|
153
|
+
isFunctionDefType(arena.dataTypes[stream[index]])) {
|
|
141
154
|
matchCount++;
|
|
142
155
|
}
|
|
143
156
|
else if (arena.dataTypes[stream[index]] === EnumToken.EndParensTokenType) {
|