@rohal12/spindle 0.64.21 → 0.64.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { Fragment, createContext, createPortal, h, render } from "preact";
2
2
  import { useCallback, useContext, useEffect, useErrorBoundary, useId, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
3
- import { useSyncExternalStore } from "preact/compat";
3
+ import { memo, useSyncExternalStore } from "preact/compat";
4
4
  import { createStore } from "zustand/vanilla";
5
5
  import { immer } from "zustand/middleware/immer";
6
6
  import { Immer, current, enableMapSet, enablePatches, freeze, isDraft, original } from "immer";
@@ -13633,17 +13633,17 @@ function lenientClose(input, i, onRunOut) {
13633
13633
  function lenientRead(input, i) {
13634
13634
  if (memoInput !== input) {
13635
13635
  memoInput = input;
13636
- memo.clear();
13636
+ memo$1.clear();
13637
13637
  }
13638
- let read = memo.get(i);
13638
+ let read = memo$1.get(i);
13639
13639
  if (read === void 0) {
13640
13640
  read = scanLenient(input, i);
13641
- memo.set(i, read);
13641
+ memo$1.set(i, read);
13642
13642
  }
13643
13643
  return read;
13644
13644
  }
13645
13645
  var memoInput = "";
13646
- var memo = /* @__PURE__ */ new Map();
13646
+ var memo$1 = /* @__PURE__ */ new Map();
13647
13647
  function scanLenient(input, start) {
13648
13648
  const codeFrame = (start) => ({
13649
13649
  kind: "code",
@@ -13663,7 +13663,7 @@ function scanLenient(input, start) {
13663
13663
  end,
13664
13664
  ranOut
13665
13665
  };
13666
- if (frame.kind === "code") memo.set(frame.start, result);
13666
+ if (frame.kind === "code") memo$1.set(frame.start, result);
13667
13667
  const parent = frames[frames.length - 1];
13668
13668
  if (!parent) return;
13669
13669
  parent.ranOut ||= ranOut;
@@ -13684,7 +13684,7 @@ function scanLenient(input, start) {
13684
13684
  else if (c === frame.quote) finish(i + 1, ranOut);
13685
13685
  else if (frame.quote !== "`" && c === "\n") finish(-1, ranOut);
13686
13686
  else if (frame.quote === "`" && c === "$" && input[i + 1] === "{") {
13687
- const cached = memo.get(i + 2);
13687
+ const cached = memo$1.get(i + 2);
13688
13688
  if (cached) {
13689
13689
  frame.ranOut ||= cached.ranOut;
13690
13690
  frame.i = cached.end === -1 ? input.length : cached.end + 1;
@@ -23669,19 +23669,58 @@ function renderPassageContent(passage) {
23669
23669
  return renderNodes(parsePassage(passage), passage.tags.includes("nobr") ? { nobr: true } : void 0);
23670
23670
  }
23671
23671
  /**
23672
- * The content of a special passage shown with every passage (PassageHeader,
23673
- * PassageFooter, PassageDone), or null. One that fails to render is logged
23674
- * and left out, so it can't take the passage down with it.
23672
+ * A passage's rendered content, drawn again only when the passage or its
23673
+ * text changes (the props are compared shallowly, so a parent re-rendering
23674
+ * with the same passage skips it).
23675
+ *
23676
+ * It is a component and not a vnode kept by `useMemo`. A kept vnode that is
23677
+ * placed again carries Preact's links (its parent, its rendered children) to
23678
+ * the tree it was first placed in. A navigation's tree reaches the kept vnode
23679
+ * of the passage on its way out, so every tree held the one before it and
23680
+ * none was ever freed. The `content` prop is only here so that an edit of
23681
+ * the passage text in place draws it again.
23682
+ */
23683
+ var PassageBody = memo(function PassageBody({ passage }) {
23684
+ try {
23685
+ return /* @__PURE__ */ jsx(Fragment$1, { children: renderPassageContent(passage) });
23686
+ } catch (err) {
23687
+ return /* @__PURE__ */ jsxs("div", {
23688
+ class: "error",
23689
+ children: [
23690
+ "Error parsing passage “",
23691
+ passage.name,
23692
+ "”",
23693
+ sourceLocationOf(passage),
23694
+ ": ",
23695
+ errorMessage(err)
23696
+ ]
23697
+ });
23698
+ }
23699
+ });
23700
+ /**
23701
+ * A special passage shown with every passage (PassageHeader, PassageFooter,
23702
+ * PassageDone), in its wrapper; nothing if it has no content. One that fails
23703
+ * to render is logged and left out, so it can't take the passage down with
23704
+ * it. Memoized like PassageBody.
23675
23705
  */
23676
- function renderSpecialPassage(passage) {
23677
- if (!passage) return null;
23706
+ var SpecialPassage = memo(function SpecialPassage({ passage, kind }) {
23707
+ let content;
23678
23708
  try {
23679
- return renderPassageContent(passage);
23709
+ content = renderPassageContent(passage);
23680
23710
  } catch (err) {
23681
23711
  console.error(`spindle: Error in ${passage.name}:`, err);
23682
23712
  return null;
23683
23713
  }
23684
- }
23714
+ if (!content) return null;
23715
+ if (kind === "done") return /* @__PURE__ */ jsx(EntryRenderBoundary, { children: /* @__PURE__ */ jsx("div", {
23716
+ hidden: true,
23717
+ children: content
23718
+ }) });
23719
+ return /* @__PURE__ */ jsx("div", {
23720
+ class: `passage-${kind}`,
23721
+ children: content
23722
+ });
23723
+ });
23685
23724
  var CODE_PASSAGES = /* @__PURE__ */ new Set([
23686
23725
  "PassageReady",
23687
23726
  "PassageHeader",
@@ -23703,34 +23742,20 @@ function Passage({ passage, dataTransition, navigationId }) {
23703
23742
  const { storyData } = useStoryFields("storyData");
23704
23743
  const isCodePassage = CODE_PASSAGES.has(passage.name);
23705
23744
  const [doneReady, setDoneReady] = useState(false);
23706
- const content = useMemo(() => {
23707
- try {
23708
- return renderPassageContent(passage);
23709
- } catch (err) {
23710
- return /* @__PURE__ */ jsxs("div", {
23711
- class: "error",
23712
- children: [
23713
- "Error parsing passage “",
23714
- passage.name,
23715
- "”",
23716
- sourceLocationOf(passage),
23717
- ": ",
23718
- errorMessage(err)
23719
- ]
23720
- });
23721
- }
23722
- }, [passage.content, passage.name]);
23723
23745
  const special = (name) => isCodePassage ? void 0 : storyData?.passages.get(name);
23724
- const headerPassage = special("PassageHeader");
23725
- const footerPassage = special("PassageFooter");
23746
+ const specialPassage = (name, kind) => {
23747
+ const found = special(name);
23748
+ return found ? /* @__PURE__ */ jsx(SpecialPassage, {
23749
+ passage: found,
23750
+ content: found.content,
23751
+ kind
23752
+ }) : null;
23753
+ };
23726
23754
  const donePassage = special("PassageDone");
23727
- const headerContent = useMemo(() => renderSpecialPassage(headerPassage), [headerPassage?.content]);
23728
- const footerContent = useMemo(() => renderSpecialPassage(footerPassage), [footerPassage?.content]);
23729
23755
  useEffect(() => {
23730
23756
  if (donePassage) setDoneReady(true);
23731
23757
  return () => setDoneReady(false);
23732
23758
  }, [passage.name]);
23733
- const doneContent = useMemo(() => doneReady ? renderSpecialPassage(donePassage) : null, [doneReady, donePassage?.content]);
23734
23759
  const elRef = useRef(null);
23735
23760
  useLayoutEffect(() => {
23736
23761
  if (navigationId !== void 0) markPassageRendered(navigationId);
@@ -23754,19 +23779,13 @@ function Passage({ passage, dataTransition, navigationId }) {
23754
23779
  "data-tags": passage.tags.join(" "),
23755
23780
  "data-transition": dataTransition,
23756
23781
  children: [
23757
- headerContent && /* @__PURE__ */ jsx("div", {
23758
- class: "passage-header",
23759
- children: headerContent
23760
- }),
23761
- content,
23762
- footerContent && /* @__PURE__ */ jsx("div", {
23763
- class: "passage-footer",
23764
- children: footerContent
23782
+ specialPassage("PassageHeader", "header"),
23783
+ /* @__PURE__ */ jsx(PassageBody, {
23784
+ passage,
23785
+ content: passage.content
23765
23786
  }),
23766
- doneContent && /* @__PURE__ */ jsx(EntryRenderBoundary, { children: /* @__PURE__ */ jsx("div", {
23767
- hidden: true,
23768
- children: doneContent
23769
- }) })
23787
+ specialPassage("PassageFooter", "footer"),
23788
+ doneReady && specialPassage("PassageDone", "done")
23770
23789
  ]
23771
23790
  })
23772
23791
  })
@@ -24325,7 +24344,7 @@ defineMacro({
24325
24344
  const displayedId = displayed.id;
24326
24345
  const isOutgoing = useCallback((state) => state.navigationId !== displayedId, [displayedId]);
24327
24346
  const hasLeft = useCallback(() => isOutgoing(useStoryStore.getState()), [isOutgoing]);
24328
- const lastElement = useRef(null);
24347
+ const lastShown = useRef(null);
24329
24348
  const containerRef = useRef(null);
24330
24349
  const timeoutsRef = useRef([]);
24331
24350
  const scrollAfterCleanup = useRef(false);
@@ -24433,12 +24452,16 @@ defineMacro({
24433
24452
  ]
24434
24453
  });
24435
24454
  const readyPassage = storyData?.passages.get("PassageReady");
24436
- const passageElement = !renderDeferred && displayed.id !== navigationId && lastElement.current ? lastElement.current : effectivePassage && /* @__PURE__ */ jsx(Passage, {
24437
- passage: effectivePassage,
24438
- dataTransition: renderDeferred ? "none" : resolvedTypeRef.current,
24439
- navigationId: renderDeferred ? void 0 : displayed.id
24440
- }, renderDeferred ? "loading" : `nav-${displayed.id}`);
24441
- lastElement.current = passageElement || null;
24455
+ const shown = !renderDeferred && displayed.id !== navigationId && lastShown.current ? lastShown.current : effectivePassage ? {
24456
+ key: renderDeferred ? "loading" : `nav-${displayed.id}`,
24457
+ props: {
24458
+ passage: effectivePassage,
24459
+ dataTransition: renderDeferred ? "none" : resolvedTypeRef.current,
24460
+ navigationId: renderDeferred ? void 0 : displayed.id
24461
+ }
24462
+ } : null;
24463
+ const passageElement = shown && /* @__PURE__ */ jsx(Passage, { ...shown.props }, shown.key);
24464
+ lastShown.current = shown;
24442
24465
  return /* @__PURE__ */ jsxs("div", {
24443
24466
  id: ctx.id ?? "story",
24444
24467
  class: ctx.className ?? "story",
@@ -25910,20 +25933,14 @@ defineMacro({
25910
25933
  }
25911
25934
  });
25912
25935
  // src/components/macros/SettingsControls.tsx
25913
- function SettingControl({ name, def }) {
25914
- const [value, setValue] = useState(() => settings.get(name));
25915
- useEffect(() => {
25916
- const sync = () => setValue(settings.get(name));
25917
- sync();
25918
- return subscribeSettings(sync);
25919
- }, [name]);
25920
- const update = (newValue) => settings.set(name, newValue);
25936
+ function SettingRow({ def, value, describedBy, update }) {
25921
25937
  switch (def.type) {
25922
25938
  case "toggle": return /* @__PURE__ */ jsxs("label", {
25923
25939
  class: "settings-row",
25924
25940
  children: [/* @__PURE__ */ jsx("span", { children: def.config.label }), /* @__PURE__ */ jsx("input", {
25925
25941
  type: "checkbox",
25926
25942
  checked: !!value,
25943
+ "aria-describedby": describedBy,
25927
25944
  onChange: (e) => update(e.target.checked)
25928
25945
  })]
25929
25946
  });
@@ -25931,6 +25948,7 @@ function SettingControl({ name, def }) {
25931
25948
  class: "settings-row",
25932
25949
  children: [/* @__PURE__ */ jsx("span", { children: def.config.label }), /* @__PURE__ */ jsx("select", {
25933
25950
  value: String(value),
25951
+ "aria-describedby": describedBy,
25934
25952
  onChange: (e) => update(e.target.value),
25935
25953
  children: def.config.options.map((opt) => /* @__PURE__ */ jsx("option", {
25936
25954
  value: opt,
@@ -25950,11 +25968,39 @@ function SettingControl({ name, def }) {
25950
25968
  max: def.config.max,
25951
25969
  step: def.config.step,
25952
25970
  value: Number(value),
25971
+ "aria-describedby": describedBy,
25953
25972
  onInput: (e) => update(parseFloat(e.target.value))
25954
25973
  })]
25955
25974
  });
25956
25975
  }
25957
25976
  }
25977
+ function SettingControl({ name, def }) {
25978
+ const [value, setValue] = useState(() => settings.get(name));
25979
+ const descriptionId = useId();
25980
+ const text = def.config.description;
25981
+ const description = typeof text === "string" && text.trim() !== "" ? text : null;
25982
+ useEffect(() => {
25983
+ const sync = () => setValue(settings.get(name));
25984
+ sync();
25985
+ return subscribeSettings(sync);
25986
+ }, [name]);
25987
+ const update = (newValue) => settings.set(name, newValue);
25988
+ const row = /* @__PURE__ */ jsx(SettingRow, {
25989
+ def,
25990
+ value,
25991
+ describedBy: description === null ? void 0 : descriptionId,
25992
+ update
25993
+ });
25994
+ if (description === null) return row;
25995
+ return /* @__PURE__ */ jsxs("div", {
25996
+ class: "settings-item",
25997
+ children: [row, /* @__PURE__ */ jsx("p", {
25998
+ id: descriptionId,
25999
+ class: "settings-description",
26000
+ children: description
26001
+ })]
26002
+ });
26003
+ }
25958
26004
  function SettingsControlsContent({ className, id }) {
25959
26005
  const defs = settings.getDefinitions();
25960
26006
  return /* @__PURE__ */ jsx("div", {
@@ -26335,7 +26381,7 @@ defineMacro({
26335
26381
  }
26336
26382
  });
26337
26383
  // src/styles.css?inline
26338
- 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";
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";
26339
26385
  // src/index.tsx
26340
26386
  function renderErrors(root, errors) {
26341
26387
  root.innerHTML = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.21",
3
+ "version": "0.64.23",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,10 +1,4 @@
1
- import {
2
- useMemo,
3
- useEffect,
4
- useLayoutEffect,
5
- useRef,
6
- useState,
7
- } from 'preact/hooks';
1
+ import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
8
2
  import { parseMarkup } from '../markup/parse';
9
3
  import type { ASTNode } from '../markup/ast';
10
4
  import {
@@ -20,6 +14,7 @@ import { sourceLocationOf } from '../utils/source-location';
20
14
  import { emitFromRender } from '../event-emitter';
21
15
  import { duringEntryRender } from '../triggers';
22
16
  import type { ComponentChildren } from 'preact';
17
+ import { memo } from 'preact/compat';
23
18
  import {
24
19
  EntryRenderContext,
25
20
  markPassageRendered,
@@ -52,21 +47,68 @@ export function renderPassageContent(passage: PassageData) {
52
47
  }
53
48
 
54
49
  /**
55
- * The content of a special passage shown with every passage (PassageHeader,
56
- * PassageFooter, PassageDone), or null. One that fails to render is logged
57
- * and left out, so it can't take the passage down with it.
50
+ * A passage's rendered content, drawn again only when the passage or its
51
+ * text changes (the props are compared shallowly, so a parent re-rendering
52
+ * with the same passage skips it).
53
+ *
54
+ * It is a component and not a vnode kept by `useMemo`. A kept vnode that is
55
+ * placed again carries Preact's links (its parent, its rendered children) to
56
+ * the tree it was first placed in. A navigation's tree reaches the kept vnode
57
+ * of the passage on its way out, so every tree held the one before it and
58
+ * none was ever freed. The `content` prop is only here so that an edit of
59
+ * the passage text in place draws it again.
58
60
  */
59
- function renderSpecialPassage(passage: PassageData | undefined) {
60
- if (!passage) return null;
61
+ const PassageBody = memo(function PassageBody({
62
+ passage,
63
+ }: {
64
+ passage: PassageData;
65
+ content: string;
66
+ }) {
67
+ try {
68
+ return <>{renderPassageContent(passage)}</>;
69
+ } catch (err) {
70
+ return (
71
+ <div class="error">
72
+ Error parsing passage &ldquo;{passage.name}&rdquo;
73
+ {sourceLocationOf(passage)}: {errorMessage(err)}
74
+ </div>
75
+ );
76
+ }
77
+ });
78
+
79
+ /**
80
+ * A special passage shown with every passage (PassageHeader, PassageFooter,
81
+ * PassageDone), in its wrapper; nothing if it has no content. One that fails
82
+ * to render is logged and left out, so it can't take the passage down with
83
+ * it. Memoized like PassageBody.
84
+ */
85
+ const SpecialPassage = memo(function SpecialPassage({
86
+ passage,
87
+ kind,
88
+ }: {
89
+ passage: PassageData;
90
+ content: string;
91
+ kind: 'header' | 'footer' | 'done';
92
+ }) {
93
+ let content: ComponentChildren;
61
94
  try {
62
- return renderPassageContent(passage);
95
+ content = renderPassageContent(passage);
63
96
  } catch (err) {
64
97
  console.error(`spindle: Error in ${passage.name}:`, err);
65
98
  return null;
66
99
  }
67
- }
100
+ if (!content) return null;
101
+ if (kind === 'done') {
102
+ return (
103
+ <EntryRenderBoundary>
104
+ <div hidden>{content}</div>
105
+ </EntryRenderBoundary>
106
+ );
107
+ }
108
+ return <div class={`passage-${kind}`}>{content}</div>;
109
+ });
68
110
 
69
- interface PassageProps {
111
+ export interface PassageProps {
70
112
  passage: PassageData;
71
113
  dataTransition?: string;
72
114
  /** The navigation this passage displays; omitted for placeholders. */
@@ -102,46 +144,27 @@ export function Passage({
102
144
  const isCodePassage = CODE_PASSAGES.has(passage.name);
103
145
  const [doneReady, setDoneReady] = useState(false);
104
146
 
105
- const content = useMemo(() => {
106
- try {
107
- return renderPassageContent(passage);
108
- } catch (err) {
109
- return (
110
- <div class="error">
111
- Error parsing passage &ldquo;{passage.name}&rdquo;
112
- {sourceLocationOf(passage)}: {errorMessage(err)}
113
- </div>
114
- );
115
- }
116
- }, [passage.content, passage.name]);
117
-
118
147
  // Code passages are shown without the special passages
119
148
  const special = (name: string) =>
120
149
  isCodePassage ? undefined : storyData?.passages.get(name);
121
- const headerPassage = special('PassageHeader');
122
- const footerPassage = special('PassageFooter');
150
+ const specialPassage = (name: string, kind: 'header' | 'footer' | 'done') => {
151
+ const found = special(name);
152
+ return found ? (
153
+ <SpecialPassage
154
+ passage={found}
155
+ content={found.content}
156
+ kind={kind}
157
+ />
158
+ ) : null;
159
+ };
123
160
  const donePassage = special('PassageDone');
124
161
 
125
- const headerContent = useMemo(
126
- () => renderSpecialPassage(headerPassage),
127
- [headerPassage?.content],
128
- );
129
- const footerContent = useMemo(
130
- () => renderSpecialPassage(footerPassage),
131
- [footerPassage?.content],
132
- );
133
-
134
162
  // Defer PassageDone to after DOM commit
135
163
  useEffect(() => {
136
164
  if (donePassage) setDoneReady(true);
137
165
  return () => setDoneReady(false);
138
166
  }, [passage.name]);
139
167
 
140
- const doneContent = useMemo(
141
- () => (doneReady ? renderSpecialPassage(donePassage) : null),
142
- [doneReady, donePassage?.content],
143
- );
144
-
145
168
  // Signal that this passage's DOM is committed (after descendants' layout
146
169
  // effects, before paint). Runs once per mount: PassageDisplay keys the
147
170
  // Passage so every navigation that shows a passage mounts a new one.
@@ -169,14 +192,13 @@ export function Passage({
169
192
  data-tags={passage.tags.join(' ')}
170
193
  data-transition={dataTransition}
171
194
  >
172
- {headerContent && <div class="passage-header">{headerContent}</div>}
173
- {content}
174
- {footerContent && <div class="passage-footer">{footerContent}</div>}
175
- {doneContent && (
176
- <EntryRenderBoundary>
177
- <div hidden>{doneContent}</div>
178
- </EntryRenderBoundary>
179
- )}
195
+ {specialPassage('PassageHeader', 'header')}
196
+ <PassageBody
197
+ passage={passage}
198
+ content={passage.content}
199
+ />
200
+ {specialPassage('PassageFooter', 'footer')}
201
+ {doneReady && specialPassage('PassageDone', 'done')}
180
202
  </div>
181
203
  </ViewScopeContext.Provider>
182
204
  </InterfaceContext.Provider>
@@ -11,7 +11,7 @@ import {
11
11
  FrozenStateContext,
12
12
  OutgoingContext,
13
13
  } from '../../hooks/use-story-fields';
14
- import { Passage, renderPassageContent } from '../Passage';
14
+ import { Passage, renderPassageContent, type PassageProps } from '../Passage';
15
15
  import { defineMacro } from '../../define-macro';
16
16
  import { resolveTransition, type ResolvedTransition } from '../../transition';
17
17
  import { skipString } from './arg-utils';
@@ -807,7 +807,13 @@ defineMacro({
807
807
  () => isOutgoing(useStoryStore.getState()),
808
808
  [isOutgoing],
809
809
  );
810
- const lastElement = useRef<preact.VNode | null>(null);
810
+ // What the passage on display was drawn with (see the render below):
811
+ // props, not the vnode, which a vnode of the next render could not
812
+ // be released from (the parent a vnode is placed under stays with it)
813
+ const lastShown = useRef<{
814
+ key: string;
815
+ props: PassageProps;
816
+ } | null>(null);
811
817
 
812
818
  // Container ref for snapshot insertion
813
819
  const containerRef = useRef<HTMLDivElement>(null);
@@ -1001,20 +1007,30 @@ defineMacro({
1001
1007
 
1002
1008
  // Between a navigation and the commit of its passage, the old passage is
1003
1009
  // still mounted. It must not execute against the destination's state, so
1004
- // it keeps the element and the state it last rendered with (#352).
1010
+ // it is drawn with what it was last drawn with (#352): the same props.
1005
1011
  const outgoing = !renderDeferred && displayed.id !== navigationId;
1006
- const passageElement =
1007
- outgoing && lastElement.current
1008
- ? lastElement.current
1009
- : effectivePassage && (
1010
- <Passage
1011
- passage={effectivePassage}
1012
- key={renderDeferred ? 'loading' : `nav-${displayed.id}`}
1013
- dataTransition={renderDeferred ? 'none' : resolvedTypeRef.current}
1014
- navigationId={renderDeferred ? undefined : displayed.id}
1015
- />
1016
- );
1017
- lastElement.current = passageElement || null;
1012
+ const shown =
1013
+ outgoing && lastShown.current
1014
+ ? lastShown.current
1015
+ : effectivePassage
1016
+ ? {
1017
+ key: renderDeferred ? 'loading' : `nav-${displayed.id}`,
1018
+ props: {
1019
+ passage: effectivePassage,
1020
+ dataTransition: renderDeferred
1021
+ ? 'none'
1022
+ : resolvedTypeRef.current,
1023
+ navigationId: renderDeferred ? undefined : displayed.id,
1024
+ },
1025
+ }
1026
+ : null;
1027
+ const passageElement = shown && (
1028
+ <Passage
1029
+ key={shown.key}
1030
+ {...shown.props}
1031
+ />
1032
+ );
1033
+ lastShown.current = shown;
1018
1034
 
1019
1035
  return (
1020
1036
  <div