@waveform-playlist/ui-components 9.0.0 → 9.0.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 CHANGED
@@ -142,8 +142,8 @@ interface ChannelProps {
142
142
  transparentBackground?: boolean;
143
143
  /**
144
144
  * Drawing mode:
145
- * - 'inverted': Draw waveOutlineColor where there's NO audio (current default). Good for gradient bars.
146
- * - 'normal': Draw waveFillColor where there IS audio. Good for gradient backgrounds.
145
+ * - 'inverted': Canvas draws waveOutlineColor where there's NO audio, revealing waveFillColor background as bars (default). Good for gradient bars.
146
+ * - 'normal': Canvas draws waveFillColor where there IS audio. Use with transparentBackground for progress overlays.
147
147
  */
148
148
  drawMode?: WaveformDrawMode;
149
149
  }
package/dist/index.d.ts CHANGED
@@ -142,8 +142,8 @@ interface ChannelProps {
142
142
  transparentBackground?: boolean;
143
143
  /**
144
144
  * Drawing mode:
145
- * - 'inverted': Draw waveOutlineColor where there's NO audio (current default). Good for gradient bars.
146
- * - 'normal': Draw waveFillColor where there IS audio. Good for gradient backgrounds.
145
+ * - 'inverted': Canvas draws waveOutlineColor where there's NO audio, revealing waveFillColor background as bars (default). Good for gradient bars.
146
+ * - 'normal': Canvas draws waveFillColor where there IS audio. Use with transparentBackground for progress overlays.
147
147
  */
148
148
  drawMode?: WaveformDrawMode;
149
149
  }
package/dist/index.js CHANGED
@@ -758,6 +758,40 @@ function useChunkedCanvasRefs() {
758
758
 
759
759
  // src/components/Channel.tsx
760
760
  var import_core = require("@waveform-playlist/core");
761
+
762
+ // src/utils/peakRendering.ts
763
+ function aggregatePeaks(data, bits, startIndex, endIndex) {
764
+ if (startIndex * 2 + 1 >= data.length) {
765
+ return null;
766
+ }
767
+ const maxValue = 2 ** (bits - 1);
768
+ let minPeak = data[startIndex * 2] / maxValue;
769
+ let maxPeak = data[startIndex * 2 + 1] / maxValue;
770
+ for (let p = startIndex + 1; p < endIndex; p++) {
771
+ if (p * 2 + 1 >= data.length) break;
772
+ const pMin = data[p * 2] / maxValue;
773
+ const pMax = data[p * 2 + 1] / maxValue;
774
+ if (pMin < minPeak) minPeak = pMin;
775
+ if (pMax > maxPeak) maxPeak = pMax;
776
+ }
777
+ return { min: minPeak, max: maxPeak };
778
+ }
779
+ function calculateBarRects(x, barWidth, halfHeight, minPeak, maxPeak, drawMode) {
780
+ const min = Math.abs(minPeak * halfHeight);
781
+ const max = Math.abs(maxPeak * halfHeight);
782
+ if (drawMode === "normal") {
783
+ return [{ x, y: halfHeight - max, width: barWidth, height: max + min }];
784
+ }
785
+ return [
786
+ { x, y: 0, width: barWidth, height: halfHeight - max },
787
+ { x, y: halfHeight + min, width: barWidth, height: halfHeight - min }
788
+ ];
789
+ }
790
+ function calculateFirstBarPosition(canvasStartGlobal, barWidth, step) {
791
+ return Math.floor((canvasStartGlobal - barWidth + step) / step) * step;
792
+ }
793
+
794
+ // src/components/Channel.tsx
761
795
  var import_jsx_runtime5 = require("react/jsx-runtime");
762
796
  function createCanvasFillStyle(ctx, color, width, height) {
763
797
  if (!isWaveformGradient(color)) {
@@ -827,7 +861,6 @@ var Channel = (props) => {
827
861
  const globalPixelOffset = canvasIdx * import_core.MAX_CANVAS_WIDTH;
828
862
  const ctx = canvas.getContext("2d");
829
863
  const h2 = Math.floor(waveHeight / 2);
830
- const maxValue = 2 ** (bits - 1);
831
864
  if (ctx) {
832
865
  ctx.resetTransform();
833
866
  ctx.clearRect(0, 0, canvas.width, canvas.height);
@@ -843,21 +876,16 @@ var Channel = (props) => {
843
876
  ctx.fillStyle = createCanvasFillStyle(ctx, fillColor, canvasWidth, waveHeight);
844
877
  const canvasStartGlobal = globalPixelOffset;
845
878
  const canvasEndGlobal = globalPixelOffset + canvasWidth;
846
- const firstBarGlobal = Math.floor((canvasStartGlobal - barWidth + step) / step) * step;
879
+ const firstBarGlobal = calculateFirstBarPosition(canvasStartGlobal, barWidth, step);
847
880
  for (let barGlobal = Math.max(0, firstBarGlobal); barGlobal < canvasEndGlobal; barGlobal += step) {
848
881
  const x = barGlobal - canvasStartGlobal;
849
882
  if (x + barWidth <= 0) continue;
850
- const peakIndex = barGlobal;
851
- if (peakIndex * 2 + 1 < data.length) {
852
- const minPeak = data[peakIndex * 2] / maxValue;
853
- const maxPeak = data[peakIndex * 2 + 1] / maxValue;
854
- const min = Math.abs(minPeak * h2);
855
- const max = Math.abs(maxPeak * h2);
856
- if (drawMode === "normal") {
857
- ctx.fillRect(x, h2 - max, barWidth, max + min);
858
- } else {
859
- ctx.fillRect(x, 0, barWidth, h2 - max);
860
- ctx.fillRect(x, h2 + min, barWidth, h2 - min);
883
+ const peakEnd = Math.min(barGlobal + step, length);
884
+ const peak = aggregatePeaks(data, bits, barGlobal, peakEnd);
885
+ if (peak) {
886
+ const rects = calculateBarRects(x, barWidth, h2, peak.min, peak.max, drawMode);
887
+ for (const rect of rects) {
888
+ ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
861
889
  }
862
890
  }
863
891
  }