@rohal12/spindle 0.64.9 → 0.64.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Fragment, createContext, h, render } from "preact";
1
+ import { Fragment, createContext, createPortal, h, render } from "preact";
2
2
  import { useCallback, useContext, useEffect, useErrorBoundary, useId, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
3
3
  import { useSyncExternalStore } from "preact/compat";
4
4
  import { createStore } from "zustand/vanilla";
@@ -5546,9 +5546,7 @@ var SigilParser = class extends Parser {
5546
5546
  if (name) {
5547
5547
  const end = at + 1 + name.length;
5548
5548
  const afterPrefix = self.type === types$1.incDec && (this.operandBeforeLast || this.breakBeforeLast);
5549
- const forced = code === 37 ? this.percentAt?.get(at) : void 0;
5550
- if (code === 64 || (forced ?? (self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)))) {
5551
- if (code === 37) this.transientsRead?.add(at);
5549
+ if (code === 64 || self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)) {
5552
5550
  self.pos = end;
5553
5551
  self.finishToken(types$1.name, self.input.charAt(at) + name);
5554
5552
  return;
@@ -5571,16 +5569,31 @@ var SigilParser = class extends Parser {
5571
5569
  }
5572
5570
  const self = this;
5573
5571
  const prevType = self.type;
5572
+ const beforePreviousValue = this.prevValue;
5574
5573
  this.prevValue = isMemberDot(this.typeBeforeLast) ? void 0 : self.value;
5575
5574
  const property = type.keyword !== void 0 && isMemberDot(prevType) || (type === types$1._function || type === types$1._class) && notABody(self.input, self.pos);
5576
5575
  if (!property && (type === types$1._function || type === types$1._class)) {
5577
- const before = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere ? this.typeBeforeLast : prevType;
5578
- self.type = before === types$1.colon && this.colonEndsTernary ? types$1.parenL : before;
5576
+ const afterAsync = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere;
5577
+ const before = afterAsync ? this.typeBeforeLast : prevType;
5578
+ const contextualOperand = before === types$1.name && (afterAsync ? this.operandBeforeLast : self.exprAllowed) && ((afterAsync ? beforePreviousValue : this.prevValue) !== "yield" || !(afterAsync ? this.breakBeforeLast : this.breakHere));
5579
+ self.type = before === types$1.colon && this.colonEndsTernary || contextualOperand ? types$1.parenL : before;
5579
5580
  }
5580
5581
  this.typeBeforeLast = prevType;
5581
5582
  super.finishToken(property ? types$1.name : type, value);
5582
5583
  if (type === types$1.name && (isMemberDot(prevType) || value === "of" && (prevType === types$1._const || prevType === types$1._var || this.prevValue === "let"))) self.exprAllowed = false;
5583
5584
  }
5585
+ parseIdent(liberal) {
5586
+ this.exprAllowed = false;
5587
+ return super.parseIdent(liberal);
5588
+ }
5589
+ parseForIn(node, init) {
5590
+ this.exprAllowed = true;
5591
+ return super.parseForIn(node, init);
5592
+ }
5593
+ parseAwait(forInit) {
5594
+ this.exprAllowed = true;
5595
+ return super.parseAwait(forInit);
5596
+ }
5584
5597
  braceIsBlock(prevType) {
5585
5598
  if (prevType === types$1.colon && this.colonEndsTernary) return false;
5586
5599
  if (prevType === types$1.braceR && this.closedBlock) return true;
@@ -5765,29 +5778,17 @@ function parseCode(src, goal = "expression") {
5765
5778
  }
5766
5779
  /** What parseCode finds in `src`, and the syntax tree it is in. */
5767
5780
  function parseWithAst(src, goal) {
5768
- const percentAt = /* @__PURE__ */ new Map();
5769
- for (;;) {
5770
- const transientsRead = /* @__PURE__ */ new Set();
5771
- try {
5772
- const ast = parseAst(src, goal, percentAt, transientsRead);
5773
- const out = {
5774
- refs: [],
5775
- strings: []
5776
- };
5777
- walk(ast, src, out, false, false);
5778
- out.refs.sort((a, b) => a.start - b.start);
5779
- return {
5780
- out,
5781
- ast
5782
- };
5783
- } catch (error) {
5784
- const pos = error.pos ?? -1;
5785
- if (!(error instanceof SyntaxError) || percentAt.has(pos)) throw error;
5786
- TRANS_NAME_RE.lastIndex = pos + 1;
5787
- if (src.charAt(pos) !== "%" || !TRANS_NAME_RE.test(src)) throw error;
5788
- percentAt.set(pos, !transientsRead.has(pos));
5789
- }
5790
- }
5781
+ const ast = parseAst(src, goal);
5782
+ const out = {
5783
+ refs: [],
5784
+ strings: []
5785
+ };
5786
+ walk(ast, src, out, false, false);
5787
+ out.refs.sort((a, b) => a.start - b.start);
5788
+ return {
5789
+ out,
5790
+ ast
5791
+ };
5791
5792
  }
5792
5793
  /**
5793
5794
  * Read `src` as a reference path: a variable with any number of `.name` and
@@ -5845,15 +5846,10 @@ function readMemberPath(src, end) {
5845
5846
  end
5846
5847
  };
5847
5848
  }
5848
- /**
5849
- * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
5850
- * noting where it read a transient in `transientsRead`.
5851
- */
5852
- function parseAst(src, goal, percentAt, transientsRead) {
5849
+ /** Parse `src` as `goal`, using the parser's context for `%name`. */
5850
+ function parseAst(src, goal) {
5853
5851
  try {
5854
5852
  const p = tokenizerAt(src, 0, goal);
5855
- p.percentAt = percentAt;
5856
- p.transientsRead = transientsRead;
5857
5853
  if (goal === "statements") return p.parse();
5858
5854
  p.nextToken();
5859
5855
  const ast = p.parseExpression();
@@ -6066,33 +6062,54 @@ var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
6066
6062
  * what in it is no JavaScript.
6067
6063
  */
6068
6064
  function findCodeEnd(src, start, { goal = "expression", stop, onRunOut } = {}) {
6069
- const end = scanCodeEnd(src, start, goal, stop, onRunOut);
6070
- return end < 0 && !stop ? parsedCodeEnd(src, start, goal) : end;
6065
+ let verifyStop = false;
6066
+ const end = scanCodeEnd(src, start, goal, stop, onRunOut, () => {
6067
+ verifyStop = true;
6068
+ });
6069
+ if (end < 0 || verifyStop) {
6070
+ const parsed = parsedCodeEnd(src, start, goal, stop);
6071
+ if (parsed >= 0) return parsed;
6072
+ }
6073
+ return end;
6071
6074
  }
6072
6075
  /**
6073
6076
  * Where the code from `start` ends, as the parser finds it: the `}` it
6074
- * stops at, or -1. The token scan of `findCodeEnd` guesses whether a `/`
6075
- * opens a regex from the tokens before it, and a few rare constructs (a
6076
- * class field named `class` inside a template literal) mislead it; the
6077
- * parser knows. Only asked when the scan finds no end.
6077
+ * stops at (or the `{` matching `stop`), or -1. The token scan of
6078
+ * `findCodeEnd` guesses whether a `/` opens a regex from the tokens before
6079
+ * it, and class fields inside template literals can mislead it. The parser
6080
+ * knows the context. Asked when the scan finds no end or a stop that might
6081
+ * still be template text.
6078
6082
  */
6079
- function parsedCodeEnd(src, start, goal) {
6083
+ function parsedCodeEnd(src, start, goal, stop) {
6080
6084
  const p = tokenizerAt(src, start, goal);
6085
+ const stopped = {};
6086
+ let stoppedAt = -1;
6087
+ if (stop) {
6088
+ const nextToken = p.nextToken;
6089
+ p.nextToken = () => {
6090
+ nextToken.call(p);
6091
+ if (p.type === types$1.braceL && stop(p.start)) {
6092
+ stoppedAt = p.start;
6093
+ throw stopped;
6094
+ }
6095
+ };
6096
+ }
6081
6097
  try {
6082
6098
  if (goal === "statements") p.parse();
6083
6099
  else {
6084
6100
  p.nextToken();
6085
6101
  p.parseExpression();
6086
- if (p.type === types$1.braceR) return p.start;
6102
+ if (!stop && p.type === types$1.braceR) return p.start;
6087
6103
  }
6088
6104
  } catch (error) {
6105
+ if (error === stopped) return stoppedAt;
6089
6106
  const pos = error.pos ?? -1;
6090
- if (src.charAt(pos) === "}") return pos;
6107
+ if (!stop && src.charAt(pos) === "}") return pos;
6091
6108
  }
6092
6109
  return -1;
6093
6110
  }
6094
6111
  /** `findCodeEnd` by the tokens: see there. */
6095
- function scanCodeEnd(src, start, goal, stop, onRunOut) {
6112
+ function scanCodeEnd(src, start, goal, stop, onRunOut, onTemplateStop) {
6096
6113
  /** No end: the code runs to the end of `src`. */
6097
6114
  const ranOut = () => {
6098
6115
  onRunOut?.();
@@ -6104,6 +6121,7 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
6104
6121
  let from = start;
6105
6122
  let afterOperand = false;
6106
6123
  let templateSlip = false;
6124
+ let interpolated = false;
6107
6125
  for (;;) {
6108
6126
  let resumeAt = -1;
6109
6127
  for (const tok of tokens(src, from, goal, { afterOperand })) {
@@ -6132,10 +6150,15 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
6132
6150
  prevWord = t === types$1.name && !WORDS_BEFORE_STRING.has(tok.value) || t === types$1.num;
6133
6151
  prevEnd = tok.end;
6134
6152
  if (t === types$1.braceL) {
6135
- if (stop?.(tok.start)) return tok.start;
6153
+ if (stop?.(tok.start)) {
6154
+ if (interpolated) onTemplateStop();
6155
+ return tok.start;
6156
+ }
6136
6157
  stack.push("{");
6137
- } else if (t === types$1.dollarBraceL) stack.push("${");
6138
- else if (t === types$1.parenL) stack.push("(");
6158
+ } else if (t === types$1.dollarBraceL) {
6159
+ interpolated = true;
6160
+ stack.push("${");
6161
+ } else if (t === types$1.parenL) stack.push("(");
6139
6162
  else if (t === types$1.bracketL) stack.push("[");
6140
6163
  else if (t === types$1.parenR || t === types$1.bracketR) {
6141
6164
  if (last$1(stack) === (t === types$1.parenR ? "(" : "[")) stack.pop();
@@ -6213,7 +6236,8 @@ function* tokens(src, start, goal, options = {}) {
6213
6236
  type: p.type,
6214
6237
  start: p.start,
6215
6238
  end: p.end,
6216
- value: p.value
6239
+ value: p.value,
6240
+ operand: p.operandHere
6217
6241
  };
6218
6242
  if (p.type === types$1.eof) return;
6219
6243
  }
@@ -9570,6 +9594,22 @@ function useAction(opts) {
9570
9594
  ]);
9571
9595
  return disabled ? "" : id;
9572
9596
  }
9597
+ // src/markup/html-elements.ts
9598
+ /** HTML raw-text bodies preserve character references as written. */
9599
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
9600
+ "script",
9601
+ "style",
9602
+ "xmp",
9603
+ "iframe",
9604
+ "noembed",
9605
+ "noframes"
9606
+ ]);
9607
+ /** Text-only bodies recognize their own end tag, never nested HTML tags. */
9608
+ var HTML_TEXT_ELEMENTS$1 = /* @__PURE__ */ new Set([
9609
+ ...RAW_TEXT_ELEMENTS,
9610
+ "textarea",
9611
+ "title"
9612
+ ]);
9573
9613
  // src/markup/tokens.ts
9574
9614
  /** Variable sigils: story ($), temporary (_), local (@), transient (%). */
9575
9615
  var SIGIL_SCOPES$1 = {
@@ -9599,12 +9639,13 @@ function withSelectors$1(target, from) {
9599
9639
  */
9600
9640
  var grammar_shared_default = {
9601
9641
  SIGIL_SCOPES: SIGIL_SCOPES$1,
9602
- withSelectors: withSelectors$1
9642
+ withSelectors: withSelectors$1,
9643
+ HTML_TEXT_ELEMENTS: HTML_TEXT_ELEMENTS$1
9603
9644
  };
9604
9645
  // src/markup/spindle.peggy
9605
9646
  var LB = String.fromCharCode(123);
9606
9647
  var RB = String.fromCharCode(125);
9607
- var { SIGIL_SCOPES, withSelectors } = grammar_shared_default;
9648
+ var { SIGIL_SCOPES, withSelectors, HTML_TEXT_ELEMENTS } = grammar_shared_default;
9608
9649
  var VOID_TAGS = /* @__PURE__ */ new Set([
9609
9650
  "area",
9610
9651
  "base",
@@ -10146,82 +10187,96 @@ function peg$parse(input, options) {
10146
10187
  return joinText(items);
10147
10188
  }
10148
10189
  function peg$f1() {
10149
- return !textMode;
10190
+ return !htmlTextTag;
10150
10191
  }
10151
10192
  function peg$f2() {
10152
- return !textMode;
10193
+ return !htmlTextTag;
10153
10194
  }
10154
- function peg$f3(tag) {
10155
- return tag;
10195
+ function peg$f3() {
10196
+ return !htmlTextTag;
10156
10197
  }
10157
10198
  function peg$f4() {
10199
+ return !textMode && !htmlTextTag;
10200
+ }
10201
+ function peg$f5() {
10202
+ return !textMode && !htmlTextTag;
10203
+ }
10204
+ function peg$f6(tag) {
10205
+ if (!tag.isSelfClose && HTML_TEXT_ELEMENTS.has(tag.lower)) htmlTextTag = tag.lower;
10206
+ return tag;
10207
+ }
10208
+ function peg$f7() {
10158
10209
  return !textMode;
10159
10210
  }
10160
- function peg$f5(tag) {
10211
+ function peg$f8(tag) {
10212
+ return !htmlTextTag || tag.lower === htmlTextTag;
10213
+ }
10214
+ function peg$f9(tag) {
10215
+ htmlTextTag = "";
10161
10216
  return VOID_TAGS.has(tag.lower) ? null : tag;
10162
10217
  }
10163
- function peg$f6(tag) {
10218
+ function peg$f10(tag) {
10164
10219
  rawName = tag.lower;
10165
10220
  return tag.kind === "open" && hooks.isRaw(rawName);
10166
10221
  }
10167
- function peg$f7(tag, b) {
10222
+ function peg$f11(tag, b) {
10168
10223
  return b;
10169
10224
  }
10170
- function peg$f8(tag, body) {
10225
+ function peg$f12(tag, body) {
10171
10226
  return body ? [tag, body] : tag;
10172
10227
  }
10173
- function peg$f9(tag) {
10228
+ function peg$f13(tag) {
10174
10229
  return tag.kind === "close";
10175
10230
  }
10176
- function peg$f10(tag) {
10231
+ function peg$f14(tag) {
10177
10232
  return tag;
10178
10233
  }
10179
- function peg$f11() {
10234
+ function peg$f15() {
10180
10235
  return !textMode;
10181
10236
  }
10182
- function peg$f12(tag) {
10237
+ function peg$f16(tag) {
10183
10238
  return tag;
10184
10239
  }
10185
- function peg$f13(start) {
10240
+ function peg$f17(start) {
10186
10241
  return skipTo(hooks.rawBodyEnd(input, start, rawName));
10187
10242
  }
10188
- function peg$f14(start) {
10243
+ function peg$f18(start) {
10189
10244
  return skipEnd - offset();
10190
10245
  }
10191
- function peg$f15(start, body, end) {
10246
+ function peg$f19(start, body, end) {
10192
10247
  const loc = {
10193
10248
  start: { offset: start },
10194
10249
  end: { offset: start + body.length }
10195
10250
  };
10196
10251
  return [body ? lexeme("text", loc, { value: body }) : null, end];
10197
10252
  }
10198
- function peg$f16() {
10253
+ function peg$f20() {
10199
10254
  return completionMode;
10200
10255
  }
10201
- function peg$f17(body) {
10256
+ function peg$f21(body) {
10202
10257
  return lexeme("text", location(), { value: body });
10203
10258
  }
10204
- function peg$f18() {
10259
+ function peg$f22() {
10205
10260
  return offset();
10206
10261
  }
10207
- function peg$f19(value) {
10262
+ function peg$f23(value) {
10208
10263
  return lexeme("text", location(), { value });
10209
10264
  }
10210
- function peg$f20() {
10265
+ function peg$f24() {
10211
10266
  return completionMode || offset() <= lastCommentClose;
10212
10267
  }
10213
- function peg$f21(value) {
10268
+ function peg$f25(value) {
10214
10269
  const node = lexeme("text", location(), { value });
10215
10270
  node.comment = true;
10216
10271
  return node;
10217
10272
  }
10218
- function peg$f22(bs) {
10273
+ function peg$f26(bs) {
10219
10274
  return bs.length % 2 === 1;
10220
10275
  }
10221
- function peg$f23(bs, c) {
10276
+ function peg$f27(bs, c) {
10222
10277
  return c;
10223
10278
  }
10224
- function peg$f24(bs, brace) {
10279
+ function peg$f28(bs, brace) {
10225
10280
  const loc = location();
10226
10281
  const next = input.charAt(loc.end.offset);
10227
10282
  if (textMode) {
@@ -10238,48 +10293,48 @@ function peg$parse(input, options) {
10238
10293
  escaped.escape = true;
10239
10294
  return bs.length > 1 ? [before, escaped] : escaped;
10240
10295
  }
10241
- function peg$f25() {
10296
+ function peg$f29() {
10242
10297
  return lexeme("text", location(), { value: LB });
10243
10298
  }
10244
- function peg$f26() {
10245
- return !textMode;
10299
+ function peg$f30() {
10300
+ return !textMode && !htmlTextTag;
10246
10301
  }
10247
- function peg$f27() {
10302
+ function peg$f31() {
10248
10303
  return lexeme("text", location(), { value: "<" });
10249
10304
  }
10250
- function peg$f28() {
10305
+ function peg$f32() {
10251
10306
  return lexeme("text", location(), { value: "[" });
10252
10307
  }
10253
- function peg$f29() {
10308
+ function peg$f33() {
10254
10309
  return !textMode;
10255
10310
  }
10256
- function peg$f30(ss, s, at, inner) {
10311
+ function peg$f34(ss, s, at, inner) {
10257
10312
  const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
10258
10313
  link.selectorSpan = selectorSpan(s, ss, at);
10259
10314
  return withSelectors(link, s);
10260
10315
  }
10261
- function peg$f31() {
10316
+ function peg$f35() {
10262
10317
  return !textMode;
10263
10318
  }
10264
- function peg$f32() {
10319
+ function peg$f36() {
10265
10320
  fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
10266
10321
  }
10267
- function peg$f33(parts) {
10322
+ function peg$f37(parts) {
10268
10323
  return selectorsOf(parts);
10269
10324
  }
10270
- function peg$f34() {
10325
+ function peg$f38() {
10271
10326
  return NO_SELECTORS;
10272
10327
  }
10273
- function peg$f35(s, end) {
10328
+ function peg$f39(s, end) {
10274
10329
  return {
10275
10330
  ...s,
10276
10331
  end
10277
10332
  };
10278
10333
  }
10279
- function peg$f36(prefix, name) {
10334
+ function peg$f40(prefix, name) {
10280
10335
  return [prefix, name];
10281
10336
  }
10282
- function peg$f37(ss, s, sigil, nameStart, name) {
10337
+ function peg$f41(ss, s, sigil, nameStart, name) {
10283
10338
  const variable = lexeme("variable", location(), {
10284
10339
  name,
10285
10340
  nameStart,
@@ -10289,7 +10344,7 @@ function peg$parse(input, options) {
10289
10344
  variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
10290
10345
  return withSelectors(variable, s);
10291
10346
  }
10292
- function peg$f38(ss, s, after, expression) {
10347
+ function peg$f42(ss, s, after, expression) {
10293
10348
  const node = lexeme("expression", location(), {
10294
10349
  expression,
10295
10350
  expressionStart: after,
@@ -10298,33 +10353,33 @@ function peg$parse(input, options) {
10298
10353
  node.selectorSpan = selectorSpan(s, ss, after);
10299
10354
  return withSelectors(node, s);
10300
10355
  }
10301
- function peg$f39() {
10356
+ function peg$f43() {
10302
10357
  fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
10303
10358
  }
10304
- function peg$f40(start) {
10359
+ function peg$f44(start) {
10305
10360
  const end = hooks.closeBrace(input, start, start);
10306
10361
  return skipTo(end < 0 && completionMode ? input.length : end);
10307
10362
  }
10308
- function peg$f41(start) {
10363
+ function peg$f45(start) {
10309
10364
  return skipEnd - offset();
10310
10365
  }
10311
- function peg$f42(start, code) {
10366
+ function peg$f46(start, code) {
10312
10367
  return code;
10313
10368
  }
10314
- function peg$f43() {
10369
+ function peg$f47() {
10315
10370
  return completionMode;
10316
10371
  }
10317
- function peg$f44(ss, s, start, close, name, nameEnd) {
10372
+ function peg$f48(ss, s, start, close, name, nameEnd) {
10318
10373
  const end = hooks.closeBrace(input, nameEnd, start);
10319
10374
  return skipTo(end < 0 && completionMode ? input.length : end);
10320
10375
  }
10321
- function peg$f45(ss, s, start, close, name, nameEnd) {
10376
+ function peg$f49(ss, s, start, close, name, nameEnd) {
10322
10377
  return skipEnd - offset();
10323
10378
  }
10324
- function peg$f46(ss, s, start, close, name, nameEnd, args) {
10379
+ function peg$f50(ss, s, start, close, name, nameEnd, args) {
10325
10380
  return args;
10326
10381
  }
10327
- function peg$f47(ss, s, start, close, name, nameEnd, tail) {
10382
+ function peg$f51(ss, s, start, close, name, nameEnd, tail) {
10328
10383
  const loc = location();
10329
10384
  const lower = name.toLowerCase();
10330
10385
  const tag = lexeme("macro", loc, {
@@ -10350,19 +10405,19 @@ function peg$parse(input, options) {
10350
10405
  }
10351
10406
  return tag;
10352
10407
  }
10353
- function peg$f48(s) {
10408
+ function peg$f52(s) {
10354
10409
  fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
10355
10410
  }
10356
- function peg$f49(value) {
10411
+ function peg$f53(value) {
10357
10412
  return EMAIL_AUTOLINK.test(value);
10358
10413
  }
10359
- function peg$f50(value) {
10414
+ function peg$f54(value) {
10360
10415
  return lexeme("text", location(), { value });
10361
10416
  }
10362
- function peg$f51(value) {
10417
+ function peg$f55(value) {
10363
10418
  return lexeme("text", location(), { value });
10364
10419
  }
10365
- function peg$f52(tagStart, tag, list, slash) {
10420
+ function peg$f56(tagStart, tag, list, slash) {
10366
10421
  const lower = tag.toLowerCase();
10367
10422
  return lexeme("html", location(), {
10368
10423
  tag,
@@ -10375,7 +10430,7 @@ function peg$parse(input, options) {
10375
10430
  isSelfClose: !!slash || VOID_TAGS.has(lower)
10376
10431
  });
10377
10432
  }
10378
- function peg$f53(tag, bad) {
10433
+ function peg$f57(tag, bad) {
10379
10434
  const c = input.charAt(bad);
10380
10435
  if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
10381
10436
  const at = {
@@ -10393,7 +10448,7 @@ function peg$parse(input, options) {
10393
10448
  };
10394
10449
  fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
10395
10450
  }
10396
- function peg$f54(tagStart, tag) {
10451
+ function peg$f58(tagStart, tag) {
10397
10452
  return lexeme("html", location(), {
10398
10453
  tag,
10399
10454
  lower: tag.toLowerCase(),
@@ -10405,14 +10460,14 @@ function peg$parse(input, options) {
10405
10460
  isSelfClose: false
10406
10461
  });
10407
10462
  }
10408
- function peg$f55(nameStart, name) {
10463
+ function peg$f59(nameStart, name) {
10409
10464
  attrCode = hooks.isCodeAttribute(name);
10410
10465
  return true;
10411
10466
  }
10412
- function peg$f56(nameStart, name, v) {
10467
+ function peg$f60(nameStart, name, v) {
10413
10468
  return v;
10414
10469
  }
10415
- function peg$f57(nameStart, name, value) {
10470
+ function peg$f61(nameStart, name, value) {
10416
10471
  const attribute = {
10417
10472
  name,
10418
10473
  value: value ? value.value : "",
@@ -10426,7 +10481,7 @@ function peg$parse(input, options) {
10426
10481
  }
10427
10482
  return attribute;
10428
10483
  }
10429
- function peg$f58(start, value, end) {
10484
+ function peg$f62(start, value, end) {
10430
10485
  return {
10431
10486
  value,
10432
10487
  start,
@@ -10434,7 +10489,7 @@ function peg$parse(input, options) {
10434
10489
  quote: "\""
10435
10490
  };
10436
10491
  }
10437
- function peg$f59(start, value, end) {
10492
+ function peg$f63(start, value, end) {
10438
10493
  return {
10439
10494
  value,
10440
10495
  start,
@@ -10442,36 +10497,36 @@ function peg$parse(input, options) {
10442
10497
  quote: "'"
10443
10498
  };
10444
10499
  }
10445
- function peg$f60(q) {
10500
+ function peg$f64(q) {
10446
10501
  fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
10447
10502
  }
10448
- function peg$f61(start, value, end) {
10503
+ function peg$f65(start, value, end) {
10449
10504
  return {
10450
10505
  value,
10451
10506
  start,
10452
10507
  end
10453
10508
  };
10454
10509
  }
10455
- function peg$f62() {
10510
+ function peg$f66() {
10456
10511
  return !attrCode;
10457
10512
  }
10458
- function peg$f63(bs) {
10513
+ function peg$f67(bs) {
10459
10514
  return bs.length % 2 === 1;
10460
10515
  }
10461
- function peg$f64() {
10516
+ function peg$f68() {
10462
10517
  return !attrCode;
10463
10518
  }
10464
- function peg$f65(start, nameEnd) {
10519
+ function peg$f69(start, nameEnd) {
10465
10520
  const end = hooks.closeBrace(input, nameEnd, start);
10466
10521
  return skipTo(end < 0 && completionMode ? input.length : end);
10467
10522
  }
10468
- function peg$f66(start, nameEnd) {
10523
+ function peg$f70(start, nameEnd) {
10469
10524
  return skipEnd - offset();
10470
10525
  }
10471
- function peg$f67() {
10526
+ function peg$f71() {
10472
10527
  return !attrCode;
10473
10528
  }
10474
- function peg$f68() {
10529
+ function peg$f72() {
10475
10530
  return attrCode;
10476
10531
  }
10477
10532
  let peg$currPos = options.peg$currPos | 0;
@@ -10607,15 +10662,66 @@ function peg$parse(input, options) {
10607
10662
  if (s0 === peg$FAILED) {
10608
10663
  s0 = peg$parseEscape();
10609
10664
  if (s0 === peg$FAILED) {
10610
- s0 = peg$parseComment();
10665
+ s0 = peg$currPos;
10666
+ peg$savedPos = peg$currPos;
10667
+ s1 = peg$f1();
10668
+ if (s1) s1 = void 0;
10669
+ else s1 = peg$FAILED;
10670
+ if (s1 !== peg$FAILED) {
10671
+ s2 = peg$parseComment();
10672
+ if (s2 !== peg$FAILED) {
10673
+ s1 = [s1, s2];
10674
+ s0 = s1;
10675
+ } else {
10676
+ peg$currPos = s0;
10677
+ s0 = peg$FAILED;
10678
+ }
10679
+ } else {
10680
+ peg$currPos = s0;
10681
+ s0 = peg$FAILED;
10682
+ }
10611
10683
  if (s0 === peg$FAILED) {
10612
- s0 = peg$parseLinkLexeme();
10684
+ s0 = peg$currPos;
10685
+ peg$savedPos = peg$currPos;
10686
+ s1 = peg$f2();
10687
+ if (s1) s1 = void 0;
10688
+ else s1 = peg$FAILED;
10689
+ if (s1 !== peg$FAILED) {
10690
+ s2 = peg$parseLinkLexeme();
10691
+ if (s2 !== peg$FAILED) {
10692
+ s1 = [s1, s2];
10693
+ s0 = s1;
10694
+ } else {
10695
+ peg$currPos = s0;
10696
+ s0 = peg$FAILED;
10697
+ }
10698
+ } else {
10699
+ peg$currPos = s0;
10700
+ s0 = peg$FAILED;
10701
+ }
10613
10702
  if (s0 === peg$FAILED) {
10614
- s0 = peg$parseEmailAutolink();
10703
+ s0 = peg$currPos;
10704
+ peg$savedPos = peg$currPos;
10705
+ s1 = peg$f3();
10706
+ if (s1) s1 = void 0;
10707
+ else s1 = peg$FAILED;
10708
+ if (s1 !== peg$FAILED) {
10709
+ s2 = peg$parseEmailAutolink();
10710
+ if (s2 !== peg$FAILED) {
10711
+ s1 = [s1, s2];
10712
+ s0 = s1;
10713
+ } else {
10714
+ peg$currPos = s0;
10715
+ s0 = peg$FAILED;
10716
+ }
10717
+ } else {
10718
+ peg$currPos = s0;
10719
+ s0 = peg$FAILED;
10720
+ }
10615
10721
  if (s0 === peg$FAILED) {
10616
10722
  s0 = peg$currPos;
10617
10723
  peg$savedPos = peg$currPos;
10618
- s1 = peg$f1();
10724
+ s1 = peg$f4();
10619
10725
  if (s1) s1 = void 0;
10620
10726
  else s1 = peg$FAILED;
10621
10727
  if (s1 !== peg$FAILED) {
@@ -10634,14 +10740,14 @@ function peg$parse(input, options) {
10634
10740
  if (s0 === peg$FAILED) {
10635
10741
  s0 = peg$currPos;
10636
10742
  peg$savedPos = peg$currPos;
10637
- s1 = peg$f2();
10743
+ s1 = peg$f5();
10638
10744
  if (s1) s1 = void 0;
10639
10745
  else s1 = peg$FAILED;
10640
10746
  if (s1 !== peg$FAILED) {
10641
10747
  s2 = peg$parseHtmlOpen();
10642
10748
  if (s2 !== peg$FAILED) {
10643
10749
  peg$savedPos = s0;
10644
- s0 = peg$f3(s2);
10750
+ s0 = peg$f6(s2);
10645
10751
  } else {
10646
10752
  peg$currPos = s0;
10647
10753
  s0 = peg$FAILED;
@@ -10653,14 +10759,23 @@ function peg$parse(input, options) {
10653
10759
  if (s0 === peg$FAILED) {
10654
10760
  s0 = peg$currPos;
10655
10761
  peg$savedPos = peg$currPos;
10656
- s1 = peg$f4();
10762
+ s1 = peg$f7();
10657
10763
  if (s1) s1 = void 0;
10658
10764
  else s1 = peg$FAILED;
10659
10765
  if (s1 !== peg$FAILED) {
10660
10766
  s2 = peg$parseHtmlClose();
10661
10767
  if (s2 !== peg$FAILED) {
10662
- peg$savedPos = s0;
10663
- s0 = peg$f5(s2);
10768
+ peg$savedPos = peg$currPos;
10769
+ s3 = peg$f8(s2);
10770
+ if (s3) s3 = void 0;
10771
+ else s3 = peg$FAILED;
10772
+ if (s3 !== peg$FAILED) {
10773
+ peg$savedPos = s0;
10774
+ s0 = peg$f9(s2);
10775
+ } else {
10776
+ peg$currPos = s0;
10777
+ s0 = peg$FAILED;
10778
+ }
10664
10779
  } else {
10665
10780
  peg$currPos = s0;
10666
10781
  s0 = peg$FAILED;
@@ -10677,14 +10792,14 @@ function peg$parse(input, options) {
10677
10792
  if (s1 !== peg$FAILED) {
10678
10793
  s2 = peg$currPos;
10679
10794
  peg$savedPos = peg$currPos;
10680
- s3 = peg$f6(s1);
10795
+ s3 = peg$f10(s1);
10681
10796
  if (s3) s3 = void 0;
10682
10797
  else s3 = peg$FAILED;
10683
10798
  if (s3 !== peg$FAILED) {
10684
10799
  s4 = peg$parseRawTokens();
10685
10800
  if (s4 !== peg$FAILED) {
10686
10801
  peg$savedPos = s2;
10687
- s2 = peg$f7(s1, s4);
10802
+ s2 = peg$f11(s1, s4);
10688
10803
  } else {
10689
10804
  peg$currPos = s2;
10690
10805
  s2 = peg$FAILED;
@@ -10695,7 +10810,7 @@ function peg$parse(input, options) {
10695
10810
  }
10696
10811
  if (s2 === peg$FAILED) s2 = null;
10697
10812
  peg$savedPos = s0;
10698
- s0 = peg$f8(s1, s2);
10813
+ s0 = peg$f12(s1, s2);
10699
10814
  } else {
10700
10815
  peg$currPos = s0;
10701
10816
  s0 = peg$FAILED;
@@ -10718,12 +10833,12 @@ function peg$parse(input, options) {
10718
10833
  s1 = peg$parseMacroTag();
10719
10834
  if (s1 !== peg$FAILED) {
10720
10835
  peg$savedPos = peg$currPos;
10721
- s2 = peg$f9(s1);
10836
+ s2 = peg$f13(s1);
10722
10837
  if (s2) s2 = void 0;
10723
10838
  else s2 = peg$FAILED;
10724
10839
  if (s2 !== peg$FAILED) {
10725
10840
  peg$savedPos = s0;
10726
- s0 = peg$f10(s1);
10841
+ s0 = peg$f14(s1);
10727
10842
  } else {
10728
10843
  peg$currPos = s0;
10729
10844
  s0 = peg$FAILED;
@@ -10735,14 +10850,14 @@ function peg$parse(input, options) {
10735
10850
  if (s0 === peg$FAILED) {
10736
10851
  s0 = peg$currPos;
10737
10852
  peg$savedPos = peg$currPos;
10738
- s1 = peg$f11();
10853
+ s1 = peg$f15();
10739
10854
  if (s1) s1 = void 0;
10740
10855
  else s1 = peg$FAILED;
10741
10856
  if (s1 !== peg$FAILED) {
10742
10857
  s2 = peg$parseHtmlClose();
10743
10858
  if (s2 !== peg$FAILED) {
10744
10859
  peg$savedPos = s0;
10745
- s0 = peg$f12(s2);
10860
+ s0 = peg$f16(s2);
10746
10861
  } else {
10747
10862
  peg$currPos = s0;
10748
10863
  s0 = peg$FAILED;
@@ -10759,12 +10874,12 @@ function peg$parse(input, options) {
10759
10874
  s0 = peg$currPos;
10760
10875
  s1 = peg$parseHere();
10761
10876
  peg$savedPos = peg$currPos;
10762
- s2 = peg$f13(s1);
10877
+ s2 = peg$f17(s1);
10763
10878
  if (s2) s2 = void 0;
10764
10879
  else s2 = peg$FAILED;
10765
10880
  if (s2 !== peg$FAILED) {
10766
10881
  s3 = peg$currPos;
10767
- s4 = peg$f14(s1);
10882
+ s4 = peg$f18(s1);
10768
10883
  s5 = peg$currPos;
10769
10884
  s6 = [];
10770
10885
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -10797,7 +10912,7 @@ function peg$parse(input, options) {
10797
10912
  s4 = peg$parseCloseTag();
10798
10913
  if (s4 !== peg$FAILED) {
10799
10914
  peg$savedPos = s0;
10800
- s0 = peg$f15(s1, s3, s4);
10915
+ s0 = peg$f19(s1, s3, s4);
10801
10916
  } else {
10802
10917
  peg$currPos = s0;
10803
10918
  s0 = peg$FAILED;
@@ -10813,7 +10928,7 @@ function peg$parse(input, options) {
10813
10928
  if (s0 === peg$FAILED) {
10814
10929
  s0 = peg$currPos;
10815
10930
  peg$savedPos = peg$currPos;
10816
- s1 = peg$f16();
10931
+ s1 = peg$f20();
10817
10932
  if (s1) s1 = void 0;
10818
10933
  else s1 = peg$FAILED;
10819
10934
  if (s1 !== peg$FAILED) {
@@ -10838,7 +10953,7 @@ function peg$parse(input, options) {
10838
10953
  }
10839
10954
  s2 = input.substring(s2, peg$currPos);
10840
10955
  peg$savedPos = s0;
10841
- s0 = peg$f17(s2);
10956
+ s0 = peg$f21(s2);
10842
10957
  } else {
10843
10958
  peg$currPos = s0;
10844
10959
  s0 = peg$FAILED;
@@ -10851,7 +10966,7 @@ function peg$parse(input, options) {
10851
10966
  s0 = peg$currPos;
10852
10967
  s1 = "";
10853
10968
  peg$savedPos = s0;
10854
- s1 = peg$f18();
10969
+ s1 = peg$f22();
10855
10970
  s0 = s1;
10856
10971
  return s0;
10857
10972
  }
@@ -10880,7 +10995,7 @@ function peg$parse(input, options) {
10880
10995
  else s1 = s2;
10881
10996
  if (s1 !== peg$FAILED) {
10882
10997
  peg$savedPos = s0;
10883
- s1 = peg$f19(s1);
10998
+ s1 = peg$f23(s1);
10884
10999
  }
10885
11000
  s0 = s1;
10886
11001
  return s0;
@@ -10916,7 +11031,7 @@ function peg$parse(input, options) {
10916
11031
  if (s4 === peg$FAILED) {
10917
11032
  s4 = peg$currPos;
10918
11033
  peg$savedPos = peg$currPos;
10919
- s5 = peg$f20();
11034
+ s5 = peg$f24();
10920
11035
  if (s5) s5 = void 0;
10921
11036
  else s5 = peg$FAILED;
10922
11037
  if (s5 !== peg$FAILED) {
@@ -11034,7 +11149,7 @@ function peg$parse(input, options) {
11034
11149
  else s1 = s2;
11035
11150
  if (s1 !== peg$FAILED) {
11036
11151
  peg$savedPos = s0;
11037
- s1 = peg$f21(s1);
11152
+ s1 = peg$f25(s1);
11038
11153
  }
11039
11154
  s0 = s1;
11040
11155
  return s0;
@@ -11067,7 +11182,7 @@ function peg$parse(input, options) {
11067
11182
  if (s1 !== peg$FAILED) {
11068
11183
  s2 = peg$currPos;
11069
11184
  peg$savedPos = peg$currPos;
11070
- s3 = peg$f22(s1);
11185
+ s3 = peg$f26(s1);
11071
11186
  if (s3) s3 = void 0;
11072
11187
  else s3 = peg$FAILED;
11073
11188
  if (s3 !== peg$FAILED) {
@@ -11079,7 +11194,7 @@ function peg$parse(input, options) {
11079
11194
  }
11080
11195
  if (s4 !== peg$FAILED) {
11081
11196
  peg$savedPos = s2;
11082
- s2 = peg$f23(s1, s4);
11197
+ s2 = peg$f27(s1, s4);
11083
11198
  } else {
11084
11199
  peg$currPos = s2;
11085
11200
  s2 = peg$FAILED;
@@ -11090,7 +11205,7 @@ function peg$parse(input, options) {
11090
11205
  }
11091
11206
  if (s2 === peg$FAILED) s2 = null;
11092
11207
  peg$savedPos = s0;
11093
- s0 = peg$f24(s1, s2);
11208
+ s0 = peg$f28(s1, s2);
11094
11209
  } else {
11095
11210
  peg$currPos = s0;
11096
11211
  s0 = peg$FAILED;
@@ -11138,7 +11253,7 @@ function peg$parse(input, options) {
11138
11253
  }
11139
11254
  if (s2 !== peg$FAILED) {
11140
11255
  peg$savedPos = s0;
11141
- s0 = peg$f25();
11256
+ s0 = peg$f29();
11142
11257
  } else {
11143
11258
  peg$currPos = s0;
11144
11259
  s0 = peg$FAILED;
@@ -11153,7 +11268,7 @@ function peg$parse(input, options) {
11153
11268
  peg$silentFails++;
11154
11269
  s2 = peg$currPos;
11155
11270
  peg$savedPos = peg$currPos;
11156
- s3 = peg$f26();
11271
+ s3 = peg$f30();
11157
11272
  if (s3) s3 = void 0;
11158
11273
  else s3 = peg$FAILED;
11159
11274
  if (s3 !== peg$FAILED) {
@@ -11185,7 +11300,7 @@ function peg$parse(input, options) {
11185
11300
  }
11186
11301
  if (s2 !== peg$FAILED) {
11187
11302
  peg$savedPos = s0;
11188
- s0 = peg$f27();
11303
+ s0 = peg$f31();
11189
11304
  } else {
11190
11305
  peg$currPos = s0;
11191
11306
  s0 = peg$FAILED;
@@ -11205,7 +11320,7 @@ function peg$parse(input, options) {
11205
11320
  }
11206
11321
  if (s1 !== peg$FAILED) {
11207
11322
  peg$savedPos = s0;
11208
- s1 = peg$f28();
11323
+ s1 = peg$f32();
11209
11324
  }
11210
11325
  s0 = s1;
11211
11326
  }
@@ -11216,7 +11331,7 @@ function peg$parse(input, options) {
11216
11331
  let s0, s1, s2, s3, s4, s5, s6, s7;
11217
11332
  s0 = peg$currPos;
11218
11333
  peg$savedPos = peg$currPos;
11219
- s1 = peg$f29();
11334
+ s1 = peg$f33();
11220
11335
  if (s1) s1 = void 0;
11221
11336
  else s1 = peg$FAILED;
11222
11337
  if (s1 !== peg$FAILED) {
@@ -11245,7 +11360,7 @@ function peg$parse(input, options) {
11245
11360
  if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
11246
11361
  if (s7 !== peg$FAILED) {
11247
11362
  peg$savedPos = s0;
11248
- s0 = peg$f30(s3, s4, s5, s6);
11363
+ s0 = peg$f34(s3, s4, s5, s6);
11249
11364
  } else {
11250
11365
  peg$currPos = s0;
11251
11366
  s0 = peg$FAILED;
@@ -11265,7 +11380,7 @@ function peg$parse(input, options) {
11265
11380
  if (s0 === peg$FAILED) {
11266
11381
  s0 = peg$currPos;
11267
11382
  peg$savedPos = peg$currPos;
11268
- s1 = peg$f31();
11383
+ s1 = peg$f35();
11269
11384
  if (s1) s1 = void 0;
11270
11385
  else s1 = peg$FAILED;
11271
11386
  if (s1 !== peg$FAILED) {
@@ -11278,7 +11393,7 @@ function peg$parse(input, options) {
11278
11393
  }
11279
11394
  if (s2 !== peg$FAILED) {
11280
11395
  peg$savedPos = s0;
11281
- s0 = peg$f32();
11396
+ s0 = peg$f36();
11282
11397
  } else {
11283
11398
  peg$currPos = s0;
11284
11399
  s0 = peg$FAILED;
@@ -11406,7 +11521,7 @@ function peg$parse(input, options) {
11406
11521
  }
11407
11522
  if (s2 === peg$FAILED) s2 = null;
11408
11523
  peg$savedPos = s0;
11409
- s0 = peg$f33(s1);
11524
+ s0 = peg$f37(s1);
11410
11525
  } else {
11411
11526
  peg$currPos = s0;
11412
11527
  s0 = peg$FAILED;
@@ -11415,7 +11530,7 @@ function peg$parse(input, options) {
11415
11530
  s0 = peg$currPos;
11416
11531
  s1 = "";
11417
11532
  peg$savedPos = s0;
11418
- s1 = peg$f34();
11533
+ s1 = peg$f38();
11419
11534
  s0 = s1;
11420
11535
  }
11421
11536
  return s0;
@@ -11445,7 +11560,7 @@ function peg$parse(input, options) {
11445
11560
  }
11446
11561
  }
11447
11562
  peg$savedPos = s0;
11448
- s0 = peg$f35(s1, s2);
11563
+ s0 = peg$f39(s1, s2);
11449
11564
  } else {
11450
11565
  peg$currPos = s0;
11451
11566
  s0 = peg$FAILED;
@@ -11471,7 +11586,7 @@ function peg$parse(input, options) {
11471
11586
  }
11472
11587
  s2 = input.substring(s2, peg$currPos);
11473
11588
  peg$savedPos = s0;
11474
- s0 = peg$f36(s1, s2);
11589
+ s0 = peg$f40(s1, s2);
11475
11590
  } else {
11476
11591
  peg$currPos = s0;
11477
11592
  s0 = peg$FAILED;
@@ -11592,7 +11707,7 @@ function peg$parse(input, options) {
11592
11707
  s7 = peg$parseBraceEnd();
11593
11708
  if (s7 !== peg$FAILED) {
11594
11709
  peg$savedPos = s0;
11595
- s0 = peg$f37(s2, s3, s4, s5, s6);
11710
+ s0 = peg$f41(s2, s3, s4, s5, s6);
11596
11711
  } else {
11597
11712
  peg$currPos = s0;
11598
11713
  s0 = peg$FAILED;
@@ -11642,7 +11757,7 @@ function peg$parse(input, options) {
11642
11757
  s7 = peg$parseBraceEnd();
11643
11758
  if (s7 !== peg$FAILED) {
11644
11759
  peg$savedPos = s0;
11645
- s0 = peg$f38(s2, s3, s4, s6);
11760
+ s0 = peg$f42(s2, s3, s4, s6);
11646
11761
  } else {
11647
11762
  peg$currPos = s0;
11648
11763
  s0 = peg$FAILED;
@@ -11690,7 +11805,7 @@ function peg$parse(input, options) {
11690
11805
  } else s3 = peg$FAILED;
11691
11806
  if (s3 !== peg$FAILED) {
11692
11807
  peg$savedPos = s0;
11693
- s0 = peg$f39();
11808
+ s0 = peg$f43();
11694
11809
  } else {
11695
11810
  peg$currPos = s0;
11696
11811
  s0 = peg$FAILED;
@@ -11712,12 +11827,12 @@ function peg$parse(input, options) {
11712
11827
  s0 = peg$currPos;
11713
11828
  s1 = peg$parseHere();
11714
11829
  peg$savedPos = peg$currPos;
11715
- s2 = peg$f40(s1);
11830
+ s2 = peg$f44(s1);
11716
11831
  if (s2) s2 = void 0;
11717
11832
  else s2 = peg$FAILED;
11718
11833
  if (s2 !== peg$FAILED) {
11719
11834
  s3 = peg$currPos;
11720
- s4 = peg$f41(s1);
11835
+ s4 = peg$f45(s1);
11721
11836
  s5 = peg$currPos;
11722
11837
  s6 = [];
11723
11838
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -11748,7 +11863,7 @@ function peg$parse(input, options) {
11748
11863
  else s3 = s4;
11749
11864
  if (s3 !== peg$FAILED) {
11750
11865
  peg$savedPos = s0;
11751
- s0 = peg$f42(s1, s3);
11866
+ s0 = peg$f46(s1, s3);
11752
11867
  } else {
11753
11868
  peg$currPos = s0;
11754
11869
  s0 = peg$FAILED;
@@ -11763,7 +11878,7 @@ function peg$parse(input, options) {
11763
11878
  let s0, s1, s2, s3;
11764
11879
  s0 = peg$currPos;
11765
11880
  peg$savedPos = peg$currPos;
11766
- s1 = peg$f43();
11881
+ s1 = peg$f47();
11767
11882
  if (s1) s1 = void 0;
11768
11883
  else s1 = peg$FAILED;
11769
11884
  if (s1 !== peg$FAILED) {
@@ -11835,12 +11950,12 @@ function peg$parse(input, options) {
11835
11950
  s7 = peg$parseHere();
11836
11951
  s8 = peg$currPos;
11837
11952
  peg$savedPos = peg$currPos;
11838
- s9 = peg$f44(s2, s3, s4, s5, s6, s7);
11953
+ s9 = peg$f48(s2, s3, s4, s5, s6, s7);
11839
11954
  if (s9) s9 = void 0;
11840
11955
  else s9 = peg$FAILED;
11841
11956
  if (s9 !== peg$FAILED) {
11842
11957
  s10 = peg$currPos;
11843
- s11 = peg$f45(s2, s3, s4, s5, s6, s7);
11958
+ s11 = peg$f49(s2, s3, s4, s5, s6, s7);
11844
11959
  s12 = peg$currPos;
11845
11960
  s13 = [];
11846
11961
  if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
@@ -11873,7 +11988,7 @@ function peg$parse(input, options) {
11873
11988
  s11 = peg$parseBraceEnd();
11874
11989
  if (s11 !== peg$FAILED) {
11875
11990
  peg$savedPos = s8;
11876
- s8 = peg$f46(s2, s3, s4, s5, s6, s7, s10);
11991
+ s8 = peg$f50(s2, s3, s4, s5, s6, s7, s10);
11877
11992
  } else {
11878
11993
  peg$currPos = s8;
11879
11994
  s8 = peg$FAILED;
@@ -11888,7 +12003,7 @@ function peg$parse(input, options) {
11888
12003
  }
11889
12004
  if (s8 === peg$FAILED) s8 = null;
11890
12005
  peg$savedPos = s0;
11891
- s0 = peg$f47(s2, s3, s4, s5, s6, s7, s8);
12006
+ s0 = peg$f51(s2, s3, s4, s5, s6, s7, s8);
11892
12007
  } else {
11893
12008
  peg$currPos = s0;
11894
12009
  s0 = peg$FAILED;
@@ -11922,7 +12037,7 @@ function peg$parse(input, options) {
11922
12037
  }
11923
12038
  if (s3 !== peg$FAILED) {
11924
12039
  peg$savedPos = s0;
11925
- s0 = peg$f48(s2);
12040
+ s0 = peg$f52(s2);
11926
12041
  } else {
11927
12042
  peg$currPos = s0;
11928
12043
  s0 = peg$FAILED;
@@ -12072,12 +12187,12 @@ function peg$parse(input, options) {
12072
12187
  else s1 = s2;
12073
12188
  if (s1 !== peg$FAILED) {
12074
12189
  peg$savedPos = peg$currPos;
12075
- s2 = peg$f49(s1);
12190
+ s2 = peg$f53(s1);
12076
12191
  if (s2) s2 = void 0;
12077
12192
  else s2 = peg$FAILED;
12078
12193
  if (s2 !== peg$FAILED) {
12079
12194
  peg$savedPos = s0;
12080
- s0 = peg$f50(s1);
12195
+ s0 = peg$f54(s1);
12081
12196
  } else {
12082
12197
  peg$currPos = s0;
12083
12198
  s0 = peg$FAILED;
@@ -12254,7 +12369,7 @@ function peg$parse(input, options) {
12254
12369
  else s1 = s2;
12255
12370
  if (s1 !== peg$FAILED) {
12256
12371
  peg$savedPos = s0;
12257
- s1 = peg$f51(s1);
12372
+ s1 = peg$f55(s1);
12258
12373
  }
12259
12374
  s0 = s1;
12260
12375
  return s0;
@@ -12298,7 +12413,7 @@ function peg$parse(input, options) {
12298
12413
  if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
12299
12414
  if (s7 !== peg$FAILED) {
12300
12415
  peg$savedPos = s0;
12301
- s0 = peg$f52(s2, s3, s4, s6);
12416
+ s0 = peg$f56(s2, s3, s4, s6);
12302
12417
  } else {
12303
12418
  peg$currPos = s0;
12304
12419
  s0 = peg$FAILED;
@@ -12363,7 +12478,7 @@ function peg$parse(input, options) {
12363
12478
  s5 = peg$parse_();
12364
12479
  s6 = peg$parseHere();
12365
12480
  peg$savedPos = s0;
12366
- s0 = peg$f53(s2, s6);
12481
+ s0 = peg$f57(s2, s6);
12367
12482
  } else {
12368
12483
  peg$currPos = s0;
12369
12484
  s0 = peg$FAILED;
@@ -12403,7 +12518,7 @@ function peg$parse(input, options) {
12403
12518
  }
12404
12519
  if (s5 !== peg$FAILED) {
12405
12520
  peg$savedPos = s0;
12406
- s0 = peg$f54(s2, s3);
12521
+ s0 = peg$f58(s2, s3);
12407
12522
  } else {
12408
12523
  peg$currPos = s0;
12409
12524
  s0 = peg$FAILED;
@@ -12538,7 +12653,7 @@ function peg$parse(input, options) {
12538
12653
  else s3 = s4;
12539
12654
  if (s3 !== peg$FAILED) {
12540
12655
  peg$savedPos = peg$currPos;
12541
- s4 = peg$f55(s2, s3);
12656
+ s4 = peg$f59(s2, s3);
12542
12657
  if (s4) s4 = void 0;
12543
12658
  else s4 = peg$FAILED;
12544
12659
  if (s4 !== peg$FAILED) {
@@ -12556,7 +12671,7 @@ function peg$parse(input, options) {
12556
12671
  s9 = peg$parseAttrValue();
12557
12672
  if (s9 !== peg$FAILED) {
12558
12673
  peg$savedPos = s5;
12559
- s5 = peg$f56(s2, s3, s9);
12674
+ s5 = peg$f60(s2, s3, s9);
12560
12675
  } else {
12561
12676
  peg$currPos = s5;
12562
12677
  s5 = peg$FAILED;
@@ -12567,7 +12682,7 @@ function peg$parse(input, options) {
12567
12682
  }
12568
12683
  if (s5 === peg$FAILED) s5 = null;
12569
12684
  peg$savedPos = s0;
12570
- s0 = peg$f57(s2, s3, s5);
12685
+ s0 = peg$f61(s2, s3, s5);
12571
12686
  } else {
12572
12687
  peg$currPos = s0;
12573
12688
  s0 = peg$FAILED;
@@ -12625,7 +12740,7 @@ function peg$parse(input, options) {
12625
12740
  if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
12626
12741
  if (s5 !== peg$FAILED) {
12627
12742
  peg$savedPos = s0;
12628
- s0 = peg$f58(s2, s3, s4);
12743
+ s0 = peg$f62(s2, s3, s4);
12629
12744
  } else {
12630
12745
  peg$currPos = s0;
12631
12746
  s0 = peg$FAILED;
@@ -12680,7 +12795,7 @@ function peg$parse(input, options) {
12680
12795
  if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
12681
12796
  if (s5 !== peg$FAILED) {
12682
12797
  peg$savedPos = s0;
12683
- s0 = peg$f59(s2, s3, s4);
12798
+ s0 = peg$f63(s2, s3, s4);
12684
12799
  } else {
12685
12800
  peg$currPos = s0;
12686
12801
  s0 = peg$FAILED;
@@ -12699,7 +12814,7 @@ function peg$parse(input, options) {
12699
12814
  }
12700
12815
  if (s1 !== peg$FAILED) {
12701
12816
  peg$savedPos = s0;
12702
- s1 = peg$f60(s1);
12817
+ s1 = peg$f64(s1);
12703
12818
  }
12704
12819
  s0 = s1;
12705
12820
  if (s0 === peg$FAILED) {
@@ -12725,7 +12840,7 @@ function peg$parse(input, options) {
12725
12840
  s2 = input.substring(s2, peg$currPos);
12726
12841
  s3 = peg$parseHere();
12727
12842
  peg$savedPos = s0;
12728
- s0 = peg$f61(s1, s2, s3);
12843
+ s0 = peg$f65(s1, s2, s3);
12729
12844
  }
12730
12845
  }
12731
12846
  }
@@ -12735,7 +12850,7 @@ function peg$parse(input, options) {
12735
12850
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
12736
12851
  s0 = peg$currPos;
12737
12852
  peg$savedPos = peg$currPos;
12738
- s1 = peg$f62();
12853
+ s1 = peg$f66();
12739
12854
  if (s1) s1 = void 0;
12740
12855
  else s1 = peg$FAILED;
12741
12856
  if (s1 !== peg$FAILED) {
@@ -12764,7 +12879,7 @@ function peg$parse(input, options) {
12764
12879
  if (s2 !== peg$FAILED) {
12765
12880
  s3 = peg$currPos;
12766
12881
  peg$savedPos = peg$currPos;
12767
- s4 = peg$f63(s2);
12882
+ s4 = peg$f67(s2);
12768
12883
  if (s4) s4 = void 0;
12769
12884
  else s4 = peg$FAILED;
12770
12885
  if (s4 !== peg$FAILED) {
@@ -12803,7 +12918,7 @@ function peg$parse(input, options) {
12803
12918
  if (s0 === peg$FAILED) {
12804
12919
  s0 = peg$currPos;
12805
12920
  peg$savedPos = peg$currPos;
12806
- s1 = peg$f64();
12921
+ s1 = peg$f68();
12807
12922
  if (s1) s1 = void 0;
12808
12923
  else s1 = peg$FAILED;
12809
12924
  if (s1 !== peg$FAILED) {
@@ -12830,12 +12945,12 @@ function peg$parse(input, options) {
12830
12945
  if (s6 !== peg$FAILED) {
12831
12946
  s7 = peg$parseHere();
12832
12947
  peg$savedPos = peg$currPos;
12833
- s8 = peg$f65(s4, s7);
12948
+ s8 = peg$f69(s4, s7);
12834
12949
  if (s8) s8 = void 0;
12835
12950
  else s8 = peg$FAILED;
12836
12951
  if (s8 !== peg$FAILED) {
12837
12952
  s9 = peg$currPos;
12838
- s10 = peg$f66(s4, s7);
12953
+ s10 = peg$f70(s4, s7);
12839
12954
  s11 = peg$currPos;
12840
12955
  s12 = [];
12841
12956
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -12911,7 +13026,7 @@ function peg$parse(input, options) {
12911
13026
  if (s0 === peg$FAILED) {
12912
13027
  s0 = peg$currPos;
12913
13028
  peg$savedPos = peg$currPos;
12914
- s1 = peg$f67();
13029
+ s1 = peg$f71();
12915
13030
  if (s1) s1 = void 0;
12916
13031
  else s1 = peg$FAILED;
12917
13032
  if (s1 !== peg$FAILED) {
@@ -12996,7 +13111,7 @@ function peg$parse(input, options) {
12996
13111
  if (s0 === peg$FAILED) {
12997
13112
  s0 = peg$currPos;
12998
13113
  peg$savedPos = peg$currPos;
12999
- s1 = peg$f68();
13114
+ s1 = peg$f72();
13000
13115
  if (s1) s1 = void 0;
13001
13116
  else s1 = peg$FAILED;
13002
13117
  if (s1 !== peg$FAILED) {
@@ -13089,6 +13204,8 @@ function peg$parse(input, options) {
13089
13204
  let attrCode = false;
13090
13205
  /** The macro whose raw body is being read. */
13091
13206
  let rawName = "";
13207
+ /** The HTML text-only body being read; its own closer ends this context. */
13208
+ let htmlTextTag = "";
13092
13209
  /**
13093
13210
  * The index in `inner` (at `at` in the input) of the first `separator` that
13094
13211
  * is not inside a {…} of the label: its code (`{if $a || $b}`, a string with
@@ -16595,6 +16712,53 @@ function unclosedHtml(text) {
16595
16712
  }
16596
16713
  } } };
16597
16714
  }
16715
+ // src/markup/html-integration.tsx
16716
+ function isHtmlEncoding(value) {
16717
+ return typeof value === "string" && /^(?:text\/html|application\/xhtml\+xml)$/i.test(value);
16718
+ }
16719
+ function authorElement(tag, attributes, children, math) {
16720
+ return math && tag === "annotation-xml" ? /* @__PURE__ */ jsx(HtmlAnnotation, {
16721
+ attributes,
16722
+ children
16723
+ }, attributes.key) : h(tag, attributes, children);
16724
+ }
16725
+ /**
16726
+ * Preact handles MathML text integration points, but does not yet switch the
16727
+ * namespace for HTML-encoded annotation-xml. A portal's container can supply
16728
+ * that namespace without adding a wrapper or changing the MathML element.
16729
+ */
16730
+ function HtmlAnnotation({ attributes, children }) {
16731
+ const elementRef = useRef(null);
16732
+ const [container, setContainer] = useState(null);
16733
+ useLayoutEffect(() => {
16734
+ const element = elementRef.current;
16735
+ setContainer({
16736
+ nodeType: 1,
16737
+ namespaceURI: "http://www.w3.org/1999/xhtml",
16738
+ ownerDocument: element.ownerDocument,
16739
+ get parentNode() {
16740
+ return element.parentNode;
16741
+ },
16742
+ get firstChild() {
16743
+ return element.firstChild;
16744
+ },
16745
+ get childNodes() {
16746
+ return element.childNodes;
16747
+ },
16748
+ insertBefore: element.insertBefore.bind(element),
16749
+ appendChild: element.appendChild.bind(element),
16750
+ removeChild: element.removeChild.bind(element)
16751
+ });
16752
+ }, []);
16753
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [h("annotation-xml", {
16754
+ ...attributes,
16755
+ ref: (element) => {
16756
+ elementRef.current = element;
16757
+ const forwarded = attributes.ref;
16758
+ if (forwarded) forwarded.current = element;
16759
+ }
16760
+ }, isHtmlEncoding(attributes.encoding) ? void 0 : children), container && isHtmlEncoding(attributes.encoding) && createPortal(children, container)] });
16761
+ }
16598
16762
  // src/markup/render.tsx
16599
16763
  var defaultUpdater = {
16600
16764
  update: (key) => {
@@ -16621,7 +16785,7 @@ var InlineContext = createContext(false);
16621
16785
  */
16622
16786
  var StructuralContext = createContext(false);
16623
16787
  /**
16624
- * True while rendering inside an element whose content is not markdown: SVG
16788
+ * True while rendering inside an element whose content is not markdown: SVG/MathML
16625
16789
  * (whose namespace `<p>` wrappers would break) and the preformatted `<pre>`
16626
16790
  * `<textarea>`, `<style>` and `<script>`, whose text is literal.
16627
16791
  * Macro and widget bodies read it so their content stays literal too.
@@ -16641,11 +16805,19 @@ function useViewScope() {
16641
16805
  return useState(() => `v${++viewScopes}`)[0];
16642
16806
  }
16643
16807
  /**
16644
- * True inside an `<svg>` element. SVG attributes are case-sensitive and have
16645
- * no live form properties, so they are set as written (see splitAttributes).
16808
+ * The foreign namespace containing author elements. SVG and MathML attributes
16809
+ * are case-sensitive and have no live HTML form properties.
16646
16810
  */
16647
- var SvgContext = createContext(false);
16811
+ var ForeignContext = createContext(void 0);
16648
16812
  var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
16813
+ var MATH_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
16814
+ var MATH_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
16815
+ "mi",
16816
+ "mo",
16817
+ "mn",
16818
+ "ms",
16819
+ "mtext"
16820
+ ]);
16649
16821
  /**
16650
16822
  * Elements whose children must be elements of particular types: markdown
16651
16823
  * paragraphs between them would pull the children out of the structure (#423).
@@ -16667,12 +16839,7 @@ var STRUCTURAL_ELEMENTS = /* @__PURE__ */ new Set([
16667
16839
  "datalist"
16668
16840
  ]);
16669
16841
  /** Elements whose content is literal text, not markdown. */
16670
- var PREFORMATTED_ELEMENTS = /* @__PURE__ */ new Set([
16671
- "pre",
16672
- "textarea",
16673
- "style",
16674
- "script"
16675
- ]);
16842
+ var PREFORMATTED_ELEMENTS = /* @__PURE__ */ new Set(["pre", ...HTML_TEXT_ELEMENTS$1]);
16676
16843
  var WidgetChildrenContext = createContext(null);
16677
16844
  function placeholderHtml(nonce, index) {
16678
16845
  return `<span data-tw=${nonce}:${index}></span>`;
@@ -16720,7 +16887,7 @@ function expandPlaceholderText(text, ph) {
16720
16887
  * evaluated as text against the store and locals, so it follows its
16721
16888
  * variables as the component would.
16722
16889
  */
16723
- function PlaceholderAttributes({ tag, attributes, placeholders, svg, children }) {
16890
+ function PlaceholderAttributes({ tag, attributes, placeholders, foreign, math, children }) {
16724
16891
  const scope = useTextScope();
16725
16892
  const errors = [];
16726
16893
  const { props, direct } = splitAttributes(attributes.map(([name, value, written]) => {
@@ -16739,20 +16906,20 @@ function PlaceholderAttributes({ tag, attributes, placeholders, svg, children })
16739
16906
  written,
16740
16907
  true
16741
16908
  ];
16742
- }), svg, tag);
16909
+ }), foreign, tag);
16743
16910
  const ref = useDirectAttributes(direct);
16744
- return withAttributeErrors(errors, h(tag, ref ? {
16911
+ return withAttributeErrors(errors, authorElement(tag, ref ? {
16745
16912
  ...props,
16746
16913
  ref
16747
- } : props, children));
16914
+ } : props, children, math));
16748
16915
  }
16749
16916
  /** An element of markdown output with attributes to set directly. */
16750
- function DirectAttributes({ tag, props, direct, children }) {
16917
+ function DirectAttributes({ tag, props, direct, math, children }) {
16751
16918
  const ref = useDirectAttributes(direct);
16752
- return h(tag, {
16919
+ return authorElement(tag, {
16753
16920
  ...props,
16754
16921
  ref
16755
- }, children);
16922
+ }, children, math);
16756
16923
  }
16757
16924
  /**
16758
16925
  * Show the errors met in an element's attributes in front of it, the way a
@@ -16810,7 +16977,7 @@ function convertDomNode(node, key, ph) {
16810
16977
  const tag = el.localName;
16811
16978
  const idx = placeholderIndex(el, ph);
16812
16979
  if (idx !== -1) return ph.components[idx];
16813
- const svg = el.namespaceURI === SVG_NAMESPACE;
16980
+ const foreign = el.namespaceURI === SVG_NAMESPACE || el.namespaceURI === MATH_NAMESPACE;
16814
16981
  const attributes = [];
16815
16982
  let placeholders;
16816
16983
  for (const { name, value } of Array.from(el.attributes)) {
@@ -16833,20 +17000,22 @@ function convertDomNode(node, key, ph) {
16833
17000
  tag,
16834
17001
  attributes,
16835
17002
  placeholders,
16836
- svg,
17003
+ foreign,
17004
+ math: el.namespaceURI === MATH_NAMESPACE,
16837
17005
  children
16838
17006
  }, key);
16839
- const { props, direct } = splitAttributes(attributes, svg, tag);
17007
+ const { props, direct } = splitAttributes(attributes, foreign, tag);
16840
17008
  if (direct.length > 0) return /* @__PURE__ */ jsx(DirectAttributes, {
16841
17009
  tag,
16842
17010
  props,
16843
17011
  direct,
17012
+ math: el.namespaceURI === MATH_NAMESPACE,
16844
17013
  children
16845
17014
  }, key);
16846
- return h(tag, {
17015
+ return authorElement(tag, {
16847
17016
  ...props,
16848
17017
  key
16849
- }, children);
17018
+ }, children, el.namespaceURI === MATH_NAMESPACE);
16850
17019
  }
16851
17020
  return null;
16852
17021
  }
@@ -16955,7 +17124,7 @@ var BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
16955
17124
  "selected"
16956
17125
  ]);
16957
17126
  /** Names set directly on SVG elements (see splitAttributes). */
16958
- var SVG_DIRECT = /* @__PURE__ */ new Set([
17127
+ var FOREIGN_DIRECT = /* @__PURE__ */ new Set([
16959
17128
  .../* @__PURE__ */ new Set([
16960
17129
  "key",
16961
17130
  "ref",
@@ -17008,18 +17177,18 @@ function isNativeDefault(tag, name) {
17008
17177
  * and `className` compat rewrites (dropping an empty `class`, turning
17009
17178
  * `className` into `class`) are set directly instead.
17010
17179
  */
17011
- function splitAttributes(attributes, svg, tag) {
17180
+ function splitAttributes(attributes, foreign, tag) {
17012
17181
  const props = {};
17013
17182
  const direct = [];
17014
17183
  const defaults = [];
17015
17184
  for (const [name, value, written, bound] of attributes) {
17016
17185
  const lower = name.toLowerCase();
17017
17186
  if (BOOLEAN_ATTRIBUTES.has(lower) && written !== "" && value === "") continue;
17018
- else if (!svg && LIVE_PROPERTIES.has(lower)) {
17187
+ else if (!foreign && LIVE_PROPERTIES.has(lower)) {
17019
17188
  if (!bound && isNativeDefault(tag, lower)) defaults.push([name.toUpperCase(), lower === "value" ? value : ""]);
17020
17189
  else props[lower] = lower !== "value" && written === "" ? true : value;
17021
- } else if (!SETTABLE_NAME.test(name) || lower.startsWith("on") || lower === "translate" || svg && (SVG_DIRECT.has(name) || name === "__proto__")) direct.push([name, value]);
17022
- else props[svg ? name : name.toUpperCase()] = value;
17190
+ } else if (!SETTABLE_NAME.test(name) || lower.startsWith("on") || lower === "translate" || foreign && (FOREIGN_DIRECT.has(name) || name === "__proto__")) direct.push([name, value]);
17191
+ else props[foreign ? name : name.toUpperCase()] = value;
17023
17192
  }
17024
17193
  for (const [name, value] of defaults) props[name] = value;
17025
17194
  return {
@@ -17146,26 +17315,30 @@ function leadingPartIndex(tag, nodes) {
17146
17315
  function HtmlNodeRenderer({ node }) {
17147
17316
  const scope = useTextScope();
17148
17317
  const { nobr, locals, raw: inRaw, inline: parentInline, structural: parentStructural } = useRenderOptions();
17149
- const inSvg = useContext(SvgContext);
17318
+ const parentNamespace = useContext(ForeignContext);
17150
17319
  const tag = node.tag.toLowerCase();
17151
- const isSvgRoot = tag === "svg";
17152
- const isHtmlRoot = inSvg && tag === "foreignobject";
17153
- const rawContent = inRaw && !isHtmlRoot;
17154
- const isRawRoot = !inRaw && (isSvgRoot || PREFORMATTED_ELEMENTS.has(tag));
17320
+ const namespace = tag === "svg" || tag === "math" ? tag : parentNamespace;
17155
17321
  const errors = [];
17156
- const { props, direct } = splitAttributes(Object.entries(node.attributes).map(([k, v]) => [
17322
+ const resolved = Object.entries(node.attributes).map(([k, v]) => [
17157
17323
  k,
17158
17324
  resolveAttributeValue(k, v, scope, errors),
17159
17325
  v,
17160
17326
  hasInterpolation(v)
17161
- ]), inSvg || isSvgRoot, tag);
17327
+ ]);
17328
+ const htmlAnnotation = namespace === "math" && tag === "annotation-xml" && isHtmlEncoding(resolved.find(([name]) => name === "encoding")?.[1]);
17329
+ const mathText = namespace === "math" && MATH_TEXT_ELEMENTS.has(tag);
17330
+ const isHtmlRoot = namespace === "svg" && tag === "foreignobject" || htmlAnnotation;
17331
+ const childNamespace = isHtmlRoot || mathText ? void 0 : namespace;
17332
+ const rawContent = inRaw && !isHtmlRoot;
17333
+ const isRawRoot = !inRaw && (namespace !== void 0 || PREFORMATTED_ELEMENTS.has(tag));
17334
+ const { props, direct } = splitAttributes(resolved, namespace !== void 0, tag);
17162
17335
  const ref = useDirectAttributes(direct);
17163
17336
  if (ref) props.ref = ref;
17164
17337
  const isInline = INLINE_ELEMENTS.has(tag);
17165
17338
  let children = void 0;
17166
17339
  let structural = false;
17167
17340
  if (node.children.length > 0) {
17168
- if (tag === "style" || tag === "script") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
17341
+ if (RAW_TEXT_ELEMENTS.has(tag)) children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
17169
17342
  else if (rawContent || isRawRoot) children = renderInlineNodes(node.children);
17170
17343
  else {
17171
17344
  const leadAt = leadingPartIndex(tag, node.children);
@@ -17190,18 +17363,18 @@ function HtmlNodeRenderer({ node }) {
17190
17363
  });
17191
17364
  }
17192
17365
  }
17193
- if (isHtmlRoot && children) children = /* @__PURE__ */ jsx(SvgContext.Provider, {
17194
- value: false,
17366
+ if (isHtmlRoot && children) children = /* @__PURE__ */ jsx(ForeignContext.Provider, {
17367
+ value: void 0,
17195
17368
  children: /* @__PURE__ */ jsx(RawTextContext.Provider, {
17196
17369
  value: false,
17197
17370
  children
17198
17371
  })
17199
17372
  });
17200
- let element = h(node.tag, props, children);
17201
- if (isSvgRoot && !inSvg) element = /* @__PURE__ */ jsx(SvgContext.Provider, {
17202
- value: true,
17203
- children: element
17373
+ if (childNamespace !== parentNamespace) children = /* @__PURE__ */ jsx(ForeignContext.Provider, {
17374
+ value: childNamespace,
17375
+ children
17204
17376
  });
17377
+ const element = authorElement(node.tag, props, children, namespace === "math");
17205
17378
  return withAttributeErrors(errors, isRawRoot ? /* @__PURE__ */ jsx(RawTextContext.Provider, {
17206
17379
  value: true,
17207
17380
  children: element
@@ -19398,6 +19571,7 @@ function persistSession(get) {
19398
19571
  const { storyData, currentPassage, variables, history, historyIndex, visitCounts, renderCounts } = get();
19399
19572
  if (!storyData) return void 0;
19400
19573
  if (sessionMoments.length > history.length) sessionMoments.length = history.length;
19574
+ for (let i = 0; i < sessionMoments.length; i++) sessionMoments[i] = savedMoment(history[i], sessionMoments[i].variables);
19401
19575
  if (sessionMoments.length < history.length) {
19402
19576
  if (history.length - sessionMoments.length === 1) {
19403
19577
  const i = history.length - 1;
@@ -21188,7 +21362,7 @@ var escapeTextReferences = (text) => escapeAttributeReferences(text).replace(/</
21188
21362
  * HtmlNodeRenderer), for which the browser did not decode any either.
21189
21363
  */
21190
21364
  function isLiteralTextElement(parent) {
21191
- return ["style", "script"].includes(parent.localName) && parent.namespaceURI === HTML_NAMESPACE;
21365
+ return RAW_TEXT_ELEMENTS.has(parent.localName) && parent.namespaceURI === HTML_NAMESPACE;
21192
21366
  }
21193
21367
  /**
21194
21368
  * `value` with the text in it escaped by `escape`, but not markup
@@ -21831,11 +22005,8 @@ function keyOf(val, seen) {
21831
22005
  const keys = className === void 0 ? [] : extraKeys(obj);
21832
22006
  return named(keys.length ? `${key}${fieldsOf(obj, keys, seen)}` : key);
21833
22007
  };
21834
- if (val instanceof Date || val instanceof RegExp) {
21835
- if (className !== void 0 && extraKeys(obj).length) seen.set(obj, seen.size);
21836
- return withFields(val instanceof Date ? `Date(${Date.prototype.getTime.call(val)})` : `RegExp(${regExpText(val)}@${val.lastIndex})`);
21837
- }
21838
22008
  seen.set(obj, seen.size);
22009
+ if (val instanceof Date || val instanceof RegExp) return withFields(val instanceof Date ? `Date(${Date.prototype.getTime.call(val)})` : `RegExp(${regExpText(val)}@${val.lastIndex})`);
21839
22010
  if (Array.isArray(val)) {
21840
22011
  const items = [];
21841
22012
  let next = 0;
@@ -22153,8 +22324,8 @@ function createStoryAPI() {
22153
22324
  if (event === "variableChanged") ensureVariableChangedSubscription();
22154
22325
  return trackRuntimeUnsub(on(event, callback));
22155
22326
  },
22156
- async waitForActions() {
22157
- await settleRunningActions();
22327
+ async waitForActions(options = {}) {
22328
+ if (options.includeRunningActions !== false) await settleRunningActions();
22158
22329
  await new Promise((resolve) => {
22159
22330
  requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
22160
22331
  });