website-xp-phone 2.2.12 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/README.md +17 -3
  3. package/build/blogDirsPlugin.ts +100 -0
  4. package/build/env.ts +4 -1
  5. package/build/routeSkeletonsPlugin.ts +44 -2
  6. package/package.json +14 -10
  7. package/public/blog/archive/eighth-post-lost-in-the-sauce.json +36 -0
  8. package/public/blog/archive/noise/eleventh-post-discussion-java-gist.md +5 -0
  9. package/public/blog/archive/noise/fifteenth-post-very-rare-windows-funny.md +8 -0
  10. package/public/blog/archive/noise/fourth-post-meta-blog.md +3 -0
  11. package/public/blog/archive/noise/sixteenth-post-meta-fantasy-blog.md +4 -0
  12. package/public/blog/archive/noise/tenth-post-meta-funny-redacted-and-timetravelled.md +3 -0
  13. package/public/blog/archive/noise/twelfth-post-mixing-phase-technique-audio-music.md +48 -0
  14. package/public/blog/archive/noise/welcome-back-ramble-meta.md +6 -0
  15. package/public/blog/archive/noise/welcome-to-my-blog-meta-blog-welcome-to-my-website.md +7 -0
  16. package/public/blog/archive/seventh-post-lie-theory-na2000.json +22 -0
  17. package/public/blog/archive/sophus-lie.json +36 -0
  18. package/public/blog/hlwm_and_herbstutil.md +11 -0
  19. package/public/blog/random/hlwm.md +8 -0
  20. package/public/blog/writing/hot-action-under-a-cold-moon.json +9 -0
  21. package/public/checksums.txt +91 -66
  22. package/public/documents/drift-report.json +42 -28
  23. package/render.yaml +11 -1
  24. package/scripts/mutable-assets.mjs +13 -22
  25. package/scripts/refresh-content.mjs +53 -32
  26. package/scripts/refresh-soundcloud.mjs +221 -136
  27. package/scripts/write-dist-checksums.mjs +48 -4
  28. package/src/content/blog.json +16 -363
  29. package/src/content/blogDirs.ts +196 -0
  30. package/src/content/configs.json +1 -1
  31. package/src/content/contacts.json +2 -2
  32. package/src/content/includes/make-recipes.md +18 -0
  33. package/src/content/index.ts +156 -57
  34. package/src/content/music-ext.json +1 -1
  35. package/src/content/projects/doftiles.json +88 -4
  36. package/src/content/projects/herbctl.json +58 -0
  37. package/src/content/projects/herbstutil.json +50 -20
  38. package/src/content/projects/on-deploy.json +57 -0
  39. package/src/content/projects/polyframes.json +83 -0
  40. package/src/content/schema.ts +7 -4
  41. package/src/content/sections.json +11 -10
  42. package/src/content/soundcloud.json +95 -47
  43. package/src/lib/clippy.ts +29 -8
  44. package/src/lib/embeds.ts +43 -24
  45. package/src/lib/history.ts +152 -0
  46. package/src/lib/markdown.tsx +19 -22
  47. package/src/lib/rehypeYoutubeEmbed.ts +65 -0
  48. package/src/lib/sanitizeSchema.ts +32 -0
  49. package/src/lib/scrollTo.ts +45 -0
  50. package/src/lib/signals.tsx +271 -0
  51. package/src/main.tsx +20 -4
  52. package/src/pages/BlogDirPage.tsx +36 -0
  53. package/src/pages/BlogPostPage.tsx +76 -3
  54. package/src/pages/ProjectPage.tsx +9 -3
  55. package/src/pages/WowPage.tsx +8 -3
  56. package/src/pages/index.ts +2 -0
  57. package/src/shell/App.tsx +14 -8
  58. package/src/shell/Clippy.tsx +13 -3
  59. package/src/shell/MenuBar.tsx +7 -4
  60. package/src/shell/resolveRoute.ts +41 -2
  61. package/src/shell/routerSignals.ts +34 -0
  62. package/src/styles/extras.css +27 -0
  63. package/src/styles/layout.css +2 -2
  64. package/src/styles/menu.css +1 -1
  65. package/src/styles/window.css +19 -9
  66. package/src/themes/pageSlide/index.ts +120 -42
  67. package/src/themes/pageSlide/pageSlide.css +20 -9
  68. package/src/virtual.d.ts +14 -0
  69. package/src/window/MaximizedWindow.tsx +97 -64
  70. package/src/window/OkButton.tsx +42 -25
  71. package/src/window/PageWindows.tsx +7 -0
  72. package/src/window/TitleBar.tsx +3 -1
  73. package/src/window/Window.tsx +132 -87
  74. package/src/window/closeSounds.ts +27 -0
  75. package/src/window/model.ts +11 -0
  76. package/src/window/state.tsx +290 -50
  77. package/src/window/themes.ts +23 -2
  78. package/test/content.test.js +15 -10
  79. package/test/deploy-pipeline.test.js +73 -0
  80. package/test/embeds.test.js +89 -0
  81. package/test/markdown-tables.test.js +96 -0
  82. package/test/mutable-assets.test.js +16 -4
  83. package/test/route-skeletons.test.js +38 -0
  84. package/test/soundcloud-refresh.test.js +68 -0
  85. package/test/youtubeEmbed.test.js +157 -0
  86. package/tsconfig.node.tsbuildinfo +1 -1
  87. package/tsconfig.tsbuildinfo +1 -1
  88. package/vite.config.ts +7 -1
  89. package/.opencode/cache/index.akinevz.html +0 -54
  90. package/public/blog/4th.md +0 -28
  91. package/public/blog/wsl.1.md +0 -40
  92. package/src/window/hidden.ts +0 -22
  93. /package/public/blog/{ → archive/noise/}/321/200/321/203/320/275/320/270/321/201/321/207-/320/263/320/273/320/276/321/201/321/201/320/260/321/200/320/270/320/271.md" +0 -0
  94. /package/src/content/{characters.json → includes/characters.json} +0 -0
@@ -0,0 +1,152 @@
1
+ import { onSignal } from "@/lib/signals";
2
+
3
+ /** The history owner: the ONE module that writes the window system's
4
+ * bookmarks into the session history. The bus carries the commands (the
5
+ * maximized view's push, the off-site departure's hash-free bookmark,
6
+ * the post-dismissal settle) and the handlers attached at boot perform
7
+ * them; nothing else in the app writes our state key.
8
+ *
9
+ * The bookmark lives in the entry's STATE payload, not the URL: an
10
+ * entry that names a window keeps a clean address bar, and the payload
11
+ * survives the cross-document round trip (leave through the maximized
12
+ * OK, come back through the browser back — a fresh boot reads the
13
+ * bookmark and reveals the section without any hash to restore it
14
+ * from). Whatever state the entry already holds (react-router's
15
+ * usr/key/idx) is preserved: the bookmark is one merged key.
16
+ *
17
+ * The pushState WRAPPER is not ours — the pageSlide theme intercepts
18
+ * history.pushState to drive its page transitions. Same-path pushes
19
+ * (every anchor this module writes) stay silent there by design: the
20
+ * maximized view's entry is a UI entry, not a page arrival. */
21
+
22
+ /** The shape of the state payloads this module reads and writes. */
23
+ type EntryState = { window?: string } & Record<string, unknown>;
24
+
25
+ /** The current entry's state with our key merged in (react-router's own
26
+ * keys survive the merge — they are read back on popstate traversals). */
27
+ const withBookmark = (id?: string): EntryState => {
28
+ const state: EntryState = { ...((history.state ?? {}) as EntryState) };
29
+ if (id) state.window = id;
30
+ else delete state.window;
31
+ return state;
32
+ };
33
+
34
+ export function attachHistoryBookmarks(): () => void {
35
+ const offAnchor = onSignal("history:anchor", ({ id, url, mode }) => {
36
+ if (mode === "push") history.pushState(withBookmark(id), "", url);
37
+ else history.replaceState(withBookmark(id), "", url);
38
+ });
39
+ const offRemember = onSignal("history:remember", ({ id, url }) => {
40
+ history.replaceState({ ...withBookmark(id), window: id }, "", url);
41
+ });
42
+ // The arrival marker: every in-document page commit is a TRAVERSAL —
43
+ // this document is a browsing session, never a fresh permalink again
44
+ // (see traversedOnce). The pageSlide theme announces commits on the
45
+ // bus: page:navigated for the pushState wrapper's and the popstate
46
+ // theme's cross-page commits, page:returned for the same-path
47
+ // traversals. Both are dispatched synchronously BEFORE the router's
48
+ // re-render remounts a page — a landing's initialFlags reads the
49
+ // marker in time.
50
+ const offNavigated = onSignal("page:navigated", () => {
51
+ traversedOnce = true;
52
+ });
53
+ const offReturned = onSignal("page:returned", () => {
54
+ traversedOnce = true;
55
+ });
56
+ return () => {
57
+ offAnchor();
58
+ offRemember();
59
+ offNavigated();
60
+ offReturned();
61
+ };
62
+ }
63
+
64
+ /** How THIS document arrived, per the Navigation Timing API: "navigate"
65
+ * (a fresh entry — nothing of ours can live in its state), "reload"
66
+ * (the entry's state survives the reload) and "back_forward" (the
67
+ * returned-to entry's state carries whatever it left with). NOTE: a
68
+ * same-document SPA traversal (the router's back onto the home page)
69
+ * keeps the ORIGINAL load's type — "navigate" — so a bookmark read back
70
+ * in that state is still ours-in-this-document, not a fresh arrival.
71
+ * See windowBookmark: the key's presence is the only gate it needs. */
72
+ export const navigationType = (): "navigate" | "reload" | "back_forward" => {
73
+ const entry = performance.getEntriesByType?.("navigation")[0] as
74
+ PerformanceNavigationTiming | undefined;
75
+ return entry?.type ?? "navigate";
76
+ };
77
+
78
+ /** The window the CURRENT entry is bookmarked to, or null. NO timing
79
+ * gate: the bookmark key is written by this module alone, merged into
80
+ * the entry the writer stood on — either within this very document (an
81
+ * internal link's bookmark, read back by the SAME document when the
82
+ * browser back remounts the page) or across one (the off-site
83
+ * departure, read back by a back_forward/reload arrival). A fresh
84
+ * cross-document navigation ("navigate" type) starts on a NEW entry
85
+ * whose state is null — it can never carry this key by accident, so
86
+ * the key's presence is already proof the entry is one of ours. The
87
+ * earlier timing gate actively BROKE the internal round trip: the SPA
88
+ * back shares the original load's "navigate" timing entry, so the
89
+ * bookmark written seconds before was refused on return. Gating on
90
+ * presence is exact. */
91
+ export function windowBookmark(): string | null {
92
+ const id = (history.state as EntryState | null)?.window;
93
+ return typeof id === "string" && id ? id : null;
94
+ }
95
+
96
+ /** Whether a traversal ALREADY happened in THIS document. Any in-document
97
+ * page commit (the pageSlide theme announces every SPA push and every
98
+ * history traversal on the bus — see attachHistoryBookmarks) sets this.
99
+ * Module scope: a fresh document load starts false. Once set, this
100
+ * document is a browsing session — a hyperlink landing on a section URL
101
+ * must be the INLINE reveal it always was, never the maximized permalink
102
+ * page (a permalink page is only for genuinely fresh arrivals). */
103
+ let traversedOnce = false;
104
+
105
+ /** Whether THIS document followed a same-site hyperlink in: an in-site
106
+ * raw anchor's cross-document arrival carries a same-origin referrer
107
+ * (full document loads bypass every SPA hook, so the click is invisible
108
+ * to the app). That click IS the traversal into the section, not a
109
+ * fresh permalink — the landing is inline. Typed URLs, out-of-site
110
+ * shared links and the Permalink button (window.open ... noreferrer)
111
+ * arrive REFERRER-LESS; the maximized landing stays theirs. */
112
+ const inSiteLinkArrival = (): boolean => {
113
+ if (!document.referrer) return false;
114
+ try {
115
+ return new URL(document.referrer).origin === window.location.origin;
116
+ } catch {
117
+ return false;
118
+ }
119
+ };
120
+
121
+ /** Whether THIS document arrived FRESH — typed, shared, or opened by a
122
+ * permalink button in a new tab: the "navigate" timing type, an entry
123
+ * that carries none of our window state, no earlier in-document
124
+ * traversal (traversedOnce) and no same-site referrer
125
+ * (inSiteLinkArrival). A same-document SPA traversal shares the
126
+ * original load's "navigate" type, and an in-site hyperlink's
127
+ * cross-document load shares the same shape — BOTH are traversals, and
128
+ * both land on the inline reveal they always had. The maximized
129
+ * permalink landing is only for genuinely fresh arrivals: returns never
130
+ * re-maximize, and a hyperlink NEVER lifts the section out of the page
131
+ * it was read on.
132
+ *
133
+ * The decision is MEMOIZED at the first call: the permalink landing
134
+ * itself anchors its entry (history:anchor writes the bookmark) within
135
+ * its first render cycle, and a later evaluation of the raw conditions
136
+ * would read that bookmark and un-decide the landing mid-flight —
137
+ * StrictMode's double-invoked effects flipped maximized landings into
138
+ * inline reveals in dev, and nothing could rely on the answer staying
139
+ * put. The memo lives until a traversal happens, after which this
140
+ * document is a browsing session and every answer is false. */
141
+ let freshAtLoad: boolean | null = null;
142
+
143
+ export function freshArrival(): boolean {
144
+ if (traversedOnce) return false;
145
+ if (freshAtLoad === null) {
146
+ freshAtLoad =
147
+ navigationType() === "navigate" &&
148
+ windowBookmark() === null &&
149
+ !inSiteLinkArrival();
150
+ }
151
+ return freshAtLoad;
152
+ }
@@ -1,34 +1,31 @@
1
1
  import Markdown from "react-markdown";
2
2
  import rehypeRaw from "rehype-raw";
3
- import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
3
+ import rehypeSanitize from "rehype-sanitize";
4
+ import remarkBreaks from "remark-breaks";
5
+ import remarkGfm from "remark-gfm";
4
6
  import { Link } from "react-router-dom";
7
+ import { rehypeYoutubeEmbed } from "@/lib/rehypeYoutubeEmbed";
8
+ import { sanitizeSchema } from "@/lib/sanitizeSchema";
5
9
  import { CLIPPY_LINK, onClippyTriggerClick } from "./clippy";
6
10
 
7
- const schema = {
8
- ...defaultSchema,
9
- tagNames: [...(defaultSchema.tagNames ?? []), "iframe"],
10
- attributes: {
11
- ...defaultSchema.attributes,
12
- img: [...(defaultSchema.attributes?.img ?? []), "style", "loading"],
13
- iframe: [
14
- "src",
15
- "width",
16
- "height",
17
- "title",
18
- "allow",
19
- "allowFullScreen",
20
- "loading",
21
- "style",
22
- ],
23
- },
24
- };
25
-
26
11
  type Props = { children: string; inline?: boolean };
27
12
 
28
- export function Md({ children }: Props) {
13
+ export function Md({ children }: Readonly<Props>) {
29
14
  return (
30
15
  <Markdown
31
- rehypePlugins={[rehypeRaw, [rehypeSanitize, schema]]}
16
+ // remarkBreaks: a single newline prints as a line break, not a
17
+ // soft-break space — line-oriented writing (transcripts, rants,
18
+ // verse) keeps its authored line shape instead of flowing into
19
+ // one paragraph; a blank line still opens a new paragraph.
20
+ // remarkGfm: CommonMark pipes tables (| Recipe | Effect |) so
21
+ // content files need no raw <table> HTML; strikethrough and
22
+ // task lists come along (unused today).
23
+ remarkPlugins={[remarkBreaks, remarkGfm]}
24
+ rehypePlugins={[
25
+ rehypeRaw,
26
+ rehypeYoutubeEmbed,
27
+ [rehypeSanitize, sanitizeSchema],
28
+ ]}
32
29
  components={{
33
30
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
31
  a({ href, children: label, node: _node, ...rest }) {
@@ -0,0 +1,65 @@
1
+ import type { Element, ElementContent, Root } from "hast";
2
+ import { visit } from "unist-util-visit";
3
+ import { youtubeVideoId } from "./embeds.ts";
4
+
5
+ /**
6
+ * Keeps the embed inside its container (the window body) at any width while
7
+ * preserving the player's 16:9 shape, and centres it when the body is wider
8
+ * than the cap. The width/height attributes stay as a no-CSS fallback and
9
+ * give the browser the intrinsic ratio before styles load.
10
+ */
11
+ const RESPONSIVE_STYLE =
12
+ "width: 100%; max-width: 560px; height: auto; aspect-ratio: 16 / 9;" +
13
+ " display: block; margin: 0 auto;";
14
+
15
+ /** The fallback title for embeds whose link text is just the bare URL
16
+ * (markdown autolinks) — a URL reads poorly as a player title. */
17
+ const FALLBACK_TITLE = "YouTube video";
18
+
19
+ function textContent(node: ElementContent): string {
20
+ if (node.type === "text") return node.value;
21
+ if (node.type === "element") return node.children.map(textContent).join("");
22
+ return "";
23
+ }
24
+
25
+ /** Uses the link's own text as the accessible player title when it is
26
+ * human-readable ([my talk](…)), falling back for bare autolinks (<…>). */
27
+ function linkTitle(node: Element, href: string): string {
28
+ const text = textContent(node).trim();
29
+ return text && text.toLowerCase() !== href.toLowerCase()
30
+ ? text
31
+ : FALLBACK_TITLE;
32
+ }
33
+
34
+ /** Rehype plugin: replace YouTube links with responsive 16:9 embeds. */
35
+ export function rehypeYoutubeEmbed() {
36
+ return (tree: Root) => {
37
+ visit(tree, "element", (node, index, parent) => {
38
+ if (!parent || index === undefined || node.tagName !== "a") return;
39
+ const href = node.properties?.href;
40
+ if (typeof href !== "string") return;
41
+ const id = youtubeVideoId(href);
42
+ if (!id) return;
43
+ parent.children[index] = {
44
+ type: "element",
45
+ tagName: "iframe",
46
+ properties: {
47
+ src: `https://www.youtube-nocookie.com/embed/${id}`,
48
+ title: linkTitle(node, href),
49
+ width: "560",
50
+ height: "315",
51
+ loading: "lazy",
52
+ style: RESPONSIVE_STYLE,
53
+ // YouTube's player rejects embeds without a usable referrer
54
+ // (error 153). The site sends Referrer-Policy: no-referrer, so
55
+ // the iframe needs its own policy to send its origin.
56
+ referrerPolicy: "strict-origin-when-cross-origin",
57
+ allow:
58
+ "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
59
+ allowFullScreen: true,
60
+ },
61
+ children: [],
62
+ };
63
+ });
64
+ };
65
+ }
@@ -0,0 +1,32 @@
1
+ import { defaultSchema } from "rehype-sanitize";
2
+
3
+ /**
4
+ * Sanitize schema shared by every Markdown pipeline (src/lib/markdown.tsx)
5
+ * and its test mirror (test/youtubeEmbed.test.js), so the pipeline and the
6
+ * tests can never drift apart.
7
+ *
8
+ * On top of the defaults it allows:
9
+ * - <iframe> (YouTube embeds via rehypeYoutubeEmbed, or hand-written raw
10
+ * HTML), including the attributes those embeds need — `style` for
11
+ * responsive sizing, `referrerPolicy` for YouTube's error-153 fix;
12
+ * - `style` and `loading` on <img> (inline content images).
13
+ */
14
+ export const sanitizeSchema = {
15
+ ...defaultSchema,
16
+ tagNames: [...(defaultSchema.tagNames ?? []), "iframe"],
17
+ attributes: {
18
+ ...defaultSchema.attributes,
19
+ img: [...(defaultSchema.attributes?.img ?? []), "style", "loading"],
20
+ iframe: [
21
+ "src",
22
+ "width",
23
+ "height",
24
+ "title",
25
+ "allow",
26
+ "allowFullScreen",
27
+ "loading",
28
+ "style",
29
+ "referrerPolicy",
30
+ ],
31
+ },
32
+ };
@@ -0,0 +1,45 @@
1
+ /** Scrolls the named element into view — inside its scrolling window (a
2
+ * maximized window scrolls its own revealed content) or the page. A
3
+ * target already fully on screen is left exactly where it is: the
4
+ * landing scroll exists to reveal an off-screen section, so yanking a
5
+ * visible one to the top row would only scramble the reader's place.
6
+ * The element can mount after the route commit (lazy pages), and the
7
+ * fresh page's height GROWS around the arrival (lazy embeds, images) —
8
+ * an early scroll into a document still shorter than the target is
9
+ * clamped to the top by the browser. So the landing re-aims on every
10
+ * tick while it may have missed: as soon as the element mounts off
11
+ * screen it gets aimed at, and the loop stops the moment the layout
12
+ * settles with it on screen.
13
+ *
14
+ * Lives in lib (not in the pageSlide theme) because two owners aim
15
+ * landings: the theme — every hash navigation, boot, popstate and the
16
+ * alias re-land — and the window system, whose dismissals of SEEDED
17
+ * maximized landings (a permalink opened the section maximized; the OK
18
+ * press minimized it into the page) are the reader's arrival at the
19
+ * section's inline resting place. */
20
+ export function scrollToId(id: string, attempts = 12): void {
21
+ if (!id) return;
22
+ const tick = (left: number) => {
23
+ const el = document.getElementById(id);
24
+ if (!el) {
25
+ // The element can mount after the route commit (lazy pages).
26
+ if (left > 0) window.setTimeout(() => tick(left - 1), 100);
27
+ return;
28
+ }
29
+ // Maximized windows are viewport-fixed overlays; scrolling the page
30
+ // behind them just resets the background while the overlay hides
31
+ // it. The restored window scrolls itself to the target on dismissal
32
+ // instead.
33
+ if (!el.closest(".maximized-backdrop")) {
34
+ const rect = el.getBoundingClientRect();
35
+ if (rect.top < 0 || rect.bottom > window.innerHeight) {
36
+ el.scrollIntoView({ behavior: "smooth", block: "start" });
37
+ // The aim may have been clamped (the document was shorter than
38
+ // the target's position): keep aiming until it sticks.
39
+ if (left > 0) window.setTimeout(() => tick(left - 1), 100);
40
+ return;
41
+ }
42
+ }
43
+ };
44
+ tick(attempts);
45
+ }
@@ -0,0 +1,271 @@
1
+ import {
2
+ createContext,
3
+ useCallback,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ useSyncExternalStore,
9
+ type ReactNode,
10
+ } from "react";
11
+
12
+ /** The named signals of the app: every entry declares a signal's
13
+ * payload, and dispatching and handling are checked against it. Four
14
+ * shapes live here — commands ("app:navigate": a handler performs the
15
+ * behaviour), notices ("page:loaded", "page:navigated": fire-and-forget
16
+ * monitoring), refusable requests ("window:close": handlers may call
17
+ * refuse() before the dispatch returns) and RETAINED notices
18
+ * ("window:hidden": the last snapshot stays readable, see RETAINED).
19
+ * Handlers run synchronously inside the dispatching stack: keep them
20
+ * side-effect-first, no long work, no awaits. */
21
+ export type SignalManifest = {
22
+ "app:navigate": { to: string };
23
+ "page:loaded": { path: string };
24
+ "page:navigated": { from: string; to: string };
25
+ /** History traversal landed on a route (browser back/forward): the
26
+ * page RETURNED — unlike a permalink arrival, a same-path traversal
27
+ * does not remount it, so the page holds the flags it left with. */
28
+ "page:returned": { path: string; hash: string };
29
+ /** The page's ADDRESS changed within the same route: the router
30
+ * pushed a same-path entry whose query or hash names a new target
31
+ * (?post=, #id — an in-site link click, not a traversal). The page
32
+ * does not remount, so holders of pre-address state repair
33
+ * themselves the way a history RETURN does: maximized windows the
34
+ * new address no longer names minimize, the named target reveals.
35
+ * The window system's own anchor pushes carry the state bookmark and
36
+ * never announce (they are UI entries, not content addresses). */
37
+ "page:addressed": { path: string; hash: string };
38
+ "window:close": { id: string; refuse: () => void };
39
+ /** Notice — Clippy parked the window the ✕ was pressed on (the
40
+ * mascot-on-screen easter egg): the successful close routed through
41
+ * Clippy's keep. Clippy owns the outcome and pipes up ("oh where did
42
+ * that go?.. I can help!"), offering its unhide roster. */
43
+ "clippy:hid": { id: string };
44
+ /** THE close's outcome NOTICE, with its sound DECLARED: the ✕ press
45
+ * dispatches which sound should play — the crunchy kick for every
46
+ * press that stays on the page (refusals, collapses, parks,
47
+ * maximized restores), the Click.ogg for the press that navigates
48
+ * away. One renderer (closeSounds.ts) plays what is declared. */
49
+ "window:closed": { id: string; sound: "kick" | "click" };
50
+ /** Command — the listening window's controller lifts the maximized
51
+ * view (the OK middleware rides this instead of threading a callback
52
+ * prop through the tree). */
53
+ "window:maximize": { id: string };
54
+ /** Command — restore/silently-dismiss the maximized view: ✕ on a
55
+ * maximized window, Escape, the out-of-bounds backdrop click and the
56
+ * title-bar Restore all ride this; the window's controller restores
57
+ * the flags it left with. `reveal: true` additionally reveals the
58
+ * content inline after the restore (the rail's OK/Cancel pair) —
59
+ * restore alone is the silent framing dismissal it always was. */
60
+ "window:dismiss": { id: string; reveal?: boolean | undefined };
61
+ /** Command — THE minimize: one path for every minimize gesture and
62
+ * its callbacks. On a maximized window the dismissal plays the
63
+ * minimize click (Click.ogg), slides the window off and either
64
+ * RESTORES the section underneath exactly as it stood at maximize
65
+ * time (park unset — the browser back out of the maximized view: the
66
+ * traversal pops the maximize push and the page:returned repair
67
+ * dispatches this) or COLLAPSES it the way the inline minimize
68
+ * handler always does (park set — the title-bar minimize button, and
69
+ * the double-click on the maximized title bar: the maximized overlay
70
+ * AND the section underneath both minimize; the section lands in its
71
+ * normal resting shape, OK bottom-right). Inline the depth-0 fold
72
+ * navigates away; every other inline window collapses to its title
73
+ * bar's ok row. The window's own controller performs the branch —
74
+ * every window listens, only the named one acts. */
75
+ "window:minimize": { id: string; park?: boolean };
76
+ /** Command — expand the named window WITHOUT lifting it: its lineage
77
+ * always opens (a collapsed parent never mounts its target), then
78
+ * either nothing but the target itself ("none" — the maximized view
79
+ * restored inline: a framing, not a reveal — collapsed sections stay
80
+ * collapsed), its direct children, or the whole subtree ("all"). The
81
+ * maximized framing keeps a returned section's inner sections as
82
+ * they stood — no force-open cascade behind the backdrop. */
83
+ "window:reveal": { id: string; descendants: "none" | "direct" | "all" };
84
+ /** Command — the history owner (lib/history) writes the named window
85
+ * into the CURRENT history entry: the id rides the entry's state
86
+ * payload ("window" key), the URL goes to what the caller computed.
87
+ * mode "push" is the maximized view's own history entry (browser back
88
+ * then pops INTO it: one entry per maximize, back un-maximizes);
89
+ * mode "replace" settles the URL after an in-page dismissal, dropping
90
+ * the bookmark when no maximized window remains. */
91
+ "history:anchor": {
92
+ /** Absent: clear the entry's bookmark (the last maximized window
93
+ * was dismissed); present: the window the entry names. */
94
+ id?: string | undefined;
95
+ url: string;
96
+ mode: "push" | "replace";
97
+ };
98
+ /** Command — bookmark the named window for an OFF-SITE departure: the
99
+ * CURRENT entry's state gains "window" and the URL lands on the
100
+ * caller's hash-free form, so navigating back to this entry (cross
101
+ * document, a fresh boot) reveals and scrolls to the section while
102
+ * the address bar carries no hash of it. */
103
+ "history:remember": { id: string; url: string };
104
+ "window:hidden": {
105
+ items: Array<{ id: string; label: string }>;
106
+ restore: (id: string) => void;
107
+ }; // retained — the parked-window roster; readers hold no state of their own
108
+ };
109
+
110
+ /** The roster of no parked windows: both the retained seed and the
111
+ * answer broadcasters send when the roster empties, so snapshot
112
+ * identity is stable across every empty interval. */
113
+ export const EMPTY_HIDDEN: SignalManifest["window:hidden"] = {
114
+ items: [],
115
+ restore: () => {},
116
+ };
117
+
118
+ /** Which signals RETAIN their last payload at module scope, seeded
119
+ * before the first dispatch. A retained signal's consumers are
120
+ * render-time READERS (useSignalValue) instead of effect-bound
121
+ * handlers: no useState bridge, no subscription management. A retained
122
+ * publisher must send a fresh snapshot object per change and never
123
+ * recompute the current one on read — useRetained does both. */
124
+ export const RETAINED: Partial<Record<SignalName, SignalManifest[SignalName]>> =
125
+ {
126
+ "window:hidden": EMPTY_HIDDEN,
127
+ };
128
+
129
+ export type SignalName = keyof SignalManifest;
130
+
131
+ export type SignalHandler<Name extends SignalName = SignalName> = (
132
+ payload: SignalManifest[Name],
133
+ ) => void;
134
+
135
+ /** Handlers registered per signal name. The never-parameter shape keeps
136
+ * the registry untyped internally while dispatch/on stay fully typed. */
137
+ type AnyHandler = (payload: never) => void;
138
+ const handlers = new Map<SignalName, Set<AnyHandler>>();
139
+
140
+ /** The last dispatched payload of each retained signal, and the cached
141
+ * getSnapshot of every one: identity is stable between dispatches, as
142
+ * useSyncExternalStore requires. */
143
+ const lastRetained = new Map<SignalName, SignalManifest[SignalName]>();
144
+ const retainedListeners = new Map<SignalName, Set<() => void>>();
145
+ const cachedSnapshot = (name: SignalName): SignalManifest[SignalName] =>
146
+ lastRetained.get(name) ?? RETAINED[name] ?? EMPTY_HIDDEN;
147
+
148
+ /** Dispatches a named signal: every current handler runs synchronously,
149
+ * in registration order, over a snapshot (handlers may unsubscribe or
150
+ * dispatch further signals mid-flight). Retained signals take their new
151
+ * snapshot BEFORE the handlers run (handlers read a consistent world)
152
+ * and their readers re-render AFTER they settle (no mid-dispatch
153
+ * render). The bus lives at module scope so machinery outside React —
154
+ * the pageSlide theme, lib singletons — dispatches and listens too; the
155
+ * context below makes it ambient for components. */
156
+ export function dispatchSignal<Name extends SignalName>(
157
+ name: Name,
158
+ payload: SignalManifest[Name],
159
+ ): void {
160
+ if (name in RETAINED) lastRetained.set(name, payload);
161
+ const registered = handlers.get(name);
162
+ if (registered) {
163
+ for (const handler of [...registered]) {
164
+ (handler as SignalHandler<Name>)(payload);
165
+ }
166
+ }
167
+ const listeners = retainedListeners.get(name);
168
+ if (listeners) {
169
+ for (const listener of [...listeners]) listener();
170
+ }
171
+ }
172
+
173
+ /** Subscribes a handler to a named signal; returns the unsubscribe. */
174
+ export function onSignal<Name extends SignalName>(
175
+ name: Name,
176
+ handler: SignalHandler<Name>,
177
+ ): () => void {
178
+ let registered = handlers.get(name);
179
+ if (!registered) handlers.set(name, (registered = new Set()));
180
+ const entry = handler as AnyHandler;
181
+ registered.add(entry);
182
+ return () => {
183
+ registered?.delete(entry);
184
+ };
185
+ }
186
+
187
+ /** Subscribes a render-time reader of a retained signal's snapshots;
188
+ * returns the unsubscribe. The never-parameter shape defers to the same
189
+ * internal typing as the handler registry. */
190
+ function onRetained(name: SignalName, listener: () => void): () => void {
191
+ let registered = retainedListeners.get(name);
192
+ if (!registered) retainedListeners.set(name, (registered = new Set()));
193
+ registered.add(listener);
194
+ return () => {
195
+ registered?.delete(listener);
196
+ };
197
+ }
198
+
199
+ type SignalBus = {
200
+ dispatch: typeof dispatchSignal;
201
+ on: typeof onSignal;
202
+ };
203
+
204
+ const Ctx = createContext<SignalBus | null>(null);
205
+
206
+ /** Wraps the app in the abstract signal context. The bus is shared and
207
+ * stable, so the provider never re-renders consumers — signals are
208
+ * events, not state. */
209
+ export function SignalProvider({ children }: { children: ReactNode }) {
210
+ const bus = useMemo<SignalBus>(
211
+ () => ({ dispatch: dispatchSignal, on: onSignal }),
212
+ [],
213
+ );
214
+ return <Ctx.Provider value={bus}>{children}</Ctx.Provider>;
215
+ }
216
+
217
+ export function useSignals(): SignalBus {
218
+ const bus = useContext(Ctx);
219
+ if (!bus) throw new Error("useSignals needs a SignalProvider");
220
+ return bus;
221
+ }
222
+
223
+ /** Subscribes a handler for the component's lifetime; the latest handler
224
+ * closure runs on every dispatch (no resubscription churn). THE one
225
+ * component-scoped escape hatch: for handlers that must close over
226
+ * component state no module-level attach can reach (e.g. the window
227
+ * store's return repair). Behaviours with a module owner attach via
228
+ * onSignal instead of calling this. */
229
+ export function useSignalHandler<Name extends SignalName>(
230
+ name: Name,
231
+ handler: SignalHandler<Name>,
232
+ ): void {
233
+ const { on } = useSignals();
234
+ const latest = useRef(handler);
235
+ latest.current = handler;
236
+ useEffect(() => on(name, (payload) => latest.current(payload)), [name, on]);
237
+ }
238
+
239
+ /** Reads a retained signal's current snapshot at render time: the
240
+ * subscription lifecycle is useSyncExternalStore's business, not the
241
+ * component's — no useState bridge, no manual effect, no missed first
242
+ * publish. */
243
+ export function useSignalValue<Name extends SignalName>(
244
+ name: Name,
245
+ ): SignalManifest[Name] {
246
+ const subscribe = useCallback(
247
+ (onChange: () => void) => onRetained(name, onChange),
248
+ [name],
249
+ );
250
+ return useSyncExternalStore(
251
+ subscribe,
252
+ () => cachedSnapshot(name) as SignalManifest[Name],
253
+ );
254
+ }
255
+
256
+ /** Declares a retained publication: the publisher hands in the
257
+ * snapshot it currently holds (a fresh object per change) and commits
258
+ * nothing itself — the library broadcasts it post-render whenever its
259
+ * identity changes and restores the manifest seed on unmount, so a
260
+ * publisher's reader never sees a stale roster after the page that
261
+ * parked the window is gone. Publishers stay declarative: no dispatch
262
+ * choreography, no teardown effect. */
263
+ export function useRetained<Name extends SignalName>(
264
+ name: Name,
265
+ snapshot: SignalManifest[Name],
266
+ ): void {
267
+ useEffect(() => {
268
+ dispatchSignal(name, snapshot);
269
+ return () => dispatchSignal(name, RETAINED[name] as SignalManifest[Name]);
270
+ }, [name, snapshot]);
271
+ }
package/src/main.tsx CHANGED
@@ -5,15 +5,29 @@ import "xp.css/dist/98.css";
5
5
  import "react-toastify/dist/ReactToastify.css";
6
6
  import "./styles/index.css";
7
7
  import { App } from "./shell/App";
8
+ import { SignalProvider } from "./lib/signals";
9
+ import { attachHistoryBookmarks } from "./lib/history";
10
+ import { attachRouterSignals } from "./shell/routerSignals";
11
+ import { attachCloseSounds } from "./window/closeSounds";
8
12
  import { enablePageSlide } from "./themes/pageSlide";
9
13
 
10
14
  document.body.classList.add("styles-loaded");
15
+ // Attach the shell's signal handlers at boot, next to the theme: the
16
+ // bus carries navigation commands, route-change notices and window
17
+ // events; handlers live here and in lib modules, not in components.
18
+ attachRouterSignals();
19
+ attachCloseSounds();
20
+ // The history bookmarker (maximized-view pushes, hash-free off-site
21
+ // bookmarks, dismissal settles) attaches at boot too: the maximized
22
+ // view's push rides the pageSlide pushState wrapper, so the owner must
23
+ // be live before any window can lift.
24
+ attachHistoryBookmarks();
11
25
  // Always install the page-slide theme: its hooks drive window
12
26
  // minimisation, navigation choreography and sounds. When the page is
13
27
  // loaded directly ONTO a hyperlinked window target (a #hash or ?post=
14
- // the route maximizes), the theme starts "parked" — zero slide distance
15
- // — so the entrance slide plays from nowhere and disturbs nothing while
16
- // the maximized overlay is the only visible paint. Page loads without a
28
+ // slug the route reveals), the theme starts "parked" — zero slide
29
+ // distance — so the entrance plays from nowhere and disturbs nothing
30
+ // before the reveal scrolls to the linked section. Page loads without a
17
31
  // hyperlink target slide in from the top as usual; later navigations
18
32
  // apply a real direction and slide as usual.
19
33
  enablePageSlide();
@@ -21,7 +35,9 @@ enablePageSlide();
21
35
  createRoot(document.getElementById("root")!).render(
22
36
  <StrictMode>
23
37
  <BrowserRouter>
24
- <App />
38
+ <SignalProvider>
39
+ <App />
40
+ </SignalProvider>
25
41
  </BrowserRouter>
26
42
  </StrictMode>,
27
43
  );