@waveform-playlist/ui-components 15.0.0-next.6 → 15.0.0-next.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2359,7 +2359,7 @@ var SelectionTimeInputs = ({
2359
2359
  };
2360
2360
 
2361
2361
  // src/components/SpectrogramChannel.tsx
2362
- import { useRef as useRef7, useEffect as useEffect5 } from "react";
2362
+ import { useRef as useRef7, useEffect as useEffect5, useState as useState4 } from "react";
2363
2363
  import styled20 from "styled-components";
2364
2364
  import {
2365
2365
  MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH3,
@@ -2392,6 +2392,23 @@ var SpectrogramCanvas = styled20.canvas.attrs((props) => ({
2392
2392
  image-rendering: pixelated;
2393
2393
  image-rendering: crisp-edges;
2394
2394
  `;
2395
+ function releaseUnmounted(ids, canvases, unregister) {
2396
+ const remaining = /* @__PURE__ */ new Set();
2397
+ for (const id of ids) {
2398
+ const parsed = parseSpectrogramCanvasId(id);
2399
+ const canvas = parsed ? canvases.get(parsed.chunkIndex) : void 0;
2400
+ if (canvas?.isConnected) {
2401
+ remaining.add(id);
2402
+ continue;
2403
+ }
2404
+ try {
2405
+ unregister(id);
2406
+ } catch (err) {
2407
+ console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2408
+ }
2409
+ }
2410
+ return remaining;
2411
+ }
2395
2412
  var SpectrogramChannel = ({
2396
2413
  index,
2397
2414
  channelIndex: channelIndexProp,
@@ -2407,10 +2424,12 @@ var SpectrogramChannel = ({
2407
2424
  }) => {
2408
2425
  const channelIndex = channelIndexProp ?? index;
2409
2426
  const { canvasRef, canvasMapRef } = useChunkedCanvasRefs();
2410
- const registeredIdsRef = useRef7([]);
2427
+ const registeredIdsRef = useRef7(/* @__PURE__ */ new Set());
2411
2428
  const transferredCanvasesRef = useRef7(/* @__PURE__ */ new WeakSet());
2412
2429
  const onCanvasRegisterRef = useRef7(onCanvasRegister);
2413
2430
  const onCanvasUnregisterRef = useRef7(onCanvasUnregister);
2431
+ const releasedRef = useRef7(false);
2432
+ const [generation, setGeneration] = useState4(0);
2414
2433
  const clipOriginX = useClipViewportOrigin();
2415
2434
  const visibleChunkIndices = useVisibleChunkIndices(length, MAX_CANVAS_WIDTH3, clipOriginX);
2416
2435
  useEffect5(() => {
@@ -2421,28 +2440,10 @@ var SpectrogramChannel = ({
2421
2440
  }, [onCanvasUnregister]);
2422
2441
  useEffect5(() => {
2423
2442
  if (!clipId) return;
2443
+ if (releasedRef.current) return;
2424
2444
  const unregister = onCanvasUnregisterRef.current;
2425
2445
  const register = onCanvasRegisterRef.current;
2426
- const remaining = [];
2427
- for (const id of registeredIdsRef.current) {
2428
- const parsed = parseSpectrogramCanvasId(id);
2429
- if (!parsed) {
2430
- remaining.push(id);
2431
- continue;
2432
- }
2433
- const chunkIdx = parsed.chunkIndex;
2434
- const canvas = canvasMapRef.current.get(chunkIdx);
2435
- if (canvas && canvas.isConnected) {
2436
- remaining.push(id);
2437
- } else {
2438
- try {
2439
- unregister(id);
2440
- } catch (err) {
2441
- console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2442
- }
2443
- }
2444
- }
2445
- registeredIdsRef.current = remaining;
2446
+ const remaining = releaseUnmounted(registeredIdsRef.current, canvasMapRef.current, unregister);
2446
2447
  for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
2447
2448
  if (transferredCanvasesRef.current.has(canvas)) continue;
2448
2449
  const canvasId = buildSpectrogramCanvasId({ clipId, channelIndex, chunkIndex: canvasIdx });
@@ -2467,11 +2468,12 @@ var SpectrogramChannel = ({
2467
2468
  ...offsetSamples !== void 0 ? { offsetSamples } : {},
2468
2469
  ...durationSamples !== void 0 ? { durationSamples } : {}
2469
2470
  });
2470
- registeredIdsRef.current.push(canvasId);
2471
+ remaining.add(canvasId);
2471
2472
  } catch (err) {
2472
2473
  console.warn(`[spectrogram] register failed for ${canvasId}:`, err);
2473
2474
  }
2474
2475
  }
2476
+ registeredIdsRef.current = remaining;
2475
2477
  }, [
2476
2478
  canvasMapRef,
2477
2479
  clipId,
@@ -2480,9 +2482,14 @@ var SpectrogramChannel = ({
2480
2482
  waveHeight,
2481
2483
  offsetSamples,
2482
2484
  durationSamples,
2483
- visibleChunkIndices
2485
+ visibleChunkIndices,
2486
+ generation
2484
2487
  ]);
2485
2488
  useEffect5(() => {
2489
+ if (releasedRef.current) {
2490
+ releasedRef.current = false;
2491
+ setGeneration((g) => g + 1);
2492
+ }
2486
2493
  return () => {
2487
2494
  const unregister = onCanvasUnregisterRef.current;
2488
2495
  for (const id of registeredIdsRef.current) {
@@ -2492,7 +2499,8 @@ var SpectrogramChannel = ({
2492
2499
  console.warn(`[spectrogram] unregister failed for ${id}:`, err);
2493
2500
  }
2494
2501
  }
2495
- registeredIdsRef.current = [];
2502
+ registeredIdsRef.current = /* @__PURE__ */ new Set();
2503
+ releasedRef.current = true;
2496
2504
  };
2497
2505
  }, []);
2498
2506
  const canvases = visibleChunkIndices.map((i) => {
@@ -2509,7 +2517,7 @@ var SpectrogramChannel = ({
2509
2517
  "data-index": i,
2510
2518
  ref: canvasRef
2511
2519
  },
2512
- `${length}-${waveHeight}-${offsetSamples ?? ""}-${durationSamples ?? ""}-${i}`
2520
+ `${generation}-${length}-${waveHeight}-${offsetSamples ?? ""}-${durationSamples ?? ""}-${i}`
2513
2521
  );
2514
2522
  });
2515
2523
  return /* @__PURE__ */ jsx21(Wrapper4, { $index: index, $cssWidth: length, $waveHeight: waveHeight, children: canvases });
@@ -2988,10 +2996,9 @@ var SmartScale = ({
2988
2996
  const { marker, bigStep, smallStep } = config;
2989
2997
  const canvasInfo = /* @__PURE__ */ new Map();
2990
2998
  const labels = [];
2991
- const pixPerSec = sampleRate / samplesPerPixel;
2992
- let counter = 0;
2993
- for (let i = 0; i < widthX; i += pixPerSec * smallStep / 1e3) {
2994
- const pix = Math.floor(i);
2999
+ for (let counter = 0; ; counter += smallStep) {
3000
+ const pix = Math.floor(counter * sampleRate / (1e3 * samplesPerPixel));
3001
+ if (!(pix < widthX)) break;
2995
3002
  if (counter % marker === 0) {
2996
3003
  labels.push({
2997
3004
  id: `timestamp-${counter}`,
@@ -3005,7 +3012,6 @@ var SmartScale = ({
3005
3012
  } else if (counter % smallStep === 0) {
3006
3013
  canvasInfo.set(pix, Math.floor(timeScaleHeight / 5));
3007
3014
  }
3008
- counter += smallStep;
3009
3015
  }
3010
3016
  return { widthX, canvasInfo, labels };
3011
3017
  }, [beatsAndBars, duration, samplesPerPixel, sampleRate, timeScaleHeight]);
@@ -3519,7 +3525,7 @@ var SliderWrapper = styled34.label`
3519
3525
  `;
3520
3526
 
3521
3527
  // src/components/TrackMenu.tsx
3522
- import React20, { useState as useState4, useEffect as useEffect6, useRef as useRef9, useCallback as useCallback5 } from "react";
3528
+ import React20, { useState as useState5, useEffect as useEffect6, useRef as useRef9, useCallback as useCallback5 } from "react";
3523
3529
  import { createPortal } from "react-dom";
3524
3530
  import styled35 from "styled-components";
3525
3531
  import { jsx as jsx38, jsxs as jsxs12 } from "react/jsx-runtime";
@@ -3562,10 +3568,10 @@ var Divider = styled35.hr`
3562
3568
  margin: 0.35rem 0;
3563
3569
  `;
3564
3570
  var TrackMenu = ({ items: itemsProp }) => {
3565
- const [open, setOpen] = useState4(false);
3571
+ const [open, setOpen] = useState5(false);
3566
3572
  const close = useCallback5(() => setOpen(false), []);
3567
3573
  const items = typeof itemsProp === "function" ? itemsProp(close) : itemsProp;
3568
- const [dropdownPos, setDropdownPos] = useState4({ top: 0, left: 0 });
3574
+ const [dropdownPos, setDropdownPos] = useState5({ top: 0, left: 0 });
3569
3575
  const buttonRef = useRef9(null);
3570
3576
  const dropdownRef = useRef9(null);
3571
3577
  const updatePosition = useCallback5(() => {
@@ -4019,11 +4025,11 @@ var SegmentedVUMeterInner = ({
4019
4025
  var SegmentedVUMeter = React21.memo(SegmentedVUMeterInner);
4020
4026
 
4021
4027
  // src/hooks/useThrottledValue.ts
4022
- import { useEffect as useEffect7, useState as useState5 } from "react";
4028
+ import { useEffect as useEffect7, useState as useState6 } from "react";
4023
4029
  var DEFAULT_UPDATE_RATE = 10;
4024
4030
  function useThrottledValue(source, options = {}) {
4025
4031
  const { updateRate = DEFAULT_UPDATE_RATE } = options;
4026
- const [state, setState] = useState5(() => ({
4032
+ const [state, setState] = useState6(() => ({
4027
4033
  source,
4028
4034
  value: source.getSnapshot()
4029
4035
  }));