@tbela99/css-parser 0.7.1 → 0.9.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/.editorconfig +484 -0
- package/README.md +140 -84
- package/dist/index-umd-web.js +8461 -51655
- package/dist/index.cjs +8437 -51636
- package/dist/index.d.ts +220 -68
- package/dist/lib/ast/expand.js +46 -9
- package/dist/lib/ast/features/calc.js +76 -12
- package/dist/lib/ast/features/inlinecssvariables.js +6 -1
- package/dist/lib/ast/features/prefix.js +17 -9
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/math/expression.js +299 -11
- package/dist/lib/ast/math/math.js +7 -1
- package/dist/lib/ast/minify.js +30 -16
- package/dist/lib/ast/types.js +59 -49
- package/dist/lib/ast/walk.js +92 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +60 -52
- package/dist/lib/parser/declaration/set.js +1 -12
- package/dist/lib/parser/parse.js +371 -119
- package/dist/lib/parser/tokenize.js +31 -6
- package/dist/lib/parser/utils/declaration.js +2 -2
- package/dist/lib/parser/utils/type.js +6 -6
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +1 -0
- package/dist/lib/renderer/color/hex.js +2 -1
- package/dist/lib/renderer/color/hsl.js +2 -1
- package/dist/lib/renderer/color/hwb.js +3 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/lch.js +2 -1
- package/dist/lib/renderer/color/oklab.js +3 -2
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- package/dist/lib/renderer/color/prophotorgb.js +1 -1
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +52 -28
- package/dist/lib/renderer/color/rgb.js +2 -1
- package/dist/lib/renderer/color/srgb.js +3 -2
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +2 -1
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +62 -12
- package/dist/lib/syntax/syntax.js +362 -4
- package/dist/lib/validation/at-rules/container.js +353 -0
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/custom-media.js +52 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/else.js +5 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
- package/dist/lib/validation/at-rules/import.js +199 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +30 -0
- package/dist/lib/validation/at-rules/media.js +254 -0
- package/dist/lib/validation/at-rules/namespace.js +85 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
- package/dist/lib/validation/at-rules/page.js +88 -0
- package/dist/lib/validation/at-rules/supports.js +262 -0
- package/dist/lib/validation/at-rules/when.js +178 -0
- package/dist/lib/validation/atrule.js +187 -0
- package/dist/lib/validation/config.js +35 -2
- package/dist/lib/validation/config.json.js +1683 -50905
- package/dist/lib/validation/declaration.js +102 -0
- package/dist/lib/validation/parser/parse.js +1137 -7
- package/dist/lib/validation/parser/types.js +28 -12
- package/dist/lib/validation/selector.js +26 -444
- package/dist/lib/validation/syntax.js +1475 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
- package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -0
- package/dist/lib/validation/syntaxes/image.js +29 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
- package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
- package/dist/lib/validation/syntaxes/layer-name.js +67 -0
- package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
- package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
- package/dist/lib/validation/syntaxes/selector-list.js +5 -0
- package/dist/lib/validation/syntaxes/selector.js +5 -0
- package/dist/lib/validation/syntaxes/url.js +75 -0
- package/dist/lib/validation/utils/list.js +24 -0
- package/dist/lib/validation/utils/whitespace.js +22 -0
- package/dist/node/index.js +5 -5
- package/dist/web/index.js +5 -1
- package/dist/web/load.js +1 -0
- package/package.json +16 -14
- package/dist/lib/ast/utils/minifyfeature.js +0 -9
- package/dist/lib/iterable/weakset.js +0 -58
- package/dist/lib/parser/utils/syntax.js +0 -450
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
|
|
2
|
+
import '../../ast/minify.js';
|
|
3
|
+
import '../../ast/walk.js';
|
|
4
|
+
import '../../parser/parse.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
8
|
+
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
|
+
import { splitTokenList } from '../utils/list.js';
|
|
10
|
+
|
|
11
|
+
const validateContainerScrollStateFeature = validateContainerSizeFeature;
|
|
12
|
+
function validateAtRuleContainer(atRule, options, root) {
|
|
13
|
+
// media-query-list
|
|
14
|
+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return {
|
|
17
|
+
valid: ValidationLevel.Drop,
|
|
18
|
+
matches: [],
|
|
19
|
+
node: atRule,
|
|
20
|
+
syntax: '@' + atRule.nam,
|
|
21
|
+
error: 'expected supports query list',
|
|
22
|
+
tokens: []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const result = validateAtRuleContainerQueryList(atRule.tokens, atRule);
|
|
26
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (!('chi' in atRule)) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return {
|
|
32
|
+
valid: ValidationLevel.Drop,
|
|
33
|
+
matches: [],
|
|
34
|
+
node: atRule,
|
|
35
|
+
syntax: '@' + atRule.nam,
|
|
36
|
+
error: 'expected at-rule body',
|
|
37
|
+
tokens: []
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
valid: ValidationLevel.Valid,
|
|
42
|
+
matches: [],
|
|
43
|
+
node: atRule,
|
|
44
|
+
syntax: '@' + atRule.nam,
|
|
45
|
+
error: '',
|
|
46
|
+
tokens: []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function validateAtRuleContainerQueryList(tokens, atRule) {
|
|
50
|
+
if (tokens.length == 0) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
return {
|
|
53
|
+
valid: ValidationLevel.Drop,
|
|
54
|
+
matches: [],
|
|
55
|
+
node: atRule,
|
|
56
|
+
syntax: '@' + atRule.nam,
|
|
57
|
+
error: 'expected container query list',
|
|
58
|
+
tokens
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
let result = null;
|
|
62
|
+
let tokenType = null;
|
|
63
|
+
for (const queries of splitTokenList(tokens)) {
|
|
64
|
+
consumeWhitespace(queries);
|
|
65
|
+
if (queries.length == 0) {
|
|
66
|
+
return {
|
|
67
|
+
valid: ValidationLevel.Drop,
|
|
68
|
+
matches: [],
|
|
69
|
+
node: atRule,
|
|
70
|
+
syntax: '@' + atRule.nam,
|
|
71
|
+
error: 'expected container query list',
|
|
72
|
+
tokens
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
result = null;
|
|
76
|
+
const match = [];
|
|
77
|
+
let token = null;
|
|
78
|
+
tokenType = null;
|
|
79
|
+
while (queries.length > 0) {
|
|
80
|
+
if (queries.length == 0) {
|
|
81
|
+
return {
|
|
82
|
+
valid: ValidationLevel.Drop,
|
|
83
|
+
matches: [],
|
|
84
|
+
node: atRule,
|
|
85
|
+
syntax: '@' + atRule.nam,
|
|
86
|
+
error: 'expected container query list',
|
|
87
|
+
tokens
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (queries[0].typ == EnumToken.IdenTokenType) {
|
|
91
|
+
match.push(queries.shift());
|
|
92
|
+
consumeWhitespace(queries);
|
|
93
|
+
}
|
|
94
|
+
if (queries.length == 0) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
token = queries[0];
|
|
98
|
+
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
99
|
+
token = token.val;
|
|
100
|
+
}
|
|
101
|
+
if (token.typ != EnumToken.ParensTokenType && (token.typ != EnumToken.FunctionTokenType || !['scroll-state', 'style'].includes(token.val))) {
|
|
102
|
+
return {
|
|
103
|
+
valid: ValidationLevel.Drop,
|
|
104
|
+
matches: [],
|
|
105
|
+
node: queries[0],
|
|
106
|
+
syntax: '@' + atRule.nam,
|
|
107
|
+
error: 'expected container query-in-parens',
|
|
108
|
+
tokens
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (token.typ == EnumToken.ParensTokenType) {
|
|
112
|
+
result = validateContainerSizeFeature(token.chi, atRule);
|
|
113
|
+
}
|
|
114
|
+
else if (token.val == 'scroll-state') {
|
|
115
|
+
result = validateContainerScrollStateFeature(token.chi, atRule);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
result = validateContainerStyleFeature(token.chi, atRule);
|
|
119
|
+
}
|
|
120
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
queries.shift();
|
|
124
|
+
consumeWhitespace(queries);
|
|
125
|
+
if (queries.length == 0) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
token = queries[0];
|
|
129
|
+
if (token.typ != EnumToken.MediaFeatureAndTokenType && token.typ != EnumToken.MediaFeatureOrTokenType) {
|
|
130
|
+
return {
|
|
131
|
+
valid: ValidationLevel.Drop,
|
|
132
|
+
matches: [],
|
|
133
|
+
node: queries[0],
|
|
134
|
+
syntax: '@' + atRule.nam,
|
|
135
|
+
error: 'expecting and/or container query token',
|
|
136
|
+
tokens
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (tokenType == null) {
|
|
140
|
+
tokenType = token.typ;
|
|
141
|
+
}
|
|
142
|
+
if (tokenType != token.typ) {
|
|
143
|
+
return {
|
|
144
|
+
valid: ValidationLevel.Drop,
|
|
145
|
+
matches: [],
|
|
146
|
+
node: queries[0],
|
|
147
|
+
syntax: '@' + atRule.nam,
|
|
148
|
+
error: 'mixing and/or not allowed at the same level',
|
|
149
|
+
tokens
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
queries.shift();
|
|
153
|
+
consumeWhitespace(queries);
|
|
154
|
+
if (queries.length == 0) {
|
|
155
|
+
return {
|
|
156
|
+
valid: ValidationLevel.Drop,
|
|
157
|
+
matches: [],
|
|
158
|
+
node: queries[0],
|
|
159
|
+
syntax: '@' + atRule.nam,
|
|
160
|
+
error: 'expected container query-in-parens',
|
|
161
|
+
tokens
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
valid: ValidationLevel.Valid,
|
|
168
|
+
matches: [],
|
|
169
|
+
node: atRule,
|
|
170
|
+
syntax: '@' + atRule.nam,
|
|
171
|
+
error: '',
|
|
172
|
+
tokens
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function validateContainerStyleFeature(tokens, atRule) {
|
|
176
|
+
tokens = tokens.slice();
|
|
177
|
+
consumeWhitespace(tokens);
|
|
178
|
+
if (tokens.length == 1) {
|
|
179
|
+
if (tokens[0].typ == EnumToken.ParensTokenType) {
|
|
180
|
+
return validateContainerStyleFeature(tokens[0].chi, atRule);
|
|
181
|
+
}
|
|
182
|
+
if ([EnumToken.DashedIdenTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ) ||
|
|
183
|
+
(tokens[0].typ == EnumToken.MediaQueryConditionTokenType && tokens[0].op.typ == EnumToken.ColonTokenType)) {
|
|
184
|
+
return {
|
|
185
|
+
valid: ValidationLevel.Valid,
|
|
186
|
+
matches: [],
|
|
187
|
+
node: atRule,
|
|
188
|
+
syntax: '@' + atRule.nam,
|
|
189
|
+
error: '',
|
|
190
|
+
tokens
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
valid: ValidationLevel.Drop,
|
|
196
|
+
matches: [],
|
|
197
|
+
node: atRule,
|
|
198
|
+
syntax: '@' + atRule.nam,
|
|
199
|
+
error: 'expected container query features',
|
|
200
|
+
tokens
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function validateContainerSizeFeature(tokens, atRule) {
|
|
204
|
+
tokens = tokens.slice();
|
|
205
|
+
consumeWhitespace(tokens);
|
|
206
|
+
if (tokens.length == 0) {
|
|
207
|
+
return {
|
|
208
|
+
valid: ValidationLevel.Drop,
|
|
209
|
+
matches: [],
|
|
210
|
+
node: atRule,
|
|
211
|
+
syntax: '@' + atRule.nam,
|
|
212
|
+
error: 'expected container query features',
|
|
213
|
+
tokens
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
if (tokens.length == 1) {
|
|
217
|
+
const token = tokens[0];
|
|
218
|
+
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
219
|
+
return validateContainerSizeFeature([token.val], atRule);
|
|
220
|
+
}
|
|
221
|
+
if (token.typ == EnumToken.ParensTokenType) {
|
|
222
|
+
return validateAtRuleContainerQueryStyleInParams(token.chi, atRule);
|
|
223
|
+
}
|
|
224
|
+
if (![EnumToken.DashedIdenTokenType, EnumToken.MediaQueryConditionTokenType].includes(tokens[0].typ)) {
|
|
225
|
+
return {
|
|
226
|
+
valid: ValidationLevel.Drop,
|
|
227
|
+
matches: [],
|
|
228
|
+
node: atRule,
|
|
229
|
+
syntax: '@' + atRule.nam,
|
|
230
|
+
error: 'expected container query features',
|
|
231
|
+
tokens
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
valid: ValidationLevel.Valid,
|
|
236
|
+
matches: [],
|
|
237
|
+
node: atRule,
|
|
238
|
+
syntax: '@' + atRule.nam,
|
|
239
|
+
error: '',
|
|
240
|
+
tokens
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return validateAtRuleContainerQueryStyleInParams(tokens, atRule);
|
|
244
|
+
}
|
|
245
|
+
function validateAtRuleContainerQueryStyleInParams(tokens, atRule) {
|
|
246
|
+
tokens = tokens.slice();
|
|
247
|
+
consumeWhitespace(tokens);
|
|
248
|
+
if (tokens.length == 0) {
|
|
249
|
+
return {
|
|
250
|
+
valid: ValidationLevel.Drop,
|
|
251
|
+
matches: [],
|
|
252
|
+
node: atRule,
|
|
253
|
+
syntax: '@' + atRule.nam,
|
|
254
|
+
error: 'expected container query features',
|
|
255
|
+
tokens
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
let token = tokens[0];
|
|
259
|
+
let tokenType = null;
|
|
260
|
+
let result = null;
|
|
261
|
+
while (tokens.length > 0) {
|
|
262
|
+
token = tokens[0];
|
|
263
|
+
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
264
|
+
token = token.val;
|
|
265
|
+
}
|
|
266
|
+
if (tokens[0].typ != EnumToken.ParensTokenType) {
|
|
267
|
+
return {
|
|
268
|
+
valid: ValidationLevel.Drop,
|
|
269
|
+
matches: [],
|
|
270
|
+
node: atRule,
|
|
271
|
+
syntax: '@' + atRule.nam,
|
|
272
|
+
error: 'expected container query-in-parens',
|
|
273
|
+
tokens
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const slices = tokens[0].chi.slice();
|
|
277
|
+
consumeWhitespace(slices);
|
|
278
|
+
if (slices.length == 1) {
|
|
279
|
+
if ([EnumToken.MediaFeatureNotTokenType, EnumToken.ParensTokenType].includes(slices[0].typ)) {
|
|
280
|
+
result = validateAtRuleContainerQueryStyleInParams(slices, atRule);
|
|
281
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else if (![EnumToken.DashedIdenTokenType, EnumToken.MediaQueryConditionTokenType].includes(slices[0].typ)) {
|
|
286
|
+
result = {
|
|
287
|
+
valid: ValidationLevel.Drop,
|
|
288
|
+
matches: [],
|
|
289
|
+
node: atRule,
|
|
290
|
+
syntax: '@' + atRule.nam,
|
|
291
|
+
error: 'expected container query features',
|
|
292
|
+
tokens
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
result = validateAtRuleContainerQueryStyleInParams(slices, atRule);
|
|
298
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
tokens.shift();
|
|
303
|
+
consumeWhitespace(tokens);
|
|
304
|
+
if (tokens.length == 0) {
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
if (![EnumToken.MediaFeatureAndTokenType, EnumToken.MediaFeatureOrTokenType].includes(tokens[0].typ)) {
|
|
308
|
+
return {
|
|
309
|
+
valid: ValidationLevel.Drop,
|
|
310
|
+
matches: [],
|
|
311
|
+
node: tokens[0],
|
|
312
|
+
syntax: '@' + atRule.nam,
|
|
313
|
+
error: 'expecting and/or container query token',
|
|
314
|
+
tokens
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (tokenType == null) {
|
|
318
|
+
tokenType = tokens[0].typ;
|
|
319
|
+
}
|
|
320
|
+
if (tokenType != tokens[0].typ) {
|
|
321
|
+
return {
|
|
322
|
+
valid: ValidationLevel.Drop,
|
|
323
|
+
matches: [],
|
|
324
|
+
node: tokens[0],
|
|
325
|
+
syntax: '@' + atRule.nam,
|
|
326
|
+
error: 'mixing and/or not allowed at the same level',
|
|
327
|
+
tokens
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
tokens.shift();
|
|
331
|
+
consumeWhitespace(tokens);
|
|
332
|
+
if (tokens.length == 0) {
|
|
333
|
+
return {
|
|
334
|
+
valid: ValidationLevel.Drop,
|
|
335
|
+
matches: [],
|
|
336
|
+
node: tokens[0],
|
|
337
|
+
syntax: '@' + atRule.nam,
|
|
338
|
+
error: 'expected container query-in-parens',
|
|
339
|
+
tokens
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
valid: ValidationLevel.Valid,
|
|
345
|
+
matches: [],
|
|
346
|
+
node: atRule,
|
|
347
|
+
syntax: '@' + atRule.nam,
|
|
348
|
+
error: '',
|
|
349
|
+
tokens
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export { validateAtRuleContainer };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
|
|
2
|
+
import '../../ast/minify.js';
|
|
3
|
+
import '../../ast/walk.js';
|
|
4
|
+
import '../../parser/parse.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
8
|
+
|
|
9
|
+
function validateAtRuleCounterStyle(atRule, options, root) {
|
|
10
|
+
// media-query-list
|
|
11
|
+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
return {
|
|
14
|
+
valid: ValidationLevel.Drop,
|
|
15
|
+
matches: [],
|
|
16
|
+
node: atRule,
|
|
17
|
+
syntax: '@counter-style',
|
|
18
|
+
error: 'expected counter style name',
|
|
19
|
+
tokens: []
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const tokens = atRule.tokens.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
23
|
+
if (tokens.length == 0) {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
return {
|
|
26
|
+
valid: ValidationLevel.Drop,
|
|
27
|
+
matches: [],
|
|
28
|
+
node: atRule,
|
|
29
|
+
syntax: '@counter-style',
|
|
30
|
+
error: 'expected counter style name',
|
|
31
|
+
tokens
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (tokens.length > 1) {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
return {
|
|
37
|
+
valid: ValidationLevel.Drop,
|
|
38
|
+
matches: [],
|
|
39
|
+
node: tokens[1] ?? atRule,
|
|
40
|
+
syntax: '@counter-style',
|
|
41
|
+
error: 'unexpected token',
|
|
42
|
+
tokens
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (![EnumToken.IdenTokenType, EnumToken.DashedIdenTokenType].includes(tokens[0].typ)) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return {
|
|
48
|
+
valid: ValidationLevel.Drop,
|
|
49
|
+
matches: [],
|
|
50
|
+
node: tokens[0],
|
|
51
|
+
syntax: '@counter-style',
|
|
52
|
+
error: 'expected counter style name',
|
|
53
|
+
tokens
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!('chi' in atRule)) {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
return {
|
|
59
|
+
valid: ValidationLevel.Drop,
|
|
60
|
+
matches: [],
|
|
61
|
+
node: atRule,
|
|
62
|
+
syntax: '@counter-style',
|
|
63
|
+
error: 'expected counter style body',
|
|
64
|
+
tokens
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
return {
|
|
69
|
+
valid: ValidationLevel.Valid,
|
|
70
|
+
matches: [],
|
|
71
|
+
node: atRule,
|
|
72
|
+
syntax: '@counter-style',
|
|
73
|
+
error: '',
|
|
74
|
+
tokens
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { validateAtRuleCounterStyle };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
|
|
2
|
+
import '../../ast/minify.js';
|
|
3
|
+
import '../../ast/walk.js';
|
|
4
|
+
import '../../parser/parse.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
8
|
+
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
|
+
import { validateAtRuleMediaQueryList } from './media.js';
|
|
10
|
+
|
|
11
|
+
function validateAtRuleCustomMedia(atRule, options, root) {
|
|
12
|
+
// media-query-list
|
|
13
|
+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return {
|
|
16
|
+
valid: ValidationLevel.Valid,
|
|
17
|
+
matches: [],
|
|
18
|
+
node: null,
|
|
19
|
+
syntax: null,
|
|
20
|
+
error: '',
|
|
21
|
+
tokens: []
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const queries = atRule.tokens.slice();
|
|
25
|
+
consumeWhitespace(queries);
|
|
26
|
+
if (queries.length == 0 || queries[0].typ != EnumToken.DashedIdenTokenType) {
|
|
27
|
+
return {
|
|
28
|
+
valid: ValidationLevel.Drop,
|
|
29
|
+
matches: [],
|
|
30
|
+
node: atRule,
|
|
31
|
+
syntax: '@custom-media',
|
|
32
|
+
error: 'expecting dashed identifier',
|
|
33
|
+
tokens: []
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
queries.shift();
|
|
37
|
+
const result = validateAtRuleMediaQueryList(queries, atRule);
|
|
38
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
39
|
+
atRule.tokens = [];
|
|
40
|
+
return {
|
|
41
|
+
valid: ValidationLevel.Valid,
|
|
42
|
+
matches: [],
|
|
43
|
+
node: atRule,
|
|
44
|
+
syntax: '@custom-media',
|
|
45
|
+
error: '',
|
|
46
|
+
tokens: []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { validateAtRuleCustomMedia };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
|
|
2
|
+
import '../../ast/minify.js';
|
|
3
|
+
import '../../ast/walk.js';
|
|
4
|
+
import '../../parser/parse.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
8
|
+
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
|
+
import { validateURL } from '../syntaxes/url.js';
|
|
10
|
+
|
|
11
|
+
function validateAtRuleDocument(atRule, options, root) {
|
|
12
|
+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
return {
|
|
15
|
+
valid: ValidationLevel.Drop,
|
|
16
|
+
matches: [],
|
|
17
|
+
node: atRule,
|
|
18
|
+
syntax: '@document',
|
|
19
|
+
error: 'expecting at-rule prelude',
|
|
20
|
+
tokens: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const tokens = atRule.tokens.slice();
|
|
24
|
+
let result = null;
|
|
25
|
+
consumeWhitespace(tokens);
|
|
26
|
+
if (tokens.length == 0) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return {
|
|
29
|
+
valid: ValidationLevel.Drop,
|
|
30
|
+
matches: [],
|
|
31
|
+
node: atRule,
|
|
32
|
+
syntax: '@document',
|
|
33
|
+
error: 'expecting at-rule prelude',
|
|
34
|
+
tokens
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (tokens[0].typ == EnumToken.CommaTokenType) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
return {
|
|
40
|
+
valid: ValidationLevel.Drop,
|
|
41
|
+
matches: [],
|
|
42
|
+
node: tokens[0],
|
|
43
|
+
syntax: '@document',
|
|
44
|
+
error: 'unexpected token',
|
|
45
|
+
tokens
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
while (tokens.length > 0) {
|
|
49
|
+
if (tokens[0].typ == EnumToken.CommentTokenType) {
|
|
50
|
+
tokens.shift();
|
|
51
|
+
consumeWhitespace(tokens);
|
|
52
|
+
}
|
|
53
|
+
result = validateURL(tokens[0]);
|
|
54
|
+
if (result.valid == ValidationLevel.Valid) {
|
|
55
|
+
tokens.shift();
|
|
56
|
+
consumeWhitespace(tokens);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (tokens[0].typ == EnumToken.FunctionTokenType) {
|
|
60
|
+
if (!['url-prefix', 'domain', 'media-document', 'regexp'].some((t) => t.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0)) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
return {
|
|
63
|
+
valid: ValidationLevel.Drop,
|
|
64
|
+
matches: [],
|
|
65
|
+
node: tokens[0],
|
|
66
|
+
syntax: '@document',
|
|
67
|
+
error: 'unexpected token',
|
|
68
|
+
tokens
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const children = tokens[0].chi.slice();
|
|
72
|
+
consumeWhitespace(children);
|
|
73
|
+
if (children.length == 0) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return {
|
|
76
|
+
valid: ValidationLevel.Drop,
|
|
77
|
+
matches: [],
|
|
78
|
+
node: tokens[0],
|
|
79
|
+
syntax: '@document',
|
|
80
|
+
error: 'expecting string argument',
|
|
81
|
+
tokens
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (children[0].typ == EnumToken.StringTokenType) {
|
|
85
|
+
children.shift();
|
|
86
|
+
consumeWhitespace(children);
|
|
87
|
+
}
|
|
88
|
+
if (children.length > 0) {
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
return {
|
|
91
|
+
valid: ValidationLevel.Drop,
|
|
92
|
+
matches: [],
|
|
93
|
+
node: children[0],
|
|
94
|
+
syntax: '@document',
|
|
95
|
+
error: 'unexpected token',
|
|
96
|
+
tokens
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
tokens.shift();
|
|
100
|
+
consumeWhitespace(tokens);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
return {
|
|
105
|
+
valid: ValidationLevel.Valid,
|
|
106
|
+
matches: [],
|
|
107
|
+
node: atRule,
|
|
108
|
+
syntax: '@document',
|
|
109
|
+
error: '',
|
|
110
|
+
tokens
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { validateAtRuleDocument };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ValidationLevel } from '../../ast/types.js';
|
|
2
|
+
import '../../ast/minify.js';
|
|
3
|
+
import '../../ast/walk.js';
|
|
4
|
+
import '../../parser/parse.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
8
|
+
import { validateFamilyName } from '../syntaxes/family-name.js';
|
|
9
|
+
import '../syntaxes/complex-selector.js';
|
|
10
|
+
import '../parser/types.js';
|
|
11
|
+
import '../parser/parse.js';
|
|
12
|
+
import '../config.js';
|
|
13
|
+
|
|
14
|
+
function validateAtRuleFontFeatureValues(atRule, options, root) {
|
|
15
|
+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return {
|
|
18
|
+
valid: ValidationLevel.Drop,
|
|
19
|
+
matches: [],
|
|
20
|
+
node: null,
|
|
21
|
+
syntax: '@' + atRule.nam,
|
|
22
|
+
error: 'expected at-rule prelude',
|
|
23
|
+
tokens: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const result = validateFamilyName(atRule.tokens, atRule);
|
|
27
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
if (!('chi' in atRule)) {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
return {
|
|
33
|
+
valid: ValidationLevel.Drop,
|
|
34
|
+
matches: [],
|
|
35
|
+
node: atRule,
|
|
36
|
+
syntax: '@' + atRule.nam,
|
|
37
|
+
error: 'expected at-rule body',
|
|
38
|
+
tokens: []
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
return {
|
|
43
|
+
valid: ValidationLevel.Valid,
|
|
44
|
+
matches: [],
|
|
45
|
+
node: atRule,
|
|
46
|
+
syntax: '@' + atRule.nam,
|
|
47
|
+
error: '',
|
|
48
|
+
tokens: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { validateAtRuleFontFeatureValues };
|