@waveform-playlist/ui-components 15.0.0-next.1 → 15.0.0-next.11

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
@@ -2503,6 +2503,23 @@ var SpectrogramCanvas = import_styled_components21.default.canvas.attrs((props)
2503
2503
  image-rendering: pixelated;
2504
2504
  image-rendering: crisp-edges;
2505
2505
  `;
2506
+ function releaseUnmounted(ids, canvases, unregister) {
2507
+ const remaining = /* @__PURE__ */ new Set();
2508
+ for (const id of ids) {
2509
+ const parsed = (0, import_core5.parseSpectrogramCanvasId)(id);
2510
+ const canvas = parsed ? canvases.get(parsed.chunkIndex) : void 0;
2511
+ if (canvas?.isConnected) {
2512
+ remaining.add(id);
2513
+ continue;
2514
+ }
2515
+ try {
2516
+ unregister(id);
2517
+ } catch (err) {
2518
+ console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2519
+ }
2520
+ }
2521
+ return remaining;
2522
+ }
2506
2523
  var SpectrogramChannel = ({
2507
2524
  index,
2508
2525
  channelIndex: channelIndexProp,
@@ -2518,10 +2535,12 @@ var SpectrogramChannel = ({
2518
2535
  }) => {
2519
2536
  const channelIndex = channelIndexProp ?? index;
2520
2537
  const { canvasRef, canvasMapRef } = useChunkedCanvasRefs();
2521
- const registeredIdsRef = (0, import_react21.useRef)([]);
2538
+ const registeredIdsRef = (0, import_react21.useRef)(/* @__PURE__ */ new Set());
2522
2539
  const transferredCanvasesRef = (0, import_react21.useRef)(/* @__PURE__ */ new WeakSet());
2523
2540
  const onCanvasRegisterRef = (0, import_react21.useRef)(onCanvasRegister);
2524
2541
  const onCanvasUnregisterRef = (0, import_react21.useRef)(onCanvasUnregister);
2542
+ const releasedRef = (0, import_react21.useRef)(false);
2543
+ const [generation, setGeneration] = (0, import_react21.useState)(0);
2525
2544
  const clipOriginX = useClipViewportOrigin();
2526
2545
  const visibleChunkIndices = useVisibleChunkIndices(length, import_core5.MAX_CANVAS_WIDTH, clipOriginX);
2527
2546
  (0, import_react21.useEffect)(() => {
@@ -2532,28 +2551,10 @@ var SpectrogramChannel = ({
2532
2551
  }, [onCanvasUnregister]);
2533
2552
  (0, import_react21.useEffect)(() => {
2534
2553
  if (!clipId) return;
2554
+ if (releasedRef.current) return;
2535
2555
  const unregister = onCanvasUnregisterRef.current;
2536
2556
  const register = onCanvasRegisterRef.current;
2537
- const remaining = [];
2538
- for (const id of registeredIdsRef.current) {
2539
- const parsed = (0, import_core5.parseSpectrogramCanvasId)(id);
2540
- if (!parsed) {
2541
- remaining.push(id);
2542
- continue;
2543
- }
2544
- const chunkIdx = parsed.chunkIndex;
2545
- const canvas = canvasMapRef.current.get(chunkIdx);
2546
- if (canvas && canvas.isConnected) {
2547
- remaining.push(id);
2548
- } else {
2549
- try {
2550
- unregister(id);
2551
- } catch (err) {
2552
- console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2553
- }
2554
- }
2555
- }
2556
- registeredIdsRef.current = remaining;
2557
+ const remaining = releaseUnmounted(registeredIdsRef.current, canvasMapRef.current, unregister);
2557
2558
  for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
2558
2559
  if (transferredCanvasesRef.current.has(canvas)) continue;
2559
2560
  const canvasId = (0, import_core5.buildSpectrogramCanvasId)({ clipId, channelIndex, chunkIndex: canvasIdx });
@@ -2578,11 +2579,12 @@ var SpectrogramChannel = ({
2578
2579
  ...offsetSamples !== void 0 ? { offsetSamples } : {},
2579
2580
  ...durationSamples !== void 0 ? { durationSamples } : {}
2580
2581
  });
2581
- registeredIdsRef.current.push(canvasId);
2582
+ remaining.add(canvasId);
2582
2583
  } catch (err) {
2583
2584
  console.warn(`[spectrogram] register failed for ${canvasId}:`, err);
2584
2585
  }
2585
2586
  }
2587
+ registeredIdsRef.current = remaining;
2586
2588
  }, [
2587
2589
  canvasMapRef,
2588
2590
  clipId,
@@ -2591,9 +2593,14 @@ var SpectrogramChannel = ({
2591
2593
  waveHeight,
2592
2594
  offsetSamples,
2593
2595
  durationSamples,
2594
- visibleChunkIndices
2596
+ visibleChunkIndices,
2597
+ generation
2595
2598
  ]);
2596
2599
  (0, import_react21.useEffect)(() => {
2600
+ if (releasedRef.current) {
2601
+ releasedRef.current = false;
2602
+ setGeneration((g) => g + 1);
2603
+ }
2597
2604
  return () => {
2598
2605
  const unregister = onCanvasUnregisterRef.current;
2599
2606
  for (const id of registeredIdsRef.current) {
@@ -2603,7 +2610,8 @@ var SpectrogramChannel = ({
2603
2610
  console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2604
2611
  }
2605
2612
  }
2606
- registeredIdsRef.current = [];
2613
+ registeredIdsRef.current = /* @__PURE__ */ new Set();
2614
+ releasedRef.current = true;
2607
2615
  };
2608
2616
  }, []);
2609
2617
  const canvases = visibleChunkIndices.map((i) => {
@@ -2620,7 +2628,7 @@ var SpectrogramChannel = ({
2620
2628
  "data-index": i,
2621
2629
  ref: canvasRef
2622
2630
  },
2623
- `${length}-${waveHeight}-${offsetSamples ?? ""}-${durationSamples ?? ""}-${i}`
2631
+ `${generation}-${length}-${waveHeight}-${offsetSamples ?? ""}-${durationSamples ?? ""}-${i}`
2624
2632
  );
2625
2633
  });
2626
2634
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Wrapper4, { $index: index, $cssWidth: length, $waveHeight: waveHeight, children: canvases });
@@ -3092,10 +3100,9 @@ var SmartScale = ({
3092
3100
  const { marker, bigStep, smallStep } = config;
3093
3101
  const canvasInfo = /* @__PURE__ */ new Map();
3094
3102
  const labels = [];
3095
- const pixPerSec = sampleRate / samplesPerPixel;
3096
- let counter = 0;
3097
- for (let i = 0; i < widthX; i += pixPerSec * smallStep / 1e3) {
3098
- const pix = Math.floor(i);
3103
+ for (let counter = 0; ; counter += smallStep) {
3104
+ const pix = Math.floor(counter * sampleRate / (1e3 * samplesPerPixel));
3105
+ if (!(pix < widthX)) break;
3099
3106
  if (counter % marker === 0) {
3100
3107
  labels.push({
3101
3108
  id: `timestamp-${counter}`,
@@ -3109,7 +3116,6 @@ var SmartScale = ({
3109
3116
  } else if (counter % smallStep === 0) {
3110
3117
  canvasInfo.set(pix, Math.floor(timeScaleHeight / 5));
3111
3118
  }
3112
- counter += smallStep;
3113
3119
  }
3114
3120
  return { widthX, canvasInfo, labels };
3115
3121
  }, [beatsAndBars, duration, samplesPerPixel, sampleRate, timeScaleHeight]);
@@ -3371,7 +3377,7 @@ var ButtonGroup = import_styled_components29.default.div`
3371
3377
 
3372
3378
  // src/components/TrackControls/CloseButton.tsx
3373
3379
  var import_styled_components30 = __toESM(require("styled-components"));
3374
- var import_react25 = require("@phosphor-icons/react");
3380
+ var import_X = require("@phosphor-icons/react/dist/csr/X");
3375
3381
  var import_jsx_runtime29 = require("react/jsx-runtime");
3376
3382
  var StyledCloseButton = import_styled_components30.default.button`
3377
3383
  position: absolute;
@@ -3396,7 +3402,7 @@ var StyledCloseButton = import_styled_components30.default.button`
3396
3402
  color: #dc3545;
3397
3403
  }
3398
3404
  `;
3399
- var CloseButton = ({ onClick, title = "Remove track" }) => /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(StyledCloseButton, { onClick, title, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_react25.X, { size: 12, weight: "bold" }) });
3405
+ var CloseButton = ({ onClick, title = "Remove track" }) => /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(StyledCloseButton, { onClick, title, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_X.XIcon, { size: 12, weight: "bold" }) });
3400
3406
 
3401
3407
  // src/components/TrackControls/Controls.tsx
3402
3408
  var import_styled_components31 = __toESM(require("styled-components"));
@@ -3431,39 +3437,39 @@ var Header = import_styled_components32.default.header`
3431
3437
  `;
3432
3438
 
3433
3439
  // src/components/TrackControls/VolumeDownIcon.tsx
3434
- var import_react26 = require("@phosphor-icons/react");
3440
+ var import_SpeakerLow = require("@phosphor-icons/react/dist/csr/SpeakerLow");
3435
3441
  var import_jsx_runtime30 = require("react/jsx-runtime");
3436
- var VolumeDownIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_react26.SpeakerLowIcon, { weight: "light", ...props });
3442
+ var VolumeDownIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_SpeakerLow.SpeakerLowIcon, { weight: "light", ...props });
3437
3443
 
3438
3444
  // src/components/TrackControls/VolumeUpIcon.tsx
3439
- var import_react27 = require("@phosphor-icons/react");
3445
+ var import_SpeakerHigh = require("@phosphor-icons/react/dist/csr/SpeakerHigh");
3440
3446
  var import_jsx_runtime31 = require("react/jsx-runtime");
3441
- var VolumeUpIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_react27.SpeakerHighIcon, { weight: "light", ...props });
3447
+ var VolumeUpIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_SpeakerHigh.SpeakerHighIcon, { weight: "light", ...props });
3442
3448
 
3443
3449
  // src/components/TrackControls/TrashIcon.tsx
3444
- var import_react28 = require("@phosphor-icons/react");
3450
+ var import_Trash = require("@phosphor-icons/react/dist/csr/Trash");
3445
3451
  var import_jsx_runtime32 = require("react/jsx-runtime");
3446
- var TrashIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_react28.TrashIcon, { weight: "light", ...props });
3452
+ var TrashIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_Trash.TrashIcon, { weight: "light", ...props });
3447
3453
 
3448
3454
  // src/components/TrackControls/DotsIcon.tsx
3449
- var import_react29 = require("@phosphor-icons/react");
3455
+ var import_DotsThree = require("@phosphor-icons/react/dist/csr/DotsThree");
3450
3456
  var import_jsx_runtime33 = require("react/jsx-runtime");
3451
- var DotsIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_react29.DotsThreeIcon, { weight: "bold", ...props });
3457
+ var DotsIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_DotsThree.DotsThreeIcon, { weight: "bold", ...props });
3452
3458
 
3453
3459
  // src/components/TrackControls/GripIcon.tsx
3454
- var import_react30 = require("@phosphor-icons/react");
3460
+ var import_DotsSixVertical = require("@phosphor-icons/react/dist/csr/DotsSixVertical");
3455
3461
  var import_jsx_runtime34 = require("react/jsx-runtime");
3456
- var GripIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_react30.DotsSixVerticalIcon, { weight: "bold", ...props });
3462
+ var GripIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_DotsSixVertical.DotsSixVerticalIcon, { weight: "bold", ...props });
3457
3463
 
3458
3464
  // src/components/TrackControls/MoveUpIcon.tsx
3459
- var import_react31 = require("@phosphor-icons/react");
3465
+ var import_CaretUp = require("@phosphor-icons/react/dist/csr/CaretUp");
3460
3466
  var import_jsx_runtime35 = require("react/jsx-runtime");
3461
- var MoveUpIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_react31.CaretUpIcon, { weight: "bold", ...props });
3467
+ var MoveUpIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_CaretUp.CaretUpIcon, { weight: "bold", ...props });
3462
3468
 
3463
3469
  // src/components/TrackControls/MoveDownIcon.tsx
3464
- var import_react32 = require("@phosphor-icons/react");
3470
+ var import_CaretDown = require("@phosphor-icons/react/dist/csr/CaretDown");
3465
3471
  var import_jsx_runtime36 = require("react/jsx-runtime");
3466
- var MoveDownIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_react32.CaretDownIcon, { weight: "bold", ...props });
3472
+ var MoveDownIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_CaretDown.CaretDownIcon, { weight: "bold", ...props });
3467
3473
 
3468
3474
  // src/components/TrackControls/ReorderRail.tsx
3469
3475
  var import_styled_components33 = __toESM(require("styled-components"));
@@ -3623,7 +3629,7 @@ var SliderWrapper = import_styled_components35.default.label`
3623
3629
  `;
3624
3630
 
3625
3631
  // src/components/TrackMenu.tsx
3626
- var import_react33 = __toESM(require("react"));
3632
+ var import_react25 = __toESM(require("react"));
3627
3633
  var import_react_dom = require("react-dom");
3628
3634
  var import_styled_components36 = __toESM(require("styled-components"));
3629
3635
  var import_jsx_runtime38 = require("react/jsx-runtime");
@@ -3666,13 +3672,13 @@ var Divider = import_styled_components36.default.hr`
3666
3672
  margin: 0.35rem 0;
3667
3673
  `;
3668
3674
  var TrackMenu = ({ items: itemsProp }) => {
3669
- const [open, setOpen] = (0, import_react33.useState)(false);
3670
- const close = (0, import_react33.useCallback)(() => setOpen(false), []);
3675
+ const [open, setOpen] = (0, import_react25.useState)(false);
3676
+ const close = (0, import_react25.useCallback)(() => setOpen(false), []);
3671
3677
  const items = typeof itemsProp === "function" ? itemsProp(close) : itemsProp;
3672
- const [dropdownPos, setDropdownPos] = (0, import_react33.useState)({ top: 0, left: 0 });
3673
- const buttonRef = (0, import_react33.useRef)(null);
3674
- const dropdownRef = (0, import_react33.useRef)(null);
3675
- const updatePosition = (0, import_react33.useCallback)(() => {
3678
+ const [dropdownPos, setDropdownPos] = (0, import_react25.useState)({ top: 0, left: 0 });
3679
+ const buttonRef = (0, import_react25.useRef)(null);
3680
+ const dropdownRef = (0, import_react25.useRef)(null);
3681
+ const updatePosition = (0, import_react25.useCallback)(() => {
3676
3682
  if (!buttonRef.current) return;
3677
3683
  const rect = buttonRef.current.getBoundingClientRect();
3678
3684
  const vw = window.innerWidth;
@@ -3689,7 +3695,7 @@ var TrackMenu = ({ items: itemsProp }) => {
3689
3695
  }
3690
3696
  setDropdownPos((prev) => prev.top === top && prev.left === left ? prev : { top, left });
3691
3697
  }, []);
3692
- (0, import_react33.useEffect)(() => {
3698
+ (0, import_react25.useEffect)(() => {
3693
3699
  if (!open) return;
3694
3700
  updatePosition();
3695
3701
  let frameId = null;
@@ -3710,7 +3716,7 @@ var TrackMenu = ({ items: itemsProp }) => {
3710
3716
  window.removeEventListener("resize", scheduleUpdate);
3711
3717
  };
3712
3718
  }, [open, updatePosition]);
3713
- (0, import_react33.useEffect)(() => {
3719
+ (0, import_react25.useEffect)(() => {
3714
3720
  if (!open) return;
3715
3721
  const handleClick = (e) => {
3716
3722
  const target = e.target;
@@ -3753,7 +3759,7 @@ var TrackMenu = ({ items: itemsProp }) => {
3753
3759
  $top: dropdownPos.top,
3754
3760
  $left: dropdownPos.left,
3755
3761
  onMouseDown: (e) => e.stopPropagation(),
3756
- children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_react33.default.Fragment, { children: [
3762
+ children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_react25.default.Fragment, { children: [
3757
3763
  index > 0 && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Divider, {}),
3758
3764
  item.content
3759
3765
  ] }, item.id))
@@ -3765,7 +3771,7 @@ var TrackMenu = ({ items: itemsProp }) => {
3765
3771
  };
3766
3772
 
3767
3773
  // src/components/SegmentedVUMeter.tsx
3768
- var import_react34 = __toESM(require("react"));
3774
+ var import_react26 = __toESM(require("react"));
3769
3775
  var import_styled_components37 = __toESM(require("styled-components"));
3770
3776
  var import_core8 = require("@waveform-playlist/core");
3771
3777
  var import_jsx_runtime39 = require("react/jsx-runtime");
@@ -3924,15 +3930,15 @@ var SegmentedVUMeterInner = ({
3924
3930
  labelColor,
3925
3931
  className
3926
3932
  }) => {
3927
- const subscribeToMeter = (0, import_react34.useCallback)(
3933
+ const subscribeToMeter = (0, import_react26.useCallback)(
3928
3934
  (onChange) => meter ? meter.subscribe(onChange) : subscribeToNothing(),
3929
3935
  [meter]
3930
3936
  );
3931
- const getMeterChannelCount = (0, import_react34.useCallback)(
3937
+ const getMeterChannelCount = (0, import_react26.useCallback)(
3932
3938
  () => meter ? meter.getSnapshot().levels.length : NO_METER,
3933
3939
  [meter]
3934
3940
  );
3935
- const meterChannelCount = (0, import_react34.useSyncExternalStore)(
3941
+ const meterChannelCount = (0, import_react26.useSyncExternalStore)(
3936
3942
  subscribeToMeter,
3937
3943
  getMeterChannelCount,
3938
3944
  getMeterChannelCount
@@ -3940,8 +3946,8 @@ var SegmentedVUMeterInner = ({
3940
3946
  const meterSnapshot = meter ? meter.getSnapshot() : null;
3941
3947
  const levels = meterSnapshot ? meterSnapshot.levels : levelsProp ?? NO_LEVELS;
3942
3948
  const peakLevels = meterSnapshot ? meterSnapshot.peakLevels : peakLevelsProp;
3943
- const containerRef = (0, import_react34.useRef)(null);
3944
- const redrawRef = (0, import_react34.useRef)(null);
3949
+ const containerRef = (0, import_react26.useRef)(null);
3950
+ const redrawRef = (0, import_react26.useRef)(null);
3945
3951
  const sourceKey = meter ? "meter" : "props";
3946
3952
  const channelCount = meter ? meterChannelCount : levels.length;
3947
3953
  const labels = channelLabels ?? getDefaultLabels(channelCount);
@@ -3954,11 +3960,11 @@ var SegmentedVUMeterInner = ({
3954
3960
  const isMultiChannel = channelCount >= 2;
3955
3961
  const segmentTotalHeight = segmentHeight + segmentGap;
3956
3962
  const [dBMin, dBMax] = dBRange;
3957
- const thresholds = (0, import_react34.useMemo)(
3963
+ const thresholds = (0, import_react26.useMemo)(
3958
3964
  () => computeThresholds(segmentCount, [dBMin, dBMax]),
3959
3965
  [segmentCount, dBMin, dBMax]
3960
3966
  );
3961
- const scaleLabels = (0, import_react34.useMemo)(() => {
3967
+ const scaleLabels = (0, import_react26.useMemo)(() => {
3962
3968
  const totalSize = segmentCount * segmentTotalHeight - segmentGap;
3963
3969
  const minDb = dBMin;
3964
3970
  const maxDb = dBMax;
@@ -3978,15 +3984,15 @@ var SegmentedVUMeterInner = ({
3978
3984
  }
3979
3985
  return labels2;
3980
3986
  }, [orientation, segmentCount, segmentTotalHeight, segmentGap, dBMin, dBMax]);
3981
- const renderThresholds = (0, import_react34.useMemo)(
3987
+ const renderThresholds = (0, import_react26.useMemo)(
3982
3988
  () => orientation === "horizontal" ? [...thresholds].reverse() : thresholds,
3983
3989
  [thresholds, orientation]
3984
3990
  );
3985
- const segmentColors = (0, import_react34.useMemo)(
3991
+ const segmentColors = (0, import_react26.useMemo)(
3986
3992
  () => renderThresholds.map((threshold) => getColorForDb(threshold, colorStops)),
3987
3993
  [renderThresholds, colorStops]
3988
3994
  );
3989
- (0, import_react34.useLayoutEffect)(() => {
3995
+ (0, import_react26.useLayoutEffect)(() => {
3990
3996
  const container = containerRef.current;
3991
3997
  if (!meter || !container) return;
3992
3998
  const channels = Array.from(container.querySelectorAll("[data-channel]")).map(
@@ -4024,7 +4030,7 @@ var SegmentedVUMeterInner = ({
4024
4030
  redrawRef.current = null;
4025
4031
  };
4026
4032
  }, [meter, channelCount, renderThresholds, segmentColors, coloredInactive, orientation]);
4027
- (0, import_react34.useLayoutEffect)(() => {
4033
+ (0, import_react26.useLayoutEffect)(() => {
4028
4034
  redrawRef.current?.();
4029
4035
  });
4030
4036
  const renderChannel = (channelIndex) => {
@@ -4120,18 +4126,18 @@ var SegmentedVUMeterInner = ({
4120
4126
  sourceKey
4121
4127
  );
4122
4128
  };
4123
- var SegmentedVUMeter = import_react34.default.memo(SegmentedVUMeterInner);
4129
+ var SegmentedVUMeter = import_react26.default.memo(SegmentedVUMeterInner);
4124
4130
 
4125
4131
  // src/hooks/useThrottledValue.ts
4126
- var import_react35 = require("react");
4132
+ var import_react27 = require("react");
4127
4133
  var DEFAULT_UPDATE_RATE = 10;
4128
4134
  function useThrottledValue(source, options = {}) {
4129
4135
  const { updateRate = DEFAULT_UPDATE_RATE } = options;
4130
- const [state, setState] = (0, import_react35.useState)(() => ({
4136
+ const [state, setState] = (0, import_react27.useState)(() => ({
4131
4137
  source,
4132
4138
  value: source.getSnapshot()
4133
4139
  }));
4134
- (0, import_react35.useEffect)(() => {
4140
+ (0, import_react27.useEffect)(() => {
4135
4141
  const interval = 1e3 / (updateRate > 0 ? updateRate : 1);
4136
4142
  let lastUpdate = -Infinity;
4137
4143
  let timer = null;