@hadoku/game-ui 0.1.91 → 0.1.93

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,19 +1,32 @@
1
1
  import { type ComponentType } from 'react';
2
2
  import type { AppSettingsTab } from '@wolffm/task-ui-components';
3
3
  import type { PrefsClient } from '@wolffm/prefs-client';
4
+ import { type MotionChoices } from '@wolffm/ui-shell/motion';
4
5
  import './settings.css';
6
+ /**
7
+ * What the Display tab saves in the game's own preferences: the UI scale, the motion switches
8
+ * (`@hadoku/ui-shell/motion`, each unset until the player chooses, following the system until then) and
9
+ * whether the front page plays its featured match (unset, it follows card motion's default).
10
+ */
11
+ export interface DisplayPrefs extends MotionChoices {
12
+ /** `usePrefs`'s own bound; nothing is read off it. */
13
+ [key: string]: unknown;
14
+ uiScale?: number;
15
+ frontMatch?: boolean;
16
+ }
5
17
  /** The game's own sections, where its UI scale is saved (and the scale before anything is), and what a new scale makes stale. */
6
18
  export interface SettingsParts {
7
19
  Game: ComponentType;
8
20
  Sound: ComponentType;
9
- prefs: () => PrefsClient<{
10
- uiScale?: number;
11
- }>;
21
+ prefs: () => PrefsClient<DisplayPrefs>;
12
22
  defaultScale: number;
13
23
  onScaled: () => void;
14
24
  }
15
25
  export declare const registerSettings: (value: SettingsParts) => void;
16
- /** The settings as tabs, in the order a player looks for them: how the game plays (and the UI scale, under it), then sound. */
26
+ /**
27
+ * The settings as tabs, in the order a player looks for them (operator, 2026-11-21): how the game plays,
28
+ * how the page looks and moves, then sound.
29
+ */
17
30
  export declare const CARDTABLE_SETTINGS_TABS: AppSettingsTab[];
18
31
  /** Every tab's sections one under another, for a popout with no tabs of its own. */
19
32
  export declare function CardtableSettings(): import("react").JSX.Element;
@@ -27,6 +40,15 @@ export declare const HostDrawsSettingsProvider: import("react").Provider<boolean
27
40
  * where the header held the only route to one.
28
41
  */
29
42
  export declare function useHostDrawsSettings(): boolean;
43
+ /** Whether the front page plays its featured match: the player's choice, else on unless the system asks for less motion. */
44
+ export declare function frontMatchShown(prefs: DisplayPrefs | null): boolean;
45
+ /**
46
+ * The motion switches, applied: for every reader of `prefersReducedMotion()` / `screenShakeAllowed()`, and
47
+ * as attributes on `root`, where the sheets look for them (`@hadoku/ui-shell/motion`'s `css.ts`). Called once
48
+ * per app, as `useUiScale` is. Until prefs answer, the switches this browser applied last; a system that
49
+ * changes its mind mid-visit is followed by every switch the player has not set.
50
+ */
51
+ export declare function useMotion(root: () => HTMLElement | null): void;
30
52
  /**
31
53
  * The saved UI scale, written where the stylesheet's tokens resolve (shell's `ui-scale.ts`). Called
32
54
  * once per app — the standalone page's and the embed's — with the element that is. Until prefs
@@ -21,23 +21,30 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
21
21
  * Every value is a preference in the fleet's service (`../play/live/prefs.ts`,
22
22
  * `../sound/mute.ts`), so whichever host draws a control, the board reads the change from the
23
23
  * service and applies it. Only "This match" is not a preference: the board publishes it
24
- * (`./liveMatch.ts`). The Game and Sound tabs are the game's own, handed in by `../composition.tsx`.
24
+ * (`./liveMatch.ts`). The Gameplay and Sound tabs' sections are the game's own, handed in by `../composition.tsx`;
25
+ * Display (the UI scale and the motion switches) is drawn here, for every game.
25
26
  */
26
27
  import { createContext, createElement, Fragment, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
27
28
  import { Icon } from '@wolffm/themes';
28
29
  import { usePrefs } from '@wolffm/prefs-client/react';
29
30
  import { applyUiScale, clampUiScale, rememberedUiScale, rememberUiScale, UI_SCALE, uiLength } from '@wolffm/ui-shell/settings';
31
+ import { appId } from '@wolffm/ui-shell/app-id';
32
+ import { applyMotion, clearMotion, motionState, rememberedMotion, rememberMotion, setMotionChoices, systemReducesMotion } from '@wolffm/ui-shell/motion';
30
33
  import { Popover, usePopover } from "../components/Popover.js";
31
34
  import { registered } from "../registered.js";
32
35
  import './settings.css';
33
36
  const parts = registered('settings');
34
37
  export const registerSettings = parts.set;
35
- /** The settings as tabs, in the order a player looks for them: how the game plays (and the UI scale, under it), then sound. */
38
+ /**
39
+ * The settings as tabs, in the order a player looks for them (operator, 2026-11-21): how the game plays,
40
+ * how the page looks and moves, then sound.
41
+ */
36
42
  export const CARDTABLE_SETTINGS_TABS = [
43
+ { id: 'game', label: 'Gameplay', render: () => _jsx("div", { className: "ct-settings__tab", children: createElement(parts.get().Game) }) },
37
44
  {
38
- id: 'game',
39
- label: 'Game',
40
- render: () => (_jsxs("div", { className: "ct-settings__tab", children: [createElement(parts.get().Game), _jsx(DisplaySettings, {})] })),
45
+ id: 'display',
46
+ label: 'Display',
47
+ render: () => (_jsxs("div", { className: "ct-settings__tab", children: [_jsx(DisplaySettings, {}), _jsx(MotionSettings, {})] })),
41
48
  },
42
49
  { id: 'sound', label: 'Sound', render: () => _jsx("div", { className: "ct-settings__tab", children: createElement(parts.get().Sound) }) },
43
50
  ];
@@ -96,6 +103,59 @@ function DisplaySettings() {
96
103
  setHeld(clampUiScale(Number(event.currentTarget.value) / 100));
97
104
  } })] })] }));
98
105
  }
106
+ /** Whether the front page plays its featured match: the player's choice, else on unless the system asks for less motion. */
107
+ export function frontMatchShown(prefs) {
108
+ return prefs?.frontMatch ?? !systemReducesMotion();
109
+ }
110
+ function MotionToggle({ testId, checked, label, onChange }) {
111
+ return (_jsxs("label", { className: "ct-settings__option", children: [_jsx("input", { type: "checkbox", "data-testid": testId, checked: checked, onChange: (event) => onChange(event.currentTarget.checked) }), label] }));
112
+ }
113
+ /**
114
+ * Each motion switch on its own (operator, 2026-11-21: "make sure that each of them can be individually
115
+ * toggled"), each drawn as the page applies it now: a switch nobody set shows the system's answer.
116
+ */
117
+ function MotionSettings() {
118
+ const { prefs: client } = parts.get();
119
+ const { prefs, save } = usePrefs(client());
120
+ const state = motionState(prefs ?? {});
121
+ return (_jsxs("fieldset", { className: "ct-settings__section", "data-testid": "settings-motion", children: [_jsx("legend", { children: "Motion" }), _jsx(MotionToggle, { testId: "settings-card-motion", checked: state.cardMotion, label: "Card animations", onChange: (on) => void save({ cardMotion: on }) }), _jsx(MotionToggle, { testId: "settings-screen-shake", checked: state.screenShake, label: "Screen shake", onChange: (on) => void save({ screenShake: on }) }), _jsx(MotionToggle, { testId: "settings-ambient-motion", checked: state.ambientMotion, label: "Looping animations", onChange: (on) => void save({ ambientMotion: on }) }), _jsx(MotionToggle, { testId: "settings-front-match", checked: frontMatchShown(prefs), label: "Front page match", onChange: (on) => void save({ frontMatch: on }) })] }));
122
+ }
123
+ /** Per game: the motion switches this browser applied last. */
124
+ const motionKey = () => `${appId()}:motion`;
125
+ /**
126
+ * The motion switches, applied: for every reader of `prefersReducedMotion()` / `screenShakeAllowed()`, and
127
+ * as attributes on `root`, where the sheets look for them (`@hadoku/ui-shell/motion`'s `css.ts`). Called once
128
+ * per app, as `useUiScale` is. Until prefs answer, the switches this browser applied last; a system that
129
+ * changes its mind mid-visit is followed by every switch the player has not set.
130
+ */
131
+ export function useMotion(root) {
132
+ const { prefs: client } = parts.get();
133
+ const { prefs } = usePrefs(client());
134
+ const [remembered] = useState(() => rememberedMotion(motionKey()));
135
+ const [systemTick, setSystemTick] = useState(0);
136
+ const choices = prefs === null ? (remembered ?? {}) : { cardMotion: prefs.cardMotion, screenShake: prefs.screenShake, ambientMotion: prefs.ambientMotion };
137
+ const { cardMotion, screenShake, ambientMotion } = choices;
138
+ useLayoutEffect(() => {
139
+ const el = root();
140
+ setMotionChoices({ cardMotion, screenShake, ambientMotion });
141
+ if (el === null)
142
+ return undefined;
143
+ applyMotion(el);
144
+ return () => clearMotion(el);
145
+ }, [root, cardMotion, screenShake, ambientMotion, systemTick]);
146
+ useEffect(() => {
147
+ if (typeof matchMedia !== 'function')
148
+ return undefined;
149
+ const query = matchMedia('(prefers-reduced-motion: reduce)');
150
+ const changed = () => setSystemTick((t) => t + 1);
151
+ query.addEventListener?.('change', changed);
152
+ return () => query.removeEventListener?.('change', changed);
153
+ }, []);
154
+ useEffect(() => {
155
+ if (prefs !== null)
156
+ rememberMotion(motionKey(), { cardMotion, screenShake, ambientMotion });
157
+ }, [prefs, cardMotion, screenShake, ambientMotion]);
158
+ }
99
159
  /**
100
160
  * The saved UI scale, written where the stylesheet's tokens resolve (shell's `ui-scale.ts`). Called
101
161
  * once per app — the standalone page's and the embed's — with the element that is. Until prefs
@@ -91,6 +91,17 @@
91
91
  gap: 4px;
92
92
  }
93
93
 
94
+ /* One line of choices after its name: Game speed's three. */
95
+ .ct-settings__choices--row {
96
+ flex-flow: row wrap;
97
+ align-items: center;
98
+ column-gap: 12px;
99
+ }
100
+
101
+ .ct-settings__choices-label {
102
+ flex-basis: 100%;
103
+ }
104
+
94
105
  .ct-settings__level {
95
106
  display: grid;
96
107
  grid-template-columns: 4rem 1fr;
package/dist/usage.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { targetName, type UsageDeps as ShellUsageDeps } from '@wolffm/ui-shell/usage';
1
+ import { targetName, type UsageAddress, type UsageDeps as ShellUsageDeps } from '@wolffm/ui-shell/usage';
2
2
  export { targetName };
3
- /** The screen a hash shows, by its route's kind; a room's table is its own screen. */
4
- export declare function screenOf(hash: string): string;
3
+ /**
4
+ * The screen an address shows, by its route's kind; a room's table is its own screen, and a table's
5
+ * full-screen step (`room/table/<step>`) its own again.
6
+ */
7
+ export declare function screenOf(address: UsageAddress, base?: string): string;
5
8
  export declare function startUsage(deps?: Partial<ShellUsageDeps>): () => void;
package/dist/usage.js CHANGED
@@ -1,17 +1,22 @@
1
1
  /**
2
2
  * Cardtable's own wiring for the shell's generic usage counter (`@hadoku/ui-shell/usage`): the URL
3
- * to post to and how a route hash names a screen, a room's table counted apart from its room.
3
+ * to post to and how an address names a screen, a room's table counted apart from its room.
4
4
  */
5
5
  import { USAGE_BATCH_MAX, USAGE_PATH } from '@wolffm/platform-wire/telemetry';
6
6
  import { startUsage as startUsageShell, targetName } from '@wolffm/ui-shell/usage';
7
- import { apiUrl } from "./http.js";
8
- import { parseRoute } from "./screens/route.js";
7
+ import { apiUrl, appBase } from "./http.js";
8
+ import { locationRoute } from "./screens/route.js";
9
9
  export { targetName };
10
- /** The screen a hash shows, by its route's kind; a room's table is its own screen. */
11
- export function screenOf(hash) {
12
- const route = parseRoute(hash);
13
- return route.kind === 'room' && route.tableId !== undefined ? 'room/table' : route.kind;
10
+ /**
11
+ * The screen an address shows, by its route's kind; a room's table is its own screen, and a table's
12
+ * full-screen step (`room/table/<step>`) its own again.
13
+ */
14
+ export function screenOf(address, base = appBase()) {
15
+ const route = locationRoute(address, base);
16
+ if (route.kind !== 'room' || route.tableId === undefined)
17
+ return route.kind;
18
+ return route.step === undefined ? 'room/table' : `room/table/${route.step}`;
14
19
  }
15
20
  export function startUsage(deps = {}) {
16
- return startUsageShell({ url: apiUrl(USAGE_PATH), screenOf, batchMax: USAGE_BATCH_MAX, ...deps });
21
+ return startUsageShell({ url: apiUrl(USAGE_PATH), screenOf: (address) => screenOf(address), batchMax: USAGE_BATCH_MAX, ...deps });
17
22
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.91",
4
- "gitHead": "f171a819a6bd741bd045c31295b8379194cb3135",
3
+ "version": "0.1.93",
4
+ "gitHead": "155c8c9335e64b29e1c0f0c9c18a8c79509093fb",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -49,8 +49,8 @@
49
49
  "react-dom": "^19.2.8"
50
50
  },
51
51
  "dependencies": {
52
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.95",
53
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.95",
52
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.97",
53
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.97",
54
54
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.31",
55
55
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.128",
56
56
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.128",