@hadoku/ui-shell 0.0.0-stage → 0.1.6
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/LICENSE +21 -0
- package/dist/app-id/index.d.ts +4 -0
- package/dist/app-id/index.js +14 -0
- package/dist/chrome/AppChrome.d.ts +9 -0
- package/dist/chrome/AppChrome.js +201 -0
- package/dist/chrome/chrome.css +336 -0
- package/dist/chrome/index.d.ts +3 -0
- package/dist/chrome/index.js +3 -0
- package/dist/chrome/matchMedia.d.ts +2 -0
- package/dist/chrome/matchMedia.js +51 -0
- package/dist/chrome/shell.d.ts +17 -0
- package/dist/chrome/shell.js +47 -0
- package/dist/chrome/trim.css +334 -0
- package/dist/components/Reveal.d.ts +20 -0
- package/dist/components/Reveal.js +38 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/reveal.css +110 -0
- package/dist/embed/index.d.ts +1 -0
- package/dist/embed/index.js +1 -0
- package/dist/embed/styles.d.ts +4 -0
- package/dist/embed/styles.js +49 -0
- package/dist/motion/index.d.ts +6 -0
- package/dist/motion/index.js +8 -0
- package/dist/settings/index.d.ts +1 -0
- package/dist/settings/index.js +1 -0
- package/dist/settings/ui-scale.d.ts +45 -0
- package/dist/settings/ui-scale.js +142 -0
- package/dist/sound/GainSlider.d.ts +6 -0
- package/dist/sound/GainSlider.js +15 -0
- package/dist/sound/index.d.ts +65 -0
- package/dist/sound/index.js +204 -0
- package/dist/sound/mix.d.ts +69 -0
- package/dist/sound/mix.js +117 -0
- package/dist/sound/mixer.d.ts +37 -0
- package/dist/sound/mixer.js +301 -0
- package/dist/sound/mute.d.ts +62 -0
- package/dist/sound/mute.js +250 -0
- package/dist/sound/queue.d.ts +32 -0
- package/dist/sound/queue.js +80 -0
- package/dist/theme/index.d.ts +18 -0
- package/dist/theme/index.js +41 -0
- package/dist/trim/index.d.ts +2 -0
- package/dist/trim/index.js +2 -0
- package/dist/trim/siteTrim.d.ts +23 -0
- package/dist/trim/siteTrim.js +91 -0
- package/dist/trim/trim.d.ts +72 -0
- package/dist/trim/trim.js +63 -0
- package/dist/usage/index.d.ts +32 -0
- package/dist/usage/index.js +84 -0
- package/package.json +69 -4
- package/README.md +0 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Trim: game-UI decoration on the app's panels and its page (the operator, 2026-10-21: "the UI
|
|
3
|
+
* looks very plain … just some generated lines/shapes to make the panels look nicer", then "it
|
|
4
|
+
* would be nice to have a composer view inside the app so i can modify it there").
|
|
5
|
+
*
|
|
6
|
+
* One choice per family, the same for every player: the site's trim (`./siteTrim.ts`), set from
|
|
7
|
+
* `#/ui` by an admin and written as `data-trim-*` attributes where the stylesheet can see them
|
|
8
|
+
* (`../chrome/trim.css`). Every panel that takes trim carries `ct-panel` (and its heading
|
|
9
|
+
* `ct-panel__title`); the page's ground is the chrome root. A site nobody has set draws
|
|
10
|
+
* `DEFAULT_TRIM`; None everywhere is `{}`, which writes no attribute and applies no rule.
|
|
11
|
+
*
|
|
12
|
+
* All of it is CSS drawn from the theme tokens: no images, no requests, nothing animated.
|
|
13
|
+
*/
|
|
14
|
+
export const TRIM_FAMILIES = {
|
|
15
|
+
frame: {
|
|
16
|
+
label: 'Frame',
|
|
17
|
+
options: { glint: 'Edge glint', chamfer: 'Chamfered corners', hud: 'HUD cut', step: 'Stepped corners', scoop: 'Scooped corners' },
|
|
18
|
+
},
|
|
19
|
+
corner: {
|
|
20
|
+
label: 'Corners',
|
|
21
|
+
options: { brackets: 'Brackets', triangles: 'Triangles', rivets: 'Rivets', gems: 'Gems' },
|
|
22
|
+
},
|
|
23
|
+
title: {
|
|
24
|
+
label: 'Titles',
|
|
25
|
+
options: { rail: 'Rail', centred: 'Centred', ribbon: 'Ribbon' },
|
|
26
|
+
},
|
|
27
|
+
edge: {
|
|
28
|
+
label: 'Edge',
|
|
29
|
+
options: { keystone: 'Keystone gem' },
|
|
30
|
+
},
|
|
31
|
+
texture: {
|
|
32
|
+
label: 'Panel texture',
|
|
33
|
+
options: { felt: 'Felt', linen: 'Linen', lattice: 'Lattice' },
|
|
34
|
+
},
|
|
35
|
+
ground: {
|
|
36
|
+
label: 'Background',
|
|
37
|
+
options: { glow: 'Overhead glow', felt: 'Table felt', dots: 'Dot grid', grid: 'HUD grid', triangles: 'Triangle lattice' },
|
|
38
|
+
},
|
|
39
|
+
groundCorner: {
|
|
40
|
+
label: 'Background corners',
|
|
41
|
+
options: { wedge: 'Wedge glow', gems: 'Gem cluster' },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/** What a site nobody has set draws (the operator's pick, 2026-10-21). */
|
|
45
|
+
export const DEFAULT_TRIM = { frame: 'scoop', ground: 'triangles', groundCorner: 'gems' };
|
|
46
|
+
export const TRIM_FAMILY_IDS = Object.keys(TRIM_FAMILIES);
|
|
47
|
+
export function isTrimOption(family, value) {
|
|
48
|
+
return Object.hasOwn(TRIM_FAMILIES[family].options, value);
|
|
49
|
+
}
|
|
50
|
+
/** `groundCorner` → `data-trim-ground-corner`. */
|
|
51
|
+
export function trimAttribute(family) {
|
|
52
|
+
return `data-trim-${family.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
|
|
53
|
+
}
|
|
54
|
+
/** Writes one attribute per chosen family and removes the rest. */
|
|
55
|
+
export function applyTrim(el, trim) {
|
|
56
|
+
for (const family of TRIM_FAMILY_IDS) {
|
|
57
|
+
const value = trim[family];
|
|
58
|
+
if (value === undefined)
|
|
59
|
+
el.removeAttribute(trimAttribute(family));
|
|
60
|
+
else
|
|
61
|
+
el.setAttribute(trimAttribute(family), value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a game's app is used: each screen shown and each named control pressed, batched to a URL
|
|
3
|
+
* the caller gives (never built here) a POST at a time. ONE click listener on the document, not a
|
|
4
|
+
* call in every component: a press is named by the nearest `data-testid` above it, lowercased with
|
|
5
|
+
* its ids stripped (`seat-3` → `seat`), so a new control is counted without anyone remembering to;
|
|
6
|
+
* a press on nothing named is not counted. A batch goes when it is full, on a timer, and when the
|
|
7
|
+
* page hides (`sendBeacon`, which survives the tab closing). A failed send is dropped.
|
|
8
|
+
*/
|
|
9
|
+
export interface UsageEntry {
|
|
10
|
+
kind: 'view' | 'click';
|
|
11
|
+
screen: string;
|
|
12
|
+
target?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UsageBatch {
|
|
15
|
+
entries: UsageEntry[];
|
|
16
|
+
}
|
|
17
|
+
/** A `data-testid` as a usage name, or null when what is left is not a name. */
|
|
18
|
+
export declare function targetName(testid: string): string | null;
|
|
19
|
+
export interface UsageDeps {
|
|
20
|
+
/** Where a batch is posted; the caller's own `/api/...` path. */
|
|
21
|
+
url: string;
|
|
22
|
+
/** The screen a route hash names; the caller's own route parsing. */
|
|
23
|
+
screenOf: (hash: string) => string;
|
|
24
|
+
/** Entries per batch before an early flush; the caller's own schema limit. */
|
|
25
|
+
batchMax: number;
|
|
26
|
+
flushMs?: number;
|
|
27
|
+
doc?: Document;
|
|
28
|
+
win?: Window;
|
|
29
|
+
send?: (url: string, batch: UsageBatch) => void;
|
|
30
|
+
}
|
|
31
|
+
/** Start counting. Returns the stop, which flushes what is left. */
|
|
32
|
+
export declare function startUsage(deps: UsageDeps): () => void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a game's app is used: each screen shown and each named control pressed, batched to a URL
|
|
3
|
+
* the caller gives (never built here) a POST at a time. ONE click listener on the document, not a
|
|
4
|
+
* call in every component: a press is named by the nearest `data-testid` above it, lowercased with
|
|
5
|
+
* its ids stripped (`seat-3` → `seat`), so a new control is counted without anyone remembering to;
|
|
6
|
+
* a press on nothing named is not counted. A batch goes when it is full, on a timer, and when the
|
|
7
|
+
* page hides (`sendBeacon`, which survives the tab closing). A failed send is dropped.
|
|
8
|
+
*/
|
|
9
|
+
const NAME = /^[a-z0-9][a-z0-9_.:/-]*$/;
|
|
10
|
+
/** A `data-testid` as a usage name, or null when what is left is not a name. */
|
|
11
|
+
export function targetName(testid) {
|
|
12
|
+
const name = testid
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/[0-9a-f]{8}-[0-9a-f-]{27,}/g, '')
|
|
15
|
+
.replace(/(^|[-_:/.])[a-z]?-?[0-9a-f]*[0-9][0-9a-f]*(?=$|[-_:/.])/g, '$1')
|
|
16
|
+
.replace(/[-_:/.]{2,}/g, '-')
|
|
17
|
+
.replace(/^[-_:/.]+|[-_:/.]+$/g, '')
|
|
18
|
+
.slice(0, 64);
|
|
19
|
+
return NAME.test(name) ? name : null;
|
|
20
|
+
}
|
|
21
|
+
function beacon(url, batch) {
|
|
22
|
+
const body = new Blob([JSON.stringify(batch)], { type: 'application/json' });
|
|
23
|
+
if (navigator.sendBeacon?.(url, body) === true)
|
|
24
|
+
return;
|
|
25
|
+
void fetch(url, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body,
|
|
28
|
+
keepalive: true,
|
|
29
|
+
credentials: 'same-origin',
|
|
30
|
+
}).catch(() => undefined);
|
|
31
|
+
}
|
|
32
|
+
/** Start counting. Returns the stop, which flushes what is left. */
|
|
33
|
+
export function startUsage(deps) {
|
|
34
|
+
const { url, screenOf, batchMax, flushMs = 30_000 } = deps;
|
|
35
|
+
const doc = deps.doc ?? document;
|
|
36
|
+
const win = deps.win ?? window;
|
|
37
|
+
const send = deps.send ?? beacon;
|
|
38
|
+
let entries = [];
|
|
39
|
+
const flush = () => {
|
|
40
|
+
if (entries.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
const batch = { entries };
|
|
43
|
+
entries = [];
|
|
44
|
+
send(url, batch);
|
|
45
|
+
};
|
|
46
|
+
const push = (entry) => {
|
|
47
|
+
entries.push(entry);
|
|
48
|
+
if (entries.length >= batchMax)
|
|
49
|
+
flush();
|
|
50
|
+
};
|
|
51
|
+
let screen = screenOf(win.location.hash);
|
|
52
|
+
push({ kind: 'view', screen });
|
|
53
|
+
const onHash = () => {
|
|
54
|
+
const next = screenOf(win.location.hash);
|
|
55
|
+
if (next === screen)
|
|
56
|
+
return;
|
|
57
|
+
screen = next;
|
|
58
|
+
push({ kind: 'view', screen });
|
|
59
|
+
};
|
|
60
|
+
const onClick = (event) => {
|
|
61
|
+
const el = event.target instanceof Element ? event.target.closest('[data-testid]') : null;
|
|
62
|
+
const testid = el?.getAttribute('data-testid');
|
|
63
|
+
const target = testid ? targetName(testid) : null;
|
|
64
|
+
if (target !== null)
|
|
65
|
+
push({ kind: 'click', screen, target });
|
|
66
|
+
};
|
|
67
|
+
const onHide = () => {
|
|
68
|
+
if (doc.visibilityState === 'hidden')
|
|
69
|
+
flush();
|
|
70
|
+
};
|
|
71
|
+
win.addEventListener('hashchange', onHash);
|
|
72
|
+
doc.addEventListener('click', onClick, { capture: true, passive: true });
|
|
73
|
+
doc.addEventListener('visibilitychange', onHide);
|
|
74
|
+
win.addEventListener('pagehide', flush);
|
|
75
|
+
const timer = win.setInterval(flush, flushMs);
|
|
76
|
+
return () => {
|
|
77
|
+
win.removeEventListener('hashchange', onHash);
|
|
78
|
+
doc.removeEventListener('click', onClick, { capture: true });
|
|
79
|
+
doc.removeEventListener('visibilitychange', onHide);
|
|
80
|
+
win.removeEventListener('pagehide', flush);
|
|
81
|
+
win.clearInterval(timer);
|
|
82
|
+
flush();
|
|
83
|
+
};
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/ui-shell",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"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 and @wolffm/*.",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./app-id": {
|
|
9
|
+
"types": "./dist/app-id/index.d.ts",
|
|
10
|
+
"import": "./dist/app-id/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./chrome": {
|
|
13
|
+
"types": "./dist/chrome/index.d.ts",
|
|
14
|
+
"import": "./dist/chrome/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./chrome/shell": {
|
|
17
|
+
"types": "./dist/chrome/shell.d.ts",
|
|
18
|
+
"import": "./dist/chrome/shell.js"
|
|
19
|
+
},
|
|
20
|
+
"./embed": {
|
|
21
|
+
"types": "./dist/embed/index.d.ts",
|
|
22
|
+
"import": "./dist/embed/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./trim": {
|
|
25
|
+
"types": "./dist/trim/index.d.ts",
|
|
26
|
+
"import": "./dist/trim/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./theme": {
|
|
29
|
+
"types": "./dist/theme/index.d.ts",
|
|
30
|
+
"import": "./dist/theme/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./settings": {
|
|
33
|
+
"types": "./dist/settings/index.d.ts",
|
|
34
|
+
"import": "./dist/settings/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./usage": {
|
|
37
|
+
"types": "./dist/usage/index.d.ts",
|
|
38
|
+
"import": "./dist/usage/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./sound": {
|
|
41
|
+
"types": "./dist/sound/index.d.ts",
|
|
42
|
+
"import": "./dist/sound/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./motion": {
|
|
45
|
+
"types": "./dist/motion/index.d.ts",
|
|
46
|
+
"import": "./dist/motion/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./components": {
|
|
49
|
+
"types": "./dist/components/index.d.ts",
|
|
50
|
+
"import": "./dist/components/index.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": "^19.2.8",
|
|
55
|
+
"react-dom": "^19.2.8"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
|
|
59
|
+
"@wolffm/themes": "npm:@hadoku/themes@^5.14.4",
|
|
60
|
+
"zod": "4.5.4"
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"dist",
|
|
64
|
+
"LICENSE"
|
|
65
|
+
],
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "https://github.com/WolffM/hadoku-cardtable.git",
|
|
69
|
+
"directory": "packages/ui-shell"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/README.md
DELETED