@waveform-playlist/annotations 13.0.1 → 14.0.0-next.1

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/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # @waveform-playlist/annotations
2
2
 
3
- Time-synchronized text annotations for waveform-playlist — mark up an audio timeline with draggable, editable regions for transcripts, podcast chapters, cue points, or music markers.
3
+ Time-synchronized text annotations for waveform-playlist — mark up an audio timeline with editable regions for transcripts, podcast chapters, cue points, or music markers.
4
4
 
5
- Used with [`@waveform-playlist/browser`](https://www.npmjs.com/package/@waveform-playlist/browser): wrap your playlist in `AnnotationProvider` and pass `annotationList` to `WaveformPlaylistProvider` — `<Waveform />` then renders annotation boxes and text automatically.
5
+ Used with [`@waveform-playlist/browser`](https://www.npmjs.com/package/@waveform-playlist/browser): render `AnnotationProvider` above the view and pass `annotationList` to `WaveformPlaylistProvider` or `MediaElementPlaylistProvider`. `<Waveform />` and `<MediaElementWaveform />` then render the annotation boxes and the annotation text list. To give either one an option, compose the view with `<WaveformAnnotationBoxes>` and `<AnnotationList>` from `@waveform-playlist/browser`.
6
6
 
7
7
  ## Features
8
8
 
9
- - **Timeline annotation boxes** — draggable regions overlaid on the waveform, with boundary resize handles
10
- - **Editable text list** — a scrollable, auto-scrolling list of annotation text synced to playback
11
- - **Drag-to-edit boundaries** — resize annotation start/end by dragging, with optional linked endpoints so adjacent segments stay contiguous
12
- - **Continuous play mode** — automatically advance to the next annotation during playback
9
+ - **Timeline annotation boxes** — a row of boxes under the waveform, with a drag handle on each edge while annotations are editable. A click on a box plays its annotation
10
+ - **Editable text list** — a scrollable list of annotation text that follows playback. A click on a row plays its annotation
11
+ - **Drag-to-edit boundaries** — move an annotation's start or end by dragging the edge of its box, with optional linked endpoints so adjacent segments stay contiguous. `<WaveformAnnotationBoxes>` wires the drag itself
12
+ - **Continuous play mode** — off: playing an annotation stops at its end; on: playback runs on through the following annotations
13
13
  - **Aeneas import/export** — `parseAeneas` / `serializeAeneas` for the Aeneas forced-alignment JSON format
14
- - **Prebuilt controls** — checkboxes for continuous play, linked endpoints, editable mode, and a JSON download button
15
- - **Composable building blocks** — use `AnnotationsTrack`, `AnnotationBox`, `AnnotationBoxesWrapper`, and `AnnotationText` directly for custom annotation UIs
14
+ - **Prebuilt controls** — `ContinuousPlayCheckbox`, `LinkEndpointsCheckbox`, `EditableCheckbox` and `DownloadAnnotationsButton`, bound to the playlist provider above them (either one)
15
+ - **Composable building blocks** — use `AnnotationBox`, `AnnotationBoxesWrapper`, and `AnnotationText` directly for custom annotation UIs
16
16
 
17
17
  ## Installation
18
18
 
@@ -20,17 +20,18 @@ Used with [`@waveform-playlist/browser`](https://www.npmjs.com/package/@waveform
20
20
  npm install @waveform-playlist/annotations
21
21
  ```
22
22
 
23
- Peer dependencies: `react` (^18.0.0), `styled-components` (^6.0.0), `@dnd-kit/react` and `@dnd-kit/dom` (^0.5.0), and `@waveform-playlist/browser` (matching major version).
23
+ Peer dependencies: `react` (^19.0.0), `styled-components` (^6.0.0), `@dnd-kit/react` and `@dnd-kit/dom` (^0.5.0), and `@waveform-playlist/browser` (matching major version).
24
24
 
25
25
  ## Usage
26
26
 
27
27
  ```tsx
28
28
  import { useState } from 'react';
29
- import { WaveformPlaylistProvider, Waveform, useAudioTracks } from '@waveform-playlist/browser';
29
+ import { WaveformPlaylistProvider, Waveform, useCreateArrangement } from '@waveform-playlist/browser';
30
+ import { audioTrack } from '@waveform-playlist/core';
30
31
  import { AnnotationProvider } from '@waveform-playlist/annotations';
31
32
 
32
33
  function AnnotatedPlaylist() {
33
- const { tracks, loading } = useAudioTracks([{ src: '/audio/podcast.mp3', name: 'Podcast' }]);
34
+ const arrangement = useCreateArrangement(() => [audioTrack({ src: '/audio/podcast.mp3', name: 'Podcast' })]);
34
35
 
35
36
  const [annotations, setAnnotations] = useState([
36
37
  { id: '1', start: 0, end: 5, lines: ['Introduction'] },
@@ -38,17 +39,10 @@ function AnnotatedPlaylist() {
38
39
  { id: '3', start: 15, end: 30, lines: ['Main Discussion'] },
39
40
  ]);
40
41
 
41
- if (loading) return <div>Loading...</div>;
42
-
43
42
  return (
44
43
  <WaveformPlaylistProvider
45
- tracks={tracks}
46
- timescale
47
- annotationList={{
48
- annotations,
49
- editable: true,
50
- linkEndpoints: false,
51
- }}
44
+ arrangement={arrangement}
45
+ annotationList={{ annotations, editable: true }}
52
46
  onAnnotationsChange={setAnnotations} // required for edits to persist
53
47
  >
54
48
  <AnnotationProvider>
@@ -71,21 +65,49 @@ interface AnnotationData {
71
65
  }
72
66
  ```
73
67
 
74
- For building a custom UI outside the integrated `<Waveform />` pattern, use `useAnnotationControls` plus the standalone components directly:
68
+ `annotationList` also takes `linkEndpoints` and `isContinuousPlay`. The three options (`editable`, `linkEndpoints`, `isContinuousPlay`) are provider state that follows the prop. Read them with `useAnnotationOptions()` and change them with `setAnnotationsEditable`, `setLinkEndpoints` and `setContinuousPlay` from `usePlaybackControls()`, or render this package's checkboxes:
75
69
 
76
70
  ```tsx
77
71
  import {
78
- useAnnotationControls,
72
+ WaveformRoot,
73
+ WaveformTimescale,
74
+ WaveformTracks,
75
+ WaveformAnnotationBoxes,
76
+ WaveformSelection,
77
+ WaveformPlayhead,
78
+ AnnotationList,
79
+ } from '@waveform-playlist/browser';
80
+ import {
79
81
  ContinuousPlayCheckbox,
80
82
  LinkEndpointsCheckbox,
81
83
  EditableCheckbox,
82
84
  DownloadAnnotationsButton,
83
85
  } from '@waveform-playlist/annotations';
84
86
 
85
- const { continuousPlay, linkEndpoints, setContinuousPlay, setLinkEndpoints } =
86
- useAnnotationControls();
87
+ // Under either playlist provider:
88
+ <ContinuousPlayCheckbox />
89
+ <LinkEndpointsCheckbox />
90
+ <EditableCheckbox>Allow editing</EditableCheckbox>
91
+ <DownloadAnnotationsButton filename="chapters.json">Save chapters</DownloadAnnotationsButton>
92
+
93
+ <WaveformRoot>
94
+ <WaveformTimescale />
95
+ <WaveformTracks />
96
+ <WaveformAnnotationBoxes height={30} />
97
+ <WaveformSelection />
98
+ <WaveformPlayhead />
99
+ </WaveformRoot>
100
+ <AnnotationList height={300} />
87
101
  ```
88
102
 
103
+ Without `AnnotationProvider` the boxes and the list draw nothing. The checkboxes and the download button do not need it: they read the playlist provider (`useAnnotationOptions()`, `usePlaybackControls()`, `useAnnotations()` of `@waveform-playlist/browser`) and throw without one.
104
+
105
+ The checkboxes take `disabled`, `children` (the label; default "Continuous Play", "Link Endpoints", "Editable Annotations") and `className`. The download button takes `filename` (default `annotations.json`), `children` (the label; default "Download JSON"), `title` (the tooltip; default one of two English sentences), `disabled` and `className`, and is also disabled while there are no annotations. Every string the four controls draw can be supplied by your app. None of the four has a controlled form: `checked`, `onChange` and `annotations` props are not read.
106
+
107
+ `AnnotationText`, `AnnotationBox` and `AnnotationBoxesWrapper` are driven by props, for an annotation UI that does not go through a playlist provider. For a checkbox with a state of your own there, build one from `BaseCheckboxWrapper`, `BaseCheckbox` and `BaseCheckboxLabel` of `@waveform-playlist/ui-components`; move an edge with `updateAnnotationBoundaries` of `@waveform-playlist/core`; save with `annotations.map(serializeAeneas)`.
108
+
109
+ `parseAeneas(fragment)` converts one Aeneas fragment to one annotation, and `serializeAeneas(annotation)` converts one back: `fragments.map(parseAeneas)`.
110
+
89
111
  ## Examples & Documentation
90
112
 
91
113
  - [Annotations guide](https://naomiaro.github.io/waveform-playlist/docs/react/guides/annotations) — full provider configuration, keyboard controls, styling, and Aeneas import/export
package/dist/index.d.mts CHANGED
@@ -11,21 +11,6 @@ interface AeneasFragment {
11
11
  declare function parseAeneas(data: AeneasFragment): AnnotationData;
12
12
  declare function serializeAeneas(annotation: AnnotationData): AeneasFragment;
13
13
 
14
- interface AnnotationProps {
15
- annotation: AnnotationData;
16
- index: number;
17
- allAnnotations: AnnotationData[];
18
- startPosition: number;
19
- endPosition: number;
20
- color?: string;
21
- editable?: boolean;
22
- controls?: AnnotationAction[];
23
- onAnnotationUpdate?: (updatedAnnotations: AnnotationData[]) => void;
24
- annotationListConfig?: AnnotationActionOptions;
25
- onClick?: (annotation: AnnotationData) => void;
26
- }
27
- declare const Annotation: FunctionComponent<AnnotationProps>;
28
-
29
14
  interface AnnotationBoxComponentProps {
30
15
  annotationId: string;
31
16
  annotationIndex: number;
@@ -48,15 +33,6 @@ interface AnnotationBoxesWrapperProps {
48
33
  }
49
34
  declare const AnnotationBoxesWrapper: FunctionComponent<AnnotationBoxesWrapperProps>;
50
35
 
51
- interface AnnotationsTrackProps {
52
- className?: string;
53
- children?: React.ReactNode;
54
- height?: number;
55
- offset?: number;
56
- width?: number;
57
- }
58
- declare const AnnotationsTrack: FunctionComponent<AnnotationsTrackProps>;
59
-
60
36
  interface AnnotationTextProps {
61
37
  annotations: AnnotationData[];
62
38
  activeAnnotationId?: string;
@@ -80,73 +56,50 @@ interface AnnotationTextProps {
80
56
  }
81
57
  declare const AnnotationText: React.NamedExoticComponent<AnnotationTextProps>;
82
58
 
83
- interface ContinuousPlayCheckboxProps {
84
- checked: boolean;
85
- onChange: (checked: boolean) => void;
86
- disabled?: boolean;
59
+ interface AnnotationCheckboxProps {
60
+ /** On the element that wraps the checkbox and its label. */
87
61
  className?: string;
62
+ disabled?: boolean;
63
+ /** The label. Default (also for `null`): the option's English name. */
64
+ children?: React.ReactNode;
88
65
  }
89
66
  /**
90
- * Checkbox control for enabling/disabling continuous play of annotations.
91
- * When enabled, playback continues from one annotation to the next without stopping.
67
+ * Shows and sets the provider's `continuousPlay` option: on, playback runs on
68
+ * through the following annotations. Under either playlist provider.
92
69
  */
93
- declare const ContinuousPlayCheckbox: React.FC<ContinuousPlayCheckboxProps>;
94
-
95
- interface LinkEndpointsCheckboxProps {
96
- checked: boolean;
97
- onChange: (checked: boolean) => void;
98
- disabled?: boolean;
99
- className?: string;
100
- }
70
+ declare const ContinuousPlayCheckbox: React.FC<AnnotationCheckboxProps>;
101
71
  /**
102
- * Checkbox control for enabling/disabling linked endpoints between annotations.
103
- * When enabled, the end time of one annotation is automatically linked to the start time of the next.
72
+ * Shows and sets the provider's `linkEndpoints` option: on, a dragged edge
73
+ * takes the edge it touches along. Under either playlist provider.
104
74
  */
105
- declare const LinkEndpointsCheckbox: React.FC<LinkEndpointsCheckboxProps>;
106
-
107
- interface EditableCheckboxProps {
108
- checked: boolean;
109
- onChange: (enabled: boolean) => void;
110
- className?: string;
111
- }
112
- declare const EditableCheckbox: React.FC<EditableCheckboxProps>;
75
+ declare const LinkEndpointsCheckbox: React.FC<AnnotationCheckboxProps>;
76
+ /**
77
+ * Shows and sets the provider's `editable` option: whether annotation edges
78
+ * and text can be changed. Under either playlist provider.
79
+ */
80
+ declare const EditableCheckbox: React.FC<AnnotationCheckboxProps>;
113
81
 
114
82
  interface DownloadAnnotationsButtonProps {
115
- annotations: AnnotationData[];
83
+ /** Name of the downloaded file. Default: `annotations.json`. */
116
84
  filename?: string;
117
85
  disabled?: boolean;
118
86
  className?: string;
87
+ /** The label. Default: `Download JSON`. */
119
88
  children?: React.ReactNode;
89
+ /**
90
+ * The tooltip. Default: an English sentence, a different one when there is
91
+ * nothing to download. Given, it is used in both cases.
92
+ */
93
+ title?: string;
120
94
  }
95
+ /**
96
+ * Downloads the provider's annotations as an array of Aeneas fragments.
97
+ * Under either playlist provider.
98
+ */
121
99
  declare const DownloadAnnotationsButton: React.FC<DownloadAnnotationsButtonProps>;
122
100
 
123
101
  declare const AnnotationProvider: React.FC<{
124
102
  children: React.ReactNode;
125
103
  }>;
126
104
 
127
- interface UseAnnotationControlsOptions {
128
- initialContinuousPlay?: boolean;
129
- initialLinkEndpoints?: boolean;
130
- }
131
- interface AnnotationUpdateParams {
132
- annotationIndex: number;
133
- newTime: number;
134
- isDraggingStart: boolean;
135
- annotations: AnnotationData[];
136
- duration: number;
137
- linkEndpoints: boolean;
138
- }
139
- interface UseAnnotationControlsReturn {
140
- continuousPlay: boolean;
141
- linkEndpoints: boolean;
142
- setContinuousPlay: (value: boolean) => void;
143
- setLinkEndpoints: (value: boolean) => void;
144
- updateAnnotationBoundaries: (params: AnnotationUpdateParams) => AnnotationData[];
145
- }
146
- /**
147
- * Hook for managing annotation control state and boundary logic.
148
- * Boundary math lives in @waveform-playlist/core (shared with dawcore).
149
- */
150
- declare const useAnnotationControls: (options?: UseAnnotationControlsOptions) => UseAnnotationControlsReturn;
151
-
152
- export { type AeneasFragment, Annotation, AnnotationBox, type AnnotationBoxComponentProps, AnnotationBoxesWrapper, type AnnotationBoxesWrapperProps, type AnnotationProps, AnnotationProvider, AnnotationText, type AnnotationTextProps, type AnnotationUpdateParams, AnnotationsTrack, type AnnotationsTrackProps, ContinuousPlayCheckbox, type ContinuousPlayCheckboxProps, DownloadAnnotationsButton, type DownloadAnnotationsButtonProps, EditableCheckbox, type EditableCheckboxProps, LinkEndpointsCheckbox, type LinkEndpointsCheckboxProps, type UseAnnotationControlsOptions, type UseAnnotationControlsReturn, parseAeneas, serializeAeneas, useAnnotationControls };
105
+ export { type AeneasFragment, AnnotationBox, type AnnotationBoxComponentProps, AnnotationBoxesWrapper, type AnnotationBoxesWrapperProps, type AnnotationCheckboxProps, AnnotationProvider, AnnotationText, type AnnotationTextProps, ContinuousPlayCheckbox, DownloadAnnotationsButton, type DownloadAnnotationsButtonProps, EditableCheckbox, LinkEndpointsCheckbox, parseAeneas, serializeAeneas };
package/dist/index.d.ts CHANGED
@@ -11,21 +11,6 @@ interface AeneasFragment {
11
11
  declare function parseAeneas(data: AeneasFragment): AnnotationData;
12
12
  declare function serializeAeneas(annotation: AnnotationData): AeneasFragment;
13
13
 
14
- interface AnnotationProps {
15
- annotation: AnnotationData;
16
- index: number;
17
- allAnnotations: AnnotationData[];
18
- startPosition: number;
19
- endPosition: number;
20
- color?: string;
21
- editable?: boolean;
22
- controls?: AnnotationAction[];
23
- onAnnotationUpdate?: (updatedAnnotations: AnnotationData[]) => void;
24
- annotationListConfig?: AnnotationActionOptions;
25
- onClick?: (annotation: AnnotationData) => void;
26
- }
27
- declare const Annotation: FunctionComponent<AnnotationProps>;
28
-
29
14
  interface AnnotationBoxComponentProps {
30
15
  annotationId: string;
31
16
  annotationIndex: number;
@@ -48,15 +33,6 @@ interface AnnotationBoxesWrapperProps {
48
33
  }
49
34
  declare const AnnotationBoxesWrapper: FunctionComponent<AnnotationBoxesWrapperProps>;
50
35
 
51
- interface AnnotationsTrackProps {
52
- className?: string;
53
- children?: React.ReactNode;
54
- height?: number;
55
- offset?: number;
56
- width?: number;
57
- }
58
- declare const AnnotationsTrack: FunctionComponent<AnnotationsTrackProps>;
59
-
60
36
  interface AnnotationTextProps {
61
37
  annotations: AnnotationData[];
62
38
  activeAnnotationId?: string;
@@ -80,73 +56,50 @@ interface AnnotationTextProps {
80
56
  }
81
57
  declare const AnnotationText: React.NamedExoticComponent<AnnotationTextProps>;
82
58
 
83
- interface ContinuousPlayCheckboxProps {
84
- checked: boolean;
85
- onChange: (checked: boolean) => void;
86
- disabled?: boolean;
59
+ interface AnnotationCheckboxProps {
60
+ /** On the element that wraps the checkbox and its label. */
87
61
  className?: string;
62
+ disabled?: boolean;
63
+ /** The label. Default (also for `null`): the option's English name. */
64
+ children?: React.ReactNode;
88
65
  }
89
66
  /**
90
- * Checkbox control for enabling/disabling continuous play of annotations.
91
- * When enabled, playback continues from one annotation to the next without stopping.
67
+ * Shows and sets the provider's `continuousPlay` option: on, playback runs on
68
+ * through the following annotations. Under either playlist provider.
92
69
  */
93
- declare const ContinuousPlayCheckbox: React.FC<ContinuousPlayCheckboxProps>;
94
-
95
- interface LinkEndpointsCheckboxProps {
96
- checked: boolean;
97
- onChange: (checked: boolean) => void;
98
- disabled?: boolean;
99
- className?: string;
100
- }
70
+ declare const ContinuousPlayCheckbox: React.FC<AnnotationCheckboxProps>;
101
71
  /**
102
- * Checkbox control for enabling/disabling linked endpoints between annotations.
103
- * When enabled, the end time of one annotation is automatically linked to the start time of the next.
72
+ * Shows and sets the provider's `linkEndpoints` option: on, a dragged edge
73
+ * takes the edge it touches along. Under either playlist provider.
104
74
  */
105
- declare const LinkEndpointsCheckbox: React.FC<LinkEndpointsCheckboxProps>;
106
-
107
- interface EditableCheckboxProps {
108
- checked: boolean;
109
- onChange: (enabled: boolean) => void;
110
- className?: string;
111
- }
112
- declare const EditableCheckbox: React.FC<EditableCheckboxProps>;
75
+ declare const LinkEndpointsCheckbox: React.FC<AnnotationCheckboxProps>;
76
+ /**
77
+ * Shows and sets the provider's `editable` option: whether annotation edges
78
+ * and text can be changed. Under either playlist provider.
79
+ */
80
+ declare const EditableCheckbox: React.FC<AnnotationCheckboxProps>;
113
81
 
114
82
  interface DownloadAnnotationsButtonProps {
115
- annotations: AnnotationData[];
83
+ /** Name of the downloaded file. Default: `annotations.json`. */
116
84
  filename?: string;
117
85
  disabled?: boolean;
118
86
  className?: string;
87
+ /** The label. Default: `Download JSON`. */
119
88
  children?: React.ReactNode;
89
+ /**
90
+ * The tooltip. Default: an English sentence, a different one when there is
91
+ * nothing to download. Given, it is used in both cases.
92
+ */
93
+ title?: string;
120
94
  }
95
+ /**
96
+ * Downloads the provider's annotations as an array of Aeneas fragments.
97
+ * Under either playlist provider.
98
+ */
121
99
  declare const DownloadAnnotationsButton: React.FC<DownloadAnnotationsButtonProps>;
122
100
 
123
101
  declare const AnnotationProvider: React.FC<{
124
102
  children: React.ReactNode;
125
103
  }>;
126
104
 
127
- interface UseAnnotationControlsOptions {
128
- initialContinuousPlay?: boolean;
129
- initialLinkEndpoints?: boolean;
130
- }
131
- interface AnnotationUpdateParams {
132
- annotationIndex: number;
133
- newTime: number;
134
- isDraggingStart: boolean;
135
- annotations: AnnotationData[];
136
- duration: number;
137
- linkEndpoints: boolean;
138
- }
139
- interface UseAnnotationControlsReturn {
140
- continuousPlay: boolean;
141
- linkEndpoints: boolean;
142
- setContinuousPlay: (value: boolean) => void;
143
- setLinkEndpoints: (value: boolean) => void;
144
- updateAnnotationBoundaries: (params: AnnotationUpdateParams) => AnnotationData[];
145
- }
146
- /**
147
- * Hook for managing annotation control state and boundary logic.
148
- * Boundary math lives in @waveform-playlist/core (shared with dawcore).
149
- */
150
- declare const useAnnotationControls: (options?: UseAnnotationControlsOptions) => UseAnnotationControlsReturn;
151
-
152
- export { type AeneasFragment, Annotation, AnnotationBox, type AnnotationBoxComponentProps, AnnotationBoxesWrapper, type AnnotationBoxesWrapperProps, type AnnotationProps, AnnotationProvider, AnnotationText, type AnnotationTextProps, type AnnotationUpdateParams, AnnotationsTrack, type AnnotationsTrackProps, ContinuousPlayCheckbox, type ContinuousPlayCheckboxProps, DownloadAnnotationsButton, type DownloadAnnotationsButtonProps, EditableCheckbox, type EditableCheckboxProps, LinkEndpointsCheckbox, type LinkEndpointsCheckboxProps, type UseAnnotationControlsOptions, type UseAnnotationControlsReturn, parseAeneas, serializeAeneas, useAnnotationControls };
105
+ export { type AeneasFragment, AnnotationBox, type AnnotationBoxComponentProps, AnnotationBoxesWrapper, type AnnotationBoxesWrapperProps, type AnnotationCheckboxProps, AnnotationProvider, AnnotationText, type AnnotationTextProps, ContinuousPlayCheckbox, DownloadAnnotationsButton, type DownloadAnnotationsButtonProps, EditableCheckbox, LinkEndpointsCheckbox, parseAeneas, serializeAeneas };