@rohal12/spindle 0.64.9 → 0.64.11

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.
@@ -9,51 +9,19 @@ var __exportAll = (all, no_symbols) => {
9
9
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
10
  return target;
11
11
  };
12
- // src/utils/macro-names.ts
13
- /**
14
- * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
15
- * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
16
- * name.
17
- */
18
- var NameMap = class extends Map {
19
- get(name) {
20
- return super.get(name.toLowerCase());
21
- }
22
- set(name, value) {
23
- return super.set(name.toLowerCase(), value);
24
- }
25
- has(name) {
26
- return super.has(name.toLowerCase());
27
- }
28
- delete(name) {
29
- return super.delete(name.toLowerCase());
30
- }
31
- };
32
- /** The latest definition of each name, using runtime replacement precedence. */
33
- function effectiveNamedDefinitions(definitions) {
34
- const latest = new NameMap();
35
- for (const definition of definitions) latest.set(definition.name, definition);
36
- return [...latest.values()];
37
- }
38
- /** A set of macro or widget names (see NameMap). */
39
- var NameSet = class {
40
- constructor(names = []) {
41
- this.names = new NameMap();
42
- for (const name of names) this.add(name);
43
- }
44
- add(name) {
45
- this.names.set(name, true);
46
- }
47
- has(name) {
48
- return this.names.has(name);
49
- }
50
- delete(name) {
51
- this.names.delete(name);
52
- }
53
- clear() {
54
- this.names.clear();
55
- }
56
- };
12
+ /** Text-only bodies recognize their own end tag, never nested HTML tags. */
13
+ var HTML_TEXT_ELEMENTS$1 = /* @__PURE__ */ new Set([
14
+ .../* @__PURE__ */ new Set([
15
+ "script",
16
+ "style",
17
+ "xmp",
18
+ "iframe",
19
+ "noembed",
20
+ "noframes"
21
+ ]),
22
+ "textarea",
23
+ "title"
24
+ ]);
57
25
  // src/markup/tokens.ts
58
26
  /** Variable sigils: story ($), temporary (_), local (@), transient (%). */
59
27
  var SIGIL_SCOPES = {
@@ -82,12 +50,13 @@ function withSelectors$1(target, from) {
82
50
  */
83
51
  var grammar_shared_default = {
84
52
  SIGIL_SCOPES,
85
- withSelectors: withSelectors$1
53
+ withSelectors: withSelectors$1,
54
+ HTML_TEXT_ELEMENTS: HTML_TEXT_ELEMENTS$1
86
55
  };
87
56
  // src/markup/spindle.peggy
88
57
  var LB = String.fromCharCode(123);
89
58
  var RB = String.fromCharCode(125);
90
- var { SIGIL_SCOPES: SIGIL_SCOPES$1, withSelectors } = grammar_shared_default;
59
+ var { SIGIL_SCOPES: SIGIL_SCOPES$1, withSelectors, HTML_TEXT_ELEMENTS } = grammar_shared_default;
91
60
  var VOID_TAGS = /* @__PURE__ */ new Set([
92
61
  "area",
93
62
  "base",
@@ -629,82 +598,96 @@ function peg$parse(input, options) {
629
598
  return joinText(items);
630
599
  }
631
600
  function peg$f1() {
632
- return !textMode;
601
+ return !htmlTextTag;
633
602
  }
634
603
  function peg$f2() {
635
- return !textMode;
604
+ return !htmlTextTag;
636
605
  }
637
- function peg$f3(tag) {
638
- return tag;
606
+ function peg$f3() {
607
+ return !htmlTextTag;
639
608
  }
640
609
  function peg$f4() {
610
+ return !textMode && !htmlTextTag;
611
+ }
612
+ function peg$f5() {
613
+ return !textMode && !htmlTextTag;
614
+ }
615
+ function peg$f6(tag) {
616
+ if (!tag.isSelfClose && HTML_TEXT_ELEMENTS.has(tag.lower)) htmlTextTag = tag.lower;
617
+ return tag;
618
+ }
619
+ function peg$f7() {
641
620
  return !textMode;
642
621
  }
643
- function peg$f5(tag) {
622
+ function peg$f8(tag) {
623
+ return !htmlTextTag || tag.lower === htmlTextTag;
624
+ }
625
+ function peg$f9(tag) {
626
+ htmlTextTag = "";
644
627
  return VOID_TAGS.has(tag.lower) ? null : tag;
645
628
  }
646
- function peg$f6(tag) {
629
+ function peg$f10(tag) {
647
630
  rawName = tag.lower;
648
631
  return tag.kind === "open" && hooks.isRaw(rawName);
649
632
  }
650
- function peg$f7(tag, b) {
633
+ function peg$f11(tag, b) {
651
634
  return b;
652
635
  }
653
- function peg$f8(tag, body) {
636
+ function peg$f12(tag, body) {
654
637
  return body ? [tag, body] : tag;
655
638
  }
656
- function peg$f9(tag) {
639
+ function peg$f13(tag) {
657
640
  return tag.kind === "close";
658
641
  }
659
- function peg$f10(tag) {
642
+ function peg$f14(tag) {
660
643
  return tag;
661
644
  }
662
- function peg$f11() {
645
+ function peg$f15() {
663
646
  return !textMode;
664
647
  }
665
- function peg$f12(tag) {
648
+ function peg$f16(tag) {
666
649
  return tag;
667
650
  }
668
- function peg$f13(start) {
651
+ function peg$f17(start) {
669
652
  return skipTo(hooks.rawBodyEnd(input, start, rawName));
670
653
  }
671
- function peg$f14(start) {
654
+ function peg$f18(start) {
672
655
  return skipEnd - offset();
673
656
  }
674
- function peg$f15(start, body, end) {
657
+ function peg$f19(start, body, end) {
675
658
  const loc = {
676
659
  start: { offset: start },
677
660
  end: { offset: start + body.length }
678
661
  };
679
662
  return [body ? lexeme("text", loc, { value: body }) : null, end];
680
663
  }
681
- function peg$f16() {
664
+ function peg$f20() {
682
665
  return completionMode;
683
666
  }
684
- function peg$f17(body) {
667
+ function peg$f21(body) {
685
668
  return lexeme("text", location(), { value: body });
686
669
  }
687
- function peg$f18() {
670
+ function peg$f22() {
688
671
  return offset();
689
672
  }
690
- function peg$f19(value) {
673
+ function peg$f23(value) {
691
674
  return lexeme("text", location(), { value });
692
675
  }
693
- function peg$f20() {
676
+ function peg$f24() {
694
677
  return completionMode || offset() <= lastCommentClose;
695
678
  }
696
- function peg$f21(value) {
679
+ function peg$f25(value) {
697
680
  const node = lexeme("text", location(), { value });
698
681
  node.comment = true;
699
682
  return node;
700
683
  }
701
- function peg$f22(bs) {
684
+ function peg$f26(bs) {
702
685
  return bs.length % 2 === 1;
703
686
  }
704
- function peg$f23(bs, c) {
687
+ function peg$f27(bs, c) {
705
688
  return c;
706
689
  }
707
- function peg$f24(bs, brace) {
690
+ function peg$f28(bs, brace) {
708
691
  const loc = location();
709
692
  const next = input.charAt(loc.end.offset);
710
693
  if (textMode) {
@@ -721,48 +704,48 @@ function peg$parse(input, options) {
721
704
  escaped.escape = true;
722
705
  return bs.length > 1 ? [before, escaped] : escaped;
723
706
  }
724
- function peg$f25() {
707
+ function peg$f29() {
725
708
  return lexeme("text", location(), { value: LB });
726
709
  }
727
- function peg$f26() {
728
- return !textMode;
710
+ function peg$f30() {
711
+ return !textMode && !htmlTextTag;
729
712
  }
730
- function peg$f27() {
713
+ function peg$f31() {
731
714
  return lexeme("text", location(), { value: "<" });
732
715
  }
733
- function peg$f28() {
716
+ function peg$f32() {
734
717
  return lexeme("text", location(), { value: "[" });
735
718
  }
736
- function peg$f29() {
719
+ function peg$f33() {
737
720
  return !textMode;
738
721
  }
739
- function peg$f30(ss, s, at, inner) {
722
+ function peg$f34(ss, s, at, inner) {
740
723
  const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
741
724
  link.selectorSpan = selectorSpan(s, ss, at);
742
725
  return withSelectors(link, s);
743
726
  }
744
- function peg$f31() {
727
+ function peg$f35() {
745
728
  return !textMode;
746
729
  }
747
- function peg$f32() {
730
+ function peg$f36() {
748
731
  fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
749
732
  }
750
- function peg$f33(parts) {
733
+ function peg$f37(parts) {
751
734
  return selectorsOf(parts);
752
735
  }
753
- function peg$f34() {
736
+ function peg$f38() {
754
737
  return NO_SELECTORS;
755
738
  }
756
- function peg$f35(s, end) {
739
+ function peg$f39(s, end) {
757
740
  return {
758
741
  ...s,
759
742
  end
760
743
  };
761
744
  }
762
- function peg$f36(prefix, name) {
745
+ function peg$f40(prefix, name) {
763
746
  return [prefix, name];
764
747
  }
765
- function peg$f37(ss, s, sigil, nameStart, name) {
748
+ function peg$f41(ss, s, sigil, nameStart, name) {
766
749
  const variable = lexeme("variable", location(), {
767
750
  name,
768
751
  nameStart,
@@ -772,7 +755,7 @@ function peg$parse(input, options) {
772
755
  variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
773
756
  return withSelectors(variable, s);
774
757
  }
775
- function peg$f38(ss, s, after, expression) {
758
+ function peg$f42(ss, s, after, expression) {
776
759
  const node = lexeme("expression", location(), {
777
760
  expression,
778
761
  expressionStart: after,
@@ -781,33 +764,33 @@ function peg$parse(input, options) {
781
764
  node.selectorSpan = selectorSpan(s, ss, after);
782
765
  return withSelectors(node, s);
783
766
  }
784
- function peg$f39() {
767
+ function peg$f43() {
785
768
  fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
786
769
  }
787
- function peg$f40(start) {
770
+ function peg$f44(start) {
788
771
  const end = hooks.closeBrace(input, start, start);
789
772
  return skipTo(end < 0 && completionMode ? input.length : end);
790
773
  }
791
- function peg$f41(start) {
774
+ function peg$f45(start) {
792
775
  return skipEnd - offset();
793
776
  }
794
- function peg$f42(start, code) {
777
+ function peg$f46(start, code) {
795
778
  return code;
796
779
  }
797
- function peg$f43() {
780
+ function peg$f47() {
798
781
  return completionMode;
799
782
  }
800
- function peg$f44(ss, s, start, close, name, nameEnd) {
783
+ function peg$f48(ss, s, start, close, name, nameEnd) {
801
784
  const end = hooks.closeBrace(input, nameEnd, start);
802
785
  return skipTo(end < 0 && completionMode ? input.length : end);
803
786
  }
804
- function peg$f45(ss, s, start, close, name, nameEnd) {
787
+ function peg$f49(ss, s, start, close, name, nameEnd) {
805
788
  return skipEnd - offset();
806
789
  }
807
- function peg$f46(ss, s, start, close, name, nameEnd, args) {
790
+ function peg$f50(ss, s, start, close, name, nameEnd, args) {
808
791
  return args;
809
792
  }
810
- function peg$f47(ss, s, start, close, name, nameEnd, tail) {
793
+ function peg$f51(ss, s, start, close, name, nameEnd, tail) {
811
794
  const loc = location();
812
795
  const lower = name.toLowerCase();
813
796
  const tag = lexeme("macro", loc, {
@@ -833,19 +816,19 @@ function peg$parse(input, options) {
833
816
  }
834
817
  return tag;
835
818
  }
836
- function peg$f48(s) {
819
+ function peg$f52(s) {
837
820
  fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
838
821
  }
839
- function peg$f49(value) {
822
+ function peg$f53(value) {
840
823
  return EMAIL_AUTOLINK.test(value);
841
824
  }
842
- function peg$f50(value) {
825
+ function peg$f54(value) {
843
826
  return lexeme("text", location(), { value });
844
827
  }
845
- function peg$f51(value) {
828
+ function peg$f55(value) {
846
829
  return lexeme("text", location(), { value });
847
830
  }
848
- function peg$f52(tagStart, tag, list, slash) {
831
+ function peg$f56(tagStart, tag, list, slash) {
849
832
  const lower = tag.toLowerCase();
850
833
  return lexeme("html", location(), {
851
834
  tag,
@@ -858,7 +841,7 @@ function peg$parse(input, options) {
858
841
  isSelfClose: !!slash || VOID_TAGS.has(lower)
859
842
  });
860
843
  }
861
- function peg$f53(tag, bad) {
844
+ function peg$f57(tag, bad) {
862
845
  const c = input.charAt(bad);
863
846
  if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
864
847
  const at = {
@@ -876,7 +859,7 @@ function peg$parse(input, options) {
876
859
  };
877
860
  fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
878
861
  }
879
- function peg$f54(tagStart, tag) {
862
+ function peg$f58(tagStart, tag) {
880
863
  return lexeme("html", location(), {
881
864
  tag,
882
865
  lower: tag.toLowerCase(),
@@ -888,14 +871,14 @@ function peg$parse(input, options) {
888
871
  isSelfClose: false
889
872
  });
890
873
  }
891
- function peg$f55(nameStart, name) {
874
+ function peg$f59(nameStart, name) {
892
875
  attrCode = hooks.isCodeAttribute(name);
893
876
  return true;
894
877
  }
895
- function peg$f56(nameStart, name, v) {
878
+ function peg$f60(nameStart, name, v) {
896
879
  return v;
897
880
  }
898
- function peg$f57(nameStart, name, value) {
881
+ function peg$f61(nameStart, name, value) {
899
882
  const attribute = {
900
883
  name,
901
884
  value: value ? value.value : "",
@@ -909,7 +892,7 @@ function peg$parse(input, options) {
909
892
  }
910
893
  return attribute;
911
894
  }
912
- function peg$f58(start, value, end) {
895
+ function peg$f62(start, value, end) {
913
896
  return {
914
897
  value,
915
898
  start,
@@ -917,7 +900,7 @@ function peg$parse(input, options) {
917
900
  quote: "\""
918
901
  };
919
902
  }
920
- function peg$f59(start, value, end) {
903
+ function peg$f63(start, value, end) {
921
904
  return {
922
905
  value,
923
906
  start,
@@ -925,36 +908,36 @@ function peg$parse(input, options) {
925
908
  quote: "'"
926
909
  };
927
910
  }
928
- function peg$f60(q) {
911
+ function peg$f64(q) {
929
912
  fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
930
913
  }
931
- function peg$f61(start, value, end) {
914
+ function peg$f65(start, value, end) {
932
915
  return {
933
916
  value,
934
917
  start,
935
918
  end
936
919
  };
937
920
  }
938
- function peg$f62() {
921
+ function peg$f66() {
939
922
  return !attrCode;
940
923
  }
941
- function peg$f63(bs) {
924
+ function peg$f67(bs) {
942
925
  return bs.length % 2 === 1;
943
926
  }
944
- function peg$f64() {
927
+ function peg$f68() {
945
928
  return !attrCode;
946
929
  }
947
- function peg$f65(start, nameEnd) {
930
+ function peg$f69(start, nameEnd) {
948
931
  const end = hooks.closeBrace(input, nameEnd, start);
949
932
  return skipTo(end < 0 && completionMode ? input.length : end);
950
933
  }
951
- function peg$f66(start, nameEnd) {
934
+ function peg$f70(start, nameEnd) {
952
935
  return skipEnd - offset();
953
936
  }
954
- function peg$f67() {
937
+ function peg$f71() {
955
938
  return !attrCode;
956
939
  }
957
- function peg$f68() {
940
+ function peg$f72() {
958
941
  return attrCode;
959
942
  }
960
943
  let peg$currPos = options.peg$currPos | 0;
@@ -1090,15 +1073,66 @@ function peg$parse(input, options) {
1090
1073
  if (s0 === peg$FAILED) {
1091
1074
  s0 = peg$parseEscape();
1092
1075
  if (s0 === peg$FAILED) {
1093
- s0 = peg$parseComment();
1076
+ s0 = peg$currPos;
1077
+ peg$savedPos = peg$currPos;
1078
+ s1 = peg$f1();
1079
+ if (s1) s1 = void 0;
1080
+ else s1 = peg$FAILED;
1081
+ if (s1 !== peg$FAILED) {
1082
+ s2 = peg$parseComment();
1083
+ if (s2 !== peg$FAILED) {
1084
+ s1 = [s1, s2];
1085
+ s0 = s1;
1086
+ } else {
1087
+ peg$currPos = s0;
1088
+ s0 = peg$FAILED;
1089
+ }
1090
+ } else {
1091
+ peg$currPos = s0;
1092
+ s0 = peg$FAILED;
1093
+ }
1094
1094
  if (s0 === peg$FAILED) {
1095
- s0 = peg$parseLinkLexeme();
1095
+ s0 = peg$currPos;
1096
+ peg$savedPos = peg$currPos;
1097
+ s1 = peg$f2();
1098
+ if (s1) s1 = void 0;
1099
+ else s1 = peg$FAILED;
1100
+ if (s1 !== peg$FAILED) {
1101
+ s2 = peg$parseLinkLexeme();
1102
+ if (s2 !== peg$FAILED) {
1103
+ s1 = [s1, s2];
1104
+ s0 = s1;
1105
+ } else {
1106
+ peg$currPos = s0;
1107
+ s0 = peg$FAILED;
1108
+ }
1109
+ } else {
1110
+ peg$currPos = s0;
1111
+ s0 = peg$FAILED;
1112
+ }
1096
1113
  if (s0 === peg$FAILED) {
1097
- s0 = peg$parseEmailAutolink();
1114
+ s0 = peg$currPos;
1115
+ peg$savedPos = peg$currPos;
1116
+ s1 = peg$f3();
1117
+ if (s1) s1 = void 0;
1118
+ else s1 = peg$FAILED;
1119
+ if (s1 !== peg$FAILED) {
1120
+ s2 = peg$parseEmailAutolink();
1121
+ if (s2 !== peg$FAILED) {
1122
+ s1 = [s1, s2];
1123
+ s0 = s1;
1124
+ } else {
1125
+ peg$currPos = s0;
1126
+ s0 = peg$FAILED;
1127
+ }
1128
+ } else {
1129
+ peg$currPos = s0;
1130
+ s0 = peg$FAILED;
1131
+ }
1098
1132
  if (s0 === peg$FAILED) {
1099
1133
  s0 = peg$currPos;
1100
1134
  peg$savedPos = peg$currPos;
1101
- s1 = peg$f1();
1135
+ s1 = peg$f4();
1102
1136
  if (s1) s1 = void 0;
1103
1137
  else s1 = peg$FAILED;
1104
1138
  if (s1 !== peg$FAILED) {
@@ -1117,14 +1151,14 @@ function peg$parse(input, options) {
1117
1151
  if (s0 === peg$FAILED) {
1118
1152
  s0 = peg$currPos;
1119
1153
  peg$savedPos = peg$currPos;
1120
- s1 = peg$f2();
1154
+ s1 = peg$f5();
1121
1155
  if (s1) s1 = void 0;
1122
1156
  else s1 = peg$FAILED;
1123
1157
  if (s1 !== peg$FAILED) {
1124
1158
  s2 = peg$parseHtmlOpen();
1125
1159
  if (s2 !== peg$FAILED) {
1126
1160
  peg$savedPos = s0;
1127
- s0 = peg$f3(s2);
1161
+ s0 = peg$f6(s2);
1128
1162
  } else {
1129
1163
  peg$currPos = s0;
1130
1164
  s0 = peg$FAILED;
@@ -1136,14 +1170,23 @@ function peg$parse(input, options) {
1136
1170
  if (s0 === peg$FAILED) {
1137
1171
  s0 = peg$currPos;
1138
1172
  peg$savedPos = peg$currPos;
1139
- s1 = peg$f4();
1173
+ s1 = peg$f7();
1140
1174
  if (s1) s1 = void 0;
1141
1175
  else s1 = peg$FAILED;
1142
1176
  if (s1 !== peg$FAILED) {
1143
1177
  s2 = peg$parseHtmlClose();
1144
1178
  if (s2 !== peg$FAILED) {
1145
- peg$savedPos = s0;
1146
- s0 = peg$f5(s2);
1179
+ peg$savedPos = peg$currPos;
1180
+ s3 = peg$f8(s2);
1181
+ if (s3) s3 = void 0;
1182
+ else s3 = peg$FAILED;
1183
+ if (s3 !== peg$FAILED) {
1184
+ peg$savedPos = s0;
1185
+ s0 = peg$f9(s2);
1186
+ } else {
1187
+ peg$currPos = s0;
1188
+ s0 = peg$FAILED;
1189
+ }
1147
1190
  } else {
1148
1191
  peg$currPos = s0;
1149
1192
  s0 = peg$FAILED;
@@ -1160,14 +1203,14 @@ function peg$parse(input, options) {
1160
1203
  if (s1 !== peg$FAILED) {
1161
1204
  s2 = peg$currPos;
1162
1205
  peg$savedPos = peg$currPos;
1163
- s3 = peg$f6(s1);
1206
+ s3 = peg$f10(s1);
1164
1207
  if (s3) s3 = void 0;
1165
1208
  else s3 = peg$FAILED;
1166
1209
  if (s3 !== peg$FAILED) {
1167
1210
  s4 = peg$parseRawTokens();
1168
1211
  if (s4 !== peg$FAILED) {
1169
1212
  peg$savedPos = s2;
1170
- s2 = peg$f7(s1, s4);
1213
+ s2 = peg$f11(s1, s4);
1171
1214
  } else {
1172
1215
  peg$currPos = s2;
1173
1216
  s2 = peg$FAILED;
@@ -1178,7 +1221,7 @@ function peg$parse(input, options) {
1178
1221
  }
1179
1222
  if (s2 === peg$FAILED) s2 = null;
1180
1223
  peg$savedPos = s0;
1181
- s0 = peg$f8(s1, s2);
1224
+ s0 = peg$f12(s1, s2);
1182
1225
  } else {
1183
1226
  peg$currPos = s0;
1184
1227
  s0 = peg$FAILED;
@@ -1201,12 +1244,12 @@ function peg$parse(input, options) {
1201
1244
  s1 = peg$parseMacroTag();
1202
1245
  if (s1 !== peg$FAILED) {
1203
1246
  peg$savedPos = peg$currPos;
1204
- s2 = peg$f9(s1);
1247
+ s2 = peg$f13(s1);
1205
1248
  if (s2) s2 = void 0;
1206
1249
  else s2 = peg$FAILED;
1207
1250
  if (s2 !== peg$FAILED) {
1208
1251
  peg$savedPos = s0;
1209
- s0 = peg$f10(s1);
1252
+ s0 = peg$f14(s1);
1210
1253
  } else {
1211
1254
  peg$currPos = s0;
1212
1255
  s0 = peg$FAILED;
@@ -1218,14 +1261,14 @@ function peg$parse(input, options) {
1218
1261
  if (s0 === peg$FAILED) {
1219
1262
  s0 = peg$currPos;
1220
1263
  peg$savedPos = peg$currPos;
1221
- s1 = peg$f11();
1264
+ s1 = peg$f15();
1222
1265
  if (s1) s1 = void 0;
1223
1266
  else s1 = peg$FAILED;
1224
1267
  if (s1 !== peg$FAILED) {
1225
1268
  s2 = peg$parseHtmlClose();
1226
1269
  if (s2 !== peg$FAILED) {
1227
1270
  peg$savedPos = s0;
1228
- s0 = peg$f12(s2);
1271
+ s0 = peg$f16(s2);
1229
1272
  } else {
1230
1273
  peg$currPos = s0;
1231
1274
  s0 = peg$FAILED;
@@ -1242,12 +1285,12 @@ function peg$parse(input, options) {
1242
1285
  s0 = peg$currPos;
1243
1286
  s1 = peg$parseHere();
1244
1287
  peg$savedPos = peg$currPos;
1245
- s2 = peg$f13(s1);
1288
+ s2 = peg$f17(s1);
1246
1289
  if (s2) s2 = void 0;
1247
1290
  else s2 = peg$FAILED;
1248
1291
  if (s2 !== peg$FAILED) {
1249
1292
  s3 = peg$currPos;
1250
- s4 = peg$f14(s1);
1293
+ s4 = peg$f18(s1);
1251
1294
  s5 = peg$currPos;
1252
1295
  s6 = [];
1253
1296
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -1280,7 +1323,7 @@ function peg$parse(input, options) {
1280
1323
  s4 = peg$parseCloseTag();
1281
1324
  if (s4 !== peg$FAILED) {
1282
1325
  peg$savedPos = s0;
1283
- s0 = peg$f15(s1, s3, s4);
1326
+ s0 = peg$f19(s1, s3, s4);
1284
1327
  } else {
1285
1328
  peg$currPos = s0;
1286
1329
  s0 = peg$FAILED;
@@ -1296,7 +1339,7 @@ function peg$parse(input, options) {
1296
1339
  if (s0 === peg$FAILED) {
1297
1340
  s0 = peg$currPos;
1298
1341
  peg$savedPos = peg$currPos;
1299
- s1 = peg$f16();
1342
+ s1 = peg$f20();
1300
1343
  if (s1) s1 = void 0;
1301
1344
  else s1 = peg$FAILED;
1302
1345
  if (s1 !== peg$FAILED) {
@@ -1321,7 +1364,7 @@ function peg$parse(input, options) {
1321
1364
  }
1322
1365
  s2 = input.substring(s2, peg$currPos);
1323
1366
  peg$savedPos = s0;
1324
- s0 = peg$f17(s2);
1367
+ s0 = peg$f21(s2);
1325
1368
  } else {
1326
1369
  peg$currPos = s0;
1327
1370
  s0 = peg$FAILED;
@@ -1334,7 +1377,7 @@ function peg$parse(input, options) {
1334
1377
  s0 = peg$currPos;
1335
1378
  s1 = "";
1336
1379
  peg$savedPos = s0;
1337
- s1 = peg$f18();
1380
+ s1 = peg$f22();
1338
1381
  s0 = s1;
1339
1382
  return s0;
1340
1383
  }
@@ -1363,7 +1406,7 @@ function peg$parse(input, options) {
1363
1406
  else s1 = s2;
1364
1407
  if (s1 !== peg$FAILED) {
1365
1408
  peg$savedPos = s0;
1366
- s1 = peg$f19(s1);
1409
+ s1 = peg$f23(s1);
1367
1410
  }
1368
1411
  s0 = s1;
1369
1412
  return s0;
@@ -1399,7 +1442,7 @@ function peg$parse(input, options) {
1399
1442
  if (s4 === peg$FAILED) {
1400
1443
  s4 = peg$currPos;
1401
1444
  peg$savedPos = peg$currPos;
1402
- s5 = peg$f20();
1445
+ s5 = peg$f24();
1403
1446
  if (s5) s5 = void 0;
1404
1447
  else s5 = peg$FAILED;
1405
1448
  if (s5 !== peg$FAILED) {
@@ -1517,7 +1560,7 @@ function peg$parse(input, options) {
1517
1560
  else s1 = s2;
1518
1561
  if (s1 !== peg$FAILED) {
1519
1562
  peg$savedPos = s0;
1520
- s1 = peg$f21(s1);
1563
+ s1 = peg$f25(s1);
1521
1564
  }
1522
1565
  s0 = s1;
1523
1566
  return s0;
@@ -1550,7 +1593,7 @@ function peg$parse(input, options) {
1550
1593
  if (s1 !== peg$FAILED) {
1551
1594
  s2 = peg$currPos;
1552
1595
  peg$savedPos = peg$currPos;
1553
- s3 = peg$f22(s1);
1596
+ s3 = peg$f26(s1);
1554
1597
  if (s3) s3 = void 0;
1555
1598
  else s3 = peg$FAILED;
1556
1599
  if (s3 !== peg$FAILED) {
@@ -1562,7 +1605,7 @@ function peg$parse(input, options) {
1562
1605
  }
1563
1606
  if (s4 !== peg$FAILED) {
1564
1607
  peg$savedPos = s2;
1565
- s2 = peg$f23(s1, s4);
1608
+ s2 = peg$f27(s1, s4);
1566
1609
  } else {
1567
1610
  peg$currPos = s2;
1568
1611
  s2 = peg$FAILED;
@@ -1573,7 +1616,7 @@ function peg$parse(input, options) {
1573
1616
  }
1574
1617
  if (s2 === peg$FAILED) s2 = null;
1575
1618
  peg$savedPos = s0;
1576
- s0 = peg$f24(s1, s2);
1619
+ s0 = peg$f28(s1, s2);
1577
1620
  } else {
1578
1621
  peg$currPos = s0;
1579
1622
  s0 = peg$FAILED;
@@ -1621,7 +1664,7 @@ function peg$parse(input, options) {
1621
1664
  }
1622
1665
  if (s2 !== peg$FAILED) {
1623
1666
  peg$savedPos = s0;
1624
- s0 = peg$f25();
1667
+ s0 = peg$f29();
1625
1668
  } else {
1626
1669
  peg$currPos = s0;
1627
1670
  s0 = peg$FAILED;
@@ -1636,7 +1679,7 @@ function peg$parse(input, options) {
1636
1679
  peg$silentFails++;
1637
1680
  s2 = peg$currPos;
1638
1681
  peg$savedPos = peg$currPos;
1639
- s3 = peg$f26();
1682
+ s3 = peg$f30();
1640
1683
  if (s3) s3 = void 0;
1641
1684
  else s3 = peg$FAILED;
1642
1685
  if (s3 !== peg$FAILED) {
@@ -1668,7 +1711,7 @@ function peg$parse(input, options) {
1668
1711
  }
1669
1712
  if (s2 !== peg$FAILED) {
1670
1713
  peg$savedPos = s0;
1671
- s0 = peg$f27();
1714
+ s0 = peg$f31();
1672
1715
  } else {
1673
1716
  peg$currPos = s0;
1674
1717
  s0 = peg$FAILED;
@@ -1688,7 +1731,7 @@ function peg$parse(input, options) {
1688
1731
  }
1689
1732
  if (s1 !== peg$FAILED) {
1690
1733
  peg$savedPos = s0;
1691
- s1 = peg$f28();
1734
+ s1 = peg$f32();
1692
1735
  }
1693
1736
  s0 = s1;
1694
1737
  }
@@ -1699,7 +1742,7 @@ function peg$parse(input, options) {
1699
1742
  let s0, s1, s2, s3, s4, s5, s6, s7;
1700
1743
  s0 = peg$currPos;
1701
1744
  peg$savedPos = peg$currPos;
1702
- s1 = peg$f29();
1745
+ s1 = peg$f33();
1703
1746
  if (s1) s1 = void 0;
1704
1747
  else s1 = peg$FAILED;
1705
1748
  if (s1 !== peg$FAILED) {
@@ -1728,7 +1771,7 @@ function peg$parse(input, options) {
1728
1771
  if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
1729
1772
  if (s7 !== peg$FAILED) {
1730
1773
  peg$savedPos = s0;
1731
- s0 = peg$f30(s3, s4, s5, s6);
1774
+ s0 = peg$f34(s3, s4, s5, s6);
1732
1775
  } else {
1733
1776
  peg$currPos = s0;
1734
1777
  s0 = peg$FAILED;
@@ -1748,7 +1791,7 @@ function peg$parse(input, options) {
1748
1791
  if (s0 === peg$FAILED) {
1749
1792
  s0 = peg$currPos;
1750
1793
  peg$savedPos = peg$currPos;
1751
- s1 = peg$f31();
1794
+ s1 = peg$f35();
1752
1795
  if (s1) s1 = void 0;
1753
1796
  else s1 = peg$FAILED;
1754
1797
  if (s1 !== peg$FAILED) {
@@ -1761,7 +1804,7 @@ function peg$parse(input, options) {
1761
1804
  }
1762
1805
  if (s2 !== peg$FAILED) {
1763
1806
  peg$savedPos = s0;
1764
- s0 = peg$f32();
1807
+ s0 = peg$f36();
1765
1808
  } else {
1766
1809
  peg$currPos = s0;
1767
1810
  s0 = peg$FAILED;
@@ -1889,7 +1932,7 @@ function peg$parse(input, options) {
1889
1932
  }
1890
1933
  if (s2 === peg$FAILED) s2 = null;
1891
1934
  peg$savedPos = s0;
1892
- s0 = peg$f33(s1);
1935
+ s0 = peg$f37(s1);
1893
1936
  } else {
1894
1937
  peg$currPos = s0;
1895
1938
  s0 = peg$FAILED;
@@ -1898,7 +1941,7 @@ function peg$parse(input, options) {
1898
1941
  s0 = peg$currPos;
1899
1942
  s1 = "";
1900
1943
  peg$savedPos = s0;
1901
- s1 = peg$f34();
1944
+ s1 = peg$f38();
1902
1945
  s0 = s1;
1903
1946
  }
1904
1947
  return s0;
@@ -1928,7 +1971,7 @@ function peg$parse(input, options) {
1928
1971
  }
1929
1972
  }
1930
1973
  peg$savedPos = s0;
1931
- s0 = peg$f35(s1, s2);
1974
+ s0 = peg$f39(s1, s2);
1932
1975
  } else {
1933
1976
  peg$currPos = s0;
1934
1977
  s0 = peg$FAILED;
@@ -1954,7 +1997,7 @@ function peg$parse(input, options) {
1954
1997
  }
1955
1998
  s2 = input.substring(s2, peg$currPos);
1956
1999
  peg$savedPos = s0;
1957
- s0 = peg$f36(s1, s2);
2000
+ s0 = peg$f40(s1, s2);
1958
2001
  } else {
1959
2002
  peg$currPos = s0;
1960
2003
  s0 = peg$FAILED;
@@ -2075,7 +2118,7 @@ function peg$parse(input, options) {
2075
2118
  s7 = peg$parseBraceEnd();
2076
2119
  if (s7 !== peg$FAILED) {
2077
2120
  peg$savedPos = s0;
2078
- s0 = peg$f37(s2, s3, s4, s5, s6);
2121
+ s0 = peg$f41(s2, s3, s4, s5, s6);
2079
2122
  } else {
2080
2123
  peg$currPos = s0;
2081
2124
  s0 = peg$FAILED;
@@ -2125,7 +2168,7 @@ function peg$parse(input, options) {
2125
2168
  s7 = peg$parseBraceEnd();
2126
2169
  if (s7 !== peg$FAILED) {
2127
2170
  peg$savedPos = s0;
2128
- s0 = peg$f38(s2, s3, s4, s6);
2171
+ s0 = peg$f42(s2, s3, s4, s6);
2129
2172
  } else {
2130
2173
  peg$currPos = s0;
2131
2174
  s0 = peg$FAILED;
@@ -2173,7 +2216,7 @@ function peg$parse(input, options) {
2173
2216
  } else s3 = peg$FAILED;
2174
2217
  if (s3 !== peg$FAILED) {
2175
2218
  peg$savedPos = s0;
2176
- s0 = peg$f39();
2219
+ s0 = peg$f43();
2177
2220
  } else {
2178
2221
  peg$currPos = s0;
2179
2222
  s0 = peg$FAILED;
@@ -2195,12 +2238,12 @@ function peg$parse(input, options) {
2195
2238
  s0 = peg$currPos;
2196
2239
  s1 = peg$parseHere();
2197
2240
  peg$savedPos = peg$currPos;
2198
- s2 = peg$f40(s1);
2241
+ s2 = peg$f44(s1);
2199
2242
  if (s2) s2 = void 0;
2200
2243
  else s2 = peg$FAILED;
2201
2244
  if (s2 !== peg$FAILED) {
2202
2245
  s3 = peg$currPos;
2203
- s4 = peg$f41(s1);
2246
+ s4 = peg$f45(s1);
2204
2247
  s5 = peg$currPos;
2205
2248
  s6 = [];
2206
2249
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2231,7 +2274,7 @@ function peg$parse(input, options) {
2231
2274
  else s3 = s4;
2232
2275
  if (s3 !== peg$FAILED) {
2233
2276
  peg$savedPos = s0;
2234
- s0 = peg$f42(s1, s3);
2277
+ s0 = peg$f46(s1, s3);
2235
2278
  } else {
2236
2279
  peg$currPos = s0;
2237
2280
  s0 = peg$FAILED;
@@ -2246,7 +2289,7 @@ function peg$parse(input, options) {
2246
2289
  let s0, s1, s2, s3;
2247
2290
  s0 = peg$currPos;
2248
2291
  peg$savedPos = peg$currPos;
2249
- s1 = peg$f43();
2292
+ s1 = peg$f47();
2250
2293
  if (s1) s1 = void 0;
2251
2294
  else s1 = peg$FAILED;
2252
2295
  if (s1 !== peg$FAILED) {
@@ -2318,12 +2361,12 @@ function peg$parse(input, options) {
2318
2361
  s7 = peg$parseHere();
2319
2362
  s8 = peg$currPos;
2320
2363
  peg$savedPos = peg$currPos;
2321
- s9 = peg$f44(s2, s3, s4, s5, s6, s7);
2364
+ s9 = peg$f48(s2, s3, s4, s5, s6, s7);
2322
2365
  if (s9) s9 = void 0;
2323
2366
  else s9 = peg$FAILED;
2324
2367
  if (s9 !== peg$FAILED) {
2325
2368
  s10 = peg$currPos;
2326
- s11 = peg$f45(s2, s3, s4, s5, s6, s7);
2369
+ s11 = peg$f49(s2, s3, s4, s5, s6, s7);
2327
2370
  s12 = peg$currPos;
2328
2371
  s13 = [];
2329
2372
  if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
@@ -2356,7 +2399,7 @@ function peg$parse(input, options) {
2356
2399
  s11 = peg$parseBraceEnd();
2357
2400
  if (s11 !== peg$FAILED) {
2358
2401
  peg$savedPos = s8;
2359
- s8 = peg$f46(s2, s3, s4, s5, s6, s7, s10);
2402
+ s8 = peg$f50(s2, s3, s4, s5, s6, s7, s10);
2360
2403
  } else {
2361
2404
  peg$currPos = s8;
2362
2405
  s8 = peg$FAILED;
@@ -2371,7 +2414,7 @@ function peg$parse(input, options) {
2371
2414
  }
2372
2415
  if (s8 === peg$FAILED) s8 = null;
2373
2416
  peg$savedPos = s0;
2374
- s0 = peg$f47(s2, s3, s4, s5, s6, s7, s8);
2417
+ s0 = peg$f51(s2, s3, s4, s5, s6, s7, s8);
2375
2418
  } else {
2376
2419
  peg$currPos = s0;
2377
2420
  s0 = peg$FAILED;
@@ -2405,7 +2448,7 @@ function peg$parse(input, options) {
2405
2448
  }
2406
2449
  if (s3 !== peg$FAILED) {
2407
2450
  peg$savedPos = s0;
2408
- s0 = peg$f48(s2);
2451
+ s0 = peg$f52(s2);
2409
2452
  } else {
2410
2453
  peg$currPos = s0;
2411
2454
  s0 = peg$FAILED;
@@ -2555,12 +2598,12 @@ function peg$parse(input, options) {
2555
2598
  else s1 = s2;
2556
2599
  if (s1 !== peg$FAILED) {
2557
2600
  peg$savedPos = peg$currPos;
2558
- s2 = peg$f49(s1);
2601
+ s2 = peg$f53(s1);
2559
2602
  if (s2) s2 = void 0;
2560
2603
  else s2 = peg$FAILED;
2561
2604
  if (s2 !== peg$FAILED) {
2562
2605
  peg$savedPos = s0;
2563
- s0 = peg$f50(s1);
2606
+ s0 = peg$f54(s1);
2564
2607
  } else {
2565
2608
  peg$currPos = s0;
2566
2609
  s0 = peg$FAILED;
@@ -2737,7 +2780,7 @@ function peg$parse(input, options) {
2737
2780
  else s1 = s2;
2738
2781
  if (s1 !== peg$FAILED) {
2739
2782
  peg$savedPos = s0;
2740
- s1 = peg$f51(s1);
2783
+ s1 = peg$f55(s1);
2741
2784
  }
2742
2785
  s0 = s1;
2743
2786
  return s0;
@@ -2781,7 +2824,7 @@ function peg$parse(input, options) {
2781
2824
  if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
2782
2825
  if (s7 !== peg$FAILED) {
2783
2826
  peg$savedPos = s0;
2784
- s0 = peg$f52(s2, s3, s4, s6);
2827
+ s0 = peg$f56(s2, s3, s4, s6);
2785
2828
  } else {
2786
2829
  peg$currPos = s0;
2787
2830
  s0 = peg$FAILED;
@@ -2846,7 +2889,7 @@ function peg$parse(input, options) {
2846
2889
  s5 = peg$parse_();
2847
2890
  s6 = peg$parseHere();
2848
2891
  peg$savedPos = s0;
2849
- s0 = peg$f53(s2, s6);
2892
+ s0 = peg$f57(s2, s6);
2850
2893
  } else {
2851
2894
  peg$currPos = s0;
2852
2895
  s0 = peg$FAILED;
@@ -2886,7 +2929,7 @@ function peg$parse(input, options) {
2886
2929
  }
2887
2930
  if (s5 !== peg$FAILED) {
2888
2931
  peg$savedPos = s0;
2889
- s0 = peg$f54(s2, s3);
2932
+ s0 = peg$f58(s2, s3);
2890
2933
  } else {
2891
2934
  peg$currPos = s0;
2892
2935
  s0 = peg$FAILED;
@@ -3021,7 +3064,7 @@ function peg$parse(input, options) {
3021
3064
  else s3 = s4;
3022
3065
  if (s3 !== peg$FAILED) {
3023
3066
  peg$savedPos = peg$currPos;
3024
- s4 = peg$f55(s2, s3);
3067
+ s4 = peg$f59(s2, s3);
3025
3068
  if (s4) s4 = void 0;
3026
3069
  else s4 = peg$FAILED;
3027
3070
  if (s4 !== peg$FAILED) {
@@ -3039,7 +3082,7 @@ function peg$parse(input, options) {
3039
3082
  s9 = peg$parseAttrValue();
3040
3083
  if (s9 !== peg$FAILED) {
3041
3084
  peg$savedPos = s5;
3042
- s5 = peg$f56(s2, s3, s9);
3085
+ s5 = peg$f60(s2, s3, s9);
3043
3086
  } else {
3044
3087
  peg$currPos = s5;
3045
3088
  s5 = peg$FAILED;
@@ -3050,7 +3093,7 @@ function peg$parse(input, options) {
3050
3093
  }
3051
3094
  if (s5 === peg$FAILED) s5 = null;
3052
3095
  peg$savedPos = s0;
3053
- s0 = peg$f57(s2, s3, s5);
3096
+ s0 = peg$f61(s2, s3, s5);
3054
3097
  } else {
3055
3098
  peg$currPos = s0;
3056
3099
  s0 = peg$FAILED;
@@ -3108,7 +3151,7 @@ function peg$parse(input, options) {
3108
3151
  if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3109
3152
  if (s5 !== peg$FAILED) {
3110
3153
  peg$savedPos = s0;
3111
- s0 = peg$f58(s2, s3, s4);
3154
+ s0 = peg$f62(s2, s3, s4);
3112
3155
  } else {
3113
3156
  peg$currPos = s0;
3114
3157
  s0 = peg$FAILED;
@@ -3163,7 +3206,7 @@ function peg$parse(input, options) {
3163
3206
  if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3164
3207
  if (s5 !== peg$FAILED) {
3165
3208
  peg$savedPos = s0;
3166
- s0 = peg$f59(s2, s3, s4);
3209
+ s0 = peg$f63(s2, s3, s4);
3167
3210
  } else {
3168
3211
  peg$currPos = s0;
3169
3212
  s0 = peg$FAILED;
@@ -3182,7 +3225,7 @@ function peg$parse(input, options) {
3182
3225
  }
3183
3226
  if (s1 !== peg$FAILED) {
3184
3227
  peg$savedPos = s0;
3185
- s1 = peg$f60(s1);
3228
+ s1 = peg$f64(s1);
3186
3229
  }
3187
3230
  s0 = s1;
3188
3231
  if (s0 === peg$FAILED) {
@@ -3208,7 +3251,7 @@ function peg$parse(input, options) {
3208
3251
  s2 = input.substring(s2, peg$currPos);
3209
3252
  s3 = peg$parseHere();
3210
3253
  peg$savedPos = s0;
3211
- s0 = peg$f61(s1, s2, s3);
3254
+ s0 = peg$f65(s1, s2, s3);
3212
3255
  }
3213
3256
  }
3214
3257
  }
@@ -3218,7 +3261,7 @@ function peg$parse(input, options) {
3218
3261
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3219
3262
  s0 = peg$currPos;
3220
3263
  peg$savedPos = peg$currPos;
3221
- s1 = peg$f62();
3264
+ s1 = peg$f66();
3222
3265
  if (s1) s1 = void 0;
3223
3266
  else s1 = peg$FAILED;
3224
3267
  if (s1 !== peg$FAILED) {
@@ -3247,7 +3290,7 @@ function peg$parse(input, options) {
3247
3290
  if (s2 !== peg$FAILED) {
3248
3291
  s3 = peg$currPos;
3249
3292
  peg$savedPos = peg$currPos;
3250
- s4 = peg$f63(s2);
3293
+ s4 = peg$f67(s2);
3251
3294
  if (s4) s4 = void 0;
3252
3295
  else s4 = peg$FAILED;
3253
3296
  if (s4 !== peg$FAILED) {
@@ -3286,7 +3329,7 @@ function peg$parse(input, options) {
3286
3329
  if (s0 === peg$FAILED) {
3287
3330
  s0 = peg$currPos;
3288
3331
  peg$savedPos = peg$currPos;
3289
- s1 = peg$f64();
3332
+ s1 = peg$f68();
3290
3333
  if (s1) s1 = void 0;
3291
3334
  else s1 = peg$FAILED;
3292
3335
  if (s1 !== peg$FAILED) {
@@ -3313,12 +3356,12 @@ function peg$parse(input, options) {
3313
3356
  if (s6 !== peg$FAILED) {
3314
3357
  s7 = peg$parseHere();
3315
3358
  peg$savedPos = peg$currPos;
3316
- s8 = peg$f65(s4, s7);
3359
+ s8 = peg$f69(s4, s7);
3317
3360
  if (s8) s8 = void 0;
3318
3361
  else s8 = peg$FAILED;
3319
3362
  if (s8 !== peg$FAILED) {
3320
3363
  s9 = peg$currPos;
3321
- s10 = peg$f66(s4, s7);
3364
+ s10 = peg$f70(s4, s7);
3322
3365
  s11 = peg$currPos;
3323
3366
  s12 = [];
3324
3367
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3394,7 +3437,7 @@ function peg$parse(input, options) {
3394
3437
  if (s0 === peg$FAILED) {
3395
3438
  s0 = peg$currPos;
3396
3439
  peg$savedPos = peg$currPos;
3397
- s1 = peg$f67();
3440
+ s1 = peg$f71();
3398
3441
  if (s1) s1 = void 0;
3399
3442
  else s1 = peg$FAILED;
3400
3443
  if (s1 !== peg$FAILED) {
@@ -3479,7 +3522,7 @@ function peg$parse(input, options) {
3479
3522
  if (s0 === peg$FAILED) {
3480
3523
  s0 = peg$currPos;
3481
3524
  peg$savedPos = peg$currPos;
3482
- s1 = peg$f68();
3525
+ s1 = peg$f72();
3483
3526
  if (s1) s1 = void 0;
3484
3527
  else s1 = peg$FAILED;
3485
3528
  if (s1 !== peg$FAILED) {
@@ -3572,6 +3615,8 @@ function peg$parse(input, options) {
3572
3615
  let attrCode = false;
3573
3616
  /** The macro whose raw body is being read. */
3574
3617
  let rawName = "";
3618
+ /** The HTML text-only body being read; its own closer ends this context. */
3619
+ let htmlTextTag = "";
3575
3620
  /**
3576
3621
  * The index in `inner` (at `at` in the input) of the first `separator` that
3577
3622
  * is not inside a {…} of the label: its code (`{if $a || $b}`, a string with
@@ -3649,6 +3694,51 @@ function peg$parse(input, options) {
3649
3694
  if (peg$success) return peg$result;
3650
3695
  else peg$throw();
3651
3696
  }
3697
+ // src/utils/macro-names.ts
3698
+ /**
3699
+ * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
3700
+ * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
3701
+ * name.
3702
+ */
3703
+ var NameMap = class extends Map {
3704
+ get(name) {
3705
+ return super.get(name.toLowerCase());
3706
+ }
3707
+ set(name, value) {
3708
+ return super.set(name.toLowerCase(), value);
3709
+ }
3710
+ has(name) {
3711
+ return super.has(name.toLowerCase());
3712
+ }
3713
+ delete(name) {
3714
+ return super.delete(name.toLowerCase());
3715
+ }
3716
+ };
3717
+ /** The latest definition of each name, using runtime replacement precedence. */
3718
+ function effectiveNamedDefinitions(definitions) {
3719
+ const latest = new NameMap();
3720
+ for (const definition of definitions) latest.set(definition.name, definition);
3721
+ return [...latest.values()];
3722
+ }
3723
+ /** A set of macro or widget names (see NameMap). */
3724
+ var NameSet = class {
3725
+ constructor(names = []) {
3726
+ this.names = new NameMap();
3727
+ for (const name of names) this.add(name);
3728
+ }
3729
+ add(name) {
3730
+ this.names.set(name, true);
3731
+ }
3732
+ has(name) {
3733
+ return this.names.has(name);
3734
+ }
3735
+ delete(name) {
3736
+ this.names.delete(name);
3737
+ }
3738
+ clear() {
3739
+ this.names.clear();
3740
+ }
3741
+ };
3652
3742
  // src/components/macros/option-clauses.ts
3653
3743
  /** The direct value clauses read by the built-in choice controls. */
3654
3744
  var OPTION_CLAUSE = "option";
@@ -9399,9 +9489,7 @@ var SigilParser = class extends Parser {
9399
9489
  if (name) {
9400
9490
  const end = at + 1 + name.length;
9401
9491
  const afterPrefix = self.type === types$1.incDec && (this.operandBeforeLast || this.breakBeforeLast);
9402
- const forced = code === 37 ? this.percentAt?.get(at) : void 0;
9403
- if (code === 64 || (forced ?? (self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)))) {
9404
- if (code === 37) this.transientsRead?.add(at);
9492
+ if (code === 64 || self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)) {
9405
9493
  self.pos = end;
9406
9494
  self.finishToken(types$1.name, self.input.charAt(at) + name);
9407
9495
  return;
@@ -9424,16 +9512,31 @@ var SigilParser = class extends Parser {
9424
9512
  }
9425
9513
  const self = this;
9426
9514
  const prevType = self.type;
9515
+ const beforePreviousValue = this.prevValue;
9427
9516
  this.prevValue = isMemberDot(this.typeBeforeLast) ? void 0 : self.value;
9428
9517
  const property = type.keyword !== void 0 && isMemberDot(prevType) || (type === types$1._function || type === types$1._class) && notABody(self.input, self.pos);
9429
9518
  if (!property && (type === types$1._function || type === types$1._class)) {
9430
- const before = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere ? this.typeBeforeLast : prevType;
9431
- self.type = before === types$1.colon && this.colonEndsTernary ? types$1.parenL : before;
9519
+ const afterAsync = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere;
9520
+ const before = afterAsync ? this.typeBeforeLast : prevType;
9521
+ const contextualOperand = before === types$1.name && (afterAsync ? this.operandBeforeLast : self.exprAllowed) && ((afterAsync ? beforePreviousValue : this.prevValue) !== "yield" || !(afterAsync ? this.breakBeforeLast : this.breakHere));
9522
+ self.type = before === types$1.colon && this.colonEndsTernary || contextualOperand ? types$1.parenL : before;
9432
9523
  }
9433
9524
  this.typeBeforeLast = prevType;
9434
9525
  super.finishToken(property ? types$1.name : type, value);
9435
9526
  if (type === types$1.name && (isMemberDot(prevType) || value === "of" && (prevType === types$1._const || prevType === types$1._var || this.prevValue === "let"))) self.exprAllowed = false;
9436
9527
  }
9528
+ parseIdent(liberal) {
9529
+ this.exprAllowed = false;
9530
+ return super.parseIdent(liberal);
9531
+ }
9532
+ parseForIn(node, init) {
9533
+ this.exprAllowed = true;
9534
+ return super.parseForIn(node, init);
9535
+ }
9536
+ parseAwait(forInit) {
9537
+ this.exprAllowed = true;
9538
+ return super.parseAwait(forInit);
9539
+ }
9437
9540
  braceIsBlock(prevType) {
9438
9541
  if (prevType === types$1.colon && this.colonEndsTernary) return false;
9439
9542
  if (prevType === types$1.braceR && this.closedBlock) return true;
@@ -9618,29 +9721,17 @@ function parseCode(src, goal = "expression") {
9618
9721
  }
9619
9722
  /** What parseCode finds in `src`, and the syntax tree it is in. */
9620
9723
  function parseWithAst(src, goal) {
9621
- const percentAt = /* @__PURE__ */ new Map();
9622
- for (;;) {
9623
- const transientsRead = /* @__PURE__ */ new Set();
9624
- try {
9625
- const ast = parseAst(src, goal, percentAt, transientsRead);
9626
- const out = {
9627
- refs: [],
9628
- strings: []
9629
- };
9630
- walk(ast, src, out, false, false);
9631
- out.refs.sort((a, b) => a.start - b.start);
9632
- return {
9633
- out,
9634
- ast
9635
- };
9636
- } catch (error) {
9637
- const pos = error.pos ?? -1;
9638
- if (!(error instanceof SyntaxError) || percentAt.has(pos)) throw error;
9639
- TRANS_NAME_RE.lastIndex = pos + 1;
9640
- if (src.charAt(pos) !== "%" || !TRANS_NAME_RE.test(src)) throw error;
9641
- percentAt.set(pos, !transientsRead.has(pos));
9642
- }
9643
- }
9724
+ const ast = parseAst(src, goal);
9725
+ const out = {
9726
+ refs: [],
9727
+ strings: []
9728
+ };
9729
+ walk(ast, src, out, false, false);
9730
+ out.refs.sort((a, b) => a.start - b.start);
9731
+ return {
9732
+ out,
9733
+ ast
9734
+ };
9644
9735
  }
9645
9736
  /**
9646
9737
  * Read `src` as a reference path: a variable with any number of `.name` and
@@ -9698,15 +9789,10 @@ function readMemberPath(src, end) {
9698
9789
  end
9699
9790
  };
9700
9791
  }
9701
- /**
9702
- * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
9703
- * noting where it read a transient in `transientsRead`.
9704
- */
9705
- function parseAst(src, goal, percentAt, transientsRead) {
9792
+ /** Parse `src` as `goal`, using the parser's context for `%name`. */
9793
+ function parseAst(src, goal) {
9706
9794
  try {
9707
9795
  const p = tokenizerAt(src, 0, goal);
9708
- p.percentAt = percentAt;
9709
- p.transientsRead = transientsRead;
9710
9796
  if (goal === "statements") return p.parse();
9711
9797
  p.nextToken();
9712
9798
  const ast = p.parseExpression();
@@ -9919,33 +10005,54 @@ var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
9919
10005
  * what in it is no JavaScript.
9920
10006
  */
9921
10007
  function findCodeEnd(src, start, { goal = "expression", stop, onRunOut } = {}) {
9922
- const end = scanCodeEnd(src, start, goal, stop, onRunOut);
9923
- return end < 0 && !stop ? parsedCodeEnd(src, start, goal) : end;
10008
+ let verifyStop = false;
10009
+ const end = scanCodeEnd(src, start, goal, stop, onRunOut, () => {
10010
+ verifyStop = true;
10011
+ });
10012
+ if (end < 0 || verifyStop) {
10013
+ const parsed = parsedCodeEnd(src, start, goal, stop);
10014
+ if (parsed >= 0) return parsed;
10015
+ }
10016
+ return end;
9924
10017
  }
9925
10018
  /**
9926
10019
  * Where the code from `start` ends, as the parser finds it: the `}` it
9927
- * stops at, or -1. The token scan of `findCodeEnd` guesses whether a `/`
9928
- * opens a regex from the tokens before it, and a few rare constructs (a
9929
- * class field named `class` inside a template literal) mislead it; the
9930
- * parser knows. Only asked when the scan finds no end.
10020
+ * stops at (or the `{` matching `stop`), or -1. The token scan of
10021
+ * `findCodeEnd` guesses whether a `/` opens a regex from the tokens before
10022
+ * it, and class fields inside template literals can mislead it. The parser
10023
+ * knows the context. Asked when the scan finds no end or a stop that might
10024
+ * still be template text.
9931
10025
  */
9932
- function parsedCodeEnd(src, start, goal) {
10026
+ function parsedCodeEnd(src, start, goal, stop) {
9933
10027
  const p = tokenizerAt(src, start, goal);
10028
+ const stopped = {};
10029
+ let stoppedAt = -1;
10030
+ if (stop) {
10031
+ const nextToken = p.nextToken;
10032
+ p.nextToken = () => {
10033
+ nextToken.call(p);
10034
+ if (p.type === types$1.braceL && stop(p.start)) {
10035
+ stoppedAt = p.start;
10036
+ throw stopped;
10037
+ }
10038
+ };
10039
+ }
9934
10040
  try {
9935
10041
  if (goal === "statements") p.parse();
9936
10042
  else {
9937
10043
  p.nextToken();
9938
10044
  p.parseExpression();
9939
- if (p.type === types$1.braceR) return p.start;
10045
+ if (!stop && p.type === types$1.braceR) return p.start;
9940
10046
  }
9941
10047
  } catch (error) {
10048
+ if (error === stopped) return stoppedAt;
9942
10049
  const pos = error.pos ?? -1;
9943
- if (src.charAt(pos) === "}") return pos;
10050
+ if (!stop && src.charAt(pos) === "}") return pos;
9944
10051
  }
9945
10052
  return -1;
9946
10053
  }
9947
10054
  /** `findCodeEnd` by the tokens: see there. */
9948
- function scanCodeEnd(src, start, goal, stop, onRunOut) {
10055
+ function scanCodeEnd(src, start, goal, stop, onRunOut, onTemplateStop) {
9949
10056
  /** No end: the code runs to the end of `src`. */
9950
10057
  const ranOut = () => {
9951
10058
  onRunOut?.();
@@ -9957,6 +10064,7 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
9957
10064
  let from = start;
9958
10065
  let afterOperand = false;
9959
10066
  let templateSlip = false;
10067
+ let interpolated = false;
9960
10068
  for (;;) {
9961
10069
  let resumeAt = -1;
9962
10070
  for (const tok of tokens(src, from, goal, { afterOperand })) {
@@ -9985,10 +10093,15 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
9985
10093
  prevWord = t === types$1.name && !WORDS_BEFORE_STRING.has(tok.value) || t === types$1.num;
9986
10094
  prevEnd = tok.end;
9987
10095
  if (t === types$1.braceL) {
9988
- if (stop?.(tok.start)) return tok.start;
10096
+ if (stop?.(tok.start)) {
10097
+ if (interpolated) onTemplateStop();
10098
+ return tok.start;
10099
+ }
9989
10100
  stack.push("{");
9990
- } else if (t === types$1.dollarBraceL) stack.push("${");
9991
- else if (t === types$1.parenL) stack.push("(");
10101
+ } else if (t === types$1.dollarBraceL) {
10102
+ interpolated = true;
10103
+ stack.push("${");
10104
+ } else if (t === types$1.parenL) stack.push("(");
9992
10105
  else if (t === types$1.bracketL) stack.push("[");
9993
10106
  else if (t === types$1.parenR || t === types$1.bracketR) {
9994
10107
  if (last(stack) === (t === types$1.parenR ? "(" : "[")) stack.pop();
@@ -10066,7 +10179,8 @@ function* tokens(src, start, goal, options = {}) {
10066
10179
  type: p.type,
10067
10180
  start: p.start,
10068
10181
  end: p.end,
10069
- value: p.value
10182
+ value: p.value,
10183
+ operand: p.operandHere
10070
10184
  };
10071
10185
  if (p.type === types$1.eof) return;
10072
10186
  }
@@ -10245,6 +10359,59 @@ function scanStringLiteral(src, start) {
10245
10359
  closed: false
10246
10360
  };
10247
10361
  }
10362
+ /** Read completion boundaries with the same tokenizer as runtime code. */
10363
+ function completionIdentifier(source, cursor, goal = "expression") {
10364
+ let previous;
10365
+ for (const token of tokens(source, 0, goal)) {
10366
+ if ("error" in token) {
10367
+ if (source[token.pos] === "@" && cursor === token.pos + 1) return {
10368
+ kind: "root",
10369
+ name: "",
10370
+ start: token.pos,
10371
+ end: cursor
10372
+ };
10373
+ return;
10374
+ }
10375
+ const member = previous && isMemberDot(previous.type) ? previous : void 0;
10376
+ if (token.start <= cursor && cursor <= token.end) {
10377
+ if (member && (token.type === types$1.name || token.type.keyword)) return {
10378
+ kind: "member",
10379
+ name: token.value,
10380
+ start: token.start,
10381
+ end: token.end,
10382
+ dotStart: member.start
10383
+ };
10384
+ if (token.type === types$1.name && !member) {
10385
+ const value = token.value;
10386
+ if ((sigilAt(source, token.start, value) || value === "$" || value === "_") && !keyPosition(source, token.end, previous?.type)) return {
10387
+ kind: "root",
10388
+ name: value.slice(1),
10389
+ start: token.start,
10390
+ end: token.end
10391
+ };
10392
+ }
10393
+ if (token.type === types$1.modulo && source.slice(token.start, token.end) === "%" && cursor === token.end && token.operand) return {
10394
+ kind: "root",
10395
+ name: "",
10396
+ start: token.start,
10397
+ end: token.end
10398
+ };
10399
+ }
10400
+ if (isMemberDot(token.type) && token.end === cursor) {
10401
+ previous = token;
10402
+ continue;
10403
+ }
10404
+ if (member && member.end === cursor && token.start >= cursor) return {
10405
+ kind: "member",
10406
+ name: "",
10407
+ start: cursor,
10408
+ end: cursor,
10409
+ dotStart: member.start
10410
+ };
10411
+ if (token.start > cursor || token.type === types$1.eof) return;
10412
+ previous = token;
10413
+ }
10414
+ }
10248
10415
  // src/markup/code-end.ts
10249
10416
  /**
10250
10417
  * A quote directly after a letter/digit is an apostrophe (don't), not a
@@ -12009,12 +12176,26 @@ var LITERAL = { kind: "literal" };
12009
12176
  * kind is literal when the cursor itself is inside one, a comment, or prose.
12010
12177
  */
12011
12178
  function completionContext(source, cursor, macros = []) {
12012
- if (!Number.isInteger(cursor) || cursor < 0 || cursor > source.length) throw new RangeError("cursor must be a UTF-16 offset within source");
12179
+ return readCompletion(source.slice(0, cursor), cursor, macros, false, source.length);
12180
+ }
12181
+ /** Includes the identifier suffix and its mappings through enclosing markup. */
12182
+ function completionTarget(source, cursor, macros = []) {
12183
+ return readCompletion(source, cursor, macros, true);
12184
+ }
12185
+ /** Visit the markup scopes enclosing a cursor, from outermost to innermost. */
12186
+ function completionScopes(source, cursor, macros, visit) {
12187
+ readCompletion(source, cursor, macros, true, source.length, visit);
12188
+ }
12189
+ function readCompletion(source, cursor, macros, full, sourceLength = source.length, visit) {
12190
+ if (!Number.isInteger(cursor) || cursor < 0 || cursor > sourceLength) throw new RangeError("cursor must be a UTF-16 offset within source");
12013
12191
  const parametersOf = parameterLookup(macros);
12014
12192
  const codeContext = (code, goal, map, containers) => {
12015
- const probe = code.length + 1;
12193
+ let position = 0;
12194
+ while (position < code.length && map(position) < cursor) position++;
12195
+ const prefix = code.slice(0, position);
12196
+ const probe = prefix.length + 1;
12016
12197
  let executable = false;
12017
- lexJs(code + " __spindle_cursor__", {
12198
+ lexJs(prefix + " __spindle_cursor__", {
12018
12199
  code(_ch, at) {
12019
12200
  if (at >= probe) executable = true;
12020
12201
  },
@@ -12023,6 +12204,7 @@ function completionContext(source, cursor, macros = []) {
12023
12204
  }
12024
12205
  }, goal);
12025
12206
  if (!executable) return LITERAL;
12207
+ const identifier = full ? completionIdentifier(code, position, goal) : void 0;
12026
12208
  const offset = map(0);
12027
12209
  const offsets = Array.from({ length: code.length + 1 }, (_, i) => map(i));
12028
12210
  return {
@@ -12030,7 +12212,8 @@ function completionContext(source, cursor, macros = []) {
12030
12212
  code,
12031
12213
  goal,
12032
12214
  offset,
12033
- cursor: code.length,
12215
+ cursor: position,
12216
+ ...identifier && { identifier },
12034
12217
  ...containers.length ? { containers } : {},
12035
12218
  ...offsets.some((at, i) => at !== offset + i) ? { sourceOffsets: offsets } : {}
12036
12219
  };
@@ -12040,7 +12223,7 @@ function completionContext(source, cursor, macros = []) {
12040
12223
  if (sigilsOnly) {
12041
12224
  let at = 0;
12042
12225
  for (const part of splitSigilTemplate(src, true)) if ("expr" in part) {
12043
- if (at + 1 + part.expr.length === src.length) return codeContext(part.expr, "expression", (i) => map(at + 1 + i), containers);
12226
+ if (map(at + 1) <= cursor && cursor <= map(at + 1 + part.expr.length)) return codeContext(part.expr, "expression", (i) => map(at + 1 + i), containers);
12044
12227
  at += part.expr.length + 2;
12045
12228
  } else at += ("text" in part ? part.text : part.verbatim).length;
12046
12229
  return LITERAL;
@@ -12049,14 +12232,17 @@ function completionContext(source, cursor, macros = []) {
12049
12232
  text,
12050
12233
  hooks: { isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0) }
12051
12234
  });
12052
- const token = tokens[tokens.length - 1];
12053
- if (!token || token.end !== src.length) return LITERAL;
12235
+ if (visit && !visit(tokens, map)) return LITERAL;
12236
+ const contains = (start, end) => map(start) <= cursor && cursor <= map(end);
12237
+ const index = tokens.findIndex((token) => map(token.start) < cursor && cursor <= map(token.end));
12238
+ const token = tokens[index];
12239
+ if (!token) return LITERAL;
12054
12240
  const codeAt = (code, at, goal = "expression") => codeContext(code, goal, (i) => map(at + i), containers);
12055
12241
  const nested = (value, at, offsets, onlySigils = false, container) => read(value, (i) => map(offsets?.[i] ?? at + i), true, depth + 1, onlySigils, container ? [...containers, container] : containers);
12056
- if (token.type === "variable" && token.nameEnd === src.length) return codeAt(src.slice(token.nameStart - 1), token.nameStart - 1);
12057
- if (token.type === "expression" && token.expressionEnd === src.length) return codeAt(token.expression, token.expressionStart);
12242
+ if (token.type === "variable" && contains(token.nameStart - 1, token.nameEnd)) return codeAt(src.slice(token.nameStart - 1, token.nameEnd), token.nameStart - 1);
12243
+ if (token.type === "expression" && contains(token.expressionStart, token.expressionEnd)) return codeAt(token.expression, token.expressionStart);
12058
12244
  if (token.type === "html") {
12059
- for (const { name, value, at } of attributeValues(src, token)) if (at + value.length === src.length) {
12245
+ for (const { name, value, at } of attributeValues(src, token)) if (contains(at, at + value.length)) {
12060
12246
  const span = token.attributeSpans.find((span) => span.valueStart === at);
12061
12247
  return nested(value, at, void 0, isCodeAttribute(name), {
12062
12248
  kind: "attribute",
@@ -12065,11 +12251,11 @@ function completionContext(source, cursor, macros = []) {
12065
12251
  code: isCodeAttribute(name)
12066
12252
  });
12067
12253
  }
12068
- } else if (token.type === "link" && token.displayEnd === src.length) return nested(token.display, token.displayStart, void 0, false, { kind: "link-label" });
12254
+ } else if (token.type === "link" && contains(token.displayStart, token.displayEnd)) return nested(token.display, token.displayStart, void 0, false, { kind: "link-label" });
12069
12255
  else if (token.type === "text" && !token.comment) {
12070
- const opener = tokens[tokens.length - 2];
12256
+ const opener = tokens[index - 1];
12071
12257
  if (opener?.type === "macro" && !opener.isClose && executesRawBody(opener.name, parametersOf)) return codeAt(token.value, token.start, "statements");
12072
- } else if (token.type === "macro" && !token.isClose && token.argsEnd === src.length) {
12258
+ } else if (token.type === "macro" && !token.isClose && contains(token.argsStart, token.argsEnd)) {
12073
12259
  const name = token.name.toLowerCase();
12074
12260
  const args = token.rawArgs;
12075
12261
  const widget = parametersOf.widget?.(name);
@@ -12082,29 +12268,32 @@ function completionContext(source, cursor, macros = []) {
12082
12268
  if (holds === "expression" || holds === "statements") return codeAt(raw, at, holds);
12083
12269
  return holds === "markup" ? nested(raw, at) : LITERAL;
12084
12270
  }
12085
- if (scanStringLiteral(raw, 0).closed) return LITERAL;
12086
- const value = escapes === "javascript" ? stringLiteralValue(raw + raw[0]) : quoted.value;
12271
+ const scan = scanStringLiteral(raw, 0);
12272
+ const bodyEnd = scan.closed ? scan.end - 1 : scan.end;
12273
+ if (!contains(at + 1, at + bodyEnd)) return LITERAL;
12274
+ const value = escapes === "javascript" ? stringLiteralValue(raw.slice(0, scan.end) + (scan.closed ? "" : raw[0])) : quoted.value;
12087
12275
  if (value == null) return LITERAL;
12088
12276
  const container = {
12089
12277
  kind: "string",
12090
12278
  quote: raw[0],
12091
12279
  escapes
12092
12280
  };
12093
- const offsets = escapeOffsets(raw.slice(1), at + 1, value, escapes);
12281
+ const offsets = escapeOffsets(raw.slice(1, bodyEnd), at + 1, value, escapes);
12094
12282
  if (holds === "expression" || holds === "statements") return codeContext(value, holds, (i) => map(offsets?.[i] ?? at + 1 + i), [...containers, container]);
12095
12283
  return holds === "markup" ? nested(value, at + 1, offsets, false, container) : LITERAL;
12096
12284
  };
12097
12285
  if (widget) {
12098
12286
  const spans = splitArgSpans(args);
12099
- const span = spans[spans.length - 1];
12287
+ const which = spans.findIndex(([start, end]) => contains(token.argsStart + start, token.argsStart + end));
12288
+ const span = spans[which];
12100
12289
  if (!span) return LITERAL;
12101
- const raw = args.slice(span[0]);
12102
- const holds = widget[spans.length - 1]?.holds;
12290
+ const raw = args.slice(...span);
12291
+ const holds = widget[which]?.holds;
12103
12292
  return /^["']/.test(raw) && holds ? stringContext(raw, token.argsStart + span[0], holds, "javascript") : codeAt(raw, token.argsStart + span[0]);
12104
12293
  }
12105
12294
  const params = parametersOf(name);
12106
12295
  if (!params) return LITERAL;
12107
- const spans = macroArgumentSpans(args, params).filter((span) => span.parameter.type !== "options" && span.end === args.trimEnd().length);
12296
+ const spans = macroArgumentSpans(args, params).filter((span) => span.parameter.type !== "options" && contains(token.argsStart + span.start, token.argsStart + span.end));
12108
12297
  const span = spans[spans.length - 1];
12109
12298
  if (!span) return LITERAL;
12110
12299
  const param = span.parameter;
@@ -12113,7 +12302,7 @@ function completionContext(source, cursor, macros = []) {
12113
12302
  at += param.name.length;
12114
12303
  while (/\s/.test(args.charAt(at))) at++;
12115
12304
  }
12116
- const raw = args.slice(at);
12305
+ const raw = args.slice(at, span.end);
12117
12306
  const offset = token.argsStart + at;
12118
12307
  if (param.type === "expression" || param.type === "passage") return codeAt(raw, offset);
12119
12308
  if (param.type === "statements") return codeAt(raw, offset, "statements");
@@ -12121,7 +12310,7 @@ function completionContext(source, cursor, macros = []) {
12121
12310
  }
12122
12311
  return LITERAL;
12123
12312
  };
12124
- return read(source.slice(0, cursor), (i) => i);
12313
+ return read(source, (i) => i);
12125
12314
  }
12126
12315
  // src/widgets/ast-scanner.ts
12127
12316
  /** The declared parameters of the macros registered so far. */
@@ -26185,7 +26374,6 @@ function blockLookup(macros, includeRuntime = true) {
26185
26374
  */
26186
26375
  function macroCalls(source, macros = []) {
26187
26376
  const all = effectiveToolingMacros(macros);
26188
- const definitions = new NameMap(all.map((macro) => [macro.name, macro]));
26189
26377
  const parametersOf = parameterLookup(all);
26190
26378
  const options = tokenizationOptions({
26191
26379
  macros: all,
@@ -26194,7 +26382,31 @@ function macroCalls(source, macros = []) {
26194
26382
  const hooks = options.hooks;
26195
26383
  const tokens = tokenizeMarkupTolerant$1(source, options).tokens;
26196
26384
  const calls = [];
26385
+ const classifier = macroClassifier(all);
26197
26386
  const classify = (tokens) => {
26387
+ for (const call of classifier(tokens)) calls.push(call);
26388
+ };
26389
+ classify(tokens);
26390
+ for (const piece of passagePiecesOf(source, tokens, parametersOf, { isBlock: hooks.isBlock })) {
26391
+ if (piece.kind !== "text" || !piece.tokens.length) continue;
26392
+ classify(piece.tokens);
26393
+ }
26394
+ let literalEnd = -1;
26395
+ return calls.sort((a, b) => a.token.start - b.token.start).filter((call) => {
26396
+ if (call.token.start < literalEnd) return false;
26397
+ if (call.kind === "value" || call.kind === "branch") literalEnd = call.token.argsEnd;
26398
+ return true;
26399
+ });
26400
+ }
26401
+ /** Shared contextual dispatch for complete and unfinished grammar tokens. */
26402
+ function macroClassifier(all) {
26403
+ const definitions = new NameMap(all.map((macro) => [macro.name, macro]));
26404
+ const hooks = tokenizationOptions({
26405
+ macros: all,
26406
+ hooks: { isBlock: blockLookup(all, false) }
26407
+ }).hooks;
26408
+ return (tokens) => {
26409
+ const calls = [];
26198
26410
  const found = /* @__PURE__ */ new Map();
26199
26411
  const pending = pairMarkup(tokens, hooks).nodes.map((node) => ({ node }));
26200
26412
  while (pending.length) {
@@ -26235,18 +26447,24 @@ function macroCalls(source, macros = []) {
26235
26447
  };
26236
26448
  calls.push(call);
26237
26449
  }
26450
+ return calls;
26238
26451
  };
26239
- classify(tokens);
26240
- for (const piece of passagePiecesOf(source, tokens, parametersOf, { isBlock: hooks.isBlock })) {
26241
- if (piece.kind !== "text" || !piece.tokens.length) continue;
26242
- classify(piece.tokens);
26243
- }
26244
- let literalEnd = -1;
26245
- return calls.sort((a, b) => a.token.start - b.token.start).filter((call) => {
26246
- if (call.token.start < literalEnd) return false;
26247
- if (call.kind === "value" || call.kind === "branch") literalEnd = call.token.argsEnd;
26248
- return true;
26452
+ }
26453
+ /** The opening macro head containing a cursor, including unfinished heads. */
26454
+ function macroCallAt(source, cursor, macros = []) {
26455
+ const all = effectiveToolingMacros(macros);
26456
+ const classify = macroClassifier(all);
26457
+ let selected;
26458
+ completionScopes(source, cursor, all, (tokens, map) => {
26459
+ const call = classify(tokens).find(({ token }) => map(token.start) < cursor && cursor <= map(token.end));
26460
+ if (call) selected = {
26461
+ ...call,
26462
+ token: mapOffsets(call.token, map),
26463
+ ...call.owner && { owner: mapOffsets(call.owner, map) }
26464
+ };
26465
+ return !call || call.kind === "invocation";
26249
26466
  });
26467
+ return selected;
26250
26468
  }
26251
26469
  /**
26252
26470
  * What a passage's markup runs and names, and where: the pieces of code
@@ -26344,4 +26562,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
26344
26562
  const list = [...passages];
26345
26563
  return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
26346
26564
  }
26347
- export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
26565
+ export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };