@hadoku/ui-shell 0.1.257 → 0.1.259
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/dist/motion/flip.js +1 -1
- package/dist/motion/index.d.ts +1 -29
- package/dist/motion/index.js +2 -76
- package/dist/motion/switches.d.ts +31 -0
- package/dist/motion/switches.js +90 -0
- package/package.json +3 -3
package/dist/motion/flip.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* The slide (FLIP): what a layout change moved glides from the box it was drawn in, as a Web Animation from there to its own. */
|
|
2
2
|
import { animate, STILL, together } from "./animate.js";
|
|
3
|
-
import { prefersReducedMotion } from "./
|
|
3
|
+
import { prefersReducedMotion } from "./switches.js";
|
|
4
4
|
/** Each element's slide under way: a new one starts from where the element is laid out, not where the old has it. */
|
|
5
5
|
const sliding = new WeakMap();
|
|
6
6
|
/**
|
package/dist/motion/index.d.ts
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface MotionChoices {
|
|
3
|
-
cardMotion?: boolean;
|
|
4
|
-
screenShake?: boolean;
|
|
5
|
-
ambientMotion?: boolean;
|
|
6
|
-
}
|
|
7
|
-
/** Every switch resolved: what the page does now. */
|
|
8
|
-
export type MotionState = Required<MotionChoices>;
|
|
9
|
-
export declare const MOTION_ATTR: {
|
|
10
|
-
readonly motion: "data-motion";
|
|
11
|
-
readonly shake: "data-shake";
|
|
12
|
-
readonly ambient: "data-ambient";
|
|
13
|
-
};
|
|
14
|
-
/** Whether the system asks for less motion: the default for every switch nobody has set. */
|
|
15
|
-
export declare function systemReducesMotion(): boolean;
|
|
16
|
-
/** The switches as the page applies them: each the player's, else the system's. */
|
|
17
|
-
export declare function motionState(choices?: MotionChoices): MotionState;
|
|
18
|
-
/** The player's choices, as the page applies them from now on (`applyMotion` writes them on a root). */
|
|
19
|
-
export declare function setMotionChoices(choices: MotionChoices): void;
|
|
20
|
-
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
21
|
-
export declare function prefersReducedMotion(): boolean;
|
|
22
|
-
/** Whether the table may shake. */
|
|
23
|
-
export declare function screenShakeAllowed(): boolean;
|
|
24
|
-
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
25
|
-
export declare function applyMotion(root: Element, choices?: MotionChoices): void;
|
|
26
|
-
export declare function clearMotion(root: Element): void;
|
|
27
|
-
/** Per game (`<key>`, handed in): the choices last applied in this browser, so the first frame is drawn with them. */
|
|
28
|
-
export declare function rememberedMotion(key: string): MotionChoices | null;
|
|
29
|
-
export declare function rememberMotion(key: string, choices: MotionChoices): void;
|
|
1
|
+
export { applyMotion, clearMotion, MOTION_ATTR, motionState, prefersReducedMotion, rememberedMotion, rememberMotion, screenShakeAllowed, setMotionChoices, subscribeMotion, systemReducesMotion, type MotionChoices, type MotionState } from './switches.js';
|
|
30
2
|
export { ambientPlayState, gateSelector, motionCss } from './css.js';
|
|
31
3
|
export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, restartMark, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations, type AnimateContext, type Clip, type MotionContext, type Running, type Timed } from './animate.js';
|
|
32
4
|
export { flip, type FlipOptions } from './flip.js';
|
package/dist/motion/index.js
CHANGED
|
@@ -1,79 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
* elements were bad for their ADHD: "let's just make sure that each of them can be individually toggled").
|
|
4
|
-
*
|
|
5
|
-
* Three switches, each its own:
|
|
6
|
-
* - **Card motion** — what travels, rams, cracks and pops. Off is the board's reduced-motion path:
|
|
7
|
-
* every `prefersReducedMotion()` reader, and every `@media (prefers-reduced-motion: …)` block,
|
|
8
|
-
* which `motionCss` (`./css.ts`) makes answer to the switch.
|
|
9
|
-
* - **Screen shake** — the table jolting under a heavy blow (`screenShakeAllowed()`).
|
|
10
|
-
* - **Ambient motion** — the endless loops: pulses, glows, shimmers, bobbing. Off pauses each, its
|
|
11
|
-
* first frame left standing (`motionCss`).
|
|
12
|
-
*
|
|
13
|
-
* A switch nobody has set follows the system's `prefers-reduced-motion`: asked for less, all three
|
|
14
|
-
* start off. What the player sets wins either way, so a player can also turn motion ON over the OS.
|
|
15
|
-
* A switch the player set is written on the root the sheets resolve on, as `data-motion` (`full`/`reduce`)
|
|
16
|
-
* or `data-ambient` (`on`/`off`); one left to the system is not, so the sheets' own media query answers in
|
|
17
|
-
* the frame the system changes (an attribute written from a `change` event lags it by a frame or more:
|
|
18
|
-
* af70's flyer swayed on under reduced motion). `data-shake` is always written: script reads it.
|
|
19
|
-
*/
|
|
20
|
-
import { remember, remembered } from "../storage/index.js";
|
|
21
|
-
export const MOTION_ATTR = { motion: 'data-motion', shake: 'data-shake', ambient: 'data-ambient' };
|
|
22
|
-
let chosen = {};
|
|
23
|
-
/** Whether the system asks for less motion: the default for every switch nobody has set. */
|
|
24
|
-
export function systemReducesMotion() {
|
|
25
|
-
return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
26
|
-
}
|
|
27
|
-
/** The switches as the page applies them: each the player's, else the system's. */
|
|
28
|
-
export function motionState(choices = chosen) {
|
|
29
|
-
const system = !systemReducesMotion();
|
|
30
|
-
return {
|
|
31
|
-
cardMotion: choices.cardMotion ?? system,
|
|
32
|
-
screenShake: choices.screenShake ?? system,
|
|
33
|
-
ambientMotion: choices.ambientMotion ?? system,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/** The player's choices, as the page applies them from now on (`applyMotion` writes them on a root). */
|
|
37
|
-
export function setMotionChoices(choices) {
|
|
38
|
-
chosen = { ...choices };
|
|
39
|
-
}
|
|
40
|
-
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
41
|
-
export function prefersReducedMotion() {
|
|
42
|
-
return !motionState().cardMotion;
|
|
43
|
-
}
|
|
44
|
-
/** Whether the table may shake. */
|
|
45
|
-
export function screenShakeAllowed() {
|
|
46
|
-
return motionState().screenShake;
|
|
47
|
-
}
|
|
48
|
-
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
49
|
-
export function applyMotion(root, choices = chosen) {
|
|
50
|
-
const set = (attr, on, yes, no) => (on === undefined ? root.removeAttribute(attr) : root.setAttribute(attr, on ? yes : no));
|
|
51
|
-
set(MOTION_ATTR.motion, choices.cardMotion, 'full', 'reduce');
|
|
52
|
-
set(MOTION_ATTR.ambient, choices.ambientMotion, 'on', 'off');
|
|
53
|
-
root.setAttribute(MOTION_ATTR.shake, motionState(choices).screenShake ? 'on' : 'off');
|
|
54
|
-
}
|
|
55
|
-
export function clearMotion(root) {
|
|
56
|
-
for (const attr of Object.values(MOTION_ATTR))
|
|
57
|
-
root.removeAttribute(attr);
|
|
58
|
-
}
|
|
59
|
-
/** Per game (`<key>`, handed in): the choices last applied in this browser, so the first frame is drawn with them. */
|
|
60
|
-
export function rememberedMotion(key) {
|
|
61
|
-
return remembered(key, (raw) => {
|
|
62
|
-
const parsed = JSON.parse(raw);
|
|
63
|
-
if (typeof parsed !== 'object' || parsed === null)
|
|
64
|
-
return null;
|
|
65
|
-
const out = {};
|
|
66
|
-
for (const name of ['cardMotion', 'screenShake', 'ambientMotion']) {
|
|
67
|
-
const v = parsed[name];
|
|
68
|
-
if (typeof v === 'boolean')
|
|
69
|
-
out[name] = v;
|
|
70
|
-
}
|
|
71
|
-
return out;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
export function rememberMotion(key, choices) {
|
|
75
|
-
remember(key, JSON.stringify(choices));
|
|
76
|
-
}
|
|
1
|
+
/* The motion kit: the player's switches (`./switches.ts`) and the pieces that answer to them. */
|
|
2
|
+
export { applyMotion, clearMotion, MOTION_ATTR, motionState, prefersReducedMotion, rememberedMotion, rememberMotion, screenShakeAllowed, setMotionChoices, subscribeMotion, systemReducesMotion } from "./switches.js";
|
|
77
3
|
export { ambientPlayState, gateSelector, motionCss } from "./css.js";
|
|
78
4
|
export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, restartMark, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations } from "./animate.js";
|
|
79
5
|
export { flip } from "./flip.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** One player's choices; a switch left `undefined` follows the system. */
|
|
2
|
+
export interface MotionChoices {
|
|
3
|
+
cardMotion?: boolean;
|
|
4
|
+
screenShake?: boolean;
|
|
5
|
+
ambientMotion?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Every switch resolved: what the page does now. */
|
|
8
|
+
export type MotionState = Required<MotionChoices>;
|
|
9
|
+
export declare const MOTION_ATTR: {
|
|
10
|
+
readonly motion: "data-motion";
|
|
11
|
+
readonly shake: "data-shake";
|
|
12
|
+
readonly ambient: "data-ambient";
|
|
13
|
+
};
|
|
14
|
+
/** Whether the system asks for less motion: the default for every switch nobody has set. */
|
|
15
|
+
export declare function systemReducesMotion(): boolean;
|
|
16
|
+
/** Told whenever `motionState()` may have changed: the choices set again, or the system's preference changing. Returns the unsubscribe. */
|
|
17
|
+
export declare function subscribeMotion(fn: () => void): () => void;
|
|
18
|
+
/** The switches as the page applies them: each the player's, else the system's. */
|
|
19
|
+
export declare function motionState(choices?: MotionChoices): MotionState;
|
|
20
|
+
/** The player's choices, as the page applies them from now on (`applyMotion` writes them on a root). */
|
|
21
|
+
export declare function setMotionChoices(choices: MotionChoices): void;
|
|
22
|
+
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
23
|
+
export declare function prefersReducedMotion(): boolean;
|
|
24
|
+
/** Whether the table may shake. */
|
|
25
|
+
export declare function screenShakeAllowed(): boolean;
|
|
26
|
+
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
27
|
+
export declare function applyMotion(root: Element, choices?: MotionChoices): void;
|
|
28
|
+
export declare function clearMotion(root: Element): void;
|
|
29
|
+
/** Per game (`<key>`, handed in): the choices last applied in this browser, so the first frame is drawn with them. */
|
|
30
|
+
export declare function rememberedMotion(key: string): MotionChoices | null;
|
|
31
|
+
export declare function rememberMotion(key: string, choices: MotionChoices): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How much the page moves, the player's say over it (operator, 2026-11-21, after a player said moving
|
|
3
|
+
* elements were bad for their ADHD: "let's just make sure that each of them can be individually toggled").
|
|
4
|
+
*
|
|
5
|
+
* Three switches, each its own:
|
|
6
|
+
* - **Card motion** — what travels, rams, cracks and pops. Off is the board's reduced-motion path:
|
|
7
|
+
* every `prefersReducedMotion()` reader, and every `@media (prefers-reduced-motion: …)` block,
|
|
8
|
+
* which `motionCss` (`./css.ts`) makes answer to the switch.
|
|
9
|
+
* - **Screen shake** — the table jolting under a heavy blow (`screenShakeAllowed()`).
|
|
10
|
+
* - **Ambient motion** — the endless loops: pulses, glows, shimmers, bobbing. Off pauses each, its
|
|
11
|
+
* first frame left standing (`motionCss`).
|
|
12
|
+
*
|
|
13
|
+
* A switch nobody has set follows the system's `prefers-reduced-motion`: asked for less, all three
|
|
14
|
+
* start off. What the player sets wins either way, so a player can also turn motion ON over the OS.
|
|
15
|
+
* A switch the player set is written on the root the sheets resolve on, as `data-motion` (`full`/`reduce`)
|
|
16
|
+
* or `data-ambient` (`on`/`off`); one left to the system is not, so the sheets' own media query answers in
|
|
17
|
+
* the frame the system changes (an attribute written from a `change` event lags it by a frame or more:
|
|
18
|
+
* af70's flyer swayed on under reduced motion). `data-shake` is always written: script reads it.
|
|
19
|
+
*/
|
|
20
|
+
import { remember, remembered } from "../storage/index.js";
|
|
21
|
+
export const MOTION_ATTR = { motion: 'data-motion', shake: 'data-shake', ambient: 'data-ambient' };
|
|
22
|
+
let chosen = {};
|
|
23
|
+
const REDUCE_QUERY = '(prefers-reduced-motion: reduce)';
|
|
24
|
+
/** Whether the system asks for less motion: the default for every switch nobody has set. */
|
|
25
|
+
export function systemReducesMotion() {
|
|
26
|
+
return typeof matchMedia === 'function' && matchMedia(REDUCE_QUERY).matches;
|
|
27
|
+
}
|
|
28
|
+
const listeners = new Set();
|
|
29
|
+
const tell = () => listeners.forEach((fn) => fn());
|
|
30
|
+
let watchingSystem = false;
|
|
31
|
+
/** Told whenever `motionState()` may have changed: the choices set again, or the system's preference changing. Returns the unsubscribe. */
|
|
32
|
+
export function subscribeMotion(fn) {
|
|
33
|
+
if (!watchingSystem && typeof matchMedia === 'function') {
|
|
34
|
+
watchingSystem = true;
|
|
35
|
+
matchMedia(REDUCE_QUERY).addEventListener('change', tell);
|
|
36
|
+
}
|
|
37
|
+
listeners.add(fn);
|
|
38
|
+
return () => void listeners.delete(fn);
|
|
39
|
+
}
|
|
40
|
+
/** The switches as the page applies them: each the player's, else the system's. */
|
|
41
|
+
export function motionState(choices = chosen) {
|
|
42
|
+
const system = !systemReducesMotion();
|
|
43
|
+
return {
|
|
44
|
+
cardMotion: choices.cardMotion ?? system,
|
|
45
|
+
screenShake: choices.screenShake ?? system,
|
|
46
|
+
ambientMotion: choices.ambientMotion ?? system,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** The player's choices, as the page applies them from now on (`applyMotion` writes them on a root). */
|
|
50
|
+
export function setMotionChoices(choices) {
|
|
51
|
+
chosen = { ...choices };
|
|
52
|
+
tell();
|
|
53
|
+
}
|
|
54
|
+
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
55
|
+
export function prefersReducedMotion() {
|
|
56
|
+
return !motionState().cardMotion;
|
|
57
|
+
}
|
|
58
|
+
/** Whether the table may shake. */
|
|
59
|
+
export function screenShakeAllowed() {
|
|
60
|
+
return motionState().screenShake;
|
|
61
|
+
}
|
|
62
|
+
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
63
|
+
export function applyMotion(root, choices = chosen) {
|
|
64
|
+
const set = (attr, on, yes, no) => (on === undefined ? root.removeAttribute(attr) : root.setAttribute(attr, on ? yes : no));
|
|
65
|
+
set(MOTION_ATTR.motion, choices.cardMotion, 'full', 'reduce');
|
|
66
|
+
set(MOTION_ATTR.ambient, choices.ambientMotion, 'on', 'off');
|
|
67
|
+
root.setAttribute(MOTION_ATTR.shake, motionState(choices).screenShake ? 'on' : 'off');
|
|
68
|
+
}
|
|
69
|
+
export function clearMotion(root) {
|
|
70
|
+
for (const attr of Object.values(MOTION_ATTR))
|
|
71
|
+
root.removeAttribute(attr);
|
|
72
|
+
}
|
|
73
|
+
/** Per game (`<key>`, handed in): the choices last applied in this browser, so the first frame is drawn with them. */
|
|
74
|
+
export function rememberedMotion(key) {
|
|
75
|
+
return remembered(key, (raw) => {
|
|
76
|
+
const parsed = JSON.parse(raw);
|
|
77
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
78
|
+
return null;
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const name of ['cardMotion', 'screenShake', 'ambientMotion']) {
|
|
81
|
+
const v = parsed[name];
|
|
82
|
+
if (typeof v === 'boolean')
|
|
83
|
+
out[name] = v;
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export function rememberMotion(key, choices) {
|
|
89
|
+
remember(key, JSON.stringify(choices));
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/ui-shell",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.259",
|
|
4
|
+
"gitHead": "e724376d6b5ef49938c93bc733dfb9e260f57d5f",
|
|
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/*.",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"react-dom": "^19.2.8"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
75
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.259",
|
|
76
76
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.4",
|
|
77
77
|
"@wolffm/themes": "npm:@hadoku/themes@^5.14.22",
|
|
78
78
|
"zod": "^4.6.7"
|