@rohal12/spindle 0.62.9 → 0.63.0

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.
@@ -5895,118 +5895,144 @@ function propertyName(node, src) {
5895
5895
  * identifiers here are declared (a `let`, a parameter), where a sigil
5896
5896
  * variable can't be. `shorthand`: the node is a shorthand property's value.
5897
5897
  */
5898
- function walk(node, src, out, binding, shorthand, access = "read") {
5899
- if (Array.isArray(node)) {
5900
- for (const n of node) walk(n, src, out, binding, false, access);
5901
- return;
5902
- }
5903
- if (!isNode(node)) return;
5904
- const sub = (child, bind = false, short = false, role = "read") => walk(child, src, out, bind, short, role);
5905
- switch (node.type) {
5906
- case "Identifier": {
5907
- const sigil = sigilOf(node, src);
5908
- if (!sigil) return;
5909
- if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
5910
- out.refs.push({
5911
- sigil: sigil[0],
5912
- name: sigil[1],
5913
- start: node.start,
5914
- end: node.end,
5915
- shorthand,
5916
- read: access !== "write",
5917
- write: access !== "read"
5918
- });
5898
+ function walk(root, src, out, binding, shorthand, access = "read") {
5899
+ const pending = [[
5900
+ root,
5901
+ binding,
5902
+ shorthand,
5903
+ access
5904
+ ]];
5905
+ while (pending.length) {
5906
+ const [node, bind, short, role] = pending.pop();
5907
+ const children = [];
5908
+ visit(node, bind, short, role, children);
5909
+ for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
5910
+ }
5911
+ function visit(node, binding, shorthand, access, children) {
5912
+ if (Array.isArray(node)) {
5913
+ for (const n of node) children.push([
5914
+ n,
5915
+ binding,
5916
+ false,
5917
+ access
5918
+ ]);
5919
5919
  return;
5920
5920
  }
5921
- case "Literal":
5922
- if (typeof node.value === "string") out.strings.push(src.slice(node.start + 1, node.end - 1));
5923
- return;
5924
- case "TemplateElement":
5925
- out.strings.push(node.value.raw);
5926
- return;
5927
- case "MemberExpression":
5928
- sub(node.object);
5929
- if (node.computed) sub(node.property);
5930
- else propertyName(node.property, src);
5931
- return;
5932
- case "Property":
5933
- if (node.computed) sub(node.key);
5934
- else if (!node.shorthand) propertyName(node.key, src);
5935
- if (node.shorthand) {
5936
- const value = node.value;
5937
- if (value.type === "AssignmentPattern") {
5938
- sub(value.left, binding, true, access);
5939
- sub(value.right);
5940
- } else sub(value, binding, true, access);
5941
- } else sub(node.value, binding, false, access);
5942
- return;
5943
- case "MethodDefinition":
5944
- case "PropertyDefinition":
5945
- if (node.computed) sub(node.key);
5946
- else propertyName(node.key, src);
5947
- sub(node.value);
5948
- return;
5949
- case "LabeledStatement":
5950
- sub(node.body);
5951
- return;
5952
- case "BreakStatement":
5953
- case "ContinueStatement":
5954
- case "MetaProperty":
5955
- case "PrivateIdentifier": return;
5956
- case "VariableDeclarator":
5957
- sub(node.id, true);
5958
- sub(node.init);
5959
- return;
5960
- case "FunctionDeclaration":
5961
- case "FunctionExpression":
5962
- case "ArrowFunctionExpression":
5963
- sub(node.id, true);
5964
- for (const p of node.params) sub(p, true);
5965
- sub(node.body);
5966
- return;
5967
- case "ClassDeclaration":
5968
- case "ClassExpression":
5969
- sub(node.id, true);
5970
- sub(node.superClass);
5971
- sub(node.body);
5972
- return;
5973
- case "CatchClause":
5974
- sub(node.param, true);
5975
- sub(node.body);
5976
- return;
5977
- case "AssignmentExpression":
5978
- sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
5979
- sub(node.right);
5980
- return;
5981
- case "UnaryExpression":
5982
- sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
5983
- return;
5984
- case "UpdateExpression":
5985
- sub(node.argument, false, false, "readwrite");
5986
- return;
5987
- case "ForInStatement":
5988
- case "ForOfStatement":
5989
- sub(node.left, false, false, "write");
5990
- sub(node.right);
5991
- sub(node.body);
5992
- return;
5993
- case "AssignmentPattern":
5994
- sub(node.left, binding, false, access);
5995
- sub(node.right);
5996
- return;
5997
- case "ObjectPattern":
5998
- case "ArrayPattern":
5999
- case "RestElement":
6000
- for (const key of [
6001
- "properties",
6002
- "elements",
6003
- "argument"
6004
- ]) sub(node[key], binding, false, access);
6005
- return;
6006
- default: for (const key in node) {
6007
- if (key === "type" || key === "start" || key === "end") continue;
6008
- const v = node[key];
6009
- if (typeof v === "object" && v !== null) sub(v);
5921
+ if (!isNode(node)) return;
5922
+ const sub = (child, bind = false, short = false, role = "read") => {
5923
+ children.push([
5924
+ child,
5925
+ bind,
5926
+ short,
5927
+ role
5928
+ ]);
5929
+ };
5930
+ switch (node.type) {
5931
+ case "Identifier": {
5932
+ const sigil = sigilOf(node, src);
5933
+ if (!sigil) return;
5934
+ if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
5935
+ out.refs.push({
5936
+ sigil: sigil[0],
5937
+ name: sigil[1],
5938
+ start: node.start,
5939
+ end: node.end,
5940
+ shorthand,
5941
+ read: access !== "write",
5942
+ write: access !== "read"
5943
+ });
5944
+ return;
5945
+ }
5946
+ case "Literal":
5947
+ if (typeof node.value === "string") out.strings.push(src.slice(node.start + 1, node.end - 1));
5948
+ return;
5949
+ case "TemplateElement":
5950
+ out.strings.push(node.value.raw);
5951
+ return;
5952
+ case "MemberExpression":
5953
+ sub(node.object);
5954
+ if (node.computed) sub(node.property);
5955
+ else propertyName(node.property, src);
5956
+ return;
5957
+ case "Property":
5958
+ if (node.computed) sub(node.key);
5959
+ else if (!node.shorthand) propertyName(node.key, src);
5960
+ if (node.shorthand) {
5961
+ const value = node.value;
5962
+ if (value.type === "AssignmentPattern") {
5963
+ sub(value.left, binding, true, access);
5964
+ sub(value.right);
5965
+ } else sub(value, binding, true, access);
5966
+ } else sub(node.value, binding, false, access);
5967
+ return;
5968
+ case "MethodDefinition":
5969
+ case "PropertyDefinition":
5970
+ if (node.computed) sub(node.key);
5971
+ else propertyName(node.key, src);
5972
+ sub(node.value);
5973
+ return;
5974
+ case "LabeledStatement":
5975
+ sub(node.body);
5976
+ return;
5977
+ case "BreakStatement":
5978
+ case "ContinueStatement":
5979
+ case "MetaProperty":
5980
+ case "PrivateIdentifier": return;
5981
+ case "VariableDeclarator":
5982
+ sub(node.id, true);
5983
+ sub(node.init);
5984
+ return;
5985
+ case "FunctionDeclaration":
5986
+ case "FunctionExpression":
5987
+ case "ArrowFunctionExpression":
5988
+ sub(node.id, true);
5989
+ for (const p of node.params) sub(p, true);
5990
+ sub(node.body);
5991
+ return;
5992
+ case "ClassDeclaration":
5993
+ case "ClassExpression":
5994
+ sub(node.id, true);
5995
+ sub(node.superClass);
5996
+ sub(node.body);
5997
+ return;
5998
+ case "CatchClause":
5999
+ sub(node.param, true);
6000
+ sub(node.body);
6001
+ return;
6002
+ case "AssignmentExpression":
6003
+ sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
6004
+ sub(node.right);
6005
+ return;
6006
+ case "UnaryExpression":
6007
+ sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
6008
+ return;
6009
+ case "UpdateExpression":
6010
+ sub(node.argument, false, false, "readwrite");
6011
+ return;
6012
+ case "ForInStatement":
6013
+ case "ForOfStatement":
6014
+ sub(node.left, false, false, "write");
6015
+ sub(node.right);
6016
+ sub(node.body);
6017
+ return;
6018
+ case "AssignmentPattern":
6019
+ sub(node.left, binding, false, access);
6020
+ sub(node.right);
6021
+ return;
6022
+ case "ObjectPattern":
6023
+ case "ArrayPattern":
6024
+ case "RestElement":
6025
+ for (const key of [
6026
+ "properties",
6027
+ "elements",
6028
+ "argument"
6029
+ ]) sub(node[key], binding, false, access);
6030
+ return;
6031
+ default: for (const key in node) {
6032
+ if (key === "type" || key === "start" || key === "end") continue;
6033
+ const v = node[key];
6034
+ if (typeof v === "object" && v !== null) sub(v);
6035
+ }
6010
6036
  }
6011
6037
  }
6012
6038
  }
@@ -13371,15 +13397,18 @@ var BLOCK_MACROS = new NameSet([
13371
13397
  ]);
13372
13398
  /**
13373
13399
  * The block widgets (those whose body renders `{@children}`), kept apart from
13374
- * BLOCK_MACROS: a widget is redefined, so it is a block only while its latest
13375
- * definition is, whereas the macros in BLOCK_MACROS stay blocks.
13400
+ * built-in defaults: a widget is a block only while its latest definition is.
13376
13401
  */
13377
13402
  var BLOCK_WIDGETS = new NameSet();
13378
13403
  /** All widgets, including inline ones, override built-in parsing semantics. */
13379
13404
  var WIDGETS = new NameSet();
13380
13405
  /** Classification owned by defineMacro, independent of explicit registrations. */
13381
13406
  var DEFINED_BLOCK_MACROS = new NameSet();
13407
+ var DEFINED_MACROS = new NameSet();
13408
+ /** Explicit registrations remain independent of macro/widget replacements. */
13409
+ var REGISTERED_BLOCK_MACROS = new NameSet();
13382
13410
  function setDefinedBlockMacro(name, isBlock) {
13411
+ DEFINED_MACROS.add(name);
13383
13412
  setClassification(DEFINED_BLOCK_MACROS, name, isBlock);
13384
13413
  }
13385
13414
  /** Update the classification owned by one registration source. */
@@ -13395,7 +13424,10 @@ function isRawMacro(name, widget = WIDGETS.has(name)) {
13395
13424
  }
13396
13425
  /** Whether a macro takes a body closed by `{/name}`. */
13397
13426
  function isBlockMacro(name) {
13398
- return BLOCK_MACROS.has(name) || DEFINED_BLOCK_MACROS.has(name) || BLOCK_WIDGETS.has(name);
13427
+ if (REGISTERED_BLOCK_MACROS.has(name)) return true;
13428
+ if (WIDGETS.has(name)) return BLOCK_WIDGETS.has(name);
13429
+ if (DEFINED_MACROS.has(name)) return DEFINED_BLOCK_MACROS.has(name);
13430
+ return BLOCK_MACROS.has(name);
13399
13431
  }
13400
13432
  /**
13401
13433
  * Record whether the widget `name` takes a body, as its latest definition
@@ -14098,7 +14130,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
14098
14130
  const rest = source.slice(base);
14099
14131
  const result = attempt(rest, base);
14100
14132
  if (Array.isArray(result)) {
14101
- tokens.push(...result);
14133
+ for (const token of result) tokens.push(token);
14102
14134
  break;
14103
14135
  }
14104
14136
  const at = base + result.offset;
@@ -14111,7 +14143,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
14111
14143
  cut = prefix.offset;
14112
14144
  prefix = attempt(rest.slice(0, cut), base);
14113
14145
  }
14114
- tokens.push(...prefix);
14146
+ for (const token of prefix) tokens.push(token);
14115
14147
  damage.push(base + cut);
14116
14148
  if (cut < rest.length) {
14117
14149
  const start = base + cut;
@@ -14867,6 +14899,27 @@ function extractOptions(children) {
14867
14899
  return options;
14868
14900
  }
14869
14901
  //#endregion
14902
+ //#region src/markup/expansion-budget.ts
14903
+ /** Shared bounds for reparsing markup inside labels, selectors and attributes. */
14904
+ var MarkupExpansionBudget = class MarkupExpansionBudget {
14905
+ static {
14906
+ this.maxDepth = 64;
14907
+ }
14908
+ constructor(sourceLength) {
14909
+ this.depth = 0;
14910
+ this.remaining = Math.max(65536, sourceLength * 8);
14911
+ }
14912
+ enter(length) {
14913
+ if (this.depth >= MarkupExpansionBudget.maxDepth || length > this.remaining) return false;
14914
+ this.remaining -= length;
14915
+ this.depth++;
14916
+ return true;
14917
+ }
14918
+ leave() {
14919
+ this.depth--;
14920
+ }
14921
+ };
14922
+ //#endregion
14870
14923
  //#region src/code-check.ts
14871
14924
  /** While a pass runs: the code it parsed so far, by goal and source. */
14872
14925
  var parses = null;
@@ -15017,6 +15070,7 @@ function* codeAndText(src, tokens, parametersOf) {
15017
15070
  offset: token.targetStart,
15018
15071
  length: token.targetEnd - token.targetStart,
15019
15072
  macro: "link",
15073
+ ...usesBuiltinSemantics("link", parametersOf) && { navigation: true },
15020
15074
  label: src.slice(token.start, token.end)
15021
15075
  };
15022
15076
  if (token.display.includes("{")) yield textPiece(token.display, token.displayStart, "In the label of a link: ");
@@ -15086,7 +15140,10 @@ function* codeAndText(src, tokens, parametersOf) {
15086
15140
  continue;
15087
15141
  }
15088
15142
  const params = parametersOf(name);
15089
- if (params) yield* argPieces(args, argsAt, params, token.name, label);
15143
+ if (params) {
15144
+ const navigation = usesBuiltinSemantics(name, parametersOf) ? name === "goto" || name === "link" ? ["passage"] : name === "watch" ? ["goto"] : [] : [];
15145
+ yield* argPieces(args, argsAt, params, token.name, label, navigation);
15146
+ }
15090
15147
  if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
15091
15148
  }
15092
15149
  }
@@ -15100,37 +15157,50 @@ function* codeAndText(src, tokens, parametersOf) {
15100
15157
  function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
15101
15158
  let position;
15102
15159
  const locate = (offset) => (position ??= sourcePositions(src))(offset);
15103
- yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0, locate);
15160
+ yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0, locate, new MarkupExpansionBudget(src.length));
15104
15161
  }
15105
15162
  /**
15106
15163
  * The pieces of `tokens`, the tokens of `src`, which is the text described by
15107
15164
  * `where` (none for `root`, the markup of the whole passage), and whose
15108
15165
  * offsets `toRoot` turns into offsets in `root`.
15109
15166
  */
15110
- function* expand(root, src, tokens, parametersOf, options, toRoot, where, locate) {
15167
+ function* expand(root, src, tokens, parametersOf, options, toRoot, where, locate, budget) {
15111
15168
  for (const flat of codeAndText(src, tokens, parametersOf)) {
15112
15169
  const piece = where ? nestedPiece(flat, toRoot, where) : flat;
15113
15170
  if (flat.kind !== "text" || !flat.text.includes("{")) {
15114
15171
  yield piece;
15115
15172
  continue;
15116
15173
  }
15117
- const toText = (i) => toRoot(pieceOffset(flat, i));
15118
- const inner = analyzeMarkup(flat.text, {
15119
- text: true,
15120
- hooks: {
15121
- ...options.isBlock && { isBlock: options.isBlock },
15122
- isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0)
15123
- }
15124
- });
15125
- yield {
15126
- ...piece,
15127
- tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
15128
- errors: inner.errors.map((e) => {
15129
- const { line, column } = locate(toText(e.offset));
15130
- return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
15131
- })
15132
- };
15133
- yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where, locate);
15174
+ const toText = (i) => pieceOffset(piece, i);
15175
+ if (!budget.enter(flat.text.length)) {
15176
+ const at = toText(0);
15177
+ const { line, column } = locate(at);
15178
+ yield {
15179
+ ...piece,
15180
+ errors: [new MarkupError("Markup in labels and attributes exceeds the nesting or work limit", at, line, column, "nesting-limit", toText(flat.text.length), { limit: String(MarkupExpansionBudget.maxDepth) })]
15181
+ };
15182
+ continue;
15183
+ }
15184
+ try {
15185
+ const inner = analyzeMarkup(flat.text, {
15186
+ text: true,
15187
+ hooks: {
15188
+ ...options.isBlock && { isBlock: options.isBlock },
15189
+ isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0)
15190
+ }
15191
+ });
15192
+ yield {
15193
+ ...piece,
15194
+ tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
15195
+ errors: inner.errors.map((e) => {
15196
+ const { line, column } = locate(toText(e.offset));
15197
+ return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
15198
+ })
15199
+ };
15200
+ yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where, locate, budget);
15201
+ } finally {
15202
+ budget.leave();
15203
+ }
15134
15204
  }
15135
15205
  }
15136
15206
  /** `piece`, of a text in another, with its offsets turned by `toRoot`. */
@@ -15209,7 +15279,7 @@ function escapeOffsets(raw, at, value, escapes) {
15209
15279
  return escaped ? offsets : void 0;
15210
15280
  }
15211
15281
  /** The code and text in the arguments `args` (at `offset`) of `macro`. */
15212
- function* argPieces(args, offset, params, macro, label) {
15282
+ function* argPieces(args, offset, params, macro, label, navigation = []) {
15213
15283
  let values;
15214
15284
  const spans = /* @__PURE__ */ new Map();
15215
15285
  try {
@@ -15226,7 +15296,7 @@ function* argPieces(args, offset, params, macro, label) {
15226
15296
  };
15227
15297
  return;
15228
15298
  }
15229
- yield* valuePieces(args, offset, params, values, spans, macro, label, "quotes");
15299
+ yield* valuePieces(args, offset, params, values, spans, macro, label, "quotes", navigation);
15230
15300
  }
15231
15301
  /**
15232
15302
  * The code and text in the arguments `args` (at `offset`) of the widget
@@ -15259,7 +15329,7 @@ function* widgetPieces(args, offset, params, macro, label) {
15259
15329
  * (at `offset`), whose `spans` tell where each was written and whose strings
15260
15330
  * are unescaped as `escapes` says.
15261
15331
  */
15262
- function* valuePieces(args, offset, params, values, spans, macro, label, escapes) {
15332
+ function* valuePieces(args, offset, params, values, spans, macro, label, escapes, navigation = []) {
15263
15333
  const name = macro.toLowerCase();
15264
15334
  /** The pieces of the parameters `list`, with their values in `from`. */
15265
15335
  function* visit(list, from) {
@@ -15280,7 +15350,8 @@ function* valuePieces(args, offset, params, values, spans, macro, label, escapes
15280
15350
  offset: offset + start,
15281
15351
  length: end - start,
15282
15352
  macro: name,
15283
- label
15353
+ label,
15354
+ ...navigation.includes(param.name) && { navigation: true }
15284
15355
  });
15285
15356
  const goal = codeGoal(param);
15286
15357
  if (param.type === "passage") {
@@ -15409,18 +15480,19 @@ registeredParameters.source = getMacroParameters.source;
15409
15480
  * Whether the text of an attribute value or macro label renders a
15410
15481
  * `{@children}`: it is markup, parsed as the renderer parses it.
15411
15482
  */
15412
- function textContainsChildren(text, parametersOf, hooks) {
15483
+ function textContainsChildren(text, parametersOf, hooks, budget = new MarkupExpansionBudget(text.length)) {
15413
15484
  if (!text.includes("{")) return false;
15414
- let nodes;
15485
+ if (!budget.enter(text.length)) return false;
15415
15486
  try {
15416
- nodes = parseMarkup(text, {
15487
+ return astContainsChildren(parseMarkup(text, {
15417
15488
  text: true,
15418
15489
  hooks
15419
- });
15490
+ }), parametersOf, hooks, budget);
15420
15491
  } catch {
15421
15492
  return false;
15493
+ } finally {
15494
+ budget.leave();
15422
15495
  }
15423
- return astContainsChildren(nodes, parametersOf, hooks);
15424
15496
  }
15425
15497
  /**
15426
15498
  * Whether a tag renders a `{@children}` in an attribute value or a macro
@@ -15430,19 +15502,21 @@ function textContainsChildren(text, parametersOf, hooks) {
15430
15502
  * are read from it); a token made from an AST has none. Discovery hooks
15431
15503
  * also apply inside these texts, before widgets have been registered.
15432
15504
  */
15433
- function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks) {
15434
- for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks)) return true;
15505
+ function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks, budget) {
15506
+ for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks, budget)) return true;
15435
15507
  return false;
15436
15508
  }
15437
15509
  /**
15438
- * Recursively scan an AST node array for a VariableNode
15510
+ * Scan an AST node array for a VariableNode
15439
15511
  * with scope 'local' and name 'children' (@children), in the content and in
15440
15512
  * the attributes and labels that render markup. A nested `{widget}` is not
15441
15513
  * entered: its slot belongs to the innermost widget (as widgetDefinitions
15442
15514
  * reads it), and a definition renders nothing of its own.
15443
15515
  */
15444
- function astContainsChildren(nodes, parametersOf = registeredParameters, hooks) {
15445
- for (const node of nodes) {
15516
+ function astContainsChildren(nodes, parametersOf = registeredParameters, hooks, budget) {
15517
+ const pending = [...nodes];
15518
+ while (pending.length) {
15519
+ const node = pending.pop();
15446
15520
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
15447
15521
  if (node.type !== "html" && node.type !== "macro") continue;
15448
15522
  if (node.type === "macro" && node.name.toLowerCase() === "widget") continue;
@@ -15465,10 +15539,9 @@ function astContainsChildren(nodes, parametersOf = registeredParameters, hooks)
15465
15539
  nameEnd: 0,
15466
15540
  argsStart: 0,
15467
15541
  argsEnd: 0
15468
- }, parametersOf, "", hooks) || astContainsChildren(node.children, parametersOf, hooks)) return true;
15469
- if (node.type === "macro" && node.branches) {
15470
- for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf, hooks)) return true;
15471
- }
15542
+ }, parametersOf, "", hooks, budget)) return true;
15543
+ for (const child of node.children) pending.push(child);
15544
+ if (node.type === "macro" && node.branches) for (const branch of node.branches) for (const child of branch.children) pending.push(child);
15472
15545
  }
15473
15546
  return false;
15474
15547
  }
@@ -15555,6 +15628,7 @@ function widgetDefinitions(passages, parametersOf = registeredParameters) {
15555
15628
  const hooks = { isRaw: (name) => isRawMacro(name, replacesDo || parametersOf.widget?.(name) !== void 0) };
15556
15629
  for (const passage of list) {
15557
15630
  if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
15631
+ const budget = new MarkupExpansionBudget(passage.content.length);
15558
15632
  const open = [];
15559
15633
  const done = [];
15560
15634
  for (const token of tokenizeMarkupTolerant(passage.content, { hooks }).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
@@ -15569,7 +15643,7 @@ function widgetDefinitions(passages, parametersOf = registeredParameters) {
15569
15643
  closeStart: token.start
15570
15644
  });
15571
15645
  }
15572
- } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks))) open[open.length - 1].isBlock = true;
15646
+ } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks, budget))) open[open.length - 1].isBlock = true;
15573
15647
  done.push(...open);
15574
15648
  const defs = [];
15575
15649
  for (const { token, isBlock, closeStart } of done) try {
@@ -19180,9 +19254,8 @@ function initializeStory(session) {
19180
19254
  if (!session) recordStoryInitState();
19181
19255
  }
19182
19256
  //#endregion
19183
- //#region src/store.ts
19184
- enablePatches();
19185
- enableMapSet();
19257
+ //#region src/passage-roles.ts
19258
+ /** Runtime-owned passage roles, shared with stateless authoring tools. */
19186
19259
  var SPECIAL_PASSAGES = /* @__PURE__ */ new Set([
19187
19260
  "StoryInit",
19188
19261
  "StoryInterface",
@@ -19200,6 +19273,10 @@ var SPECIAL_PASSAGES = /* @__PURE__ */ new Set([
19200
19273
  function isSpecialPassage(name) {
19201
19274
  return SPECIAL_PASSAGES.has(name);
19202
19275
  }
19276
+ //#endregion
19277
+ //#region src/store.ts
19278
+ enablePatches();
19279
+ enableMapSet();
19203
19280
  /** Full variable snapshot at history index 0. */
19204
19281
  var variableBase = createNamespace();
19205
19282
  /**
@@ -20108,13 +20185,13 @@ var useStoryStore = create()(storyStore((set, get) => ({
20108
20185
  setVariable: (name, value) => {
20109
20186
  set((state) => {
20110
20187
  checkVariableName(name, `$${name}`);
20111
- state.variables[name] = value;
20188
+ setByPath(state.variables, [name], value);
20112
20189
  });
20113
20190
  },
20114
20191
  setTemporary: (name, value) => {
20115
20192
  set((state) => {
20116
20193
  checkVariableName(name, `_${name}`);
20117
- state.temporary[name] = value;
20194
+ setByPath(state.temporary, [name], value);
20118
20195
  });
20119
20196
  },
20120
20197
  deleteVariable: (name) => {
@@ -20132,7 +20209,7 @@ var useStoryStore = create()(storyStore((set, get) => ({
20132
20209
  setTransient: (name, value) => {
20133
20210
  set((state) => {
20134
20211
  checkVariableName(name, `%${name}`);
20135
- state.transient[name] = value;
20212
+ setByPath(state.transient, [name], value);
20136
20213
  });
20137
20214
  },
20138
20215
  deleteTransient: (name) => {
@@ -21899,7 +21976,7 @@ function observe() {
21899
21976
  text: body ? observableText(body, DIALOG) : ""
21900
21977
  }));
21901
21978
  const errors = [
21902
- passageEl,
21979
+ document.getElementById("root") ?? passageEl,
21903
21980
  ...bodies.map((d) => d.body),
21904
21981
  contextEl
21905
21982
  ].flatMap((el) => el ? observableErrors(el, DIALOG, el === contextEl ? el : void 0) : []);
@@ -22400,6 +22477,13 @@ function validateMarkup(passages, options) {
22400
22477
  report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
22401
22478
  break;
22402
22479
  case "passage":
22480
+ if (piece.navigation && isSpecialPassage(piece.name)) {
22481
+ report(passage, at, at + piece.length, "special-passage", `${where}Cannot navigate to special passage ${JSON.stringify(piece.name)} in ${piece.label}.`, {
22482
+ name: piece.name,
22483
+ macro: piece.macro
22484
+ });
22485
+ break;
22486
+ }
22403
22487
  if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
22404
22488
  const best = closestName(piece.name, passageNames);
22405
22489
  report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
@@ -23149,7 +23233,15 @@ function scanSigilReferences(value, at, emit) {
23149
23233
  */
23150
23234
  function scanInterpolations(text, at, emit, options) {
23151
23235
  if (!text.includes("{")) return;
23152
- collectTokenRefs(text, tokensOf(text, true, options), at, emit, options);
23236
+ const budget = options.expansionBudget;
23237
+ if (!budget.enter(text.length)) return;
23238
+ try {
23239
+ const offset = at(0);
23240
+ const sourceOffsets = at(text.length) - offset === text.length ? void 0 : Array.from({ length: text.length + 1 }, (_, i) => at(i));
23241
+ collectTokenRefs(text, tokensOf(text, true, options), (i) => sourceOffsets?.[i] ?? offset + i, emit, options);
23242
+ } finally {
23243
+ budget.leave();
23244
+ }
23153
23245
  }
23154
23246
  /**
23155
23247
  * Report `$var` references in JavaScript code, lexed as the expression
@@ -23331,7 +23423,10 @@ function collectTokenRefs(content, tokens, at, emit, options) {
23331
23423
  */
23332
23424
  function collectVariableReferences(content, options) {
23333
23425
  const found = [];
23334
- withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), options));
23426
+ withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), {
23427
+ ...options,
23428
+ expansionBudget: new MarkupExpansionBudget(content.length)
23429
+ }));
23335
23430
  return found.sort((a, b) => a.start - b.start);
23336
23431
  }
23337
23432
  /**