@waveform-playlist/core 13.0.0-next.0 → 13.0.0-next.2

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
@@ -13,6 +13,7 @@ Used by nearly every `@waveform-playlist/*` and `@dawcore/*` package (`engine`,
13
13
  - **Peaks generation** — real-time min/max peak extraction during recording
14
14
  - **Musical time** — PPQN tick math, bar/beat conversion, time-signature meter detection, grid snapping
15
15
  - **Keyboard shortcuts** — a framework-agnostic shortcut matcher shared by the React and Web Components layers
16
+ - **Annotation store** — `createAnnotationStore`, the one owner of a list of annotations that both React providers take as `annotationStore`: `set` / `update` apply at once, every list is validated, and an optional `beforeChange` rule can accept, refuse or adjust each change
16
17
  - **Spectrogram canvas-ID contract** — canonical build/parse helpers for the `${clipId}-ch${n}-chunk${m}` canvas ID format shared by the worker pool and rendering layers
17
18
  - **HTTP range support probing** — detect whether an audio host supports byte-range seeking
18
19
 
@@ -73,6 +74,8 @@ parseSpectrogramCanvasId(id);
73
74
  | `utils/latency` | `resolveRecordingOffsetSamples` — override-vs-auto recording latency compensation (shared by React + dawcore) |
74
75
  | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split) |
75
76
  | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent` |
77
+ | `annotations/store` | `createAnnotationStore`, `AnnotationStore`, `AnnotationStoreOptions` |
78
+ | `annotations/bounds` | `applyAnnotationBounds`, `AnnotationBoundsChange` — write `start`/`end` onto annotations by id |
76
79
  | `spectrogramCanvasId` | `buildSpectrogramCanvasId`, `parseSpectrogramCanvasId`, `SpectrogramCanvasIdParts`, `SpectrogramCanvasRegistration` |
77
80
  | `probeRangeSupport` | `probeRangeSupport`, `RangeSupport` |
78
81
  | `enumerateMicrophones` | `enumerateMicrophones`, `watchMicrophoneDevices`, `MicrophoneEnumeration` — permission-free device listing with `supported`/`hasLabels` flags (labels are browser-redacted pre-permission) |
package/dist/index.d.mts CHANGED
@@ -513,7 +513,7 @@ interface AnnotationData {
513
513
  interface AnnotationFormat {
514
514
  name: string;
515
515
  parse: (data: unknown) => AnnotationData[];
516
- serialize: (annotations: AnnotationData[]) => unknown;
516
+ serialize: (annotations: readonly AnnotationData[]) => unknown;
517
517
  }
518
518
  /**
519
519
  * Options for annotation list behavior
@@ -1354,7 +1354,7 @@ interface AnnotationBoundaryUpdate {
1354
1354
  annotationIndex: number;
1355
1355
  newTime: number;
1356
1356
  isDraggingStart: boolean;
1357
- annotations: AnnotationData[];
1357
+ annotations: readonly AnnotationData[];
1358
1358
  duration: number;
1359
1359
  linkEndpoints: boolean;
1360
1360
  }
@@ -1390,6 +1390,61 @@ declare function resolveAnnotationShortcuts(remap: AnnotationShortcutMap | null)
1390
1390
  binding: KeyBinding;
1391
1391
  }>;
1392
1392
 
1393
+ /**
1394
+ * The owner of a list of annotations. The app makes one and gives it to a
1395
+ * provider; everything that reads the annotations reads them here, and every
1396
+ * change is a call to `set` or `update`.
1397
+ */
1398
+ interface AnnotationStore {
1399
+ /**
1400
+ * The current annotations. The same array until a change. Never write to
1401
+ * it: outside production builds it is frozen.
1402
+ */
1403
+ getAnnotations(): readonly AnnotationData[];
1404
+ /** Be told after every change. Returns the function that unsubscribes. */
1405
+ subscribe(listener: () => void): () => void;
1406
+ /** Replace the annotations. */
1407
+ set(annotations: readonly AnnotationData[]): void;
1408
+ /**
1409
+ * Change the annotations: `fn` gets the current array and returns the next.
1410
+ * The change is applied before `update` returns, so the next call's
1411
+ * `current` already holds it. Returning `current` changes nothing.
1412
+ */
1413
+ update(fn: (current: readonly AnnotationData[]) => readonly AnnotationData[]): void;
1414
+ }
1415
+ interface AnnotationStoreOptions {
1416
+ /**
1417
+ * The app's rule for every change. Gets the proposed list and the current
1418
+ * one, returns the list to store: `next` to accept, `current` to refuse,
1419
+ * or another list to adjust (e.g. clamp an edge so it does not overlap).
1420
+ * Not called for the initial list. A throw from it reaches the caller of
1421
+ * `set` or `update`, and the store keeps its value.
1422
+ */
1423
+ beforeChange?: (next: readonly AnnotationData[], current: readonly AnnotationData[]) => readonly AnnotationData[];
1424
+ }
1425
+ /**
1426
+ * Make an annotation store holding `initial` (empty when absent). Throws a
1427
+ * `TypeError` for an invalid list: an annotation without numeric `start` and
1428
+ * `end`, or two with one id.
1429
+ */
1430
+ declare function createAnnotationStore(initial?: readonly AnnotationData[], options?: AnnotationStoreOptions): AnnotationStore;
1431
+
1432
+ /** New bounds for the annotation with `id`. */
1433
+ interface AnnotationBoundsChange {
1434
+ id: string;
1435
+ start: number;
1436
+ end: number;
1437
+ }
1438
+ /**
1439
+ * Write `start` and `end` of each change onto the annotation with that id in
1440
+ * `current`. Every other field, and every annotation no change names, is kept
1441
+ * as it is (the same object). An id that is not in `current` is skipped.
1442
+ *
1443
+ * Returns `current` itself when nothing changes, so an `update` with it
1444
+ * notifies nobody.
1445
+ */
1446
+ declare function applyAnnotationBounds(current: readonly AnnotationData[], changes: readonly AnnotationBoundsChange[]): readonly AnnotationData[];
1447
+
1393
1448
  /** Gains of the pan matrix: `out = [[ll, rl], [lr, rr]] · in`, where e.g.
1394
1449
  * `rl` is how much of the input's RIGHT channel reaches the LEFT output. */
1395
1450
  interface PanMatrix {
@@ -1631,4 +1686,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1631
1686
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1632
1687
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1633
1688
 
1634
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1689
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.d.ts CHANGED
@@ -513,7 +513,7 @@ interface AnnotationData {
513
513
  interface AnnotationFormat {
514
514
  name: string;
515
515
  parse: (data: unknown) => AnnotationData[];
516
- serialize: (annotations: AnnotationData[]) => unknown;
516
+ serialize: (annotations: readonly AnnotationData[]) => unknown;
517
517
  }
518
518
  /**
519
519
  * Options for annotation list behavior
@@ -1354,7 +1354,7 @@ interface AnnotationBoundaryUpdate {
1354
1354
  annotationIndex: number;
1355
1355
  newTime: number;
1356
1356
  isDraggingStart: boolean;
1357
- annotations: AnnotationData[];
1357
+ annotations: readonly AnnotationData[];
1358
1358
  duration: number;
1359
1359
  linkEndpoints: boolean;
1360
1360
  }
@@ -1390,6 +1390,61 @@ declare function resolveAnnotationShortcuts(remap: AnnotationShortcutMap | null)
1390
1390
  binding: KeyBinding;
1391
1391
  }>;
1392
1392
 
1393
+ /**
1394
+ * The owner of a list of annotations. The app makes one and gives it to a
1395
+ * provider; everything that reads the annotations reads them here, and every
1396
+ * change is a call to `set` or `update`.
1397
+ */
1398
+ interface AnnotationStore {
1399
+ /**
1400
+ * The current annotations. The same array until a change. Never write to
1401
+ * it: outside production builds it is frozen.
1402
+ */
1403
+ getAnnotations(): readonly AnnotationData[];
1404
+ /** Be told after every change. Returns the function that unsubscribes. */
1405
+ subscribe(listener: () => void): () => void;
1406
+ /** Replace the annotations. */
1407
+ set(annotations: readonly AnnotationData[]): void;
1408
+ /**
1409
+ * Change the annotations: `fn` gets the current array and returns the next.
1410
+ * The change is applied before `update` returns, so the next call's
1411
+ * `current` already holds it. Returning `current` changes nothing.
1412
+ */
1413
+ update(fn: (current: readonly AnnotationData[]) => readonly AnnotationData[]): void;
1414
+ }
1415
+ interface AnnotationStoreOptions {
1416
+ /**
1417
+ * The app's rule for every change. Gets the proposed list and the current
1418
+ * one, returns the list to store: `next` to accept, `current` to refuse,
1419
+ * or another list to adjust (e.g. clamp an edge so it does not overlap).
1420
+ * Not called for the initial list. A throw from it reaches the caller of
1421
+ * `set` or `update`, and the store keeps its value.
1422
+ */
1423
+ beforeChange?: (next: readonly AnnotationData[], current: readonly AnnotationData[]) => readonly AnnotationData[];
1424
+ }
1425
+ /**
1426
+ * Make an annotation store holding `initial` (empty when absent). Throws a
1427
+ * `TypeError` for an invalid list: an annotation without numeric `start` and
1428
+ * `end`, or two with one id.
1429
+ */
1430
+ declare function createAnnotationStore(initial?: readonly AnnotationData[], options?: AnnotationStoreOptions): AnnotationStore;
1431
+
1432
+ /** New bounds for the annotation with `id`. */
1433
+ interface AnnotationBoundsChange {
1434
+ id: string;
1435
+ start: number;
1436
+ end: number;
1437
+ }
1438
+ /**
1439
+ * Write `start` and `end` of each change onto the annotation with that id in
1440
+ * `current`. Every other field, and every annotation no change names, is kept
1441
+ * as it is (the same object). An id that is not in `current` is skipped.
1442
+ *
1443
+ * Returns `current` itself when nothing changes, so an `update` with it
1444
+ * notifies nobody.
1445
+ */
1446
+ declare function applyAnnotationBounds(current: readonly AnnotationData[], changes: readonly AnnotationBoundsChange[]): readonly AnnotationData[];
1447
+
1393
1448
  /** Gains of the pan matrix: `out = [[ll, rl], [lr, rr]] · in`, where e.g.
1394
1449
  * `rl` is how much of the input's RIGHT channel reaches the LEFT output. */
1395
1450
  interface PanMatrix {
@@ -1631,4 +1686,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1631
1686
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1632
1687
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1633
1688
 
1634
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1689
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  annotationMinDurationTicks: () => annotationMinDurationTicks,
35
35
  appendPeaks: () => appendPeaks,
36
36
  appendToAudioBuffer: () => appendToAudioBuffer,
37
+ applyAnnotationBounds: () => applyAnnotationBounds,
37
38
  applyFadeIn: () => applyFadeIn,
38
39
  applyFadeOut: () => applyFadeOut,
39
40
  assertTrackKind: () => assertTrackKind,
@@ -51,6 +52,7 @@ __export(index_exports, {
51
52
  clipsOverlap: () => clipsOverlap,
52
53
  computeMusicalTicks: () => computeMusicalTicks,
53
54
  concatenateAudioData: () => concatenateAudioData,
55
+ createAnnotationStore: () => createAnnotationStore,
54
56
  createAudioBuffer: () => createAudioBuffer,
55
57
  createClip: () => createClip,
56
58
  createClipFromSeconds: () => createClipFromSeconds,
@@ -1321,6 +1323,99 @@ function resolveAnnotationShortcuts(remap) {
1321
1323
  });
1322
1324
  }
1323
1325
 
1326
+ // src/annotations/devFreeze.ts
1327
+ function isDevelopmentBuild() {
1328
+ try {
1329
+ return process.env.NODE_ENV !== "production";
1330
+ } catch {
1331
+ return false;
1332
+ }
1333
+ }
1334
+ function freezeAnnotations(list) {
1335
+ if (!isDevelopmentBuild()) return list;
1336
+ for (const annotation of list) {
1337
+ if (Array.isArray(annotation.lines)) Object.freeze(annotation.lines);
1338
+ Object.freeze(annotation);
1339
+ }
1340
+ return Object.freeze(list);
1341
+ }
1342
+
1343
+ // src/annotations/store.ts
1344
+ function invalid(message) {
1345
+ return new TypeError("[waveform-playlist] Invalid annotations: " + message);
1346
+ }
1347
+ function validateAnnotations(list) {
1348
+ if (!Array.isArray(list)) throw invalid("expected an array.");
1349
+ const seen = /* @__PURE__ */ new Set();
1350
+ for (const annotation of list) {
1351
+ const { id, start, end } = annotation ?? {};
1352
+ if (!Number.isFinite(start) || !Number.isFinite(end)) {
1353
+ throw invalid(
1354
+ `annotation "${String(id)}" needs numeric start and end (got ${typeof start} and ${typeof end}). Parse text formats first, e.g. parseAeneas() from @waveform-playlist/annotations.`
1355
+ );
1356
+ }
1357
+ if (seen.has(id)) throw invalid(`two annotations have the id "${id}".`);
1358
+ seen.add(id);
1359
+ }
1360
+ }
1361
+ function createAnnotationStore(initial = [], options = {}) {
1362
+ validateAnnotations(initial);
1363
+ let annotations = freezeAnnotations(initial);
1364
+ const listeners = /* @__PURE__ */ new Set();
1365
+ const { beforeChange } = options;
1366
+ const commit = (proposed) => {
1367
+ if (proposed === annotations) return;
1368
+ validateAnnotations(proposed);
1369
+ let next = proposed;
1370
+ if (beforeChange) {
1371
+ next = beforeChange(proposed, annotations);
1372
+ if (next === annotations) return;
1373
+ if (next !== proposed) validateAnnotations(next);
1374
+ }
1375
+ annotations = freezeAnnotations(next);
1376
+ for (const entry of [...listeners]) {
1377
+ if (!listeners.has(entry)) continue;
1378
+ try {
1379
+ entry.listener();
1380
+ } catch (error) {
1381
+ console.warn("[waveform-playlist] Error in an annotation store subscriber:", error);
1382
+ }
1383
+ }
1384
+ };
1385
+ return {
1386
+ getAnnotations: () => annotations,
1387
+ subscribe(listener) {
1388
+ const entry = { listener };
1389
+ listeners.add(entry);
1390
+ return () => {
1391
+ listeners.delete(entry);
1392
+ };
1393
+ },
1394
+ set(next) {
1395
+ commit(next);
1396
+ },
1397
+ update(fn) {
1398
+ commit(fn(annotations));
1399
+ }
1400
+ };
1401
+ }
1402
+
1403
+ // src/annotations/bounds.ts
1404
+ function applyAnnotationBounds(current, changes) {
1405
+ if (changes.length === 0) return current;
1406
+ const byId = new Map(changes.map((change) => [change.id, change]));
1407
+ let changed = false;
1408
+ const next = current.map((annotation) => {
1409
+ const change = byId.get(annotation.id);
1410
+ if (!change || change.start === annotation.start && change.end === annotation.end) {
1411
+ return annotation;
1412
+ }
1413
+ changed = true;
1414
+ return { ...annotation, start: change.start, end: change.end };
1415
+ });
1416
+ return changed ? next : current;
1417
+ }
1418
+
1324
1419
  // src/panStage.ts
1325
1420
  var PREFIX = "[waveform-playlist] ";
1326
1421
  function panMatrix(pan, sourceChannelCount) {
@@ -1747,6 +1842,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1747
1842
  annotationMinDurationTicks,
1748
1843
  appendPeaks,
1749
1844
  appendToAudioBuffer,
1845
+ applyAnnotationBounds,
1750
1846
  applyFadeIn,
1751
1847
  applyFadeOut,
1752
1848
  assertTrackKind,
@@ -1764,6 +1860,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1764
1860
  clipsOverlap,
1765
1861
  computeMusicalTicks,
1766
1862
  concatenateAudioData,
1863
+ createAnnotationStore,
1767
1864
  createAudioBuffer,
1768
1865
  createClip,
1769
1866
  createClipFromSeconds,