@markgrafhq/markgraf-react 0.0.27 → 0.0.28

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.
@@ -3,6 +3,51 @@
3
3
 
4
4
  import type { FC, MutableRefObject } from "react";
5
5
 
6
+ export type MarkgrafCueKind = "step" | "tokenLine";
7
+ export type MarkgrafPlaybackDirection = "auto" | "forward" | "backward";
8
+
9
+ export interface MarkgrafPlaybackOptions {
10
+ direction?: MarkgrafPlaybackDirection;
11
+ speed?: number;
12
+ duration?: number;
13
+ loop?: boolean;
14
+ stopAt?: MarkgrafCueKind[];
15
+ }
16
+
17
+ export interface MarkgrafCueBase {
18
+ readonly id: string;
19
+ readonly index: number;
20
+ readonly kind: MarkgrafCueKind;
21
+ readonly time: number;
22
+ readonly endTime: number;
23
+ readonly path: readonly string[];
24
+ }
25
+
26
+ export interface MarkgrafStepCue extends MarkgrafCueBase {
27
+ readonly kind: "step";
28
+ readonly name: string;
29
+ }
30
+
31
+ export interface MarkgrafTokenLineCue extends MarkgrafCueBase {
32
+ readonly kind: "tokenLine";
33
+ readonly tokenIndex: number;
34
+ readonly lineIndex: number;
35
+ readonly text: string;
36
+ readonly from: string;
37
+ readonly to: string;
38
+ }
39
+
40
+ export type MarkgrafCue = MarkgrafStepCue | MarkgrafTokenLineCue;
41
+
42
+ export interface MarkgrafCompleteEvent {
43
+ readonly reason: "target" | "boundary" | string;
44
+ readonly direction: "forward" | "backward";
45
+ readonly targetId: string;
46
+ readonly targetStep: string;
47
+ readonly reached: boolean;
48
+ readonly time: number;
49
+ }
50
+
6
51
  /**
7
52
  * Reactive view of a mounted markgraf player. `time`, `keyframe`, and
8
53
  * `playing` update on every animation frame; the imperative methods are
@@ -27,21 +72,25 @@ export interface MarkgrafApi<E extends Element = HTMLCanvasElement> {
27
72
  readonly duration: number;
28
73
  /** `true` once parse + layout + first render have completed. */
29
74
  readonly ready: boolean;
30
- play(): void;
75
+ readonly cues: readonly MarkgrafCue[];
76
+ readonly steps: readonly MarkgrafStepCue[];
77
+ play(options?: MarkgrafPlaybackOptions): void;
78
+ playWith(options?: MarkgrafPlaybackOptions): void;
31
79
  pause(): void;
32
80
  toggle(): void;
33
81
  /** Clamped to `[0, duration]`. Pauses the player. */
34
82
  seek(seconds: number): void;
83
+ seekCue(cueId: string): void;
84
+ seekStep(stepName: string): void;
85
+ playToCue(cueId: string, options?: MarkgrafPlaybackOptions): void;
86
+ playToStep(stepName: string, options?: MarkgrafPlaybackOptions): void;
87
+ playNext(options?: MarkgrafPlaybackOptions): void;
88
+ playPrevious(options?: MarkgrafPlaybackOptions): void;
35
89
  /** `1.0` is normal playback speed. */
36
90
  setSpeed(speed: number): void;
37
- /**
38
- * Register a callback that fires every time the player enters the named
39
- * keyframe. Fires immediately if already in that frame. Returns an
40
- * unsubscribe function.
41
- */
42
- onFrameEnter(frameName: string, callback: () => void): () => void;
43
- /** Seek to the start of the named keyframe. No-op if the frame doesn't exist. */
44
- seekFrame(frameName: string): void;
91
+ onCueEnter(callback: (cue: MarkgrafCue) => void): () => void;
92
+ onStepEnter(stepName: string, callback: (cue: MarkgrafStepCue) => void): () => void;
93
+ onComplete(callback: (event: MarkgrafCompleteEvent) => void): () => void;
45
94
  }
46
95
 
47
96
  export interface UseMarkgrafOptions<R extends "canvas" | "svg" = "canvas"> {