@waveform-playlist/browser 5.0.0-alpha.9 → 5.1.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/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { default as default_3 } from 'waveform-data';
4
4
  import { DragEndEvent } from '@dnd-kit/core';
5
5
  import { Fade as Fade_2 } from '@waveform-playlist/core';
6
6
  import { Gain } from 'tone';
7
+ import { MediaElementPlayout } from '@waveform-playlist/media-element-playout';
7
8
  import { MutableRefObject } from 'react';
8
9
  import react__default from 'react';
9
10
  import { ReactNode } from 'react';
@@ -50,7 +51,7 @@ declare interface AnnotationActionOptions {
50
51
  [key: string]: unknown;
51
52
  }
52
53
 
53
- declare interface AnnotationData {
54
+ export declare interface AnnotationData {
54
55
  id: string;
55
56
  start: number;
56
57
  end: number;
@@ -58,6 +59,19 @@ declare interface AnnotationData {
58
59
  language?: string;
59
60
  }
60
61
 
62
+ /**
63
+ * Shared annotation types used across Waveform components
64
+ */
65
+ /**
66
+ * Base annotation data structure
67
+ */
68
+ declare interface AnnotationData_2 {
69
+ id: string;
70
+ start: number;
71
+ end: number;
72
+ lines: string[];
73
+ }
74
+
61
75
  /**
62
76
  * Represents a single audio clip on the timeline
63
77
  *
@@ -410,6 +424,21 @@ export declare const FastForwardButton: default_2.FC<{
410
424
  className?: string;
411
425
  }>;
412
426
 
427
+ /**
428
+ * Custom function to generate the label shown on annotation boxes in the waveform.
429
+ * Receives the annotation data and its index in the list, returns a string label.
430
+ * Default behavior: displays annotation.id
431
+ *
432
+ * @example
433
+ * // Show sequence numbers
434
+ * getAnnotationBoxLabel={(annotation, index) => String(index + 1)}
435
+ *
436
+ * @example
437
+ * // Show formatted time
438
+ * getAnnotationBoxLabel={(annotation) => formatTime(annotation.start)}
439
+ */
440
+ export declare type GetAnnotationBoxLabelFn = (annotation: AnnotationData_2, index: number) => string;
441
+
413
442
  export declare const getEffectDefinition: (id: string) => EffectDefinition | undefined;
414
443
 
415
444
  export declare const getEffectsByCategory: (category: EffectDefinition["category"]) => EffectDefinition[];
@@ -530,12 +559,165 @@ export declare interface MasterVolumeControls {
530
559
  setMasterVolume: (volume: number) => void;
531
560
  }
532
561
 
562
+ export declare interface MediaElementAnimationContextValue {
563
+ isPlaying: boolean;
564
+ currentTime: number;
565
+ currentTimeRef: default_2.RefObject<number>;
566
+ }
567
+
568
+ export declare interface MediaElementControlsContextValue {
569
+ play: (startTime?: number) => void;
570
+ pause: () => void;
571
+ stop: () => void;
572
+ seekTo: (time: number) => void;
573
+ setPlaybackRate: (rate: number) => void;
574
+ setContinuousPlay: (enabled: boolean) => void;
575
+ setAnnotations: (annotations: AnnotationData[]) => void;
576
+ setActiveAnnotationId: (id: string | null) => void;
577
+ setAutomaticScroll: (enabled: boolean) => void;
578
+ setScrollContainer: (element: HTMLDivElement | null) => void;
579
+ scrollContainerRef: default_2.RefObject<HTMLDivElement | null>;
580
+ }
581
+
582
+ export declare interface MediaElementDataContextValue {
583
+ duration: number;
584
+ peaksDataArray: TrackClipPeaks[];
585
+ sampleRate: number;
586
+ waveHeight: number;
587
+ timeScaleHeight: number;
588
+ samplesPerPixel: number;
589
+ playoutRef: default_2.RefObject<MediaElementPlayout | null>;
590
+ controls: {
591
+ show: boolean;
592
+ width: number;
593
+ };
594
+ barWidth: number;
595
+ barGap: number;
596
+ progressBarWidth: number;
597
+ }
598
+
599
+ /**
600
+ * MediaElementPlaylistProvider
601
+ *
602
+ * A simplified playlist provider for single-track playback using HTMLAudioElement.
603
+ * Key features:
604
+ * - Pitch-preserving playback rate (0.5x - 2.0x)
605
+ * - Pre-computed peaks visualization (no AudioBuffer needed)
606
+ * - Simpler API than full WaveformPlaylistProvider
607
+ *
608
+ * Use this for:
609
+ * - Language learning apps (speed control)
610
+ * - Podcast players
611
+ * - Single-track audio viewers
612
+ *
613
+ * For multi-track editing, use WaveformPlaylistProvider instead.
614
+ */
615
+ export declare const MediaElementPlaylistProvider: default_2.FC<MediaElementPlaylistProviderProps>;
616
+
617
+ declare interface MediaElementPlaylistProviderProps {
618
+ /** Single track configuration with source URL and waveform data */
619
+ track: MediaElementTrackConfig;
620
+ /** Initial samples per pixel (zoom level) */
621
+ samplesPerPixel?: number;
622
+ /** Height of each waveform track */
623
+ waveHeight?: number;
624
+ /** Show timescale */
625
+ timescale?: boolean;
626
+ /** Initial playback rate (0.5 to 2.0) */
627
+ playbackRate?: number;
628
+ /** Enable automatic scroll to keep playhead centered */
629
+ automaticScroll?: boolean;
630
+ /** Theme configuration */
631
+ theme?: Partial<WaveformPlaylistTheme>;
632
+ /** Track controls configuration */
633
+ controls?: {
634
+ show: boolean;
635
+ width: number;
636
+ };
637
+ /** Annotations */
638
+ annotationList?: {
639
+ annotations?: any[];
640
+ isContinuousPlay?: boolean;
641
+ };
642
+ /** Width of waveform bars */
643
+ barWidth?: number;
644
+ /** Gap between waveform bars */
645
+ barGap?: number;
646
+ /** Width of progress bars */
647
+ progressBarWidth?: number;
648
+ /** Callback when audio is ready */
649
+ onReady?: () => void;
650
+ children: ReactNode;
651
+ }
652
+
653
+ export declare interface MediaElementStateContextValue {
654
+ continuousPlay: boolean;
655
+ annotations: AnnotationData[];
656
+ activeAnnotationId: string | null;
657
+ playbackRate: number;
658
+ isAutomaticScroll: boolean;
659
+ }
660
+
661
+ export declare interface MediaElementTrackConfig {
662
+ /** Audio source URL or Blob URL */
663
+ source: string;
664
+ /** Pre-computed waveform data (required for visualization) */
665
+ waveformData: WaveformDataObject;
666
+ /** Track name for display */
667
+ name?: string;
668
+ }
669
+
670
+ /**
671
+ * Simplified Waveform component for MediaElementPlaylistProvider
672
+ *
673
+ * This is a stripped-down version of Waveform that works with the
674
+ * MediaElement context. It supports:
675
+ * - Single track visualization
676
+ * - Click to seek
677
+ * - Annotation display and click-to-play
678
+ * - Playhead animation
679
+ *
680
+ * For multi-track editing, use the full Waveform with WaveformPlaylistProvider.
681
+ */
682
+ export declare const MediaElementWaveform: default_2.FC<MediaElementWaveformProps>;
683
+
684
+ export declare interface MediaElementWaveformProps {
685
+ /** Height in pixels for the annotation text list */
686
+ annotationTextHeight?: number;
687
+ /** Custom function to generate the label shown on annotation boxes */
688
+ getAnnotationBoxLabel?: GetAnnotationBoxLabelFn;
689
+ /**
690
+ * Custom render function for annotation items in the text list.
691
+ * When provided, completely replaces the default annotation item rendering.
692
+ * Use this to customize the appearance of each annotation (e.g., add furigana).
693
+ */
694
+ renderAnnotationItem?: (props: RenderAnnotationItemProps) => default_2.ReactNode;
695
+ /** Whether annotation boundaries can be edited by dragging. Defaults to false. */
696
+ editable?: boolean;
697
+ /**
698
+ * Callback when annotations are updated (e.g., boundaries dragged).
699
+ * Called with the full updated annotations array.
700
+ */
701
+ onAnnotationUpdate?: OnAnnotationUpdateFn;
702
+ /** Where to position the active annotation when auto-scrolling: 'center', 'start', 'end', or 'nearest'. Defaults to 'center'. */
703
+ scrollActivePosition?: ScrollLogicalPosition;
704
+ /** Which scrollable containers to scroll: 'nearest' (only the annotation list) or 'all' (including viewport). Defaults to 'nearest'. */
705
+ scrollActiveContainer?: 'nearest' | 'all';
706
+ className?: string;
707
+ }
708
+
533
709
  declare interface MicrophoneDevice {
534
710
  deviceId: string;
535
711
  label: string;
536
712
  groupId: string;
537
713
  }
538
714
 
715
+ /**
716
+ * Callback when annotations are updated (e.g., boundaries dragged).
717
+ * Called with the full updated annotations array.
718
+ */
719
+ export declare type OnAnnotationUpdateFn = (annotations: AnnotationData_2[]) => void;
720
+
539
721
  /**
540
722
  * Effect definitions for all available Tone.js effects
541
723
  * Each effect has parameters with min/max/default values for UI controls
@@ -656,6 +838,8 @@ declare interface PlaylistDataContextValue {
656
838
  barGap: number;
657
839
  /** Width in pixels of progress bars. Defaults to barWidth + barGap (fills gaps). */
658
840
  progressBarWidth: number;
841
+ /** Whether the playlist has finished loading all tracks */
842
+ isReady: boolean;
659
843
  }
660
844
 
661
845
  declare interface PlaylistStateContextValue {
@@ -673,6 +857,17 @@ declare interface PlaylistStateContextValue {
673
857
  loopEnd: number;
674
858
  }
675
859
 
860
+ /**
861
+ * Props passed to the renderAnnotationItem function for custom rendering
862
+ */
863
+ export declare interface RenderAnnotationItemProps {
864
+ annotation: AnnotationData;
865
+ index: number;
866
+ isActive: boolean;
867
+ onClick: () => void;
868
+ formatTime: (seconds: number) => string;
869
+ }
870
+
676
871
  /**
677
872
  * Type for custom playhead render functions.
678
873
  * Receives position, color, and animation refs for smooth 60fps animation.
@@ -1303,6 +1498,14 @@ declare interface UseMasterVolumeProps {
1303
1498
  onVolumeChange?: (volume: number) => void;
1304
1499
  }
1305
1500
 
1501
+ export declare const useMediaElementAnimation: () => MediaElementAnimationContextValue;
1502
+
1503
+ export declare const useMediaElementControls: () => MediaElementControlsContextValue;
1504
+
1505
+ export declare const useMediaElementData: () => MediaElementDataContextValue;
1506
+
1507
+ export declare const useMediaElementState: () => MediaElementStateContextValue;
1508
+
1306
1509
  export declare const usePlaybackAnimation: () => PlaybackAnimationContextValue;
1307
1510
 
1308
1511
  /**
@@ -1653,6 +1856,21 @@ export declare interface WaveformProps {
1653
1856
  annotationControls?: AnnotationAction[];
1654
1857
  annotationListConfig?: AnnotationActionOptions;
1655
1858
  annotationTextHeight?: number;
1859
+ /**
1860
+ * Custom render function for annotation items in the text list.
1861
+ * Use this to completely customize how each annotation is displayed.
1862
+ */
1863
+ renderAnnotationItem?: (props: RenderAnnotationItemProps) => ReactNode;
1864
+ /**
1865
+ * Custom function to generate the label shown on annotation boxes in the waveform.
1866
+ * Receives the annotation data and its index, returns a string label.
1867
+ * Default: annotation.id
1868
+ */
1869
+ getAnnotationBoxLabel?: GetAnnotationBoxLabelFn;
1870
+ /** Where to position the active annotation when auto-scrolling: 'center', 'start', 'end', or 'nearest'. Defaults to 'center'. */
1871
+ scrollActivePosition?: ScrollLogicalPosition;
1872
+ /** Which scrollable containers to scroll: 'nearest' (only the annotation list) or 'all' (including viewport). Defaults to 'nearest'. */
1873
+ scrollActiveContainer?: 'nearest' | 'all';
1656
1874
  className?: string;
1657
1875
  showClipHeaders?: boolean;
1658
1876
  interactiveClips?: boolean;