@hadoku/game-ui 0.1.46 → 0.1.48

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,5 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
+ import { type RoomFeed } from '../rooms/feed.js';
2
3
  import type { Look } from '@wolffm/platform-wire/look';
4
+ import './RoomFront.css';
3
5
  export interface RoomFrontMember {
4
6
  id: string;
5
7
  name: string;
@@ -10,7 +12,8 @@ export interface RoomFrontMember {
10
12
  /** Every number and label a row draws besides its name, its lock and its roster — a game's own derivation, computed before the room reaches this file. */
11
13
  export interface RoomFrontView {
12
14
  seatsFilled: number;
13
- seatsCapacity: number;
15
+ /** `null` draws the count alone: a room whose seats grow (a tournament) has no capacity worth showing. */
16
+ seatsCapacity: number | null;
14
17
  state: {
15
18
  key: string;
16
19
  label: string;
@@ -72,10 +75,13 @@ export interface RoomFrontClient<V extends RoomFrontRoom> {
72
75
  message: string;
73
76
  }>;
74
77
  }
75
- /** What says the list changed, without polling it (`games/magic/ui/src/rooms/follow.ts`'s shape). Defaults to reading once and never again. */
76
- export interface RoomFrontFeed {
77
- follow(target: string, refresh: () => void): () => void;
78
- }
78
+ /**
79
+ * What says the list changed, without polling it. Defaults to the page's room feed
80
+ * (`../rooms/feed.ts`'s `roomFeed()`: game-server's `attachRoomFeed` pings, a read when the tab is
81
+ * shown again, and a long resilience read), so a game that attached the feed server-side needs no
82
+ * timer of its own.
83
+ */
84
+ export type RoomFrontFeed = RoomFeed;
79
85
  export interface RoomFrontGameType {
80
86
  id: string;
81
87
  label: string;
@@ -105,8 +111,14 @@ export interface RoomFrontRowExtras {
105
111
  seriesChip?: ReactNode;
106
112
  /** The row's trailing, screen-reader-mostly line (a streamed client's own label, say). */
107
113
  legacyMeta?: ReactNode;
108
- /** `data-family` on the row — which background gradient it draws (`rooms.css`). */
114
+ /** `data-family` on the row: the game's own name for its kind (a format family, say), for its tests and its telemetry. */
109
115
  family?: string;
116
+ /**
117
+ * The row's own custom properties (`./RoomFront.css`): `--room-front-tint` (the card's wash),
118
+ * `--room-front-dot` (its state's dot), `--room-front-state-ink` (its state's label). A game's own
119
+ * reading of its room, so the colours of a "drafting" or a "done" room are the game's, not this module's.
120
+ */
121
+ vars?: Readonly<Record<`--room-front-${string}`, string>>;
110
122
  }
111
123
  export interface RoomFrontProps<V extends RoomFrontRoom> {
112
124
  rooms: RoomFrontClient<V>;
@@ -152,13 +164,11 @@ export interface RoomFrontProps<V extends RoomFrontRoom> {
152
164
  /** The list's own `<section>`, the moment it mounts and again on unmount — a caller's own tooltip or scroll mechanism attaches here, same as it would to any other section it owns. */
153
165
  onSectionRef?: (el: HTMLElement | null) => void;
154
166
  /**
155
- * The create dialog's own panel class (default: an unstyled block of this module's own,
156
- * `room-front-create`). A caller with its own "raised surface" convention supplies its exact
157
- * class string here rather than this file hard-coding one — Magic's `RoomList.tsx` passes
158
- * `"rooms__create ct-surface ct-panel"`, the same classes base's own `CreateRoomDialog` always
159
- * drew, from the one file (`RoomList.tsx`, through `CreateEventDialog.tsx`'s own import of
160
- * `Modal.tsx`) `css-ownership.test.ts` already knows reaches the tree that owns `.ct-surface` —
161
- * this module never does, and must not have to.
167
+ * Classes added to the create dialog's panel, after its own `room-front-create` (which lays it
168
+ * out and draws a plain surface `./RoomFront.css` keeps low enough for these to draw over). A
169
+ * caller with its own "raised surface" convention supplies it here rather than this file
170
+ * hard-coding one: Magic's `RoomList.tsx` passes `"ct-surface ct-panel"`, from the one file
171
+ * `css-ownership.test.ts` already knows reaches the tree that owns `.ct-surface`.
162
172
  *
163
173
  * Named `createPanelClassName`, not the bare `className` an earlier draft of this prop used
164
174
  * (`docs/planning/s3-2026-11-17.md` §G.5): a plain `className` on a component that is not a
@@ -168,9 +178,9 @@ export interface RoomFrontProps<V extends RoomFrontRoom> {
168
178
  * list" check (`CLASS_AT`) used to recognise ONLY a literal sitting right after a bare
169
179
  * `className=`/`class=`, which is exactly why that draft kept the confusing name — any camelCase
170
180
  * prefix broke the check. `CLASS_AT` now also matches `\w*ClassName=` generically, so a
171
- * caller's own call-site literal (`<RoomFront createPanelClassName="rooms__create ct-surface
172
- * ct-panel" />`) is still recognised as a real class list, the same as a bare `className=` is.
181
+ * caller's own call-site literal (`<RoomFront createPanelClassName="ct-surface ct-panel" />`)
182
+ * is still recognised as a real class list, the same as a bare `className=` is.
173
183
  */
174
184
  createPanelClassName?: string;
175
185
  }
176
- export declare function RoomFront<V extends RoomFrontRoom>({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed, matches: matchesFilter, beforeOpenRoom, nameMaxLength, passwordMaxLength, testingStorageKey, defaultName, onSectionRef, createPanelClassName: createSurfaceClassName, }: RoomFrontProps<V>): import("react").JSX.Element;
186
+ export declare function RoomFront<V extends RoomFrontRoom>({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed, matches: matchesFilter, beforeOpenRoom, nameMaxLength, passwordMaxLength, testingStorageKey, defaultName, onSectionRef, createPanelClassName, }: RoomFrontProps<V>): import("react").JSX.Element;
@@ -16,9 +16,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
16
16
  *
17
17
  * Platform: imports nothing from `@hadoku/magic-ui`, any `games/**` package, or `@hadoku/shared`
18
18
  * (the layer ratchet resolves that package as Magic even through `/platform`, bar the handful of
19
- * files it whitelists itself). No CSS is imported here either: a caller's own stylesheet draws these
20
- * classes (cardtable's `games/magic/ui/src/rooms/rooms.css`, unmoved, still does for cardtable's own
21
- * app) — the DOM this file emits is exactly the markup `rooms.css` was already written against.
19
+ * files it whitelists itself). Its paint is `./RoomFront.css`, imported here: a game tunes it with
20
+ * that file's custom properties (on the page for the list, on `:root` for the dialog, which portals
21
+ * into `<body>`) and a row's own colours with `RoomFrontRowExtras.vars`, never with a copy of it.
22
22
  */
23
23
  import { useCallback, useContext, useEffect, useRef, useState } from 'react';
24
24
  import { Icon } from '@wolffm/themes';
@@ -33,12 +33,8 @@ import { MAX_ROOM_GHOSTS } from "./shape.js";
33
33
  import { ConstructedIcon, LockIcon, PersonIcon } from "./icons.js";
34
34
  import { useWhoami } from "../room/whoami.js";
35
35
  import { playRole } from "../sound/index.js";
36
- const NEVER_FOLLOWED = {
37
- follow(_target, refresh) {
38
- refresh();
39
- return () => undefined;
40
- },
41
- };
36
+ import { roomFeed } from "../rooms/feed.js";
37
+ import './RoomFront.css';
42
38
  const DEFAULT_NAME_MAX = 60;
43
39
  const DEFAULT_PASSWORD_MAX = 200;
44
40
  const DEFAULT_TESTING_KEY = 'room-front.testingFolded';
@@ -84,7 +80,7 @@ function saveTestingFolded(key, folded) {
84
80
  // Unremembered is the whole fallback; nothing else to do.
85
81
  }
86
82
  }
87
- export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed = NEVER_FOLLOWED, matches: matchesFilter, beforeOpenRoom, nameMaxLength = DEFAULT_NAME_MAX, passwordMaxLength = DEFAULT_PASSWORD_MAX, testingStorageKey = DEFAULT_TESTING_KEY, defaultName, onSectionRef, createPanelClassName: createSurfaceClassName = 'room-front-create', }) {
83
+ export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed = roomFeed(), matches: matchesFilter, beforeOpenRoom, nameMaxLength = DEFAULT_NAME_MAX, passwordMaxLength = DEFAULT_PASSWORD_MAX, testingStorageKey = DEFAULT_TESTING_KEY, defaultName, onSectionRef, createPanelClassName, }) {
88
84
  const [state, setState] = useState({ kind: 'loading' });
89
85
  const [creating, setCreating] = useState(false);
90
86
  const [testingFolded, setTestingFolded] = useState(() => loadTestingFolded(testingStorageKey));
@@ -142,10 +138,10 @@ export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, b
142
138
  if (drawnRooms !== null)
143
139
  remember({ rooms: drawnRooms });
144
140
  }, [drawnRooms, remember]);
145
- return (_jsxs(_Fragment, { children: [isRenderable(navTools) && _jsx("nav", { className: "shell__tools", children: navTools }), isRenderable(featured) && featured, isRenderable(banner) && banner, _jsxs("section", { className: "rooms ct-panel", "data-testid": "rooms", "aria-labelledby": "rooms-title", "aria-busy": !shown, ref: onSectionRef, children: [_jsxs("div", { className: "rooms__head", children: [_jsx("h2", { id: "rooms-title", className: "rooms__title ct-panel__title", children: "Rooms" }), headExtras, _jsxs("span", { className: "rooms__actions", children: [_jsx("button", { type: "button", className: "lobby__go", "data-testid": "room-create-open", "aria-haspopup": "dialog", onClick: () => {
141
+ return (_jsxs(_Fragment, { children: [isRenderable(navTools) && _jsx("nav", { className: "shell__tools", children: navTools }), isRenderable(featured) && featured, isRenderable(banner) && banner, _jsxs("section", { className: "rooms ct-panel", "data-testid": "rooms", "aria-labelledby": "rooms-title", "aria-busy": !shown, ref: onSectionRef, children: [_jsxs("div", { className: "rooms__head", children: [_jsx("h2", { id: "rooms-title", className: "rooms__title ct-panel__title", children: "Rooms" }), headExtras, _jsxs("span", { className: "rooms__actions", children: [_jsx("button", { type: "button", className: "room-front__go", "data-testid": "room-create-open", "aria-haspopup": "dialog", onClick: () => {
146
142
  playRole('ui.select');
147
143
  setCreating(true);
148
- }, children: "Create room" }), actionsExtras] })] }), _jsxs(Reveal, { name: "rooms", shown: shown, skeleton: _jsx(RoomGhosts, { count: shape.rooms }), layerClassName: "rooms__layer", children: [state.kind === 'failed' && (_jsxs("div", { className: "rooms__status rooms__status--bad", role: "alert", "data-testid": "rooms-error", children: [_jsx("p", { children: state.message }), _jsx("button", { type: "button", "data-testid": "rooms-retry", onClick: retry, children: "Retry" })] })), state.kind === 'ready' && normal.length === 0 && testing.length === 0 && (_jsx("p", { className: "rooms__status", "data-testid": "rooms-empty", children: "No rooms yet." })), state.kind === 'ready' && normal.length > 0 && (_jsx("ul", { className: "rooms__list", "data-testid": "room-list", children: orderedNormal.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) })), state.kind === 'ready' && testing.length > 0 && (_jsxs("div", { className: "rooms__testing", "data-testid": "rooms-testing", children: [_jsx("h3", { className: "rooms__title ct-panel__title", children: _jsxs("button", { type: "button", className: "rooms__fold", "aria-expanded": !testingFolded, "aria-controls": "room-list-testing", "data-testid": "rooms-testing-fold", onClick: toggleTesting, children: [_jsx("svg", { className: "rooms__fold-chevron", width: "14", height: "14", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M9 5l7 7-7 7" }) }), "Testing"] }) }), !testingFolded && (_jsx("ul", { className: "rooms__list", id: "room-list-testing", "data-testid": "room-list-testing", children: orderedTesting.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) }))] })), state.kind === 'ready' && state.stale !== null && (_jsx("p", { className: "rooms__stale", "data-testid": "rooms-stale", children: "List may be out of date." }))] }), creating && (_jsx(CreateRoomDialog, { client: client, gameTypes: gameTypes, createFields: createFields, onClose: () => setCreating(false), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, nameMaxLength: nameMaxLength, defaultName: defaultName, surfaceClassName: createSurfaceClassName })), _jsx(TopLayer, { fixed: true })] })] }));
144
+ }, children: "Create room" }), actionsExtras] })] }), _jsxs(Reveal, { name: "rooms", shown: shown, skeleton: _jsx(RoomGhosts, { count: shape.rooms }), layerClassName: "rooms__layer", children: [state.kind === 'failed' && (_jsxs("div", { className: "rooms__status rooms__status--bad", role: "alert", "data-testid": "rooms-error", children: [_jsx("p", { children: state.message }), _jsx("button", { type: "button", "data-testid": "rooms-retry", onClick: retry, children: "Retry" })] })), state.kind === 'ready' && normal.length === 0 && testing.length === 0 && (_jsx("p", { className: "rooms__status", "data-testid": "rooms-empty", children: "No rooms yet." })), state.kind === 'ready' && normal.length > 0 && (_jsx("ul", { className: "rooms__list", "data-testid": "room-list", children: orderedNormal.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) })), state.kind === 'ready' && testing.length > 0 && (_jsxs("div", { "data-testid": "rooms-testing", children: [_jsx("h3", { className: "rooms__title ct-panel__title", children: _jsxs("button", { type: "button", className: "rooms__fold", "aria-expanded": !testingFolded, "aria-controls": "room-list-testing", "data-testid": "rooms-testing-fold", onClick: toggleTesting, children: [_jsx("svg", { className: "rooms__fold-chevron", width: "14", height: "14", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M9 5l7 7-7 7" }) }), "Testing"] }) }), !testingFolded && (_jsx("ul", { className: "rooms__list", id: "room-list-testing", "data-testid": "room-list-testing", children: orderedTesting.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) }))] })), state.kind === 'ready' && state.stale !== null && (_jsx("p", { className: "rooms__stale", "data-testid": "rooms-stale", children: "List may be out of date." }))] }), creating && (_jsx(CreateRoomDialog, { client: client, gameTypes: gameTypes, createFields: createFields, onClose: () => setCreating(false), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, nameMaxLength: nameMaxLength, defaultName: defaultName, surfaceClassName: createPanelClassName === undefined ? 'room-front-create' : `room-front-create ${createPanelClassName}` })), _jsx(TopLayer, { fixed: true })] })] }));
149
145
  }
150
146
  /* ── until the list arrives ─────────────────────────────────────────── */
151
147
  function RoomGhosts({ count }) {
@@ -238,7 +234,7 @@ function RoomRow({ room, client, rowExtras, matches, onGone, onOpenRoom, beforeO
238
234
  const names = room.members.map((m) => m.name);
239
235
  const view = room.view;
240
236
  const extras = rowExtras?.(room) ?? {};
241
- return (_jsxs("li", { className: "room-card", "data-testid": "room-row", "data-room-id": room.id, "data-mine": isMine(room) ? '' : undefined, "data-match": matches(room) ? undefined : 'false', "data-family": extras.family, children: [extras.scene !== undefined && (_jsx("span", { className: "room-card__mark", "aria-hidden": "true", children: extras.scene })), _jsxs("div", { className: "room-card__body", children: [_jsxs("div", { className: "room-card__row1", children: [extras.typeIcon !== undefined && (_jsx("span", { className: "room-card__type-icon", "aria-hidden": "true", children: extras.typeIcon })), _jsx("span", { ref: nameRef, className: "room-card__name", "data-testid": "room-name", "data-tip": nameTruncated ? room.name : undefined, tabIndex: nameTruncated ? 0 : undefined, children: room.name }), extras.trophy !== undefined && _jsx("span", { className: "room-card__trophy", children: extras.trophy }), _jsxs("span", { className: "room-card__seats", "data-testid": "room-seats", children: [_jsx(PersonIcon, {}), view.seatsFilled, "/", view.seatsCapacity] })] }), (extras.modeChip !== undefined || extras.seriesChip !== undefined) && (_jsxs("div", { className: "room-card__row2", children: [extras.modeChip, extras.seriesChip] })), _jsxs("div", { className: "room-card__row3", children: [_jsxs("span", { className: "room-card__state", "data-testid": "room-state", "data-state": view.state.key, children: [_jsx("span", { className: "room-card__dot", "aria-hidden": "true" }), view.state.label] }), view.state.detail !== null && _jsx("span", { className: "room-card__state-detail", children: view.state.detail })] }), _jsxs("span", { className: "rooms__members rooms__sr", "data-testid": "room-members", children: [room.members.map((m) => (_jsx(Avatar, { ...faceOf(m), fallback: "none", className: "rooms__face", "data-testid": "room-face", "data-avatar-id": m.avatarId, title: m.name, width: 18, height: 18, loading: "lazy" }, m.id))), names.join(', ')] }), _jsxs("div", { className: "room-card__row4", children: [!asking && (_jsxs("button", { type: "button", className: "rooms__enter room-card__go", "data-testid": "room-enter", "aria-label": `${view.primaryAction} ${room.name}`, disabled: busy, onClick: onEnterClick, children: [room.locked && (_jsx("span", { className: "room-card__lock", "data-testid": "room-locked", "aria-hidden": "true", children: _jsx(LockIcon, {}) })), view.primaryAction] })), !asking && view.extraWatch && (_jsx("button", { type: "button", className: "rooms__enter room-card__go room-card__go--watch", "data-testid": "room-watch", "aria-label": `Watch ${room.name}`, disabled: busy, onClick: onEnterClick, children: "Watch" })), !asking && room.testing === true && client.reset !== undefined && (_jsx("button", { type: "button", className: "rooms__enter room-card__go", "data-testid": "room-reset", "aria-label": `Reset ${room.name}`, disabled: busy, onClick: () => void onResetClick(), children: "Reset" })), extras.legacyMeta !== undefined && _jsx("div", { className: "rooms__meta room-card__legacy", children: extras.legacyMeta })] })] }), asking && (_jsxs("form", { className: "rooms__password", onSubmit: onPassword, children: [_jsxs("label", { htmlFor: `room-password-${room.id}`, children: ["Password for ", room.name] }), _jsx("input", { id: `room-password-${room.id}`, "data-testid": "room-password", type: "password", maxLength: passwordMaxLength, autoComplete: "off", autoFocus: true, value: password, onChange: (e) => {
237
+ return (_jsxs("li", { className: "room-card", "data-testid": "room-row", "data-room-id": room.id, "data-mine": isMine(room) ? '' : undefined, "data-match": matches(room) ? undefined : 'false', "data-family": extras.family, style: extras.vars, children: [extras.scene !== undefined && (_jsx("span", { className: "room-card__mark", "aria-hidden": "true", children: extras.scene })), _jsxs("div", { className: "room-card__body", children: [_jsxs("div", { className: "room-card__row1", children: [extras.typeIcon !== undefined && (_jsx("span", { className: "room-card__type-icon", "aria-hidden": "true", children: extras.typeIcon })), _jsx("span", { ref: nameRef, className: "room-card__name", "data-testid": "room-name", "data-tip": nameTruncated ? room.name : undefined, tabIndex: nameTruncated ? 0 : undefined, children: room.name }), extras.trophy !== undefined && _jsx("span", { className: "room-card__trophy", children: extras.trophy }), _jsxs("span", { className: "room-card__seats", "data-testid": "room-seats", children: [_jsx(PersonIcon, {}), view.seatsCapacity === null ? view.seatsFilled : `${view.seatsFilled}/${view.seatsCapacity}`] })] }), (extras.modeChip !== undefined || extras.seriesChip !== undefined) && (_jsxs("div", { className: "room-card__row2", children: [extras.modeChip, extras.seriesChip] })), _jsxs("div", { className: "room-card__row3", children: [_jsxs("span", { className: "room-card__state", "data-testid": "room-state", "data-state": view.state.key, children: [_jsx("span", { className: "room-card__dot", "aria-hidden": "true" }), view.state.label] }), view.state.detail !== null && _jsx("span", { className: "room-card__state-detail", children: view.state.detail })] }), _jsxs("span", { className: "rooms__members rooms__sr", "data-testid": "room-members", children: [room.members.map((m) => (_jsx(Avatar, { ...faceOf(m), fallback: "none", className: "rooms__face", "data-testid": "room-face", "data-avatar-id": m.avatarId, title: m.name, width: 18, height: 18, loading: "lazy" }, m.id))), names.join(', ')] }), _jsxs("div", { className: "room-card__row4", children: [!asking && (_jsxs("button", { type: "button", className: "rooms__enter room-card__go", "data-testid": "room-enter", "aria-label": `${view.primaryAction} ${room.name}`, disabled: busy, onClick: onEnterClick, children: [room.locked && (_jsx("span", { className: "room-card__lock", "data-testid": "room-locked", "aria-hidden": "true", children: _jsx(LockIcon, {}) })), view.primaryAction] })), !asking && view.extraWatch && (_jsx("button", { type: "button", className: "rooms__enter room-card__go room-card__go--watch", "data-testid": "room-watch", "aria-label": `Watch ${room.name}`, disabled: busy, onClick: onEnterClick, children: "Watch" })), !asking && room.testing === true && client.reset !== undefined && (_jsx("button", { type: "button", className: "rooms__enter room-card__go", "data-testid": "room-reset", "aria-label": `Reset ${room.name}`, disabled: busy, onClick: () => void onResetClick(), children: "Reset" })), extras.legacyMeta !== undefined && _jsx("div", { className: "room-card__legacy", children: extras.legacyMeta })] })] }), asking && (_jsxs("form", { className: "rooms__password", onSubmit: onPassword, children: [_jsxs("label", { htmlFor: `room-password-${room.id}`, children: ["Password for ", room.name] }), _jsx("input", { id: `room-password-${room.id}`, "data-testid": "room-password", type: "password", maxLength: passwordMaxLength, autoComplete: "off", autoFocus: true, value: password, onChange: (e) => {
242
238
  setPassword(e.target.value);
243
239
  setError(null);
244
240
  } }), _jsx("button", { type: "submit", "data-testid": "room-password-submit", "aria-label": `Enter ${room.name}`, disabled: busy, children: "Enter" }), _jsx("button", { type: "button", className: "rooms__cancel", onClick: () => {
@@ -313,5 +309,5 @@ function CreateRoomDialog({ client, gameTypes, createFields, onClose, onOpenRoom
313
309
  }, children: _jsxs("form", { className: surfaceClassName, "data-testid": "room-create", role: "dialog", "aria-modal": "true", "aria-labelledby": "room-create-title", autoComplete: "off", onSubmit: (e) => void submit(e), children: [_jsxs("div", { className: "rooms__create-head", children: [_jsx("h3", { id: "room-create-title", children: "Create a room" }), _jsx("button", { type: "button", className: "rooms__create-close", "aria-label": "Close", "data-testid": "room-create-close", onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) })] }), kindOptions.length > 1 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "rooms__caption", children: "Game type" }), _jsx(RadioCards, { name: "room-create-type", label: "Game type", options: kindOptions, value: kind, onChange: setKind, testId: "room-create-type" })] })), !nameless && (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: "room-create-name", children: "Name" }), _jsx("input", { id: "room-create-name", "data-testid": "room-create-name", value: name, maxLength: nameMaxLength, placeholder: "Friday night", autoComplete: "nickname", autoFocus: true, onChange: (e) => {
314
310
  setTyped(e.target.value);
315
311
  setError(null);
316
- } })] })), slot?.node, _jsx("button", { type: "submit", className: "lobby__go", "data-testid": "room-create-submit", disabled: busy || !ready, children: "Create room" }), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-create-error", children: error }))] }) }) }));
312
+ } })] })), slot?.node, _jsx("button", { type: "submit", className: "room-front__go", "data-testid": "room-create-submit", disabled: busy || !ready, children: "Create room" }), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-create-error", children: error }))] }) }) }));
317
313
  }
@@ -1,9 +1,5 @@
1
- /** How far a sideways drag must travel to turn the page. */
2
- export declare const SWIPE_PX = 40;
3
1
  /** One page on from `index` (`delta` ±1), wrapping at both ends. */
4
2
  export declare function stepPage(index: number, delta: number, count: number): number;
5
- /** A drag of `dx`×`dy` px as a page step: ±1 past the threshold, 0 for a short or mostly vertical one (scrolling a list). */
6
- export declare function swipeStep(dx: number, dy: number): -1 | 0 | 1;
7
3
  /**
8
4
  * The Upcoming card's page as the front page opens: Polls when it has something and Calendar has
9
5
  * nothing (the operator, 2026-11-04), else Calendar.
@@ -1,21 +1,13 @@
1
1
  /*
2
2
  * The front cards' manual gallery (`./Gallery.tsx`): pages the reader flips with the arrows, the
3
- * dots or a swipe, and never on a timer. The pure steps, so they are tested without mounting it.
3
+ * dots, and never on a timer. The pure steps, so they are tested without mounting it.
4
4
  */
5
- /** How far a sideways drag must travel to turn the page. */
6
- export const SWIPE_PX = 40;
7
5
  /** One page on from `index` (`delta` ±1), wrapping at both ends. */
8
6
  export function stepPage(index, delta, count) {
9
7
  if (count <= 1)
10
8
  return 0;
11
9
  return (((index + delta) % count) + count) % count;
12
10
  }
13
- /** A drag of `dx`×`dy` px as a page step: ±1 past the threshold, 0 for a short or mostly vertical one (scrolling a list). */
14
- export function swipeStep(dx, dy) {
15
- if (Math.abs(dx) < SWIPE_PX || Math.abs(dy) > Math.abs(dx))
16
- return 0;
17
- return dx < 0 ? 1 : -1;
18
- }
19
11
  /**
20
12
  * The Upcoming card's page as the front page opens: Polls when it has something and Calendar has
21
13
  * nothing (the operator, 2026-11-04), else Calendar.
@@ -14,9 +14,10 @@ export declare function TrophyIcon({ size }: {
14
14
  export declare function LockIcon({ size }: {
15
15
  size?: number;
16
16
  }): import("react").JSX.Element;
17
- /** A seat count. */
18
- export declare function PersonIcon({ size }: {
17
+ /** A count of people: a room's seats unless `label` says what it counts. */
18
+ export declare function PersonIcon({ size, label }: {
19
19
  size?: number;
20
+ label?: string;
20
21
  }): import("react").JSX.Element;
21
22
  /** Classic: crossed swords — blade, point, guard, grip and pommel each. */
22
23
  export declare function SwordsIcon({ size }: {
@@ -35,9 +35,9 @@ export function TrophyIcon({ size = 16 }) {
35
35
  export function LockIcon({ size = 15 }) {
36
36
  return (_jsxs(Glyph, { label: "Locked", size: size, children: [_jsx("rect", { x: "5", y: "11", width: "14", height: "10", rx: "2" }), _jsx("path", { d: "M8 11V7a4 4 0 0 1 8 0v4" })] }));
37
37
  }
38
- /** A seat count. */
39
- export function PersonIcon({ size = 14 }) {
40
- return (_jsxs(Glyph, { label: "Seats", size: size, children: [_jsx("circle", { cx: "12", cy: "8", r: "3.2" }), _jsx("path", { d: "M5.5 20c0-3.6 2.9-6 6.5-6s6.5 2.4 6.5 6" })] }));
38
+ /** A count of people: a room's seats unless `label` says what it counts. */
39
+ export function PersonIcon({ size = 14, label = 'Seats' }) {
40
+ return (_jsxs(Glyph, { label: label, size: size, children: [_jsx("circle", { cx: "12", cy: "8", r: "3.2" }), _jsx("path", { d: "M5.5 20c0-3.6 2.9-6 6.5-6s6.5 2.4 6.5 6" })] }));
41
41
  }
42
42
  /** Classic: crossed swords — blade, point, guard, grip and pommel each. */
43
43
  export function SwordsIcon({ size = 14 }) {
@@ -0,0 +1,17 @@
1
+ import { type FeedTarget, type PingSource } from '@wolffm/rooms-client';
2
+ import { type RereadDeps } from '../visible.js';
3
+ export type { FeedTarget, PingReason, PingSource } from '@wolffm/rooms-client';
4
+ /**
5
+ * How often a visible screen reads anyway. A lost ping costs at most this much staleness. Long,
6
+ * because a ping is lost only with its socket, and a reconnect already reads again on the ack.
7
+ */
8
+ export declare const FALLBACK_MS = 120000;
9
+ export interface RoomFeed {
10
+ /** Call `refresh` on the schedule in this file's header. Returns the stop. */
11
+ follow(target: FeedTarget, refresh: () => void): () => void;
12
+ }
13
+ export declare function createRoomFeed(pings: PingSource, deps?: RereadDeps & {
14
+ fallbackMs?: number;
15
+ }): RoomFeed;
16
+ /** The page's feed. Nothing connects until a screen follows something. */
17
+ export declare function roomFeed(): RoomFeed;
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Following a room, or the room list, without polling it.
3
+ *
4
+ * The server says when a room changed (`@hadoku/game-server/room/watching`'s `attachRoomFeed`, on the
5
+ * default socket.io namespace) and a screen reads it then. The pings come from the rooms core's feed client (`@wolffm/rooms-client`'s
6
+ * `createFeedPings`): one socket per page, shared by every follower, opened by the first and
7
+ * closed once the commit that let go of the last is over (`e2e/embed.spec.ts` counts them), and a
8
+ * `heard` ping whenever the server confirms the watch — at the start and after every reconnect,
9
+ * since nothing that changed before then could have been said. Its own connection, not the
10
+ * match's or the pod's: those come and go with their screens.
11
+ *
12
+ * A following screen reads:
13
+ *
14
+ * - once when it starts following, if the tab is shown;
15
+ * - on every ping, if the tab is shown;
16
+ * - once when the tab is shown again;
17
+ * - and every `FALLBACK_MS` while shown, in case a ping was lost some other way. That is the
18
+ * resilience read, not the mechanism.
19
+ *
20
+ * A hidden tab reads nothing. The server keeps the room offered meanwhile: the watch is presence.
21
+ */
22
+ import { io } from 'socket.io-client';
23
+ import { ROOM_FEED_CHANNEL, parseRoomChanged } from '@wolffm/rooms-protocol';
24
+ import { createFeedPings } from '@wolffm/rooms-client';
25
+ import { socketOptions } from "../room/socket-options.js";
26
+ import { documentVisibility, rereadWhileVisible } from "../visible.js";
27
+ /**
28
+ * How often a visible screen reads anyway. A lost ping costs at most this much staleness. Long,
29
+ * because a ping is lost only with its socket, and a reconnect already reads again on the ack.
30
+ */
31
+ export const FALLBACK_MS = 120_000;
32
+ export function createRoomFeed(pings, deps = {}) {
33
+ const page = deps.page ?? documentVisibility();
34
+ return {
35
+ follow(target, refresh) {
36
+ const stopReread = rereadWhileVisible(refresh, deps.fallbackMs ?? FALLBACK_MS, { ...deps, page });
37
+ const stopPings = pings.subscribe(target, () => {
38
+ if (!page.hidden())
39
+ refresh();
40
+ });
41
+ return () => {
42
+ stopPings();
43
+ stopReread();
44
+ };
45
+ },
46
+ };
47
+ }
48
+ let sharedPings;
49
+ let shared;
50
+ /** The page's one feed socket's pings. */
51
+ function roomPings() {
52
+ sharedPings ??= createFeedPings({
53
+ wire: { channel: ROOM_FEED_CHANNEL, parseChanged: parseRoomChanged },
54
+ connect: () => io(socketOptions()),
55
+ });
56
+ return sharedPings;
57
+ }
58
+ /** The page's feed. Nothing connects until a screen follows something. */
59
+ export function roomFeed() {
60
+ shared ??= createRoomFeed(roomPings());
61
+ return shared;
62
+ }
@@ -0,0 +1,69 @@
1
+ import { type Fetch } from '../http.js';
2
+ import type { RoomFrontClient, RoomFrontJoinOutcome, RoomFrontRoom } from '../front/RoomFront.js';
3
+ /** A room write's answer: the room as the server now has it, or why not. */
4
+ export type RoomOutcome<R> = {
5
+ ok: true;
6
+ room: R;
7
+ } | {
8
+ ok: false;
9
+ message: string;
10
+ };
11
+ /** A write that ends the room for everyone (a close, a testing room's reset): answered with no room. */
12
+ export type RoomEndOutcome = {
13
+ ok: true;
14
+ } | {
15
+ ok: false;
16
+ message: string;
17
+ };
18
+ export type RoomJoinOutcome<R> = RoomFrontJoinOutcome<R>;
19
+ export interface RoomCoreClientOptions<R> {
20
+ /** The game's own room body, or `null` for a body that is not one (it is dropped from a list, refused elsewhere). */
21
+ parse(body: unknown): R | null;
22
+ fetch?: Fetch;
23
+ /** The `/api/` base, `apiBase()` (this bundle's own) unless given. */
24
+ base?: string;
25
+ }
26
+ export interface RoomCoreClient<R> {
27
+ /** `GET /api/rooms`: every room the caller may see, and the whole body for a game's own extras (a featured pick, say). Throws a sentence. */
28
+ list(): Promise<{
29
+ rooms: R[];
30
+ body: Record<string, unknown>;
31
+ }>;
32
+ /** `GET /api/rooms/:id`: `null` on the usual 404, a thrown sentence for anything else. */
33
+ get(roomId: string): Promise<R | null>;
34
+ create(body: Record<string, unknown>): Promise<RoomOutcome<R>>;
35
+ join(roomId: string, password?: string): Promise<RoomJoinOutcome<R>>;
36
+ leave(roomId: string): Promise<RoomOutcome<R>>;
37
+ ready(roomId: string, ready: boolean): Promise<RoomOutcome<R>>;
38
+ close(roomId: string): Promise<RoomEndOutcome>;
39
+ reset(roomId: string): Promise<RoomEndOutcome>;
40
+ /** The viewer takes `seat`, or the first open one (the room grows by one when none is). */
41
+ sit(roomId: string, seat?: number): Promise<RoomOutcome<R>>;
42
+ /** The viewer gives their seat back. */
43
+ stand(roomId: string): Promise<RoomOutcome<R>>;
44
+ /** The leader closes an empty seat, or opens a closed one. */
45
+ setSeatClosed(roomId: string, seat: number, closed: boolean): Promise<RoomOutcome<R>>;
46
+ /** The leader puts the bot in `seat`, evicting a human holder first. */
47
+ bot(roomId: string, seat: number): Promise<RoomOutcome<R>>;
48
+ /** The leader takes the bot back out of `seat`. */
49
+ botOff(roomId: string, seat: number): Promise<RoomOutcome<R>>;
50
+ /** The leader moves a seated member to the spectators. */
51
+ removeFromSeat(roomId: string, memberId: string): Promise<RoomOutcome<R>>;
52
+ /** The leader closes seats from the top down until `count` are open. */
53
+ lowerSeatCapacity(roomId: string, count: number): Promise<RoomOutcome<R>>;
54
+ /** The leader hands the room to another member, seated or watching. */
55
+ makeLeader(roomId: string, memberId: string): Promise<RoomOutcome<R>>;
56
+ /** Any other write that answers with the room, under `/api/rooms`: `path` starts with `/` or is `''`. */
57
+ write(path: string, payload: unknown, whatFailed: string, method?: 'POST' | 'PATCH' | 'PUT'): Promise<RoomOutcome<R>>;
58
+ /** Any other read of one room under `/api/rooms`, as `get` reads one. */
59
+ read(path: string): Promise<R | null>;
60
+ }
61
+ export declare function roomCoreClient<R>({ parse, fetch: fetchImpl, base }: RoomCoreClientOptions<R>): RoomCoreClient<R>;
62
+ /**
63
+ * `RoomFront`'s client over a core client: the game's own projection of its room (`toFront`: the
64
+ * seats, the state and the primary action a row draws) applied to every list, create and join.
65
+ * `reset` offers an admin's Reset on the game's seeded testing rooms.
66
+ */
67
+ export declare function roomFrontClient<R, V extends RoomFrontRoom>(core: RoomCoreClient<R>, toFront: (room: R) => V, opts?: {
68
+ reset?: boolean;
69
+ }): RoomFrontClient<V>;
@@ -0,0 +1,148 @@
1
+ /*
2
+ * The browser's client for game-server's generic room routes (`@hadoku/game-server/http/room-core`):
3
+ * the room list, a room, create, join, leave, ready, close, reset, and the seat ops (sit, stand, the
4
+ * leader's close/open, bot in and out, remove, fewer seats, a new leader). One copy, so every game
5
+ * reads the same refusals the same way; a game supplies only how its room body parses
6
+ * (`parse`), and adds its own routes with `write`/`read`.
7
+ *
8
+ * ## One answer for "wrong password" and "no such room"
9
+ *
10
+ * room-core answers both with the same refusal, on purpose (a 404-vs-403 would tell an enumerator
11
+ * which rooms exist). A join refused with either status is `refused`, and nothing downstream can
12
+ * tell which it was.
13
+ *
14
+ * ## The words
15
+ *
16
+ * A room write that fails reads `<what failed>: <the server's own sentence>.`; a seat op's refusal
17
+ * is the server's own sentence as is (the seat strip shows it under the seats). A body that is not a
18
+ * room is a refusal too, never a crash: a proxy's error page parses as nothing.
19
+ */
20
+ import { apiBase, bodyOf, getJson, isRecord, pageFetch, sendJson, serverMessage } from "../http.js";
21
+ const UNREACHABLE = 'Could not reach the server.';
22
+ const NOT_A_ROOM = 'The server answered with something that is not a room.';
23
+ const id = (roomId) => `/${encodeURIComponent(roomId)}`;
24
+ export function roomCoreClient({ parse, fetch: fetchImpl = pageFetch, base = apiBase() }) {
25
+ const url = (path) => `${base}rooms${path}`;
26
+ /** A write answered with the room; `whatFailed` null for a seat op, whose refusal is the server's own sentence. */
27
+ const send = async (path, payload, whatFailed, method = 'POST') => {
28
+ let res;
29
+ try {
30
+ res = await sendJson(url(path), method, payload, fetchImpl);
31
+ }
32
+ catch {
33
+ return { ok: false, message: UNREACHABLE };
34
+ }
35
+ const body = await bodyOf(res);
36
+ if (!res.ok)
37
+ return { ok: false, message: whatFailed === null ? serverMessage(body, res.status) : `${whatFailed}: ${serverMessage(body, res.status)}.` };
38
+ const room = parse(body);
39
+ return room === null ? { ok: false, message: NOT_A_ROOM } : { ok: true, room };
40
+ };
41
+ const end = async (roomId, verb, whatFailed) => {
42
+ let res;
43
+ try {
44
+ res = await sendJson(url(`${id(roomId)}/${verb}`), 'POST', {}, fetchImpl);
45
+ }
46
+ catch {
47
+ return { ok: false, message: UNREACHABLE };
48
+ }
49
+ if (res.ok)
50
+ return { ok: true };
51
+ return { ok: false, message: `${whatFailed}: ${serverMessage(await bodyOf(res), res.status)}.` };
52
+ };
53
+ const read = async (path) => {
54
+ let res;
55
+ try {
56
+ res = await getJson(url(path), fetchImpl);
57
+ }
58
+ catch {
59
+ throw new Error(UNREACHABLE);
60
+ }
61
+ if (res.status === 404)
62
+ return null;
63
+ const body = await bodyOf(res);
64
+ if (!res.ok)
65
+ throw new Error(`Could not load the room: ${serverMessage(body, res.status)}.`);
66
+ const room = parse(body);
67
+ if (room === null)
68
+ throw new Error('The server sent something that is not a room.');
69
+ return room;
70
+ };
71
+ const seat = (roomId, op, payload) => send(`${id(roomId)}/${op}`, payload, null);
72
+ return {
73
+ async list() {
74
+ let res;
75
+ try {
76
+ res = await getJson(url(''), fetchImpl);
77
+ }
78
+ catch {
79
+ throw new Error(UNREACHABLE);
80
+ }
81
+ const body = await bodyOf(res);
82
+ if (!res.ok)
83
+ throw new Error(`Could not load the rooms: ${serverMessage(body, res.status)}.`);
84
+ if (!isRecord(body) || !Array.isArray(body.rooms))
85
+ throw new Error('Could not load the rooms: the server sent something that is not a room list.');
86
+ const rooms = body.rooms.map(parse).filter((r) => r !== null);
87
+ return { rooms, body };
88
+ },
89
+ get: (roomId) => read(id(roomId)),
90
+ create: (body) => send('', body, 'Could not create the room'),
91
+ async join(roomId, password) {
92
+ let res;
93
+ try {
94
+ res = await sendJson(url(`${id(roomId)}/join`), 'POST', password === undefined || password === '' ? {} : { password }, fetchImpl);
95
+ }
96
+ catch {
97
+ return { ok: false, reason: 'error', message: UNREACHABLE };
98
+ }
99
+ if (res.status === 403 || res.status === 404)
100
+ return { ok: false, reason: 'refused' };
101
+ if (res.status === 429)
102
+ return { ok: false, reason: 'rate-limited' };
103
+ const body = await bodyOf(res);
104
+ if (!res.ok)
105
+ return { ok: false, reason: 'error', message: `Could not join: ${serverMessage(body, res.status)}.` };
106
+ const room = parse(body);
107
+ if (room === null)
108
+ return { ok: false, reason: 'error', message: 'The server answered the join with something that is not a room.' };
109
+ return { ok: true, room };
110
+ },
111
+ leave: (roomId) => send(`${id(roomId)}/leave`, {}, 'Could not leave the room'),
112
+ ready: (roomId, ready) => send(`${id(roomId)}/ready`, { ready }, 'Could not change your readiness'),
113
+ close: (roomId) => end(roomId, 'close', 'Could not close the room'),
114
+ reset: (roomId) => end(roomId, 'reset', 'Could not reset the room'),
115
+ sit: (roomId, at) => seat(roomId, 'seats/sit', at === undefined ? {} : { seat: at }),
116
+ stand: (roomId) => seat(roomId, 'seats/stand', {}),
117
+ setSeatClosed: (roomId, at, closed) => seat(roomId, 'seats/close', { seat: at, closed }),
118
+ bot: (roomId, at) => seat(roomId, 'seats/bot', { seat: at }),
119
+ botOff: (roomId, at) => seat(roomId, 'seats/bot-off', { seat: at }),
120
+ removeFromSeat: (roomId, memberId) => seat(roomId, 'seats/remove', { memberId }),
121
+ lowerSeatCapacity: (roomId, count) => seat(roomId, 'seats/capacity', { count }),
122
+ makeLeader: (roomId, memberId) => seat(roomId, 'leader', { memberId }),
123
+ write: (path, payload, whatFailed, method = 'POST') => send(path, payload, whatFailed, method),
124
+ read,
125
+ };
126
+ }
127
+ /**
128
+ * `RoomFront`'s client over a core client: the game's own projection of its room (`toFront`: the
129
+ * seats, the state and the primary action a row draws) applied to every list, create and join.
130
+ * `reset` offers an admin's Reset on the game's seeded testing rooms.
131
+ */
132
+ export function roomFrontClient(core, toFront, opts = {}) {
133
+ return {
134
+ async list() {
135
+ const { rooms } = await core.list();
136
+ return { rooms: rooms.map(toFront) };
137
+ },
138
+ async create(body) {
139
+ const outcome = await core.create(body);
140
+ return outcome.ok ? { ok: true, room: toFront(outcome.room) } : outcome;
141
+ },
142
+ async join(roomId, password) {
143
+ const outcome = await core.join(roomId, password);
144
+ return outcome.ok ? { ok: true, room: toFront(outcome.room) } : outcome;
145
+ },
146
+ ...(opts.reset === true ? { reset: (roomId) => core.reset(roomId) } : {}),
147
+ };
148
+ }