@rohal12/spindle 0.59.20 → 0.59.22

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.
@@ -130,9 +130,10 @@ var NO_SELECTORS = {};
130
130
  var EMAIL_AUTOLINK = /^<[a-zA-Z0-9.!#$%&'*+/=?^_`|~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*>$/;
131
131
  /**
132
132
  * A link's display text and target, from its text `inner` (at `at` in the
133
- * input), with where the target is written.
133
+ * input), with where the target is written. `indexOf(separator)` finds a
134
+ * separator that is written outside markup (see linkSeparatorIndex).
134
135
  */
135
- function parseLink(inner, at) {
136
+ function parseLink(inner, at, indexOf) {
136
137
  /** The trimmed text from `start` to `end` of inner, and where it is. */
137
138
  const part = (start, end) => {
138
139
  const raw = inner.slice(start, end);
@@ -145,7 +146,7 @@ function parseLink(inner, at) {
145
146
  };
146
147
  };
147
148
  for (const [separator, targetFirst] of LINK_SEPARATORS) {
148
- const idx = inner.indexOf(separator);
149
+ const idx = indexOf(separator);
149
150
  if (idx === -1) continue;
150
151
  const before = part(0, idx);
151
152
  const after = part(idx + separator.length, inner.length);
@@ -827,7 +828,7 @@ function peg$parse(input, options) {
827
828
  return !textMode;
828
829
  }
829
830
  function peg$f50(s, at, inner) {
830
- return withSelectors(lexeme("link", location(), parseLink(inner, at)), s);
831
+ return withSelectors(lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator))), s);
831
832
  }
832
833
  function peg$f51() {
833
834
  return !textMode;
@@ -3730,6 +3731,24 @@ function peg$parse(input, options) {
3730
3731
  let attrCode = false;
3731
3732
  /** The macro whose raw body is being read. */
3732
3733
  let rawName = "";
3734
+ /**
3735
+ * The index in `inner` (at `at` in the input) of the first `separator` that
3736
+ * is not inside a {…} of the label: its code (`{if $a || $b}`, a string with
3737
+ * a pipe) belongs to the label, not to the link's syntax.
3738
+ */
3739
+ function linkSeparatorIndex(inner, at, separator) {
3740
+ for (let i = 0; i < inner.length; i++) {
3741
+ const c = inner.charAt(i);
3742
+ if (c === "\\" && /[{}]/.test(inner.charAt(i + 1))) i++;
3743
+ else if (c === LB) {
3744
+ const head = /^(?:[.#][\w-]*)* ?(\/?[a-zA-Z][\w-]*|(?=[$_@%(!]))/.exec(inner.slice(i + 1));
3745
+ if (!head) continue;
3746
+ const close = hooks.closeBrace(input, at + i + 1 + head[0].length, at + i + 1);
3747
+ if (close !== -1 && close < at + inner.length) i = close - at;
3748
+ } else if (inner.startsWith(separator, i)) return i;
3749
+ }
3750
+ return -1;
3751
+ }
3733
3752
  function skipTo(end) {
3734
3753
  skipEnd = end;
3735
3754
  return end >= 0;
@@ -12124,6 +12143,7 @@ function useRenderOptions() {
12124
12143
  nobr: useContext(NobrContext),
12125
12144
  inline: useContext(InlineContext),
12126
12145
  raw: useContext(RawTextContext),
12146
+ structural: useContext(StructuralContext),
12127
12147
  locals: useContext(LocalsValuesContext)
12128
12148
  };
12129
12149
  }
@@ -12455,6 +12475,13 @@ var InterfaceContext = createContext(false);
12455
12475
  */
12456
12476
  var InlineContext = createContext(false);
12457
12477
  /**
12478
+ * True while rendering the content of a structural HTML element (see
12479
+ * STRUCTURAL_ELEMENTS) whose own children are all elements: macro and widget
12480
+ * bodies read it so the elements they produce (the rows of a `{for}`) stay
12481
+ * its direct children (#436). An element resets it for its own content.
12482
+ */
12483
+ var StructuralContext = createContext(false);
12484
+ /**
12458
12485
  * True while rendering inside an element whose content is not markdown: SVG
12459
12486
  * (whose namespace `<p>` wrappers would break) and the preformatted `<pre>`
12460
12487
  * `<textarea>` and `<style>`, whose text (indentation, `#`, `*`, ...) is literal.
@@ -12937,7 +12964,7 @@ function leadingSummaryIndex(nodes) {
12937
12964
  }
12938
12965
  function HtmlNodeRenderer({ node }) {
12939
12966
  const scope = useTextScope();
12940
- const { nobr, locals, raw: inRaw, inline: parentInline } = useRenderOptions();
12967
+ const { nobr, locals, raw: inRaw, inline: parentInline, structural: parentStructural } = useRenderOptions();
12941
12968
  const inSvg = useContext(SvgContext);
12942
12969
  const tag = node.tag.toLowerCase();
12943
12970
  const isSvgRoot = tag === "svg";
@@ -12952,6 +12979,7 @@ function HtmlNodeRenderer({ node }) {
12952
12979
  if (ref) props.ref = ref;
12953
12980
  const isInline = INLINE_ELEMENTS.has(tag);
12954
12981
  let children = void 0;
12982
+ let structural = false;
12955
12983
  if (node.children.length > 0) if (inRaw || isRawRoot) children = renderInlineNodes(node.children);
12956
12984
  else {
12957
12985
  const summaryAt = tag === "details" ? leadingSummaryIndex(node.children) : -1;
@@ -12960,7 +12988,8 @@ function HtmlNodeRenderer({ node }) {
12960
12988
  locals,
12961
12989
  inline: isInline
12962
12990
  });
12963
- children = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || n.value.trim() === "") ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
12991
+ structural = STRUCTURAL_ELEMENTS.has(tag) && node.children.every((n) => n.type !== "text" || n.value.trim() === "");
12992
+ children = structural ? node.children.filter((n) => n.type !== "text").map((n) => renderSingleNode(n)) : summaryAt === -1 ? body(node.children) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
12964
12993
  body(node.children.slice(0, summaryAt)),
12965
12994
  renderSingleNode(node.children[summaryAt]),
12966
12995
  body(node.children.slice(summaryAt + 1))
@@ -12969,6 +12998,10 @@ function HtmlNodeRenderer({ node }) {
12969
12998
  value: isInline,
12970
12999
  children
12971
13000
  });
13001
+ if (structural !== parentStructural) children = /* @__PURE__ */ jsx(StructuralContext.Provider, {
13002
+ value: structural,
13003
+ children
13004
+ });
12972
13005
  }
12973
13006
  if (inSvg && tag === "foreignobject" && children) children = /* @__PURE__ */ jsx(SvgContext.Provider, {
12974
13007
  value: false,
@@ -13128,6 +13161,7 @@ function buildPlainTextVnodes(core, ph, unwrapParagraphs) {
13128
13161
  function renderNodes(nodes, options) {
13129
13162
  if (nodes.length === 0) return null;
13130
13163
  if (options?.raw) return renderInlineNodes(nodes);
13164
+ if (options?.structural && nodes.every((n) => n.type !== "text" || n.value.trim() === "")) return nodes.filter((n) => n.type !== "text").map(renderSingleNode);
13131
13165
  if (!nodes.some((n) => n.type === "text" && (n.value.trim() !== "" || BLANK_LINE_RE.test(n.value)))) return nodes.map((node) => renderSingleNode(node));
13132
13166
  const components = [];
13133
13167
  const ph = {
@@ -14631,6 +14665,13 @@ function lsSet(key, value) {
14631
14665
  function lsDel(key) {
14632
14666
  localStorage.removeItem(key);
14633
14667
  }
14668
+ /** Put an item back as it was (`raw` null: absent); best effort. */
14669
+ function lsRestore(key, raw) {
14670
+ try {
14671
+ if (raw === null) localStorage.removeItem(key);
14672
+ else localStorage.setItem(key, raw);
14673
+ } catch {}
14674
+ }
14634
14675
  function lsIndex(key) {
14635
14676
  return lsGet(key) ?? [];
14636
14677
  }
@@ -14664,11 +14705,21 @@ function createLocalStorageBackend() {
14664
14705
  async put(key, value) {
14665
14706
  const previous = lsGet(`${prefix}${key}`);
14666
14707
  const lists = listsOf(value);
14667
- if (previous !== void 0) {
14668
- for (const list of listsOf(previous)) if (!lists.includes(list)) lsIndexRemove(list, key);
14708
+ const obsolete = previous === void 0 ? [] : listsOf(previous).filter((list) => !lists.includes(list));
14709
+ const touched = [
14710
+ `${prefix}${key}`,
14711
+ ...obsolete,
14712
+ ...lists
14713
+ ];
14714
+ const before = touched.map((k) => localStorage.getItem(k));
14715
+ try {
14716
+ for (const list of obsolete) lsIndexRemove(list, key);
14717
+ lsSet(`${prefix}${key}`, value);
14718
+ for (const list of lists) lsIndexAdd(list, key);
14719
+ } catch (err) {
14720
+ touched.forEach((k, i) => lsRestore(k, before[i] ?? null));
14721
+ throw err;
14669
14722
  }
14670
- lsSet(`${prefix}${key}`, value);
14671
- for (const list of lists) lsIndexAdd(list, key);
14672
14723
  },
14673
14724
  async delete(key) {
14674
14725
  const record = lsGet(`${prefix}${key}`);
@@ -15785,6 +15836,8 @@ function generateTitleNow(payload) {
15785
15836
  });
15786
15837
  return `${payload.passage} - ${time}`;
15787
15838
  }
15839
+ /** The browser lock every storage operation holds, across tabs. */
15840
+ var OPERATION_LOCK = "spindle-saves";
15788
15841
  /** Tail of the queue every storage operation runs through. */
15789
15842
  var operationQueue = Promise.resolve();
15790
15843
  /**
@@ -15801,7 +15854,7 @@ var operationQueue = Promise.resolve();
15801
15854
  * must never wait for another operation queued after it.
15802
15855
  */
15803
15856
  function inOrder(op) {
15804
- const run = operationQueue.then(op);
15857
+ const run = operationQueue.then(() => withTabLock(OPERATION_LOCK, op));
15805
15858
  operationQueue = run.catch(() => {});
15806
15859
  return run;
15807
15860
  }
@@ -15963,6 +16016,7 @@ async function createSaveNow(ifid, playthroughPromise, payload, custom = {}) {
15963
16016
  custom
15964
16017
  }, payload);
15965
16018
  await (await getBackend()).putSave(record);
16019
+ announceSlots(ifid);
15966
16020
  return record;
15967
16021
  }
15968
16022
  /**
@@ -16027,6 +16081,7 @@ function deleteSaveById(saveId) {
16027
16081
  await backend.deleteSave(saveId);
16028
16082
  if (!record) return;
16029
16083
  await emptySlotsHolding(record.meta.ifid, (id) => id === saveId);
16084
+ announceSlots(record.meta.ifid);
16030
16085
  });
16031
16086
  }
16032
16087
  function renameSave(saveId, newTitle) {
@@ -16044,6 +16099,7 @@ function renameSave(saveId, newTitle) {
16044
16099
  }
16045
16100
  };
16046
16101
  await backend.putSave(updated);
16102
+ announceSlots(updated.meta.ifid);
16047
16103
  });
16048
16104
  }
16049
16105
  var getSavesGrouped = queued(async function getSavesGroupedNow(ifid) {
@@ -16407,6 +16463,7 @@ function importSave(data, ifid) {
16407
16463
  return inOrder(async () => {
16408
16464
  const record = await prepareImport(data, ifid);
16409
16465
  await (await getBackend()).putSave(record);
16466
+ announceSlots(ifid);
16410
16467
  return record;
16411
16468
  });
16412
16469
  }
@@ -16496,6 +16553,7 @@ function deletePlaythroughData(ifid, playthroughId, replacement) {
16496
16553
  await backend.deletePlaythroughById(playthroughId);
16497
16554
  const deletedSet = new Set(deletedSaveIds);
16498
16555
  await emptySlotsHolding(ifid, (id) => deletedSet.has(id));
16556
+ announceSlots(ifid);
16499
16557
  if (replacement && await replacement.current === playthroughId) {
16500
16558
  await startNewPlaythroughNow(ifid, replacement.id);
16501
16559
  return true;
@@ -17746,6 +17804,17 @@ var latestStateApplied = 0;
17746
17804
  var slotLoadApplying = null;
17747
17805
  /** The playthrough the slot load calling loadFromPayload leaves. */
17748
17806
  var slotLoadLeaving = null;
17807
+ /**
17808
+ * Take a place in the order of replacements for a load that reads before it
17809
+ * applies (the save dialog's): see isStateReplacementSuperseded.
17810
+ */
17811
+ function issueStateReplacement() {
17812
+ return ++stateReplacementsIssued;
17813
+ }
17814
+ /** Whether a replacement issued after `n` has been applied. */
17815
+ function isStateReplacementSuperseded(n) {
17816
+ return latestStateApplied > n;
17817
+ }
17749
17818
  /** A replacement of the game state applied at its call. */
17750
17819
  function replaceStateNow() {
17751
17820
  applyReplacement(++stateReplacementsIssued);
@@ -18338,8 +18407,8 @@ var useStoryStore = create()(storyStore((set, get) => ({
18338
18407
  return payload;
18339
18408
  };
18340
18409
  },
18341
- loadFromPayload: (payload, slot, playthroughId) => {
18342
- const applying = slotLoadApplying;
18410
+ loadFromPayload: (payload, slot, playthroughId, issued) => {
18411
+ const applying = slotLoadApplying ?? issued;
18343
18412
  slotLoadApplying = null;
18344
18413
  const leaving = slotLoadLeaving;
18345
18414
  slotLoadLeaving = null;
@@ -18578,6 +18647,7 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18578
18647
  } else next = backwards ? last : first;
18579
18648
  (next ?? (backwards ? last : first)).focus();
18580
18649
  };
18650
+ let steppingMedia = null;
18581
18651
  const onKeyDown = (e) => {
18582
18652
  if (!top()) return;
18583
18653
  if (e.key === "Escape") {
@@ -18588,8 +18658,19 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18588
18658
  return;
18589
18659
  }
18590
18660
  if (e.key !== "Tab") return;
18661
+ const active = document.activeElement;
18662
+ if (active instanceof HTMLMediaElement && active.controls) {
18663
+ steppingMedia = {
18664
+ el: active,
18665
+ backwards: e.shiftKey
18666
+ };
18667
+ return;
18668
+ }
18591
18669
  e.preventDefault();
18592
- moveFocus(document.activeElement, e.shiftKey);
18670
+ moveFocus(active, e.shiftKey);
18671
+ };
18672
+ const onPointerDown = () => {
18673
+ steppingMedia = null;
18593
18674
  };
18594
18675
  const controller = new AbortController();
18595
18676
  const { signal } = controller;
@@ -18632,11 +18713,28 @@ function useModalFocus(panelRef, bodySelector, dismissible, onClose) {
18632
18713
  attachFrames();
18633
18714
  const onFocusIn = (e) => {
18634
18715
  const target = e.target;
18716
+ if (steppingMedia && target !== steppingMedia.el && top()) {
18717
+ const { el, backwards } = steppingMedia;
18718
+ steppingMedia = null;
18719
+ moveFocus(el, backwards);
18720
+ return;
18721
+ }
18635
18722
  if (!top() || !(target instanceof Node) || panel.contains(target)) return;
18636
18723
  if (target === document.body || target === document.documentElement) return;
18637
18724
  moveFocus(null, false);
18638
18725
  };
18639
18726
  document.addEventListener("keydown", onKeyDown, { signal });
18727
+ document.addEventListener("pointerdown", onPointerDown, {
18728
+ capture: true,
18729
+ signal
18730
+ });
18731
+ const onFocusOut = (e) => {
18732
+ const pending = steppingMedia;
18733
+ if (!pending || e.target !== pending.el || e.relatedTarget || !top()) return;
18734
+ steppingMedia = null;
18735
+ moveFocus(pending.el, pending.backwards);
18736
+ };
18737
+ document.addEventListener("focusout", onFocusOut, { signal });
18640
18738
  document.addEventListener("focusin", onFocusIn, { signal });
18641
18739
  return () => {
18642
18740
  controller.abort();
@@ -21164,7 +21262,7 @@ var frozenAlways = () => true;
21164
21262
  */
21165
21263
  function useDetachedBody() {
21166
21264
  const updater = useContext(LocalsUpdateContext);
21167
- const { nobr, inline } = useRenderOptions();
21265
+ const { nobr, inline, structural } = useRenderOptions();
21168
21266
  const widgetChildren = useContext(WidgetChildrenContext);
21169
21267
  const repeat = useContext(RepeatContext);
21170
21268
  const closeDialog = useContext(DialogCloseContext);
@@ -21196,20 +21294,24 @@ function useDetachedBody() {
21196
21294
  value: nobr,
21197
21295
  children: /* @__PURE__ */ jsx(InlineContext.Provider, {
21198
21296
  value: inline,
21199
- children: /* @__PURE__ */ jsx(WidgetChildrenContext.Provider, {
21200
- value: widgetChildren,
21201
- children: /* @__PURE__ */ jsx(RepeatContext.Provider, {
21202
- value: repeat,
21203
- children: /* @__PURE__ */ jsx(DialogCloseContext.Provider, {
21204
- value: closeDialog,
21205
- children: /* @__PURE__ */ jsx(ItemEditContext.Provider, {
21206
- value: inIteration,
21207
- children: /* @__PURE__ */ jsx(OutgoingContext.Provider, {
21208
- value: hasLeft,
21209
- children: renderNodes(children, {
21210
- nobr,
21211
- inline,
21212
- locals
21297
+ children: /* @__PURE__ */ jsx(StructuralContext.Provider, {
21298
+ value: structural,
21299
+ children: /* @__PURE__ */ jsx(WidgetChildrenContext.Provider, {
21300
+ value: widgetChildren,
21301
+ children: /* @__PURE__ */ jsx(RepeatContext.Provider, {
21302
+ value: repeat,
21303
+ children: /* @__PURE__ */ jsx(DialogCloseContext.Provider, {
21304
+ value: closeDialog,
21305
+ children: /* @__PURE__ */ jsx(ItemEditContext.Provider, {
21306
+ value: inIteration,
21307
+ children: /* @__PURE__ */ jsx(OutgoingContext.Provider, {
21308
+ value: hasLeft,
21309
+ children: renderNodes(children, {
21310
+ nobr,
21311
+ inline,
21312
+ structural,
21313
+ locals
21314
+ })
21213
21315
  })
21214
21316
  })
21215
21317
  })
@@ -21823,9 +21925,11 @@ function SaveManagerContent() {
21823
21925
  }
21824
21926
  };
21825
21927
  const handleLoad = async (save) => {
21928
+ const replacement = issueStateReplacement();
21826
21929
  try {
21827
21930
  const current = await getSaveRecord(save.meta.id) ?? save;
21828
- loadFromPayload(decodeSavePayload(current.payload), void 0, current.meta.playthroughId);
21931
+ if (isStateReplacementSuperseded(replacement)) return;
21932
+ loadFromPayload(decodeSavePayload(current.payload), void 0, current.meta.playthroughId, replacement);
21829
21933
  showStatus("Game loaded");
21830
21934
  if (closeDialog) closeTimer.current = window.setTimeout(closeDialog, 500);
21831
21935
  await refresh();
@@ -21833,19 +21937,25 @@ function SaveManagerContent() {
21833
21937
  showStatus("Failed to load save", "error");
21834
21938
  }
21835
21939
  };
21940
+ /** Run `op`, then tell the player how it went and list the saves again. */
21941
+ const runAction = async (done, failed, op) => {
21942
+ try {
21943
+ await op();
21944
+ showStatus(done);
21945
+ await refresh();
21946
+ } catch {
21947
+ showStatus(failed, "error");
21948
+ }
21949
+ };
21836
21950
  const handleDelete = async (saveId) => {
21837
21951
  if (!confirm("Delete this save?")) return;
21838
- try {
21952
+ await runAction("Save deleted", "Failed to delete save", async () => {
21839
21953
  await deleteSaveById(saveId);
21840
21954
  const known = await populateKnownSaves(ifid);
21841
21955
  useStoryStore.setState((state) => {
21842
21956
  state.knownSaves = known;
21843
21957
  });
21844
- showStatus("Save deleted");
21845
- await refresh();
21846
- } catch {
21847
- showStatus("Failed to delete save", "error");
21848
- }
21958
+ });
21849
21959
  };
21850
21960
  const handleRenameStart = (save) => {
21851
21961
  renameCancelled.current = false;
@@ -21853,15 +21963,12 @@ function SaveManagerContent() {
21853
21963
  setRenameValue(save.meta.title);
21854
21964
  };
21855
21965
  const handleRenameConfirm = async () => {
21856
- if (!renamingId || !renameValue.trim()) return;
21857
- try {
21858
- await renameSave(renamingId, renameValue.trim());
21859
- setRenamingId(null);
21860
- showStatus("Save renamed");
21861
- await refresh();
21862
- } catch {
21863
- showStatus("Failed to rename", "error");
21864
- }
21966
+ const id = renamingId;
21967
+ if (!id || !renameValue.trim()) return;
21968
+ await runAction("Save renamed", "Failed to rename", async () => {
21969
+ await renameSave(id, renameValue.trim());
21970
+ setRenamingId((current) => current === id ? null : current);
21971
+ });
21865
21972
  };
21866
21973
  const handleRenameKeyDown = (e) => {
21867
21974
  if (e.key === "Enter") handleRenameConfirm();
@@ -22534,7 +22641,7 @@ defineMacro({
22534
22641
  });
22535
22642
  //#endregion
22536
22643
  //#region src/styles.css?inline
22537
- var styles_default = "*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\nhtml {\n font-size: 16px;\n -webkit-text-size-adjust: 100%;\n}\n\nbody {\n margin: 0;\n padding: 0;\n font-family: Georgia, 'Times New Roman', serif;\n line-height: 1.75;\n color: #e0e0e0;\n background-color: #1a1a2e;\n min-height: 100vh;\n}\n\ntw-storydata {\n display: none !important;\n}\n\n#story {\n max-width: 42em;\n margin: 0 auto;\n padding: 2em 1.5em;\n}\n\n/* Passage transitions */\n\n.passage-container {\n position: relative;\n}\n\n.passage-container--crossfading {\n display: grid;\n}\n\n.passage-container--crossfading > * {\n grid-area: 1 / 1;\n}\n\n.passage {\n animation: passage-fade-in var(--passage-in-duration, 0.3s) ease;\n}\n\n.passage[data-transition='none'] {\n animation: none;\n}\n\n.passage-snapshot {\n animation: passage-fade-out var(--passage-out-duration, 0.3s) ease forwards;\n pointer-events: none;\n user-select: none;\n}\n\n@keyframes passage-fade-in {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes passage-fade-out {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(-8px);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .passage,\n .passage-snapshot {\n animation-duration: 0.01s !important;\n }\n}\n\n.macro-button {\n background: rgba(100, 181, 246, 0.15);\n color: #64b5f6;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 4px;\n padding: 0.25em 0.75em;\n font: inherit;\n font-size: 0.95em;\n cursor: pointer;\n transition:\n background 0.2s,\n border-color 0.2s;\n}\n\n.macro-button:hover {\n background: rgba(100, 181, 246, 0.25);\n border-color: #90caf9;\n}\n\n.macro-button:active {\n background: rgba(100, 181, 246, 0.35);\n}\n\n.error {\n color: #ef5350;\n font-family: monospace;\n padding: 1em;\n border: 1px solid #ef5350;\n border-radius: 4px;\n background: rgba(239, 83, 80, 0.1);\n}\n\n/* Runtime errors shown on the page (see src/components/RuntimeErrors.tsx) */\n.spindle-error-banners {\n position: fixed;\n top: 0.75em;\n left: 50%;\n z-index: 300;\n display: flex;\n flex-direction: column;\n gap: 0.5em;\n width: min(42em, calc(100% - 1.5em));\n transform: translateX(-50%);\n}\n\n.spindle-error-banner {\n position: relative;\n padding: 0.75em 2.75em 0.75em 1em;\n border: 1px solid #ef5350;\n border-radius: 4px;\n background: #2b1a1e;\n color: #ffcdd2;\n font-size: 0.9em;\n line-height: 1.5;\n box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);\n}\n\n.spindle-error-banner-message {\n font-family: monospace;\n color: #ef9a9a;\n}\n\n.spindle-error-banner-dismiss {\n position: absolute;\n top: 0.5em;\n right: 0.5em;\n background: transparent;\n border: none;\n color: inherit;\n font-size: 1em;\n cursor: pointer;\n}\n\n.spindle-error-banner-dismiss:hover {\n color: #fff;\n}\n\n.loading {\n text-align: center;\n padding: 2em;\n opacity: 0.6;\n}\n\n/* Menu bar */\n\n.story-menubar {\n position: sticky;\n top: 0;\n z-index: 100;\n display: flex;\n align-items: center;\n gap: 0.5em;\n padding: 0.5em 1.5em;\n background: #16213e;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n font-family: system-ui, sans-serif;\n font-size: 0.9em;\n}\n\n.story-title {\n flex: 1;\n font-weight: 600;\n color: #e0e0e0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.menubar-button {\n background: transparent;\n color: #9e9e9e;\n border: 1px solid transparent;\n padding: 0.35em 0.7em;\n border-radius: 4px;\n cursor: pointer;\n font: inherit;\n transition:\n color 0.2s,\n background 0.2s;\n}\n\n.menubar-button:hover {\n color: #e0e0e0;\n background: rgba(255, 255, 255, 0.08);\n}\n\n.menubar-button:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.menubar-button:disabled:hover {\n color: #9e9e9e;\n background: transparent;\n}\n\n/* Generic dialog */\n\n.dialog-overlay {\n position: fixed;\n inset: 0;\n z-index: 200;\n display: flex;\n align-items: center;\n justify-content: center;\n background: rgba(0, 0, 0, 0.6);\n}\n\n.dialog-panel {\n background: #16213e;\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 8px;\n width: 90%;\n max-width: 500px;\n max-height: 80vh;\n display: flex;\n flex-direction: column;\n color: #e0e0e0;\n font-family: system-ui, sans-serif;\n position: relative;\n}\n\n/* Focused programmatically when the dialog has no focusable content */\n.dialog-panel:focus {\n outline: none;\n}\n\n.dialog-saves {\n max-width: 550px;\n}\n\n.dialog-settings {\n max-width: 400px;\n}\n\n/* Keep the first control clear of the close button above it */\n.dialog-settings .dialog-body {\n padding-top: 2.25em;\n}\n\n.dialog-close {\n position: absolute;\n top: 0.75em;\n right: 0.75em;\n z-index: 1;\n background: transparent;\n border: none;\n color: #9e9e9e;\n font-size: 1.1em;\n cursor: pointer;\n padding: 0.25em;\n line-height: 1;\n}\n\n.dialog-close:hover {\n color: #e0e0e0;\n}\n\n.dialog-body {\n overflow-y: auto;\n flex: 1;\n min-height: 0;\n}\n\n/* Settings controls */\n\n.settings-controls {\n padding: 1em 1.25em;\n display: flex;\n flex-direction: column;\n gap: 1em;\n}\n\n.settings-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 1em;\n}\n\n.settings-row select,\n.settings-row input[type='range'] {\n accent-color: #64b5f6;\n}\n\n.settings-row select {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n.settings-row input[type='checkbox'] {\n accent-color: #64b5f6;\n width: 1.1em;\n height: 1.1em;\n}\n\n/* Save manager */\n\n.save-manager {\n display: flex;\n flex-direction: column;\n flex: 1;\n min-height: 0;\n}\n\n.saves-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 1em 1.25em;\n padding-right: 3em;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n font-weight: 600;\n flex-shrink: 0;\n}\n\n.saves-header-left {\n display: flex;\n align-items: center;\n gap: 0.75em;\n}\n\n.saves-mode-toggle {\n display: flex;\n gap: 0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n overflow: hidden;\n}\n\n.saves-mode-toggle button {\n background: transparent;\n color: #9e9e9e;\n border: none;\n padding: 0.3em 0.8em;\n font: inherit;\n font-size: 0.85em;\n font-weight: 600;\n cursor: pointer;\n transition:\n background 0.2s,\n color 0.2s;\n}\n\n.saves-mode-toggle button.active {\n background: rgba(100, 181, 246, 0.2);\n color: #64b5f6;\n}\n\n.saves-mode-toggle button:hover:not(.active) {\n color: #e0e0e0;\n}\n\n.saves-body {\n padding: 0.75em 1.25em;\n overflow-y: auto;\n flex: 1;\n min-height: 0;\n}\n\n.saves-empty {\n text-align: center;\n padding: 2em 1em;\n opacity: 0.5;\n font-size: 0.9em;\n}\n\n.saves-toolbar {\n display: flex;\n gap: 0.5em;\n padding: 0.5em 1.25em;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n flex-shrink: 0;\n}\n\n.saves-toolbar-button {\n background: rgba(255, 255, 255, 0.05);\n color: #9e9e9e;\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 4px;\n padding: 0.3em 0.7em;\n font: inherit;\n font-size: 0.8em;\n cursor: pointer;\n transition:\n background 0.2s,\n color 0.2s;\n}\n\n.saves-toolbar-button:hover {\n background: rgba(255, 255, 255, 0.1);\n color: #e0e0e0;\n}\n\n.playthrough-group {\n margin-bottom: 0.75em;\n}\n\n.playthrough-header {\n display: flex;\n width: 100%;\n border: 0;\n background: none;\n font-family: inherit;\n text-align: left;\n align-items: center;\n gap: 0.5em;\n padding: 0.4em 0;\n cursor: pointer;\n user-select: none;\n font-size: 0.85em;\n color: #9e9e9e;\n transition: color 0.2s;\n}\n\n.playthrough-header:hover {\n color: #e0e0e0;\n}\n\n.playthrough-chevron {\n display: inline-block;\n font-size: 0.7em;\n transition: transform 0.2s;\n}\n\n.playthrough-chevron.open {\n transform: rotate(90deg);\n}\n\n.playthrough-label {\n font-weight: 600;\n}\n\n.playthrough-date {\n opacity: 0.6;\n font-size: 0.9em;\n}\n\n.playthrough-saves {\n display: flex;\n flex-direction: column;\n gap: 0.4em;\n padding-left: 0.25em;\n}\n\n.save-slot {\n display: flex;\n align-items: center;\n gap: 0.75em;\n padding: 0.5em 0.6em;\n background: rgba(255, 255, 255, 0.03);\n border: 1px solid rgba(255, 255, 255, 0.06);\n border-radius: 6px;\n transition: background 0.15s;\n}\n\n.save-slot:hover {\n background: rgba(255, 255, 255, 0.06);\n}\n\n.save-slot-info {\n flex: 1;\n min-width: 0;\n}\n\n.save-slot-title {\n font-weight: 500;\n font-size: 0.9em;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.save-slot-meta {\n font-size: 0.75em;\n color: #9e9e9e;\n display: flex;\n gap: 0.75em;\n}\n\n.save-slot-actions {\n display: flex;\n gap: 0.3em;\n flex-shrink: 0;\n}\n\n.save-slot-action {\n background: transparent;\n color: #9e9e9e;\n border: 1px solid transparent;\n border-radius: 3px;\n padding: 0.2em 0.5em;\n font: inherit;\n font-size: 0.75em;\n cursor: pointer;\n transition:\n color 0.2s,\n background 0.2s;\n white-space: nowrap;\n}\n\n.save-slot-action:hover {\n color: #e0e0e0;\n background: rgba(255, 255, 255, 0.08);\n}\n\n.save-slot-action.primary {\n color: #64b5f6;\n border-color: rgba(100, 181, 246, 0.3);\n}\n\n.save-slot-action.primary:hover {\n background: rgba(100, 181, 246, 0.15);\n}\n\n.save-slot-action.danger:hover {\n color: #ef5350;\n background: rgba(239, 83, 80, 0.1);\n}\n\n.save-slot-new {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0.5em;\n margin-top: 0.25em;\n border: 1px dashed rgba(255, 255, 255, 0.12);\n border-radius: 6px;\n color: #9e9e9e;\n font: inherit;\n font-size: 0.8em;\n background: transparent;\n cursor: pointer;\n width: 100%;\n transition:\n color 0.2s,\n border-color 0.2s,\n background 0.2s;\n}\n\n.save-slot-new:hover {\n color: #64b5f6;\n border-color: rgba(100, 181, 246, 0.3);\n background: rgba(100, 181, 246, 0.05);\n}\n\n.saves-notice {\n padding: 0.5em 1.25em;\n font-size: 0.8em;\n color: #ffb74d;\n border-bottom: 1px solid rgba(255, 183, 77, 0.3);\n background: rgba(255, 183, 77, 0.08);\n flex-shrink: 0;\n}\n\n.saves-status {\n padding: 0.5em 1.25em;\n font-size: 0.8em;\n color: #81c784;\n border-top: 1px solid rgba(255, 255, 255, 0.08);\n flex-shrink: 0;\n text-align: center;\n}\n\n.saves-status.error {\n color: #ef5350;\n border: none;\n border-radius: 0;\n padding: 0.5em 1.25em;\n font-family: inherit;\n background: transparent;\n}\n\n.save-rename-input {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 3px;\n padding: 0.15em 0.4em;\n font: inherit;\n font-size: 0.9em;\n width: 100%;\n}\n\n.save-rename-input:focus {\n outline: none;\n border-color: #64b5f6;\n}\n\n/* Macro: link */\n\n.macro-link {\n color: #64b5f6;\n text-decoration: none;\n border-bottom: 1px solid rgba(100, 181, 246, 0.3);\n transition:\n color 0.2s,\n border-color 0.2s;\n cursor: pointer;\n}\n\n.macro-link:hover {\n color: #90caf9;\n border-bottom-color: #90caf9;\n}\n\n.macro-link:active {\n color: #42a5f5;\n}\n\n/* Macro: form inputs */\n\n.macro-textbox,\n.macro-numberbox,\n.macro-textarea {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n.macro-textbox:focus,\n.macro-numberbox:focus,\n.macro-textarea:focus {\n outline: none;\n border-color: #64b5f6;\n}\n\n.macro-textarea {\n min-height: 3em;\n resize: vertical;\n}\n\n.macro-checkbox,\n.macro-radiobutton {\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n gap: 0.3em;\n}\n\n.macro-checkbox input,\n.macro-radiobutton input {\n accent-color: #64b5f6;\n}\n\n/* Macro: listbox */\n\n.macro-listbox {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n/* Macro: cycle */\n\n.macro-cycle {\n background: rgba(100, 181, 246, 0.15);\n color: #64b5f6;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 4px;\n padding: 0.25em 0.75em;\n font: inherit;\n cursor: pointer;\n transition:\n background 0.2s,\n border-color 0.2s;\n}\n\n.macro-cycle:hover {\n background: rgba(100, 181, 246, 0.25);\n border-color: #90caf9;\n}\n\n/* Macro: meter */\n\n.macro-meter {\n position: relative;\n width: 100%;\n height: 1.4em;\n background: #2a2a3e;\n border-radius: 0.3em;\n overflow: hidden;\n border: 1px solid #444;\n}\n\n.macro-meter-fill {\n height: 100%;\n background: #64b5f6;\n transition: width 0.3s ease;\n}\n\n.macro-meter-label {\n position: absolute;\n inset: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 0.85em;\n color: #e0e0e0;\n text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);\n pointer-events: none;\n}\n\n/* Markdown wrapper — invisible to layout */\n\n.md {\n display: contents;\n}\n\n/* Markdown block elements inside passages */\n\n.passage p {\n margin: 0.6em 0;\n}\n\n.passage p:first-child {\n margin-top: 0;\n}\n\n.passage p:last-child {\n margin-bottom: 0;\n}\n\n.passage h1,\n.passage h2,\n.passage h3,\n.passage h4,\n.passage h5,\n.passage h6 {\n margin: 1em 0 0.4em;\n line-height: 1.3;\n color: #f0f0f0;\n}\n\n.passage h1 {\n font-size: 1.8em;\n}\n.passage h2 {\n font-size: 1.5em;\n}\n.passage h3 {\n font-size: 1.25em;\n}\n.passage h4 {\n font-size: 1.1em;\n}\n.passage h5 {\n font-size: 1em;\n}\n.passage h6 {\n font-size: 0.9em;\n opacity: 0.8;\n}\n\n.passage code {\n font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;\n font-size: 0.9em;\n background: rgba(255, 255, 255, 0.08);\n padding: 0.15em 0.35em;\n border-radius: 3px;\n}\n\n.passage pre {\n background: rgba(0, 0, 0, 0.3);\n border: 1px solid rgba(255, 255, 255, 0.08);\n border-radius: 6px;\n padding: 1em;\n overflow-x: auto;\n margin: 0.8em 0;\n}\n\n.passage pre code {\n background: none;\n padding: 0;\n border-radius: 0;\n font-size: 0.85em;\n}\n\n.passage blockquote {\n border-left: 3px solid rgba(100, 181, 246, 0.5);\n margin: 0.8em 0;\n padding: 0.4em 1em;\n color: #b0b0b0;\n}\n\n.passage blockquote p {\n margin: 0.3em 0;\n}\n\n.passage ul,\n.passage ol {\n margin: 0.6em 0;\n padding-left: 1.8em;\n}\n\n.passage li {\n margin: 0.2em 0;\n}\n\n.passage hr {\n border: none;\n border-top: 1px solid rgba(255, 255, 255, 0.12);\n margin: 1.2em 0;\n}\n\n.passage table {\n border-collapse: collapse;\n width: 100%;\n margin: 0.8em 0;\n}\n\n.passage th,\n.passage td {\n border: 1px solid rgba(255, 255, 255, 0.12);\n padding: 0.5em 0.75em;\n text-align: left;\n}\n\n.passage th {\n background: rgba(255, 255, 255, 0.06);\n font-weight: 600;\n}\n\n.passage tr:nth-child(even) {\n background: rgba(255, 255, 255, 0.02);\n}\n\n.passage del {\n opacity: 0.5;\n}\n\n.passage strong {\n color: #f0f0f0;\n}\n\n/* Macro: type (typewriter) */\n\n.macro-type-cursor::after {\n content: '\\2588';\n animation: type-blink 0.7s step-end infinite;\n color: #64b5f6;\n}\n\n.macro-type-done .macro-type-cursor::after {\n display: none;\n}\n\n@keyframes type-blink {\n 50% {\n opacity: 0;\n }\n}\n";
22644
+ var styles_default = "*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\nhtml {\n font-size: 16px;\n -webkit-text-size-adjust: 100%;\n}\n\nbody {\n margin: 0;\n padding: 0;\n font-family: Georgia, 'Times New Roman', serif;\n line-height: 1.75;\n color: #e0e0e0;\n background-color: #1a1a2e;\n min-height: 100vh;\n}\n\ntw-storydata {\n display: none !important;\n}\n\n#story {\n max-width: 42em;\n margin: 0 auto;\n padding: 2em 1.5em;\n}\n\n/* Passage transitions */\n\n.passage-container {\n position: relative;\n}\n\n.passage-container--crossfading {\n display: grid;\n}\n\n.passage-container--crossfading > * {\n grid-area: 1 / 1;\n}\n\n.passage {\n animation: passage-fade-in var(--passage-in-duration, 0.3s) ease;\n}\n\n.passage[data-transition='none'] {\n animation: none;\n}\n\n.passage-snapshot {\n animation: passage-fade-out var(--passage-out-duration, 0.3s) ease forwards;\n pointer-events: none;\n user-select: none;\n}\n\n@keyframes passage-fade-in {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes passage-fade-out {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(-8px);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .passage,\n .passage-snapshot {\n animation-duration: 0.01s !important;\n }\n}\n\n.macro-button {\n background: rgba(100, 181, 246, 0.15);\n color: #64b5f6;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 4px;\n padding: 0.25em 0.75em;\n font: inherit;\n font-size: 0.95em;\n cursor: pointer;\n transition:\n background 0.2s,\n border-color 0.2s;\n}\n\n.macro-button:hover {\n background: rgba(100, 181, 246, 0.25);\n border-color: #90caf9;\n}\n\n.macro-button:active {\n background: rgba(100, 181, 246, 0.35);\n}\n\n.error {\n color: #ef5350;\n font-family: monospace;\n padding: 1em;\n border: 1px solid #ef5350;\n border-radius: 4px;\n background: rgba(239, 83, 80, 0.1);\n}\n\n/* Runtime errors shown on the page (see src/components/RuntimeErrors.tsx) */\n.spindle-error-banners {\n position: fixed;\n top: 0.75em;\n left: 50%;\n z-index: 300;\n display: flex;\n flex-direction: column;\n gap: 0.5em;\n width: min(42em, calc(100% - 1.5em));\n transform: translateX(-50%);\n}\n\n.spindle-error-banner {\n position: relative;\n padding: 0.75em 2.75em 0.75em 1em;\n border: 1px solid #ef5350;\n border-radius: 4px;\n background: #2b1a1e;\n color: #ffcdd2;\n font-size: 0.9em;\n line-height: 1.5;\n box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);\n}\n\n.spindle-error-banner-message {\n font-family: monospace;\n color: #ef9a9a;\n}\n\n.spindle-error-banner-dismiss {\n position: absolute;\n top: 0.5em;\n right: 0.5em;\n background: transparent;\n border: none;\n color: inherit;\n font-size: 1em;\n cursor: pointer;\n}\n\n.spindle-error-banner-dismiss:hover {\n color: #fff;\n}\n\n.loading {\n text-align: center;\n padding: 2em;\n opacity: 0.6;\n}\n\n/* Menu bar */\n\n.story-menubar {\n position: sticky;\n top: 0;\n z-index: 100;\n display: flex;\n align-items: center;\n gap: 0.5em;\n padding: 0.5em 1.5em;\n background: #16213e;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n font-family: system-ui, sans-serif;\n font-size: 0.9em;\n}\n\n@media (max-width: 600px) {\n .story-menubar {\n flex-wrap: wrap;\n padding: 0.5em 0.75em;\n }\n\n .story-menubar .story-title {\n flex: 1 1 100%;\n }\n}\n\n.story-title {\n flex: 1;\n font-weight: 600;\n color: #e0e0e0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.menubar-button {\n background: transparent;\n color: #9e9e9e;\n border: 1px solid transparent;\n padding: 0.35em 0.7em;\n border-radius: 4px;\n cursor: pointer;\n font: inherit;\n transition:\n color 0.2s,\n background 0.2s;\n}\n\n.menubar-button:hover {\n color: #e0e0e0;\n background: rgba(255, 255, 255, 0.08);\n}\n\n.menubar-button:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.menubar-button:disabled:hover {\n color: #9e9e9e;\n background: transparent;\n}\n\n/* Generic dialog */\n\n.dialog-overlay {\n position: fixed;\n inset: 0;\n z-index: 200;\n display: flex;\n align-items: center;\n justify-content: center;\n background: rgba(0, 0, 0, 0.6);\n}\n\n.dialog-panel {\n background: #16213e;\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 8px;\n width: 90%;\n max-width: 500px;\n max-height: 80vh;\n display: flex;\n flex-direction: column;\n color: #e0e0e0;\n font-family: system-ui, sans-serif;\n position: relative;\n}\n\n/* Focused programmatically when the dialog has no focusable content */\n.dialog-panel:focus {\n outline: none;\n}\n\n.dialog-saves {\n max-width: 550px;\n}\n\n.dialog-settings {\n max-width: 400px;\n}\n\n/* Keep the first control clear of the close button above it */\n.dialog-settings .dialog-body {\n padding-top: 2.25em;\n}\n\n.dialog-close {\n position: absolute;\n top: 0.75em;\n right: 0.75em;\n z-index: 1;\n background: transparent;\n border: none;\n color: #9e9e9e;\n font-size: 1.1em;\n cursor: pointer;\n padding: 0.25em;\n line-height: 1;\n}\n\n.dialog-close:hover {\n color: #e0e0e0;\n}\n\n.dialog-body {\n overflow-y: auto;\n flex: 1;\n min-height: 0;\n}\n\n/* Settings controls */\n\n.settings-controls {\n padding: 1em 1.25em;\n display: flex;\n flex-direction: column;\n gap: 1em;\n}\n\n.settings-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 1em;\n}\n\n.settings-row select,\n.settings-row input[type='range'] {\n accent-color: #64b5f6;\n}\n\n.settings-row select {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n.settings-row input[type='checkbox'] {\n accent-color: #64b5f6;\n width: 1.1em;\n height: 1.1em;\n}\n\n/* Save manager */\n\n.save-manager {\n display: flex;\n flex-direction: column;\n flex: 1;\n min-height: 0;\n}\n\n.saves-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 1em 1.25em;\n padding-right: 3em;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n font-weight: 600;\n flex-shrink: 0;\n}\n\n.saves-header-left {\n display: flex;\n align-items: center;\n gap: 0.75em;\n}\n\n.saves-mode-toggle {\n display: flex;\n gap: 0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n overflow: hidden;\n}\n\n.saves-mode-toggle button {\n background: transparent;\n color: #9e9e9e;\n border: none;\n padding: 0.3em 0.8em;\n font: inherit;\n font-size: 0.85em;\n font-weight: 600;\n cursor: pointer;\n transition:\n background 0.2s,\n color 0.2s;\n}\n\n.saves-mode-toggle button.active {\n background: rgba(100, 181, 246, 0.2);\n color: #64b5f6;\n}\n\n.saves-mode-toggle button:hover:not(.active) {\n color: #e0e0e0;\n}\n\n.saves-body {\n padding: 0.75em 1.25em;\n overflow-y: auto;\n flex: 1;\n min-height: 0;\n}\n\n.saves-empty {\n text-align: center;\n padding: 2em 1em;\n opacity: 0.5;\n font-size: 0.9em;\n}\n\n.saves-toolbar {\n display: flex;\n gap: 0.5em;\n padding: 0.5em 1.25em;\n border-bottom: 1px solid rgba(255, 255, 255, 0.08);\n flex-shrink: 0;\n}\n\n.saves-toolbar-button {\n background: rgba(255, 255, 255, 0.05);\n color: #9e9e9e;\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 4px;\n padding: 0.3em 0.7em;\n font: inherit;\n font-size: 0.8em;\n cursor: pointer;\n transition:\n background 0.2s,\n color 0.2s;\n}\n\n.saves-toolbar-button:hover {\n background: rgba(255, 255, 255, 0.1);\n color: #e0e0e0;\n}\n\n.playthrough-group {\n margin-bottom: 0.75em;\n}\n\n.playthrough-header {\n display: flex;\n width: 100%;\n border: 0;\n background: none;\n font-family: inherit;\n text-align: left;\n align-items: center;\n gap: 0.5em;\n padding: 0.4em 0;\n cursor: pointer;\n user-select: none;\n font-size: 0.85em;\n color: #9e9e9e;\n transition: color 0.2s;\n}\n\n.playthrough-header:hover {\n color: #e0e0e0;\n}\n\n.playthrough-chevron {\n display: inline-block;\n font-size: 0.7em;\n transition: transform 0.2s;\n}\n\n.playthrough-chevron.open {\n transform: rotate(90deg);\n}\n\n.playthrough-label {\n font-weight: 600;\n}\n\n.playthrough-date {\n opacity: 0.6;\n font-size: 0.9em;\n}\n\n.playthrough-saves {\n display: flex;\n flex-direction: column;\n gap: 0.4em;\n padding-left: 0.25em;\n}\n\n.save-slot {\n display: flex;\n align-items: center;\n gap: 0.75em;\n padding: 0.5em 0.6em;\n background: rgba(255, 255, 255, 0.03);\n border: 1px solid rgba(255, 255, 255, 0.06);\n border-radius: 6px;\n transition: background 0.15s;\n}\n\n.save-slot:hover {\n background: rgba(255, 255, 255, 0.06);\n}\n\n.save-slot-info {\n flex: 1;\n min-width: 0;\n}\n\n.save-slot-title {\n font-weight: 500;\n font-size: 0.9em;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.save-slot-meta {\n font-size: 0.75em;\n color: #9e9e9e;\n display: flex;\n gap: 0.75em;\n}\n\n.save-slot-actions {\n display: flex;\n gap: 0.3em;\n flex-shrink: 0;\n}\n\n.save-slot-action {\n background: transparent;\n color: #9e9e9e;\n border: 1px solid transparent;\n border-radius: 3px;\n padding: 0.2em 0.5em;\n font: inherit;\n font-size: 0.75em;\n cursor: pointer;\n transition:\n color 0.2s,\n background 0.2s;\n white-space: nowrap;\n}\n\n.save-slot-action:hover {\n color: #e0e0e0;\n background: rgba(255, 255, 255, 0.08);\n}\n\n.save-slot-action.primary {\n color: #64b5f6;\n border-color: rgba(100, 181, 246, 0.3);\n}\n\n.save-slot-action.primary:hover {\n background: rgba(100, 181, 246, 0.15);\n}\n\n.save-slot-action.danger:hover {\n color: #ef5350;\n background: rgba(239, 83, 80, 0.1);\n}\n\n.save-slot-new {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0.5em;\n margin-top: 0.25em;\n border: 1px dashed rgba(255, 255, 255, 0.12);\n border-radius: 6px;\n color: #9e9e9e;\n font: inherit;\n font-size: 0.8em;\n background: transparent;\n cursor: pointer;\n width: 100%;\n transition:\n color 0.2s,\n border-color 0.2s,\n background 0.2s;\n}\n\n.save-slot-new:hover {\n color: #64b5f6;\n border-color: rgba(100, 181, 246, 0.3);\n background: rgba(100, 181, 246, 0.05);\n}\n\n.saves-notice {\n padding: 0.5em 1.25em;\n font-size: 0.8em;\n color: #ffb74d;\n border-bottom: 1px solid rgba(255, 183, 77, 0.3);\n background: rgba(255, 183, 77, 0.08);\n flex-shrink: 0;\n}\n\n.saves-status {\n padding: 0.5em 1.25em;\n font-size: 0.8em;\n color: #81c784;\n border-top: 1px solid rgba(255, 255, 255, 0.08);\n flex-shrink: 0;\n text-align: center;\n}\n\n.saves-status.error {\n color: #ef5350;\n border: none;\n border-radius: 0;\n padding: 0.5em 1.25em;\n font-family: inherit;\n background: transparent;\n}\n\n.save-rename-input {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 3px;\n padding: 0.15em 0.4em;\n font: inherit;\n font-size: 0.9em;\n width: 100%;\n}\n\n.save-rename-input:focus {\n outline: none;\n border-color: #64b5f6;\n}\n\n/* Macro: link */\n\n.macro-link {\n color: #64b5f6;\n text-decoration: none;\n border-bottom: 1px solid rgba(100, 181, 246, 0.3);\n transition:\n color 0.2s,\n border-color 0.2s;\n cursor: pointer;\n}\n\n.macro-link:hover {\n color: #90caf9;\n border-bottom-color: #90caf9;\n}\n\n.macro-link:active {\n color: #42a5f5;\n}\n\n/* Macro: form inputs */\n\n.macro-textbox,\n.macro-numberbox,\n.macro-textarea {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n.macro-textbox:focus,\n.macro-numberbox:focus,\n.macro-textarea:focus {\n outline: none;\n border-color: #64b5f6;\n}\n\n.macro-textarea {\n min-height: 3em;\n resize: vertical;\n}\n\n.macro-checkbox,\n.macro-radiobutton {\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n gap: 0.3em;\n}\n\n.macro-checkbox input,\n.macro-radiobutton input {\n accent-color: #64b5f6;\n}\n\n/* Macro: listbox */\n\n.macro-listbox {\n background: #1a1a2e;\n color: #e0e0e0;\n border: 1px solid rgba(255, 255, 255, 0.15);\n border-radius: 4px;\n padding: 0.3em 0.5em;\n font: inherit;\n}\n\n/* Macro: cycle */\n\n.macro-cycle {\n background: rgba(100, 181, 246, 0.15);\n color: #64b5f6;\n border: 1px solid rgba(100, 181, 246, 0.4);\n border-radius: 4px;\n padding: 0.25em 0.75em;\n font: inherit;\n cursor: pointer;\n transition:\n background 0.2s,\n border-color 0.2s;\n}\n\n.macro-cycle:hover {\n background: rgba(100, 181, 246, 0.25);\n border-color: #90caf9;\n}\n\n/* Macro: meter */\n\n.macro-meter {\n position: relative;\n width: 100%;\n height: 1.4em;\n background: #2a2a3e;\n border-radius: 0.3em;\n overflow: hidden;\n border: 1px solid #444;\n}\n\n.macro-meter-fill {\n height: 100%;\n background: #64b5f6;\n transition: width 0.3s ease;\n}\n\n.macro-meter-label {\n position: absolute;\n inset: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 0.85em;\n color: #e0e0e0;\n text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);\n pointer-events: none;\n}\n\n/* Markdown wrapper — invisible to layout */\n\n.md {\n display: contents;\n}\n\n/* Markdown block elements inside passages */\n\n.passage p {\n margin: 0.6em 0;\n}\n\n.passage p:first-child {\n margin-top: 0;\n}\n\n.passage p:last-child {\n margin-bottom: 0;\n}\n\n.passage h1,\n.passage h2,\n.passage h3,\n.passage h4,\n.passage h5,\n.passage h6 {\n margin: 1em 0 0.4em;\n line-height: 1.3;\n color: #f0f0f0;\n}\n\n.passage h1 {\n font-size: 1.8em;\n}\n.passage h2 {\n font-size: 1.5em;\n}\n.passage h3 {\n font-size: 1.25em;\n}\n.passage h4 {\n font-size: 1.1em;\n}\n.passage h5 {\n font-size: 1em;\n}\n.passage h6 {\n font-size: 0.9em;\n opacity: 0.8;\n}\n\n.passage code {\n font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;\n font-size: 0.9em;\n background: rgba(255, 255, 255, 0.08);\n padding: 0.15em 0.35em;\n border-radius: 3px;\n}\n\n.passage pre {\n background: rgba(0, 0, 0, 0.3);\n border: 1px solid rgba(255, 255, 255, 0.08);\n border-radius: 6px;\n padding: 1em;\n overflow-x: auto;\n margin: 0.8em 0;\n}\n\n.passage pre code {\n background: none;\n padding: 0;\n border-radius: 0;\n font-size: 0.85em;\n}\n\n.passage blockquote {\n border-left: 3px solid rgba(100, 181, 246, 0.5);\n margin: 0.8em 0;\n padding: 0.4em 1em;\n color: #b0b0b0;\n}\n\n.passage blockquote p {\n margin: 0.3em 0;\n}\n\n.passage ul,\n.passage ol {\n margin: 0.6em 0;\n padding-left: 1.8em;\n}\n\n.passage li {\n margin: 0.2em 0;\n}\n\n.passage hr {\n border: none;\n border-top: 1px solid rgba(255, 255, 255, 0.12);\n margin: 1.2em 0;\n}\n\n.passage table {\n border-collapse: collapse;\n width: 100%;\n margin: 0.8em 0;\n}\n\n.passage th,\n.passage td {\n border: 1px solid rgba(255, 255, 255, 0.12);\n padding: 0.5em 0.75em;\n text-align: left;\n}\n\n.passage th {\n background: rgba(255, 255, 255, 0.06);\n font-weight: 600;\n}\n\n.passage tr:nth-child(even) {\n background: rgba(255, 255, 255, 0.02);\n}\n\n.passage del {\n opacity: 0.5;\n}\n\n.passage strong {\n color: #f0f0f0;\n}\n\n/* Macro: type (typewriter) */\n\n.macro-type-cursor::after {\n content: '\\2588';\n animation: type-blink 0.7s step-end infinite;\n color: #64b5f6;\n}\n\n.macro-type-done .macro-type-cursor::after {\n display: none;\n}\n\n@keyframes type-blink {\n 50% {\n opacity: 0;\n }\n}\n";
22538
22645
  //#endregion
22539
22646
  //#region src/index.tsx
22540
22647
  function renderErrors(root, errors) {
@@ -75,9 +75,10 @@ var NO_SELECTORS = {};
75
75
  var EMAIL_AUTOLINK = /^<[a-zA-Z0-9.!#$%&'*+/=?^_`|~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*>$/;
76
76
  /**
77
77
  * A link's display text and target, from its text `inner` (at `at` in the
78
- * input), with where the target is written.
78
+ * input), with where the target is written. `indexOf(separator)` finds a
79
+ * separator that is written outside markup (see linkSeparatorIndex).
79
80
  */
80
- function parseLink(inner, at) {
81
+ function parseLink(inner, at, indexOf) {
81
82
  /** The trimmed text from `start` to `end` of inner, and where it is. */
82
83
  const part = (start, end) => {
83
84
  const raw = inner.slice(start, end);
@@ -90,7 +91,7 @@ function parseLink(inner, at) {
90
91
  };
91
92
  };
92
93
  for (const [separator, targetFirst] of LINK_SEPARATORS) {
93
- const idx = inner.indexOf(separator);
94
+ const idx = indexOf(separator);
94
95
  if (idx === -1) continue;
95
96
  const before = part(0, idx);
96
97
  const after = part(idx + separator.length, inner.length);
@@ -772,7 +773,7 @@ function peg$parse(input, options) {
772
773
  return !textMode;
773
774
  }
774
775
  function peg$f50(s, at, inner) {
775
- return withSelectors(lexeme("link", location(), parseLink(inner, at)), s);
776
+ return withSelectors(lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator))), s);
776
777
  }
777
778
  function peg$f51() {
778
779
  return !textMode;
@@ -3675,6 +3676,24 @@ function peg$parse(input, options) {
3675
3676
  let attrCode = false;
3676
3677
  /** The macro whose raw body is being read. */
3677
3678
  let rawName = "";
3679
+ /**
3680
+ * The index in `inner` (at `at` in the input) of the first `separator` that
3681
+ * is not inside a {…} of the label: its code (`{if $a || $b}`, a string with
3682
+ * a pipe) belongs to the label, not to the link's syntax.
3683
+ */
3684
+ function linkSeparatorIndex(inner, at, separator) {
3685
+ for (let i = 0; i < inner.length; i++) {
3686
+ const c = inner.charAt(i);
3687
+ if (c === "\\" && /[{}]/.test(inner.charAt(i + 1))) i++;
3688
+ else if (c === LB) {
3689
+ const head = /^(?:[.#][\w-]*)* ?(\/?[a-zA-Z][\w-]*|(?=[$_@%(!]))/.exec(inner.slice(i + 1));
3690
+ if (!head) continue;
3691
+ const close = hooks.closeBrace(input, at + i + 1 + head[0].length, at + i + 1);
3692
+ if (close !== -1 && close < at + inner.length) i = close - at;
3693
+ } else if (inner.startsWith(separator, i)) return i;
3694
+ }
3695
+ return -1;
3696
+ }
3678
3697
  function skipTo(end) {
3679
3698
  skipEnd = end;
3680
3699
  return end >= 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.59.20",
3
+ "version": "0.59.22",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -5,7 +5,12 @@ import {
5
5
  useRef,
6
6
  useContext,
7
7
  } from 'preact/hooks';
8
- import { useStoryStore, resolvePlaythroughId } from '../../store';
8
+ import {
9
+ useStoryStore,
10
+ resolvePlaythroughId,
11
+ issueStateReplacement,
12
+ isStateReplacementSuperseded,
13
+ } from '../../store';
9
14
  import { useStoryFields } from '../../hooks/use-story-fields';
10
15
  import { isSaveExport, type SaveRecord } from '../../saves/types';
11
16
  import {
@@ -169,16 +174,21 @@ export function SaveManagerContent() {
169
174
  };
170
175
 
171
176
  const handleLoad = async (save: SaveRecord) => {
177
+ // Ordered with restarts and other loads by the click, not by the read
178
+ const replacement = issueStateReplacement();
172
179
  try {
173
180
  // The record as stored now: the listed one may have been overwritten
174
181
  // since the list was read (#428). One deleted since is loaded as listed.
175
182
  const current = (await getSaveRecord(save.meta.id)) ?? save;
183
+ // A restart or load issued since the click wins (#434)
184
+ if (isStateReplacementSuperseded(replacement)) return;
176
185
  // Stored records hold serialized variables; the store expects live
177
186
  // ones. The game moves to the save's playthrough.
178
187
  loadFromPayload(
179
188
  decodeSavePayload(current.payload),
180
189
  undefined,
181
190
  current.meta.playthroughId,
191
+ replacement,
182
192
  );
183
193
  showStatus('Game loaded');
184
194
  if (closeDialog) {
@@ -191,9 +201,24 @@ export function SaveManagerContent() {
191
201
  }
192
202
  };
193
203
 
204
+ /** Run `op`, then tell the player how it went and list the saves again. */
205
+ const runAction = async (
206
+ done: string,
207
+ failed: string,
208
+ op: () => Promise<void>,
209
+ ) => {
210
+ try {
211
+ await op();
212
+ showStatus(done);
213
+ await refresh();
214
+ } catch {
215
+ showStatus(failed, 'error');
216
+ }
217
+ };
218
+
194
219
  const handleDelete = async (saveId: string) => {
195
220
  if (!confirm('Delete this save?')) return;
196
- try {
221
+ await runAction('Save deleted', 'Failed to delete save', async () => {
197
222
  await deleteSaveById(saveId);
198
223
  // The save may have been held by a slot; hasSave() and QuickLoad
199
224
  // read the store's cache
@@ -201,11 +226,7 @@ export function SaveManagerContent() {
201
226
  useStoryStore.setState((state) => {
202
227
  state.knownSaves = known;
203
228
  });
204
- showStatus('Save deleted');
205
- await refresh();
206
- } catch {
207
- showStatus('Failed to delete save', 'error');
208
- }
229
+ });
209
230
  };
210
231
 
211
232
  const handleRenameStart = (save: SaveRecord) => {
@@ -215,15 +236,13 @@ export function SaveManagerContent() {
215
236
  };
216
237
 
217
238
  const handleRenameConfirm = async () => {
218
- if (!renamingId || !renameValue.trim()) return;
219
- try {
220
- await renameSave(renamingId, renameValue.trim());
221
- setRenamingId(null);
222
- showStatus('Save renamed');
223
- await refresh();
224
- } catch {
225
- showStatus('Failed to rename', 'error');
226
- }
239
+ const id = renamingId;
240
+ if (!id || !renameValue.trim()) return;
241
+ await runAction('Save renamed', 'Failed to rename', async () => {
242
+ await renameSave(id, renameValue.trim());
243
+ // Only this edit is over: another save may be in the editor since (#438)
244
+ setRenamingId((current) => (current === id ? null : current));
245
+ });
227
246
  };
228
247
 
229
248
  const handleRenameKeyDown = (e: KeyboardEvent) => {