@hadoku/ui-shell 0.1.102 → 0.1.104

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.
@@ -24,6 +24,23 @@ export declare const STILL: Running;
24
24
  export declare const animationsOf: (r: Running) => readonly Animation[];
25
25
  /** `anims` as one {@link Running}: over once every one is, cancelled together. */
26
26
  export declare function runningOf(anims: readonly Animation[]): Running;
27
+ /** A layer's timers: `after` runs `fn` in `ms`, unless `clear` (the layer taken down) came first; after it, none starts. */
28
+ export declare function timerSet(): {
29
+ after: (fn: () => void, ms: number) => void;
30
+ clear: () => void;
31
+ };
32
+ /** A clip and how long it lasts on its own clock (before `ctx.tempo` divides it): what a timeline adds up. */
33
+ export type Timed = Clip & {
34
+ readonly ms: number;
35
+ };
36
+ /** The `runs` as one: over once every one is, cancelled together, as long as the longest. */
37
+ export declare const together: (runs: readonly Running[]) => Running;
38
+ /** `clip` `ms` from now on its clock, at once for none: cancelled before then, it never starts, and is over. */
39
+ export declare function at(ms: number, clip: Timed): Timed;
40
+ /** Nothing, `ms` long: a part a timeline waits for that something else draws. */
41
+ export declare const hold: (ms: number) => Timed;
42
+ /** `fn` as a clip `ms` long: what it sets off plays on its own, and the clip is over once that long is. */
43
+ export declare const moment: (fn: () => void, ms?: number) => Timed;
27
44
  /** `el.animate(frames, options)` at `ctx.tempo`: already over without Web Animations (jsdom) or when `ctx.reduced`; with `ctx.stage`, one of its beats. */
28
45
  export declare function animate(el: Element, frames: Keyframe[] | PropertyIndexedKeyframes, options: KeyframeAnimationOptions, ctx?: AnimateContext): Running;
29
46
  /** The custom property every beat's sheet divides its lengths by. */
@@ -23,6 +23,47 @@ export function runningOf(anims) {
23
23
  ANIMATIONS.set(r, anims);
24
24
  return r;
25
25
  }
26
+ /** A layer's timers: `after` runs `fn` in `ms`, unless `clear` (the layer taken down) came first; after it, none starts. */
27
+ export function timerSet() {
28
+ const due = new Set();
29
+ let open = true;
30
+ return {
31
+ after: (fn, ms) => {
32
+ if (!open)
33
+ return;
34
+ const timer = setTimeout(() => (due.delete(timer), fn()), ms);
35
+ due.add(timer);
36
+ },
37
+ clear: () => {
38
+ open = false;
39
+ due.forEach(clearTimeout);
40
+ },
41
+ };
42
+ }
43
+ /** The `runs` as one: over once every one is, cancelled together, as long as the longest. */
44
+ export const together = (runs) => ({
45
+ finished: Promise.all(runs.map((r) => r.finished)).then(() => undefined),
46
+ cancel: () => runs.forEach((r) => r.cancel()),
47
+ endsInMs: Math.max(0, ...runs.map((r) => r.endsInMs)),
48
+ });
49
+ /** `clip` `ms` from now on its clock, at once for none: cancelled before then, it never starts, and is over. */
50
+ export function at(ms, clip) {
51
+ if (ms <= 0)
52
+ return clip;
53
+ return Object.assign((ctx) => {
54
+ let started = null;
55
+ let stop = () => undefined;
56
+ const finished = new Promise((over) => {
57
+ const timer = setTimeout(() => void (started = clip(ctx)).finished.then(over), ms / ctx.tempo);
58
+ stop = () => (clearTimeout(timer), over());
59
+ });
60
+ return { finished, cancel: () => (started === null ? stop() : started.cancel()), endsInMs: (ms + clip.ms) / ctx.tempo };
61
+ }, { ms: ms + clip.ms });
62
+ }
63
+ /** Nothing, `ms` long: a part a timeline waits for that something else draws. */
64
+ export const hold = (ms) => at(ms, Object.assign(() => STILL, { ms: 0 }));
65
+ /** `fn` as a clip `ms` long: what it sets off plays on its own, and the clip is over once that long is. */
66
+ export const moment = (fn, ms = 0) => Object.assign((ctx) => (fn(), hold(ms)(ctx)), { ms });
26
67
  /** `el.animate(frames, options)` at `ctx.tempo`: already over without Web Animations (jsdom) or when `ctx.reduced`; with `ctx.stage`, one of its beats. */
27
68
  export function animate(el, frames, options, ctx = {}) {
28
69
  if (ctx.reduced === true || typeof el.animate !== 'function')
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * Every per-frame loop on one `requestAnimationFrame`: every loop's read, then every loop's write, so N loops
3
3
  * cost one layout a frame, not N (a board wipe's eleven trails and stand-ins forced 30–60 ms a frame,
4
- * 2026-11-01). `step` is the read and returns the write, or null once over. A loop added mid-frame runs next
5
- * frame; one that throws ends alone, rethrown once the frame is through.
4
+ * 2026-11-01). `step` is the read, given the frame's start time, and returns the write, or null once over. A
5
+ * loop added mid-frame runs next frame; one that throws ends alone, rethrown once the frame is through.
6
6
  */
7
- export type FrameStep = () => (() => void) | null;
7
+ export type FrameStep = (now: number) => (() => void) | null;
8
8
  /** Run `step` every frame, its read with every other loop's reads and its write after them. Returns the stop. */
9
9
  export declare function everyFrame(step: FrameStep): () => void;
10
+ /** `write` once, with the next frame's writes. Returns the cancel. */
11
+ export declare function nextFrame(write: () => void): () => void;
12
+ /** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
13
+ export declare function resetFrames(): void;
@@ -8,13 +8,23 @@ export function everyFrame(step) {
8
8
  loops.delete(step);
9
9
  };
10
10
  }
11
- function run() {
11
+ /** `write` once, with the next frame's writes. Returns the cancel. */
12
+ export function nextFrame(write) {
13
+ const stop = everyFrame(() => (stop(), write));
14
+ return stop;
15
+ }
16
+ /** Test-only: forgets every loop and the frame owed, as when a test leaves fake timers with one still due. */
17
+ export function resetFrames() {
18
+ loops.clear();
19
+ frame = null;
20
+ }
21
+ function run(now) {
12
22
  frame = null;
13
23
  let failed = null;
14
24
  const writes = [];
15
25
  for (const step of [...loops]) {
16
26
  try {
17
- const write = step();
27
+ const write = step(now);
18
28
  if (write === null)
19
29
  loops.delete(step);
20
30
  else
@@ -31,8 +31,8 @@ export declare function clearMotion(root: Element): void;
31
31
  export declare function rememberedMotion(key: string): MotionChoices | null;
32
32
  export declare function rememberMotion(key: string, choices: MotionChoices): void;
33
33
  export { ambientPlayState, gateSelector, motionCss } from './css.js';
34
- export { animate, animationsOf, homeEase, markTempo, quicken, runningOf, STILL, TEMPO_PROPERTY, weightEase, writeDurations, type AnimateContext, type Clip, type MotionContext, type Running } from './animate.js';
35
- export { everyFrame, type FrameStep } from './frame.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 { everyFrame, nextFrame, resetFrames, type FrameStep } from './frame.js';
36
36
  export { claimParticles, PARTICLE_BUDGET, particlePool, particleShare, shared, type ParticlePool } from './particles.js';
37
37
  export { animationName, Stage, type StageHold, type StageOptions, type TrackOptions } from './stage.js';
38
38
  export { afterGlide, rel, standIn, type Box, type StandInOptions } from './stand-in.js';
@@ -86,8 +86,8 @@ export function rememberMotion(key, choices) {
86
86
  }
87
87
  }
88
88
  export { ambientPlayState, gateSelector, motionCss } from "./css.js";
89
- export { animate, animationsOf, homeEase, markTempo, quicken, runningOf, STILL, TEMPO_PROPERTY, weightEase, writeDurations } from "./animate.js";
90
- export { everyFrame } from "./frame.js";
89
+ export { animate, animationsOf, at, hold, homeEase, markTempo, moment, quicken, runningOf, STILL, TEMPO_PROPERTY, timerSet, together, weightEase, writeDurations } from "./animate.js";
90
+ export { everyFrame, nextFrame, resetFrames } from "./frame.js";
91
91
  export { claimParticles, PARTICLE_BUDGET, particlePool, particleShare, shared } from "./particles.js";
92
92
  export { animationName, Stage } from "./stage.js";
93
93
  export { afterGlide, rel, standIn } from "./stand-in.js";
@@ -1,8 +1,7 @@
1
1
  import { type Running } from './animate.js';
2
- /** `unlockAt`: how far through its drawings the stage unlocks (1: once over). `isBeat`: a beat unregistered. */
2
+ /** `unlockAt`: how far through its drawings the stage unlocks (1: once over). */
3
3
  export interface StageOptions {
4
4
  unlockAt?: number;
5
- isBeat?: (a: Animation) => boolean;
6
5
  }
7
6
  /** `root`: where its beats run, each still running there at its time waited for to `unlockAt`. `after`: not unlocked before it settles. */
8
7
  export interface TrackOptions {
@@ -19,25 +18,29 @@ export type StageHold = {
19
18
  export declare function animationName(a: Animation): string;
20
19
  export declare class Stage {
21
20
  readonly unlockAt: number;
22
- private readonly recognised;
23
21
  private readonly drawing;
24
22
  private readonly locked;
25
- private readonly live;
26
23
  private readonly registered;
24
+ /** The elements whose stylesheet animations are beats, each with the names they start with. */
25
+ private readonly css;
27
26
  private readonly roots;
28
27
  private readonly cues;
29
28
  private lastBeatAt;
30
29
  private waiting;
31
30
  constructor(options?: StageOptions);
32
- unlockAfter(ms: number): number;
31
+ /** The stage of the board `el` is on: the nearest element up from it that one is attached to. */
32
+ static of(el: Element | null): Stage | undefined;
33
+ /** What draws inside `el` draws on this stage. Returns the detach. */
34
+ attach(el: Element): () => void;
33
35
  /** `r`'s animations are this stage's beats. Returns `r`. */
34
36
  beat(r: Running): Running;
35
- /** The finite stylesheet animations on `el` and inside it now, as beats: registered, not recognised by name. */
36
- trackCss(el: Element): Running;
37
+ /**
38
+ * The stylesheet animations named `prefix…` on `el` and inside it, whenever they run, are beats: a card's own
39
+ * glint or shimmer inside it is not, nor a transition. Read at each look, so one set off later counts too.
40
+ */
41
+ trackCss(el: Element, prefix: string): void;
37
42
  /** The stage draws `r`: busy until it is over, locked until it is `unlockAt` through its `endsInMs` (an endless one: over). */
38
43
  track(r: Running, o?: TrackOptions): Running;
39
- /** Cancels every beat and drawing still running. */
40
- cancelAll(): void;
41
44
  get drawingCount(): number;
42
45
  held(): StageHold;
43
46
  /** Runs `done` once nothing tracked plays, at once when still. Returns a cancel. */
@@ -49,7 +52,7 @@ export declare class Stage {
49
52
  /** Drawing `seq`'s moment `name`, or null when it had none. */
50
53
  cueAt<T = number>(name: string, seq: number): T | null;
51
54
  isBeat(a: Animation): boolean;
52
- /** The beats still waited on, by name (`beat×2 board-number-rise×1`). */
55
+ /** The beats still waited on, by name (`unnamed×2 board-number-rise×1`: a script animation has none). */
53
56
  waitingOn(): string;
54
57
  /** Settles once every finite beat on `root` and inside it is `through` of the way through, looking again as each comes due (one may start another). */
55
58
  settled(root: Element, through?: number): Promise<void>;
@@ -3,11 +3,12 @@
3
3
  * (`whenStill`: a game's end) and UNLOCKED once each is `unlockAt` through (`whenUnlocked`: a pacer's wait),
4
4
  * the motion playing on to its end. A real-time game asks for neither.
5
5
  *
6
- * Its waits look at its beats: animations registered (`beat`, `trackCss`, `animate()` with a stage) or
7
- * recognised by its `isBeat`; an endless pulse, a banner or a glide is no beat. Cues are moments a drawing
8
- * tells the page about (its first hit, a sound's moment): one per name, keyed by the drawing's number.
6
+ * Its waits look at its beats, the animations registered with it (`beat`, `animate()` with a stage, and the
7
+ * stylesheet animations `trackCss` names); an endless pulse, a banner or a glide is no beat. Cues are moments a
8
+ * drawing tells the page about (its first hit, a sound's moment): one per name, keyed by the drawing's number.
9
+ * A board's stage is attached to its element (`attach`), where what draws on it finds it (`Stage.of`).
9
10
  */
10
- import { animationsOf, runningOf } from "./animate.js";
11
+ import { animationsOf } from "./animate.js";
11
12
  /** An animation's name: its id, a stylesheet animation's keyframes, or the property a transition moves. */
12
13
  export function animationName(a) {
13
14
  const named = a;
@@ -46,38 +47,52 @@ class Holds {
46
47
  return () => void this.waiters.delete(done);
47
48
  }
48
49
  }
50
+ /** Each attached element's stage. */
51
+ const STAGES = new WeakMap();
49
52
  export class Stage {
50
53
  unlockAt;
51
- recognised;
52
54
  drawing = new Holds();
53
55
  locked = new Holds();
54
- live = new Set();
55
56
  registered = new WeakSet();
57
+ /** The elements whose stylesheet animations are beats, each with the names they start with. */
58
+ css = new WeakMap();
56
59
  roots = new Map();
57
60
  cues = new Map();
58
61
  lastBeatAt = null;
59
62
  waiting = [];
60
63
  constructor(options = {}) {
61
64
  this.unlockAt = options.unlockAt ?? 1;
62
- this.recognised = options.isBeat ?? (() => false);
63
65
  }
64
- unlockAfter(ms) {
65
- return Math.round(ms * this.unlockAt);
66
+ /** The stage of the board `el` is on: the nearest element up from it that one is attached to. */
67
+ static of(el) {
68
+ for (let at = el; at !== null; at = at.parentElement) {
69
+ const stage = STAGES.get(at);
70
+ if (stage !== undefined)
71
+ return stage;
72
+ }
73
+ return undefined;
74
+ }
75
+ /** What draws inside `el` draws on this stage. Returns the detach. */
76
+ attach(el) {
77
+ STAGES.set(el, this);
78
+ return () => void (STAGES.get(el) === this && STAGES.delete(el));
66
79
  }
67
80
  /** `r`'s animations are this stage's beats. Returns `r`. */
68
81
  beat(r) {
69
82
  for (const a of animationsOf(r))
70
83
  this.registered.add(a);
71
- if (!this.live.has(r)) {
72
- this.live.add(r);
73
- void r.finished.then(() => this.live.delete(r));
74
- }
75
84
  return r;
76
85
  }
77
- /** The finite stylesheet animations on `el` and inside it now, as beats: registered, not recognised by name. */
78
- trackCss(el) {
79
- const anims = typeof el.getAnimations === 'function' ? el.getAnimations({ subtree: true }) : [];
80
- return this.beat(runningOf(anims.filter((a) => Number(a.effect?.getComputedTiming().endTime ?? 0) !== Infinity)));
86
+ /**
87
+ * The stylesheet animations named `prefix…` on `el` and inside it, whenever they run, are beats: a card's own
88
+ * glint or shimmer inside it is not, nor a transition. Read at each look, so one set off later counts too.
89
+ */
90
+ trackCss(el, prefix) {
91
+ const prefixes = this.css.get(el);
92
+ if (prefixes === undefined)
93
+ this.css.set(el, [prefix]);
94
+ else if (!prefixes.includes(prefix))
95
+ prefixes.push(prefix);
81
96
  }
82
97
  /** The stage draws `r`: busy until it is over, locked until it is `unlockAt` through its `endsInMs` (an endless one: over). */
83
98
  track(r, o = {}) {
@@ -90,16 +105,11 @@ export class Stage {
90
105
  if (!Number.isFinite(r.endsInMs))
91
106
  return;
92
107
  const look = () => (done || o.root === undefined ? at() : void this.settled(o.root, this.unlockAt).then(at));
93
- setTimeout(() => void Promise.resolve(o.after).then(look, look), this.unlockAfter(r.endsInMs));
108
+ setTimeout(() => void Promise.resolve(o.after).then(look, look), Math.round(r.endsInMs * this.unlockAt));
94
109
  });
95
110
  this.locked.add(Promise.race([settled, unlocked]));
96
111
  return r;
97
112
  }
98
- /** Cancels every beat and drawing still running. */
99
- cancelAll() {
100
- for (const r of [...this.live])
101
- r.cancel();
102
- }
103
113
  get drawingCount() {
104
114
  return this.drawing.size();
105
115
  }
@@ -124,9 +134,18 @@ export class Stage {
124
134
  return c !== undefined && c.seq === seq ? c.value : null;
125
135
  }
126
136
  isBeat(a) {
127
- return this.registered.has(a) || this.recognised(a);
137
+ if (this.registered.has(a))
138
+ return true;
139
+ const name = a.animationName;
140
+ if (typeof name !== 'string')
141
+ return false;
142
+ for (let at = a.effect?.target ?? null; at !== null; at = at.parentElement) {
143
+ if (this.css.get(at)?.some((prefix) => name.startsWith(prefix)) === true)
144
+ return true;
145
+ }
146
+ return false;
128
147
  }
129
- /** The beats still waited on, by name (`beat×2 board-number-rise×1`). */
148
+ /** The beats still waited on, by name (`unnamed×2 board-number-rise×1`: a script animation has none). */
130
149
  waitingOn() {
131
150
  const counts = new Map();
132
151
  for (const a of this.waiting)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/ui-shell",
3
- "version": "0.1.102",
4
- "gitHead": "162621d4d3a7a5d4bef7d74046968836705d27e2",
3
+ "version": "0.1.104",
4
+ "gitHead": "23d61b02b042b181d594268a3e6d1f0f39c7d12a",
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 and @wolffm/*.",