@rohal12/spindle 0.64.23 → 0.64.24

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.
@@ -15648,6 +15648,18 @@ var PendingIterationContext = createContext(null);
15648
15648
  */
15649
15649
  var OutgoingContext = createContext(null);
15650
15650
  /**
15651
+ * Tells the macros that run code as they mount ({set}, {do}, {unset},
15652
+ * {goto}, {computed}, the count of an {include}) whether they come too late: the
15653
+ * passage they belong to was on the page and has been left since. State
15654
+ * that changed before the navigation can still render new content into the
15655
+ * passage on its way out, and its code would run against the destination's
15656
+ * state (#352, as #410 for timers). The macros that mount while the passage
15657
+ * is first rendered are never late, whatever that render navigates. Null
15658
+ * outside a displayed passage, and in a click body, which renders apart
15659
+ * from the passage and runs as part of the click.
15660
+ */
15661
+ var LateMountContext = createContext(null);
15662
+ /**
15651
15663
  * Story state fields `keys`, re-rendering when any of them changes (as one
15652
15664
  * useStoryStore() selector per field would). The result keeps its identity
15653
15665
  * while the fields don't change, as the store's snapshot must.
@@ -16120,14 +16132,17 @@ function logMacroError(label, error, location = currentSourceLocation()) {
16120
16132
  console.error(`spindle: Error in {${label}}${location}:`, error);
16121
16133
  }
16122
16134
  /**
16123
- * Run `effect` once, during the macro's first render. If it throws, the
16135
+ * Run `effect` once, during the macro's first render, unless that is in a
16136
+ * passage already left (see LateMountContext). If it throws, the
16124
16137
  * error is logged under `{macro rawArgs}` and shown in place of the macro
16125
16138
  * from then on; otherwise the macro renders nothing.
16126
16139
  */
16127
16140
  function useRunOnce(macro, rawArgs, effect) {
16128
16141
  const failure = useRef(void 0);
16142
+ const lateMount = useContext(LateMountContext);
16129
16143
  if (failure.current === void 0) {
16130
16144
  failure.current = null;
16145
+ if (lateMount?.()) return null;
16131
16146
  const location = currentSourceLocation();
16132
16147
  try {
16133
16148
  effect();
@@ -23766,27 +23781,36 @@ function Passage({ passage, dataTransition, navigationId }) {
23766
23781
  else emit();
23767
23782
  }
23768
23783
  }, [passage.name, navigationId]);
23784
+ const hasLeft = useContext(OutgoingContext);
23785
+ const committed = useRef(false);
23786
+ useLayoutEffect(() => {
23787
+ committed.current = true;
23788
+ }, []);
23789
+ const lateMount = useCallback(() => committed.current && !!hasLeft?.(), [hasLeft]);
23769
23790
  const nobr = passage.tags.includes("nobr");
23770
23791
  const viewScope = useViewScope();
23771
23792
  const inner = /* @__PURE__ */ jsx(InterfaceContext.Provider, {
23772
23793
  value: false,
23773
23794
  children: /* @__PURE__ */ jsx(ViewScopeContext.Provider, {
23774
23795
  value: viewScope,
23775
- children: /* @__PURE__ */ jsxs("div", {
23776
- ref: elRef,
23777
- class: "passage",
23778
- "data-passage": passage.name,
23779
- "data-tags": passage.tags.join(" "),
23780
- "data-transition": dataTransition,
23781
- children: [
23782
- specialPassage("PassageHeader", "header"),
23783
- /* @__PURE__ */ jsx(PassageBody, {
23784
- passage,
23785
- content: passage.content
23786
- }),
23787
- specialPassage("PassageFooter", "footer"),
23788
- doneReady && specialPassage("PassageDone", "done")
23789
- ]
23796
+ children: /* @__PURE__ */ jsx(LateMountContext.Provider, {
23797
+ value: lateMount,
23798
+ children: /* @__PURE__ */ jsxs("div", {
23799
+ ref: elRef,
23800
+ class: "passage",
23801
+ "data-passage": passage.name,
23802
+ "data-tags": passage.tags.join(" "),
23803
+ "data-transition": dataTransition,
23804
+ children: [
23805
+ specialPassage("PassageHeader", "header"),
23806
+ /* @__PURE__ */ jsx(PassageBody, {
23807
+ passage,
23808
+ content: passage.content
23809
+ }),
23810
+ specialPassage("PassageFooter", "footer"),
23811
+ doneReady && specialPassage("PassageDone", "done")
23812
+ ]
23813
+ })
23790
23814
  })
23791
23815
  })
23792
23816
  });
@@ -24613,16 +24637,17 @@ defineMacro({
24613
24637
  const name = target.slice(1);
24614
24638
  const localsUpdate = isLocal ? ctx.update : null;
24615
24639
  const pendingIteration = ctx.hooks.useContext(PendingIterationContext);
24640
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
24616
24641
  const prevOutput = ctx.hooks.useRef(UNSET);
24617
24642
  const lastNavigation = ctx.hooks.useRef(-1);
24618
24643
  const compute = () => computeAndApply(expr, name, isTemp, isLocal, ctx.getValues, rawArgs, prevOutput, lastNavigation, localsUpdate);
24619
24644
  const ran = ctx.hooks.useRef(false);
24620
24645
  if (!ran.current) {
24621
24646
  ran.current = true;
24622
- compute();
24647
+ if (!tooLate) compute();
24623
24648
  }
24624
24649
  ctx.hooks.useLayoutEffect(() => {
24625
- if (!pendingIteration?.(useStoryStore.getState())) compute();
24650
+ if (!tooLate && !pendingIteration?.(useStoryStore.getState())) compute();
24626
24651
  }, [ctx.merged, pendingIteration]);
24627
24652
  return null;
24628
24653
  }
@@ -25560,6 +25585,10 @@ defineMacro({
25560
25585
  }
25561
25586
  });
25562
25587
  // src/components/macros/SaveManager.tsx
25588
+ /** How long a Delete button stays armed without a second press. */
25589
+ var ARMED_DELETE_MS = 5e3;
25590
+ var ARMED_DELETE_LABEL = "Press again to delete";
25591
+ var ARMED_DELETE_HINT = "Press again to delete this save";
25563
25592
  function relativeTime(iso) {
25564
25593
  const diff = Date.now() - new Date(iso).getTime();
25565
25594
  const secs = Math.floor(diff / 1e3);
@@ -25586,6 +25615,7 @@ function SaveManagerContent({ className, id }) {
25586
25615
  const [status, setStatus] = useState(null);
25587
25616
  const [collapsed, setCollapsed] = useState(() => /* @__PURE__ */ new Set());
25588
25617
  const [renamingId, setRenamingId] = useState(null);
25618
+ const [armedId, setArmedId] = useState(null);
25589
25619
  const renameCancelled = useRef(false);
25590
25620
  const [renameValue, setRenameValue] = useState("");
25591
25621
  const renameInputRef = useRef(null);
@@ -25631,6 +25661,29 @@ function SaveManagerContent({ className, id }) {
25631
25661
  clearTimeout(closeTimer.current);
25632
25662
  };
25633
25663
  }, []);
25664
+ useEffect(() => {
25665
+ if (armedId === null) return;
25666
+ const disarm = () => setArmedId(null);
25667
+ const onArmedButton = (e) => e.target instanceof Element && !!e.target.closest("[data-armed]");
25668
+ const onPointerDown = (e) => {
25669
+ if (!onArmedButton(e)) disarm();
25670
+ };
25671
+ const onKeyDown = (e) => {
25672
+ if (e.key === "Escape") {
25673
+ e.preventDefault();
25674
+ e.stopPropagation();
25675
+ disarm();
25676
+ } else if (!onArmedButton(e)) disarm();
25677
+ };
25678
+ const timer = window.setTimeout(disarm, ARMED_DELETE_MS);
25679
+ document.addEventListener("pointerdown", onPointerDown, true);
25680
+ document.addEventListener("keydown", onKeyDown, true);
25681
+ return () => {
25682
+ clearTimeout(timer);
25683
+ document.removeEventListener("pointerdown", onPointerDown, true);
25684
+ document.removeEventListener("keydown", onKeyDown, true);
25685
+ };
25686
+ }, [armedId]);
25634
25687
  const toggleCollapse = (id) => {
25635
25688
  setCollapsed((prev) => {
25636
25689
  const next = new Set(prev);
@@ -25690,8 +25743,13 @@ function SaveManagerContent({ className, id }) {
25690
25743
  showStatus(failed, "error");
25691
25744
  }
25692
25745
  };
25746
+ /** The first press arms the button; a second press on it deletes. */
25693
25747
  const handleDelete = async (saveId) => {
25694
- if (!confirm("Delete this save?")) return;
25748
+ if (armedId !== saveId) {
25749
+ setArmedId(saveId);
25750
+ return;
25751
+ }
25752
+ setArmedId(null);
25695
25753
  await runAction("Save deleted", "Failed to delete save", async () => {
25696
25754
  await deleteSaveById(saveId);
25697
25755
  const known = await populateKnownSaves(ifid);
@@ -25888,9 +25946,13 @@ function SaveManagerContent({ className, id }) {
25888
25946
  }),
25889
25947
  /* @__PURE__ */ jsx("button", {
25890
25948
  type: "button",
25891
- class: "save-slot-action danger",
25949
+ class: armedId === save.meta.id ? "save-slot-action danger is-armed" : "save-slot-action danger",
25950
+ "data-armed": armedId === save.meta.id ? "true" : void 0,
25951
+ "aria-label": armedId === save.meta.id ? ARMED_DELETE_HINT : void 0,
25952
+ title: armedId === save.meta.id ? ARMED_DELETE_HINT : void 0,
25892
25953
  onClick: () => handleDelete(save.meta.id),
25893
- children: "Delete"
25954
+ onBlur: () => setArmedId((id) => id === save.meta.id ? null : id),
25955
+ children: armedId === save.meta.id ? ARMED_DELETE_LABEL : "Delete"
25894
25956
  })
25895
25957
  ]
25896
25958
  })]
@@ -25915,6 +25977,12 @@ function SaveManagerContent({ className, id }) {
25915
25977
  })
25916
25978
  })]
25917
25979
  }),
25980
+ /* @__PURE__ */ jsx("div", {
25981
+ class: "saves-sr-only",
25982
+ role: "status",
25983
+ "aria-live": "polite",
25984
+ children: armedId !== null ? ARMED_DELETE_HINT : ""
25985
+ }),
25918
25986
  status && /* @__PURE__ */ jsx("div", {
25919
25987
  class: `saves-status ${status.type === "error" ? "error" : ""}`,
25920
25988
  children: status.text
@@ -26030,6 +26098,7 @@ defineMacro({
26030
26098
  parameters: INCLUDE_PARAMETERS,
26031
26099
  render(_props, ctx) {
26032
26100
  const displayOnly = ctx.hooks.useContext(DisplayOnlyContext);
26101
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
26033
26102
  const { storyData } = useStoryFields("storyData");
26034
26103
  const { inline } = ctx.args;
26035
26104
  let passageName = "";
@@ -26043,7 +26112,7 @@ defineMacro({
26043
26112
  const ast = ctx.hooks.useMemo(() => passage ? parseMarkup(passage.content) : null, [passage]);
26044
26113
  const included = !failure && !!passage;
26045
26114
  ctx.hooks.useEffect(() => {
26046
- if (included && !displayOnly) useStoryStore.getState().trackRender(passageName);
26115
+ if (included && !displayOnly && !tooLate) useStoryStore.getState().trackRender(passageName);
26047
26116
  }, [
26048
26117
  included,
26049
26118
  passageName,
@@ -26082,7 +26151,9 @@ defineMacro({
26082
26151
  }],
26083
26152
  render(_props, ctx) {
26084
26153
  const [failure, setFailure] = ctx.hooks.useState();
26154
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
26085
26155
  ctx.hooks.useLayoutEffect(() => {
26156
+ if (tooLate) return;
26086
26157
  const location = ctx.sourceLocation();
26087
26158
  try {
26088
26159
  const store = useStoryStore.getState();
@@ -26381,7 +26452,7 @@ defineMacro({
26381
26452
  }
26382
26453
  });
26383
26454
  // src/styles.css?inline
26384
- 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-item {\n display: flex;\n flex-direction: column;\n gap: 0.25em;\n}\n\n.settings-description {\n margin: 0;\n font-size: 0.85em;\n color: #9e9e9e;\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";
26455
+ 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-item {\n display: flex;\n flex-direction: column;\n gap: 0.25em;\n}\n\n.settings-description {\n margin: 0;\n font-size: 0.85em;\n color: #9e9e9e;\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-action.danger.is-armed {\n color: #ef5350;\n background: rgba(239, 83, 80, 0.15);\n border-color: rgba(239, 83, 80, 0.5);\n}\n\n/* Read by screen readers, not shown: announces an armed Delete button */\n.saves-sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\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";
26385
26456
  // src/index.tsx
26386
26457
  function renderErrors(root, errors) {
26387
26458
  root.innerHTML = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.23",
3
+ "version": "0.64.24",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,4 +1,11 @@
1
- import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
1
+ import {
2
+ useCallback,
3
+ useContext,
4
+ useEffect,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useState,
8
+ } from 'preact/hooks';
2
9
  import { parseMarkup } from '../markup/parse';
3
10
  import type { ASTNode } from '../markup/ast';
4
11
  import {
@@ -8,7 +15,11 @@ import {
8
15
  InterfaceContext,
9
16
  useViewScope,
10
17
  } from '../markup/render';
11
- import { useStoryFields } from '../hooks/use-story-fields';
18
+ import {
19
+ LateMountContext,
20
+ OutgoingContext,
21
+ useStoryFields,
22
+ } from '../hooks/use-story-fields';
12
23
  import type { Passage as PassageData } from '../parser';
13
24
  import { sourceLocationOf } from '../utils/source-location';
14
25
  import { emitFromRender } from '../event-emitter';
@@ -179,27 +190,42 @@ export function Passage({
179
190
  }
180
191
  }, [passage.name, navigationId]);
181
192
 
193
+ // The macros that mount after this passage was left must not run (see
194
+ // LateMountContext). Those of its first render are not late: that render
195
+ // may itself navigate away, and the macros after the navigation still run.
196
+ const hasLeft = useContext(OutgoingContext);
197
+ const committed = useRef(false);
198
+ useLayoutEffect(() => {
199
+ committed.current = true;
200
+ }, []);
201
+ const lateMount = useCallback(
202
+ () => committed.current && !!hasLeft?.(),
203
+ [hasLeft],
204
+ );
205
+
182
206
  const nobr = passage.tags.includes('nobr');
183
207
  const viewScope = useViewScope();
184
208
 
185
209
  const inner = (
186
210
  <InterfaceContext.Provider value={false}>
187
211
  <ViewScopeContext.Provider value={viewScope}>
188
- <div
189
- ref={elRef}
190
- class="passage"
191
- data-passage={passage.name}
192
- data-tags={passage.tags.join(' ')}
193
- data-transition={dataTransition}
194
- >
195
- {specialPassage('PassageHeader', 'header')}
196
- <PassageBody
197
- passage={passage}
198
- content={passage.content}
199
- />
200
- {specialPassage('PassageFooter', 'footer')}
201
- {doneReady && specialPassage('PassageDone', 'done')}
202
- </div>
212
+ <LateMountContext.Provider value={lateMount}>
213
+ <div
214
+ ref={elRef}
215
+ class="passage"
216
+ data-passage={passage.name}
217
+ data-tags={passage.tags.join(' ')}
218
+ data-transition={dataTransition}
219
+ >
220
+ {specialPassage('PassageHeader', 'header')}
221
+ <PassageBody
222
+ passage={passage}
223
+ content={passage.content}
224
+ />
225
+ {specialPassage('PassageFooter', 'footer')}
226
+ {doneReady && specialPassage('PassageDone', 'done')}
227
+ </div>
228
+ </LateMountContext.Provider>
203
229
  </ViewScopeContext.Provider>
204
230
  </InterfaceContext.Provider>
205
231
  );
@@ -7,7 +7,10 @@ import { defineMacro } from '../../define-macro';
7
7
  import { MacroError, logMacroError } from './MacroError';
8
8
  import { currentSourceLocation } from '../../utils/source-location';
9
9
  import { checkVariableName, ownValue } from '../../utils/namespace';
10
- import { PendingIterationContext } from '../../hooks/use-story-fields';
10
+ import {
11
+ LateMountContext,
12
+ PendingIterationContext,
13
+ } from '../../hooks/use-story-fields';
11
14
 
12
15
  /**
13
16
  * The previous output before the first successful evaluation. Distinct from
@@ -130,6 +133,8 @@ defineMacro({
130
133
  const name = target.slice(1);
131
134
  const localsUpdate = isLocal ? ctx.update : null;
132
135
  const pendingIteration = ctx.hooks.useContext(PendingIterationContext);
136
+ // In a passage that was left it must not compute (see LateMountContext)
137
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
133
138
 
134
139
  const prevOutput = ctx.hooks.useRef<unknown>(UNSET);
135
140
  // The navigation the target was last checked in
@@ -151,7 +156,7 @@ defineMacro({
151
156
  const ran = ctx.hooks.useRef(false);
152
157
  if (!ran.current) {
153
158
  ran.current = true;
154
- compute();
159
+ if (!tooLate) compute();
155
160
  }
156
161
 
157
162
  // The merged values only decide when to recompute; computeAndApply reads
@@ -160,7 +165,7 @@ defineMacro({
160
165
  ctx.hooks.useLayoutEffect(() => {
161
166
  // A queued effect can outlive the loop state its locals belong to.
162
167
  // Let the owner reconcile first, dropping any removed iterations.
163
- if (!pendingIteration?.(useStoryStore.getState())) compute();
168
+ if (!tooLate && !pendingIteration?.(useStoryStore.getState())) compute();
164
169
  }, [ctx.merged, pendingIteration]);
165
170
 
166
171
  return null;
@@ -1,4 +1,5 @@
1
1
  import { useStoryStore } from '../../store';
2
+ import { LateMountContext } from '../../hooks/use-story-fields';
2
3
  import { defineMacro } from '../../define-macro';
3
4
  import { evaluatePassageName } from './macro-args';
4
5
  import { logMacroError, MacroError } from './MacroError';
@@ -10,7 +11,11 @@ defineMacro({
10
11
  render(_props, ctx) {
11
12
  // Boxed: anything can be thrown, including null and other falsy values
12
13
  const [failure, setFailure] = ctx.hooks.useState<{ error: unknown }>();
14
+ // Mounting in a passage that was left: it must not navigate (see
15
+ // LateMountContext)
16
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
13
17
  ctx.hooks.useLayoutEffect(() => {
18
+ if (tooLate) return;
14
19
  // Reported like an error in {do}: thrown out of an effect, it would
15
20
  // abort the rest of the render's effects (e.g. the session could not
16
21
  // be written because the state holds a function). The location is
@@ -1,6 +1,6 @@
1
1
  import { DisplayOnlyContext } from '../../display-only';
2
2
  import { useStoryStore } from '../../store';
3
- import { useStoryFields } from '../../hooks/use-story-fields';
3
+ import { LateMountContext, useStoryFields } from '../../hooks/use-story-fields';
4
4
  import { parseMarkup } from '../../markup/parse';
5
5
  import { NobrContext } from '../../markup/render';
6
6
  import { defineMacro } from '../../define-macro';
@@ -15,6 +15,9 @@ defineMacro({
15
15
  parameters: INCLUDE_PARAMETERS,
16
16
  render(_props, ctx) {
17
17
  const displayOnly = ctx.hooks.useContext(DisplayOnlyContext);
18
+ // Mounting in a passage that was left: it must not count (see
19
+ // LateMountContext)
20
+ const tooLate = ctx.hooks.useContext(LateMountContext)?.() ?? false;
18
21
  const { storyData } = useStoryFields('storyData');
19
22
 
20
23
  const { inline } = ctx.args;
@@ -42,9 +45,10 @@ defineMacro({
42
45
 
43
46
  // Count the inclusion when its content mounts or the passage changes,
44
47
  // not on every render (an unrelated variable update re-renders it)
48
+ // (tooLate is read when the effect runs for the content that mounted)
45
49
  const included = !failure && !!passage;
46
50
  ctx.hooks.useEffect(() => {
47
- if (included && !displayOnly) {
51
+ if (included && !displayOnly && !tooLate) {
48
52
  useStoryStore.getState().trackRender(passageName);
49
53
  }
50
54
  }, [included, passageName, displayOnly]);
@@ -1,4 +1,5 @@
1
- import { useRef } from 'preact/hooks';
1
+ import { useContext, useRef } from 'preact/hooks';
2
+ import { LateMountContext } from '../../hooks/use-story-fields';
2
3
  import { currentSourceLocation } from '../../utils/source-location';
3
4
  import { errorMessage } from '../../utils/error-message';
4
5
 
@@ -34,7 +35,8 @@ export function logMacroError(
34
35
  }
35
36
 
36
37
  /**
37
- * Run `effect` once, during the macro's first render. If it throws, the
38
+ * Run `effect` once, during the macro's first render, unless that is in a
39
+ * passage already left (see LateMountContext). If it throws, the
38
40
  * error is logged under `{macro rawArgs}` and shown in place of the macro
39
41
  * from then on; otherwise the macro renders nothing.
40
42
  */
@@ -42,8 +44,11 @@ export function useRunOnce(macro: string, rawArgs: string, effect: () => void) {
42
44
  // Unset until the effect has run. Boxed: anything can be thrown,
43
45
  // including null and other falsy values.
44
46
  const failure = useRef<{ error: unknown } | null | undefined>(undefined);
47
+ const lateMount = useContext(LateMountContext);
45
48
  if (failure.current === undefined) {
46
49
  failure.current = null;
50
+ // Mounting in a passage that was left: it must not run (see LateMountContext)
51
+ if (lateMount?.()) return null;
47
52
  const location = currentSourceLocation();
48
53
  try {
49
54
  effect();
@@ -34,6 +34,11 @@ import { DialogCloseContext } from '../PassageDialog';
34
34
  import { defineMacro } from '../../define-macro';
35
35
  import { errorMessage } from '../../utils/error-message';
36
36
 
37
+ /** How long a Delete button stays armed without a second press. */
38
+ const ARMED_DELETE_MS = 5000;
39
+ const ARMED_DELETE_LABEL = 'Press again to delete';
40
+ const ARMED_DELETE_HINT = 'Press again to delete this save';
41
+
37
42
  function relativeTime(iso: string): string {
38
43
  const diff = Date.now() - new Date(iso).getTime();
39
44
  const secs = Math.floor(diff / 1000);
@@ -71,6 +76,8 @@ export function SaveManagerContent({
71
76
  } | null>(null);
72
77
  const [collapsed, setCollapsed] = useState<Set<string>>(() => new Set());
73
78
  const [renamingId, setRenamingId] = useState<string | null>(null);
79
+ // The save whose Delete button has been pressed once (see handleDelete)
80
+ const [armedId, setArmedId] = useState<string | null>(null);
74
81
  const renameCancelled = useRef(false);
75
82
  const [renameValue, setRenameValue] = useState('');
76
83
  const renameInputRef = useRef<HTMLInputElement>(null);
@@ -137,6 +144,38 @@ export function SaveManagerContent({
137
144
  };
138
145
  }, []);
139
146
 
147
+ // While a Delete button is armed, anything else the player does (a press
148
+ // elsewhere, a key, Escape) or a pause puts it back. Blur and Tab are
149
+ // covered by the button's onBlur; the document listeners cover browsers
150
+ // that do not focus a button on click. Escape disarms only: the dialog
151
+ // stays open.
152
+ useEffect(() => {
153
+ if (armedId === null) return;
154
+ const disarm = () => setArmedId(null);
155
+ const onArmedButton = (e: Event) =>
156
+ e.target instanceof Element && !!e.target.closest('[data-armed]');
157
+ const onPointerDown = (e: Event) => {
158
+ if (!onArmedButton(e)) disarm();
159
+ };
160
+ const onKeyDown = (e: KeyboardEvent) => {
161
+ if (e.key === 'Escape') {
162
+ e.preventDefault();
163
+ e.stopPropagation();
164
+ disarm();
165
+ } else if (!onArmedButton(e)) {
166
+ disarm();
167
+ }
168
+ };
169
+ const timer = window.setTimeout(disarm, ARMED_DELETE_MS);
170
+ document.addEventListener('pointerdown', onPointerDown, true);
171
+ document.addEventListener('keydown', onKeyDown, true);
172
+ return () => {
173
+ clearTimeout(timer);
174
+ document.removeEventListener('pointerdown', onPointerDown, true);
175
+ document.removeEventListener('keydown', onKeyDown, true);
176
+ };
177
+ }, [armedId]);
178
+
140
179
  const toggleCollapse = (id: string) => {
141
180
  setCollapsed((prev) => {
142
181
  const next = new Set(prev);
@@ -229,8 +268,13 @@ export function SaveManagerContent({
229
268
  }
230
269
  };
231
270
 
271
+ /** The first press arms the button; a second press on it deletes. */
232
272
  const handleDelete = async (saveId: string) => {
233
- if (!confirm('Delete this save?')) return;
273
+ if (armedId !== saveId) {
274
+ setArmedId(saveId);
275
+ return;
276
+ }
277
+ setArmedId(null);
234
278
  await runAction('Save deleted', 'Failed to delete save', async () => {
235
279
  await deleteSaveById(saveId);
236
280
  // The save may have been held by a slot; hasSave() and QuickLoad
@@ -475,10 +519,34 @@ export function SaveManagerContent({
475
519
  </button>
476
520
  <button
477
521
  type="button"
478
- class="save-slot-action danger"
522
+ class={
523
+ armedId === save.meta.id
524
+ ? 'save-slot-action danger is-armed'
525
+ : 'save-slot-action danger'
526
+ }
527
+ data-armed={
528
+ armedId === save.meta.id ? 'true' : undefined
529
+ }
530
+ aria-label={
531
+ armedId === save.meta.id
532
+ ? ARMED_DELETE_HINT
533
+ : undefined
534
+ }
535
+ title={
536
+ armedId === save.meta.id
537
+ ? ARMED_DELETE_HINT
538
+ : undefined
539
+ }
479
540
  onClick={() => handleDelete(save.meta.id)}
541
+ onBlur={() =>
542
+ setArmedId((id) =>
543
+ id === save.meta.id ? null : id,
544
+ )
545
+ }
480
546
  >
481
- Delete
547
+ {armedId === save.meta.id
548
+ ? ARMED_DELETE_LABEL
549
+ : 'Delete'}
482
550
  </button>
483
551
  </div>
484
552
  </div>
@@ -517,6 +585,14 @@ export function SaveManagerContent({
517
585
  )}
518
586
  </div>
519
587
 
588
+ <div
589
+ class="saves-sr-only"
590
+ role="status"
591
+ aria-live="polite"
592
+ >
593
+ {armedId !== null ? ARMED_DELETE_HINT : ''}
594
+ </div>
595
+
520
596
  {status && (
521
597
  <div class={`saves-status ${status.type === 'error' ? 'error' : ''}`}>
522
598
  {status.text}