@projectwallace/css-parser 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arena.d.ts +24 -11
- package/dist/{string-utils-tMt2O9RW.js → css-node-BzCSxoLM.js} +263 -90
- package/dist/css-node.d.ts +11 -4
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -5
- package/dist/{lexer-DXablYMZ.js → lexer-CtBKgfVv.js} +30 -0
- package/dist/lexer.d.ts +20 -0
- package/dist/parse-anplusb.d.ts +22 -0
- package/dist/parse-anplusb.js +220 -0
- package/dist/parse-atrule-prelude.d.ts +24 -0
- package/dist/parse-atrule-prelude.js +452 -3
- package/dist/parse-selector.d.ts +30 -0
- package/dist/parse-selector.js +614 -3
- package/dist/parse-utils.d.ts +56 -0
- package/dist/parse-value.d.ts +22 -0
- package/dist/parse-value.js +142 -0
- package/dist/parse.d.ts +34 -2
- package/dist/parse.js +51 -194
- package/dist/string-utils.d.ts +14 -13
- package/dist/tokenize.js +1 -1
- package/dist/walk.d.ts +1 -1
- package/package.json +9 -1
- package/dist/at-rule-prelude-parser-Cj8ecgQp.js +0 -467
- package/dist/at-rule-prelude-parser.d.ts +0 -24
- package/dist/parser.d.ts +0 -34
- package/dist/selector-parser-C-u1epDB.js +0 -370
- package/dist/selector-parser.d.ts +0 -25
- package/dist/value-parser.d.ts +0 -19
package/dist/arena.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const NODE_AT_RULE = 3;
|
|
|
4
4
|
export declare const NODE_DECLARATION = 4;
|
|
5
5
|
export declare const NODE_SELECTOR = 5;
|
|
6
6
|
export declare const NODE_COMMENT = 6;
|
|
7
|
+
export declare const NODE_BLOCK = 7;
|
|
7
8
|
export declare const NODE_VALUE_KEYWORD = 10;
|
|
8
9
|
export declare const NODE_VALUE_NUMBER = 11;
|
|
9
10
|
export declare const NODE_VALUE_DIMENSION = 12;
|
|
@@ -21,23 +22,33 @@ export declare const NODE_SELECTOR_PSEUDO_ELEMENT = 26;
|
|
|
21
22
|
export declare const NODE_SELECTOR_COMBINATOR = 27;
|
|
22
23
|
export declare const NODE_SELECTOR_UNIVERSAL = 28;
|
|
23
24
|
export declare const NODE_SELECTOR_NESTING = 29;
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
25
|
+
export declare const NODE_SELECTOR_NTH = 30;
|
|
26
|
+
export declare const NODE_SELECTOR_NTH_OF = 31;
|
|
27
|
+
export declare const NODE_SELECTOR_LANG = 56;
|
|
28
|
+
export declare const NODE_PRELUDE_MEDIA_QUERY = 32;
|
|
29
|
+
export declare const NODE_PRELUDE_MEDIA_FEATURE = 33;
|
|
30
|
+
export declare const NODE_PRELUDE_MEDIA_TYPE = 34;
|
|
31
|
+
export declare const NODE_PRELUDE_CONTAINER_QUERY = 35;
|
|
32
|
+
export declare const NODE_PRELUDE_SUPPORTS_QUERY = 36;
|
|
33
|
+
export declare const NODE_PRELUDE_LAYER_NAME = 37;
|
|
34
|
+
export declare const NODE_PRELUDE_IDENTIFIER = 38;
|
|
35
|
+
export declare const NODE_PRELUDE_OPERATOR = 39;
|
|
36
|
+
export declare const NODE_PRELUDE_IMPORT_URL = 40;
|
|
37
|
+
export declare const NODE_PRELUDE_IMPORT_LAYER = 41;
|
|
38
|
+
export declare const NODE_PRELUDE_IMPORT_SUPPORTS = 42;
|
|
35
39
|
export declare const FLAG_IMPORTANT: number;
|
|
36
40
|
export declare const FLAG_HAS_ERROR: number;
|
|
37
41
|
export declare const FLAG_LENGTH_OVERFLOW: number;
|
|
38
42
|
export declare const FLAG_HAS_BLOCK: number;
|
|
39
43
|
export declare const FLAG_VENDOR_PREFIXED: number;
|
|
40
44
|
export declare const FLAG_HAS_DECLARATIONS: number;
|
|
45
|
+
export declare const ATTR_OPERATOR_NONE = 0;
|
|
46
|
+
export declare const ATTR_OPERATOR_EQUAL = 1;
|
|
47
|
+
export declare const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
48
|
+
export declare const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
49
|
+
export declare const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
50
|
+
export declare const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
51
|
+
export declare const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
41
52
|
export declare class CSSDataArena {
|
|
42
53
|
private buffer;
|
|
43
54
|
private view;
|
|
@@ -57,6 +68,7 @@ export declare class CSSDataArena {
|
|
|
57
68
|
get_length(node_index: number): number;
|
|
58
69
|
get_content_start(node_index: number): number;
|
|
59
70
|
get_content_length(node_index: number): number;
|
|
71
|
+
get_attr_operator(node_index: number): number;
|
|
60
72
|
get_first_child(node_index: number): number;
|
|
61
73
|
get_last_child(node_index: number): number;
|
|
62
74
|
get_next_sibling(node_index: number): number;
|
|
@@ -70,6 +82,7 @@ export declare class CSSDataArena {
|
|
|
70
82
|
set_length(node_index: number, length: number): void;
|
|
71
83
|
set_content_start(node_index: number, offset: number): void;
|
|
72
84
|
set_content_length(node_index: number, length: number): void;
|
|
85
|
+
set_attr_operator(node_index: number, operator: number): void;
|
|
73
86
|
set_first_child(node_index: number, childIndex: number): void;
|
|
74
87
|
set_last_child(node_index: number, childIndex: number): void;
|
|
75
88
|
set_next_sibling(node_index: number, siblingIndex: number): void;
|
|
@@ -5,6 +5,7 @@ const NODE_AT_RULE = 3;
|
|
|
5
5
|
const NODE_DECLARATION = 4;
|
|
6
6
|
const NODE_SELECTOR = 5;
|
|
7
7
|
const NODE_COMMENT = 6;
|
|
8
|
+
const NODE_BLOCK = 7;
|
|
8
9
|
const NODE_VALUE_KEYWORD = 10;
|
|
9
10
|
const NODE_VALUE_NUMBER = 11;
|
|
10
11
|
const NODE_VALUE_DIMENSION = 12;
|
|
@@ -22,22 +23,32 @@ const NODE_SELECTOR_PSEUDO_ELEMENT = 26;
|
|
|
22
23
|
const NODE_SELECTOR_COMBINATOR = 27;
|
|
23
24
|
const NODE_SELECTOR_UNIVERSAL = 28;
|
|
24
25
|
const NODE_SELECTOR_NESTING = 29;
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
26
|
+
const NODE_SELECTOR_NTH = 30;
|
|
27
|
+
const NODE_SELECTOR_NTH_OF = 31;
|
|
28
|
+
const NODE_SELECTOR_LANG = 56;
|
|
29
|
+
const NODE_PRELUDE_MEDIA_QUERY = 32;
|
|
30
|
+
const NODE_PRELUDE_MEDIA_FEATURE = 33;
|
|
31
|
+
const NODE_PRELUDE_MEDIA_TYPE = 34;
|
|
32
|
+
const NODE_PRELUDE_CONTAINER_QUERY = 35;
|
|
33
|
+
const NODE_PRELUDE_SUPPORTS_QUERY = 36;
|
|
34
|
+
const NODE_PRELUDE_LAYER_NAME = 37;
|
|
35
|
+
const NODE_PRELUDE_IDENTIFIER = 38;
|
|
36
|
+
const NODE_PRELUDE_OPERATOR = 39;
|
|
37
|
+
const NODE_PRELUDE_IMPORT_URL = 40;
|
|
38
|
+
const NODE_PRELUDE_IMPORT_LAYER = 41;
|
|
39
|
+
const NODE_PRELUDE_IMPORT_SUPPORTS = 42;
|
|
36
40
|
const FLAG_IMPORTANT = 1 << 0;
|
|
37
41
|
const FLAG_HAS_ERROR = 1 << 1;
|
|
38
42
|
const FLAG_HAS_BLOCK = 1 << 3;
|
|
39
43
|
const FLAG_VENDOR_PREFIXED = 1 << 4;
|
|
40
44
|
const FLAG_HAS_DECLARATIONS = 1 << 5;
|
|
45
|
+
const ATTR_OPERATOR_NONE = 0;
|
|
46
|
+
const ATTR_OPERATOR_EQUAL = 1;
|
|
47
|
+
const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
48
|
+
const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
49
|
+
const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
50
|
+
const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
51
|
+
const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
41
52
|
class CSSDataArena {
|
|
42
53
|
buffer;
|
|
43
54
|
view;
|
|
@@ -100,6 +111,10 @@ class CSSDataArena {
|
|
|
100
111
|
get_content_length(node_index) {
|
|
101
112
|
return this.view.getUint16(this.node_offset(node_index) + 16, true);
|
|
102
113
|
}
|
|
114
|
+
// Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
115
|
+
get_attr_operator(node_index) {
|
|
116
|
+
return this.view.getUint8(this.node_offset(node_index) + 2);
|
|
117
|
+
}
|
|
103
118
|
// Read first child index (0 = no children)
|
|
104
119
|
get_first_child(node_index) {
|
|
105
120
|
return this.view.getUint32(this.node_offset(node_index) + 20, true);
|
|
@@ -153,6 +168,10 @@ class CSSDataArena {
|
|
|
153
168
|
set_content_length(node_index, length) {
|
|
154
169
|
this.view.setUint16(this.node_offset(node_index) + 16, length, true);
|
|
155
170
|
}
|
|
171
|
+
// Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
172
|
+
set_attr_operator(node_index, operator) {
|
|
173
|
+
this.view.setUint8(this.node_offset(node_index) + 2, operator);
|
|
174
|
+
}
|
|
156
175
|
// Write first child index
|
|
157
176
|
set_first_child(node_index, childIndex) {
|
|
158
177
|
this.view.setUint32(this.node_offset(node_index) + 20, childIndex, true);
|
|
@@ -241,6 +260,153 @@ class CSSDataArena {
|
|
|
241
260
|
}
|
|
242
261
|
}
|
|
243
262
|
|
|
263
|
+
const CHAR_SPACE = 32;
|
|
264
|
+
const CHAR_TAB = 9;
|
|
265
|
+
const CHAR_NEWLINE = 10;
|
|
266
|
+
const CHAR_CARRIAGE_RETURN = 13;
|
|
267
|
+
const CHAR_FORM_FEED = 12;
|
|
268
|
+
const CHAR_FORWARD_SLASH = 47;
|
|
269
|
+
const CHAR_ASTERISK = 42;
|
|
270
|
+
const CHAR_MINUS_HYPHEN = 45;
|
|
271
|
+
const CHAR_SINGLE_QUOTE = 39;
|
|
272
|
+
const CHAR_DOUBLE_QUOTE = 34;
|
|
273
|
+
const CHAR_PLUS = 43;
|
|
274
|
+
const CHAR_PERIOD = 46;
|
|
275
|
+
const CHAR_TILDE = 126;
|
|
276
|
+
const CHAR_GREATER_THAN = 62;
|
|
277
|
+
const CHAR_AMPERSAND = 38;
|
|
278
|
+
const CHAR_EQUALS = 61;
|
|
279
|
+
const CHAR_PIPE = 124;
|
|
280
|
+
const CHAR_DOLLAR = 36;
|
|
281
|
+
const CHAR_CARET = 94;
|
|
282
|
+
const CHAR_COLON = 58;
|
|
283
|
+
function is_whitespace(ch) {
|
|
284
|
+
return ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED;
|
|
285
|
+
}
|
|
286
|
+
function is_combinator(ch) {
|
|
287
|
+
return ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch == CHAR_TILDE;
|
|
288
|
+
}
|
|
289
|
+
function is_digit(ch) {
|
|
290
|
+
return ch >= 48 && ch <= 57;
|
|
291
|
+
}
|
|
292
|
+
function str_equals(a, b) {
|
|
293
|
+
if (a.length !== b.length) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
for (let i = 0; i < a.length; i++) {
|
|
297
|
+
let ca = a.charCodeAt(i);
|
|
298
|
+
let cb = b.charCodeAt(i);
|
|
299
|
+
cb |= 32;
|
|
300
|
+
if (ca !== cb) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
function is_vendor_prefixed(source, start, end) {
|
|
307
|
+
if (source.charCodeAt(start) !== CHAR_MINUS_HYPHEN) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (source.charCodeAt(start + 1) === CHAR_MINUS_HYPHEN) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
let length = end - start;
|
|
314
|
+
if (length < 3) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
let secondHyphenPos = source.indexOf("-", start + 2);
|
|
318
|
+
return secondHyphenPos !== -1 && secondHyphenPos < end;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function parse_dimension(text) {
|
|
322
|
+
let numEnd = 0;
|
|
323
|
+
for (let i = 0; i < text.length; i++) {
|
|
324
|
+
let ch = text.charCodeAt(i);
|
|
325
|
+
if (ch === 101 || ch === 69) {
|
|
326
|
+
if (i + 1 < text.length) {
|
|
327
|
+
let nextCh = text.charCodeAt(i + 1);
|
|
328
|
+
if (is_digit(nextCh)) {
|
|
329
|
+
numEnd = i + 1;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if ((nextCh === 43 || nextCh === 45) && i + 2 < text.length) {
|
|
333
|
+
let afterSign = text.charCodeAt(i + 2);
|
|
334
|
+
if (is_digit(afterSign)) {
|
|
335
|
+
numEnd = i + 1;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
if (is_digit(ch) || ch === CHAR_PERIOD || ch === CHAR_MINUS_HYPHEN || ch === CHAR_PLUS) {
|
|
343
|
+
numEnd = i + 1;
|
|
344
|
+
} else {
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
let numStr = text.substring(0, numEnd);
|
|
349
|
+
let unit = text.substring(numEnd);
|
|
350
|
+
let value = numStr ? parseFloat(numStr) : 0;
|
|
351
|
+
return { value, unit };
|
|
352
|
+
}
|
|
353
|
+
function skip_whitespace_forward(source, pos, end) {
|
|
354
|
+
while (pos < end && is_whitespace(source.charCodeAt(pos))) {
|
|
355
|
+
pos++;
|
|
356
|
+
}
|
|
357
|
+
return pos;
|
|
358
|
+
}
|
|
359
|
+
function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
360
|
+
while (pos < end) {
|
|
361
|
+
let ch = source.charCodeAt(pos);
|
|
362
|
+
if (is_whitespace(ch)) {
|
|
363
|
+
pos++;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (ch === CHAR_FORWARD_SLASH && pos + 1 < end && source.charCodeAt(pos + 1) === CHAR_ASTERISK) {
|
|
367
|
+
pos += 2;
|
|
368
|
+
while (pos < end) {
|
|
369
|
+
if (source.charCodeAt(pos) === CHAR_ASTERISK && pos + 1 < end && source.charCodeAt(pos + 1) === CHAR_FORWARD_SLASH) {
|
|
370
|
+
pos += 2;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
pos++;
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
return pos;
|
|
380
|
+
}
|
|
381
|
+
function skip_whitespace_and_comments_backward(source, pos, start) {
|
|
382
|
+
while (pos > start) {
|
|
383
|
+
let ch = source.charCodeAt(pos - 1);
|
|
384
|
+
if (is_whitespace(ch)) {
|
|
385
|
+
pos--;
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (pos >= 2 && ch === CHAR_FORWARD_SLASH && source.charCodeAt(pos - 2) === CHAR_ASTERISK) {
|
|
389
|
+
pos -= 2;
|
|
390
|
+
while (pos > start) {
|
|
391
|
+
if (pos >= 2 && source.charCodeAt(pos - 2) === CHAR_FORWARD_SLASH && source.charCodeAt(pos - 1) === CHAR_ASTERISK) {
|
|
392
|
+
pos -= 2;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
pos--;
|
|
396
|
+
}
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
return pos;
|
|
402
|
+
}
|
|
403
|
+
function trim_boundaries(source, start, end) {
|
|
404
|
+
start = skip_whitespace_and_comments_forward(source, start, end);
|
|
405
|
+
end = skip_whitespace_and_comments_backward(source, end, start);
|
|
406
|
+
if (start >= end) return null;
|
|
407
|
+
return [start, end];
|
|
408
|
+
}
|
|
409
|
+
|
|
244
410
|
class CSSNode {
|
|
245
411
|
arena;
|
|
246
412
|
source;
|
|
@@ -277,7 +443,12 @@ class CSSNode {
|
|
|
277
443
|
return this.name;
|
|
278
444
|
}
|
|
279
445
|
// Get the value text (for declarations: "blue" in "color: blue")
|
|
446
|
+
// For dimension/number nodes: returns the numeric value as a number
|
|
447
|
+
// For string nodes: returns the string content without quotes
|
|
280
448
|
get value() {
|
|
449
|
+
if (this.type === NODE_VALUE_DIMENSION || this.type === NODE_VALUE_NUMBER) {
|
|
450
|
+
return parse_dimension(this.text).value;
|
|
451
|
+
}
|
|
281
452
|
let start = this.arena.get_value_start(this.index);
|
|
282
453
|
let length = this.arena.get_value_length(this.index);
|
|
283
454
|
if (length === 0) return null;
|
|
@@ -286,10 +457,22 @@ class CSSNode {
|
|
|
286
457
|
// Get the prelude text (for at-rules: "(min-width: 768px)" in "@media (min-width: 768px)")
|
|
287
458
|
// This is an alias for `value` to make at-rule usage more semantic
|
|
288
459
|
get prelude() {
|
|
289
|
-
|
|
460
|
+
let val = this.value;
|
|
461
|
+
return typeof val === "string" ? val : null;
|
|
462
|
+
}
|
|
463
|
+
// Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
|
|
464
|
+
// Returns one of the ATTR_OPERATOR_* constants
|
|
465
|
+
get attr_operator() {
|
|
466
|
+
return this.arena.get_attr_operator(this.index);
|
|
467
|
+
}
|
|
468
|
+
// Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%")
|
|
469
|
+
get unit() {
|
|
470
|
+
if (this.type !== NODE_VALUE_DIMENSION) return null;
|
|
471
|
+
return parse_dimension(this.text).unit;
|
|
290
472
|
}
|
|
291
473
|
// Check if this declaration has !important
|
|
292
474
|
get is_important() {
|
|
475
|
+
if (this.type !== NODE_DECLARATION) return null;
|
|
293
476
|
return this.arena.has_flag(this.index, FLAG_IMPORTANT);
|
|
294
477
|
}
|
|
295
478
|
// Check if this has a vendor prefix (flag-based for performance)
|
|
@@ -312,6 +495,41 @@ class CSSNode {
|
|
|
312
495
|
get has_declarations() {
|
|
313
496
|
return this.arena.has_flag(this.index, FLAG_HAS_DECLARATIONS);
|
|
314
497
|
}
|
|
498
|
+
// Get the block node (for style rules and at-rules with blocks)
|
|
499
|
+
get block() {
|
|
500
|
+
if (this.type === NODE_STYLE_RULE) {
|
|
501
|
+
let first = this.first_child;
|
|
502
|
+
if (!first) return null;
|
|
503
|
+
let blockNode = first.next_sibling;
|
|
504
|
+
if (blockNode && blockNode.type === NODE_BLOCK) {
|
|
505
|
+
return blockNode;
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
if (this.type === NODE_AT_RULE) {
|
|
510
|
+
let child = this.first_child;
|
|
511
|
+
while (child) {
|
|
512
|
+
if (child.type === NODE_BLOCK && !child.next_sibling) {
|
|
513
|
+
return child;
|
|
514
|
+
}
|
|
515
|
+
child = child.next_sibling;
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
// Check if this block is empty (no declarations or rules, only comments allowed)
|
|
522
|
+
get is_empty() {
|
|
523
|
+
if (this.type !== NODE_BLOCK) return false;
|
|
524
|
+
let child = this.first_child;
|
|
525
|
+
while (child) {
|
|
526
|
+
if (child.type !== NODE_COMMENT) {
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
child = child.next_sibling;
|
|
530
|
+
}
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
315
533
|
// --- Value Node Access (for declarations) ---
|
|
316
534
|
// Get array of parsed value nodes (for declarations only)
|
|
317
535
|
get values() {
|
|
@@ -362,6 +580,10 @@ class CSSNode {
|
|
|
362
580
|
if (sibling_index === 0) return null;
|
|
363
581
|
return new CSSNode(this.arena, this.source, sibling_index);
|
|
364
582
|
}
|
|
583
|
+
get has_next() {
|
|
584
|
+
let sibling_index = this.arena.get_next_sibling(this.index);
|
|
585
|
+
return sibling_index !== 0;
|
|
586
|
+
}
|
|
365
587
|
// Check if this node has children
|
|
366
588
|
get has_children() {
|
|
367
589
|
return this.arena.has_children(this.index);
|
|
@@ -384,88 +606,39 @@ class CSSNode {
|
|
|
384
606
|
child = child.next_sibling;
|
|
385
607
|
}
|
|
386
608
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const CHAR_ASTERISK = 42;
|
|
396
|
-
const CHAR_MINUS_HYPHEN = 45;
|
|
397
|
-
function is_whitespace(ch) {
|
|
398
|
-
return ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED;
|
|
399
|
-
}
|
|
400
|
-
function trim_boundaries(source, start, end) {
|
|
401
|
-
while (start < end) {
|
|
402
|
-
let ch = source.charCodeAt(start);
|
|
403
|
-
if (is_whitespace(ch)) {
|
|
404
|
-
start++;
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
if (ch === CHAR_FORWARD_SLASH && start + 1 < end && source.charCodeAt(start + 1) === CHAR_ASTERISK) {
|
|
408
|
-
start += 2;
|
|
409
|
-
while (start < end) {
|
|
410
|
-
if (source.charCodeAt(start) === CHAR_ASTERISK && start + 1 < end && source.charCodeAt(start + 1) === CHAR_FORWARD_SLASH) {
|
|
411
|
-
start += 2;
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
start++;
|
|
415
|
-
}
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
break;
|
|
609
|
+
// --- An+B Expression Helpers (for NODE_SELECTOR_NTH) ---
|
|
610
|
+
// Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd")
|
|
611
|
+
get nth_a() {
|
|
612
|
+
if (this.type !== NODE_SELECTOR_NTH) return null;
|
|
613
|
+
let len = this.arena.get_content_length(this.index);
|
|
614
|
+
if (len === 0) return null;
|
|
615
|
+
let start = this.arena.get_content_start(this.index);
|
|
616
|
+
return this.source.substring(start, start + len);
|
|
419
617
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
end--;
|
|
618
|
+
// Get the 'b' coefficient from An+B expression (e.g., "1" from "2n+1")
|
|
619
|
+
get nth_b() {
|
|
620
|
+
if (this.type !== NODE_SELECTOR_NTH) return null;
|
|
621
|
+
let len = this.arena.get_value_length(this.index);
|
|
622
|
+
if (len === 0) return null;
|
|
623
|
+
let start = this.arena.get_value_start(this.index);
|
|
624
|
+
let value = this.source.substring(start, start + len);
|
|
625
|
+
let check_pos = start - 1;
|
|
626
|
+
while (check_pos >= 0) {
|
|
627
|
+
let ch = this.source.charCodeAt(check_pos);
|
|
628
|
+
if (is_whitespace(ch)) {
|
|
629
|
+
check_pos--;
|
|
630
|
+
continue;
|
|
434
631
|
}
|
|
435
|
-
|
|
632
|
+
if (ch === CHAR_MINUS_HYPHEN) {
|
|
633
|
+
value = "-" + value;
|
|
634
|
+
}
|
|
635
|
+
break;
|
|
436
636
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (start >= end) return null;
|
|
440
|
-
return [start, end];
|
|
441
|
-
}
|
|
442
|
-
function str_equals(a, b) {
|
|
443
|
-
if (a.length !== b.length) {
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
for (let i = 0; i < a.length; i++) {
|
|
447
|
-
let ca = a.charCodeAt(i);
|
|
448
|
-
let cb = b.charCodeAt(i);
|
|
449
|
-
if (cb >= 65 && cb <= 90) cb |= 32;
|
|
450
|
-
if (ca !== cb) {
|
|
451
|
-
return false;
|
|
637
|
+
if (value.charCodeAt(0) === CHAR_PLUS) {
|
|
638
|
+
return value.substring(1);
|
|
452
639
|
}
|
|
640
|
+
return value;
|
|
453
641
|
}
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
function is_vendor_prefixed(source, start, end) {
|
|
457
|
-
if (source.charCodeAt(start) !== CHAR_MINUS_HYPHEN) {
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
460
|
-
if (source.charCodeAt(start + 1) === CHAR_MINUS_HYPHEN) {
|
|
461
|
-
return false;
|
|
462
|
-
}
|
|
463
|
-
let length = end - start;
|
|
464
|
-
if (length < 3) {
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
let secondHyphenPos = source.indexOf("-", start + 2);
|
|
468
|
-
return secondHyphenPos !== -1 && secondHyphenPos < end;
|
|
469
642
|
}
|
|
470
643
|
|
|
471
|
-
export {
|
|
644
|
+
export { CHAR_GREATER_THAN as $, ATTR_OPERATOR_NONE as A, NODE_SELECTOR_UNIVERSAL as B, CSSNode as C, NODE_SELECTOR_NESTING as D, NODE_SELECTOR_NTH as E, NODE_SELECTOR_NTH_OF as F, NODE_PRELUDE_MEDIA_QUERY as G, NODE_PRELUDE_MEDIA_FEATURE as H, NODE_PRELUDE_MEDIA_TYPE as I, NODE_PRELUDE_CONTAINER_QUERY as J, NODE_PRELUDE_SUPPORTS_QUERY as K, NODE_PRELUDE_LAYER_NAME as L, NODE_PRELUDE_IDENTIFIER as M, NODE_STYLE_RULE as N, NODE_PRELUDE_OPERATOR as O, NODE_PRELUDE_IMPORT_URL as P, NODE_PRELUDE_IMPORT_LAYER as Q, NODE_PRELUDE_IMPORT_SUPPORTS as R, FLAG_IMPORTANT as S, CSSDataArena as T, FLAG_HAS_BLOCK as U, NODE_BLOCK as V, FLAG_HAS_DECLARATIONS as W, is_vendor_prefixed as X, FLAG_VENDOR_PREFIXED as Y, trim_boundaries as Z, NODE_SELECTOR_LANG as _, ATTR_OPERATOR_EQUAL as a, CHAR_PLUS as a0, CHAR_TILDE as a1, CHAR_PERIOD as a2, CHAR_ASTERISK as a3, CHAR_AMPERSAND as a4, is_whitespace as a5, is_combinator as a6, skip_whitespace_and_comments_forward as a7, skip_whitespace_and_comments_backward as a8, CHAR_EQUALS as a9, CHAR_PIPE as aa, CHAR_CARET as ab, CHAR_DOLLAR as ac, CHAR_SINGLE_QUOTE as ad, CHAR_DOUBLE_QUOTE as ae, CHAR_COLON as af, skip_whitespace_forward as ag, str_equals as ah, CHAR_MINUS_HYPHEN as ai, CHAR_FORWARD_SLASH as aj, ATTR_OPERATOR_TILDE_EQUAL as b, ATTR_OPERATOR_PIPE_EQUAL as c, ATTR_OPERATOR_CARET_EQUAL as d, ATTR_OPERATOR_DOLLAR_EQUAL as e, ATTR_OPERATOR_STAR_EQUAL as f, NODE_AT_RULE as g, NODE_COMMENT as h, NODE_DECLARATION as i, NODE_SELECTOR as j, NODE_STYLESHEET as k, NODE_VALUE_KEYWORD as l, NODE_VALUE_NUMBER as m, NODE_VALUE_DIMENSION as n, NODE_VALUE_STRING as o, NODE_VALUE_COLOR as p, NODE_VALUE_FUNCTION as q, NODE_VALUE_OPERATOR as r, NODE_SELECTOR_LIST as s, NODE_SELECTOR_TYPE as t, NODE_SELECTOR_CLASS as u, NODE_SELECTOR_ID as v, NODE_SELECTOR_ATTRIBUTE as w, NODE_SELECTOR_PSEUDO_CLASS as x, NODE_SELECTOR_PSEUDO_ELEMENT as y, NODE_SELECTOR_COMBINATOR as z };
|
package/dist/css-node.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CSSDataArena } from './arena';
|
|
2
|
-
import { NODE_STYLESHEET, NODE_STYLE_RULE, NODE_AT_RULE, NODE_DECLARATION, NODE_SELECTOR, NODE_COMMENT, NODE_VALUE_KEYWORD, NODE_VALUE_NUMBER, NODE_VALUE_DIMENSION, NODE_VALUE_STRING, NODE_VALUE_COLOR, NODE_VALUE_FUNCTION, NODE_VALUE_OPERATOR, NODE_SELECTOR_LIST, NODE_SELECTOR_TYPE, NODE_SELECTOR_CLASS, NODE_SELECTOR_ID, NODE_SELECTOR_ATTRIBUTE, NODE_SELECTOR_PSEUDO_CLASS, NODE_SELECTOR_PSEUDO_ELEMENT, NODE_SELECTOR_COMBINATOR, NODE_SELECTOR_UNIVERSAL, NODE_SELECTOR_NESTING, NODE_PRELUDE_MEDIA_QUERY, NODE_PRELUDE_MEDIA_FEATURE, NODE_PRELUDE_MEDIA_TYPE, NODE_PRELUDE_CONTAINER_QUERY, NODE_PRELUDE_SUPPORTS_QUERY, NODE_PRELUDE_LAYER_NAME, NODE_PRELUDE_IDENTIFIER, NODE_PRELUDE_OPERATOR, NODE_PRELUDE_IMPORT_URL, NODE_PRELUDE_IMPORT_LAYER, NODE_PRELUDE_IMPORT_SUPPORTS } from './arena';
|
|
3
|
-
export type CSSNodeType = typeof NODE_STYLESHEET | typeof NODE_STYLE_RULE | typeof NODE_AT_RULE | typeof NODE_DECLARATION | typeof NODE_SELECTOR | typeof NODE_COMMENT | typeof NODE_VALUE_KEYWORD | typeof NODE_VALUE_NUMBER | typeof NODE_VALUE_DIMENSION | typeof NODE_VALUE_STRING | typeof NODE_VALUE_COLOR | typeof NODE_VALUE_FUNCTION | typeof NODE_VALUE_OPERATOR | typeof NODE_SELECTOR_LIST | typeof NODE_SELECTOR_TYPE | typeof NODE_SELECTOR_CLASS | typeof NODE_SELECTOR_ID | typeof NODE_SELECTOR_ATTRIBUTE | typeof NODE_SELECTOR_PSEUDO_CLASS | typeof NODE_SELECTOR_PSEUDO_ELEMENT | typeof NODE_SELECTOR_COMBINATOR | typeof NODE_SELECTOR_UNIVERSAL | typeof NODE_SELECTOR_NESTING | typeof NODE_PRELUDE_MEDIA_QUERY | typeof NODE_PRELUDE_MEDIA_FEATURE | typeof NODE_PRELUDE_MEDIA_TYPE | typeof NODE_PRELUDE_CONTAINER_QUERY | typeof NODE_PRELUDE_SUPPORTS_QUERY | typeof NODE_PRELUDE_LAYER_NAME | typeof NODE_PRELUDE_IDENTIFIER | typeof NODE_PRELUDE_OPERATOR | typeof NODE_PRELUDE_IMPORT_URL | typeof NODE_PRELUDE_IMPORT_LAYER | typeof NODE_PRELUDE_IMPORT_SUPPORTS;
|
|
2
|
+
import { NODE_STYLESHEET, NODE_STYLE_RULE, NODE_AT_RULE, NODE_DECLARATION, NODE_SELECTOR, NODE_COMMENT, NODE_BLOCK, NODE_VALUE_KEYWORD, NODE_VALUE_NUMBER, NODE_VALUE_DIMENSION, NODE_VALUE_STRING, NODE_VALUE_COLOR, NODE_VALUE_FUNCTION, NODE_VALUE_OPERATOR, NODE_SELECTOR_LIST, NODE_SELECTOR_TYPE, NODE_SELECTOR_CLASS, NODE_SELECTOR_ID, NODE_SELECTOR_ATTRIBUTE, NODE_SELECTOR_PSEUDO_CLASS, NODE_SELECTOR_PSEUDO_ELEMENT, NODE_SELECTOR_COMBINATOR, NODE_SELECTOR_UNIVERSAL, NODE_SELECTOR_NESTING, NODE_SELECTOR_NTH, NODE_SELECTOR_NTH_OF, NODE_SELECTOR_LANG, NODE_PRELUDE_MEDIA_QUERY, NODE_PRELUDE_MEDIA_FEATURE, NODE_PRELUDE_MEDIA_TYPE, NODE_PRELUDE_CONTAINER_QUERY, NODE_PRELUDE_SUPPORTS_QUERY, NODE_PRELUDE_LAYER_NAME, NODE_PRELUDE_IDENTIFIER, NODE_PRELUDE_OPERATOR, NODE_PRELUDE_IMPORT_URL, NODE_PRELUDE_IMPORT_LAYER, NODE_PRELUDE_IMPORT_SUPPORTS } from './arena';
|
|
3
|
+
export type CSSNodeType = typeof NODE_STYLESHEET | typeof NODE_STYLE_RULE | typeof NODE_AT_RULE | typeof NODE_DECLARATION | typeof NODE_SELECTOR | typeof NODE_COMMENT | typeof NODE_BLOCK | typeof NODE_VALUE_KEYWORD | typeof NODE_VALUE_NUMBER | typeof NODE_VALUE_DIMENSION | typeof NODE_VALUE_STRING | typeof NODE_VALUE_COLOR | typeof NODE_VALUE_FUNCTION | typeof NODE_VALUE_OPERATOR | typeof NODE_SELECTOR_LIST | typeof NODE_SELECTOR_TYPE | typeof NODE_SELECTOR_CLASS | typeof NODE_SELECTOR_ID | typeof NODE_SELECTOR_ATTRIBUTE | typeof NODE_SELECTOR_PSEUDO_CLASS | typeof NODE_SELECTOR_PSEUDO_ELEMENT | typeof NODE_SELECTOR_COMBINATOR | typeof NODE_SELECTOR_UNIVERSAL | typeof NODE_SELECTOR_NESTING | typeof NODE_SELECTOR_NTH | typeof NODE_SELECTOR_NTH_OF | typeof NODE_SELECTOR_LANG | typeof NODE_PRELUDE_MEDIA_QUERY | typeof NODE_PRELUDE_MEDIA_FEATURE | typeof NODE_PRELUDE_MEDIA_TYPE | typeof NODE_PRELUDE_CONTAINER_QUERY | typeof NODE_PRELUDE_SUPPORTS_QUERY | typeof NODE_PRELUDE_LAYER_NAME | typeof NODE_PRELUDE_IDENTIFIER | typeof NODE_PRELUDE_OPERATOR | typeof NODE_PRELUDE_IMPORT_URL | typeof NODE_PRELUDE_IMPORT_LAYER | typeof NODE_PRELUDE_IMPORT_SUPPORTS;
|
|
4
4
|
export declare class CSSNode {
|
|
5
5
|
private arena;
|
|
6
6
|
private source;
|
|
@@ -11,14 +11,18 @@ export declare class CSSNode {
|
|
|
11
11
|
get text(): string;
|
|
12
12
|
get name(): string;
|
|
13
13
|
get property(): string;
|
|
14
|
-
get value(): string | null;
|
|
14
|
+
get value(): string | number | null;
|
|
15
15
|
get prelude(): string | null;
|
|
16
|
-
get
|
|
16
|
+
get attr_operator(): number;
|
|
17
|
+
get unit(): string | null;
|
|
18
|
+
get is_important(): boolean | null;
|
|
17
19
|
get is_vendor_prefixed(): boolean;
|
|
18
20
|
get has_error(): boolean;
|
|
19
21
|
get has_prelude(): boolean;
|
|
20
22
|
get has_block(): boolean;
|
|
21
23
|
get has_declarations(): boolean;
|
|
24
|
+
get block(): CSSNode | null;
|
|
25
|
+
get is_empty(): boolean;
|
|
22
26
|
get values(): CSSNode[];
|
|
23
27
|
get value_count(): number;
|
|
24
28
|
get line(): number;
|
|
@@ -27,7 +31,10 @@ export declare class CSSNode {
|
|
|
27
31
|
get length(): number;
|
|
28
32
|
get first_child(): CSSNode | null;
|
|
29
33
|
get next_sibling(): CSSNode | null;
|
|
34
|
+
get has_next(): boolean;
|
|
30
35
|
get has_children(): boolean;
|
|
31
36
|
get children(): CSSNode[];
|
|
32
37
|
[Symbol.iterator](): Iterator<CSSNode>;
|
|
38
|
+
get nth_a(): string | null;
|
|
39
|
+
get nth_b(): string | null;
|
|
33
40
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export { parse } from './parse';
|
|
2
2
|
export { parse_selector } from './parse-selector';
|
|
3
3
|
export { parse_atrule_prelude } from './parse-atrule-prelude';
|
|
4
|
+
export { parse_value } from './parse-value';
|
|
4
5
|
export { tokenize } from './tokenize';
|
|
5
|
-
export { walk,
|
|
6
|
-
export { type ParserOptions } from './
|
|
6
|
+
export { walk, traverse } from './walk';
|
|
7
|
+
export { type ParserOptions } from './parse';
|
|
7
8
|
export { CSSNode, type CSSNodeType } from './css-node';
|
|
8
|
-
export {
|
|
9
|
+
export type { LexerPosition } from './lexer';
|
|
10
|
+
export { ATTR_OPERATOR_NONE, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_STAR_EQUAL, } from './arena';
|
|
11
|
+
export { NODE_STYLE_RULE, NODE_AT_RULE, NODE_COMMENT, NODE_DECLARATION, NODE_SELECTOR, NODE_STYLESHEET, NODE_VALUE_KEYWORD, NODE_VALUE_NUMBER, NODE_VALUE_DIMENSION, NODE_VALUE_STRING, NODE_VALUE_COLOR, NODE_VALUE_FUNCTION, NODE_VALUE_OPERATOR, NODE_SELECTOR_LIST, NODE_SELECTOR_TYPE, NODE_SELECTOR_CLASS, NODE_SELECTOR_ID, NODE_SELECTOR_ATTRIBUTE, NODE_SELECTOR_PSEUDO_CLASS, NODE_SELECTOR_PSEUDO_ELEMENT, NODE_SELECTOR_COMBINATOR, NODE_SELECTOR_UNIVERSAL, NODE_SELECTOR_NESTING, NODE_SELECTOR_NTH, NODE_SELECTOR_NTH_OF, NODE_PRELUDE_MEDIA_QUERY, NODE_PRELUDE_MEDIA_FEATURE, NODE_PRELUDE_MEDIA_TYPE, NODE_PRELUDE_CONTAINER_QUERY, NODE_PRELUDE_SUPPORTS_QUERY, NODE_PRELUDE_LAYER_NAME, NODE_PRELUDE_IDENTIFIER, NODE_PRELUDE_OPERATOR, NODE_PRELUDE_IMPORT_URL, NODE_PRELUDE_IMPORT_LAYER, NODE_PRELUDE_IMPORT_SUPPORTS, FLAG_IMPORTANT, } from './parse';
|
|
9
12
|
export { TOKEN_IDENT, TOKEN_FUNCTION, TOKEN_AT_KEYWORD, TOKEN_HASH, TOKEN_STRING, TOKEN_BAD_STRING, TOKEN_URL, TOKEN_BAD_URL, TOKEN_DELIM, TOKEN_NUMBER, TOKEN_PERCENTAGE, TOKEN_DIMENSION, TOKEN_WHITESPACE, TOKEN_CDO, TOKEN_CDC, TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_COMMA, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE, TOKEN_COMMENT, TOKEN_EOF, type Token, type TokenType, } from './token-types';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { parse } from './parse.js';
|
|
2
2
|
export { parse_selector } from './parse-selector.js';
|
|
3
3
|
export { parse_atrule_prelude } from './parse-atrule-prelude.js';
|
|
4
|
+
export { parse_value } from './parse-value.js';
|
|
4
5
|
export { tokenize } from './tokenize.js';
|
|
5
|
-
export { C as CSSNode,
|
|
6
|
-
export { b as TOKEN_AT_KEYWORD, e as TOKEN_BAD_STRING, g as TOKEN_BAD_URL, n as TOKEN_CDC, m as TOKEN_CDO, o as TOKEN_COLON, q as TOKEN_COMMA, x as TOKEN_COMMENT, h as TOKEN_DELIM, k as TOKEN_DIMENSION, y as TOKEN_EOF, a as TOKEN_FUNCTION, c as TOKEN_HASH, T as TOKEN_IDENT, v as TOKEN_LEFT_BRACE, r as TOKEN_LEFT_BRACKET, t as TOKEN_LEFT_PAREN, i as TOKEN_NUMBER, j as TOKEN_PERCENTAGE, w as TOKEN_RIGHT_BRACE, s as TOKEN_RIGHT_BRACKET, u as TOKEN_RIGHT_PAREN, p as TOKEN_SEMICOLON, d as TOKEN_STRING, f as TOKEN_URL, l as TOKEN_WHITESPACE } from './lexer-
|
|
6
|
+
export { d as ATTR_OPERATOR_CARET_EQUAL, e as ATTR_OPERATOR_DOLLAR_EQUAL, a as ATTR_OPERATOR_EQUAL, A as ATTR_OPERATOR_NONE, c as ATTR_OPERATOR_PIPE_EQUAL, f as ATTR_OPERATOR_STAR_EQUAL, b as ATTR_OPERATOR_TILDE_EQUAL, C as CSSNode, S as FLAG_IMPORTANT, g as NODE_AT_RULE, h as NODE_COMMENT, i as NODE_DECLARATION, J as NODE_PRELUDE_CONTAINER_QUERY, M as NODE_PRELUDE_IDENTIFIER, Q as NODE_PRELUDE_IMPORT_LAYER, R as NODE_PRELUDE_IMPORT_SUPPORTS, P as NODE_PRELUDE_IMPORT_URL, L as NODE_PRELUDE_LAYER_NAME, H as NODE_PRELUDE_MEDIA_FEATURE, G as NODE_PRELUDE_MEDIA_QUERY, I as NODE_PRELUDE_MEDIA_TYPE, O as NODE_PRELUDE_OPERATOR, K as NODE_PRELUDE_SUPPORTS_QUERY, j as NODE_SELECTOR, w as NODE_SELECTOR_ATTRIBUTE, u as NODE_SELECTOR_CLASS, z as NODE_SELECTOR_COMBINATOR, v as NODE_SELECTOR_ID, s as NODE_SELECTOR_LIST, D as NODE_SELECTOR_NESTING, E as NODE_SELECTOR_NTH, F as NODE_SELECTOR_NTH_OF, x as NODE_SELECTOR_PSEUDO_CLASS, y as NODE_SELECTOR_PSEUDO_ELEMENT, t as NODE_SELECTOR_TYPE, B as NODE_SELECTOR_UNIVERSAL, k as NODE_STYLESHEET, N as NODE_STYLE_RULE, p as NODE_VALUE_COLOR, n as NODE_VALUE_DIMENSION, q as NODE_VALUE_FUNCTION, l as NODE_VALUE_KEYWORD, m as NODE_VALUE_NUMBER, r as NODE_VALUE_OPERATOR, o as NODE_VALUE_STRING } from './css-node-BzCSxoLM.js';
|
|
7
|
+
export { b as TOKEN_AT_KEYWORD, e as TOKEN_BAD_STRING, g as TOKEN_BAD_URL, n as TOKEN_CDC, m as TOKEN_CDO, o as TOKEN_COLON, q as TOKEN_COMMA, x as TOKEN_COMMENT, h as TOKEN_DELIM, k as TOKEN_DIMENSION, y as TOKEN_EOF, a as TOKEN_FUNCTION, c as TOKEN_HASH, T as TOKEN_IDENT, v as TOKEN_LEFT_BRACE, r as TOKEN_LEFT_BRACKET, t as TOKEN_LEFT_PAREN, i as TOKEN_NUMBER, j as TOKEN_PERCENTAGE, w as TOKEN_RIGHT_BRACE, s as TOKEN_RIGHT_BRACKET, u as TOKEN_RIGHT_PAREN, p as TOKEN_SEMICOLON, d as TOKEN_STRING, f as TOKEN_URL, l as TOKEN_WHITESPACE } from './lexer-CtBKgfVv.js';
|
|
7
8
|
|
|
8
9
|
function walk(node, callback, depth = 0) {
|
|
9
10
|
callback(node, depth);
|
|
@@ -15,14 +16,14 @@ function walk(node, callback, depth = 0) {
|
|
|
15
16
|
}
|
|
16
17
|
const NOOP = function() {
|
|
17
18
|
};
|
|
18
|
-
function
|
|
19
|
+
function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
|
|
19
20
|
enter(node);
|
|
20
21
|
let child = node.first_child;
|
|
21
22
|
while (child) {
|
|
22
|
-
|
|
23
|
+
traverse(child, { enter, leave });
|
|
23
24
|
child = child.next_sibling;
|
|
24
25
|
}
|
|
25
26
|
leave(node);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export {
|
|
29
|
+
export { traverse, walk };
|
|
@@ -474,6 +474,36 @@ class Lexer {
|
|
|
474
474
|
column: this.token_column
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* Save complete lexer state for backtracking
|
|
479
|
+
* @returns Object containing all lexer state
|
|
480
|
+
*/
|
|
481
|
+
save_position() {
|
|
482
|
+
return {
|
|
483
|
+
pos: this.pos,
|
|
484
|
+
line: this.line,
|
|
485
|
+
column: this.column,
|
|
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.column = saved.column;
|
|
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
|
+
}
|
|
477
507
|
}
|
|
478
508
|
|
|
479
509
|
export { Lexer as L, TOKEN_IDENT as T, TOKEN_FUNCTION as a, TOKEN_AT_KEYWORD as b, TOKEN_HASH as c, TOKEN_STRING as d, TOKEN_BAD_STRING as e, TOKEN_URL as f, TOKEN_BAD_URL as g, TOKEN_DELIM as h, TOKEN_NUMBER as i, TOKEN_PERCENTAGE as j, TOKEN_DIMENSION as k, TOKEN_WHITESPACE as l, TOKEN_CDO as m, TOKEN_CDC as n, TOKEN_COLON as o, TOKEN_SEMICOLON as p, TOKEN_COMMA as q, TOKEN_LEFT_BRACKET as r, TOKEN_RIGHT_BRACKET as s, TOKEN_LEFT_PAREN as t, TOKEN_RIGHT_PAREN as u, TOKEN_LEFT_BRACE as v, TOKEN_RIGHT_BRACE as w, TOKEN_COMMENT as x, TOKEN_EOF as y };
|