@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
@@ -0,0 +1,540 @@
1
+ let char_types = new Uint8Array(128);
2
+ for (let i = 48; i <= 57; i++) char_types[i] = 2;
3
+ for (let i = 48; i <= 57; i++) char_types[i] |= 4;
4
+ for (let i = 65; i <= 70; i++) char_types[i] = 4;
5
+ for (let i = 97; i <= 102; i++) char_types[i] = 4;
6
+ for (let i = 65; i <= 90; i++) char_types[i] |= 1;
7
+ for (let i = 97; i <= 122; i++) char_types[i] |= 1;
8
+ char_types[32] = 8;
9
+ char_types[9] = 8;
10
+ char_types[10] = 16;
11
+ char_types[13] = 16;
12
+ char_types[12] = 16;
13
+ for (let i = 0; i < 128; i++) if (char_types[i] & 3) char_types[i] |= 32;
14
+ char_types[45] |= 32;
15
+ char_types[95] |= 32;
16
+ function is_hex_digit(ch) {
17
+ return ch < 128 && (char_types[ch] & 4) !== 0;
18
+ }
19
+ function is_alpha(ch) {
20
+ return ch < 128 && (char_types[ch] & 1) !== 0;
21
+ }
22
+ function is_whitespace(ch) {
23
+ return ch < 128 && (char_types[ch] & 8) !== 0;
24
+ }
25
+ function is_ident_start(ch) {
26
+ if (ch >= 128) return true;
27
+ if (ch === 95) return true;
28
+ return is_alpha(ch);
29
+ }
30
+ //#endregion
31
+ //#region src/token-types.ts
32
+ const TOKEN_IDENT = 1;
33
+ const TOKEN_FUNCTION = 2;
34
+ const TOKEN_AT_KEYWORD = 3;
35
+ const TOKEN_HASH = 4;
36
+ const TOKEN_STRING = 5;
37
+ const TOKEN_BAD_STRING = 6;
38
+ const TOKEN_URL = 7;
39
+ const TOKEN_BAD_URL = 8;
40
+ const TOKEN_DELIM = 9;
41
+ const TOKEN_NUMBER = 10;
42
+ const TOKEN_PERCENTAGE = 11;
43
+ const TOKEN_DIMENSION = 12;
44
+ const TOKEN_WHITESPACE = 13;
45
+ const TOKEN_CDO = 14;
46
+ const TOKEN_CDC = 15;
47
+ const TOKEN_COLON = 16;
48
+ const TOKEN_SEMICOLON = 17;
49
+ const TOKEN_COMMA = 18;
50
+ const TOKEN_LEFT_BRACKET = 19;
51
+ const TOKEN_RIGHT_BRACKET = 20;
52
+ const TOKEN_LEFT_PAREN = 21;
53
+ const TOKEN_RIGHT_PAREN = 22;
54
+ const TOKEN_LEFT_BRACE = 23;
55
+ const TOKEN_RIGHT_BRACE = 24;
56
+ const TOKEN_COMMENT = 25;
57
+ const TOKEN_EOF = 26;
58
+ const TOKEN_UNICODE_RANGE = 27;
59
+ //#endregion
60
+ //#region src/tokenize.ts
61
+ function is_newline(ch) {
62
+ return ch < 128 && (char_types[ch] & 16) !== 0;
63
+ }
64
+ const CHAR_LEFT_BRACE = 123;
65
+ const CHAR_RIGHT_BRACE = 125;
66
+ const CHAR_COLON = 58;
67
+ const CHAR_SEMICOLON = 59;
68
+ const CHAR_COMMA = 44;
69
+ const CHAR_LEFT_BRACKET = 91;
70
+ const CHAR_RIGHT_BRACKET = 93;
71
+ const CHAR_LEFT_PAREN = 40;
72
+ const CHAR_RIGHT_PAREN = 41;
73
+ const CHAR_FORWARD_SLASH = 47;
74
+ const CHAR_ASTERISK = 42;
75
+ const CHAR_DOUBLE_QUOTE = 34;
76
+ const CHAR_SINGLE_QUOTE = 39;
77
+ const CHAR_DOT = 46;
78
+ const CHAR_LESS_THAN = 60;
79
+ const CHAR_EXCLAMATION = 33;
80
+ const CHAR_HYPHEN = 45;
81
+ const CHAR_GREATER_THAN = 62;
82
+ const CHAR_AT_SIGN = 64;
83
+ const CHAR_HASH = 35;
84
+ const CHAR_BACKSLASH = 92;
85
+ const CHAR_PLUS = 43;
86
+ const CHAR_PERCENT = 37;
87
+ const CHAR_LOWERCASE_E = 101;
88
+ const CHAR_UPPERCASE_E = 69;
89
+ const CHAR_LOWERCASE_U = 117;
90
+ const CHAR_UPPERCASE_U = 85;
91
+ const CHAR_QUESTION_MARK = 63;
92
+ const CHAR_CARRIAGE_RETURN = 13;
93
+ const CHAR_LINE_FEED = 10;
94
+ /** @internal */
95
+ var Lexer = class {
96
+ source;
97
+ pos;
98
+ _line;
99
+ _line_offset;
100
+ on_comment;
101
+ token_type;
102
+ token_start;
103
+ token_end;
104
+ token_line;
105
+ token_column;
106
+ constructor(source, on_comment) {
107
+ this.source = source;
108
+ this.pos = 0;
109
+ this._line = 1;
110
+ this._line_offset = 0;
111
+ this.on_comment = on_comment;
112
+ this.token_type = 26;
113
+ this.token_start = 0;
114
+ this.token_end = 0;
115
+ this.token_line = 1;
116
+ this.token_column = 1;
117
+ }
118
+ get line() {
119
+ return this._line;
120
+ }
121
+ get column() {
122
+ return this.pos - this._line_offset + 1;
123
+ }
124
+ seek(pos, line, column = 1) {
125
+ this.pos = pos;
126
+ this._line = line;
127
+ this._line_offset = pos - column + 1;
128
+ }
129
+ next_token_fast(skip_whitespace = false) {
130
+ if (skip_whitespace) while (this.pos < this.source.length) {
131
+ let ch = this.source.charCodeAt(this.pos);
132
+ if (ch >= 128 || (char_types[ch] & 24) === 0) break;
133
+ this.advance();
134
+ }
135
+ if (this.pos >= this.source.length) return this.make_token(26, this.pos, this.pos);
136
+ let ch = this.source.charCodeAt(this.pos);
137
+ let start = this.pos;
138
+ let start_line = this.line;
139
+ let start_column = this.column;
140
+ switch (ch) {
141
+ case CHAR_LEFT_BRACE:
142
+ this.advance();
143
+ return this.make_token(23, start, this.pos, start_line, start_column);
144
+ case CHAR_RIGHT_BRACE:
145
+ this.advance();
146
+ return this.make_token(24, start, this.pos, start_line, start_column);
147
+ case CHAR_COLON:
148
+ this.advance();
149
+ return this.make_token(16, start, this.pos, start_line, start_column);
150
+ case CHAR_SEMICOLON:
151
+ this.advance();
152
+ return this.make_token(17, start, this.pos, start_line, start_column);
153
+ case CHAR_COMMA:
154
+ this.advance();
155
+ return this.make_token(18, start, this.pos, start_line, start_column);
156
+ case CHAR_LEFT_BRACKET:
157
+ this.advance();
158
+ return this.make_token(19, start, this.pos, start_line, start_column);
159
+ case CHAR_RIGHT_BRACKET:
160
+ this.advance();
161
+ return this.make_token(20, start, this.pos, start_line, start_column);
162
+ case CHAR_LEFT_PAREN:
163
+ this.advance();
164
+ return this.make_token(21, start, this.pos, start_line, start_column);
165
+ case CHAR_RIGHT_PAREN:
166
+ this.advance();
167
+ return this.make_token(22, start, this.pos, start_line, start_column);
168
+ }
169
+ if (ch < 128 && (char_types[ch] & 24) !== 0) return this.consume_whitespace(start_line, start_column);
170
+ if (ch === CHAR_FORWARD_SLASH && this.peek() === CHAR_ASTERISK) {
171
+ let comment_start = start;
172
+ let comment_line = start_line;
173
+ let comment_column = start_column;
174
+ this.advance(2);
175
+ while (this.pos < this.source.length - 1) {
176
+ if (this.source.charCodeAt(this.pos) === CHAR_ASTERISK && this.peek() === CHAR_FORWARD_SLASH) {
177
+ this.advance(2);
178
+ break;
179
+ }
180
+ this.advance();
181
+ }
182
+ let comment_end = this.pos;
183
+ if (this.on_comment) this.on_comment({
184
+ start: comment_start,
185
+ end: comment_end,
186
+ length: comment_end - comment_start,
187
+ line: comment_line,
188
+ column: comment_column
189
+ });
190
+ return this.next_token_fast(skip_whitespace);
191
+ }
192
+ if (ch === CHAR_DOUBLE_QUOTE || ch === CHAR_SINGLE_QUOTE) return this.consume_string(ch, start_line, start_column);
193
+ if (ch < 128 && (char_types[ch] & 2) !== 0) return this.consume_number(start_line, start_column);
194
+ if (ch === CHAR_DOT) {
195
+ let next = this.peek();
196
+ if (next < 128 && (char_types[next] & 2) !== 0) return this.consume_number(start_line, start_column);
197
+ }
198
+ if (ch === CHAR_LESS_THAN && this.pos + 3 < this.source.length) {
199
+ if (this.peek() === CHAR_EXCLAMATION && this.peek(2) === CHAR_HYPHEN && this.peek(3) === CHAR_HYPHEN) {
200
+ this.advance(4);
201
+ return this.make_token(14, start, this.pos, start_line, start_column);
202
+ }
203
+ }
204
+ if (ch === CHAR_HYPHEN && this.pos + 2 < this.source.length) {
205
+ if (this.peek() === CHAR_HYPHEN && this.peek(2) === CHAR_GREATER_THAN) {
206
+ this.advance(3);
207
+ return this.make_token(15, start, this.pos, start_line, start_column);
208
+ }
209
+ }
210
+ if (ch === CHAR_AT_SIGN) return this.consume_at_keyword(start_line, start_column);
211
+ if (ch === CHAR_HASH) return this.consume_hash(start_line, start_column);
212
+ if (is_ident_start(ch)) return this.consume_ident_or_function(start_line, start_column);
213
+ if (ch === CHAR_HYPHEN) {
214
+ let next = this.peek();
215
+ if (is_ident_start(next) || next === CHAR_HYPHEN) return this.consume_ident_or_function(start_line, start_column);
216
+ }
217
+ if (ch === CHAR_BACKSLASH) {
218
+ let next = this.peek();
219
+ if (next !== 0 && !is_newline(next)) return this.consume_ident_or_function(start_line, start_column);
220
+ }
221
+ if (ch === CHAR_HYPHEN || ch === CHAR_PLUS) {
222
+ let next = this.peek();
223
+ if (next < 128 && (char_types[next] & 2) !== 0) return this.consume_number(start_line, start_column);
224
+ if (next === CHAR_DOT) {
225
+ let next2 = this.peek(2);
226
+ if (next2 < 128 && (char_types[next2] & 2) !== 0) return this.consume_number(start_line, start_column);
227
+ }
228
+ }
229
+ this.advance();
230
+ return this.make_token(9, start, this.pos, start_line, start_column);
231
+ }
232
+ consume_whitespace(start_line, start_column) {
233
+ let start = this.pos;
234
+ while (this.pos < this.source.length) {
235
+ let ch = this.source.charCodeAt(this.pos);
236
+ if (ch >= 128 || (char_types[ch] & 24) === 0) break;
237
+ this.advance();
238
+ }
239
+ return this.make_token(13, start, this.pos, start_line, start_column);
240
+ }
241
+ consume_string(quote, start_line, start_column) {
242
+ let start = this.pos;
243
+ this.advance();
244
+ while (this.pos < this.source.length) {
245
+ let ch = this.source.charCodeAt(this.pos);
246
+ if (ch === quote) {
247
+ this.advance();
248
+ return this.make_token(5, start, this.pos, start_line, start_column);
249
+ }
250
+ if (is_newline(ch)) return this.make_token(6, start, this.pos, start_line, start_column);
251
+ if (ch === CHAR_BACKSLASH) {
252
+ this.advance();
253
+ if (this.pos < this.source.length) {
254
+ let next = this.source.charCodeAt(this.pos);
255
+ if (is_hex_digit(next)) this.consume_hex_escape();
256
+ else if (!is_newline(next)) this.advance();
257
+ else this.advance();
258
+ }
259
+ continue;
260
+ }
261
+ this.advance();
262
+ }
263
+ return this.make_token(6, start, this.pos, start_line, start_column);
264
+ }
265
+ consume_hex_escape() {
266
+ let count = 0;
267
+ while (count < 6 && this.pos < this.source.length) {
268
+ if (!is_hex_digit(this.source.charCodeAt(this.pos))) break;
269
+ this.advance();
270
+ count++;
271
+ }
272
+ if (this.pos < this.source.length) {
273
+ let ch = this.source.charCodeAt(this.pos);
274
+ if (is_whitespace(ch) || is_newline(ch)) this.advance();
275
+ }
276
+ }
277
+ consume_number(start_line, start_column) {
278
+ let start = this.pos;
279
+ let ch = this.source.charCodeAt(this.pos);
280
+ if (ch === CHAR_PLUS || ch === CHAR_HYPHEN) this.advance();
281
+ while (this.pos < this.source.length) {
282
+ let ch = this.source.charCodeAt(this.pos);
283
+ if (ch >= 128 || (char_types[ch] & 2) === 0) break;
284
+ this.advance();
285
+ }
286
+ if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_DOT && this.pos + 1 < this.source.length) {
287
+ let next = this.peek();
288
+ if (next < 128 && (char_types[next] & 2) !== 0) {
289
+ this.advance();
290
+ while (this.pos < this.source.length) {
291
+ let ch = this.source.charCodeAt(this.pos);
292
+ if (ch >= 128 || (char_types[ch] & 2) === 0) break;
293
+ this.advance();
294
+ }
295
+ }
296
+ }
297
+ if (this.pos < this.source.length) {
298
+ let ch = this.source.charCodeAt(this.pos);
299
+ if (ch === CHAR_LOWERCASE_E || ch === CHAR_UPPERCASE_E) {
300
+ let next = this.peek();
301
+ let is_next_digit = next < 128 && (char_types[next] & 2) !== 0;
302
+ let next2 = this.peek(2);
303
+ let is_next2_digit = next2 < 128 && (char_types[next2] & 2) !== 0;
304
+ if (is_next_digit || (next === CHAR_PLUS || next === CHAR_HYPHEN) && is_next2_digit) {
305
+ this.advance();
306
+ if (this.pos < this.source.length) {
307
+ let sign = this.source.charCodeAt(this.pos);
308
+ if (sign === CHAR_PLUS || sign === CHAR_HYPHEN) this.advance();
309
+ }
310
+ while (this.pos < this.source.length) {
311
+ let ch = this.source.charCodeAt(this.pos);
312
+ if (ch >= 128 || (char_types[ch] & 2) === 0) break;
313
+ this.advance();
314
+ }
315
+ }
316
+ }
317
+ }
318
+ if (this.pos < this.source.length) {
319
+ let ch = this.source.charCodeAt(this.pos);
320
+ if (ch === CHAR_PERCENT) {
321
+ this.advance();
322
+ return this.make_token(11, start, this.pos, start_line, start_column);
323
+ }
324
+ if (is_ident_start(ch) || ch === CHAR_HYPHEN && is_ident_start(this.peek())) {
325
+ while (this.pos < this.source.length) {
326
+ let ch = this.source.charCodeAt(this.pos);
327
+ if (ch < 128 && (char_types[ch] & 32) === 0) break;
328
+ this.advance();
329
+ }
330
+ return this.make_token(12, start, this.pos, start_line, start_column);
331
+ }
332
+ }
333
+ return this.make_token(10, start, this.pos, start_line, start_column);
334
+ }
335
+ consume_ident_or_function(start_line, start_column) {
336
+ let start = this.pos;
337
+ while (this.pos < this.source.length) {
338
+ let ch = this.source.charCodeAt(this.pos);
339
+ if (ch === CHAR_BACKSLASH) {
340
+ if (this.pos + 1 >= this.source.length) break;
341
+ let next = this.peek();
342
+ if (is_newline(next)) break;
343
+ this.advance();
344
+ if (is_hex_digit(next)) {
345
+ this.advance();
346
+ for (let i = 0; i < 5 && this.pos < this.source.length; i++) {
347
+ if (!is_hex_digit(this.source.charCodeAt(this.pos))) break;
348
+ this.advance();
349
+ }
350
+ if (this.pos < this.source.length) {
351
+ let ws = this.source.charCodeAt(this.pos);
352
+ if (is_whitespace(ws) || is_newline(ws)) this.advance();
353
+ }
354
+ } else this.advance();
355
+ } else if (ch >= 128 || (char_types[ch] & 32) !== 0) this.advance();
356
+ else break;
357
+ }
358
+ if (this.pos - start === 1) {
359
+ let first_ch = this.source.charCodeAt(start);
360
+ if ((first_ch === CHAR_LOWERCASE_U || first_ch === CHAR_UPPERCASE_U) && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_PLUS) return this.consume_unicode_range(start, start_line, start_column);
361
+ }
362
+ if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LEFT_PAREN) {
363
+ this.advance();
364
+ return this.make_token(2, start, this.pos, start_line, start_column);
365
+ }
366
+ return this.make_token(1, start, this.pos, start_line, start_column);
367
+ }
368
+ consume_unicode_range(start, start_line, start_column) {
369
+ this.advance();
370
+ let hex_digits = 0;
371
+ let has_question = false;
372
+ while (this.pos < this.source.length && hex_digits < 6) {
373
+ let ch = this.source.charCodeAt(this.pos);
374
+ if (is_hex_digit(ch)) {
375
+ if (has_question) break;
376
+ this.advance();
377
+ hex_digits++;
378
+ } else if (ch === CHAR_QUESTION_MARK) {
379
+ this.advance();
380
+ hex_digits++;
381
+ has_question = true;
382
+ } else break;
383
+ }
384
+ if (has_question) return this.make_token(27, start, this.pos, start_line, start_column);
385
+ if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_HYPHEN) {
386
+ if (this.pos + 1 < this.source.length && is_hex_digit(this.source.charCodeAt(this.pos + 1))) {
387
+ this.advance();
388
+ let end_hex_digits = 0;
389
+ while (this.pos < this.source.length && end_hex_digits < 6) if (is_hex_digit(this.source.charCodeAt(this.pos))) {
390
+ this.advance();
391
+ end_hex_digits++;
392
+ } else break;
393
+ }
394
+ }
395
+ return this.make_token(27, start, this.pos, start_line, start_column);
396
+ }
397
+ consume_at_keyword(start_line, start_column) {
398
+ let start = this.pos;
399
+ this.advance();
400
+ while (this.pos < this.source.length) {
401
+ let ch = this.source.charCodeAt(this.pos);
402
+ if (ch < 128 && (char_types[ch] & 32) === 0) break;
403
+ this.advance();
404
+ }
405
+ return this.make_token(3, start, this.pos, start_line, start_column);
406
+ }
407
+ consume_hash(start_line, start_column) {
408
+ let start = this.pos;
409
+ this.advance();
410
+ while (this.pos < this.source.length) {
411
+ let ch = this.source.charCodeAt(this.pos);
412
+ if (ch < 128 && (char_types[ch] & 32) === 0) break;
413
+ this.advance();
414
+ }
415
+ return this.make_token(4, start, this.pos, start_line, start_column);
416
+ }
417
+ advance(count = 1) {
418
+ if (count === 1) {
419
+ if (this.pos >= this.source.length) return;
420
+ let ch = this.source.charCodeAt(this.pos);
421
+ this.pos++;
422
+ if (ch < 128 && (char_types[ch] & 16) !== 0) {
423
+ if (ch === CHAR_CARRIAGE_RETURN && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LINE_FEED) this.pos++;
424
+ this._line++;
425
+ this._line_offset = this.pos;
426
+ }
427
+ return;
428
+ }
429
+ for (let i = 0; i < count; i++) {
430
+ if (this.pos >= this.source.length) break;
431
+ let ch = this.source.charCodeAt(this.pos);
432
+ this.pos++;
433
+ if (ch < 128 && (char_types[ch] & 16) !== 0) {
434
+ if (ch === CHAR_CARRIAGE_RETURN && this.pos < this.source.length && this.source.charCodeAt(this.pos) === CHAR_LINE_FEED) {
435
+ this.pos++;
436
+ i++;
437
+ }
438
+ this._line++;
439
+ this._line_offset = this.pos;
440
+ }
441
+ }
442
+ }
443
+ peek(offset = 1) {
444
+ let index = this.pos + offset;
445
+ if (index >= this.source.length) return 0;
446
+ return this.source.charCodeAt(index);
447
+ }
448
+ make_token(type, start, end, line = this.line, column = this.column) {
449
+ this.token_type = type;
450
+ this.token_start = start;
451
+ this.token_end = end;
452
+ this.token_line = line;
453
+ this.token_column = column;
454
+ return type;
455
+ }
456
+ next_token(skip_whitespace = false) {
457
+ this.next_token_fast(skip_whitespace);
458
+ return {
459
+ type: this.token_type,
460
+ start: this.token_start,
461
+ end: this.token_end,
462
+ line: this.token_line,
463
+ column: this.token_column
464
+ };
465
+ }
466
+ /**
467
+ * Save complete lexer state for backtracking
468
+ * @returns Object containing all lexer state
469
+ */
470
+ save_position() {
471
+ return {
472
+ pos: this.pos,
473
+ line: this._line,
474
+ column: this.column,
475
+ _line_offset: this._line_offset,
476
+ token_type: this.token_type,
477
+ token_start: this.token_start,
478
+ token_end: this.token_end,
479
+ token_line: this.token_line,
480
+ token_column: this.token_column
481
+ };
482
+ }
483
+ /**
484
+ * Restore lexer state from saved position
485
+ * @param saved The saved position to restore
486
+ */
487
+ restore_position(saved) {
488
+ this.pos = saved.pos;
489
+ this._line = saved.line;
490
+ this._line_offset = saved._line_offset;
491
+ this.token_type = saved.token_type;
492
+ this.token_start = saved.token_start;
493
+ this.token_end = saved.token_end;
494
+ this.token_line = saved.token_line;
495
+ this.token_column = saved.token_column;
496
+ }
497
+ /**
498
+ * Skip whitespace and comments within a range, maintaining line/column tracking
499
+ * @param end The end boundary (exclusive)
500
+ */
501
+ skip_whitespace_in_range(end) {
502
+ while (this.pos < end) {
503
+ let ch = this.source.charCodeAt(this.pos);
504
+ if (is_whitespace(ch)) {
505
+ this.advance();
506
+ continue;
507
+ }
508
+ if (ch === CHAR_FORWARD_SLASH && this.pos + 1 < end && this.source.charCodeAt(this.pos + 1) === CHAR_ASTERISK) {
509
+ this.advance();
510
+ this.advance();
511
+ while (this.pos < end) {
512
+ if (this.source.charCodeAt(this.pos) === CHAR_ASTERISK && this.pos + 1 < end && this.source.charCodeAt(this.pos + 1) === CHAR_FORWARD_SLASH) {
513
+ this.advance();
514
+ this.advance();
515
+ break;
516
+ }
517
+ this.advance();
518
+ }
519
+ continue;
520
+ }
521
+ break;
522
+ }
523
+ }
524
+ };
525
+ /**
526
+ * Tokenize CSS source code
527
+ * @param source - The CSS source code to tokenize
528
+ * @param on_comment - Optional callback for comment tokens
529
+ * @yields CSS tokens
530
+ */
531
+ function* tokenize(source, on_comment) {
532
+ const lexer = new Lexer(source, on_comment);
533
+ while (true) {
534
+ const token = lexer.next_token();
535
+ if (!token || token.type === 26) break;
536
+ yield token;
537
+ }
538
+ }
539
+ //#endregion
540
+ export { TOKEN_RIGHT_BRACKET as C, TOKEN_UNICODE_RANGE as D, TOKEN_STRING as E, TOKEN_URL as O, TOKEN_RIGHT_BRACE as S, TOKEN_SEMICOLON as T, TOKEN_LEFT_BRACE as _, TOKEN_BAD_URL as a, TOKEN_NUMBER as b, TOKEN_COLON as c, TOKEN_DELIM as d, TOKEN_DIMENSION as f, TOKEN_IDENT as g, TOKEN_HASH as h, TOKEN_BAD_STRING as i, TOKEN_WHITESPACE as k, TOKEN_COMMA as l, TOKEN_FUNCTION as m, tokenize as n, TOKEN_CDC as o, TOKEN_EOF as p, TOKEN_AT_KEYWORD as r, TOKEN_CDO as s, Lexer as t, TOKEN_COMMENT as u, TOKEN_LEFT_BRACKET as v, TOKEN_RIGHT_PAREN as w, TOKEN_PERCENTAGE as x, TOKEN_LEFT_PAREN as y };
@@ -0,0 +1,110 @@
1
+ //#region src/token-types.d.ts
2
+ declare const TOKEN_IDENT = 1;
3
+ declare const TOKEN_FUNCTION = 2;
4
+ declare const TOKEN_AT_KEYWORD = 3;
5
+ declare const TOKEN_HASH = 4;
6
+ declare const TOKEN_STRING = 5;
7
+ declare const TOKEN_BAD_STRING = 6;
8
+ declare const TOKEN_URL = 7;
9
+ declare const TOKEN_BAD_URL = 8;
10
+ declare const TOKEN_DELIM = 9;
11
+ declare const TOKEN_NUMBER = 10;
12
+ declare const TOKEN_PERCENTAGE = 11;
13
+ declare const TOKEN_DIMENSION = 12;
14
+ declare const TOKEN_WHITESPACE = 13;
15
+ declare const TOKEN_CDO = 14;
16
+ declare const TOKEN_CDC = 15;
17
+ declare const TOKEN_COLON = 16;
18
+ declare const TOKEN_SEMICOLON = 17;
19
+ declare const TOKEN_COMMA = 18;
20
+ declare const TOKEN_LEFT_BRACKET = 19;
21
+ declare const TOKEN_RIGHT_BRACKET = 20;
22
+ declare const TOKEN_LEFT_PAREN = 21;
23
+ declare const TOKEN_RIGHT_PAREN = 22;
24
+ declare const TOKEN_LEFT_BRACE = 23;
25
+ declare const TOKEN_RIGHT_BRACE = 24;
26
+ declare const TOKEN_COMMENT = 25;
27
+ declare const TOKEN_EOF = 26;
28
+ declare const TOKEN_UNICODE_RANGE = 27;
29
+ type TokenType = typeof TOKEN_IDENT | typeof TOKEN_FUNCTION | typeof TOKEN_AT_KEYWORD | typeof TOKEN_HASH | typeof TOKEN_STRING | typeof TOKEN_BAD_STRING | typeof TOKEN_URL | typeof TOKEN_BAD_URL | typeof TOKEN_DELIM | typeof TOKEN_NUMBER | typeof TOKEN_PERCENTAGE | typeof TOKEN_DIMENSION | typeof TOKEN_WHITESPACE | typeof TOKEN_CDO | typeof TOKEN_CDC | typeof TOKEN_COLON | typeof TOKEN_SEMICOLON | typeof TOKEN_COMMA | typeof TOKEN_LEFT_BRACKET | typeof TOKEN_RIGHT_BRACKET | typeof TOKEN_LEFT_PAREN | typeof TOKEN_RIGHT_PAREN | typeof TOKEN_LEFT_BRACE | typeof TOKEN_RIGHT_BRACE | typeof TOKEN_COMMENT | typeof TOKEN_EOF | typeof TOKEN_UNICODE_RANGE;
30
+ type Token = {
31
+ type: TokenType;
32
+ start: number;
33
+ end: number;
34
+ line: number;
35
+ column: number;
36
+ };
37
+ //#endregion
38
+ //#region src/tokenize.d.ts
39
+ interface LexerPosition {
40
+ pos: number;
41
+ line: number;
42
+ column: number;
43
+ _line_offset: number;
44
+ token_type: TokenType;
45
+ token_start: number;
46
+ token_end: number;
47
+ token_line: number;
48
+ token_column: number;
49
+ }
50
+ interface CommentInfo {
51
+ start: number;
52
+ end: number;
53
+ length: number;
54
+ line: number;
55
+ column: number;
56
+ }
57
+ /** @internal */
58
+ declare class Lexer {
59
+ source: string;
60
+ pos: number;
61
+ private _line;
62
+ private _line_offset;
63
+ on_comment: ((info: CommentInfo) => void) | undefined;
64
+ token_type: TokenType;
65
+ token_start: number;
66
+ token_end: number;
67
+ token_line: number;
68
+ token_column: number;
69
+ constructor(source: string, on_comment?: (info: CommentInfo) => void);
70
+ get line(): number;
71
+ get column(): number;
72
+ seek(pos: number, line: number, column?: number): void;
73
+ next_token_fast(skip_whitespace?: boolean): TokenType;
74
+ consume_whitespace(start_line: number, start_column: number): TokenType;
75
+ consume_string(quote: number, start_line: number, start_column: number): TokenType;
76
+ consume_hex_escape(): void;
77
+ consume_number(start_line: number, start_column: number): TokenType;
78
+ consume_ident_or_function(start_line: number, start_column: number): TokenType;
79
+ consume_unicode_range(start: number, start_line: number, start_column: number): TokenType;
80
+ consume_at_keyword(start_line: number, start_column: number): TokenType;
81
+ consume_hash(start_line: number, start_column: number): TokenType;
82
+ advance(count?: number): void;
83
+ peek(offset?: number): number;
84
+ make_token(type: TokenType, start: number, end: number, line?: number, column?: number): TokenType;
85
+ next_token(skip_whitespace?: boolean): Token | null;
86
+ /**
87
+ * Save complete lexer state for backtracking
88
+ * @returns Object containing all lexer state
89
+ */
90
+ save_position(): LexerPosition;
91
+ /**
92
+ * Restore lexer state from saved position
93
+ * @param saved The saved position to restore
94
+ */
95
+ restore_position(saved: LexerPosition): void;
96
+ /**
97
+ * Skip whitespace and comments within a range, maintaining line/column tracking
98
+ * @param end The end boundary (exclusive)
99
+ */
100
+ skip_whitespace_in_range(end: number): void;
101
+ }
102
+ /**
103
+ * Tokenize CSS source code
104
+ * @param source - The CSS source code to tokenize
105
+ * @param on_comment - Optional callback for comment tokens
106
+ * @yields CSS tokens
107
+ */
108
+ declare function tokenize(source: string, on_comment?: (info: CommentInfo) => void): Generator<Token, void, undefined>;
109
+ //#endregion
110
+ export { TOKEN_URL as A, TOKEN_PERCENTAGE as C, TOKEN_SEMICOLON as D, TOKEN_RIGHT_PAREN as E, Token as M, TokenType as N, TOKEN_STRING as O, TOKEN_NUMBER as S, TOKEN_RIGHT_BRACKET as T, TOKEN_HASH as _, TOKEN_AT_KEYWORD as a, TOKEN_LEFT_BRACKET as b, TOKEN_CDC as c, TOKEN_COMMA as d, TOKEN_COMMENT as f, TOKEN_FUNCTION as g, TOKEN_EOF as h, tokenize as i, TOKEN_WHITESPACE as j, TOKEN_UNICODE_RANGE as k, TOKEN_CDO as l, TOKEN_DIMENSION as m, Lexer as n, TOKEN_BAD_STRING as o, TOKEN_DELIM as p, LexerPosition as r, TOKEN_BAD_URL as s, CommentInfo as t, TOKEN_COLON as u, TOKEN_IDENT as v, TOKEN_RIGHT_BRACE as w, TOKEN_LEFT_PAREN as x, TOKEN_LEFT_BRACE as y };
@@ -1,26 +1,2 @@
1
- import { type Token, type TokenType } from './token-types';
2
- export interface LexerPosition {
3
- pos: number;
4
- line: number;
5
- column: number;
6
- _line_offset: number;
7
- token_type: TokenType;
8
- token_start: number;
9
- token_end: number;
10
- token_line: number;
11
- token_column: number;
12
- }
13
- export interface CommentInfo {
14
- start: number;
15
- end: number;
16
- length: number;
17
- line: number;
18
- column: number;
19
- }
20
- /**
21
- * Tokenize CSS source code
22
- * @param source - The CSS source code to tokenize
23
- * @param on_comment - Optional callback for comment tokens
24
- * @yields CSS tokens
25
- */
26
- export declare function tokenize(source: string, on_comment?: (info: CommentInfo) => void): Generator<Token, void, undefined>;
1
+ import { i as tokenize, n as Lexer, r as LexerPosition, t as CommentInfo } from "./tokenize-odLrcjj2.js";
2
+ export { CommentInfo, Lexer, LexerPosition, tokenize };