@projectwallace/css-parser 0.16.2 → 0.18.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.
@@ -1,23 +1,12 @@
1
- import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
2
- import { q as Value } from "./node-types-BrZu8T2C.js";
3
-
1
+ import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
2
+ import { q as Value } from "./node-types-BRnQyc9B.js";
4
3
  //#region src/parse-value.d.ts
5
4
  /** @internal */
6
5
  declare class ValueParser {
7
- private lexer;
6
+ private nodes;
8
7
  private arena;
9
- private source;
10
- private value_end;
11
8
  constructor(arena: CSSDataArena, source: string);
12
9
  parse_value(start: number, end: number, start_line: number, start_column: number): number;
13
- private parse_value_tokens;
14
- private is_whitespace_inline;
15
- private parse_value_node;
16
- private create_node;
17
- private create_operator_node;
18
- private parse_operator_node;
19
- private parse_function_node;
20
- private parse_parenthesis_node;
21
10
  }
22
11
  /**
23
12
  * Parse a CSS declaration value string and return a VALUE node
@@ -1,171 +1,25 @@
1
- import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
- import { l as CSSDataArena } from "./arena-CCye9VYE.js";
3
- import { a as is_whitespace, o as str_equals } from "./parse-dimension-B0AZRxxt.js";
4
- import { t as CSSNode } from "./css-node-TR2T5Q7D.js";
1
+ import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
2
+ import { t as CSSNode } from "./css-node-B3EzCweR.js";
3
+ import { t as ValueNodeParser } from "./value-node-parser-CZ47v3hp.js";
5
4
  //#region src/parse-value.ts
6
5
  /** @internal */
7
6
  var ValueParser = class {
8
- lexer;
7
+ nodes;
9
8
  arena;
10
- source;
11
- value_end;
12
9
  constructor(arena, source) {
13
10
  this.arena = arena;
14
- this.source = source;
15
- this.lexer = new Lexer(source);
16
- this.value_end = 0;
11
+ this.nodes = new ValueNodeParser(arena, source);
17
12
  }
18
13
  parse_value(start, end, start_line, start_column) {
19
- this.value_end = end;
20
- this.lexer.seek(start, start_line, start_column);
21
- let value_nodes = this.parse_value_tokens();
22
- if (value_nodes.length === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
23
- let first_node_start = this.arena.get_start_offset(value_nodes[0]);
24
- let last_node_index = value_nodes.at(-1);
25
- let last_node_end = this.arena.get_start_offset(last_node_index) + this.arena.get_length(last_node_index);
14
+ let first_node = this.nodes.parse_chain(start, end, start_line, start_column);
15
+ if (first_node === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
16
+ let last_node = this.nodes.last_chain_node;
17
+ let first_node_start = this.arena.get_start_offset(first_node);
18
+ let last_node_end = this.arena.get_start_offset(last_node) + this.arena.get_length(last_node);
26
19
  let value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
27
- this.arena.append_children(value_node, value_nodes);
20
+ this.arena.set_first_child(value_node, first_node);
28
21
  return value_node;
29
22
  }
30
- parse_value_tokens() {
31
- let nodes = [];
32
- while (this.lexer.pos < this.value_end) {
33
- this.lexer.next_token_fast(false);
34
- if (this.lexer.token_start >= this.value_end) break;
35
- if (this.lexer.token_type === 26) break;
36
- if (this.is_whitespace_inline()) continue;
37
- let node = this.parse_value_node();
38
- if (node !== null) nodes.push(node);
39
- }
40
- return nodes;
41
- }
42
- is_whitespace_inline() {
43
- if (this.lexer.token_start >= this.lexer.token_end) return false;
44
- for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
45
- return true;
46
- }
47
- parse_value_node() {
48
- let token_type = this.lexer.token_type;
49
- let start = this.lexer.token_start;
50
- let end = this.lexer.token_end;
51
- switch (token_type) {
52
- case 1: return this.create_node(10, start, end);
53
- case 10: return this.create_node(11, start, end);
54
- case 11:
55
- case 12: return this.create_node(12, start, end);
56
- case 5: return this.create_node(13, start, end);
57
- case 4: return this.create_node(14, start, end);
58
- case 27: return this.create_node(19, start, end);
59
- case 2: return this.parse_function_node(start, end);
60
- case 9: return this.parse_operator_node(start, end);
61
- case 18: return this.create_node(16, start, end);
62
- case 21: return this.parse_parenthesis_node(start, end);
63
- default: return null;
64
- }
65
- }
66
- create_node(node_type, start, end) {
67
- let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
68
- this.arena.set_content_length(node, end - start);
69
- return node;
70
- }
71
- create_operator_node(start, end) {
72
- return this.create_node(16, start, end);
73
- }
74
- parse_operator_node(start, end) {
75
- let ch = this.source.charCodeAt(start);
76
- if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_operator_node(start, end);
77
- return null;
78
- }
79
- parse_function_node(start, end) {
80
- let name_end = end - 1;
81
- let func_name_substr = this.source.substring(start, name_end);
82
- let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
83
- this.arena.set_content_start_delta(node, 0);
84
- this.arena.set_content_length(node, name_end - start);
85
- if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
86
- let save_pos = this.lexer.save_position();
87
- this.lexer.next_token_fast(false);
88
- while (this.is_whitespace_inline() && this.lexer.pos < this.value_end) this.lexer.next_token_fast(false);
89
- let first_token_type = this.lexer.token_type;
90
- this.lexer.restore_position(save_pos);
91
- if (first_token_type === 5) {} else {
92
- let paren_depth = 1;
93
- let func_end = end;
94
- let content_start = end;
95
- let content_end = end;
96
- while (paren_depth > 0) {
97
- this.lexer.next_token_fast(false);
98
- let token_type = this.lexer.token_type;
99
- if (token_type === 26) break;
100
- if (token_type === 21 || token_type === 2) paren_depth++;
101
- else if (token_type === 22) {
102
- paren_depth--;
103
- if (paren_depth === 0) {
104
- content_end = this.lexer.token_start;
105
- func_end = this.lexer.token_end;
106
- break;
107
- }
108
- }
109
- }
110
- this.arena.set_length(node, func_end - start);
111
- this.arena.set_value_start_delta(node, content_start - start);
112
- this.arena.set_value_length(node, content_end - content_start);
113
- return node;
114
- }
115
- }
116
- let args = [];
117
- let paren_depth = 1;
118
- let func_end = end;
119
- let content_start = end;
120
- let content_end = end;
121
- while (this.lexer.pos < this.value_end && paren_depth > 0) {
122
- this.lexer.next_token_fast(false);
123
- let token_type = this.lexer.token_type;
124
- if (token_type === 26) break;
125
- if (this.lexer.token_start >= this.value_end) break;
126
- if (token_type === 22) {
127
- paren_depth--;
128
- if (paren_depth === 0) {
129
- content_end = this.lexer.token_start;
130
- func_end = this.lexer.token_end;
131
- break;
132
- }
133
- }
134
- if (this.is_whitespace_inline()) continue;
135
- let arg_node = this.parse_value_node();
136
- if (arg_node !== null) args.push(arg_node);
137
- }
138
- this.arena.set_length(node, func_end - start);
139
- this.arena.set_value_start_delta(node, content_start - start);
140
- this.arena.set_value_length(node, content_end - content_start);
141
- this.arena.append_children(node, args);
142
- return node;
143
- }
144
- parse_parenthesis_node(start, end) {
145
- let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
146
- let children = [];
147
- let paren_depth = 1;
148
- let paren_end = end;
149
- while (this.lexer.pos < this.value_end && paren_depth > 0) {
150
- this.lexer.next_token_fast(false);
151
- let token_type = this.lexer.token_type;
152
- if (token_type === 26) break;
153
- if (this.lexer.token_start >= this.value_end) break;
154
- if (token_type === 22) {
155
- paren_depth--;
156
- if (paren_depth === 0) {
157
- paren_end = this.lexer.token_end;
158
- break;
159
- }
160
- }
161
- if (this.is_whitespace_inline()) continue;
162
- let child_node = this.parse_value_node();
163
- if (child_node !== null) children.push(child_node);
164
- }
165
- this.arena.set_length(node, paren_end - start);
166
- this.arena.append_children(node, children);
167
- return node;
168
- }
169
23
  };
170
24
  /**
171
25
  * Parse a CSS declaration value string and return a VALUE node
package/dist/parse.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
1
+ import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
2
2
  import { t as CommentInfo } from "./tokenize-DeZYFa9R.js";
3
- import { z as StyleSheet } from "./node-types-BrZu8T2C.js";
4
-
3
+ import { z as StyleSheet } from "./node-types-BRnQyc9B.js";
5
4
  //#region src/parse.d.ts
6
5
  interface ParserOptions {
7
6
  parse_values?: boolean;
package/dist/parse.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
- import { l as CSSDataArena } from "./arena-CCye9VYE.js";
3
- import { t as CSSNode } from "./css-node-TR2T5Q7D.js";
4
- import { i as trim_boundaries } from "./parse-utils-BmXnziOy.js";
2
+ import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
3
+ import { t as CSSNode } from "./css-node-B3EzCweR.js";
4
+ import { i as trim_boundaries } from "./parse-utils-D7srNG13.js";
5
5
  import { SelectorParser } from "./parse-selector.js";
6
6
  import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
7
7
  import { DeclarationParser } from "./parse-declaration.js";
@@ -59,13 +59,18 @@ var Parser = class {
59
59
  parse() {
60
60
  this.next_token();
61
61
  let stylesheet = this.arena.create_node(1, 0, this.source.length, 1, 1);
62
- let rules = [];
62
+ let first_rule = 0;
63
+ let last_rule = 0;
63
64
  while (!this.is_eof()) {
64
65
  let rule = this.parse_rule();
65
66
  if (rule === null) this.next_token();
66
- else rules.push(rule);
67
+ else {
68
+ if (first_rule === 0) first_rule = rule;
69
+ else this.arena.set_next_sibling(last_rule, rule);
70
+ last_rule = rule;
71
+ }
67
72
  }
68
- this.arena.append_children(stylesheet, rules);
73
+ if (first_rule !== 0) this.arena.set_first_child(stylesheet, first_rule);
69
74
  this.arena.trim();
70
75
  return new CSSNode(this.arena, this.source, stylesheet);
71
76
  }
@@ -88,25 +93,27 @@ var Parser = class {
88
93
  let block_line = this.lexer.token_line;
89
94
  let block_column = this.lexer.token_column;
90
95
  let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
91
- let block_children = [];
96
+ let first_child = 0;
97
+ let last_child = 0;
92
98
  while (!this.is_eof()) {
93
99
  let token_type = this.peek_type();
94
100
  if (token_type === 24) break;
101
+ let child = null;
95
102
  if (token_type === 3) {
96
- let nested_at_rule = this.parse_atrule();
97
- if (nested_at_rule === null) this.next_token();
98
- else block_children.push(nested_at_rule);
99
- continue;
103
+ child = this.parse_atrule();
104
+ if (child === null) this.next_token();
105
+ } else {
106
+ child = this.parse_declaration();
107
+ if (child === null) {
108
+ child = this.parse_style_rule();
109
+ if (child === null) this.next_token();
110
+ } else this.arena.set_flag(style_rule, 32);
100
111
  }
101
- let declaration = this.parse_declaration();
102
- if (declaration !== null) {
103
- this.arena.set_flag(style_rule, 32);
104
- block_children.push(declaration);
105
- continue;
112
+ if (child !== null) {
113
+ if (first_child === 0) first_child = child;
114
+ else this.arena.set_next_sibling(last_child, child);
115
+ last_child = child;
106
116
  }
107
- let nested_rule = this.parse_style_rule();
108
- if (nested_rule === null) this.next_token();
109
- else block_children.push(nested_rule);
110
117
  }
111
118
  let block_end = this.lexer.token_start;
112
119
  let rule_end = this.lexer.token_end;
@@ -116,12 +123,13 @@ var Parser = class {
116
123
  this.next_token();
117
124
  }
118
125
  this.arena.set_length(block_node, block_end - block_start);
119
- this.arena.append_children(block_node, block_children);
126
+ if (first_child !== 0) this.arena.set_first_child(block_node, first_child);
120
127
  this.arena.set_length(style_rule, rule_end - rule_start);
121
- let style_rule_children = [];
122
- if (selector !== null) style_rule_children.push(selector);
123
- style_rule_children.push(block_node);
124
- this.arena.append_children(style_rule, style_rule_children);
128
+ if (selector === null) this.arena.set_first_child(style_rule, block_node);
129
+ else {
130
+ this.arena.set_first_child(style_rule, selector);
131
+ this.arena.set_next_sibling(selector, block_node);
132
+ }
125
133
  return style_rule;
126
134
  }
127
135
  parse_selector() {
@@ -193,30 +201,37 @@ var Parser = class {
193
201
  let block_column = this.lexer.token_column;
194
202
  let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
195
203
  let has_declarations = this.atrule_has_declarations(at_rule_name);
196
- let block_children = [];
204
+ let first_child = 0;
205
+ let last_child = 0;
197
206
  if (has_declarations) while (!this.is_eof()) {
198
207
  if (this.peek_type() === 24) break;
199
208
  let declaration = this.parse_declaration();
200
209
  if (declaration === null) this.next_token();
201
- else block_children.push(declaration);
210
+ else {
211
+ if (first_child === 0) first_child = declaration;
212
+ else this.arena.set_next_sibling(last_child, declaration);
213
+ last_child = declaration;
214
+ }
202
215
  }
203
216
  else while (!this.is_eof()) {
204
217
  let token_type = this.peek_type();
205
218
  if (token_type === 24) break;
219
+ let child = null;
206
220
  if (token_type === 3) {
207
- let nested_at_rule = this.parse_atrule();
208
- if (nested_at_rule === null) this.next_token();
209
- else block_children.push(nested_at_rule);
210
- continue;
221
+ child = this.parse_atrule();
222
+ if (child === null) this.next_token();
223
+ } else {
224
+ child = this.parse_declaration();
225
+ if (child === null) {
226
+ child = this.parse_style_rule();
227
+ if (child === null) this.next_token();
228
+ }
211
229
  }
212
- let declaration = this.parse_declaration();
213
- if (declaration !== null) {
214
- block_children.push(declaration);
215
- continue;
230
+ if (child !== null) {
231
+ if (first_child === 0) first_child = child;
232
+ else this.arena.set_next_sibling(last_child, child);
233
+ last_child = child;
216
234
  }
217
- let nested_rule = this.parse_style_rule();
218
- if (nested_rule === null) this.next_token();
219
- else block_children.push(nested_rule);
220
235
  }
221
236
  if (this.peek_type() === 24) {
222
237
  let block_end = this.lexer.token_start;
@@ -224,19 +239,20 @@ var Parser = class {
224
239
  this.next_token();
225
240
  this.arena.set_length(block_node, block_end - block_start);
226
241
  } else this.arena.set_length(block_node, last_end - block_start);
227
- this.arena.append_children(block_node, block_children);
228
- let at_rule_children = [];
229
- if (prelude_wrapper !== null) at_rule_children.push(prelude_wrapper);
230
- at_rule_children.push(block_node);
242
+ if (first_child !== 0) this.arena.set_first_child(block_node, first_child);
231
243
  this.arena.set_length(at_rule, last_end - at_rule_start);
232
- this.arena.append_children(at_rule, at_rule_children);
244
+ if (prelude_wrapper === null) this.arena.set_first_child(at_rule, block_node);
245
+ else {
246
+ this.arena.set_first_child(at_rule, prelude_wrapper);
247
+ this.arena.set_next_sibling(prelude_wrapper, block_node);
248
+ }
233
249
  } else {
234
250
  if (this.peek_type() === 17) {
235
251
  last_end = this.lexer.token_end;
236
252
  this.next_token();
237
253
  }
238
254
  this.arena.set_length(at_rule, last_end - at_rule_start);
239
- if (prelude_wrapper !== null) this.arena.append_children(at_rule, [prelude_wrapper]);
255
+ if (prelude_wrapper !== null) this.arena.set_first_child(at_rule, prelude_wrapper);
240
256
  }
241
257
  return at_rule;
242
258
  }
@@ -0,0 +1,176 @@
1
+ import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
+ import "./arena-CFwM4uQs.js";
3
+ import { a as is_whitespace, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
4
+ //#region src/value-node-parser.ts
5
+ /** @internal */
6
+ var ValueNodeParser = class {
7
+ lexer;
8
+ arena;
9
+ source;
10
+ end = 0;
11
+ last_chain_node = 0;
12
+ constructor(arena, source) {
13
+ this.arena = arena;
14
+ this.source = source;
15
+ this.lexer = new Lexer(source);
16
+ }
17
+ parse_chain(start, end, start_line, start_column) {
18
+ this.end = end;
19
+ this.lexer.seek(start, start_line, start_column);
20
+ let first_node = 0;
21
+ let last_node = 0;
22
+ while (this.lexer.pos < this.end) {
23
+ this.lexer.next_token_fast(false);
24
+ if (this.lexer.token_start >= this.end) break;
25
+ if (this.lexer.token_type === 26) break;
26
+ if (this.is_whitespace_inline()) continue;
27
+ let node = this.parse_value_node();
28
+ if (node !== null) {
29
+ if (first_node === 0) first_node = node;
30
+ else this.arena.set_next_sibling(last_node, node);
31
+ last_node = node;
32
+ }
33
+ }
34
+ this.last_chain_node = last_node;
35
+ return first_node;
36
+ }
37
+ is_whitespace_inline() {
38
+ if (this.lexer.token_start >= this.lexer.token_end) return false;
39
+ for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
40
+ return true;
41
+ }
42
+ parse_value_node() {
43
+ let token_type = this.lexer.token_type;
44
+ let start = this.lexer.token_start;
45
+ let end = this.lexer.token_end;
46
+ switch (token_type) {
47
+ case 1: return this.create_node(10, start, end);
48
+ case 10: return this.create_node(11, start, end);
49
+ case 11:
50
+ case 12: return this.create_node(12, start, end);
51
+ case 5: return this.create_node(13, start, end);
52
+ case 4: return this.create_node(14, start, end);
53
+ case 27: return this.create_node(19, start, end);
54
+ case 2: return this.parse_function_node(start, end);
55
+ case 9: return this.parse_operator_node(start, end);
56
+ case 18: return this.create_node(16, start, end);
57
+ case 21: return this.parse_parenthesis_node(start, end);
58
+ default: return null;
59
+ }
60
+ }
61
+ create_node(node_type, start, end) {
62
+ let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
63
+ this.arena.set_content_length(node, end - start);
64
+ return node;
65
+ }
66
+ create_operator_node(start, end) {
67
+ return this.create_node(16, start, end);
68
+ }
69
+ parse_operator_node(start, end) {
70
+ let ch = this.source.charCodeAt(start);
71
+ if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_operator_node(start, end);
72
+ return null;
73
+ }
74
+ parse_function_node(start, end) {
75
+ let name_end = end - 1;
76
+ let func_name_substr = this.source.substring(start, name_end);
77
+ let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
78
+ this.arena.set_content_start_delta(node, 0);
79
+ this.arena.set_content_length(node, name_end - start);
80
+ if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
81
+ let save_pos = this.lexer.save_position();
82
+ this.lexer.next_token_fast(false);
83
+ while (this.is_whitespace_inline() && this.lexer.pos < this.end) this.lexer.next_token_fast(false);
84
+ let first_token_type = this.lexer.token_type;
85
+ this.lexer.restore_position(save_pos);
86
+ if (first_token_type === 5) {} else {
87
+ let paren_depth = 1;
88
+ let func_end = end;
89
+ let content_start = end;
90
+ let content_end = end;
91
+ while (paren_depth > 0) {
92
+ this.lexer.next_token_fast(false);
93
+ let token_type = this.lexer.token_type;
94
+ if (token_type === 26) break;
95
+ if (token_type === 21 || token_type === 2) paren_depth++;
96
+ else if (token_type === 22) {
97
+ paren_depth--;
98
+ if (paren_depth === 0) {
99
+ content_end = this.lexer.token_start;
100
+ func_end = this.lexer.token_end;
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ this.arena.set_length(node, func_end - start);
106
+ this.arena.set_value_start_delta(node, content_start - start);
107
+ this.arena.set_value_length(node, content_end - content_start);
108
+ return node;
109
+ }
110
+ }
111
+ let first_arg = 0;
112
+ let last_arg = 0;
113
+ let paren_depth = 1;
114
+ let func_end = end;
115
+ let content_start = end;
116
+ let content_end = end;
117
+ while (this.lexer.pos < this.end && paren_depth > 0) {
118
+ this.lexer.next_token_fast(false);
119
+ let token_type = this.lexer.token_type;
120
+ if (token_type === 26) break;
121
+ if (this.lexer.token_start >= this.end) break;
122
+ if (token_type === 22) {
123
+ paren_depth--;
124
+ if (paren_depth === 0) {
125
+ content_end = this.lexer.token_start;
126
+ func_end = this.lexer.token_end;
127
+ break;
128
+ }
129
+ }
130
+ if (this.is_whitespace_inline()) continue;
131
+ let arg_node = this.parse_value_node();
132
+ if (arg_node !== null) {
133
+ if (first_arg === 0) first_arg = arg_node;
134
+ else this.arena.set_next_sibling(last_arg, arg_node);
135
+ last_arg = arg_node;
136
+ }
137
+ }
138
+ this.arena.set_length(node, func_end - start);
139
+ this.arena.set_value_start_delta(node, content_start - start);
140
+ this.arena.set_value_length(node, content_end - content_start);
141
+ if (first_arg !== 0) this.arena.set_first_child(node, first_arg);
142
+ return node;
143
+ }
144
+ parse_parenthesis_node(start, end) {
145
+ let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
146
+ let first_child = 0;
147
+ let last_child = 0;
148
+ let paren_depth = 1;
149
+ let paren_end = end;
150
+ while (this.lexer.pos < this.end && paren_depth > 0) {
151
+ this.lexer.next_token_fast(false);
152
+ let token_type = this.lexer.token_type;
153
+ if (token_type === 26) break;
154
+ if (this.lexer.token_start >= this.end) break;
155
+ if (token_type === 22) {
156
+ paren_depth--;
157
+ if (paren_depth === 0) {
158
+ paren_end = this.lexer.token_end;
159
+ break;
160
+ }
161
+ }
162
+ if (this.is_whitespace_inline()) continue;
163
+ let child_node = this.parse_value_node();
164
+ if (child_node !== null) {
165
+ if (first_child === 0) first_child = child_node;
166
+ else this.arena.set_next_sibling(last_child, child_node);
167
+ last_child = child_node;
168
+ }
169
+ }
170
+ this.arena.set_length(node, paren_end - start);
171
+ if (first_child !== 0) this.arena.set_first_child(node, first_child);
172
+ return node;
173
+ }
174
+ };
175
+ //#endregion
176
+ export { ValueNodeParser as t };
package/dist/walk.d.ts CHANGED
@@ -1,17 +1,12 @@
1
- import { o as CSSNode, t as AnyNode } from "./node-types-BrZu8T2C.js";
2
-
1
+ import { o as CSSNode, t as AnyNode } from "./node-types-BRnQyc9B.js";
3
2
  //#region src/walk.d.ts
4
3
  declare const SKIP: unique symbol;
5
4
  declare const BREAK: unique symbol;
6
5
  type WalkCallback = (node: AnyNode, depth: number) => void | typeof SKIP | typeof BREAK;
7
6
  /**
8
- * Walk the AST in depth-first order, calling the callback for each node.
9
- * Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
10
- *
11
- * @param node - The root node to start walking from
12
- * @param callback - Function called for each node. Receives the node and its nesting depth.
13
- * Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
14
- * @param depth - Starting depth (default: 0)
7
+ * Walk the AST depth-first, calling `callback` for each node. Return SKIP to skip
8
+ * children, BREAK to stop. `depth` tracks rule nesting (STYLE_RULE/AT_RULE only),
9
+ * not tree depth.
15
10
  */
16
11
  declare function walk(node: CSSNode, callback: WalkCallback, depth?: number): boolean;
17
12
  type WalkEnterLeaveCallback = (node: AnyNode) => void | typeof SKIP | typeof BREAK;
@@ -20,15 +15,9 @@ interface WalkEnterLeaveOptions {
20
15
  leave?: WalkEnterLeaveCallback;
21
16
  }
22
17
  /**
23
- * Walk the AST in depth-first order, calling enter before visiting children and leave after.
24
- * Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
25
- *
26
- * @param node - The root node to start walking from
27
- * @param options - Object with optional enter and leave callback functions
18
+ * Walk the AST depth-first, calling `enter` before children and `leave` after.
19
+ * SKIP in enter skips children (leave still runs); BREAK stops (leave doesn't run).
28
20
  */
29
- declare function traverse(node: CSSNode, {
30
- enter,
31
- leave
32
- }?: WalkEnterLeaveOptions): boolean;
21
+ declare function traverse(node: CSSNode, { enter, leave }?: WalkEnterLeaveOptions): boolean;
33
22
  //#endregion
34
23
  export { BREAK, SKIP, traverse, walk };
package/dist/walk.js CHANGED
@@ -1,17 +1,13 @@
1
- import "./arena-CCye9VYE.js";
2
- import { t as CSSNode } from "./css-node-TR2T5Q7D.js";
1
+ import "./arena-CFwM4uQs.js";
2
+ import { t as CSSNode } from "./css-node-B3EzCweR.js";
3
3
  import "./constants.js";
4
4
  //#region src/walk.ts
5
5
  const SKIP = Symbol("SKIP");
6
6
  const BREAK = Symbol("BREAK");
7
7
  /**
8
- * Walk the AST in depth-first order, calling the callback for each node.
9
- * Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
10
- *
11
- * @param node - The root node to start walking from
12
- * @param callback - Function called for each node. Receives the node and its nesting depth.
13
- * Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
14
- * @param depth - Starting depth (default: 0)
8
+ * Walk the AST depth-first, calling `callback` for each node. Return SKIP to skip
9
+ * children, BREAK to stop. `depth` tracks rule nesting (STYLE_RULE/AT_RULE only),
10
+ * not tree depth.
15
11
  */
16
12
  function walk(node, callback, depth = 0) {
17
13
  const result = callback(node, depth);
@@ -45,11 +41,8 @@ function _walk(arena, source, index, callback, depth) {
45
41
  }
46
42
  const NOOP = function() {};
47
43
  /**
48
- * Walk the AST in depth-first order, calling enter before visiting children and leave after.
49
- * Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
50
- *
51
- * @param node - The root node to start walking from
52
- * @param options - Object with optional enter and leave callback functions
44
+ * Walk the AST depth-first, calling `enter` before children and `leave` after.
45
+ * SKIP in enter skips children (leave still runs); BREAK stops (leave doesn't run).
53
46
  */
54
47
  function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
55
48
  const enter_result = enter(node);