@hadoku/ui-shell 0.1.218 → 0.1.220

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.
@@ -30,10 +30,9 @@ export declare function timerSet(): {
30
30
  clear: () => void;
31
31
  };
32
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.
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.
37
36
  */
38
37
  export declare function restartMark(el: Element, attr: string, o: {
39
38
  value?: string;
@@ -43,10 +43,9 @@ export function timerSet() {
43
43
  /** Each element's newest restart of each mark: an older one's end never clears a newer one. */
44
44
  const marks = new WeakMap();
45
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.
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.
50
49
  */
51
50
  export function restartMark(el, attr, o) {
52
51
  const mine = {};
@@ -55,16 +54,13 @@ export function restartMark(el, attr, o) {
55
54
  el.removeAttribute(attr);
56
55
  void el.offsetWidth;
57
56
  el.setAttribute(attr, o.value ?? '');
57
+ const ended = (e) => void (e.animationName === o.onEnd && end());
58
58
  const end = () => {
59
+ el.removeEventListener('animationend', ended);
59
60
  if (own.get(attr) !== mine)
60
61
  return;
61
62
  own.delete(attr);
62
63
  el.removeAttribute(attr);
63
- el.removeEventListener('animationend', ended);
64
- };
65
- const ended = (e) => {
66
- if (e.animationName === o.onEnd)
67
- end();
68
64
  };
69
65
  if (o.onEnd !== undefined)
70
66
  el.addEventListener('animationend', ended);
@@ -1,15 +1,14 @@
1
1
  import { type AnimateContext, type Running } from './animate.js';
2
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. */
3
4
  export interface FlipOptions {
4
5
  ms: number;
5
6
  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
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
8
  scale?: boolean;
10
9
  }
11
10
  /**
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.
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.
14
13
  */
15
14
  export declare function flip(moved: Iterable<readonly [HTMLElement, Box]>, o: FlipOptions, ctx?: AnimateContext): Running;
@@ -1,53 +1,42 @@
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
- */
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. */
6
2
  import { animate, STILL, together } from "./animate.js";
7
3
  import { prefersReducedMotion } from "./index.js";
8
- /** Less than this far, in pixels, is not a move. */
9
- const STILL_PX = 0.5;
10
4
  /** Each element's slide under way: a new one starts from where the element is laid out, not where the old has it. */
11
5
  const sliding = new WeakMap();
12
6
  /**
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.
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.
15
9
  */
16
10
  export function flip(moved, o, ctx = {}) {
17
11
  const reduced = ctx.reduced ?? prefersReducedMotion();
18
12
  if (reduced)
19
13
  return STILL;
20
- const { flag } = o;
21
14
  const pairs = [...moved];
22
15
  for (const [el] of pairs)
23
16
  sliding.get(el)?.cancel();
24
- const starts = pairs.map(([el, was]) => {
17
+ const starts = pairs.flatMap(([el, was]) => {
25
18
  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);
19
+ const [dx, dy] = [was.left + was.width / 2 - now.left - now.width / 2, was.top + was.height / 2 - now.top - now.height / 2];
28
20
  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})`];
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})`}`]];
31
24
  });
32
- const runs = [];
33
- for (const start of starts) {
34
- if (start === null)
35
- continue;
36
- const [el, from] = start;
25
+ const runs = starts.flatMap(([el, from]) => {
37
26
  const run = animate(el, [{ transform: from }, { transform: 'none' }], { duration: o.ms, easing: o.easing }, { ...ctx, reduced });
38
27
  if (run === STILL)
39
- continue;
28
+ return [];
40
29
  sliding.set(el, run);
41
- if (flag !== undefined)
42
- el.setAttribute(flag, '');
30
+ if (o.flag !== undefined)
31
+ el.setAttribute(o.flag, '');
43
32
  void run.finished.then(() => {
44
33
  if (sliding.get(el) !== run)
45
34
  return;
46
35
  sliding.delete(el);
47
- if (flag !== undefined)
48
- el.removeAttribute(flag);
36
+ if (o.flag !== undefined)
37
+ el.removeAttribute(o.flag);
49
38
  });
50
- runs.push(run);
51
- }
39
+ return [run];
40
+ });
52
41
  return runs.length === 0 ? STILL : together(runs);
53
42
  }
@@ -9,10 +9,7 @@ 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
- */
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. */
16
13
  export declare function perFrame(step: FrameStep): {
17
14
  soon: () => void;
18
15
  cancel: () => void;
@@ -13,24 +13,11 @@ 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
- */
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. */
20
17
  export function perFrame(step) {
21
18
  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
- };
19
+ const cancel = () => void (owed?.(), (owed = null));
20
+ return { soon: () => void (owed ??= everyFrame((now) => (cancel(), step(now)))), cancel };
34
21
  }
35
22
  /** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
36
23
  export function resetFrames() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/ui-shell",
3
- "version": "0.1.218",
4
- "gitHead": "dd16a0ec8c9c1406543927f1aacfec66728179e7",
3
+ "version": "0.1.220",
4
+ "gitHead": "b8f1d780b5f44ecdfcfd8bcf07f25b4ce7cdff20",
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.218",
75
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.220",
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"