@waveform-playlist/ui-components 9.5.0 → 9.5.2
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 +4 -24
- package/dist/index.d.ts +4 -24
- package/dist/index.js +3 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -2297,11 +2297,10 @@ var usePlayoutStatus = () => useContext8(PlayoutStatusContext);
|
|
|
2297
2297
|
var usePlayoutStatusUpdate = () => useContext8(PlayoutStatusUpdateContext);
|
|
2298
2298
|
|
|
2299
2299
|
// src/components/SpectrogramChannel.tsx
|
|
2300
|
-
import { useRef as useRef6, useEffect as useEffect6
|
|
2300
|
+
import { useRef as useRef6, useEffect as useEffect6 } from "react";
|
|
2301
2301
|
import styled20 from "styled-components";
|
|
2302
2302
|
import { MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH3 } from "@waveform-playlist/core";
|
|
2303
2303
|
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2304
|
-
var LINEAR_FREQUENCY_SCALE = (f, minF, maxF) => (f - minF) / (maxF - minF);
|
|
2305
2304
|
var Wrapper4 = styled20.div.attrs((props) => ({
|
|
2306
2305
|
style: {
|
|
2307
2306
|
top: `${props.$waveHeight * props.$index}px`,
|
|
@@ -2326,26 +2325,13 @@ var SpectrogramCanvas = styled20.canvas.attrs((props) => ({
|
|
|
2326
2325
|
image-rendering: pixelated;
|
|
2327
2326
|
image-rendering: crisp-edges;
|
|
2328
2327
|
`;
|
|
2329
|
-
function defaultGetColorMap() {
|
|
2330
|
-
const lut = new Uint8Array(256 * 3);
|
|
2331
|
-
for (let i = 0; i < 256; i++) {
|
|
2332
|
-
lut[i * 3] = lut[i * 3 + 1] = lut[i * 3 + 2] = i;
|
|
2333
|
-
}
|
|
2334
|
-
return lut;
|
|
2335
|
-
}
|
|
2336
|
-
var DEFAULT_COLOR_LUT = defaultGetColorMap();
|
|
2337
2328
|
var SpectrogramChannel = ({
|
|
2338
2329
|
index,
|
|
2339
2330
|
channelIndex: channelIndexProp,
|
|
2340
|
-
data,
|
|
2341
2331
|
length,
|
|
2342
2332
|
waveHeight,
|
|
2343
2333
|
devicePixelRatio = 1,
|
|
2344
|
-
samplesPerPixel,
|
|
2345
|
-
colorLUT,
|
|
2346
|
-
frequencyScaleFn,
|
|
2347
|
-
minFrequency = 0,
|
|
2348
|
-
maxFrequency,
|
|
2334
|
+
samplesPerPixel: _samplesPerPixel,
|
|
2349
2335
|
workerApi,
|
|
2350
2336
|
clipId,
|
|
2351
2337
|
onCanvasesReady
|
|
@@ -2356,13 +2342,8 @@ var SpectrogramChannel = ({
|
|
|
2356
2342
|
const transferredCanvasesRef = useRef6(/* @__PURE__ */ new WeakSet());
|
|
2357
2343
|
const workerApiRef = useRef6(workerApi);
|
|
2358
2344
|
const onCanvasesReadyRef = useRef6(onCanvasesReady);
|
|
2359
|
-
const isWorkerMode = !!(workerApi && clipId);
|
|
2360
2345
|
const clipOriginX = useClipViewportOrigin();
|
|
2361
2346
|
const visibleChunkIndices = useVisibleChunkIndices(length, MAX_CANVAS_WIDTH3, clipOriginX);
|
|
2362
|
-
const lut = colorLUT ?? DEFAULT_COLOR_LUT;
|
|
2363
|
-
const maxF = maxFrequency ?? (data ? data.sampleRate / 2 : 22050);
|
|
2364
|
-
const scaleFn = frequencyScaleFn ?? LINEAR_FREQUENCY_SCALE;
|
|
2365
|
-
const hasCustomFrequencyScale = Boolean(frequencyScaleFn);
|
|
2366
2347
|
useEffect6(() => {
|
|
2367
2348
|
workerApiRef.current = workerApi;
|
|
2368
2349
|
}, [workerApi]);
|
|
@@ -2370,7 +2351,6 @@ var SpectrogramChannel = ({
|
|
|
2370
2351
|
onCanvasesReadyRef.current = onCanvasesReady;
|
|
2371
2352
|
}, [onCanvasesReady]);
|
|
2372
2353
|
useEffect6(() => {
|
|
2373
|
-
if (!isWorkerMode) return;
|
|
2374
2354
|
const currentWorkerApi = workerApiRef.current;
|
|
2375
2355
|
if (!currentWorkerApi || !clipId) return;
|
|
2376
2356
|
const previousCount = registeredIdsRef.current.length;
|
|
@@ -2431,7 +2411,7 @@ var SpectrogramChannel = ({
|
|
|
2431
2411
|
});
|
|
2432
2412
|
onCanvasesReadyRef.current?.(allIds, allWidths);
|
|
2433
2413
|
}
|
|
2434
|
-
}, [canvasMapRef,
|
|
2414
|
+
}, [canvasMapRef, clipId, channelIndex, length, visibleChunkIndices]);
|
|
2435
2415
|
useEffect6(() => {
|
|
2436
2416
|
return () => {
|
|
2437
2417
|
const api = workerApiRef.current;
|
|
@@ -2446,94 +2426,6 @@ var SpectrogramChannel = ({
|
|
|
2446
2426
|
registeredIdsRef.current = [];
|
|
2447
2427
|
};
|
|
2448
2428
|
}, []);
|
|
2449
|
-
useLayoutEffect4(() => {
|
|
2450
|
-
if (isWorkerMode || !data) return;
|
|
2451
|
-
const {
|
|
2452
|
-
frequencyBinCount,
|
|
2453
|
-
frameCount,
|
|
2454
|
-
hopSize,
|
|
2455
|
-
sampleRate,
|
|
2456
|
-
gainDb,
|
|
2457
|
-
rangeDb: rawRangeDb
|
|
2458
|
-
} = data;
|
|
2459
|
-
const rangeDb = rawRangeDb === 0 ? 1 : rawRangeDb;
|
|
2460
|
-
const binToFreq = (bin) => bin / frequencyBinCount * (sampleRate / 2);
|
|
2461
|
-
for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
|
|
2462
|
-
const globalPixelOffset = canvasIdx * MAX_CANVAS_WIDTH3;
|
|
2463
|
-
const ctx = canvas.getContext("2d");
|
|
2464
|
-
if (!ctx) continue;
|
|
2465
|
-
const canvasWidth = canvas.width / devicePixelRatio;
|
|
2466
|
-
const canvasHeight = waveHeight;
|
|
2467
|
-
ctx.resetTransform();
|
|
2468
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
2469
|
-
ctx.imageSmoothingEnabled = false;
|
|
2470
|
-
ctx.scale(devicePixelRatio, devicePixelRatio);
|
|
2471
|
-
const imgData = ctx.createImageData(canvasWidth, canvasHeight);
|
|
2472
|
-
const pixels = imgData.data;
|
|
2473
|
-
for (let x = 0; x < canvasWidth; x++) {
|
|
2474
|
-
const globalX = globalPixelOffset + x;
|
|
2475
|
-
const samplePos = globalX * samplesPerPixel;
|
|
2476
|
-
const frame = Math.floor(samplePos / hopSize);
|
|
2477
|
-
if (frame < 0 || frame >= frameCount) continue;
|
|
2478
|
-
const frameOffset = frame * frequencyBinCount;
|
|
2479
|
-
for (let y = 0; y < canvasHeight; y++) {
|
|
2480
|
-
const normalizedY = 1 - y / canvasHeight;
|
|
2481
|
-
let bin = Math.floor(normalizedY * frequencyBinCount);
|
|
2482
|
-
if (hasCustomFrequencyScale) {
|
|
2483
|
-
let lo = 0;
|
|
2484
|
-
let hi = frequencyBinCount - 1;
|
|
2485
|
-
while (lo < hi) {
|
|
2486
|
-
const mid = lo + hi >> 1;
|
|
2487
|
-
const freq = binToFreq(mid);
|
|
2488
|
-
const scaled = scaleFn(freq, minFrequency, maxF);
|
|
2489
|
-
if (scaled < normalizedY) {
|
|
2490
|
-
lo = mid + 1;
|
|
2491
|
-
} else {
|
|
2492
|
-
hi = mid;
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
bin = lo;
|
|
2496
|
-
}
|
|
2497
|
-
if (bin < 0 || bin >= frequencyBinCount) continue;
|
|
2498
|
-
const db = data.data[frameOffset + bin];
|
|
2499
|
-
const normalized = Math.max(0, Math.min(1, (db + rangeDb + gainDb) / rangeDb));
|
|
2500
|
-
const colorIdx = Math.floor(normalized * 255);
|
|
2501
|
-
const pixelIdx = (y * canvasWidth + x) * 4;
|
|
2502
|
-
pixels[pixelIdx] = lut[colorIdx * 3];
|
|
2503
|
-
pixels[pixelIdx + 1] = lut[colorIdx * 3 + 1];
|
|
2504
|
-
pixels[pixelIdx + 2] = lut[colorIdx * 3 + 2];
|
|
2505
|
-
pixels[pixelIdx + 3] = 255;
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
ctx.resetTransform();
|
|
2509
|
-
ctx.putImageData(imgData, 0, 0);
|
|
2510
|
-
if (devicePixelRatio !== 1) {
|
|
2511
|
-
const tmpCanvas = document.createElement("canvas");
|
|
2512
|
-
tmpCanvas.width = canvasWidth;
|
|
2513
|
-
tmpCanvas.height = canvasHeight;
|
|
2514
|
-
const tmpCtx = tmpCanvas.getContext("2d");
|
|
2515
|
-
if (!tmpCtx) continue;
|
|
2516
|
-
tmpCtx.putImageData(imgData, 0, 0);
|
|
2517
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
2518
|
-
ctx.imageSmoothingEnabled = false;
|
|
2519
|
-
ctx.drawImage(tmpCanvas, 0, 0, canvas.width, canvas.height);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
}, [
|
|
2523
|
-
canvasMapRef,
|
|
2524
|
-
isWorkerMode,
|
|
2525
|
-
data,
|
|
2526
|
-
length,
|
|
2527
|
-
waveHeight,
|
|
2528
|
-
devicePixelRatio,
|
|
2529
|
-
samplesPerPixel,
|
|
2530
|
-
lut,
|
|
2531
|
-
minFrequency,
|
|
2532
|
-
maxF,
|
|
2533
|
-
scaleFn,
|
|
2534
|
-
hasCustomFrequencyScale,
|
|
2535
|
-
visibleChunkIndices
|
|
2536
|
-
]);
|
|
2537
2429
|
const canvases = visibleChunkIndices.map((i) => {
|
|
2538
2430
|
const chunkLeft = i * MAX_CANVAS_WIDTH3;
|
|
2539
2431
|
const currentWidth = Math.min(length - chunkLeft, MAX_CANVAS_WIDTH3);
|
|
@@ -2560,12 +2452,7 @@ var SmartChannel = ({
|
|
|
2560
2452
|
isSelected,
|
|
2561
2453
|
transparentBackground,
|
|
2562
2454
|
renderMode = "waveform",
|
|
2563
|
-
spectrogramData,
|
|
2564
|
-
spectrogramColorLUT,
|
|
2565
2455
|
samplesPerPixel: sppProp,
|
|
2566
|
-
spectrogramFrequencyScaleFn,
|
|
2567
|
-
spectrogramMinFrequency,
|
|
2568
|
-
spectrogramMaxFrequency,
|
|
2569
2456
|
spectrogramWorkerApi,
|
|
2570
2457
|
spectrogramClipId,
|
|
2571
2458
|
spectrogramOnCanvasesReady,
|
|
@@ -2587,21 +2474,16 @@ var SmartChannel = ({
|
|
|
2587
2474
|
const waveOutlineColor = isSelected && theme ? theme.selectedWaveOutlineColor : theme?.waveOutlineColor;
|
|
2588
2475
|
const waveFillColor = isSelected && theme ? theme.selectedWaveFillColor : theme?.waveFillColor;
|
|
2589
2476
|
const drawMode = theme?.waveformDrawMode || "inverted";
|
|
2590
|
-
const hasSpectrogram =
|
|
2477
|
+
const hasSpectrogram = spectrogramWorkerApi && spectrogramClipId;
|
|
2591
2478
|
if (renderMode === "spectrogram" && hasSpectrogram) {
|
|
2592
2479
|
return /* @__PURE__ */ jsx24(
|
|
2593
2480
|
SpectrogramChannel,
|
|
2594
2481
|
{
|
|
2595
2482
|
index: props.index,
|
|
2596
|
-
data: spectrogramData,
|
|
2597
2483
|
length: props.length,
|
|
2598
2484
|
waveHeight,
|
|
2599
2485
|
devicePixelRatio,
|
|
2600
2486
|
samplesPerPixel,
|
|
2601
|
-
colorLUT: spectrogramColorLUT,
|
|
2602
|
-
frequencyScaleFn: spectrogramFrequencyScaleFn,
|
|
2603
|
-
minFrequency: spectrogramMinFrequency,
|
|
2604
|
-
maxFrequency: spectrogramMaxFrequency,
|
|
2605
2487
|
workerApi: spectrogramWorkerApi,
|
|
2606
2488
|
clipId: spectrogramClipId,
|
|
2607
2489
|
onCanvasesReady: spectrogramOnCanvasesReady
|
|
@@ -2616,15 +2498,10 @@ var SmartChannel = ({
|
|
|
2616
2498
|
{
|
|
2617
2499
|
index: props.index * 2,
|
|
2618
2500
|
channelIndex: props.index,
|
|
2619
|
-
data: spectrogramData,
|
|
2620
2501
|
length: props.length,
|
|
2621
2502
|
waveHeight: halfHeight,
|
|
2622
2503
|
devicePixelRatio,
|
|
2623
2504
|
samplesPerPixel,
|
|
2624
|
-
colorLUT: spectrogramColorLUT,
|
|
2625
|
-
frequencyScaleFn: spectrogramFrequencyScaleFn,
|
|
2626
|
-
minFrequency: spectrogramMinFrequency,
|
|
2627
|
-
maxFrequency: spectrogramMaxFrequency,
|
|
2628
2505
|
workerApi: spectrogramWorkerApi,
|
|
2629
2506
|
clipId: spectrogramClipId,
|
|
2630
2507
|
onCanvasesReady: spectrogramOnCanvasesReady
|
|
@@ -2695,7 +2572,7 @@ var SmartChannel = ({
|
|
|
2695
2572
|
};
|
|
2696
2573
|
|
|
2697
2574
|
// src/components/SpectrogramLabels.tsx
|
|
2698
|
-
import { useRef as useRef7, useLayoutEffect as
|
|
2575
|
+
import { useRef as useRef7, useLayoutEffect as useLayoutEffect4 } from "react";
|
|
2699
2576
|
import styled21 from "styled-components";
|
|
2700
2577
|
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
2701
2578
|
var LABELS_WIDTH = 72;
|
|
@@ -2752,7 +2629,7 @@ var SpectrogramLabels = ({
|
|
|
2752
2629
|
const spectrogramHeight = renderMode === "both" ? Math.floor(waveHeight / 2) : waveHeight;
|
|
2753
2630
|
const totalHeight = numChannels * waveHeight;
|
|
2754
2631
|
const clipHeaderOffset = hasClipHeaders ? 22 : 0;
|
|
2755
|
-
|
|
2632
|
+
useLayoutEffect4(() => {
|
|
2756
2633
|
const canvas = canvasRef.current;
|
|
2757
2634
|
if (!canvas) return;
|
|
2758
2635
|
const ctx = canvas.getContext("2d");
|
|
@@ -2810,7 +2687,7 @@ import React19, { useContext as useContext10, useMemo as useMemo4 } from "react"
|
|
|
2810
2687
|
import styled23 from "styled-components";
|
|
2811
2688
|
|
|
2812
2689
|
// src/components/TimeScale.tsx
|
|
2813
|
-
import { useLayoutEffect as
|
|
2690
|
+
import { useLayoutEffect as useLayoutEffect5, useContext as useContext9 } from "react";
|
|
2814
2691
|
import styled22, { withTheme as withTheme2 } from "styled-components";
|
|
2815
2692
|
import { MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH4 } from "@waveform-playlist/core";
|
|
2816
2693
|
import { jsx as jsx26, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
@@ -2865,7 +2742,7 @@ var TimeScale = (props) => {
|
|
|
2865
2742
|
const firstChunkLeft = visibleChunkIndices.length > 0 ? visibleChunkIndices[0] * MAX_CANVAS_WIDTH4 : 0;
|
|
2866
2743
|
const lastChunkRight = visibleChunkIndices.length > 0 ? (visibleChunkIndices[visibleChunkIndices.length - 1] + 1) * MAX_CANVAS_WIDTH4 : Infinity;
|
|
2867
2744
|
const visibleMarkers = visibleChunkIndices.length > 0 ? timeMarkersWithPositions.filter(({ pix }) => pix >= firstChunkLeft && pix < lastChunkRight).map(({ element }) => element) : timeMarkersWithPositions.map(({ element }) => element);
|
|
2868
|
-
|
|
2745
|
+
useLayoutEffect5(() => {
|
|
2869
2746
|
for (const [chunkIdx, canvas] of canvasMapRef.current.entries()) {
|
|
2870
2747
|
const ctx = canvas.getContext("2d");
|
|
2871
2748
|
if (!ctx) continue;
|