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