Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { WaveformAudio } from "../../Media/WaveformAudio";
 
/**
 * Parameters representing the current state needed for rendering.
 */
export interface RenderContext {
  scrollLeftPx: number;
  width: number;
  zoom: number;
  samplesPerPx: number;
  dataLength: number;
  /**
   * Callback to notify the parent visualizer that the render is complete and a transferImage may be needed.
   */
  notifyRenderComplete?: () => void;
}
 
/**
 * Interface for decoupled rendering strategies.
 * @template Config - The configuration type specific to the renderer implementation.
 */
export interface Renderer<Config = unknown> {
  /**
   * The renderer's configuration.
   */
  config: Config;
 
  /**
   * Initializes the renderer with audio data and render context.
   * @param context - The current rendering context.
   * @param audio - The WaveformAudio object.
   */
  init(context: RenderContext, audio: WaveformAudio): void;
 
  /**
   * Draws the visualization based on the provided context.
   * @param context - The current rendering context (scroll, zoom, dimensions, etc.).
   */
  draw(context: RenderContext): void;
 
  /**
   * Updates the renderer's configuration.
   * @param config - The new configuration to apply.
   */
  updateConfig(config: Config): void;
 
  /**
   * Cleans up resources used by the renderer.
   */
  destroy(): void;
 
  /**
   * Optional resize handler for renderers
   */
  onResize?(): void;
}