@rohal12/spindle 0.59.23 → 0.59.26

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";
@@ -39,7 +39,7 @@ function create() {
39
39
  */
40
40
  function randomUUID() {
41
41
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
42
- const bytes = crypto.getRandomValues(new Uint8Array(16));
42
+ const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
43
43
  bytes[6] = bytes[6] & 15 | 64;
44
44
  bytes[8] = bytes[8] & 63 | 128;
45
45
  const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
@@ -89,7 +89,7 @@ var grammar_shared_default = {
89
89
  var LB = String.fromCharCode(123);
90
90
  var RB = String.fromCharCode(125);
91
91
  var { SIGIL_SCOPES, withSelectors } = grammar_shared_default;
92
- var VOID_TAGS = new Set([
92
+ var VOID_TAGS = /* @__PURE__ */ new Set([
93
93
  "area",
94
94
  "base",
95
95
  "br",
@@ -751,7 +751,7 @@ function peg$parse(input, options) {
751
751
  return withSelectors(node, s);
752
752
  }
753
753
  function peg$f35() {
754
- fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
754
+ fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
755
755
  }
756
756
  function peg$f36(start) {
757
757
  return skipTo(hooks.closeBrace(input, start, start));
@@ -783,13 +783,13 @@ function peg$parse(input, options) {
783
783
  tag.nameStart = nameEnd - name.length;
784
784
  tag.nameEnd = nameEnd;
785
785
  tag.selectorSpan = selectorSpan(s, ss, start);
786
- if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
786
+ if (tail === null) fail("Unclosed {" + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
787
787
  tag.rawArgs = tail.trim();
788
788
  tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
789
789
  tag.argsEnd = tag.argsStart + tag.rawArgs.length;
790
790
  if (close) {
791
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");
792
+ if (tag.rawArgs) fail("A closing tag takes no arguments: {/" + name + " " + tag.rawArgs + RB, loc, "closer-with-arguments");
793
793
  tag.kind = "close";
794
794
  } else {
795
795
  withSelectors(tag, s);
@@ -798,7 +798,7 @@ function peg$parse(input, options) {
798
798
  return tag;
799
799
  }
800
800
  function peg$f43(s) {
801
- fail("A closing tag starts with a letter after " + LB + "/", location(), "invalid-closer");
801
+ fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
802
802
  }
803
803
  function peg$f44(value) {
804
804
  return EMAIL_AUTOLINK.test(value);
@@ -1677,12 +1677,14 @@ function peg$parse(input, options) {
1677
1677
  s3 = peg$FAILED;
1678
1678
  if (peg$silentFails === 0) peg$fail(peg$e13);
1679
1679
  }
1680
- if (s3 === peg$FAILED) if (input.substr(peg$currPos, 2) === peg$c8) {
1681
- s3 = peg$c8;
1682
- peg$currPos += 2;
1683
- } else {
1684
- s3 = peg$FAILED;
1685
- if (peg$silentFails === 0) peg$fail(peg$e12);
1680
+ if (s3 === peg$FAILED) {
1681
+ if (input.substr(peg$currPos, 2) === peg$c8) {
1682
+ s3 = peg$c8;
1683
+ peg$currPos += 2;
1684
+ } else {
1685
+ s3 = peg$FAILED;
1686
+ if (peg$silentFails === 0) peg$fail(peg$e12);
1687
+ }
1686
1688
  }
1687
1689
  peg$silentFails--;
1688
1690
  if (s3 === peg$FAILED) s2 = void 0;
@@ -1721,12 +1723,14 @@ function peg$parse(input, options) {
1721
1723
  s3 = peg$FAILED;
1722
1724
  if (peg$silentFails === 0) peg$fail(peg$e13);
1723
1725
  }
1724
- if (s3 === peg$FAILED) if (input.substr(peg$currPos, 2) === peg$c8) {
1725
- s3 = peg$c8;
1726
- peg$currPos += 2;
1727
- } else {
1728
- s3 = peg$FAILED;
1729
- if (peg$silentFails === 0) peg$fail(peg$e12);
1726
+ if (s3 === peg$FAILED) {
1727
+ if (input.substr(peg$currPos, 2) === peg$c8) {
1728
+ s3 = peg$c8;
1729
+ peg$currPos += 2;
1730
+ } else {
1731
+ s3 = peg$FAILED;
1732
+ if (peg$silentFails === 0) peg$fail(peg$e12);
1733
+ }
1730
1734
  }
1731
1735
  peg$silentFails--;
1732
1736
  if (s3 === peg$FAILED) s2 = void 0;
@@ -3409,7 +3413,7 @@ var BLOCK_MACROS = new NameSet([
3409
3413
  "nobr"
3410
3414
  ]);
3411
3415
  /** Macros whose body is JavaScript source, kept verbatim. */
3412
- var RAW_BODY_MACROS = new Set(["do"]);
3416
+ var RAW_BODY_MACROS = /* @__PURE__ */ new Set(["do"]);
3413
3417
  /** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
3414
3418
  function isRawMacro(name) {
3415
3419
  return RAW_BODY_MACROS.has(name);
@@ -3423,7 +3427,7 @@ function registerBlockMacro(name) {
3423
3427
  BLOCK_MACROS.add(name);
3424
3428
  }
3425
3429
  /** Macros whose branches render as one: the node holds one per branch. */
3426
- var BRANCHING = new Set([
3430
+ var BRANCHING = /* @__PURE__ */ new Set([
3427
3431
  "if",
3428
3432
  "switch",
3429
3433
  "timed"
@@ -4728,7 +4732,8 @@ function binop(name, prec) {
4728
4732
  binop: prec
4729
4733
  });
4730
4734
  }
4731
- var beforeExpr = { beforeExpr: true }, startsExpr = { startsExpr: true };
4735
+ var beforeExpr = { beforeExpr: true };
4736
+ var startsExpr = { startsExpr: true };
4732
4737
  var keywords = {};
4733
4738
  function kw(name, options) {
4734
4739
  if (options === void 0) options = {};
@@ -4983,11 +4988,27 @@ function pushComment(options, array) {
4983
4988
  array.push(comment);
4984
4989
  };
4985
4990
  }
4986
- var SCOPE_TOP = 1, SCOPE_FUNCTION = 2, SCOPE_ASYNC = 4, SCOPE_GENERATOR = 8, SCOPE_ARROW = 16, SCOPE_SIMPLE_CATCH = 32, SCOPE_SUPER = 64, SCOPE_DIRECT_SUPER = 128, SCOPE_CLASS_STATIC_BLOCK = 256, SCOPE_CLASS_FIELD_INIT = 512, SCOPE_SWITCH = 1024, SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
4991
+ var SCOPE_TOP = 1;
4992
+ var SCOPE_FUNCTION = 2;
4993
+ var SCOPE_ASYNC = 4;
4994
+ var SCOPE_GENERATOR = 8;
4995
+ var SCOPE_ARROW = 16;
4996
+ var SCOPE_SIMPLE_CATCH = 32;
4997
+ var SCOPE_SUPER = 64;
4998
+ var SCOPE_DIRECT_SUPER = 128;
4999
+ var SCOPE_CLASS_STATIC_BLOCK = 256;
5000
+ var SCOPE_CLASS_FIELD_INIT = 512;
5001
+ var SCOPE_SWITCH = 1024;
5002
+ var SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
4987
5003
  function functionFlags(async, generator) {
4988
5004
  return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0);
4989
5005
  }
4990
- var BIND_NONE = 0, BIND_VAR = 1, BIND_LEXICAL = 2, BIND_FUNCTION = 3, BIND_SIMPLE_CATCH = 4, BIND_OUTSIDE = 5;
5006
+ var BIND_NONE = 0;
5007
+ var BIND_VAR = 1;
5008
+ var BIND_LEXICAL = 2;
5009
+ var BIND_FUNCTION = 3;
5010
+ var BIND_SIMPLE_CATCH = 4;
5011
+ var BIND_OUTSIDE = 5;
4991
5012
  var Parser = function Parser(options, input, startPos) {
4992
5013
  this.options = options = getOptions(options);
4993
5014
  this.sourceFile = options.sourceFile;
@@ -5242,7 +5263,8 @@ pp$8.parseTopLevel = function(node) {
5242
5263
  node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType;
5243
5264
  return this.finishNode(node, "Program");
5244
5265
  };
5245
- var loopLabel = { kind: "loop" }, switchLabel = { kind: "switch" };
5266
+ var loopLabel = { kind: "loop" };
5267
+ var switchLabel = { kind: "switch" };
5246
5268
  pp$8.isLet = function(context) {
5247
5269
  if (this.options.ecmaVersion < 6 || !this.isContextual("let")) return false;
5248
5270
  skipWhiteSpace.lastIndex = this.pos;
@@ -5671,7 +5693,9 @@ pp$8.parseVarId = function(decl, kind) {
5671
5693
  decl.id = kind === "using" || kind === "await using" ? this.parseIdent() : this.parseBindingAtom();
5672
5694
  this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
5673
5695
  };
5674
- var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
5696
+ var FUNC_STATEMENT = 1;
5697
+ var FUNC_HANGING_STATEMENT = 2;
5698
+ var FUNC_NULLABLE_ID = 4;
5675
5699
  pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
5676
5700
  this.initFunction(node);
5677
5701
  if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
@@ -5746,13 +5770,17 @@ pp$8.parseClassElement = function(constructorAllowsSuper) {
5746
5770
  else keyName = "static";
5747
5771
  }
5748
5772
  node.static = isStatic;
5749
- if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) isAsync = true;
5750
- else keyName = "async";
5773
+ if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
5774
+ if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) isAsync = true;
5775
+ else keyName = "async";
5776
+ }
5751
5777
  if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) isGenerator = true;
5752
5778
  if (!keyName && !isAsync && !isGenerator) {
5753
5779
  var lastValue = this.value;
5754
- if (this.eatContextual("get") || this.eatContextual("set")) if (this.isClassElementNameStart()) kind = lastValue;
5755
- else keyName = lastValue;
5780
+ if (this.eatContextual("get") || this.eatContextual("set")) {
5781
+ if (this.isClassElementNameStart()) kind = lastValue;
5782
+ else keyName = lastValue;
5783
+ }
5756
5784
  }
5757
5785
  if (keyName) {
5758
5786
  node.computed = false;
@@ -5845,8 +5873,10 @@ pp$8.exitClassBody = function() {
5845
5873
  var parent = len === 0 ? null : this.privateNameStack[len - 1];
5846
5874
  for (var i = 0; i < used.length; ++i) {
5847
5875
  var id = used[i];
5848
- if (!hasOwn$1(declared, id.name)) if (parent) parent.used.push(id);
5849
- else this.raiseRecoverable(id.start, "Private field '#" + id.name + "' must be declared in an enclosing class");
5876
+ if (!hasOwn$1(declared, id.name)) {
5877
+ if (parent) parent.used.push(id);
5878
+ else this.raiseRecoverable(id.start, "Private field '#" + id.name + "' must be declared in an enclosing class");
5879
+ }
5850
5880
  }
5851
5881
  };
5852
5882
  function isPrivateNameConflicted(privateNameMap, element) {
@@ -5868,10 +5898,12 @@ function checkKeyName(node, name) {
5868
5898
  return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name);
5869
5899
  }
5870
5900
  pp$8.parseExportAllDeclaration = function(node, exports$1) {
5871
- if (this.options.ecmaVersion >= 11) if (this.eatContextual("as")) {
5872
- node.exported = this.parseModuleExportName();
5873
- this.checkExport(exports$1, node.exported, this.lastTokStart);
5874
- } else node.exported = null;
5901
+ if (this.options.ecmaVersion >= 11) {
5902
+ if (this.eatContextual("as")) {
5903
+ node.exported = this.parseModuleExportName();
5904
+ this.checkExport(exports$1, node.exported, this.lastTokStart);
5905
+ } else node.exported = null;
5906
+ }
5875
5907
  this.expectContextual("from");
5876
5908
  if (this.type !== types$1.string) this.unexpected();
5877
5909
  node.source = this.parseExprAtom();
@@ -6389,9 +6421,11 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
6389
6421
  var kind = prop.kind;
6390
6422
  if (this.options.ecmaVersion >= 6) {
6391
6423
  if (name === "__proto__" && kind === "init") {
6392
- if (propHash.proto) if (refDestructuringErrors) {
6393
- if (refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start;
6394
- } else this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
6424
+ if (propHash.proto) {
6425
+ if (refDestructuringErrors) {
6426
+ if (refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start;
6427
+ } else this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
6428
+ }
6395
6429
  propHash.proto = true;
6396
6430
  }
6397
6431
  return;
@@ -6425,8 +6459,10 @@ pp$5.parseExpression = function(forInit, refDestructuringErrors) {
6425
6459
  });
6426
6460
  };
6427
6461
  pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
6428
- if (this.isContextual("yield")) if (this.inGenerator) return this.parseYield(forInit);
6429
- else this.exprAllowed = false;
6462
+ if (this.isContextual("yield")) {
6463
+ if (this.inGenerator) return this.parseYield(forInit);
6464
+ else this.exprAllowed = false;
6465
+ }
6430
6466
  var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
6431
6467
  if (refDestructuringErrors) {
6432
6468
  oldParenAssign = refDestructuringErrors.parenthesizedAssign;
@@ -6545,9 +6581,10 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
6545
6581
  expr = this.finishNode(node$1, "UpdateExpression");
6546
6582
  }
6547
6583
  }
6548
- if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar)) if (sawUnary) this.unexpected(this.lastTokStart);
6549
- else return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false);
6550
- else return expr;
6584
+ if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar)) {
6585
+ if (sawUnary) this.unexpected(this.lastTokStart);
6586
+ else return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false);
6587
+ } else return expr;
6551
6588
  };
6552
6589
  function isLocalVariableAccess(node) {
6553
6590
  return node.type === "Identifier" || node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression);
@@ -6745,17 +6782,18 @@ pp$5.parseExprImport = function(forNew) {
6745
6782
  pp$5.parseDynamicImport = function(node) {
6746
6783
  this.next();
6747
6784
  node.source = this.parseMaybeAssign();
6748
- if (this.options.ecmaVersion >= 16) if (!this.eat(types$1.parenR)) {
6749
- this.expect(types$1.comma);
6750
- if (!this.afterTrailingComma(types$1.parenR)) {
6751
- node.options = this.parseMaybeAssign();
6752
- if (!this.eat(types$1.parenR)) {
6753
- this.expect(types$1.comma);
6754
- if (!this.afterTrailingComma(types$1.parenR)) this.unexpected();
6755
- }
6785
+ if (this.options.ecmaVersion >= 16) {
6786
+ if (!this.eat(types$1.parenR)) {
6787
+ this.expect(types$1.comma);
6788
+ if (!this.afterTrailingComma(types$1.parenR)) {
6789
+ node.options = this.parseMaybeAssign();
6790
+ if (!this.eat(types$1.parenR)) {
6791
+ this.expect(types$1.comma);
6792
+ if (!this.afterTrailingComma(types$1.parenR)) this.unexpected();
6793
+ }
6794
+ } else node.options = null;
6756
6795
  } else node.options = null;
6757
- } else node.options = null;
6758
- else if (!this.eat(types$1.parenR)) {
6796
+ } else if (!this.eat(types$1.parenR)) {
6759
6797
  var errorPos = this.start;
6760
6798
  if (this.eat(types$1.comma) && this.eat(types$1.parenR)) this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
6761
6799
  else this.unexpected(errorPos);
@@ -6989,12 +7027,14 @@ pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP
6989
7027
  } else this.unexpected();
6990
7028
  };
6991
7029
  pp$5.parsePropertyName = function(prop) {
6992
- if (this.options.ecmaVersion >= 6) if (this.eat(types$1.bracketL)) {
6993
- prop.computed = true;
6994
- prop.key = this.parseMaybeAssign();
6995
- this.expect(types$1.bracketR);
6996
- return prop.key;
6997
- } else prop.computed = false;
7030
+ if (this.options.ecmaVersion >= 6) {
7031
+ if (this.eat(types$1.bracketL)) {
7032
+ prop.computed = true;
7033
+ prop.key = this.parseMaybeAssign();
7034
+ this.expect(types$1.bracketR);
7035
+ return prop.key;
7036
+ } else prop.computed = false;
7037
+ }
6998
7038
  return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never");
6999
7039
  };
7000
7040
  pp$5.initFunction = function(node) {
@@ -7129,8 +7169,10 @@ pp$5.parsePrivateIdent = function() {
7129
7169
  else this.unexpected();
7130
7170
  this.next();
7131
7171
  this.finishNode(node, "PrivateIdentifier");
7132
- if (this.options.checkPrivateFields) if (this.privateNameStack.length === 0) this.raise(node.start, "Private field '#" + node.name + "' must be declared in an enclosing class");
7133
- else this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
7172
+ if (this.options.checkPrivateFields) {
7173
+ if (this.privateNameStack.length === 0) this.raise(node.start, "Private field '#" + node.name + "' must be declared in an enclosing class");
7174
+ else this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
7175
+ }
7134
7176
  return node;
7135
7177
  };
7136
7178
  pp$5.parseYield = function(forInit) {
@@ -7266,23 +7308,21 @@ var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
7266
7308
  var ecma11BinaryProperties = ecma10BinaryProperties;
7267
7309
  var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
7268
7310
  var ecma13BinaryProperties = ecma12BinaryProperties;
7269
- var ecma14BinaryProperties = ecma13BinaryProperties;
7270
7311
  var unicodeBinaryProperties = {
7271
7312
  9: ecma9BinaryProperties,
7272
7313
  10: ecma10BinaryProperties,
7273
7314
  11: ecma11BinaryProperties,
7274
7315
  12: ecma12BinaryProperties,
7275
7316
  13: ecma13BinaryProperties,
7276
- 14: ecma14BinaryProperties
7317
+ 14: ecma13BinaryProperties
7277
7318
  };
7278
- var ecma14BinaryPropertiesOfStrings = "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji";
7279
7319
  var unicodeBinaryPropertiesOfStrings = {
7280
7320
  9: "",
7281
7321
  10: "",
7282
7322
  11: "",
7283
7323
  12: "",
7284
7324
  13: "",
7285
- 14: ecma14BinaryPropertiesOfStrings
7325
+ 14: "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji"
7286
7326
  };
7287
7327
  var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
7288
7328
  var ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
@@ -7290,14 +7330,13 @@ var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Han
7290
7330
  var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
7291
7331
  var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
7292
7332
  var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
7293
- var ecma14ScriptValues = ecma13ScriptValues + " " + scriptValuesAddedInUnicode;
7294
7333
  var unicodeScriptValues = {
7295
7334
  9: ecma9ScriptValues,
7296
7335
  10: ecma10ScriptValues,
7297
7336
  11: ecma11ScriptValues,
7298
7337
  12: ecma12ScriptValues,
7299
7338
  13: ecma13ScriptValues,
7300
- 14: ecma14ScriptValues
7339
+ 14: ecma13ScriptValues + " " + scriptValuesAddedInUnicode
7301
7340
  };
7302
7341
  var data = {};
7303
7342
  function buildUnicodeData(ecmaVersion) {
@@ -7668,9 +7707,11 @@ pp$1.regexp_groupSpecifier = function(state) {
7668
7707
  if (!this.regexp_eatGroupName(state)) state.raise("Invalid group");
7669
7708
  var trackDisjunction = this.options.ecmaVersion >= 16;
7670
7709
  var known = state.groupNames[state.lastStringValue];
7671
- if (known) if (trackDisjunction) {
7672
- for (var i = 0, list = known; i < list.length; i += 1) if (!list[i].separatedFrom(state.branchID)) state.raise("Duplicate capture group name");
7673
- } else state.raise("Duplicate capture group name");
7710
+ if (known) {
7711
+ if (trackDisjunction) {
7712
+ for (var i = 0, list = known; i < list.length; i += 1) if (!list[i].separatedFrom(state.branchID)) state.raise("Duplicate capture group name");
7713
+ } else state.raise("Duplicate capture group name");
7714
+ }
7674
7715
  if (trackDisjunction) (known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
7675
7716
  else state.groupNames[state.lastStringValue] = true;
7676
7717
  }
@@ -8684,12 +8725,14 @@ pp.readTmplToken = function() {
8684
8725
  if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
8685
8726
  var ch = this.input.charCodeAt(this.pos);
8686
8727
  if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
8687
- if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) if (ch === 36) {
8688
- this.pos += 2;
8689
- return this.finishToken(types$1.dollarBraceL);
8690
- } else {
8691
- ++this.pos;
8692
- return this.finishToken(types$1.backQuote);
8728
+ if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) {
8729
+ if (ch === 36) {
8730
+ this.pos += 2;
8731
+ return this.finishToken(types$1.dollarBraceL);
8732
+ } else {
8733
+ ++this.pos;
8734
+ return this.finishToken(types$1.backQuote);
8735
+ }
8693
8736
  }
8694
8737
  out += this.input.slice(chunkStart, this.pos);
8695
8738
  return this.finishToken(types$1.template, out);
@@ -8706,9 +8749,7 @@ pp.readTmplToken = function() {
8706
8749
  case 10:
8707
8750
  out += "\n";
8708
8751
  break;
8709
- default:
8710
- out += String.fromCharCode(ch);
8711
- break;
8752
+ default: out += String.fromCharCode(ch);
8712
8753
  }
8713
8754
  if (this.options.locations) {
8714
8755
  ++this.curLine;
@@ -8731,7 +8772,6 @@ pp.readInvalidTemplateToken = function() {
8731
8772
  case "\u2029":
8732
8773
  ++this.curLine;
8733
8774
  this.lineStart = this.pos + 1;
8734
- break;
8735
8775
  }
8736
8776
  this.raise(this.start, "Unterminated template");
8737
8777
  };
@@ -8890,7 +8930,7 @@ function notABody(src, pos) {
8890
8930
  return NOT_A_BODY_RE.test(src);
8891
8931
  }
8892
8932
  /** Tokens that may end an operand, and so a statement before a line break. */
8893
- var OPERAND_ENDS = new Set([
8933
+ var OPERAND_ENDS = /* @__PURE__ */ new Set([
8894
8934
  types$1.name,
8895
8935
  types$1.num,
8896
8936
  types$1.string,
@@ -9016,13 +9056,13 @@ function transientAssignment(p, end) {
9016
9056
  return false;
9017
9057
  }
9018
9058
  }
9019
- var OPENERS = new Set([
9059
+ var OPENERS = /* @__PURE__ */ new Set([
9020
9060
  types$1.parenL,
9021
9061
  types$1.bracketL,
9022
9062
  types$1.braceL,
9023
9063
  types$1.dollarBraceL
9024
9064
  ]);
9025
- var CLOSERS = new Set([
9065
+ var CLOSERS = /* @__PURE__ */ new Set([
9026
9066
  types$1.parenR,
9027
9067
  types$1.bracketR,
9028
9068
  types$1.braceR
@@ -9319,7 +9359,7 @@ var WORD_RE$1 = /[\p{ID_Continue}$.]*/uy;
9319
9359
  /** The flags after a regex literal, whatever they are. */
9320
9360
  var FLAGS_RE = /[\p{ID_Continue}$]*/uy;
9321
9361
  /** Words a string may follow with no space between (`of'x'`, `get"y"`). */
9322
- var WORDS_BEFORE_STRING = new Set([
9362
+ var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
9323
9363
  "of",
9324
9364
  "get",
9325
9365
  "set",
@@ -10058,7 +10098,7 @@ function withEntry(ns, key, value) {
10058
10098
  var EMPTY_NAMESPACE = Object.freeze(createNamespace());
10059
10099
  /** The names whose own entries differ between `a` and `b`, `a`'s first. */
10060
10100
  function changedNames(a, b) {
10061
- return [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((name) => ownValue(a, name) !== ownValue(b, name));
10101
+ return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].filter((name) => ownValue(a, name) !== ownValue(b, name));
10062
10102
  }
10063
10103
  var isCount = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0;
10064
10104
  /** The count of `name` in `counts`: its own entry, or 0. */
@@ -10149,10 +10189,10 @@ function createListeners() {
10149
10189
  //#region src/runtime-errors.ts
10150
10190
  var errors = [];
10151
10191
  var nextId = 1;
10152
- var listeners$1 = createListeners();
10192
+ var listeners$2 = createListeners();
10153
10193
  function update(next) {
10154
10194
  errors = next;
10155
- listeners$1.notify();
10195
+ listeners$2.notify();
10156
10196
  }
10157
10197
  /**
10158
10198
  * Show `error` on the page, after `context` (what failed). The same error
@@ -10188,7 +10228,7 @@ function getRuntimeErrors() {
10188
10228
  return errors;
10189
10229
  }
10190
10230
  /** Call `listener` whenever the shown errors change; returns unsubscribe. */
10191
- var subscribeRuntimeErrors = listeners$1.subscribe;
10231
+ var subscribeRuntimeErrors = listeners$2.subscribe;
10192
10232
  //#endregion
10193
10233
  //#region src/components/macros/arg-utils.ts
10194
10234
  /**
@@ -10657,7 +10697,7 @@ var OPTION_PARAMETERS = [{
10657
10697
  required: true
10658
10698
  }];
10659
10699
  /** The parameters of the built-in sub-macros that take arguments. */
10660
- var SUB_MACRO_PARAMETERS = new Map([["option", OPTION_PARAMETERS]]);
10700
+ var SUB_MACRO_PARAMETERS = /* @__PURE__ */ new Map([["option", OPTION_PARAMETERS]]);
10661
10701
  /** The parameters of the built-in sub-macro `name`, if it takes any. */
10662
10702
  function subMacroParameters(name) {
10663
10703
  return SUB_MACRO_PARAMETERS.get(name.toLowerCase());
@@ -10713,13 +10753,13 @@ function extentOf(piece) {
10713
10753
  return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
10714
10754
  }
10715
10755
  /** Macros whose whole argument text is one expression: branch conditions. */
10716
- var CONDITION_MACROS = new Set([
10756
+ var CONDITION_MACROS = /* @__PURE__ */ new Set([
10717
10757
  "if",
10718
10758
  "elseif",
10719
10759
  "case"
10720
10760
  ]);
10721
10761
  /** Block macros whose body is the name of a passage. */
10722
- var PASSAGE_BODIES = new Set(["dialog"]);
10762
+ var PASSAGE_BODIES = /* @__PURE__ */ new Set(["dialog"]);
10723
10763
  /**
10724
10764
  * `params` with each `string` and `text` parameter (options too) saying
10725
10765
  * what it holds: what it declares, else `holds`.
@@ -10801,19 +10841,13 @@ function* codeAndText(src, tokens, parametersOf) {
10801
10841
  yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
10802
10842
  continue;
10803
10843
  }
10804
- let from = 0;
10805
- for (const part of splitSigilTemplate(value)) {
10806
- if (!("expr" in part)) continue;
10807
- const k = locate(value, part.expr, from);
10808
- from = k + part.expr.length;
10809
- yield {
10810
- kind: "code",
10811
- code: part.expr,
10812
- offset: at + k,
10813
- goal: "expression",
10814
- label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10815
- };
10816
- }
10844
+ for (const { expr, at: k } of sigilExpressions(value)) yield {
10845
+ kind: "code",
10846
+ code: expr,
10847
+ offset: at + k,
10848
+ goal: "expression",
10849
+ label: `{${expr}} in the ${name} attribute of <${token.tag}>`
10850
+ };
10817
10851
  }
10818
10852
  else if (token.type === "macro" && !token.isClose) {
10819
10853
  const name = token.name.toLowerCase();
@@ -11081,6 +11115,24 @@ function attributeValues(src, token) {
11081
11115
  return values;
11082
11116
  }
11083
11117
  /**
11118
+ * The `{$…}` expressions in the value of a code attribute (`onclick`, see
11119
+ * isCodeAttribute), with where each is in the value.
11120
+ */
11121
+ function sigilExpressions(value) {
11122
+ const found = [];
11123
+ let from = 0;
11124
+ for (const part of splitSigilTemplate(value)) {
11125
+ if (!("expr" in part)) continue;
11126
+ const at = locate(value, part.expr, from);
11127
+ from = at + part.expr.length;
11128
+ found.push({
11129
+ expr: part.expr,
11130
+ at
11131
+ });
11132
+ }
11133
+ return found;
11134
+ }
11135
+ /**
11084
11136
  * Index of `part` in `text` from `from` on, else anywhere, else `from`: the
11085
11137
  * place to report an error in `part` at.
11086
11138
  */
@@ -11296,37 +11348,71 @@ function widgetDef({ name = "", parameters = "" }) {
11296
11348
  function parseWidgetDef(rawArgs) {
11297
11349
  return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
11298
11350
  }
11351
+ /** Where the name is written in the arguments, without its quotes. */
11352
+ function nameSpan(rawArgs) {
11353
+ const spans = /* @__PURE__ */ new Map();
11354
+ parseMacroArgs(rawArgs, WIDGET_PARAMETERS, spans);
11355
+ const [start, end] = spans.get(WIDGET_PARAMETERS[0]) ?? [0, 0];
11356
+ const quote = rawArgs[start];
11357
+ return (quote === "\"" || quote === "'") && end - start >= 2 ? [start + 1, rawArgs[end - 1] === quote ? end - 1 : end] : [start, end];
11358
+ }
11299
11359
  /**
11300
- * The names of the block widgets (those whose body renders `{@children}`)
11301
- * that StoryInit and the passages tagged `widget` define. They must be
11302
- * known as block macros before any passage is parsed, so that passages
11303
- * invoking them nest their content whatever the passage order.
11360
+ * The widgets that StoryInit and the passages tagged `widget` define, in
11361
+ * source order: the ones the runtime registers, read tolerantly (a half-typed
11362
+ * definition is still reported, without a `closeStart`). Definitions whose
11363
+ * arguments cannot be read are left out.
11304
11364
  *
11305
11365
  * The passages are read as flat tokens, which need no block macros to be
11306
11366
  * known, so a `{@children}` in an HTML comment or in a `{do}` body is text
11307
- * here as it is to the parser, and does not make a block widget (#387).
11367
+ * here as it is to the parser, and does not make a block widget (#387). In
11368
+ * nested definitions, it belongs to the innermost.
11308
11369
  */
11309
- function blockWidgetNames(passages, parametersOf = registeredParameters) {
11310
- const names = [];
11370
+ function widgetDefinitions(passages, parametersOf = registeredParameters) {
11371
+ const found = [];
11311
11372
  for (const passage of passages) {
11312
11373
  if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
11313
11374
  const open = [];
11375
+ const done = [];
11314
11376
  for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
11315
- if (!token.isClose) {
11316
- open.push({
11317
- rawArgs: token.rawArgs,
11318
- isBlock: false
11377
+ if (!token.isClose) open.push({
11378
+ token,
11379
+ isBlock: false
11380
+ });
11381
+ else {
11382
+ const def = open.pop();
11383
+ if (def) done.push({
11384
+ ...def,
11385
+ closeStart: token.start
11319
11386
  });
11320
- continue;
11321
11387
  }
11322
- const def = open.pop();
11323
- if (!def?.isBlock) continue;
11324
- try {
11325
- names.push(parseWidgetDef(def.rawArgs).name);
11326
- } catch {}
11327
11388
  } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
11389
+ done.push(...open);
11390
+ const defs = [];
11391
+ for (const { token, isBlock, closeStart } of done) try {
11392
+ const [from, to] = nameSpan(token.rawArgs);
11393
+ defs.push({
11394
+ ...parseWidgetDef(token.rawArgs),
11395
+ block: isBlock,
11396
+ passage: passage.name,
11397
+ start: token.start,
11398
+ end: token.end,
11399
+ nameStart: token.argsStart + from,
11400
+ nameEnd: token.argsStart + to,
11401
+ ...closeStart === void 0 ? {} : { closeStart }
11402
+ });
11403
+ } catch {}
11404
+ found.push(...defs.sort((a, b) => a.start - b.start));
11328
11405
  }
11329
- return names;
11406
+ return found;
11407
+ }
11408
+ /**
11409
+ * The names of the block widgets (those whose body renders `{@children}`)
11410
+ * that StoryInit and the passages tagged `widget` define, closed. They must
11411
+ * be known as block macros before any passage is parsed, so that passages
11412
+ * invoking them nest their content whatever the passage order.
11413
+ */
11414
+ function blockWidgetNames(passages, parametersOf = registeredParameters) {
11415
+ return widgetDefinitions(passages, parametersOf).filter((def) => def.block && def.closeStart !== void 0).map((def) => def.name);
11330
11416
  }
11331
11417
  //#endregion
11332
11418
  //#region src/widgets/register-widget-def.ts
@@ -11381,7 +11467,7 @@ var OutgoingContext = createContext(null);
11381
11467
  * while the fields don't change, as the store's snapshot must.
11382
11468
  */
11383
11469
  function useStoryFields(...keys) {
11384
- const prev = useRef();
11470
+ const prev = useRef(void 0);
11385
11471
  const freeze = useContext(FrozenStateContext);
11386
11472
  return useStoryStore((s) => {
11387
11473
  if (prev.current && freeze?.(s)) return prev.current;
@@ -12340,7 +12426,7 @@ function unclosedHtml(text) {
12340
12426
  }
12341
12427
  }
12342
12428
  }
12343
- const construct = {
12429
+ return { text: { 60: {
12344
12430
  name: "unclosedHtml",
12345
12431
  resolveTo: joinData,
12346
12432
  tokenize(effects, ok, nok) {
@@ -12353,8 +12439,7 @@ function unclosedHtml(text) {
12353
12439
  return ok;
12354
12440
  };
12355
12441
  }
12356
- };
12357
- return { text: { 60: construct } };
12442
+ } } };
12358
12443
  }
12359
12444
  //#endregion
12360
12445
  //#region src/utils/source-location.ts
@@ -12397,7 +12482,7 @@ function logMacroError(label, error, location = currentSourceLocation()) {
12397
12482
  * from then on; otherwise the macro renders nothing.
12398
12483
  */
12399
12484
  function useRunOnce(macro, rawArgs, effect) {
12400
- const failure = useRef();
12485
+ const failure = useRef(void 0);
12401
12486
  if (failure.current === void 0) {
12402
12487
  failure.current = null;
12403
12488
  const location = currentSourceLocation();
@@ -12471,7 +12556,7 @@ var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
12471
12556
  * paragraphs between them would pull the children out of the structure (#423).
12472
12557
  * Text between the children, when it is only whitespace, is dropped.
12473
12558
  */
12474
- var STRUCTURAL_ELEMENTS = new Set([
12559
+ var STRUCTURAL_ELEMENTS = /* @__PURE__ */ new Set([
12475
12560
  "table",
12476
12561
  "thead",
12477
12562
  "tbody",
@@ -12487,7 +12572,7 @@ var STRUCTURAL_ELEMENTS = new Set([
12487
12572
  "datalist"
12488
12573
  ]);
12489
12574
  /** Elements whose content is literal text, not markdown. */
12490
- var PREFORMATTED_ELEMENTS = new Set([
12575
+ var PREFORMATTED_ELEMENTS = /* @__PURE__ */ new Set([
12491
12576
  "pre",
12492
12577
  "textarea",
12493
12578
  "style"
@@ -12613,7 +12698,8 @@ function htmlToPreact(html, ph, unwrapParagraphs = false) {
12613
12698
  if (unwrapParagraphs) {
12614
12699
  for (const child of Array.from(content.childNodes)) if (child.nodeType === Node.ELEMENT_NODE && child.nodeName === "P") child.replaceWith(...Array.from(child.childNodes));
12615
12700
  }
12616
- return /* @__PURE__ */ jsx(Fragment$1, { children: Array.from(content.childNodes).map((child, i) => convertDomNode(child, i, ph)) });
12701
+ const children = Array.from(content.childNodes).map((child, i) => convertDomNode(child, i, ph));
12702
+ return /* @__PURE__ */ jsx(Fragment$1, { children });
12617
12703
  }
12618
12704
  function convertDomNode(node, key, ph) {
12619
12705
  if (node.nodeType === Node.TEXT_NODE) {
@@ -12671,7 +12757,7 @@ function convertDomNode(node, key, ph) {
12671
12757
  * (lists, headings, paragraphs) is invalid in them: inline elements, and
12672
12758
  * block elements such as headings and buttons that only take inline children.
12673
12759
  */
12674
- var INLINE_ELEMENTS = new Set([
12760
+ var INLINE_ELEMENTS = /* @__PURE__ */ new Set([
12675
12761
  "a",
12676
12762
  "abbr",
12677
12763
  "b",
@@ -12724,7 +12810,7 @@ var INLINE_ELEMENTS = new Set([
12724
12810
  * as `=""` are passed as `true`, since '' is falsy (#177); one that only
12725
12811
  * resolves to '' through an interpolation stays ''.
12726
12812
  */
12727
- var LIVE_PROPERTIES = new Set([
12813
+ var LIVE_PROPERTIES = /* @__PURE__ */ new Set([
12728
12814
  "value",
12729
12815
  "checked",
12730
12816
  "selected",
@@ -12736,7 +12822,7 @@ var LIVE_PROPERTIES = new Set([
12736
12822
  * (`disabled="{$locked ? 'disabled' : ''}"`) is left out, so a variable can
12737
12823
  * switch it off.
12738
12824
  */
12739
- var BOOLEAN_ATTRIBUTES = new Set([
12825
+ var BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
12740
12826
  "allowfullscreen",
12741
12827
  "async",
12742
12828
  "autofocus",
@@ -12764,8 +12850,8 @@ var BOOLEAN_ATTRIBUTES = new Set([
12764
12850
  "selected"
12765
12851
  ]);
12766
12852
  /** Names set directly on SVG elements (see splitAttributes). */
12767
- var SVG_DIRECT = new Set([
12768
- ...new Set([
12853
+ var SVG_DIRECT = /* @__PURE__ */ new Set([
12854
+ .../* @__PURE__ */ new Set([
12769
12855
  "key",
12770
12856
  "ref",
12771
12857
  "children",
@@ -12831,6 +12917,7 @@ function splitAttributes(attributes, svg) {
12831
12917
  */
12832
12918
  function useDirectAttributes(direct) {
12833
12919
  const elementRef = useRef(null);
12920
+ const directKey = JSON.stringify(direct);
12834
12921
  useLayoutEffect(() => {
12835
12922
  const el = elementRef.current;
12836
12923
  if (!el || direct.length === 0) return;
@@ -12838,7 +12925,7 @@ function useDirectAttributes(direct) {
12838
12925
  return () => {
12839
12926
  for (const [name] of direct) el.removeAttribute(name);
12840
12927
  };
12841
- }, [JSON.stringify(direct)]);
12928
+ }, [directKey]);
12842
12929
  return direct.length > 0 ? elementRef : void 0;
12843
12930
  }
12844
12931
  var decodedText = /* @__PURE__ */ new Map();
@@ -12915,9 +13002,13 @@ function resolveAttributeValue(name, value, scope, errors) {
12915
13002
  for (const error of result.errors) errors.push([name, error]);
12916
13003
  return result.text;
12917
13004
  }
13005
+ /** Whether a node shows nothing as text: whitespace, or a closed HTML comment. */
13006
+ function isBlankText(n) {
13007
+ return n.type === "text" && (n.comment === true || n.value.trim() === "");
13008
+ }
12918
13009
  /** The index of the summary element opening `nodes`, or -1 when none does. */
12919
13010
  function leadingSummaryIndex(nodes) {
12920
- const at = nodes.findIndex((n) => n.type !== "text" || n.value.trim() !== "");
13011
+ const at = nodes.findIndex((n) => !isBlankText(n));
12921
13012
  const first = nodes[at];
12922
13013
  return first?.type === "html" && first.tag.toLowerCase() === "summary" ? at : -1;
12923
13014
  }
@@ -12939,28 +13030,31 @@ function HtmlNodeRenderer({ node }) {
12939
13030
  const isInline = INLINE_ELEMENTS.has(tag);
12940
13031
  let children = void 0;
12941
13032
  let structural = false;
12942
- if (node.children.length > 0) if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
12943
- else {
12944
- const summaryAt = tag === "details" ? leadingSummaryIndex(node.children) : -1;
12945
- const body = (nodes) => renderNodes(nodes, {
12946
- nobr,
12947
- locals,
12948
- inline: isInline
12949
- });
12950
- structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || n.value.trim() === "");
12951
- children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
12952
- body(node.children.slice(0, summaryAt)),
12953
- renderSingleNode(node.children[summaryAt]),
12954
- body(node.children.slice(summaryAt + 1))
12955
- ] });
12956
- if (isInline !== parentInline) children = /* @__PURE__ */ jsx(InlineContext.Provider, {
12957
- value: isInline,
12958
- children
12959
- });
12960
- if (structural !== parentStructural) children = /* @__PURE__ */ jsx(StructuralContext.Provider, {
12961
- value: structural,
12962
- children
12963
- });
13033
+ if (node.children.length > 0) {
13034
+ if (tag === "style") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
13035
+ else if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
13036
+ else {
13037
+ const summaryAt = tag === "details" ? leadingSummaryIndex(node.children) : -1;
13038
+ const body = (nodes) => renderNodes(nodes, {
13039
+ nobr,
13040
+ locals,
13041
+ inline: isInline
13042
+ });
13043
+ structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || isBlankText(n));
13044
+ children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
13045
+ body(node.children.slice(0, summaryAt)),
13046
+ renderSingleNode(node.children[summaryAt]),
13047
+ body(node.children.slice(summaryAt + 1))
13048
+ ] });
13049
+ if (isInline !== parentInline) children = /* @__PURE__ */ jsx(InlineContext.Provider, {
13050
+ value: isInline,
13051
+ children
13052
+ });
13053
+ if (structural !== parentStructural) children = /* @__PURE__ */ jsx(StructuralContext.Provider, {
13054
+ value: structural,
13055
+ children
13056
+ });
13057
+ }
12964
13058
  }
12965
13059
  if (inSvg && tag === "foreignobject" && children) children = /* @__PURE__ */ jsx(SvgContext.Provider, {
12966
13060
  value: false,
@@ -13120,7 +13214,7 @@ function buildPlainTextVnodes(core, ph, unwrapParagraphs) {
13120
13214
  function renderNodes(nodes, options) {
13121
13215
  if (nodes.length === 0) return null;
13122
13216
  if (options?.raw) return renderInlineNodes(nodes);
13123
- if (options?.structural && nodes.every((n) => n.type !== "text" || n.value.trim() === "")) return nodes.filter((n) => n.type !== "text").map(renderSingleNode);
13217
+ if (options?.structural && nodes.every((n) => n.type !== "text" || isBlankText(n))) return nodes.filter((n) => n.type !== "text").map(renderSingleNode);
13124
13218
  if (!nodes.some((n) => n.type === "text" && (n.value.trim() !== "" || BLANK_LINE_RE.test(n.value)))) return nodes.map((node) => renderSingleNode(node));
13125
13219
  const components = [];
13126
13220
  const ph = {
@@ -13526,120 +13620,121 @@ function unflatten(parsed, revivers, options) {
13526
13620
  if (index >= values.length) invalid$1();
13527
13621
  const value = values[index];
13528
13622
  if (!value || typeof value !== "object") hydrated[index] = ops.fromPrimitive(value);
13529
- else if (Array.isArray(value)) if (typeof value[0] === "string") {
13530
- const type = value[0];
13531
- const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
13532
- if (reviver) {
13533
- let i = value[1];
13534
- if (typeof i !== "number") i = values.push(value[1]) - 1;
13535
- if (Object.hasOwn(hydrated, i)) return hydrated[index] = reviver(hydrated[i]);
13536
- hydrating ??= /* @__PURE__ */ new Set();
13537
- if (hydrating.has(i)) throw new Error("Invalid circular reference");
13538
- hydrating.add(i);
13539
- hydrated[index] = reviver(hydrate(i));
13540
- hydrating.delete(i);
13541
- return hydrated[index];
13542
- }
13543
- switch (type) {
13544
- case "Date":
13545
- hydrated[index] = ops.fromISOString(value[1]);
13546
- break;
13547
- case "Set":
13548
- const set = ops.createSet();
13549
- hydrated[index] = set;
13550
- for (let i = 1; i < value.length; i += 1) ops.addValue(set, hydrate(value[i]));
13551
- break;
13552
- case "Map":
13553
- const map = ops.createMap();
13554
- hydrated[index] = map;
13555
- for (let i = 1; i < value.length; i += 2) ops.addEntry(map, hydrate(value[i]), hydrate(value[i + 1]));
13556
- break;
13557
- case "RegExp":
13558
- hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
13559
- break;
13560
- case "Object": {
13561
- const wrapped_index = value[1];
13562
- if (!(wrapped_index === -3 || wrapped_index === -4 || wrapped_index === -5 || wrapped_index === -6)) {
13563
- const wrapped = get_raw(wrapped_index);
13564
- const is_bigint = Array.isArray(wrapped) && wrapped[0] === "BigInt";
13565
- if ((wrapped === void 0 || typeof wrapped === "object") && !is_bigint) invalid$1();
13566
- }
13567
- hydrated[index] = ops.box(hydrate(wrapped_index));
13568
- break;
13623
+ else if (Array.isArray(value)) {
13624
+ if (typeof value[0] === "string") {
13625
+ const type = value[0];
13626
+ const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
13627
+ if (reviver) {
13628
+ let i = value[1];
13629
+ if (typeof i !== "number") i = values.push(value[1]) - 1;
13630
+ if (Object.hasOwn(hydrated, i)) return hydrated[index] = reviver(hydrated[i]);
13631
+ hydrating ??= /* @__PURE__ */ new Set();
13632
+ if (hydrating.has(i)) throw new Error("Invalid circular reference");
13633
+ hydrating.add(i);
13634
+ hydrated[index] = reviver(hydrate(i));
13635
+ hydrating.delete(i);
13636
+ return hydrated[index];
13569
13637
  }
13570
- case "BigInt":
13571
- hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
13572
- break;
13573
- case "null":
13574
- const obj = ops.createNullPrototypeObject();
13575
- hydrated[index] = obj;
13576
- for (let i = 1; i < value.length; i += 2) {
13577
- const key = value[i];
13578
- if (typeof key !== "string") throw new Error("Cannot parse an object with a non-string key");
13579
- if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
13580
- ops.set(obj, key, hydrate(value[i + 1]));
13638
+ switch (type) {
13639
+ case "Date":
13640
+ hydrated[index] = ops.fromISOString(value[1]);
13641
+ break;
13642
+ case "Set":
13643
+ const set = ops.createSet();
13644
+ hydrated[index] = set;
13645
+ for (let i = 1; i < value.length; i += 1) ops.addValue(set, hydrate(value[i]));
13646
+ break;
13647
+ case "Map":
13648
+ const map = ops.createMap();
13649
+ hydrated[index] = map;
13650
+ for (let i = 1; i < value.length; i += 2) ops.addEntry(map, hydrate(value[i]), hydrate(value[i + 1]));
13651
+ break;
13652
+ case "RegExp":
13653
+ hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
13654
+ break;
13655
+ case "Object": {
13656
+ const wrapped_index = value[1];
13657
+ if (!(wrapped_index === -3 || wrapped_index === -4 || wrapped_index === -5 || wrapped_index === -6)) {
13658
+ const wrapped = get_raw(wrapped_index);
13659
+ const is_bigint = Array.isArray(wrapped) && wrapped[0] === "BigInt";
13660
+ if ((wrapped === void 0 || typeof wrapped === "object") && !is_bigint) invalid$1();
13661
+ }
13662
+ hydrated[index] = ops.box(hydrate(wrapped_index));
13663
+ break;
13581
13664
  }
13582
- break;
13583
- case "Int8Array":
13584
- case "Uint8Array":
13585
- case "Uint8ClampedArray":
13586
- case "Int16Array":
13587
- case "Uint16Array":
13588
- case "Float16Array":
13589
- case "Int32Array":
13590
- case "Uint32Array":
13591
- case "Float32Array":
13592
- case "Float64Array":
13593
- case "BigInt64Array":
13594
- case "BigUint64Array":
13595
- case "DataView": {
13596
- const buffer_index = value[1];
13597
- const raw = get_raw(buffer_index);
13598
- if (!Array.isArray(raw) || raw[0] !== "ArrayBuffer") invalid$1();
13599
- const buffer = hydrate(buffer_index);
13600
- hydrated[index] = ops.fromViewInfo(type, buffer, value[2], value[3]);
13601
- break;
13665
+ case "BigInt":
13666
+ hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
13667
+ break;
13668
+ case "null":
13669
+ const obj = ops.createNullPrototypeObject();
13670
+ hydrated[index] = obj;
13671
+ for (let i = 1; i < value.length; i += 2) {
13672
+ const key = value[i];
13673
+ if (typeof key !== "string") throw new Error("Cannot parse an object with a non-string key");
13674
+ if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
13675
+ ops.set(obj, key, hydrate(value[i + 1]));
13676
+ }
13677
+ break;
13678
+ case "Int8Array":
13679
+ case "Uint8Array":
13680
+ case "Uint8ClampedArray":
13681
+ case "Int16Array":
13682
+ case "Uint16Array":
13683
+ case "Float16Array":
13684
+ case "Int32Array":
13685
+ case "Uint32Array":
13686
+ case "Float32Array":
13687
+ case "Float64Array":
13688
+ case "BigInt64Array":
13689
+ case "BigUint64Array":
13690
+ case "DataView": {
13691
+ const buffer_index = value[1];
13692
+ const raw = get_raw(buffer_index);
13693
+ if (!Array.isArray(raw) || raw[0] !== "ArrayBuffer") invalid$1();
13694
+ const buffer = hydrate(buffer_index);
13695
+ hydrated[index] = ops.fromViewInfo(type, buffer, value[2], value[3]);
13696
+ break;
13697
+ }
13698
+ case "ArrayBuffer": {
13699
+ const base64 = value[1];
13700
+ if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
13701
+ hydrated[index] = ops.fromArrayBuffer(decode64(base64));
13702
+ break;
13703
+ }
13704
+ case "URL":
13705
+ case "URLSearchParams":
13706
+ case "Temporal.Duration":
13707
+ case "Temporal.Instant":
13708
+ case "Temporal.PlainDate":
13709
+ case "Temporal.PlainTime":
13710
+ case "Temporal.PlainDateTime":
13711
+ case "Temporal.PlainMonthDay":
13712
+ case "Temporal.PlainYearMonth":
13713
+ case "Temporal.ZonedDateTime":
13714
+ hydrated[index] = ops.fromStringValue(type, value[1]);
13715
+ break;
13716
+ default: throw new Error(`Unknown type ${type}`);
13602
13717
  }
13603
- case "ArrayBuffer": {
13604
- const base64 = value[1];
13605
- if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
13606
- hydrated[index] = ops.fromArrayBuffer(decode64(base64));
13607
- break;
13718
+ } else if (value[0] === -7) {
13719
+ const len = value[1];
13720
+ if (!is_valid_array_len(len)) invalid$1();
13721
+ const array = ops.createSparseArray(len);
13722
+ hydrated[index] = array;
13723
+ for (let i = 2; i < value.length; i += 2) {
13724
+ const idx = value[i];
13725
+ if (!is_valid_array_index(idx) || idx >= len) invalid$1();
13726
+ ops.set(array, idx, hydrate(value[i + 1]));
13727
+ }
13728
+ } else {
13729
+ const array = ops.createArray(value.length);
13730
+ hydrated[index] = array;
13731
+ for (let i = 0; i < value.length; i += 1) {
13732
+ const n = value[i];
13733
+ if (n === -2) continue;
13734
+ ops.set(array, i, hydrate(n));
13608
13735
  }
13609
- case "URL":
13610
- case "URLSearchParams":
13611
- case "Temporal.Duration":
13612
- case "Temporal.Instant":
13613
- case "Temporal.PlainDate":
13614
- case "Temporal.PlainTime":
13615
- case "Temporal.PlainDateTime":
13616
- case "Temporal.PlainMonthDay":
13617
- case "Temporal.PlainYearMonth":
13618
- case "Temporal.ZonedDateTime":
13619
- hydrated[index] = ops.fromStringValue(type, value[1]);
13620
- break;
13621
- default: throw new Error(`Unknown type ${type}`);
13622
- }
13623
- } else if (value[0] === -7) {
13624
- const len = value[1];
13625
- if (!is_valid_array_len(len)) invalid$1();
13626
- const array = ops.createSparseArray(len);
13627
- hydrated[index] = array;
13628
- for (let i = 2; i < value.length; i += 2) {
13629
- const idx = value[i];
13630
- if (!is_valid_array_index(idx) || idx >= len) invalid$1();
13631
- ops.set(array, idx, hydrate(value[i + 1]));
13632
13736
  }
13633
13737
  } else {
13634
- const array = ops.createArray(value.length);
13635
- hydrated[index] = array;
13636
- for (let i = 0; i < value.length; i += 1) {
13637
- const n = value[i];
13638
- if (n === -2) continue;
13639
- ops.set(array, i, hydrate(n));
13640
- }
13641
- }
13642
- else {
13643
13738
  const object = ops.createObject();
13644
13739
  hydrated[index] = object;
13645
13740
  for (const key of Object.keys(value)) {
@@ -14477,7 +14572,7 @@ function decodeQuietly(encoded) {
14477
14572
  */
14478
14573
  function checkSaveExport(value) {
14479
14574
  if (!isRecord(value)) throw new Error(INVALID_FILE);
14480
- if (!hasOwn(value, "formatVersion")) throw value.version === 1 ? new IncompatibleSaveError() : new Error(INVALID_FILE);
14575
+ if (!hasOwn(value, "formatVersion")) throw value.version === 1 ? new IncompatibleSaveError() : /* @__PURE__ */ new Error(INVALID_FILE);
14481
14576
  checkFormatVersion(value.formatVersion);
14482
14577
  if (typeof value.ifid !== "string") throw new Error(INVALID_FILE);
14483
14578
  const save = value.save;
@@ -15119,7 +15214,7 @@ function loosePairs() {
15119
15214
  const pairs = assumed.get(a);
15120
15215
  if (pairs?.has(b)) return true;
15121
15216
  if (pairs) pairs.add(b);
15122
- else assumed.set(a, new Set([b]));
15217
+ else assumed.set(a, /* @__PURE__ */ new Set([b]));
15123
15218
  };
15124
15219
  }
15125
15220
  /**
@@ -15252,7 +15347,7 @@ function equalKeys(a, b, assumed, keysOf = Object.keys) {
15252
15347
  return true;
15253
15348
  }
15254
15349
  /** Built-in prototypes (see builtinLike), whose instances hold no extra keys. */
15255
- var BUILTIN_PROTOS = new Set([
15350
+ var BUILTIN_PROTOS = /* @__PURE__ */ new Set([
15256
15351
  Array.prototype,
15257
15352
  Map.prototype,
15258
15353
  Set.prototype,
@@ -15712,7 +15807,7 @@ function applyChange(target, change) {
15712
15807
  }
15713
15808
  //#endregion
15714
15809
  //#region src/event-emitter.ts
15715
- var VALID_EVENTS = new Set([
15810
+ var VALID_EVENTS = /* @__PURE__ */ new Set([
15716
15811
  "storyinit",
15717
15812
  "beforerestart",
15718
15813
  "actionsChanged",
@@ -15726,13 +15821,13 @@ var VALID_EVENTS = new Set([
15726
15821
  "passagerender",
15727
15822
  "dialogrender"
15728
15823
  ]);
15729
- var listeners = /* @__PURE__ */ new Map();
15824
+ var listeners$1 = /* @__PURE__ */ new Map();
15730
15825
  function on(event, cb) {
15731
15826
  if (!VALID_EVENTS.has(event)) throw new Error(`spindle: Unknown event "${event}".`);
15732
- let set = listeners.get(event);
15827
+ let set = listeners$1.get(event);
15733
15828
  if (!set) {
15734
15829
  set = /* @__PURE__ */ new Set();
15735
- listeners.set(event, set);
15830
+ listeners$1.set(event, set);
15736
15831
  }
15737
15832
  set.add(cb);
15738
15833
  return () => {
@@ -15741,7 +15836,7 @@ function on(event, cb) {
15741
15836
  }
15742
15837
  /** Call `call` with each listener of `event`. */
15743
15838
  function forEachListener(event, call) {
15744
- const set = listeners.get(event);
15839
+ const set = listeners$1.get(event);
15745
15840
  if (!set) return;
15746
15841
  for (const cb of [...set]) call(cb);
15747
15842
  }
@@ -16262,7 +16357,6 @@ function quickSave$1(ifid, playthroughId, payload, slot, custom) {
16262
16357
  return record;
16263
16358
  });
16264
16359
  }
16265
- queued(hasQuickSaveNow);
16266
16360
  async function hasQuickSaveNow(ifid, slot) {
16267
16361
  return await slotRecord(ifid, slot) !== void 0;
16268
16362
  }
@@ -16747,7 +16841,7 @@ function changeTo(ns, path) {
16747
16841
  * replaces exactly what it replaced in program order.
16748
16842
  */
16749
16843
  function writtenPaths(before, after, patches) {
16750
- if (patches.some((p) => p.path.length === 1)) return [...new Set([...Object.keys(before), ...Object.keys(after)])].filter((root) => !hasOwn(before, root) || before[root] !== after[root]).map((root) => changeTo(after, [root]));
16844
+ if (patches.some((p) => p.path.length === 1)) return [.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])].filter((root) => !hasOwn(before, root) || before[root] !== after[root]).map((root) => changeTo(after, [root]));
16751
16845
  const seen = /* @__PURE__ */ new Set();
16752
16846
  const changes = [];
16753
16847
  for (const patch of patches) {
@@ -17329,7 +17423,7 @@ function isDialogShowing() {
17329
17423
  //#region src/store.ts
17330
17424
  enablePatches();
17331
17425
  enableMapSet();
17332
- var SPECIAL_PASSAGES = new Set([
17426
+ var SPECIAL_PASSAGES = /* @__PURE__ */ new Set([
17333
17427
  "StoryInit",
17334
17428
  "StoryInterface",
17335
17429
  "StoryVariables",
@@ -17460,12 +17554,14 @@ function persistSession(get) {
17460
17554
  const { storyData, currentPassage, variables, history, historyIndex, visitCounts, renderCounts } = get();
17461
17555
  if (!storyData) return void 0;
17462
17556
  if (sessionMoments.length > history.length) sessionMoments.length = history.length;
17463
- if (sessionMoments.length < history.length) if (history.length - sessionMoments.length === 1) {
17464
- const i = history.length - 1;
17465
- sessionMoments[i] = savedMoment(history[i], variables);
17466
- } else forEachRecorded(history.length, (vars, i) => {
17467
- if (i >= sessionMoments.length) sessionMoments[i] = savedMoment(history[i], vars);
17468
- });
17557
+ if (sessionMoments.length < history.length) {
17558
+ if (history.length - sessionMoments.length === 1) {
17559
+ const i = history.length - 1;
17560
+ sessionMoments[i] = savedMoment(history[i], variables);
17561
+ } else forEachRecorded(history.length, (vars, i) => {
17562
+ if (i >= sessionMoments.length) sessionMoments[i] = savedMoment(history[i], vars);
17563
+ });
17564
+ }
17469
17565
  return saveSession(storyData.ifid, {
17470
17566
  passage: currentPassage,
17471
17567
  variables,
@@ -17883,9 +17979,10 @@ function writeKey(holder, key, value, change) {
17883
17979
  const deleted = change?.deleted ?? false;
17884
17980
  if (Array.isArray(holder)) {
17885
17981
  const index = Number(key);
17886
- if (deleted) if (change && "hole" in change) delete holder[index];
17887
- else holder.length = Math.min(holder.length, index);
17888
- else if (change && "appended" in change) {
17982
+ if (deleted) {
17983
+ if (change && "hole" in change) delete holder[index];
17984
+ else holder.length = Math.min(holder.length, index);
17985
+ } else if (change && "appended" in change) {
17889
17986
  holder.length += change.gap ?? 0;
17890
17987
  holder.push(value);
17891
17988
  } else if (key === "length" && change) holder.length += value;
@@ -18454,7 +18551,8 @@ function StoryInterface() {
18454
18551
  const nobr = overridePassage?.tags.includes("nobr") ?? false;
18455
18552
  const rendered = useMemo(() => {
18456
18553
  try {
18457
- return /* @__PURE__ */ jsx(Fragment$1, { children: renderInlineNodes(parseMarkup(markup)) });
18554
+ const ast = parseMarkup(markup);
18555
+ return /* @__PURE__ */ jsx(Fragment$1, { children: renderInlineNodes(ast) });
18458
18556
  } catch (err) {
18459
18557
  return /* @__PURE__ */ jsxs("span", {
18460
18558
  class: "error",
@@ -18562,6 +18660,24 @@ var openModals = [];
18562
18660
  * - closes the topmost dialog on Escape when it is dismissible;
18563
18661
  * - returns focus to the previously focused element on close.
18564
18662
  */
18663
+ /** The input types made of several segments, each a native Tab stop. */
18664
+ var SEGMENTED_INPUTS = /* @__PURE__ */ new Set([
18665
+ "date",
18666
+ "time",
18667
+ "datetime-local",
18668
+ "month",
18669
+ "week"
18670
+ ]);
18671
+ /** Whether the element has native tab stops inside it, in its shadow tree. */
18672
+ function hasNativeStops(el) {
18673
+ if (el instanceof HTMLMediaElement) return el.controls;
18674
+ return el instanceof HTMLInputElement && SEGMENTED_INPUTS.has(el.type) && !el.readOnly;
18675
+ }
18676
+ /** The tab stops of an embedded document, in tab order. */
18677
+ function frameStops(doc) {
18678
+ if (!doc) return [];
18679
+ return Array.from(doc.querySelectorAll(FOCUSABLE)).filter((el) => isAvailable(el) && isTabStop(el));
18680
+ }
18565
18681
  function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18566
18682
  useLayoutEffect(() => {
18567
18683
  const panel = panelRef.current;
@@ -18589,6 +18705,21 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18589
18705
  * (#424). `from` may be an element of an embedded document, whose frame
18590
18706
  * element then stands in for it.
18591
18707
  */
18708
+ /** Focus `el`; a frame is entered at its first (or last) control (#460). */
18709
+ const enter = (el, backwards) => {
18710
+ if (el instanceof HTMLIFrameElement) {
18711
+ let inner = [];
18712
+ try {
18713
+ inner = frameStops(el.contentDocument);
18714
+ } catch {}
18715
+ const edge = backwards ? inner[inner.length - 1] : inner[0];
18716
+ if (edge) {
18717
+ edge.focus();
18718
+ return;
18719
+ }
18720
+ }
18721
+ el.focus();
18722
+ };
18592
18723
  const moveFocus = (from, backwards) => {
18593
18724
  const items = focusables(panel);
18594
18725
  const first = items[0];
@@ -18604,9 +18735,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18604
18735
  const after = (el) => !!(from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING);
18605
18736
  next = backwards ? items.filter((el) => !after(el)).pop() : items.find(after);
18606
18737
  } else next = backwards ? last : first;
18607
- (next ?? (backwards ? last : first)).focus();
18738
+ enter(next ?? (backwards ? last : first), backwards);
18608
18739
  };
18609
- let steppingMedia = null;
18740
+ let steppingNative = null;
18610
18741
  const onKeyDown = (e) => {
18611
18742
  if (!top()) return;
18612
18743
  if (e.key === "Escape") {
@@ -18618,8 +18749,8 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18618
18749
  }
18619
18750
  if (e.key !== "Tab") return;
18620
18751
  const active = document.activeElement;
18621
- if (active instanceof HTMLMediaElement && active.controls) {
18622
- steppingMedia = {
18752
+ if (hasNativeStops(active)) {
18753
+ steppingNative = {
18623
18754
  el: active,
18624
18755
  backwards: e.shiftKey
18625
18756
  };
@@ -18629,7 +18760,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18629
18760
  moveFocus(active, e.shiftKey);
18630
18761
  };
18631
18762
  const onPointerDown = () => {
18632
- steppingMedia = null;
18763
+ steppingNative = null;
18633
18764
  };
18634
18765
  const controller = new AbortController();
18635
18766
  const { signal } = controller;
@@ -18644,7 +18775,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18644
18775
  const onFrameKeyDown = (e) => {
18645
18776
  if (!top()) return;
18646
18777
  if (e.key !== "Tab") return onKeyDown(e);
18647
- const inner = Array.from(doc.querySelectorAll(FOCUSABLE)).filter((el) => isAvailable(el) && isTabStop(el));
18778
+ const inner = frameStops(doc);
18648
18779
  const active = doc.activeElement;
18649
18780
  const edge = e.shiftKey ? inner[0] : inner[inner.length - 1];
18650
18781
  if (!edge || active === edge || active === doc.body) {
@@ -18672,9 +18803,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18672
18803
  attachFrames();
18673
18804
  const onFocusIn = (e) => {
18674
18805
  const target = e.target;
18675
- if (steppingMedia && target !== steppingMedia.el && top()) {
18676
- const { el, backwards } = steppingMedia;
18677
- steppingMedia = null;
18806
+ if (steppingNative && target !== steppingNative.el && top()) {
18807
+ const { el, backwards } = steppingNative;
18808
+ steppingNative = null;
18678
18809
  moveFocus(el, backwards);
18679
18810
  return;
18680
18811
  }
@@ -18688,9 +18819,9 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18688
18819
  signal
18689
18820
  });
18690
18821
  const onFocusOut = (e) => {
18691
- const pending = steppingMedia;
18822
+ const pending = steppingNative;
18692
18823
  if (!pending || e.target !== pending.el || e.relatedTarget || !top()) return;
18693
- steppingMedia = null;
18824
+ steppingNative = null;
18694
18825
  moveFocus(pending.el, pending.backwards);
18695
18826
  };
18696
18827
  document.addEventListener("focusout", onFocusOut, { signal });
@@ -18704,7 +18835,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18704
18835
  //#endregion
18705
18836
  //#region src/components/PassageDialog.tsx
18706
18837
  var DialogCloseContext = createContext(null);
18707
- function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismissible = true, showCloseButton = dismissible }) {
18838
+ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, label, dismissible = true, showCloseButton = dismissible }) {
18708
18839
  const onCloseRef = useRef(onClose);
18709
18840
  onCloseRef.current = onClose;
18710
18841
  const stableOnClose = useCallback(() => onCloseRef.current(), []);
@@ -18731,9 +18862,19 @@ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismi
18731
18862
  }
18732
18863
  }, [markup, nobr]);
18733
18864
  const panelRef = useRef(null);
18865
+ const labelId = useId();
18734
18866
  const viewScope = useViewScope();
18735
18867
  useModalFocus(panelRef, ".dialog-body", dismissible, stableOnClose);
18736
18868
  useLayoutEffect(() => registerOpenDialog(stableOnClose), [stableOnClose]);
18869
+ useLayoutEffect(() => {
18870
+ const panel = panelRef.current;
18871
+ if (!panel || label) return;
18872
+ const heading = panel.querySelector(".dialog-body :is(h1, h2, h3, h4, h5, h6)");
18873
+ if (!heading) return;
18874
+ heading.id ||= `${labelId}-heading`;
18875
+ panel.setAttribute("aria-labelledby", heading.id);
18876
+ return () => panel.removeAttribute("aria-labelledby");
18877
+ }, [label, markup]);
18737
18878
  useLayoutEffect(() => {
18738
18879
  if (panelRef.current) emitFromRender("dialogrender", passageName ?? "", panelRef.current);
18739
18880
  }, []);
@@ -18752,6 +18893,7 @@ function PassageDialog({ passageName, fallbackMarkup, panelClass, onClose, dismi
18752
18893
  class: cls,
18753
18894
  role: "dialog",
18754
18895
  "aria-modal": "true",
18896
+ "aria-label": label ?? passageName,
18755
18897
  tabIndex: -1,
18756
18898
  children: [showCloseButton && /* @__PURE__ */ jsx("button", {
18757
18899
  type: "button",
@@ -18917,7 +19059,7 @@ function App() {
18917
19059
  //#region src/parser.ts
18918
19060
  var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
18919
19061
  /** HTML elements written without content or end tag, as innerHTML does. */
18920
- var VOID_ELEMENTS = new Set([
19062
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
18921
19063
  "area",
18922
19064
  "base",
18923
19065
  "basefont",
@@ -19033,7 +19175,7 @@ function parseStoryData() {
19033
19175
  const tags = (el.getAttribute("tags") || "").split(/\s+/).filter((t) => t.length > 0);
19034
19176
  const content = passageMarkup(el);
19035
19177
  const metadata = {};
19036
- const skipAttrs = new Set([
19178
+ const skipAttrs = /* @__PURE__ */ new Set([
19037
19179
  "pid",
19038
19180
  "name",
19039
19181
  "tags"
@@ -19067,6 +19209,12 @@ var definitions = /* @__PURE__ */ new Map();
19067
19209
  var values = createNamespace();
19068
19210
  var storageLoaded = false;
19069
19211
  var unsubscribeStoryData = null;
19212
+ var listeners = /* @__PURE__ */ new Set();
19213
+ /** Call `listener` after a setting changes; returns the unsubscribe. */
19214
+ function subscribeSettings(listener) {
19215
+ listeners.add(listener);
19216
+ return () => listeners.delete(listener);
19217
+ }
19070
19218
  function storageKey() {
19071
19219
  return `spindle.${useStoryStore.getState().storyData?.ifid || "unknown"}.settings`;
19072
19220
  }
@@ -19140,6 +19288,7 @@ var settings = {
19140
19288
  set(name, value) {
19141
19289
  values[name] = value;
19142
19290
  persist();
19291
+ for (const listener of [...listeners]) listener();
19143
19292
  },
19144
19293
  getAll() {
19145
19294
  return { ...values };
@@ -19805,14 +19954,14 @@ function installStoryAPI() {
19805
19954
  * Passages that hold no markup: declarations, and the JavaScript function
19806
19955
  * body of SaveTitle.
19807
19956
  */
19808
- var NOT_MARKUP = new Set([
19957
+ var NOT_MARKUP = /* @__PURE__ */ new Set([
19809
19958
  "StoryVariables",
19810
19959
  "StoryTransients",
19811
19960
  "SaveTitle"
19812
19961
  ]);
19813
19962
  var NOT_MARKUP_TAGS = ["script", "stylesheet"];
19814
19963
  /** Branch macros, which their parent macro renders. */
19815
- var BRANCH_MACROS = new Set([
19964
+ var BRANCH_MACROS = /* @__PURE__ */ new Set([
19816
19965
  "elseif",
19817
19966
  "else",
19818
19967
  "case",
@@ -20231,10 +20380,11 @@ var Reader = class {
20231
20380
  //#endregion
20232
20381
  //#region src/story-variables.ts
20233
20382
  /**
20234
- * The tokens of markup, or none if it is malformed: validateMarkup reports
20235
- * that, with its position.
20383
+ * The tokens of markup, or none if it is malformed (validateMarkup reports
20384
+ * that, with its position); in tolerant mode, those of the well-formed parts.
20236
20385
  */
20237
- function tokensOf(text, textMode) {
20386
+ function tokensOf(text, textMode, { tolerant } = {}) {
20387
+ if (tolerant) return tokenizeMarkupTolerant(text, { text: textMode }).tokens;
20238
20388
  try {
20239
20389
  return tokenizeMarkup(text, { text: textMode });
20240
20390
  } catch (err) {
@@ -20246,11 +20396,11 @@ function declarationRegex(sigil) {
20246
20396
  const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20247
20397
  return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
20248
20398
  }
20249
- /** A `$name` reference with its dot path, at a `$` the lexer found. */
20250
- var VAR_PATH_RE = /\$(\w+(?:\.\w+)*)/y;
20399
+ /** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
20400
+ var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
20251
20401
  /** Quoted first argument of an input macro naming a story variable. */
20252
20402
  var QUOTED_VAR_ARG_RE = /^["']\$(\w+(?:\.\w+)*)["']?$/;
20253
- var VALID_VAR_TYPES = new Set([
20403
+ var VALID_VAR_TYPES = /* @__PURE__ */ new Set([
20254
20404
  "number",
20255
20405
  "string",
20256
20406
  "boolean"
@@ -20401,19 +20551,30 @@ function parseStoryVariables(content, sigil = "$") {
20401
20551
  return schema;
20402
20552
  }
20403
20553
  /**
20404
- * Validate a single variable reference path (e.g. "player.health") against
20405
- * the schema. Returns an error message or null if valid.
20554
+ * Check a reference against the declarations: the error code and message, or
20555
+ * null if it is valid. (Unknown fields of objects are valid: classes
20556
+ * registered with Story.registerClass() can add members that are not in the
20557
+ * defaults.)
20406
20558
  */
20407
- function validateRef(ref, schema) {
20408
- const parts = ref.split(".");
20409
- const rootName = parts[0];
20410
- const nameError = variableNameError(rootName, "$" + rootName);
20411
- if (nameError) return nameError;
20412
- const rootSchema = schema.get(rootName);
20413
- if (!rootSchema) return `Undeclared variable: $${ref}`;
20414
- let current = rootSchema;
20415
- for (let i = 1; i < parts.length; i++) {
20416
- const part = parts[i];
20559
+ function checkReference(ref, declared) {
20560
+ const label = (path) => ref.sigil + [ref.name, ...path].join(".");
20561
+ const nameError = variableNameError(ref.name, ref.sigil + ref.name);
20562
+ if (nameError) return {
20563
+ code: "reserved-name",
20564
+ message: nameError
20565
+ };
20566
+ const schema = ref.sigil === "$" ? declared.variables : declared.transients;
20567
+ if (!schema) return null;
20568
+ if (!schema.has(ref.name)) return ref.sigil === "$" ? {
20569
+ code: "undeclared-variable",
20570
+ message: `Undeclared variable: ${label(ref.path)}`
20571
+ } : {
20572
+ code: "undeclared-transient",
20573
+ message: `Undeclared transient: ${label(ref.path)}`
20574
+ };
20575
+ let current = schema.get(ref.name);
20576
+ for (let i = 0; current && i < ref.path.length; i++) {
20577
+ const part = ref.path[i];
20417
20578
  if (current.type === "array") return null;
20418
20579
  if (current.type === "null") return null;
20419
20580
  const sample = PRIMITIVE_SAMPLES[current.type];
@@ -20423,10 +20584,11 @@ function validateRef(ref, schema) {
20423
20584
  current = { type: memberType };
20424
20585
  continue;
20425
20586
  }
20426
- if (current.type !== "object" || !current.fields) return `Cannot access field "${part}" on $${parts.slice(0, i).join(".")} (type: ${current.type})`;
20427
- const fieldSchema = current.fields.get(part);
20428
- if (!fieldSchema) return null;
20429
- current = fieldSchema;
20587
+ if (current.type !== "object" || !current.fields) return {
20588
+ code: "primitive-field",
20589
+ message: `Cannot access field "${part}" on ${label(ref.path.slice(0, i))} (type: ${current.type})`
20590
+ };
20591
+ current = current.fields.get(part);
20430
20592
  }
20431
20593
  return null;
20432
20594
  }
@@ -20444,12 +20606,27 @@ var BUILTIN_STORE_VAR_MACROS = [
20444
20606
  "textbox"
20445
20607
  ];
20446
20608
  var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
20609
+ /** A reference written at `index` of `code`, with its dot path. */
20610
+ function referenceAt(code, index, at) {
20611
+ VAR_PATH_RE.lastIndex = index;
20612
+ const match = VAR_PATH_RE.exec(code);
20613
+ if (!match) return void 0;
20614
+ const [name, ...path] = match[2].split(".");
20615
+ return {
20616
+ sigil: match[1],
20617
+ name,
20618
+ path,
20619
+ start: at(index),
20620
+ end: at(index + match[0].length)
20621
+ };
20622
+ }
20447
20623
  /**
20448
20624
  * Scan the value of a code attribute (`onclick`, see isCodeAttribute) for
20449
- * the `{$…}` references resolved in it; its other braces are code.
20625
+ * the `{$…}` references resolved in it; its other braces are code. `at` is
20626
+ * where the value is.
20450
20627
  */
20451
- function scanSigilReferences(value, onRef) {
20452
- for (const part of splitSigilTemplate(value)) if ("expr" in part) scanCode(part.expr, onRef);
20628
+ function scanSigilReferences(value, at, emit) {
20629
+ for (const { expr, at: k } of sigilExpressions(value)) scanCode(expr, (i) => at(k + i), emit);
20453
20630
  }
20454
20631
  /**
20455
20632
  * Scan literal text (string contents, HTML attribute values) for the markup
@@ -20457,9 +20634,9 @@ function scanSigilReferences(value, onRef) {
20457
20634
  * expressions and macros, read as in passage text. A bare `$word` in
20458
20635
  * literal text is not a reference.
20459
20636
  */
20460
- function scanInterpolations(text, onRef, storeVarMacros = NO_STORE_VAR_MACROS) {
20637
+ function scanInterpolations(text, at, emit, options) {
20461
20638
  if (!text.includes("{")) return;
20462
- collectTokenRefs(text, tokensOf(text, true), storeVarMacros, onRef);
20639
+ collectTokenRefs(text, tokensOf(text, true, options), at, emit, options);
20463
20640
  }
20464
20641
  /**
20465
20642
  * Report `$var` references in JavaScript code, lexed as the expression
@@ -20469,76 +20646,104 @@ function scanInterpolations(text, onRef, storeVarMacros = NO_STORE_VAR_MACROS) {
20469
20646
  * is literal text unless a macro argument that holds markup is read as such
20470
20647
  * (see scanArgs); the `${…}` parts of template literals are code.
20471
20648
  */
20472
- function scanCode(code, onRef, goal = "expression") {
20649
+ function scanCode(code, at, emit, goal = "expression") {
20473
20650
  const parsed = parseOrError(code, goal);
20474
20651
  if (parsed instanceof CodeSyntaxError) {
20475
- scanCodeLeniently(code, onRef, goal);
20652
+ scanCodeLeniently(code, at, emit, goal);
20476
20653
  return;
20477
20654
  }
20478
20655
  for (const ref of parsed.refs) {
20479
- if (ref.sigil !== "$") continue;
20480
- VAR_PATH_RE.lastIndex = ref.start;
20481
- onRef(VAR_PATH_RE.exec(code)[1]);
20656
+ if (ref.sigil !== "$" && ref.sigil !== "%") continue;
20657
+ const found = referenceAt(code, ref.start, at);
20658
+ if (found) emit(found);
20482
20659
  }
20483
20660
  }
20484
20661
  /** `scanCode` for code acorn can't parse: lexed leniently. */
20485
- function scanCodeLeniently(code, onRef, goal) {
20662
+ function scanCodeLeniently(code, at, emit, goal) {
20486
20663
  lexJs(code, {
20487
20664
  variable(sigil, _name, index) {
20488
- if (sigil !== "$") return;
20489
- VAR_PATH_RE.lastIndex = index;
20490
- onRef(VAR_PATH_RE.exec(code)[1]);
20665
+ if (sigil !== "$" && sigil !== "%") return;
20666
+ const found = referenceAt(code, index, at);
20667
+ if (found) emit(found);
20491
20668
  },
20492
20669
  literal() {}
20493
20670
  }, goal);
20494
20671
  }
20495
20672
  /**
20496
- * Report the `$var` references a passage evaluates at runtime: `{$var}`
20497
- * displays, `{$expr}` expressions, macro arguments and `{do}` bodies (as
20498
- * code), quoted variable names bound by input macros, and `{$…}`
20499
- * interpolations in HTML attributes. Prose is literal text and not scanned.
20500
- */
20501
- function collectPassageRefs(content, storeVarMacros, onRef, parametersOf) {
20502
- withParseCache(() => collectTokenRefs(content, tokensOf(content, false), storeVarMacros, onRef, parametersOf));
20503
- }
20504
- /**
20505
20673
  * Report the references in the arguments of a macro by what its parameters
20506
20674
  * say each holds (see ParameterDef.holds): code is scanned as code and
20507
20675
  * markup as markup, but literal text (a placeholder, a passage name) holds
20508
20676
  * none. A macro without declared parameters, or arguments that do not
20509
20677
  * parse, are scanned as code.
20510
20678
  */
20511
- function scanArgs(token, params, onRef) {
20679
+ function scanArgs(token, params, at, emit, options) {
20512
20680
  if (!token.rawArgs) return;
20513
20681
  if (params) {
20514
- const pieces = [...argPieces(token.rawArgs, 0, params, token.name, "")];
20682
+ const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
20515
20683
  if (!pieces.some((piece) => piece.kind === "argument-error")) {
20516
- for (const piece of pieces) if (piece.kind === "code") scanCode(piece.code, onRef, piece.goal);
20517
- else if (piece.kind === "text") scanInterpolations(piece.text, onRef);
20684
+ for (const piece of pieces) {
20685
+ const pieceAt = (i) => at(pieceOffset(piece, i));
20686
+ if (piece.kind === "code") scanCode(piece.code, pieceAt, emit, piece.goal);
20687
+ else if (piece.kind === "text") scanInterpolations(piece.text, pieceAt, emit, {
20688
+ ...options,
20689
+ storeVarMacros: NO_STORE_VAR_MACROS
20690
+ });
20691
+ }
20518
20692
  return;
20519
20693
  }
20520
20694
  }
20521
- scanCode(token.rawArgs, onRef);
20695
+ scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
20522
20696
  }
20523
20697
  /** Report the `$var` references in the tokens of `content`. */
20524
- function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf = () => void 0) {
20698
+ function collectTokenRefs(content, tokens, at, emit, options) {
20699
+ const { storeVarMacros, parametersOf } = options;
20525
20700
  for (let t = 0; t < tokens.length; t++) {
20526
20701
  const token = tokens[t];
20527
20702
  if (token.type === "variable") {
20528
- if (token.scope === "variable" && token.name) onRef(token.name);
20529
- } else if (token.type === "link") scanInterpolations(token.display, onRef);
20530
- else if (token.type === "expression") scanCode(token.expression, onRef);
20531
- else if (token.type === "html") for (const [name, value] of Object.entries(token.attributes)) if (isCodeAttribute(name)) scanSigilReferences(value, onRef);
20532
- else scanInterpolations(value, onRef, storeVarMacros);
20703
+ if ((token.scope === "variable" || token.scope === "transient") && token.name) {
20704
+ const [name, ...path] = token.name.split(".");
20705
+ emit({
20706
+ sigil: token.scope === "variable" ? "$" : "%",
20707
+ name,
20708
+ path,
20709
+ start: at(token.nameStart - 1),
20710
+ end: at(token.nameEnd)
20711
+ });
20712
+ }
20713
+ } else if (token.type === "link") scanInterpolations(token.display, (i) => at(token.displayStart + i), emit, {
20714
+ ...options,
20715
+ storeVarMacros: NO_STORE_VAR_MACROS
20716
+ });
20717
+ else if (token.type === "expression") scanCode(token.expression, (i) => at(token.expressionStart + i), emit);
20718
+ else if (token.type === "html") for (const { name, value, at: valueAt } of attributeValues(content, token)) {
20719
+ const valueIn = (i) => at(valueAt + i);
20720
+ if (isCodeAttribute(name)) scanSigilReferences(value, valueIn, emit);
20721
+ else scanInterpolations(value, valueIn, emit, options);
20722
+ }
20533
20723
  else if (token.type === "macro" && !token.isClose) {
20534
- scanArgs(token, parametersOf(token.name), onRef);
20535
- if (token.className) scanInterpolations(token.className, onRef);
20536
- if (token.id) scanInterpolations(token.id, onRef);
20724
+ scanArgs(token, parametersOf(token.name), at, emit, options);
20725
+ if (token.selectorsStart !== void 0 && token.selectorsEnd !== void 0) {
20726
+ const from = token.selectorsStart;
20727
+ scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
20728
+ ...options,
20729
+ storeVarMacros: NO_STORE_VAR_MACROS
20730
+ });
20731
+ }
20537
20732
  if (storeVarMacros.has(token.name.toLowerCase())) {
20733
+ const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
20538
20734
  const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
20539
20735
  const quoted = QUOTED_VAR_ARG_RE.exec(first);
20540
- if (quoted) onRef(quoted[1]);
20541
- else if (!/^["'`]/.test(first)) scanCode(first, onRef);
20736
+ if (quoted) {
20737
+ const [name, ...path] = quoted[1].split(".");
20738
+ const start = token.argsStart + lead + 1;
20739
+ emit({
20740
+ sigil: "$",
20741
+ name,
20742
+ path,
20743
+ start: at(start),
20744
+ end: at(start + 1 + quoted[1].length)
20745
+ });
20746
+ } else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
20542
20747
  }
20543
20748
  if (token.name.toLowerCase() === "do") {
20544
20749
  let close = t + 1;
@@ -20548,7 +20753,7 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20548
20753
  close++;
20549
20754
  }
20550
20755
  if (close < tokens.length) {
20551
- scanCode(content.slice(token.end, tokens[close].start), onRef, "statements");
20756
+ scanCode(content.slice(token.end, tokens[close].start), (i) => at(token.end + i), emit, "statements");
20552
20757
  t = close;
20553
20758
  }
20554
20759
  }
@@ -20556,6 +20761,43 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20556
20761
  }
20557
20762
  }
20558
20763
  /**
20764
+ * The `$` and `%` variable references a passage evaluates at runtime, in
20765
+ * source order: `{$var}` displays, `{$expr}` expressions, macro arguments and
20766
+ * `{do}` bodies (as code), quoted variable names bound by input macros, and
20767
+ * `{$…}` interpolations in labels and HTML attributes. Prose is literal text
20768
+ * and not scanned.
20769
+ */
20770
+ function collectVariableReferences(content, options) {
20771
+ const found = [];
20772
+ withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), options));
20773
+ return found;
20774
+ }
20775
+ /**
20776
+ * The invalid variable references of the passages, against what is declared,
20777
+ * with their positions. The passages that hold no markup (the declarations
20778
+ * themselves, SaveTitle) are skipped.
20779
+ */
20780
+ function checkVariableReferences(passages, declared, options) {
20781
+ const diagnostics = [];
20782
+ for (const passage of passages) {
20783
+ if (NOT_MARKUP.has(passage.name)) continue;
20784
+ for (const ref of collectVariableReferences(passage.content, options)) {
20785
+ const error = checkReference(ref, declared);
20786
+ if (!error) continue;
20787
+ diagnostics.push({
20788
+ passage: passage.name,
20789
+ code: error.code,
20790
+ name: ref.name,
20791
+ ...ref.path.length > 0 ? { path: ref.path } : {},
20792
+ start: ref.start,
20793
+ end: ref.end,
20794
+ message: error.message
20795
+ });
20796
+ }
20797
+ }
20798
+ return diagnostics;
20799
+ }
20800
+ /**
20559
20801
  * Check the `$var` references of all passages against the schema, at story
20560
20802
  * start. Returns the error messages (empty = valid). (The syntax of their
20561
20803
  * code is checked with their markup: see markup/validate.ts.)
@@ -20564,16 +20806,10 @@ function collectTokenRefs(content, tokens, storeVarMacros, onRef, parametersOf =
20564
20806
  * variable; it defaults to the built-in ones.
20565
20807
  */
20566
20808
  function validatePassages(passages, schema, storeVarMacros = BUILTIN_STORE_VAR_MACROS, parametersOf = getMacroParameters) {
20567
- const errors = [];
20568
- const storeVarSet = new Set(Array.from(storeVarMacros, (m) => m.toLowerCase()));
20569
- for (const [name, passage] of passages) {
20570
- if (NOT_MARKUP.has(name)) continue;
20571
- collectPassageRefs(passage.content, storeVarSet, (ref) => {
20572
- const error = validateRef(ref, schema);
20573
- if (error) errors.push(`Passage "${name}": ${error}`);
20574
- }, parametersOf);
20575
- }
20576
- return errors;
20809
+ return checkVariableReferences(passages.values(), { variables: schema }, {
20810
+ storeVarMacros: new Set(Array.from(storeVarMacros, (m) => m.toLowerCase())),
20811
+ parametersOf
20812
+ }).map((d) => `Passage "${d.passage}": ${d.message}`);
20577
20813
  }
20578
20814
  /**
20579
20815
  * Extract default values from the schema as a record without a prototype,
@@ -20620,7 +20856,7 @@ function renderSpecialPassage(passage) {
20620
20856
  return null;
20621
20857
  }
20622
20858
  }
20623
- var CODE_PASSAGES = new Set([
20859
+ var CODE_PASSAGES = /* @__PURE__ */ new Set([
20624
20860
  "PassageReady",
20625
20861
  "PassageHeader",
20626
20862
  "PassageFooter",
@@ -20697,7 +20933,7 @@ function Passage({ passage, dataTransition, navigationId }) {
20697
20933
  }
20698
20934
  //#endregion
20699
20935
  //#region src/transition.ts
20700
- var TRANSITION_TYPES = new Set([
20936
+ var TRANSITION_TYPES = /* @__PURE__ */ new Set([
20701
20937
  "none",
20702
20938
  "fade",
20703
20939
  "fade-through",
@@ -20919,19 +21155,21 @@ defineMacro({
20919
21155
  setDisplayedPassage(currentPassage);
20920
21156
  }, incomingDelay);
20921
21157
  const cleanupDelay = incomingDelay + config.duration;
20922
- timeoutsRef.current = [t1, setTimeout(() => {
21158
+ const t2 = setTimeout(() => {
20923
21159
  cleanupSnapshots(containerEl);
20924
21160
  if (scrollAfterCleanup.current) scrollToPassageStart(containerEl);
20925
21161
  scrollAfterCleanup.current = false;
20926
- }, cleanupDelay)];
21162
+ }, cleanupDelay);
21163
+ timeoutsRef.current = [t1, t2];
20927
21164
  return;
20928
21165
  }
20929
21166
  containerEl.classList.add("passage-container--crossfading");
20930
21167
  containerEl.appendChild(snapshot);
20931
21168
  setDisplayedPassage(currentPassage);
20932
- timeoutsRef.current = [setTimeout(() => {
21169
+ const t1 = setTimeout(() => {
20933
21170
  cleanupSnapshots(containerEl);
20934
- }, config.duration)];
21171
+ }, config.duration);
21172
+ timeoutsRef.current = [t1];
20935
21173
  }, [navigationId]);
20936
21174
  const shownId = displayedPassage && !renderDeferred ? displayed.id : null;
20937
21175
  const lastShownId = useRef(shownId);
@@ -21369,18 +21607,19 @@ function loopArgs(rawArgs, args) {
21369
21607
  };
21370
21608
  }
21371
21609
  function ForIteration({ parentValues, itemVar, itemValue, indexVar, indexValue, children }) {
21610
+ const ownKeys = useMemo(() => ({
21611
+ [itemVar]: itemValue,
21612
+ ...indexVar ? { [indexVar]: indexValue } : void 0
21613
+ }), [
21614
+ itemVar,
21615
+ itemValue,
21616
+ indexVar,
21617
+ indexValue
21618
+ ]);
21372
21619
  return /* @__PURE__ */ jsx(LocalsScope, {
21373
21620
  body: children,
21374
21621
  parentValues,
21375
- ownKeys: useMemo(() => ({
21376
- [itemVar]: itemValue,
21377
- ...indexVar ? { [indexVar]: indexValue } : void 0
21378
- }), [
21379
- itemVar,
21380
- itemValue,
21381
- indexVar,
21382
- indexValue
21383
- ])
21622
+ ownKeys
21384
21623
  });
21385
21624
  }
21386
21625
  defineMacro({
@@ -21535,14 +21774,50 @@ defineMacro({
21535
21774
  //#region src/components/macros/detached-body.tsx
21536
21775
  var frozenAlways = () => true;
21537
21776
  /**
21777
+ * Macros whose work is over once their effects have run: a body made of
21778
+ * these alone has nothing left to wait for. Any other macro (a timer, a
21779
+ * widget, an author's macro) may keep working after rendering.
21780
+ */
21781
+ var SETTLING_MACROS = new NameSet([
21782
+ "set",
21783
+ "unset",
21784
+ "if",
21785
+ "for",
21786
+ "switch",
21787
+ "do",
21788
+ "print",
21789
+ "goto",
21790
+ "nobr",
21791
+ "span"
21792
+ ]);
21793
+ /** Whether `nodes` use no macro outside SETTLING_MACROS (see above). */
21794
+ function settlesAfterRender(nodes) {
21795
+ return nodes.every((n) => {
21796
+ switch (n.type) {
21797
+ case "macro": return SETTLING_MACROS.has(n.name) && settlesAfterRender(n.children) && (n.branches ?? []).every((b) => settlesAfterRender(b.children));
21798
+ case "html": return settlesAfterRender(n.children);
21799
+ default: return true;
21800
+ }
21801
+ });
21802
+ }
21803
+ /** Calls `onSettled` once the effects of the content before it have run. */
21804
+ function Settled({ onSettled }) {
21805
+ useEffect(() => {
21806
+ const timer = setTimeout(onSettled, 0);
21807
+ return () => clearTimeout(timer);
21808
+ }, []);
21809
+ return null;
21810
+ }
21811
+ /**
21538
21812
  * Return a function that runs a macro body once, outside the passage tree:
21539
21813
  * it renders `children` into a detached node, so the body's macros ({set},
21540
21814
  * {if}, {goto}, ...) fire their side effects through the normal Preact
21541
21815
  * pipeline. Used by {button} and {link} on click. The body's state is frozen
21542
21816
  * once it has rendered, so it runs once per click. It stays mounted
21543
- * until the owning macro unmounts (its passage changes, say), so work it
21544
- * starts in an effect, such as the timer of a {timed} or {repeat}, can
21545
- * finish; the passage leaving cancels it, and so does a restart or a load
21817
+ * until it has nothing left to do: a body of plain macros ({set}, {if},
21818
+ * {goto}...) once its effects have run, any other (with the timer of a
21819
+ * {timed} or {repeat}, say) until the owning macro unmounts, e.g. its
21820
+ * 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
21546
21821
  * replacing the game, which a control of the story interface outlives
21547
21822
  * (#401).
21548
21823
  *
@@ -21584,6 +21859,12 @@ function useDetachedBody() {
21584
21859
  const run = (children) => {
21585
21860
  const locals = liveLocalsView(updater.getValues);
21586
21861
  const container = document.createElement("div");
21862
+ const release = settlesAfterRender(children) ? () => {
21863
+ const at = mounted.current.indexOf(container);
21864
+ if (at === -1) return;
21865
+ mounted.current.splice(at, 1);
21866
+ render(null, container);
21867
+ } : null;
21587
21868
  render(/* @__PURE__ */ jsx(FrozenStateContext.Provider, {
21588
21869
  value: frozenAlways,
21589
21870
  children: /* @__PURE__ */ jsx(LocalsUpdateContext.Provider, {
@@ -21604,14 +21885,14 @@ function useDetachedBody() {
21604
21885
  value: closeDialog,
21605
21886
  children: /* @__PURE__ */ jsx(ItemEditContext.Provider, {
21606
21887
  value: inIteration,
21607
- children: /* @__PURE__ */ jsx(OutgoingContext.Provider, {
21888
+ children: /* @__PURE__ */ jsxs(OutgoingContext.Provider, {
21608
21889
  value: hasLeft,
21609
- children: renderNodes(children, {
21890
+ children: [renderNodes(children, {
21610
21891
  nobr,
21611
21892
  inline,
21612
21893
  structural,
21613
21894
  locals
21614
- })
21895
+ }), release && /* @__PURE__ */ jsx(Settled, { onSettled: release })]
21615
21896
  })
21616
21897
  })
21617
21898
  })
@@ -21864,7 +22145,10 @@ defineMacro({
21864
22145
  const visibleCharsRef = useRef(0);
21865
22146
  visibleCharsRef.current = visibleChars;
21866
22147
  useEffect(() => {
21867
- if (containerRef.current) setMeasured((containerRef.current.textContent || "").length);
22148
+ if (containerRef.current) {
22149
+ const text = containerRef.current.textContent || "";
22150
+ setMeasured(text.length);
22151
+ }
21868
22152
  });
21869
22153
  useEffect(() => {
21870
22154
  if (totalChars === 0) return;
@@ -21914,7 +22198,7 @@ defineMacro({
21914
22198
  visibility: measured === null ? "hidden" : "visible",
21915
22199
  clipPath: clip
21916
22200
  },
21917
- children: ctx.renderInlineNodes(children)
22201
+ children: ctx.renderNodes(children, { inline: true })
21918
22202
  }), !done && totalChars > 0 && /* @__PURE__ */ jsx("span", { class: "macro-type-cursor" })]
21919
22203
  });
21920
22204
  }
@@ -22007,6 +22291,7 @@ function defineMenubarAction(config) {
22007
22291
  passageName: config.dialog.passageName,
22008
22292
  fallbackMarkup: config.dialog.fallbackMarkup,
22009
22293
  panelClass: config.dialog.panelClass,
22294
+ label: typeof config.label === "string" ? config.label : config.name,
22010
22295
  onClose: () => setDialogOpen(false),
22011
22296
  showCloseButton: config.dialog.showCloseButton
22012
22297
  })] });
@@ -22172,8 +22457,8 @@ function SaveManagerContent() {
22172
22457
  }
22173
22458
  }, [renamingId]);
22174
22459
  const mounted = useRef(true);
22175
- const statusTimer = useRef();
22176
- const closeTimer = useRef();
22460
+ const statusTimer = useRef(void 0);
22461
+ const closeTimer = useRef(void 0);
22177
22462
  const showStatus = (text, type = "success") => {
22178
22463
  if (!mounted.current) return;
22179
22464
  clearTimeout(statusTimer.current);
@@ -22488,10 +22773,12 @@ defineMacro({
22488
22773
  //#region src/components/macros/SettingsControls.tsx
22489
22774
  function SettingControl({ name, def }) {
22490
22775
  const [value, setValue] = useState(() => settings.get(name));
22491
- const update = (newValue) => {
22492
- setValue(newValue);
22493
- settings.set(name, newValue);
22494
- };
22776
+ useEffect(() => {
22777
+ const sync = () => setValue(settings.get(name));
22778
+ sync();
22779
+ return subscribeSettings(sync);
22780
+ }, [name]);
22781
+ const update = (newValue) => settings.set(name, newValue);
22495
22782
  switch (def.type) {
22496
22783
  case "toggle": return /* @__PURE__ */ jsxs("label", {
22497
22784
  class: "settings-row",