@waveform-playlist/ui-components 13.0.0 → 13.1.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.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
 
@@ -2473,6 +2501,7 @@ var SmartChannel = ({
2473
2501
  waveHeight,
2474
2502
  barWidth,
2475
2503
  barGap,
2504
+ roundedBars,
2476
2505
  samplesPerPixel: contextSpp,
2477
2506
  sampleRate: contextSampleRate
2478
2507
  } = usePlaylistInfo();
@@ -2534,6 +2563,7 @@ var SmartChannel = ({
2534
2563
  devicePixelRatio,
2535
2564
  barWidth,
2536
2565
  barGap,
2566
+ roundedBars,
2537
2567
  transparentBackground,
2538
2568
  drawMode
2539
2569
  }
@@ -2572,6 +2602,7 @@ var SmartChannel = ({
2572
2602
  devicePixelRatio,
2573
2603
  barWidth,
2574
2604
  barGap,
2605
+ roundedBars,
2575
2606
  transparentBackground,
2576
2607
  drawMode
2577
2608
  }