@waveform-playlist/browser 17.0.0-next.3 → 17.0.0-next.5

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.mjs CHANGED
@@ -51,16 +51,16 @@ var __async = (__this, __arguments, generator) => {
51
51
  };
52
52
 
53
53
  // <define:__INSTALL_SPECS__>
54
- var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.2", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.1", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.1", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.2", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.1" };
54
+ var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.4", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.2", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.2", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.4", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.2" };
55
55
 
56
56
  // src/WaveformPlaylistContext.tsx
57
57
  import {
58
- useState as useState15,
58
+ useState as useState16,
59
59
  useEffect as useEffect10,
60
- useLayoutEffect as useLayoutEffect2,
61
- useRef as useRef20,
60
+ useLayoutEffect as useLayoutEffect3,
61
+ useRef as useRef21,
62
62
  useCallback as useCallback19,
63
- useMemo as useMemo10
63
+ useMemo as useMemo11
64
64
  } from "react";
65
65
  import { ThemeProvider } from "styled-components";
66
66
 
@@ -669,11 +669,24 @@ function useClipDragHandlers({
669
669
  import React2 from "react";
670
670
  import { flushSync } from "react-dom";
671
671
  import {
672
+ applyAnnotationBounds,
672
673
  updateAnnotationBoundaries
673
674
  } from "@waveform-playlist/core";
675
+ function touchedChanges(drag) {
676
+ return [...drag.touched.values()];
677
+ }
678
+ function snapshotBounds(drag) {
679
+ const before = new Map(drag.snapshot.map((a) => [a.id, a]));
680
+ return [...drag.touched.keys()].flatMap((id) => {
681
+ const old = before.get(id);
682
+ return old ? [{ id, start: old.start, end: old.end }] : [];
683
+ });
684
+ }
685
+ function shownDuringDrag(drag) {
686
+ return applyAnnotationBounds(drag.store.getAnnotations(), touchedChanges(drag));
687
+ }
674
688
  function useAnnotationDragHandlers({
675
- annotations,
676
- onAnnotationsChange,
689
+ store,
677
690
  samplesPerPixel,
678
691
  // Default mirrors the engine default; the providers always pass the real rate from context (#510).
679
692
  sampleRate = 48e3,
@@ -682,81 +695,132 @@ function useAnnotationDragHandlers({
682
695
  preview
683
696
  }) {
684
697
  const dragRef = React2.useRef(null);
685
- const annotationsRef = React2.useRef(annotations);
686
- annotationsRef.current = annotations;
687
- const onAnnotationsChangeRef = React2.useRef(onAnnotationsChange);
688
- onAnnotationsChangeRef.current = onAnnotationsChange;
698
+ const storeRef = React2.useRef(store);
699
+ storeRef.current = store;
700
+ const previewRef = React2.useRef(preview);
701
+ previewRef.current = preview;
702
+ const abandon = React2.useCallback(() => {
703
+ var _a;
704
+ if (!dragRef.current) return;
705
+ dragRef.current = null;
706
+ (_a = previewRef.current) == null ? void 0 : _a.publish(null);
707
+ }, []);
689
708
  React2.useEffect(() => {
690
- if (!preview) return;
691
- return () => {
692
- if (dragRef.current) {
693
- dragRef.current = null;
694
- preview.publish(null);
709
+ if (!store) return;
710
+ const unsubscribe = store.subscribe(() => {
711
+ const drag = dragRef.current;
712
+ if (!drag || drag.store !== store) return;
713
+ if (!store.getAnnotations().some((a) => a.id === drag.draggedId)) {
714
+ abandon();
715
+ return;
716
+ }
717
+ const shown = previewRef.current;
718
+ if (shown && shown.source.getSnapshot() !== null) {
719
+ shown.publish(shownDuringDrag(drag));
695
720
  }
721
+ });
722
+ return () => {
723
+ unsubscribe();
724
+ abandon();
696
725
  };
697
- }, [preview]);
726
+ }, [store, abandon]);
727
+ React2.useEffect(() => abandon, [preview, abandon]);
698
728
  const onDragStart = React2.useCallback((event) => {
699
729
  var _a;
700
730
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
701
- const snapshot = annotationsRef.current;
702
- const annotation = (data == null ? void 0 : data.annotationIndex) === void 0 ? void 0 : snapshot[data.annotationIndex];
703
- dragRef.current = data && annotation ? {
731
+ const owner = storeRef.current;
732
+ if (!owner || !data) {
733
+ dragRef.current = null;
734
+ return;
735
+ }
736
+ const snapshot = owner.getAnnotations();
737
+ const annotation = data.annotationIndex === void 0 ? void 0 : snapshot[data.annotationIndex];
738
+ dragRef.current = annotation ? {
739
+ store: owner,
704
740
  snapshot,
741
+ touched: /* @__PURE__ */ new Map(),
742
+ draggedId: annotation.id,
743
+ edge: data.edge,
705
744
  start: annotation.start,
706
- end: annotation.end,
707
- annotationIndex: data.annotationIndex
745
+ end: annotation.end
708
746
  } : null;
709
747
  }, []);
710
748
  const onDragMove = React2.useCallback(
711
749
  (event) => {
712
- var _a, _b, _c, _d;
750
+ var _a, _b;
713
751
  const drag = dragRef.current;
714
- if (!drag) {
752
+ if (!drag) return;
753
+ if (drag.store !== storeRef.current) {
754
+ abandon();
715
755
  return;
716
756
  }
717
- const data = (_a = event.operation.source) == null ? void 0 : _a.data;
718
- if (!data) return;
719
- const { edge, annotationIndex } = data;
720
- const currentX = (_c = (_b = event.to) == null ? void 0 : _b.x) != null ? _c : event.operation.position.current.x;
757
+ const currentX = (_b = (_a = event.to) == null ? void 0 : _a.x) != null ? _b : event.operation.position.current.x;
721
758
  const rawDeltaX = currentX - event.operation.position.initial.x;
722
759
  const timeDelta = rawDeltaX * samplesPerPixel / sampleRate;
723
- const newTime = edge === "start" ? drag.start + timeDelta : drag.end + timeDelta;
724
- const updatedAnnotations = updateAnnotationBoundaries({
760
+ const newTime = drag.edge === "start" ? drag.start + timeDelta : drag.end + timeDelta;
761
+ const base = shownDuringDrag(drag);
762
+ const annotationIndex = base.findIndex((a) => a.id === drag.draggedId);
763
+ if (annotationIndex < 0) {
764
+ abandon();
765
+ return;
766
+ }
767
+ const updated = updateAnnotationBoundaries({
725
768
  annotationIndex,
726
769
  newTime,
727
- isDraggingStart: edge === "start",
728
- annotations: preview ? (_d = preview.source.getSnapshot()) != null ? _d : drag.snapshot : annotationsRef.current,
770
+ isDraggingStart: drag.edge === "start",
771
+ annotations: base,
729
772
  duration,
730
773
  linkEndpoints
731
774
  });
775
+ updated.forEach((annotation, i) => {
776
+ const was = base[i];
777
+ if (drag.touched.has(annotation.id) || was.start !== annotation.start || was.end !== annotation.end) {
778
+ drag.touched.set(annotation.id, {
779
+ id: annotation.id,
780
+ start: annotation.start,
781
+ end: annotation.end
782
+ });
783
+ }
784
+ });
732
785
  if (preview) {
733
- preview.publish(updatedAnnotations);
786
+ preview.publish(updated);
734
787
  } else {
735
- onAnnotationsChangeRef.current(updatedAnnotations);
788
+ const changes = touchedChanges(drag);
789
+ drag.store.update((current) => applyAnnotationBounds(current, changes));
736
790
  }
737
791
  },
738
- [samplesPerPixel, sampleRate, duration, linkEndpoints, preview]
792
+ [samplesPerPixel, sampleRate, duration, linkEndpoints, preview, abandon]
739
793
  );
740
794
  const onDragEnd = React2.useCallback(
741
795
  (event) => {
742
796
  const drag = dragRef.current;
743
797
  dragRef.current = null;
744
798
  if (!drag) return;
799
+ if (drag.store !== storeRef.current) {
800
+ preview == null ? void 0 : preview.publish(null);
801
+ return;
802
+ }
745
803
  if (!preview) {
746
- if (event.canceled && annotationsRef.current !== drag.snapshot) {
747
- onAnnotationsChangeRef.current(drag.snapshot);
804
+ if (event.canceled) {
805
+ const restore = snapshotBounds(drag);
806
+ drag.store.update((current) => applyAnnotationBounds(current, restore));
748
807
  }
749
808
  return;
750
809
  }
751
- const result = preview.source.getSnapshot();
752
- if (result === null) return;
810
+ if (preview.source.getSnapshot() === null) return;
753
811
  if (event.canceled) {
754
812
  preview.publish(null);
755
813
  return;
756
814
  }
757
815
  flushSync(() => {
758
- onAnnotationsChangeRef.current(result);
759
- preview.publish(null);
816
+ try {
817
+ const changes = touchedChanges(drag);
818
+ drag.store.update(
819
+ (current) => current.some((a) => a.id === drag.draggedId) ? applyAnnotationBounds(current, changes) : current
820
+ );
821
+ } finally {
822
+ preview.publish(null);
823
+ }
760
824
  });
761
825
  },
762
826
  [preview]
@@ -972,13 +1036,95 @@ var usePlaybackShortcuts = (options = {}) => {
972
1036
  };
973
1037
 
974
1038
  // src/hooks/useAnnotationKeyboardControls.ts
975
- import { useCallback as useCallback10, useMemo as useMemo2, useEffect as useEffect3 } from "react";
1039
+ import { useCallback as useCallback10, useMemo as useMemo2, useEffect as useEffect3, useSyncExternalStore as useSyncExternalStore2 } from "react";
1040
+
1041
+ // src/utils/annotationBoundaryKeys.ts
976
1042
  var LINK_THRESHOLD = 0.01;
1043
+ var MIN_LENGTH = 0.1;
1044
+ function unlessUnchanged(list, updated) {
1045
+ const same = updated.every((a, i) => a.start === list[i].start && a.end === list[i].end);
1046
+ return same ? list : updated;
1047
+ }
1048
+ function moveAnnotationStart(list, index, delta, { linkEndpoints }) {
1049
+ const annotation = list[index];
1050
+ const newStart = Math.max(0, Math.min(annotation.end - MIN_LENGTH, annotation.start + delta));
1051
+ const actualDelta = newStart - annotation.start;
1052
+ const updated = [...list];
1053
+ updated[index] = __spreadProps(__spreadValues({}, annotation), { start: newStart });
1054
+ if (linkEndpoints && index > 0) {
1055
+ const prev = updated[index - 1];
1056
+ if (Math.abs(prev.end - annotation.start) < LINK_THRESHOLD) {
1057
+ updated[index - 1] = __spreadProps(__spreadValues({}, prev), {
1058
+ end: Math.max(prev.start + MIN_LENGTH, prev.end + actualDelta)
1059
+ });
1060
+ }
1061
+ } else if (!linkEndpoints && index > 0) {
1062
+ const prev = updated[index - 1];
1063
+ if (newStart < prev.end) {
1064
+ updated[index - 1] = __spreadProps(__spreadValues({}, prev), { end: newStart });
1065
+ }
1066
+ }
1067
+ return unlessUnchanged(list, updated);
1068
+ }
1069
+ function moveAnnotationEnd(list, index, delta, { linkEndpoints, duration }) {
1070
+ const annotation = list[index];
1071
+ const newEnd = Math.max(
1072
+ annotation.start + MIN_LENGTH,
1073
+ Math.min(duration, annotation.end + delta)
1074
+ );
1075
+ const actualDelta = newEnd - annotation.end;
1076
+ const updated = [...list];
1077
+ updated[index] = __spreadProps(__spreadValues({}, annotation), { end: newEnd });
1078
+ if (linkEndpoints && index < list.length - 1) {
1079
+ const next = updated[index + 1];
1080
+ if (Math.abs(next.start - annotation.end) < LINK_THRESHOLD) {
1081
+ updated[index + 1] = __spreadProps(__spreadValues({}, next), {
1082
+ start: Math.min(next.end - MIN_LENGTH, next.start + actualDelta)
1083
+ });
1084
+ let current = index + 1;
1085
+ while (current < updated.length - 1) {
1086
+ const moved = updated[current];
1087
+ const following = updated[current + 1];
1088
+ if (Math.abs(following.start - list[current].end) < LINK_THRESHOLD) {
1089
+ const nextDelta = moved.end - list[current].end;
1090
+ updated[current + 1] = __spreadProps(__spreadValues({}, following), {
1091
+ start: Math.min(following.end - MIN_LENGTH, following.start + nextDelta)
1092
+ });
1093
+ current++;
1094
+ } else {
1095
+ break;
1096
+ }
1097
+ }
1098
+ }
1099
+ } else if (!linkEndpoints && index < list.length - 1) {
1100
+ const next = updated[index + 1];
1101
+ if (newEnd > next.start) {
1102
+ updated[index + 1] = __spreadProps(__spreadValues({}, next), { start: newEnd });
1103
+ let current = index + 1;
1104
+ while (current < updated.length - 1) {
1105
+ const pushed = updated[current];
1106
+ const following = updated[current + 1];
1107
+ if (pushed.end > following.start) {
1108
+ updated[current + 1] = __spreadProps(__spreadValues({}, following), { start: pushed.end });
1109
+ current++;
1110
+ } else {
1111
+ break;
1112
+ }
1113
+ }
1114
+ }
1115
+ }
1116
+ return unlessUnchanged(list, updated);
1117
+ }
1118
+
1119
+ // src/hooks/useAnnotationKeyboardControls.ts
977
1120
  var TIME_DELTA = 0.01;
1121
+ var NO_ANNOTATIONS = Object.freeze([]);
1122
+ var noSubscription = () => () => {
1123
+ };
1124
+ var noAnnotations = () => NO_ANNOTATIONS;
978
1125
  function useAnnotationKeyboardControls({
979
- annotations,
1126
+ store,
980
1127
  activeAnnotationId,
981
- onAnnotationsChange,
982
1128
  onActiveAnnotationChange,
983
1129
  duration,
984
1130
  linkEndpoints,
@@ -989,6 +1135,15 @@ function useAnnotationKeyboardControls({
989
1135
  samplesPerPixel: samplesPerPixelProp,
990
1136
  sampleRate: sampleRateProp
991
1137
  }) {
1138
+ const source = useMemo2(
1139
+ () => store ? {
1140
+ subscribe: (listener) => store.subscribe(listener),
1141
+ getSnapshot: () => store.getAnnotations()
1142
+ } : { subscribe: noSubscription, getSnapshot: noAnnotations },
1143
+ [store]
1144
+ );
1145
+ const stored = useSyncExternalStore2(source.subscribe, source.getSnapshot, source.getSnapshot);
1146
+ const annotations = stored;
992
1147
  const playlistView = usePlaylistViewOptional();
993
1148
  const playlistZoom = usePlaylistZoomOptional();
994
1149
  const samplesPerPixel = samplesPerPixelProp != null ? samplesPerPixelProp : playlistZoom == null ? void 0 : playlistZoom.samplesPerPixel;
@@ -1027,92 +1182,21 @@ function useAnnotationKeyboardControls({
1027
1182
  }, [activeAnnotationId, scrollToAnnotation, scrollContainerRef, samplesPerPixel, sampleRate]);
1028
1183
  const moveStartBoundary = useCallback10(
1029
1184
  (delta) => {
1030
- if (activeIndex < 0) return;
1031
- const annotation = annotations[activeIndex];
1032
- const newStart = Math.max(0, Math.min(annotation.end - 0.1, annotation.start + delta));
1033
- const actualDelta = newStart - annotation.start;
1034
- const updatedAnnotations = [...annotations];
1035
- updatedAnnotations[activeIndex] = __spreadProps(__spreadValues({}, annotation), {
1036
- start: newStart
1185
+ store == null ? void 0 : store.update((current) => {
1186
+ const index = current.findIndex((a) => a.id === activeAnnotationId);
1187
+ return index < 0 ? current : moveAnnotationStart(current, index, delta, { linkEndpoints });
1037
1188
  });
1038
- if (linkEndpoints && activeIndex > 0) {
1039
- const prevAnnotation = updatedAnnotations[activeIndex - 1];
1040
- if (Math.abs(prevAnnotation.end - annotation.start) < LINK_THRESHOLD) {
1041
- updatedAnnotations[activeIndex - 1] = __spreadProps(__spreadValues({}, prevAnnotation), {
1042
- end: Math.max(prevAnnotation.start + 0.1, prevAnnotation.end + actualDelta)
1043
- });
1044
- }
1045
- } else if (!linkEndpoints && activeIndex > 0) {
1046
- const prevAnnotation = updatedAnnotations[activeIndex - 1];
1047
- if (newStart < prevAnnotation.end) {
1048
- updatedAnnotations[activeIndex - 1] = __spreadProps(__spreadValues({}, prevAnnotation), {
1049
- end: newStart
1050
- });
1051
- }
1052
- }
1053
- onAnnotationsChange(updatedAnnotations);
1054
1189
  },
1055
- [annotations, activeIndex, linkEndpoints, onAnnotationsChange]
1190
+ [store, activeAnnotationId, linkEndpoints]
1056
1191
  );
1057
1192
  const moveEndBoundary = useCallback10(
1058
1193
  (delta) => {
1059
- if (activeIndex < 0) return;
1060
- const annotation = annotations[activeIndex];
1061
- const newEnd = Math.max(annotation.start + 0.1, Math.min(duration, annotation.end + delta));
1062
- const actualDelta = newEnd - annotation.end;
1063
- const updatedAnnotations = [...annotations];
1064
- updatedAnnotations[activeIndex] = __spreadProps(__spreadValues({}, annotation), {
1065
- end: newEnd
1194
+ store == null ? void 0 : store.update((current) => {
1195
+ const index = current.findIndex((a) => a.id === activeAnnotationId);
1196
+ return index < 0 ? current : moveAnnotationEnd(current, index, delta, { linkEndpoints, duration });
1066
1197
  });
1067
- if (linkEndpoints && activeIndex < annotations.length - 1) {
1068
- const nextAnnotation = updatedAnnotations[activeIndex + 1];
1069
- if (Math.abs(nextAnnotation.start - annotation.end) < LINK_THRESHOLD) {
1070
- const newNextStart = Math.min(
1071
- nextAnnotation.end - 0.1,
1072
- nextAnnotation.start + actualDelta
1073
- );
1074
- updatedAnnotations[activeIndex + 1] = __spreadProps(__spreadValues({}, nextAnnotation), {
1075
- start: newNextStart
1076
- });
1077
- let currentIndex = activeIndex + 1;
1078
- while (currentIndex < updatedAnnotations.length - 1) {
1079
- const current = updatedAnnotations[currentIndex];
1080
- const next = updatedAnnotations[currentIndex + 1];
1081
- if (Math.abs(next.start - annotations[currentIndex].end) < LINK_THRESHOLD) {
1082
- const nextDelta = current.end - annotations[currentIndex].end;
1083
- updatedAnnotations[currentIndex + 1] = __spreadProps(__spreadValues({}, next), {
1084
- start: Math.min(next.end - 0.1, next.start + nextDelta)
1085
- });
1086
- currentIndex++;
1087
- } else {
1088
- break;
1089
- }
1090
- }
1091
- }
1092
- } else if (!linkEndpoints && activeIndex < annotations.length - 1) {
1093
- const nextAnnotation = updatedAnnotations[activeIndex + 1];
1094
- if (newEnd > nextAnnotation.start) {
1095
- updatedAnnotations[activeIndex + 1] = __spreadProps(__spreadValues({}, nextAnnotation), {
1096
- start: newEnd
1097
- });
1098
- let currentIndex = activeIndex + 1;
1099
- while (currentIndex < updatedAnnotations.length - 1) {
1100
- const current = updatedAnnotations[currentIndex];
1101
- const next = updatedAnnotations[currentIndex + 1];
1102
- if (current.end > next.start) {
1103
- updatedAnnotations[currentIndex + 1] = __spreadProps(__spreadValues({}, next), {
1104
- start: current.end
1105
- });
1106
- currentIndex++;
1107
- } else {
1108
- break;
1109
- }
1110
- }
1111
- }
1112
- }
1113
- onAnnotationsChange(updatedAnnotations);
1114
1198
  },
1115
- [annotations, activeIndex, duration, linkEndpoints, onAnnotationsChange]
1199
+ [store, activeAnnotationId, duration, linkEndpoints]
1116
1200
  );
1117
1201
  const selectPrevious = useCallback10(() => {
1118
1202
  if (!onActiveAnnotationChange || annotations.length === 0) return;
@@ -1631,7 +1715,7 @@ function useCreateArrangement(init, options) {
1631
1715
  }
1632
1716
 
1633
1717
  // src/hooks/useArrangementTracks.ts
1634
- import { useMemo as useMemo3, useSyncExternalStore as useSyncExternalStore2 } from "react";
1718
+ import { useMemo as useMemo3, useSyncExternalStore as useSyncExternalStore3 } from "react";
1635
1719
  function useArrangementTracks(arrangement) {
1636
1720
  const store = useMemo3(
1637
1721
  () => ({
@@ -1640,11 +1724,11 @@ function useArrangementTracks(arrangement) {
1640
1724
  }),
1641
1725
  [arrangement]
1642
1726
  );
1643
- return useSyncExternalStore2(store.subscribe, store.getSnapshot, store.getSnapshot);
1727
+ return useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getSnapshot);
1644
1728
  }
1645
1729
 
1646
1730
  // src/hooks/useArrangementSources.ts
1647
- import { useMemo as useMemo4, useSyncExternalStore as useSyncExternalStore3 } from "react";
1731
+ import { useMemo as useMemo4, useSyncExternalStore as useSyncExternalStore4 } from "react";
1648
1732
  function useArrangementSources(arrangement) {
1649
1733
  const store = useMemo4(
1650
1734
  () => ({
@@ -1653,7 +1737,37 @@ function useArrangementSources(arrangement) {
1653
1737
  }),
1654
1738
  [arrangement]
1655
1739
  );
1656
- return useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getSnapshot);
1740
+ return useSyncExternalStore4(store.subscribe, store.getSnapshot, store.getSnapshot);
1741
+ }
1742
+
1743
+ // src/hooks/useCreateAnnotationStore.ts
1744
+ import { useLayoutEffect, useRef as useRef10, useState as useState9 } from "react";
1745
+ import { createAnnotationStore } from "@waveform-playlist/core";
1746
+ function useCreateAnnotationStore(init, options) {
1747
+ const beforeChange = options == null ? void 0 : options.beforeChange;
1748
+ const ruleRef = useRef10(beforeChange);
1749
+ useLayoutEffect(() => {
1750
+ ruleRef.current = beforeChange;
1751
+ }, [beforeChange]);
1752
+ const [store] = useState9(
1753
+ () => createAnnotationStore(init == null ? void 0 : init(), {
1754
+ beforeChange: (next, current) => ruleRef.current ? ruleRef.current(next, current) : next
1755
+ })
1756
+ );
1757
+ return store;
1758
+ }
1759
+
1760
+ // src/hooks/useStoredAnnotations.ts
1761
+ import { useMemo as useMemo5, useSyncExternalStore as useSyncExternalStore5 } from "react";
1762
+ function useStoredAnnotations(store) {
1763
+ const source = useMemo5(
1764
+ () => ({
1765
+ subscribe: (listener) => store.subscribe(listener),
1766
+ getSnapshot: () => store.getAnnotations()
1767
+ }),
1768
+ [store]
1769
+ );
1770
+ return useSyncExternalStore5(source.subscribe, source.getSnapshot, source.getSnapshot);
1657
1771
  }
1658
1772
 
1659
1773
  // src/providerInternals/followAnnotations.ts
@@ -1686,7 +1800,7 @@ function followAnnotations({
1686
1800
  }
1687
1801
 
1688
1802
  // src/providerInternals/useAnnotationState.ts
1689
- import { useCallback as useCallback13, useMemo as useMemo5, useRef as useRef10, useState as useState9 } from "react";
1803
+ import { useCallback as useCallback13, useMemo as useMemo6, useRef as useRef11, useState as useState10, useSyncExternalStore as useSyncExternalStore6 } from "react";
1690
1804
  import { createValueSource } from "@waveform-playlist/core";
1691
1805
 
1692
1806
  // src/utils/annotationLookup.ts
@@ -1742,20 +1856,11 @@ function createAnnotationLookup() {
1742
1856
  };
1743
1857
  }
1744
1858
 
1745
- // src/utils/isDevelopmentBuild.ts
1746
- function isDevelopmentBuild() {
1747
- try {
1748
- return process.env.NODE_ENV !== "production";
1749
- } catch (e) {
1750
- return false;
1751
- }
1752
- }
1753
-
1754
1859
  // src/providerInternals/useAnnotationState.ts
1755
1860
  function useFollowedOption(prop) {
1756
1861
  const wanted = prop != null ? prop : false;
1757
- const [value, setValue] = useState9(wanted);
1758
- const [seen, setSeen] = useState9(wanted);
1862
+ const [value, setValue] = useState10(wanted);
1863
+ const [seen, setSeen] = useState10(wanted);
1759
1864
  if (seen !== wanted) {
1760
1865
  setSeen(wanted);
1761
1866
  setValue(wanted);
@@ -1763,29 +1868,35 @@ function useFollowedOption(prop) {
1763
1868
  }
1764
1869
  return [value, setValue];
1765
1870
  }
1871
+ var NO_ANNOTATIONS2 = Object.freeze([]);
1872
+ var noSubscription2 = () => () => {
1873
+ };
1874
+ var noAnnotations2 = () => NO_ANNOTATIONS2;
1766
1875
  function useAnnotationState({
1767
- annotationList,
1768
- onAnnotationsChange,
1769
- providerName
1876
+ annotationStore,
1877
+ annotationList
1770
1878
  }) {
1771
- const annotations = useMemo5(() => {
1772
- if (!(annotationList == null ? void 0 : annotationList.annotations)) return [];
1773
- if (isDevelopmentBuild() && annotationList.annotations.length > 0) {
1774
- const first = annotationList.annotations[0];
1775
- if (typeof first.start !== "number" || typeof first.end !== "number") {
1776
- console.error(
1777
- "[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: " + typeof first.start
1778
- );
1779
- return [];
1780
- }
1781
- }
1782
- return annotationList.annotations;
1783
- }, [annotationList == null ? void 0 : annotationList.annotations]);
1784
- const annotationsRef = useRef10(annotations);
1785
- annotationsRef.current = annotations;
1786
- const [annotationLookup] = useState9(() => createAnnotationLookup());
1787
- const [activeAnnotationId, setActiveAnnotationIdState] = useState9(null);
1788
- const activeAnnotationIdRef = useRef10(null);
1879
+ const source = useMemo6(
1880
+ () => annotationStore ? {
1881
+ subscribe: (listener) => annotationStore.subscribe(listener),
1882
+ getSnapshot: () => annotationStore.getAnnotations()
1883
+ } : { subscribe: noSubscription2, getSnapshot: noAnnotations2 },
1884
+ [annotationStore]
1885
+ );
1886
+ const annotations = useSyncExternalStore6(
1887
+ source.subscribe,
1888
+ source.getSnapshot,
1889
+ source.getSnapshot
1890
+ );
1891
+ const storeRef = useRef11(annotationStore);
1892
+ storeRef.current = annotationStore;
1893
+ const getAnnotations = useCallback13(
1894
+ () => storeRef.current ? storeRef.current.getAnnotations() : NO_ANNOTATIONS2,
1895
+ []
1896
+ );
1897
+ const [annotationLookup] = useState10(() => createAnnotationLookup());
1898
+ const [activeAnnotationId, setActiveAnnotationIdState] = useState10(null);
1899
+ const activeAnnotationIdRef = useRef11(null);
1789
1900
  const setActiveAnnotationId = useCallback13((value) => {
1790
1901
  activeAnnotationIdRef.current = value;
1791
1902
  setActiveAnnotationIdState(value);
@@ -1793,7 +1904,7 @@ function useAnnotationState({
1793
1904
  const [continuousPlay, setContinuousPlayState] = useFollowedOption(
1794
1905
  annotationList == null ? void 0 : annotationList.isContinuousPlay
1795
1906
  );
1796
- const continuousPlayRef = useRef10(continuousPlay);
1907
+ const continuousPlayRef = useRef11(continuousPlay);
1797
1908
  continuousPlayRef.current = continuousPlay;
1798
1909
  const setContinuousPlay = useCallback13(
1799
1910
  (value) => {
@@ -1804,36 +1915,18 @@ function useAnnotationState({
1804
1915
  );
1805
1916
  const [editable, setAnnotationsEditable] = useFollowedOption(annotationList == null ? void 0 : annotationList.editable);
1806
1917
  const [linkEndpoints, setLinkEndpoints] = useFollowedOption(annotationList == null ? void 0 : annotationList.linkEndpoints);
1807
- const annotationsValue = useMemo5(() => ({ annotations }), [annotations]);
1808
- const annotationOptionsValue = useMemo5(
1918
+ const annotationsValue = useMemo6(() => ({ annotations }), [annotations]);
1919
+ const annotationOptionsValue = useMemo6(
1809
1920
  () => ({ editable, linkEndpoints, continuousPlay }),
1810
1921
  [editable, linkEndpoints, continuousPlay]
1811
1922
  );
1812
- const [annotationPreview] = useState9(
1923
+ const [annotationPreview] = useState10(
1813
1924
  () => createValueSource(null)
1814
1925
  );
1815
- const onAnnotationsChangeRef = useRef10(onAnnotationsChange);
1816
- onAnnotationsChangeRef.current = onAnnotationsChange;
1817
- const setAnnotations = useCallback13(
1818
- (action) => {
1819
- const updated = typeof action === "function" ? action(annotationsRef.current) : action;
1820
- if (!onAnnotationsChangeRef.current) {
1821
- if (isDevelopmentBuild()) {
1822
- console.warn(
1823
- "waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to " + providerName + " to handle annotation updates."
1824
- );
1825
- }
1826
- return;
1827
- }
1828
- onAnnotationsChangeRef.current(updated);
1829
- },
1830
- [providerName]
1831
- );
1832
1926
  return {
1833
1927
  annotations,
1834
- annotationsRef,
1928
+ getAnnotations,
1835
1929
  annotationLookup,
1836
- setAnnotations,
1837
1930
  annotationPreview,
1838
1931
  activeAnnotationId,
1839
1932
  activeAnnotationIdRef,
@@ -1849,9 +1942,9 @@ function useAnnotationState({
1849
1942
  }
1850
1943
 
1851
1944
  // src/providerInternals/useFrameCallbacks.ts
1852
- import { useCallback as useCallback14, useRef as useRef11 } from "react";
1945
+ import { useCallback as useCallback14, useRef as useRef12 } from "react";
1853
1946
  function useFrameCallbacks() {
1854
- const callbacksRef = useRef11(/* @__PURE__ */ new Map());
1947
+ const callbacksRef = useRef12(/* @__PURE__ */ new Map());
1855
1948
  const registerFrameCallback = useCallback14((id, cb) => {
1856
1949
  callbacksRef.current.set(id, cb);
1857
1950
  }, []);
@@ -1867,15 +1960,15 @@ function useFrameCallbacks() {
1867
1960
  }
1868
1961
 
1869
1962
  // src/providerInternals/useScrollFollow.ts
1870
- import { useCallback as useCallback15, useRef as useRef12, useState as useState10 } from "react";
1963
+ import { useCallback as useCallback15, useRef as useRef13, useState as useState11 } from "react";
1871
1964
  function centrePlayhead(container, time, sampleRate, samplesPerPixel) {
1872
1965
  const pixelPosition = time * sampleRate / samplesPerPixel;
1873
1966
  container.scrollLeft = Math.round(Math.max(0, pixelPosition - container.clientWidth / 2));
1874
1967
  }
1875
1968
  function useScrollFollow(initialAutomaticScroll) {
1876
- const scrollContainerRef = useRef12(null);
1877
- const [isAutomaticScroll, setIsAutomaticScroll] = useState10(initialAutomaticScroll);
1878
- const isAutomaticScrollRef = useRef12(initialAutomaticScroll);
1969
+ const scrollContainerRef = useRef13(null);
1970
+ const [isAutomaticScroll, setIsAutomaticScroll] = useState11(initialAutomaticScroll);
1971
+ const isAutomaticScrollRef = useRef13(initialAutomaticScroll);
1879
1972
  const setScrollContainer = useCallback15((element) => {
1880
1973
  scrollContainerRef.current = element;
1881
1974
  }, []);
@@ -1893,11 +1986,11 @@ function useScrollFollow(initialAutomaticScroll) {
1893
1986
  }
1894
1987
 
1895
1988
  // src/providerInternals/useMergedTheme.ts
1896
- import { useMemo as useMemo6 } from "react";
1989
+ import { useMemo as useMemo7 } from "react";
1897
1990
  import { defaultTheme } from "@waveform-playlist/ui-components";
1898
1991
 
1899
1992
  // src/hooks/useShallowStable.ts
1900
- import { useRef as useRef13 } from "react";
1993
+ import { useRef as useRef14 } from "react";
1901
1994
  function shallowEqual(a, b) {
1902
1995
  if (a === b) return true;
1903
1996
  const aKeys = Object.keys(a);
@@ -1910,7 +2003,7 @@ function shallowEqual(a, b) {
1910
2003
  );
1911
2004
  }
1912
2005
  function useShallowStable(value) {
1913
- const ref = useRef13(value);
2006
+ const ref = useRef14(value);
1914
2007
  const previous = ref.current;
1915
2008
  if (previous !== value) {
1916
2009
  if (previous === void 0 || value === void 0 || !shallowEqual(previous, value)) {
@@ -1923,11 +2016,11 @@ function useShallowStable(value) {
1923
2016
  // src/providerInternals/useMergedTheme.ts
1924
2017
  function useMergedTheme(themeProp) {
1925
2018
  const userTheme = useShallowStable(themeProp);
1926
- return useMemo6(() => __spreadValues(__spreadValues({}, defaultTheme), userTheme), [userTheme]);
2019
+ return useMemo7(() => __spreadValues(__spreadValues({}, defaultTheme), userTheme), [userTheme]);
1927
2020
  }
1928
2021
 
1929
2022
  // src/providerInternals/useTrimPreview.ts
1930
- import { useRef as useRef14, useState as useState11 } from "react";
2023
+ import { useRef as useRef15, useState as useState12 } from "react";
1931
2024
  import { createValueSource as createValueSource2 } from "@waveform-playlist/core";
1932
2025
 
1933
2026
  // src/waveformDataLoader.ts
@@ -2226,19 +2319,19 @@ function previewedClipPeaks(preview, { tracks, peaksOptions, peaksCacheRef }) {
2226
2319
  return clipPeaksFor(previewed, track.name, peaksOptions, previous).clipPeaks;
2227
2320
  }
2228
2321
  function useTrimPreview(inputs) {
2229
- const [trimPreview] = useState11(
2322
+ const [trimPreview] = useState12(
2230
2323
  () => createValueSource2(null)
2231
2324
  );
2232
- const inputsRef = useRef14(inputs);
2325
+ const inputsRef = useRef15(inputs);
2233
2326
  inputsRef.current = inputs;
2234
- const [trimPreviewPeaks] = useState11(() => ({
2327
+ const [trimPreviewPeaks] = useState12(() => ({
2235
2328
  peaksFor: (preview) => previewedClipPeaks(preview, inputsRef.current)
2236
2329
  }));
2237
2330
  return { trimPreview, trimPreviewPeaks };
2238
2331
  }
2239
2332
 
2240
2333
  // src/providerInternals/useEngineLifetime.ts
2241
- import { useCallback as useCallback16, useEffect as useEffect6, useLayoutEffect, useMemo as useMemo7, useRef as useRef15, useState as useState12 } from "react";
2334
+ import { useCallback as useCallback16, useEffect as useEffect6, useLayoutEffect as useLayoutEffect2, useMemo as useMemo8, useRef as useRef16, useState as useState13 } from "react";
2242
2335
  import {
2243
2336
  attachDecodeContext,
2244
2337
  PlaylistEngine
@@ -2364,10 +2457,10 @@ function reportBuildFailure(ctx, run, engine, error) {
2364
2457
  onError == null ? void 0 : onError(error instanceof Error ? error : new Error(String(error)));
2365
2458
  }
2366
2459
  function useKnownSampleRate(sampleRateProp) {
2367
- const [sampleRate, setSampleRateState] = useState12(
2460
+ const [sampleRate, setSampleRateState] = useState13(
2368
2461
  () => sampleRateProp != null ? sampleRateProp : PROVISIONAL_SAMPLE_RATE
2369
2462
  );
2370
- const [isSampleRateKnown, setIsSampleRateKnown] = useState12(() => sampleRateProp !== void 0);
2463
+ const [isSampleRateKnown, setIsSampleRateKnown] = useState13(() => sampleRateProp !== void 0);
2371
2464
  const setSampleRate = useCallback16((rate) => {
2372
2465
  setSampleRateState(rate);
2373
2466
  setIsSampleRateKnown(true);
@@ -2375,7 +2468,7 @@ function useKnownSampleRate(sampleRateProp) {
2375
2468
  return { sampleRate, isSampleRateKnown, setSampleRate };
2376
2469
  }
2377
2470
  function useDecodeContext(arrangement, adapterRef) {
2378
- const arrivalRef = useRef15(null);
2471
+ const arrivalRef = useRef16(null);
2379
2472
  const getDecodeContext = useCallback16(() => __async(null, null, function* () {
2380
2473
  var _a;
2381
2474
  const adapter = adapterRef.current;
@@ -2412,22 +2505,22 @@ function useDisposeKeepingPlayback(refs) {
2412
2505
  }
2413
2506
  function useEngineLifetime(options) {
2414
2507
  const { arrangement, effects, zoomLevels, sampleRateProp } = options;
2415
- const latest = useRef15(options);
2416
- useLayoutEffect(() => {
2508
+ const latest = useRef16(options);
2509
+ useLayoutEffect2(() => {
2417
2510
  latest.current = options;
2418
2511
  });
2419
- const stableZoomLevels = useMemo7(
2512
+ const stableZoomLevels = useMemo8(
2420
2513
  () => zoomLevels,
2421
2514
  // eslint-disable-next-line react-hooks/exhaustive-deps
2422
2515
  [zoomLevels == null ? void 0 : zoomLevels.join(",")]
2423
2516
  );
2424
- const engineRef = useRef15(null);
2425
- const adapterRef = useRef15(null);
2426
- const engineBuildInFlightRef = useRef15(false);
2427
- const pendingResumeRef = useRef15(null);
2428
- const audioInitializedRef = useRef15(false);
2429
- const [engineEpoch, setEngineEpoch] = useState12(0);
2430
- const [isEngineAttached, setIsEngineAttached] = useState12(false);
2517
+ const engineRef = useRef16(null);
2518
+ const adapterRef = useRef16(null);
2519
+ const engineBuildInFlightRef = useRef16(false);
2520
+ const pendingResumeRef = useRef16(null);
2521
+ const audioInitializedRef = useRef16(false);
2522
+ const [engineEpoch, setEngineEpoch] = useState13(0);
2523
+ const [isEngineAttached, setIsEngineAttached] = useState13(false);
2431
2524
  const bumpEngineEpoch = useCallback16(() => setEngineEpoch((epoch) => epoch + 1), []);
2432
2525
  const { sampleRate, isSampleRateKnown, setSampleRate } = useKnownSampleRate(sampleRateProp);
2433
2526
  const onAssigned = useDecodeContext(arrangement, adapterRef);
@@ -2496,7 +2589,7 @@ function useEngineLifetime(options) {
2496
2589
  }
2497
2590
 
2498
2591
  // src/providerInternals/useArrangementView.ts
2499
- import { useMemo as useMemo8, useRef as useRef16, useSyncExternalStore as useSyncExternalStore4 } from "react";
2592
+ import { useMemo as useMemo9, useRef as useRef17, useSyncExternalStore as useSyncExternalStore7 } from "react";
2500
2593
  import { isLoadingClip as isLoadingClip2 } from "@waveform-playlist/core";
2501
2594
 
2502
2595
  // src/utils/placeholderPeaks.ts
@@ -2640,14 +2733,14 @@ function deriveTrackStates(tracks, mixer, previous) {
2640
2733
  return { byTrackId, result: sameItems(previous.result, states) ? previous.result : states };
2641
2734
  }
2642
2735
  function useArrangementValue(arrangement, read) {
2643
- const store = useMemo8(
2736
+ const store = useMemo9(
2644
2737
  () => ({
2645
2738
  subscribe: (listener) => arrangement.subscribe(listener),
2646
2739
  getSnapshot: () => read(arrangement)
2647
2740
  }),
2648
2741
  [arrangement, read]
2649
2742
  );
2650
- return useSyncExternalStore4(store.subscribe, store.getSnapshot, store.getSnapshot);
2743
+ return useSyncExternalStore7(store.subscribe, store.getSnapshot, store.getSnapshot);
2651
2744
  }
2652
2745
  var readMixer = (arrangement) => arrangement.getMixer();
2653
2746
  var readCanUndo = (arrangement) => arrangement.canUndo;
@@ -2658,33 +2751,33 @@ function useArrangementView(arrangement, options) {
2658
2751
  const mixer = useArrangementValue(arrangement, readMixer);
2659
2752
  const canUndo = useArrangementValue(arrangement, readCanUndo);
2660
2753
  const canRedo = useArrangementValue(arrangement, readCanRedo);
2661
- const loadedCacheRef = useRef16(EMPTY_LOADED_TRACKS);
2662
- const tracks = useMemo8(() => {
2754
+ const loadedCacheRef = useRef17(EMPTY_LOADED_TRACKS);
2755
+ const tracks = useMemo9(() => {
2663
2756
  const next = loadedTracks(arrangementTracks, loadedCacheRef.current);
2664
2757
  loadedCacheRef.current = next.cache;
2665
2758
  return next.tracks;
2666
2759
  }, [arrangementTracks]);
2667
2760
  const { getWaveformData, version } = useWaveformDataCache(tracks, baseScale);
2668
- const peaksOptions = useMemo8(
2761
+ const peaksOptions = useMemo9(
2669
2762
  () => ({ samplesPerPixel, mono, getGeneratedWaveformData: getWaveformData }),
2670
2763
  [samplesPerPixel, mono, getWaveformData]
2671
2764
  );
2672
- const peaksCacheRef = useRef16(EMPTY_PEAKS_CACHE);
2673
- const loadedPeaks = useMemo8(() => {
2765
+ const peaksCacheRef = useRef17(EMPTY_PEAKS_CACHE);
2766
+ const loadedPeaks = useMemo9(() => {
2674
2767
  const next = derivePeaks(tracks, peaksOptions, peaksCacheRef.current);
2675
2768
  peaksCacheRef.current = next;
2676
2769
  return next;
2677
2770
  }, [tracks, peaksOptions, version]);
2678
- const rowsCacheRef = useRef16(EMPTY_ROWS);
2679
- const peaksDataArray = useMemo8(() => {
2771
+ const rowsCacheRef = useRef17(EMPTY_ROWS);
2772
+ const peaksDataArray = useMemo9(() => {
2680
2773
  const inputs = { loadedPeaks, samplesPerPixel, mono, placeholderSampleRate };
2681
2774
  const next = deriveRows(arrangementTracks, inputs, rowsCacheRef.current);
2682
2775
  rowsCacheRef.current = next;
2683
2776
  return next.result;
2684
2777
  }, [arrangementTracks, loadedPeaks, samplesPerPixel, mono, placeholderSampleRate]);
2685
- const duration = useMemo8(() => timelineDuration(tracks), [tracks]);
2686
- const statesCacheRef = useRef16(EMPTY_STATES);
2687
- const trackStates = useMemo8(() => {
2778
+ const duration = useMemo9(() => timelineDuration(tracks), [tracks]);
2779
+ const statesCacheRef = useRef17(EMPTY_STATES);
2780
+ const trackStates = useMemo9(() => {
2688
2781
  const next = deriveTrackStates(arrangementTracks, mixer, statesCacheRef.current);
2689
2782
  statesCacheRef.current = next;
2690
2783
  return next.result;
@@ -2702,7 +2795,18 @@ function useArrangementView(arrangement, options) {
2702
2795
  }
2703
2796
 
2704
2797
  // src/providerInternals/useReadyOnce.ts
2705
- import { useCallback as useCallback17, useEffect as useEffect7, useInsertionEffect, useRef as useRef17, useState as useState13 } from "react";
2798
+ import { useCallback as useCallback17, useEffect as useEffect7, useInsertionEffect, useRef as useRef18, useState as useState14 } from "react";
2799
+
2800
+ // src/utils/isDevelopmentBuild.ts
2801
+ function isDevelopmentBuild() {
2802
+ try {
2803
+ return process.env.NODE_ENV !== "production";
2804
+ } catch (e) {
2805
+ return false;
2806
+ }
2807
+ }
2808
+
2809
+ // src/providerInternals/useReadyOnce.ts
2706
2810
  var READY_EVENT = "waveform-playlist:ready";
2707
2811
  var PLAY_BEFORE_READY_WARNING = "[waveform-playlist] play() was called before the playlist was ready and did nothing: playback starts once the playlist is ready. Wait for `isReady` (usePlaylistTimeline) or the `onReady` callback before calling play().";
2708
2812
  function callOnReady({
@@ -2721,11 +2825,11 @@ function callOnReady({
2721
2825
  function useReadyOnce(options) {
2722
2826
  const { isEngineAttached, arrangement, onReadyRef, onErrorRef, trackCount, duration } = options;
2723
2827
  const { pendingCount } = useArrangementSources(arrangement);
2724
- const [hasBeenReady, setHasBeenReady] = useState13(false);
2725
- const firedRef = useRef17(false);
2828
+ const [hasBeenReady, setHasBeenReady] = useState14(false);
2829
+ const firedRef = useRef18(false);
2726
2830
  const isReady = isEngineAttached && (hasBeenReady || pendingCount === 0);
2727
- const firstReadyRef = useRef17(false);
2728
- const warnedPlayRef = useRef17(false);
2831
+ const firstReadyRef = useRef18(false);
2832
+ const warnedPlayRef = useRef18(false);
2729
2833
  useInsertionEffect(() => {
2730
2834
  if (isReady) firstReadyRef.current = true;
2731
2835
  }, [isReady]);
@@ -2749,7 +2853,7 @@ function useReadyOnce(options) {
2749
2853
  }
2750
2854
 
2751
2855
  // src/providerInternals/useArrangementEditing.ts
2752
- import { useCallback as useCallback18, useEffect as useEffect8, useMemo as useMemo9, useRef as useRef18, useState as useState14, useSyncExternalStore as useSyncExternalStore5 } from "react";
2856
+ import { useCallback as useCallback18, useEffect as useEffect8, useMemo as useMemo10, useRef as useRef19, useState as useState15, useSyncExternalStore as useSyncExternalStore8 } from "react";
2753
2857
  import { createValueSource as createValueSource3 } from "@waveform-playlist/core";
2754
2858
 
2755
2859
  // src/components/partWarnings.ts
@@ -2771,8 +2875,8 @@ function isTrackId(setter, trackId) {
2771
2875
  return false;
2772
2876
  }
2773
2877
  function useRecordingActive(arrangement) {
2774
- const recordingActiveRef = useRef18(false);
2775
- const [armed] = useState14(() => createValueSource3(null));
2878
+ const recordingActiveRef = useRef19(false);
2879
+ const [armed] = useState15(() => createValueSource3(null));
2776
2880
  const setRecordingActive = useCallback18(
2777
2881
  (active, armedTrackId2) => {
2778
2882
  var _a, _b;
@@ -2801,8 +2905,8 @@ function useRecordingActive(arrangement) {
2801
2905
  var _a, _b;
2802
2906
  return (_b = (_a = armed.source.getSnapshot()) == null ? void 0 : _a.trackId) != null ? _b : null;
2803
2907
  }, [armed]);
2804
- const armedTrackId = useSyncExternalStore5(armed.source.subscribe, getArmedTrackId);
2805
- const recordingArm = useMemo9(() => ({ armedTrackId }), [armedTrackId]);
2908
+ const armedTrackId = useSyncExternalStore8(armed.source.subscribe, getArmedTrackId);
2909
+ const recordingArm = useMemo10(() => ({ armedTrackId }), [armedTrackId]);
2806
2910
  return { setRecordingActive, recordingActiveRef, recordingArm };
2807
2911
  }
2808
2912
  function useArrangementEditing(arrangement) {
@@ -2852,7 +2956,7 @@ function useArrangementEditing(arrangement) {
2852
2956
  }
2853
2957
 
2854
2958
  // src/providerInternals/arrangementIdentity.ts
2855
- import { useEffect as useEffect9, useRef as useRef19 } from "react";
2959
+ import { useEffect as useEffect9, useRef as useRef20 } from "react";
2856
2960
  var arrangementKeys = /* @__PURE__ */ new WeakMap();
2857
2961
  var lastArrangementKey = 0;
2858
2962
  var MISSING_ARRANGEMENT_ERROR = "[waveform-playlist] WaveformPlaylistProvider needs an `arrangement` prop: an arrangement made with `useCreateArrangement`, which owns the tracks. The `tracks` and `onTracksChange` props were removed. See https://naomiaro.github.io/waveform-playlist/docs/react/upgrading";
@@ -2871,8 +2975,8 @@ function keyOf(arrangement) {
2871
2975
  var NEW_ARRANGEMENT_WARNING = "[waveform-playlist] WaveformPlaylistProvider was given a new `arrangement` prop: everything below it mounts again (a new engine, the view and its state). Keep one arrangement for the life of the playlist (`useCreateArrangement`) and change it through its methods.";
2872
2976
  function useArrangementKey(arrangement) {
2873
2977
  const key = keyOf(arrangement);
2874
- const firstKeyRef = useRef19(key);
2875
- const warnedRef = useRef19(false);
2978
+ const firstKeyRef = useRef20(key);
2979
+ const warnedRef = useRef20(false);
2876
2980
  useEffect9(() => {
2877
2981
  if (key === firstKeyRef.current || warnedRef.current) return;
2878
2982
  warnedRef.current = true;
@@ -2897,12 +3001,12 @@ var ProviderOnArrangement = ({
2897
3001
  zoomLevels,
2898
3002
  automaticScroll = false,
2899
3003
  theme: userThemeProp,
3004
+ annotationStore,
2900
3005
  annotationList,
2901
3006
  effects,
2902
3007
  trackEffects,
2903
3008
  onReady,
2904
3009
  onError,
2905
- onAnnotationsChange,
2906
3010
  soundFontCache,
2907
3011
  indefinitePlayback = false,
2908
3012
  sampleRate: sampleRateProp,
@@ -2910,15 +3014,14 @@ var ProviderOnArrangement = ({
2910
3014
  children
2911
3015
  }) => {
2912
3016
  const mergedTheme = useMergedTheme(userThemeProp);
2913
- const stableZoomLevels = useMemo10(
3017
+ const stableZoomLevels = useMemo11(
2914
3018
  () => zoomLevels,
2915
3019
  // eslint-disable-next-line react-hooks/exhaustive-deps
2916
3020
  [zoomLevels == null ? void 0 : zoomLevels.join(",")]
2917
3021
  );
2918
3022
  const {
2919
- annotationsRef,
3023
+ getAnnotations,
2920
3024
  annotationLookup,
2921
- setAnnotations,
2922
3025
  annotationPreview,
2923
3026
  activeAnnotationId,
2924
3027
  activeAnnotationIdRef,
@@ -2931,9 +3034,8 @@ var ProviderOnArrangement = ({
2931
3034
  annotationsValue,
2932
3035
  annotationOptionsValue
2933
3036
  } = useAnnotationState({
2934
- annotationList,
2935
- onAnnotationsChange,
2936
- providerName: "WaveformPlaylistProvider"
3037
+ annotationStore,
3038
+ annotationList
2937
3039
  });
2938
3040
  const {
2939
3041
  scrollContainerRef,
@@ -2943,20 +3045,20 @@ var ProviderOnArrangement = ({
2943
3045
  setAutomaticScroll
2944
3046
  } = useScrollFollow(automaticScroll);
2945
3047
  const { registerFrameCallback, unregisterFrameCallback, runFrameCallbacks } = useFrameCallbacks();
2946
- const [isPlaying, setIsPlaying] = useState15(false);
2947
- const [currentTime, setCurrentTime] = useState15(0);
2948
- const [trackReorderEpoch, setTrackReorderEpoch] = useState15(0);
2949
- const [trackDragPreview, setTrackDragPreview] = useState15(null);
2950
- const indefinitePlaybackRef = useRef20(indefinitePlayback);
3048
+ const [isPlaying, setIsPlaying] = useState16(false);
3049
+ const [currentTime, setCurrentTime] = useState16(0);
3050
+ const [trackReorderEpoch, setTrackReorderEpoch] = useState16(0);
3051
+ const [trackDragPreview, setTrackDragPreview] = useState16(null);
3052
+ const indefinitePlaybackRef = useRef21(indefinitePlayback);
2951
3053
  indefinitePlaybackRef.current = indefinitePlayback;
2952
- const isPlayingRef = useRef20(false);
3054
+ const isPlayingRef = useRef21(false);
2953
3055
  isPlayingRef.current = isPlaying;
2954
- const playStartPositionRef = useRef20(0);
2955
- const currentTimeRef = useRef20(0);
2956
- const visualTimeRef = useRef20(0);
2957
- const soundFontCacheRef = useRef20(soundFontCache);
3056
+ const playStartPositionRef = useRef21(0);
3057
+ const currentTimeRef = useRef21(0);
3058
+ const visualTimeRef = useRef21(0);
3059
+ const soundFontCacheRef = useRef21(soundFontCache);
2958
3060
  soundFontCacheRef.current = soundFontCache;
2959
- const trackEffectsRef = useRef20(trackEffects);
3061
+ const trackEffectsRef = useRef21(trackEffects);
2960
3062
  trackEffectsRef.current = trackEffects;
2961
3063
  const resolveTrackEffects = useCallback19(
2962
3064
  (trackId) => {
@@ -2965,19 +3067,19 @@ var ProviderOnArrangement = ({
2965
3067
  },
2966
3068
  []
2967
3069
  );
2968
- const onReadyRef = useRef20(onReady);
2969
- const onErrorRef = useRef20(onError);
2970
- useLayoutEffect2(() => {
3070
+ const onReadyRef = useRef21(onReady);
3071
+ const onErrorRef = useRef21(onError);
3072
+ useLayoutEffect3(() => {
2971
3073
  onReadyRef.current = onReady;
2972
3074
  onErrorRef.current = onError;
2973
3075
  });
2974
- const playbackStartTimeRef = useRef20(0);
2975
- const audioStartPositionRef = useRef20(0);
2976
- const playbackEndTimeRef = useRef20(null);
2977
- const suppressEngineStopMirrorRef = useRef20(false);
2978
- const samplesPerPixelRef = useRef20(initialSamplesPerPixel);
2979
- const isSelectionPlayRef = useRef20(false);
2980
- const playRequestIdRef = useRef20(0);
3076
+ const playbackStartTimeRef = useRef21(0);
3077
+ const audioStartPositionRef = useRef21(0);
3078
+ const playbackEndTimeRef = useRef21(null);
3079
+ const suppressEngineStopMirrorRef = useRef21(false);
3080
+ const samplesPerPixelRef = useRef21(initialSamplesPerPixel);
3081
+ const isSelectionPlayRef = useRef21(false);
3082
+ const playRequestIdRef = useRef21(0);
2981
3083
  const { animationFrameRef, startAnimationFrameLoop, stopAnimationFrameLoop } = useAnimationFrameLoop();
2982
3084
  const onBuildFailure = useCallback19(() => {
2983
3085
  if (!isPlayingRef.current) return;
@@ -2986,7 +3088,7 @@ var ProviderOnArrangement = ({
2986
3088
  visualTimeRef.current = toVisualTime(currentTimeRef.current);
2987
3089
  setCurrentTime(currentTimeRef.current);
2988
3090
  }, [stopAnimationFrameLoop]);
2989
- const followersRef = useRef20(null);
3091
+ const followersRef = useRef21(null);
2990
3092
  const seedEngine = useCallback19(
2991
3093
  (engine) => {
2992
3094
  var _a;
@@ -3036,7 +3138,7 @@ var ProviderOnArrangement = ({
3036
3138
  onErrorRef,
3037
3139
  onBuildFailure
3038
3140
  });
3039
- const sampleRateRef = useRef20(sampleRate);
3141
+ const sampleRateRef = useRef21(sampleRate);
3040
3142
  sampleRateRef.current = sampleRate;
3041
3143
  const { timeFormat, setTimeFormat } = useTimeFormat();
3042
3144
  const zoom = useZoomControls({ engineRef, initialSamplesPerPixel });
@@ -3074,7 +3176,7 @@ var ProviderOnArrangement = ({
3074
3176
  onEngineState: onSelectedTrackEngineState,
3075
3177
  selectedTrackIdRef
3076
3178
  } = useSelectedTrack({ engineRef });
3077
- const baseScale = useMemo10(
3179
+ const baseScale = useMemo11(
3078
3180
  () => Math.min(...stableZoomLevels != null ? stableZoomLevels : [256, 512, 1024, 2048, 4096, 8192]),
3079
3181
  [stableZoomLevels]
3080
3182
  );
@@ -3085,7 +3187,7 @@ var ProviderOnArrangement = ({
3085
3187
  placeholderSampleRate: isSampleRateKnown ? sampleRate : null
3086
3188
  });
3087
3189
  const { tracks, duration } = view;
3088
- const durationRef = useRef20(duration);
3190
+ const durationRef = useRef21(duration);
3089
3191
  durationRef.current = duration;
3090
3192
  const { isReady, refusePlayBeforeFirstReady } = useReadyOnce({
3091
3193
  isEngineAttached,
@@ -3145,7 +3247,7 @@ var ProviderOnArrangement = ({
3145
3247
  },
3146
3248
  [adapterRef]
3147
3249
  );
3148
- const getPlaybackTimeFallbackWarnedRef = useRef20(false);
3250
+ const getPlaybackTimeFallbackWarnedRef = useRef21(false);
3149
3251
  const getPlaybackTime = useCallback19(() => {
3150
3252
  var _a, _b;
3151
3253
  if (engineRef.current) {
@@ -3188,7 +3290,7 @@ var ProviderOnArrangement = ({
3188
3290
  },
3189
3291
  [stopAnimationFrameLoop, setCurrentTimeRefs]
3190
3292
  );
3191
- useLayoutEffect2(() => {
3293
+ useLayoutEffect3(() => {
3192
3294
  const mirror = (state) => {
3193
3295
  onSelectionEngineState(state);
3194
3296
  onLoopEngineState(state);
@@ -3229,7 +3331,7 @@ var ProviderOnArrangement = ({
3229
3331
  };
3230
3332
  runFrameCallbacks(frameData);
3231
3333
  const activeAnnotationEnded = followAnnotations({
3232
- annotations: annotationsRef.current,
3334
+ annotations: getAnnotations(),
3233
3335
  lookup: annotationLookup,
3234
3336
  time,
3235
3337
  activeId: activeAnnotationIdRef.current,
@@ -3281,7 +3383,7 @@ var ProviderOnArrangement = ({
3281
3383
  annotationLookup,
3282
3384
  // Refs and a stable function from the shared provider hooks: they never
3283
3385
  // change, and are listed because the linter cannot see that.
3284
- annotationsRef,
3386
+ getAnnotations,
3285
3387
  activeAnnotationIdRef,
3286
3388
  continuousPlayRef,
3287
3389
  isAutomaticScrollRef,
@@ -3291,7 +3393,7 @@ var ProviderOnArrangement = ({
3291
3393
  recordingActiveRef
3292
3394
  ]);
3293
3395
  const stopAnimationLoop = stopAnimationFrameLoop;
3294
- const prevContinuousPlayRef = useRef20(continuousPlay);
3396
+ const prevContinuousPlayRef = useRef21(continuousPlay);
3295
3397
  useEffect10(() => {
3296
3398
  const continuousPlayTurnedOn = continuousPlay && !prevContinuousPlayRef.current && !isSelectionPlayRef.current;
3297
3399
  prevContinuousPlayRef.current = continuousPlay;
@@ -3308,7 +3410,7 @@ var ProviderOnArrangement = ({
3308
3410
  audioStartPositionRef.current = currentPos;
3309
3411
  const boundedEnd = playbackEndTimeRef.current;
3310
3412
  const activeId = activeAnnotationIdRef.current;
3311
- const activeAnnotation = activeId ? annotationLookup.byId(annotationsRef.current, activeId) : void 0;
3413
+ const activeAnnotation = activeId ? annotationLookup.byId(getAnnotations(), activeId) : void 0;
3312
3414
  const endsWithAnnotation = boundedEnd !== null && activeAnnotation !== void 0 && Math.abs(boundedEnd - activeAnnotation.end) < 1e-6;
3313
3415
  const endTime = endsWithAnnotation ? null : boundedEnd;
3314
3416
  playbackEndTimeRef.current = endTime;
@@ -3333,7 +3435,7 @@ var ProviderOnArrangement = ({
3333
3435
  animationFrameRef,
3334
3436
  getAudioContextTime,
3335
3437
  annotationLookup,
3336
- annotationsRef,
3438
+ getAnnotations,
3337
3439
  activeAnnotationIdRef,
3338
3440
  engineRef
3339
3441
  ]);
@@ -3534,8 +3636,8 @@ var ProviderOnArrangement = ({
3534
3636
  pendingResumeRef
3535
3637
  ]
3536
3638
  );
3537
- const isPlayingValue = useMemo10(() => ({ isPlaying }), [isPlaying]);
3538
- const refsValue = useMemo10(
3639
+ const isPlayingValue = useMemo11(() => ({ isPlaying }), [isPlaying]);
3640
+ const refsValue = useMemo11(
3539
3641
  () => ({
3540
3642
  currentTimeRef,
3541
3643
  visualTimeRef,
@@ -3544,7 +3646,7 @@ var ProviderOnArrangement = ({
3544
3646
  }),
3545
3647
  [currentTimeRef, visualTimeRef, registerFrameCallback, unregisterFrameCallback]
3546
3648
  );
3547
- const engineRefsValue = useMemo10(
3649
+ const engineRefsValue = useMemo11(
3548
3650
  () => ({
3549
3651
  playbackStartTimeRef,
3550
3652
  audioStartPositionRef,
@@ -3564,25 +3666,25 @@ var ProviderOnArrangement = ({
3564
3666
  engineRef
3565
3667
  ]
3566
3668
  );
3567
- const loopValue = useMemo10(
3669
+ const loopValue = useMemo11(
3568
3670
  () => ({ isLoopEnabled, loopStart, loopEnd }),
3569
3671
  [isLoopEnabled, loopStart, loopEnd]
3570
3672
  );
3571
- const selectedTrackIdValue = useMemo10(
3673
+ const selectedTrackIdValue = useMemo11(
3572
3674
  () => ({ selectedTrackId }),
3573
3675
  [selectedTrackId]
3574
3676
  );
3575
3677
  const { canUndo, canRedo } = view;
3576
- const undoRedoValue = useMemo10(
3678
+ const undoRedoValue = useMemo11(
3577
3679
  () => ({ canUndo, canRedo }),
3578
3680
  [canUndo, canRedo]
3579
3681
  );
3580
- const selectionValue = useMemo10(
3682
+ const selectionValue = useMemo11(
3581
3683
  () => ({ selectionStart, selectionEnd }),
3582
3684
  [selectionStart, selectionEnd]
3583
3685
  );
3584
- const currentTimeValue = useMemo10(() => ({ currentTime }), [currentTime]);
3585
- const activeAnnotationValue = useMemo10(
3686
+ const currentTimeValue = useMemo11(() => ({ currentTime }), [currentTime]);
3687
+ const activeAnnotationValue = useMemo11(
3586
3688
  () => ({ activeAnnotationId }),
3587
3689
  [activeAnnotationId]
3588
3690
  );
@@ -3606,7 +3708,7 @@ var ProviderOnArrangement = ({
3606
3708
  },
3607
3709
  [play, setActiveAnnotationId, continuousPlayRef, refusePlayBeforeFirstReady]
3608
3710
  );
3609
- const controlsValue = useMemo10(
3711
+ const controlsValue = useMemo11(
3610
3712
  () => ({
3611
3713
  play,
3612
3714
  pause,
@@ -3620,8 +3722,8 @@ var ProviderOnArrangement = ({
3620
3722
  setContinuousPlay,
3621
3723
  setAnnotationsEditable,
3622
3724
  setLinkEndpoints,
3623
- setAnnotations,
3624
3725
  annotationPreview,
3726
+ annotationStore,
3625
3727
  setActiveAnnotationId,
3626
3728
  playAnnotation
3627
3729
  }),
@@ -3638,13 +3740,13 @@ var ProviderOnArrangement = ({
3638
3740
  setContinuousPlay,
3639
3741
  setAnnotationsEditable,
3640
3742
  setLinkEndpoints,
3641
- setAnnotations,
3642
3743
  annotationPreview,
3744
+ annotationStore,
3643
3745
  setActiveAnnotationId,
3644
3746
  playAnnotation
3645
3747
  ]
3646
3748
  );
3647
- const editorControlsValue = useMemo10(
3749
+ const editorControlsValue = useMemo11(
3648
3750
  () => ({
3649
3751
  setCurrentTime: setCurrentTimeControl,
3650
3752
  // Track controls (the arrangement's mix and order)
@@ -3694,7 +3796,7 @@ var ProviderOnArrangement = ({
3694
3796
  editing.setRecordingActive
3695
3797
  ]
3696
3798
  );
3697
- const viewValue = useMemo10(
3799
+ const viewValue = useMemo11(
3698
3800
  () => ({
3699
3801
  sampleRate,
3700
3802
  mono,
@@ -3702,24 +3804,24 @@ var ProviderOnArrangement = ({
3702
3804
  }),
3703
3805
  [sampleRate, mono, indefinitePlayback]
3704
3806
  );
3705
- const settingsValue = useMemo10(
3807
+ const settingsValue = useMemo11(
3706
3808
  () => ({ timeFormat, isAutomaticScroll }),
3707
3809
  [timeFormat, isAutomaticScroll]
3708
3810
  );
3709
- const zoomValue = useMemo10(
3811
+ const zoomValue = useMemo11(
3710
3812
  () => ({ samplesPerPixel, canZoomIn: zoom.canZoomIn, canZoomOut: zoom.canZoomOut }),
3711
3813
  [samplesPerPixel, zoom.canZoomIn, zoom.canZoomOut]
3712
3814
  );
3713
3815
  const { peaksDataArray, trackStates } = view;
3714
- const timelineValue = useMemo10(
3816
+ const timelineValue = useMemo11(
3715
3817
  () => ({ tracks, peaksDataArray, duration, isReady }),
3716
3818
  [tracks, peaksDataArray, duration, isReady]
3717
3819
  );
3718
- const mixerValue = useMemo10(
3820
+ const mixerValue = useMemo11(
3719
3821
  () => ({ trackStates, masterVolume }),
3720
3822
  [trackStates, masterVolume]
3721
3823
  );
3722
- const reorderPreviewValue = useMemo10(
3824
+ const reorderPreviewValue = useMemo11(
3723
3825
  () => ({ trackDragPreview, trackReorderEpoch }),
3724
3826
  [trackDragPreview, trackReorderEpoch]
3725
3827
  );
@@ -3746,12 +3848,12 @@ var ProviderOnArrangement = ({
3746
3848
 
3747
3849
  // src/MediaElementPlaylistContext.tsx
3748
3850
  import {
3749
- useState as useState16,
3851
+ useState as useState17,
3750
3852
  useEffect as useEffect11,
3751
- useLayoutEffect as useLayoutEffect3,
3752
- useRef as useRef21,
3853
+ useLayoutEffect as useLayoutEffect4,
3854
+ useRef as useRef22,
3753
3855
  useCallback as useCallback20,
3754
- useMemo as useMemo11
3856
+ useMemo as useMemo12
3755
3857
  } from "react";
3756
3858
  import { ThemeProvider as ThemeProvider2 } from "styled-components";
3757
3859
 
@@ -3788,40 +3890,39 @@ var MediaElementPlaylistProvider = ({
3788
3890
  preservesPitch = true,
3789
3891
  automaticScroll = false,
3790
3892
  theme: userThemeProp,
3893
+ annotationStore,
3791
3894
  annotationList,
3792
3895
  audioContext,
3793
- onAnnotationsChange,
3794
3896
  onReady,
3795
3897
  onError,
3796
3898
  createPlayout,
3797
3899
  children
3798
3900
  }) => {
3799
3901
  const mergedTheme = useMergedTheme(userThemeProp);
3800
- const [isPlaying, setIsPlayingState] = useState16(false);
3801
- const isPlayingRef = useRef21(false);
3902
+ const [isPlaying, setIsPlayingState] = useState17(false);
3903
+ const isPlayingRef = useRef22(false);
3802
3904
  const setIsPlaying = useCallback20((playing) => {
3803
3905
  isPlayingRef.current = playing;
3804
3906
  setIsPlayingState(playing);
3805
3907
  }, []);
3806
- const [currentTime, setCurrentTime] = useState16(0);
3807
- const [isReady, setIsReady] = useState16(false);
3808
- const [playbackRate, setPlaybackRateState] = useState16(initialPlaybackRate);
3809
- const [ratePropSeen, setRatePropSeen] = useState16(initialPlaybackRate);
3908
+ const [currentTime, setCurrentTime] = useState17(0);
3909
+ const [isReady, setIsReady] = useState17(false);
3910
+ const [playbackRate, setPlaybackRateState] = useState17(initialPlaybackRate);
3911
+ const [ratePropSeen, setRatePropSeen] = useState17(initialPlaybackRate);
3810
3912
  if (!Object.is(ratePropSeen, initialPlaybackRate)) {
3811
3913
  setRatePropSeen(initialPlaybackRate);
3812
3914
  setPlaybackRateState(initialPlaybackRate);
3813
3915
  }
3814
- const playbackRateRef = useRef21(initialPlaybackRate);
3815
- const ratePropAppliedRef = useRef21(initialPlaybackRate);
3816
- useLayoutEffect3(() => {
3916
+ const playbackRateRef = useRef22(initialPlaybackRate);
3917
+ const ratePropAppliedRef = useRef22(initialPlaybackRate);
3918
+ useLayoutEffect4(() => {
3817
3919
  if (Object.is(ratePropAppliedRef.current, initialPlaybackRate)) return;
3818
3920
  ratePropAppliedRef.current = initialPlaybackRate;
3819
3921
  playbackRateRef.current = initialPlaybackRate;
3820
3922
  }, [initialPlaybackRate]);
3821
3923
  const {
3822
- annotationsRef,
3924
+ getAnnotations,
3823
3925
  annotationLookup,
3824
- setAnnotations,
3825
3926
  annotationPreview,
3826
3927
  activeAnnotationId,
3827
3928
  activeAnnotationIdRef,
@@ -3833,9 +3934,8 @@ var MediaElementPlaylistProvider = ({
3833
3934
  annotationsValue,
3834
3935
  annotationOptionsValue
3835
3936
  } = useAnnotationState({
3836
- annotationList,
3837
- onAnnotationsChange,
3838
- providerName: "MediaElementPlaylistProvider"
3937
+ annotationStore,
3938
+ annotationList
3839
3939
  });
3840
3940
  const {
3841
3941
  scrollContainerRef,
@@ -3845,27 +3945,27 @@ var MediaElementPlaylistProvider = ({
3845
3945
  setAutomaticScroll
3846
3946
  } = useScrollFollow(automaticScroll);
3847
3947
  const { registerFrameCallback, unregisterFrameCallback, runFrameCallbacks } = useFrameCallbacks();
3848
- const [selection, setSelectionState] = useState16({
3948
+ const [selection, setSelectionState] = useState17({
3849
3949
  selectionStart: 0,
3850
3950
  selectionEnd: 0
3851
3951
  });
3852
- const selectionRef = useRef21(selection);
3853
- const [samplesPerPixel] = useState16(initialSamplesPerPixel);
3952
+ const selectionRef = useRef22(selection);
3953
+ const [samplesPerPixel] = useState17(initialSamplesPerPixel);
3854
3954
  const { timeFormat, setTimeFormat } = useTimeFormat();
3855
- const playoutRef = useRef21(null);
3856
- const currentTimeRef = useRef21(0);
3857
- const samplesPerPixelRef = useRef21(initialSamplesPerPixel);
3955
+ const playoutRef = useRef22(null);
3956
+ const currentTimeRef = useRef22(0);
3957
+ const samplesPerPixelRef = useRef22(initialSamplesPerPixel);
3858
3958
  const { startAnimationFrameLoop, stopAnimationFrameLoop } = useAnimationFrameLoop();
3859
- const playStartPositionRef = useRef21(0);
3860
- const playbackEndTimeRef = useRef21(null);
3861
- const isSelectionPlayRef = useRef21(false);
3862
- const pendingPlayRef = useRef21(null);
3863
- const playoutInFlightRef = useRef21(true);
3959
+ const playStartPositionRef = useRef22(0);
3960
+ const playbackEndTimeRef = useRef22(null);
3961
+ const isSelectionPlayRef = useRef22(false);
3962
+ const pendingPlayRef = useRef22(null);
3963
+ const playoutInFlightRef = useRef22(true);
3864
3964
  const sampleRate = track.waveformData.sample_rate;
3865
3965
  const duration = track.waveformData.duration;
3866
3966
  const trackName = track.name;
3867
3967
  const trackWaveformData = track.waveformData;
3868
- const trackPeaks = useMemo11(() => {
3968
+ const trackPeaks = useMemo12(() => {
3869
3969
  try {
3870
3970
  const durationSamples = Math.ceil(trackWaveformData.duration * sampleRate);
3871
3971
  const extractedPeaks = extractPeaksFromWaveformData(
@@ -3894,7 +3994,7 @@ var MediaElementPlaylistProvider = ({
3894
3994
  }, [trackWaveformData, samplesPerPixel, sampleRate]);
3895
3995
  const trackFadeIn = useShallowStable(track.fadeIn);
3896
3996
  const trackFadeOut = useShallowStable(track.fadeOut);
3897
- const peaksDataArray = useMemo11(() => {
3997
+ const peaksDataArray = useMemo12(() => {
3898
3998
  if (!trackPeaks) return [];
3899
3999
  const clipPeaks = {
3900
4000
  clipId: "media-element-clip",
@@ -3908,8 +4008,8 @@ var MediaElementPlaylistProvider = ({
3908
4008
  };
3909
4009
  return [[clipPeaks]];
3910
4010
  }, [trackPeaks, trackName, trackFadeIn, trackFadeOut]);
3911
- const latestAudioRef = useRef21({ source: track.source, waveformData: track.waveformData });
3912
- useLayoutEffect3(() => {
4011
+ const latestAudioRef = useRef22({ source: track.source, waveformData: track.waveformData });
4012
+ useLayoutEffect4(() => {
3913
4013
  latestAudioRef.current = { source: track.source, waveformData: track.waveformData };
3914
4014
  }, [track.source, track.waveformData]);
3915
4015
  const restAt = useCallback20(
@@ -3928,9 +4028,9 @@ var MediaElementPlaylistProvider = ({
3928
4028
  },
3929
4029
  [stopAnimationFrameLoop, setIsPlaying]
3930
4030
  );
3931
- const startAnimationLoopRef = useRef21(() => {
4031
+ const startAnimationLoopRef = useRef22(() => {
3932
4032
  });
3933
- const endPlaybackIfDueRef = useRef21(() => false);
4033
+ const endPlaybackIfDueRef = useRef22(() => false);
3934
4034
  useEffect11(() => {
3935
4035
  let cancelled = false;
3936
4036
  let createdPlayout = null;
@@ -4060,7 +4160,7 @@ var MediaElementPlaylistProvider = ({
4060
4160
  const endPlaybackIfDue = useCallback20(
4061
4161
  (time) => {
4062
4162
  const activeAnnotationEnded = followAnnotations({
4063
- annotations: annotationsRef.current,
4163
+ annotations: getAnnotations(),
4064
4164
  lookup: annotationLookup,
4065
4165
  time,
4066
4166
  activeId: activeAnnotationIdRef.current,
@@ -4083,7 +4183,7 @@ var MediaElementPlaylistProvider = ({
4083
4183
  return false;
4084
4184
  },
4085
4185
  [
4086
- annotationsRef,
4186
+ getAnnotations,
4087
4187
  annotationLookup,
4088
4188
  activeAnnotationIdRef,
4089
4189
  continuousPlayRef,
@@ -4117,7 +4217,7 @@ var MediaElementPlaylistProvider = ({
4117
4217
  runFrameCallbacks,
4118
4218
  endPlaybackIfDue
4119
4219
  ]);
4120
- useLayoutEffect3(() => {
4220
+ useLayoutEffect4(() => {
4121
4221
  startAnimationLoopRef.current = startAnimationLoop;
4122
4222
  endPlaybackIfDueRef.current = endPlaybackIfDue;
4123
4223
  }, [startAnimationLoop, endPlaybackIfDue]);
@@ -4232,17 +4332,17 @@ var MediaElementPlaylistProvider = ({
4232
4332
  playoutRef.current.setPlaybackRate(clampedRate);
4233
4333
  }
4234
4334
  }, []);
4235
- const isPlayingValue = useMemo11(() => ({ isPlaying }), [isPlaying]);
4236
- const currentTimeValue = useMemo11(() => ({ currentTime }), [currentTime]);
4237
- const activeAnnotationValue = useMemo11(
4335
+ const isPlayingValue = useMemo12(() => ({ isPlaying }), [isPlaying]);
4336
+ const currentTimeValue = useMemo12(() => ({ currentTime }), [currentTime]);
4337
+ const activeAnnotationValue = useMemo12(
4238
4338
  () => ({ activeAnnotationId }),
4239
4339
  [activeAnnotationId]
4240
4340
  );
4241
- const settingsValue = useMemo11(
4341
+ const settingsValue = useMemo12(
4242
4342
  () => ({ timeFormat, isAutomaticScroll }),
4243
4343
  [timeFormat, isAutomaticScroll]
4244
4344
  );
4245
- const refsValue = useMemo11(
4345
+ const refsValue = useMemo12(
4246
4346
  () => ({
4247
4347
  currentTimeRef,
4248
4348
  visualTimeRef: currentTimeRef,
@@ -4262,7 +4362,7 @@ var MediaElementPlaylistProvider = ({
4262
4362
  },
4263
4363
  [play, setActiveAnnotationId]
4264
4364
  );
4265
- const controlsValue = useMemo11(
4365
+ const controlsValue = useMemo12(
4266
4366
  () => ({
4267
4367
  play,
4268
4368
  pause,
@@ -4276,8 +4376,8 @@ var MediaElementPlaylistProvider = ({
4276
4376
  setContinuousPlay,
4277
4377
  setAnnotationsEditable,
4278
4378
  setLinkEndpoints,
4279
- setAnnotations,
4280
4379
  annotationPreview,
4380
+ annotationStore,
4281
4381
  setActiveAnnotationId,
4282
4382
  playAnnotation
4283
4383
  }),
@@ -4294,25 +4394,25 @@ var MediaElementPlaylistProvider = ({
4294
4394
  setContinuousPlay,
4295
4395
  setAnnotationsEditable,
4296
4396
  setLinkEndpoints,
4297
- setAnnotations,
4298
4397
  annotationPreview,
4398
+ annotationStore,
4299
4399
  setActiveAnnotationId,
4300
4400
  playAnnotation
4301
4401
  ]
4302
4402
  );
4303
- const viewValue = useMemo11(
4403
+ const viewValue = useMemo12(
4304
4404
  () => ({ sampleRate, mono: false, indefinitePlayback: false }),
4305
4405
  [sampleRate]
4306
4406
  );
4307
- const zoomValue = useMemo11(
4407
+ const zoomValue = useMemo12(
4308
4408
  () => ({ samplesPerPixel, canZoomIn: false, canZoomOut: false }),
4309
4409
  [samplesPerPixel]
4310
4410
  );
4311
- const playbackRateValue = useMemo11(
4411
+ const playbackRateValue = useMemo12(
4312
4412
  () => ({ playbackRate, setPlaybackRate }),
4313
4413
  [playbackRate, setPlaybackRate]
4314
4414
  );
4315
- const trackValue = useMemo11(
4415
+ const trackValue = useMemo12(
4316
4416
  () => ({
4317
4417
  duration,
4318
4418
  isReady,
@@ -4466,7 +4566,7 @@ var ZoomOutButton = ({
4466
4566
  };
4467
4567
 
4468
4568
  // src/components/ContextualControls.tsx
4469
- import { useRef as useRef22, useEffect as useEffect12, useId } from "react";
4569
+ import { useRef as useRef23, useEffect as useEffect12, useId } from "react";
4470
4570
  import {
4471
4571
  MasterVolumeControl as BaseMasterVolumeControl,
4472
4572
  TimeFormatSelect as BaseTimeFormatSelect,
@@ -4506,7 +4606,7 @@ var PositionDisplay = styled.span`
4506
4606
  `;
4507
4607
  var AudioPosition = ({ className }) => {
4508
4608
  var _a;
4509
- const timeRef = useRef22(null);
4609
+ const timeRef = useRef23(null);
4510
4610
  const { currentTimeRef, registerFrameCallback, unregisterFrameCallback } = usePlaybackRefs();
4511
4611
  const { isPlaying } = useIsPlaying();
4512
4612
  useCurrentTime();
@@ -4576,10 +4676,10 @@ var AutomaticScrollCheckbox = ({ className }) => {
4576
4676
  // src/components/WaveformRoot.tsx
4577
4677
  import {
4578
4678
  use as use13,
4579
- useLayoutEffect as useLayoutEffect6,
4580
- useRef as useRef29,
4581
- useState as useState20,
4582
- useMemo as useMemo19,
4679
+ useLayoutEffect as useLayoutEffect7,
4680
+ useRef as useRef30,
4681
+ useState as useState21,
4682
+ useMemo as useMemo20,
4583
4683
  useCallback as useCallback26
4584
4684
  } from "react";
4585
4685
  import { createPortal } from "react-dom";
@@ -4619,9 +4719,9 @@ function trackIdAtOffset(orderedIds, layout, heightById, y) {
4619
4719
  }
4620
4720
 
4621
4721
  // src/hooks/useTrailingActive.ts
4622
- import { useEffect as useEffect13, useState as useState17 } from "react";
4722
+ import { useEffect as useEffect13, useState as useState18 } from "react";
4623
4723
  function useTrailingActive(active, trailingMs) {
4624
- const [trailing, setTrailing] = useState17(active);
4724
+ const [trailing, setTrailing] = useState18(active);
4625
4725
  useEffect13(() => {
4626
4726
  if (active) {
4627
4727
  setTrailing(true);
@@ -4634,7 +4734,7 @@ function useTrailingActive(active, trailingMs) {
4634
4734
  }
4635
4735
 
4636
4736
  // src/hooks/useRecordingLayout.ts
4637
- import { useCallback as useCallback22, useSyncExternalStore as useSyncExternalStore6 } from "react";
4737
+ import { useCallback as useCallback22, useSyncExternalStore as useSyncExternalStore9 } from "react";
4638
4738
  var RECORDING_EXTENT_STEP_SECONDS = 10;
4639
4739
  function recordingDisplayEnd(takeEndSeconds) {
4640
4740
  const step = RECORDING_EXTENT_STEP_SECONDS;
@@ -4655,19 +4755,19 @@ function useRecordingLayout(progress, startSample, sampleRate) {
4655
4755
  () => progress && sampleRate > 0 ? recordingDisplayEnd(startSample / sampleRate + progress.getSnapshot().duration) : 0,
4656
4756
  [progress, startSample, sampleRate]
4657
4757
  );
4658
- const channelCount = useSyncExternalStore6(subscribe, getChannelCount, getChannelCount);
4659
- const displayEndSeconds = useSyncExternalStore6(subscribe, getDisplayEnd, getDisplayEnd);
4758
+ const channelCount = useSyncExternalStore9(subscribe, getChannelCount, getChannelCount);
4759
+ const displayEndSeconds = useSyncExternalStore9(subscribe, getDisplayEnd, getDisplayEnd);
4660
4760
  return { channelCount, displayEndSeconds };
4661
4761
  }
4662
4762
 
4663
4763
  // src/hooks/useTrimPreviewView.ts
4664
- import { useCallback as useCallback23, useMemo as useMemo12, useSyncExternalStore as useSyncExternalStore7 } from "react";
4764
+ import { useCallback as useCallback23, useMemo as useMemo13, useSyncExternalStore as useSyncExternalStore10 } from "react";
4665
4765
  var TRIM_EXTENT_STEP_SECONDS = RECORDING_EXTENT_STEP_SECONDS;
4666
4766
  var NO_UNSUBSCRIBE = () => {
4667
4767
  };
4668
4768
  var subscribeToNothing2 = () => NO_UNSUBSCRIBE;
4669
4769
  function useSubscribe(source) {
4670
- return useMemo12(
4770
+ return useMemo13(
4671
4771
  () => source ? (onChange) => source.subscribe(onChange) : subscribeToNothing2,
4672
4772
  [source]
4673
4773
  );
@@ -4683,8 +4783,8 @@ function usePreviewedClipPeaks(clip, trackId) {
4683
4783
  const preview2 = (_a2 = source == null ? void 0 : source.getSnapshot()) != null ? _a2 : null;
4684
4784
  return preview2 !== null && preview2.clipId === clipId && preview2.trackId === trackId ? preview2 : null;
4685
4785
  }, [source, clipId, trackId]);
4686
- const preview = useSyncExternalStore7(subscribe, getSnapshot, getSnapshot);
4687
- return useMemo12(
4786
+ const preview = useSyncExternalStore10(subscribe, getSnapshot, getSnapshot);
4787
+ return useMemo13(
4688
4788
  () => {
4689
4789
  var _a2;
4690
4790
  return preview && peaks ? (_a2 = peaks.peaksFor(preview)) != null ? _a2 : clip : clip;
@@ -4704,7 +4804,7 @@ function useTrimPreviewExtent(sampleRate, durationSeconds) {
4704
4804
  if (endSeconds <= durationSeconds) return 0;
4705
4805
  return Math.ceil(endSeconds / TRIM_EXTENT_STEP_SECONDS) * TRIM_EXTENT_STEP_SECONDS;
4706
4806
  }, [source, sampleRate, durationSeconds]);
4707
- return useSyncExternalStore7(subscribe, getSnapshot, getSnapshot);
4807
+ return useSyncExternalStore10(subscribe, getSnapshot, getSnapshot);
4708
4808
  }
4709
4809
 
4710
4810
  // src/components/WaveformRoot.tsx
@@ -4779,7 +4879,7 @@ import React17, {
4779
4879
  createElement,
4780
4880
  Fragment as Fragment2,
4781
4881
  useCallback as useCallback25,
4782
- useMemo as useMemo18
4882
+ useMemo as useMemo19
4783
4883
  } from "react";
4784
4884
  import {
4785
4885
  Playlist,
@@ -4789,11 +4889,11 @@ import {
4789
4889
  } from "@waveform-playlist/ui-components";
4790
4890
 
4791
4891
  // src/hooks/useSelectionDrag.ts
4792
- import { createContext as createContext3, memo as memo2, useLayoutEffect as useLayoutEffect5, useMemo as useMemo13, useRef as useRef24, useState as useState18 } from "react";
4892
+ import { createContext as createContext3, memo as memo2, useLayoutEffect as useLayoutEffect6, useMemo as useMemo14, useRef as useRef25, useState as useState19 } from "react";
4793
4893
  import { createValueSource as createValueSource4 } from "@waveform-playlist/core";
4794
4894
 
4795
4895
  // src/hooks/useWindowDrag.ts
4796
- import { useEffect as useEffect14, useLayoutEffect as useLayoutEffect4, useRef as useRef23 } from "react";
4896
+ import { useEffect as useEffect14, useLayoutEffect as useLayoutEffect5, useRef as useRef24 } from "react";
4797
4897
  var activeDrags = 0;
4798
4898
  var userSelectBeforeDrags = "";
4799
4899
  var webkitUserSelectBeforeDrags = "";
@@ -4815,8 +4915,8 @@ function suspendTextSelection() {
4815
4915
  };
4816
4916
  }
4817
4917
  function useWindowDrag(active, onMove, onEnd) {
4818
- const callbacksRef = useRef23({ onMove, onEnd });
4819
- useLayoutEffect4(() => {
4918
+ const callbacksRef = useRef24({ onMove, onEnd });
4919
+ useLayoutEffect5(() => {
4820
4920
  callbacksRef.current = { onMove, onEnd };
4821
4921
  });
4822
4922
  useEffect14(() => {
@@ -4860,7 +4960,7 @@ var AutomaticScrollFlag = memo2(function AutomaticScrollFlag2({
4860
4960
  flagRef
4861
4961
  }) {
4862
4962
  const { isAutomaticScroll } = usePlaylistSettings();
4863
- useLayoutEffect5(() => {
4963
+ useLayoutEffect6(() => {
4864
4964
  flagRef.current = isAutomaticScroll;
4865
4965
  });
4866
4966
  return null;
@@ -4873,12 +4973,12 @@ function useSelectionDrag({
4873
4973
  }) {
4874
4974
  const { isPlaying } = useIsPlaying();
4875
4975
  const { setSelection } = usePlaybackControls();
4876
- const [isSelecting, setIsSelecting] = useState18(false);
4877
- const automaticScrollRef = useRef24(false);
4878
- const previewHandle = useMemo13(() => createValueSource4(null), []);
4879
- const pressTimeRef = useRef24(0);
4880
- const wroteSelectionRef = useRef24(false);
4881
- const dragElementRef = useRef24(null);
4976
+ const [isSelecting, setIsSelecting] = useState19(false);
4977
+ const automaticScrollRef = useRef25(false);
4978
+ const previewHandle = useMemo14(() => createValueSource4(null), []);
4979
+ const pressTimeRef = useRef25(0);
4980
+ const wroteSelectionRef = useRef25(false);
4981
+ const dragElementRef = useRef25(null);
4882
4982
  const timeAt = (clientX) => {
4883
4983
  const element = dragElementRef.current;
4884
4984
  const x = element ? clampedOffsetX(element, clientX) : null;
@@ -4969,8 +5069,8 @@ import React9, {
4969
5069
  createContext as createContext6,
4970
5070
  useCallback as useCallback24,
4971
5071
  use as use5,
4972
- useMemo as useMemo15,
4973
- useSyncExternalStore as useSyncExternalStore8
5072
+ useMemo as useMemo16,
5073
+ useSyncExternalStore as useSyncExternalStore11
4974
5074
  } from "react";
4975
5075
  import {
4976
5076
  Track as TrackComponent,
@@ -4986,7 +5086,7 @@ import {
4986
5086
  } from "@waveform-playlist/core";
4987
5087
 
4988
5088
  // src/contexts/ClipInteractionContext.tsx
4989
- import { createContext as createContext5, use as use4, useMemo as useMemo14 } from "react";
5089
+ import { createContext as createContext5, use as use4, useMemo as useMemo15 } from "react";
4990
5090
  import { jsx as jsx6 } from "react/jsx-runtime";
4991
5091
  var NO_CLIP_INTERACTION = { enabled: false, touchOptimized: false };
4992
5092
  var ClipInteractionContext = createContext5(NO_CLIP_INTERACTION);
@@ -4998,7 +5098,7 @@ var ClipInteractionOptions = ({
4998
5098
  const inherited = use4(ClipInteractionContext);
4999
5099
  const enabled = enabledProp != null ? enabledProp : inherited.enabled;
5000
5100
  const touchOptimized = touchOptimizedProp != null ? touchOptimizedProp : inherited.touchOptimized;
5001
- const value = useMemo14(() => ({ enabled, touchOptimized }), [enabled, touchOptimized]);
5101
+ const value = useMemo15(() => ({ enabled, touchOptimized }), [enabled, touchOptimized]);
5002
5102
  return /* @__PURE__ */ jsx6(ClipInteractionContext, { value, children });
5003
5103
  };
5004
5104
  function useClipInteraction() {
@@ -5009,7 +5109,7 @@ function useClipInteractionEnabled() {
5009
5109
  }
5010
5110
 
5011
5111
  // src/components/ChannelWithProgress.tsx
5012
- import { useId as useId2, useRef as useRef25, useEffect as useEffect15 } from "react";
5112
+ import { useId as useId2, useRef as useRef26, useEffect as useEffect15 } from "react";
5013
5113
  import styled3 from "styled-components";
5014
5114
  import {
5015
5115
  clipPixelWidth as computeClipPixelWidth
@@ -5073,7 +5173,7 @@ var ClipProgress = ({
5073
5173
  height,
5074
5174
  top
5075
5175
  }) => {
5076
- const progressRef = useRef25(null);
5176
+ const progressRef = useRef26(null);
5077
5177
  const callbackId = useId2();
5078
5178
  const { currentTimeRef, visualTimeRef, registerFrameCallback, unregisterFrameCallback } = usePlaybackRefs();
5079
5179
  const { isPlaying } = useIsPlaying();
@@ -5309,7 +5409,7 @@ var RecordingPreviewClip = ({
5309
5409
  const source = recordingState.progress;
5310
5410
  const subscribe = useCallback24((onChange) => source.subscribe(onChange), [source]);
5311
5411
  const getSnapshot = useCallback24(() => source.getSnapshot(), [source]);
5312
- const progress = useSyncExternalStore8(subscribe, getSnapshot, getSnapshot);
5412
+ const progress = useSyncExternalStore11(subscribe, getSnapshot, getSnapshot);
5313
5413
  const durationSamples = Math.floor(progress.duration * sampleRate);
5314
5414
  const latencyOffsetSamples = resolveRecordingOffsetSamples({
5315
5415
  overrideSeconds: recordingState.latencyOffset,
@@ -5519,7 +5619,7 @@ var WaveformTracks = ({ gainScaled = false, children }) => {
5519
5619
  const { selectTrack } = rows;
5520
5620
  const registerSpectrogramCanvas = spectrogram == null ? void 0 : spectrogram.registerSpectrogramCanvas;
5521
5621
  const unregisterSpectrogramCanvas = spectrogram == null ? void 0 : spectrogram.unregisterSpectrogramCanvas;
5522
- const clipDisplay = useMemo15(
5622
+ const clipDisplay = useMemo16(
5523
5623
  () => ({
5524
5624
  gainScaledWaveforms: gainScaled,
5525
5625
  showFades,
@@ -5565,7 +5665,7 @@ var WaveformTracks = ({ gainScaled = false, children }) => {
5565
5665
  };
5566
5666
 
5567
5667
  // src/components/TrackControlsColumn.tsx
5568
- import React12, { use as use9, useMemo as useMemo16, useRef as useRef27, useState as useState19 } from "react";
5668
+ import React12, { use as use9, useMemo as useMemo17, useRef as useRef28, useState as useState20 } from "react";
5569
5669
  import { useTheme as useTheme3 } from "@waveform-playlist/ui-components";
5570
5670
 
5571
5671
  // src/components/DefaultTrackControls.tsx
@@ -5871,7 +5971,7 @@ function DefaultTrackControlsImpl({ children }) {
5871
5971
  var DefaultTrackControls = React11.memo(DefaultTrackControlsImpl);
5872
5972
 
5873
5973
  // src/utils/stableTemplate.ts
5874
- import { isValidElement, useRef as useRef26 } from "react";
5974
+ import { isValidElement, useRef as useRef27 } from "react";
5875
5975
  function sameStyle(a, b) {
5876
5976
  if (Object.is(a, b)) return true;
5877
5977
  if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
@@ -5901,7 +6001,7 @@ function sameTemplate(a, b) {
5901
6001
  return false;
5902
6002
  }
5903
6003
  function useStableTemplate(template) {
5904
- const kept = useRef26(template);
6004
+ const kept = useRef27(template);
5905
6005
  if (!sameTemplate(kept.current, template)) {
5906
6006
  kept.current = template;
5907
6007
  }
@@ -5944,9 +6044,9 @@ function TrackControlsSlotImpl({
5944
6044
  } = useEditorControls();
5945
6045
  const theme = useTheme3();
5946
6046
  const shared = use9(TrackControlsSharedContext);
5947
- const indexRef = useRef27(index);
6047
+ const indexRef = useRef28(index);
5948
6048
  indexRef.current = index;
5949
- const actions = useMemo16(
6049
+ const actions = useMemo17(
5950
6050
  () => ({
5951
6051
  setMuted: (value2) => setTrackMute(trackId, value2),
5952
6052
  setSoloed: (value2) => setTrackSolo(trackId, value2),
@@ -5970,7 +6070,7 @@ function TrackControlsSlotImpl({
5970
6070
  shared
5971
6071
  ]
5972
6072
  );
5973
- const value = useMemo16(
6073
+ const value = useMemo17(
5974
6074
  () => __spreadValues({
5975
6075
  id: trackId,
5976
6076
  kind,
@@ -6005,9 +6105,9 @@ function TrackControlsSlotImpl({
6005
6105
  actions
6006
6106
  ]
6007
6107
  );
6008
- const elementRef = useRef27(null);
6009
- const [isDragSource, setDragSource] = useState19(false);
6010
- const wiring = useMemo16(
6108
+ const elementRef = useRef28(null);
6109
+ const [isDragSource, setDragSource] = useState20(false);
6110
+ const wiring = useMemo17(
6011
6111
  () => ({ elementRef, setDragSource, handleCount: { current: 0 } }),
6012
6112
  []
6013
6113
  );
@@ -6059,10 +6159,10 @@ function WaveformTrackControlsImpl({ children }) {
6059
6159
  const spectrogram = use9(SpectrogramIntegrationContext);
6060
6160
  const { trackStates } = usePlaylistMixer();
6061
6161
  const template = useStableTemplate(children != null ? children : DEFAULT_TEMPLATE);
6062
- const spectrogramRef = useRef27(spectrogram);
6162
+ const spectrogramRef = useRef28(spectrogram);
6063
6163
  spectrogramRef.current = spectrogram;
6064
6164
  const menuAvailable = Boolean(spectrogram == null ? void 0 : spectrogram.renderMenuItems);
6065
- const shared = useMemo16(
6165
+ const shared = useMemo17(
6066
6166
  () => ({
6067
6167
  menuAvailable,
6068
6168
  menuItems: (args) => {
@@ -6118,7 +6218,7 @@ function WaveformTrackControlsImpl({ children }) {
6118
6218
  var WaveformTrackControls = React12.memo(WaveformTrackControlsImpl);
6119
6219
 
6120
6220
  // src/components/VisualizationOverlays.tsx
6121
- import React14, { use as use10, useSyncExternalStore as useSyncExternalStore9 } from "react";
6221
+ import React14, { use as use10, useSyncExternalStore as useSyncExternalStore12 } from "react";
6122
6222
  import {
6123
6223
  Selection,
6124
6224
  TimescaleLoopRegion,
@@ -6126,7 +6226,7 @@ import {
6126
6226
  } from "@waveform-playlist/ui-components";
6127
6227
 
6128
6228
  // src/components/AnimatedPlayhead.tsx
6129
- import { useRef as useRef28, useEffect as useEffect17, useId as useId3 } from "react";
6229
+ import { useRef as useRef29, useEffect as useEffect17, useId as useId3 } from "react";
6130
6230
  import styled5 from "styled-components";
6131
6231
  import { usePlaylistInfo as usePlaylistInfo3 } from "@waveform-playlist/ui-components";
6132
6232
  import { jsx as jsx12 } from "react/jsx-runtime";
@@ -6145,7 +6245,7 @@ var PlayheadLine = styled5.div.attrs((props) => ({
6145
6245
  will-change: transform;
6146
6246
  `;
6147
6247
  var AnimatedPlayhead = ({ color = "#ff0000" }) => {
6148
- const playheadRef = useRef28(null);
6248
+ const playheadRef = useRef29(null);
6149
6249
  const frameCallbackId = useId3();
6150
6250
  const { currentTimeRef, visualTimeRef, registerFrameCallback, unregisterFrameCallback } = usePlaybackRefs();
6151
6251
  const { isPlaying } = useIsPlaying();
@@ -6189,7 +6289,7 @@ var WaveformSelection = React14.memo(function WaveformSelection2() {
6189
6289
  const { sampleRate } = usePlaylistView();
6190
6290
  const { samplesPerPixel } = usePlaylistZoom();
6191
6291
  const previewSource = use10(SelectionPreviewContext);
6192
- const preview = useSyncExternalStore9(
6292
+ const preview = useSyncExternalStore12(
6193
6293
  previewSource ? (onChange) => previewSource.subscribe(onChange) : subscribeToNothing3,
6194
6294
  previewSource ? () => previewSource.getSnapshot() : noPreview,
6195
6295
  previewSource ? () => previewSource.getSnapshot() : noPreview
@@ -6271,7 +6371,7 @@ var WaveformLoopRegion = React14.memo(function WaveformLoopRegion2() {
6271
6371
  });
6272
6372
 
6273
6373
  // src/components/WaveformViewOptions.tsx
6274
- import { createContext as createContext8, use as use11, useMemo as useMemo17 } from "react";
6374
+ import { createContext as createContext8, use as use11, useMemo as useMemo18 } from "react";
6275
6375
  import {
6276
6376
  DEFAULT_BAR_GAP,
6277
6377
  DEFAULT_BAR_WIDTH,
@@ -6296,7 +6396,7 @@ var WaveformViewOptions = ({
6296
6396
  const roundedBars = ownRoundedBars != null ? ownRoundedBars : above.roundedBars;
6297
6397
  const progressBarWidth = ownProgressBarWidth != null ? ownProgressBarWidth : above.progressBarWidth;
6298
6398
  const fillViewport = ownFillViewport != null ? ownFillViewport : above.fillViewport;
6299
- const value = useMemo17(
6399
+ const value = useMemo18(
6300
6400
  () => ({ waveHeight, barWidth, barGap, roundedBars, progressBarWidth, fillViewport }),
6301
6401
  [waveHeight, barWidth, barGap, roundedBars, progressBarWidth, fillViewport]
6302
6402
  );
@@ -6450,7 +6550,7 @@ function keyedByKind(parts) {
6450
6550
  });
6451
6551
  }
6452
6552
  function useWaveformParts(children) {
6453
- return useMemo18(() => {
6553
+ return useMemo19(() => {
6454
6554
  const sorted = sortWaveformParts(children);
6455
6555
  return {
6456
6556
  // One element per place. The tracks-area and controls parts are its
@@ -6500,7 +6600,7 @@ function useWaveformFrame({
6500
6600
  preview: selectionPreview,
6501
6601
  automaticScrollRef
6502
6602
  } = useSelectionDrag({ samplesPerPixel, sampleRate, onPress, onClickWhileStopped });
6503
- const playlistInfo = useMemo18(
6603
+ const playlistInfo = useMemo19(
6504
6604
  () => ({
6505
6605
  samplesPerPixel,
6506
6606
  sampleRate,
@@ -6522,7 +6622,7 @@ function useWaveformFrame({
6522
6622
  progressBarWidth
6523
6623
  ]
6524
6624
  );
6525
- const extent = useMemo18(
6625
+ const extent = useMemo19(
6526
6626
  () => ({ displayDuration, tracksFullWidth }),
6527
6627
  [displayDuration, tracksFullWidth]
6528
6628
  );
@@ -6573,7 +6673,7 @@ var WaveformRoot = ({ className, children }) => {
6573
6673
  const spectrogram = use13(SpectrogramIntegrationContext);
6574
6674
  const parts = useWaveformParts(children);
6575
6675
  const { showClipHeaders, recordingState } = parts.tracksOptions;
6576
- const spectrogramHelpersById = useMemo19(() => {
6676
+ const spectrogramHelpersById = useMemo20(() => {
6577
6677
  const helpers = /* @__PURE__ */ new Map();
6578
6678
  if (!spectrogram) return helpers;
6579
6679
  tracks.forEach((track) => {
@@ -6594,7 +6694,7 @@ var WaveformRoot = ({ className, children }) => {
6594
6694
  });
6595
6695
  return helpers;
6596
6696
  }, [tracks, spectrogram]);
6597
- const renderModeById = useMemo19(() => {
6697
+ const renderModeById = useMemo20(() => {
6598
6698
  const modes = /* @__PURE__ */ new Map();
6599
6699
  tracks.forEach((track) => {
6600
6700
  var _a2;
@@ -6614,12 +6714,12 @@ var WaveformRoot = ({ className, children }) => {
6614
6714
  const recordingTrackId = (recordingState == null ? void 0 : recordingState.isRecording) ? recordingState.trackId : null;
6615
6715
  const trimPreviewEnd = useTrimPreviewExtent(sampleRate, duration);
6616
6716
  const recordingChannelCount = recordingProgress ? mono ? 1 : recordingLayout.channelCount : 0;
6617
- const [settingsModalTrackId, setSettingsModalTrackId] = useState20(null);
6717
+ const [settingsModalTrackId, setSettingsModalTrackId] = useState21(null);
6618
6718
  const closeSettingsModal = useCallback26(() => setSettingsModalTrackId(null), []);
6619
- const [scrollContainerElement, setScrollContainerElement] = useState20(null);
6719
+ const [scrollContainerElement, setScrollContainerElement] = useState21(null);
6620
6720
  const fillsContainer = indefinitePlayback || fillViewport;
6621
- const [scrollContainerWidth, setScrollContainerWidth] = useState20(0);
6622
- useLayoutEffect6(() => {
6721
+ const [scrollContainerWidth, setScrollContainerWidth] = useState21(0);
6722
+ useLayoutEffect7(() => {
6623
6723
  if (!fillsContainer || !scrollContainerElement) return;
6624
6724
  const measure = () => setScrollContainerWidth(scrollContainerElement.clientWidth);
6625
6725
  measure();
@@ -6628,7 +6728,7 @@ var WaveformRoot = ({ className, children }) => {
6628
6728
  observer.observe(scrollContainerElement);
6629
6729
  return () => observer.disconnect();
6630
6730
  }, [fillsContainer, scrollContainerElement]);
6631
- const placeholdersEndSeconds = useMemo19(() => placeholdersEnd(peaksDataArray), [peaksDataArray]);
6731
+ const placeholdersEndSeconds = useMemo20(() => placeholdersEnd(peaksDataArray), [peaksDataArray]);
6632
6732
  let displayDuration = Math.max(
6633
6733
  duration > 0 ? duration : DEFAULT_EMPTY_TRACK_DURATION,
6634
6734
  placeholdersEndSeconds
@@ -6641,7 +6741,7 @@ var WaveformRoot = ({ className, children }) => {
6641
6741
  displayDuration = Math.max(displayDuration, recordingLayout.displayEndSeconds);
6642
6742
  }
6643
6743
  displayDuration = Math.max(displayDuration, trimPreviewEnd);
6644
- const tracksRef = useRef29(tracks);
6744
+ const tracksRef = useRef30(tracks);
6645
6745
  tracksRef.current = tracks;
6646
6746
  const selectTrack = useCallback26(
6647
6747
  (trackIndex) => {
@@ -6652,7 +6752,7 @@ var WaveformRoot = ({ className, children }) => {
6652
6752
  },
6653
6753
  [setSelectedTrackId]
6654
6754
  );
6655
- const trackHeightById = useMemo19(() => {
6755
+ const trackHeightById = useMemo20(() => {
6656
6756
  const m = /* @__PURE__ */ new Map();
6657
6757
  peaksDataArray.forEach((trackClipPeaks, trackIndex) => {
6658
6758
  const track = tracks[trackIndex];
@@ -6672,21 +6772,21 @@ var WaveformRoot = ({ className, children }) => {
6672
6772
  waveHeight,
6673
6773
  showClipHeaders
6674
6774
  ]);
6675
- const displayOrderIds = useMemo19(
6775
+ const displayOrderIds = useMemo20(
6676
6776
  () => applyTrackOrderPreview(tracks, trackDragPreview).map((t) => t.id),
6677
6777
  [tracks, trackDragPreview]
6678
6778
  );
6679
- const trackLayout = useMemo19(
6779
+ const trackLayout = useMemo20(
6680
6780
  () => computeTrackLayout(displayOrderIds, trackHeightById),
6681
6781
  [displayOrderIds, trackHeightById]
6682
6782
  );
6683
6783
  const animateTrackLayout = useTrailingActive(trackDragPreview !== null, 200);
6684
- const rowList = useMemo19(
6784
+ const rowList = useMemo20(
6685
6785
  () => tracks.map((track) => ({ id: track.id, kind: trackKind2(track) })),
6686
6786
  [tracks]
6687
6787
  );
6688
6788
  const dragSourceTrackId = (_b = trackDragPreview == null ? void 0 : trackDragPreview.trackId) != null ? _b : null;
6689
- const rows = useMemo19(
6789
+ const rows = useMemo20(
6690
6790
  () => ({
6691
6791
  rows: rowList,
6692
6792
  peaksDataArray,
@@ -6855,7 +6955,7 @@ var WaveformAnnotationBoxes = React20.memo(function WaveformAnnotationBoxes2({
6855
6955
  const { annotations } = useAnnotations();
6856
6956
  const { editable, linkEndpoints } = useAnnotationOptions();
6857
6957
  const { activeAnnotationId } = useActiveAnnotation();
6858
- const { setAnnotations, annotationPreview, playAnnotation } = usePlaybackControls();
6958
+ const { annotationStore, annotationPreview, playAnnotation } = usePlaybackControls();
6859
6959
  const { sampleRate } = usePlaylistView();
6860
6960
  const { samplesPerPixel } = usePlaylistZoom();
6861
6961
  const { touchOptimized } = useClipInteraction();
@@ -6863,8 +6963,7 @@ var WaveformAnnotationBoxes = React20.memo(function WaveformAnnotationBoxes2({
6863
6963
  const shownAnnotations = useAnnotationsWithPreview(annotations, annotationPreview);
6864
6964
  const sensors = useDragSensors({ touchOptimized });
6865
6965
  const { onDragStart, onDragMove, onDragEnd } = useAnnotationDragHandlers({
6866
- annotations,
6867
- onAnnotationsChange: setAnnotations,
6966
+ store: annotationStore,
6868
6967
  preview: annotationPreview,
6869
6968
  samplesPerPixel,
6870
6969
  sampleRate,
@@ -6900,7 +6999,7 @@ var WaveformAnnotationBoxes = React20.memo(function WaveformAnnotationBoxes2({
6900
6999
  });
6901
7000
 
6902
7001
  // src/components/AnnotationList.tsx
6903
- import { use as use17, useMemo as useMemo20 } from "react";
7002
+ import { use as use17, useMemo as useMemo21 } from "react";
6904
7003
  import { jsx as jsx20 } from "react/jsx-runtime";
6905
7004
  var AnnotationList = ({
6906
7005
  height,
@@ -6913,9 +7012,9 @@ var AnnotationList = ({
6913
7012
  const { annotations } = useAnnotations();
6914
7013
  const { editable, linkEndpoints, continuousPlay } = useAnnotationOptions();
6915
7014
  const { activeAnnotationId } = useActiveAnnotation();
6916
- const { setAnnotations, annotationPreview, playAnnotation } = usePlaybackControls();
7015
+ const { annotationStore, annotationPreview, playAnnotation } = usePlaybackControls();
6917
7016
  const shownAnnotations = useAnnotationsWithPreview(annotations, annotationPreview);
6918
- const actionOptions = useMemo20(
7017
+ const actionOptions = useMemo21(
6919
7018
  () => ({ linkEndpoints, continuousPlay }),
6920
7019
  [linkEndpoints, continuousPlay]
6921
7020
  );
@@ -6941,7 +7040,7 @@ var AnnotationList = ({
6941
7040
  annotationListConfig: actionOptions,
6942
7041
  height,
6943
7042
  onAnnotationClick: playAnnotation,
6944
- onAnnotationUpdate: setAnnotations,
7043
+ store: annotationStore,
6945
7044
  renderAnnotationItem: children
6946
7045
  }
6947
7046
  );
@@ -6979,7 +7078,7 @@ var Waveform = (props) => composeWaveform(__spreadProps(__spreadValues({}, props
6979
7078
  var WaveformEditor = (props) => composeWaveform(__spreadProps(__spreadValues({}, props), { tracks: TRACKS_WITH_HEADERS_AND_FADES }));
6980
7079
 
6981
7080
  // src/components/MediaElementWaveformRoot.tsx
6982
- import { useCallback as useCallback27, useMemo as useMemo21 } from "react";
7081
+ import { useCallback as useCallback27, useMemo as useMemo22 } from "react";
6983
7082
  import { DevicePixelRatioProvider as DevicePixelRatioProvider2, CLIP_HEADER_HEIGHT as CLIP_HEADER_HEIGHT2 } from "@waveform-playlist/ui-components";
6984
7083
  import { jsx as jsx22 } from "react/jsx-runtime";
6985
7084
  var ONE_ROW = [{ id: MEDIA_ELEMENT_TRACK_ID, kind: "audio" }];
@@ -7003,7 +7102,7 @@ var MediaElementWaveformRoot = ({
7003
7102
  );
7004
7103
  }
7005
7104
  const { showClipHeaders } = parts.tracksOptions;
7006
- const rows = useMemo21(() => {
7105
+ const rows = useMemo22(() => {
7007
7106
  const rowList = ONE_ROW;
7008
7107
  const rowPeaks = peaksDataArray.length > 0 ? peaksDataArray : ONE_EMPTY_ROW;
7009
7108
  const trackHeightById = /* @__PURE__ */ new Map();
@@ -7083,7 +7182,7 @@ var KeyboardShortcuts = ({
7083
7182
  const { annotations: annotationList } = useAnnotations();
7084
7183
  const { linkEndpoints, continuousPlay } = useAnnotationOptions();
7085
7184
  const { activeAnnotationId } = useActiveAnnotation();
7086
- const { setAnnotations, setActiveAnnotationId, scrollContainerRef, play } = usePlaybackControls();
7185
+ const { annotationStore, setActiveAnnotationId, scrollContainerRef, play } = usePlaybackControls();
7087
7186
  const { undo, redo } = useEditorControls();
7088
7187
  const { splitClipAtPlayhead } = useClipSplitting({ samplesPerPixel });
7089
7188
  const allAdditional = [];
@@ -7110,9 +7209,8 @@ var KeyboardShortcuts = ({
7110
7209
  enabled: playback || allAdditional.length > 0
7111
7210
  }, playback ? { additionalShortcuts: allAdditional } : { shortcuts: allAdditional }));
7112
7211
  useAnnotationKeyboardControls({
7113
- annotations: annotationList,
7212
+ store: annotationStore,
7114
7213
  activeAnnotationId,
7115
- onAnnotationsChange: setAnnotations,
7116
7214
  onActiveAnnotationChange: setActiveAnnotationId,
7117
7215
  duration,
7118
7216
  linkEndpoints,
@@ -7137,7 +7235,7 @@ function useRecordingSession({ isRecording, trackId }) {
7137
7235
  }
7138
7236
 
7139
7237
  // src/components/ClipInteractionProvider.tsx
7140
- import React23, { useCallback as useCallback28, useMemo as useMemo22, useRef as useRef30 } from "react";
7238
+ import React23, { useCallback as useCallback28, useMemo as useMemo23, useRef as useRef31 } from "react";
7141
7239
  import { flushSync as flushSync2 } from "react-dom";
7142
7240
  import { DragDropProvider as DragDropProvider2 } from "@dnd-kit/react";
7143
7241
  import { RestrictToHorizontalAxis as RestrictToHorizontalAxis2 } from "@dnd-kit/abstract/modifiers";
@@ -7244,7 +7342,7 @@ var ClipInteractionProvider = ({
7244
7342
  const beatsAndBars = useBeatsAndBars();
7245
7343
  const useBeatsSnap = snap && beatsAndBars != null && beatsAndBars.scaleMode === "beats" && beatsAndBars.snapTo !== "off";
7246
7344
  const useTimescaleSnap = snap && !useBeatsSnap;
7247
- const snapSamplePosition = useMemo22(() => {
7345
+ const snapSamplePosition = useMemo23(() => {
7248
7346
  if (useBeatsSnap && beatsAndBars) {
7249
7347
  const { bpm, timeSignature, snapTo } = beatsAndBars;
7250
7348
  const gridTicks = snapTo === "bar" ? ticksPerBar2(timeSignature) : ticksPerBeat2(timeSignature);
@@ -7260,7 +7358,7 @@ var ClipInteractionProvider = ({
7260
7358
  }
7261
7359
  return void 0;
7262
7360
  }, [useBeatsSnap, useTimescaleSnap, beatsAndBars, sampleRate, samplesPerPixel]);
7263
- const tracksRef = useRef30(tracks);
7361
+ const tracksRef = useRef31(tracks);
7264
7362
  tracksRef.current = tracks;
7265
7363
  const getTracks = useCallback28(() => tracksRef.current, []);
7266
7364
  const sensors = useDragSensors({ touchOptimized });
@@ -7324,7 +7422,7 @@ var ClipInteractionProvider = ({
7324
7422
  },
7325
7423
  [onDragEnd, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview]
7326
7424
  );
7327
- const modifiers = useMemo22(() => {
7425
+ const modifiers = useMemo23(() => {
7328
7426
  const mods = [RestrictToHorizontalAxis2];
7329
7427
  if (useBeatsSnap && beatsAndBars) {
7330
7428
  mods.push(
@@ -7432,6 +7530,7 @@ export {
7432
7530
  useClipDragHandlers,
7433
7531
  useClipInteractionEnabled,
7434
7532
  useClipSplitting,
7533
+ useCreateAnnotationStore,
7435
7534
  useCreateArrangement,
7436
7535
  useCurrentTime,
7437
7536
  useDragSensors,
@@ -7455,6 +7554,7 @@ export {
7455
7554
  useSelectedTrackId,
7456
7555
  useSelection,
7457
7556
  useSpectrogramIntegration,
7557
+ useStoredAnnotations,
7458
7558
  useTimeFormat,
7459
7559
  useTrack,
7460
7560
  useTrackReorderHandle,