@projectwallace/css-parser 0.13.5 → 0.13.6
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/dist/css-node-2ejJUrIw.js +645 -0
- package/dist/css-node-DqyvMXBN.d.ts +313 -0
- package/dist/index.d.ts +150 -16
- package/dist/index.js +103 -13
- package/dist/parse-anplusb.d.ts +26 -2
- package/dist/parse-anplusb.js +191 -207
- package/dist/parse-atrule-prelude.d.ts +40 -2
- package/dist/parse-atrule-prelude.js +556 -652
- package/dist/parse-declaration.d.ts +16 -2
- package/dist/parse-declaration.js +140 -167
- package/dist/parse-dimension-CCn_XRDe.js +177 -0
- package/dist/parse-dimension.d.ts +6 -3
- package/dist/parse-dimension.js +1 -35
- package/dist/parse-selector.d.ts +37 -2
- package/dist/parse-selector.js +508 -635
- package/dist/parse-utils-DnsZRpfd.js +98 -0
- package/dist/parse-value.d.ts +23 -2
- package/dist/parse-value.js +176 -224
- package/dist/parse.d.ts +38 -8
- package/dist/parse.js +274 -353
- package/dist/tokenize-BQFB1jXg.js +540 -0
- package/dist/tokenize-odLrcjj2.d.ts +110 -0
- package/dist/tokenize.d.ts +2 -26
- package/dist/tokenize.js +1 -545
- package/package.json +20 -26
- package/dist/arena.d.ts +0 -60
- package/dist/arena.js +0 -291
- package/dist/char-types.d.ts +0 -14
- package/dist/char-types.js +0 -53
- package/dist/constants.d.ts +0 -44
- package/dist/constants.js +0 -51
- package/dist/css-node.d.ts +0 -203
- package/dist/css-node.js +0 -498
- package/dist/parse-utils.d.ts +0 -1
- package/dist/parse-utils.js +0 -60
- package/dist/string-utils.d.ts +0 -99
- package/dist/string-utils.js +0 -129
- package/dist/token-types.d.ts +0 -35
- package/dist/token-types.js +0 -29
- package/dist/walk.d.ts +0 -28
- package/dist/walk.js +0 -51
|
@@ -1,655 +1,559 @@
|
|
|
1
|
-
import { Lexer } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const url_node = this.parse_import_url();
|
|
555
|
-
if (url_node !== null) nodes.push(url_node);
|
|
556
|
-
return nodes;
|
|
557
|
-
}
|
|
558
|
-
// Parse @scope prelude: [(<scope-start>)] [to (<scope-end>)]
|
|
559
|
-
// e.g. @scope (.parent) to (.child) { }
|
|
560
|
-
parse_scope_prelude() {
|
|
561
|
-
let nodes = [];
|
|
562
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
563
|
-
this.skip_whitespace();
|
|
564
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
565
|
-
const token_type = this.peek_token_type();
|
|
566
|
-
if (token_type === TOKEN_LEFT_PAREN) {
|
|
567
|
-
this.next_token();
|
|
568
|
-
let paren_start = this.lexer.token_start;
|
|
569
|
-
let content_start = this.lexer.pos;
|
|
570
|
-
let depth = 1;
|
|
571
|
-
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
572
|
-
this.next_token();
|
|
573
|
-
if (this.lexer.token_type === TOKEN_LEFT_PAREN) depth++;
|
|
574
|
-
else if (this.lexer.token_type === TOKEN_RIGHT_PAREN) depth--;
|
|
575
|
-
}
|
|
576
|
-
let content_end = this.lexer.token_start;
|
|
577
|
-
let paren_end = this.lexer.token_end;
|
|
578
|
-
let scope_node = this.create_node(PRELUDE_SELECTORLIST, paren_start, paren_end);
|
|
579
|
-
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
580
|
-
if (trimmed) {
|
|
581
|
-
this.arena.set_value_start_delta(scope_node, trimmed[0] - paren_start);
|
|
582
|
-
this.arena.set_value_length(scope_node, trimmed[1] - trimmed[0]);
|
|
583
|
-
}
|
|
584
|
-
nodes.push(scope_node);
|
|
585
|
-
} else if (token_type === TOKEN_IDENT) {
|
|
586
|
-
this.next_token();
|
|
587
|
-
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
588
|
-
if (str_equals("to", text)) {
|
|
589
|
-
nodes.push(this.create_node(PRELUDE_OPERATOR, this.lexer.token_start, this.lexer.token_end));
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
this.next_token();
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return nodes;
|
|
596
|
-
}
|
|
597
|
-
// Parse @custom-media prelude: --name <media-condition>
|
|
598
|
-
// e.g. @custom-media --small (max-width: 30em);
|
|
599
|
-
parse_custom_media_prelude() {
|
|
600
|
-
let nodes = [];
|
|
601
|
-
this.skip_whitespace();
|
|
602
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
603
|
-
this.next_token();
|
|
604
|
-
if (this.lexer.token_type !== TOKEN_IDENT) return [];
|
|
605
|
-
nodes.push(this.create_node(IDENTIFIER, this.lexer.token_start, this.lexer.token_end));
|
|
606
|
-
nodes.push(...this.parse_media_query_list());
|
|
607
|
-
return nodes;
|
|
608
|
-
}
|
|
609
|
-
// Parse media feature range syntax: (50px <= width <= 100px)
|
|
610
|
-
parse_feature_range(feature_start, feature_end, content_start, content_end) {
|
|
611
|
-
let range_node = this.create_node(FEATURE_RANGE, feature_start, feature_end);
|
|
612
|
-
let children = [];
|
|
613
|
-
let feature_name_start = -1;
|
|
614
|
-
let feature_name_end = -1;
|
|
615
|
-
let pos = content_start;
|
|
616
|
-
while (pos < content_end) {
|
|
617
|
-
pos = skip_whitespace_and_comments_forward(this.source, pos, content_end);
|
|
618
|
-
if (pos >= content_end) break;
|
|
619
|
-
let ch = this.source.charCodeAt(pos);
|
|
620
|
-
if (ch === CHAR_LESS_THAN || ch === CHAR_GREATER_THAN || ch === CHAR_EQUALS) {
|
|
621
|
-
let op_start = pos++;
|
|
622
|
-
if (pos < content_end && this.source.charCodeAt(pos) === CHAR_EQUALS) pos++;
|
|
623
|
-
let op = this.create_node(PRELUDE_OPERATOR, op_start, pos);
|
|
624
|
-
children.push(op);
|
|
625
|
-
} else {
|
|
626
|
-
let saved = this.lexer.save_position();
|
|
627
|
-
this.lexer.pos = pos;
|
|
628
|
-
this.next_token();
|
|
629
|
-
if (this.lexer.token_type === TOKEN_IDENT) {
|
|
630
|
-
feature_name_start = this.lexer.token_start;
|
|
631
|
-
feature_name_end = this.lexer.token_end;
|
|
632
|
-
} else {
|
|
633
|
-
let value_nodes = this.parse_feature_value(this.lexer.token_start, this.lexer.token_end);
|
|
634
|
-
children.push(...value_nodes);
|
|
635
|
-
}
|
|
636
|
-
pos = this.lexer.pos;
|
|
637
|
-
this.lexer.restore_position(saved);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (feature_name_start !== -1) {
|
|
641
|
-
this.arena.set_content_start_delta(range_node, feature_name_start - feature_start);
|
|
642
|
-
this.arena.set_content_length(range_node, feature_name_end - feature_name_start);
|
|
643
|
-
}
|
|
644
|
-
this.arena.append_children(range_node, children);
|
|
645
|
-
return range_node;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
1
|
+
import { t as Lexer } from "./tokenize-BQFB1jXg.js";
|
|
2
|
+
import { C as CSSDataArena, r as CSSNode } from "./css-node-2ejJUrIw.js";
|
|
3
|
+
import { a as is_whitespace, l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
|
|
4
|
+
import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-DnsZRpfd.js";
|
|
5
|
+
//#region src/parse-atrule-prelude.ts
|
|
6
|
+
/** @internal */
|
|
7
|
+
var AtRulePreludeParser = class {
|
|
8
|
+
lexer;
|
|
9
|
+
arena;
|
|
10
|
+
source;
|
|
11
|
+
prelude_end;
|
|
12
|
+
constructor(arena, source) {
|
|
13
|
+
this.arena = arena;
|
|
14
|
+
this.source = source;
|
|
15
|
+
this.lexer = new Lexer(source);
|
|
16
|
+
this.prelude_end = 0;
|
|
17
|
+
}
|
|
18
|
+
parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
|
|
19
|
+
this.prelude_end = end;
|
|
20
|
+
this.lexer.seek(start, line, column);
|
|
21
|
+
return this.parse_prelude_dispatch(at_rule_name);
|
|
22
|
+
}
|
|
23
|
+
parse_prelude_dispatch(at_rule_name) {
|
|
24
|
+
switch (strip_vendor_prefix(at_rule_name).toLowerCase()) {
|
|
25
|
+
case "media": return this.parse_media_query_list();
|
|
26
|
+
case "container": return this.parse_container_query();
|
|
27
|
+
case "supports": return this.parse_supports_query();
|
|
28
|
+
case "layer": return this.parse_layer_names();
|
|
29
|
+
case "keyframes":
|
|
30
|
+
case "property":
|
|
31
|
+
case "counter-style":
|
|
32
|
+
case "color-profile":
|
|
33
|
+
case "font-palette-values":
|
|
34
|
+
case "position-try":
|
|
35
|
+
case "font-feature-values":
|
|
36
|
+
case "page": return this.parse_identifier();
|
|
37
|
+
case "function": return this.parse_function_prelude();
|
|
38
|
+
case "import": return this.parse_import_prelude();
|
|
39
|
+
case "charset": return this.parse_charset_prelude();
|
|
40
|
+
case "namespace": return this.parse_namespace_prelude();
|
|
41
|
+
case "scope": return this.parse_scope_prelude();
|
|
42
|
+
case "custom-media": return this.parse_custom_media_prelude();
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
parse_media_query_list() {
|
|
47
|
+
let nodes = [];
|
|
48
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
49
|
+
this.skip_whitespace();
|
|
50
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
51
|
+
let query = this.parse_single_media_query();
|
|
52
|
+
if (query !== null) nodes.push(query);
|
|
53
|
+
this.skip_whitespace();
|
|
54
|
+
const saved = this.lexer.save_position();
|
|
55
|
+
this.next_token();
|
|
56
|
+
if (this.lexer.token_type !== 18) this.lexer.restore_position(saved);
|
|
57
|
+
}
|
|
58
|
+
return nodes;
|
|
59
|
+
}
|
|
60
|
+
create_node(type, start, end) {
|
|
61
|
+
return this.arena.create_node(type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
62
|
+
}
|
|
63
|
+
is_and_or_not(str) {
|
|
64
|
+
return str_equals("and", str) || str_equals("or", str) || str_equals("not", str);
|
|
65
|
+
}
|
|
66
|
+
parse_single_media_query() {
|
|
67
|
+
let query_start = this.lexer.pos;
|
|
68
|
+
this.skip_whitespace();
|
|
69
|
+
if (this.lexer.pos >= this.prelude_end) return null;
|
|
70
|
+
const saved_token_start = this.lexer.save_position();
|
|
71
|
+
this.next_token();
|
|
72
|
+
if (this.lexer.token_type === 1) {
|
|
73
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
74
|
+
if (!str_equals("only", text) && !str_equals("not", text)) this.lexer.restore_position(saved_token_start);
|
|
75
|
+
} else this.lexer.restore_position(saved_token_start);
|
|
76
|
+
let components = [];
|
|
77
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
78
|
+
this.skip_whitespace();
|
|
79
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
80
|
+
if (this.peek_token_type() === 18) break;
|
|
81
|
+
this.next_token();
|
|
82
|
+
let token_type = this.lexer.token_type;
|
|
83
|
+
if (token_type === 21) {
|
|
84
|
+
let feature = this.parse_media_feature();
|
|
85
|
+
if (feature !== null) components.push(feature);
|
|
86
|
+
} else if (token_type === 1) {
|
|
87
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
88
|
+
if (this.is_and_or_not(text)) {
|
|
89
|
+
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
90
|
+
components.push(op);
|
|
91
|
+
} else {
|
|
92
|
+
let media_type = this.create_node(34, this.lexer.token_start, this.lexer.token_end);
|
|
93
|
+
components.push(media_type);
|
|
94
|
+
}
|
|
95
|
+
} else break;
|
|
96
|
+
}
|
|
97
|
+
if (components.length === 0) return null;
|
|
98
|
+
let query_node = this.create_node(32, query_start, this.lexer.pos);
|
|
99
|
+
this.arena.append_children(query_node, components);
|
|
100
|
+
return query_node;
|
|
101
|
+
}
|
|
102
|
+
parse_media_feature() {
|
|
103
|
+
let feature_start = this.lexer.token_start;
|
|
104
|
+
let depth = 1;
|
|
105
|
+
let content_start = this.lexer.pos;
|
|
106
|
+
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
107
|
+
this.next_token();
|
|
108
|
+
let token_type = this.lexer.token_type;
|
|
109
|
+
if (token_type === 21) depth++;
|
|
110
|
+
else if (token_type === 22) depth--;
|
|
111
|
+
}
|
|
112
|
+
if (depth !== 0) return null;
|
|
113
|
+
let content_end = this.lexer.token_start;
|
|
114
|
+
let feature_end = this.lexer.token_end;
|
|
115
|
+
let has_comparison = false;
|
|
116
|
+
let i = content_start;
|
|
117
|
+
while (i < content_end) {
|
|
118
|
+
i = skip_whitespace_and_comments_forward(this.source, i, content_end);
|
|
119
|
+
if (i >= content_end) break;
|
|
120
|
+
let ch = this.source.charCodeAt(i);
|
|
121
|
+
if (ch === 60 || ch === 62 || ch === 61) {
|
|
122
|
+
has_comparison = true;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
if (has_comparison) return this.parse_feature_range(feature_start, feature_end, content_start, content_end);
|
|
128
|
+
let feature = this.create_node(33, feature_start, feature_end);
|
|
129
|
+
let colon_pos = -1;
|
|
130
|
+
let j = content_start;
|
|
131
|
+
while (j < content_end) {
|
|
132
|
+
j = skip_whitespace_and_comments_forward(this.source, j, content_end);
|
|
133
|
+
if (j >= content_end) break;
|
|
134
|
+
if (this.source.charCodeAt(j) === 58) {
|
|
135
|
+
colon_pos = j;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
j++;
|
|
139
|
+
}
|
|
140
|
+
if (colon_pos !== -1) {
|
|
141
|
+
let name_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
142
|
+
if (name_trimmed) {
|
|
143
|
+
this.arena.set_content_start_delta(feature, name_trimmed[0] - feature_start);
|
|
144
|
+
this.arena.set_content_length(feature, name_trimmed[1] - name_trimmed[0]);
|
|
145
|
+
}
|
|
146
|
+
let value_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
147
|
+
if (value_trimmed) {
|
|
148
|
+
let value_nodes = this.parse_feature_value(value_trimmed[0], value_trimmed[1]);
|
|
149
|
+
if (value_nodes.length > 0) this.arena.append_children(feature, value_nodes);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
153
|
+
if (trimmed) {
|
|
154
|
+
this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
|
|
155
|
+
this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return feature;
|
|
159
|
+
}
|
|
160
|
+
parse_container_query() {
|
|
161
|
+
let nodes = [];
|
|
162
|
+
let query_start = this.lexer.pos;
|
|
163
|
+
let components = [];
|
|
164
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
165
|
+
this.skip_whitespace();
|
|
166
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
167
|
+
this.next_token();
|
|
168
|
+
let token_type = this.lexer.token_type;
|
|
169
|
+
if (token_type === 21) {
|
|
170
|
+
let feature = this.parse_media_feature();
|
|
171
|
+
if (feature !== null) components.push(feature);
|
|
172
|
+
} else if (token_type === 2) {
|
|
173
|
+
let func_name = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
174
|
+
let func_start = this.lexer.token_start;
|
|
175
|
+
let content_start = this.lexer.token_end;
|
|
176
|
+
let paren_depth = 1;
|
|
177
|
+
let func_end = this.lexer.token_end;
|
|
178
|
+
let content_end = content_start;
|
|
179
|
+
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
180
|
+
this.next_token();
|
|
181
|
+
let inner_token = this.lexer.token_type;
|
|
182
|
+
if (inner_token === 21 || inner_token === 2) paren_depth++;
|
|
183
|
+
else if (inner_token === 22) {
|
|
184
|
+
paren_depth--;
|
|
185
|
+
if (paren_depth === 0) {
|
|
186
|
+
content_end = this.lexer.token_start;
|
|
187
|
+
func_end = this.lexer.token_end;
|
|
188
|
+
}
|
|
189
|
+
} else if (inner_token === 26) break;
|
|
190
|
+
}
|
|
191
|
+
let func_node = this.create_node(15, func_start, func_end);
|
|
192
|
+
this.arena.set_content_start_delta(func_node, 0);
|
|
193
|
+
this.arena.set_content_length(func_node, func_name.length);
|
|
194
|
+
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
195
|
+
this.arena.set_value_length(func_node, content_end - content_start);
|
|
196
|
+
components.push(func_node);
|
|
197
|
+
} else if (token_type === 1) {
|
|
198
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
199
|
+
if (this.is_and_or_not(text)) {
|
|
200
|
+
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
201
|
+
components.push(op);
|
|
202
|
+
} else {
|
|
203
|
+
let name = this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
204
|
+
components.push(name);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (components.length === 0) return [];
|
|
209
|
+
let query_node = this.create_node(35, query_start, this.lexer.pos);
|
|
210
|
+
this.arena.append_children(query_node, components);
|
|
211
|
+
nodes.push(query_node);
|
|
212
|
+
return nodes;
|
|
213
|
+
}
|
|
214
|
+
parse_supports_query() {
|
|
215
|
+
let nodes = [];
|
|
216
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
217
|
+
this.skip_whitespace();
|
|
218
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
219
|
+
this.next_token();
|
|
220
|
+
let token_type = this.lexer.token_type;
|
|
221
|
+
if (token_type === 21) {
|
|
222
|
+
let feature_start = this.lexer.token_start;
|
|
223
|
+
let depth = 1;
|
|
224
|
+
let content_start = this.lexer.pos;
|
|
225
|
+
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
226
|
+
this.next_token();
|
|
227
|
+
let inner_token_type = this.lexer.token_type;
|
|
228
|
+
if (inner_token_type === 21) depth++;
|
|
229
|
+
else if (inner_token_type === 22) depth--;
|
|
230
|
+
}
|
|
231
|
+
if (depth === 0) {
|
|
232
|
+
let content_end = this.lexer.token_start;
|
|
233
|
+
let feature_end = this.lexer.token_end;
|
|
234
|
+
let query = this.create_node(36, feature_start, feature_end);
|
|
235
|
+
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
236
|
+
if (trimmed) {
|
|
237
|
+
this.arena.set_value_start_delta(query, trimmed[0] - feature_start);
|
|
238
|
+
this.arena.set_value_length(query, trimmed[1] - trimmed[0]);
|
|
239
|
+
}
|
|
240
|
+
nodes.push(query);
|
|
241
|
+
}
|
|
242
|
+
} else if (token_type === 1) {
|
|
243
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
244
|
+
if (this.is_and_or_not(text)) {
|
|
245
|
+
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
246
|
+
nodes.push(op);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return nodes;
|
|
251
|
+
}
|
|
252
|
+
parse_layer_names() {
|
|
253
|
+
let nodes = [];
|
|
254
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
255
|
+
this.skip_whitespace();
|
|
256
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
257
|
+
this.next_token();
|
|
258
|
+
let token_type = this.lexer.token_type;
|
|
259
|
+
if (token_type === 1) {
|
|
260
|
+
let layer = this.create_node(37, this.lexer.token_start, this.lexer.token_end);
|
|
261
|
+
this.arena.set_value_start_delta(layer, 0);
|
|
262
|
+
this.arena.set_value_length(layer, this.lexer.token_end - this.lexer.token_start);
|
|
263
|
+
nodes.push(layer);
|
|
264
|
+
} else if (token_type === 18) continue;
|
|
265
|
+
else if (token_type === 13) continue;
|
|
266
|
+
}
|
|
267
|
+
return nodes;
|
|
268
|
+
}
|
|
269
|
+
parse_function_prelude() {
|
|
270
|
+
this.skip_whitespace();
|
|
271
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
272
|
+
this.next_token();
|
|
273
|
+
if (this.lexer.token_type !== 2) return [];
|
|
274
|
+
let name_start = this.lexer.token_start;
|
|
275
|
+
let name_end = this.lexer.token_end - 1;
|
|
276
|
+
return [this.create_node(10, name_start, name_end)];
|
|
277
|
+
}
|
|
278
|
+
parse_identifier() {
|
|
279
|
+
this.skip_whitespace();
|
|
280
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
281
|
+
this.next_token();
|
|
282
|
+
if (this.lexer.token_type !== 1) return [];
|
|
283
|
+
return [this.create_node(10, this.lexer.token_start, this.lexer.token_end)];
|
|
284
|
+
}
|
|
285
|
+
parse_charset_prelude() {
|
|
286
|
+
this.skip_whitespace();
|
|
287
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
288
|
+
this.next_token();
|
|
289
|
+
if (this.lexer.token_type !== 5) return [];
|
|
290
|
+
return [this.create_node(13, this.lexer.token_start, this.lexer.token_end)];
|
|
291
|
+
}
|
|
292
|
+
parse_import_prelude() {
|
|
293
|
+
let nodes = [];
|
|
294
|
+
this.skip_whitespace();
|
|
295
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
296
|
+
let url_node = this.parse_import_url();
|
|
297
|
+
if (url_node !== null) nodes.push(url_node);
|
|
298
|
+
else return [];
|
|
299
|
+
this.skip_whitespace();
|
|
300
|
+
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
301
|
+
let layer_node = this.parse_import_layer();
|
|
302
|
+
if (layer_node !== null) nodes.push(layer_node);
|
|
303
|
+
this.skip_whitespace();
|
|
304
|
+
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
305
|
+
let supports_node = this.parse_import_supports();
|
|
306
|
+
if (supports_node !== null) nodes.push(supports_node);
|
|
307
|
+
this.skip_whitespace();
|
|
308
|
+
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
309
|
+
let media_nodes = this.parse_media_query_list();
|
|
310
|
+
nodes.push(...media_nodes);
|
|
311
|
+
return nodes;
|
|
312
|
+
}
|
|
313
|
+
parse_import_url() {
|
|
314
|
+
this.next_token();
|
|
315
|
+
if (this.lexer.token_type !== 7 && this.lexer.token_type !== 2 && this.lexer.token_type !== 5) return null;
|
|
316
|
+
let url_start = this.lexer.token_start;
|
|
317
|
+
let url_end = this.lexer.token_end;
|
|
318
|
+
if (this.lexer.token_type === 2) {
|
|
319
|
+
let paren_depth = 1;
|
|
320
|
+
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
321
|
+
let tokenType = this.next_token();
|
|
322
|
+
if (tokenType === 21 || tokenType === 2) paren_depth++;
|
|
323
|
+
else if (tokenType === 22) {
|
|
324
|
+
paren_depth--;
|
|
325
|
+
if (paren_depth === 0) url_end = this.lexer.token_end;
|
|
326
|
+
} else if (tokenType === 26) break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return this.create_node(18, url_start, url_end);
|
|
330
|
+
}
|
|
331
|
+
parse_import_layer() {
|
|
332
|
+
const saved = this.lexer.save_position();
|
|
333
|
+
this.next_token();
|
|
334
|
+
if (this.lexer.token_type === 1 || this.lexer.token_type === 2) {
|
|
335
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
336
|
+
if (this.lexer.token_type === 2 && text.endsWith("(")) text = text.slice(0, -1);
|
|
337
|
+
if (str_equals("layer", text)) {
|
|
338
|
+
let layer_start = this.lexer.token_start;
|
|
339
|
+
let layer_end = this.lexer.token_end;
|
|
340
|
+
let content_start = 0;
|
|
341
|
+
let content_length = 0;
|
|
342
|
+
if (this.lexer.token_type === 2) {
|
|
343
|
+
content_start = this.lexer.pos;
|
|
344
|
+
let paren_depth = 1;
|
|
345
|
+
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
346
|
+
let tokenType = this.next_token();
|
|
347
|
+
if (tokenType === 21 || tokenType === 2) paren_depth++;
|
|
348
|
+
else if (tokenType === 22) {
|
|
349
|
+
paren_depth--;
|
|
350
|
+
if (paren_depth === 0) {
|
|
351
|
+
content_length = this.lexer.token_start - content_start;
|
|
352
|
+
layer_end = this.lexer.token_end;
|
|
353
|
+
}
|
|
354
|
+
} else if (tokenType === 26) break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
let layer_node = this.create_node(37, layer_start, layer_end);
|
|
358
|
+
if (content_length > 0) {
|
|
359
|
+
let trimmed = trim_boundaries(this.source, content_start, content_start + content_length);
|
|
360
|
+
if (trimmed) {
|
|
361
|
+
this.arena.set_content_start_delta(layer_node, trimmed[0] - layer_start);
|
|
362
|
+
this.arena.set_content_length(layer_node, trimmed[1] - trimmed[0]);
|
|
363
|
+
this.arena.set_value_start_delta(layer_node, trimmed[0] - layer_start);
|
|
364
|
+
this.arena.set_value_length(layer_node, trimmed[1] - trimmed[0]);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return layer_node;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this.lexer.restore_position(saved);
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
parse_import_supports() {
|
|
374
|
+
const saved = this.lexer.save_position();
|
|
375
|
+
this.next_token();
|
|
376
|
+
if (this.lexer.token_type === 2) {
|
|
377
|
+
if (str_equals("supports", this.source.substring(this.lexer.token_start, this.lexer.token_end - 1))) {
|
|
378
|
+
let supports_start = this.lexer.token_start;
|
|
379
|
+
let content_start = this.lexer.token_end;
|
|
380
|
+
let paren_depth = 1;
|
|
381
|
+
let supports_end = this.lexer.token_end;
|
|
382
|
+
let content_end = content_start;
|
|
383
|
+
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
384
|
+
let tokenType = this.next_token();
|
|
385
|
+
if (tokenType === 21 || tokenType === 2) paren_depth++;
|
|
386
|
+
else if (tokenType === 22) {
|
|
387
|
+
paren_depth--;
|
|
388
|
+
if (paren_depth === 0) {
|
|
389
|
+
content_end = this.lexer.token_start;
|
|
390
|
+
supports_end = this.lexer.token_end;
|
|
391
|
+
}
|
|
392
|
+
} else if (tokenType === 26) break;
|
|
393
|
+
}
|
|
394
|
+
let supports_node = this.create_node(36, supports_start, supports_end);
|
|
395
|
+
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
396
|
+
if (trimmed) {
|
|
397
|
+
this.arena.set_value_start_delta(supports_node, trimmed[0] - supports_start);
|
|
398
|
+
this.arena.set_value_length(supports_node, trimmed[1] - trimmed[0]);
|
|
399
|
+
}
|
|
400
|
+
return supports_node;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
this.lexer.restore_position(saved);
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
skip_whitespace() {
|
|
407
|
+
this.lexer.skip_whitespace_in_range(this.prelude_end);
|
|
408
|
+
}
|
|
409
|
+
peek_token_type() {
|
|
410
|
+
const saved = this.lexer.save_position();
|
|
411
|
+
this.next_token();
|
|
412
|
+
let type = this.lexer.token_type;
|
|
413
|
+
this.lexer.restore_position(saved);
|
|
414
|
+
return type;
|
|
415
|
+
}
|
|
416
|
+
next_token() {
|
|
417
|
+
if (this.lexer.pos >= this.prelude_end) {
|
|
418
|
+
this.lexer.token_type = 26;
|
|
419
|
+
return 26;
|
|
420
|
+
}
|
|
421
|
+
return this.lexer.next_token_fast(false);
|
|
422
|
+
}
|
|
423
|
+
parse_value_token() {
|
|
424
|
+
switch (this.lexer.token_type) {
|
|
425
|
+
case 1: return this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
426
|
+
case 10: return this.create_node(11, this.lexer.token_start, this.lexer.token_end);
|
|
427
|
+
case 11:
|
|
428
|
+
case 12: return this.create_node(12, this.lexer.token_start, this.lexer.token_end);
|
|
429
|
+
case 5: return this.create_node(13, this.lexer.token_start, this.lexer.token_end);
|
|
430
|
+
default: return null;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
parse_feature_value(start, end) {
|
|
434
|
+
let temp_lexer = new Lexer(this.source);
|
|
435
|
+
temp_lexer.seek(start, this.lexer.line, this.lexer.column);
|
|
436
|
+
let nodes = [];
|
|
437
|
+
let saved_lexer = this.lexer;
|
|
438
|
+
this.lexer = temp_lexer;
|
|
439
|
+
while (this.lexer.pos < end) {
|
|
440
|
+
this.lexer.next_token_fast(false);
|
|
441
|
+
if (this.lexer.token_start >= end) break;
|
|
442
|
+
let all_whitespace = true;
|
|
443
|
+
for (let i = this.lexer.token_start; i < this.lexer.token_end && i < end; i++) if (!is_whitespace(this.source.charCodeAt(i))) {
|
|
444
|
+
all_whitespace = false;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
if (all_whitespace) continue;
|
|
448
|
+
let node = this.parse_value_token();
|
|
449
|
+
if (node !== null) nodes.push(node);
|
|
450
|
+
}
|
|
451
|
+
this.lexer = saved_lexer;
|
|
452
|
+
return nodes;
|
|
453
|
+
}
|
|
454
|
+
parse_namespace_prelude() {
|
|
455
|
+
let nodes = [];
|
|
456
|
+
this.skip_whitespace();
|
|
457
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
458
|
+
const saved = this.lexer.save_position();
|
|
459
|
+
this.next_token();
|
|
460
|
+
if (this.lexer.token_type === 1) {
|
|
461
|
+
nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end));
|
|
462
|
+
this.skip_whitespace();
|
|
463
|
+
} else this.lexer.restore_position(saved);
|
|
464
|
+
const url_node = this.parse_import_url();
|
|
465
|
+
if (url_node !== null) nodes.push(url_node);
|
|
466
|
+
return nodes;
|
|
467
|
+
}
|
|
468
|
+
parse_scope_prelude() {
|
|
469
|
+
let nodes = [];
|
|
470
|
+
while (this.lexer.pos < this.prelude_end) {
|
|
471
|
+
this.skip_whitespace();
|
|
472
|
+
if (this.lexer.pos >= this.prelude_end) break;
|
|
473
|
+
const token_type = this.peek_token_type();
|
|
474
|
+
if (token_type === 21) {
|
|
475
|
+
this.next_token();
|
|
476
|
+
let paren_start = this.lexer.token_start;
|
|
477
|
+
let content_start = this.lexer.pos;
|
|
478
|
+
let depth = 1;
|
|
479
|
+
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
480
|
+
this.next_token();
|
|
481
|
+
if (this.lexer.token_type === 21) depth++;
|
|
482
|
+
else if (this.lexer.token_type === 22) depth--;
|
|
483
|
+
}
|
|
484
|
+
let content_end = this.lexer.token_start;
|
|
485
|
+
let paren_end = this.lexer.token_end;
|
|
486
|
+
let scope_node = this.create_node(41, paren_start, paren_end);
|
|
487
|
+
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
488
|
+
if (trimmed) {
|
|
489
|
+
this.arena.set_value_start_delta(scope_node, trimmed[0] - paren_start);
|
|
490
|
+
this.arena.set_value_length(scope_node, trimmed[1] - trimmed[0]);
|
|
491
|
+
}
|
|
492
|
+
nodes.push(scope_node);
|
|
493
|
+
} else if (token_type === 1) {
|
|
494
|
+
this.next_token();
|
|
495
|
+
if (str_equals("to", this.source.substring(this.lexer.token_start, this.lexer.token_end))) nodes.push(this.create_node(38, this.lexer.token_start, this.lexer.token_end));
|
|
496
|
+
} else this.next_token();
|
|
497
|
+
}
|
|
498
|
+
return nodes;
|
|
499
|
+
}
|
|
500
|
+
parse_custom_media_prelude() {
|
|
501
|
+
let nodes = [];
|
|
502
|
+
this.skip_whitespace();
|
|
503
|
+
if (this.lexer.pos >= this.prelude_end) return [];
|
|
504
|
+
this.next_token();
|
|
505
|
+
if (this.lexer.token_type !== 1) return [];
|
|
506
|
+
nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end));
|
|
507
|
+
nodes.push(...this.parse_media_query_list());
|
|
508
|
+
return nodes;
|
|
509
|
+
}
|
|
510
|
+
parse_feature_range(feature_start, feature_end, content_start, content_end) {
|
|
511
|
+
let range_node = this.create_node(39, feature_start, feature_end);
|
|
512
|
+
let children = [];
|
|
513
|
+
let feature_name_start = -1;
|
|
514
|
+
let feature_name_end = -1;
|
|
515
|
+
let pos = content_start;
|
|
516
|
+
while (pos < content_end) {
|
|
517
|
+
pos = skip_whitespace_and_comments_forward(this.source, pos, content_end);
|
|
518
|
+
if (pos >= content_end) break;
|
|
519
|
+
let ch = this.source.charCodeAt(pos);
|
|
520
|
+
if (ch === 60 || ch === 62 || ch === 61) {
|
|
521
|
+
let op_start = pos++;
|
|
522
|
+
if (pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
|
|
523
|
+
let op = this.create_node(38, op_start, pos);
|
|
524
|
+
children.push(op);
|
|
525
|
+
} else {
|
|
526
|
+
let saved = this.lexer.save_position();
|
|
527
|
+
this.lexer.pos = pos;
|
|
528
|
+
this.next_token();
|
|
529
|
+
if (this.lexer.token_type === 1) {
|
|
530
|
+
feature_name_start = this.lexer.token_start;
|
|
531
|
+
feature_name_end = this.lexer.token_end;
|
|
532
|
+
} else {
|
|
533
|
+
let value_nodes = this.parse_feature_value(this.lexer.token_start, this.lexer.token_end);
|
|
534
|
+
children.push(...value_nodes);
|
|
535
|
+
}
|
|
536
|
+
pos = this.lexer.pos;
|
|
537
|
+
this.lexer.restore_position(saved);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (feature_name_start !== -1) {
|
|
541
|
+
this.arena.set_content_start_delta(range_node, feature_name_start - feature_start);
|
|
542
|
+
this.arena.set_content_length(range_node, feature_name_end - feature_name_start);
|
|
543
|
+
}
|
|
544
|
+
this.arena.append_children(range_node, children);
|
|
545
|
+
return range_node;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Parse an at-rule prelude string and return an array of AST nodes
|
|
550
|
+
* @param at_rule_name - The name of the at-rule (e.g., "media", "supports", "layer")
|
|
551
|
+
* @param prelude - The at-rule prelude to parse (e.g., "(min-width: 768px)", "utilities")
|
|
552
|
+
* @returns An array of CSSNode objects representing the parsed prelude
|
|
553
|
+
*/
|
|
648
554
|
function parse_atrule_prelude(at_rule_name, prelude) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const node_indices = prelude_parser.parse_prelude(at_rule_name, 0, prelude.length);
|
|
652
|
-
return node_indices.map((index) => new CSSNode(arena, prelude, index));
|
|
555
|
+
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(prelude.length));
|
|
556
|
+
return new AtRulePreludeParser(arena, prelude).parse_prelude(at_rule_name, 0, prelude.length).map((index) => new CSSNode(arena, prelude, index));
|
|
653
557
|
}
|
|
654
|
-
|
|
558
|
+
//#endregion
|
|
655
559
|
export { AtRulePreludeParser, parse_atrule_prelude };
|