@projectwallace/css-parser 0.5.0 → 0.6.1
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 +30 -11
- package/dist/{string-utils-tMt2O9RW.js → css-node-CIM4dthB.js} +287 -90
- package/dist/css-node.d.ts +12 -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 +631 -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,37 @@ 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 FLAG_HAS_PARENS: number;
|
|
46
|
+
export declare const ATTR_OPERATOR_NONE = 0;
|
|
47
|
+
export declare const ATTR_OPERATOR_EQUAL = 1;
|
|
48
|
+
export declare const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
49
|
+
export declare const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
50
|
+
export declare const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
51
|
+
export declare const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
52
|
+
export declare const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
53
|
+
export declare const ATTR_FLAG_NONE = 0;
|
|
54
|
+
export declare const ATTR_FLAG_CASE_INSENSITIVE = 1;
|
|
55
|
+
export declare const ATTR_FLAG_CASE_SENSITIVE = 2;
|
|
41
56
|
export declare class CSSDataArena {
|
|
42
57
|
private buffer;
|
|
43
58
|
private view;
|
|
@@ -57,6 +72,8 @@ export declare class CSSDataArena {
|
|
|
57
72
|
get_length(node_index: number): number;
|
|
58
73
|
get_content_start(node_index: number): number;
|
|
59
74
|
get_content_length(node_index: number): number;
|
|
75
|
+
get_attr_operator(node_index: number): number;
|
|
76
|
+
get_attr_flags(node_index: number): number;
|
|
60
77
|
get_first_child(node_index: number): number;
|
|
61
78
|
get_last_child(node_index: number): number;
|
|
62
79
|
get_next_sibling(node_index: number): number;
|
|
@@ -70,6 +87,8 @@ export declare class CSSDataArena {
|
|
|
70
87
|
set_length(node_index: number, length: number): void;
|
|
71
88
|
set_content_start(node_index: number, offset: number): void;
|
|
72
89
|
set_content_length(node_index: number, length: number): void;
|
|
90
|
+
set_attr_operator(node_index: number, operator: number): void;
|
|
91
|
+
set_attr_flags(node_index: number, flags: number): void;
|
|
73
92
|
set_first_child(node_index: number, childIndex: number): void;
|
|
74
93
|
set_last_child(node_index: number, childIndex: number): void;
|
|
75
94
|
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,36 @@ 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 FLAG_HAS_PARENS = 1 << 6;
|
|
46
|
+
const ATTR_OPERATOR_NONE = 0;
|
|
47
|
+
const ATTR_OPERATOR_EQUAL = 1;
|
|
48
|
+
const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
49
|
+
const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
50
|
+
const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
51
|
+
const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
52
|
+
const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
53
|
+
const ATTR_FLAG_NONE = 0;
|
|
54
|
+
const ATTR_FLAG_CASE_INSENSITIVE = 1;
|
|
55
|
+
const ATTR_FLAG_CASE_SENSITIVE = 2;
|
|
41
56
|
class CSSDataArena {
|
|
42
57
|
buffer;
|
|
43
58
|
view;
|
|
@@ -100,6 +115,14 @@ class CSSDataArena {
|
|
|
100
115
|
get_content_length(node_index) {
|
|
101
116
|
return this.view.getUint16(this.node_offset(node_index) + 16, true);
|
|
102
117
|
}
|
|
118
|
+
// Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
119
|
+
get_attr_operator(node_index) {
|
|
120
|
+
return this.view.getUint8(this.node_offset(node_index) + 2);
|
|
121
|
+
}
|
|
122
|
+
// Read attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
123
|
+
get_attr_flags(node_index) {
|
|
124
|
+
return this.view.getUint8(this.node_offset(node_index) + 3);
|
|
125
|
+
}
|
|
103
126
|
// Read first child index (0 = no children)
|
|
104
127
|
get_first_child(node_index) {
|
|
105
128
|
return this.view.getUint32(this.node_offset(node_index) + 20, true);
|
|
@@ -153,6 +176,14 @@ class CSSDataArena {
|
|
|
153
176
|
set_content_length(node_index, length) {
|
|
154
177
|
this.view.setUint16(this.node_offset(node_index) + 16, length, true);
|
|
155
178
|
}
|
|
179
|
+
// Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
180
|
+
set_attr_operator(node_index, operator) {
|
|
181
|
+
this.view.setUint8(this.node_offset(node_index) + 2, operator);
|
|
182
|
+
}
|
|
183
|
+
// Write attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
184
|
+
set_attr_flags(node_index, flags) {
|
|
185
|
+
this.view.setUint8(this.node_offset(node_index) + 3, flags);
|
|
186
|
+
}
|
|
156
187
|
// Write first child index
|
|
157
188
|
set_first_child(node_index, childIndex) {
|
|
158
189
|
this.view.setUint32(this.node_offset(node_index) + 20, childIndex, true);
|
|
@@ -241,6 +272,153 @@ class CSSDataArena {
|
|
|
241
272
|
}
|
|
242
273
|
}
|
|
243
274
|
|
|
275
|
+
const CHAR_SPACE = 32;
|
|
276
|
+
const CHAR_TAB = 9;
|
|
277
|
+
const CHAR_NEWLINE = 10;
|
|
278
|
+
const CHAR_CARRIAGE_RETURN = 13;
|
|
279
|
+
const CHAR_FORM_FEED = 12;
|
|
280
|
+
const CHAR_FORWARD_SLASH = 47;
|
|
281
|
+
const CHAR_ASTERISK = 42;
|
|
282
|
+
const CHAR_MINUS_HYPHEN = 45;
|
|
283
|
+
const CHAR_SINGLE_QUOTE = 39;
|
|
284
|
+
const CHAR_DOUBLE_QUOTE = 34;
|
|
285
|
+
const CHAR_PLUS = 43;
|
|
286
|
+
const CHAR_PERIOD = 46;
|
|
287
|
+
const CHAR_TILDE = 126;
|
|
288
|
+
const CHAR_GREATER_THAN = 62;
|
|
289
|
+
const CHAR_AMPERSAND = 38;
|
|
290
|
+
const CHAR_EQUALS = 61;
|
|
291
|
+
const CHAR_PIPE = 124;
|
|
292
|
+
const CHAR_DOLLAR = 36;
|
|
293
|
+
const CHAR_CARET = 94;
|
|
294
|
+
const CHAR_COLON = 58;
|
|
295
|
+
function is_whitespace(ch) {
|
|
296
|
+
return ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED;
|
|
297
|
+
}
|
|
298
|
+
function is_combinator(ch) {
|
|
299
|
+
return ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch == CHAR_TILDE;
|
|
300
|
+
}
|
|
301
|
+
function is_digit(ch) {
|
|
302
|
+
return ch >= 48 && ch <= 57;
|
|
303
|
+
}
|
|
304
|
+
function str_equals(a, b) {
|
|
305
|
+
if (a.length !== b.length) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
for (let i = 0; i < a.length; i++) {
|
|
309
|
+
let ca = a.charCodeAt(i);
|
|
310
|
+
let cb = b.charCodeAt(i);
|
|
311
|
+
cb |= 32;
|
|
312
|
+
if (ca !== cb) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
function is_vendor_prefixed(source, start, end) {
|
|
319
|
+
if (source.charCodeAt(start) !== CHAR_MINUS_HYPHEN) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
if (source.charCodeAt(start + 1) === CHAR_MINUS_HYPHEN) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
let length = end - start;
|
|
326
|
+
if (length < 3) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
let secondHyphenPos = source.indexOf("-", start + 2);
|
|
330
|
+
return secondHyphenPos !== -1 && secondHyphenPos < end;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function parse_dimension(text) {
|
|
334
|
+
let numEnd = 0;
|
|
335
|
+
for (let i = 0; i < text.length; i++) {
|
|
336
|
+
let ch = text.charCodeAt(i);
|
|
337
|
+
if (ch === 101 || ch === 69) {
|
|
338
|
+
if (i + 1 < text.length) {
|
|
339
|
+
let nextCh = text.charCodeAt(i + 1);
|
|
340
|
+
if (is_digit(nextCh)) {
|
|
341
|
+
numEnd = i + 1;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if ((nextCh === 43 || nextCh === 45) && i + 2 < text.length) {
|
|
345
|
+
let afterSign = text.charCodeAt(i + 2);
|
|
346
|
+
if (is_digit(afterSign)) {
|
|
347
|
+
numEnd = i + 1;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (is_digit(ch) || ch === CHAR_PERIOD || ch === CHAR_MINUS_HYPHEN || ch === CHAR_PLUS) {
|
|
355
|
+
numEnd = i + 1;
|
|
356
|
+
} else {
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
let numStr = text.substring(0, numEnd);
|
|
361
|
+
let unit = text.substring(numEnd);
|
|
362
|
+
let value = numStr ? parseFloat(numStr) : 0;
|
|
363
|
+
return { value, unit };
|
|
364
|
+
}
|
|
365
|
+
function skip_whitespace_forward(source, pos, end) {
|
|
366
|
+
while (pos < end && is_whitespace(source.charCodeAt(pos))) {
|
|
367
|
+
pos++;
|
|
368
|
+
}
|
|
369
|
+
return pos;
|
|
370
|
+
}
|
|
371
|
+
function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
372
|
+
while (pos < end) {
|
|
373
|
+
let ch = source.charCodeAt(pos);
|
|
374
|
+
if (is_whitespace(ch)) {
|
|
375
|
+
pos++;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (ch === CHAR_FORWARD_SLASH && pos + 1 < end && source.charCodeAt(pos + 1) === CHAR_ASTERISK) {
|
|
379
|
+
pos += 2;
|
|
380
|
+
while (pos < end) {
|
|
381
|
+
if (source.charCodeAt(pos) === CHAR_ASTERISK && pos + 1 < end && source.charCodeAt(pos + 1) === CHAR_FORWARD_SLASH) {
|
|
382
|
+
pos += 2;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
pos++;
|
|
386
|
+
}
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
return pos;
|
|
392
|
+
}
|
|
393
|
+
function skip_whitespace_and_comments_backward(source, pos, start) {
|
|
394
|
+
while (pos > start) {
|
|
395
|
+
let ch = source.charCodeAt(pos - 1);
|
|
396
|
+
if (is_whitespace(ch)) {
|
|
397
|
+
pos--;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (pos >= 2 && ch === CHAR_FORWARD_SLASH && source.charCodeAt(pos - 2) === CHAR_ASTERISK) {
|
|
401
|
+
pos -= 2;
|
|
402
|
+
while (pos > start) {
|
|
403
|
+
if (pos >= 2 && source.charCodeAt(pos - 2) === CHAR_FORWARD_SLASH && source.charCodeAt(pos - 1) === CHAR_ASTERISK) {
|
|
404
|
+
pos -= 2;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
pos--;
|
|
408
|
+
}
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
return pos;
|
|
414
|
+
}
|
|
415
|
+
function trim_boundaries(source, start, end) {
|
|
416
|
+
start = skip_whitespace_and_comments_forward(source, start, end);
|
|
417
|
+
end = skip_whitespace_and_comments_backward(source, end, start);
|
|
418
|
+
if (start >= end) return null;
|
|
419
|
+
return [start, end];
|
|
420
|
+
}
|
|
421
|
+
|
|
244
422
|
class CSSNode {
|
|
245
423
|
arena;
|
|
246
424
|
source;
|
|
@@ -277,7 +455,12 @@ class CSSNode {
|
|
|
277
455
|
return this.name;
|
|
278
456
|
}
|
|
279
457
|
// Get the value text (for declarations: "blue" in "color: blue")
|
|
458
|
+
// For dimension/number nodes: returns the numeric value as a number
|
|
459
|
+
// For string nodes: returns the string content without quotes
|
|
280
460
|
get value() {
|
|
461
|
+
if (this.type === NODE_VALUE_DIMENSION || this.type === NODE_VALUE_NUMBER) {
|
|
462
|
+
return parse_dimension(this.text).value;
|
|
463
|
+
}
|
|
281
464
|
let start = this.arena.get_value_start(this.index);
|
|
282
465
|
let length = this.arena.get_value_length(this.index);
|
|
283
466
|
if (length === 0) return null;
|
|
@@ -286,10 +469,27 @@ class CSSNode {
|
|
|
286
469
|
// Get the prelude text (for at-rules: "(min-width: 768px)" in "@media (min-width: 768px)")
|
|
287
470
|
// This is an alias for `value` to make at-rule usage more semantic
|
|
288
471
|
get prelude() {
|
|
289
|
-
|
|
472
|
+
let val = this.value;
|
|
473
|
+
return typeof val === "string" ? val : null;
|
|
474
|
+
}
|
|
475
|
+
// Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
|
|
476
|
+
// Returns one of the ATTR_OPERATOR_* constants
|
|
477
|
+
get attr_operator() {
|
|
478
|
+
return this.arena.get_attr_operator(this.index);
|
|
479
|
+
}
|
|
480
|
+
// Get the attribute flags (for attribute selectors: i, s)
|
|
481
|
+
// Returns one of the ATTR_FLAG_* constants
|
|
482
|
+
get attr_flags() {
|
|
483
|
+
return this.arena.get_attr_flags(this.index);
|
|
484
|
+
}
|
|
485
|
+
// Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%")
|
|
486
|
+
get unit() {
|
|
487
|
+
if (this.type !== NODE_VALUE_DIMENSION) return null;
|
|
488
|
+
return parse_dimension(this.text).unit;
|
|
290
489
|
}
|
|
291
490
|
// Check if this declaration has !important
|
|
292
491
|
get is_important() {
|
|
492
|
+
if (this.type !== NODE_DECLARATION) return null;
|
|
293
493
|
return this.arena.has_flag(this.index, FLAG_IMPORTANT);
|
|
294
494
|
}
|
|
295
495
|
// Check if this has a vendor prefix (flag-based for performance)
|
|
@@ -312,6 +512,41 @@ class CSSNode {
|
|
|
312
512
|
get has_declarations() {
|
|
313
513
|
return this.arena.has_flag(this.index, FLAG_HAS_DECLARATIONS);
|
|
314
514
|
}
|
|
515
|
+
// Get the block node (for style rules and at-rules with blocks)
|
|
516
|
+
get block() {
|
|
517
|
+
if (this.type === NODE_STYLE_RULE) {
|
|
518
|
+
let first = this.first_child;
|
|
519
|
+
if (!first) return null;
|
|
520
|
+
let blockNode = first.next_sibling;
|
|
521
|
+
if (blockNode && blockNode.type === NODE_BLOCK) {
|
|
522
|
+
return blockNode;
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
if (this.type === NODE_AT_RULE) {
|
|
527
|
+
let child = this.first_child;
|
|
528
|
+
while (child) {
|
|
529
|
+
if (child.type === NODE_BLOCK && !child.next_sibling) {
|
|
530
|
+
return child;
|
|
531
|
+
}
|
|
532
|
+
child = child.next_sibling;
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
// Check if this block is empty (no declarations or rules, only comments allowed)
|
|
539
|
+
get is_empty() {
|
|
540
|
+
if (this.type !== NODE_BLOCK) return false;
|
|
541
|
+
let child = this.first_child;
|
|
542
|
+
while (child) {
|
|
543
|
+
if (child.type !== NODE_COMMENT) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
child = child.next_sibling;
|
|
547
|
+
}
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
315
550
|
// --- Value Node Access (for declarations) ---
|
|
316
551
|
// Get array of parsed value nodes (for declarations only)
|
|
317
552
|
get values() {
|
|
@@ -362,8 +597,19 @@ class CSSNode {
|
|
|
362
597
|
if (sibling_index === 0) return null;
|
|
363
598
|
return new CSSNode(this.arena, this.source, sibling_index);
|
|
364
599
|
}
|
|
600
|
+
get has_next() {
|
|
601
|
+
let sibling_index = this.arena.get_next_sibling(this.index);
|
|
602
|
+
return sibling_index !== 0;
|
|
603
|
+
}
|
|
365
604
|
// Check if this node has children
|
|
605
|
+
// For pseudo-class/pseudo-element functions, returns true if FLAG_HAS_PARENS is set
|
|
606
|
+
// This allows formatters to distinguish :lang() from :hover
|
|
366
607
|
get has_children() {
|
|
608
|
+
if (this.type === NODE_SELECTOR_PSEUDO_CLASS || this.type === NODE_SELECTOR_PSEUDO_ELEMENT) {
|
|
609
|
+
if (this.arena.has_flag(this.index, FLAG_HAS_PARENS)) {
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
367
613
|
return this.arena.has_children(this.index);
|
|
368
614
|
}
|
|
369
615
|
// Get all children as an array
|
|
@@ -384,88 +630,39 @@ class CSSNode {
|
|
|
384
630
|
child = child.next_sibling;
|
|
385
631
|
}
|
|
386
632
|
}
|
|
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;
|
|
633
|
+
// --- An+B Expression Helpers (for NODE_SELECTOR_NTH) ---
|
|
634
|
+
// Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd")
|
|
635
|
+
get nth_a() {
|
|
636
|
+
if (this.type !== NODE_SELECTOR_NTH) return null;
|
|
637
|
+
let len = this.arena.get_content_length(this.index);
|
|
638
|
+
if (len === 0) return null;
|
|
639
|
+
let start = this.arena.get_content_start(this.index);
|
|
640
|
+
return this.source.substring(start, start + len);
|
|
419
641
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
end--;
|
|
642
|
+
// Get the 'b' coefficient from An+B expression (e.g., "1" from "2n+1")
|
|
643
|
+
get nth_b() {
|
|
644
|
+
if (this.type !== NODE_SELECTOR_NTH) return null;
|
|
645
|
+
let len = this.arena.get_value_length(this.index);
|
|
646
|
+
if (len === 0) return null;
|
|
647
|
+
let start = this.arena.get_value_start(this.index);
|
|
648
|
+
let value = this.source.substring(start, start + len);
|
|
649
|
+
let check_pos = start - 1;
|
|
650
|
+
while (check_pos >= 0) {
|
|
651
|
+
let ch = this.source.charCodeAt(check_pos);
|
|
652
|
+
if (is_whitespace(ch)) {
|
|
653
|
+
check_pos--;
|
|
654
|
+
continue;
|
|
434
655
|
}
|
|
435
|
-
|
|
656
|
+
if (ch === CHAR_MINUS_HYPHEN) {
|
|
657
|
+
value = "-" + value;
|
|
658
|
+
}
|
|
659
|
+
break;
|
|
436
660
|
}
|
|
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;
|
|
661
|
+
if (value.charCodeAt(0) === CHAR_PLUS) {
|
|
662
|
+
return value.substring(1);
|
|
452
663
|
}
|
|
664
|
+
return value;
|
|
453
665
|
}
|
|
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
666
|
}
|
|
470
667
|
|
|
471
|
-
export {
|
|
668
|
+
export { FLAG_VENDOR_PREFIXED as $, ATTR_OPERATOR_NONE as A, NODE_SELECTOR_PSEUDO_CLASS as B, CSSNode as C, NODE_SELECTOR_PSEUDO_ELEMENT as D, NODE_SELECTOR_COMBINATOR as E, NODE_SELECTOR_UNIVERSAL as F, NODE_SELECTOR_NESTING as G, NODE_SELECTOR_NTH as H, NODE_SELECTOR_NTH_OF as I, NODE_PRELUDE_MEDIA_QUERY as J, NODE_PRELUDE_MEDIA_FEATURE as K, NODE_PRELUDE_MEDIA_TYPE as L, NODE_PRELUDE_CONTAINER_QUERY as M, NODE_STYLE_RULE as N, NODE_PRELUDE_SUPPORTS_QUERY as O, NODE_PRELUDE_LAYER_NAME as P, NODE_PRELUDE_IDENTIFIER as Q, NODE_PRELUDE_OPERATOR as R, NODE_PRELUDE_IMPORT_URL as S, NODE_PRELUDE_IMPORT_LAYER as T, NODE_PRELUDE_IMPORT_SUPPORTS as U, FLAG_IMPORTANT as V, CSSDataArena as W, FLAG_HAS_BLOCK as X, NODE_BLOCK as Y, FLAG_HAS_DECLARATIONS as Z, is_vendor_prefixed as _, ATTR_OPERATOR_EQUAL as a, trim_boundaries as a0, NODE_SELECTOR_LANG as a1, CHAR_GREATER_THAN as a2, CHAR_PLUS as a3, CHAR_TILDE as a4, CHAR_PERIOD as a5, CHAR_ASTERISK as a6, CHAR_AMPERSAND as a7, is_whitespace as a8, is_combinator as a9, skip_whitespace_and_comments_forward as aa, skip_whitespace_and_comments_backward as ab, CHAR_EQUALS as ac, CHAR_PIPE as ad, CHAR_CARET as ae, CHAR_DOLLAR as af, CHAR_SINGLE_QUOTE as ag, CHAR_DOUBLE_QUOTE as ah, CHAR_COLON as ai, FLAG_HAS_PARENS as aj, skip_whitespace_forward as ak, str_equals as al, CHAR_MINUS_HYPHEN as am, CHAR_FORWARD_SLASH as an, 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, ATTR_FLAG_NONE as g, ATTR_FLAG_CASE_INSENSITIVE as h, ATTR_FLAG_CASE_SENSITIVE as i, NODE_AT_RULE as j, NODE_COMMENT as k, NODE_DECLARATION as l, NODE_SELECTOR as m, NODE_STYLESHEET as n, NODE_VALUE_KEYWORD as o, NODE_VALUE_NUMBER as p, NODE_VALUE_DIMENSION as q, NODE_VALUE_STRING as r, NODE_VALUE_COLOR as s, NODE_VALUE_FUNCTION as t, NODE_VALUE_OPERATOR as u, NODE_SELECTOR_LIST as v, NODE_SELECTOR_TYPE as w, NODE_SELECTOR_CLASS as x, NODE_SELECTOR_ID as y, NODE_SELECTOR_ATTRIBUTE 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,19 @@ 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 attr_flags(): number;
|
|
18
|
+
get unit(): string | null;
|
|
19
|
+
get is_important(): boolean | null;
|
|
17
20
|
get is_vendor_prefixed(): boolean;
|
|
18
21
|
get has_error(): boolean;
|
|
19
22
|
get has_prelude(): boolean;
|
|
20
23
|
get has_block(): boolean;
|
|
21
24
|
get has_declarations(): boolean;
|
|
25
|
+
get block(): CSSNode | null;
|
|
26
|
+
get is_empty(): boolean;
|
|
22
27
|
get values(): CSSNode[];
|
|
23
28
|
get value_count(): number;
|
|
24
29
|
get line(): number;
|
|
@@ -27,7 +32,10 @@ export declare class CSSNode {
|
|
|
27
32
|
get length(): number;
|
|
28
33
|
get first_child(): CSSNode | null;
|
|
29
34
|
get next_sibling(): CSSNode | null;
|
|
35
|
+
get has_next(): boolean;
|
|
30
36
|
get has_children(): boolean;
|
|
31
37
|
get children(): CSSNode[];
|
|
32
38
|
[Symbol.iterator](): Iterator<CSSNode>;
|
|
39
|
+
get nth_a(): string | null;
|
|
40
|
+
get nth_b(): string | null;
|
|
33
41
|
}
|
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, ATTR_FLAG_NONE, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, } 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 { h as ATTR_FLAG_CASE_INSENSITIVE, i as ATTR_FLAG_CASE_SENSITIVE, g as ATTR_FLAG_NONE, 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, V as FLAG_IMPORTANT, j as NODE_AT_RULE, k as NODE_COMMENT, l as NODE_DECLARATION, M as NODE_PRELUDE_CONTAINER_QUERY, Q as NODE_PRELUDE_IDENTIFIER, T as NODE_PRELUDE_IMPORT_LAYER, U as NODE_PRELUDE_IMPORT_SUPPORTS, S as NODE_PRELUDE_IMPORT_URL, P as NODE_PRELUDE_LAYER_NAME, K as NODE_PRELUDE_MEDIA_FEATURE, J as NODE_PRELUDE_MEDIA_QUERY, L as NODE_PRELUDE_MEDIA_TYPE, R as NODE_PRELUDE_OPERATOR, O as NODE_PRELUDE_SUPPORTS_QUERY, m as NODE_SELECTOR, z as NODE_SELECTOR_ATTRIBUTE, x as NODE_SELECTOR_CLASS, E as NODE_SELECTOR_COMBINATOR, y as NODE_SELECTOR_ID, v as NODE_SELECTOR_LIST, G as NODE_SELECTOR_NESTING, H as NODE_SELECTOR_NTH, I as NODE_SELECTOR_NTH_OF, B as NODE_SELECTOR_PSEUDO_CLASS, D as NODE_SELECTOR_PSEUDO_ELEMENT, w as NODE_SELECTOR_TYPE, F as NODE_SELECTOR_UNIVERSAL, n as NODE_STYLESHEET, N as NODE_STYLE_RULE, s as NODE_VALUE_COLOR, q as NODE_VALUE_DIMENSION, t as NODE_VALUE_FUNCTION, o as NODE_VALUE_KEYWORD, p as NODE_VALUE_NUMBER, u as NODE_VALUE_OPERATOR, r as NODE_VALUE_STRING } from './css-node-CIM4dthB.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 };
|