@waveform-playlist/ui-components 13.0.1 → 13.1.1

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
@@ -718,6 +718,13 @@ function calculateBarRects(x, barWidth, halfHeight, minPeak, maxPeak, drawMode)
718
718
  { x, y: halfHeight + min, width: barWidth, height: halfHeight - min }
719
719
  ];
720
720
  }
721
+ function addBarToPath(ctx, rect, radius) {
722
+ if (typeof ctx.roundRect === "function") {
723
+ ctx.roundRect(rect.x, rect.y, rect.width, rect.height, radius);
724
+ } else {
725
+ ctx.rect(rect.x, rect.y, rect.width, rect.height);
726
+ }
727
+ }
721
728
  function calculateFirstBarPosition(canvasStartGlobal, barWidth, step) {
722
729
  return Math.floor((canvasStartGlobal - barWidth + step) / step) * step;
723
730
  }
@@ -778,6 +785,7 @@ var Channel = (props) => {
778
785
  waveFillColor = "grey",
779
786
  barWidth = 1,
780
787
  barGap = 0,
788
+ roundedBars = false,
781
789
  transparentBackground = false,
782
790
  drawMode = "inverted"
783
791
  } = props;
@@ -790,7 +798,7 @@ var Channel = (props) => {
790
798
  dataVersionRef.current += 1;
791
799
  prevDataRef.current = data;
792
800
  }
793
- const drawVersion = `${dataVersionRef.current}-${bits}-${waveHeight}-${devicePixelRatio}-${length}-${barWidth}-${barGap}-${drawMode}-${waveformColorToCss(waveOutlineColor)}-${waveformColorToCss(waveFillColor)}`;
801
+ const drawVersion = `${dataVersionRef.current}-${bits}-${waveHeight}-${devicePixelRatio}-${length}-${barWidth}-${barGap}-${drawMode}-${roundedBars}-${waveformColorToCss(waveOutlineColor)}-${waveformColorToCss(waveFillColor)}`;
794
802
  useLayoutEffect2(() => {
795
803
  const step = barWidth + barGap;
796
804
  for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
@@ -814,18 +822,36 @@ var Channel = (props) => {
814
822
  const canvasStartGlobal = globalPixelOffset;
815
823
  const canvasEndGlobal = globalPixelOffset + canvasWidth;
816
824
  const firstBarGlobal = calculateFirstBarPosition(canvasStartGlobal, barWidth, step);
825
+ const rectMode = roundedBars ? "normal" : drawMode;
826
+ const barRadius = barWidth / 2;
827
+ const complementFill = roundedBars && drawMode === "inverted";
828
+ if (roundedBars) {
829
+ ctx.beginPath();
830
+ }
831
+ if (complementFill) {
832
+ ctx.rect(0, 0, canvasWidth, waveHeight);
833
+ }
817
834
  for (let barGlobal = Math.max(0, firstBarGlobal); barGlobal < canvasEndGlobal; barGlobal += step) {
818
835
  const x = barGlobal - canvasStartGlobal;
819
836
  if (x + barWidth <= 0) continue;
820
837
  const peakEnd = Math.min(barGlobal + step, length);
821
838
  const peak = aggregatePeaks(data, bits, barGlobal, peakEnd);
822
839
  if (peak) {
823
- const rects = calculateBarRects(x, barWidth, h2, peak.min, peak.max, drawMode);
840
+ const rects = calculateBarRects(x, barWidth, h2, peak.min, peak.max, rectMode);
824
841
  for (const rect of rects) {
825
- ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
842
+ if (roundedBars) {
843
+ addBarToPath(ctx, rect, barRadius);
844
+ } else {
845
+ ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
846
+ }
826
847
  }
827
848
  }
828
849
  }
850
+ if (complementFill) {
851
+ ctx.fill("evenodd");
852
+ } else if (roundedBars) {
853
+ ctx.fill();
854
+ }
829
855
  canvas.dataset.drawVersion = drawVersion;
830
856
  }
831
857
  }
@@ -840,6 +866,7 @@ var Channel = (props) => {
840
866
  length,
841
867
  barWidth,
842
868
  barGap,
869
+ roundedBars,
843
870
  drawVersion,
844
871
  drawMode,
845
872
  visibleChunkIndices,
@@ -2259,7 +2286,8 @@ var PlaylistInfoContext = createContext5({
2259
2286
  },
2260
2287
  duration: 3e4,
2261
2288
  barWidth: 1,
2262
- barGap: 0
2289
+ barGap: 0,
2290
+ roundedBars: false
2263
2291
  });
2264
2292
  var usePlaylistInfo = () => useContext5(PlaylistInfoContext);
2265
2293
 
@@ -2317,7 +2345,11 @@ var usePlayoutStatusUpdate = () => useContext8(PlayoutStatusUpdateContext);
2317
2345
  // src/components/SpectrogramChannel.tsx
2318
2346
  import { useRef as useRef7, useEffect as useEffect6 } from "react";
2319
2347
  import styled20 from "styled-components";
2320
- import { MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH3 } from "@waveform-playlist/core";
2348
+ import {
2349
+ MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH3,
2350
+ buildSpectrogramCanvasId,
2351
+ parseSpectrogramCanvasId
2352
+ } from "@waveform-playlist/core";
2321
2353
  import { jsx as jsx23 } from "react/jsx-runtime";
2322
2354
  var Wrapper4 = styled20.div.attrs((props) => ({
2323
2355
  style: {
@@ -2374,12 +2406,12 @@ var SpectrogramChannel = ({
2374
2406
  const register = onCanvasRegisterRef.current;
2375
2407
  const remaining = [];
2376
2408
  for (const id of registeredIdsRef.current) {
2377
- const match = id.match(/chunk(\d+)$/);
2378
- if (!match) {
2409
+ const parsed = parseSpectrogramCanvasId(id);
2410
+ if (!parsed) {
2379
2411
  remaining.push(id);
2380
2412
  continue;
2381
2413
  }
2382
- const chunkIdx = parseInt(match[1], 10);
2414
+ const chunkIdx = parsed.chunkIndex;
2383
2415
  const canvas = canvasMapRef.current.get(chunkIdx);
2384
2416
  if (canvas && canvas.isConnected) {
2385
2417
  remaining.push(id);
@@ -2394,7 +2426,7 @@ var SpectrogramChannel = ({
2394
2426
  registeredIdsRef.current = remaining;
2395
2427
  for (const [canvasIdx, canvas] of canvasMapRef.current.entries()) {
2396
2428
  if (transferredCanvasesRef.current.has(canvas)) continue;
2397
- const canvasId = `${clipId}-ch${channelIndex}-chunk${canvasIdx}`;
2429
+ const canvasId = buildSpectrogramCanvasId({ clipId, channelIndex, chunkIndex: canvasIdx });
2398
2430
  let offscreen;
2399
2431
  try {
2400
2432
  offscreen = canvas.transferControlToOffscreen();
@@ -2473,6 +2505,7 @@ var SmartChannel = ({
2473
2505
  waveHeight,
2474
2506
  barWidth,
2475
2507
  barGap,
2508
+ roundedBars,
2476
2509
  samplesPerPixel: contextSpp,
2477
2510
  sampleRate: contextSampleRate
2478
2511
  } = usePlaylistInfo();
@@ -2534,6 +2567,7 @@ var SmartChannel = ({
2534
2567
  devicePixelRatio,
2535
2568
  barWidth,
2536
2569
  barGap,
2570
+ roundedBars,
2537
2571
  transparentBackground,
2538
2572
  drawMode
2539
2573
  }
@@ -2572,6 +2606,7 @@ var SmartChannel = ({
2572
2606
  devicePixelRatio,
2573
2607
  barWidth,
2574
2608
  barGap,
2609
+ roundedBars,
2575
2610
  transparentBackground,
2576
2611
  drawMode
2577
2612
  }