@projectwallace/css-parser 0.15.0 → 0.16.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.
@@ -1,8 +1,8 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
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-C3t4b8Jt.js";
5
- import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-BxrmqJxI.js";
1
+ import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
+ import { l as CSSDataArena } from "./arena-CCye9VYE.js";
3
+ import { a as is_whitespace, l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-B0AZRxxt.js";
4
+ import { t as CSSNode } from "./css-node-CuLhABl8.js";
5
+ import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-BmXnziOy.js";
6
6
  //#region src/parse-atrule-prelude.ts
7
7
  /** @internal */
8
8
  var AtRulePreludeParser = class {
@@ -468,11 +468,9 @@ var AtRulePreludeParser = class {
468
468
  }
469
469
  }
470
470
  parse_feature_value(start, end) {
471
- let temp_lexer = new Lexer(this.source);
472
- 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);
473
473
  let nodes = [];
474
- let saved_lexer = this.lexer;
475
- this.lexer = temp_lexer;
476
474
  while (this.lexer.pos < end) {
477
475
  this.lexer.next_token_fast(false);
478
476
  if (this.lexer.token_start >= end) break;
@@ -485,7 +483,7 @@ var AtRulePreludeParser = class {
485
483
  let node = this.parse_value_token();
486
484
  if (node !== null) nodes.push(node);
487
485
  }
488
- this.lexer = saved_lexer;
486
+ this.lexer.restore_position(saved_position);
489
487
  return nodes;
490
488
  }
491
489
  parse_namespace_prelude() {
@@ -540,8 +538,7 @@ var AtRulePreludeParser = class {
540
538
  if (this.lexer.pos >= this.prelude_end) return [];
541
539
  this.next_token();
542
540
  if (this.lexer.token_type !== 1) return [];
543
- nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end));
544
- nodes.push(...this.parse_media_query_list());
541
+ nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end), ...this.parse_media_query_list());
545
542
  return nodes;
546
543
  }
547
544
  parse_feature_range(feature_start, feature_end, content_start, content_end) {
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
- import { n as Lexer } from "./tokenize-CyiJelQC.js";
3
- import { d as Declaration } from "./node-types-DJytj0FB.js";
1
+ import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
2
+ import { n as Lexer } from "./tokenize-DeZYFa9R.js";
3
+ import { d as Declaration } from "./node-types-BrZu8T2C.js";
4
4
 
5
5
  //#region src/parse-declaration.d.ts
6
6
  /** @internal */
@@ -1,8 +1,8 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
- import { i as is_vendor_prefixed } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-C3t4b8Jt.js";
5
- import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
1
+ import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
+ import { l as CSSDataArena } from "./arena-CCye9VYE.js";
3
+ import { i as is_vendor_prefixed } from "./parse-dimension-B0AZRxxt.js";
4
+ import { t as CSSNode } from "./css-node-CuLhABl8.js";
5
+ import { i as trim_boundaries } from "./parse-utils-BmXnziOy.js";
6
6
  import { ValueParser } from "./parse-value.js";
7
7
  //#region src/parse-declaration.ts
8
8
  /** @internal */
@@ -169,7 +169,7 @@ function parse_dimension(text) {
169
169
  let num_str = text.substring(0, num_end);
170
170
  let unit = text.substring(num_end);
171
171
  return {
172
- value: num_str ? parseFloat(num_str) : 0,
172
+ value: num_str ? Number.parseFloat(num_str) : 0,
173
173
  unit
174
174
  };
175
175
  }
@@ -1,2 +1,2 @@
1
- import { t as parse_dimension } from "./parse-dimension-CCn_XRDe.js";
1
+ import { t as parse_dimension } from "./parse-dimension-B0AZRxxt.js";
2
2
  export { parse_dimension };
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
- import { I as SelectorList } from "./node-types-DJytj0FB.js";
1
+ import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
2
+ import { F as Selector, I as SelectorList } from "./node-types-BrZu8T2C.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,8 +1,8 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
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-C3t4b8Jt.js";
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";
1
+ import { t as Lexer } from "./tokenize-BiRLfVbm.js";
2
+ import { l as CSSDataArena } from "./arena-CCye9VYE.js";
3
+ import { a as is_whitespace, n as is_combinator, o as str_equals } from "./parse-dimension-B0AZRxxt.js";
4
+ import { t as CSSNode } from "./css-node-CuLhABl8.js";
5
+ import { n as skip_whitespace_and_comments_forward, r as skip_whitespace_forward, t as skip_whitespace_and_comments_backward } from "./parse-utils-BmXnziOy.js";
6
6
  import { ANplusBParser } from "./parse-anplusb.js";
7
7
  //#region src/parse-selector.ts
8
8
  /** @internal */
@@ -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;
@@ -372,11 +374,9 @@ var SelectorParser = class {
372
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);
373
375
  }
374
376
  parse_lang_identifiers(start, end, parent_node) {
375
- let temp_lexer = new Lexer(this.source);
376
- 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);
377
379
  let saved_selector_end = this.selector_end;
378
- let saved_lexer = this.lexer;
379
- this.lexer = temp_lexer;
380
380
  this.selector_end = end;
381
381
  let first_child = null;
382
382
  let last_child = null;
@@ -397,11 +397,11 @@ var SelectorParser = class {
397
397
  }
398
398
  if (first_child !== null) this.arena.set_first_child(parent_node, first_child);
399
399
  this.selector_end = saved_selector_end;
400
- this.lexer = saved_lexer;
400
+ this.lexer.restore_position(saved_position);
401
401
  }
402
402
  parse_nth_expression(start, end) {
403
403
  let of_index = this.find_of_keyword(start, end);
404
- let anplusb_parser = new ANplusBParser(this.arena, this.source);
404
+ let anplusb_parser = this.anplusb_parser;
405
405
  if (of_index === -1) return anplusb_parser.parse_anplusb(start, end, this.lexer.line);
406
406
  let anplusb_node = anplusb_parser.parse_anplusb(start, of_index, this.lexer.line);
407
407
  let selector_start = of_index + 2;
@@ -470,16 +470,14 @@ var SelectorParser = class {
470
470
  }
471
471
  }
472
472
  };
473
- /**
474
- * Parse a CSS selector string and return an AST
475
- * @param source - The CSS selector to parse (e.g., "div.class > p#id")
476
- * @returns The root CSSNode of the selector AST
477
- */
478
- function parse_selector(source) {
473
+ function parse_selector_list(source) {
479
474
  const arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
480
475
  const selector_index = new SelectorParser(arena, source).parse_selector(0, source.length);
481
476
  if (selector_index === null) return new CSSNode(arena, source, arena.create_node(20, 0, 0, 1, 1));
482
477
  return new CSSNode(arena, source, selector_index);
483
478
  }
479
+ function parse_selector(source) {
480
+ return parse_selector_list(source).first_child;
481
+ }
484
482
  //#endregion
485
- export { SelectorParser, parse_selector };
483
+ export { SelectorParser, parse_selector, parse_selector_list };
@@ -1,4 +1,4 @@
1
- import { a as is_whitespace } from "./parse-dimension-CCn_XRDe.js";
1
+ import { a as is_whitespace } from "./parse-dimension-B0AZRxxt.js";
2
2
  //#region src/parse-utils.ts
3
3
  /**
4
4
  * Skip whitespace forward from a position
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
- import { q as Value } from "./node-types-DJytj0FB.js";
1
+ import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
2
+ import { q as Value } from "./node-types-BrZu8T2C.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-DnV0a_Ne.js";
3
- import { a as is_whitespace, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-C3t4b8Jt.js";
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-CuLhABl8.js";
5
5
  //#region src/parse-value.ts
6
6
  /** @internal */
7
7
  var ValueParser = class {
package/dist/parse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-CSK5NfHq.js";
2
- import { t as CommentInfo } from "./tokenize-CyiJelQC.js";
3
- import { z as StyleSheet } from "./node-types-DJytj0FB.js";
1
+ import { l as CSSDataArena } from "./arena-DfpuGV9Y.js";
2
+ import { t as CommentInfo } from "./tokenize-DeZYFa9R.js";
3
+ import { z as StyleSheet } from "./node-types-BrZu8T2C.js";
4
4
 
5
5
  //#region src/parse.d.ts
6
6
  interface ParserOptions {
package/dist/parse.js CHANGED
@@ -1,12 +1,12 @@
1
- import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
- import { l as CSSDataArena } from "./arena-DnV0a_Ne.js";
3
- import { t as CSSNode } from "./css-node-C3t4b8Jt.js";
4
- import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
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-CuLhABl8.js";
4
+ import { i as trim_boundaries } from "./parse-utils-BmXnziOy.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";
8
8
  //#region src/parse.ts
9
- let DECLARATION_AT_RULES = new Set([
9
+ let DECLARATION_AT_RULES = /* @__PURE__ */ new Set([
10
10
  "font-face",
11
11
  "font-feature-values",
12
12
  "page",
@@ -66,6 +66,7 @@ var Parser = class {
66
66
  else rules.push(rule);
67
67
  }
68
68
  this.arena.append_children(stylesheet, rules);
69
+ this.arena.trim();
69
70
  return new CSSNode(this.arena, this.source, stylesheet);
70
71
  }
71
72
  parse_rule() {