@rohal12/spindle 0.59.27 → 0.59.29

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.
@@ -10128,18 +10128,29 @@ var widgets = new NameMap();
10128
10128
  * that no namespace can hold (`@__proto__`) throws a TypeError and the
10129
10129
  * widget is not registered.
10130
10130
  */
10131
- function registerWidget(name, bodyAST, params, isBlock = false) {
10131
+ function registerWidget(name, bodyAST, params, isBlock = false, holds = {}) {
10132
10132
  const filteredParams = params.filter((p) => p !== "@children");
10133
10133
  for (const param of filteredParams) if (param.startsWith("@")) checkVariableName(param.slice(1), param);
10134
10134
  widgets.set(name, {
10135
10135
  body: bodyAST,
10136
10136
  params: filteredParams,
10137
+ holds,
10137
10138
  isBlock
10138
10139
  });
10139
10140
  }
10140
10141
  function getWidget(name) {
10141
10142
  return widgets.get(name);
10142
10143
  }
10144
+ /** The widgets as `parameterLookup` reads them (see MacroParameters). */
10145
+ function widgetMacros() {
10146
+ return [...widgets].map(([name, { params, holds }]) => ({
10147
+ name,
10148
+ widget: {
10149
+ params,
10150
+ holds
10151
+ }
10152
+ }));
10153
+ }
10143
10154
  //#endregion
10144
10155
  //#region src/utils/parse-delay.ts
10145
10156
  /**
@@ -10336,19 +10347,19 @@ function topLevelIndices(src, isSeparator) {
10336
10347
  return indices;
10337
10348
  }
10338
10349
  /**
10339
- * Split `src` at every depth-0 separator (see `topLevelIndices`). Segments
10340
- * are returned as written, untrimmed, and empty segments are kept, so
10350
+ * The segments of `src` between its depth-0 separators (see
10351
+ * `topLevelIndices`), as spans: untrimmed, and empty segments are kept, so
10341
10352
  * `n` separators always give `n + 1` segments.
10342
10353
  */
10343
- function splitTopLevel(src, isSeparator) {
10344
- const segments = [];
10354
+ function topLevelSpans(src, isSeparator) {
10355
+ const spans = [];
10345
10356
  let from = 0;
10346
10357
  for (const i of topLevelIndices(src, isSeparator)) {
10347
- segments.push(src.slice(from, i));
10358
+ spans.push([from, i]);
10348
10359
  from = i + 1;
10349
10360
  }
10350
- segments.push(src.slice(from));
10351
- return segments;
10361
+ spans.push([from, src.length]);
10362
+ return spans;
10352
10363
  }
10353
10364
  /**
10354
10365
  * Check whether a whitespace-delimited token looks like a standalone value
@@ -10373,29 +10384,44 @@ function startsLikeValue(token) {
10373
10384
  * Try to split a raw string on whitespace at depth 0 (respecting strings,
10374
10385
  * template literals, parentheses, brackets, and braces). Each resulting token
10375
10386
  * must pass `isStandaloneValue()` or the split is rejected and `null` is
10376
- * returned.
10387
+ * returned. The spans are those of the tokens in `raw`.
10377
10388
  */
10378
10389
  function trySplitOnWhitespace(raw) {
10379
- const args = splitTopLevel(raw, isWhitespace).filter(Boolean);
10390
+ const args = topLevelSpans(raw, isWhitespace).filter(([a, b]) => b > a);
10380
10391
  if (args.length < 2) return null;
10381
- for (const arg of args) if (!isStandaloneValue(arg)) return null;
10392
+ for (const [a, b] of args) if (!isStandaloneValue(raw.slice(a, b))) return null;
10382
10393
  return args;
10383
10394
  }
10395
+ /** `span` less the whitespace at its ends. */
10396
+ function trimmed$1(src, [start, end]) {
10397
+ const text = src.slice(start, end);
10398
+ const lead = text.length - text.trimStart().length;
10399
+ return [start + lead, Math.max(start + lead, end - (text.length - text.trimEnd().length))];
10400
+ }
10384
10401
  /**
10385
- * Split rawArgs by commas, respecting parentheses, brackets, braces, and
10386
- * strings. When no top-level commas are present, also supports adjacent quoted
10387
- * string literals separated by whitespace (e.g. `"Label" "target"`).
10402
+ * Where the arguments in `raw` are written (see `splitArgs`), as spans of
10403
+ * `raw`.
10388
10404
  */
10389
- function splitArgs(raw) {
10390
- const args = splitTopLevel(raw, (ch) => ch === ",").map((a) => a.trim());
10405
+ function splitArgSpans(raw) {
10406
+ const args = topLevelSpans(raw, (ch) => ch === ",").map((span) => trimmed$1(raw, span));
10391
10407
  const hasComma = args.length > 1;
10392
- if (args[args.length - 1] === "") args.pop();
10408
+ const last = args[args.length - 1];
10409
+ if (last[0] === last[1]) args.pop();
10393
10410
  if (!hasComma && args.length === 1) {
10394
- const split = trySplitOnWhitespace(args[0]);
10395
- if (split) return split;
10411
+ const [start, end] = args[0];
10412
+ const split = trySplitOnWhitespace(raw.slice(start, end));
10413
+ if (split) return split.map(([a, b]) => [start + a, start + b]);
10396
10414
  }
10397
10415
  return args;
10398
10416
  }
10417
+ /**
10418
+ * Split rawArgs by commas, respecting parentheses, brackets, braces, and
10419
+ * strings. When no top-level commas are present, also supports adjacent quoted
10420
+ * string literals separated by whitespace (e.g. `"Label" "target"`).
10421
+ */
10422
+ function splitArgs(raw) {
10423
+ return splitArgSpans(raw).map(([a, b]) => raw.slice(a, b));
10424
+ }
10399
10425
  //#endregion
10400
10426
  //#region src/components/macros/macro-args.ts
10401
10427
  /**
@@ -10764,6 +10790,18 @@ var CONDITION_MACROS = /* @__PURE__ */ new Set([
10764
10790
  /** Block macros whose body is the name of a passage. */
10765
10791
  var PASSAGE_BODIES = /* @__PURE__ */ new Set(["dialog"]);
10766
10792
  /**
10793
+ * The parameters of a widget given its `@` parameters and what they declare
10794
+ * to hold, or none when it declares nothing (a call is then not read by
10795
+ * parameter).
10796
+ */
10797
+ function widgetParameters(params, holds = {}) {
10798
+ if (!params.some((param) => hasOwn(holds, param))) return void 0;
10799
+ return params.map((name) => ({
10800
+ name,
10801
+ ...hasOwn(holds, name) ? { holds: holds[name] } : {}
10802
+ }));
10803
+ }
10804
+ /**
10767
10805
  * `params` with each `string` and `text` parameter (options too) saying
10768
10806
  * what it holds: what it declares, else `holds`.
10769
10807
  */
@@ -10785,11 +10823,17 @@ function withHolds(params, holds) {
10785
10823
  * collection and tooling read arguments by. Each `string` and `text`
10786
10824
  * parameter says what it holds: what it declares, else `markup` for a macro
10787
10825
  * with `interpolate` (which can resolve markup) and `text` for any other.
10826
+ * A widget among `macros` says what its parameters hold (see ParametersOf).
10788
10827
  */
10789
10828
  function parameterLookup(macros) {
10790
10829
  const parameters = new NameMap();
10791
- for (const { name, parameters: params, interpolate } of macros) if (params) parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
10792
- return (name) => {
10830
+ const widgets = new NameMap();
10831
+ for (const { name, parameters: params, interpolate, widget } of macros) {
10832
+ if (params) parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
10833
+ const declared = widget && widgetParameters(widget.params, widget.holds);
10834
+ if (declared) widgets.set(name, declared);
10835
+ }
10836
+ const lookup = (name) => {
10793
10837
  let params = parameters.get(name);
10794
10838
  if (!params) {
10795
10839
  const sub = subMacroParameters(name);
@@ -10797,6 +10841,8 @@ function parameterLookup(macros) {
10797
10841
  }
10798
10842
  return params;
10799
10843
  };
10844
+ if (widgets.size > 0) lookup.widget = (name) => widgets.get(name);
10845
+ return lookup;
10800
10846
  }
10801
10847
  /** What a `string` or `text` argument holds when its parameter doesn't say. */
10802
10848
  var holdsByDefault = (interpolate) => interpolate ? "markup" : "text";
@@ -10899,6 +10945,8 @@ function* codeAndText(src, tokens, parametersOf) {
10899
10945
  }
10900
10946
  const params = parametersOf(name);
10901
10947
  if (params) yield* argPieces(args, argsAt, params, token.name, label);
10948
+ const widget = parametersOf.widget?.(name);
10949
+ if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
10902
10950
  }
10903
10951
  }
10904
10952
  }
@@ -10990,7 +11038,6 @@ function escapeOffsets(raw, at, value) {
10990
11038
  }
10991
11039
  /** The code and text in the arguments `args` (at `offset`) of `macro`. */
10992
11040
  function* argPieces(args, offset, params, macro, label) {
10993
- const name = macro.toLowerCase();
10994
11041
  let values;
10995
11042
  const spans = /* @__PURE__ */ new Map();
10996
11043
  try {
@@ -11003,10 +11050,44 @@ function* argPieces(args, offset, params, macro, label) {
11003
11050
  offset,
11004
11051
  length: args.length,
11005
11052
  label,
11006
- macro: name
11053
+ macro: macro.toLowerCase()
11007
11054
  };
11008
11055
  return;
11009
11056
  }
11057
+ yield* valuePieces(args, offset, params, values, spans, macro, label);
11058
+ }
11059
+ /**
11060
+ * The code and text in the arguments `args` (at `offset`) of the widget
11061
+ * `macro`, the ones whose parameter declares what it holds. Such an argument
11062
+ * is checked when it is one quoted string, as a `string` parameter with that
11063
+ * `holds` of a macro is; any other expression is its value at run time.
11064
+ */
11065
+ function* widgetPieces(args, offset, params, macro, label) {
11066
+ const written = splitArgSpans(args);
11067
+ const declared = [];
11068
+ const values = {};
11069
+ const spans = /* @__PURE__ */ new Map();
11070
+ params.forEach(({ name, holds }, i) => {
11071
+ const span = written[i];
11072
+ const value = span && stringLiteralValue(args.slice(...span));
11073
+ if (!holds || value == null) return;
11074
+ const param = {
11075
+ name,
11076
+ type: "string",
11077
+ holds
11078
+ };
11079
+ declared.push(param);
11080
+ values[name] = value;
11081
+ spans.set(param, span);
11082
+ });
11083
+ yield* valuePieces(args, offset, declared, values, spans, macro, label);
11084
+ }
11085
+ /**
11086
+ * The pieces of the `params` of `macro` with the `values` read from `args`
11087
+ * (at `offset`), whose `spans` tell where each was written.
11088
+ */
11089
+ function* valuePieces(args, offset, params, values, spans, macro, label) {
11090
+ const name = macro.toLowerCase();
11010
11091
  /** The pieces of the parameters `list`, with their values in `from`. */
11011
11092
  function* visit(list, from) {
11012
11093
  for (const param of list) {
@@ -11341,15 +11422,39 @@ var WIDGET_PARAMETERS = [{
11341
11422
  /**
11342
11423
  * The widget a {widget} definition's arguments declare: its name and its
11343
11424
  * parameters, the words after it that start with `@` (docs/widgets.md),
11344
- * separated by spaces or commas (`@a, @b`). Other words, such as `$name`, are
11345
- * not parameters.
11425
+ * separated by spaces or commas (`@a, @b`). A parameter may say what its
11426
+ * argument holds after a colon (`@target:passage`, one of the `holds` of a
11427
+ * macro parameter; another word is a `badHolds`). Other words, such as
11428
+ * `$name`, are not parameters.
11346
11429
  */
11347
11430
  function widgetDef({ name = "", parameters = "" }) {
11431
+ const params = [];
11432
+ const holds = {};
11433
+ const badHolds = [];
11434
+ for (const word of parameters.split(/[\s,]+/)) {
11435
+ if (!word.startsWith("@")) continue;
11436
+ const [param = word, written] = word.split(/:(.*)/s);
11437
+ params.push(param);
11438
+ if (written === void 0) continue;
11439
+ if (STRING_HOLDS.includes(written)) holds[param] = written;
11440
+ else badHolds.push({
11441
+ param,
11442
+ written
11443
+ });
11444
+ }
11348
11445
  return {
11349
11446
  name,
11350
- params: parameters.split(/[\s,]+/).filter((word) => word.startsWith("@"))
11447
+ params,
11448
+ ...Object.keys(holds).length > 0 ? { holds } : {},
11449
+ ...badHolds.length > 0 ? { badHolds } : {}
11351
11450
  };
11352
11451
  }
11452
+ /** Throw if a parameter of `def` declares what it holds wrongly. */
11453
+ function checkWidgetHolds({ name, badHolds = [] }) {
11454
+ const [bad] = badHolds;
11455
+ if (!bad) return;
11456
+ throw new Error(`spindle: The widget parameter ${bad.param} of {widget "${name}"} holds the unknown ${JSON.stringify(bad.written)}. Write one of ${STRING_HOLDS.join(", ")} after the colon (see docs/widgets.md#what-an-argument-holds).`);
11457
+ }
11353
11458
  /** Read the arguments of a {widget} definition (see widgetDef). */
11354
11459
  function parseWidgetDef(rawArgs) {
11355
11460
  return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
@@ -11426,12 +11531,14 @@ function blockWidgetNames(passages, parametersOf = registeredParameters) {
11426
11531
  * Register the widget a definition declares, with its body. Widgets whose
11427
11532
  * body renders {@children} take a closing tag, so they are registered as
11428
11533
  * block macros too: passages parsed later nest their content. A parameter
11429
- * that no namespace can hold throws (see registerWidget), registering
11430
- * nothing.
11534
+ * that no namespace can hold or declares what it holds wrongly throws (see
11535
+ * registerWidget and checkWidgetHolds), registering nothing.
11431
11536
  */
11432
- function registerWidgetDef({ name, params }, body) {
11537
+ function registerWidgetDef(def, body) {
11538
+ checkWidgetHolds(def);
11539
+ const { name, params, holds } = def;
11433
11540
  const isBlock = astContainsChildren(body);
11434
- registerWidget(name, body, params, isBlock);
11541
+ registerWidget(name, body, params, isBlock, holds);
11435
11542
  if (isBlock) registerBlockMacro(name);
11436
11543
  }
11437
11544
  /**
@@ -13012,11 +13119,25 @@ function resolveAttributeValue(name, value, scope, errors) {
13012
13119
  function isBlankText(n) {
13013
13120
  return n.type === "text" && (n.comment === true || n.value.trim() === "");
13014
13121
  }
13015
- /** The index of the summary element opening `nodes`, or -1 when none does. */
13016
- function leadingSummaryIndex(nodes) {
13122
+ /**
13123
+ * The element a container must open with, to stay its direct child: the
13124
+ * summary of a details element (#382), the legend of a fieldset (#475), whose
13125
+ * first legend exempts the controls in it from the fieldset's `disabled`.
13126
+ */
13127
+ var LEADING_PARTS = {
13128
+ details: "summary",
13129
+ fieldset: "legend"
13130
+ };
13131
+ /**
13132
+ * The index of the node opening `nodes` as the leading part of the `tag`
13133
+ * container, or -1 when none does: the element itself, or a macro, which may
13134
+ * render it ({if}, {include}, a widget: #474).
13135
+ */
13136
+ function leadingPartIndex(tag, nodes) {
13137
+ const part = LEADING_PARTS[tag];
13017
13138
  const at = nodes.findIndex((n) => !isBlankText(n));
13018
13139
  const first = nodes[at];
13019
- return first?.type === "html" && first.tag.toLowerCase() === "summary" ? at : -1;
13140
+ return part && (first?.type === "macro" || first?.type === "html" && first.tag.toLowerCase() === part) ? at : -1;
13020
13141
  }
13021
13142
  function HtmlNodeRenderer({ node }) {
13022
13143
  const scope = useTextScope();
@@ -13024,6 +13145,8 @@ function HtmlNodeRenderer({ node }) {
13024
13145
  const inSvg = useContext(SvgContext);
13025
13146
  const tag = node.tag.toLowerCase();
13026
13147
  const isSvgRoot = tag === "svg";
13148
+ const isHtmlRoot = inSvg && tag === "foreignobject";
13149
+ const rawContent = inRaw && !isHtmlRoot;
13027
13150
  const isRawRoot = !inRaw && (isSvgRoot || PREFORMATTED_ELEMENTS.has(tag));
13028
13151
  const errors = [];
13029
13152
  const { props, direct } = splitAttributes(Object.entries(node.attributes).map(([k, v]) => [
@@ -13038,19 +13161,19 @@ function HtmlNodeRenderer({ node }) {
13038
13161
  let structural = false;
13039
13162
  if (node.children.length > 0) {
13040
13163
  if (tag === "style") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
13041
- else if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
13164
+ else if (rawContent || isRawRoot) children = renderInlineNodes(node.children);
13042
13165
  else {
13043
- const summaryAt = tag === "details" ? leadingSummaryIndex(node.children) : -1;
13166
+ const leadAt = leadingPartIndex(tag, node.children);
13044
13167
  const body = (nodes) => renderNodes(nodes, {
13045
13168
  nobr,
13046
13169
  locals,
13047
13170
  inline: isInline
13048
13171
  });
13049
13172
  structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || isBlankText(n));
13050
- children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
13051
- body(node.children.slice(0, summaryAt)),
13052
- renderSingleNode(node.children[summaryAt]),
13053
- body(node.children.slice(summaryAt + 1))
13173
+ children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : leadAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
13174
+ body(node.children.slice(0, leadAt)),
13175
+ renderSingleNode(node.children[leadAt]),
13176
+ body(node.children.slice(leadAt + 1))
13054
13177
  ] });
13055
13178
  if (isInline !== parentInline) children = /* @__PURE__ */ jsx(InlineContext.Provider, {
13056
13179
  value: isInline,
@@ -13062,9 +13185,12 @@ function HtmlNodeRenderer({ node }) {
13062
13185
  });
13063
13186
  }
13064
13187
  }
13065
- if (inSvg && tag === "foreignobject" && children) children = /* @__PURE__ */ jsx(SvgContext.Provider, {
13188
+ if (isHtmlRoot && children) children = /* @__PURE__ */ jsx(SvgContext.Provider, {
13066
13189
  value: false,
13067
- children
13190
+ children: /* @__PURE__ */ jsx(RawTextContext.Provider, {
13191
+ value: false,
13192
+ children
13193
+ })
13068
13194
  });
13069
13195
  let element = h(node.tag, props, children);
13070
13196
  if (isSvgRoot && !inSvg) element = /* @__PURE__ */ jsx(SvgContext.Provider, {
@@ -16754,11 +16880,22 @@ var clonersFor = (paths) => {
16754
16880
  function frozenCopy(value) {
16755
16881
  return freeze(cloneValue(value), true);
16756
16882
  }
16883
+ /**
16884
+ * Whether a built-in's mutators can still change a frozen `value` (#473):
16885
+ * Object.freeze() locks properties, not internal slots. Immer locks a Map or
16886
+ * Set it freezes by overriding its mutators with own properties; a Date, URL
16887
+ * or URLSearchParams has no such lock, and one frozen by hand has none either.
16888
+ */
16889
+ function hasUnlockedSlots(value) {
16890
+ if (value instanceof Map) return !hasOwn(value, "set");
16891
+ if (value instanceof Set) return !hasOwn(value, "add");
16892
+ return value instanceof Date || value instanceof URL || value instanceof URLSearchParams;
16893
+ }
16757
16894
  /** Whether `value` and everything it holds is frozen. */
16758
16895
  function deeplyFrozen(value, seen = /* @__PURE__ */ new Set()) {
16759
16896
  if (typeof value !== "object" || value === null || seen.has(value)) return true;
16760
16897
  if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return false;
16761
- if (!Object.isFrozen(value)) return false;
16898
+ if (!Object.isFrozen(value) || hasUnlockedSlots(value)) return false;
16762
16899
  seen.add(value);
16763
16900
  if (value instanceof Map) {
16764
16901
  for (const [key, entry] of mapEntries(value)) if (!deeplyFrozen(key, seen) || !deeplyFrozen(entry, seen)) return false;
@@ -17930,6 +18067,12 @@ function loadedEntryMoment(payload) {
17930
18067
  if (typeof moment.variables !== "object" || moment.variables === null) return;
17931
18068
  return moment;
17932
18069
  }
18070
+ /** The variable paths `Story.set` writes while a save's hooks run. */
18071
+ var hookWrites = null;
18072
+ /** Note that `path` of the variables was written (see keepHookWrites). */
18073
+ function recordHookWrite(path) {
18074
+ hookWrites?.set(pathKey(path), path);
18075
+ }
17933
18076
  /**
17934
18077
  * Write the changes between `before` and `after` (the live variables around
17935
18078
  * the `beforesave` hooks) into the payload's snapshot of the saved moment. A
@@ -17943,10 +18086,22 @@ function loadedEntryMoment(payload) {
17943
18086
  * snapshot's own object of it (#302). Only the payload's copy changes: the
17944
18087
  * live history keeps the recorded snapshot (#159).
17945
18088
  */
17946
- function keepHookWrites(payload, before, after) {
18089
+ function keepHookWrites(payload, before, after, written) {
17947
18090
  const moment = payload.history[payload.historyIndex];
17948
18091
  if (!moment) return;
17949
18092
  const changes = changesBetween(before, after, true);
18093
+ const keys = new Set(changes.map((c) => pathKey(c.path)));
18094
+ for (const path of written) {
18095
+ if (underChange(path, keys)) continue;
18096
+ keys.add(pathKey(path));
18097
+ const value = getByPath(after, path);
18098
+ if (deepEqual(getByPath(moment.variables, path), value)) continue;
18099
+ changes.push({
18100
+ path,
18101
+ deleted: false,
18102
+ value
18103
+ });
18104
+ }
17950
18105
  if (changes.length === 0) return;
17951
18106
  const work = deepClone(moment.variables);
17952
18107
  const seen = existingObjects(locateObjects(after, changes), work);
@@ -18463,9 +18618,12 @@ var useStoryStore = create()(storyStore((set, get) => ({
18463
18618
  },
18464
18619
  beginSave: () => {
18465
18620
  const before = get().variables;
18621
+ const writes = /* @__PURE__ */ new Map();
18622
+ hookWrites = writes;
18466
18623
  return () => {
18624
+ if (hookWrites === writes) hookWrites = null;
18467
18625
  const payload = get().getSavePayload();
18468
- keepHookWrites(payload, before, get().variables);
18626
+ keepHookWrites(payload, before, get().variables, [...writes.values()]);
18469
18627
  return payload;
18470
18628
  };
18471
18629
  },
@@ -19742,6 +19900,7 @@ function createStoryAPI() {
19742
19900
  for (const [name] of entries) {
19743
19901
  const { isTransient, key } = parseName(name);
19744
19902
  warnIfUndeclared(isTransient, key);
19903
+ if (!isTransient) recordHookWrite(key.split("."));
19745
19904
  }
19746
19905
  if (entries.some(([k]) => k.includes("."))) {
19747
19906
  mutateState((work, adopt) => {
@@ -22412,6 +22571,7 @@ defineMacro({
22412
22571
  try {
22413
22572
  const def = widgetDef(ctx.args);
22414
22573
  for (const param of def.params) checkVariableName(param.slice(1), param);
22574
+ checkWidgetHolds(def);
22415
22575
  parsed = def;
22416
22576
  } catch (err) {
22417
22577
  error = err;
@@ -23453,6 +23613,18 @@ function stopWithErrors(errors) {
23453
23613
  throw new Error(`spindle: ${errors.length} validation error(s):\n${errors.join("\n")}`);
23454
23614
  }
23455
23615
  /**
23616
+ * The result of `parse`, or, when it throws, the error shown on the page
23617
+ * instead of the story (a declaration that does not evaluate, a widget passage
23618
+ * that does not parse), prefixed with `where` when that is not in the message.
23619
+ */
23620
+ function orStop(parse, where = "") {
23621
+ try {
23622
+ return parse();
23623
+ } catch (err) {
23624
+ return stopWithErrors([where + errorMessage(err)]);
23625
+ }
23626
+ }
23627
+ /**
23456
23628
  * The undeclared variables the passages refer to, with the macros known now:
23457
23629
  * the input macros that bind a variable (registered by author JS or
23458
23630
  * StoryInit) and the roles of their parameters decide what is a reference.
@@ -23471,7 +23643,7 @@ function markupErrors(storyData, only) {
23471
23643
  return validateMarkup(storyData.passages.values(), {
23472
23644
  isKnownMacro: (name) => !!getMacro(name) || isSubMacro(name) || !!getWidget(name),
23473
23645
  macroNames: macros.map((m) => m.name),
23474
- parametersOf: parameterLookup(macros),
23646
+ parametersOf: parameterLookup([...macros, ...widgetMacros()]),
23475
23647
  only
23476
23648
  }).map(formatDiagnostic);
23477
23649
  }
@@ -23509,14 +23681,14 @@ function boot() {
23509
23681
  if (root) renderErrors(root, [msg]);
23510
23682
  throw new Error(`spindle: ${msg}`);
23511
23683
  }
23512
- const schema = parseStoryVariables(storyVarsPassage.content);
23513
- for (const name of blockWidgetNames(storyData.passages.values())) registerBlockMacro(name);
23684
+ const schema = orStop(() => parseStoryVariables(storyVarsPassage.content));
23685
+ for (const name of orStop(() => blockWidgetNames(storyData.passages.values()))) registerBlockMacro(name);
23514
23686
  const errors = variableErrors(storyData, schema);
23515
23687
  errors.push(...markupErrors(storyData, (p) => p.name === "StoryInit"));
23516
23688
  let transientDefaults = {};
23517
23689
  const storyTransientsPassage = storyData.passages.get("StoryTransients");
23518
23690
  if (storyTransientsPassage) {
23519
- const transientSchema = parseStoryVariables(storyTransientsPassage.content, "%");
23691
+ const transientSchema = orStop(() => parseStoryVariables(storyTransientsPassage.content, "%"));
23520
23692
  for (const name of transientSchema.keys()) if (schema.has(name)) errors.push(`StoryTransients: Variable "${name}" is already declared in StoryVariables. Names must be unique across scopes.`);
23521
23693
  transientDefaults = extractDefaults(transientSchema);
23522
23694
  }
@@ -23525,7 +23697,7 @@ function boot() {
23525
23697
  setDeclaredVariables(Object.keys(defaults), Object.keys(transientDefaults));
23526
23698
  useStoryStore.getState().init(storyData, defaults, transientDefaults);
23527
23699
  enterRuntimePhase();
23528
- for (const [, passage] of storyData.passages) if (passage.tags.includes("widget")) registerWidgetDefinitions(parseMarkup(passage.content), passage.name);
23700
+ for (const [, passage] of storyData.passages) if (passage.tags.includes("widget")) orStop(() => registerWidgetDefinitions(parseMarkup(passage.content), passage.name), `Passage "${passage.name}": `);
23529
23701
  initializeStory(loadSession(storyData.ifid));
23530
23702
  const markup = [...variableErrors(storyData, schema), ...markupErrors(storyData, (p) => p.name !== "StoryInit")];
23531
23703
  if (markup.length > 0) stopWithErrors(markup);