@hadoku/ui-shell 0.1.217 → 0.1.219
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 +11 -0
- package/dist/motion/animate.js +27 -0
- package/dist/motion/flip.d.ts +14 -0
- package/dist/motion/flip.js +42 -0
- package/dist/motion/frame.d.ts +5 -0
- package/dist/motion/frame.js +6 -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,17 @@ export declare function timerSet(): {
|
|
|
29
29
|
after: (fn: () => void, ms: number) => void;
|
|
30
30
|
clear: () => void;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* `attr` (= `value`, else empty) on `el` again, its animation replayed from the start: off, one style flush, on. It
|
|
34
|
+
* comes off after `ms` on `after` (the layer's timer, so teardown clears it), or at the end of the animation named
|
|
35
|
+
* `onEnd`, `ms` then the backstop. Returns the cancel: off now, unless a newer restart has it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function restartMark(el: Element, attr: string, o: {
|
|
38
|
+
value?: string;
|
|
39
|
+
ms: number;
|
|
40
|
+
after: (fn: () => void, ms: number) => void;
|
|
41
|
+
onEnd?: string;
|
|
42
|
+
}): () => void;
|
|
32
43
|
/** A clip and how long it lasts on its own clock (before `ctx.tempo` divides it): what a timeline adds up. */
|
|
33
44
|
export type Timed = Clip & {
|
|
34
45
|
readonly ms: number;
|
package/dist/motion/animate.js
CHANGED
|
@@ -40,6 +40,33 @@ 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` (= `value`, else empty) on `el` again, its animation replayed from the start: off, one style flush, on. It
|
|
47
|
+
* comes off after `ms` on `after` (the layer's timer, so teardown clears it), or at the end of the animation named
|
|
48
|
+
* `onEnd`, `ms` then the backstop. Returns the cancel: off now, unless a newer restart has it.
|
|
49
|
+
*/
|
|
50
|
+
export function restartMark(el, attr, o) {
|
|
51
|
+
const mine = {};
|
|
52
|
+
const own = marks.get(el) ?? new Map();
|
|
53
|
+
marks.set(el, own.set(attr, mine));
|
|
54
|
+
el.removeAttribute(attr);
|
|
55
|
+
void el.offsetWidth;
|
|
56
|
+
el.setAttribute(attr, o.value ?? '');
|
|
57
|
+
const ended = (e) => void (e.animationName === o.onEnd && end());
|
|
58
|
+
const end = () => {
|
|
59
|
+
el.removeEventListener('animationend', ended);
|
|
60
|
+
if (own.get(attr) !== mine)
|
|
61
|
+
return;
|
|
62
|
+
own.delete(attr);
|
|
63
|
+
el.removeAttribute(attr);
|
|
64
|
+
};
|
|
65
|
+
if (o.onEnd !== undefined)
|
|
66
|
+
el.addEventListener('animationend', ended);
|
|
67
|
+
o.after(end, o.ms);
|
|
68
|
+
return end;
|
|
69
|
+
}
|
|
43
70
|
/** The `runs` as one: over once every one is, cancelled together, as long as the longest. */
|
|
44
71
|
export const together = (runs) => ({
|
|
45
72
|
finished: Promise.all(runs.map((r) => r.finished)).then(() => undefined),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AnimateContext, type Running } from './animate.js';
|
|
2
|
+
import type { Box } from './stand-in.js';
|
|
3
|
+
/** `flag`: worn by each element while it slides. `scale`: it also grows or shrinks from the old box's size, about its centre. */
|
|
4
|
+
export interface FlipOptions {
|
|
5
|
+
ms: number;
|
|
6
|
+
easing: string;
|
|
7
|
+
flag?: string;
|
|
8
|
+
scale?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Each element in `moved` glides from `was` (viewport coordinates) to the box it is laid out in now; one moved less
|
|
12
|
+
* than half a pixel stays. Reduced motion (`ctx.reduced`, else the player's card-motion switch) plays and writes nothing.
|
|
13
|
+
*/
|
|
14
|
+
export declare function flip(moved: Iterable<readonly [HTMLElement, Box]>, o: FlipOptions, ctx?: AnimateContext): Running;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { animate, STILL, together } from "./animate.js";
|
|
3
|
+
import { prefersReducedMotion } from "./index.js";
|
|
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
|
+
const sliding = new WeakMap();
|
|
6
|
+
/**
|
|
7
|
+
* Each element in `moved` glides from `was` (viewport coordinates) to the box it is laid out in now; one moved less
|
|
8
|
+
* than half a pixel stays. Reduced motion (`ctx.reduced`, else the player's card-motion switch) plays and writes nothing.
|
|
9
|
+
*/
|
|
10
|
+
export function flip(moved, o, ctx = {}) {
|
|
11
|
+
const reduced = ctx.reduced ?? prefersReducedMotion();
|
|
12
|
+
if (reduced)
|
|
13
|
+
return STILL;
|
|
14
|
+
const pairs = [...moved];
|
|
15
|
+
for (const [el] of pairs)
|
|
16
|
+
sliding.get(el)?.cancel();
|
|
17
|
+
const starts = pairs.flatMap(([el, was]) => {
|
|
18
|
+
const now = el.getBoundingClientRect();
|
|
19
|
+
const [dx, dy] = [was.left + was.width / 2 - now.left - now.width / 2, was.top + was.height / 2 - now.top - now.height / 2];
|
|
20
|
+
const s = o.scale === true && now.width > 0 ? was.width / now.width : 1;
|
|
21
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 && Math.abs(s - 1) < 0.01)
|
|
22
|
+
return [];
|
|
23
|
+
return [[el, `translate(${dx}px, ${dy}px)${s === 1 ? '' : ` scale(${s})`}`]];
|
|
24
|
+
});
|
|
25
|
+
const runs = starts.flatMap(([el, from]) => {
|
|
26
|
+
const run = animate(el, [{ transform: from }, { transform: 'none' }], { duration: o.ms, easing: o.easing }, { ...ctx, reduced });
|
|
27
|
+
if (run === STILL)
|
|
28
|
+
return [];
|
|
29
|
+
sliding.set(el, run);
|
|
30
|
+
if (o.flag !== undefined)
|
|
31
|
+
el.setAttribute(o.flag, '');
|
|
32
|
+
void run.finished.then(() => {
|
|
33
|
+
if (sliding.get(el) !== run)
|
|
34
|
+
return;
|
|
35
|
+
sliding.delete(el);
|
|
36
|
+
if (o.flag !== undefined)
|
|
37
|
+
el.removeAttribute(o.flag);
|
|
38
|
+
});
|
|
39
|
+
return [run];
|
|
40
|
+
});
|
|
41
|
+
return runs.length === 0 ? STILL : together(runs);
|
|
42
|
+
}
|
package/dist/motion/frame.d.ts
CHANGED
|
@@ -9,5 +9,10 @@ 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
|
+
/** `step` on the next frame after `soon()`, read and write in their phases: one frame owed however often asked; asked during the step, the next. */
|
|
13
|
+
export declare function perFrame(step: FrameStep): {
|
|
14
|
+
soon: () => void;
|
|
15
|
+
cancel: () => void;
|
|
16
|
+
};
|
|
12
17
|
/** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
|
|
13
18
|
export declare function resetFrames(): void;
|
package/dist/motion/frame.js
CHANGED
|
@@ -13,6 +13,12 @@ export function nextFrame(write) {
|
|
|
13
13
|
const stop = everyFrame(() => (stop(), write));
|
|
14
14
|
return stop;
|
|
15
15
|
}
|
|
16
|
+
/** `step` on the next frame after `soon()`, read and write in their phases: one frame owed however often asked; asked during the step, the next. */
|
|
17
|
+
export function perFrame(step) {
|
|
18
|
+
let owed = null;
|
|
19
|
+
const cancel = () => void (owed?.(), (owed = null));
|
|
20
|
+
return { soon: () => void (owed ??= everyFrame((now) => (cancel(), step(now)))), cancel };
|
|
21
|
+
}
|
|
16
22
|
/** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
|
|
17
23
|
export function resetFrames() {
|
|
18
24
|
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.219",
|
|
4
|
+
"gitHead": "5fc2457da600b68050cd490e151fa006e7c1f23e",
|
|
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.219",
|
|
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"
|