@holtjs/stage 0.3.0 → 0.4.0

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/kernel.js ADDED
@@ -0,0 +1,639 @@
1
+ import { buildSceneDigest, sanitizeTrackToken } from "./trace.js";
2
+ import { Easings } from "./tween.js";
3
+ // src/kernel.ts
4
+ /** Godot-inspired semantic action map binding logical game verbs (`'jump'`, `'interact'`) to key codes. */
5
+ var ActionMap = class {
6
+ bindings = /* @__PURE__ */ new Map();
7
+ game;
8
+ constructor(game) {
9
+ this.game = game;
10
+ }
11
+ bind(action, codes) {
12
+ this.bindings.set(action, [...codes]);
13
+ return this;
14
+ }
15
+ unbind(action) {
16
+ this.bindings.delete(action);
17
+ return this;
18
+ }
19
+ codesFor(action) {
20
+ return this.bindings.get(action) ?? [];
21
+ }
22
+ isDown(action) {
23
+ const kb = this.game.input?.keyboard;
24
+ if (!kb) return false;
25
+ const codes = this.bindings.get(action);
26
+ if (!codes) return false;
27
+ for (let i = 0; i < codes.length; i++) if (kb.isDown(codes[i])) return true;
28
+ return false;
29
+ }
30
+ justPressed(action) {
31
+ const kb = this.game.input?.keyboard;
32
+ if (!kb) return false;
33
+ const codes = this.bindings.get(action);
34
+ if (!codes) return false;
35
+ for (let i = 0; i < codes.length; i++) if (kb.justPressed(codes[i])) return true;
36
+ return false;
37
+ }
38
+ justReleased(action) {
39
+ const kb = this.game.input?.keyboard;
40
+ if (!kb) return false;
41
+ const codes = this.bindings.get(action);
42
+ if (!codes) return false;
43
+ for (let i = 0; i < codes.length; i++) if (kb.justReleased(codes[i])) return true;
44
+ return false;
45
+ }
46
+ /** Compute signed `[-1, 0, +1]` axis from negative/positive action names or key codes. */
47
+ axis(negativeActionOrCode, positiveActionOrCode) {
48
+ const neg = this.bindings.has(negativeActionOrCode) ? this.isDown(negativeActionOrCode) : Boolean(this.game.input?.keyboard?.isDown(negativeActionOrCode));
49
+ return ((this.bindings.has(positiveActionOrCode) ? this.isDown(positiveActionOrCode) : Boolean(this.game.input?.keyboard?.isDown(positiveActionOrCode))) ? 1 : 0) - (neg ? 1 : 0);
50
+ }
51
+ };
52
+ var StageKernel = class {
53
+ game;
54
+ actions;
55
+ plugins = /* @__PURE__ */ new Map();
56
+ pluginOrder = [];
57
+ providers = /* @__PURE__ */ new Map();
58
+ providerOrder = [];
59
+ inputListeners = [];
60
+ inputGuard = null;
61
+ disposed = false;
62
+ constructor(game) {
63
+ this.game = game;
64
+ this.actions = new ActionMap(game);
65
+ }
66
+ /** Optional input barrier predicate (e.g. `() => !surfaces.isWorldBlocked()`). */
67
+ setInputGuard(guard) {
68
+ this.inputGuard = guard;
69
+ return this;
70
+ }
71
+ /** Subscribe to every normalized `StageInputEvent` flowing through the kernel (used by recorders/mods). */
72
+ onInput(listener) {
73
+ this.inputListeners.push(listener);
74
+ return () => {
75
+ const idx = this.inputListeners.indexOf(listener);
76
+ if (idx >= 0) this.inputListeners.splice(idx, 1);
77
+ };
78
+ }
79
+ /** Mount a `StagePlugin` (idempotent per `plugin.id`; LIFO-disposed on `remove` or `game.destroy()`). */
80
+ use(plugin) {
81
+ if (this.disposed) return plugin;
82
+ if (this.plugins.has(plugin.id)) this.removePlugin(plugin.id);
83
+ let teardown = null;
84
+ if (typeof plugin.setup === "function") {
85
+ const res = plugin.setup(this);
86
+ if (typeof res === "function") teardown = res;
87
+ }
88
+ const entry = {
89
+ plugin,
90
+ teardown
91
+ };
92
+ this.plugins.set(plugin.id, entry);
93
+ this.pluginOrder.push(entry);
94
+ return plugin;
95
+ }
96
+ getPlugin(id) {
97
+ return this.plugins.get(id)?.plugin ?? null;
98
+ }
99
+ removePlugin(id) {
100
+ const entry = this.plugins.get(id);
101
+ if (!entry) return false;
102
+ this.plugins.delete(id);
103
+ const idx = this.pluginOrder.indexOf(entry);
104
+ if (idx >= 0) this.pluginOrder.splice(idx, 1);
105
+ try {
106
+ entry.teardown?.();
107
+ } catch {}
108
+ try {
109
+ entry.plugin.dispose?.();
110
+ } catch {}
111
+ return true;
112
+ }
113
+ /** Register an `InputProvider` (DOM, headless timeline, replay, or Mod controller). */
114
+ addInputProvider(provider) {
115
+ if (this.disposed) return provider;
116
+ if (this.providers.has(provider.id)) this.removeInputProvider(provider.id);
117
+ let teardown = null;
118
+ if (typeof provider.attach === "function") {
119
+ const res = provider.attach(this);
120
+ if (typeof res === "function") teardown = res;
121
+ }
122
+ const entry = {
123
+ provider,
124
+ teardown
125
+ };
126
+ this.providers.set(provider.id, entry);
127
+ this.providerOrder.push(entry);
128
+ return provider;
129
+ }
130
+ removeInputProvider(id) {
131
+ const entry = this.providers.get(id);
132
+ if (!entry) return false;
133
+ this.providers.delete(id);
134
+ const idx = this.providerOrder.indexOf(entry);
135
+ if (idx >= 0) this.providerOrder.splice(idx, 1);
136
+ try {
137
+ entry.teardown?.();
138
+ } catch {}
139
+ try {
140
+ entry.provider.dispose?.();
141
+ } catch {}
142
+ return true;
143
+ }
144
+ /** Dispatch a normalized input event into `Game.input` + `KeyboardPlugin` and notify listeners. */
145
+ dispatchInput(event) {
146
+ if (this.disposed || !this.game.input?.enabled) return false;
147
+ if (this.inputGuard && !this.inputGuard(event)) return false;
148
+ const frameSeq = this.game.clock.frameSeq;
149
+ const simTimeMs = this.game.clock.simTimeMs;
150
+ for (let i = 0; i < this.inputListeners.length; i++) this.inputListeners[i](event, frameSeq, simTimeMs);
151
+ const input = this.game.input;
152
+ const cam = this.game.scene.getPrimaryCamera();
153
+ switch (event.kind) {
154
+ case "pointerdown":
155
+ case "pointermove":
156
+ case "pointerup": {
157
+ const p = input.activePointer;
158
+ p.x = event.x;
159
+ p.y = event.y;
160
+ if (event.kind === "pointerdown") {
161
+ p.isDown = true;
162
+ p.button = event.button ?? 0;
163
+ p.buttons = 1;
164
+ } else if (event.kind === "pointerup") {
165
+ p.isDown = false;
166
+ p.button = event.button ?? 0;
167
+ p.buttons = 0;
168
+ }
169
+ p.updateWorldPoint(cam);
170
+ input.emit(event.kind, p);
171
+ return true;
172
+ }
173
+ case "wheel": {
174
+ const p = input.activePointer;
175
+ p.x = event.x;
176
+ p.y = event.y;
177
+ p.deltaX = event.deltaX;
178
+ p.deltaY = event.deltaY;
179
+ p.deltaZ = event.deltaZ ?? 0;
180
+ p.updateWorldPoint(cam);
181
+ input.emit("wheel", p, [], p.deltaX, p.deltaY, p.deltaZ);
182
+ return true;
183
+ }
184
+ case "keydown":
185
+ case "keyup":
186
+ input.keyboard?.injectKey(event.kind, event.code, event.key);
187
+ return true;
188
+ }
189
+ }
190
+ /** Internal per-tick prestep invoked by `Game.step()` / `Game.stepSimOnly()`. */
191
+ _prestep(timeMs, deltaMs) {
192
+ const simTimeMs = this.game.clock.simTimeMs;
193
+ for (let i = 0; i < this.providerOrder.length; i++) this.providerOrder[i].provider.poll?.(this, simTimeMs, deltaMs);
194
+ for (let i = 0; i < this.pluginOrder.length; i++) this.pluginOrder[i].plugin.prestep?.(timeMs, deltaMs);
195
+ }
196
+ /** Internal per-scene update hook invoked by `Game.step()` / `Game.stepSimOnly()`. */
197
+ _updateScene(scene, timeMs, deltaMs) {
198
+ for (let i = 0; i < this.pluginOrder.length; i++) this.pluginOrder[i].plugin.update?.(scene, timeMs, deltaMs);
199
+ }
200
+ /** Internal postrender hook invoked by `Game.step()`. */
201
+ _postrender(renderer) {
202
+ for (let i = 0; i < this.pluginOrder.length; i++) this.pluginOrder[i].plugin.postrender?.(renderer);
203
+ }
204
+ /** Collect sanitized plugin digests for `buildSceneDigest()`. */
205
+ collectPluginDigests() {
206
+ if (this.pluginOrder.length === 0) return null;
207
+ let out = null;
208
+ for (let i = 0; i < this.pluginOrder.length; i++) {
209
+ const p = this.pluginOrder[i].plugin;
210
+ if (typeof p.digest !== "function") continue;
211
+ const safeId = sanitizeTrackToken(p.id);
212
+ if (!safeId) continue;
213
+ const raw = p.digest();
214
+ if (!raw || typeof raw !== "object") continue;
215
+ const clean = {};
216
+ for (const [k, v] of Object.entries(raw)) {
217
+ const sk = sanitizeTrackToken(k, 32);
218
+ if (!sk) continue;
219
+ if (v === null || typeof v === "boolean") clean[sk] = v;
220
+ else if (typeof v === "number" && Number.isFinite(v)) clean[sk] = +v.toFixed(3);
221
+ else if (typeof v === "string") clean[sk] = sanitizeTrackToken(v, 48);
222
+ }
223
+ if (!out) out = {};
224
+ out[safeId] = clean;
225
+ }
226
+ return out;
227
+ }
228
+ /** LIFO teardown of all mounted input providers and plugins. */
229
+ dispose() {
230
+ if (this.disposed) return;
231
+ this.disposed = true;
232
+ for (let i = this.providerOrder.length - 1; i >= 0; i--) {
233
+ const e = this.providerOrder[i];
234
+ try {
235
+ e.teardown?.();
236
+ } catch {}
237
+ try {
238
+ e.provider.dispose?.();
239
+ } catch {}
240
+ }
241
+ this.providerOrder.length = 0;
242
+ this.providers.clear();
243
+ for (let i = this.pluginOrder.length - 1; i >= 0; i--) {
244
+ const e = this.pluginOrder[i];
245
+ try {
246
+ e.teardown?.();
247
+ } catch {}
248
+ try {
249
+ e.plugin.dispose?.();
250
+ } catch {}
251
+ }
252
+ this.pluginOrder.length = 0;
253
+ this.plugins.clear();
254
+ this.inputListeners.length = 0;
255
+ }
256
+ };
257
+ /**
258
+ * Programmable input choreography plugin & `InputProvider` for AI agents, automated gameplay tests,
259
+ * and 60 FPS product demo videos. Supports clicking directly by `trackId` (`timeline.click('shop.buy', { atMs: 400 })`)
260
+ * via `buildSceneDigest()` as well as coordinates, drags, key holds, typing, and optional visual cursor ripples!
261
+ */
262
+ function createInputTimeline(options = {}) {
263
+ const id = options.id ?? "stage.input-timeline";
264
+ const actions = [];
265
+ const cursor = {
266
+ x: options.initialX ?? 64,
267
+ y: options.initialY ?? 64,
268
+ isDown: false
269
+ };
270
+ const ripples = [];
271
+ let overlayGfx = null;
272
+ let overlayScene = null;
273
+ let firedClicks = 0;
274
+ let firedKeys = 0;
275
+ const resolveTarget = (kernel, spec) => {
276
+ if (typeof spec !== "string") return {
277
+ x: spec.x,
278
+ y: spec.y
279
+ };
280
+ const sc = kernel.game.scene.scenes[0];
281
+ if (!sc) return {
282
+ x: cursor.x,
283
+ y: cursor.y
284
+ };
285
+ const dg = buildSceneDigest(sc, options.digestOptions);
286
+ for (let i = 0; i < dg.nodes.length; i++) {
287
+ const n = dg.nodes[i];
288
+ if (n.trackId === spec) {
289
+ const [bx, by, bw, bh] = n.bounds;
290
+ return {
291
+ x: bx + bw * .5,
292
+ y: by + bh * .5
293
+ };
294
+ }
295
+ }
296
+ return {
297
+ x: cursor.x,
298
+ y: cursor.y
299
+ };
300
+ };
301
+ const plugin = {
302
+ id,
303
+ cursor,
304
+ setup(kernel) {
305
+ kernel.addInputProvider(plugin);
306
+ return () => {
307
+ kernel.removeInputProvider(id);
308
+ };
309
+ },
310
+ poll(kernel, simTimeMs, deltaMs) {
311
+ for (let i = 0; i < actions.length; i++) {
312
+ const act = actions[i];
313
+ if (act.finished || simTimeMs < act.startMs) continue;
314
+ if (act.kind === "move") {
315
+ if (!act.started) {
316
+ act.started = true;
317
+ const fromPt = act.fromTarget ? resolveTarget(kernel, act.fromTarget) : {
318
+ x: cursor.x,
319
+ y: cursor.y
320
+ };
321
+ const toPt = act.target ? resolveTarget(kernel, act.target) : fromPt;
322
+ act.resolvedFromX = fromPt.x;
323
+ act.resolvedFromY = fromPt.y;
324
+ act.resolvedToX = toPt.x;
325
+ act.resolvedToY = toPt.y;
326
+ }
327
+ const dur = Math.max(1, act.endMs - act.startMs);
328
+ const rawT = Math.min(1, (simTimeMs - act.startMs) / dur);
329
+ const e = Easings.inOutCubic(rawT);
330
+ cursor.x = act.resolvedFromX + (act.resolvedToX - act.resolvedFromX) * e;
331
+ cursor.y = act.resolvedFromY + (act.resolvedToY - act.resolvedFromY) * e;
332
+ kernel.dispatchInput({
333
+ kind: "pointermove",
334
+ x: cursor.x,
335
+ y: cursor.y,
336
+ source: id
337
+ });
338
+ if (rawT >= 1) act.finished = true;
339
+ } else if (act.kind === "down") {
340
+ act.started = true;
341
+ act.finished = true;
342
+ if (act.target) {
343
+ const pt = resolveTarget(kernel, act.target);
344
+ cursor.x = pt.x;
345
+ cursor.y = pt.y;
346
+ }
347
+ cursor.isDown = true;
348
+ firedClicks++;
349
+ ripples.push({
350
+ x: cursor.x,
351
+ y: cursor.y,
352
+ ageMs: 0
353
+ });
354
+ options.onCue?.(simTimeMs, "click", typeof act.target === "string" ? act.target : `${Math.round(cursor.x)},${Math.round(cursor.y)}`);
355
+ kernel.dispatchInput({
356
+ kind: "pointerdown",
357
+ x: cursor.x,
358
+ y: cursor.y,
359
+ button: act.button ?? 0,
360
+ source: id
361
+ });
362
+ } else if (act.kind === "up") {
363
+ act.started = true;
364
+ act.finished = true;
365
+ cursor.isDown = false;
366
+ kernel.dispatchInput({
367
+ kind: "pointerup",
368
+ x: cursor.x,
369
+ y: cursor.y,
370
+ button: act.button ?? 0,
371
+ source: id
372
+ });
373
+ } else if (act.kind === "key") {
374
+ if (!act.started) {
375
+ act.started = true;
376
+ firedKeys++;
377
+ options.onCue?.(simTimeMs, "key", act.code ?? "");
378
+ kernel.dispatchInput({
379
+ kind: "keydown",
380
+ code: act.code ?? "",
381
+ key: act.key,
382
+ source: id
383
+ });
384
+ }
385
+ if (simTimeMs >= act.endMs) {
386
+ act.finished = true;
387
+ kernel.dispatchInput({
388
+ kind: "keyup",
389
+ code: act.code ?? "",
390
+ key: act.key,
391
+ source: id
392
+ });
393
+ }
394
+ }
395
+ }
396
+ for (let i = ripples.length - 1; i >= 0; i--) {
397
+ ripples[i].ageMs += deltaMs;
398
+ if (ripples[i].ageMs > 380) ripples.splice(i, 1);
399
+ }
400
+ },
401
+ update(scene) {
402
+ if (!options.showCursor) return;
403
+ if (!overlayGfx || overlayScene !== scene || !overlayGfx.active) {
404
+ overlayScene = scene;
405
+ overlayGfx = scene.add.graphics();
406
+ overlayGfx.setDepth(1e9);
407
+ overlayGfx.setScrollFactor(0, 0);
408
+ overlayGfx.trackId = "stage.virtual-cursor";
409
+ overlayGfx.role = "presentation";
410
+ }
411
+ const g = overlayGfx;
412
+ g.clear();
413
+ for (let i = 0; i < ripples.length; i++) {
414
+ const rp = ripples[i];
415
+ const p = Math.min(1, rp.ageMs / 380);
416
+ g.lineStyle(2.5, 0xb6ef48, 1 - p);
417
+ g.strokeCircle(rp.x, rp.y, 8 + p * 26);
418
+ }
419
+ const r = cursor.isDown ? 6 : 8;
420
+ g.fillStyle(1513761, .9);
421
+ g.fillCircle(cursor.x, cursor.y, r + 2.5);
422
+ g.fillStyle(cursor.isDown ? 0xfde047 : 0xb6ef48, 1);
423
+ g.fillCircle(cursor.x, cursor.y, r);
424
+ },
425
+ digest() {
426
+ return {
427
+ scheduled: actions.length,
428
+ clicks: firedClicks,
429
+ keys: firedKeys,
430
+ cursorX: Math.round(cursor.x),
431
+ cursorY: Math.round(cursor.y),
432
+ isDown: cursor.isDown
433
+ };
434
+ },
435
+ dispose() {
436
+ overlayGfx?.destroy();
437
+ overlayGfx = null;
438
+ overlayScene = null;
439
+ },
440
+ moveTo(target, moveOpts) {
441
+ const start = Math.max(0, moveOpts.atMs);
442
+ const dur = Math.max(1, moveOpts.durationMs ?? 180);
443
+ actions.push({
444
+ kind: "move",
445
+ startMs: start,
446
+ endMs: start + dur,
447
+ target,
448
+ started: false,
449
+ finished: false,
450
+ resolvedFromX: 0,
451
+ resolvedFromY: 0,
452
+ resolvedToX: 0,
453
+ resolvedToY: 0
454
+ });
455
+ return plugin;
456
+ },
457
+ click(target, clickOpts) {
458
+ const clickAt = Math.max(0, clickOpts.atMs);
459
+ const moveDur = Math.max(0, clickOpts.moveDurationMs ?? 160);
460
+ const holdMs = Math.max(16, clickOpts.holdMs ?? 50);
461
+ if (moveDur > 0) actions.push({
462
+ kind: "move",
463
+ startMs: Math.max(0, clickAt - moveDur),
464
+ endMs: clickAt,
465
+ target,
466
+ started: false,
467
+ finished: false,
468
+ resolvedFromX: 0,
469
+ resolvedFromY: 0,
470
+ resolvedToX: 0,
471
+ resolvedToY: 0
472
+ });
473
+ actions.push({
474
+ kind: "down",
475
+ startMs: clickAt,
476
+ endMs: clickAt,
477
+ target,
478
+ button: clickOpts.button ?? 0,
479
+ started: false,
480
+ finished: false,
481
+ resolvedFromX: 0,
482
+ resolvedFromY: 0,
483
+ resolvedToX: 0,
484
+ resolvedToY: 0
485
+ });
486
+ actions.push({
487
+ kind: "up",
488
+ startMs: clickAt + holdMs,
489
+ endMs: clickAt + holdMs,
490
+ button: clickOpts.button ?? 0,
491
+ started: false,
492
+ finished: false,
493
+ resolvedFromX: 0,
494
+ resolvedFromY: 0,
495
+ resolvedToX: 0,
496
+ resolvedToY: 0
497
+ });
498
+ return plugin;
499
+ },
500
+ drag(dragOpts) {
501
+ const start = Math.max(0, dragOpts.atMs);
502
+ const dur = Math.max(16, dragOpts.durationMs ?? 300);
503
+ actions.push({
504
+ kind: "down",
505
+ startMs: start,
506
+ endMs: start,
507
+ target: dragOpts.from,
508
+ button: dragOpts.button ?? 0,
509
+ started: false,
510
+ finished: false,
511
+ resolvedFromX: 0,
512
+ resolvedFromY: 0,
513
+ resolvedToX: 0,
514
+ resolvedToY: 0
515
+ });
516
+ actions.push({
517
+ kind: "move",
518
+ startMs: start,
519
+ endMs: start + dur,
520
+ fromTarget: dragOpts.from,
521
+ target: dragOpts.to,
522
+ started: false,
523
+ finished: false,
524
+ resolvedFromX: 0,
525
+ resolvedFromY: 0,
526
+ resolvedToX: 0,
527
+ resolvedToY: 0
528
+ });
529
+ actions.push({
530
+ kind: "up",
531
+ startMs: start + dur,
532
+ endMs: start + dur,
533
+ button: dragOpts.button ?? 0,
534
+ started: false,
535
+ finished: false,
536
+ resolvedFromX: 0,
537
+ resolvedFromY: 0,
538
+ resolvedToX: 0,
539
+ resolvedToY: 0
540
+ });
541
+ return plugin;
542
+ },
543
+ pressKey(code, keyOpts) {
544
+ const start = Math.max(0, keyOpts.atMs);
545
+ const dur = Math.max(16, keyOpts.durationMs ?? 80);
546
+ actions.push({
547
+ kind: "key",
548
+ startMs: start,
549
+ endMs: start + dur,
550
+ code,
551
+ key: code,
552
+ started: false,
553
+ finished: false,
554
+ resolvedFromX: 0,
555
+ resolvedFromY: 0,
556
+ resolvedToX: 0,
557
+ resolvedToY: 0
558
+ });
559
+ return plugin;
560
+ },
561
+ typeText(text, typeOpts) {
562
+ const interval = Math.max(16, typeOpts.intervalMs ?? 55);
563
+ for (let i = 0; i < text.length; i++) {
564
+ const ch = text[i];
565
+ const code = ch === " " ? "Space" : ch.length === 1 && /[a-z]/i.test(ch) ? `Key${ch.toUpperCase()}` : ch;
566
+ plugin.pressKey(code, {
567
+ atMs: typeOpts.atMs + i * interval,
568
+ durationMs: Math.min(32, interval * .6)
569
+ });
570
+ }
571
+ return plugin;
572
+ }
573
+ };
574
+ return plugin;
575
+ }
576
+ /** Records frame-stamped `StageInputEvent`s for deterministic headless replay or bug repro bundles. */
577
+ function createInputRecorder(id = "stage.input-recorder") {
578
+ const entries = [];
579
+ let unsub = null;
580
+ return {
581
+ id,
582
+ entries,
583
+ setup(kernel) {
584
+ unsub = kernel.onInput((event, frameSeq, simTimeMs) => {
585
+ entries.push({
586
+ frameSeq,
587
+ simTimeMs: Math.round(simTimeMs),
588
+ event
589
+ });
590
+ });
591
+ return () => {
592
+ unsub?.();
593
+ unsub = null;
594
+ };
595
+ },
596
+ digest() {
597
+ return { recordedEvents: entries.length };
598
+ },
599
+ clear() {
600
+ entries.length = 0;
601
+ },
602
+ toJSON() {
603
+ return entries.slice();
604
+ }
605
+ };
606
+ }
607
+ /** Replays a recorded `RecordedInputEntry[]` log deterministically on matching simulation timestamps. */
608
+ function createInputReplay(log, id = "stage.input-replay") {
609
+ let cursorIdx = 0;
610
+ const sorted = [...log].sort((a, b) => a.simTimeMs - b.simTimeMs || a.frameSeq - b.frameSeq);
611
+ const replay = {
612
+ id,
613
+ setup(kernel) {
614
+ cursorIdx = 0;
615
+ kernel.addInputProvider(replay);
616
+ return () => {
617
+ kernel.removeInputProvider(id);
618
+ };
619
+ },
620
+ poll(kernel, simTimeMs) {
621
+ while (cursorIdx < sorted.length && sorted[cursorIdx].simTimeMs <= simTimeMs + .001) {
622
+ const item = sorted[cursorIdx++];
623
+ if (item.event.source === id) continue;
624
+ kernel.dispatchInput({
625
+ ...item.event,
626
+ source: id
627
+ });
628
+ }
629
+ },
630
+ digest() {
631
+ return {
632
+ total: sorted.length,
633
+ replayed: cursorIdx
634
+ };
635
+ }
636
+ };
637
+ return replay;
638
+ }
639
+ export { ActionMap, StageKernel, createInputRecorder, createInputReplay, createInputTimeline };