@tbela99/css-parser 0.8.0 → 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 +5 -3
- package/dist/index-umd-web.js +3272 -1898
- package/dist/index.cjs +3272 -1898
- package/dist/index.d.ts +48 -11
- package/dist/lib/ast/expand.js +14 -2
- package/dist/lib/ast/math/expression.js +1 -1
- package/dist/lib/ast/minify.js +30 -16
- package/dist/lib/ast/types.js +1 -0
- package/dist/lib/ast/walk.js +12 -0
- package/dist/lib/parser/declaration/map.js +59 -52
- package/dist/lib/parser/declaration/set.js +0 -12
- package/dist/lib/parser/parse.js +140 -101
- package/dist/lib/parser/tokenize.js +15 -3
- package/dist/lib/renderer/color/hex.js +1 -1
- package/dist/lib/renderer/color/hsl.js +1 -1
- package/dist/lib/renderer/color/hwb.js +2 -2
- package/dist/lib/renderer/color/lab.js +1 -1
- package/dist/lib/renderer/color/lch.js +1 -1
- package/dist/lib/renderer/color/oklab.js +2 -2
- package/dist/lib/renderer/color/oklch.js +1 -1
- package/dist/lib/renderer/color/p3.js +1 -1
- package/dist/lib/renderer/color/prophotoRgb.js +1 -1
- package/dist/lib/renderer/color/prophotorgb.js +1 -1
- package/dist/lib/renderer/color/rgb.js +1 -1
- package/dist/lib/renderer/color/srgb.js +2 -2
- package/dist/lib/renderer/color/utils/constants.js +1 -1
- package/dist/lib/renderer/color/xyz.js +1 -1
- package/dist/lib/renderer/render.js +34 -6
- package/dist/lib/syntax/syntax.js +336 -1
- package/dist/lib/validation/at-rules/container.js +353 -0
- package/dist/lib/validation/at-rules/counter-style.js +2 -2
- package/dist/lib/validation/at-rules/custom-media.js +52 -0
- package/dist/lib/validation/at-rules/else.js +5 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +3 -0
- package/dist/lib/validation/at-rules/import.js +3 -0
- package/dist/lib/validation/at-rules/layer.js +3 -0
- package/dist/lib/validation/at-rules/media.js +117 -29
- package/dist/lib/validation/at-rules/supports.js +11 -11
- package/dist/lib/validation/at-rules/when.js +178 -0
- package/dist/lib/validation/atrule.js +25 -10
- package/dist/lib/validation/config.js +20 -15
- package/dist/lib/validation/config.json.js +162 -42
- package/dist/lib/validation/declaration.js +39 -9
- package/dist/lib/validation/parser/parse.js +91 -13
- package/dist/lib/validation/parser/types.js +1 -0
- package/dist/lib/validation/selector.js +6 -3
- package/dist/lib/validation/syntax.js +50 -4
- package/dist/lib/validation/syntaxes/complex-selector-list.js +16 -12
- package/dist/lib/validation/syntaxes/complex-selector.js +17 -247
- package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
- package/dist/lib/validation/syntaxes/image.js +29 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +1 -1
- package/dist/lib/validation/syntaxes/keyframe-selector.js +1 -1
- package/dist/lib/validation/syntaxes/relative-selector-list.js +43 -13
- package/dist/lib/validation/utils/list.js +2 -2
- package/dist/node/index.js +1 -1
- package/dist/web/index.js +1 -1
- package/package.json +7 -7
|
@@ -25,6 +25,341 @@ const mediaTypes = ['all', 'print', 'screen',
|
|
|
25
25
|
'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
|
|
26
26
|
// https://www.w3.org/TR/css-values-4/#math-function
|
|
27
27
|
const mathFuncs = ['calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
|
|
28
|
+
const webkitPseudoAliasMap = {
|
|
29
|
+
'-webkit-autofill': 'autofill',
|
|
30
|
+
'-webkit-any': 'is',
|
|
31
|
+
'-moz-any': 'is',
|
|
32
|
+
'-webkit-border-after': 'border-block-end',
|
|
33
|
+
'-webkit-border-after-color': 'border-block-end-color',
|
|
34
|
+
'-webkit-border-after-style': 'border-block-end-style',
|
|
35
|
+
'-webkit-border-after-width': 'border-block-end-width',
|
|
36
|
+
'-webkit-border-before': 'border-block-start',
|
|
37
|
+
'-webkit-border-before-color': 'border-block-start-color',
|
|
38
|
+
'-webkit-border-before-style': 'border-block-start-style',
|
|
39
|
+
'-webkit-border-before-width': 'border-block-start-width',
|
|
40
|
+
'-webkit-border-end': 'border-inline-end',
|
|
41
|
+
'-webkit-border-end-color': 'border-inline-end-color',
|
|
42
|
+
'-webkit-border-end-style': 'border-inline-end-style',
|
|
43
|
+
'-webkit-border-end-width': 'border-inline-end-width',
|
|
44
|
+
'-webkit-border-start': 'border-inline-start',
|
|
45
|
+
'-webkit-border-start-color': 'border-inline-start-color',
|
|
46
|
+
'-webkit-border-start-style': 'border-inline-start-style',
|
|
47
|
+
'-webkit-border-start-width': 'border-inline-start-width',
|
|
48
|
+
'-webkit-box-align': 'align-items',
|
|
49
|
+
'-webkit-box-direction': 'flex-direction',
|
|
50
|
+
'-webkit-box-flex': 'flex-grow',
|
|
51
|
+
'-webkit-box-lines': 'flex-flow',
|
|
52
|
+
'-webkit-box-ordinal-group': 'order',
|
|
53
|
+
'-webkit-box-orient': 'flex-direction',
|
|
54
|
+
'-webkit-box-pack': 'justify-content',
|
|
55
|
+
'-webkit-column-break-after': 'break-after',
|
|
56
|
+
'-webkit-column-break-before': 'break-before',
|
|
57
|
+
'-webkit-column-break-inside': 'break-inside',
|
|
58
|
+
'-webkit-font-feature-settings': 'font-feature-settings',
|
|
59
|
+
'-webkit-hyphenate-character': 'hyphenate-character',
|
|
60
|
+
'-webkit-initial-letter': 'initial-letter',
|
|
61
|
+
'-webkit-margin-end': 'margin-block-end',
|
|
62
|
+
'-webkit-margin-start': 'margin-block-start',
|
|
63
|
+
'-webkit-padding-after': 'padding-block-end',
|
|
64
|
+
'-webkit-padding-before': 'padding-block-start',
|
|
65
|
+
'-webkit-padding-end': 'padding-inline-end',
|
|
66
|
+
'-webkit-padding-start': 'padding-inline-start',
|
|
67
|
+
'-webkit-min-device-pixel-ratio': 'min-resolution',
|
|
68
|
+
'-webkit-max-device-pixel-ratio': 'max-resolution'
|
|
69
|
+
};
|
|
70
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
|
|
71
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar
|
|
72
|
+
const webkitExtensions = new Set([
|
|
73
|
+
'-webkit-app-region',
|
|
74
|
+
'-webkit-border-horizontal-spacing',
|
|
75
|
+
'-webkit-border-vertical-spacing',
|
|
76
|
+
'-webkit-box-reflect',
|
|
77
|
+
'-webkit-column-axis',
|
|
78
|
+
'-webkit-column-progression',
|
|
79
|
+
'-webkit-cursor-visibility',
|
|
80
|
+
'-webkit-font-smoothing',
|
|
81
|
+
'-webkit-hyphenate-limit-after',
|
|
82
|
+
'-webkit-hyphenate-limit-before',
|
|
83
|
+
'-webkit-hyphenate-limit-lines',
|
|
84
|
+
'-webkit-line-align',
|
|
85
|
+
'-webkit-line-box-contain',
|
|
86
|
+
'-webkit-line-clamp',
|
|
87
|
+
'-webkit-line-grid',
|
|
88
|
+
'-webkit-line-snap',
|
|
89
|
+
'-webkit-locale',
|
|
90
|
+
'-webkit-logical-height',
|
|
91
|
+
'-webkit-logical-width',
|
|
92
|
+
'-webkit-margin-after',
|
|
93
|
+
'-webkit-margin-before',
|
|
94
|
+
'-webkit-mask-box-image-outset',
|
|
95
|
+
'-webkit-mask-box-image-repeat',
|
|
96
|
+
'-webkit-mask-box-image-slice',
|
|
97
|
+
'-webkit-mask-box-image-source',
|
|
98
|
+
'-webkit-mask-box-image-width',
|
|
99
|
+
'-webkit-mask-box-image',
|
|
100
|
+
'-webkit-mask-composite',
|
|
101
|
+
'-webkit-mask-position-x',
|
|
102
|
+
'-webkit-mask-position-y',
|
|
103
|
+
'-webkit-mask-repeat-x',
|
|
104
|
+
'-webkit-mask-repeat-y',
|
|
105
|
+
'-webkit-mask-source-type',
|
|
106
|
+
'-webkit-max-logical-height',
|
|
107
|
+
'-webkit-max-logical-width',
|
|
108
|
+
'-webkit-min-logical-height',
|
|
109
|
+
'-webkit-min-logical-width',
|
|
110
|
+
'-webkit-nbsp-mode',
|
|
111
|
+
'-webkit-perspective-origin-x',
|
|
112
|
+
'-webkit-perspective-origin-y',
|
|
113
|
+
'-webkit-rtl-ordering',
|
|
114
|
+
'-webkit-tap-highlight-color',
|
|
115
|
+
'-webkit-text-decoration-skip',
|
|
116
|
+
'-webkit-text-decorations-in-effect',
|
|
117
|
+
'-webkit-text-fill-color',
|
|
118
|
+
'-webkit-text-security',
|
|
119
|
+
'-webkit-text-stroke-color',
|
|
120
|
+
'-webkit-text-stroke-width',
|
|
121
|
+
'-webkit-text-stroke',
|
|
122
|
+
'-webkit-text-zoom',
|
|
123
|
+
'-webkit-touch-callout',
|
|
124
|
+
'-webkit-transform-origin-x',
|
|
125
|
+
'-webkit-transform-origin-y',
|
|
126
|
+
'-webkit-transform-origin-z',
|
|
127
|
+
'-webkit-user-drag',
|
|
128
|
+
'-webkit-user-modify',
|
|
129
|
+
'-webkit-border-after',
|
|
130
|
+
'-webkit-border-after-color',
|
|
131
|
+
'-webkit-border-after-style',
|
|
132
|
+
'-webkit-border-after-width',
|
|
133
|
+
'-webkit-border-before',
|
|
134
|
+
'-webkit-border-before-color',
|
|
135
|
+
'-webkit-border-before-style',
|
|
136
|
+
'-webkit-border-before-width',
|
|
137
|
+
'-webkit-border-end',
|
|
138
|
+
'-webkit-border-end-color',
|
|
139
|
+
'-webkit-border-end-style',
|
|
140
|
+
'-webkit-border-end-width',
|
|
141
|
+
'-webkit-border-start',
|
|
142
|
+
'-webkit-border-start-color',
|
|
143
|
+
'-webkit-border-start-style',
|
|
144
|
+
'-webkit-border-start-width',
|
|
145
|
+
'-webkit-box-align',
|
|
146
|
+
'-webkit-box-direction',
|
|
147
|
+
'-webkit-box-flex-group',
|
|
148
|
+
'-webkit-box-flex',
|
|
149
|
+
'-webkit-box-lines',
|
|
150
|
+
'-webkit-box-ordinal-group',
|
|
151
|
+
'-webkit-box-orient',
|
|
152
|
+
'-webkit-box-pack',
|
|
153
|
+
'-webkit-column-break-after',
|
|
154
|
+
'-webkit-column-break-before',
|
|
155
|
+
'-webkit-column-break-inside',
|
|
156
|
+
'-webkit-font-feature-settings',
|
|
157
|
+
'-webkit-hyphenate-character',
|
|
158
|
+
'-webkit-initial-letter',
|
|
159
|
+
'-webkit-margin-end',
|
|
160
|
+
'-webkit-margin-start',
|
|
161
|
+
'-webkit-padding-after',
|
|
162
|
+
'-webkit-padding-before',
|
|
163
|
+
'-webkit-padding-end',
|
|
164
|
+
'-webkit-padding-start',
|
|
165
|
+
'-webkit-fill-available',
|
|
166
|
+
':-webkit-animating-full-screen-transition',
|
|
167
|
+
':-webkit-any',
|
|
168
|
+
':-webkit-any-link',
|
|
169
|
+
':-webkit-autofill',
|
|
170
|
+
':-webkit-autofill-strong-password',
|
|
171
|
+
':-webkit-drag',
|
|
172
|
+
':-webkit-full-page-media',
|
|
173
|
+
':-webkit-full-screen*',
|
|
174
|
+
':-webkit-full-screen-ancestor',
|
|
175
|
+
':-webkit-full-screen-document',
|
|
176
|
+
':-webkit-full-screen-controls-hidden',
|
|
177
|
+
'::-webkit-file-upload-button*',
|
|
178
|
+
'::-webkit-inner-spin-button',
|
|
179
|
+
'::-webkit-input-placeholder',
|
|
180
|
+
'::-webkit-meter-bar',
|
|
181
|
+
'::-webkit-meter-even-less-good-value',
|
|
182
|
+
'::-webkit-meter-inner-element',
|
|
183
|
+
'::-webkit-meter-optimum-value',
|
|
184
|
+
'::-webkit-meter-suboptimum-value',
|
|
185
|
+
'::-webkit-progress-bar',
|
|
186
|
+
'::-webkit-progress-inner-element',
|
|
187
|
+
'::-webkit-progress-value',
|
|
188
|
+
'::-webkit-search-cancel-button',
|
|
189
|
+
'::-webkit-search-results-button',
|
|
190
|
+
'::-webkit-slider-runnable-track',
|
|
191
|
+
'::-webkit-slider-thumb',
|
|
192
|
+
'-webkit-animation',
|
|
193
|
+
'-webkit-device-pixel-ratio',
|
|
194
|
+
'-webkit-transform-2d',
|
|
195
|
+
'-webkit-transform-3d',
|
|
196
|
+
'-webkit-transition',
|
|
197
|
+
'::-webkit-scrollbar',
|
|
198
|
+
'::-webkit-scrollbar-button',
|
|
199
|
+
'::-webkit-scrollbar',
|
|
200
|
+
'::-webkit-scrollbar-thumb',
|
|
201
|
+
'::-webkit-scrollbar-track',
|
|
202
|
+
'::-webkit-scrollbar-track-piece',
|
|
203
|
+
'::-webkit-scrollbar:vertical',
|
|
204
|
+
'::-webkit-scrollbar-corner ',
|
|
205
|
+
'::-webkit-resizer',
|
|
206
|
+
':vertical',
|
|
207
|
+
':horizontal',
|
|
208
|
+
]);
|
|
209
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
|
|
210
|
+
const mozExtensions = new Set([
|
|
211
|
+
'-moz-box-align',
|
|
212
|
+
'-moz-box-direction',
|
|
213
|
+
'-moz-box-flex',
|
|
214
|
+
'-moz-box-ordinal-group',
|
|
215
|
+
'-moz-box-orient',
|
|
216
|
+
'-moz-box-pack',
|
|
217
|
+
'-moz-float-edge',
|
|
218
|
+
'-moz-force-broken-image-icon',
|
|
219
|
+
'-moz-image-region',
|
|
220
|
+
'-moz-orient',
|
|
221
|
+
'-moz-osx-font-smoothing',
|
|
222
|
+
'-moz-user-focus',
|
|
223
|
+
'-moz-user-input',
|
|
224
|
+
'-moz-user-modify',
|
|
225
|
+
'-moz-animation',
|
|
226
|
+
'-moz-animation-delay',
|
|
227
|
+
'-moz-animation-direction',
|
|
228
|
+
'-moz-animation-duration',
|
|
229
|
+
'-moz-animation-fill-mode',
|
|
230
|
+
'-moz-animation-iteration-count',
|
|
231
|
+
'-moz-animation-name',
|
|
232
|
+
'-moz-animation-play-state',
|
|
233
|
+
'-moz-animation-timing-function',
|
|
234
|
+
'-moz-appearance',
|
|
235
|
+
'-moz-backface-visibility',
|
|
236
|
+
'-moz-background-clip',
|
|
237
|
+
'-moz-background-origin',
|
|
238
|
+
'-moz-background-inline-policy',
|
|
239
|
+
'-moz-background-size',
|
|
240
|
+
'-moz-border-end',
|
|
241
|
+
'-moz-border-end-color',
|
|
242
|
+
'-moz-border-end-style',
|
|
243
|
+
'-moz-border-end-width',
|
|
244
|
+
'-moz-border-image',
|
|
245
|
+
'-moz-border-start',
|
|
246
|
+
'-moz-border-start-color',
|
|
247
|
+
'-moz-border-start-style',
|
|
248
|
+
'-moz-border-start-width',
|
|
249
|
+
'-moz-box-sizing',
|
|
250
|
+
'clip-path',
|
|
251
|
+
'-moz-column-count',
|
|
252
|
+
'-moz-column-fill',
|
|
253
|
+
'-moz-column-gap',
|
|
254
|
+
'-moz-column-width',
|
|
255
|
+
'-moz-column-rule',
|
|
256
|
+
'-moz-column-rule-width',
|
|
257
|
+
'-moz-column-rule-style',
|
|
258
|
+
'-moz-column-rule-color',
|
|
259
|
+
'filter',
|
|
260
|
+
'-moz-font-feature-settings',
|
|
261
|
+
'-moz-font-language-override',
|
|
262
|
+
'-moz-hyphens',
|
|
263
|
+
'-moz-margin-end',
|
|
264
|
+
'-moz-margin-start',
|
|
265
|
+
'mask',
|
|
266
|
+
'-moz-opacity',
|
|
267
|
+
'-moz-outline',
|
|
268
|
+
'-moz-outline-color',
|
|
269
|
+
'-moz-outline-offset',
|
|
270
|
+
'-moz-outline-style',
|
|
271
|
+
'-moz-outline-width',
|
|
272
|
+
'-moz-padding-end',
|
|
273
|
+
'-moz-padding-start',
|
|
274
|
+
'-moz-perspective',
|
|
275
|
+
'-moz-perspective-origin',
|
|
276
|
+
'pointer-events',
|
|
277
|
+
'-moz-tab-size',
|
|
278
|
+
'-moz-text-align-last',
|
|
279
|
+
'-moz-text-decoration-color',
|
|
280
|
+
'-moz-text-decoration-line',
|
|
281
|
+
'-moz-text-decoration-style',
|
|
282
|
+
'-moz-text-size-adjust',
|
|
283
|
+
'-moz-transform',
|
|
284
|
+
'-moz-transform-origin',
|
|
285
|
+
'-moz-transform-style',
|
|
286
|
+
'-moz-transition',
|
|
287
|
+
'-moz-transition-delay',
|
|
288
|
+
'-moz-transition-duration',
|
|
289
|
+
'-moz-transition-property',
|
|
290
|
+
'-moz-transition-timing-function',
|
|
291
|
+
'-moz-user-select',
|
|
292
|
+
'-moz-initial',
|
|
293
|
+
'-moz-appearance',
|
|
294
|
+
'-moz-linear-gradient',
|
|
295
|
+
'-moz-radial-gradient',
|
|
296
|
+
'-moz-element',
|
|
297
|
+
'-moz-image-rect',
|
|
298
|
+
'::-moz-anonymous-block',
|
|
299
|
+
'::-moz-anonymous-positioned-block',
|
|
300
|
+
':-moz-any',
|
|
301
|
+
':-moz-any-link',
|
|
302
|
+
':-moz-broken',
|
|
303
|
+
'::-moz-canvas',
|
|
304
|
+
'::-moz-color-swatch',
|
|
305
|
+
'::-moz-cell-content',
|
|
306
|
+
':-moz-drag-over',
|
|
307
|
+
':-moz-first-node',
|
|
308
|
+
'::-moz-focus-inner',
|
|
309
|
+
'::-moz-focus-outer',
|
|
310
|
+
':-moz-full-screen',
|
|
311
|
+
':-moz-full-screen-ancestor',
|
|
312
|
+
':-moz-handler-blocked',
|
|
313
|
+
':-moz-handler-crashed',
|
|
314
|
+
':-moz-handler-disabled',
|
|
315
|
+
'::-moz-inline-table',
|
|
316
|
+
':-moz-last-node',
|
|
317
|
+
'::-moz-list-bullet',
|
|
318
|
+
'::-moz-list-number',
|
|
319
|
+
':-moz-loading',
|
|
320
|
+
':-moz-locale-dir',
|
|
321
|
+
':-moz-locale-dir',
|
|
322
|
+
':-moz-lwtheme',
|
|
323
|
+
':-moz-lwtheme-brighttext',
|
|
324
|
+
':-moz-lwtheme-darktext',
|
|
325
|
+
'::-moz-meter-bar',
|
|
326
|
+
':-moz-native-anonymous',
|
|
327
|
+
':-moz-only-whitespace',
|
|
328
|
+
'::-moz-pagebreak',
|
|
329
|
+
'::-moz-pagecontent',
|
|
330
|
+
':-moz-placeholder',
|
|
331
|
+
'::-moz-placeholder',
|
|
332
|
+
'::-moz-progress-bar',
|
|
333
|
+
'::-moz-range-progress',
|
|
334
|
+
'::-moz-range-thumb',
|
|
335
|
+
'::-moz-range-track',
|
|
336
|
+
':-moz-read-only',
|
|
337
|
+
':-moz-read-write',
|
|
338
|
+
'::-moz-scrolled-canvas',
|
|
339
|
+
'::-moz-scrolled-content',
|
|
340
|
+
'::-moz-selection',
|
|
341
|
+
':-moz-submit-invalid',
|
|
342
|
+
':-moz-suppressed',
|
|
343
|
+
'::-moz-svg-foreign-content',
|
|
344
|
+
'::-moz-table',
|
|
345
|
+
'::-moz-table-cell',
|
|
346
|
+
'::-moz-table-column',
|
|
347
|
+
'::-moz-table-column-group',
|
|
348
|
+
'::-moz-table-outer',
|
|
349
|
+
'::-moz-table-row',
|
|
350
|
+
'::-moz-table-row-group',
|
|
351
|
+
':-moz-ui-invalid',
|
|
352
|
+
':-moz-ui-valid',
|
|
353
|
+
':-moz-user-disabled',
|
|
354
|
+
'::-moz-viewport',
|
|
355
|
+
'::-moz-viewport-scroll',
|
|
356
|
+
':-moz-window-inactive',
|
|
357
|
+
'-moz-device-pixel-ratio',
|
|
358
|
+
'-moz-os-version',
|
|
359
|
+
'-moz-touch-enabled',
|
|
360
|
+
'-moz-windows-glass',
|
|
361
|
+
'-moz-alt-content'
|
|
362
|
+
]);
|
|
28
363
|
function isLength(dimension) {
|
|
29
364
|
return 'unit' in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
|
|
30
365
|
}
|
|
@@ -476,4 +811,4 @@ function isWhiteSpace(codepoint) {
|
|
|
476
811
|
codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
|
|
477
812
|
}
|
|
478
813
|
|
|
479
|
-
export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, parseDimension };
|
|
814
|
+
export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseDimension, webkitExtensions, webkitPseudoAliasMap };
|
|
@@ -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 };
|