@hadoku/ui-shell 0.1.217 → 0.1.218
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/animate.d.ts +12 -0
- package/dist/motion/animate.js +31 -0
- package/dist/motion/flip.d.ts +15 -0
- package/dist/motion/flip.js +53 -0
- package/dist/motion/frame.d.ts +8 -0
- package/dist/motion/frame.js +19 -0
- package/dist/motion/index.d.ts +4 -6
- package/dist/motion/index.js +4 -6
- package/package.json +3 -3
package/dist/motion/animate.d.ts
CHANGED
|
@@ -29,6 +29,18 @@ export declare function timerSet(): {
|
|
|
29
29
|
after: (fn: () => void, ms: number) => void;
|
|
30
30
|
clear: () => void;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* `attr` (set to `value`, else empty) on `el` once more, its animation replayed from the start even if it is still
|
|
34
|
+
* running: off, one style flush, and on again. It comes off after `ms` on `after` (the layer's timer, so taking the
|
|
35
|
+
* layer down clears it), or at the end of the animation named `onEnd`, `ms` then being only the backstop for one
|
|
36
|
+
* never shown. Returns the cancel, which takes the mark off now unless a newer restart has it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function restartMark(el: Element, attr: string, o: {
|
|
39
|
+
value?: string;
|
|
40
|
+
ms: number;
|
|
41
|
+
after: (fn: () => void, ms: number) => void;
|
|
42
|
+
onEnd?: string;
|
|
43
|
+
}): () => void;
|
|
32
44
|
/** A clip and how long it lasts on its own clock (before `ctx.tempo` divides it): what a timeline adds up. */
|
|
33
45
|
export type Timed = Clip & {
|
|
34
46
|
readonly ms: number;
|
package/dist/motion/animate.js
CHANGED
|
@@ -40,6 +40,37 @@ export function timerSet() {
|
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
/** Each element's newest restart of each mark: an older one's end never clears a newer one. */
|
|
44
|
+
const marks = new WeakMap();
|
|
45
|
+
/**
|
|
46
|
+
* `attr` (set to `value`, else empty) on `el` once more, its animation replayed from the start even if it is still
|
|
47
|
+
* running: off, one style flush, and on again. It comes off after `ms` on `after` (the layer's timer, so taking the
|
|
48
|
+
* layer down clears it), or at the end of the animation named `onEnd`, `ms` then being only the backstop for one
|
|
49
|
+
* never shown. Returns the cancel, which takes the mark off now unless a newer restart has it.
|
|
50
|
+
*/
|
|
51
|
+
export function restartMark(el, attr, o) {
|
|
52
|
+
const mine = {};
|
|
53
|
+
const own = marks.get(el) ?? new Map();
|
|
54
|
+
marks.set(el, own.set(attr, mine));
|
|
55
|
+
el.removeAttribute(attr);
|
|
56
|
+
void el.offsetWidth;
|
|
57
|
+
el.setAttribute(attr, o.value ?? '');
|
|
58
|
+
const end = () => {
|
|
59
|
+
if (own.get(attr) !== mine)
|
|
60
|
+
return;
|
|
61
|
+
own.delete(attr);
|
|
62
|
+
el.removeAttribute(attr);
|
|
63
|
+
el.removeEventListener('animationend', ended);
|
|
64
|
+
};
|
|
65
|
+
const ended = (e) => {
|
|
66
|
+
if (e.animationName === o.onEnd)
|
|
67
|
+
end();
|
|
68
|
+
};
|
|
69
|
+
if (o.onEnd !== undefined)
|
|
70
|
+
el.addEventListener('animationend', ended);
|
|
71
|
+
o.after(end, o.ms);
|
|
72
|
+
return end;
|
|
73
|
+
}
|
|
43
74
|
/** The `runs` as one: over once every one is, cancelled together, as long as the longest. */
|
|
44
75
|
export const together = (runs) => ({
|
|
45
76
|
finished: Promise.all(runs.map((r) => r.finished)).then(() => undefined),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AnimateContext, type Running } from './animate.js';
|
|
2
|
+
import type { Box } from './stand-in.js';
|
|
3
|
+
export interface FlipOptions {
|
|
4
|
+
ms: number;
|
|
5
|
+
easing: string;
|
|
6
|
+
/** An attribute each sliding element wears until its slide is over, for a sheet that keeps it out of the pointer's way meanwhile. */
|
|
7
|
+
flag?: string;
|
|
8
|
+
/** The old box's size too, not only its place: the element grows or shrinks into its own, about its centre. */
|
|
9
|
+
scale?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Each element in `moved` glides from `was`, the box it was drawn in (viewport coordinates), to the box it is laid
|
|
13
|
+
* out in now. Reduced motion (`ctx.reduced`, else the player's card-motion switch) plays nothing and writes nothing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function flip(moved: Iterable<readonly [HTMLElement, Box]>, o: FlipOptions, ctx?: AnimateContext): Running;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The slide: elements a layout change moved glide from where they were drawn to where they are drawn now (FLIP:
|
|
3
|
+
* First, Last, Invert, Play). The old box is the first keyframe of a Web Animation, so nothing is written inline
|
|
4
|
+
* and no layout is forced between the two. Under reduced motion nothing slides: each element is simply where it is.
|
|
5
|
+
*/
|
|
6
|
+
import { animate, STILL, together } from "./animate.js";
|
|
7
|
+
import { prefersReducedMotion } from "./index.js";
|
|
8
|
+
/** Less than this far, in pixels, is not a move. */
|
|
9
|
+
const STILL_PX = 0.5;
|
|
10
|
+
/** Each element's slide under way: a new one starts from where the element is laid out, not where the old has it. */
|
|
11
|
+
const sliding = new WeakMap();
|
|
12
|
+
/**
|
|
13
|
+
* Each element in `moved` glides from `was`, the box it was drawn in (viewport coordinates), to the box it is laid
|
|
14
|
+
* out in now. Reduced motion (`ctx.reduced`, else the player's card-motion switch) plays nothing and writes nothing.
|
|
15
|
+
*/
|
|
16
|
+
export function flip(moved, o, ctx = {}) {
|
|
17
|
+
const reduced = ctx.reduced ?? prefersReducedMotion();
|
|
18
|
+
if (reduced)
|
|
19
|
+
return STILL;
|
|
20
|
+
const { flag } = o;
|
|
21
|
+
const pairs = [...moved];
|
|
22
|
+
for (const [el] of pairs)
|
|
23
|
+
sliding.get(el)?.cancel();
|
|
24
|
+
const starts = pairs.map(([el, was]) => {
|
|
25
|
+
const now = el.getBoundingClientRect();
|
|
26
|
+
const dx = was.left + was.width / 2 - (now.left + now.width / 2);
|
|
27
|
+
const dy = was.top + was.height / 2 - (now.top + now.height / 2);
|
|
28
|
+
const s = o.scale === true && now.width > 0 ? was.width / now.width : 1;
|
|
29
|
+
const still = Math.abs(dx) < STILL_PX && Math.abs(dy) < STILL_PX && Math.abs(s - 1) < 0.01;
|
|
30
|
+
return still ? null : [el, s === 1 ? `translate(${dx}px, ${dy}px)` : `translate(${dx}px, ${dy}px) scale(${s})`];
|
|
31
|
+
});
|
|
32
|
+
const runs = [];
|
|
33
|
+
for (const start of starts) {
|
|
34
|
+
if (start === null)
|
|
35
|
+
continue;
|
|
36
|
+
const [el, from] = start;
|
|
37
|
+
const run = animate(el, [{ transform: from }, { transform: 'none' }], { duration: o.ms, easing: o.easing }, { ...ctx, reduced });
|
|
38
|
+
if (run === STILL)
|
|
39
|
+
continue;
|
|
40
|
+
sliding.set(el, run);
|
|
41
|
+
if (flag !== undefined)
|
|
42
|
+
el.setAttribute(flag, '');
|
|
43
|
+
void run.finished.then(() => {
|
|
44
|
+
if (sliding.get(el) !== run)
|
|
45
|
+
return;
|
|
46
|
+
sliding.delete(el);
|
|
47
|
+
if (flag !== undefined)
|
|
48
|
+
el.removeAttribute(flag);
|
|
49
|
+
});
|
|
50
|
+
runs.push(run);
|
|
51
|
+
}
|
|
52
|
+
return runs.length === 0 ? STILL : together(runs);
|
|
53
|
+
}
|
package/dist/motion/frame.d.ts
CHANGED
|
@@ -9,5 +9,13 @@ export type FrameStep = (now: number) => (() => void) | null;
|
|
|
9
9
|
export declare function everyFrame(step: FrameStep): () => void;
|
|
10
10
|
/** `write` once, with the next frame's writes. Returns the cancel. */
|
|
11
11
|
export declare function nextFrame(write: () => void): () => void;
|
|
12
|
+
/**
|
|
13
|
+
* `step` once, on the next frame after `soon()`: its read with the frame's reads, its write with the frame's writes.
|
|
14
|
+
* At most one frame is owed, however often `soon()` is asked meanwhile; one asked for during the step is the next.
|
|
15
|
+
*/
|
|
16
|
+
export declare function perFrame(step: FrameStep): {
|
|
17
|
+
soon: () => void;
|
|
18
|
+
cancel: () => void;
|
|
19
|
+
};
|
|
12
20
|
/** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
|
|
13
21
|
export declare function resetFrames(): void;
|
package/dist/motion/frame.js
CHANGED
|
@@ -13,6 +13,25 @@ export function nextFrame(write) {
|
|
|
13
13
|
const stop = everyFrame(() => (stop(), write));
|
|
14
14
|
return stop;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* `step` once, on the next frame after `soon()`: its read with the frame's reads, its write with the frame's writes.
|
|
18
|
+
* At most one frame is owed, however often `soon()` is asked meanwhile; one asked for during the step is the next.
|
|
19
|
+
*/
|
|
20
|
+
export function perFrame(step) {
|
|
21
|
+
let owed = null;
|
|
22
|
+
return {
|
|
23
|
+
soon: () => {
|
|
24
|
+
if (owed !== null)
|
|
25
|
+
return;
|
|
26
|
+
const stop = everyFrame((now) => (stop(), (owed = null), step(now)));
|
|
27
|
+
owed = stop;
|
|
28
|
+
},
|
|
29
|
+
cancel: () => {
|
|
30
|
+
owed?.();
|
|
31
|
+
owed = null;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
16
35
|
/** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
|
|
17
36
|
export function resetFrames() {
|
|
18
37
|
loops.clear();
|
package/dist/motion/index.d.ts
CHANGED
|
@@ -17,10 +17,7 @@ export declare function systemReducesMotion(): boolean;
|
|
|
17
17
|
export declare function motionState(choices?: MotionChoices): MotionState;
|
|
18
18
|
/** The player's choices, as the page applies them from now on (`applyMotion` writes them on a root). */
|
|
19
19
|
export declare function setMotionChoices(choices: MotionChoices): void;
|
|
20
|
-
/**
|
|
21
|
-
* Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without
|
|
22
|
-
* caring where the question lives; cardtable's own `play/motion.ts` re-exports it.
|
|
23
|
-
*/
|
|
20
|
+
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
24
21
|
export declare function prefersReducedMotion(): boolean;
|
|
25
22
|
/** Whether the table may shake. */
|
|
26
23
|
export declare function screenShakeAllowed(): boolean;
|
|
@@ -31,8 +28,9 @@ export declare function clearMotion(root: Element): void;
|
|
|
31
28
|
export declare function rememberedMotion(key: string): MotionChoices | null;
|
|
32
29
|
export declare function rememberMotion(key: string, choices: MotionChoices): void;
|
|
33
30
|
export { ambientPlayState, gateSelector, motionCss } from './css.js';
|
|
34
|
-
export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations, type AnimateContext, type Clip, type MotionContext, type Running, type Timed } from './animate.js';
|
|
35
|
-
export {
|
|
31
|
+
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
|
+
export { flip, type FlipOptions } from './flip.js';
|
|
33
|
+
export { everyFrame, nextFrame, perFrame, resetFrames, type FrameStep } from './frame.js';
|
|
36
34
|
export { claimParticles, PARTICLE_BUDGET, particlePool, particleShare, shared, type ParticlePool } from './particles.js';
|
|
37
35
|
export { animationName, Stage, type StageHold, type StageOptions, type TrackOptions } from './stage.js';
|
|
38
36
|
export { afterGlide, rel, standIn, type Box, type StandInOptions } from './stand-in.js';
|
package/dist/motion/index.js
CHANGED
|
@@ -37,10 +37,7 @@ export function motionState(choices = chosen) {
|
|
|
37
37
|
export function setMotionChoices(choices) {
|
|
38
38
|
chosen = { ...choices };
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without
|
|
42
|
-
* caring where the question lives; cardtable's own `play/motion.ts` re-exports it.
|
|
43
|
-
*/
|
|
40
|
+
/** Whether the board draws its reduced-motion path: card motion off. Any game's board reads this without caring where the question lives. */
|
|
44
41
|
export function prefersReducedMotion() {
|
|
45
42
|
return !motionState().cardMotion;
|
|
46
43
|
}
|
|
@@ -78,8 +75,9 @@ export function rememberMotion(key, choices) {
|
|
|
78
75
|
remember(key, JSON.stringify(choices));
|
|
79
76
|
}
|
|
80
77
|
export { ambientPlayState, gateSelector, motionCss } from "./css.js";
|
|
81
|
-
export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations } from "./animate.js";
|
|
82
|
-
export {
|
|
78
|
+
export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, restartMark, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations } from "./animate.js";
|
|
79
|
+
export { flip } from "./flip.js";
|
|
80
|
+
export { everyFrame, nextFrame, perFrame, resetFrames } from "./frame.js";
|
|
83
81
|
export { claimParticles, PARTICLE_BUDGET, particlePool, particleShare, shared } from "./particles.js";
|
|
84
82
|
export { animationName, Stage } from "./stage.js";
|
|
85
83
|
export { afterGlide, rel, standIn } from "./stand-in.js";
|
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.218",
|
|
4
|
+
"gitHead": "dd16a0ec8c9c1406543927f1aacfec66728179e7",
|
|
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.218",
|
|
76
76
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
77
77
|
"@wolffm/themes": "npm:@hadoku/themes@^5.14.21",
|
|
78
78
|
"zod": "4.5.4"
|