@projectwallace/css-parser 0.13.5 → 0.13.8

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 (41) hide show
  1. package/dist/css-node-DqyvMXBN.d.ts +313 -0
  2. package/dist/css-node-Uj4oBgaw.js +647 -0
  3. package/dist/index.d.ts +150 -16
  4. package/dist/index.js +103 -13
  5. package/dist/parse-anplusb.d.ts +26 -2
  6. package/dist/parse-anplusb.js +191 -207
  7. package/dist/parse-atrule-prelude.d.ts +40 -2
  8. package/dist/parse-atrule-prelude.js +556 -652
  9. package/dist/parse-declaration.d.ts +16 -2
  10. package/dist/parse-declaration.js +140 -167
  11. package/dist/parse-dimension-CCn_XRDe.js +177 -0
  12. package/dist/parse-dimension.d.ts +6 -3
  13. package/dist/parse-dimension.js +1 -35
  14. package/dist/parse-selector.d.ts +37 -2
  15. package/dist/parse-selector.js +508 -635
  16. package/dist/parse-utils-DnsZRpfd.js +98 -0
  17. package/dist/parse-value.d.ts +23 -2
  18. package/dist/parse-value.js +176 -224
  19. package/dist/parse.d.ts +37 -8
  20. package/dist/parse.js +252 -353
  21. package/dist/tokenize-BQFB1jXg.js +540 -0
  22. package/dist/tokenize-odLrcjj2.d.ts +110 -0
  23. package/dist/tokenize.d.ts +2 -26
  24. package/dist/tokenize.js +1 -545
  25. package/package.json +20 -26
  26. package/dist/arena.d.ts +0 -60
  27. package/dist/arena.js +0 -291
  28. package/dist/char-types.d.ts +0 -14
  29. package/dist/char-types.js +0 -53
  30. package/dist/constants.d.ts +0 -44
  31. package/dist/constants.js +0 -51
  32. package/dist/css-node.d.ts +0 -203
  33. package/dist/css-node.js +0 -498
  34. package/dist/parse-utils.d.ts +0 -1
  35. package/dist/parse-utils.js +0 -60
  36. package/dist/string-utils.d.ts +0 -99
  37. package/dist/string-utils.js +0 -129
  38. package/dist/token-types.d.ts +0 -35
  39. package/dist/token-types.js +0 -29
  40. package/dist/walk.d.ts +0 -28
  41. package/dist/walk.js +0 -51
package/dist/tokenize.js CHANGED
@@ -1,546 +1,2 @@
1
- import { char_types, CHAR_WHITESPACE, CHAR_NEWLINE, CHAR_DIGIT, is_ident_start, is_hex_digit, is_whitespace, CHAR_IDENT } from './char-types.js';
2
- import { TOKEN_EOF, TOKEN_RIGHT_PAREN, TOKEN_LEFT_PAREN, TOKEN_RIGHT_BRACKET, TOKEN_LEFT_BRACKET, TOKEN_COMMA, TOKEN_SEMICOLON, TOKEN_COLON, TOKEN_RIGHT_BRACE, TOKEN_LEFT_BRACE, TOKEN_CDO, TOKEN_CDC, TOKEN_DELIM, TOKEN_WHITESPACE, TOKEN_STRING, TOKEN_BAD_STRING, TOKEN_PERCENTAGE, TOKEN_DIMENSION, TOKEN_NUMBER, TOKEN_FUNCTION, TOKEN_IDENT, TOKEN_UNICODE_RANGE, TOKEN_AT_KEYWORD, TOKEN_HASH } from './token-types.js';
3
-
4
- function is_newline(ch) {
5
- return ch < 128 && (char_types[ch] & CHAR_NEWLINE) !== 0;
6
- }
7
- const CHAR_LEFT_BRACE = 123;
8
- const CHAR_RIGHT_BRACE = 125;
9
- const CHAR_COLON = 58;
10
- const CHAR_SEMICOLON = 59;
11
- const CHAR_COMMA = 44;
12
- const CHAR_LEFT_BRACKET = 91;
13
- const CHAR_RIGHT_BRACKET = 93;
14
- const CHAR_LEFT_PAREN = 40;
15
- const CHAR_RIGHT_PAREN = 41;
16
- const CHAR_FORWARD_SLASH = 47;
17
- const CHAR_ASTERISK = 42;
18
- const CHAR_DOUBLE_QUOTE = 34;
19
- const CHAR_SINGLE_QUOTE = 39;
20
- const CHAR_DOT = 46;
21
- const CHAR_LESS_THAN = 60;
22
- const CHAR_EXCLAMATION = 33;
23
- const CHAR_HYPHEN = 45;
24
- const CHAR_GREATER_THAN = 62;
25
- const CHAR_AT_SIGN = 64;
26
- const CHAR_HASH = 35;
27
- const CHAR_BACKSLASH = 92;
28
- const CHAR_PLUS = 43;
29
- const CHAR_PERCENT = 37;
30
- const CHAR_LOWERCASE_E = 101;
31
- const CHAR_UPPERCASE_E = 69;
32
- const CHAR_LOWERCASE_U = 117;
33
- const CHAR_UPPERCASE_U = 85;
34
- const CHAR_QUESTION_MARK = 63;
35
- const CHAR_CARRIAGE_RETURN = 13;
36
- const CHAR_LINE_FEED = 10;
37
- class Lexer {
38
- source;
39
- pos;
40
- _line;
41
- _line_offset;
42
- on_comment;
43
- // Current token properties (avoiding object allocation)
44
- token_type;
45
- token_start;
46
- token_end;
47
- token_line;
48
- token_column;
49
- constructor(source, on_comment) {
50
- this.source = source;
51
- this.pos = 0;
52
- this._line = 1;
53
- this._line_offset = 0;
54
- this.on_comment = on_comment;
55
- this.token_type = TOKEN_EOF;
56
- this.token_start = 0;
57
- this.token_end = 0;
58
- this.token_line = 1;
59
- this.token_column = 1;
60
- }
61
- get line() {
62
- return this._line;
63
- }
64
- get column() {
65
- return this.pos - this._line_offset + 1;
66
- }
67
- seek(pos, line, column = 1) {
68
- this.pos = pos;
69
- this._line = line;
70
- this._line_offset = pos - column + 1;
71
- }
72
- // Fast token advancing without object allocation (for internal parser use)
73
- next_token_fast(skip_whitespace = false) {
74
- if (skip_whitespace) {
75
- while (this.pos < this.source.length) {
76
- let ch2 = this.source.charCodeAt(this.pos);
77
- if (ch2 >= 128 || (char_types[ch2] & (CHAR_WHITESPACE | CHAR_NEWLINE)) === 0) break;
78
- this.advance();
79
- }
80
- }
81
- if (this.pos >= this.source.length) {
82
- return this.make_token(TOKEN_EOF, this.pos, this.pos);
83
- }
84
- let ch = this.source.charCodeAt(this.pos);
85
- let start = this.pos;
86
- let start_line = this.line;
87
- let start_column = this.column;
88
- switch (ch) {
89
- case CHAR_LEFT_BRACE:
90
- this.advance();
91
- return this.make_token(TOKEN_LEFT_BRACE, start, this.pos, start_line, start_column);
92
- case CHAR_RIGHT_BRACE:
93
- this.advance();
94
- return this.make_token(TOKEN_RIGHT_BRACE, start, this.pos, start_line, start_column);
95
- case CHAR_COLON:
96
- this.advance();
97
- return this.make_token(TOKEN_COLON, start, this.pos, start_line, start_column);
98
- case CHAR_SEMICOLON:
99
- this.advance();
100
- return this.make_token(TOKEN_SEMICOLON, start, this.pos, start_line, start_column);
101
- case CHAR_COMMA:
102
- this.advance();
103
- return this.make_token(TOKEN_COMMA, start, this.pos, start_line, start_column);
104
- case CHAR_LEFT_BRACKET:
105
- this.advance();
106
- return this.make_token(TOKEN_LEFT_BRACKET, start, this.pos, start_line, start_column);
107
- case CHAR_RIGHT_BRACKET:
108
- this.advance();
109
- return this.make_token(TOKEN_RIGHT_BRACKET, start, this.pos, start_line, start_column);
110
- case CHAR_LEFT_PAREN:
111
- this.advance();
112
- return this.make_token(TOKEN_LEFT_PAREN, start, this.pos, start_line, start_column);
113
- case CHAR_RIGHT_PAREN:
114
- this.advance();
115
- return this.make_token(TOKEN_RIGHT_PAREN, start, this.pos, start_line, start_column);
116
- }
117
- if (ch < 128 && (char_types[ch] & (CHAR_WHITESPACE | CHAR_NEWLINE)) !== 0) {
118
- return this.consume_whitespace(start_line, start_column);
119
- }
120
- if (ch === CHAR_FORWARD_SLASH && this.peek() === CHAR_ASTERISK) {
121
- let comment_start = start;
122
- let comment_line = start_line;
123
- let comment_column = start_column;
124
- this.advance(2);
125
- while (this.pos < this.source.length - 1) {
126
- let ch2 = this.source.charCodeAt(this.pos);
127
- if (ch2 === CHAR_ASTERISK && this.peek() === CHAR_FORWARD_SLASH) {
128
- this.advance(2);
129
- break;
130
- }
131
- this.advance();
132
- }
133
- let comment_end = this.pos;
134
- if (this.on_comment) {
135
- this.on_comment({
136
- start: comment_start,
137
- end: comment_end,
138
- length: comment_end - comment_start,
139
- line: comment_line,
140
- column: comment_column
141
- });
142
- }
143
- return this.next_token_fast(skip_whitespace);
144
- }
145
- if (ch === CHAR_DOUBLE_QUOTE || ch === CHAR_SINGLE_QUOTE) {
146
- return this.consume_string(ch, start_line, start_column);
147
- }
148
- if (ch < 128 && (char_types[ch] & CHAR_DIGIT) !== 0) {
149
- return this.consume_number(start_line, start_column);
150
- }
151
- if (ch === CHAR_DOT) {
152
- let next = this.peek();
153
- if (next < 128 && (char_types[next] & CHAR_DIGIT) !== 0) {
154
- return this.consume_number(start_line, start_column);
155
- }
156
- }
157
- if (ch === CHAR_LESS_THAN && this.pos + 3 < this.source.length) {
158
- if (this.peek() === CHAR_EXCLAMATION && this.peek(2) === CHAR_HYPHEN && this.peek(3) === CHAR_HYPHEN) {
159
- this.advance(4);
160
- return this.make_token(TOKEN_CDO, start, this.pos, start_line, start_column);
161
- }
162
- }
163
- if (ch === CHAR_HYPHEN && this.pos + 2 < this.source.length) {
164
- if (this.peek() === CHAR_HYPHEN && this.peek(2) === CHAR_GREATER_THAN) {
165
- this.advance(3);
166
- return this.make_token(TOKEN_CDC, start, this.pos, start_line, start_column);
167
- }
168
- }
169
- if (ch === CHAR_AT_SIGN) {
170
- return this.consume_at_keyword(start_line, start_column);
171
- }
172
- if (ch === CHAR_HASH) {
173
- return this.consume_hash(start_line, start_column);
174
- }
175
- if (is_ident_start(ch)) {
176
- return this.consume_ident_or_function(start_line, start_column);
177
- }
178
- if (ch === CHAR_HYPHEN) {
179
- let next = this.peek();
180
- if (is_ident_start(next) || next === CHAR_HYPHEN) {
181
- return this.consume_ident_or_function(start_line, start_column);
182
- }
183
- }
184
- if (ch === CHAR_BACKSLASH) {
185
- let next = this.peek();
186
- if (next !== 0 && !is_newline(next)) {
187
- return this.consume_ident_or_function(start_line, start_column);
188
- }
189
- }
190
- if (ch === CHAR_HYPHEN || ch === CHAR_PLUS) {
191
- let next = this.peek();
192
- let is_next_digit = next < 128 && (char_types[next] & CHAR_DIGIT) !== 0;
193
- if (is_next_digit) {
194
- return this.consume_number(start_line, start_column);
195
- }
196
- if (next === CHAR_DOT) {
197
- let next2 = this.peek(2);
198
- if (next2 < 128 && (char_types[next2] & CHAR_DIGIT) !== 0) {
199
- return this.consume_number(start_line, start_column);
200
- }
201
- }
202
- }
203
- this.advance();
204
- return this.make_token(TOKEN_DELIM, start, this.pos, start_line, start_column);
205
- }
206
- consume_whitespace(start_line, start_column) {
207
- let start = this.pos;
208
- while (this.pos < this.source.length) {
209
- let ch = this.source.charCodeAt(this.pos);
210
- if (ch >= 128 || (char_types[ch] & (CHAR_WHITESPACE | CHAR_NEWLINE)) === 0) break;
211
- this.advance();
212
- }
213
- return this.make_token(TOKEN_WHITESPACE, start, this.pos, start_line, start_column);
214
- }
215
- consume_string(quote, start_line, start_column) {
216
- let start = this.pos;
217
- this.advance();
218
- while (this.pos < this.source.length) {
219
- let ch = this.source.charCodeAt(this.pos);
220
- if (ch === quote) {
221
- this.advance();
222
- return this.make_token(TOKEN_STRING, start, this.pos, start_line, start_column);
223
- }
224
- if (is_newline(ch)) {
225
- return this.make_token(TOKEN_BAD_STRING, start, this.pos, start_line, start_column);
226
- }
227
- if (ch === CHAR_BACKSLASH) {
228
- this.advance();
229
- if (this.pos < this.source.length) {
230
- let next = this.source.charCodeAt(this.pos);
231
- if (is_hex_digit(next)) {
232
- this.consume_hex_escape();
233
- } else if (!is_newline(next)) {
234
- this.advance();
235
- } else {
236
- this.advance();
237
- }
238
- }
239
- continue;
240
- }
241
- this.advance();
242
- }
243
- return this.make_token(TOKEN_BAD_STRING, start, this.pos, start_line, start_column);
244
- }
245
- consume_hex_escape() {
246
- let count = 0;
247
- while (count < 6 && this.pos < this.source.length) {
248
- let ch = this.source.charCodeAt(this.pos);
249
- if (!is_hex_digit(ch)) break;
250
- this.advance();
251
- count++;
252
- }
253
- if (this.pos < this.source.length) {
254
- let ch = this.source.charCodeAt(this.pos);
255
- if (is_whitespace(ch) || is_newline(ch)) {
256
- this.advance();
257
- }
258
- }
259
- }
260
- consume_number(start_line, start_column) {
261
- let start = this.pos;
262
- let ch = this.source.charCodeAt(this.pos);
263
- if (ch === CHAR_PLUS || ch === CHAR_HYPHEN) {
264
- this.advance();
265
- }
266
- while (this.pos < this.source.length) {
267
- let ch2 = this.source.charCodeAt(this.pos);
268
- if (ch2 >= 128 || (char_types[ch2] & CHAR_DIGIT) === 0) break;
269
- this.advance();
270
- }
271
- if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_DOT && this.pos + 1 < this.source.length) {
272
- let next = this.peek();
273
- if (next < 128 && (char_types[next] & CHAR_DIGIT) !== 0) {
274
- this.advance();
275
- while (this.pos < this.source.length) {
276
- let ch2 = this.source.charCodeAt(this.pos);
277
- if (ch2 >= 128 || (char_types[ch2] & CHAR_DIGIT) === 0) break;
278
- this.advance();
279
- }
280
- }
281
- }
282
- if (this.pos < this.source.length) {
283
- let ch2 = this.source.charCodeAt(this.pos);
284
- if (ch2 === CHAR_LOWERCASE_E || ch2 === CHAR_UPPERCASE_E) {
285
- let next = this.peek();
286
- let is_next_digit = next < 128 && (char_types[next] & CHAR_DIGIT) !== 0;
287
- let next2 = this.peek(2);
288
- let is_next2_digit = next2 < 128 && (char_types[next2] & CHAR_DIGIT) !== 0;
289
- if (is_next_digit || (next === CHAR_PLUS || next === CHAR_HYPHEN) && is_next2_digit) {
290
- this.advance();
291
- if (this.pos < this.source.length) {
292
- let sign = this.source.charCodeAt(this.pos);
293
- if (sign === CHAR_PLUS || sign === CHAR_HYPHEN) {
294
- this.advance();
295
- }
296
- }
297
- while (this.pos < this.source.length) {
298
- let ch3 = this.source.charCodeAt(this.pos);
299
- if (ch3 >= 128 || (char_types[ch3] & CHAR_DIGIT) === 0) break;
300
- this.advance();
301
- }
302
- }
303
- }
304
- }
305
- if (this.pos < this.source.length) {
306
- let ch2 = this.source.charCodeAt(this.pos);
307
- if (ch2 === CHAR_PERCENT) {
308
- this.advance();
309
- return this.make_token(TOKEN_PERCENTAGE, start, this.pos, start_line, start_column);
310
- }
311
- if (is_ident_start(ch2) || ch2 === CHAR_HYPHEN && is_ident_start(this.peek())) {
312
- while (this.pos < this.source.length) {
313
- let ch3 = this.source.charCodeAt(this.pos);
314
- if (ch3 < 128 && (char_types[ch3] & CHAR_IDENT) === 0) break;
315
- this.advance();
316
- }
317
- return this.make_token(TOKEN_DIMENSION, start, this.pos, start_line, start_column);
318
- }
319
- }
320
- return this.make_token(TOKEN_NUMBER, start, this.pos, start_line, start_column);
321
- }
322
- consume_ident_or_function(start_line, start_column) {
323
- let start = this.pos;
324
- while (this.pos < this.source.length) {
325
- let ch = this.source.charCodeAt(this.pos);
326
- if (ch === CHAR_BACKSLASH) {
327
- if (this.pos + 1 >= this.source.length) break;
328
- let next = this.peek();
329
- if (is_newline(next)) break;
330
- this.advance();
331
- if (is_hex_digit(next)) {
332
- this.advance();
333
- for (let i = 0; i < 5 && this.pos < this.source.length; i++) {
334
- if (!is_hex_digit(this.source.charCodeAt(this.pos))) break;
335
- this.advance();
336
- }
337
- if (this.pos < this.source.length) {
338
- let ws = this.source.charCodeAt(this.pos);
339
- if (is_whitespace(ws) || is_newline(ws)) {
340
- this.advance();
341
- }
342
- }
343
- } else {
344
- this.advance();
345
- }
346
- } else if (ch >= 128 || (char_types[ch] & CHAR_IDENT) !== 0) {
347
- this.advance();
348
- } else {
349
- break;
350
- }
351
- }
352
- if (this.pos - start === 1) {
353
- let first_ch = this.source.charCodeAt(start);
354
- if ((first_ch === CHAR_LOWERCASE_U || first_ch === CHAR_UPPERCASE_U) && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_PLUS) {
355
- return this.consume_unicode_range(start, start_line, start_column);
356
- }
357
- }
358
- if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LEFT_PAREN) {
359
- this.advance();
360
- return this.make_token(TOKEN_FUNCTION, start, this.pos, start_line, start_column);
361
- }
362
- return this.make_token(TOKEN_IDENT, start, this.pos, start_line, start_column);
363
- }
364
- consume_unicode_range(start, start_line, start_column) {
365
- this.advance();
366
- let hex_digits = 0;
367
- let has_question = false;
368
- while (this.pos < this.source.length && hex_digits < 6) {
369
- let ch = this.source.charCodeAt(this.pos);
370
- if (is_hex_digit(ch)) {
371
- if (has_question) {
372
- break;
373
- }
374
- this.advance();
375
- hex_digits++;
376
- } else if (ch === CHAR_QUESTION_MARK) {
377
- this.advance();
378
- hex_digits++;
379
- has_question = true;
380
- } else {
381
- break;
382
- }
383
- }
384
- if (has_question) {
385
- return this.make_token(TOKEN_UNICODE_RANGE, start, this.pos, start_line, start_column);
386
- }
387
- if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_HYPHEN) {
388
- if (this.pos + 1 < this.source.length && is_hex_digit(this.source.charCodeAt(this.pos + 1))) {
389
- this.advance();
390
- let end_hex_digits = 0;
391
- while (this.pos < this.source.length && end_hex_digits < 6) {
392
- let ch = this.source.charCodeAt(this.pos);
393
- if (is_hex_digit(ch)) {
394
- this.advance();
395
- end_hex_digits++;
396
- } else {
397
- break;
398
- }
399
- }
400
- }
401
- }
402
- return this.make_token(TOKEN_UNICODE_RANGE, start, this.pos, start_line, start_column);
403
- }
404
- consume_at_keyword(start_line, start_column) {
405
- let start = this.pos;
406
- this.advance();
407
- while (this.pos < this.source.length) {
408
- let ch = this.source.charCodeAt(this.pos);
409
- if (ch < 128 && (char_types[ch] & CHAR_IDENT) === 0) break;
410
- this.advance();
411
- }
412
- return this.make_token(TOKEN_AT_KEYWORD, start, this.pos, start_line, start_column);
413
- }
414
- consume_hash(start_line, start_column) {
415
- let start = this.pos;
416
- this.advance();
417
- while (this.pos < this.source.length) {
418
- let ch = this.source.charCodeAt(this.pos);
419
- if (ch < 128 && (char_types[ch] & CHAR_IDENT) === 0) break;
420
- this.advance();
421
- }
422
- return this.make_token(TOKEN_HASH, start, this.pos, start_line, start_column);
423
- }
424
- advance(count = 1) {
425
- if (count === 1) {
426
- if (this.pos >= this.source.length) return;
427
- let ch = this.source.charCodeAt(this.pos);
428
- this.pos++;
429
- if (ch < 128 && (char_types[ch] & CHAR_NEWLINE) !== 0) {
430
- if (ch === CHAR_CARRIAGE_RETURN && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LINE_FEED) {
431
- this.pos++;
432
- }
433
- this._line++;
434
- this._line_offset = this.pos;
435
- }
436
- return;
437
- }
438
- for (let i = 0; i < count; i++) {
439
- if (this.pos >= this.source.length) break;
440
- let ch = this.source.charCodeAt(this.pos);
441
- this.pos++;
442
- if (ch < 128 && (char_types[ch] & CHAR_NEWLINE) !== 0) {
443
- if (ch === CHAR_CARRIAGE_RETURN && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LINE_FEED) {
444
- this.pos++;
445
- i++;
446
- }
447
- this._line++;
448
- this._line_offset = this.pos;
449
- }
450
- }
451
- }
452
- peek(offset = 1) {
453
- let index = this.pos + offset;
454
- if (index >= this.source.length) return 0;
455
- return this.source.charCodeAt(index);
456
- }
457
- make_token(type, start, end, line = this.line, column = this.column) {
458
- this.token_type = type;
459
- this.token_start = start;
460
- this.token_end = end;
461
- this.token_line = line;
462
- this.token_column = column;
463
- return type;
464
- }
465
- // Public API: returns Token object for backwards compatibility
466
- next_token(skip_whitespace = false) {
467
- this.next_token_fast(skip_whitespace);
468
- return {
469
- type: this.token_type,
470
- start: this.token_start,
471
- end: this.token_end,
472
- line: this.token_line,
473
- column: this.token_column
474
- };
475
- }
476
- /**
477
- * Save complete lexer state for backtracking
478
- * @returns Object containing all lexer state
479
- */
480
- save_position() {
481
- return {
482
- pos: this.pos,
483
- line: this._line,
484
- column: this.column,
485
- _line_offset: this._line_offset,
486
- token_type: this.token_type,
487
- token_start: this.token_start,
488
- token_end: this.token_end,
489
- token_line: this.token_line,
490
- token_column: this.token_column
491
- };
492
- }
493
- /**
494
- * Restore lexer state from saved position
495
- * @param saved The saved position to restore
496
- */
497
- restore_position(saved) {
498
- this.pos = saved.pos;
499
- this._line = saved.line;
500
- this._line_offset = saved._line_offset;
501
- this.token_type = saved.token_type;
502
- this.token_start = saved.token_start;
503
- this.token_end = saved.token_end;
504
- this.token_line = saved.token_line;
505
- this.token_column = saved.token_column;
506
- }
507
- /**
508
- * Skip whitespace and comments within a range, maintaining line/column tracking
509
- * @param end The end boundary (exclusive)
510
- */
511
- skip_whitespace_in_range(end) {
512
- while (this.pos < end) {
513
- let ch = this.source.charCodeAt(this.pos);
514
- if (is_whitespace(ch)) {
515
- this.advance();
516
- continue;
517
- }
518
- if (ch === CHAR_FORWARD_SLASH && this.pos + 1 < end && this.source.charCodeAt(this.pos + 1) === CHAR_ASTERISK) {
519
- this.advance();
520
- this.advance();
521
- while (this.pos < end) {
522
- if (this.source.charCodeAt(this.pos) === CHAR_ASTERISK && this.pos + 1 < end && this.source.charCodeAt(this.pos + 1) === CHAR_FORWARD_SLASH) {
523
- this.advance();
524
- this.advance();
525
- break;
526
- }
527
- this.advance();
528
- }
529
- continue;
530
- }
531
- break;
532
- }
533
- }
534
- }
535
- function* tokenize(source, on_comment) {
536
- const lexer = new Lexer(source, on_comment);
537
- while (true) {
538
- const token = lexer.next_token();
539
- if (!token || token.type === TOKEN_EOF) {
540
- break;
541
- }
542
- yield token;
543
- }
544
- }
545
-
1
+ import { n as tokenize, t as Lexer } from "./tokenize-BQFB1jXg.js";
546
2
  export { Lexer, tokenize };
package/package.json CHANGED
@@ -1,15 +1,24 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.13.5",
3
+ "version": "0.13.8",
4
4
  "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
- "author": "Bart Veneman <bart@projectwallace.com>",
5
+ "keywords": [
6
+ "ast",
7
+ "css",
8
+ "lexer",
9
+ "parser",
10
+ "tokenizer"
11
+ ],
12
+ "homepage": "https://github.com/projectwallace/css-parser",
6
13
  "license": "MIT",
14
+ "author": "Bart Veneman <bart@projectwallace.com>",
7
15
  "repository": {
8
16
  "type": "git",
9
17
  "url": "git+https://github.com/projectwallace/css-parser.git"
10
18
  },
11
- "issues": "https://github.com/projectwallace/css-parser/issues",
12
- "homepage": "https://github.com/projectwallace/css-parser",
19
+ "files": [
20
+ "dist"
21
+ ],
13
22
  "type": "module",
14
23
  "main": "./dist/index.js",
15
24
  "module": "./dist/index.js",
@@ -53,48 +62,33 @@
53
62
  "import": "./dist/parse-dimension.js"
54
63
  }
55
64
  },
56
- "files": [
57
- "dist"
58
- ],
59
65
  "scripts": {
60
66
  "test": "vitest",
61
67
  "test-coverage": "vitest --coverage",
62
68
  "test-build": "npm run build && vitest run --config vitest.config.build.ts",
63
- "build": "vite build && tsc --project tsconfig.build.json",
69
+ "build": "tsdown",
64
70
  "benchmark": "npm run build && node benchmark/index.ts",
65
71
  "benchmark:memory": "npm run build && node --expose-gc benchmark/memory.ts",
66
- "lint": "oxlint --config .oxlintrc.json",
67
- "lint-package": "publint",
72
+ "lint": "oxlint --config .oxlintrc.json && oxfmt --check",
68
73
  "check": "tsc --noEmit",
69
74
  "precommit": "npm run test -- --run; npm run lint; npm run check"
70
75
  },
71
- "keywords": [
72
- "css",
73
- "parser",
74
- "lexer",
75
- "tokenizer",
76
- "ast"
77
- ],
78
76
  "devDependencies": {
79
- "@codecov/vite-plugin": "^1.9.1",
77
+ "@codecov/rollup-plugin": "^1.9.1",
80
78
  "@projectwallace/preset-oxlint": "^0.0.7",
81
79
  "@types/node": "^24.10.1",
82
80
  "@vitest/coverage-v8": "^4.0.8",
83
81
  "bootstrap": "^5.3.8",
84
82
  "css-tree": "^3.1.0",
83
+ "oxfmt": "^0.36.0",
85
84
  "oxlint": "^1.28.0",
86
85
  "postcss": "^8.5.6",
87
- "prettier": "^3.6.2",
88
- "publint": "^0.3.15",
86
+ "publint": "^0.3.18",
89
87
  "tailwindcss": "^2.2.8",
90
88
  "tinybench": "^2.9.0",
89
+ "tsdown": "^0.21.0",
91
90
  "typescript": "^5.9.3",
92
- "vite": "^7.2.2",
93
91
  "vitest": "^4.0.8"
94
92
  },
95
- "overrides": {
96
- "@codecov/vite-plugin": {
97
- "vite": "$vite"
98
- }
99
- }
93
+ "issues": "https://github.com/projectwallace/css-parser/issues"
100
94
  }
package/dist/arena.d.ts DELETED
@@ -1,60 +0,0 @@
1
- export declare const STYLESHEET = 1;
2
- export declare const STYLE_RULE = 2;
3
- export declare const AT_RULE = 3;
4
- export declare const DECLARATION = 4;
5
- export declare const SELECTOR = 5;
6
- export declare const COMMENT = 6;
7
- export declare const BLOCK = 7;
8
- export declare const RAW = 8;
9
- export declare const IDENTIFIER = 10;
10
- export declare const NUMBER = 11;
11
- export declare const DIMENSION = 12;
12
- export declare const STRING = 13;
13
- export declare const HASH = 14;
14
- export declare const FUNCTION = 15;
15
- export declare const OPERATOR = 16;
16
- export declare const PARENTHESIS = 17;
17
- export declare const URL = 18;
18
- export declare const UNICODE_RANGE = 19;
19
- export declare const SELECTOR_LIST = 20;
20
- export declare const TYPE_SELECTOR = 21;
21
- export declare const CLASS_SELECTOR = 22;
22
- export declare const ID_SELECTOR = 23;
23
- export declare const ATTRIBUTE_SELECTOR = 24;
24
- export declare const PSEUDO_CLASS_SELECTOR = 25;
25
- export declare const PSEUDO_ELEMENT_SELECTOR = 26;
26
- export declare const COMBINATOR = 27;
27
- export declare const UNIVERSAL_SELECTOR = 28;
28
- export declare const NESTING_SELECTOR = 29;
29
- export declare const NTH_SELECTOR = 30;
30
- export declare const NTH_OF_SELECTOR = 31;
31
- export declare const LANG_SELECTOR = 56;
32
- export declare const MEDIA_QUERY = 32;
33
- export declare const MEDIA_FEATURE = 33;
34
- export declare const MEDIA_TYPE = 34;
35
- export declare const CONTAINER_QUERY = 35;
36
- export declare const SUPPORTS_QUERY = 36;
37
- export declare const LAYER_NAME = 37;
38
- export declare const PRELUDE_OPERATOR = 38;
39
- export declare const FEATURE_RANGE = 39;
40
- export declare const AT_RULE_PRELUDE = 40;
41
- export declare const PRELUDE_SELECTORLIST = 41;
42
- export declare const VALUE = 50;
43
- export declare const FLAG_IMPORTANT: number;
44
- export declare const FLAG_HAS_ERROR: number;
45
- export declare const FLAG_LENGTH_OVERFLOW: number;
46
- export declare const FLAG_HAS_BLOCK: number;
47
- export declare const FLAG_VENDOR_PREFIXED: number;
48
- export declare const FLAG_HAS_DECLARATIONS: number;
49
- export declare const FLAG_HAS_PARENS: number;
50
- export declare const FLAG_BROWSERHACK: number;
51
- export declare const ATTR_OPERATOR_NONE = 0;
52
- export declare const ATTR_OPERATOR_EQUAL = 1;
53
- export declare const ATTR_OPERATOR_TILDE_EQUAL = 2;
54
- export declare const ATTR_OPERATOR_PIPE_EQUAL = 3;
55
- export declare const ATTR_OPERATOR_CARET_EQUAL = 4;
56
- export declare const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
57
- export declare const ATTR_OPERATOR_STAR_EQUAL = 6;
58
- export declare const ATTR_FLAG_NONE = 0;
59
- export declare const ATTR_FLAG_CASE_INSENSITIVE = 1;
60
- export declare const ATTR_FLAG_CASE_SENSITIVE = 2;