@tbela99/css-parser 0.9.1 → 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 (99) hide show
  1. package/CHANGELOG.md +265 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +29 -17
  4. package/dist/index-umd-web.js +7461 -4360
  5. package/dist/index.cjs +8608 -5507
  6. package/dist/index.d.ts +203 -61
  7. package/dist/lib/ast/expand.js +2 -1
  8. package/dist/lib/ast/features/calc.js +19 -11
  9. package/dist/lib/ast/features/index.js +1 -0
  10. package/dist/lib/ast/features/inlinecssvariables.js +47 -29
  11. package/dist/lib/ast/features/prefix.js +117 -91
  12. package/dist/lib/ast/features/shorthand.js +34 -14
  13. package/dist/lib/ast/features/transform.js +67 -0
  14. package/dist/lib/ast/features/type.js +7 -0
  15. package/dist/lib/ast/math/expression.js +20 -10
  16. package/dist/lib/ast/math/math.js +20 -2
  17. package/dist/lib/ast/minify.js +209 -80
  18. package/dist/lib/ast/transform/compute.js +337 -0
  19. package/dist/lib/ast/transform/convert.js +33 -0
  20. package/dist/lib/ast/transform/matrix.js +112 -0
  21. package/dist/lib/ast/transform/minify.js +296 -0
  22. package/dist/lib/ast/transform/perspective.js +10 -0
  23. package/dist/lib/ast/transform/rotate.js +40 -0
  24. package/dist/lib/ast/transform/scale.js +32 -0
  25. package/dist/lib/ast/transform/skew.js +23 -0
  26. package/dist/lib/ast/transform/translate.js +32 -0
  27. package/dist/lib/ast/transform/utils.js +198 -0
  28. package/dist/lib/ast/types.js +18 -15
  29. package/dist/lib/ast/walk.js +54 -22
  30. package/dist/lib/fs/resolve.js +10 -0
  31. package/dist/lib/parser/declaration/list.js +48 -45
  32. package/dist/lib/parser/declaration/map.js +1 -0
  33. package/dist/lib/parser/declaration/set.js +2 -1
  34. package/dist/lib/parser/parse.js +449 -340
  35. package/dist/lib/parser/tokenize.js +147 -72
  36. package/dist/lib/parser/utils/declaration.js +5 -4
  37. package/dist/lib/parser/utils/type.js +2 -1
  38. package/dist/lib/renderer/color/a98rgb.js +2 -1
  39. package/dist/lib/renderer/color/{colormix.js → color-mix.js} +16 -7
  40. package/dist/lib/renderer/color/color.js +264 -170
  41. package/dist/lib/renderer/color/hex.js +19 -8
  42. package/dist/lib/renderer/color/hsl.js +9 -3
  43. package/dist/lib/renderer/color/hwb.js +2 -1
  44. package/dist/lib/renderer/color/lab.js +10 -1
  45. package/dist/lib/renderer/color/lch.js +10 -1
  46. package/dist/lib/renderer/color/oklab.js +10 -1
  47. package/dist/lib/renderer/color/oklch.js +10 -1
  48. package/dist/lib/renderer/color/p3.js +2 -1
  49. package/dist/lib/renderer/color/rec2020.js +2 -1
  50. package/dist/lib/renderer/color/relativecolor.js +27 -32
  51. package/dist/lib/renderer/color/rgb.js +14 -10
  52. package/dist/lib/renderer/color/srgb.js +48 -23
  53. package/dist/lib/renderer/color/utils/components.js +18 -6
  54. package/dist/lib/renderer/color/utils/constants.js +47 -3
  55. package/dist/lib/renderer/color/xyz.js +2 -1
  56. package/dist/lib/renderer/color/xyzd50.js +2 -1
  57. package/dist/lib/renderer/render.js +108 -43
  58. package/dist/lib/syntax/syntax.js +267 -136
  59. package/dist/lib/validation/at-rules/container.js +81 -103
  60. package/dist/lib/validation/at-rules/counter-style.js +9 -8
  61. package/dist/lib/validation/at-rules/custom-media.js +13 -15
  62. package/dist/lib/validation/at-rules/document.js +22 -27
  63. package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
  64. package/dist/lib/validation/at-rules/import.js +30 -81
  65. package/dist/lib/validation/at-rules/keyframes.js +19 -23
  66. package/dist/lib/validation/at-rules/layer.js +5 -5
  67. package/dist/lib/validation/at-rules/media.js +42 -53
  68. package/dist/lib/validation/at-rules/namespace.js +19 -23
  69. package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
  70. package/dist/lib/validation/at-rules/page.js +8 -7
  71. package/dist/lib/validation/at-rules/supports.js +73 -82
  72. package/dist/lib/validation/at-rules/when.js +32 -36
  73. package/dist/lib/validation/atrule.js +15 -18
  74. package/dist/lib/validation/config.js +24 -1
  75. package/dist/lib/validation/config.json.js +563 -63
  76. package/dist/lib/validation/parser/parse.js +196 -185
  77. package/dist/lib/validation/parser/types.js +1 -1
  78. package/dist/lib/validation/selector.js +8 -5
  79. package/dist/lib/validation/syntax.js +724 -1405
  80. package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
  81. package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
  82. package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
  83. package/dist/lib/validation/syntaxes/family-name.js +9 -8
  84. package/dist/lib/validation/syntaxes/keyframe-block-list.js +6 -5
  85. package/dist/lib/validation/syntaxes/keyframe-selector.js +23 -105
  86. package/dist/lib/validation/syntaxes/layer-name.js +6 -5
  87. package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
  88. package/dist/lib/validation/syntaxes/relative-selector.js +17 -15
  89. package/dist/lib/validation/syntaxes/url.js +18 -22
  90. package/dist/lib/validation/utils/list.js +20 -2
  91. package/dist/lib/validation/utils/whitespace.js +2 -1
  92. package/dist/node/index.js +4 -2
  93. package/dist/node/load.js +6 -1
  94. package/dist/web/index.js +4 -2
  95. package/dist/web/load.js +5 -0
  96. package/package.json +16 -15
  97. package/dist/lib/renderer/color/prophotoRgb.js +0 -56
  98. package/dist/lib/validation/declaration.js +0 -94
  99. package/dist/lib/validation/syntaxes/image.js +0 -29
@@ -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,
@@ -1,16 +1,16 @@
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 { validateAtRuleMediaQueryList } from './media.js';
9
10
  import { consumeWhitespace } from '../utils/whitespace.js';
10
11
  import { validateLayerName } from '../syntaxes/layer-name.js';
11
12
  import '../syntaxes/complex-selector.js';
12
- import '../parser/types.js';
13
- import '../parser/parse.js';
13
+ import '../syntax.js';
14
14
  import '../config.js';
15
15
  import { validateAtRuleSupportsConditions } from './supports.js';
16
16
 
@@ -18,35 +18,32 @@ function validateAtRuleImport(atRule, options, root) {
18
18
  if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
19
19
  // @ts-ignore
20
20
  return {
21
- valid: ValidationLevel.Drop,
22
- matches: [],
21
+ valid: SyntaxValidationResult.Drop,
22
+ context: [],
23
23
  node: null,
24
24
  syntax: '@' + atRule.nam,
25
- error: 'expected @import media query list',
26
- tokens: []
25
+ error: 'expected @import media query list'
27
26
  };
28
27
  }
29
28
  if ('chi' in atRule) {
30
29
  // @ts-ignore
31
30
  return {
32
- valid: ValidationLevel.Drop,
33
- matches: [],
31
+ valid: SyntaxValidationResult.Drop,
32
+ context: [],
34
33
  node: null,
35
34
  syntax: '@' + atRule.nam,
36
- error: 'unexpected at-rule body',
37
- tokens: []
35
+ error: 'unexpected at-rule body'
38
36
  };
39
37
  }
40
38
  const tokens = atRule.tokens.filter((t) => ![EnumToken.CommentTokenType].includes(t.typ));
41
39
  if (tokens.length == 0) {
42
40
  // @ts-ignore
43
41
  return {
44
- valid: ValidationLevel.Drop,
45
- matches: [],
42
+ valid: SyntaxValidationResult.Drop,
43
+ context: [],
46
44
  node: null,
47
45
  syntax: '@' + atRule.nam,
48
- error: 'expected @import media query list',
49
- tokens: []
46
+ error: 'expected @import media query list'
50
47
  };
51
48
  }
52
49
  if (tokens[0].typ == EnumToken.StringTokenType) {
@@ -59,12 +56,11 @@ function validateAtRuleImport(atRule, options, root) {
59
56
  if (slice.length != 1 || ![EnumToken.StringTokenType, EnumToken.UrlTokenTokenType].includes(slice[0].typ)) {
60
57
  // @ts-ignore
61
58
  return {
62
- valid: ValidationLevel.Drop,
63
- matches: [],
59
+ valid: SyntaxValidationResult.Drop,
60
+ context: [],
64
61
  node: tokens[0],
65
62
  syntax: '@' + atRule.nam,
66
- error: 'invalid url()',
67
- tokens
63
+ error: 'invalid url()'
68
64
  };
69
65
  }
70
66
  else {
@@ -73,12 +69,11 @@ function validateAtRuleImport(atRule, options, root) {
73
69
  if (!consumeWhitespace(tokens)) {
74
70
  // @ts-ignore
75
71
  return {
76
- valid: ValidationLevel.Drop,
77
- matches: [],
72
+ valid: SyntaxValidationResult.Drop,
73
+ context: [],
78
74
  node: tokens[0],
79
75
  syntax: '@' + atRule.nam,
80
- error: 'expecting whitespace',
81
- tokens
76
+ error: 'expecting whitespace'
82
77
  };
83
78
  }
84
79
  }
@@ -89,12 +84,11 @@ function validateAtRuleImport(atRule, options, root) {
89
84
  else {
90
85
  // @ts-ignore
91
86
  return {
92
- valid: ValidationLevel.Drop,
93
- matches: [],
87
+ valid: SyntaxValidationResult.Drop,
88
+ context: [],
94
89
  node: tokens[0],
95
90
  syntax: '@' + atRule.nam,
96
- error: 'expecting url() or string',
97
- tokens
91
+ error: 'expecting url() or string'
98
92
  };
99
93
  }
100
94
  if (tokens.length > 0) {
@@ -107,12 +101,11 @@ function validateAtRuleImport(atRule, options, root) {
107
101
  if (!consumeWhitespace(tokens)) {
108
102
  // @ts-ignore
109
103
  return {
110
- valid: ValidationLevel.Drop,
111
- matches: [],
104
+ valid: SyntaxValidationResult.Drop,
105
+ context: [],
112
106
  node: tokens[0],
113
107
  syntax: '@' + atRule.nam,
114
- error: 'expecting whitespace',
115
- tokens
108
+ error: 'expecting whitespace'
116
109
  };
117
110
  }
118
111
  }
@@ -122,7 +115,7 @@ function validateAtRuleImport(atRule, options, root) {
122
115
  // @ts-ignore
123
116
  if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
124
117
  const result = validateLayerName(tokens[0].chi);
125
- if (result.valid == ValidationLevel.Drop) {
118
+ if (result.valid == SyntaxValidationResult.Drop) {
126
119
  return result;
127
120
  }
128
121
  tokens.shift();
@@ -132,7 +125,7 @@ function validateAtRuleImport(atRule, options, root) {
132
125
  // @ts-ignore
133
126
  if ('supports'.localeCompare(tokens[0]?.val, undefined, { sensitivity: 'base' }) == 0) {
134
127
  const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
135
- if (result.valid == ValidationLevel.Drop) {
128
+ if (result.valid == SyntaxValidationResult.Drop) {
136
129
  return result;
137
130
  }
138
131
  tokens.shift();
@@ -141,60 +134,16 @@ function validateAtRuleImport(atRule, options, root) {
141
134
  }
142
135
  }
143
136
  }
144
- // if (tokens.length > 0) {
145
- //
146
- // // @ts-ignore
147
- // if (tokens[0].typ == EnumToken.AtRuleTokenType) {
148
- //
149
- // if ((tokens[0] as AstAtRule).nam != 'supports') {
150
- //
151
- // // @ts-ignore
152
- // return {
153
- // valid: ValidationLevel.Drop,
154
- // matches: [],
155
- // node: tokens[0],
156
- // syntax: '@' + atRule.nam,
157
- // error: 'expecting @supports or media query list',
158
- // tokens
159
- // }
160
- // }
161
- //
162
- // // @ts-ignore
163
- // const result: ValidationSyntaxResult = validateAtRuleSupports(tokens[0] as AstAtRule, options, atRule);
164
- //
165
- // if (result.valid == ValidationLevel.Drop) {
166
- //
167
- // return result;
168
- // }
169
- //
170
- // tokens.shift();
171
- //
172
- // // @ts-ignore
173
- // if (!consumeWhitespace(tokens)) {
174
- //
175
- // // @ts-ignore
176
- // return {
177
- // valid: ValidationLevel.Drop,
178
- // matches: [],
179
- // node: tokens[0],
180
- // syntax: '@' + atRule.nam,
181
- // error: 'expecting whitespace',
182
- // tokens
183
- // }
184
- // }
185
- // }
186
- // }
187
137
  if (tokens.length > 0) {
188
138
  return validateAtRuleMediaQueryList(tokens, atRule);
189
139
  }
190
140
  // @ts-ignore
191
141
  return {
192
- valid: ValidationLevel.Valid,
193
- matches: [],
142
+ valid: SyntaxValidationResult.Valid,
143
+ context: [],
194
144
  node: null,
195
145
  syntax: '@' + atRule.nam,
196
- error: '',
197
- tokens: []
146
+ error: ''
198
147
  };
199
148
  }
200
149
 
@@ -1,22 +1,22 @@
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
 
10
11
  function validateAtRuleKeyframes(atRule, options, root) {
11
12
  if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
12
13
  // @ts-ignore
13
14
  return {
14
- valid: ValidationLevel.Drop,
15
- matches: [],
15
+ valid: SyntaxValidationResult.Drop,
16
+ context: [],
16
17
  node: atRule,
17
- syntax: '@document',
18
- error: 'expecting at-rule prelude',
19
- tokens: []
18
+ syntax: '@keyframes',
19
+ error: 'expecting at-rule prelude'
20
20
  };
21
21
  }
22
22
  const tokens = atRule.tokens.slice();
@@ -24,23 +24,21 @@ function validateAtRuleKeyframes(atRule, options, root) {
24
24
  if (tokens.length == 0) {
25
25
  // @ts-ignore
26
26
  return {
27
- valid: ValidationLevel.Drop,
28
- matches: [],
27
+ valid: SyntaxValidationResult.Drop,
28
+ context: [],
29
29
  node: atRule,
30
30
  syntax: '@keyframes',
31
- error: 'expecting at-rule prelude',
32
- tokens
31
+ error: 'expecting at-rule prelude'
33
32
  };
34
33
  }
35
34
  if (![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
36
35
  // @ts-ignore
37
36
  return {
38
- valid: ValidationLevel.Drop,
39
- matches: [],
37
+ valid: SyntaxValidationResult.Drop,
38
+ context: [],
40
39
  node: atRule,
41
40
  syntax: '@keyframes',
42
- error: 'expecting ident or string token',
43
- tokens
41
+ error: 'expecting ident or string token'
44
42
  };
45
43
  }
46
44
  tokens.shift();
@@ -48,22 +46,20 @@ function validateAtRuleKeyframes(atRule, options, root) {
48
46
  if (tokens.length > 0) {
49
47
  // @ts-ignore
50
48
  return {
51
- valid: ValidationLevel.Drop,
52
- matches: [],
49
+ valid: SyntaxValidationResult.Drop,
50
+ context: [],
53
51
  node: tokens[0],
54
52
  syntax: '@keyframes',
55
- error: 'unexpected token',
56
- tokens
53
+ error: 'unexpected token'
57
54
  };
58
55
  }
59
56
  // @ts-ignore
60
57
  return {
61
- valid: ValidationLevel.Valid,
62
- matches: [],
58
+ valid: SyntaxValidationResult.Valid,
59
+ context: [],
63
60
  node: atRule,
64
61
  syntax: '@keyframes',
65
- error: '',
66
- tokens
62
+ error: ''
67
63
  };
68
64
  }
69
65
 
@@ -1,14 +1,14 @@
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 { validateLayerName } from '../syntaxes/layer-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 validateAtRuleLayer(atRule, options, root) {
@@ -16,7 +16,7 @@ function validateAtRuleLayer(atRule, options, root) {
16
16
  if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
17
17
  // @ts-ignore
18
18
  return {
19
- valid: ValidationLevel.Valid,
19
+ valid: SyntaxValidationResult.Valid,
20
20
  matches: [],
21
21
  node: atRule,
22
22
  syntax: '@layer',
@@ -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 '../../renderer/color/utils/constants.js';
6
- import '../../renderer/sourcemap/lib/encode.js';
5
+ import '../../parser/tokenize.js';
7
6
  import '../../parser/utils/config.js';
7
+ import { generalEnclosedFunc } from '../../renderer/color/utils/constants.js';
8
+ import '../../renderer/sourcemap/lib/encode.js';
8
9
  import { consumeWhitespace } from '../utils/whitespace.js';
9
10
  import { splitTokenList } from '../utils/list.js';
10
11
 
@@ -13,8 +14,8 @@ function validateAtRuleMedia(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
21
  error: '',
@@ -26,37 +27,34 @@ function validateAtRuleMedia(atRule, options, root) {
26
27
  consumeWhitespace(slice);
27
28
  if (slice.length == 0) {
28
29
  return {
29
- valid: ValidationLevel.Valid,
30
- matches: [],
30
+ valid: SyntaxValidationResult.Valid,
31
+ context: [],
31
32
  node: atRule,
32
33
  syntax: '@media',
33
- error: '',
34
- tokens: []
34
+ error: ''
35
35
  };
36
36
  }
37
37
  result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
38
- if (result.valid == ValidationLevel.Drop) {
38
+ if (result.valid == SyntaxValidationResult.Drop) {
39
39
  return result;
40
40
  }
41
41
  if (!('chi' in atRule)) {
42
42
  // @ts-ignore
43
43
  return {
44
- valid: ValidationLevel.Drop,
45
- matches: [],
44
+ valid: SyntaxValidationResult.Drop,
45
+ context: [],
46
46
  node: atRule,
47
47
  syntax: '@media',
48
- error: 'expected at-rule body',
49
- tokens: []
48
+ error: 'expected at-rule body'
50
49
  };
51
50
  }
52
51
  // @ts-ignore
53
52
  return {
54
- valid: ValidationLevel.Valid,
55
- matches: [],
53
+ valid: SyntaxValidationResult.Valid,
54
+ context: [],
56
55
  node: atRule,
57
56
  syntax: '@media',
58
- error: '',
59
- tokens: []
57
+ error: ''
60
58
  };
61
59
  }
62
60
  function validateAtRuleMediaQueryList(tokenList, atRule) {
@@ -74,12 +72,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
74
72
  if (tokens.length == 0) {
75
73
  // @ts-ignore
76
74
  result = {
77
- valid: ValidationLevel.Drop,
78
- matches: [],
75
+ valid: SyntaxValidationResult.Drop,
76
+ context: [],
79
77
  node: tokens[0] ?? atRule,
80
78
  syntax: '@media',
81
- error: 'unexpected token',
82
- tokens: []
79
+ error: 'unexpected token'
83
80
  };
84
81
  continue;
85
82
  }
@@ -92,15 +89,14 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
92
89
  }
93
90
  else {
94
91
  result = {
95
- valid: ValidationLevel.Drop,
96
- matches: [],
92
+ valid: SyntaxValidationResult.Drop,
93
+ context: [],
97
94
  node: tokens[0] ?? atRule,
98
95
  syntax: '@media',
99
- error: 'expecting media feature or media condition',
100
- tokens: []
96
+ error: 'expecting media feature or media condition'
101
97
  };
102
98
  }
103
- if (result.valid == ValidationLevel.Drop) {
99
+ if (result.valid == SyntaxValidationResult.Drop) {
104
100
  break;
105
101
  }
106
102
  result = null;
@@ -113,12 +109,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
113
109
  if (previousToken?.typ != EnumToken.ParensTokenType) {
114
110
  // @ts-ignore
115
111
  result = {
116
- valid: ValidationLevel.Drop,
117
- matches: [],
112
+ valid: SyntaxValidationResult.Drop,
113
+ context: [],
118
114
  node: tokens[0] ?? atRule,
119
115
  syntax: '@media',
120
- error: 'expected media query list',
121
- tokens: []
116
+ error: 'expected media query list'
122
117
  };
123
118
  break;
124
119
  }
@@ -126,12 +121,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
126
121
  else if (![EnumToken.MediaFeatureOrTokenType, EnumToken.MediaFeatureAndTokenType].includes(tokens[0].typ)) {
127
122
  // @ts-ignore
128
123
  result = {
129
- valid: ValidationLevel.Drop,
130
- matches: [],
124
+ valid: SyntaxValidationResult.Drop,
125
+ context: [],
131
126
  node: tokens[0] ?? atRule,
132
127
  syntax: '@media',
133
- error: 'expected and/or',
134
- tokens: []
128
+ error: 'expected and/or'
135
129
  };
136
130
  break;
137
131
  }
@@ -141,12 +135,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
141
135
  if (mediaFeatureType.typ != tokens[0].typ) {
142
136
  // @ts-ignore
143
137
  result = {
144
- valid: ValidationLevel.Drop,
145
- matches: [],
138
+ valid: SyntaxValidationResult.Drop,
139
+ context: [],
146
140
  node: tokens[0] ?? atRule,
147
141
  syntax: '@media',
148
- error: 'mixing and/or not allowed at the same level',
149
- tokens: []
142
+ error: 'mixing and/or not allowed at the same level'
150
143
  };
151
144
  break;
152
145
  }
@@ -155,12 +148,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
155
148
  if (tokens.length == 0) {
156
149
  // @ts-ignore
157
150
  result = {
158
- valid: ValidationLevel.Drop,
159
- matches: [],
151
+ valid: SyntaxValidationResult.Drop,
152
+ context: [],
160
153
  node: tokens[0] ?? atRule,
161
154
  syntax: '@media',
162
- error: 'expected media-condition',
163
- tokens: []
155
+ error: 'expected media-condition'
164
156
  };
165
157
  break;
166
158
  }
@@ -175,12 +167,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
175
167
  }
176
168
  if (matched.length == 0) {
177
169
  return {
178
- valid: ValidationLevel.Drop,
179
- matches: [],
170
+ valid: SyntaxValidationResult.Drop,
171
+ context: [],
180
172
  node: atRule,
181
173
  syntax: '@media',
182
- error: 'expected media query list',
183
- tokens: []
174
+ error: 'expected media query list'
184
175
  };
185
176
  }
186
177
  tokenList.length = 0;
@@ -200,12 +191,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
200
191
  }
201
192
  // @ts-ignore
202
193
  return {
203
- valid: ValidationLevel.Valid,
204
- matches: [],
194
+ valid: SyntaxValidationResult.Valid,
195
+ context: [],
205
196
  node: atRule,
206
197
  syntax: '@media',
207
- error: '',
208
- tokens: []
198
+ error: ''
209
199
  };
210
200
  }
211
201
  function validateCustomMediaCondition(token, atRule) {
@@ -225,7 +215,7 @@ function validateMediaCondition(token, atRule) {
225
215
  if (token.typ == EnumToken.MediaFeatureNotTokenType) {
226
216
  return validateMediaCondition(token.val, atRule);
227
217
  }
228
- if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType && ['media', 'supports', 'selector'].includes(token.val))) {
218
+ if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType && generalEnclosedFunc.includes(token.val))) {
229
219
  return false;
230
220
  }
231
221
  const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
@@ -241,7 +231,6 @@ function validateMediaCondition(token, atRule) {
241
231
  if (chi[0].typ == EnumToken.MediaQueryConditionTokenType) {
242
232
  return chi[0].l.typ == EnumToken.IdenTokenType;
243
233
  }
244
- console.error(chi[0].parent);
245
234
  return false;
246
235
  }
247
236
  function validateMediaFeature(token) {