@projectwallace/css-parser 0.14.10 → 0.16.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,7 +1,7 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
3
  import { o as str_equals, s as str_index_of } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
5
5
  //#region src/parse-anplusb.ts
6
6
  /** @internal */
7
7
  var ANplusBParser = class {
@@ -58,7 +58,7 @@ var ANplusBParser = class {
58
58
  b_start = this.lexer.token_start;
59
59
  b_end = this.lexer.token_end;
60
60
  }
61
- return this.create_anplusb_node(node_start, a_start, a_end, b !== null ? b_start : 0, b !== null ? b_end : 0);
61
+ return this.create_anplusb_node(node_start, a_start, a_end, b === null ? 0 : b_start, b === null ? 0 : b_end);
62
62
  }
63
63
  if (first_char === 110) {
64
64
  if (this.lexer.token_end > this.lexer.token_start + 1) {
@@ -78,7 +78,7 @@ var ANplusBParser = class {
78
78
  b_start = this.lexer.token_start;
79
79
  b_end = this.lexer.token_end;
80
80
  }
81
- return this.create_anplusb_node(node_start, a_start, a_end, b !== null ? b_start : 0, b !== null ? b_end : 0);
81
+ return this.create_anplusb_node(node_start, a_start, a_end, b === null ? 0 : b_start, b === null ? 0 : b_end);
82
82
  }
83
83
  return null;
84
84
  }
@@ -102,7 +102,7 @@ var ANplusBParser = class {
102
102
  b_start = this.lexer.token_start;
103
103
  b_end = this.lexer.token_end;
104
104
  }
105
- return this.create_anplusb_node(node_start, a_start, a_end, b !== null ? b_start : 0, b !== null ? b_end : 0);
105
+ return this.create_anplusb_node(node_start, a_start, a_end, b === null ? 0 : b_start, b === null ? 0 : b_end);
106
106
  }
107
107
  }
108
108
  this.lexer.restore_position(saved);
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { t as AnyNode } from "./node-types-D282RMOz.js";
1
+ import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
+ import { t as AnyNode } from "./node-types-mntWKkN-.js";
3
3
 
4
4
  //#region src/parse-atrule-prelude.d.ts
5
5
  /** @internal */
@@ -18,6 +18,8 @@ declare class AtRulePreludeParser {
18
18
  private parse_media_feature;
19
19
  private parse_container_query;
20
20
  private parse_supports_query;
21
+ private find_colon_at_depth_zero;
22
+ private create_supports_declaration;
21
23
  private parse_layer_names;
22
24
  private parse_function_prelude;
23
25
  private parse_identifier;
@@ -1,7 +1,7 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
3
  import { a as is_whitespace, l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
5
5
  import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-BxrmqJxI.js";
6
6
  //#region src/parse-atrule-prelude.ts
7
7
  /** @internal */
@@ -138,7 +138,13 @@ var AtRulePreludeParser = class {
138
138
  }
139
139
  j++;
140
140
  }
141
- if (colon_pos !== -1) {
141
+ if (colon_pos === -1) {
142
+ let trimmed = trim_boundaries(this.source, content_start, content_end);
143
+ if (trimmed) {
144
+ this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
145
+ this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
146
+ }
147
+ } else {
142
148
  let name_trimmed = trim_boundaries(this.source, content_start, colon_pos);
143
149
  if (name_trimmed) {
144
150
  this.arena.set_content_start_delta(feature, name_trimmed[0] - feature_start);
@@ -149,12 +155,6 @@ var AtRulePreludeParser = class {
149
155
  let value_nodes = this.parse_feature_value(value_trimmed[0], value_trimmed[1]);
150
156
  if (value_nodes.length > 0) this.arena.append_children(feature, value_nodes);
151
157
  }
152
- } else {
153
- let trimmed = trim_boundaries(this.source, content_start, content_end);
154
- if (trimmed) {
155
- this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
156
- this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
157
- }
158
158
  }
159
159
  return feature;
160
160
  }
@@ -237,6 +237,11 @@ var AtRulePreludeParser = class {
237
237
  if (trimmed) {
238
238
  this.arena.set_value_start_delta(query, trimmed[0] - feature_start);
239
239
  this.arena.set_value_length(query, trimmed[1] - trimmed[0]);
240
+ let colon_pos = this.find_colon_at_depth_zero(trimmed[0], trimmed[1]);
241
+ if (colon_pos !== -1) {
242
+ let decl_child = this.create_supports_declaration(trimmed[0], trimmed[1], colon_pos);
243
+ this.arena.append_children(query, [decl_child]);
244
+ }
240
245
  }
241
246
  nodes.push(query);
242
247
  }
@@ -250,6 +255,39 @@ var AtRulePreludeParser = class {
250
255
  }
251
256
  return nodes;
252
257
  }
258
+ find_colon_at_depth_zero(start, end) {
259
+ let depth = 0;
260
+ for (let i = start; i < end; i++) {
261
+ let ch = this.source.charCodeAt(i);
262
+ if (ch === 40) depth++;
263
+ else if (ch === 41) depth--;
264
+ else if (ch === 58 && depth === 0) return i;
265
+ }
266
+ return -1;
267
+ }
268
+ create_supports_declaration(content_start, content_end, colon_pos) {
269
+ let prop_trimmed = trim_boundaries(this.source, content_start, colon_pos);
270
+ let val_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
271
+ if (!prop_trimmed) return this.create_node(57, content_start, content_end);
272
+ let decl_start = prop_trimmed[0];
273
+ let decl_end = val_trimmed ? val_trimmed[1] : colon_pos + 1;
274
+ let decl = this.create_node(4, decl_start, decl_end);
275
+ this.arena.set_content_start_delta(decl, 0);
276
+ this.arena.set_content_length(decl, prop_trimmed[1] - prop_trimmed[0]);
277
+ if (val_trimmed) {
278
+ let value_nodes = this.parse_feature_value(val_trimmed[0], val_trimmed[1]);
279
+ let value_node;
280
+ if (value_nodes.length === 0) value_node = this.arena.create_node(50, val_trimmed[0], 0, this.lexer.token_line, this.lexer.token_column);
281
+ else {
282
+ value_node = this.arena.create_node(50, val_trimmed[0], val_trimmed[1] - val_trimmed[0], this.lexer.token_line, this.lexer.token_column);
283
+ this.arena.append_children(value_node, value_nodes);
284
+ }
285
+ this.arena.append_children(decl, [value_node]);
286
+ }
287
+ let supports_decl = this.create_node(57, content_start, content_end);
288
+ this.arena.append_children(supports_decl, [decl]);
289
+ return supports_decl;
290
+ }
253
291
  parse_layer_names() {
254
292
  let nodes = [];
255
293
  while (this.lexer.pos < this.prelude_end) {
@@ -295,8 +333,8 @@ var AtRulePreludeParser = class {
295
333
  this.skip_whitespace();
296
334
  if (this.lexer.pos >= this.prelude_end) return [];
297
335
  let url_node = this.parse_import_url();
298
- if (url_node !== null) nodes.push(url_node);
299
- else return [];
336
+ if (url_node === null) return [];
337
+ nodes.push(url_node);
300
338
  this.skip_whitespace();
301
339
  if (this.lexer.pos >= this.prelude_end) return nodes;
302
340
  let layer_node = this.parse_import_layer();
@@ -430,11 +468,9 @@ var AtRulePreludeParser = class {
430
468
  }
431
469
  }
432
470
  parse_feature_value(start, end) {
433
- let temp_lexer = new Lexer(this.source);
434
- temp_lexer.seek(start, this.lexer.line, this.lexer.column);
471
+ const saved_position = this.lexer.save_position();
472
+ this.lexer.seek(start, this.lexer.line, this.lexer.column);
435
473
  let nodes = [];
436
- let saved_lexer = this.lexer;
437
- this.lexer = temp_lexer;
438
474
  while (this.lexer.pos < end) {
439
475
  this.lexer.next_token_fast(false);
440
476
  if (this.lexer.token_start >= end) break;
@@ -447,7 +483,7 @@ var AtRulePreludeParser = class {
447
483
  let node = this.parse_value_token();
448
484
  if (node !== null) nodes.push(node);
449
485
  }
450
- this.lexer = saved_lexer;
486
+ this.lexer.restore_position(saved_position);
451
487
  return nodes;
452
488
  }
453
489
  parse_namespace_prelude() {
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { n as Lexer } from "./tokenize-CyiJelQC.js";
3
- import { d as Declaration } from "./node-types-D282RMOz.js";
1
+ import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
+ import { n as Lexer } from "./tokenize-mV23Aiyb.js";
3
+ import { d as Declaration } from "./node-types-mntWKkN-.js";
4
4
 
5
5
  //#region src/parse-declaration.d.ts
6
6
  /** @internal */
@@ -1,7 +1,7 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
3
  import { i as is_vendor_prefixed } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
5
5
  import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
6
6
  import { ValueParser } from "./parse-value.js";
7
7
  //#region src/parse-declaration.ts
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { I as SelectorList } from "./node-types-D282RMOz.js";
1
+ import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
+ import { F as Selector, I as SelectorList } from "./node-types-mntWKkN-.js";
3
3
 
4
4
  //#region src/parse-selector.d.ts
5
5
  /** @internal */
@@ -8,6 +8,7 @@ declare class SelectorParser {
8
8
  private arena;
9
9
  private source;
10
10
  private selector_end;
11
+ private anplusb_parser;
11
12
  constructor(arena: CSSDataArena, source: string);
12
13
  parse_selector(start: number, end: number, line?: number, column?: number, allow_relative?: boolean): number | null;
13
14
  private parse_selector_list;
@@ -33,11 +34,7 @@ declare class SelectorParser {
33
34
  private create_node_at;
34
35
  private skip_whitespace;
35
36
  }
36
- /**
37
- * Parse a CSS selector string and return an AST
38
- * @param source - The CSS selector to parse (e.g., "div.class > p#id")
39
- * @returns The root CSSNode of the selector AST
40
- */
41
- declare function parse_selector(source: string): SelectorList;
37
+ declare function parse_selector_list(source: string): SelectorList;
38
+ declare function parse_selector(source: string): Selector;
42
39
  //#endregion
43
- export { SelectorParser, parse_selector };
40
+ export { SelectorParser, parse_selector, parse_selector_list };
@@ -1,7 +1,7 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
3
  import { a as is_whitespace, n as is_combinator, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
5
5
  import { n as skip_whitespace_and_comments_forward, r as skip_whitespace_forward, t as skip_whitespace_and_comments_backward } from "./parse-utils-BxrmqJxI.js";
6
6
  import { ANplusBParser } from "./parse-anplusb.js";
7
7
  //#region src/parse-selector.ts
@@ -11,11 +11,13 @@ var SelectorParser = class {
11
11
  arena;
12
12
  source;
13
13
  selector_end;
14
+ anplusb_parser;
14
15
  constructor(arena, source) {
15
16
  this.arena = arena;
16
17
  this.source = source;
17
18
  this.lexer = new Lexer(source);
18
19
  this.selector_end = 0;
20
+ this.anplusb_parser = new ANplusBParser(arena, source);
19
21
  }
20
22
  parse_selector(start, end, line = 1, column = 1, allow_relative = true) {
21
23
  this.selector_end = end;
@@ -53,7 +55,7 @@ var SelectorParser = class {
53
55
  continue;
54
56
  } else break;
55
57
  }
56
- if (selectors.length >= 1) {
58
+ if (selectors.length > 0) {
57
59
  let list_node = this.arena.create_node(20, list_start, this.lexer.pos - list_start, list_line, list_column);
58
60
  this.arena.append_children(list_node, selectors);
59
61
  return list_node;
@@ -77,8 +79,8 @@ var SelectorParser = class {
77
79
  }
78
80
  while (this.lexer.pos < this.selector_end) {
79
81
  let compound = this.parse_compound_selector();
80
- if (compound !== null) components.push(compound);
81
- else break;
82
+ if (compound === null) break;
83
+ components.push(compound);
82
84
  let combinator = this.try_parse_combinator();
83
85
  if (combinator !== null) {
84
86
  components.push(combinator);
@@ -115,11 +117,11 @@ var SelectorParser = class {
115
117
  if (this.lexer.token_start >= this.selector_end) break;
116
118
  if (this.lexer.token_type === 26) break;
117
119
  let part = this.parse_simple_selector();
118
- if (part !== null) parts.push(part);
119
- else {
120
+ if (part === null) {
120
121
  this.lexer.restore_position(saved);
121
122
  break;
122
123
  }
124
+ parts.push(part);
123
125
  }
124
126
  if (parts.length === 0) return null;
125
127
  for (let i = 0; i < parts.length - 1; i++) this.arena.set_next_sibling(parts[i], parts[i + 1]);
@@ -132,13 +134,14 @@ var SelectorParser = class {
132
134
  switch (token_type) {
133
135
  case 1: return this.parse_type_or_namespace_selector(start, end);
134
136
  case 4: return this.create_node(23, start, end);
135
- case 9:
137
+ case 9: {
136
138
  let ch = this.source.charCodeAt(start);
137
139
  if (ch === 46) return this.parse_class_selector(start);
138
140
  else if (ch === 42) return this.parse_universal_or_namespace_selector(start, end);
139
141
  else if (ch === 38) return this.create_node(29, start, end);
140
142
  else if (ch === 124) return this.parse_empty_namespace_selector(start);
141
143
  return null;
144
+ }
142
145
  case 19: return this.parse_attribute_selector(start);
143
146
  case 16: return this.parse_pseudo(start);
144
147
  case 2: return this.parse_pseudo_function(start, end);
@@ -148,7 +151,7 @@ var SelectorParser = class {
148
151
  default: return null;
149
152
  }
150
153
  }
151
- parse_namespace_local_part(selector_start, namespace_start, namespace_length) {
154
+ parse_namespace_local_part(selector_start, namespace_start, namespace_prefix_length) {
152
155
  const saved = this.lexer.save_position();
153
156
  this.lexer.next_token_fast(false);
154
157
  let node_type;
@@ -158,9 +161,14 @@ var SelectorParser = class {
158
161
  this.lexer.restore_position(saved);
159
162
  return null;
160
163
  }
161
- let node = this.create_node(node_type, selector_start, this.lexer.token_end);
162
- this.arena.set_content_start_delta(node, namespace_start - selector_start);
163
- this.arena.set_content_length(node, namespace_length);
164
+ let local_start = this.lexer.token_start;
165
+ let local_end = this.lexer.token_end;
166
+ let node = this.create_node(node_type, selector_start, local_end);
167
+ this.arena.set_flag(node, 16);
168
+ this.arena.set_content_start_delta(node, local_start - selector_start);
169
+ this.arena.set_content_length(node, local_end - local_start);
170
+ this.arena.set_value_start_delta(node, namespace_start - selector_start);
171
+ this.arena.set_value_length(node, namespace_prefix_length);
164
172
  return node;
165
173
  }
166
174
  parse_type_or_namespace_selector(start, end) {
@@ -171,8 +179,8 @@ var SelectorParser = class {
171
179
  this.lexer.pos++;
172
180
  let node = this.parse_namespace_local_part(start, start, end - start);
173
181
  if (node !== null) return node;
174
- this.lexer.restore_position(saved);
175
- } else this.lexer.restore_position(saved);
182
+ }
183
+ this.lexer.restore_position(saved);
176
184
  return this.create_node(21, start, end);
177
185
  }
178
186
  parse_universal_or_namespace_selector(start, end) {
@@ -182,12 +190,12 @@ var SelectorParser = class {
182
190
  this.lexer.pos++;
183
191
  let node = this.parse_namespace_local_part(start, start, end - start);
184
192
  if (node !== null) return node;
185
- this.lexer.restore_position(saved);
186
- } else this.lexer.restore_position(saved);
193
+ }
194
+ this.lexer.restore_position(saved);
187
195
  return this.create_node(28, start, end);
188
196
  }
189
197
  parse_empty_namespace_selector(start) {
190
- return this.parse_namespace_local_part(start, start, 1);
198
+ return this.parse_namespace_local_part(start, start, 0);
191
199
  }
192
200
  try_parse_combinator() {
193
201
  const saved_whitespace_start = this.lexer.save_position();
@@ -287,14 +295,11 @@ var SelectorParser = class {
287
295
  if (c === 92) pos += 2;
288
296
  else pos++;
289
297
  }
290
- value_end = pos;
291
- } else {
292
- while (pos < end) {
293
- if (is_whitespace(this.source.charCodeAt(pos))) break;
294
- pos++;
295
- }
296
- value_end = pos;
298
+ } else while (pos < end) {
299
+ if (is_whitespace(this.source.charCodeAt(pos))) break;
300
+ pos++;
297
301
  }
302
+ value_end = pos;
298
303
  if (value_end > value_start) {
299
304
  this.arena.set_value_start_delta(node, value_start - this.arena.get_start_offset(node));
300
305
  this.arena.set_value_length(node, value_end - value_start);
@@ -369,11 +374,9 @@ var SelectorParser = class {
369
374
  return str_equals("nth-child", name) || str_equals("nth-last-child", name) || str_equals("nth-of-type", name) || str_equals("nth-last-of-type", name) || str_equals("nth-col", name) || str_equals("nth-last-col", name);
370
375
  }
371
376
  parse_lang_identifiers(start, end, parent_node) {
372
- let temp_lexer = new Lexer(this.source);
373
- temp_lexer.seek(start, this.lexer.line, this.lexer.column);
377
+ const saved_position = this.lexer.save_position();
378
+ this.lexer.seek(start, this.lexer.line, this.lexer.column);
374
379
  let saved_selector_end = this.selector_end;
375
- let saved_lexer = this.lexer;
376
- this.lexer = temp_lexer;
377
380
  this.selector_end = end;
378
381
  let first_child = null;
379
382
  let last_child = null;
@@ -394,28 +397,28 @@ var SelectorParser = class {
394
397
  }
395
398
  if (first_child !== null) this.arena.set_first_child(parent_node, first_child);
396
399
  this.selector_end = saved_selector_end;
397
- this.lexer = saved_lexer;
400
+ this.lexer.restore_position(saved_position);
398
401
  }
399
402
  parse_nth_expression(start, end) {
400
403
  let of_index = this.find_of_keyword(start, end);
401
- if (of_index !== -1) {
402
- let anplusb_node = new ANplusBParser(this.arena, this.source).parse_anplusb(start, of_index, this.lexer.line);
403
- let selector_start = of_index + 2;
404
- selector_start = skip_whitespace_forward(this.source, selector_start, end);
405
- let saved_selector_end = this.selector_end;
406
- const saved = this.lexer.save_position();
407
- this.selector_end = end;
408
- this.lexer.pos = selector_start;
409
- let selector_list = this.parse_selector_list();
410
- this.selector_end = saved_selector_end;
411
- this.lexer.restore_position(saved);
412
- let of_node = this.arena.create_node(31, start, end - start, this.lexer.line, 1);
413
- if (anplusb_node !== null && selector_list !== null) {
414
- this.arena.set_first_child(of_node, anplusb_node);
415
- this.arena.set_next_sibling(anplusb_node, selector_list);
416
- } else if (anplusb_node !== null) this.arena.set_first_child(of_node, anplusb_node);
417
- return of_node;
418
- } else return new ANplusBParser(this.arena, this.source).parse_anplusb(start, end, this.lexer.line);
404
+ let anplusb_parser = this.anplusb_parser;
405
+ if (of_index === -1) return anplusb_parser.parse_anplusb(start, end, this.lexer.line);
406
+ let anplusb_node = anplusb_parser.parse_anplusb(start, of_index, this.lexer.line);
407
+ let selector_start = of_index + 2;
408
+ selector_start = skip_whitespace_forward(this.source, selector_start, end);
409
+ let saved_selector_end = this.selector_end;
410
+ const saved = this.lexer.save_position();
411
+ this.selector_end = end;
412
+ this.lexer.pos = selector_start;
413
+ let selector_list = this.parse_selector_list();
414
+ this.selector_end = saved_selector_end;
415
+ this.lexer.restore_position(saved);
416
+ let of_node = this.arena.create_node(31, start, end - start, this.lexer.line, 1);
417
+ if (anplusb_node !== null && selector_list !== null) {
418
+ this.arena.set_first_child(of_node, anplusb_node);
419
+ this.arena.set_next_sibling(anplusb_node, selector_list);
420
+ } else if (anplusb_node !== null) this.arena.set_first_child(of_node, anplusb_node);
421
+ return of_node;
419
422
  }
420
423
  find_of_keyword(start, end) {
421
424
  let i = start;
@@ -467,16 +470,14 @@ var SelectorParser = class {
467
470
  }
468
471
  }
469
472
  };
470
- /**
471
- * Parse a CSS selector string and return an AST
472
- * @param source - The CSS selector to parse (e.g., "div.class > p#id")
473
- * @returns The root CSSNode of the selector AST
474
- */
475
- function parse_selector(source) {
473
+ function parse_selector_list(source) {
476
474
  const arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
477
475
  const selector_index = new SelectorParser(arena, source).parse_selector(0, source.length);
478
476
  if (selector_index === null) return new CSSNode(arena, source, arena.create_node(20, 0, 0, 1, 1));
479
477
  return new CSSNode(arena, source, selector_index);
480
478
  }
479
+ function parse_selector(source) {
480
+ return parse_selector_list(source).first_child;
481
+ }
481
482
  //#endregion
482
- export { SelectorParser, parse_selector };
483
+ export { SelectorParser, parse_selector, parse_selector_list };
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { K as Value } from "./node-types-D282RMOz.js";
1
+ import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
+ import { q as Value } from "./node-types-mntWKkN-.js";
3
3
 
4
4
  //#region src/parse-value.d.ts
5
5
  /** @internal */
@@ -1,7 +1,7 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
3
  import { a as is_whitespace, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
5
5
  //#region src/parse-value.ts
6
6
  /** @internal */
7
7
  var ValueParser = class {
@@ -21,7 +21,7 @@ var ValueParser = class {
21
21
  let value_nodes = this.parse_value_tokens();
22
22
  if (value_nodes.length === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
23
23
  let first_node_start = this.arena.get_start_offset(value_nodes[0]);
24
- let last_node_index = value_nodes[value_nodes.length - 1];
24
+ let last_node_index = value_nodes.at(-1);
25
25
  let last_node_end = this.arena.get_start_offset(last_node_index) + this.arena.get_length(last_node_index);
26
26
  let value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
27
27
  this.arena.append_children(value_node, value_nodes);
package/dist/parse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { t as CommentInfo } from "./tokenize-CyiJelQC.js";
3
- import { z as StyleSheet } from "./node-types-D282RMOz.js";
1
+ import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
+ import { t as CommentInfo } from "./tokenize-mV23Aiyb.js";
3
+ import { z as StyleSheet } from "./node-types-mntWKkN-.js";
4
4
 
5
5
  //#region src/parse.d.ts
6
6
  interface ParserOptions {
package/dist/parse.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
- import { t as CSSNode } from "./css-node-DMd5jbdm.js";
1
+ import { t as Lexer } from "./tokenize-BxUina14.js";
2
+ import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
+ import { t as CSSNode } from "./css-node-BTgoFWDU.js";
4
4
  import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
5
5
  import { SelectorParser } from "./parse-selector.js";
6
6
  import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
@@ -35,7 +35,8 @@ var Parser = class {
35
35
  this.parse_selectors_enabled = opts.parse_selectors ?? true;
36
36
  this.parse_atrule_preludes_enabled = opts.parse_atrule_preludes ?? true;
37
37
  this.lexer = new Lexer(source, opts.on_comment);
38
- this.arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
38
+ let capacity = CSSDataArena.capacity_for_source(source.length);
39
+ this.arena = new CSSDataArena(capacity);
39
40
  this.selector_parser = this.parse_selectors_enabled ? new SelectorParser(this.arena, source) : null;
40
41
  this.prelude_parser = this.parse_atrule_preludes_enabled ? new AtRulePreludeParser(this.arena, source) : null;
41
42
  this.declaration_parser = new DeclarationParser(this.arena, source, this.parse_values_enabled);
@@ -61,8 +62,8 @@ var Parser = class {
61
62
  let rules = [];
62
63
  while (!this.is_eof()) {
63
64
  let rule = this.parse_rule();
64
- if (rule !== null) rules.push(rule);
65
- else this.next_token();
65
+ if (rule === null) this.next_token();
66
+ else rules.push(rule);
66
67
  }
67
68
  this.arena.append_children(stylesheet, rules);
68
69
  return new CSSNode(this.arena, this.source, stylesheet);
@@ -92,8 +93,8 @@ var Parser = class {
92
93
  if (token_type === 24) break;
93
94
  if (token_type === 3) {
94
95
  let nested_at_rule = this.parse_atrule();
95
- if (nested_at_rule !== null) block_children.push(nested_at_rule);
96
- else this.next_token();
96
+ if (nested_at_rule === null) this.next_token();
97
+ else block_children.push(nested_at_rule);
97
98
  continue;
98
99
  }
99
100
  let declaration = this.parse_declaration();
@@ -103,8 +104,8 @@ var Parser = class {
103
104
  continue;
104
105
  }
105
106
  let nested_rule = this.parse_style_rule();
106
- if (nested_rule !== null) block_children.push(nested_rule);
107
- else this.next_token();
107
+ if (nested_rule === null) this.next_token();
108
+ else block_children.push(nested_rule);
108
109
  }
109
110
  let block_end = this.lexer.token_start;
110
111
  let rule_end = this.lexer.token_end;
@@ -195,16 +196,16 @@ var Parser = class {
195
196
  if (has_declarations) while (!this.is_eof()) {
196
197
  if (this.peek_type() === 24) break;
197
198
  let declaration = this.parse_declaration();
198
- if (declaration !== null) block_children.push(declaration);
199
- else this.next_token();
199
+ if (declaration === null) this.next_token();
200
+ else block_children.push(declaration);
200
201
  }
201
202
  else while (!this.is_eof()) {
202
203
  let token_type = this.peek_type();
203
204
  if (token_type === 24) break;
204
205
  if (token_type === 3) {
205
206
  let nested_at_rule = this.parse_atrule();
206
- if (nested_at_rule !== null) block_children.push(nested_at_rule);
207
- else this.next_token();
207
+ if (nested_at_rule === null) this.next_token();
208
+ else block_children.push(nested_at_rule);
208
209
  continue;
209
210
  }
210
211
  let declaration = this.parse_declaration();
@@ -213,8 +214,8 @@ var Parser = class {
213
214
  continue;
214
215
  }
215
216
  let nested_rule = this.parse_style_rule();
216
- if (nested_rule !== null) block_children.push(nested_rule);
217
- else this.next_token();
217
+ if (nested_rule === null) this.next_token();
218
+ else block_children.push(nested_rule);
218
219
  }
219
220
  if (this.peek_type() === 24) {
220
221
  let block_end = this.lexer.token_start;
@@ -228,12 +229,11 @@ var Parser = class {
228
229
  at_rule_children.push(block_node);
229
230
  this.arena.set_length(at_rule, last_end - at_rule_start);
230
231
  this.arena.append_children(at_rule, at_rule_children);
231
- } else if (this.peek_type() === 17) {
232
- last_end = this.lexer.token_end;
233
- this.next_token();
234
- this.arena.set_length(at_rule, last_end - at_rule_start);
235
- if (prelude_wrapper !== null) this.arena.append_children(at_rule, [prelude_wrapper]);
236
232
  } else {
233
+ if (this.peek_type() === 17) {
234
+ last_end = this.lexer.token_end;
235
+ this.next_token();
236
+ }
237
237
  this.arena.set_length(at_rule, last_end - at_rule_start);
238
238
  if (prelude_wrapper !== null) this.arena.append_children(at_rule, [prelude_wrapper]);
239
239
  }