@projectwallace/css-parser 0.19.3 → 0.19.4

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.
Files changed (40) hide show
  1. package/README.md +14 -2
  2. package/dist/{arena-D123N1LO.js → arena-CaLnNKbP.js} +1 -2
  3. package/dist/{arena-DnAc8Oy_.d.ts → arena-D689Bo6V.d.ts} +0 -2
  4. package/dist/constants.d.ts +46 -48
  5. package/dist/constants.js +2 -3
  6. package/dist/{css-node-D9rqMgMI.js → css-node-CDTLvxo3.js} +3 -4
  7. package/dist/index.d.ts +6 -6
  8. package/dist/index.js +6 -6
  9. package/dist/{node-types-Pa1MR4CP.d.ts → node-types-BF6bhAjo.d.ts} +54 -62
  10. package/dist/node-types.d.ts +1 -1
  11. package/dist/node-types.js +2 -3
  12. package/dist/parse-anplusb.d.ts +3 -5
  13. package/dist/parse-anplusb.js +5 -6
  14. package/dist/{value-node-parser-ysQ7ssqf.js → parse-atrule-prelude-BMkgCZjw.js} +450 -12
  15. package/dist/parse-atrule-prelude.d.ts +3 -5
  16. package/dist/parse-atrule-prelude.js +1 -431
  17. package/dist/parse-declaration.d.ts +3 -5
  18. package/dist/parse-declaration.js +6 -7
  19. package/dist/parse-dimension.d.ts +1 -3
  20. package/dist/parse-dimension.js +2 -3
  21. package/dist/{parse-selector-BMeyZ-oJ.js → parse-selector-CMKZgPmu.js} +6 -8
  22. package/dist/parse-selector.d.ts +3 -5
  23. package/dist/parse-selector.js +1 -1
  24. package/dist/parse-value.d.ts +3 -5
  25. package/dist/parse-value.js +4 -5
  26. package/dist/parse.d.ts +3 -5
  27. package/dist/parse.js +6 -7
  28. package/dist/{string-helpers-t7UofIfp.d.ts → string-helpers-CwNEcEhd.d.ts} +0 -2
  29. package/dist/string-helpers.d.ts +1 -1
  30. package/dist/string-helpers.js +1 -1
  31. package/dist/{string-utils-aEEsA2CS.js → string-utils-BYH1Oe8a.js} +0 -1
  32. package/dist/{token-types-Bqsf5FX-.d.ts → token-types-BhoXrORA.d.ts} +0 -2
  33. package/dist/token-types.d.ts +1 -1
  34. package/dist/token-types.js +1 -2
  35. package/dist/{tokenize-B2QSzdrM.js → tokenize-DC2Vb0J_.js} +20 -6
  36. package/dist/tokenize.d.ts +17 -5
  37. package/dist/tokenize.js +1 -1
  38. package/dist/walk.d.ts +1 -3
  39. package/dist/walk.js +3 -4
  40. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
- import "./arena-D123N1LO.js";
2
- //#region src/node-types.ts
1
+ import "./arena-CaLnNKbP.js";
2
+ // src/node-types.ts
3
3
  function is_stylesheet(node) {
4
4
  return node.type === 1;
5
5
  }
@@ -138,5 +138,4 @@ function is_ratio(node) {
138
138
  function is_prelude_selectorlist(node) {
139
139
  return node.type === 41;
140
140
  }
141
- //#endregion
142
141
  export { is_atrule, is_atrule_prelude, is_attribute_selector, is_block, is_class_selector, is_combinator, is_comment, is_container_query, is_declaration, is_dimension, is_feature_range, is_function, is_hash, is_id_selector, is_identifier, is_if_branch, is_if_condition, is_lang_selector, is_layer_name, is_media_feature, is_media_query, is_media_type, is_nesting_selector, is_nth_of_selector, is_nth_selector, is_number, is_operator, is_parenthesis, is_prelude_operator, is_prelude_selectorlist, is_pseudo_class_selector, is_pseudo_element_selector, is_ratio, is_raw, is_rule, is_selector, is_selector_list, is_string, is_stylesheet, is_supports_declaration, is_supports_query, is_type_selector, is_unicode_range, is_universal_selector, is_url, is_value };
@@ -1,6 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-DnAc8Oy_.js";
2
- import { O as NthSelector } from "./node-types-Pa1MR4CP.js";
3
- //#region src/parse-anplusb.d.ts
1
+ import { l as CSSDataArena } from "./arena-D689Bo6V.js";
2
+ import { O as NthSelector } from "./node-types-BF6bhAjo.js";
4
3
  /** @internal */
5
4
  export declare class ANplusBParser {
6
5
  private lexer;
@@ -13,5 +12,4 @@ export declare class ANplusBParser {
13
12
  private skip_whitespace;
14
13
  private create_anplusb_node;
15
14
  }
16
- export declare function parse_anplusb(expr: string): NthSelector | null;
17
- //#endregion
15
+ export declare function parse_anplusb(expr: string): NthSelector | null;
@@ -1,9 +1,9 @@
1
- import { t as Lexer } from "./tokenize-B2QSzdrM.js";
1
+ import { t as Lexer } from "./tokenize-DC2Vb0J_.js";
2
2
  import "./token-types.js";
3
- import { l as CSSDataArena } from "./arena-D123N1LO.js";
4
- import { l as str_index_of, s as str_equals } from "./string-utils-aEEsA2CS.js";
5
- import { t as CSSNode } from "./css-node-D9rqMgMI.js";
6
- //#region src/parse-anplusb.ts
3
+ import { l as CSSDataArena } from "./arena-CaLnNKbP.js";
4
+ import { l as str_index_of, s as str_equals } from "./string-utils-BYH1Oe8a.js";
5
+ import { t as CSSNode } from "./css-node-CDTLvxo3.js";
6
+ // src/parse-anplusb.ts
7
7
  /** @internal */
8
8
  var ANplusBParser = class {
9
9
  lexer;
@@ -184,5 +184,4 @@ function parse_anplusb(expr) {
184
184
  if (nodeIndex === null) return null;
185
185
  return new CSSNode(arena, expr, nodeIndex);
186
186
  }
187
- //#endregion
188
187
  export { ANplusBParser, parse_anplusb };
@@ -1,9 +1,10 @@
1
- import { t as Lexer } from "./tokenize-B2QSzdrM.js";
1
+ import { t as Lexer } from "./tokenize-DC2Vb0J_.js";
2
2
  import "./token-types.js";
3
- import "./arena-D123N1LO.js";
4
- import { c as str_equals_range, t as is_and_or_not_range } from "./string-utils-aEEsA2CS.js";
5
- import { i as find_colon_at_depth_zero, o as skip_whitespace_and_comments_forward, s as trim_boundaries, t as SelectorParser } from "./parse-selector-BMeyZ-oJ.js";
6
- //#region src/parse-condition.ts
3
+ import { l as CSSDataArena } from "./arena-CaLnNKbP.js";
4
+ import { c as str_equals_range, d as strip_vendor_prefix, t as is_and_or_not_range } from "./string-utils-BYH1Oe8a.js";
5
+ import { t as CSSNode } from "./css-node-CDTLvxo3.js";
6
+ import { i as find_colon_at_depth_zero, o as skip_whitespace_and_comments_forward, s as trim_boundaries, t as SelectorParser } from "./parse-selector-CMKZgPmu.js";
7
+ // src/parse-condition.ts
7
8
  var ConditionParser = class {
8
9
  lexer;
9
10
  arena;
@@ -314,8 +315,7 @@ var ConditionParser = class {
314
315
  return nodes;
315
316
  }
316
317
  };
317
- //#endregion
318
- //#region src/value-node-parser.ts
318
+ // src/value-node-parser.ts
319
319
  var ValueNodeParser = class ValueNodeParser {
320
320
  lexer;
321
321
  arena;
@@ -385,16 +385,25 @@ var ValueNodeParser = class ValueNodeParser {
385
385
  return null;
386
386
  }
387
387
  paren_content_end = 0;
388
+ paren_has_logical_op = false;
389
+ paren_starts_with_paren = false;
388
390
  paren_close_end = 0;
389
391
  scan_matching_paren(bounded) {
390
392
  let depth = 1;
391
393
  let content_end = this.lexer.pos;
392
394
  let close_end = this.lexer.token_end;
395
+ this.paren_has_logical_op = false;
396
+ this.paren_starts_with_paren = false;
397
+ let seen_first_token = false;
393
398
  while ((!bounded || this.lexer.pos < this.end) && depth > 0) {
394
399
  this.lexer.next_token(false);
395
400
  const token_type = this.lexer.token_type;
396
401
  if (token_type === 26) break;
397
402
  if (bounded && this.lexer.token_start >= this.end) break;
403
+ if (!seen_first_token && token_type !== 13 && token_type !== 25) {
404
+ seen_first_token = true;
405
+ this.paren_starts_with_paren = token_type === 21 || token_type === 1 && (str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end, "only") || str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end, "not"));
406
+ }
398
407
  if (token_type === 21 || token_type === 2) depth++;
399
408
  else if (token_type === 22) {
400
409
  depth--;
@@ -402,7 +411,7 @@ var ValueNodeParser = class ValueNodeParser {
402
411
  content_end = this.lexer.token_start;
403
412
  close_end = this.lexer.token_end;
404
413
  }
405
- }
414
+ } else if (depth === 1 && token_type === 1 && is_and_or_not_range(this.source, this.lexer.token_start, this.lexer.token_end)) this.paren_has_logical_op = true;
406
415
  }
407
416
  this.paren_content_end = content_end;
408
417
  this.paren_close_end = close_end;
@@ -640,6 +649,7 @@ var ValueNodeParser = class ValueNodeParser {
640
649
  let content_end = content_start;
641
650
  let func_end = content_start;
642
651
  const matched = this.scan_matching_paren(true);
652
+ const is_media_condition = this.paren_starts_with_paren || this.paren_has_logical_op;
643
653
  const scanned_content_end = this.paren_content_end;
644
654
  const scanned_func_end = this.paren_close_end;
645
655
  if (matched) {
@@ -660,11 +670,18 @@ var ValueNodeParser = class ValueNodeParser {
660
670
  const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
661
671
  if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
662
672
  else child_nodes = [decl];
663
- } else if (str_equals_range(this.source, func_start, func_name_end, "media")) child_nodes = [this.condition_parser.parse_media_feature_content(content_start, content_end, content_start, content_end)];
664
- else child_nodes = this.parse_value_nodes_in_range(content_start, content_end);
673
+ } else if (str_equals_range(this.source, func_start, func_name_end, "media")) {
674
+ if (is_media_condition) child_nodes = this.media_prelude_parser.parse_prelude("media", content_start, content_end, func_line, func_col + (content_start - func_start));
675
+ else child_nodes = [this.condition_parser.parse_media_feature_content(content_start, content_end, content_start, content_end)];
676
+ } else child_nodes = this.parse_value_nodes_in_range(content_start, content_end);
665
677
  this.arena.append_children(func_node, child_nodes);
666
678
  return func_node;
667
679
  }
680
+ _media_prelude_parser = null;
681
+ get media_prelude_parser() {
682
+ if (this._media_prelude_parser === null) this._media_prelude_parser = new AtRulePreludeParser(this.arena, this.source, this.media_feature_range_name_as_child);
683
+ return this._media_prelude_parser;
684
+ }
668
685
  parse_value_nodes_in_range(start, end) {
669
686
  const saved_end = this.end;
670
687
  const saved_pos = this.lexer.save_position();
@@ -712,5 +729,426 @@ var ValueNodeParser = class ValueNodeParser {
712
729
  return node;
713
730
  }
714
731
  };
715
- //#endregion
716
- export { ConditionParser as n, ValueNodeParser as t };
732
+ // src/parse-atrule-prelude.ts
733
+ var AtRulePreludeParser = class {
734
+ lexer;
735
+ arena;
736
+ source;
737
+ prelude_end;
738
+ value_node_parser;
739
+ condition_parser;
740
+ selector_parser;
741
+ constructor(arena, source, media_feature_range_name_as_child = false) {
742
+ this.arena = arena;
743
+ this.source = source;
744
+ this.lexer = new Lexer(source);
745
+ this.prelude_end = 0;
746
+ this.value_node_parser = new ValueNodeParser(arena, source, media_feature_range_name_as_child);
747
+ this.condition_parser = new ConditionParser(arena, source, this.value_node_parser, media_feature_range_name_as_child);
748
+ this.selector_parser = new SelectorParser(arena, source);
749
+ }
750
+ parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
751
+ this.prelude_end = end;
752
+ this.lexer.seek(start, line, column);
753
+ return this.parse_prelude_dispatch(at_rule_name);
754
+ }
755
+ parse_prelude_dispatch(at_rule_name) {
756
+ switch (strip_vendor_prefix(at_rule_name).toLowerCase()) {
757
+ case "media": return this.parse_media_query_list();
758
+ case "container": return this.parse_container_query();
759
+ case "supports": return this.parse_supports_query();
760
+ case "layer": return this.parse_layer_names();
761
+ case "keyframes":
762
+ case "property":
763
+ case "counter-style":
764
+ case "color-profile":
765
+ case "font-palette-values":
766
+ case "position-try":
767
+ case "font-feature-values":
768
+ case "page": return this.parse_identifier();
769
+ case "function": return this.parse_function_prelude();
770
+ case "import": return this.parse_import_prelude();
771
+ case "charset": return this.parse_charset_prelude();
772
+ case "namespace": return this.parse_namespace_prelude();
773
+ case "scope": return this.parse_scope_prelude();
774
+ case "custom-media": return this.parse_custom_media_prelude();
775
+ }
776
+ return [];
777
+ }
778
+ parse_media_query_list() {
779
+ const nodes = [];
780
+ while (this.lexer.pos < this.prelude_end) {
781
+ this.skip_whitespace();
782
+ if (this.lexer.pos >= this.prelude_end) break;
783
+ const query = this.parse_single_media_query();
784
+ if (query !== null) nodes.push(query);
785
+ this.skip_whitespace();
786
+ const saved = this.lexer.save_position();
787
+ this.next_token();
788
+ if (this.lexer.token_type !== 18) this.lexer.restore_position(saved);
789
+ }
790
+ return nodes;
791
+ }
792
+ create_node(type, start, end) {
793
+ return this.arena.create_node(type, start, end - start, this.lexer.token_line, this.lexer.token_column);
794
+ }
795
+ paren_content_end = 0;
796
+ paren_close_end = 0;
797
+ scan_matching_paren() {
798
+ let depth = 1;
799
+ let content_end = this.lexer.pos;
800
+ let close_end = this.lexer.token_end;
801
+ while (this.lexer.pos < this.prelude_end && depth > 0) {
802
+ const token_type = this.next_token();
803
+ if (token_type === 21 || token_type === 2) depth++;
804
+ else if (token_type === 22) {
805
+ depth--;
806
+ if (depth === 0) {
807
+ content_end = this.lexer.token_start;
808
+ close_end = this.lexer.token_end;
809
+ }
810
+ } else if (token_type === 26) break;
811
+ }
812
+ this.paren_content_end = content_end;
813
+ this.paren_close_end = close_end;
814
+ return depth === 0;
815
+ }
816
+ parse_single_media_query() {
817
+ const query_start = this.lexer.pos;
818
+ this.skip_whitespace();
819
+ if (this.lexer.pos >= this.prelude_end) return null;
820
+ let first_component = 0;
821
+ let last_component = 0;
822
+ const saved_token_start = this.lexer.save_position();
823
+ this.next_token();
824
+ if (this.lexer.token_type === 1) {
825
+ const source = this.source;
826
+ const token_start = this.lexer.token_start;
827
+ const token_end = this.lexer.token_end;
828
+ if (str_equals_range(source, token_start, token_end, "only") || str_equals_range(source, token_start, token_end, "not")) {
829
+ const modifier = this.create_node(38, token_start, token_end);
830
+ first_component = modifier;
831
+ last_component = modifier;
832
+ } else this.lexer.restore_position(saved_token_start);
833
+ } else this.lexer.restore_position(saved_token_start);
834
+ while (this.lexer.pos < this.prelude_end) {
835
+ this.skip_whitespace();
836
+ if (this.lexer.pos >= this.prelude_end) break;
837
+ if (this.peek_token_type() === 18) break;
838
+ this.next_token();
839
+ const token_type = this.lexer.token_type;
840
+ let component = null;
841
+ if (token_type === 21) {
842
+ component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
843
+ if (component !== null) this.condition_parser.seek_to_end(this.lexer);
844
+ } else if (token_type === 1) {
845
+ const token_start = this.lexer.token_start;
846
+ const token_end = this.lexer.token_end;
847
+ if (is_and_or_not_range(this.source, token_start, token_end)) component = this.create_node(38, token_start, token_end);
848
+ else component = this.create_node(34, token_start, token_end);
849
+ } else break;
850
+ if (component !== null) {
851
+ if (first_component === 0) first_component = component;
852
+ else this.arena.set_next_sibling(last_component, component);
853
+ last_component = component;
854
+ }
855
+ }
856
+ if (first_component === 0) return null;
857
+ const query_node = this.create_node(32, query_start, this.lexer.pos);
858
+ this.arena.set_first_child(query_node, first_component);
859
+ return query_node;
860
+ }
861
+ parse_container_query() {
862
+ const query_start = this.lexer.pos;
863
+ let first_component = 0;
864
+ let last_component = 0;
865
+ while (this.lexer.pos < this.prelude_end) {
866
+ this.skip_whitespace();
867
+ if (this.lexer.pos >= this.prelude_end) break;
868
+ this.next_token();
869
+ const token_type = this.lexer.token_type;
870
+ let component = null;
871
+ if (token_type === 21) {
872
+ component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
873
+ if (component !== null) this.condition_parser.seek_to_end(this.lexer);
874
+ } else if (token_type === 2) {
875
+ component = this.condition_parser.parse_function_condition(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
876
+ this.condition_parser.seek_to_end(this.lexer);
877
+ } else if (token_type === 1) {
878
+ const token_start = this.lexer.token_start;
879
+ const token_end = this.lexer.token_end;
880
+ if (is_and_or_not_range(this.source, token_start, token_end)) component = this.create_node(38, token_start, token_end);
881
+ else component = this.create_node(10, token_start, token_end);
882
+ }
883
+ if (component !== null) {
884
+ if (first_component === 0) first_component = component;
885
+ else this.arena.set_next_sibling(last_component, component);
886
+ last_component = component;
887
+ }
888
+ }
889
+ if (first_component === 0) return [];
890
+ const query_node = this.create_node(35, query_start, this.lexer.pos);
891
+ this.arena.set_first_child(query_node, first_component);
892
+ return [query_node];
893
+ }
894
+ parse_supports_query() {
895
+ return this.condition_parser.parse_supports_condition(this.lexer.pos, this.prelude_end, this.lexer.line, this.lexer.column);
896
+ }
897
+ parse_layer_names() {
898
+ const nodes = [];
899
+ while (this.lexer.pos < this.prelude_end) {
900
+ this.skip_whitespace();
901
+ if (this.lexer.pos >= this.prelude_end) break;
902
+ this.next_token();
903
+ const token_type = this.lexer.token_type;
904
+ if (token_type === 1) {
905
+ const name_start = this.lexer.token_start;
906
+ let name_end = this.lexer.token_end;
907
+ while (this.lexer.pos < this.prelude_end) {
908
+ const saved = this.lexer.save_position();
909
+ if (this.next_token() !== 9 || this.source.charCodeAt(this.lexer.token_start) !== 46 || this.lexer.token_start !== name_end) {
910
+ this.lexer.restore_position(saved);
911
+ break;
912
+ }
913
+ const dot_end = this.lexer.token_end;
914
+ if (this.next_token() !== 1 || this.lexer.token_start !== dot_end) {
915
+ this.lexer.restore_position(saved);
916
+ break;
917
+ }
918
+ name_end = this.lexer.token_end;
919
+ }
920
+ const layer = this.create_node(37, name_start, name_end);
921
+ this.arena.set_content_start_delta(layer, 0);
922
+ this.arena.set_content_length(layer, name_end - name_start);
923
+ nodes.push(layer);
924
+ } else if (token_type === 18) continue;
925
+ else if (token_type === 13) continue;
926
+ }
927
+ return nodes;
928
+ }
929
+ parse_function_prelude() {
930
+ this.skip_whitespace();
931
+ if (this.lexer.pos >= this.prelude_end) return [];
932
+ this.next_token();
933
+ if (this.lexer.token_type !== 2) return [];
934
+ const name_start = this.lexer.token_start;
935
+ const name_end = this.lexer.token_end - 1;
936
+ return [this.create_node(10, name_start, name_end)];
937
+ }
938
+ parse_identifier() {
939
+ this.skip_whitespace();
940
+ if (this.lexer.pos >= this.prelude_end) return [];
941
+ this.next_token();
942
+ if (this.lexer.token_type !== 1) return [];
943
+ return [this.create_node(10, this.lexer.token_start, this.lexer.token_end)];
944
+ }
945
+ parse_charset_prelude() {
946
+ this.skip_whitespace();
947
+ if (this.lexer.pos >= this.prelude_end) return [];
948
+ this.next_token();
949
+ if (this.lexer.token_type !== 5) return [];
950
+ return [this.create_node(13, this.lexer.token_start, this.lexer.token_end)];
951
+ }
952
+ parse_import_prelude() {
953
+ const nodes = [];
954
+ this.skip_whitespace();
955
+ if (this.lexer.pos >= this.prelude_end) return [];
956
+ const url_node = this.parse_import_url();
957
+ if (url_node === null) return [];
958
+ nodes.push(url_node);
959
+ this.skip_whitespace();
960
+ if (this.lexer.pos >= this.prelude_end) return nodes;
961
+ const layer_node = this.parse_import_layer();
962
+ if (layer_node !== null) nodes.push(layer_node);
963
+ this.skip_whitespace();
964
+ if (this.lexer.pos >= this.prelude_end) return nodes;
965
+ const supports_node = this.parse_import_supports();
966
+ if (supports_node !== null) nodes.push(supports_node);
967
+ this.skip_whitespace();
968
+ if (this.lexer.pos >= this.prelude_end) return nodes;
969
+ const media_nodes = this.parse_media_query_list();
970
+ nodes.push(...media_nodes);
971
+ return nodes;
972
+ }
973
+ parse_import_url() {
974
+ this.next_token();
975
+ if (this.lexer.token_type !== 7 && this.lexer.token_type !== 2 && this.lexer.token_type !== 5) return null;
976
+ const url_start = this.lexer.token_start;
977
+ let url_end = this.lexer.token_end;
978
+ if (this.lexer.token_type === 2) {
979
+ this.scan_matching_paren();
980
+ url_end = this.paren_close_end;
981
+ }
982
+ return this.create_node(18, url_start, url_end);
983
+ }
984
+ parse_import_layer() {
985
+ const saved = this.lexer.save_position();
986
+ this.next_token();
987
+ if (this.lexer.token_type === 1 || this.lexer.token_type === 2) {
988
+ const name_end = this.lexer.token_type === 2 ? this.lexer.token_end - 1 : this.lexer.token_end;
989
+ if (str_equals_range(this.source, this.lexer.token_start, name_end, "layer")) {
990
+ const layer_start = this.lexer.token_start;
991
+ if (this.lexer.token_type === 1) {
992
+ const layer_node = this.create_node(37, layer_start, this.lexer.token_end);
993
+ this.arena.set_content_start_delta(layer_node, 0);
994
+ this.arena.set_content_length(layer_node, 0);
995
+ return layer_node;
996
+ }
997
+ const content_start = this.lexer.token_end;
998
+ const after_open = this.lexer.save_position();
999
+ const matched = this.scan_matching_paren();
1000
+ const content_end = this.paren_content_end;
1001
+ const layer_end = matched ? this.paren_close_end : this.lexer.pos;
1002
+ const func_node = this.create_node(15, layer_start, layer_end);
1003
+ this.arena.set_content_start_delta(func_node, 0);
1004
+ this.arena.set_content_length(func_node, name_end - layer_start);
1005
+ const trimmed = matched ? trim_boundaries(this.source, content_start, content_end) : null;
1006
+ if (trimmed) {
1007
+ this.arena.set_value_start_delta(func_node, trimmed[0] - layer_start);
1008
+ this.arena.set_value_length(func_node, trimmed[1] - trimmed[0]);
1009
+ const after_close = this.lexer.save_position();
1010
+ const saved_prelude_end = this.prelude_end;
1011
+ this.lexer.restore_position(after_open);
1012
+ this.prelude_end = content_end;
1013
+ const names = this.parse_layer_names();
1014
+ this.prelude_end = saved_prelude_end;
1015
+ this.lexer.restore_position(after_close);
1016
+ this.arena.append_children(func_node, names);
1017
+ }
1018
+ return func_node;
1019
+ }
1020
+ }
1021
+ this.lexer.restore_position(saved);
1022
+ return null;
1023
+ }
1024
+ parse_import_supports() {
1025
+ const saved = this.lexer.save_position();
1026
+ this.next_token();
1027
+ if (this.lexer.token_type === 2) {
1028
+ if (str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end - 1, "supports")) {
1029
+ const supports_start = this.lexer.token_start;
1030
+ const name_end = this.lexer.token_end - 1;
1031
+ const content_start = this.lexer.token_end;
1032
+ const line = this.lexer.line;
1033
+ const column = this.lexer.column;
1034
+ this.scan_matching_paren();
1035
+ const content_end = this.paren_content_end;
1036
+ const supports_end = this.paren_close_end;
1037
+ const func_node = this.create_node(15, supports_start, supports_end);
1038
+ this.arena.set_content_start_delta(func_node, 0);
1039
+ this.arena.set_content_length(func_node, name_end - supports_start);
1040
+ const trimmed = trim_boundaries(this.source, content_start, content_end);
1041
+ if (trimmed) {
1042
+ const condition_start = trimmed[0];
1043
+ const condition_end = trimmed[1];
1044
+ const condition_length = condition_end - condition_start;
1045
+ this.arena.set_value_start_delta(func_node, condition_start - supports_start);
1046
+ this.arena.set_value_length(func_node, condition_length);
1047
+ const decl_child = this.condition_parser.parse_supports_declaration_content(condition_start, condition_end);
1048
+ if (decl_child === null) {
1049
+ const children = this.condition_parser.parse_supports_condition(condition_start, condition_end, line, column);
1050
+ this.arena.append_children(func_node, children);
1051
+ } else {
1052
+ const query = this.create_node(36, condition_start, condition_end);
1053
+ this.arena.set_value_start_delta(query, 0);
1054
+ this.arena.set_value_length(query, condition_length);
1055
+ this.arena.set_first_child(query, decl_child);
1056
+ this.arena.set_first_child(func_node, query);
1057
+ }
1058
+ }
1059
+ return func_node;
1060
+ }
1061
+ }
1062
+ this.lexer.restore_position(saved);
1063
+ return null;
1064
+ }
1065
+ skip_whitespace() {
1066
+ this.lexer.skip_whitespace_in_range(this.prelude_end);
1067
+ }
1068
+ peek_token_type() {
1069
+ const saved = this.lexer.save_position();
1070
+ this.next_token();
1071
+ const type = this.lexer.token_type;
1072
+ this.lexer.restore_position(saved);
1073
+ return type;
1074
+ }
1075
+ next_token() {
1076
+ if (this.lexer.pos >= this.prelude_end) {
1077
+ this.lexer.token_type = 26;
1078
+ return 26;
1079
+ }
1080
+ return this.lexer.next_token(false);
1081
+ }
1082
+ parse_namespace_prelude() {
1083
+ const nodes = [];
1084
+ this.skip_whitespace();
1085
+ if (this.lexer.pos >= this.prelude_end) return [];
1086
+ const saved = this.lexer.save_position();
1087
+ this.next_token();
1088
+ if (this.lexer.token_type === 1) {
1089
+ nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end));
1090
+ this.skip_whitespace();
1091
+ } else this.lexer.restore_position(saved);
1092
+ const url_node = this.parse_import_url();
1093
+ if (url_node !== null) nodes.push(url_node);
1094
+ return nodes;
1095
+ }
1096
+ parse_scope_prelude() {
1097
+ const nodes = [];
1098
+ while (this.lexer.pos < this.prelude_end) {
1099
+ this.skip_whitespace();
1100
+ if (this.lexer.pos >= this.prelude_end) break;
1101
+ const token_type = this.peek_token_type();
1102
+ if (token_type === 21) {
1103
+ this.next_token();
1104
+ const paren_start = this.lexer.token_start;
1105
+ const content_start = this.lexer.pos;
1106
+ const content_line = this.lexer.token_line;
1107
+ const content_column = this.lexer.token_column;
1108
+ this.scan_matching_paren();
1109
+ const content_end = this.paren_content_end;
1110
+ const paren_end = this.paren_close_end;
1111
+ const scope_node = this.create_node(41, paren_start, paren_end);
1112
+ const trimmed = trim_boundaries(this.source, content_start, content_end);
1113
+ if (trimmed) {
1114
+ this.arena.set_value_start_delta(scope_node, trimmed[0] - paren_start);
1115
+ this.arena.set_value_length(scope_node, trimmed[1] - trimmed[0]);
1116
+ let line = content_line;
1117
+ let column = content_column;
1118
+ for (let i = content_start; i < trimmed[0]; i++) if (this.source.charCodeAt(i) === 10) {
1119
+ line++;
1120
+ column = 1;
1121
+ } else column++;
1122
+ const selector_list = this.selector_parser.parse_selector(trimmed[0], trimmed[1], line, column, false);
1123
+ if (selector_list !== null) this.arena.set_first_child(scope_node, selector_list);
1124
+ }
1125
+ nodes.push(scope_node);
1126
+ } else if (token_type === 1) {
1127
+ this.next_token();
1128
+ if (str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end, "to")) nodes.push(this.create_node(38, this.lexer.token_start, this.lexer.token_end));
1129
+ } else this.next_token();
1130
+ }
1131
+ return nodes;
1132
+ }
1133
+ parse_custom_media_prelude() {
1134
+ const nodes = [];
1135
+ this.skip_whitespace();
1136
+ if (this.lexer.pos >= this.prelude_end) return [];
1137
+ this.next_token();
1138
+ if (this.lexer.token_type !== 1) return [];
1139
+ nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end), ...this.parse_media_query_list());
1140
+ return nodes;
1141
+ }
1142
+ };
1143
+ /**
1144
+ * Parse an at-rule prelude string and return an array of AST nodes
1145
+ * @param at_rule_name - The name of the at-rule (e.g., "media", "supports", "layer")
1146
+ * @param prelude - The at-rule prelude to parse (e.g., "(min-width: 768px)", "utilities")
1147
+ * @param options - Parser options (`media_feature_range_name_as_child`: also add the feature name of a media range as an Identifier child. This will become the default behavior in 0.20.0.)
1148
+ * @returns An array of CSSNode objects representing the parsed prelude
1149
+ */
1150
+ function parse_atrule_prelude(at_rule_name, prelude, options) {
1151
+ const arena = new CSSDataArena(CSSDataArena.capacity_for_source(prelude.length));
1152
+ return new AtRulePreludeParser(arena, prelude, options?.media_feature_range_name_as_child ?? false).parse_prelude(at_rule_name, 0, prelude.length).map((index) => new CSSNode(arena, prelude, index));
1153
+ }
1154
+ export { parse_atrule_prelude as n, ValueNodeParser as r, AtRulePreludeParser as t };
@@ -1,6 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-DnAc8Oy_.js";
2
- import { t as AnyNode } from "./node-types-Pa1MR4CP.js";
3
- //#region src/parse-atrule-prelude.d.ts
1
+ import { l as CSSDataArena } from "./arena-D689Bo6V.js";
2
+ import { t as AnyNode } from "./node-types-BF6bhAjo.js";
4
3
  /** @internal */
5
4
  export interface PreludeParserOptions {
6
5
  /**
@@ -51,5 +50,4 @@ export declare class AtRulePreludeParser {
51
50
  * @param options - Parser options (`media_feature_range_name_as_child`: also add the feature name of a media range as an Identifier child. This will become the default behavior in 0.20.0.)
52
51
  * @returns An array of CSSNode objects representing the parsed prelude
53
52
  */
54
- export declare function parse_atrule_prelude(at_rule_name: string, prelude: string, options?: PreludeParserOptions): AnyNode[];
55
- //#endregion
53
+ export declare function parse_atrule_prelude(at_rule_name: string, prelude: string, options?: PreludeParserOptions): AnyNode[];