@hadoku/ui-shell 0.1.180 → 0.1.181

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,181 +1,38 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*
3
- * The app's chrome: everything above the screens, and the boundary anything
4
- * that replaces it has to honour.
5
- *
6
- * cardtable was hydrated from `templates/tunnel-loopback-ui`, which scaffolds
7
- * no UI at all, and the hydrator's "NO HADOKU CHROME" warning is gated on
8
- * `isProxy && !isContained` — so a loopback-ui app never sees it. Nothing in
9
- * the pipeline ever handed this app `HadokuThemeRoot` or `AppHeader`, and the
10
- * operator found the two symptoms in one viewport: no theme selector anywhere,
11
- * beside a watchparty chat column that WAS themed because `RoomChrome` reads
12
- * `@wolffm/themes` itself. `docs/requests/HADOKU_SITE_GAME_TEMPLATE.md` is the
13
- * ask that the next loopback-ui app not repeat it.
14
- *
15
- * This file is the fix, and it is deliberately thin: everything it renders
16
- * belongs to the platform.
17
- *
18
- * =====================================================================
19
- * THE CONTRACT — read this before swapping this file for the template
20
- * =====================================================================
21
- *
22
- * hadoku_site's `templates/game` is meant to replace this hand-written
23
- * wrapper. That swap is the whole reason this section exists: the boundary
24
- * it has to land on is written down here, so the replacement is a diff
25
- * against a stated contract rather than archaeology over six files. Wave 18
26
- * §D is where it was written; the audit behind "known gaps" below was run
27
- * then, and the line numbers are from that reading.
28
- *
29
- * ## The swap, done: it was a LAYOUT diff, not a migration (wave 21 §A)
30
- *
31
- * The operator, 2026-09-25: *"would be much better to use the child frontend
32
- * header that is minted with the proper standard child app header that
33
- * hadoku_site uses"*. Read against the reference before anything was designed
34
- * — `~/srv/hadoku_site/templates/game/apps/ui/src/`, `templates/ui-app` and
35
- * `templates/tunnel-contained` — and the answer was that we ALREADY mount the
36
- * fleet's header: the same `AppHeader` from `@wolffm/task-ui-components`, with
37
- * the same `@wolffm/task-ui-components/app-header.css` import, inside the same
38
- * `HadokuThemeRoot`. There is no other header in the fleet to migrate to.
39
- *
40
- * What differed was where the header SITS. The fleet's header stylesheet sets
41
- * no left/right/top spacing on purpose; in `templates/ui-app` and
42
- * `templates/tunnel-contained` the buffer comes from the content wrapper the
43
- * header is rendered inside (`padding: 2rem`). `templates/game` is the one
44
- * template that renders `<AppHeader>` OUTSIDE that wrapper, and this app was
45
- * written against `templates/game` — which is exactly why the bar had no edge
46
- * buffer. `chrome.css` now carries that one rule, with the provenance of its
47
- * value; see its `.cardtable-chrome > .app-header` block.
48
- *
49
- * ## The division
50
- *
51
- * `main.tsx` mounts and nothing else. `App.tsx` routes and authors the
52
- * header. `chrome/` frames — it owns everything ABOVE the screens and
53
- * nothing below them, and it knows what a pod, a room or a match is only in
54
- * the sense that `chrome.css` has to name their dark roots (see the island
55
- * seam below). Screens own themselves.
56
- *
57
- * ## What `chrome/` guarantees to whatever it wraps
58
- *
59
- * 1. **The theme tokens are defined and resolved.** `--color-*` and
60
- * `--hdk-*` exist by the time a child paints, and `data-theme` is on
61
- * <html> AND mirrored onto `.cardtable-chrome`, so a descendant resolves
62
- * light/dark from either. `screens/screens.css` paints entirely from
63
- * these. This is the designed channel between chrome and screens and the
64
- * only one — there is no theme value on any prop today.
65
- * 1. **`color-scheme` matches the theme**, via `data-dark-theme` on the
66
- * container, so native controls and scrollbars are not the wrong half.
67
- * 2. **One content region, and it grows.** `.cardtable-chrome__content` is a
68
- * column flex item with `min-height: 0`, and its DIRECT CHILD is given
69
- * `flex: 1 1 auto; min-height: 0`. A screen may assume it has the
70
- * viewport minus the header and may scroll inside it; `screens.css`
71
- * dropped its own `min-height: 100vh` on the strength of this.
72
- * 3. **`window.matchMedia` exists** before any child effect runs
73
- * (`ensureMatchMedia()`, at module load — `matchMedia.ts` has the
74
- * upstream bug it absorbs). A wrapper that drops it takes the throw in
75
- * every jsdom test that renders `App`, and in any embedder without the
76
- * API.
77
- * 4. **Exactly one chrome per page.** Watchparty's store and socket are
78
- * module singletons; a second `RoomChrome` shares and then tears down the
79
- * first one's connection. This wraps `RoomShell`, outside it, once.
80
- *
81
- * ## What a screen may assume
82
- *
83
- * Its own props, and the CSS tokens above. Nothing else. There is no chrome
84
- * context, no chrome export a screen imports, and no global this file sets.
85
- * `grep -r "from '../chrome" games/magic/ui/src/screens/` is empty and is meant to
86
- * stay empty — that grep is the cheap half of this contract.
87
- *
88
- * ## What `chrome/` will pass down when a screen needs something
89
- *
90
- * A prop from `App.tsx`, or a context exported from this directory. Never a
91
- * global, never a module singleton. Both candidates are already resolved
92
- * above the screens and neither is asked for today:
93
- *
94
- * - **Identity.** `App.tsx` reads `useWhoami()` once and spends it on the
95
- * header's `status` and `settingsProps`. `RoomShell` reads the same hook,
96
- * and `whoami()` shares one in-flight promise per page
97
- * (`globalThis.__hadokuWhoami`), so that is one identity path with two
98
- * consumers rather than two paths. A screen that needs the viewer takes it
99
- * as a prop; it does not call `whoami()` itself.
100
- * - **Theme state.** `useHadokuTheme()` is read in `ChromeInner` and nowhere
101
- * else in this repo. A screen that has to branch on light/dark takes
102
- * `isDarkTheme` as a prop or reads `data-theme` in CSS.
103
- *
104
- * ## What a replacement wrapper must provide
105
- *
106
- * The five guarantees, plus the two seams this file carries that do not look
107
- * like chrome at first glance:
108
- *
109
- * - **The island rules in `chrome.css`** (its last three blocks). The draft
110
- * table and its neighbours paint from the TABLE's palette — `--bg`,
111
- * `--ink` — which is dark on purpose, and they inherit their text colour.
112
- * Letting `--color-text` reach them puts a light theme's dark ink on a
113
- * permanently dark tile. Those rules are the seam between the themed frame
114
- * and the table; a wrapper that drops them breaks the table in light mode,
115
- * and the breakage is the chrome's.
116
- * - **The header is a SLOT, not an import.** `App.tsx` authors `<AppHeader>`
117
- * at the app root — the fleet's convention, and where its audit reads it —
118
- * and this file slots it in INSIDE `HadokuThemeRoot`, the one place it is
119
- * themeable. `<AppHeader>` renders the theme picker and the settings gear
120
- * itself; neither is a prop and there is no slot to substitute one, which
121
- * is the point. Its `title` is a NODE — a link home, with the <h1> inside
122
- * it — and `chrome.css` owns the two rules that make that node stop
123
- * looking like a link, plus the header's edge buffer. A wrapper that slots
124
- * a different header in has to bring both.
125
- *
126
- * ## The game's settings ARE in the header's gear, through its slot
127
- *
128
- * Out of it from 2026-10-10 (a host's menu is not ours to fill, and embedded
129
- * there is no header), back in on 2026-10-30 when the operator made the fleet's
130
- * popout the one place for settings. `App.tsx` passes `CARDTABLE_SETTINGS_TABS`
131
- * as `<AppHeader>`'s `appTabs`, the slot the fleet made for exactly this: tabs
132
- * of the game's own after the site's, never reaching into the header's own markup.
133
- * Embedded, `../settings/Settings.tsx`'s own gear stands in until watchparty
134
- * draws the popout.
135
- *
136
- * ## Theming is NOT ours, and must not become ours
137
- *
138
- * `<HadokuThemeRoot>` owns the theme, its three persistence layers
139
- * (sessionStorage for the pre-paint script, localStorage for the next cold
140
- * load, the prefs row for cross-device) and the picker. There is no local
141
- * `useTheme`, `themePrefs` or `themeConfig` in this repo and there must never
142
- * be one — eight apps each carried a hand-copied `useTheme.ts` and they drifted
143
- * on real behaviour (only one wrote localStorage, so the rest lost the theme on
144
- * a browser restart). That is the entire reason the shared one exists.
145
- *
146
- * ## Known gaps — where the boundary is NOT clean
147
- *
148
- * Audited at wave 18. Lane D owned only `chrome/**`, `App.tsx`, `main.tsx`
149
- * and `index.html`, so every one of these is reported here rather than
150
- * fixed: each fix lives in a file the lane did not own. They are listed
151
- * because a wrapper swap meets them, not because they are acceptable.
152
- *
153
- * 2. **`screens/route.ts` is a global-reading module singleton** — the hash
154
- * router reads `globalThis.location.hash` (:290, :304), subscribes to
155
- * `hashchange` on the global (:282, :285) and mints ids from
156
- * `globalThis.crypto` (:254). Every screen imports `navigate` from it,
157
- * and so does `App.tsx` (`useRoute`). It is deliberate and documented
158
- * there, but it means a screen's navigation is not a prop, and a wrapper
159
- * that owns routing has to meet it. The watchparty embed (D21) meets it
160
- * with `routeInMemory`, which takes the router off the address bar.
161
- * 3. **`rooms/RoomList.tsx` subscribes to `document.visibilitychange`** in
162
- * the effect that drives its poll, to stop polling on a hidden tab.
163
- * Page-visibility is the shell's fact, not a list's. (No line numbers:
164
- * lane C is rewriting that file in this same wave.)
165
- * 4. **`screens/tables.ts` (:127) and `screens/LobbyScreen.tsx` read
166
- * `import.meta.env`** — `BASE_URL` for the api base, `DEV` for a
167
- * dev-only affordance. Build-time, not runtime, and both optional-chain.
168
- * Named so a wrapper that changes the base path knows where it is read.
169
- * 5. **`chrome.css` reaches DOWN**, at its last blocks, naming
170
- * `.app`, `.draft`, `.board`, `.deck`, `.deckrow`, `.rooms`, `.spectate`,
171
- * `.conn`, `.prompt` and `.confirm`. That is this lane's
172
- * own file and it is the island seam above — deliberate, but it is a
173
- * coupling in the other direction and it is the thing to delete when
174
- * those sheets move onto semantic tokens.
175
- *
176
- * What is NOT here, and must not move here: routing rules, the api base,
177
- * room/match/draft state, and anything that knows a card. This file renders
178
- * a frame.
3
+ * The app's chrome: everything above the screens, and the boundary anything that replaces it has
4
+ * to honour. It is deliberately thin: everything it renders belongs to the platform. `App.tsx`
5
+ * authors the fleet's `<AppHeader>` (with the game's settings tabs in its gear, through `appTabs`)
6
+ * and this file slots it in INSIDE `HadokuThemeRoot`, the one place it is themeable. `main.tsx`
7
+ * mounts and nothing else; screens own themselves.
8
+ *
9
+ * ## What it guarantees to whatever it wraps
10
+ *
11
+ * 1. **The theme tokens are defined and resolved.** `--color-*` and `--hdk-*` exist by the time a
12
+ * child paints, and `data-theme` is on <html> AND mirrored onto `.cardtable-chrome`, so a
13
+ * descendant resolves light/dark from either. This is the one channel between chrome and
14
+ * screens; there is no theme value on any prop.
15
+ * 2. **`color-scheme` matches the theme**, via `data-dark-theme` on the container, so native
16
+ * controls and scrollbars are not the wrong half.
17
+ * 3. **One content region, and it grows.** `.cardtable-chrome__content` is a column flex item with
18
+ * `min-height: 0`, and its direct child gets `flex: 1 1 auto; min-height: 0` (`chrome.css`). A
19
+ * screen may assume the viewport minus the header and may scroll inside it.
20
+ * 4. **`window.matchMedia` exists** before any child effect runs (`ensureMatchMedia()`, at module
21
+ * load; `matchMedia.ts` has the upstream bug it absorbs).
22
+ * 5. **Exactly one chrome per page.** Watchparty's store and socket are module singletons; a second
23
+ * `RoomChrome` shares and then tears down the first one's connection.
24
+ *
25
+ * A screen may assume its own props and the CSS tokens above, nothing else: no chrome context, no
26
+ * global this file sets. When a screen needs the viewer or the theme, it takes it as a prop from
27
+ * `App.tsx` (which reads `useWhoami()` once) or reads `data-theme` in CSS.
28
+ *
29
+ * A replacement wrapper must also bring the two seams `chrome.css` carries: the island rules (the
30
+ * draft table and its neighbours paint from the table's own dark palette, and a light theme's ink
31
+ * must not reach them) and the header's edge buffer and title-link rules.
32
+ *
33
+ * Theming is not ours: `<HadokuThemeRoot>` owns the theme, its persistence and the picker. There
34
+ * is no local `useTheme` in this repo and there must never be one (eight apps each hand-copied
35
+ * one and drifted).
179
36
  */
180
37
  import { useRef } from 'react';
181
38
  import { HadokuThemeRoot, useHadokuTheme } from '@wolffm/themes';
@@ -1,5 +1,4 @@
1
1
  import { z } from 'zod';
2
- import { type GamesPrefs } from '@wolffm/prefs-client/platform';
3
2
  /** `volume` scales everything; `music` scales the music bus under it. Both 0..1. */
4
3
  export type LevelName = 'volume' | 'music';
5
4
  /** A level nobody has set: the music starts at half, under the game's own sounds; everything else full. */
@@ -9,13 +8,6 @@ export declare const SoundPrefsSchema: z.ZodObject<{
9
8
  musicPicks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
10
9
  }, z.core.$strict>;
11
10
  export type SoundPrefs = z.infer<typeof SoundPrefsSchema>;
12
- /** The `localStorage` keys the values lived in before the service held them, built from `appId()`. Called lazily — never at module load — so importing this before `configureShell` runs does not throw. */
13
- export declare function legacyKeys(): Readonly<{
14
- muted: string;
15
- volume: string;
16
- music: string;
17
- musicPicks: string;
18
- }>;
19
11
  type Listener = () => void;
20
12
  /** Whether sounds are currently silenced. */
21
13
  export declare function isMuted(): boolean;
@@ -38,14 +30,10 @@ export declare function setMusicPick(role: string, file: string): void;
38
30
  * service's own broadcast and lands here.
39
31
  */
40
32
  export declare function subscribeSound(fn: Listener): () => void;
41
- /** Whatever the old `<appId>.sound.*` keys still hold, parsed; anything unreadable is absent. */
42
- export declare function readLegacy(store?: Storage | undefined): GamesPrefs & SoundPrefs;
43
33
  /**
44
34
  * Connect the sound settings to the preference service for as long as the calling component is
45
35
  * mounted: adopt what it holds, follow its changes (another tab, another host on the page), and
46
- * save every change made here. The first time a page connects, a value only the old keys hold is
47
- * saved to the service and the keys are removed. `ready` settles once the service's first answer
48
- * is adopted.
36
+ * save every change made here. `ready` settles once the service's first answer is adopted.
49
37
  */
50
38
  export declare function connectSoundPrefs(): {
51
39
  ready: Promise<void>;
@@ -14,8 +14,7 @@
14
14
  * never collide). The three levels are per DEVICE, as `localStorage` held
15
15
  * them; music picks are per PLAYER. Values live here in memory, read
16
16
  * synchronously on every sound; `useSoundPrefs` connects them to the
17
- * service once per page. The old `<appId>.sound.*` keys are read once, as
18
- * a migration, and removed.
17
+ * service once per page.
19
18
  */
20
19
  import { useEffect } from 'react';
21
20
  import { z } from 'zod';
@@ -32,16 +31,6 @@ export const SoundPrefsSchema = z
32
31
  musicPicks: z.record(z.string(), z.string()).optional(),
33
32
  })
34
33
  .strict();
35
- /** The `localStorage` keys the values lived in before the service held them, built from `appId()`. Called lazily — never at module load — so importing this before `configureShell` runs does not throw. */
36
- export function legacyKeys() {
37
- const prefix = appId();
38
- return {
39
- muted: `${prefix}.sound.muted`,
40
- volume: `${prefix}.sound.volume`,
41
- music: `${prefix}.sound.music`,
42
- musicPicks: `${prefix}.sound.music-picks`,
43
- };
44
- }
45
34
  let muted = GAMES_DEFAULTS.muted;
46
35
  let musicPicks = {};
47
36
  const levels = { ...LEVEL_DEFAULTS };
@@ -123,58 +112,11 @@ function adopt(games, sound) {
123
112
  if (JSON.stringify([muted, levels, musicPicks]) !== before)
124
113
  notify();
125
114
  }
126
- /** Whatever the old `<appId>.sound.*` keys still hold, parsed; anything unreadable is absent. */
127
- export function readLegacy(store = globalThis.localStorage) {
128
- const out = {};
129
- if (store === undefined)
130
- return out;
131
- const raw = (key) => {
132
- try {
133
- return store.getItem(key);
134
- }
135
- catch {
136
- // A blocked store holds nothing to move.
137
- return null;
138
- }
139
- };
140
- const keys = legacyKeys();
141
- const m = raw(keys.muted);
142
- if (m === 'true' || m === 'false')
143
- out.muted = m === 'true';
144
- for (const name of ['volume', 'music']) {
145
- const v = raw(keys[name]);
146
- const n = v === null ? NaN : Number(v);
147
- if (Number.isFinite(n))
148
- out[name] = clamp(n);
149
- }
150
- const p = raw(keys.musicPicks);
151
- if (p !== null) {
152
- try {
153
- const parsed = SoundPrefsSchema.shape.musicPicks.safeParse(JSON.parse(p));
154
- if (parsed.success && parsed.data !== undefined)
155
- out.musicPicks = parsed.data;
156
- }
157
- catch {
158
- // Not JSON: no picks to move.
159
- }
160
- }
161
- return out;
162
- }
163
- function removeLegacy(store = globalThis.localStorage) {
164
- for (const key of Object.values(legacyKeys())) {
165
- try {
166
- store?.removeItem(key);
167
- }
168
- catch {
169
- // A blocked store: the keys stay, and are read again (and found already moved) next time.
170
- }
171
- }
172
- }
173
115
  /** Each a row of its own, built on first connect; one per app id, as the SDK promises. */
174
116
  let clients = null;
175
117
  function soundClients() {
176
118
  clients ??= {
177
- // No `defaults`: an unset field is how `connectSoundPrefs` knows the legacy key still has to move.
119
+ // No `defaults`: a field the service does not hold keeps the page's value (`adopt`).
178
120
  games: createPrefsClient({ appId: GAMES_ROW.appId, schema: GAMES_ROW.schema }),
179
121
  sound: createPrefsClient({ appId: `${appId()}-sound`, schema: SoundPrefsSchema }),
180
122
  };
@@ -183,15 +125,11 @@ function soundClients() {
183
125
  /**
184
126
  * Connect the sound settings to the preference service for as long as the calling component is
185
127
  * mounted: adopt what it holds, follow its changes (another tab, another host on the page), and
186
- * save every change made here. The first time a page connects, a value only the old keys hold is
187
- * saved to the service and the keys are removed. `ready` settles once the service's first answer
188
- * is adopted.
128
+ * save every change made here. `ready` settles once the service's first answer is adopted.
189
129
  */
190
130
  export function connectSoundPrefs() {
191
131
  const c = soundClients();
192
132
  connection = c;
193
- const legacy = readLegacy();
194
- adopt(legacy, legacy);
195
133
  let games = {};
196
134
  let sound = {};
197
135
  const offGames = c.games.subscribe((next) => {
@@ -207,18 +145,6 @@ export function connectSoundPrefs() {
207
145
  return;
208
146
  games = g;
209
147
  sound = s;
210
- const toGames = {};
211
- if (g.muted === undefined && legacy.muted !== undefined)
212
- toGames.muted = legacy.muted;
213
- if (g.volume === undefined && legacy.volume !== undefined)
214
- toGames.volume = legacy.volume;
215
- if (Object.keys(toGames).length > 0)
216
- void c.games.save(toGames, { scope: GAMES_ROW.scope });
217
- if (s.music === undefined && legacy.music !== undefined)
218
- void c.sound.save({ music: legacy.music }, { scope: 'device' });
219
- if (s.musicPicks === undefined && legacy.musicPicks !== undefined)
220
- void c.sound.save({ musicPicks: legacy.musicPicks });
221
- removeLegacy();
222
148
  adopt(games, sound);
223
149
  });
224
150
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/ui-shell",
3
- "version": "0.1.180",
4
- "gitHead": "08b6dd41a5babb752b2291cdfbc1566758032125",
3
+ "version": "0.1.181",
4
+ "gitHead": "28246a63a42ac214aa91feecefa5ab94c394a570",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The parts of a game's UI any game keeps: chrome, trim, room shell, embed mount, theme and settings frame, UI scale, usage counting, the sound mixer, motion and generic components. One appId parameterizes its storage keys, events and chat prefix. MIT; imports only react, react-dom, platform-wire and @wolffm/*.",
@@ -68,7 +68,7 @@
68
68
  "react-dom": "^19.2.8"
69
69
  },
70
70
  "dependencies": {
71
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.180",
71
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.181",
72
72
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
73
73
  "@wolffm/themes": "npm:@hadoku/themes@^5.14.20",
74
74
  "zod": "4.5.4"