@waveform-playlist/browser 15.3.4 → 15.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -107,6 +107,7 @@ __export(index_exports, {
107
107
  SkipBackwardButton: () => SkipBackwardButton,
108
108
  SkipForwardButton: () => SkipForwardButton,
109
109
  SnapToGridModifier: () => SnapToGridModifier,
110
+ SortableTrackControls: () => SortableTrackControls,
110
111
  SpectrogramIntegrationProvider: () => SpectrogramIntegrationProvider,
111
112
  StopButton: () => StopButton,
112
113
  TimeFormatSelect: () => TimeFormatSelect,
@@ -670,7 +671,7 @@ function useClipDragHandlers({
670
671
  (event) => {
671
672
  var _a;
672
673
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
673
- if (!data) return;
674
+ if (!data || data.kind === "track-reorder") return;
674
675
  if (!data.boundary) {
675
676
  originalClipStateRef.current = null;
676
677
  if (engineRef.current) {
@@ -706,7 +707,7 @@ function useClipDragHandlers({
706
707
  (event) => {
707
708
  var _a, _b, _c;
708
709
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
709
- if (!data) return;
710
+ if (!data || data.kind === "track-reorder") return;
710
711
  if (!data.boundary) return;
711
712
  if (!originalClipStateRef.current) return;
712
713
  const { boundary, trackIndex, clipIndex } = data;
@@ -766,10 +767,12 @@ function useClipDragHandlers({
766
767
  );
767
768
  const onDragEnd = import_react8.default.useCallback(
768
769
  (event) => {
769
- var _a, _b, _c, _d, _e, _f, _g;
770
+ var _a, _b, _c, _d, _e, _f, _g, _h;
771
+ const kindData = (_a = event.operation.source) == null ? void 0 : _a.data;
772
+ if ((kindData == null ? void 0 : kindData.kind) === "track-reorder") return;
770
773
  if (event.canceled) {
771
774
  if (originalClipStateRef.current) {
772
- const cancelData = (_a = event.operation.source) == null ? void 0 : _a.data;
775
+ const cancelData = (_b = event.operation.source) == null ? void 0 : _b.data;
773
776
  if (cancelData) {
774
777
  const { trackIndex: trackIndex2, clipIndex } = cancelData;
775
778
  const original = originalClipStateRef.current;
@@ -791,25 +794,25 @@ function useClipDragHandlers({
791
794
  isDraggingRef.current = false;
792
795
  originalClipStateRef.current = null;
793
796
  lastBoundaryDeltaRef.current = 0;
794
- (_b = engineRef.current) == null ? void 0 : _b.abortTransaction();
797
+ (_c = engineRef.current) == null ? void 0 : _c.abortTransaction();
795
798
  return;
796
799
  }
797
- const data = (_c = event.operation.source) == null ? void 0 : _c.data;
800
+ const data = (_d = event.operation.source) == null ? void 0 : _d.data;
798
801
  if (!data) {
799
802
  isDraggingRef.current = false;
800
- (_d = engineRef.current) == null ? void 0 : _d.abortTransaction();
803
+ (_e = engineRef.current) == null ? void 0 : _e.abortTransaction();
801
804
  return;
802
805
  }
803
806
  const { trackIndex, clipId, boundary } = data;
804
807
  const sampleDelta = boundary ? lastBoundaryDeltaRef.current : event.operation.transform.x * samplesPerPixel;
805
- const trackId = (_e = tracks[trackIndex]) == null ? void 0 : _e.id;
808
+ const trackId = (_f = tracks[trackIndex]) == null ? void 0 : _f.id;
806
809
  if (boundary) {
807
810
  isDraggingRef.current = false;
808
811
  if (!trackId) {
809
812
  console.warn(
810
813
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 trim not synced to adapter`
811
814
  );
812
- (_f = engineRef.current) == null ? void 0 : _f.abortTransaction();
815
+ (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
813
816
  } else if (!engineRef.current) {
814
817
  console.warn("[waveform-playlist] engineRef is null \u2014 trim not synced to adapter");
815
818
  } else {
@@ -824,7 +827,7 @@ function useClipDragHandlers({
824
827
  console.warn(
825
828
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 move not synced to adapter`
826
829
  );
827
- (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
830
+ (_h = engineRef.current) == null ? void 0 : _h.abortTransaction();
828
831
  } else if (!engineRef.current) {
829
832
  console.warn("[waveform-playlist] engineRef is null \u2014 move not synced to adapter");
830
833
  } else {
@@ -1931,6 +1934,8 @@ var WaveformPlaylistProvider = ({
1931
1934
  const [linkEndpoints, setLinkEndpoints] = (0, import_react17.useState)((_b = annotationList == null ? void 0 : annotationList.linkEndpoints) != null ? _b : false);
1932
1935
  const [annotationsEditable, setAnnotationsEditable] = (0, import_react17.useState)((_c = annotationList == null ? void 0 : annotationList.editable) != null ? _c : false);
1933
1936
  const [isReady, setIsReady] = (0, import_react17.useState)(false);
1937
+ const [trackReorderEpoch, setTrackReorderEpoch] = (0, import_react17.useState)(0);
1938
+ const [trackDragPreview, setTrackDragPreview] = (0, import_react17.useState)(null);
1934
1939
  const engineRef = (0, import_react17.useRef)(null);
1935
1940
  const adapterRef = (0, import_react17.useRef)(null);
1936
1941
  const audioInitializedRef = (0, import_react17.useRef)(false);
@@ -2270,6 +2275,19 @@ var WaveformPlaylistProvider = ({
2270
2275
  if (!suppressTracksMirroring && state.tracksVersion !== lastTracksVersionRef.current) {
2271
2276
  lastTracksVersionRef.current = state.tracksVersion;
2272
2277
  engineTracksRef.current = state.tracks;
2278
+ const oldTracks = tracksRef.current;
2279
+ const oldStates = trackStatesRef.current;
2280
+ if (oldTracks.length === oldStates.length && oldTracks.length === state.tracks.length) {
2281
+ const idToState = new Map(oldTracks.map((t, i) => [t.id, oldStates[i]]));
2282
+ const reordered = state.tracks.map((t, i) => {
2283
+ var _a4;
2284
+ return (_a4 = idToState.get(t.id)) != null ? _a4 : oldStates[i];
2285
+ });
2286
+ const orderChanged = reordered.some((s, i) => s !== oldStates[i]);
2287
+ if (orderChanged) {
2288
+ setTrackStates(reordered);
2289
+ }
2290
+ }
2273
2291
  if (onTracksChange) {
2274
2292
  onTracksChange(state.tracks);
2275
2293
  } else {
@@ -2752,6 +2770,19 @@ var WaveformPlaylistProvider = ({
2752
2770
  },
2753
2771
  [trackStates]
2754
2772
  );
2773
+ const reorderTrack = (0, import_react17.useCallback)(
2774
+ (trackId, toIndex) => {
2775
+ if (!engineRef.current) {
2776
+ console.warn("[waveform-playlist] reorderTrack: engine not ready, call ignored");
2777
+ return;
2778
+ }
2779
+ engineRef.current.reorderTrack(trackId, toIndex);
2780
+ },
2781
+ [engineRef]
2782
+ );
2783
+ const bumpTrackReorderEpoch = (0, import_react17.useCallback)(() => {
2784
+ setTrackReorderEpoch((epoch) => epoch + 1);
2785
+ }, []);
2755
2786
  const setSelection = (0, import_react17.useCallback)(
2756
2787
  (start, end) => {
2757
2788
  setSelectionEngine(start, end);
@@ -2881,6 +2912,9 @@ var WaveformPlaylistProvider = ({
2881
2912
  setTrackSolo,
2882
2913
  setTrackVolume,
2883
2914
  setTrackPan,
2915
+ reorderTrack,
2916
+ bumpTrackReorderEpoch,
2917
+ setTrackDragPreview,
2884
2918
  // Selection
2885
2919
  setSelection,
2886
2920
  setSelectedTrackId: setSelectedTrackIdControl,
@@ -2923,6 +2957,9 @@ var WaveformPlaylistProvider = ({
2923
2957
  setTrackSolo,
2924
2958
  setTrackVolume,
2925
2959
  setTrackPan,
2960
+ reorderTrack,
2961
+ bumpTrackReorderEpoch,
2962
+ setTrackDragPreview,
2926
2963
  setSelection,
2927
2964
  setSelectedTrackIdControl,
2928
2965
  setTimeFormat,
@@ -2970,6 +3007,8 @@ var WaveformPlaylistProvider = ({
2970
3007
  roundedBars,
2971
3008
  progressBarWidth,
2972
3009
  isReady,
3010
+ trackReorderEpoch,
3011
+ trackDragPreview,
2973
3012
  mono,
2974
3013
  isDraggingRef,
2975
3014
  onTracksChange
@@ -2996,6 +3035,8 @@ var WaveformPlaylistProvider = ({
2996
3035
  roundedBars,
2997
3036
  progressBarWidth,
2998
3037
  isReady,
3038
+ trackReorderEpoch,
3039
+ trackDragPreview,
2999
3040
  mono,
3000
3041
  isDraggingRef,
3001
3042
  onTracksChange
@@ -3755,16 +3796,147 @@ function useClipInteractionEnabled() {
3755
3796
  }
3756
3797
 
3757
3798
  // src/components/PlaylistVisualization.tsx
3758
- var import_react26 = require("react");
3799
+ var import_react28 = require("react");
3759
3800
  var import_react_dom = require("react-dom");
3760
3801
  var import_styled_components6 = __toESM(require("styled-components"));
3761
3802
  var import_ui_components8 = require("@waveform-playlist/ui-components");
3803
+
3804
+ // src/components/SortableTrackControls.tsx
3805
+ var import_react23 = require("react");
3806
+ var import_sortable = require("@dnd-kit/react/sortable");
3807
+ var import_modifiers = require("@dnd-kit/abstract/modifiers");
3808
+
3809
+ // src/utils/dragPopoverHealer.ts
3810
+ function createDragPopoverHealer(element) {
3811
+ if (typeof element.showPopover !== "function") {
3812
+ return () => {
3813
+ };
3814
+ }
3815
+ const heal = () => {
3816
+ if (!element.isConnected || !element.hasAttribute("popover")) return;
3817
+ let open = false;
3818
+ try {
3819
+ open = element.matches(":popover-open");
3820
+ } catch (e) {
3821
+ }
3822
+ if (open) return;
3823
+ try {
3824
+ element.showPopover();
3825
+ } catch (e) {
3826
+ }
3827
+ };
3828
+ const observer = new MutationObserver(heal);
3829
+ observer.observe(element.ownerDocument.body, {
3830
+ childList: true,
3831
+ subtree: true
3832
+ });
3833
+ return () => observer.disconnect();
3834
+ }
3835
+
3836
+ // src/components/SortableTrackControls.tsx
3837
+ var import_jsx_runtime7 = require("react/jsx-runtime");
3838
+ var SortableTrackControls = ({
3839
+ trackId,
3840
+ index,
3841
+ disabled = false,
3842
+ children
3843
+ }) => {
3844
+ const { ref, handleRef, isDragSource } = (0, import_sortable.useSortable)({
3845
+ id: `track-reorder-${trackId}`,
3846
+ index,
3847
+ group: "playlist-tracks",
3848
+ type: "track",
3849
+ accept: ["track"],
3850
+ data: { kind: "track-reorder", trackId },
3851
+ modifiers: [import_modifiers.RestrictToVerticalAxis],
3852
+ disabled,
3853
+ // feedback: 'move' (NOT 'none' — see below) disables the Feedback
3854
+ // plugin's placeholder/clone splicing for this sortable while KEEPING its
3855
+ // dragOperation.shape computation alive. That plugin does raw,
3856
+ // React-bypassing DOM surgery on ANY pointer movement during an activated
3857
+ // drag (insertAdjacentElement to splice in a placeholder, then
3858
+ // `placeholder.replaceWith(element)` on drop) — confirmed via
3859
+ // MutationObserver instrumentation to relocate the React-owned row 6
3860
+ // times during a single one-slot drag, leaving its final parent/sibling
3861
+ // different from what React's fiber tree still believes. That desync is
3862
+ // permanent for the session: every later React-driven reorder (button OR
3863
+ // drag) computes the correct data but silently fails to update the DOM
3864
+ // for these rows. The placeholder splice is created only when
3865
+ // `feedback !== 'move'` (@dnd-kit/dom Feedback.ts) — 'move' keeps the
3866
+ // dragged element in the live DOM (no clone/placeholder) while still
3867
+ // running the *unconditional* `dragOperation.shape = ...` assignment.
3868
+ // `feedback: 'none'` looked like the boundary-trim precedent (Clip.tsx /
3869
+ // AnnotationBox.tsx) but is wrong here: 'none' bails out of Feedback's
3870
+ // render function BEFORE dragOperation.shape is ever set, and shape is
3871
+ // the ONLY input CollisionObserver.computeCollisions() checks — with
3872
+ // 'none', collision (and therefore sortable.index) never updates, so
3873
+ // drag-based reordering silently never commits. Boundary trims don't hit
3874
+ // this because they're plain useDraggable (no collision-based commit) —
3875
+ // sortables need shape. `isDragSource` (box-shadow lift feedback below)
3876
+ // is a reactive signal, unaffected either way. See browser/CLAUDE.md
3877
+ // "Track Reordering".
3878
+ feedback: "move"
3879
+ });
3880
+ const elementRef = (0, import_react23.useRef)(null);
3881
+ const composedRef = (0, import_react23.useCallback)(
3882
+ (element) => {
3883
+ elementRef.current = element instanceof HTMLElement ? element : null;
3884
+ ref(element);
3885
+ },
3886
+ [ref]
3887
+ );
3888
+ (0, import_react23.useEffect)(() => {
3889
+ if (!isDragSource || !elementRef.current) return void 0;
3890
+ return createDragPopoverHealer(elementRef.current);
3891
+ }, [isDragSource]);
3892
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: children({ ref: composedRef, handleRef, isDragSource }) });
3893
+ };
3894
+
3895
+ // src/utils/trackOrderPreview.ts
3896
+ function applyTrackOrderPreview(tracks, preview) {
3897
+ if (!preview) return tracks;
3898
+ const fromIndex = tracks.findIndex((t) => t.id === preview.trackId);
3899
+ if (fromIndex === -1) return tracks;
3900
+ const toIndex = Math.max(0, Math.min(tracks.length - 1, preview.toIndex));
3901
+ if (toIndex === fromIndex) return tracks;
3902
+ const next = tracks.slice();
3903
+ const [moved] = next.splice(fromIndex, 1);
3904
+ next.splice(toIndex, 0, moved);
3905
+ return next;
3906
+ }
3907
+ function computeTrackLayout(orderedIds, heightById) {
3908
+ var _a;
3909
+ const topById = /* @__PURE__ */ new Map();
3910
+ let top = 0;
3911
+ for (const id of orderedIds) {
3912
+ topById.set(id, top);
3913
+ top += (_a = heightById.get(id)) != null ? _a : 0;
3914
+ }
3915
+ return { topById, totalHeight: top };
3916
+ }
3917
+
3918
+ // src/hooks/useTrailingActive.ts
3919
+ var import_react24 = require("react");
3920
+ function useTrailingActive(active, trailingMs) {
3921
+ const [trailing, setTrailing] = (0, import_react24.useState)(active);
3922
+ (0, import_react24.useEffect)(() => {
3923
+ if (active) {
3924
+ setTrailing(true);
3925
+ return void 0;
3926
+ }
3927
+ const timer = setTimeout(() => setTrailing(false), trailingMs);
3928
+ return () => clearTimeout(timer);
3929
+ }, [active, trailingMs]);
3930
+ return trailing || active;
3931
+ }
3932
+
3933
+ // src/components/PlaylistVisualization.tsx
3762
3934
  var import_core4 = require("@waveform-playlist/core");
3763
3935
 
3764
3936
  // src/components/AnimatedPlayhead.tsx
3765
- var import_react23 = require("react");
3937
+ var import_react25 = require("react");
3766
3938
  var import_styled_components4 = __toESM(require("styled-components"));
3767
- var import_jsx_runtime7 = require("react/jsx-runtime");
3939
+ var import_jsx_runtime8 = require("react/jsx-runtime");
3768
3940
  var PlayheadLine = import_styled_components4.default.div.attrs((props) => ({
3769
3941
  style: {
3770
3942
  width: `${props.$width}px`,
@@ -3780,7 +3952,7 @@ var PlayheadLine = import_styled_components4.default.div.attrs((props) => ({
3780
3952
  will-change: transform;
3781
3953
  `;
3782
3954
  var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3783
- const playheadRef = (0, import_react23.useRef)(null);
3955
+ const playheadRef = (0, import_react25.useRef)(null);
3784
3956
  const {
3785
3957
  isPlaying,
3786
3958
  currentTimeRef,
@@ -3789,7 +3961,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3789
3961
  unregisterFrameCallback
3790
3962
  } = usePlaybackAnimation();
3791
3963
  const { samplesPerPixel, sampleRate, progressBarWidth } = usePlaylistData();
3792
- (0, import_react23.useEffect)(() => {
3964
+ (0, import_react25.useEffect)(() => {
3793
3965
  const id = "playhead";
3794
3966
  if (isPlaying) {
3795
3967
  registerFrameCallback(id, ({ visualTime, sampleRate: sr, samplesPerPixel: spp }) => {
@@ -3801,7 +3973,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3801
3973
  }
3802
3974
  return () => unregisterFrameCallback(id);
3803
3975
  }, [isPlaying, registerFrameCallback, unregisterFrameCallback]);
3804
- (0, import_react23.useEffect)(() => {
3976
+ (0, import_react25.useEffect)(() => {
3805
3977
  var _a, _b;
3806
3978
  if (!isPlaying && playheadRef.current) {
3807
3979
  const time = (_b = (_a = visualTimeRef.current) != null ? _a : currentTimeRef.current) != null ? _b : 0;
@@ -3809,15 +3981,15 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3809
3981
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
3810
3982
  }
3811
3983
  });
3812
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3984
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3813
3985
  };
3814
3986
 
3815
3987
  // src/components/ChannelWithProgress.tsx
3816
- var import_react24 = require("react");
3988
+ var import_react26 = require("react");
3817
3989
  var import_styled_components5 = __toESM(require("styled-components"));
3818
3990
  var import_core3 = require("@waveform-playlist/core");
3819
3991
  var import_ui_components7 = require("@waveform-playlist/ui-components");
3820
- var import_jsx_runtime8 = require("react/jsx-runtime");
3992
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3821
3993
  var ChannelWrapper = import_styled_components5.default.div`
3822
3994
  position: relative;
3823
3995
  `;
@@ -3871,8 +4043,8 @@ var ChannelWithProgress = (_a) => {
3871
4043
  "clipSampleRate",
3872
4044
  "clipOffsetSeconds"
3873
4045
  ]);
3874
- const progressRef = (0, import_react24.useRef)(null);
3875
- const callbackId = (0, import_react24.useId)();
4046
+ const progressRef = (0, import_react26.useRef)(null);
4047
+ const callbackId = (0, import_react26.useId)();
3876
4048
  const theme = (0, import_ui_components7.useTheme)();
3877
4049
  const { waveHeight } = (0, import_ui_components7.usePlaylistInfo)();
3878
4050
  const {
@@ -3889,7 +4061,7 @@ var ChannelWithProgress = (_a) => {
3889
4061
  clipDurationSamples,
3890
4062
  samplesPerPixel
3891
4063
  );
3892
- (0, import_react24.useEffect)(() => {
4064
+ (0, import_react26.useEffect)(() => {
3893
4065
  if (isPlaying) {
3894
4066
  registerFrameCallback(callbackId, ({ visualTime, sampleRate: sr }) => {
3895
4067
  if (progressRef.current) {
@@ -3917,7 +4089,7 @@ var ChannelWithProgress = (_a) => {
3917
4089
  registerFrameCallback,
3918
4090
  unregisterFrameCallback
3919
4091
  ]);
3920
- (0, import_react24.useEffect)(() => {
4092
+ (0, import_react26.useEffect)(() => {
3921
4093
  var _a2, _b2;
3922
4094
  if (!isPlaying && progressRef.current) {
3923
4095
  const currentTime = (_b2 = (_a2 = visualTimeRef.current) != null ? _a2 : currentTimeRef.current) != null ? _b2 : 0;
@@ -3950,9 +4122,9 @@ var ChannelWithProgress = (_a) => {
3950
4122
  const effectiveHeight = waveHeight;
3951
4123
  const effectiveTop = isBothMode ? smartChannelProps.index * waveHeight : smartChannelProps.index * waveHeight;
3952
4124
  const waveformBackgroundCss = (0, import_ui_components7.waveformColorToCss)(backgroundColor);
3953
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(ChannelWrapper, { children: [
3954
- isBothMode ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
3955
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4125
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(ChannelWrapper, { children: [
4126
+ isBothMode ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4127
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3956
4128
  Background,
3957
4129
  {
3958
4130
  $color: "#000",
@@ -3961,7 +4133,7 @@ var ChannelWithProgress = (_a) => {
3961
4133
  $width: smartChannelProps.length
3962
4134
  }
3963
4135
  ),
3964
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4136
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3965
4137
  Background,
3966
4138
  {
3967
4139
  $color: waveformBackgroundCss,
@@ -3970,7 +4142,7 @@ var ChannelWithProgress = (_a) => {
3970
4142
  $width: smartChannelProps.length
3971
4143
  }
3972
4144
  )
3973
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4145
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3974
4146
  Background,
3975
4147
  {
3976
4148
  $color: backgroundCss,
@@ -3979,7 +4151,7 @@ var ChannelWithProgress = (_a) => {
3979
4151
  $width: smartChannelProps.length
3980
4152
  }
3981
4153
  ),
3982
- !isPianoRollMode && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4154
+ !isPianoRollMode && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3983
4155
  ProgressOverlay,
3984
4156
  {
3985
4157
  ref: progressRef,
@@ -3989,7 +4161,7 @@ var ChannelWithProgress = (_a) => {
3989
4161
  $width: clipPixelWidth
3990
4162
  }
3991
4163
  ),
3992
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ChannelContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4164
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChannelContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3993
4165
  import_ui_components7.SmartChannel,
3994
4166
  __spreadProps(__spreadValues({}, smartChannelProps), {
3995
4167
  transparentBackground: true,
@@ -4002,11 +4174,11 @@ var ChannelWithProgress = (_a) => {
4002
4174
  };
4003
4175
 
4004
4176
  // src/SpectrogramIntegrationContext.tsx
4005
- var import_react25 = require("react");
4006
- var SpectrogramIntegrationContext = (0, import_react25.createContext)(null);
4177
+ var import_react27 = require("react");
4178
+ var SpectrogramIntegrationContext = (0, import_react27.createContext)(null);
4007
4179
  var SpectrogramIntegrationProvider = SpectrogramIntegrationContext.Provider;
4008
4180
  function useSpectrogramIntegration() {
4009
- const context = (0, import_react25.useContext)(SpectrogramIntegrationContext);
4181
+ const context = (0, import_react27.useContext)(SpectrogramIntegrationContext);
4010
4182
  if (!context) {
4011
4183
  throw new Error(
4012
4184
  "useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>."
@@ -4016,15 +4188,42 @@ function useSpectrogramIntegration() {
4016
4188
  }
4017
4189
 
4018
4190
  // src/components/PlaylistVisualization.tsx
4019
- var import_jsx_runtime9 = require("react/jsx-runtime");
4191
+ var import_jsx_runtime10 = require("react/jsx-runtime");
4020
4192
  var DEFAULT_EMPTY_TRACK_DURATION = 60;
4021
- var ControlSlot = import_styled_components6.default.div.attrs((props) => ({
4193
+ var DRAG_SOURCE_SHADOW = "0 4px 12px rgba(0, 0, 0, 0.35)";
4194
+ var TracksLayout = import_styled_components6.default.div.attrs((props) => ({
4022
4195
  style: { height: `${props.$height}px` }
4023
4196
  }))`
4197
+ position: relative;
4198
+ `;
4199
+ var TrackRowPositioner = import_styled_components6.default.div.attrs((props) => ({
4200
+ style: { top: `${props.$top}px` }
4201
+ }))`
4202
+ position: absolute;
4203
+ left: 0;
4204
+ right: 0;
4205
+ ${(props) => props.$animate && "transition: top 150ms ease;"}
4206
+ @media (prefers-reduced-motion: reduce) {
4207
+ transition: none;
4208
+ }
4209
+ `;
4210
+ var ControlSlot = import_styled_components6.default.div.attrs((props) => ({
4211
+ style: {
4212
+ height: `${props.$height}px`,
4213
+ top: `${props.$top}px`
4214
+ }
4215
+ }))`
4216
+ position: absolute;
4217
+ left: 0;
4218
+ right: 0;
4024
4219
  overflow: hidden;
4025
4220
  pointer-events: auto;
4026
4221
  background: ${(props) => props.theme.surfaceColor};
4027
4222
  transition: background 0.15s ease-in-out;
4223
+ ${(props) => props.$animate && "transition: top 150ms ease, background 0.15s ease-in-out;"}
4224
+ @media (prefers-reduced-motion: reduce) {
4225
+ transition: background 0.15s ease-in-out;
4226
+ }
4028
4227
  ${(props) => props.$isSelected && `background: ${props.theme.selectedTrackControlsBackground};`}
4029
4228
  `;
4030
4229
  var CustomPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
@@ -4059,6 +4258,133 @@ function getTrackChannelCount(trackClipPeaks, recordingState, trackId, mono) {
4059
4258
  const recordingChannels = (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === trackId ? mono ? 1 : recordingState.peaks.length : 0;
4060
4259
  return Math.max(clipChannels, recordingChannels);
4061
4260
  }
4261
+ function DefaultTrackControls({
4262
+ trackIndex,
4263
+ track,
4264
+ trackState,
4265
+ effectiveRenderMode,
4266
+ selectTrack,
4267
+ onRemoveTrack,
4268
+ setTrackMute,
4269
+ setTrackSolo,
4270
+ setTrackVolume,
4271
+ setTrackPan,
4272
+ spectrogram,
4273
+ setSettingsModalTrackId,
4274
+ trackReordering,
4275
+ reorderTrack,
4276
+ trackCount,
4277
+ gripRef
4278
+ }) {
4279
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4280
+ import_ui_components8.Controls,
4281
+ {
4282
+ onClick: () => selectTrack(trackIndex),
4283
+ style: trackReordering ? { position: "relative", paddingLeft: 18, paddingRight: 18 } : void 0,
4284
+ children: [
4285
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.Header, { style: { justifyContent: "center", position: "relative" }, children: [
4286
+ onRemoveTrack && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4287
+ import_ui_components8.CloseButton,
4288
+ {
4289
+ onClick: (e) => {
4290
+ e.stopPropagation();
4291
+ onRemoveTrack(trackIndex);
4292
+ }
4293
+ }
4294
+ ),
4295
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4296
+ "span",
4297
+ {
4298
+ style: {
4299
+ overflow: "hidden",
4300
+ textOverflow: "ellipsis",
4301
+ whiteSpace: "nowrap",
4302
+ padding: "0 24px",
4303
+ display: "block"
4304
+ },
4305
+ children: trackState.name || `Track ${trackIndex + 1}`
4306
+ }
4307
+ ),
4308
+ (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4309
+ import_ui_components8.TrackMenu,
4310
+ {
4311
+ items: (onClose) => spectrogram.renderMenuItems({
4312
+ renderMode: effectiveRenderMode,
4313
+ onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4314
+ onOpenSettings: () => setSettingsModalTrackId(track.id),
4315
+ onClose
4316
+ })
4317
+ }
4318
+ ) })
4319
+ ] }),
4320
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.ButtonGroup, { children: [
4321
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4322
+ import_ui_components8.Button,
4323
+ {
4324
+ $variant: trackState.muted ? "danger" : "outline",
4325
+ onClick: () => setTrackMute(trackIndex, !trackState.muted),
4326
+ children: "Mute"
4327
+ }
4328
+ ),
4329
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4330
+ import_ui_components8.Button,
4331
+ {
4332
+ $variant: trackState.soloed ? "info" : "outline",
4333
+ onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4334
+ children: "Solo"
4335
+ }
4336
+ )
4337
+ ] }),
4338
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.SliderWrapper, { children: [
4339
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.VolumeDownIcon, {}),
4340
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4341
+ import_ui_components8.Slider,
4342
+ {
4343
+ min: "0",
4344
+ max: "1",
4345
+ step: "0.01",
4346
+ value: trackState.volume,
4347
+ onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4348
+ }
4349
+ ),
4350
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.VolumeUpIcon, {})
4351
+ ] }),
4352
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.SliderWrapper, { children: [
4353
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "L" }),
4354
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4355
+ import_ui_components8.Slider,
4356
+ {
4357
+ min: "-1",
4358
+ max: "1",
4359
+ step: "0.01",
4360
+ value: trackState.pan,
4361
+ onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4362
+ }
4363
+ ),
4364
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "R" })
4365
+ ] }),
4366
+ trackReordering && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4367
+ import_ui_components8.ReorderRail,
4368
+ {
4369
+ style: { position: "absolute", right: 2, top: "50%", transform: "translateY(-50%)" },
4370
+ gripRef,
4371
+ onGripClick: (e) => e.stopPropagation(),
4372
+ upDisabled: trackIndex === 0,
4373
+ downDisabled: trackIndex === trackCount - 1,
4374
+ onMoveUp: (e) => {
4375
+ e.stopPropagation();
4376
+ reorderTrack(track.id, trackIndex - 1);
4377
+ },
4378
+ onMoveDown: (e) => {
4379
+ e.stopPropagation();
4380
+ reorderTrack(track.id, trackIndex + 1);
4381
+ }
4382
+ }
4383
+ )
4384
+ ]
4385
+ }
4386
+ );
4387
+ }
4062
4388
  var PlaylistVisualization = ({
4063
4389
  renderTrackControls,
4064
4390
  renderTick,
@@ -4071,7 +4397,8 @@ var PlaylistVisualization = ({
4071
4397
  showFades = false,
4072
4398
  touchOptimized = false,
4073
4399
  onRemoveTrack,
4074
- recordingState
4400
+ recordingState,
4401
+ trackReordering = false
4075
4402
  }) => {
4076
4403
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
4077
4404
  const theme = (0, import_ui_components8.useTheme)();
@@ -4091,7 +4418,7 @@ var PlaylistVisualization = ({
4091
4418
  indefinitePlayback,
4092
4419
  fillViewport
4093
4420
  } = usePlaylistState();
4094
- const annotationIntegration = (0, import_react26.useContext)(AnnotationIntegrationContext);
4421
+ const annotationIntegration = (0, import_react28.useContext)(AnnotationIntegrationContext);
4095
4422
  const {
4096
4423
  setAnnotations: _setAnnotations,
4097
4424
  setActiveAnnotationId,
@@ -4105,7 +4432,8 @@ var PlaylistVisualization = ({
4105
4432
  setSelectedTrackId,
4106
4433
  setCurrentTime,
4107
4434
  setLoopRegion,
4108
- setRecordingActive
4435
+ setRecordingActive,
4436
+ reorderTrack
4109
4437
  } = usePlaylistControls();
4110
4438
  const {
4111
4439
  peaksDataArray,
@@ -4121,17 +4449,19 @@ var PlaylistVisualization = ({
4121
4449
  barGap,
4122
4450
  roundedBars,
4123
4451
  isReady,
4124
- mono
4452
+ trackReorderEpoch,
4453
+ mono,
4454
+ trackDragPreview
4125
4455
  } = usePlaylistData();
4126
- const spectrogram = (0, import_react26.useContext)(SpectrogramIntegrationContext);
4456
+ const spectrogram = (0, import_react28.useContext)(SpectrogramIntegrationContext);
4127
4457
  const recordingActive = !!(recordingState == null ? void 0 : recordingState.isRecording);
4128
4458
  const armedTrackId = (_a = recordingState == null ? void 0 : recordingState.trackId) != null ? _a : null;
4129
- (0, import_react26.useEffect)(() => {
4459
+ (0, import_react28.useEffect)(() => {
4130
4460
  if (!recordingActive) return void 0;
4131
4461
  setRecordingActive(true, armedTrackId);
4132
4462
  return () => setRecordingActive(false);
4133
4463
  }, [recordingActive, armedTrackId, setRecordingActive]);
4134
- const perTrackSpectrogramHelpers = (0, import_react26.useMemo)(() => {
4464
+ const perTrackSpectrogramHelpers = (0, import_react28.useMemo)(() => {
4135
4465
  if (!spectrogram)
4136
4466
  return /* @__PURE__ */ new Map();
4137
4467
  const helpers = /* @__PURE__ */ new Map();
@@ -4150,11 +4480,11 @@ var PlaylistVisualization = ({
4150
4480
  });
4151
4481
  return helpers;
4152
4482
  }, [tracks, spectrogram]);
4153
- const [settingsModalTrackId, setSettingsModalTrackId] = (0, import_react26.useState)(null);
4154
- const [isSelecting, setIsSelecting] = (0, import_react26.useState)(false);
4155
- const mouseDownTimeRef = (0, import_react26.useRef)(0);
4156
- const scrollContainerRef = (0, import_react26.useRef)(null);
4157
- const handleScrollContainerRef = (0, import_react26.useCallback)(
4483
+ const [settingsModalTrackId, setSettingsModalTrackId] = (0, import_react28.useState)(null);
4484
+ const [isSelecting, setIsSelecting] = (0, import_react28.useState)(false);
4485
+ const mouseDownTimeRef = (0, import_react28.useRef)(0);
4486
+ const scrollContainerRef = (0, import_react28.useRef)(null);
4487
+ const handleScrollContainerRef = (0, import_react28.useCallback)(
4158
4488
  (element) => {
4159
4489
  scrollContainerRef.current = element;
4160
4490
  setScrollContainer(element);
@@ -4192,7 +4522,7 @@ var PlaylistVisualization = ({
4192
4522
  );
4193
4523
  }
4194
4524
  });
4195
- const selectTrack = (0, import_react26.useCallback)(
4525
+ const selectTrack = (0, import_react28.useCallback)(
4196
4526
  (trackIndex) => {
4197
4527
  if (trackIndex >= 0 && trackIndex < tracks.length) {
4198
4528
  const track = tracks[trackIndex];
@@ -4260,120 +4590,99 @@ var PlaylistVisualization = ({
4260
4590
  setSelection(start, end);
4261
4591
  }
4262
4592
  };
4593
+ const trackHeightById = (0, import_react28.useMemo)(() => {
4594
+ const m = /* @__PURE__ */ new Map();
4595
+ peaksDataArray.forEach((trackClipPeaks, trackIndex) => {
4596
+ const track = tracks[trackIndex];
4597
+ if (!track) return;
4598
+ const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4599
+ m.set(track.id, waveHeight * maxChannels + (showClipHeaders ? import_ui_components8.CLIP_HEADER_HEIGHT : 0));
4600
+ });
4601
+ return m;
4602
+ }, [peaksDataArray, tracks, recordingState, mono, waveHeight, showClipHeaders]);
4603
+ const displayOrderIds = (0, import_react28.useMemo)(
4604
+ () => applyTrackOrderPreview(tracks, trackDragPreview).map((t) => t.id),
4605
+ [tracks, trackDragPreview]
4606
+ );
4607
+ const trackLayout = (0, import_react28.useMemo)(
4608
+ () => computeTrackLayout(displayOrderIds, trackHeightById),
4609
+ [displayOrderIds, trackHeightById]
4610
+ );
4611
+ const animateTrackLayout = useTrailingActive(trackDragPreview !== null, 200);
4263
4612
  const hasClips = tracks.some((track) => track.clips.length > 0);
4264
4613
  if (hasClips && peaksDataArray.length === 0) {
4265
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, children: "Loading waveform..." });
4614
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, children: "Loading waveform..." });
4266
4615
  }
4267
- const trackControlsSlots = controls.show ? peaksDataArray.map((trackClipPeaks, trackIndex) => {
4268
- var _a2, _b2, _c2;
4269
- const track = tracks[trackIndex];
4270
- if (!track) return null;
4271
- const trackState = trackStates[trackIndex] || {
4272
- name: `Track ${trackIndex + 1}`,
4273
- muted: false,
4274
- soloed: false,
4275
- volume: 1,
4276
- pan: 0
4277
- };
4278
- const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4279
- const effectiveRenderMode = (_c2 = (_b2 = (_a2 = spectrogram == null ? void 0 : spectrogram.trackSpectrogramOverrides.get(track.id)) == null ? void 0 : _a2.renderMode) != null ? _b2 : track.renderMode) != null ? _c2 : hasMidiNotes ? "piano-roll" : "waveform";
4280
- const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4281
- const slotHeight = waveHeight * maxChannels + (showClipHeaders ? import_ui_components8.CLIP_HEADER_HEIGHT : 0);
4282
- const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.Controls, { onClick: () => selectTrack(trackIndex), children: [
4283
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.Header, { style: { justifyContent: "center", position: "relative" }, children: [
4284
- onRemoveTrack && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4285
- import_ui_components8.CloseButton,
4286
- {
4287
- onClick: (e) => {
4288
- e.stopPropagation();
4289
- onRemoveTrack(trackIndex);
4290
- }
4291
- }
4292
- ),
4293
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4294
- "span",
4295
- {
4296
- style: {
4297
- overflow: "hidden",
4298
- textOverflow: "ellipsis",
4299
- whiteSpace: "nowrap",
4300
- padding: "0 24px",
4301
- display: "block"
4302
- },
4303
- children: trackState.name || `Track ${trackIndex + 1}`
4304
- }
4305
- ),
4306
- (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4307
- import_ui_components8.TrackMenu,
4308
- {
4309
- items: (onClose) => spectrogram.renderMenuItems({
4310
- renderMode: effectiveRenderMode,
4311
- onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4312
- onOpenSettings: () => setSettingsModalTrackId(track.id),
4313
- onClose
4314
- })
4315
- }
4316
- ) })
4317
- ] }),
4318
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.ButtonGroup, { children: [
4319
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4320
- import_ui_components8.Button,
4321
- {
4322
- $variant: trackState.muted ? "danger" : "outline",
4323
- onClick: () => setTrackMute(trackIndex, !trackState.muted),
4324
- children: "Mute"
4325
- }
4326
- ),
4327
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4328
- import_ui_components8.Button,
4616
+ const trackControlsSlots = controls.show ? [
4617
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4618
+ var _a2, _b2, _c2, _d2, _e2;
4619
+ const track = tracks[trackIndex];
4620
+ if (!track) return null;
4621
+ const trackState = trackStates[trackIndex] || {
4622
+ name: `Track ${trackIndex + 1}`,
4623
+ muted: false,
4624
+ soloed: false,
4625
+ volume: 1,
4626
+ pan: 0
4627
+ };
4628
+ const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4629
+ const effectiveRenderMode = (_c2 = (_b2 = (_a2 = spectrogram == null ? void 0 : spectrogram.trackSpectrogramOverrides.get(track.id)) == null ? void 0 : _a2.renderMode) != null ? _b2 : track.renderMode) != null ? _c2 : hasMidiNotes ? "piano-roll" : "waveform";
4630
+ const slotHeight = (_d2 = trackHeightById.get(track.id)) != null ? _d2 : 0;
4631
+ const defaultControlProps = {
4632
+ trackIndex,
4633
+ track,
4634
+ trackState,
4635
+ effectiveRenderMode,
4636
+ selectTrack,
4637
+ onRemoveTrack,
4638
+ setTrackMute,
4639
+ setTrackSolo,
4640
+ setTrackVolume,
4641
+ setTrackPan,
4642
+ spectrogram,
4643
+ setSettingsModalTrackId,
4644
+ trackReordering,
4645
+ reorderTrack,
4646
+ trackCount: peaksDataArray.length
4647
+ };
4648
+ const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : trackReordering ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SortableTrackControls, { trackId: track.id, index: trackIndex, children: ({ ref, handleRef, isDragSource }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4649
+ "div",
4650
+ {
4651
+ ref,
4652
+ style: {
4653
+ height: "100%",
4654
+ boxShadow: isDragSource ? DRAG_SOURCE_SHADOW : void 0,
4655
+ // Opaque background for the floating (top-layer, popover-based)
4656
+ // drag-source row — without it the row underneath shows through.
4657
+ // onDragStart selects the dragged track, so its slot always shows
4658
+ // the selected-track background while lifted.
4659
+ background: isDragSource ? theme.selectedTrackControlsBackground : void 0
4660
+ },
4661
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DefaultTrackControls, __spreadProps(__spreadValues({}, defaultControlProps), { gripRef: handleRef }))
4662
+ }
4663
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DefaultTrackControls, __spreadValues({}, defaultControlProps));
4664
+ return (
4665
+ // key includes trackReorderEpoch: forces a remount after every
4666
+ // track-reorder drag, discarding @dnd-kit sortable-plugin DOM
4667
+ // corruption (see bumpTrackReorderEpoch's doc comment in
4668
+ // WaveformPlaylistContext). Stays at `-0` — a no-op suffix — for
4669
+ // consumers that never enable trackReordering.
4670
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4671
+ ControlSlot,
4329
4672
  {
4330
- $variant: trackState.soloed ? "info" : "outline",
4331
- onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4332
- children: "Solo"
4333
- }
4673
+ $height: slotHeight,
4674
+ $top: (_e2 = trackLayout.topById.get(track.id)) != null ? _e2 : 0,
4675
+ $animate: animateTrackLayout,
4676
+ $isSelected: track.id === selectedTrackId,
4677
+ children: trackControlContent
4678
+ },
4679
+ `${track.id}-${trackReorderEpoch}`
4334
4680
  )
4335
- ] }),
4336
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
4337
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeDownIcon, {}),
4338
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4339
- import_ui_components8.Slider,
4340
- {
4341
- min: "0",
4342
- max: "1",
4343
- step: "0.01",
4344
- value: trackState.volume,
4345
- onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4346
- }
4347
- ),
4348
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeUpIcon, {})
4349
- ] }),
4350
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
4351
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "L" }),
4352
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4353
- import_ui_components8.Slider,
4354
- {
4355
- min: "-1",
4356
- max: "1",
4357
- step: "0.01",
4358
- value: trackState.pan,
4359
- onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4360
- }
4361
- ),
4362
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "R" })
4363
- ] })
4364
- ] });
4365
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4366
- ControlSlot,
4367
- {
4368
- $height: slotHeight,
4369
- $isSelected: track.id === selectedTrackId,
4370
- children: trackControlContent
4371
- },
4372
- track.id
4373
- );
4374
- }) : void 0;
4375
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.DevicePixelRatioProvider, { children: [
4376
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4681
+ );
4682
+ }) }, "control-slots-layout")
4683
+ ] : void 0;
4684
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.DevicePixelRatioProvider, { children: [
4685
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4377
4686
  import_ui_components8.PlaylistInfoContext.Provider,
4378
4687
  {
4379
4688
  value: {
@@ -4388,7 +4697,7 @@ var PlaylistVisualization = ({
4388
4697
  barGap,
4389
4698
  roundedBars
4390
4699
  },
4391
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4700
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4392
4701
  import_ui_components8.Playlist,
4393
4702
  {
4394
4703
  theme,
@@ -4405,9 +4714,9 @@ var PlaylistVisualization = ({
4405
4714
  "data-playlist-state": isReady ? "ready" : "loading",
4406
4715
  trackControlsSlots,
4407
4716
  timescaleGapHeight: timeScaleHeight > 0 ? timeScaleHeight + 1 : 0,
4408
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4409
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.SmartScale, { renderTick }),
4410
- isLoopEnabled && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4717
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
4718
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.SmartScale, { renderTick }),
4719
+ isLoopEnabled && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4411
4720
  import_ui_components8.TimescaleLoopRegion,
4412
4721
  {
4413
4722
  startPosition: Math.min(loopStart, loopEnd) * sampleRate / samplesPerPixel,
@@ -4424,9 +4733,9 @@ var PlaylistVisualization = ({
4424
4733
  }
4425
4734
  )
4426
4735
  ] }) : void 0,
4427
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4428
- peaksDataArray.map((trackClipPeaks, trackIndex) => {
4429
- var _a2, _b2, _c2, _d2;
4736
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
4737
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4738
+ var _a2, _b2, _c2, _d2, _e2;
4430
4739
  const track = tracks[trackIndex];
4431
4740
  if (!track) return null;
4432
4741
  const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
@@ -4437,153 +4746,163 @@ var PlaylistVisualization = ({
4437
4746
  track.id,
4438
4747
  mono
4439
4748
  );
4440
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4441
- import_ui_components8.Track,
4749
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4750
+ TrackRowPositioner,
4442
4751
  {
4443
- numChannels: maxChannels,
4444
- backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : (0, import_ui_components8.waveformColorToCss)(theme.waveOutlineColor),
4445
- offset: 0,
4446
- width: tracksFullWidth,
4447
- hasClipHeaders: showClipHeaders,
4448
- trackId: track.id,
4449
- isSelected: track.id === selectedTrackId,
4450
- children: [
4451
- effectiveRenderMode !== "waveform" && (() => {
4452
- var _a3, _b3;
4453
- const helpers = perTrackSpectrogramHelpers.get(track.id);
4454
- const trackCfg = helpers == null ? void 0 : helpers.config;
4455
- if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4456
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4457
- import_ui_components8.SpectrogramLabels,
4458
- {
4459
- waveHeight,
4460
- numChannels: maxChannels,
4461
- frequencyScaleFn: helpers.frequencyScaleFn,
4462
- minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4463
- maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4464
- labelsColor: trackCfg.labelsColor,
4465
- labelsBackground: trackCfg.labelsBackground,
4466
- renderMode: effectiveRenderMode,
4467
- hasClipHeaders: showClipHeaders
4468
- }
4469
- );
4470
- })(),
4471
- trackClipPeaks.map((clip, clipIndex) => {
4472
- const peaksData = clip.peaks;
4473
- const width = peaksData.length;
4474
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4475
- import_ui_components8.Clip,
4476
- {
4477
- clipId: clip.clipId,
4478
- trackIndex,
4479
- clipIndex,
4480
- trackName: clip.trackName,
4481
- startSample: clip.startSample,
4482
- durationSamples: clip.durationSamples,
4483
- samplesPerPixel,
4484
- showHeader: showClipHeaders,
4485
- disableHeaderDrag: !interactiveClips,
4486
- isSelected: track.id === selectedTrackId,
4487
- trackId: track.id,
4488
- fadeIn: clip.fadeIn,
4489
- fadeOut: clip.fadeOut,
4490
- sampleRate,
4491
- showFades,
4492
- touchOptimized,
4493
- onMouseDown: (e) => {
4494
- const target = e.target;
4495
- const isDraggable = target.closest(
4496
- '[role="button"][aria-roledescription="draggable"]'
4497
- );
4498
- if (isDraggable) {
4499
- return;
4752
+ $top: (_d2 = trackLayout.topById.get(track.id)) != null ? _d2 : 0,
4753
+ $animate: animateTrackLayout,
4754
+ "data-track-row": "",
4755
+ "data-track-id": track.id,
4756
+ "data-track-drag-source": (trackDragPreview == null ? void 0 : trackDragPreview.trackId) === track.id ? "true" : void 0,
4757
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4758
+ import_ui_components8.Track,
4759
+ {
4760
+ numChannels: maxChannels,
4761
+ backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : (0, import_ui_components8.waveformColorToCss)(theme.waveOutlineColor),
4762
+ offset: 0,
4763
+ width: tracksFullWidth,
4764
+ hasClipHeaders: showClipHeaders,
4765
+ trackId: track.id,
4766
+ isSelected: track.id === selectedTrackId,
4767
+ children: [
4768
+ effectiveRenderMode !== "waveform" && (() => {
4769
+ var _a3, _b3;
4770
+ const helpers = perTrackSpectrogramHelpers.get(track.id);
4771
+ const trackCfg = helpers == null ? void 0 : helpers.config;
4772
+ if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4773
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4774
+ import_ui_components8.SpectrogramLabels,
4775
+ {
4776
+ waveHeight,
4777
+ numChannels: maxChannels,
4778
+ frequencyScaleFn: helpers.frequencyScaleFn,
4779
+ minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4780
+ maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4781
+ labelsColor: trackCfg.labelsColor,
4782
+ labelsBackground: trackCfg.labelsBackground,
4783
+ renderMode: effectiveRenderMode,
4784
+ hasClipHeaders: showClipHeaders
4500
4785
  }
4501
- selectTrack(trackIndex);
4502
- },
4503
- children: peaksData.data.map((channelPeaks, channelIndex) => {
4504
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4505
- ChannelWithProgress,
4506
- {
4507
- index: channelIndex,
4508
- data: channelPeaks,
4509
- bits: peaksData.bits,
4510
- length: width,
4511
- isSelected: track.id === selectedTrackId,
4512
- clipStartSample: clip.startSample,
4513
- clipDurationSamples: clip.durationSamples,
4514
- renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4515
- midiNotes: clip.midiNotes,
4516
- clipSampleRate: clip.sampleRate,
4517
- clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4518
- samplesPerPixel,
4519
- spectrogramClipId: clip.clipId,
4520
- spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4521
- spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4786
+ );
4787
+ })(),
4788
+ trackClipPeaks.map((clip, clipIndex) => {
4789
+ const peaksData = clip.peaks;
4790
+ const width = peaksData.length;
4791
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4792
+ import_ui_components8.Clip,
4793
+ {
4794
+ clipId: clip.clipId,
4795
+ trackIndex,
4796
+ clipIndex,
4797
+ trackName: clip.trackName,
4798
+ startSample: clip.startSample,
4799
+ durationSamples: clip.durationSamples,
4800
+ samplesPerPixel,
4801
+ showHeader: showClipHeaders,
4802
+ disableHeaderDrag: !interactiveClips,
4803
+ isSelected: track.id === selectedTrackId,
4804
+ trackId: track.id,
4805
+ fadeIn: clip.fadeIn,
4806
+ fadeOut: clip.fadeOut,
4807
+ sampleRate,
4808
+ showFades,
4809
+ touchOptimized,
4810
+ onMouseDown: (e) => {
4811
+ const target = e.target;
4812
+ const isDraggable = target.closest(
4813
+ '[role="button"][aria-roledescription="draggable"]'
4814
+ );
4815
+ if (isDraggable) {
4816
+ return;
4817
+ }
4818
+ selectTrack(trackIndex);
4522
4819
  },
4523
- `${clip.clipId}-${channelIndex}`
4524
- );
4525
- })
4526
- },
4527
- clip.clipId
4528
- );
4529
- }),
4530
- (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_d2 = recordingState.peaks[0]) == null ? void 0 : _d2.length) > 0 && (() => {
4531
- const latencyOffsetSamples = (0, import_core4.resolveRecordingOffsetSamples)({
4532
- overrideSeconds: recordingState.latencyOffset,
4533
- outputLatency: getOutputLatency(),
4534
- lookAhead: getLookAhead(),
4535
- sampleRate
4536
- });
4537
- const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4538
- const skipPeakElements = latencyPixels * 2;
4539
- const previewDuration = Math.max(
4540
- 0,
4541
- recordingState.durationSamples - latencyOffsetSamples
4542
- );
4543
- const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4544
- (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4545
- );
4546
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4547
- import_ui_components8.Clip,
4548
- {
4549
- clipId: "recording-preview",
4550
- trackIndex,
4551
- clipIndex: trackClipPeaks.length,
4552
- trackName: "Recording...",
4553
- startSample: recordingState.startSample,
4554
- durationSamples: previewDuration,
4555
- samplesPerPixel,
4556
- showHeader: showClipHeaders,
4557
- disableHeaderDrag: true,
4558
- isSelected: track.id === selectedTrackId,
4559
- trackId: track.id,
4560
- children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4561
- ChannelWithProgress,
4820
+ children: peaksData.data.map((channelPeaks, channelIndex) => {
4821
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4822
+ ChannelWithProgress,
4823
+ {
4824
+ index: channelIndex,
4825
+ data: channelPeaks,
4826
+ bits: peaksData.bits,
4827
+ length: width,
4828
+ isSelected: track.id === selectedTrackId,
4829
+ clipStartSample: clip.startSample,
4830
+ clipDurationSamples: clip.durationSamples,
4831
+ renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4832
+ midiNotes: clip.midiNotes,
4833
+ clipSampleRate: clip.sampleRate,
4834
+ clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4835
+ samplesPerPixel,
4836
+ spectrogramClipId: clip.clipId,
4837
+ spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4838
+ spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4839
+ },
4840
+ `${clip.clipId}-${channelIndex}`
4841
+ );
4842
+ })
4843
+ },
4844
+ clip.clipId
4845
+ );
4846
+ }),
4847
+ (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_e2 = recordingState.peaks[0]) == null ? void 0 : _e2.length) > 0 && (() => {
4848
+ const latencyOffsetSamples = (0, import_core4.resolveRecordingOffsetSamples)({
4849
+ overrideSeconds: recordingState.latencyOffset,
4850
+ outputLatency: getOutputLatency(),
4851
+ lookAhead: getLookAhead(),
4852
+ sampleRate
4853
+ });
4854
+ const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4855
+ const skipPeakElements = latencyPixels * 2;
4856
+ const previewDuration = Math.max(
4857
+ 0,
4858
+ recordingState.durationSamples - latencyOffsetSamples
4859
+ );
4860
+ const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4861
+ (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4862
+ );
4863
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4864
+ import_ui_components8.Clip,
4562
4865
  {
4563
- index: chIdx,
4564
- data: channelPeaks,
4565
- bits: recordingState.bits,
4566
- length: Math.floor(channelPeaks.length / 2),
4866
+ clipId: "recording-preview",
4867
+ trackIndex,
4868
+ clipIndex: trackClipPeaks.length,
4869
+ trackName: "Recording...",
4870
+ startSample: recordingState.startSample,
4871
+ durationSamples: previewDuration,
4872
+ samplesPerPixel,
4873
+ showHeader: showClipHeaders,
4874
+ disableHeaderDrag: true,
4567
4875
  isSelected: track.id === selectedTrackId,
4568
- clipStartSample: recordingState.startSample,
4569
- clipDurationSamples: previewDuration
4876
+ trackId: track.id,
4877
+ children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4878
+ ChannelWithProgress,
4879
+ {
4880
+ index: chIdx,
4881
+ data: channelPeaks,
4882
+ bits: recordingState.bits,
4883
+ length: Math.floor(channelPeaks.length / 2),
4884
+ isSelected: track.id === selectedTrackId,
4885
+ clipStartSample: recordingState.startSample,
4886
+ clipDurationSamples: previewDuration
4887
+ },
4888
+ `${track.id}-recording-${chIdx}`
4889
+ ))
4570
4890
  },
4571
- `${track.id}-recording-${chIdx}`
4572
- ))
4573
- },
4574
- `${track.id}-recording`
4575
- );
4576
- })()
4577
- ]
4891
+ `${track.id}-recording`
4892
+ );
4893
+ })()
4894
+ ]
4895
+ }
4896
+ )
4578
4897
  },
4579
4898
  track.id
4580
4899
  );
4581
- }),
4582
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4900
+ }) }),
4901
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4583
4902
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
4584
4903
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
4585
4904
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
4586
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4905
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4587
4906
  annotationIntegration.AnnotationBox,
4588
4907
  {
4589
4908
  annotationId: annotation.id,
@@ -4599,7 +4918,7 @@ var PlaylistVisualization = ({
4599
4918
  annotation.id
4600
4919
  );
4601
4920
  }) }),
4602
- selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4921
+ selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4603
4922
  import_ui_components8.Selection,
4604
4923
  {
4605
4924
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -4607,7 +4926,7 @@ var PlaylistVisualization = ({
4607
4926
  color: theme.selectionColor
4608
4927
  }
4609
4928
  ),
4610
- (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4929
+ (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4611
4930
  CustomPlayhead,
4612
4931
  {
4613
4932
  renderPlayhead,
@@ -4615,14 +4934,14 @@ var PlaylistVisualization = ({
4615
4934
  samplesPerPixel,
4616
4935
  sampleRate
4617
4936
  }
4618
- ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AnimatedPlayhead, { color: theme.playheadColor }))
4937
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AnimatedPlayhead, { color: theme.playheadColor }))
4619
4938
  ] })
4620
4939
  }
4621
4940
  )
4622
4941
  }
4623
4942
  ),
4624
4943
  (spectrogram == null ? void 0 : spectrogram.SettingsModal) && typeof document !== "undefined" && (0, import_react_dom.createPortal)(
4625
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4944
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4626
4945
  spectrogram.SettingsModal,
4627
4946
  {
4628
4947
  open: settingsModalTrackId !== null,
@@ -4642,8 +4961,8 @@ var PlaylistVisualization = ({
4642
4961
  };
4643
4962
 
4644
4963
  // src/components/PlaylistAnnotationList.tsx
4645
- var import_react27 = require("react");
4646
- var import_jsx_runtime10 = require("react/jsx-runtime");
4964
+ var import_react29 = require("react");
4965
+ var import_jsx_runtime11 = require("react/jsx-runtime");
4647
4966
  var PlaylistAnnotationList = ({
4648
4967
  height,
4649
4968
  renderAnnotationItem,
@@ -4657,7 +4976,7 @@ var PlaylistAnnotationList = ({
4657
4976
  const integration = useAnnotationIntegration();
4658
4977
  const { setAnnotations } = usePlaylistControls();
4659
4978
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints, continuousPlay };
4660
- const handleAnnotationUpdate = (0, import_react27.useCallback)(
4979
+ const handleAnnotationUpdate = (0, import_react29.useCallback)(
4661
4980
  (updatedAnnotations) => {
4662
4981
  setAnnotations(updatedAnnotations);
4663
4982
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -4665,7 +4984,7 @@ var PlaylistAnnotationList = ({
4665
4984
  [setAnnotations, onAnnotationUpdate]
4666
4985
  );
4667
4986
  const { AnnotationText } = integration;
4668
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4987
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4669
4988
  AnnotationText,
4670
4989
  {
4671
4990
  annotations,
@@ -4684,7 +5003,7 @@ var PlaylistAnnotationList = ({
4684
5003
  };
4685
5004
 
4686
5005
  // src/components/Waveform.tsx
4687
- var import_jsx_runtime11 = require("react/jsx-runtime");
5006
+ var import_jsx_runtime12 = require("react/jsx-runtime");
4688
5007
  var Waveform = ({
4689
5008
  renderTrackControls,
4690
5009
  renderTick,
@@ -4703,13 +5022,14 @@ var Waveform = ({
4703
5022
  showFades = false,
4704
5023
  touchOptimized = false,
4705
5024
  onRemoveTrack,
5025
+ trackReordering = false,
4706
5026
  recordingState
4707
5027
  }) => {
4708
5028
  const { annotations } = usePlaylistState();
4709
5029
  const clipInteractionEnabled = useClipInteractionEnabled();
4710
5030
  const effectiveInteractiveClips = interactiveClips || clipInteractionEnabled;
4711
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
4712
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
5031
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
5032
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4713
5033
  PlaylistVisualization,
4714
5034
  {
4715
5035
  renderTrackControls,
@@ -4723,10 +5043,11 @@ var Waveform = ({
4723
5043
  showFades,
4724
5044
  touchOptimized,
4725
5045
  onRemoveTrack,
5046
+ trackReordering,
4726
5047
  recordingState
4727
5048
  }
4728
5049
  ),
4729
- annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
5050
+ annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4730
5051
  PlaylistAnnotationList,
4731
5052
  {
4732
5053
  height: annotationTextHeight,
@@ -4741,9 +5062,9 @@ var Waveform = ({
4741
5062
  };
4742
5063
 
4743
5064
  // src/components/MediaElementPlaylist.tsx
4744
- var import_react30 = require("react");
4745
- var import_react31 = require("@dnd-kit/react");
4746
- var import_modifiers = require("@dnd-kit/abstract/modifiers");
5065
+ var import_react32 = require("react");
5066
+ var import_react33 = require("@dnd-kit/react");
5067
+ var import_modifiers2 = require("@dnd-kit/abstract/modifiers");
4747
5068
  var import_ui_components10 = require("@waveform-playlist/ui-components");
4748
5069
 
4749
5070
  // src/plugins/noDropAnimationPlugins.ts
@@ -4766,9 +5087,9 @@ var noDropAnimationPlugins = (defaults) => {
4766
5087
  };
4767
5088
 
4768
5089
  // src/components/AnimatedMediaElementPlayhead.tsx
4769
- var import_react28 = require("react");
5090
+ var import_react30 = require("react");
4770
5091
  var import_styled_components7 = __toESM(require("styled-components"));
4771
- var import_jsx_runtime12 = require("react/jsx-runtime");
5092
+ var import_jsx_runtime13 = require("react/jsx-runtime");
4772
5093
  var PlayheadLine2 = import_styled_components7.default.div`
4773
5094
  position: absolute;
4774
5095
  top: 0;
@@ -4783,11 +5104,11 @@ var PlayheadLine2 = import_styled_components7.default.div`
4783
5104
  var AnimatedMediaElementPlayhead = ({
4784
5105
  color = "#ff0000"
4785
5106
  }) => {
4786
- const playheadRef = (0, import_react28.useRef)(null);
4787
- const animationFrameRef = (0, import_react28.useRef)(null);
5107
+ const playheadRef = (0, import_react30.useRef)(null);
5108
+ const animationFrameRef = (0, import_react30.useRef)(null);
4788
5109
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4789
5110
  const { samplesPerPixel, sampleRate, progressBarWidth } = useMediaElementData();
4790
- (0, import_react28.useEffect)(() => {
5111
+ (0, import_react30.useEffect)(() => {
4791
5112
  const updatePosition = () => {
4792
5113
  var _a;
4793
5114
  if (playheadRef.current) {
@@ -4811,7 +5132,7 @@ var AnimatedMediaElementPlayhead = ({
4811
5132
  }
4812
5133
  };
4813
5134
  }, [isPlaying, sampleRate, samplesPerPixel, currentTimeRef]);
4814
- (0, import_react28.useEffect)(() => {
5135
+ (0, import_react30.useEffect)(() => {
4815
5136
  var _a;
4816
5137
  if (!isPlaying && playheadRef.current) {
4817
5138
  const time = (_a = currentTimeRef.current) != null ? _a : 0;
@@ -4819,14 +5140,14 @@ var AnimatedMediaElementPlayhead = ({
4819
5140
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
4820
5141
  }
4821
5142
  });
4822
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
5143
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
4823
5144
  };
4824
5145
 
4825
5146
  // src/components/ChannelWithMediaElementProgress.tsx
4826
- var import_react29 = require("react");
5147
+ var import_react31 = require("react");
4827
5148
  var import_styled_components8 = __toESM(require("styled-components"));
4828
5149
  var import_ui_components9 = require("@waveform-playlist/ui-components");
4829
- var import_jsx_runtime13 = require("react/jsx-runtime");
5150
+ var import_jsx_runtime14 = require("react/jsx-runtime");
4830
5151
  var ChannelWrapper2 = import_styled_components8.default.div`
4831
5152
  position: relative;
4832
5153
  `;
@@ -4863,14 +5184,14 @@ var ChannelWithMediaElementProgress = (_a) => {
4863
5184
  "clipStartSample",
4864
5185
  "clipDurationSamples"
4865
5186
  ]);
4866
- const progressRef = (0, import_react29.useRef)(null);
4867
- const animationFrameRef = (0, import_react29.useRef)(null);
5187
+ const progressRef = (0, import_react31.useRef)(null);
5188
+ const animationFrameRef = (0, import_react31.useRef)(null);
4868
5189
  const theme = (0, import_ui_components9.useTheme)();
4869
5190
  const { waveHeight } = (0, import_ui_components9.usePlaylistInfo)();
4870
5191
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4871
5192
  const { samplesPerPixel, sampleRate } = useMediaElementData();
4872
5193
  const progressColor = (theme == null ? void 0 : theme.waveProgressColor) || "rgba(0, 0, 0, 0.1)";
4873
- (0, import_react29.useEffect)(() => {
5194
+ (0, import_react31.useEffect)(() => {
4874
5195
  const updateProgress = () => {
4875
5196
  var _a2;
4876
5197
  if (progressRef.current) {
@@ -4912,7 +5233,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4912
5233
  smartChannelProps.length,
4913
5234
  currentTimeRef
4914
5235
  ]);
4915
- (0, import_react29.useEffect)(() => {
5236
+ (0, import_react31.useEffect)(() => {
4916
5237
  var _a2;
4917
5238
  if (!isPlaying && progressRef.current) {
4918
5239
  const currentTime = (_a2 = currentTimeRef.current) != null ? _a2 : 0;
@@ -4938,8 +5259,8 @@ var ChannelWithMediaElementProgress = (_a) => {
4938
5259
  backgroundColor = (theme == null ? void 0 : theme.selectedWaveOutlineColor) || (theme == null ? void 0 : theme.waveOutlineColor) || "grey";
4939
5260
  }
4940
5261
  const backgroundCss = (0, import_ui_components9.waveformColorToCss)(backgroundColor);
4941
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(ChannelWrapper2, { children: [
4942
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5262
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChannelWrapper2, { children: [
5263
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4943
5264
  Background2,
4944
5265
  {
4945
5266
  $color: backgroundCss,
@@ -4948,7 +5269,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4948
5269
  $width: smartChannelProps.length
4949
5270
  }
4950
5271
  ),
4951
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5272
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4952
5273
  ProgressOverlay2,
4953
5274
  {
4954
5275
  ref: progressRef,
@@ -4957,12 +5278,12 @@ var ChannelWithMediaElementProgress = (_a) => {
4957
5278
  $top: smartChannelProps.index * waveHeight
4958
5279
  }
4959
5280
  ),
4960
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ChannelContainer2, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui_components9.SmartChannel, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
5281
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChannelContainer2, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components9.SmartChannel, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
4961
5282
  ] });
4962
5283
  };
4963
5284
 
4964
5285
  // src/components/MediaElementPlaylist.tsx
4965
- var import_jsx_runtime14 = require("react/jsx-runtime");
5286
+ var import_jsx_runtime15 = require("react/jsx-runtime");
4966
5287
  var ZERO_REF = { current: 0 };
4967
5288
  var CustomMediaElementPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
4968
5289
  var _a;
@@ -4991,7 +5312,7 @@ var MediaElementPlaylist = ({
4991
5312
  const theme = (0, import_ui_components10.useTheme)();
4992
5313
  const { isPlaying } = useMediaElementAnimation();
4993
5314
  const { annotations, activeAnnotationId } = useMediaElementState();
4994
- const annotationIntegration = (0, import_react30.useContext)(AnnotationIntegrationContext);
5315
+ const annotationIntegration = (0, import_react32.useContext)(AnnotationIntegrationContext);
4995
5316
  const { play, seekTo, setActiveAnnotationId, setAnnotations, setScrollContainer } = useMediaElementControls();
4996
5317
  const {
4997
5318
  duration,
@@ -5008,11 +5329,11 @@ var MediaElementPlaylist = ({
5008
5329
  fadeIn,
5009
5330
  fadeOut
5010
5331
  } = useMediaElementData();
5011
- const [selectionStart, setSelectionStart] = (0, import_react30.useState)(0);
5012
- const [selectionEnd, setSelectionEnd] = (0, import_react30.useState)(0);
5013
- const [isSelecting, setIsSelecting] = (0, import_react30.useState)(false);
5014
- const scrollContainerRef = (0, import_react30.useRef)(null);
5015
- const handleScrollContainerRef = (0, import_react30.useCallback)(
5332
+ const [selectionStart, setSelectionStart] = (0, import_react32.useState)(0);
5333
+ const [selectionEnd, setSelectionEnd] = (0, import_react32.useState)(0);
5334
+ const [isSelecting, setIsSelecting] = (0, import_react32.useState)(false);
5335
+ const scrollContainerRef = (0, import_react32.useRef)(null);
5336
+ const handleScrollContainerRef = (0, import_react32.useCallback)(
5016
5337
  (el) => {
5017
5338
  scrollContainerRef.current = el;
5018
5339
  setScrollContainer(el);
@@ -5020,7 +5341,7 @@ var MediaElementPlaylist = ({
5020
5341
  [setScrollContainer]
5021
5342
  );
5022
5343
  const tracksFullWidth = Math.floor(duration * sampleRate / samplesPerPixel);
5023
- const handleAnnotationClick = (0, import_react30.useCallback)(
5344
+ const handleAnnotationClick = (0, import_react32.useCallback)(
5024
5345
  (annotation) => __async(null, null, function* () {
5025
5346
  setActiveAnnotationId(annotation.id);
5026
5347
  try {
@@ -5035,7 +5356,7 @@ var MediaElementPlaylist = ({
5035
5356
  }),
5036
5357
  [setActiveAnnotationId, play]
5037
5358
  );
5038
- const handleAnnotationUpdate = (0, import_react30.useCallback)(
5359
+ const handleAnnotationUpdate = (0, import_react32.useCallback)(
5039
5360
  (updatedAnnotations) => {
5040
5361
  setAnnotations(updatedAnnotations);
5041
5362
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5049,8 +5370,8 @@ var MediaElementPlaylist = ({
5049
5370
  duration,
5050
5371
  linkEndpoints: linkEndpointsProp
5051
5372
  });
5052
- const mouseDownTimeRef = (0, import_react30.useRef)(0);
5053
- const handleMouseDown = (0, import_react30.useCallback)(
5373
+ const mouseDownTimeRef = (0, import_react32.useRef)(0);
5374
+ const handleMouseDown = (0, import_react32.useCallback)(
5054
5375
  (e) => {
5055
5376
  const rect = e.currentTarget.getBoundingClientRect();
5056
5377
  const x = e.clientX - rect.left;
@@ -5062,7 +5383,7 @@ var MediaElementPlaylist = ({
5062
5383
  },
5063
5384
  [samplesPerPixel, sampleRate]
5064
5385
  );
5065
- const handleMouseMove = (0, import_react30.useCallback)(
5386
+ const handleMouseMove = (0, import_react32.useCallback)(
5066
5387
  (e) => {
5067
5388
  if (!isSelecting) return;
5068
5389
  const rect = e.currentTarget.getBoundingClientRect();
@@ -5072,7 +5393,7 @@ var MediaElementPlaylist = ({
5072
5393
  },
5073
5394
  [isSelecting, samplesPerPixel, sampleRate]
5074
5395
  );
5075
- const handleMouseUp = (0, import_react30.useCallback)(
5396
+ const handleMouseUp = (0, import_react32.useCallback)(
5076
5397
  (e) => {
5077
5398
  if (!isSelecting) return;
5078
5399
  setIsSelecting(false);
@@ -5102,9 +5423,9 @@ var MediaElementPlaylist = ({
5102
5423
  [isSelecting, selectionStart, samplesPerPixel, sampleRate, seekTo, isPlaying, playoutRef, play]
5103
5424
  );
5104
5425
  if (peaksDataArray.length === 0) {
5105
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className, children: "Loading waveform..." });
5426
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className, children: "Loading waveform..." });
5106
5427
  }
5107
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components10.DevicePixelRatioProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5428
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui_components10.DevicePixelRatioProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5108
5429
  import_ui_components10.PlaylistInfoContext.Provider,
5109
5430
  {
5110
5431
  value: {
@@ -5119,7 +5440,7 @@ var MediaElementPlaylist = ({
5119
5440
  barGap,
5120
5441
  roundedBars
5121
5442
  },
5122
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5443
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5123
5444
  import_ui_components10.Playlist,
5124
5445
  {
5125
5446
  theme,
@@ -5133,11 +5454,11 @@ var MediaElementPlaylist = ({
5133
5454
  onTracksMouseUp: handleMouseUp,
5134
5455
  scrollContainerRef: handleScrollContainerRef,
5135
5456
  isSelecting,
5136
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components10.SmartScale, {}) : void 0,
5137
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
5457
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui_components10.SmartScale, {}) : void 0,
5458
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
5138
5459
  peaksDataArray.map((trackClipPeaks, trackIndex) => {
5139
5460
  const maxChannels = trackClipPeaks.length > 0 ? Math.max(...trackClipPeaks.map((clip) => clip.peaks.data.length)) : 1;
5140
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5461
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5141
5462
  import_ui_components10.Track,
5142
5463
  {
5143
5464
  numChannels: maxChannels,
@@ -5150,7 +5471,7 @@ var MediaElementPlaylist = ({
5150
5471
  children: trackClipPeaks.map((clip, clipIndex) => {
5151
5472
  const peaksData = clip.peaks;
5152
5473
  const width = peaksData.length;
5153
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
5474
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
5154
5475
  import_ui_components10.Clip,
5155
5476
  {
5156
5477
  clipId: clip.clipId,
@@ -5165,7 +5486,7 @@ var MediaElementPlaylist = ({
5165
5486
  isSelected: true,
5166
5487
  trackId: `media-element-track-${trackIndex}`,
5167
5488
  children: [
5168
- peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5489
+ peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5169
5490
  ChannelWithMediaElementProgress,
5170
5491
  {
5171
5492
  index: channelIndex,
@@ -5177,7 +5498,7 @@ var MediaElementPlaylist = ({
5177
5498
  },
5178
5499
  `${trackIndex}-${clipIndex}-${channelIndex}`
5179
5500
  )),
5180
- showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5501
+ showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5181
5502
  import_ui_components10.FadeOverlay,
5182
5503
  {
5183
5504
  left: 0,
@@ -5186,7 +5507,7 @@ var MediaElementPlaylist = ({
5186
5507
  curveType: fadeIn.type
5187
5508
  }
5188
5509
  ),
5189
- showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5510
+ showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5190
5511
  import_ui_components10.FadeOverlay,
5191
5512
  {
5192
5513
  left: width - Math.floor(fadeOut.duration * sampleRate / samplesPerPixel),
@@ -5204,19 +5525,19 @@ var MediaElementPlaylist = ({
5204
5525
  trackIndex
5205
5526
  );
5206
5527
  }),
5207
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5208
- import_react31.DragDropProvider,
5528
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5529
+ import_react33.DragDropProvider,
5209
5530
  {
5210
5531
  onDragStart,
5211
5532
  onDragMove,
5212
5533
  onDragEnd,
5213
- modifiers: editable ? [import_modifiers.RestrictToHorizontalAxis] : [],
5534
+ modifiers: editable ? [import_modifiers2.RestrictToHorizontalAxis] : [],
5214
5535
  plugins: noDropAnimationPlugins,
5215
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5536
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5216
5537
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
5217
5538
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
5218
5539
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
5219
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5540
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5220
5541
  annotationIntegration.AnnotationBox,
5221
5542
  {
5222
5543
  annotationId: annotation.id,
@@ -5234,7 +5555,7 @@ var MediaElementPlaylist = ({
5234
5555
  }) })
5235
5556
  }
5236
5557
  ),
5237
- selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5558
+ selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5238
5559
  import_ui_components10.Selection,
5239
5560
  {
5240
5561
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -5242,7 +5563,7 @@ var MediaElementPlaylist = ({
5242
5563
  color: theme.selectionColor
5243
5564
  }
5244
5565
  ),
5245
- renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5566
+ renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5246
5567
  CustomMediaElementPlayhead,
5247
5568
  {
5248
5569
  renderPlayhead,
@@ -5250,7 +5571,7 @@ var MediaElementPlaylist = ({
5250
5571
  samplesPerPixel,
5251
5572
  sampleRate
5252
5573
  }
5253
- ) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5574
+ ) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5254
5575
  ] })
5255
5576
  }
5256
5577
  )
@@ -5259,8 +5580,8 @@ var MediaElementPlaylist = ({
5259
5580
  };
5260
5581
 
5261
5582
  // src/components/MediaElementAnnotationList.tsx
5262
- var import_react32 = require("react");
5263
- var import_jsx_runtime15 = require("react/jsx-runtime");
5583
+ var import_react34 = require("react");
5584
+ var import_jsx_runtime16 = require("react/jsx-runtime");
5264
5585
  var MediaElementAnnotationList = ({
5265
5586
  height,
5266
5587
  renderAnnotationItem,
@@ -5275,7 +5596,7 @@ var MediaElementAnnotationList = ({
5275
5596
  const integration = useAnnotationIntegration();
5276
5597
  const { setAnnotations } = useMediaElementControls();
5277
5598
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints: false, continuousPlay };
5278
- const handleAnnotationUpdate = (0, import_react32.useCallback)(
5599
+ const handleAnnotationUpdate = (0, import_react34.useCallback)(
5279
5600
  (updatedAnnotations) => {
5280
5601
  setAnnotations(updatedAnnotations);
5281
5602
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5283,7 +5604,7 @@ var MediaElementAnnotationList = ({
5283
5604
  [setAnnotations, onAnnotationUpdate]
5284
5605
  );
5285
5606
  const { AnnotationText } = integration;
5286
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5607
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5287
5608
  AnnotationText,
5288
5609
  {
5289
5610
  annotations,
@@ -5302,7 +5623,7 @@ var MediaElementAnnotationList = ({
5302
5623
  };
5303
5624
 
5304
5625
  // src/components/MediaElementWaveform.tsx
5305
- var import_jsx_runtime16 = require("react/jsx-runtime");
5626
+ var import_jsx_runtime17 = require("react/jsx-runtime");
5306
5627
  var MediaElementWaveform = ({
5307
5628
  annotationTextHeight,
5308
5629
  getAnnotationBoxLabel,
@@ -5317,8 +5638,8 @@ var MediaElementWaveform = ({
5317
5638
  className
5318
5639
  }) => {
5319
5640
  const { annotations } = useMediaElementState();
5320
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
5321
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5641
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
5642
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5322
5643
  MediaElementPlaylist,
5323
5644
  {
5324
5645
  getAnnotationBoxLabel,
@@ -5330,7 +5651,7 @@ var MediaElementWaveform = ({
5330
5651
  className
5331
5652
  }
5332
5653
  ),
5333
- annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5654
+ annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5334
5655
  MediaElementAnnotationList,
5335
5656
  {
5336
5657
  height: annotationTextHeight,
@@ -5405,9 +5726,9 @@ var KeyboardShortcuts = ({
5405
5726
  };
5406
5727
 
5407
5728
  // src/components/ClipInteractionProvider.tsx
5408
- var import_react33 = __toESM(require("react"));
5409
- var import_react34 = require("@dnd-kit/react");
5410
- var import_modifiers2 = require("@dnd-kit/abstract/modifiers");
5729
+ var import_react35 = __toESM(require("react"));
5730
+ var import_react36 = require("@dnd-kit/react");
5731
+ var import_modifiers3 = require("@dnd-kit/abstract/modifiers");
5411
5732
  var import_core6 = require("@waveform-playlist/core");
5412
5733
  var import_ui_components11 = require("@waveform-playlist/ui-components");
5413
5734
 
@@ -5477,7 +5798,7 @@ _SnapToGridModifier.configure = (0, import_abstract2.configurator)(_SnapToGridMo
5477
5798
  var SnapToGridModifier = _SnapToGridModifier;
5478
5799
 
5479
5800
  // src/components/ClipInteractionProvider.tsx
5480
- var import_jsx_runtime17 = require("react/jsx-runtime");
5801
+ var import_jsx_runtime18 = require("react/jsx-runtime");
5481
5802
  var NOOP_TRACKS_CHANGE = () => {
5482
5803
  };
5483
5804
  var ClipInteractionProvider = ({
@@ -5486,18 +5807,18 @@ var ClipInteractionProvider = ({
5486
5807
  children
5487
5808
  }) => {
5488
5809
  const { tracks, samplesPerPixel, sampleRate, playoutRef, isDraggingRef, onTracksChange } = usePlaylistData();
5489
- const { setSelectedTrackId } = usePlaylistControls();
5810
+ const { setSelectedTrackId, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview } = usePlaylistControls();
5490
5811
  const beatsAndBars = (0, import_ui_components11.useBeatsAndBars)();
5491
5812
  const useBeatsSnap = snap && beatsAndBars != null && beatsAndBars.scaleMode === "beats" && beatsAndBars.snapTo !== "off";
5492
5813
  const useTimescaleSnap = snap && !useBeatsSnap;
5493
- (0, import_react33.useEffect)(() => {
5814
+ (0, import_react35.useEffect)(() => {
5494
5815
  if (onTracksChange == null) {
5495
5816
  console.warn(
5496
5817
  "[waveform-playlist] ClipInteractionProvider: onTracksChange is not set on WaveformPlaylistProvider. Drag and trim edits will not be persisted."
5497
5818
  );
5498
5819
  }
5499
5820
  }, [onTracksChange]);
5500
- const snapSamplePosition = (0, import_react33.useMemo)(() => {
5821
+ const snapSamplePosition = (0, import_react35.useMemo)(() => {
5501
5822
  if (useBeatsSnap && beatsAndBars) {
5502
5823
  const { bpm, timeSignature, snapTo } = beatsAndBars;
5503
5824
  const gridTicks = snapTo === "bar" ? (0, import_core6.ticksPerBar)(timeSignature) : (0, import_core6.ticksPerBeat)(timeSignature);
@@ -5526,10 +5847,15 @@ var ClipInteractionProvider = ({
5526
5847
  isDraggingRef,
5527
5848
  snapSamplePosition
5528
5849
  });
5529
- const onDragStart = import_react33.default.useCallback(
5850
+ const onDragStart = import_react35.default.useCallback(
5530
5851
  (event) => {
5531
- var _a, _b, _c;
5532
- const trackIndex = (_c = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data) == null ? void 0 : _c.trackIndex;
5852
+ var _a, _b;
5853
+ const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
5854
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5855
+ if (data.trackId) setSelectedTrackId(data.trackId);
5856
+ return;
5857
+ }
5858
+ const trackIndex = data == null ? void 0 : data.trackIndex;
5533
5859
  if (trackIndex !== void 0 && tracks[trackIndex]) {
5534
5860
  setSelectedTrackId(tracks[trackIndex].id);
5535
5861
  }
@@ -5537,8 +5863,41 @@ var ClipInteractionProvider = ({
5537
5863
  },
5538
5864
  [handleDragStart, tracks, setSelectedTrackId]
5539
5865
  );
5540
- const modifiers = (0, import_react33.useMemo)(() => {
5541
- const mods = [import_modifiers2.RestrictToHorizontalAxis];
5866
+ const handleDragOver = import_react35.default.useCallback(
5867
+ (event) => {
5868
+ var _a;
5869
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5870
+ if ((data == null ? void 0 : data.kind) !== "track-reorder" || !data.trackId) return;
5871
+ const sortable = event.operation.source.sortable;
5872
+ if (!sortable) return;
5873
+ const trackId = data.trackId;
5874
+ const toIndex = sortable.index;
5875
+ setTrackDragPreview(
5876
+ (prev) => prev && prev.trackId === trackId && prev.toIndex === toIndex ? prev : { trackId, toIndex }
5877
+ );
5878
+ },
5879
+ [setTrackDragPreview]
5880
+ );
5881
+ const handleDragEnd = import_react35.default.useCallback(
5882
+ (event) => {
5883
+ var _a;
5884
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5885
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5886
+ bumpTrackReorderEpoch();
5887
+ setTrackDragPreview(null);
5888
+ if (event.canceled || !data.trackId) return;
5889
+ const sortable = event.operation.source.sortable;
5890
+ if (sortable && sortable.index !== sortable.initialIndex) {
5891
+ reorderTrack(data.trackId, sortable.index);
5892
+ }
5893
+ return;
5894
+ }
5895
+ onDragEnd(event);
5896
+ },
5897
+ [onDragEnd, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview]
5898
+ );
5899
+ const modifiers = (0, import_react35.useMemo)(() => {
5900
+ const mods = [import_modifiers3.RestrictToHorizontalAxis];
5542
5901
  if (useBeatsSnap && beatsAndBars) {
5543
5902
  mods.push(
5544
5903
  SnapToGridModifier.configure({
@@ -5562,13 +5921,14 @@ var ClipInteractionProvider = ({
5562
5921
  mods.push(ClipCollisionModifier.configure({ tracks, samplesPerPixel }));
5563
5922
  return mods;
5564
5923
  }, [useBeatsSnap, useTimescaleSnap, beatsAndBars, tracks, samplesPerPixel, sampleRate]);
5565
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5566
- import_react34.DragDropProvider,
5924
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
5925
+ import_react36.DragDropProvider,
5567
5926
  {
5568
5927
  sensors,
5569
5928
  onDragStart,
5570
5929
  onDragMove,
5571
- onDragEnd,
5930
+ onDragOver: handleDragOver,
5931
+ onDragEnd: handleDragEnd,
5572
5932
  modifiers,
5573
5933
  plugins: noDropAnimationPlugins,
5574
5934
  children
@@ -5605,6 +5965,7 @@ var ClipInteractionProvider = ({
5605
5965
  SkipBackwardButton,
5606
5966
  SkipForwardButton,
5607
5967
  SnapToGridModifier,
5968
+ SortableTrackControls,
5608
5969
  SpectrogramIntegrationProvider,
5609
5970
  StopButton,
5610
5971
  TimeFormatSelect,