@waveform-playlist/ui-components 12.0.0 → 13.0.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.d.mts +32 -15
- package/dist/index.d.ts +32 -15
- package/dist/index.js +42 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1487,6 +1487,7 @@ var PlayheadWithMarker = ({
|
|
|
1487
1487
|
color = "#ff0000",
|
|
1488
1488
|
isPlaying,
|
|
1489
1489
|
currentTimeRef,
|
|
1490
|
+
visualTimeRef,
|
|
1490
1491
|
playbackStartTimeRef,
|
|
1491
1492
|
audioStartPositionRef,
|
|
1492
1493
|
samplesPerPixel,
|
|
@@ -1501,7 +1502,9 @@ var PlayheadWithMarker = ({
|
|
|
1501
1502
|
const updatePosition = () => {
|
|
1502
1503
|
if (containerRef.current) {
|
|
1503
1504
|
let time;
|
|
1504
|
-
if (
|
|
1505
|
+
if (visualTimeRef?.current !== void 0 && visualTimeRef.current !== null) {
|
|
1506
|
+
time = visualTimeRef.current;
|
|
1507
|
+
} else if (isPlaying) {
|
|
1505
1508
|
if (getPlaybackTime) {
|
|
1506
1509
|
time = getPlaybackTime();
|
|
1507
1510
|
} else if (getAudioContextTime) {
|
|
@@ -1537,6 +1540,7 @@ var PlayheadWithMarker = ({
|
|
|
1537
1540
|
samplesPerPixel,
|
|
1538
1541
|
controlsOffset,
|
|
1539
1542
|
currentTimeRef,
|
|
1543
|
+
visualTimeRef,
|
|
1540
1544
|
playbackStartTimeRef,
|
|
1541
1545
|
audioStartPositionRef,
|
|
1542
1546
|
getAudioContextTime,
|
|
@@ -1544,7 +1548,7 @@ var PlayheadWithMarker = ({
|
|
|
1544
1548
|
]);
|
|
1545
1549
|
useEffect3(() => {
|
|
1546
1550
|
if (!isPlaying && containerRef.current) {
|
|
1547
|
-
const time = currentTimeRef.current ?? 0;
|
|
1551
|
+
const time = visualTimeRef?.current ?? currentTimeRef.current ?? 0;
|
|
1548
1552
|
const pos = time * sampleRate / samplesPerPixel + controlsOffset;
|
|
1549
1553
|
containerRef.current.style.transform = `translate3d(${pos}px, 0, 0)`;
|
|
1550
1554
|
}
|
|
@@ -2346,28 +2350,28 @@ var SpectrogramChannel = ({
|
|
|
2346
2350
|
waveHeight,
|
|
2347
2351
|
devicePixelRatio = 1,
|
|
2348
2352
|
samplesPerPixel: _samplesPerPixel,
|
|
2349
|
-
workerApi,
|
|
2350
2353
|
clipId,
|
|
2351
|
-
|
|
2354
|
+
onCanvasRegister,
|
|
2355
|
+
onCanvasUnregister
|
|
2352
2356
|
}) => {
|
|
2353
2357
|
const channelIndex = channelIndexProp ?? index;
|
|
2354
2358
|
const { canvasRef, canvasMapRef } = useChunkedCanvasRefs();
|
|
2355
2359
|
const registeredIdsRef = useRef7([]);
|
|
2356
2360
|
const transferredCanvasesRef = useRef7(/* @__PURE__ */ new WeakSet());
|
|
2357
|
-
const
|
|
2358
|
-
const
|
|
2361
|
+
const onCanvasRegisterRef = useRef7(onCanvasRegister);
|
|
2362
|
+
const onCanvasUnregisterRef = useRef7(onCanvasUnregister);
|
|
2359
2363
|
const clipOriginX = useClipViewportOrigin();
|
|
2360
2364
|
const visibleChunkIndices = useVisibleChunkIndices(length, MAX_CANVAS_WIDTH3, clipOriginX);
|
|
2361
2365
|
useEffect6(() => {
|
|
2362
|
-
|
|
2363
|
-
}, [
|
|
2366
|
+
onCanvasRegisterRef.current = onCanvasRegister;
|
|
2367
|
+
}, [onCanvasRegister]);
|
|
2364
2368
|
useEffect6(() => {
|
|
2365
|
-
|
|
2366
|
-
}, [
|
|
2369
|
+
onCanvasUnregisterRef.current = onCanvasUnregister;
|
|
2370
|
+
}, [onCanvasUnregister]);
|
|
2367
2371
|
useEffect6(() => {
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
const
|
|
2372
|
+
if (!clipId) return;
|
|
2373
|
+
const unregister = onCanvasUnregisterRef.current;
|
|
2374
|
+
const register = onCanvasRegisterRef.current;
|
|
2371
2375
|
const remaining = [];
|
|
2372
2376
|
for (const id of registeredIdsRef.current) {
|
|
2373
2377
|
const match = id.match(/chunk(\d+)$/);
|
|
@@ -2381,14 +2385,13 @@ var SpectrogramChannel = ({
|
|
|
2381
2385
|
remaining.push(id);
|
|
2382
2386
|
} else {
|
|
2383
2387
|
try {
|
|
2384
|
-
|
|
2388
|
+
unregister(id);
|
|
2385
2389
|
} catch (err) {
|
|
2386
|
-
console.warn(`[spectrogram]
|
|
2390
|
+
console.warn(`[spectrogram] unregister failed for ${id}:`, err);
|
|
2387
2391
|
}
|
|
2388
2392
|
}
|
|
2389
2393
|
}
|
|
2390
2394
|
registeredIdsRef.current = remaining;
|
|
2391
|
-
const newIds = [];
|
|
2392
2395
|
for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
|
|
2393
2396
|
if (transferredCanvasesRef.current.has(canvas)) continue;
|
|
2394
2397
|
const canvasId = `${clipId}-ch${channelIndex}-chunk${canvasIdx}`;
|
|
@@ -2400,41 +2403,31 @@ var SpectrogramChannel = ({
|
|
|
2400
2403
|
continue;
|
|
2401
2404
|
}
|
|
2402
2405
|
transferredCanvasesRef.current.add(canvas);
|
|
2406
|
+
const widthPx = Math.min(length - canvasIdx * MAX_CANVAS_WIDTH3, MAX_CANVAS_WIDTH3);
|
|
2403
2407
|
try {
|
|
2404
|
-
|
|
2405
|
-
|
|
2408
|
+
register({
|
|
2409
|
+
canvasId,
|
|
2410
|
+
canvas: offscreen,
|
|
2411
|
+
clipId,
|
|
2412
|
+
channelIndex,
|
|
2413
|
+
chunkIndex: canvasIdx,
|
|
2414
|
+
widthPx,
|
|
2415
|
+
heightPx: waveHeight
|
|
2416
|
+
});
|
|
2417
|
+
registeredIdsRef.current.push(canvasId);
|
|
2406
2418
|
} catch (err) {
|
|
2407
|
-
console.warn(`[spectrogram]
|
|
2408
|
-
continue;
|
|
2419
|
+
console.warn(`[spectrogram] register failed for ${canvasId}:`, err);
|
|
2409
2420
|
}
|
|
2410
2421
|
}
|
|
2411
|
-
|
|
2412
|
-
registeredIdsRef.current = [...registeredIdsRef.current, ...newIds];
|
|
2413
|
-
}
|
|
2414
|
-
const canvasSetChanged = newIds.length > 0 || remaining.length < previousCount;
|
|
2415
|
-
if (canvasSetChanged) {
|
|
2416
|
-
const allIds = registeredIdsRef.current;
|
|
2417
|
-
const allWidths = allIds.map((id) => {
|
|
2418
|
-
const match = id.match(/chunk(\d+)$/);
|
|
2419
|
-
if (!match) {
|
|
2420
|
-
console.warn(`[spectrogram] Unexpected canvas ID format: ${id}`);
|
|
2421
|
-
return MAX_CANVAS_WIDTH3;
|
|
2422
|
-
}
|
|
2423
|
-
const chunkIdx = parseInt(match[1], 10);
|
|
2424
|
-
return Math.min(length - chunkIdx * MAX_CANVAS_WIDTH3, MAX_CANVAS_WIDTH3);
|
|
2425
|
-
});
|
|
2426
|
-
onCanvasesReadyRef.current?.(allIds, allWidths);
|
|
2427
|
-
}
|
|
2428
|
-
}, [canvasMapRef, clipId, channelIndex, length, visibleChunkIndices]);
|
|
2422
|
+
}, [canvasMapRef, clipId, channelIndex, length, waveHeight, visibleChunkIndices]);
|
|
2429
2423
|
useEffect6(() => {
|
|
2430
2424
|
return () => {
|
|
2431
|
-
const
|
|
2432
|
-
if (!api) return;
|
|
2425
|
+
const unregister = onCanvasUnregisterRef.current;
|
|
2433
2426
|
for (const id of registeredIdsRef.current) {
|
|
2434
2427
|
try {
|
|
2435
|
-
|
|
2428
|
+
unregister(id);
|
|
2436
2429
|
} catch (err) {
|
|
2437
|
-
console.warn(`[spectrogram]
|
|
2430
|
+
console.warn(`[spectrogram] unregister failed for ${id}:`, err);
|
|
2438
2431
|
}
|
|
2439
2432
|
}
|
|
2440
2433
|
registeredIdsRef.current = [];
|
|
@@ -2467,9 +2460,9 @@ var SmartChannel = ({
|
|
|
2467
2460
|
transparentBackground,
|
|
2468
2461
|
renderMode = "waveform",
|
|
2469
2462
|
samplesPerPixel: sppProp,
|
|
2470
|
-
spectrogramWorkerApi,
|
|
2471
2463
|
spectrogramClipId,
|
|
2472
|
-
|
|
2464
|
+
spectrogramOnCanvasRegister,
|
|
2465
|
+
spectrogramOnCanvasUnregister,
|
|
2473
2466
|
midiNotes,
|
|
2474
2467
|
sampleRate: sampleRateProp,
|
|
2475
2468
|
clipOffsetSeconds,
|
|
@@ -2488,7 +2481,7 @@ var SmartChannel = ({
|
|
|
2488
2481
|
const waveOutlineColor = isSelected && theme ? theme.selectedWaveOutlineColor : theme?.waveOutlineColor;
|
|
2489
2482
|
const waveFillColor = isSelected && theme ? theme.selectedWaveFillColor : theme?.waveFillColor;
|
|
2490
2483
|
const drawMode = theme?.waveformDrawMode || "inverted";
|
|
2491
|
-
const hasSpectrogram =
|
|
2484
|
+
const hasSpectrogram = spectrogramClipId && spectrogramOnCanvasRegister && spectrogramOnCanvasUnregister;
|
|
2492
2485
|
if (renderMode === "spectrogram" && hasSpectrogram) {
|
|
2493
2486
|
return /* @__PURE__ */ jsx24(
|
|
2494
2487
|
SpectrogramChannel,
|
|
@@ -2498,9 +2491,9 @@ var SmartChannel = ({
|
|
|
2498
2491
|
waveHeight,
|
|
2499
2492
|
devicePixelRatio,
|
|
2500
2493
|
samplesPerPixel,
|
|
2501
|
-
workerApi: spectrogramWorkerApi,
|
|
2502
2494
|
clipId: spectrogramClipId,
|
|
2503
|
-
|
|
2495
|
+
onCanvasRegister: spectrogramOnCanvasRegister,
|
|
2496
|
+
onCanvasUnregister: spectrogramOnCanvasUnregister
|
|
2504
2497
|
}
|
|
2505
2498
|
);
|
|
2506
2499
|
}
|
|
@@ -2516,9 +2509,9 @@ var SmartChannel = ({
|
|
|
2516
2509
|
waveHeight: halfHeight,
|
|
2517
2510
|
devicePixelRatio,
|
|
2518
2511
|
samplesPerPixel,
|
|
2519
|
-
workerApi: spectrogramWorkerApi,
|
|
2520
2512
|
clipId: spectrogramClipId,
|
|
2521
|
-
|
|
2513
|
+
onCanvasRegister: spectrogramOnCanvasRegister,
|
|
2514
|
+
onCanvasUnregister: spectrogramOnCanvasUnregister
|
|
2522
2515
|
}
|
|
2523
2516
|
),
|
|
2524
2517
|
/* @__PURE__ */ jsx24(
|