@tbela99/css-parser 1.4.1 → 1.4.3

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