@rohal12/spindle 0.59.22 → 0.59.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Fragment, createContext, h, render } from "preact";
2
- import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
2
+ import { useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
3
3
  import { useSyncExternalStore } from "preact/compat";
4
4
  import { createStore } from "zustand/vanilla";
5
5
  import { immer } from "zustand/middleware/immer";
@@ -105,18 +105,13 @@ var VOID_TAGS = new Set([
105
105
  "track",
106
106
  "wbr"
107
107
  ]);
108
- var BRANCH_PARENT = {
108
+ var BRANCH_PARENT$1 = {
109
109
  elseif: "if",
110
110
  else: "if",
111
111
  case: "switch",
112
112
  default: "switch",
113
113
  next: "timed"
114
114
  };
115
- var BRANCHING = new Set([
116
- "if",
117
- "switch",
118
- "timed"
119
- ]);
120
115
  var LINK_SEPARATORS = [
121
116
  ["|", false],
122
117
  ["->", false],
@@ -153,6 +148,8 @@ function parseLink(inner, at, indexOf) {
153
148
  const [display, target] = targetFirst ? [after, before] : [before, after];
154
149
  return {
155
150
  display: display.value,
151
+ displayStart: display.start,
152
+ displayEnd: display.end,
156
153
  target: target.value,
157
154
  targetStart: target.start,
158
155
  targetEnd: target.end
@@ -161,14 +158,13 @@ function parseLink(inner, at, indexOf) {
161
158
  const whole = part(0, inner.length);
162
159
  return {
163
160
  display: whole.value,
161
+ displayStart: whole.start,
162
+ displayEnd: whole.end,
164
163
  target: whole.value,
165
164
  targetStart: whole.start,
166
165
  targetEnd: whole.end
167
166
  };
168
167
  }
169
- function quoteArg(value) {
170
- return "\"" + value.replace(/[\\"]/g, "\\$&") + "\"";
171
- }
172
168
  function selectorsOf(parts) {
173
169
  const classes = [];
174
170
  let id = "";
@@ -187,15 +183,6 @@ function label(tag) {
187
183
  if (tag.lex === "html") return (tag.isClose ? "</" : "<") + tag.tag + ">";
188
184
  return LB + (tag.isClose ? "/" : "") + tag.name + RB;
189
185
  }
190
- function closerOf(tag) {
191
- return tag.lex === "html" ? "</" + tag.tag + ">" : LB + "/" + tag.name + RB;
192
- }
193
- function at(loc) {
194
- return "line " + loc.start.line + ", column " + loc.start.column;
195
- }
196
- function sameName(open, close) {
197
- return open.lex === close.lex && open.lower === close.lower;
198
- }
199
186
  /** A lexeme: what one token of the flat stream holds, with its span. */
200
187
  function lexeme(lex, loc, fields) {
201
188
  fields.lex = lex;
@@ -204,35 +191,6 @@ function lexeme(lex, loc, fields) {
204
191
  fields.loc = loc;
205
192
  return fields;
206
193
  }
207
- /** The AST node of a lexeme that stands alone (not a macro or element). */
208
- function nodeOf(x) {
209
- switch (x.lex) {
210
- case "text": return x.comment ? {
211
- type: "text",
212
- value: x.value,
213
- comment: true
214
- } : {
215
- type: "text",
216
- value: x.value
217
- };
218
- case "link": return withSelectors({
219
- type: "macro",
220
- name: "link",
221
- rawArgs: quoteArg(x.display) + " " + quoteArg(x.target),
222
- children: []
223
- }, x);
224
- case "variable": return withSelectors({
225
- type: "variable",
226
- name: x.name,
227
- scope: x.scope
228
- }, x);
229
- case "expression": return withSelectors({
230
- type: "expression",
231
- expression: x.expression
232
- }, x);
233
- default: return x;
234
- }
235
- }
236
194
  /** The token of a lexeme (tokens.ts Token). */
237
195
  function tokenOf(x) {
238
196
  const span = {
@@ -240,7 +198,12 @@ function tokenOf(x) {
240
198
  end: x.end
241
199
  };
242
200
  switch (x.lex) {
243
- case "text": return {
201
+ case "text": return x.comment ? {
202
+ type: "text",
203
+ value: x.value,
204
+ comment: true,
205
+ ...span
206
+ } : {
244
207
  type: "text",
245
208
  value: x.value,
246
209
  ...span
@@ -248,33 +211,50 @@ function tokenOf(x) {
248
211
  case "link": return withSelectors({
249
212
  type: "link",
250
213
  display: x.display,
214
+ displayStart: x.displayStart,
215
+ displayEnd: x.displayEnd,
251
216
  target: x.target,
252
217
  targetStart: x.targetStart,
253
218
  targetEnd: x.targetEnd,
219
+ ...x.selectorSpan,
254
220
  ...span
255
221
  }, x);
256
222
  case "variable": return withSelectors({
257
223
  type: "variable",
258
224
  name: x.name,
225
+ nameStart: x.nameStart,
226
+ nameEnd: x.nameEnd,
259
227
  scope: x.scope,
228
+ ...x.selectorSpan,
260
229
  ...span
261
230
  }, x);
262
231
  case "expression": return withSelectors({
263
232
  type: "expression",
264
233
  expression: x.expression,
234
+ expressionStart: x.expressionStart,
235
+ expressionEnd: x.expressionEnd,
236
+ ...x.selectorSpan,
265
237
  ...span
266
238
  }, x);
267
239
  case "macro": return withSelectors({
268
240
  type: "macro",
269
241
  name: x.name,
242
+ nameStart: x.nameStart,
243
+ nameEnd: x.nameEnd,
270
244
  rawArgs: x.rawArgs,
245
+ argsStart: x.argsStart,
246
+ argsEnd: x.argsEnd,
271
247
  isClose: x.isClose,
248
+ ...x.selectorSpan,
272
249
  ...span
273
250
  }, x);
274
251
  case "html": return {
275
252
  type: "html",
276
253
  tag: x.tag,
254
+ tagNameStart: x.tagNameStart,
255
+ tagNameEnd: x.tagNameEnd,
277
256
  attributes: x.attributes,
257
+ attributeSpans: x.attributeSpans,
278
258
  isClose: x.isClose,
279
259
  isSelfClose: x.isSelfClose,
280
260
  ...span
@@ -285,7 +265,7 @@ function tokenOf(x) {
285
265
  * Flatten items (lexemes, nodes, arrays of them, nulls) and join adjacent
286
266
  * text, except escaped braces and comments, which stay a text item of their own.
287
267
  */
288
- function joinText(items, convert) {
268
+ function joinText(items) {
289
269
  const out = [];
290
270
  let last = null;
291
271
  const add = (item) => {
@@ -300,7 +280,7 @@ function joinText(items, convert) {
300
280
  last = item;
301
281
  };
302
282
  add(items);
303
- return convert ? out.map(convert) : out;
283
+ return out.map(tokenOf);
304
284
  }
305
285
  var peg$SyntaxError = class extends SyntaxError {
306
286
  constructor(message, expected, found, location) {
@@ -393,11 +373,10 @@ function peg$parse(input, options) {
393
373
  const peg$FAILED = {};
394
374
  const peg$source = options.grammarSource;
395
375
  const peg$startRuleFunctions = {
396
- Markup: peg$parseMarkup,
397
376
  Tokens: peg$parseTokens,
398
377
  SelectorsPrefix: peg$parseSelectorsPrefix
399
378
  };
400
- let peg$startRuleFunction = peg$parseMarkup;
379
+ let peg$startRuleFunction = peg$parseTokens;
401
380
  const peg$c0 = "<!--";
402
381
  const peg$c1 = ">";
403
382
  const peg$c2 = "->";
@@ -627,175 +606,74 @@ function peg$parse(input, options) {
627
606
  " ",
628
607
  ""
629
608
  ], false, false, false);
630
- function peg$f0(nodes) {
631
- return nodes;
609
+ function peg$f0(items) {
610
+ return joinText(items);
632
611
  }
633
- function peg$f1(tag) {
634
- fail(label(tag) + " must be directly inside {" + BRANCH_PARENT[tag.lower] + RB, tag.loc);
612
+ function peg$f1() {
613
+ return !textMode;
635
614
  }
636
615
  function peg$f2(tag) {
637
- fail(label(tag) + " closes nothing: no " + (tag.lex === "html" ? "<" + tag.tag + ">" : LB + tag.name + RB) + " is open here", tag.loc);
616
+ return tag;
638
617
  }
639
- function peg$f3(items) {
640
- return joinText(items, nodeOf);
618
+ function peg$f3() {
619
+ return !textMode;
641
620
  }
642
621
  function peg$f4(tag) {
643
- return tag.kind === "open";
622
+ return VOID_TAGS.has(tag.lower) ? null : tag;
644
623
  }
645
624
  function peg$f5(tag) {
646
625
  rawName = tag.lower;
647
- return hooks.isRaw(rawName);
626
+ return tag.kind === "open" && hooks.isRaw(rawName);
648
627
  }
649
628
  function peg$f6(tag, b) {
650
629
  return b;
651
630
  }
652
- function peg$f7(tag) {
653
- return hooks.isBlock(tag.lower);
654
- }
655
- function peg$f8(tag, b) {
656
- return b;
657
- }
658
- function peg$f9(tag) {
659
- return null;
660
- }
661
- function peg$f10(tag, body) {
662
- return macroNode(tag, body);
663
- }
664
- function peg$f11() {
665
- return !textMode;
666
- }
667
- function peg$f12(open) {
668
- return !open.isSelfClose;
669
- }
670
- function peg$f13(open, b) {
671
- return b;
672
- }
673
- function peg$f14(open, body) {
674
- const node = {
675
- type: "html",
676
- tag: open.tag,
677
- attributes: open.attributes,
678
- children: []
679
- };
680
- if (body) {
681
- checkBody(open, body);
682
- node.children = body.children;
683
- }
684
- return node;
685
- }
686
- function peg$f15(children, branches, end) {
687
- return {
688
- children,
689
- branches,
690
- end
691
- };
692
- }
693
- function peg$f16(tag, children) {
694
- return {
695
- tag,
696
- children
697
- };
698
- }
699
- function peg$f17() {
700
- return null;
701
- }
702
- function peg$f18(tag) {
703
- return tag.kind === "branch";
704
- }
705
- function peg$f19(tag) {
706
- return tag;
631
+ function peg$f7(tag, body) {
632
+ return body ? [tag, body] : tag;
707
633
  }
708
- function peg$f20(tag) {
634
+ function peg$f8(tag) {
709
635
  return tag.kind === "close";
710
636
  }
711
- function peg$f21(tag) {
712
- return tag;
713
- }
714
- function peg$f22() {
715
- return !textMode;
716
- }
717
- function peg$f23(tag) {
637
+ function peg$f9(tag) {
718
638
  return tag;
719
639
  }
720
- function peg$f24(start) {
721
- return skipTo(hooks.rawBodyEnd(input, start, rawName));
722
- }
723
- function peg$f25(start) {
724
- return skipEnd - offset();
725
- }
726
- function peg$f26(start, body, end) {
727
- return {
728
- children: body ? [{
729
- type: "text",
730
- value: body
731
- }] : [],
732
- branches: [],
733
- end
734
- };
735
- }
736
- function peg$f27() {
737
- return {
738
- children: [],
739
- branches: [],
740
- end: null
741
- };
742
- }
743
- function peg$f28(items) {
744
- return joinText(items, tokenOf);
745
- }
746
- function peg$f29() {
640
+ function peg$f10() {
747
641
  return !textMode;
748
642
  }
749
- function peg$f30(tag) {
643
+ function peg$f11(tag) {
750
644
  return tag;
751
645
  }
752
- function peg$f31() {
753
- return !textMode;
754
- }
755
- function peg$f32(tag) {
756
- return VOID_TAGS.has(tag.lower) ? null : tag;
757
- }
758
- function peg$f33(tag) {
759
- rawName = tag.lower;
760
- return tag.kind === "open" && hooks.isRaw(rawName);
761
- }
762
- function peg$f34(tag, b) {
763
- return b;
764
- }
765
- function peg$f35(tag, body) {
766
- return body ? [tag, body] : tag;
767
- }
768
- function peg$f36(start) {
646
+ function peg$f12(start) {
769
647
  return skipTo(hooks.rawBodyEnd(input, start, rawName));
770
648
  }
771
- function peg$f37(start) {
649
+ function peg$f13(start) {
772
650
  return skipEnd - offset();
773
651
  }
774
- function peg$f38(start, body, end) {
652
+ function peg$f14(start, body, end) {
775
653
  const loc = {
776
654
  start: { offset: start },
777
655
  end: { offset: start + body.length }
778
656
  };
779
657
  return [body ? lexeme("text", loc, { value: body }) : null, end];
780
658
  }
781
- function peg$f39() {
659
+ function peg$f15() {
782
660
  return offset();
783
661
  }
784
- function peg$f40(value) {
662
+ function peg$f16(value) {
785
663
  return lexeme("text", location(), { value });
786
664
  }
787
- function peg$f41(value) {
665
+ function peg$f17(value) {
788
666
  const node = lexeme("text", location(), { value });
789
667
  node.comment = true;
790
668
  return node;
791
669
  }
792
- function peg$f42(bs) {
670
+ function peg$f18(bs) {
793
671
  return bs.length % 2 === 1;
794
672
  }
795
- function peg$f43(bs, c) {
673
+ function peg$f19(bs, c) {
796
674
  return c;
797
675
  }
798
- function peg$f44(bs, brace) {
676
+ function peg$f20(bs, brace) {
799
677
  const loc = location();
800
678
  const next = input.charAt(loc.end.offset);
801
679
  if (textMode) {
@@ -812,76 +690,88 @@ function peg$parse(input, options) {
812
690
  escaped.escape = true;
813
691
  return bs.length > 1 ? [before, escaped] : escaped;
814
692
  }
815
- function peg$f45() {
693
+ function peg$f21() {
816
694
  return lexeme("text", location(), { value: LB });
817
695
  }
818
- function peg$f46() {
696
+ function peg$f22() {
819
697
  return !textMode;
820
698
  }
821
- function peg$f47() {
699
+ function peg$f23() {
822
700
  return lexeme("text", location(), { value: "<" });
823
701
  }
824
- function peg$f48() {
702
+ function peg$f24() {
825
703
  return lexeme("text", location(), { value: "[" });
826
704
  }
827
- function peg$f49() {
705
+ function peg$f25() {
828
706
  return !textMode;
829
707
  }
830
- function peg$f50(s, at, inner) {
831
- return withSelectors(lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator))), s);
708
+ function peg$f26(ss, s, at, inner) {
709
+ const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
710
+ link.selectorSpan = selectorSpan(s, ss, at);
711
+ return withSelectors(link, s);
832
712
  }
833
- function peg$f51() {
713
+ function peg$f27() {
834
714
  return !textMode;
835
715
  }
836
- function peg$f52() {
837
- fail("Unclosed link: [[ without ]]", location());
716
+ function peg$f28() {
717
+ fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
838
718
  }
839
- function peg$f53(parts) {
719
+ function peg$f29(parts) {
840
720
  return selectorsOf(parts);
841
721
  }
842
- function peg$f54() {
722
+ function peg$f30() {
843
723
  return NO_SELECTORS;
844
724
  }
845
- function peg$f55(s, end) {
725
+ function peg$f31(s, end) {
846
726
  return {
847
727
  ...s,
848
728
  end
849
729
  };
850
730
  }
851
- function peg$f56(prefix, name) {
731
+ function peg$f32(prefix, name) {
852
732
  return [prefix, name];
853
733
  }
854
- function peg$f57(s, sigil, name) {
855
- return withSelectors(lexeme("variable", location(), {
734
+ function peg$f33(ss, s, sigil, nameStart, name) {
735
+ const variable = lexeme("variable", location(), {
856
736
  name,
737
+ nameStart,
738
+ nameEnd: nameStart + name.length,
857
739
  scope: SIGIL_SCOPES[sigil]
858
- }), s);
859
- }
860
- function peg$f58(s, expression) {
861
- return withSelectors(lexeme("expression", location(), { expression }), s);
740
+ });
741
+ variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
742
+ return withSelectors(variable, s);
743
+ }
744
+ function peg$f34(ss, s, after, expression) {
745
+ const node = lexeme("expression", location(), {
746
+ expression,
747
+ expressionStart: after,
748
+ expressionEnd: after + expression.length
749
+ });
750
+ node.selectorSpan = selectorSpan(s, ss, after);
751
+ return withSelectors(node, s);
862
752
  }
863
- function peg$f59() {
864
- fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location());
753
+ function peg$f35() {
754
+ fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
865
755
  }
866
- function peg$f60(start) {
756
+ function peg$f36(start) {
867
757
  return skipTo(hooks.closeBrace(input, start, start));
868
758
  }
869
- function peg$f61(start) {
759
+ function peg$f37(start) {
870
760
  return skipEnd - offset();
871
761
  }
872
- function peg$f62(start, code) {
762
+ function peg$f38(start, code) {
873
763
  return code;
874
764
  }
875
- function peg$f63(s, start, close, name, nameEnd) {
765
+ function peg$f39(ss, s, start, close, name, nameEnd) {
876
766
  return skipTo(hooks.closeBrace(input, nameEnd, start));
877
767
  }
878
- function peg$f64(s, start, close, name, nameEnd) {
768
+ function peg$f40(ss, s, start, close, name, nameEnd) {
879
769
  return skipEnd - offset();
880
770
  }
881
- function peg$f65(s, start, close, name, nameEnd, args) {
771
+ function peg$f41(ss, s, start, close, name, nameEnd, args) {
882
772
  return args;
883
773
  }
884
- function peg$f66(s, start, close, name, nameEnd, tail) {
774
+ function peg$f42(ss, s, start, close, name, nameEnd, tail) {
885
775
  const loc = location();
886
776
  const lower = name.toLowerCase();
887
777
  const tag = lexeme("macro", loc, {
@@ -890,49 +780,48 @@ function peg$parse(input, options) {
890
780
  rawArgs: "",
891
781
  isClose: !!close
892
782
  });
893
- if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc);
783
+ tag.nameStart = nameEnd - name.length;
784
+ tag.nameEnd = nameEnd;
785
+ tag.selectorSpan = selectorSpan(s, ss, start);
786
+ if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
894
787
  tag.rawArgs = tail.trim();
788
+ tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
789
+ tag.argsEnd = tag.argsStart + tag.rawArgs.length;
895
790
  if (close) {
896
- if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc);
897
- if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc);
791
+ if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc, "closer-with-selectors");
792
+ if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc, "closer-with-arguments");
898
793
  tag.kind = "close";
899
794
  } else {
900
795
  withSelectors(tag, s);
901
- tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT, lower) ? "branch" : "open";
796
+ tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT$1, lower) ? "branch" : "open";
902
797
  }
903
798
  return tag;
904
799
  }
905
- function peg$f67(s) {
906
- fail("A closing tag starts with a letter after " + LB + "/", location());
800
+ function peg$f43(s) {
801
+ fail("A closing tag starts with a letter after " + LB + "/", location(), "invalid-closer");
907
802
  }
908
- function peg$f68(value) {
803
+ function peg$f44(value) {
909
804
  return EMAIL_AUTOLINK.test(value);
910
805
  }
911
- function peg$f69(value) {
806
+ function peg$f45(value) {
912
807
  return lexeme("text", location(), { value });
913
808
  }
914
- function peg$f70() {
915
- return !textMode;
916
- }
917
- function peg$f71(tag) {
918
- return VOID_TAGS.has(tag.lower);
919
- }
920
- function peg$f72(tag) {
921
- return null;
922
- }
923
- function peg$f73(tag, list, slash) {
809
+ function peg$f46(tagStart, tag, list, slash) {
924
810
  const lower = tag.toLowerCase();
925
811
  return lexeme("html", location(), {
926
812
  tag,
927
813
  lower,
814
+ tagNameStart: tagStart,
815
+ tagNameEnd: tagStart + tag.length,
928
816
  attributes: attrs(list),
817
+ attributeSpans: list,
929
818
  isClose: false,
930
819
  isSelfClose: !!slash || VOID_TAGS.has(lower)
931
820
  });
932
821
  }
933
- function peg$f74(tag, bad) {
822
+ function peg$f47(tag, bad) {
934
823
  const c = input.charAt(bad);
935
- if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location());
824
+ if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
936
825
  const at = {
937
826
  source: location().source,
938
827
  start: {
@@ -946,55 +835,86 @@ function peg$parse(input, options) {
946
835
  column: 0
947
836
  }
948
837
  };
949
- fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at);
838
+ fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
950
839
  }
951
- function peg$f75(tag) {
840
+ function peg$f48(tagStart, tag) {
952
841
  return lexeme("html", location(), {
953
842
  tag,
954
843
  lower: tag.toLowerCase(),
844
+ tagNameStart: tagStart,
845
+ tagNameEnd: tagStart + tag.length,
955
846
  attributes: {},
847
+ attributeSpans: [],
956
848
  isClose: true,
957
849
  isSelfClose: false
958
850
  });
959
851
  }
960
- function peg$f76(name) {
852
+ function peg$f49(nameStart, name) {
961
853
  attrCode = hooks.isCodeAttribute(name);
962
854
  return true;
963
855
  }
964
- function peg$f77(name, v) {
856
+ function peg$f50(nameStart, name, v) {
965
857
  return v;
966
858
  }
967
- function peg$f78(name, value) {
968
- return [name, value ?? ""];
859
+ function peg$f51(nameStart, name, value) {
860
+ const attribute = {
861
+ name,
862
+ value: value ? value.value : "",
863
+ nameStart,
864
+ nameEnd: nameStart + name.length
865
+ };
866
+ if (value) {
867
+ attribute.valueStart = value.start;
868
+ attribute.valueEnd = value.end;
869
+ if (value.quote) attribute.quote = value.quote;
870
+ }
871
+ return attribute;
872
+ }
873
+ function peg$f52(start, value, end) {
874
+ return {
875
+ value,
876
+ start,
877
+ end,
878
+ quote: "\""
879
+ };
969
880
  }
970
- function peg$f79(v) {
971
- return v;
881
+ function peg$f53(start, value, end) {
882
+ return {
883
+ value,
884
+ start,
885
+ end,
886
+ quote: "'"
887
+ };
972
888
  }
973
- function peg$f80(v) {
974
- return v;
889
+ function peg$f54(q) {
890
+ fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
975
891
  }
976
- function peg$f81(q) {
977
- fail("Unclosed attribute value: the " + q + " here has no closing " + q, location());
892
+ function peg$f55(start, value, end) {
893
+ return {
894
+ value,
895
+ start,
896
+ end
897
+ };
978
898
  }
979
- function peg$f82() {
899
+ function peg$f56() {
980
900
  return !attrCode;
981
901
  }
982
- function peg$f83(bs) {
902
+ function peg$f57(bs) {
983
903
  return bs.length % 2 === 1;
984
904
  }
985
- function peg$f84() {
905
+ function peg$f58() {
986
906
  return !attrCode;
987
907
  }
988
- function peg$f85(start, nameEnd) {
908
+ function peg$f59(start, nameEnd) {
989
909
  return skipTo(hooks.closeBrace(input, nameEnd, start));
990
910
  }
991
- function peg$f86(start, nameEnd) {
911
+ function peg$f60(start, nameEnd) {
992
912
  return skipEnd - offset();
993
913
  }
994
- function peg$f87() {
914
+ function peg$f61() {
995
915
  return !attrCode;
996
916
  }
997
- function peg$f88() {
917
+ function peg$f62() {
998
918
  return attrCode;
999
919
  }
1000
920
  let peg$currPos = options.peg$currPos | 0;
@@ -1055,469 +975,60 @@ function peg$parse(input, options) {
1055
975
  else {
1056
976
  if (pos >= peg$posDetailsCache.length) p = peg$posDetailsCache.length - 1;
1057
977
  else {
1058
- p = pos;
1059
- while (!peg$posDetailsCache[--p]);
1060
- }
1061
- details = peg$posDetailsCache[p];
1062
- details = {
1063
- line: details.line,
1064
- column: details.column
1065
- };
1066
- while (p < pos) {
1067
- if (input.charCodeAt(p) === 10) {
1068
- details.line++;
1069
- details.column = 1;
1070
- } else details.column++;
1071
- p++;
1072
- }
1073
- peg$posDetailsCache[pos] = details;
1074
- return details;
1075
- }
1076
- }
1077
- function peg$computeLocation(startPos, endPos, offset) {
1078
- const startPosDetails = peg$computePosDetails(startPos);
1079
- const endPosDetails = peg$computePosDetails(endPos);
1080
- const res = {
1081
- source: peg$source,
1082
- start: {
1083
- offset: startPos,
1084
- line: startPosDetails.line,
1085
- column: startPosDetails.column
1086
- },
1087
- end: {
1088
- offset: endPos,
1089
- line: endPosDetails.line,
1090
- column: endPosDetails.column
1091
- }
1092
- };
1093
- if (offset && peg$source && typeof peg$source.offset === "function") {
1094
- res.start = peg$source.offset(res.start);
1095
- res.end = peg$source.offset(res.end);
1096
- }
1097
- return res;
1098
- }
1099
- function peg$fail(expected) {
1100
- if (peg$currPos < peg$maxFailPos) return;
1101
- if (peg$currPos > peg$maxFailPos) {
1102
- peg$maxFailPos = peg$currPos;
1103
- peg$maxFailExpected = [];
1104
- }
1105
- peg$maxFailExpected.push(expected);
1106
- }
1107
- function peg$buildSimpleError(message, location) {
1108
- return new peg$SyntaxError(message, null, null, location);
1109
- }
1110
- function peg$buildStructuredError(expected, found, location) {
1111
- return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1112
- }
1113
- function peg$parseMarkup() {
1114
- let s0, s1, s2;
1115
- s0 = peg$currPos;
1116
- s1 = peg$parseContent();
1117
- s2 = peg$parseTail();
1118
- if (s2 !== peg$FAILED) {
1119
- peg$savedPos = s0;
1120
- s0 = peg$f0(s1);
1121
- } else {
1122
- peg$currPos = s0;
1123
- s0 = peg$FAILED;
1124
- }
1125
- return s0;
1126
- }
1127
- function peg$parseTail() {
1128
- let s0, s1;
1129
- s0 = peg$currPos;
1130
- peg$silentFails++;
1131
- if (input.length > peg$currPos) {
1132
- s1 = input.charAt(peg$currPos);
1133
- peg$currPos++;
1134
- } else {
1135
- s1 = peg$FAILED;
1136
- if (peg$silentFails === 0) peg$fail(peg$e0);
1137
- }
1138
- peg$silentFails--;
1139
- if (s1 === peg$FAILED) s0 = void 0;
1140
- else {
1141
- peg$currPos = s0;
1142
- s0 = peg$FAILED;
1143
- }
1144
- if (s0 === peg$FAILED) {
1145
- s0 = peg$currPos;
1146
- s1 = peg$parseBranchTag();
1147
- if (s1 !== peg$FAILED) {
1148
- peg$savedPos = s0;
1149
- s1 = peg$f1(s1);
1150
- }
1151
- s0 = s1;
1152
- if (s0 === peg$FAILED) {
1153
- s0 = peg$currPos;
1154
- s1 = peg$parseCloseTag();
1155
- if (s1 !== peg$FAILED) {
1156
- peg$savedPos = s0;
1157
- s1 = peg$f2(s1);
1158
- }
1159
- s0 = s1;
1160
- }
1161
- }
1162
- return s0;
1163
- }
1164
- function peg$parseContent() {
1165
- let s0, s1, s2;
1166
- s0 = peg$currPos;
1167
- s1 = [];
1168
- s2 = peg$parseItem();
1169
- while (s2 !== peg$FAILED) {
1170
- s1.push(s2);
1171
- s2 = peg$parseItem();
1172
- }
1173
- peg$savedPos = s0;
1174
- s1 = peg$f3(s1);
1175
- s0 = s1;
1176
- return s0;
1177
- }
1178
- function peg$parseItem() {
1179
- let s0;
1180
- s0 = peg$parseTextRun();
1181
- if (s0 === peg$FAILED) {
1182
- s0 = peg$parseEscape();
1183
- if (s0 === peg$FAILED) {
1184
- s0 = peg$parseComment();
1185
- if (s0 === peg$FAILED) {
1186
- s0 = peg$parseLinkLexeme();
1187
- if (s0 === peg$FAILED) {
1188
- s0 = peg$parseEmailAutolink();
1189
- if (s0 === peg$FAILED) {
1190
- s0 = peg$parseHtmlElement();
1191
- if (s0 === peg$FAILED) {
1192
- s0 = peg$parseVoidCloser();
1193
- if (s0 === peg$FAILED) {
1194
- s0 = peg$parseValue();
1195
- if (s0 === peg$FAILED) {
1196
- s0 = peg$parseMacroElement();
1197
- if (s0 === peg$FAILED) s0 = peg$parseLiteral();
1198
- }
1199
- }
1200
- }
1201
- }
1202
- }
1203
- }
1204
- }
1205
- }
1206
- return s0;
1207
- }
1208
- function peg$parseMacroElement() {
1209
- let s0, s1, s2, s3, s4, s5;
1210
- s0 = peg$currPos;
1211
- s1 = peg$parseMacroTag();
1212
- if (s1 !== peg$FAILED) {
1213
- peg$savedPos = peg$currPos;
1214
- s2 = peg$f4(s1);
1215
- if (s2) s2 = void 0;
1216
- else s2 = peg$FAILED;
1217
- if (s2 !== peg$FAILED) {
1218
- s3 = peg$currPos;
1219
- peg$savedPos = peg$currPos;
1220
- s4 = peg$f5(s1);
1221
- if (s4) s4 = void 0;
1222
- else s4 = peg$FAILED;
1223
- if (s4 !== peg$FAILED) {
1224
- s5 = peg$parseRawBody();
1225
- if (s5 !== peg$FAILED) {
1226
- peg$savedPos = s3;
1227
- s3 = peg$f6(s1, s5);
1228
- } else {
1229
- peg$currPos = s3;
1230
- s3 = peg$FAILED;
1231
- }
1232
- } else {
1233
- peg$currPos = s3;
1234
- s3 = peg$FAILED;
1235
- }
1236
- if (s3 === peg$FAILED) {
1237
- s3 = peg$currPos;
1238
- peg$savedPos = peg$currPos;
1239
- s4 = peg$f7(s1);
1240
- if (s4) s4 = void 0;
1241
- else s4 = peg$FAILED;
1242
- if (s4 !== peg$FAILED) {
1243
- s5 = peg$parseBlockBody();
1244
- if (s5 !== peg$FAILED) {
1245
- peg$savedPos = s3;
1246
- s3 = peg$f8(s1, s5);
1247
- } else {
1248
- peg$currPos = s3;
1249
- s3 = peg$FAILED;
1250
- }
1251
- } else {
1252
- peg$currPos = s3;
1253
- s3 = peg$FAILED;
1254
- }
1255
- if (s3 === peg$FAILED) {
1256
- s3 = peg$currPos;
1257
- s4 = "";
1258
- peg$savedPos = s3;
1259
- s4 = peg$f9(s1);
1260
- s3 = s4;
1261
- }
1262
- }
1263
- if (s3 !== peg$FAILED) {
1264
- peg$savedPos = s0;
1265
- s0 = peg$f10(s1, s3);
1266
- } else {
1267
- peg$currPos = s0;
1268
- s0 = peg$FAILED;
1269
- }
1270
- } else {
1271
- peg$currPos = s0;
1272
- s0 = peg$FAILED;
1273
- }
1274
- } else {
1275
- peg$currPos = s0;
1276
- s0 = peg$FAILED;
1277
- }
1278
- return s0;
1279
- }
1280
- function peg$parseHtmlElement() {
1281
- let s0, s1, s2, s3, s4, s5;
1282
- s0 = peg$currPos;
1283
- peg$savedPos = peg$currPos;
1284
- s1 = peg$f11();
1285
- if (s1) s1 = void 0;
1286
- else s1 = peg$FAILED;
1287
- if (s1 !== peg$FAILED) {
1288
- s2 = peg$parseHtmlOpen();
1289
- if (s2 !== peg$FAILED) {
1290
- s3 = peg$currPos;
1291
- peg$savedPos = peg$currPos;
1292
- s4 = peg$f12(s2);
1293
- if (s4) s4 = void 0;
1294
- else s4 = peg$FAILED;
1295
- if (s4 !== peg$FAILED) {
1296
- s5 = peg$parseBlockBody();
1297
- if (s5 !== peg$FAILED) {
1298
- peg$savedPos = s3;
1299
- s3 = peg$f13(s2, s5);
1300
- } else {
1301
- peg$currPos = s3;
1302
- s3 = peg$FAILED;
1303
- }
1304
- } else {
1305
- peg$currPos = s3;
1306
- s3 = peg$FAILED;
1307
- }
1308
- if (s3 === peg$FAILED) s3 = null;
1309
- peg$savedPos = s0;
1310
- s0 = peg$f14(s2, s3);
1311
- } else {
1312
- peg$currPos = s0;
1313
- s0 = peg$FAILED;
1314
- }
1315
- } else {
1316
- peg$currPos = s0;
1317
- s0 = peg$FAILED;
1318
- }
1319
- return s0;
1320
- }
1321
- function peg$parseBlockBody() {
1322
- let s0, s1, s2, s3;
1323
- s0 = peg$currPos;
1324
- s1 = peg$parseContent();
1325
- if (s1 !== peg$FAILED) {
1326
- s2 = [];
1327
- s3 = peg$parseBranchPart();
1328
- while (s3 !== peg$FAILED) {
1329
- s2.push(s3);
1330
- s3 = peg$parseBranchPart();
1331
- }
1332
- s3 = peg$parseBlockEnd();
1333
- if (s3 !== peg$FAILED) {
1334
- peg$savedPos = s0;
1335
- s0 = peg$f15(s1, s2, s3);
1336
- } else {
1337
- peg$currPos = s0;
1338
- s0 = peg$FAILED;
1339
- }
1340
- } else {
1341
- peg$currPos = s0;
1342
- s0 = peg$FAILED;
1343
- }
1344
- return s0;
1345
- }
1346
- function peg$parseBranchPart() {
1347
- let s0, s1, s2;
1348
- s0 = peg$currPos;
1349
- s1 = peg$parseBranchTag();
1350
- if (s1 !== peg$FAILED) {
1351
- s2 = peg$parseContent();
1352
- if (s2 !== peg$FAILED) {
1353
- peg$savedPos = s0;
1354
- s0 = peg$f16(s1, s2);
1355
- } else {
1356
- peg$currPos = s0;
1357
- s0 = peg$FAILED;
1358
- }
1359
- } else {
1360
- peg$currPos = s0;
1361
- s0 = peg$FAILED;
1362
- }
1363
- return s0;
1364
- }
1365
- function peg$parseBlockEnd() {
1366
- let s0, s1, s2;
1367
- s0 = peg$parseCloseTag();
1368
- if (s0 === peg$FAILED) {
1369
- s0 = peg$currPos;
1370
- s1 = peg$currPos;
1371
- peg$silentFails++;
1372
- if (input.length > peg$currPos) {
1373
- s2 = input.charAt(peg$currPos);
1374
- peg$currPos++;
1375
- } else {
1376
- s2 = peg$FAILED;
1377
- if (peg$silentFails === 0) peg$fail(peg$e0);
1378
- }
1379
- peg$silentFails--;
1380
- if (s2 === peg$FAILED) s1 = void 0;
1381
- else {
1382
- peg$currPos = s1;
1383
- s1 = peg$FAILED;
1384
- }
1385
- if (s1 !== peg$FAILED) {
1386
- peg$savedPos = s0;
1387
- s1 = peg$f17();
1388
- }
1389
- s0 = s1;
1390
- }
1391
- return s0;
1392
- }
1393
- function peg$parseBranchTag() {
1394
- let s0, s1, s2;
1395
- s0 = peg$currPos;
1396
- s1 = peg$parseMacroTag();
1397
- if (s1 !== peg$FAILED) {
1398
- peg$savedPos = peg$currPos;
1399
- s2 = peg$f18(s1);
1400
- if (s2) s2 = void 0;
1401
- else s2 = peg$FAILED;
1402
- if (s2 !== peg$FAILED) {
1403
- peg$savedPos = s0;
1404
- s0 = peg$f19(s1);
1405
- } else {
1406
- peg$currPos = s0;
1407
- s0 = peg$FAILED;
1408
- }
1409
- } else {
1410
- peg$currPos = s0;
1411
- s0 = peg$FAILED;
1412
- }
1413
- return s0;
1414
- }
1415
- function peg$parseCloseTag() {
1416
- let s0, s1, s2;
1417
- s0 = peg$currPos;
1418
- s1 = peg$parseMacroTag();
1419
- if (s1 !== peg$FAILED) {
1420
- peg$savedPos = peg$currPos;
1421
- s2 = peg$f20(s1);
1422
- if (s2) s2 = void 0;
1423
- else s2 = peg$FAILED;
1424
- if (s2 !== peg$FAILED) {
1425
- peg$savedPos = s0;
1426
- s0 = peg$f21(s1);
1427
- } else {
1428
- peg$currPos = s0;
1429
- s0 = peg$FAILED;
1430
- }
1431
- } else {
1432
- peg$currPos = s0;
1433
- s0 = peg$FAILED;
1434
- }
1435
- if (s0 === peg$FAILED) {
1436
- s0 = peg$currPos;
1437
- peg$savedPos = peg$currPos;
1438
- s1 = peg$f22();
1439
- if (s1) s1 = void 0;
1440
- else s1 = peg$FAILED;
1441
- if (s1 !== peg$FAILED) {
1442
- s2 = peg$parseHtmlClose();
1443
- if (s2 !== peg$FAILED) {
1444
- peg$savedPos = s0;
1445
- s0 = peg$f23(s2);
1446
- } else {
1447
- peg$currPos = s0;
1448
- s0 = peg$FAILED;
1449
- }
1450
- } else {
1451
- peg$currPos = s0;
1452
- s0 = peg$FAILED;
1453
- }
1454
- }
1455
- return s0;
1456
- }
1457
- function peg$parseRawBody() {
1458
- let s0, s1, s2, s3, s4, s5, s6, s7;
1459
- s0 = peg$currPos;
1460
- s1 = peg$parseHere();
1461
- peg$savedPos = peg$currPos;
1462
- s2 = peg$f24(s1);
1463
- if (s2) s2 = void 0;
1464
- else s2 = peg$FAILED;
1465
- if (s2 !== peg$FAILED) {
1466
- s3 = peg$currPos;
1467
- s4 = peg$f25(s1);
1468
- s5 = peg$currPos;
1469
- s6 = [];
1470
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1471
- else if (input.length > peg$currPos) {
1472
- s7 = input.charAt(peg$currPos);
1473
- peg$currPos++;
1474
- } else {
1475
- s7 = peg$FAILED;
1476
- if (peg$silentFails === 0) peg$fail(peg$e0);
1477
- }
1478
- while (s7 !== peg$FAILED) {
1479
- s6.push(s7);
1480
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1481
- else if (input.length > peg$currPos) {
1482
- s7 = input.charAt(peg$currPos);
1483
- peg$currPos++;
1484
- } else {
1485
- s7 = peg$FAILED;
1486
- if (peg$silentFails === 0) peg$fail(peg$e0);
1487
- }
978
+ p = pos;
979
+ while (!peg$posDetailsCache[--p]);
1488
980
  }
1489
- if (s6.length < (s4 | 0)) {
1490
- peg$currPos = s5;
1491
- s5 = peg$FAILED;
1492
- } else s5 = s6;
1493
- s4 = s5;
1494
- if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
1495
- else s3 = s4;
1496
- if (s3 !== peg$FAILED) {
1497
- s4 = peg$parseCloseTag();
1498
- if (s4 !== peg$FAILED) {
1499
- peg$savedPos = s0;
1500
- s0 = peg$f26(s1, s3, s4);
1501
- } else {
1502
- peg$currPos = s0;
1503
- s0 = peg$FAILED;
1504
- }
1505
- } else {
1506
- peg$currPos = s0;
1507
- s0 = peg$FAILED;
981
+ details = peg$posDetailsCache[p];
982
+ details = {
983
+ line: details.line,
984
+ column: details.column
985
+ };
986
+ while (p < pos) {
987
+ if (input.charCodeAt(p) === 10) {
988
+ details.line++;
989
+ details.column = 1;
990
+ } else details.column++;
991
+ p++;
1508
992
  }
1509
- } else {
1510
- peg$currPos = s0;
1511
- s0 = peg$FAILED;
993
+ peg$posDetailsCache[pos] = details;
994
+ return details;
1512
995
  }
1513
- if (s0 === peg$FAILED) {
1514
- s0 = peg$currPos;
1515
- s1 = "";
1516
- peg$savedPos = s0;
1517
- s1 = peg$f27();
1518
- s0 = s1;
996
+ }
997
+ function peg$computeLocation(startPos, endPos, offset) {
998
+ const startPosDetails = peg$computePosDetails(startPos);
999
+ const endPosDetails = peg$computePosDetails(endPos);
1000
+ const res = {
1001
+ source: peg$source,
1002
+ start: {
1003
+ offset: startPos,
1004
+ line: startPosDetails.line,
1005
+ column: startPosDetails.column
1006
+ },
1007
+ end: {
1008
+ offset: endPos,
1009
+ line: endPosDetails.line,
1010
+ column: endPosDetails.column
1011
+ }
1012
+ };
1013
+ if (offset && peg$source && typeof peg$source.offset === "function") {
1014
+ res.start = peg$source.offset(res.start);
1015
+ res.end = peg$source.offset(res.end);
1519
1016
  }
1520
- return s0;
1017
+ return res;
1018
+ }
1019
+ function peg$fail(expected) {
1020
+ if (peg$currPos < peg$maxFailPos) return;
1021
+ if (peg$currPos > peg$maxFailPos) {
1022
+ peg$maxFailPos = peg$currPos;
1023
+ peg$maxFailExpected = [];
1024
+ }
1025
+ peg$maxFailExpected.push(expected);
1026
+ }
1027
+ function peg$buildSimpleError(message, location) {
1028
+ return new peg$SyntaxError(message, null, null, location);
1029
+ }
1030
+ function peg$buildStructuredError(expected, found, location) {
1031
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1521
1032
  }
1522
1033
  function peg$parseTokens() {
1523
1034
  let s0, s1, s2;
@@ -1529,7 +1040,7 @@ function peg$parse(input, options) {
1529
1040
  s2 = peg$parseTokenItem();
1530
1041
  }
1531
1042
  peg$savedPos = s0;
1532
- s1 = peg$f28(s1);
1043
+ s1 = peg$f0(s1);
1533
1044
  s0 = s1;
1534
1045
  return s0;
1535
1046
  }
@@ -1547,14 +1058,14 @@ function peg$parse(input, options) {
1547
1058
  if (s0 === peg$FAILED) {
1548
1059
  s0 = peg$currPos;
1549
1060
  peg$savedPos = peg$currPos;
1550
- s1 = peg$f29();
1061
+ s1 = peg$f1();
1551
1062
  if (s1) s1 = void 0;
1552
1063
  else s1 = peg$FAILED;
1553
1064
  if (s1 !== peg$FAILED) {
1554
1065
  s2 = peg$parseHtmlOpen();
1555
1066
  if (s2 !== peg$FAILED) {
1556
1067
  peg$savedPos = s0;
1557
- s0 = peg$f30(s2);
1068
+ s0 = peg$f2(s2);
1558
1069
  } else {
1559
1070
  peg$currPos = s0;
1560
1071
  s0 = peg$FAILED;
@@ -1566,14 +1077,14 @@ function peg$parse(input, options) {
1566
1077
  if (s0 === peg$FAILED) {
1567
1078
  s0 = peg$currPos;
1568
1079
  peg$savedPos = peg$currPos;
1569
- s1 = peg$f31();
1080
+ s1 = peg$f3();
1570
1081
  if (s1) s1 = void 0;
1571
1082
  else s1 = peg$FAILED;
1572
1083
  if (s1 !== peg$FAILED) {
1573
1084
  s2 = peg$parseHtmlClose();
1574
1085
  if (s2 !== peg$FAILED) {
1575
1086
  peg$savedPos = s0;
1576
- s0 = peg$f32(s2);
1087
+ s0 = peg$f4(s2);
1577
1088
  } else {
1578
1089
  peg$currPos = s0;
1579
1090
  s0 = peg$FAILED;
@@ -1590,14 +1101,14 @@ function peg$parse(input, options) {
1590
1101
  if (s1 !== peg$FAILED) {
1591
1102
  s2 = peg$currPos;
1592
1103
  peg$savedPos = peg$currPos;
1593
- s3 = peg$f33(s1);
1104
+ s3 = peg$f5(s1);
1594
1105
  if (s3) s3 = void 0;
1595
1106
  else s3 = peg$FAILED;
1596
1107
  if (s3 !== peg$FAILED) {
1597
1108
  s4 = peg$parseRawTokens();
1598
1109
  if (s4 !== peg$FAILED) {
1599
1110
  peg$savedPos = s2;
1600
- s2 = peg$f34(s1, s4);
1111
+ s2 = peg$f6(s1, s4);
1601
1112
  } else {
1602
1113
  peg$currPos = s2;
1603
1114
  s2 = peg$FAILED;
@@ -1608,7 +1119,7 @@ function peg$parse(input, options) {
1608
1119
  }
1609
1120
  if (s2 === peg$FAILED) s2 = null;
1610
1121
  peg$savedPos = s0;
1611
- s0 = peg$f35(s1, s2);
1122
+ s0 = peg$f7(s1, s2);
1612
1123
  } else {
1613
1124
  peg$currPos = s0;
1614
1125
  s0 = peg$FAILED;
@@ -1624,17 +1135,59 @@ function peg$parse(input, options) {
1624
1135
  }
1625
1136
  return s0;
1626
1137
  }
1138
+ function peg$parseCloseTag() {
1139
+ let s0, s1, s2;
1140
+ s0 = peg$currPos;
1141
+ s1 = peg$parseMacroTag();
1142
+ if (s1 !== peg$FAILED) {
1143
+ peg$savedPos = peg$currPos;
1144
+ s2 = peg$f8(s1);
1145
+ if (s2) s2 = void 0;
1146
+ else s2 = peg$FAILED;
1147
+ if (s2 !== peg$FAILED) {
1148
+ peg$savedPos = s0;
1149
+ s0 = peg$f9(s1);
1150
+ } else {
1151
+ peg$currPos = s0;
1152
+ s0 = peg$FAILED;
1153
+ }
1154
+ } else {
1155
+ peg$currPos = s0;
1156
+ s0 = peg$FAILED;
1157
+ }
1158
+ if (s0 === peg$FAILED) {
1159
+ s0 = peg$currPos;
1160
+ peg$savedPos = peg$currPos;
1161
+ s1 = peg$f10();
1162
+ if (s1) s1 = void 0;
1163
+ else s1 = peg$FAILED;
1164
+ if (s1 !== peg$FAILED) {
1165
+ s2 = peg$parseHtmlClose();
1166
+ if (s2 !== peg$FAILED) {
1167
+ peg$savedPos = s0;
1168
+ s0 = peg$f11(s2);
1169
+ } else {
1170
+ peg$currPos = s0;
1171
+ s0 = peg$FAILED;
1172
+ }
1173
+ } else {
1174
+ peg$currPos = s0;
1175
+ s0 = peg$FAILED;
1176
+ }
1177
+ }
1178
+ return s0;
1179
+ }
1627
1180
  function peg$parseRawTokens() {
1628
1181
  let s0, s1, s2, s3, s4, s5, s6, s7;
1629
1182
  s0 = peg$currPos;
1630
1183
  s1 = peg$parseHere();
1631
1184
  peg$savedPos = peg$currPos;
1632
- s2 = peg$f36(s1);
1185
+ s2 = peg$f12(s1);
1633
1186
  if (s2) s2 = void 0;
1634
1187
  else s2 = peg$FAILED;
1635
1188
  if (s2 !== peg$FAILED) {
1636
1189
  s3 = peg$currPos;
1637
- s4 = peg$f37(s1);
1190
+ s4 = peg$f13(s1);
1638
1191
  s5 = peg$currPos;
1639
1192
  s6 = [];
1640
1193
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -1667,7 +1220,7 @@ function peg$parse(input, options) {
1667
1220
  s4 = peg$parseCloseTag();
1668
1221
  if (s4 !== peg$FAILED) {
1669
1222
  peg$savedPos = s0;
1670
- s0 = peg$f38(s1, s3, s4);
1223
+ s0 = peg$f14(s1, s3, s4);
1671
1224
  } else {
1672
1225
  peg$currPos = s0;
1673
1226
  s0 = peg$FAILED;
@@ -1687,7 +1240,7 @@ function peg$parse(input, options) {
1687
1240
  s0 = peg$currPos;
1688
1241
  s1 = "";
1689
1242
  peg$savedPos = s0;
1690
- s1 = peg$f39();
1243
+ s1 = peg$f15();
1691
1244
  s0 = s1;
1692
1245
  return s0;
1693
1246
  }
@@ -1716,7 +1269,7 @@ function peg$parse(input, options) {
1716
1269
  else s1 = s2;
1717
1270
  if (s1 !== peg$FAILED) {
1718
1271
  peg$savedPos = s0;
1719
- s1 = peg$f40(s1);
1272
+ s1 = peg$f16(s1);
1720
1273
  }
1721
1274
  s0 = s1;
1722
1275
  return s0;
@@ -1856,7 +1409,7 @@ function peg$parse(input, options) {
1856
1409
  else s1 = s2;
1857
1410
  if (s1 !== peg$FAILED) {
1858
1411
  peg$savedPos = s0;
1859
- s1 = peg$f41(s1);
1412
+ s1 = peg$f17(s1);
1860
1413
  }
1861
1414
  s0 = s1;
1862
1415
  return s0;
@@ -1889,7 +1442,7 @@ function peg$parse(input, options) {
1889
1442
  if (s1 !== peg$FAILED) {
1890
1443
  s2 = peg$currPos;
1891
1444
  peg$savedPos = peg$currPos;
1892
- s3 = peg$f42(s1);
1445
+ s3 = peg$f18(s1);
1893
1446
  if (s3) s3 = void 0;
1894
1447
  else s3 = peg$FAILED;
1895
1448
  if (s3 !== peg$FAILED) {
@@ -1901,7 +1454,7 @@ function peg$parse(input, options) {
1901
1454
  }
1902
1455
  if (s4 !== peg$FAILED) {
1903
1456
  peg$savedPos = s2;
1904
- s2 = peg$f43(s1, s4);
1457
+ s2 = peg$f19(s1, s4);
1905
1458
  } else {
1906
1459
  peg$currPos = s2;
1907
1460
  s2 = peg$FAILED;
@@ -1912,7 +1465,7 @@ function peg$parse(input, options) {
1912
1465
  }
1913
1466
  if (s2 === peg$FAILED) s2 = null;
1914
1467
  peg$savedPos = s0;
1915
- s0 = peg$f44(s1, s2);
1468
+ s0 = peg$f20(s1, s2);
1916
1469
  } else {
1917
1470
  peg$currPos = s0;
1918
1471
  s0 = peg$FAILED;
@@ -1960,7 +1513,7 @@ function peg$parse(input, options) {
1960
1513
  }
1961
1514
  if (s2 !== peg$FAILED) {
1962
1515
  peg$savedPos = s0;
1963
- s0 = peg$f45();
1516
+ s0 = peg$f21();
1964
1517
  } else {
1965
1518
  peg$currPos = s0;
1966
1519
  s0 = peg$FAILED;
@@ -1975,7 +1528,7 @@ function peg$parse(input, options) {
1975
1528
  peg$silentFails++;
1976
1529
  s2 = peg$currPos;
1977
1530
  peg$savedPos = peg$currPos;
1978
- s3 = peg$f46();
1531
+ s3 = peg$f22();
1979
1532
  if (s3) s3 = void 0;
1980
1533
  else s3 = peg$FAILED;
1981
1534
  if (s3 !== peg$FAILED) {
@@ -2007,7 +1560,7 @@ function peg$parse(input, options) {
2007
1560
  }
2008
1561
  if (s2 !== peg$FAILED) {
2009
1562
  peg$savedPos = s0;
2010
- s0 = peg$f47();
1563
+ s0 = peg$f23();
2011
1564
  } else {
2012
1565
  peg$currPos = s0;
2013
1566
  s0 = peg$FAILED;
@@ -2027,7 +1580,7 @@ function peg$parse(input, options) {
2027
1580
  }
2028
1581
  if (s1 !== peg$FAILED) {
2029
1582
  peg$savedPos = s0;
2030
- s1 = peg$f48();
1583
+ s1 = peg$f24();
2031
1584
  }
2032
1585
  s0 = s1;
2033
1586
  }
@@ -2035,10 +1588,10 @@ function peg$parse(input, options) {
2035
1588
  return s0;
2036
1589
  }
2037
1590
  function peg$parseLinkLexeme() {
2038
- let s0, s1, s2, s3, s4, s5, s6;
1591
+ let s0, s1, s2, s3, s4, s5, s6, s7;
2039
1592
  s0 = peg$currPos;
2040
1593
  peg$savedPos = peg$currPos;
2041
- s1 = peg$f49();
1594
+ s1 = peg$f25();
2042
1595
  if (s1) s1 = void 0;
2043
1596
  else s1 = peg$FAILED;
2044
1597
  if (s1 !== peg$FAILED) {
@@ -2050,22 +1603,23 @@ function peg$parse(input, options) {
2050
1603
  if (peg$silentFails === 0) peg$fail(peg$e12);
2051
1604
  }
2052
1605
  if (s2 !== peg$FAILED) {
2053
- s3 = peg$parseSelectors();
2054
- if (s3 !== peg$FAILED) {
2055
- s4 = peg$parseHere();
2056
- s5 = peg$currPos;
2057
- s6 = peg$parseLinkText();
2058
- s5 = input.substring(s5, peg$currPos);
1606
+ s3 = peg$parseHere();
1607
+ s4 = peg$parseSelectors();
1608
+ if (s4 !== peg$FAILED) {
1609
+ s5 = peg$parseHere();
1610
+ s6 = peg$currPos;
1611
+ s7 = peg$parseLinkText();
1612
+ s6 = input.substring(s6, peg$currPos);
2059
1613
  if (input.substr(peg$currPos, 2) === peg$c9) {
2060
- s6 = peg$c9;
1614
+ s7 = peg$c9;
2061
1615
  peg$currPos += 2;
2062
1616
  } else {
2063
- s6 = peg$FAILED;
1617
+ s7 = peg$FAILED;
2064
1618
  if (peg$silentFails === 0) peg$fail(peg$e13);
2065
1619
  }
2066
- if (s6 !== peg$FAILED) {
1620
+ if (s7 !== peg$FAILED) {
2067
1621
  peg$savedPos = s0;
2068
- s0 = peg$f50(s3, s4, s5);
1622
+ s0 = peg$f26(s3, s4, s5, s6);
2069
1623
  } else {
2070
1624
  peg$currPos = s0;
2071
1625
  s0 = peg$FAILED;
@@ -2085,7 +1639,7 @@ function peg$parse(input, options) {
2085
1639
  if (s0 === peg$FAILED) {
2086
1640
  s0 = peg$currPos;
2087
1641
  peg$savedPos = peg$currPos;
2088
- s1 = peg$f51();
1642
+ s1 = peg$f27();
2089
1643
  if (s1) s1 = void 0;
2090
1644
  else s1 = peg$FAILED;
2091
1645
  if (s1 !== peg$FAILED) {
@@ -2098,7 +1652,7 @@ function peg$parse(input, options) {
2098
1652
  }
2099
1653
  if (s2 !== peg$FAILED) {
2100
1654
  peg$savedPos = s0;
2101
- s0 = peg$f52();
1655
+ s0 = peg$f28();
2102
1656
  } else {
2103
1657
  peg$currPos = s0;
2104
1658
  s0 = peg$FAILED;
@@ -2222,7 +1776,7 @@ function peg$parse(input, options) {
2222
1776
  }
2223
1777
  if (s2 === peg$FAILED) s2 = null;
2224
1778
  peg$savedPos = s0;
2225
- s0 = peg$f53(s1);
1779
+ s0 = peg$f29(s1);
2226
1780
  } else {
2227
1781
  peg$currPos = s0;
2228
1782
  s0 = peg$FAILED;
@@ -2231,7 +1785,7 @@ function peg$parse(input, options) {
2231
1785
  s0 = peg$currPos;
2232
1786
  s1 = "";
2233
1787
  peg$savedPos = s0;
2234
- s1 = peg$f54();
1788
+ s1 = peg$f30();
2235
1789
  s0 = s1;
2236
1790
  }
2237
1791
  return s0;
@@ -2261,7 +1815,7 @@ function peg$parse(input, options) {
2261
1815
  }
2262
1816
  }
2263
1817
  peg$savedPos = s0;
2264
- s0 = peg$f55(s1, s2);
1818
+ s0 = peg$f31(s1, s2);
2265
1819
  } else {
2266
1820
  peg$currPos = s0;
2267
1821
  s0 = peg$FAILED;
@@ -2287,7 +1841,7 @@ function peg$parse(input, options) {
2287
1841
  }
2288
1842
  s2 = input.substring(s2, peg$currPos);
2289
1843
  peg$savedPos = s0;
2290
- s0 = peg$f56(s1, s2);
1844
+ s0 = peg$f32(s1, s2);
2291
1845
  } else {
2292
1846
  peg$currPos = s0;
2293
1847
  s0 = peg$FAILED;
@@ -2366,7 +1920,7 @@ function peg$parse(input, options) {
2366
1920
  return s0;
2367
1921
  }
2368
1922
  function peg$parseValue() {
2369
- let s0, s1, s2, s3, s4, s5, s6;
1923
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
2370
1924
  s0 = peg$currPos;
2371
1925
  if (input.charCodeAt(peg$currPos) === 123) {
2372
1926
  s1 = peg$c5;
@@ -2376,43 +1930,45 @@ function peg$parse(input, options) {
2376
1930
  if (peg$silentFails === 0) peg$fail(peg$e8);
2377
1931
  }
2378
1932
  if (s1 !== peg$FAILED) {
2379
- s2 = peg$parseSelectors();
2380
- if (s2 !== peg$FAILED) {
2381
- s3 = input.charAt(peg$currPos);
2382
- if (peg$r5.test(s3)) peg$currPos++;
1933
+ s2 = peg$parseHere();
1934
+ s3 = peg$parseSelectors();
1935
+ if (s3 !== peg$FAILED) {
1936
+ s4 = input.charAt(peg$currPos);
1937
+ if (peg$r5.test(s4)) peg$currPos++;
2383
1938
  else {
2384
- s3 = peg$FAILED;
1939
+ s4 = peg$FAILED;
2385
1940
  if (peg$silentFails === 0) peg$fail(peg$e17);
2386
1941
  }
2387
- if (s3 !== peg$FAILED) {
2388
- s4 = peg$currPos;
2389
- s5 = [];
2390
- s6 = input.charAt(peg$currPos);
2391
- if (peg$r6.test(s6)) peg$currPos++;
1942
+ if (s4 !== peg$FAILED) {
1943
+ s5 = peg$parseHere();
1944
+ s6 = peg$currPos;
1945
+ s7 = [];
1946
+ s8 = input.charAt(peg$currPos);
1947
+ if (peg$r6.test(s8)) peg$currPos++;
2392
1948
  else {
2393
- s6 = peg$FAILED;
1949
+ s8 = peg$FAILED;
2394
1950
  if (peg$silentFails === 0) peg$fail(peg$e18);
2395
1951
  }
2396
- while (s6 !== peg$FAILED) {
2397
- s5.push(s6);
2398
- s6 = input.charAt(peg$currPos);
2399
- if (peg$r6.test(s6)) peg$currPos++;
1952
+ while (s8 !== peg$FAILED) {
1953
+ s7.push(s8);
1954
+ s8 = input.charAt(peg$currPos);
1955
+ if (peg$r6.test(s8)) peg$currPos++;
2400
1956
  else {
2401
- s6 = peg$FAILED;
1957
+ s8 = peg$FAILED;
2402
1958
  if (peg$silentFails === 0) peg$fail(peg$e18);
2403
1959
  }
2404
1960
  }
2405
- s4 = input.substring(s4, peg$currPos);
1961
+ s6 = input.substring(s6, peg$currPos);
2406
1962
  if (input.charCodeAt(peg$currPos) === 125) {
2407
- s5 = peg$c11;
1963
+ s7 = peg$c11;
2408
1964
  peg$currPos++;
2409
1965
  } else {
2410
- s5 = peg$FAILED;
1966
+ s7 = peg$FAILED;
2411
1967
  if (peg$silentFails === 0) peg$fail(peg$e19);
2412
1968
  }
2413
- if (s5 !== peg$FAILED) {
1969
+ if (s7 !== peg$FAILED) {
2414
1970
  peg$savedPos = s0;
2415
- s0 = peg$f57(s2, s3, s4);
1971
+ s0 = peg$f33(s2, s3, s4, s5, s6);
2416
1972
  } else {
2417
1973
  peg$currPos = s0;
2418
1974
  s0 = peg$FAILED;
@@ -2439,34 +1995,36 @@ function peg$parse(input, options) {
2439
1995
  if (peg$silentFails === 0) peg$fail(peg$e8);
2440
1996
  }
2441
1997
  if (s1 !== peg$FAILED) {
2442
- s2 = peg$parseSelectors();
2443
- if (s2 !== peg$FAILED) {
2444
- s3 = peg$currPos;
1998
+ s2 = peg$parseHere();
1999
+ s3 = peg$parseSelectors();
2000
+ if (s3 !== peg$FAILED) {
2001
+ s4 = peg$parseHere();
2002
+ s5 = peg$currPos;
2445
2003
  peg$silentFails++;
2446
- s4 = input.charAt(peg$currPos);
2447
- if (peg$r7.test(s4)) peg$currPos++;
2004
+ s6 = input.charAt(peg$currPos);
2005
+ if (peg$r7.test(s6)) peg$currPos++;
2448
2006
  else {
2449
- s4 = peg$FAILED;
2007
+ s6 = peg$FAILED;
2450
2008
  if (peg$silentFails === 0) peg$fail(peg$e20);
2451
2009
  }
2452
2010
  peg$silentFails--;
2453
- if (s4 !== peg$FAILED) {
2454
- peg$currPos = s3;
2455
- s3 = void 0;
2456
- } else s3 = peg$FAILED;
2457
- if (s3 !== peg$FAILED) {
2458
- s4 = peg$parseCodeToBrace();
2459
- if (s4 !== peg$FAILED) {
2011
+ if (s6 !== peg$FAILED) {
2012
+ peg$currPos = s5;
2013
+ s5 = void 0;
2014
+ } else s5 = peg$FAILED;
2015
+ if (s5 !== peg$FAILED) {
2016
+ s6 = peg$parseCodeToBrace();
2017
+ if (s6 !== peg$FAILED) {
2460
2018
  if (input.charCodeAt(peg$currPos) === 125) {
2461
- s5 = peg$c11;
2019
+ s7 = peg$c11;
2462
2020
  peg$currPos++;
2463
2021
  } else {
2464
- s5 = peg$FAILED;
2022
+ s7 = peg$FAILED;
2465
2023
  if (peg$silentFails === 0) peg$fail(peg$e19);
2466
2024
  }
2467
- if (s5 !== peg$FAILED) {
2025
+ if (s7 !== peg$FAILED) {
2468
2026
  peg$savedPos = s0;
2469
- s0 = peg$f58(s2, s4);
2027
+ s0 = peg$f34(s2, s3, s4, s6);
2470
2028
  } else {
2471
2029
  peg$currPos = s0;
2472
2030
  s0 = peg$FAILED;
@@ -2514,7 +2072,7 @@ function peg$parse(input, options) {
2514
2072
  } else s3 = peg$FAILED;
2515
2073
  if (s3 !== peg$FAILED) {
2516
2074
  peg$savedPos = s0;
2517
- s0 = peg$f59();
2075
+ s0 = peg$f35();
2518
2076
  } else {
2519
2077
  peg$currPos = s0;
2520
2078
  s0 = peg$FAILED;
@@ -2536,12 +2094,12 @@ function peg$parse(input, options) {
2536
2094
  s0 = peg$currPos;
2537
2095
  s1 = peg$parseHere();
2538
2096
  peg$savedPos = peg$currPos;
2539
- s2 = peg$f60(s1);
2097
+ s2 = peg$f36(s1);
2540
2098
  if (s2) s2 = void 0;
2541
2099
  else s2 = peg$FAILED;
2542
2100
  if (s2 !== peg$FAILED) {
2543
2101
  s3 = peg$currPos;
2544
- s4 = peg$f61(s1);
2102
+ s4 = peg$f37(s1);
2545
2103
  s5 = peg$currPos;
2546
2104
  s6 = [];
2547
2105
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2572,7 +2130,7 @@ function peg$parse(input, options) {
2572
2130
  else s3 = s4;
2573
2131
  if (s3 !== peg$FAILED) {
2574
2132
  peg$savedPos = s0;
2575
- s0 = peg$f62(s1, s3);
2133
+ s0 = peg$f38(s1, s3);
2576
2134
  } else {
2577
2135
  peg$currPos = s0;
2578
2136
  s0 = peg$FAILED;
@@ -2584,7 +2142,7 @@ function peg$parse(input, options) {
2584
2142
  return s0;
2585
2143
  }
2586
2144
  function peg$parseMacroTag() {
2587
- let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
2145
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
2588
2146
  s0 = peg$currPos;
2589
2147
  if (input.charCodeAt(peg$currPos) === 123) {
2590
2148
  s1 = peg$c5;
@@ -2594,82 +2152,83 @@ function peg$parse(input, options) {
2594
2152
  if (peg$silentFails === 0) peg$fail(peg$e8);
2595
2153
  }
2596
2154
  if (s1 !== peg$FAILED) {
2597
- s2 = peg$parseSelectors();
2598
- if (s2 !== peg$FAILED) {
2599
- s3 = peg$parseHere();
2155
+ s2 = peg$parseHere();
2156
+ s3 = peg$parseSelectors();
2157
+ if (s3 !== peg$FAILED) {
2158
+ s4 = peg$parseHere();
2600
2159
  if (input.charCodeAt(peg$currPos) === 47) {
2601
- s4 = peg$c12;
2160
+ s5 = peg$c12;
2602
2161
  peg$currPos++;
2603
2162
  } else {
2604
- s4 = peg$FAILED;
2163
+ s5 = peg$FAILED;
2605
2164
  if (peg$silentFails === 0) peg$fail(peg$e21);
2606
2165
  }
2607
- if (s4 === peg$FAILED) s4 = null;
2608
- s5 = peg$parseMacroName();
2609
- if (s5 !== peg$FAILED) {
2610
- s6 = peg$parseHere();
2611
- s7 = peg$currPos;
2166
+ if (s5 === peg$FAILED) s5 = null;
2167
+ s6 = peg$parseMacroName();
2168
+ if (s6 !== peg$FAILED) {
2169
+ s7 = peg$parseHere();
2170
+ s8 = peg$currPos;
2612
2171
  peg$savedPos = peg$currPos;
2613
- s8 = peg$f63(s2, s3, s4, s5, s6);
2614
- if (s8) s8 = void 0;
2615
- else s8 = peg$FAILED;
2616
- if (s8 !== peg$FAILED) {
2617
- s9 = peg$currPos;
2618
- s10 = peg$f64(s2, s3, s4, s5, s6);
2619
- s11 = peg$currPos;
2620
- s12 = [];
2621
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2172
+ s9 = peg$f39(s2, s3, s4, s5, s6, s7);
2173
+ if (s9) s9 = void 0;
2174
+ else s9 = peg$FAILED;
2175
+ if (s9 !== peg$FAILED) {
2176
+ s10 = peg$currPos;
2177
+ s11 = peg$f40(s2, s3, s4, s5, s6, s7);
2178
+ s12 = peg$currPos;
2179
+ s13 = [];
2180
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2622
2181
  else if (input.length > peg$currPos) {
2623
- s13 = input.charAt(peg$currPos);
2182
+ s14 = input.charAt(peg$currPos);
2624
2183
  peg$currPos++;
2625
2184
  } else {
2626
- s13 = peg$FAILED;
2185
+ s14 = peg$FAILED;
2627
2186
  if (peg$silentFails === 0) peg$fail(peg$e0);
2628
2187
  }
2629
- while (s13 !== peg$FAILED) {
2630
- s12.push(s13);
2631
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2188
+ while (s14 !== peg$FAILED) {
2189
+ s13.push(s14);
2190
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2632
2191
  else if (input.length > peg$currPos) {
2633
- s13 = input.charAt(peg$currPos);
2192
+ s14 = input.charAt(peg$currPos);
2634
2193
  peg$currPos++;
2635
2194
  } else {
2636
- s13 = peg$FAILED;
2195
+ s14 = peg$FAILED;
2637
2196
  if (peg$silentFails === 0) peg$fail(peg$e0);
2638
2197
  }
2639
2198
  }
2640
- if (s12.length < (s10 | 0)) {
2641
- peg$currPos = s11;
2642
- s11 = peg$FAILED;
2643
- } else s11 = s12;
2644
- s10 = s11;
2645
- if (s10 !== peg$FAILED) s9 = input.substring(s9, peg$currPos);
2646
- else s9 = s10;
2647
- if (s9 !== peg$FAILED) {
2199
+ if (s13.length < (s11 | 0)) {
2200
+ peg$currPos = s12;
2201
+ s12 = peg$FAILED;
2202
+ } else s12 = s13;
2203
+ s11 = s12;
2204
+ if (s11 !== peg$FAILED) s10 = input.substring(s10, peg$currPos);
2205
+ else s10 = s11;
2206
+ if (s10 !== peg$FAILED) {
2648
2207
  if (input.charCodeAt(peg$currPos) === 125) {
2649
- s10 = peg$c11;
2208
+ s11 = peg$c11;
2650
2209
  peg$currPos++;
2651
2210
  } else {
2652
- s10 = peg$FAILED;
2211
+ s11 = peg$FAILED;
2653
2212
  if (peg$silentFails === 0) peg$fail(peg$e19);
2654
2213
  }
2655
- if (s10 !== peg$FAILED) {
2656
- peg$savedPos = s7;
2657
- s7 = peg$f65(s2, s3, s4, s5, s6, s9);
2214
+ if (s11 !== peg$FAILED) {
2215
+ peg$savedPos = s8;
2216
+ s8 = peg$f41(s2, s3, s4, s5, s6, s7, s10);
2658
2217
  } else {
2659
- peg$currPos = s7;
2660
- s7 = peg$FAILED;
2218
+ peg$currPos = s8;
2219
+ s8 = peg$FAILED;
2661
2220
  }
2662
2221
  } else {
2663
- peg$currPos = s7;
2664
- s7 = peg$FAILED;
2222
+ peg$currPos = s8;
2223
+ s8 = peg$FAILED;
2665
2224
  }
2666
2225
  } else {
2667
- peg$currPos = s7;
2668
- s7 = peg$FAILED;
2226
+ peg$currPos = s8;
2227
+ s8 = peg$FAILED;
2669
2228
  }
2670
- if (s7 === peg$FAILED) s7 = null;
2229
+ if (s8 === peg$FAILED) s8 = null;
2671
2230
  peg$savedPos = s0;
2672
- s0 = peg$f66(s2, s3, s4, s5, s6, s7);
2231
+ s0 = peg$f42(s2, s3, s4, s5, s6, s7, s8);
2673
2232
  } else {
2674
2233
  peg$currPos = s0;
2675
2234
  s0 = peg$FAILED;
@@ -2703,7 +2262,7 @@ function peg$parse(input, options) {
2703
2262
  }
2704
2263
  if (s3 !== peg$FAILED) {
2705
2264
  peg$savedPos = s0;
2706
- s0 = peg$f67(s2);
2265
+ s0 = peg$f43(s2);
2707
2266
  } else {
2708
2267
  peg$currPos = s0;
2709
2268
  s0 = peg$FAILED;
@@ -2853,43 +2412,12 @@ function peg$parse(input, options) {
2853
2412
  else s1 = s2;
2854
2413
  if (s1 !== peg$FAILED) {
2855
2414
  peg$savedPos = peg$currPos;
2856
- s2 = peg$f68(s1);
2415
+ s2 = peg$f44(s1);
2857
2416
  if (s2) s2 = void 0;
2858
2417
  else s2 = peg$FAILED;
2859
2418
  if (s2 !== peg$FAILED) {
2860
2419
  peg$savedPos = s0;
2861
- s0 = peg$f69(s1);
2862
- } else {
2863
- peg$currPos = s0;
2864
- s0 = peg$FAILED;
2865
- }
2866
- } else {
2867
- peg$currPos = s0;
2868
- s0 = peg$FAILED;
2869
- }
2870
- return s0;
2871
- }
2872
- function peg$parseVoidCloser() {
2873
- let s0, s1, s2, s3;
2874
- s0 = peg$currPos;
2875
- peg$savedPos = peg$currPos;
2876
- s1 = peg$f70();
2877
- if (s1) s1 = void 0;
2878
- else s1 = peg$FAILED;
2879
- if (s1 !== peg$FAILED) {
2880
- s2 = peg$parseHtmlClose();
2881
- if (s2 !== peg$FAILED) {
2882
- peg$savedPos = peg$currPos;
2883
- s3 = peg$f71(s2);
2884
- if (s3) s3 = void 0;
2885
- else s3 = peg$FAILED;
2886
- if (s3 !== peg$FAILED) {
2887
- peg$savedPos = s0;
2888
- s0 = peg$f72(s2);
2889
- } else {
2890
- peg$currPos = s0;
2891
- s0 = peg$FAILED;
2892
- }
2420
+ s0 = peg$f45(s1);
2893
2421
  } else {
2894
2422
  peg$currPos = s0;
2895
2423
  s0 = peg$FAILED;
@@ -2901,7 +2429,7 @@ function peg$parse(input, options) {
2901
2429
  return s0;
2902
2430
  }
2903
2431
  function peg$parseHtmlOpen() {
2904
- let s0, s1, s2, s3, s4, s5, s6;
2432
+ let s0, s1, s2, s3, s4, s5, s6, s7;
2905
2433
  s0 = peg$currPos;
2906
2434
  if (input.charCodeAt(peg$currPos) === 60) {
2907
2435
  s1 = peg$c6;
@@ -2911,33 +2439,34 @@ function peg$parse(input, options) {
2911
2439
  if (peg$silentFails === 0) peg$fail(peg$e10);
2912
2440
  }
2913
2441
  if (s1 !== peg$FAILED) {
2914
- s2 = peg$parseTagName();
2915
- if (s2 !== peg$FAILED) {
2916
- s3 = [];
2917
- s4 = peg$parseAttribute();
2918
- while (s4 !== peg$FAILED) {
2919
- s3.push(s4);
2920
- s4 = peg$parseAttribute();
2442
+ s2 = peg$parseHere();
2443
+ s3 = peg$parseTagName();
2444
+ if (s3 !== peg$FAILED) {
2445
+ s4 = [];
2446
+ s5 = peg$parseAttribute();
2447
+ while (s5 !== peg$FAILED) {
2448
+ s4.push(s5);
2449
+ s5 = peg$parseAttribute();
2921
2450
  }
2922
- s4 = peg$parse_();
2451
+ s5 = peg$parse_();
2923
2452
  if (input.charCodeAt(peg$currPos) === 47) {
2924
- s5 = peg$c12;
2453
+ s6 = peg$c12;
2925
2454
  peg$currPos++;
2926
2455
  } else {
2927
- s5 = peg$FAILED;
2456
+ s6 = peg$FAILED;
2928
2457
  if (peg$silentFails === 0) peg$fail(peg$e21);
2929
2458
  }
2930
- if (s5 === peg$FAILED) s5 = null;
2459
+ if (s6 === peg$FAILED) s6 = null;
2931
2460
  if (input.charCodeAt(peg$currPos) === 62) {
2932
- s6 = peg$c1;
2461
+ s7 = peg$c1;
2933
2462
  peg$currPos++;
2934
2463
  } else {
2935
- s6 = peg$FAILED;
2464
+ s7 = peg$FAILED;
2936
2465
  if (peg$silentFails === 0) peg$fail(peg$e3);
2937
2466
  }
2938
- if (s6 !== peg$FAILED) {
2467
+ if (s7 !== peg$FAILED) {
2939
2468
  peg$savedPos = s0;
2940
- s0 = peg$f73(s2, s3, s5);
2469
+ s0 = peg$f46(s2, s3, s4, s6);
2941
2470
  } else {
2942
2471
  peg$currPos = s0;
2943
2472
  s0 = peg$FAILED;
@@ -3002,7 +2531,7 @@ function peg$parse(input, options) {
3002
2531
  s5 = peg$parse_();
3003
2532
  s6 = peg$parseHere();
3004
2533
  peg$savedPos = s0;
3005
- s0 = peg$f74(s2, s6);
2534
+ s0 = peg$f47(s2, s6);
3006
2535
  } else {
3007
2536
  peg$currPos = s0;
3008
2537
  s0 = peg$FAILED;
@@ -3019,7 +2548,7 @@ function peg$parse(input, options) {
3019
2548
  return s0;
3020
2549
  }
3021
2550
  function peg$parseHtmlClose() {
3022
- let s0, s1, s2, s4;
2551
+ let s0, s1, s2, s3, s5;
3023
2552
  s0 = peg$currPos;
3024
2553
  if (input.substr(peg$currPos, 2) === peg$c14) {
3025
2554
  s1 = peg$c14;
@@ -3029,19 +2558,20 @@ function peg$parse(input, options) {
3029
2558
  if (peg$silentFails === 0) peg$fail(peg$e28);
3030
2559
  }
3031
2560
  if (s1 !== peg$FAILED) {
3032
- s2 = peg$parseTagName();
3033
- if (s2 !== peg$FAILED) {
2561
+ s2 = peg$parseHere();
2562
+ s3 = peg$parseTagName();
2563
+ if (s3 !== peg$FAILED) {
3034
2564
  peg$parse_();
3035
2565
  if (input.charCodeAt(peg$currPos) === 62) {
3036
- s4 = peg$c1;
2566
+ s5 = peg$c1;
3037
2567
  peg$currPos++;
3038
2568
  } else {
3039
- s4 = peg$FAILED;
2569
+ s5 = peg$FAILED;
3040
2570
  if (peg$silentFails === 0) peg$fail(peg$e3);
3041
2571
  }
3042
- if (s4 !== peg$FAILED) {
2572
+ if (s5 !== peg$FAILED) {
3043
2573
  peg$savedPos = s0;
3044
- s0 = peg$f75(s2);
2574
+ s0 = peg$f48(s2, s3);
3045
2575
  } else {
3046
2576
  peg$currPos = s0;
3047
2577
  s0 = peg$FAILED;
@@ -3094,117 +2624,118 @@ function peg$parse(input, options) {
3094
2624
  return s0;
3095
2625
  }
3096
2626
  function peg$parseAttribute() {
3097
- let s0, s2, s3, s4, s5, s6, s8;
2627
+ let s0, s2, s3, s4, s5, s6, s7, s9;
3098
2628
  s0 = peg$currPos;
3099
2629
  peg$parse_();
3100
- s2 = peg$currPos;
3101
- s3 = [];
3102
- s4 = peg$currPos;
2630
+ s2 = peg$parseHere();
2631
+ s3 = peg$currPos;
2632
+ s4 = [];
3103
2633
  s5 = peg$currPos;
2634
+ s6 = peg$currPos;
3104
2635
  peg$silentFails++;
3105
- s6 = input.charAt(peg$currPos);
3106
- if (peg$r14.test(s6)) peg$currPos++;
2636
+ s7 = input.charAt(peg$currPos);
2637
+ if (peg$r14.test(s7)) peg$currPos++;
3107
2638
  else {
3108
- s6 = peg$FAILED;
2639
+ s7 = peg$FAILED;
3109
2640
  if (peg$silentFails === 0) peg$fail(peg$e30);
3110
2641
  }
3111
2642
  peg$silentFails--;
3112
- if (s6 === peg$FAILED) s5 = void 0;
2643
+ if (s7 === peg$FAILED) s6 = void 0;
3113
2644
  else {
3114
- peg$currPos = s5;
3115
- s5 = peg$FAILED;
2645
+ peg$currPos = s6;
2646
+ s6 = peg$FAILED;
3116
2647
  }
3117
- if (s5 !== peg$FAILED) {
2648
+ if (s6 !== peg$FAILED) {
3118
2649
  if (input.length > peg$currPos) {
3119
- s6 = input.charAt(peg$currPos);
2650
+ s7 = input.charAt(peg$currPos);
3120
2651
  peg$currPos++;
3121
2652
  } else {
3122
- s6 = peg$FAILED;
2653
+ s7 = peg$FAILED;
3123
2654
  if (peg$silentFails === 0) peg$fail(peg$e0);
3124
2655
  }
3125
- if (s6 !== peg$FAILED) {
3126
- s5 = [s5, s6];
3127
- s4 = s5;
2656
+ if (s7 !== peg$FAILED) {
2657
+ s6 = [s6, s7];
2658
+ s5 = s6;
3128
2659
  } else {
3129
- peg$currPos = s4;
3130
- s4 = peg$FAILED;
2660
+ peg$currPos = s5;
2661
+ s5 = peg$FAILED;
3131
2662
  }
3132
2663
  } else {
3133
- peg$currPos = s4;
3134
- s4 = peg$FAILED;
2664
+ peg$currPos = s5;
2665
+ s5 = peg$FAILED;
3135
2666
  }
3136
- if (s4 !== peg$FAILED) while (s4 !== peg$FAILED) {
3137
- s3.push(s4);
3138
- s4 = peg$currPos;
2667
+ if (s5 !== peg$FAILED) while (s5 !== peg$FAILED) {
2668
+ s4.push(s5);
3139
2669
  s5 = peg$currPos;
2670
+ s6 = peg$currPos;
3140
2671
  peg$silentFails++;
3141
- s6 = input.charAt(peg$currPos);
3142
- if (peg$r14.test(s6)) peg$currPos++;
2672
+ s7 = input.charAt(peg$currPos);
2673
+ if (peg$r14.test(s7)) peg$currPos++;
3143
2674
  else {
3144
- s6 = peg$FAILED;
2675
+ s7 = peg$FAILED;
3145
2676
  if (peg$silentFails === 0) peg$fail(peg$e30);
3146
2677
  }
3147
2678
  peg$silentFails--;
3148
- if (s6 === peg$FAILED) s5 = void 0;
2679
+ if (s7 === peg$FAILED) s6 = void 0;
3149
2680
  else {
3150
- peg$currPos = s5;
3151
- s5 = peg$FAILED;
2681
+ peg$currPos = s6;
2682
+ s6 = peg$FAILED;
3152
2683
  }
3153
- if (s5 !== peg$FAILED) {
2684
+ if (s6 !== peg$FAILED) {
3154
2685
  if (input.length > peg$currPos) {
3155
- s6 = input.charAt(peg$currPos);
2686
+ s7 = input.charAt(peg$currPos);
3156
2687
  peg$currPos++;
3157
2688
  } else {
3158
- s6 = peg$FAILED;
2689
+ s7 = peg$FAILED;
3159
2690
  if (peg$silentFails === 0) peg$fail(peg$e0);
3160
2691
  }
3161
- if (s6 !== peg$FAILED) {
3162
- s5 = [s5, s6];
3163
- s4 = s5;
2692
+ if (s7 !== peg$FAILED) {
2693
+ s6 = [s6, s7];
2694
+ s5 = s6;
3164
2695
  } else {
3165
- peg$currPos = s4;
3166
- s4 = peg$FAILED;
2696
+ peg$currPos = s5;
2697
+ s5 = peg$FAILED;
3167
2698
  }
3168
2699
  } else {
3169
- peg$currPos = s4;
3170
- s4 = peg$FAILED;
2700
+ peg$currPos = s5;
2701
+ s5 = peg$FAILED;
3171
2702
  }
3172
2703
  }
3173
- else s3 = peg$FAILED;
3174
- if (s3 !== peg$FAILED) s2 = input.substring(s2, peg$currPos);
3175
- else s2 = s3;
3176
- if (s2 !== peg$FAILED) {
2704
+ else s4 = peg$FAILED;
2705
+ if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
2706
+ else s3 = s4;
2707
+ if (s3 !== peg$FAILED) {
3177
2708
  peg$savedPos = peg$currPos;
3178
- s3 = peg$f76(s2);
3179
- if (s3) s3 = void 0;
3180
- else s3 = peg$FAILED;
3181
- if (s3 !== peg$FAILED) {
3182
- s4 = peg$currPos;
3183
- s5 = peg$parse_();
2709
+ s4 = peg$f49(s2, s3);
2710
+ if (s4) s4 = void 0;
2711
+ else s4 = peg$FAILED;
2712
+ if (s4 !== peg$FAILED) {
2713
+ s5 = peg$currPos;
2714
+ s6 = peg$parse_();
3184
2715
  if (input.charCodeAt(peg$currPos) === 61) {
3185
- s6 = peg$c15;
2716
+ s7 = peg$c15;
3186
2717
  peg$currPos++;
3187
2718
  } else {
3188
- s6 = peg$FAILED;
2719
+ s7 = peg$FAILED;
3189
2720
  if (peg$silentFails === 0) peg$fail(peg$e31);
3190
2721
  }
3191
- if (s6 !== peg$FAILED) {
2722
+ if (s7 !== peg$FAILED) {
3192
2723
  peg$parse_();
3193
- s8 = peg$parseAttrValue();
3194
- if (s8 !== peg$FAILED) {
3195
- peg$savedPos = s4;
3196
- s4 = peg$f77(s2, s8);
2724
+ s9 = peg$parseAttrValue();
2725
+ if (s9 !== peg$FAILED) {
2726
+ peg$savedPos = s5;
2727
+ s5 = peg$f50(s2, s3, s9);
3197
2728
  } else {
3198
- peg$currPos = s4;
3199
- s4 = peg$FAILED;
2729
+ peg$currPos = s5;
2730
+ s5 = peg$FAILED;
3200
2731
  }
3201
2732
  } else {
3202
- peg$currPos = s4;
3203
- s4 = peg$FAILED;
2733
+ peg$currPos = s5;
2734
+ s5 = peg$FAILED;
3204
2735
  }
3205
- if (s4 === peg$FAILED) s4 = null;
2736
+ if (s5 === peg$FAILED) s5 = null;
3206
2737
  peg$savedPos = s0;
3207
- s0 = peg$f78(s2, s4);
2738
+ s0 = peg$f51(s2, s3, s5);
3208
2739
  } else {
3209
2740
  peg$currPos = s0;
3210
2741
  s0 = peg$FAILED;
@@ -3216,7 +2747,7 @@ function peg$parse(input, options) {
3216
2747
  return s0;
3217
2748
  }
3218
2749
  function peg$parseAttrValue() {
3219
- let s0, s1, s2, s3, s4;
2750
+ let s0, s1, s2, s3, s4, s5;
3220
2751
  s0 = peg$currPos;
3221
2752
  if (input.charCodeAt(peg$currPos) === 34) {
3222
2753
  s1 = peg$c16;
@@ -3226,40 +2757,42 @@ function peg$parse(input, options) {
3226
2757
  if (peg$silentFails === 0) peg$fail(peg$e32);
3227
2758
  }
3228
2759
  if (s1 !== peg$FAILED) {
3229
- s2 = peg$currPos;
3230
- s3 = [];
3231
- s4 = peg$parseValuePart();
3232
- if (s4 === peg$FAILED) {
3233
- s4 = input.charAt(peg$currPos);
3234
- if (peg$r15.test(s4)) peg$currPos++;
2760
+ s2 = peg$parseHere();
2761
+ s3 = peg$currPos;
2762
+ s4 = [];
2763
+ s5 = peg$parseValuePart();
2764
+ if (s5 === peg$FAILED) {
2765
+ s5 = input.charAt(peg$currPos);
2766
+ if (peg$r15.test(s5)) peg$currPos++;
3235
2767
  else {
3236
- s4 = peg$FAILED;
2768
+ s5 = peg$FAILED;
3237
2769
  if (peg$silentFails === 0) peg$fail(peg$e33);
3238
2770
  }
3239
2771
  }
3240
- while (s4 !== peg$FAILED) {
3241
- s3.push(s4);
3242
- s4 = peg$parseValuePart();
3243
- if (s4 === peg$FAILED) {
3244
- s4 = input.charAt(peg$currPos);
3245
- if (peg$r15.test(s4)) peg$currPos++;
2772
+ while (s5 !== peg$FAILED) {
2773
+ s4.push(s5);
2774
+ s5 = peg$parseValuePart();
2775
+ if (s5 === peg$FAILED) {
2776
+ s5 = input.charAt(peg$currPos);
2777
+ if (peg$r15.test(s5)) peg$currPos++;
3246
2778
  else {
3247
- s4 = peg$FAILED;
2779
+ s5 = peg$FAILED;
3248
2780
  if (peg$silentFails === 0) peg$fail(peg$e33);
3249
2781
  }
3250
2782
  }
3251
2783
  }
3252
- s2 = input.substring(s2, peg$currPos);
2784
+ s3 = input.substring(s3, peg$currPos);
2785
+ s4 = peg$parseHere();
3253
2786
  if (input.charCodeAt(peg$currPos) === 34) {
3254
- s3 = peg$c16;
2787
+ s5 = peg$c16;
3255
2788
  peg$currPos++;
3256
2789
  } else {
3257
- s3 = peg$FAILED;
2790
+ s5 = peg$FAILED;
3258
2791
  if (peg$silentFails === 0) peg$fail(peg$e32);
3259
2792
  }
3260
- if (s3 !== peg$FAILED) {
2793
+ if (s5 !== peg$FAILED) {
3261
2794
  peg$savedPos = s0;
3262
- s0 = peg$f79(s2);
2795
+ s0 = peg$f52(s2, s3, s4);
3263
2796
  } else {
3264
2797
  peg$currPos = s0;
3265
2798
  s0 = peg$FAILED;
@@ -3278,40 +2811,42 @@ function peg$parse(input, options) {
3278
2811
  if (peg$silentFails === 0) peg$fail(peg$e34);
3279
2812
  }
3280
2813
  if (s1 !== peg$FAILED) {
3281
- s2 = peg$currPos;
3282
- s3 = [];
3283
- s4 = peg$parseValuePart();
3284
- if (s4 === peg$FAILED) {
3285
- s4 = input.charAt(peg$currPos);
3286
- if (peg$r16.test(s4)) peg$currPos++;
2814
+ s2 = peg$parseHere();
2815
+ s3 = peg$currPos;
2816
+ s4 = [];
2817
+ s5 = peg$parseValuePart();
2818
+ if (s5 === peg$FAILED) {
2819
+ s5 = input.charAt(peg$currPos);
2820
+ if (peg$r16.test(s5)) peg$currPos++;
3287
2821
  else {
3288
- s4 = peg$FAILED;
2822
+ s5 = peg$FAILED;
3289
2823
  if (peg$silentFails === 0) peg$fail(peg$e35);
3290
2824
  }
3291
2825
  }
3292
- while (s4 !== peg$FAILED) {
3293
- s3.push(s4);
3294
- s4 = peg$parseValuePart();
3295
- if (s4 === peg$FAILED) {
3296
- s4 = input.charAt(peg$currPos);
3297
- if (peg$r16.test(s4)) peg$currPos++;
2826
+ while (s5 !== peg$FAILED) {
2827
+ s4.push(s5);
2828
+ s5 = peg$parseValuePart();
2829
+ if (s5 === peg$FAILED) {
2830
+ s5 = input.charAt(peg$currPos);
2831
+ if (peg$r16.test(s5)) peg$currPos++;
3298
2832
  else {
3299
- s4 = peg$FAILED;
2833
+ s5 = peg$FAILED;
3300
2834
  if (peg$silentFails === 0) peg$fail(peg$e35);
3301
2835
  }
3302
2836
  }
3303
2837
  }
3304
- s2 = input.substring(s2, peg$currPos);
2838
+ s3 = input.substring(s3, peg$currPos);
2839
+ s4 = peg$parseHere();
3305
2840
  if (input.charCodeAt(peg$currPos) === 39) {
3306
- s3 = peg$c17;
2841
+ s5 = peg$c17;
3307
2842
  peg$currPos++;
3308
2843
  } else {
3309
- s3 = peg$FAILED;
2844
+ s5 = peg$FAILED;
3310
2845
  if (peg$silentFails === 0) peg$fail(peg$e34);
3311
2846
  }
3312
- if (s3 !== peg$FAILED) {
2847
+ if (s5 !== peg$FAILED) {
3313
2848
  peg$savedPos = s0;
3314
- s0 = peg$f80(s2);
2849
+ s0 = peg$f53(s2, s3, s4);
3315
2850
  } else {
3316
2851
  peg$currPos = s0;
3317
2852
  s0 = peg$FAILED;
@@ -3330,28 +2865,33 @@ function peg$parse(input, options) {
3330
2865
  }
3331
2866
  if (s1 !== peg$FAILED) {
3332
2867
  peg$savedPos = s0;
3333
- s1 = peg$f81(s1);
2868
+ s1 = peg$f54(s1);
3334
2869
  }
3335
2870
  s0 = s1;
3336
2871
  if (s0 === peg$FAILED) {
3337
2872
  s0 = peg$currPos;
3338
- s1 = [];
3339
- s2 = input.charAt(peg$currPos);
3340
- if (peg$r18.test(s2)) peg$currPos++;
2873
+ s1 = peg$parseHere();
2874
+ s2 = peg$currPos;
2875
+ s3 = [];
2876
+ s4 = input.charAt(peg$currPos);
2877
+ if (peg$r18.test(s4)) peg$currPos++;
3341
2878
  else {
3342
- s2 = peg$FAILED;
2879
+ s4 = peg$FAILED;
3343
2880
  if (peg$silentFails === 0) peg$fail(peg$e37);
3344
2881
  }
3345
- while (s2 !== peg$FAILED) {
3346
- s1.push(s2);
3347
- s2 = input.charAt(peg$currPos);
3348
- if (peg$r18.test(s2)) peg$currPos++;
2882
+ while (s4 !== peg$FAILED) {
2883
+ s3.push(s4);
2884
+ s4 = input.charAt(peg$currPos);
2885
+ if (peg$r18.test(s4)) peg$currPos++;
3349
2886
  else {
3350
- s2 = peg$FAILED;
2887
+ s4 = peg$FAILED;
3351
2888
  if (peg$silentFails === 0) peg$fail(peg$e37);
3352
2889
  }
3353
2890
  }
3354
- s0 = input.substring(s0, peg$currPos);
2891
+ s2 = input.substring(s2, peg$currPos);
2892
+ s3 = peg$parseHere();
2893
+ peg$savedPos = s0;
2894
+ s0 = peg$f55(s1, s2, s3);
3355
2895
  }
3356
2896
  }
3357
2897
  }
@@ -3361,7 +2901,7 @@ function peg$parse(input, options) {
3361
2901
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3362
2902
  s0 = peg$currPos;
3363
2903
  peg$savedPos = peg$currPos;
3364
- s1 = peg$f82();
2904
+ s1 = peg$f56();
3365
2905
  if (s1) s1 = void 0;
3366
2906
  else s1 = peg$FAILED;
3367
2907
  if (s1 !== peg$FAILED) {
@@ -3390,7 +2930,7 @@ function peg$parse(input, options) {
3390
2930
  if (s2 !== peg$FAILED) {
3391
2931
  s3 = peg$currPos;
3392
2932
  peg$savedPos = peg$currPos;
3393
- s4 = peg$f83(s2);
2933
+ s4 = peg$f57(s2);
3394
2934
  if (s4) s4 = void 0;
3395
2935
  else s4 = peg$FAILED;
3396
2936
  if (s4 !== peg$FAILED) {
@@ -3429,7 +2969,7 @@ function peg$parse(input, options) {
3429
2969
  if (s0 === peg$FAILED) {
3430
2970
  s0 = peg$currPos;
3431
2971
  peg$savedPos = peg$currPos;
3432
- s1 = peg$f84();
2972
+ s1 = peg$f58();
3433
2973
  if (s1) s1 = void 0;
3434
2974
  else s1 = peg$FAILED;
3435
2975
  if (s1 !== peg$FAILED) {
@@ -3456,12 +2996,12 @@ function peg$parse(input, options) {
3456
2996
  if (s6 !== peg$FAILED) {
3457
2997
  s7 = peg$parseHere();
3458
2998
  peg$savedPos = peg$currPos;
3459
- s8 = peg$f85(s4, s7);
2999
+ s8 = peg$f59(s4, s7);
3460
3000
  if (s8) s8 = void 0;
3461
3001
  else s8 = peg$FAILED;
3462
3002
  if (s8 !== peg$FAILED) {
3463
3003
  s9 = peg$currPos;
3464
- s10 = peg$f86(s4, s7);
3004
+ s10 = peg$f60(s4, s7);
3465
3005
  s11 = peg$currPos;
3466
3006
  s12 = [];
3467
3007
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3543,7 +3083,7 @@ function peg$parse(input, options) {
3543
3083
  if (s0 === peg$FAILED) {
3544
3084
  s0 = peg$currPos;
3545
3085
  peg$savedPos = peg$currPos;
3546
- s1 = peg$f87();
3086
+ s1 = peg$f61();
3547
3087
  if (s1) s1 = void 0;
3548
3088
  else s1 = peg$FAILED;
3549
3089
  if (s1 !== peg$FAILED) {
@@ -3634,7 +3174,7 @@ function peg$parse(input, options) {
3634
3174
  if (s0 === peg$FAILED) {
3635
3175
  s0 = peg$currPos;
3636
3176
  peg$savedPos = peg$currPos;
3637
- s1 = peg$f88();
3177
+ s1 = peg$f62();
3638
3178
  if (s1) s1 = void 0;
3639
3179
  else s1 = peg$FAILED;
3640
3180
  if (s1 !== peg$FAILED) {
@@ -3749,17 +3289,35 @@ function peg$parse(input, options) {
3749
3289
  }
3750
3290
  return -1;
3751
3291
  }
3292
+ /**
3293
+ * Where the selectors `s` are written, from `start` up to `after`, the end of
3294
+ * what Selectors consumed (the one space that may follow them is not part of
3295
+ * them): the fields of a token; none without selectors.
3296
+ */
3297
+ function selectorSpan(s, start, after) {
3298
+ if (s === NO_SELECTORS) return {};
3299
+ return {
3300
+ selectorsStart: start,
3301
+ selectorsEnd: input.charAt(after - 1) === " " ? after - 1 : after
3302
+ };
3303
+ }
3752
3304
  function skipTo(end) {
3753
3305
  skipEnd = end;
3754
3306
  return end >= 0;
3755
3307
  }
3756
- function fail(message, loc) {
3757
- error(message, loc);
3308
+ /** Fail with `message` at `loc`; `code` tells the kind of error apart (MarkupError). */
3309
+ function fail(message, loc, code) {
3310
+ try {
3311
+ error(message, loc);
3312
+ } catch (e) {
3313
+ e.code = code;
3314
+ throw e;
3315
+ }
3758
3316
  }
3759
3317
  function attrs(list) {
3760
3318
  const attributes = {};
3761
3319
  const seen = /* @__PURE__ */ new Set();
3762
- for (const [name, value] of list) {
3320
+ for (const { name, value } of list) {
3763
3321
  const lower = name.toLowerCase();
3764
3322
  if (seen.has(lower)) continue;
3765
3323
  seen.add(lower);
@@ -3772,38 +3330,6 @@ function peg$parse(input, options) {
3772
3330
  }
3773
3331
  return attributes;
3774
3332
  }
3775
- /** Check the body of a macro or element against its opening tag. */
3776
- function checkBody(open, body) {
3777
- for (const branch of body.branches) {
3778
- const parent = BRANCH_PARENT[branch.tag.lower];
3779
- if (open.lex !== "macro" || open.lower !== parent) fail(label(branch.tag) + " must be directly inside {" + parent + RB + ", not inside " + label(open), branch.tag.loc);
3780
- }
3781
- if (!body.end) fail("Unclosed " + label(open) + ": no " + closerOf(open) + " closes it", open.loc);
3782
- if (!sameName(open, body.end)) fail(label(body.end) + " found where " + closerOf(open) + " should close the " + label(open) + " opened at " + at(open.loc), body.end.loc);
3783
- }
3784
- function macroNode(tag, body) {
3785
- const node = {
3786
- type: "macro",
3787
- name: tag.lower,
3788
- rawArgs: tag.rawArgs,
3789
- children: []
3790
- };
3791
- if (!body) return withSelectors(node, tag);
3792
- checkBody(tag, body);
3793
- node.children = body.children;
3794
- if (BRANCHING.has(tag.lower)) {
3795
- node.branches = [withSelectors({
3796
- rawArgs: tag.rawArgs,
3797
- children: body.children
3798
- }, tag)];
3799
- for (const b of body.branches) node.branches.push(withSelectors({
3800
- rawArgs: b.tag.rawArgs,
3801
- children: b.children
3802
- }, b.tag));
3803
- node.children = [];
3804
- } else withSelectors(node, tag);
3805
- return node;
3806
- }
3807
3333
  peg$result = peg$startRuleFunction();
3808
3334
  const peg$success = peg$result !== peg$FAILED && peg$currPos === input.length;
3809
3335
  function peg$throw() {
@@ -3861,6 +3387,10 @@ var NameSet = class {
3861
3387
  };
3862
3388
  //#endregion
3863
3389
  //#region src/markup/ast.ts
3390
+ /**
3391
+ * The passage AST (built by parse.ts), and the registry of block macros:
3392
+ * those whose body the parser nests up to their `{/name}`.
3393
+ */
3864
3394
  /** Macros that require a closing tag and can contain children */
3865
3395
  var BLOCK_MACROS = new NameSet([
3866
3396
  "if",
@@ -3878,6 +3408,12 @@ var BLOCK_MACROS = new NameSet([
3878
3408
  "span",
3879
3409
  "nobr"
3880
3410
  ]);
3411
+ /** Macros whose body is JavaScript source, kept verbatim. */
3412
+ var RAW_BODY_MACROS = new Set(["do"]);
3413
+ /** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
3414
+ function isRawMacro(name) {
3415
+ return RAW_BODY_MACROS.has(name);
3416
+ }
3881
3417
  /** Whether a macro takes a body closed by `{/name}`. */
3882
3418
  function isBlockMacro(name) {
3883
3419
  return BLOCK_MACROS.has(name);
@@ -3886,6 +3422,261 @@ function isBlockMacro(name) {
3886
3422
  function registerBlockMacro(name) {
3887
3423
  BLOCK_MACROS.add(name);
3888
3424
  }
3425
+ /** Macros whose branches render as one: the node holds one per branch. */
3426
+ var BRANCHING = new Set([
3427
+ "if",
3428
+ "switch",
3429
+ "timed"
3430
+ ]);
3431
+ /** `value` as a quoted macro argument. */
3432
+ var quoteArg = (value) => `"${value.replace(/[\\"]/g, "\\$&")}"`;
3433
+ /** The AST of paired markup (see pair.ts): what the renderer runs. */
3434
+ function buildAst(nodes) {
3435
+ return nodes.map(astNode);
3436
+ }
3437
+ function astNode({ token, body }) {
3438
+ switch (token.type) {
3439
+ case "text": return token.comment ? {
3440
+ type: "text",
3441
+ value: token.value,
3442
+ comment: true
3443
+ } : {
3444
+ type: "text",
3445
+ value: token.value
3446
+ };
3447
+ case "link": return withSelectors$1({
3448
+ type: "macro",
3449
+ name: "link",
3450
+ rawArgs: `${quoteArg(token.display)} ${quoteArg(token.target)}`,
3451
+ children: []
3452
+ }, token);
3453
+ case "variable": return withSelectors$1({
3454
+ type: "variable",
3455
+ name: token.name,
3456
+ scope: token.scope
3457
+ }, token);
3458
+ case "expression": return withSelectors$1({
3459
+ type: "expression",
3460
+ expression: token.expression
3461
+ }, token);
3462
+ case "html": return {
3463
+ type: "html",
3464
+ tag: token.tag,
3465
+ attributes: token.attributes,
3466
+ children: body ? buildAst(body.children) : []
3467
+ };
3468
+ case "macro": {
3469
+ const name = token.name.toLowerCase();
3470
+ const node = {
3471
+ type: "macro",
3472
+ name,
3473
+ rawArgs: token.rawArgs,
3474
+ children: []
3475
+ };
3476
+ if (!body) return withSelectors$1(node, token);
3477
+ const children = buildAst(body.children);
3478
+ if (!BRANCHING.has(name)) {
3479
+ node.children = children;
3480
+ return withSelectors$1(node, token);
3481
+ }
3482
+ const branch = (tag, branchChildren) => withSelectors$1({
3483
+ rawArgs: tag.rawArgs,
3484
+ children: branchChildren
3485
+ }, tag);
3486
+ node.branches = [branch(token, children), ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
3487
+ return node;
3488
+ }
3489
+ }
3490
+ }
3491
+ //#endregion
3492
+ //#region src/markup/line-column.ts
3493
+ /** 1-based line and column of `offset` in `text`. */
3494
+ function lineColumn(text, offset) {
3495
+ let line = 1;
3496
+ let lineStart = 0;
3497
+ for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
3498
+ line++;
3499
+ lineStart = i + 1;
3500
+ i = text.indexOf("\n", lineStart);
3501
+ }
3502
+ return {
3503
+ line,
3504
+ column: offset - lineStart + 1
3505
+ };
3506
+ }
3507
+ //#endregion
3508
+ //#region src/markup/pair.ts
3509
+ /**
3510
+ * Pairing: which closer closes which opener among the flat tokens of markup
3511
+ * (parse.ts tokenizeMarkup), and which branch (`{else}`, `{case}`) belongs to
3512
+ * which macro. The runtime AST (ast.ts) is built from this, and editor tooling
3513
+ * reads the same tree (`pairMarkup` in tooling.ts), so both agree on where a
3514
+ * block starts and ends.
3515
+ *
3516
+ * It never throws: a problem is an entry of `errors`, and the tree is
3517
+ * recovered around it. A closer closes the innermost open element, as the
3518
+ * runtime reads it, or, when it matches one further out, closes that one and
3519
+ * what was open inside it stays unclosed.
3520
+ */
3521
+ /** The last of `items`. */
3522
+ var last$1 = (items) => items[items.length - 1];
3523
+ /** The macro each branch macro belongs to. */
3524
+ var BRANCH_PARENT = {
3525
+ elseif: "if",
3526
+ else: "if",
3527
+ case: "switch",
3528
+ default: "switch",
3529
+ next: "timed"
3530
+ };
3531
+ var isBranchTag = (token) => token.type === "macro" && !token.isClose && Object.prototype.hasOwnProperty.call(BRANCH_PARENT, token.name.toLowerCase());
3532
+ var lowerName = (token) => nameOf(token).toLowerCase();
3533
+ /** The macro name or HTML tag of `tag`, as written. */
3534
+ var nameOf = (tag) => tag.type === "macro" ? tag.name : tag.tag;
3535
+ /** How a tag reads in an error message. */
3536
+ function tagLabel(tag) {
3537
+ return tag.type === "html" ? `${tag.isClose ? "</" : "<"}${tag.tag}>` : `{${tag.isClose ? "/" : ""}${tag.name}}`;
3538
+ }
3539
+ /** The tag that closes the element opened by `tag`. */
3540
+ var closerOf = (tag) => tag.type === "html" ? `</${tag.tag}>` : `{/${tag.name}}`;
3541
+ /** Whether `close` is the closing tag of the element opened by `open`. */
3542
+ var closes = (open, close) => open.type === close.type && lowerName(open) === lowerName(close);
3543
+ /**
3544
+ * Pair `tokens`, the tokens of `source`, into a tree: elements with their
3545
+ * bodies and branches, and the problems found (unclosed, mismatched and
3546
+ * stray closers, branches outside their macro) in the order a parser reading
3547
+ * from left to right notices them.
3548
+ */
3549
+ function pairMarkup(tokens, options = {}) {
3550
+ const isBlock = options.isBlock ?? isBlockMacro;
3551
+ const isRaw = options.isRaw ?? isRawMacro;
3552
+ const errors = [];
3553
+ const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
3554
+ const where = (offset) => {
3555
+ if (options.source === void 0) return `offset ${offset}`;
3556
+ const { line, column } = lineColumn(options.source, offset);
3557
+ return `line ${line}, column ${column}`;
3558
+ };
3559
+ const report = (code, token, message, noticedAt, data) => {
3560
+ errors.push({
3561
+ code,
3562
+ message,
3563
+ start: token.start,
3564
+ end: token.end,
3565
+ noticedAt,
3566
+ data
3567
+ });
3568
+ };
3569
+ /** A branch outside its macro, or inside another element `inside`. */
3570
+ const misplaced = (tag, inside, noticedAt) => {
3571
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3572
+ const where = inside ? `, not inside ${tagLabel(inside)}` : "";
3573
+ report("misplaced-branch", tag, `${tagLabel(tag)} must be directly inside {${parent}}${where}`, noticedAt, {
3574
+ name: tag.name,
3575
+ parent,
3576
+ ...inside && { inside: nameOf(inside) }
3577
+ });
3578
+ };
3579
+ const root = [];
3580
+ const stack = [];
3581
+ const add = (node) => (last$1(stack)?.into ?? root).push(node);
3582
+ /**
3583
+ * End the element on top of the stack, with `close` if it has one: its
3584
+ * misplaced branches are reported first, then how it ends.
3585
+ */
3586
+ const end = (ending, close, owns = ending === "closed") => {
3587
+ const { node, body } = stack.pop();
3588
+ const open = node.token;
3589
+ const noticedAt = close ? close.end : noticedAtEnd;
3590
+ for (const { tag } of body.branches) {
3591
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3592
+ if (open.type !== "macro" || lowerName(open) !== parent) misplaced(tag, open, noticedAt);
3593
+ }
3594
+ if (ending === "unclosed") report("unclosed-block", open, `Unclosed ${tagLabel(open)}: no ${closerOf(open)} closes it`, noticedAt, { name: nameOf(open) });
3595
+ else if (ending === "mismatch") report("mismatched-closer", close, `${tagLabel(close)} found where ${closerOf(open)} should close the ${tagLabel(open)} opened at ${where(open.start)}`, noticedAt, {
3596
+ name: nameOf(open),
3597
+ closer: nameOf(close)
3598
+ });
3599
+ if (owns) body.close = close;
3600
+ node.end = body.close?.end ?? lastEnd(body) ?? open.end;
3601
+ add(node);
3602
+ };
3603
+ for (let i = 0; i < tokens.length; i++) {
3604
+ const token = tokens[i];
3605
+ if ((token.type === "macro" || token.type === "html") && token.isClose) {
3606
+ const top = last$1(stack);
3607
+ if (!top) report("stray-closer", token, `${tagLabel(token)} closes nothing: no ${token.type === "html" ? `<${token.tag}>` : `{${token.name}}`} is open here`, token.start, { name: nameOf(token) });
3608
+ else if (closes(top.node.token, token)) end("closed", token);
3609
+ else {
3610
+ let outer = stack.length - 1;
3611
+ while (outer >= 0 && !closes(stack[outer].node.token, token)) outer--;
3612
+ end("mismatch", token, outer === -1);
3613
+ if (outer !== -1) {
3614
+ while (stack.length > outer + 1) end("cut", token);
3615
+ end("closed", token);
3616
+ }
3617
+ }
3618
+ continue;
3619
+ }
3620
+ if (isBranchTag(token)) {
3621
+ const tag = token;
3622
+ const frame = last$1(stack);
3623
+ if (!frame) {
3624
+ misplaced(tag, void 0, tag.start);
3625
+ continue;
3626
+ }
3627
+ const branch = {
3628
+ tag,
3629
+ children: []
3630
+ };
3631
+ frame.body.branches.push(branch);
3632
+ frame.into = branch.children;
3633
+ continue;
3634
+ }
3635
+ const node = {
3636
+ token,
3637
+ start: token.start,
3638
+ end: token.end
3639
+ };
3640
+ const opens = token.type === "html" ? !token.isSelfClose : token.type === "macro" && isBlock(token.name.toLowerCase());
3641
+ if (opens && token.type === "macro" && isRaw(token.name.toLowerCase()) && !closesRawBody(token, tokens[i + 1], tokens[i + 2])) {
3642
+ report("unclosed-block", token, `Unclosed ${tagLabel(token)}: no ${closerOf(token)} closes it`, token.end, { name: nameOf(token) });
3643
+ add(node);
3644
+ continue;
3645
+ }
3646
+ if (!opens) {
3647
+ add(node);
3648
+ continue;
3649
+ }
3650
+ const body = {
3651
+ children: [],
3652
+ branches: []
3653
+ };
3654
+ node.body = body;
3655
+ stack.push({
3656
+ node,
3657
+ body,
3658
+ into: body.children
3659
+ });
3660
+ }
3661
+ while (stack.length > 0) end("unclosed");
3662
+ return {
3663
+ nodes: root,
3664
+ errors
3665
+ };
3666
+ }
3667
+ /**
3668
+ * Whether the tokens after the opening tag `open` of a raw macro are its
3669
+ * body (one text token, if it is not empty) and its closer.
3670
+ */
3671
+ function closesRawBody(open, next, after) {
3672
+ const closer = (t) => t?.type === "macro" && t.isClose && closes(open, t);
3673
+ return closer(next) || next?.type === "text" && closer(after);
3674
+ }
3675
+ /** The end of the last thing in `body`. */
3676
+ function lastEnd(body) {
3677
+ const branch = last$1(body.branches);
3678
+ return last$1(branch?.children ?? body.children)?.end ?? branch?.tag.end;
3679
+ }
3889
3680
  //#endregion
3890
3681
  //#region node_modules/acorn/dist/acorn.mjs
3891
3682
  var astralIdentifierCodes = [
@@ -10013,39 +9804,26 @@ function splitSigilTemplate(template) {
10013
9804
  * hooks plugged in. It builds the AST directly and reports malformed markup
10014
9805
  * as a MarkupError carrying its line and column.
10015
9806
  */
10016
- /** Macros whose body is JavaScript source, kept verbatim. */
10017
- var RAW_BODY_MACROS = new Set(["do"]);
10018
9807
  var defaultHooks = {
10019
9808
  ...defaultCodeEnd,
10020
9809
  isBlock: isBlockMacro,
10021
- isRaw: (name) => RAW_BODY_MACROS.has(name),
9810
+ isRaw: isRawMacro,
10022
9811
  isCodeAttribute
10023
9812
  };
10024
9813
  /** Malformed markup, with where it starts (1-based line and column). */
10025
9814
  var MarkupError = class extends Error {
10026
- constructor(reason, offset, line, column) {
9815
+ constructor(reason, offset, line, column, code = "syntax", end = offset, data = {}) {
10027
9816
  super(`${reason} (line ${line}, column ${column})`);
10028
9817
  this.reason = reason;
10029
9818
  this.offset = offset;
10030
9819
  this.line = line;
10031
9820
  this.column = column;
9821
+ this.code = code;
9822
+ this.end = end;
9823
+ this.data = data;
10032
9824
  this.name = "MarkupError";
10033
9825
  }
10034
9826
  };
10035
- /** 1-based line and column of `offset` in `text`. */
10036
- function lineColumn(text, offset) {
10037
- let line = 1;
10038
- let lineStart = 0;
10039
- for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
10040
- line++;
10041
- lineStart = i + 1;
10042
- i = text.indexOf("\n", lineStart);
10043
- }
10044
- return {
10045
- line,
10046
- column: offset - lineStart + 1
10047
- };
10048
- }
10049
9827
  function run$2(source, startRule, options) {
10050
9828
  const hooks = options.hooks ? {
10051
9829
  ...defaultHooks,
@@ -10058,21 +9836,61 @@ function run$2(source, startRule, options) {
10058
9836
  hooks
10059
9837
  });
10060
9838
  } catch (err) {
10061
- const location = err.location;
9839
+ const { location, code } = err;
10062
9840
  if (err instanceof Error && err.name === "SyntaxError" && location) {
10063
9841
  const { offset } = location.start;
10064
9842
  const { line, column } = lineColumn(source, offset);
10065
- throw new MarkupError(err.message, offset, line, column);
9843
+ throw new MarkupError(err.message, offset, line, column, code, location.end.offset);
10066
9844
  }
10067
9845
  throw err;
10068
9846
  }
10069
9847
  }
10070
9848
  /**
9849
+ * Read markup that may be malformed: its tokens, their pairing and every
9850
+ * error (malformed tags, and closers and branches that pair with nothing),
9851
+ * with offsets in `source`. Markup inside a malformed tag is not read as such,
9852
+ * so it has no errors of its own.
9853
+ */
9854
+ function analyzeMarkup(source, options = {}) {
9855
+ const { tokens, errors, damage } = scan(source, options);
9856
+ const hooks = {
9857
+ ...defaultHooks,
9858
+ ...options.hooks
9859
+ };
9860
+ const paired = pairMarkup(tokens, {
9861
+ isBlock: hooks.isBlock,
9862
+ isRaw: hooks.isRaw,
9863
+ source
9864
+ });
9865
+ if (errors.length === 0 && paired.errors.length === 0) return {
9866
+ tokens,
9867
+ nodes: paired.nodes,
9868
+ errors
9869
+ };
9870
+ const inDamage = (start) => errors.some((e, i) => start >= damage[i] && start <= e.offset);
9871
+ const noticed = errors.map((e, i) => [damage[i] + .5, e]);
9872
+ for (const error of paired.errors) if (!inDamage(error.start)) noticed.push([error.noticedAt, pairingError(source, error)]);
9873
+ noticed.sort((a, b) => a[0] - b[0]);
9874
+ return {
9875
+ tokens,
9876
+ nodes: paired.nodes,
9877
+ errors: noticed.map(([, e]) => e)
9878
+ };
9879
+ }
9880
+ /**
10071
9881
  * Parse markup into its AST: macros with their bodies and branches, HTML
10072
- * elements with their children. Throws a MarkupError for malformed markup.
9882
+ * elements with their children. Throws a MarkupError for malformed markup:
9883
+ * the first problem a parser reading from left to right meets.
10073
9884
  */
10074
9885
  function parseMarkup(source, options = {}) {
10075
- return run$2(source, "Markup", options);
9886
+ const { nodes, errors } = analyzeMarkup(source, options);
9887
+ if (errors.length > 0) throw errors[0];
9888
+ return buildAst(nodes);
9889
+ }
9890
+ /** A pairing problem as the MarkupError it is for `source`. */
9891
+ function pairingError(source, error) {
9892
+ const { line, column } = lineColumn(source, error.start);
9893
+ return new MarkupError(error.message, error.start, line, column, error.code, error.end, error.data);
10076
9894
  }
10077
9895
  /**
10078
9896
  * The flat tokens of markup, without nesting, so unclosed or mismatched
@@ -10091,8 +9909,21 @@ function tokenizeMarkup(source, options = {}) {
10091
9909
  * markup the tokens are those of `tokenizeMarkup` and there are no errors.
10092
9910
  */
10093
9911
  function tokenizeMarkupTolerant(source, options = {}) {
9912
+ const { tokens, errors } = scan(source, options);
9913
+ return {
9914
+ tokens,
9915
+ errors
9916
+ };
9917
+ }
9918
+ /**
9919
+ * The tokens of tolerant tokenizing, the errors, and where the damage of
9920
+ * each error starts: the tag that is malformed, which an error inside it
9921
+ * (an attribute value) is after.
9922
+ */
9923
+ function scan(source, options) {
10094
9924
  const tokens = [];
10095
9925
  const errors = [];
9926
+ const damage = [];
10096
9927
  const lastBrace = source.lastIndexOf("}");
10097
9928
  const { closeBrace } = {
10098
9929
  ...defaultHooks,
@@ -10108,7 +9939,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10108
9939
  return tokenizeMarkup(text, {
10109
9940
  ...options,
10110
9941
  hooks
10111
- }).map((token) => shift(token, base));
9942
+ }).map((token) => shiftOffsets(token, base));
10112
9943
  } catch (error) {
10113
9944
  if (!(error instanceof MarkupError)) throw error;
10114
9945
  return error;
@@ -10124,7 +9955,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10124
9955
  }
10125
9956
  const at = base + result.offset;
10126
9957
  const { line, column } = lineColumn(source, at);
10127
- errors.push(new MarkupError(result.reason, at, line, column));
9958
+ errors.push(new MarkupError(result.reason, at, line, column, result.code, base + result.end));
10128
9959
  let cut = result.offset;
10129
9960
  let prefix = attempt(rest.slice(0, cut), base);
10130
9961
  while (!Array.isArray(prefix)) {
@@ -10132,6 +9963,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10132
9963
  prefix = attempt(rest.slice(0, cut), base);
10133
9964
  }
10134
9965
  tokens.push(...prefix);
9966
+ damage.push(base + cut);
10135
9967
  if (cut < rest.length) {
10136
9968
  const start = base + cut;
10137
9969
  tokens.push({
@@ -10145,23 +9977,23 @@ function tokenizeMarkupTolerant(source, options = {}) {
10145
9977
  }
10146
9978
  return {
10147
9979
  tokens,
10148
- errors
9980
+ errors,
9981
+ damage
10149
9982
  };
10150
9983
  }
10151
- /** `token` with its offsets moved `by` on. */
10152
- function shift(token, by) {
10153
- if (by === 0) return token;
10154
- const moved = {
10155
- ...token,
10156
- start: token.start + by,
10157
- end: token.end + by
10158
- };
10159
- if (moved.type === "link") {
10160
- moved.targetStart += by;
10161
- moved.targetEnd += by;
10162
- }
9984
+ /** The offset fields of a token (and of an attribute): `start`, `nameEnd`… */
9985
+ var OFFSET_FIELD = /^(start|end|[A-Za-z]*(Start|End))$/;
9986
+ /** `token` (or an attribute of it) with each of its offsets turned by `map`. */
9987
+ function mapOffsets(token, map) {
9988
+ const moved = { ...token };
9989
+ for (const [key, value] of Object.entries(moved)) if (typeof value === "number" && OFFSET_FIELD.test(key)) moved[key] = map(value);
9990
+ else if (key === "attributeSpans") moved[key] = value.map((span) => mapOffsets(span, map));
10163
9991
  return moved;
10164
9992
  }
9993
+ /** `token` (or an attribute of it) with its offsets moved `by` on. */
9994
+ function shiftOffsets(token, by) {
9995
+ return by === 0 ? token : mapOffsets(token, (offset) => offset + by);
9996
+ }
10165
9997
  //#endregion
10166
9998
  //#region src/utils/namespace.ts
10167
9999
  /** The variable name no namespace can hold. */
@@ -10317,10 +10149,10 @@ function createListeners() {
10317
10149
  //#region src/runtime-errors.ts
10318
10150
  var errors = [];
10319
10151
  var nextId = 1;
10320
- var listeners$1 = createListeners();
10152
+ var listeners$2 = createListeners();
10321
10153
  function update(next) {
10322
10154
  errors = next;
10323
- listeners$1.notify();
10155
+ listeners$2.notify();
10324
10156
  }
10325
10157
  /**
10326
10158
  * Show `error` on the page, after `context` (what failed). The same error
@@ -10356,7 +10188,7 @@ function getRuntimeErrors() {
10356
10188
  return errors;
10357
10189
  }
10358
10190
  /** Call `listener` whenever the shown errors change; returns unsubscribe. */
10359
- var subscribeRuntimeErrors = listeners$1.subscribe;
10191
+ var subscribeRuntimeErrors = listeners$2.subscribe;
10360
10192
  //#endregion
10361
10193
  //#region src/components/macros/arg-utils.ts
10362
10194
  /**
@@ -10589,7 +10421,7 @@ function unset(param) {
10589
10421
  return param.type === "options" ? {} : void 0;
10590
10422
  }
10591
10423
  var WORD_RE = /\w+/y;
10592
- var NUMBER_RE = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10424
+ var NUMBER_RE$1 = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10593
10425
  var WORD_OR_PUNCT_RE = /\S+/y;
10594
10426
  /** Match the sticky regex `re` at `pos`, returning the matched text. */
10595
10427
  function matchAt(re, src, pos) {
@@ -10618,7 +10450,7 @@ function readOptions(params, src, { at, spans }) {
10618
10450
  let j = i;
10619
10451
  while (j < src.length && isWhitespace(src[j])) j++;
10620
10452
  const quoted = readQuoted(src, j);
10621
- const digits = quoted || j === i ? null : matchAt(NUMBER_RE, src, j);
10453
+ const digits = quoted || j === i ? null : matchAt(NUMBER_RE$1, src, j);
10622
10454
  if (quoted) {
10623
10455
  val = quoted.value;
10624
10456
  i = quoted.end;
@@ -10872,6 +10704,14 @@ function parseOrError(code, goal) {
10872
10704
  parses?.set(key, result);
10873
10705
  return result;
10874
10706
  }
10707
+ /** Where character `index` of the code or text of `piece` is in the source. */
10708
+ function pieceOffset(piece, index) {
10709
+ return piece.sourceOffsets?.[index] ?? piece.offset + index;
10710
+ }
10711
+ /** How much of a piece's own text or code there is (not its source extent). */
10712
+ function extentOf(piece) {
10713
+ return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
10714
+ }
10875
10715
  /** Macros whose whole argument text is one expression: branch conditions. */
10876
10716
  var CONDITION_MACROS = new Set([
10877
10717
  "if",
@@ -10948,48 +10788,28 @@ function* codeAndText(src, tokens, parametersOf) {
10948
10788
  macro: "link",
10949
10789
  label: src.slice(token.start, token.end)
10950
10790
  };
10951
- if (token.display.includes("{")) yield {
10952
- kind: "text",
10953
- text: token.display,
10954
- offset: locate(src, token.display, token.start),
10955
- where: "In the label of a link: "
10956
- };
10791
+ if (token.display.includes("{")) yield textPiece(token.display, token.displayStart, "In the label of a link: ");
10957
10792
  } else if (token.type === "expression") yield {
10958
- kind: "code",
10959
- code: token.expression,
10960
- offset: token.end - 1 - token.expression.length,
10961
- goal: "expression",
10962
- label: `{${token.expression}}`
10963
- };
10964
- else if (token.type === "html") {
10965
- let cursor = token.start;
10966
- for (const [name, value] of Object.entries(token.attributes)) {
10967
- const at = locate(src, value, cursor);
10968
- cursor = at + value.length;
10969
- if (!isCodeAttribute(name)) {
10970
- yield {
10971
- kind: "text",
10972
- text: value,
10973
- offset: at,
10974
- where: `In the ${name} attribute of <${token.tag}>: `
10975
- };
10976
- continue;
10977
- }
10978
- let from = 0;
10979
- for (const part of splitSigilTemplate(value)) {
10980
- if (!("expr" in part)) continue;
10981
- const k = locate(value, part.expr, from);
10982
- from = k + part.expr.length;
10983
- yield {
10984
- kind: "code",
10985
- code: part.expr,
10986
- offset: at + k,
10987
- goal: "expression",
10988
- label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10989
- };
10990
- }
10793
+ kind: "code",
10794
+ code: token.expression,
10795
+ offset: token.expressionStart,
10796
+ goal: "expression",
10797
+ label: `{${token.expression}}`
10798
+ };
10799
+ else if (token.type === "html") for (const { name, value, at } of attributeValues(src, token)) {
10800
+ if (!isCodeAttribute(name)) {
10801
+ yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
10802
+ continue;
10991
10803
  }
10992
- } else if (token.type === "macro" && !token.isClose) {
10804
+ for (const { expr, at: k } of sigilExpressions(value)) yield {
10805
+ kind: "code",
10806
+ code: expr,
10807
+ offset: at + k,
10808
+ goal: "expression",
10809
+ label: `{${expr}} in the ${name} attribute of <${token.tag}>`
10810
+ };
10811
+ }
10812
+ else if (token.type === "macro" && !token.isClose) {
10993
10813
  const name = token.name.toLowerCase();
10994
10814
  if (name === "do") {
10995
10815
  const close = closeOf(t, name);
@@ -11023,8 +10843,7 @@ function* codeAndText(src, tokens, parametersOf) {
11023
10843
  }
11024
10844
  if (!args) continue;
11025
10845
  const label = `{${token.name} ${args}}`;
11026
- const tag = src.slice(token.start, token.end - 1);
11027
- const argsAt = token.start + tag.trimEnd().length - args.length;
10846
+ const argsAt = token.argsStart;
11028
10847
  if (CONDITION_MACROS.has(name)) {
11029
10848
  yield {
11030
10849
  kind: "code",
@@ -11040,8 +10859,95 @@ function* codeAndText(src, tokens, parametersOf) {
11040
10859
  }
11041
10860
  }
11042
10861
  }
10862
+ /**
10863
+ * `codeAndText`, with the markup in the texts read too: a text piece (a label,
10864
+ * an attribute value) with a `{` in it carries its tokens and errors, and is
10865
+ * followed by the pieces of that markup, `nested`, in the offsets of the whole
10866
+ * `src`. In source order, a nested piece after the text it is in.
10867
+ */
10868
+ function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
10869
+ yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0);
10870
+ }
10871
+ /**
10872
+ * The pieces of `tokens`, the tokens of `src`, which is the text described by
10873
+ * `where` (none for `root`, the markup of the whole passage), and whose
10874
+ * offsets `toRoot` turns into offsets in `root`.
10875
+ */
10876
+ function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
10877
+ for (const flat of codeAndText(src, tokens, parametersOf)) {
10878
+ const piece = where ? nestedPiece(flat, toRoot, where) : flat;
10879
+ if (flat.kind !== "text" || !flat.text.includes("{")) {
10880
+ yield piece;
10881
+ continue;
10882
+ }
10883
+ const toText = (i) => toRoot(pieceOffset(flat, i));
10884
+ const inner = analyzeMarkup(flat.text, {
10885
+ text: true,
10886
+ hooks: options.isBlock && { isBlock: options.isBlock }
10887
+ });
10888
+ yield {
10889
+ ...piece,
10890
+ tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
10891
+ errors: inner.errors.map((e) => {
10892
+ const { line, column } = lineColumn(root, toText(e.offset));
10893
+ return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
10894
+ })
10895
+ };
10896
+ yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where);
10897
+ }
10898
+ }
10899
+ /** `piece`, of a text in another, with its offsets turned by `toRoot`. */
10900
+ function nestedPiece(piece, toRoot, where) {
10901
+ const offset = toRoot(piece.offset);
10902
+ const nested = {
10903
+ offset,
10904
+ nested: true,
10905
+ where
10906
+ };
10907
+ if (piece.kind === "passage" || piece.kind === "argument-error") {
10908
+ const length = toRoot(piece.offset + piece.length) - offset;
10909
+ return {
10910
+ ...piece,
10911
+ ...nested,
10912
+ length
10913
+ };
10914
+ }
10915
+ const extent = extentOf(piece);
10916
+ const sourceOffsets = piece.sourceOffsets ? piece.sourceOffsets.map(toRoot) : toRoot(piece.offset + extent) - offset !== extent ? Array.from({ length: extent + 1 }, (_, i) => toRoot(piece.offset + i)) : void 0;
10917
+ return sourceOffsets ? {
10918
+ ...piece,
10919
+ ...nested,
10920
+ sourceOffsets
10921
+ } : {
10922
+ ...piece,
10923
+ ...nested
10924
+ };
10925
+ }
10926
+ /**
10927
+ * Where each character of `value`, the unescaped text of a quoted string
10928
+ * written as `raw` from `at` on (a backslash before a quote or a backslash
10929
+ * is dropped), is
10930
+ * in the source, and where the text ends. None when the text is where its
10931
+ * length says, or is not that string.
10932
+ */
10933
+ function escapeOffsets(raw, at, value) {
10934
+ const offsets = [];
10935
+ let escaped = false;
10936
+ let i = 0;
10937
+ while (offsets.length < value.length) {
10938
+ if (i >= raw.length) return void 0;
10939
+ offsets.push(at + i);
10940
+ if (raw[i] === "\\" && /["'\\]/.test(raw.charAt(i + 1))) {
10941
+ escaped = true;
10942
+ i += 2;
10943
+ } else i++;
10944
+ }
10945
+ offsets.push(at + i);
10946
+ return escaped ? offsets : void 0;
10947
+ }
11043
10948
  /** The code and text in the arguments `args` (at `offset`) of `macro`. */
11044
10949
  function* argPieces(args, offset, params, macro, label) {
10950
+ const name = macro.toLowerCase();
11045
10951
  let values;
11046
10952
  const spans = /* @__PURE__ */ new Map();
11047
10953
  try {
@@ -11052,11 +10958,12 @@ function* argPieces(args, offset, params, macro, label) {
11052
10958
  kind: "argument-error",
11053
10959
  message: error.message,
11054
10960
  offset,
11055
- label
10961
+ length: args.length,
10962
+ label,
10963
+ macro: name
11056
10964
  };
11057
10965
  return;
11058
10966
  }
11059
- const name = macro.toLowerCase();
11060
10967
  /** The pieces of the parameters `list`, with their values in `from`. */
11061
10968
  function* visit(list, from) {
11062
10969
  for (const param of list) {
@@ -11103,25 +11010,88 @@ function* argPieces(args, offset, params, macro, label) {
11103
11010
  }
11104
11011
  const at = offset + start + (value !== written && /^["']/.test(written) ? 1 : 0);
11105
11012
  const holds = stringHolds(param);
11106
- if (holds === "expression" || holds === "statements") yield {
11107
- kind: "code",
11108
- code: value,
11109
- offset: at,
11110
- goal: holds,
11111
- label,
11112
- inString: true
11113
- };
11114
- else if (holds === "passage") yield passage(value);
11115
- else if (holds === "markup") yield {
11116
- kind: "text",
11117
- text: value,
11118
- offset: at,
11119
- where: `In the ${param.name} of {${macro}}: `
11120
- };
11013
+ const sourceOffsets = escapeOffsets(args.slice(at - offset), at, value);
11014
+ if (holds === "expression" || holds === "statements") {
11015
+ const piece = {
11016
+ kind: "code",
11017
+ code: value,
11018
+ offset: at,
11019
+ goal: holds,
11020
+ label,
11021
+ inString: true
11022
+ };
11023
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
11024
+ yield piece;
11025
+ } else if (holds === "passage") yield passage(value);
11026
+ else if (holds === "markup") {
11027
+ const piece = textPiece(value, at, `In the ${param.name} of {${macro}}: `);
11028
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
11029
+ yield piece;
11030
+ }
11121
11031
  }
11122
11032
  }
11123
11033
  yield* [...visit(params, values)].sort((a, b) => a.offset - b.offset);
11124
11034
  }
11035
+ /** A text that may hold markup, at `offset`; read when it is expanded. */
11036
+ var textPiece = (text, offset, where) => ({
11037
+ kind: "text",
11038
+ text,
11039
+ offset,
11040
+ where,
11041
+ tokens: [],
11042
+ errors: []
11043
+ });
11044
+ /**
11045
+ * The attributes of an HTML tag by the values as written, with where each
11046
+ * value is: the first of equal names, which is the one in effect. A token
11047
+ * with no spans (made from an AST) has them found in `src`, in order.
11048
+ */
11049
+ function attributeValues(src, token) {
11050
+ if (token.attributeSpans.length === 0) {
11051
+ let cursor = token.start;
11052
+ return Object.entries(token.attributes).map(([name, value]) => {
11053
+ const at = locate(src, value, cursor);
11054
+ cursor = at + value.length;
11055
+ return {
11056
+ name,
11057
+ value,
11058
+ at
11059
+ };
11060
+ });
11061
+ }
11062
+ const seen = /* @__PURE__ */ new Set();
11063
+ const values = [];
11064
+ for (const span of token.attributeSpans) {
11065
+ const lower = span.name.toLowerCase();
11066
+ if (seen.has(lower)) continue;
11067
+ seen.add(lower);
11068
+ if (span.valueStart === void 0) continue;
11069
+ values.push({
11070
+ name: span.name,
11071
+ value: src.slice(span.valueStart, span.valueEnd),
11072
+ at: span.valueStart
11073
+ });
11074
+ }
11075
+ return values;
11076
+ }
11077
+ /**
11078
+ * The `{$…}` expressions in the value of a code attribute (`onclick`, see
11079
+ * isCodeAttribute), with where each is in the value.
11080
+ */
11081
+ function sigilExpressions(value) {
11082
+ const found = [];
11083
+ let from = 0;
11084
+ for (const part of splitSigilTemplate(value)) {
11085
+ if (!("expr" in part)) continue;
11086
+ const at = locate(value, part.expr, from);
11087
+ from = at + part.expr.length;
11088
+ found.push({
11089
+ expr: part.expr,
11090
+ at
11091
+ });
11092
+ }
11093
+ return found;
11094
+ }
11125
11095
  /**
11126
11096
  * Index of `part` in `text` from `from` on, else anywhere, else `from`: the
11127
11097
  * place to report an error in `part` at.
@@ -11277,26 +11247,27 @@ function astContainsChildren(nodes, parametersOf = registeredParameters) {
11277
11247
  for (const node of nodes) {
11278
11248
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
11279
11249
  if (node.type === "html") {
11280
- const span = {
11281
- start: 0,
11282
- end: 0
11283
- };
11284
11250
  if (tokenTextContainsChildren({
11285
11251
  isClose: false,
11286
11252
  isSelfClose: false,
11253
+ tagNameStart: 0,
11254
+ tagNameEnd: 0,
11255
+ attributeSpans: [],
11287
11256
  ...node,
11288
- ...span
11257
+ start: 0,
11258
+ end: 0
11289
11259
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11290
11260
  }
11291
11261
  if (node.type === "macro") {
11292
- const span = {
11293
- start: 0,
11294
- end: 0
11295
- };
11296
11262
  if (tokenTextContainsChildren({
11297
11263
  isClose: false,
11264
+ nameStart: 0,
11265
+ nameEnd: 0,
11266
+ argsStart: 0,
11267
+ argsEnd: 0,
11298
11268
  ...node,
11299
- ...span
11269
+ start: 0,
11270
+ end: 0
11300
11271
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11301
11272
  if (node.branches) {
11302
11273
  for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
@@ -11337,37 +11308,70 @@ function widgetDef({ name = "", parameters = "" }) {
11337
11308
  function parseWidgetDef(rawArgs) {
11338
11309
  return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
11339
11310
  }
11311
+ /** Where the name is written in the arguments, without its quotes. */
11312
+ function nameSpan(rawArgs) {
11313
+ const spans = /* @__PURE__ */ new Map();
11314
+ parseMacroArgs(rawArgs, WIDGET_PARAMETERS, spans);
11315
+ const [start, end] = spans.get(WIDGET_PARAMETERS[0]) ?? [0, 0];
11316
+ const quote = rawArgs[start];
11317
+ return (quote === "\"" || quote === "'") && end - start >= 2 ? [start + 1, rawArgs[end - 1] === quote ? end - 1 : end] : [start, end];
11318
+ }
11340
11319
  /**
11341
- * The names of the block widgets (those whose body renders `{@children}`)
11342
- * that StoryInit and the passages tagged `widget` define. They must be
11343
- * known as block macros before any passage is parsed, so that passages
11344
- * invoking them nest their content whatever the passage order.
11320
+ * The widgets that StoryInit and the passages tagged `widget` define, in
11321
+ * source order: the ones the runtime registers, read tolerantly (a half-typed
11322
+ * definition is still reported, without a `closeStart`). Definitions whose
11323
+ * arguments cannot be read are left out.
11345
11324
  *
11346
11325
  * The passages are read as flat tokens, which need no block macros to be
11347
11326
  * known, so a `{@children}` in an HTML comment or in a `{do}` body is text
11348
- * here as it is to the parser, and does not make a block widget (#387).
11327
+ * here as it is to the parser, and does not make a block widget (#387). In
11328
+ * nested definitions, it belongs to the innermost.
11349
11329
  */
11350
- function blockWidgetNames(passages, parametersOf = registeredParameters) {
11351
- const names = [];
11330
+ function widgetDefinitions(passages, parametersOf = registeredParameters) {
11331
+ const found = [];
11352
11332
  for (const passage of passages) {
11353
11333
  if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
11354
11334
  const open = [];
11355
- for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
11356
- if (!token.isClose) {
11357
- open.push({
11358
- rawArgs: token.rawArgs,
11359
- isBlock: false
11360
- });
11361
- continue;
11362
- }
11335
+ const done = [];
11336
+ for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") if (!token.isClose) open.push({
11337
+ token,
11338
+ isBlock: false
11339
+ });
11340
+ else {
11363
11341
  const def = open.pop();
11364
- if (!def?.isBlock) continue;
11365
- try {
11366
- names.push(parseWidgetDef(def.rawArgs).name);
11367
- } catch {}
11368
- } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
11342
+ if (def) done.push({
11343
+ ...def,
11344
+ closeStart: token.start
11345
+ });
11346
+ }
11347
+ else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
11348
+ done.push(...open);
11349
+ const defs = [];
11350
+ for (const { token, isBlock, closeStart } of done) try {
11351
+ const [from, to] = nameSpan(token.rawArgs);
11352
+ defs.push({
11353
+ ...parseWidgetDef(token.rawArgs),
11354
+ block: isBlock,
11355
+ passage: passage.name,
11356
+ start: token.start,
11357
+ end: token.end,
11358
+ nameStart: token.argsStart + from,
11359
+ nameEnd: token.argsStart + to,
11360
+ ...closeStart === void 0 ? {} : { closeStart }
11361
+ });
11362
+ } catch {}
11363
+ found.push(...defs.sort((a, b) => a.start - b.start));
11369
11364
  }
11370
- return names;
11365
+ return found;
11366
+ }
11367
+ /**
11368
+ * The names of the block widgets (those whose body renders `{@children}`)
11369
+ * that StoryInit and the passages tagged `widget` define, closed. They must
11370
+ * be known as block macros before any passage is parsed, so that passages
11371
+ * invoking them nest their content whatever the passage order.
11372
+ */
11373
+ function blockWidgetNames(passages, parametersOf = registeredParameters) {
11374
+ return widgetDefinitions(passages, parametersOf).filter((def) => def.block && def.closeStart !== void 0).map((def) => def.name);
11371
11375
  }
11372
11376
  //#endregion
11373
11377
  //#region src/widgets/register-widget-def.ts
@@ -12956,9 +12960,13 @@ function resolveAttributeValue(name, value, scope, errors) {
12956
12960
  for (const error of result.errors) errors.push([name, error]);
12957
12961
  return result.text;
12958
12962
  }
12963
+ /** Whether a node shows nothing as text: whitespace, or a closed HTML comment. */
12964
+ function isBlankText(n) {
12965
+ return n.type === "text" && (n.comment === true || n.value.trim() === "");
12966
+ }
12959
12967
  /** The index of the summary element opening `nodes`, or -1 when none does. */
12960
12968
  function leadingSummaryIndex(nodes) {
12961
- const at = nodes.findIndex((n) => n.type !== "text" || n.value.trim() !== "");
12969
+ const at = nodes.findIndex((n) => !isBlankText(n));
12962
12970
  const first = nodes[at];
12963
12971
  return first?.type === "html" && first.tag.toLowerCase() === "summary" ? at : -1;
12964
12972
  }
@@ -12980,7 +12988,8 @@ function HtmlNodeRenderer({ node }) {
12980
12988
  const isInline = INLINE_ELEMENTS.has(tag);
12981
12989
  let children = void 0;
12982
12990
  let structural = false;
12983
- if (node.children.length > 0) if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
12991
+ if (node.children.length > 0) if (tag === "style") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
12992
+ else if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
12984
12993
  else {
12985
12994
  const summaryAt = tag === "details" ? leadingSummaryIndex(node.children) : -1;
12986
12995
  const body = (nodes) => renderNodes(nodes, {
@@ -12988,7 +12997,7 @@ function HtmlNodeRenderer({ node }) {
12988
12997
  locals,
12989
12998
  inline: isInline
12990
12999
  });
12991
- structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || n.value.trim() === "");
13000
+ structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || isBlankText(n));
12992
13001
  children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
12993
13002
  body(node.children.slice(0, summaryAt)),
12994
13003
  renderSingleNode(node.children[summaryAt]),
@@ -13161,7 +13170,7 @@ function buildPlainTextVnodes(core, ph, unwrapParagraphs) {
13161
13170
  function renderNodes(nodes, options) {
13162
13171
  if (nodes.length === 0) return null;
13163
13172
  if (options?.raw) return renderInlineNodes(nodes);
13164
- if (options?.structural && nodes.every((n) => n.type !== "text" || n.value.trim() === "")) return nodes.filter((n) => n.type !== "text").map(renderSingleNode);
13173
+ if (options?.structural && nodes.every((n) => n.type !== "text" || isBlankText(n))) return nodes.filter((n) => n.type !== "text").map(renderSingleNode);
13165
13174
  if (!nodes.some((n) => n.type === "text" && (n.value.trim() !== "" || BLANK_LINE_RE.test(n.value)))) return nodes.map((node) => renderSingleNode(node));
13166
13175
  const components = [];
13167
13176
  const ph = {
@@ -15767,13 +15776,13 @@ var VALID_EVENTS = new Set([
15767
15776
  "passagerender",
15768
15777
  "dialogrender"
15769
15778
  ]);
15770
- var listeners = /* @__PURE__ */ new Map();
15779
+ var listeners$1 = /* @__PURE__ */ new Map();
15771
15780
  function on(event, cb) {
15772
15781
  if (!VALID_EVENTS.has(event)) throw new Error(`spindle: Unknown event "${event}".`);
15773
- let set = listeners.get(event);
15782
+ let set = listeners$1.get(event);
15774
15783
  if (!set) {
15775
15784
  set = /* @__PURE__ */ new Set();
15776
- listeners.set(event, set);
15785
+ listeners$1.set(event, set);
15777
15786
  }
15778
15787
  set.add(cb);
15779
15788
  return () => {
@@ -15782,7 +15791,7 @@ function on(event, cb) {
15782
15791
  }
15783
15792
  /** Call `call` with each listener of `event`. */
15784
15793
  function forEachListener(event, call) {
15785
- const set = listeners.get(event);
15794
+ const set = listeners$1.get(event);
15786
15795
  if (!set) return;
15787
15796
  for (const cb of [...set]) call(cb);
15788
15797
  }
@@ -18603,6 +18612,24 @@ var openModals = [];
18603
18612
  * - closes the topmost dialog on Escape when it is dismissible;
18604
18613
  * - returns focus to the previously focused element on close.
18605
18614
  */
18615
+ /** The input types made of several segments, each a native Tab stop. */
18616
+ var SEGMENTED_INPUTS = new Set([
18617
+ "date",
18618
+ "time",
18619
+ "datetime-local",
18620
+ "month",
18621
+ "week"
18622
+ ]);
18623
+ /** Whether the element has native tab stops inside it, in its shadow tree. */
18624
+ function hasNativeStops(el) {
18625
+ if (el instanceof HTMLMediaElement) return el.controls;
18626
+ return el instanceof HTMLInputElement && SEGMENTED_INPUTS.has(el.type) && !el.readOnly;
18627
+ }
18628
+ /** The tab stops of an embedded document, in tab order. */
18629
+ function frameStops(doc) {
18630
+ if (!doc) return [];
18631
+ return Array.from(doc.querySelectorAll(FOCUSABLE)).filter((el) => isAvailable(el) && isTabStop(el));
18632
+ }
18606
18633
  function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18607
18634
  useLayoutEffect(() => {
18608
18635
  const panel = panelRef.current;
@@ -18630,6 +18657,21 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18630
18657
  * (#424). `from` may be an element of an embedded document, whose frame
18631
18658
  * element then stands in for it.
18632
18659
  */
18660
+ /** Focus `el`; a frame is entered at its first (or last) control (#460). */
18661
+ const enter = (el, backwards) => {
18662
+ if (el instanceof HTMLIFrameElement) {
18663
+ let inner = [];
18664
+ try {
18665
+ inner = frameStops(el.contentDocument);
18666
+ } catch {}
18667
+ const edge = backwards ? inner[inner.length - 1] : inner[0];
18668
+ if (edge) {
18669
+ edge.focus();
18670
+ return;
18671
+ }
18672
+ }
18673
+ el.focus();
18674
+ };
18633
18675
  const moveFocus = (from, backwards) => {
18634
18676
  const items = focusables(panel);
18635
18677
  const first = items[0];
@@ -18645,9 +18687,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18645
18687
  const after = (el) => !!(from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING);
18646
18688
  next = backwards ? items.filter((el) => !after(el)).pop() : items.find(after);
18647
18689
  } else next = backwards ? last : first;
18648
- (next ?? (backwards ? last : first)).focus();
18690
+ enter(next ?? (backwards ? last : first), backwards);
18649
18691
  };
18650
- let steppingMedia = null;
18692
+ let steppingNative = null;
18651
18693
  const onKeyDown = (e) => {
18652
18694
  if (!top()) return;
18653
18695
  if (e.key === "Escape") {
@@ -18659,8 +18701,8 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18659
18701
  }
18660
18702
  if (e.key !== "Tab") return;
18661
18703
  const active = document.activeElement;
18662
- if (active instanceof HTMLMediaElement && active.controls) {
18663
- steppingMedia = {
18704
+ if (hasNativeStops(active)) {
18705
+ steppingNative = {
18664
18706
  el: active,
18665
18707
  backwards: e.shiftKey
18666
18708
  };
@@ -18670,7 +18712,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18670
18712
  moveFocus(active, e.shiftKey);
18671
18713
  };
18672
18714
  const onPointerDown = () => {
18673
- steppingMedia = null;
18715
+ steppingNative = null;
18674
18716
  };
18675
18717
  const controller = new AbortController();
18676
18718
  const { signal } = controller;
@@ -18685,7 +18727,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18685
18727
  const onFrameKeyDown = (e) => {
18686
18728
  if (!top()) return;
18687
18729
  if (e.key !== "Tab") return onKeyDown(e);
18688
- const inner = Array.from(doc.querySelectorAll(FOCUSABLE)).filter((el) => isAvailable(el) && isTabStop(el));
18730
+ const inner = frameStops(doc);
18689
18731
  const active = doc.activeElement;
18690
18732
  const edge = e.shiftKey ? inner[0] : inner[inner.length - 1];
18691
18733
  if (!edge || active === edge || active === doc.body) {
@@ -18713,9 +18755,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18713
18755
  attachFrames();
18714
18756
  const onFocusIn = (e) => {
18715
18757
  const target = e.target;
18716
- if (steppingMedia && target !== steppingMedia.el && top()) {
18717
- const { el, backwards } = steppingMedia;
18718
- steppingMedia = null;
18758
+ if (steppingNative && target !== steppingNative.el && top()) {
18759
+ const { el, backwards } = steppingNative;
18760
+ steppingNative = null;
18719
18761
  moveFocus(el, backwards);
18720
18762
  return;
18721
18763
  }
@@ -18729,9 +18771,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18729
18771
  signal
18730
18772
  });
18731
18773
  const onFocusOut = (e) => {
18732
- const pending = steppingMedia;
18774
+ const pending = steppingNative;
18733
18775
  if (!pending || e.target !== pending.el || e.relatedTarget || !top()) return;
18734
- steppingMedia = null;
18776
+ steppingNative = null;
18735
18777
  moveFocus(pending.el, pending.backwards);
18736
18778
  };
18737
18779
  document.addEventListener("focusout", onFocusOut, { signal });
@@ -18745,7 +18787,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18745
18787
  //#endregion
18746
18788
  //#region src/components/PassageDialog.tsx
18747
18789
  var DialogCloseContext = createContext(null);
18748
- function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismissible = true, showCloseButton = dismissible }) {
18790
+ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, label, dismissible = true, showCloseButton = dismissible }) {
18749
18791
  const onCloseRef = useRef(onClose);
18750
18792
  onCloseRef.current = onClose;
18751
18793
  const stableOnClose = useCallback(() => onCloseRef.current(), []);
@@ -18772,9 +18814,19 @@ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismi
18772
18814
  }
18773
18815
  }, [markup, nobr]);
18774
18816
  const panelRef = useRef(null);
18817
+ const labelId = useId();
18775
18818
  const viewScope = useViewScope();
18776
18819
  useModalFocus(panelRef, ".dialog-body", dismissible, stableOnClose);
18777
18820
  useLayoutEffect(() => registerOpenDialog(stableOnClose), [stableOnClose]);
18821
+ useLayoutEffect(() => {
18822
+ const panel = panelRef.current;
18823
+ if (!panel || label) return;
18824
+ const heading = panel.querySelector(".dialog-body :is(h1, h2, h3, h4, h5, h6)");
18825
+ if (!heading) return;
18826
+ heading.id ||= `${labelId}-heading`;
18827
+ panel.setAttribute("aria-labelledby", heading.id);
18828
+ return () => panel.removeAttribute("aria-labelledby");
18829
+ }, [label, markup]);
18778
18830
  useLayoutEffect(() => {
18779
18831
  if (panelRef.current) emitFromRender("dialogrender", passageName ?? "", panelRef.current);
18780
18832
  }, []);
@@ -18793,6 +18845,7 @@ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismi
18793
18845
  class: cls,
18794
18846
  role: "dialog",
18795
18847
  "aria-modal": "true",
18848
+ "aria-label": label ?? passageName,
18796
18849
  tabIndex: -1,
18797
18850
  children: [showCloseButton && /* @__PURE__ */ jsx("button", {
18798
18851
  type: "button",
@@ -19108,6 +19161,12 @@ var definitions = /* @__PURE__ */ new Map();
19108
19161
  var values = createNamespace();
19109
19162
  var storageLoaded = false;
19110
19163
  var unsubscribeStoryData = null;
19164
+ var listeners = /* @__PURE__ */ new Set();
19165
+ /** Call `listener` after a setting changes; returns the unsubscribe. */
19166
+ function subscribeSettings(listener) {
19167
+ listeners.add(listener);
19168
+ return () => listeners.delete(listener);
19169
+ }
19111
19170
  function storageKey() {
19112
19171
  return `spindle.${useStoryStore.getState().storyData?.ifid || "unknown"}.settings`;
19113
19172
  }
@@ -19181,6 +19240,7 @@ var settings = {
19181
19240
  set(name, value) {
19182
19241
  values[name] = value;
19183
19242
  persist();
19243
+ for (const listener of [...listeners]) listener();
19184
19244
  },
19185
19245
  getAll() {
19186
19246
  return { ...values };
@@ -19875,13 +19935,10 @@ function distance(a, b) {
19875
19935
  }
19876
19936
  return prev[b.length];
19877
19937
  }
19878
- /**
19879
- * " Did you mean …?" with the known name closest to `name`, written by
19880
- * `quote`, if one is close.
19881
- */
19882
- function didYouMean(name, names, quote) {
19938
+ /** The known name closest to `name`, if one is close. */
19939
+ function closestName(name, names) {
19883
19940
  const lower = name.toLowerCase();
19884
- let best = "";
19941
+ let best;
19885
19942
  let bestDistance = Math.max(2, Math.floor(lower.length / 3)) + 1;
19886
19943
  for (const candidate of names) {
19887
19944
  const d = distance(lower, candidate.toLowerCase());
@@ -19890,8 +19947,10 @@ function didYouMean(name, names, quote) {
19890
19947
  bestDistance = d;
19891
19948
  }
19892
19949
  }
19893
- return best ? ` Did you mean ${quote(best)}?` : "";
19950
+ return best;
19894
19951
  }
19952
+ /** " Did you mean …?" with `best`, written by `quote`, if there is one. */
19953
+ var didYouMean = (best, quote) => best ? ` Did you mean ${quote(best)}?` : "";
19895
19954
  /** What a passage argument may be, after an error in one. */
19896
19955
  var PASSAGE_ARGUMENT_HINT = " (a passage name is a quoted string or an expression)";
19897
19956
  /** A passage argument that is one bare word (`{goto Kitchen}`). */
@@ -19911,14 +19970,18 @@ function widgetName(rawArgs) {
19911
19970
  function validateMarkup(passages, options) {
19912
19971
  const diagnostics = [];
19913
19972
  const hooks = options.isBlockMacro ? { isBlock: options.isBlockMacro } : void 0;
19914
- const report = (passage, offset, message) => {
19915
- const { line, column } = lineColumn(passage.content, offset);
19973
+ const report = (passage, start, end, code, message, data) => {
19974
+ const { line, column } = lineColumn(passage.content, start);
19916
19975
  const d = {
19917
19976
  passage: passage.name,
19918
19977
  line,
19919
19978
  column,
19920
- message
19979
+ message,
19980
+ code,
19981
+ start,
19982
+ end
19921
19983
  };
19984
+ if (data) d.data = data;
19922
19985
  const file = passage.metadata?.["data-source-file"];
19923
19986
  if (file) {
19924
19987
  d.file = file;
@@ -19927,6 +19990,8 @@ function validateMarkup(passages, options) {
19927
19990
  }
19928
19991
  diagnostics.push(d);
19929
19992
  };
19993
+ /** Report malformed markup. */
19994
+ const reportError = (passage, err, where) => report(passage, err.offset, err.end, err.code, where + err.reason, err.data);
19930
19995
  const parsed = [];
19931
19996
  const widgets = /* @__PURE__ */ new Set();
19932
19997
  const passageNames = /* @__PURE__ */ new Set();
@@ -19948,72 +20013,330 @@ function validateMarkup(passages, options) {
19948
20013
  parsed.push([passage, tokens]);
19949
20014
  } catch (err) {
19950
20015
  if (!(err instanceof MarkupError)) throw err;
19951
- if (reported) report(passage, err.offset, err.reason);
20016
+ if (reported) reportError(passage, err, "");
19952
20017
  }
19953
20018
  }
19954
20019
  const names = [...options.macroNames ?? [], ...widgets];
19955
- /** Report the unknown macros among `tokens`, which start at `base`. */
19956
- const checkMacros = (passage, tokens, base, where) => {
20020
+ /** Report the unknown macros among `tokens`, with `where` in front. */
20021
+ const checkMacros = (passage, tokens, where) => {
19957
20022
  for (const token of tokens) {
19958
20023
  if (token.type !== "macro" || token.isClose) continue;
19959
20024
  const lower = token.name.toLowerCase();
19960
20025
  if (BRANCH_MACROS.has(lower) || widgets.has(lower) || options.isKnownMacro(lower)) continue;
19961
- report(passage, base + token.start, `${where}Unknown macro {${token.name}}.${didYouMean(token.name, names, (n) => `{${n}}`)}`);
20026
+ const best = closestName(token.name, names);
20027
+ report(passage, token.start, token.end, "unknown-macro", `${where}Unknown macro {${token.name}}.${didYouMean(best, (n) => `{${n}}`)}`, {
20028
+ name: token.name,
20029
+ suggestions: best ? [best] : []
20030
+ });
19962
20031
  }
19963
20032
  };
19964
20033
  const parametersOf = options.parametersOf ?? (() => void 0);
19965
20034
  /**
19966
- * Check `tokens`, the tokens of `src`, which starts at `base` in the
19967
- * passage: their macros, the code in them and the markup in their text.
20035
+ * Check the pieces of a passage: its macros, the code in them, the passage
20036
+ * names they write out and the markup in their text.
19968
20037
  */
19969
- const checkTokens = (passage, src, tokens, base, where) => {
19970
- checkMacros(passage, tokens, base, where);
19971
- for (const piece of codeAndText(src, tokens, parametersOf)) {
19972
- const at = base + piece.offset;
19973
- if (piece.kind === "argument-error") {
19974
- report(passage, at, `${where}${piece.message} in ${piece.label}`);
19975
- continue;
20038
+ const checkPassage = (passage, tokens) => {
20039
+ checkMacros(passage, tokens, "");
20040
+ let skipTo = 0;
20041
+ for (const piece of passagePiecesOf(passage.content, tokens, parametersOf, { isBlock: options.isBlockMacro })) {
20042
+ if (piece.nested && piece.offset < skipTo) continue;
20043
+ const at = piece.offset;
20044
+ const where = piece.where && piece.nested ? piece.where : "";
20045
+ switch (piece.kind) {
20046
+ case "argument-error":
20047
+ report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
20048
+ break;
20049
+ case "passage":
20050
+ if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
20051
+ const best = closestName(piece.name, passageNames);
20052
+ report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
20053
+ name: piece.name,
20054
+ macro: piece.macro,
20055
+ suggestions: best ? [best] : []
20056
+ });
20057
+ }
20058
+ break;
20059
+ case "code":
20060
+ checkCode(passage, piece, where);
20061
+ break;
20062
+ case "text": if (piece.errors.length > 0) {
20063
+ reportError(passage, piece.errors[0], piece.where);
20064
+ skipTo = pieceOffset(piece, piece.text.length);
20065
+ } else checkMacros(passage, piece.tokens, piece.where);
19976
20066
  }
19977
- if (piece.kind === "passage") {
19978
- if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
19979
- const hint = didYouMean(piece.name, passageNames, JSON.stringify);
19980
- report(passage, at, `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${hint}`);
19981
- }
19982
- continue;
20067
+ }
20068
+ };
20069
+ const checkCode = (passage, piece, where) => {
20070
+ const at = piece.offset;
20071
+ const result = parseOrError(piece.code, piece.goal);
20072
+ const code = piece.code.trim();
20073
+ if (result instanceof CodeSyntaxError) {
20074
+ const offending = /^(?:[\w$]+|\S)/.exec(piece.code.slice(result.pos));
20075
+ report(passage, pieceOffset(piece, result.pos), pieceOffset(piece, result.pos + (offending?.[0].length ?? 0)), "code-syntax", `${where}${result.reasonIn(passage.content, at)} in ${piece.label}` + (piece.passage ? PASSAGE_ARGUMENT_HINT : ""), piece.macro ? { macro: piece.macro } : void 0);
20076
+ } else if (piece.passage && BARE_WORD_RE.test(code)) {
20077
+ const lead = piece.code.length - piece.code.trimStart().length;
20078
+ report(passage, pieceOffset(piece, lead), pieceOffset(piece, lead + code.length), "unquoted-passage-name", `${where}Unquoted passage name in ${piece.label}: write ${JSON.stringify(code)}${PASSAGE_ARGUMENT_HINT}`, {
20079
+ name: code,
20080
+ macro: piece.macro ?? ""
20081
+ });
20082
+ }
20083
+ };
20084
+ for (const [passage, tokens] of parsed) withParseCache(() => checkPassage(passage, tokens));
20085
+ return diagnostics;
20086
+ }
20087
+ //#endregion
20088
+ //#region src/static-literal.ts
20089
+ /**
20090
+ * The shape of a JavaScript literal, read from its text without running it:
20091
+ * what a StoryVariables initializer is when it is a literal, or an array or
20092
+ * object literal of literals (see parseDeclarations in story-variables.ts).
20093
+ *
20094
+ * The reader is deliberately small. Anything it does not recognise (a call,
20095
+ * an operator, a reference, a spread) is "not static", which is no error: the
20096
+ * value is simply not known without running the code.
20097
+ */
20098
+ var NUMBER_RE = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][+-]?\d+)?)(n?)/y;
20099
+ var IDENT_RE = /[A-Za-z_$][\w$]*/y;
20100
+ var ARROW_RE = /(?:async\s+)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*=>/y;
20101
+ /** Read `src`, one literal and nothing else. */
20102
+ function staticLiteral(src) {
20103
+ const reader = new Reader(src);
20104
+ const value = reader.value();
20105
+ reader.space();
20106
+ return reader.i === src.length ? value : void 0;
20107
+ }
20108
+ var Reader = class {
20109
+ constructor(src) {
20110
+ this.src = src;
20111
+ this.i = 0;
20112
+ }
20113
+ /** Skip whitespace and comments. */
20114
+ space() {
20115
+ const { src } = this;
20116
+ for (;;) {
20117
+ while (/\s/.test(src.charAt(this.i))) this.i++;
20118
+ if (src.startsWith("//", this.i)) {
20119
+ const end = src.indexOf("\n", this.i);
20120
+ this.i = end < 0 ? src.length : end;
20121
+ } else if (src.startsWith("/*", this.i)) {
20122
+ const end = src.indexOf("*/", this.i + 2);
20123
+ this.i = end < 0 ? src.length : end + 2;
20124
+ } else return;
20125
+ }
20126
+ }
20127
+ /** The value at the cursor, which is left after it (or anywhere, if not static). */
20128
+ value() {
20129
+ const { src } = this;
20130
+ this.space();
20131
+ const c = src.charAt(this.i);
20132
+ if (c === "\"" || c === "'") return this.string().closed ? { shape: { type: "string" } } : void 0;
20133
+ if (c === "`") return this.template();
20134
+ if (c === "[") return this.skipBalanced() ? { shape: { type: "array" } } : void 0;
20135
+ if (c === "{") return this.object();
20136
+ if (/[\d.+-]/.test(c)) return this.number();
20137
+ if (/[A-Za-z_$(]/.test(c)) return this.word();
20138
+ }
20139
+ /** Skip the string literal at the cursor: its body, and whether it is closed. */
20140
+ string() {
20141
+ const { end, closed } = scanStringLiteral(this.src, this.i);
20142
+ const body = this.src.slice(this.i + 1, closed ? end - 1 : end);
20143
+ this.i = end;
20144
+ return {
20145
+ body,
20146
+ closed
20147
+ };
20148
+ }
20149
+ /** A template literal: a string, but for `${}`. */
20150
+ template() {
20151
+ const { src } = this;
20152
+ for (let i = this.i + 1; i < src.length; i++) {
20153
+ const c = src.charAt(i);
20154
+ if (c === "\\") i++;
20155
+ else if (c === "`") {
20156
+ this.i = i + 1;
20157
+ return { shape: { type: "string" } };
20158
+ } else if (c === "$" && src.charAt(i + 1) === "{") return void 0;
20159
+ }
20160
+ }
20161
+ /** A number, or a sign and one. */
20162
+ number() {
20163
+ const { src } = this;
20164
+ let i = this.i;
20165
+ if (src.charAt(i) === "+" || src.charAt(i) === "-") {
20166
+ i++;
20167
+ while (/\s/.test(src.charAt(i))) i++;
20168
+ }
20169
+ NUMBER_RE.lastIndex = i;
20170
+ const match = NUMBER_RE.exec(src);
20171
+ if (match) {
20172
+ this.i = NUMBER_RE.lastIndex;
20173
+ return match[1] ? { unsupported: "bigint" } : { shape: { type: "number" } };
20174
+ }
20175
+ IDENT_RE.lastIndex = i;
20176
+ if (IDENT_RE.exec(src)?.[0] === "Infinity") {
20177
+ this.i = IDENT_RE.lastIndex;
20178
+ return { shape: { type: "number" } };
20179
+ }
20180
+ }
20181
+ /** A keyword, a function, or a name (which is not static). */
20182
+ word() {
20183
+ const { src } = this;
20184
+ ARROW_RE.lastIndex = this.i;
20185
+ if (ARROW_RE.test(src)) return this.function();
20186
+ IDENT_RE.lastIndex = this.i;
20187
+ const word = IDENT_RE.exec(src)?.[0];
20188
+ if (word === void 0) return void 0;
20189
+ const end = IDENT_RE.lastIndex;
20190
+ switch (word) {
20191
+ case "true":
20192
+ case "false":
20193
+ this.i = end;
20194
+ return { shape: { type: "boolean" } };
20195
+ case "null":
20196
+ this.i = end;
20197
+ return { shape: { type: "null" } };
20198
+ case "NaN":
20199
+ this.i = end;
20200
+ return { shape: { type: "number" } };
20201
+ case "undefined":
20202
+ this.i = end;
20203
+ return { unsupported: "undefined" };
20204
+ case "function":
20205
+ case "class":
20206
+ case "async": return this.function();
20207
+ }
20208
+ }
20209
+ /** A function (or class): the rest is its body, which is not read. */
20210
+ function() {
20211
+ return this.unsupported({ unsupported: "function" });
20212
+ }
20213
+ /** `value`, which makes the whole literal unsupported: the rest is not read. */
20214
+ unsupported(value) {
20215
+ this.i = this.src.length;
20216
+ return value;
20217
+ }
20218
+ /** An object literal: the members that are static. */
20219
+ object() {
20220
+ const { src } = this;
20221
+ const fields = /* @__PURE__ */ new Map();
20222
+ this.i++;
20223
+ for (;;) {
20224
+ this.space();
20225
+ const c = src.charAt(this.i);
20226
+ if (c === "}") {
20227
+ this.i++;
20228
+ return { shape: {
20229
+ type: "object",
20230
+ fields
20231
+ } };
19983
20232
  }
19984
- if (piece.kind === "code") {
19985
- const result = parseOrError(piece.code, piece.goal);
19986
- const code = piece.code.trim();
19987
- if (result instanceof CodeSyntaxError) {
19988
- const reason = result.reasonIn(passage.content, at);
19989
- report(passage, at + result.pos, `${where}${reason} in ${piece.label}` + (piece.passage ? PASSAGE_ARGUMENT_HINT : ""));
19990
- } else if (piece.passage && BARE_WORD_RE.test(code)) report(passage, at, `${where}Unquoted passage name in ${piece.label}: write ${JSON.stringify(code)}${PASSAGE_ARGUMENT_HINT}`);
20233
+ if (c === ",") {
20234
+ this.i++;
19991
20235
  continue;
19992
20236
  }
19993
- if (!piece.text.includes("{")) continue;
19994
- try {
19995
- parseMarkup(piece.text, {
19996
- text: true,
19997
- hooks
19998
- });
19999
- const inner = tokenizeMarkup(piece.text, { text: true });
20000
- checkTokens(passage, piece.text, inner, at, piece.where);
20001
- } catch (err) {
20002
- if (!(err instanceof MarkupError)) throw err;
20003
- report(passage, at + err.offset, piece.where + err.reason);
20237
+ if (this.i >= src.length) return void 0;
20238
+ const key = this.key();
20239
+ this.space();
20240
+ if (key !== void 0 && src.charAt(this.i) === ":") {
20241
+ this.i++;
20242
+ const at = this.i;
20243
+ const value = this.value();
20244
+ this.space();
20245
+ if (value && "unsupported" in value) return this.unsupported(value);
20246
+ if (value && ",}".includes(src.charAt(this.i))) {
20247
+ fields.set(key, value.shape);
20248
+ continue;
20249
+ }
20250
+ this.i = at;
20251
+ } else if (key !== void 0 && src.charAt(this.i) === "(") return this.unsupported({ unsupported: "function" });
20252
+ if (!this.skipMember()) return void 0;
20253
+ }
20254
+ }
20255
+ /** The key of a member (a name, a string or a number), if it has one. */
20256
+ key() {
20257
+ const { src } = this;
20258
+ const c = src.charAt(this.i);
20259
+ if (c === "\"" || c === "'") {
20260
+ const { body, closed } = this.string();
20261
+ return closed ? body : void 0;
20262
+ }
20263
+ const word = /[\w$]+/y;
20264
+ word.lastIndex = this.i;
20265
+ const found = word.exec(src)?.[0];
20266
+ if (found === void 0) return void 0;
20267
+ this.i = word.lastIndex;
20268
+ return found;
20269
+ }
20270
+ /** Skip to the `,` or `}` that ends a member, balancing what is inside. */
20271
+ skipMember() {
20272
+ const { src } = this;
20273
+ while (this.i < src.length) {
20274
+ const c = src.charAt(this.i);
20275
+ if (c === "," || c === "}") return true;
20276
+ if (!this.skipOne()) return false;
20277
+ }
20278
+ return false;
20279
+ }
20280
+ /** Skip an array literal (or any bracketed group) at the cursor. */
20281
+ skipBalanced() {
20282
+ const { src } = this;
20283
+ const close = {
20284
+ "[": "]",
20285
+ "{": "}",
20286
+ "(": ")"
20287
+ }[src.charAt(this.i)];
20288
+ if (!close) return false;
20289
+ this.i++;
20290
+ while (this.i < src.length) {
20291
+ if (src.charAt(this.i) === close) {
20292
+ this.i++;
20293
+ return true;
20004
20294
  }
20295
+ if (!this.skipOne()) return false;
20005
20296
  }
20006
- };
20007
- for (const [passage, tokens] of parsed) withParseCache(() => checkTokens(passage, passage.content, tokens, 0, ""));
20008
- return diagnostics;
20009
- }
20297
+ return false;
20298
+ }
20299
+ /** Skip one character, or one string, template, comment or group. */
20300
+ skipOne() {
20301
+ const { src } = this;
20302
+ const c = src.charAt(this.i);
20303
+ if (c === "\"" || c === "'") return this.string().closed;
20304
+ if (c === "`") return this.skipTemplate();
20305
+ if (src.startsWith("//", this.i) || src.startsWith("/*", this.i)) {
20306
+ this.space();
20307
+ return true;
20308
+ }
20309
+ if (c === "[" || c === "{" || c === "(") return this.skipBalanced();
20310
+ if (c === "]" || c === "}" || c === ")") return false;
20311
+ this.i++;
20312
+ return true;
20313
+ }
20314
+ /** Skip a template literal, with the expressions in it. */
20315
+ skipTemplate() {
20316
+ const { src } = this;
20317
+ this.i++;
20318
+ while (this.i < src.length) {
20319
+ const c = src.charAt(this.i);
20320
+ if (c === "\\") this.i += 2;
20321
+ else if (c === "`") {
20322
+ this.i++;
20323
+ return true;
20324
+ } else if (c === "$" && src.charAt(this.i + 1) === "{") {
20325
+ this.i++;
20326
+ if (!this.skipBalanced()) return false;
20327
+ } else this.i++;
20328
+ }
20329
+ return false;
20330
+ }
20331
+ };
20010
20332
  //#endregion
20011
20333
  //#region src/story-variables.ts
20012
20334
  /**
20013
- * The tokens of markup, or none if it is malformed: validateMarkup reports
20014
- * that, with its position.
20335
+ * The tokens of markup, or none if it is malformed (validateMarkup reports
20336
+ * that, with its position); in tolerant mode, those of the well-formed parts.
20015
20337
  */
20016
- function tokensOf(text, textMode) {
20338
+ function tokensOf(text, textMode, { tolerant } = {}) {
20339
+ if (tolerant) return tokenizeMarkupTolerant(text, { text: textMode }).tokens;
20017
20340
  try {
20018
20341
  return tokenizeMarkup(text, { text: textMode });
20019
20342
  } catch (err) {
@@ -20025,8 +20348,8 @@ function declarationRegex(sigil) {
20025
20348
  const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20026
20349
  return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
20027
20350
  }
20028
- /** A `$name` reference with its dot path, at a `$` the lexer found. */
20029
- var VAR_PATH_RE = /\$(\w+(?:\.\w+)*)/y;
20351
+ /** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
20352
+ var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
20030
20353
  /** Quoted first argument of an input macro naming a story variable. */
20031
20354
  var QUOTED_VAR_ARG_RE = /^["']\$(\w+(?:\.\w+)*)["']?$/;
20032
20355
  var VALID_VAR_TYPES = new Set([
@@ -20064,22 +20387,101 @@ function inferSchema(value, seen = /* @__PURE__ */ new Map()) {
20064
20387
  if (!VALID_VAR_TYPES.has(jsType)) throw new Error(`Unsupported type "${jsType}" for value ${String(value)}. Expected number, string, boolean, array, or object.`);
20065
20388
  return { type: jsType };
20066
20389
  }
20390
+ var UNSUPPORTED_TYPE = "Expected number, string, boolean, array, or object.";
20391
+ /** The schema of a literal shape (see staticLiteral). */
20392
+ function shapeSchema(shape) {
20393
+ if (!shape.fields) return { type: shape.type };
20394
+ const fields = /* @__PURE__ */ new Map();
20395
+ for (const [key, member] of shape.fields) fields.set(key, shapeSchema(member));
20396
+ return {
20397
+ type: shape.type,
20398
+ fields
20399
+ };
20400
+ }
20067
20401
  /**
20068
- * Parse a StoryVariables or StoryTransients passage content into a schema map.
20069
- * Each line: `$varName = expression` (or `%varName = expression` for transients)
20070
- */
20071
- function parseStoryVariables(content, sigil = "$") {
20072
- const schema = /* @__PURE__ */ new Map();
20402
+ * Read the declarations of a StoryVariables (`$name = value`) or
20403
+ * StoryTransients (`%name = value`) passage, without evaluating them and
20404
+ * without throwing: every valid declaration, and every invalid line as an
20405
+ * error. It is the grammar parseStoryVariables reads with.
20406
+ *
20407
+ * A declaration is a line of the form `$name = expression`; blank lines are
20408
+ * skipped. A line that is not, and a name that cannot be a variable, are
20409
+ * errors. So is an initializer that no variable can hold (a function,
20410
+ * `undefined`), when it is a literal; whether any other initializer can only
20411
+ * be known by running it. A name declared again is an error too, but both
20412
+ * declarations are returned (the later wins when evaluated).
20413
+ */
20414
+ function parseDeclarations(content, sigil = "$") {
20415
+ const declarations = [];
20416
+ const errors = [];
20073
20417
  const DECLARATION_RE = declarationRegex(sigil);
20074
- const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
20418
+ const seen = /* @__PURE__ */ new Set();
20419
+ let lineStart = 0;
20075
20420
  for (const rawLine of content.split("\n")) {
20421
+ const at = lineStart + rawLine.length - rawLine.trimStart().length;
20422
+ lineStart += rawLine.length + 1;
20076
20423
  const line = rawLine.trim();
20077
20424
  if (!line) continue;
20078
20425
  const match = line.match(DECLARATION_RE);
20079
- if (!match) throw new Error(`${passageName}: Invalid declaration: "${line}". Expected: ${sigil}name = value`);
20426
+ const error = (code, start, end, message) => errors.push({
20427
+ code,
20428
+ offset: start,
20429
+ end,
20430
+ message
20431
+ });
20432
+ if (!match) {
20433
+ error("invalid-declaration", at, at + line.length, `Invalid declaration: "${line}". Expected: ${sigil}name = value`);
20434
+ continue;
20435
+ }
20080
20436
  const [, name, expr] = match;
20437
+ const nameStart = at + sigil.length;
20438
+ const nameEnd = nameStart + name.length;
20081
20439
  const nameError = variableNameError(name, sigil + name);
20082
- if (nameError) throw new Error(`${passageName}: ${nameError}`);
20440
+ if (nameError) {
20441
+ error("invalid-name", nameStart, nameEnd, nameError);
20442
+ continue;
20443
+ }
20444
+ const valueEnd = at + line.length;
20445
+ const declaration = {
20446
+ name,
20447
+ nameStart,
20448
+ nameEnd,
20449
+ valueStart: valueEnd - expr.length,
20450
+ valueEnd
20451
+ };
20452
+ if (seen.has(name)) error("duplicate-declaration", nameStart, nameEnd, `Duplicate declaration of ${sigil}${name}`);
20453
+ seen.add(name);
20454
+ const literal = staticLiteral(expr);
20455
+ if (literal && "shape" in literal) declaration.schema = shapeSchema(literal.shape);
20456
+ else if (literal) error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${expr}. ${UNSUPPORTED_TYPE}`);
20457
+ declarations.push(declaration);
20458
+ }
20459
+ return {
20460
+ declarations,
20461
+ errors
20462
+ };
20463
+ }
20464
+ /**
20465
+ * Parse a StoryVariables or StoryTransients passage content into a schema map.
20466
+ * Each line: `$varName = expression` (or `%varName = expression` for transients)
20467
+ * The expressions are evaluated; parseDeclarations reads the same lines
20468
+ * without.
20469
+ */
20470
+ function parseStoryVariables(content, sigil = "$") {
20471
+ const schema = /* @__PURE__ */ new Map();
20472
+ const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
20473
+ const { declarations, errors } = parseDeclarations(content, sigil);
20474
+ const lines = [...errors.filter((e) => e.code === "invalid-declaration" || e.code === "invalid-name").map((e) => ({
20475
+ at: e.offset,
20476
+ error: e
20477
+ })), ...declarations.map((d) => ({
20478
+ at: d.nameStart,
20479
+ declaration: d
20480
+ }))].sort((a, b) => a.at - b.at);
20481
+ for (const line of lines) {
20482
+ if ("error" in line) throw new Error(`${passageName}: ${line.error.message}`);
20483
+ const { name, valueStart, valueEnd } = line.declaration;
20484
+ const expr = content.slice(valueStart, valueEnd);
20083
20485
  let value;
20084
20486
  try {
20085
20487
  value = new Function("return (" + expr + ")")();
@@ -20101,19 +20503,30 @@ function parseStoryVariables(content, sigil = "$") {
20101
20503
  return schema;
20102
20504
  }
20103
20505
  /**
20104
- * Validate a single variable reference path (e.g. "player.health") against
20105
- * the schema. Returns an error message or null if valid.
20506
+ * Check a reference against the declarations: the error code and message, or
20507
+ * null if it is valid. (Unknown fields of objects are valid: classes
20508
+ * registered with Story.registerClass() can add members that are not in the
20509
+ * defaults.)
20106
20510
  */
20107
- function validateRef(ref, schema) {
20108
- const parts = ref.split(".");
20109
- const rootName = parts[0];
20110
- const nameError = variableNameError(rootName, "$" + rootName);
20111
- if (nameError) return nameError;
20112
- const rootSchema = schema.get(rootName);
20113
- if (!rootSchema) return `Undeclared variable: $${ref}`;
20114
- let current = rootSchema;
20115
- for (let i = 1; i < parts.length; i++) {
20116
- const part = parts[i];
20511
+ function checkReference(ref, declared) {
20512
+ const label = (path) => ref.sigil + [ref.name, ...path].join(".");
20513
+ const nameError = variableNameError(ref.name, ref.sigil + ref.name);
20514
+ if (nameError) return {
20515
+ code: "reserved-name",
20516
+ message: nameError
20517
+ };
20518
+ const schema = ref.sigil === "$" ? declared.variables : declared.transients;
20519
+ if (!schema) return null;
20520
+ if (!schema.has(ref.name)) return ref.sigil === "$" ? {
20521
+ code: "undeclared-variable",
20522
+ message: `Undeclared variable: ${label(ref.path)}`
20523
+ } : {
20524
+ code: "undeclared-transient",
20525
+ message: `Undeclared transient: ${label(ref.path)}`
20526
+ };
20527
+ let current = schema.get(ref.name);
20528
+ for (let i = 0; current && i < ref.path.length; i++) {
20529
+ const part = ref.path[i];
20117
20530
  if (current.type === "array") return null;
20118
20531
  if (current.type === "null") return null;
20119
20532
  const sample = PRIMITIVE_SAMPLES[current.type];
@@ -20123,10 +20536,11 @@ function validateRef(ref, schema) {
20123
20536
  current = { type: memberType };
20124
20537
  continue;
20125
20538
  }
20126
- if (current.type !== "object" || !current.fields) return `Cannot access field "${part}" on $${parts.slice(0, i).join(".")} (type: ${current.type})`;
20127
- const fieldSchema = current.fields.get(part);
20128
- if (!fieldSchema) return null;
20129
- current = fieldSchema;
20539
+ if (current.type !== "object" || !current.fields) return {
20540
+ code: "primitive-field",
20541
+ message: `Cannot access field "${part}" on ${label(ref.path.slice(0, i))} (type: ${current.type})`
20542
+ };
20543
+ current = current.fields.get(part);
20130
20544
  }
20131
20545
  return null;
20132
20546
  }
@@ -20144,12 +20558,27 @@ var BUILTIN_STORE_VAR_MACROS = [
20144
20558
  "textbox"
20145
20559
  ];
20146
20560
  var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
20561
+ /** A reference written at `index` of `code`, with its dot path. */
20562
+ function referenceAt(code, index, at) {
20563
+ VAR_PATH_RE.lastIndex = index;
20564
+ const match = VAR_PATH_RE.exec(code);
20565
+ if (!match) return void 0;
20566
+ const [name, ...path] = match[2].split(".");
20567
+ return {
20568
+ sigil: match[1],
20569
+ name,
20570
+ path,
20571
+ start: at(index),
20572
+ end: at(index + match[0].length)
20573
+ };
20574
+ }
20147
20575
  /**
20148
20576
  * Scan the value of a code attribute (`onclick`, see isCodeAttribute) for
20149
- * the `{$…}` references resolved in it; its other braces are code.
20577
+ * the `{$…}` references resolved in it; its other braces are code. `at` is
20578
+ * where the value is.
20150
20579
  */
20151
- function scanSigilReferences(value, onRef) {
20152
- for (const part of splitSigilTemplate(value)) if ("expr" in part) scanCode(part.expr, onRef);
20580
+ function scanSigilReferences(value, at, emit) {
20581
+ for (const { expr, at: k } of sigilExpressions(value)) scanCode(expr, (i) => at(k + i), emit);
20153
20582
  }
20154
20583
  /**
20155
20584
  * Scan literal text (string contents, HTML attribute values) for the markup
@@ -20157,9 +20586,9 @@ function scanSigilReferences(value, onRef) {
20157
20586
  * expressions and macros, read as in passage text. A bare `$word` in
20158
20587
  * literal text is not a reference.
20159
20588
  */
20160
- function scanInterpolations(text, onRef, storeVarMacros = NO_STORE_VAR_MACROS) {
20589
+ function scanInterpolations(text, at, emit, options) {
20161
20590
  if (!text.includes("{")) return;
20162
- collectTokenRefs(text, tokensOf(text, true), storeVarMacros, onRef);
20591
+ collectTokenRefs(text, tokensOf(text, true, options), at, emit, options);
20163
20592
  }
20164
20593
  /**
20165
20594
  * Report `$var` references in JavaScript code, lexed as the expression
@@ -20169,76 +20598,104 @@ function scanInterpolations(text, onRef, storeVarMacros = NO_STORE_VAR_MACROS) {
20169
20598
  * is literal text unless a macro argument that holds markup is read as such
20170
20599
  * (see scanArgs); the `${…}` parts of template literals are code.
20171
20600
  */
20172
- function scanCode(code, onRef, goal = "expression") {
20601
+ function scanCode(code, at, emit, goal = "expression") {
20173
20602
  const parsed = parseOrError(code, goal);
20174
20603
  if (parsed instanceof CodeSyntaxError) {
20175
- scanCodeLeniently(code, onRef, goal);
20604
+ scanCodeLeniently(code, at, emit, goal);
20176
20605
  return;
20177
20606
  }
20178
20607
  for (const ref of parsed.refs) {
20179
- if (ref.sigil !== "$") continue;
20180
- VAR_PATH_RE.lastIndex = ref.start;
20181
- onRef(VAR_PATH_RE.exec(code)[1]);
20608
+ if (ref.sigil !== "$" && ref.sigil !== "%") continue;
20609
+ const found = referenceAt(code, ref.start, at);
20610
+ if (found) emit(found);
20182
20611
  }
20183
20612
  }
20184
20613
  /** `scanCode` for code acorn can't parse: lexed leniently. */
20185
- function scanCodeLeniently(code, onRef, goal) {
20614
+ function scanCodeLeniently(code, at, emit, goal) {
20186
20615
  lexJs(code, {
20187
20616
  variable(sigil, _name, index) {
20188
- if (sigil !== "$") return;
20189
- VAR_PATH_RE.lastIndex = index;
20190
- onRef(VAR_PATH_RE.exec(code)[1]);
20617
+ if (sigil !== "$" && sigil !== "%") return;
20618
+ const found = referenceAt(code, index, at);
20619
+ if (found) emit(found);
20191
20620
  },
20192
20621
  literal() {}
20193
20622
  }, goal);
20194
20623
  }
20195
20624
  /**
20196
- * Report the `$var` references a passage evaluates at runtime: `{$var}`
20197
- * displays, `{$expr}` expressions, macro arguments and `{do}` bodies (as
20198
- * code), quoted variable names bound by input macros, and `{$…}`
20199
- * interpolations in HTML attributes. Prose is literal text and not scanned.
20200
- */
20201
- function collectPassageRefs(content, storeVarMacros, onRef, parametersOf) {
20202
- withParseCache(() => collectTokenRefs(content, tokensOf(content, false), storeVarMacros, onRef, parametersOf));
20203
- }
20204
- /**
20205
20625
  * Report the references in the arguments of a macro by what its parameters
20206
20626
  * say each holds (see ParameterDef.holds): code is scanned as code and
20207
20627
  * markup as markup, but literal text (a placeholder, a passage name) holds
20208
20628
  * none. A macro without declared parameters, or arguments that do not
20209
20629
  * parse, are scanned as code.
20210
20630
  */
20211
- function scanArgs(token, params, onRef) {
20631
+ function scanArgs(token, params, at, emit, options) {
20212
20632
  if (!token.rawArgs) return;
20213
20633
  if (params) {
20214
- const pieces = [...argPieces(token.rawArgs, 0, params, token.name, "")];
20634
+ const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
20215
20635
  if (!pieces.some((piece) => piece.kind === "argument-error")) {
20216
- for (const piece of pieces) if (piece.kind === "code") scanCode(piece.code, onRef, piece.goal);
20217
- else if (piece.kind === "text") scanInterpolations(piece.text, onRef);
20636
+ for (const piece of pieces) {
20637
+ const pieceAt = (i) => at(pieceOffset(piece, i));
20638
+ if (piece.kind === "code") scanCode(piece.code, pieceAt, emit, piece.goal);
20639
+ else if (piece.kind === "text") scanInterpolations(piece.text, pieceAt, emit, {
20640
+ ...options,
20641
+ storeVarMacros: NO_STORE_VAR_MACROS
20642
+ });
20643
+ }
20218
20644
  return;
20219
20645
  }
20220
20646
  }
20221
- scanCode(token.rawArgs, onRef);
20647
+ scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
20222
20648
  }
20223
20649
  /** Report the `$var` references in the tokens of `content`. */
20224
- function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf = () => void 0) {
20650
+ function collectTokenRefs(content, tokens, at, emit, options) {
20651
+ const { storeVarMacros, parametersOf } = options;
20225
20652
  for (let t = 0; t < tokens.length; t++) {
20226
20653
  const token = tokens[t];
20227
20654
  if (token.type === "variable") {
20228
- if (token.scope === "variable" && token.name) onRef(token.name);
20229
- } else if (token.type === "link") scanInterpolations(token.display, onRef);
20230
- else if (token.type === "expression") scanCode(token.expression, onRef);
20231
- else if (token.type === "html") for (const [name, value] of Object.entries(token.attributes)) if (isCodeAttribute(name)) scanSigilReferences(value, onRef);
20232
- else scanInterpolations(value, onRef, storeVarMacros);
20655
+ if ((token.scope === "variable" || token.scope === "transient") && token.name) {
20656
+ const [name, ...path] = token.name.split(".");
20657
+ emit({
20658
+ sigil: token.scope === "variable" ? "$" : "%",
20659
+ name,
20660
+ path,
20661
+ start: at(token.nameStart - 1),
20662
+ end: at(token.nameEnd)
20663
+ });
20664
+ }
20665
+ } else if (token.type === "link") scanInterpolations(token.display, (i) => at(token.displayStart + i), emit, {
20666
+ ...options,
20667
+ storeVarMacros: NO_STORE_VAR_MACROS
20668
+ });
20669
+ else if (token.type === "expression") scanCode(token.expression, (i) => at(token.expressionStart + i), emit);
20670
+ else if (token.type === "html") for (const { name, value, at: valueAt } of attributeValues(content, token)) {
20671
+ const valueIn = (i) => at(valueAt + i);
20672
+ if (isCodeAttribute(name)) scanSigilReferences(value, valueIn, emit);
20673
+ else scanInterpolations(value, valueIn, emit, options);
20674
+ }
20233
20675
  else if (token.type === "macro" && !token.isClose) {
20234
- scanArgs(token, parametersOf(token.name), onRef);
20235
- if (token.className) scanInterpolations(token.className, onRef);
20236
- if (token.id) scanInterpolations(token.id, onRef);
20676
+ scanArgs(token, parametersOf(token.name), at, emit, options);
20677
+ if (token.selectorsStart !== void 0 && token.selectorsEnd !== void 0) {
20678
+ const from = token.selectorsStart;
20679
+ scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
20680
+ ...options,
20681
+ storeVarMacros: NO_STORE_VAR_MACROS
20682
+ });
20683
+ }
20237
20684
  if (storeVarMacros.has(token.name.toLowerCase())) {
20685
+ const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
20238
20686
  const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
20239
20687
  const quoted = QUOTED_VAR_ARG_RE.exec(first);
20240
- if (quoted) onRef(quoted[1]);
20241
- else if (!/^["'`]/.test(first)) scanCode(first, onRef);
20688
+ if (quoted) {
20689
+ const [name, ...path] = quoted[1].split(".");
20690
+ const start = token.argsStart + lead + 1;
20691
+ emit({
20692
+ sigil: "$",
20693
+ name,
20694
+ path,
20695
+ start: at(start),
20696
+ end: at(start + 1 + quoted[1].length)
20697
+ });
20698
+ } else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
20242
20699
  }
20243
20700
  if (token.name.toLowerCase() === "do") {
20244
20701
  let close = t + 1;
@@ -20248,7 +20705,7 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20248
20705
  close++;
20249
20706
  }
20250
20707
  if (close < tokens.length) {
20251
- scanCode(content.slice(token.end, tokens[close].start), onRef, "statements");
20708
+ scanCode(content.slice(token.end, tokens[close].start), (i) => at(token.end + i), emit, "statements");
20252
20709
  t = close;
20253
20710
  }
20254
20711
  }
@@ -20256,6 +20713,43 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20256
20713
  }
20257
20714
  }
20258
20715
  /**
20716
+ * The `$` and `%` variable references a passage evaluates at runtime, in
20717
+ * source order: `{$var}` displays, `{$expr}` expressions, macro arguments and
20718
+ * `{do}` bodies (as code), quoted variable names bound by input macros, and
20719
+ * `{$…}` interpolations in labels and HTML attributes. Prose is literal text
20720
+ * and not scanned.
20721
+ */
20722
+ function collectVariableReferences(content, options) {
20723
+ const found = [];
20724
+ withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), options));
20725
+ return found;
20726
+ }
20727
+ /**
20728
+ * The invalid variable references of the passages, against what is declared,
20729
+ * with their positions. The passages that hold no markup (the declarations
20730
+ * themselves, SaveTitle) are skipped.
20731
+ */
20732
+ function checkVariableReferences(passages, declared, options) {
20733
+ const diagnostics = [];
20734
+ for (const passage of passages) {
20735
+ if (NOT_MARKUP.has(passage.name)) continue;
20736
+ for (const ref of collectVariableReferences(passage.content, options)) {
20737
+ const error = checkReference(ref, declared);
20738
+ if (!error) continue;
20739
+ diagnostics.push({
20740
+ passage: passage.name,
20741
+ code: error.code,
20742
+ name: ref.name,
20743
+ ...ref.path.length > 0 ? { path: ref.path } : {},
20744
+ start: ref.start,
20745
+ end: ref.end,
20746
+ message: error.message
20747
+ });
20748
+ }
20749
+ }
20750
+ return diagnostics;
20751
+ }
20752
+ /**
20259
20753
  * Check the `$var` references of all passages against the schema, at story
20260
20754
  * start. Returns the error messages (empty = valid). (The syntax of their
20261
20755
  * code is checked with their markup: see markup/validate.ts.)
@@ -20264,16 +20758,10 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20264
20758
  * variable; it defaults to the built-in ones.
20265
20759
  */
20266
20760
  function validatePassages(passages, schema, storeVarMacros = BUILTIN_STORE_VAR_MACROS, parametersOf = getMacroParameters) {
20267
- const errors = [];
20268
- const storeVarSet = new Set(Array.from(storeVarMacros, (m) => m.toLowerCase()));
20269
- for (const [name, passage] of passages) {
20270
- if (NOT_MARKUP.has(name)) continue;
20271
- collectPassageRefs(passage.content, storeVarSet, (ref) => {
20272
- const error = validateRef(ref, schema);
20273
- if (error) errors.push(`Passage "${name}": ${error}`);
20274
- }, parametersOf);
20275
- }
20276
- return errors;
20761
+ return checkVariableReferences(passages.values(), { variables: schema }, {
20762
+ storeVarMacros: new Set(Array.from(storeVarMacros, (m) => m.toLowerCase())),
20763
+ parametersOf
20764
+ }).map((d) => `Passage "${d.passage}": ${d.message}`);
20277
20765
  }
20278
20766
  /**
20279
20767
  * Extract default values from the schema as a record without a prototype,
@@ -21235,14 +21723,50 @@ defineMacro({
21235
21723
  //#region src/components/macros/detached-body.tsx
21236
21724
  var frozenAlways = () => true;
21237
21725
  /**
21726
+ * Macros whose work is over once their effects have run: a body made of
21727
+ * these alone has nothing left to wait for. Any other macro (a timer, a
21728
+ * widget, an author's macro) may keep working after rendering.
21729
+ */
21730
+ var SETTLING_MACROS = new NameSet([
21731
+ "set",
21732
+ "unset",
21733
+ "if",
21734
+ "for",
21735
+ "switch",
21736
+ "do",
21737
+ "print",
21738
+ "goto",
21739
+ "nobr",
21740
+ "span"
21741
+ ]);
21742
+ /** Whether `nodes` use no macro outside SETTLING_MACROS (see above). */
21743
+ function settlesAfterRender(nodes) {
21744
+ return nodes.every((n) => {
21745
+ switch (n.type) {
21746
+ case "macro": return SETTLING_MACROS.has(n.name) && settlesAfterRender(n.children) && (n.branches ?? []).every((b) => settlesAfterRender(b.children));
21747
+ case "html": return settlesAfterRender(n.children);
21748
+ default: return true;
21749
+ }
21750
+ });
21751
+ }
21752
+ /** Calls `onSettled` once the effects of the content before it have run. */
21753
+ function Settled({ onSettled }) {
21754
+ useEffect(() => {
21755
+ const timer = setTimeout(onSettled, 0);
21756
+ return () => clearTimeout(timer);
21757
+ }, []);
21758
+ return null;
21759
+ }
21760
+ /**
21238
21761
  * Return a function that runs a macro body once, outside the passage tree:
21239
21762
  * it renders `children` into a detached node, so the body's macros ({set},
21240
21763
  * {if}, {goto}, ...) fire their side effects through the normal Preact
21241
21764
  * pipeline. Used by {button} and {link} on click. The body's state is frozen
21242
21765
  * once it has rendered, so it runs once per click. It stays mounted
21243
- * until the owning macro unmounts (its passage changes, say), so work it
21244
- * starts in an effect, such as the timer of a {timed} or {repeat}, can
21245
- * finish; the passage leaving cancels it, and so does a restart or a load
21766
+ * until it has nothing left to do: a body of plain macros ({set}, {if},
21767
+ * {goto}...) once its effects have run, any other (with the timer of a
21768
+ * {timed} or {repeat}, say) until the owning macro unmounts, e.g. its
21769
+ * passage changes, so that work it starts in an effect can finish; the passage leaving cancels it, and so does a restart or a load
21246
21770
  * replacing the game, which a control of the story interface outlives
21247
21771
  * (#401).
21248
21772
  *
@@ -21284,6 +21808,12 @@ function useDetachedBody() {
21284
21808
  const run = (children) => {
21285
21809
  const locals = liveLocalsView(updater.getValues);
21286
21810
  const container = document.createElement("div");
21811
+ const release = settlesAfterRender(children) ? () => {
21812
+ const at = mounted.current.indexOf(container);
21813
+ if (at === -1) return;
21814
+ mounted.current.splice(at, 1);
21815
+ render(null, container);
21816
+ } : null;
21287
21817
  render(/* @__PURE__ */ jsx(FrozenStateContext.Provider, {
21288
21818
  value: frozenAlways,
21289
21819
  children: /* @__PURE__ */ jsx(LocalsUpdateContext.Provider, {
@@ -21304,14 +21834,14 @@ function useDetachedBody() {
21304
21834
  value: closeDialog,
21305
21835
  children: /* @__PURE__ */ jsx(ItemEditContext.Provider, {
21306
21836
  value: inIteration,
21307
- children: /* @__PURE__ */ jsx(OutgoingContext.Provider, {
21837
+ children: /* @__PURE__ */ jsxs(OutgoingContext.Provider, {
21308
21838
  value: hasLeft,
21309
- children: renderNodes(children, {
21839
+ children: [renderNodes(children, {
21310
21840
  nobr,
21311
21841
  inline,
21312
21842
  structural,
21313
21843
  locals
21314
- })
21844
+ }), release && /* @__PURE__ */ jsx(Settled, { onSettled: release })]
21315
21845
  })
21316
21846
  })
21317
21847
  })
@@ -21614,7 +22144,7 @@ defineMacro({
21614
22144
  visibility: measured === null ? "hidden" : "visible",
21615
22145
  clipPath: clip
21616
22146
  },
21617
- children: ctx.renderInlineNodes(children)
22147
+ children: ctx.renderNodes(children, { inline: true })
21618
22148
  }), !done && totalChars > 0 && /* @__PURE__ */ jsx("span", { class: "macro-type-cursor" })]
21619
22149
  });
21620
22150
  }
@@ -21707,6 +22237,7 @@ function defineMenubarAction(config) {
21707
22237
  passageName: config.dialog.passageName,
21708
22238
  fallbackMarkup: config.dialog.fallbackMarkup,
21709
22239
  panelClass: config.dialog.panelClass,
22240
+ label: typeof config.label === "string" ? config.label : config.name,
21710
22241
  onClose: () => setDialogOpen(false),
21711
22242
  showCloseButton: config.dialog.showCloseButton
21712
22243
  })] });
@@ -22188,10 +22719,12 @@ defineMacro({
22188
22719
  //#region src/components/macros/SettingsControls.tsx
22189
22720
  function SettingControl({ name, def }) {
22190
22721
  const [value, setValue] = useState(() => settings.get(name));
22191
- const update = (newValue) => {
22192
- setValue(newValue);
22193
- settings.set(name, newValue);
22194
- };
22722
+ useEffect(() => {
22723
+ const sync = () => setValue(settings.get(name));
22724
+ sync();
22725
+ return subscribeSettings(sync);
22726
+ }, [name]);
22727
+ const update = (newValue) => settings.set(name, newValue);
22195
22728
  switch (def.type) {
22196
22729
  case "toggle": return /* @__PURE__ */ jsxs("label", {
22197
22730
  class: "settings-row",