@waveform-playlist/ui-components 15.0.0-next.0 → 15.0.0-next.10

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]);
@@ -3267,7 +3273,7 @@ var ButtonGroup = styled28.div`
3267
3273
 
3268
3274
  // src/components/TrackControls/CloseButton.tsx
3269
3275
  import styled29 from "styled-components";
3270
- import { X as XIcon } from "@phosphor-icons/react";
3276
+ import { XIcon } from "@phosphor-icons/react/dist/csr/X";
3271
3277
  import { jsx as jsx29 } from "react/jsx-runtime";
3272
3278
  var StyledCloseButton = styled29.button`
3273
3279
  position: absolute;
@@ -3327,37 +3333,37 @@ var Header = styled31.header`
3327
3333
  `;
3328
3334
 
3329
3335
  // src/components/TrackControls/VolumeDownIcon.tsx
3330
- import { SpeakerLowIcon } from "@phosphor-icons/react";
3336
+ import { SpeakerLowIcon } from "@phosphor-icons/react/dist/csr/SpeakerLow";
3331
3337
  import { jsx as jsx30 } from "react/jsx-runtime";
3332
3338
  var VolumeDownIcon = (props) => /* @__PURE__ */ jsx30(SpeakerLowIcon, { weight: "light", ...props });
3333
3339
 
3334
3340
  // src/components/TrackControls/VolumeUpIcon.tsx
3335
- import { SpeakerHighIcon } from "@phosphor-icons/react";
3341
+ import { SpeakerHighIcon } from "@phosphor-icons/react/dist/csr/SpeakerHigh";
3336
3342
  import { jsx as jsx31 } from "react/jsx-runtime";
3337
3343
  var VolumeUpIcon = (props) => /* @__PURE__ */ jsx31(SpeakerHighIcon, { weight: "light", ...props });
3338
3344
 
3339
3345
  // src/components/TrackControls/TrashIcon.tsx
3340
- import { TrashIcon as PhosphorTrashIcon } from "@phosphor-icons/react";
3346
+ import { TrashIcon as PhosphorTrashIcon } from "@phosphor-icons/react/dist/csr/Trash";
3341
3347
  import { jsx as jsx32 } from "react/jsx-runtime";
3342
3348
  var TrashIcon = (props) => /* @__PURE__ */ jsx32(PhosphorTrashIcon, { weight: "light", ...props });
3343
3349
 
3344
3350
  // src/components/TrackControls/DotsIcon.tsx
3345
- import { DotsThreeIcon } from "@phosphor-icons/react";
3351
+ import { DotsThreeIcon } from "@phosphor-icons/react/dist/csr/DotsThree";
3346
3352
  import { jsx as jsx33 } from "react/jsx-runtime";
3347
3353
  var DotsIcon = (props) => /* @__PURE__ */ jsx33(DotsThreeIcon, { weight: "bold", ...props });
3348
3354
 
3349
3355
  // src/components/TrackControls/GripIcon.tsx
3350
- import { DotsSixVerticalIcon } from "@phosphor-icons/react";
3356
+ import { DotsSixVerticalIcon } from "@phosphor-icons/react/dist/csr/DotsSixVertical";
3351
3357
  import { jsx as jsx34 } from "react/jsx-runtime";
3352
3358
  var GripIcon = (props) => /* @__PURE__ */ jsx34(DotsSixVerticalIcon, { weight: "bold", ...props });
3353
3359
 
3354
3360
  // src/components/TrackControls/MoveUpIcon.tsx
3355
- import { CaretUpIcon } from "@phosphor-icons/react";
3361
+ import { CaretUpIcon } from "@phosphor-icons/react/dist/csr/CaretUp";
3356
3362
  import { jsx as jsx35 } from "react/jsx-runtime";
3357
3363
  var MoveUpIcon = (props) => /* @__PURE__ */ jsx35(CaretUpIcon, { weight: "bold", ...props });
3358
3364
 
3359
3365
  // src/components/TrackControls/MoveDownIcon.tsx
3360
- import { CaretDownIcon } from "@phosphor-icons/react";
3366
+ import { CaretDownIcon } from "@phosphor-icons/react/dist/csr/CaretDown";
3361
3367
  import { jsx as jsx36 } from "react/jsx-runtime";
3362
3368
  var MoveDownIcon = (props) => /* @__PURE__ */ jsx36(CaretDownIcon, { weight: "bold", ...props });
3363
3369
 
@@ -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
  }));