@projectwallace/css-parser 0.19.2 → 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 +15 -2
  2. package/dist/{arena-CsJhQRUX.js → arena-CaLnNKbP.js} +7 -4
  3. package/dist/{arena-7RLvyGPB.d.ts → arena-D689Bo6V.d.ts} +4 -3
  4. package/dist/constants.d.ts +46 -48
  5. package/dist/constants.js +2 -3
  6. package/dist/{css-node-BKcf0ZeS.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-CD7A-d_c.d.ts → node-types-BF6bhAjo.d.ts} +56 -64
  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-B568SwUx.js → parse-atrule-prelude-BMkgCZjw.js} +465 -15
  15. package/dist/parse-atrule-prelude.d.ts +13 -6
  16. package/dist/parse-atrule-prelude.js +1 -431
  17. package/dist/parse-declaration.d.ts +4 -6
  18. package/dist/parse-declaration.js +8 -9
  19. package/dist/parse-dimension.d.ts +1 -3
  20. package/dist/parse-dimension.js +2 -3
  21. package/dist/{parse-selector-DORsuJvq.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 +4 -6
  25. package/dist/parse-value.js +6 -7
  26. package/dist/parse.d.ts +10 -5
  27. package/dist/parse.js +9 -10
  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,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-CsJhQRUX.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-DORsuJvq.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;
@@ -11,7 +12,9 @@ var ConditionParser = class {
11
12
  end = 0;
12
13
  value_node_parser;
13
14
  selector_parser;
14
- constructor(arena, source, value_node_parser) {
15
+ media_feature_range_name_as_child;
16
+ constructor(arena, source, value_node_parser, media_feature_range_name_as_child = false) {
17
+ this.media_feature_range_name_as_child = media_feature_range_name_as_child;
15
18
  this.arena = arena;
16
19
  this.source = source;
17
20
  this.lexer = new Lexer(source);
@@ -142,6 +145,14 @@ var ConditionParser = class {
142
145
  if (this.lexer.token_type === 1) {
143
146
  feature_name_start = this.lexer.token_start;
144
147
  feature_name_end = this.lexer.token_end;
148
+ if (this.media_feature_range_name_as_child) {
149
+ const name_first = this.parse_feature_value(feature_name_start, feature_name_end);
150
+ if (name_first !== 0) {
151
+ if (first_child === 0) first_child = name_first;
152
+ else this.arena.set_next_sibling(last_child, name_first);
153
+ last_child = this.arena.get_last_sibling(name_first);
154
+ }
155
+ }
145
156
  } else {
146
157
  const value_start = this.lexer.token_start;
147
158
  let value_end = this.lexer.token_end;
@@ -304,8 +315,7 @@ var ConditionParser = class {
304
315
  return nodes;
305
316
  }
306
317
  };
307
- //#endregion
308
- //#region src/value-node-parser.ts
318
+ // src/value-node-parser.ts
309
319
  var ValueNodeParser = class ValueNodeParser {
310
320
  lexer;
311
321
  arena;
@@ -314,10 +324,12 @@ var ValueNodeParser = class ValueNodeParser {
314
324
  last_chain_node = 0;
315
325
  _condition_parser = null;
316
326
  get condition_parser() {
317
- if (this._condition_parser === null) this._condition_parser = new ConditionParser(this.arena, this.source, new ValueNodeParser(this.arena, this.source));
327
+ if (this._condition_parser === null) this._condition_parser = new ConditionParser(this.arena, this.source, new ValueNodeParser(this.arena, this.source), this.media_feature_range_name_as_child);
318
328
  return this._condition_parser;
319
329
  }
320
- constructor(arena, source) {
330
+ media_feature_range_name_as_child;
331
+ constructor(arena, source, media_feature_range_name_as_child = false) {
332
+ this.media_feature_range_name_as_child = media_feature_range_name_as_child;
321
333
  this.arena = arena;
322
334
  this.source = source;
323
335
  this.lexer = new Lexer(source);
@@ -373,16 +385,25 @@ var ValueNodeParser = class ValueNodeParser {
373
385
  return null;
374
386
  }
375
387
  paren_content_end = 0;
388
+ paren_has_logical_op = false;
389
+ paren_starts_with_paren = false;
376
390
  paren_close_end = 0;
377
391
  scan_matching_paren(bounded) {
378
392
  let depth = 1;
379
393
  let content_end = this.lexer.pos;
380
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;
381
398
  while ((!bounded || this.lexer.pos < this.end) && depth > 0) {
382
399
  this.lexer.next_token(false);
383
400
  const token_type = this.lexer.token_type;
384
401
  if (token_type === 26) break;
385
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
+ }
386
407
  if (token_type === 21 || token_type === 2) depth++;
387
408
  else if (token_type === 22) {
388
409
  depth--;
@@ -390,7 +411,7 @@ var ValueNodeParser = class ValueNodeParser {
390
411
  content_end = this.lexer.token_start;
391
412
  close_end = this.lexer.token_end;
392
413
  }
393
- }
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;
394
415
  }
395
416
  this.paren_content_end = content_end;
396
417
  this.paren_close_end = close_end;
@@ -628,6 +649,7 @@ var ValueNodeParser = class ValueNodeParser {
628
649
  let content_end = content_start;
629
650
  let func_end = content_start;
630
651
  const matched = this.scan_matching_paren(true);
652
+ const is_media_condition = this.paren_starts_with_paren || this.paren_has_logical_op;
631
653
  const scanned_content_end = this.paren_content_end;
632
654
  const scanned_func_end = this.paren_close_end;
633
655
  if (matched) {
@@ -648,11 +670,18 @@ var ValueNodeParser = class ValueNodeParser {
648
670
  const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
649
671
  if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
650
672
  else child_nodes = [decl];
651
- } 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)];
652
- 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);
653
677
  this.arena.append_children(func_node, child_nodes);
654
678
  return func_node;
655
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
+ }
656
685
  parse_value_nodes_in_range(start, end) {
657
686
  const saved_end = this.end;
658
687
  const saved_pos = this.lexer.save_position();
@@ -700,5 +729,426 @@ var ValueNodeParser = class ValueNodeParser {
700
729
  return node;
701
730
  }
702
731
  };
703
- //#endregion
704
- 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,7 +1,14 @@
1
- import { l as CSSDataArena } from "./arena-7RLvyGPB.js";
2
- import { t as AnyNode } from "./node-types-CD7A-d_c.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 */
4
+ export interface PreludeParserOptions {
5
+ /**
6
+ * Defaults to `false`, but this will become the default behavior in 0.20.0.
7
+ *
8
+ * @deprecated Opt-in only as a migration aid: in 0.20.0 this behavior is always on and the option will be removed.
9
+ */
10
+ media_feature_range_name_as_child?: boolean;
11
+ }
5
12
  export declare class AtRulePreludeParser {
6
13
  private lexer;
7
14
  private arena;
@@ -10,7 +17,7 @@ export declare class AtRulePreludeParser {
10
17
  private value_node_parser;
11
18
  private condition_parser;
12
19
  private selector_parser;
13
- constructor(arena: CSSDataArena, source: string);
20
+ constructor(arena: CSSDataArena, source: string, media_feature_range_name_as_child?: boolean);
14
21
  parse_prelude(at_rule_name: string, start: number, end: number, line?: number, column?: number): number[];
15
22
  private parse_prelude_dispatch;
16
23
  private parse_media_query_list;
@@ -40,7 +47,7 @@ export declare class AtRulePreludeParser {
40
47
  * Parse an at-rule prelude string and return an array of AST nodes
41
48
  * @param at_rule_name - The name of the at-rule (e.g., "media", "supports", "layer")
42
49
  * @param prelude - The at-rule prelude to parse (e.g., "(min-width: 768px)", "utilities")
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.)
43
51
  * @returns An array of CSSNode objects representing the parsed prelude
44
52
  */
45
- export declare function parse_atrule_prelude(at_rule_name: string, prelude: string): AnyNode[];
46
- //#endregion
53
+ export declare function parse_atrule_prelude(at_rule_name: string, prelude: string, options?: PreludeParserOptions): AnyNode[];