website-xp-phone 2.3.0 → 2.5.1
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.
- package/build/blogDirsPlugin.ts +100 -0
- package/package.json +15 -8
- package/public/blog/archive/eighth-post-lost-in-the-sauce.json +36 -0
- package/public/blog/archive/noise/eleventh-post-discussion-java-gist.md +5 -0
- package/public/blog/archive/noise/fifteenth-post-very-rare-windows-funny.md +8 -0
- package/public/blog/archive/noise/fourth-post-meta-blog.md +3 -0
- package/public/blog/archive/noise/sixteenth-post-meta-fantasy-blog.md +4 -0
- package/public/blog/archive/noise/tenth-post-meta-funny-redacted-and-timetravelled.md +3 -0
- package/public/blog/archive/noise/twelfth-post-mixing-phase-technique-audio-music.md +48 -0
- package/public/blog/archive/noise/welcome-back-ramble-meta.md +6 -0
- package/public/blog/archive/noise/welcome-to-my-blog-meta-blog-welcome-to-my-website.md +7 -0
- package/public/blog/archive/seventh-post-lie-theory-na2000.json +22 -0
- package/public/blog/archive/sophus-lie.json +36 -0
- package/public/blog/hlwm_and_herbstutil.md +74 -0
- package/public/blog/writing/hot-action-under-a-cold-moon.json +9 -0
- package/public/checksums.txt +90 -67
- package/public/documents/drift-report.json +13 -1
- package/scripts/refresh-soundcloud.mjs +54 -8
- package/sonar-project.properties +12 -0
- package/src/content/addons.json +2 -2
- package/src/content/blog.json +17 -365
- package/src/content/blogDirs.ts +197 -0
- package/src/content/configs.json +5 -3
- package/src/content/contacts.json +7 -5
- package/src/content/index.ts +155 -57
- package/src/content/music-ext.json +1 -1
- package/src/content/pages.json +2 -1
- package/src/content/projects/development.json +2 -2
- package/src/content/projects/doftiles.json +63 -7
- package/src/content/projects/frontend.json +2 -2
- package/src/content/projects/graphbrowser.json +2 -2
- package/src/content/projects/herbctl.json +213 -0
- package/src/content/projects/herbstutil.json +66 -36
- package/src/content/projects/lightdni-jssas-toggle.json +2 -2
- package/src/content/projects/on-deploy.json +67 -0
- package/src/content/projects/pagerts.json +4 -4
- package/src/content/projects/polyframes.json +83 -0
- package/src/content/projects/rarebert.json +2 -2
- package/src/content/projects/webuser.json +2 -2
- package/src/content/schema.ts +7 -4
- package/src/content/sections.json +20 -13
- package/src/content/soundcloud.json +61 -13
- package/src/lib/clippy.ts +29 -8
- package/src/lib/history.ts +152 -0
- package/src/lib/markdown.tsx +11 -1
- package/src/lib/scrollTo.ts +45 -0
- package/src/lib/signals.tsx +271 -0
- package/src/lib/slashes.ts +20 -0
- package/src/lib/tabNav.ts +192 -0
- package/src/main.tsx +20 -4
- package/src/pages/BlogDirPage.tsx +37 -0
- package/src/pages/BlogPostPage.tsx +78 -3
- package/src/pages/ProjectPage.tsx +9 -3
- package/src/pages/WowPage.tsx +8 -3
- package/src/pages/index.ts +2 -0
- package/src/shell/App.tsx +19 -8
- package/src/shell/Clippy.tsx +13 -3
- package/src/shell/MenuBar.tsx +7 -4
- package/src/shell/resolveRoute.ts +43 -3
- package/src/shell/routerSignals.ts +34 -0
- package/src/styles/extras.css +20 -0
- package/src/styles/layout.css +2 -3
- package/src/styles/menu.css +1 -1
- package/src/styles/window.css +20 -8
- package/src/themes/pageSlide/index.ts +120 -42
- package/src/themes/pageSlide/pageSlide.css +20 -9
- package/src/virtual.d.ts +14 -0
- package/src/window/MaximizedWindow.tsx +100 -64
- package/src/window/OkButton.tsx +42 -25
- package/src/window/PageWindows.tsx +7 -0
- package/src/window/TitleBar.tsx +3 -1
- package/src/window/Window.tsx +132 -87
- package/src/window/closeSounds.ts +27 -0
- package/src/window/model.ts +11 -0
- package/src/window/state.tsx +301 -54
- package/src/window/themes.ts +23 -2
- package/test/content.test.js +15 -10
- package/test/deploy-pipeline.test.js +11 -11
- package/test/markdown-tables.test.js +96 -0
- package/test/soundcloud-refresh.test.js +68 -0
- package/test/tabNav.test.js +137 -0
- package/tsconfig.node.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +7 -1
- package/xp.css/dist/98.css +2 -0
- package/xp.css/dist/98.css.map +1 -0
- package/xp.css/dist/GUI.css +2 -0
- package/xp.css/dist/GUI.css.map +1 -0
- package/xp.css/dist/XP.css +2 -0
- package/xp.css/dist/XP.css.map +1 -0
- package/xp.css/dist/fonts/converted/PerfectDOSVGA437Win.woff +0 -0
- package/xp.css/dist/fonts/converted/PerfectDOSVGA437Win.woff2 +0 -0
- package/xp.css/dist/fonts/converted/ms_sans_serif.woff +0 -0
- package/xp.css/dist/fonts/converted/ms_sans_serif.woff2 +0 -0
- package/xp.css/dist/fonts/converted/ms_sans_serif_bold.woff +0 -0
- package/xp.css/dist/fonts/converted/ms_sans_serif_bold.woff2 +0 -0
- package/public/blog/4th.md +0 -28
- package/public/blog/wsl.1.md +0 -40
- package/src/window/hidden.ts +0 -22
- /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
- /package/src/content/{characters.json → includes/characters.json} +0 -0
package/src/lib/clippy.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { playLayeredAudio } from "./audio";
|
|
2
|
+
import { onSignal } from "./signals";
|
|
2
3
|
import {
|
|
3
4
|
advanceWord,
|
|
4
5
|
blipRollMs,
|
|
@@ -23,6 +24,9 @@ export type ClippyState = {
|
|
|
23
24
|
saysNo: boolean;
|
|
24
25
|
/** The unhide list is shown instead of a bubble (masks it completely). */
|
|
25
26
|
listOpen: boolean;
|
|
27
|
+
/** The bubble carries the post-park offer ("oh where did that go?").
|
|
28
|
+
* Independent of saysNo: neither flag outlives its bubble. */
|
|
29
|
+
offering: boolean;
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
const storedVisible = () =>
|
|
@@ -34,6 +38,7 @@ let state: ClippyState = {
|
|
|
34
38
|
bubble: false,
|
|
35
39
|
saysNo: false,
|
|
36
40
|
listOpen: false,
|
|
41
|
+
offering: false,
|
|
37
42
|
};
|
|
38
43
|
const listeners = new Set<() => void>();
|
|
39
44
|
const set = (patch: Partial<ClippyState>) => {
|
|
@@ -126,12 +131,26 @@ const hint = () => {
|
|
|
126
131
|
// The hint is the priority UI: dismiss the unhide list in the same
|
|
127
132
|
// atomically-committed state update so it can never mask the bubble
|
|
128
133
|
// (the stray "haha it said no"/hiding interplay of the flag mirrors).
|
|
129
|
-
set({ bubble: true, saysNo: false, listOpen: false });
|
|
134
|
+
set({ bubble: true, saysNo: false, offering: false, listOpen: false });
|
|
130
135
|
bubbleTimer = setTimeout(
|
|
131
136
|
// saysNo dies with its bubble: a stale veto would otherwise turn every
|
|
132
137
|
// later bubble into "haha it said no" (visible the moment another
|
|
133
138
|
// bubble is unmasked, e.g. dismissing the reopen list).
|
|
134
|
-
() => set({ bubble: false, saysNo: false }),
|
|
139
|
+
() => set({ bubble: false, saysNo: false, offering: false }),
|
|
140
|
+
BUBBLE_MS,
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** The post-park pipe-up: ✕ closed a window while Clippy was on screen,
|
|
145
|
+
* so the window went into Clippy's keep — say the line and offer the
|
|
146
|
+
* unhide roster (the roster button lives on the image which is already
|
|
147
|
+
* the tap target that opens the list). The offer bubble follows the
|
|
148
|
+
* same lifecycle and priority atomics as the hint's. */
|
|
149
|
+
const offer = () => {
|
|
150
|
+
clearTimeout(bubbleTimer);
|
|
151
|
+
set({ bubble: true, saysNo: false, offering: true, listOpen: false });
|
|
152
|
+
bubbleTimer = setTimeout(
|
|
153
|
+
() => set({ bubble: false, saysNo: false, offering: false }),
|
|
135
154
|
BUBBLE_MS,
|
|
136
155
|
);
|
|
137
156
|
};
|
|
@@ -188,23 +207,25 @@ export const toggleClippyList = () => {
|
|
|
188
207
|
// said no" veto state — so the reopen list owns the attention; pending
|
|
189
208
|
// bubble timers are cancelled alongside.
|
|
190
209
|
clearTimeout(bubbleTimer);
|
|
191
|
-
set({ listOpen: true, bubble: false, saysNo: false });
|
|
210
|
+
set({ listOpen: true, bubble: false, saysNo: false, offering: false });
|
|
192
211
|
};
|
|
193
212
|
|
|
194
|
-
const onCrunchy = (
|
|
195
|
-
if (state.listOpen || !state.bubble || state.saysNo) return;
|
|
196
|
-
|
|
213
|
+
const onCrunchy = ({ refuse }: { refuse: () => void }) => {
|
|
214
|
+
if (state.listOpen || !state.bubble || state.saysNo || state.offering) return;
|
|
215
|
+
refuse();
|
|
197
216
|
set({ saysNo: true });
|
|
198
217
|
};
|
|
199
218
|
|
|
200
219
|
/** Attaches the global listeners; returns the detach function. */
|
|
201
220
|
export function attachClippy(): () => void {
|
|
202
221
|
window.addEventListener("keydown", onKeyDown);
|
|
203
|
-
|
|
222
|
+
const offWindowClose = onSignal("window:close", onCrunchy);
|
|
223
|
+
const offHid = onSignal("clippy:hid", offer);
|
|
204
224
|
getAudio().addEventListener("ended", onAudioEnded);
|
|
205
225
|
return () => {
|
|
206
226
|
window.removeEventListener("keydown", onKeyDown);
|
|
207
|
-
|
|
227
|
+
offWindowClose();
|
|
228
|
+
offHid();
|
|
208
229
|
getAudio().removeEventListener("ended", onAudioEnded);
|
|
209
230
|
clearBlip();
|
|
210
231
|
activeMs = 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
|
+
}
|
package/src/lib/markdown.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Markdown from "react-markdown";
|
|
2
2
|
import rehypeRaw from "rehype-raw";
|
|
3
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";
|
|
5
7
|
import { rehypeYoutubeEmbed } from "@/lib/rehypeYoutubeEmbed";
|
|
6
8
|
import { sanitizeSchema } from "@/lib/sanitizeSchema";
|
|
@@ -8,9 +10,17 @@ import { CLIPPY_LINK, onClippyTriggerClick } from "./clippy";
|
|
|
8
10
|
|
|
9
11
|
type Props = { children: string; inline?: boolean };
|
|
10
12
|
|
|
11
|
-
export function Md({ children }: Props) {
|
|
13
|
+
export function Md({ children }: Readonly<Props>) {
|
|
12
14
|
return (
|
|
13
15
|
<Markdown
|
|
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]}
|
|
14
24
|
rehypePlugins={[
|
|
15
25
|
rehypeRaw,
|
|
16
26
|
rehypeYoutubeEmbed,
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Path-slash trimming without regex backtracking scans (Sonar S8786).
|
|
2
|
+
* A trailing run of one character is O(1) per position but the regex
|
|
3
|
+
* matcher re-tries every start position on failure — O(n²) on long
|
|
4
|
+
* paths. These string walks are strictly linear. */
|
|
5
|
+
|
|
6
|
+
/** Strip trailing slashes ("/blog/" -> "/blog", "/" stays "/"). */
|
|
7
|
+
export function stripTrailingSlashes(path: string): string {
|
|
8
|
+
let end = path.length;
|
|
9
|
+
while (end > 1 && path[end - 1] === "/") end--;
|
|
10
|
+
return end === path.length ? path : path.slice(0, end);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Trim slashes on both ends ("/blog//" → "/blog"). */
|
|
14
|
+
export function stripEdgeSlashes(path: string): string {
|
|
15
|
+
let start = 0;
|
|
16
|
+
let end = path.length;
|
|
17
|
+
while (start < end && path[start] === "/") start++;
|
|
18
|
+
while (end > start && path[end - 1] === "/") end--;
|
|
19
|
+
return end - start === path.length ? path : path.slice(start, end);
|
|
20
|
+
}
|