@grundyjs/algiviz 0.8.2 → 0.9.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.
@@ -5,6 +5,9 @@ export interface Player<S, E> {
5
5
  readonly finished: boolean;
6
6
  /** Advance by playback time; pass zero to redraw without consuming steps. */
7
7
  advance(deltaMs: number): Frame<S, E>;
8
+ /** Finish the current transition, or consume one next step at a boundary.
9
+ * At the terminal boundary, finish the hold. Renders once, even if finished. */
10
+ nextStep(): Frame<S, E>;
8
11
  /** Close the source early. The last frame remains readable. */
9
12
  dispose(): void;
10
13
  }
@@ -13,6 +16,6 @@ export declare function createPlayer<S, E>(steps: Iterable<Step<S, E>>, options:
13
16
  stepDurationMs: number;
14
17
  finalHoldMs: number;
15
18
  isTerminal: (step: Step<S, E>) => boolean;
16
- /** Called initially and on each advance, including advance(0). */
19
+ /** Called initially and on each advance or nextStep, including after completion. */
17
20
  render?: (frame: Frame<S, E>) => void;
18
21
  }): Player<S, E>;
@@ -59,6 +59,38 @@ export function createPlayer(steps, options) {
59
59
  return Object.freeze({
60
60
  get frame() { return frame(); },
61
61
  get finished() { return finished; },
62
+ nextStep() {
63
+ if (disposed)
64
+ throw new Error("Player has been disposed");
65
+ try {
66
+ if (!finished) {
67
+ if (elapsed === stepDurationMs) {
68
+ if (options.isTerminal(current)) {
69
+ hold = finalHoldMs;
70
+ }
71
+ else {
72
+ const next = iterator.next();
73
+ if (next.done)
74
+ throw new RangeError("Step source ended without a terminal step");
75
+ previous = current;
76
+ current = next.value;
77
+ }
78
+ }
79
+ // Assign the endpoint directly: time arithmetic can undershoot or
80
+ // spill a rounding remainder into an unwanted additional step.
81
+ elapsed = stepDurationMs;
82
+ complete();
83
+ }
84
+ const result = frame();
85
+ options.render?.(result);
86
+ return result;
87
+ }
88
+ catch (error) {
89
+ disposed = true;
90
+ closeAfterFailure();
91
+ throw error;
92
+ }
93
+ },
62
94
  advance(deltaMs) {
63
95
  if (disposed)
64
96
  throw new Error("Player has been disposed");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grundyjs/algiviz",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "TypeScript toolkit for custom algorithm visualizations with step-by-step playback and extensible rendering",
5
5
  "type": "module",
6
6
  "files": [