@arraypress/waveform-player 1.13.1 → 1.15.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/index.d.ts CHANGED
@@ -78,7 +78,8 @@ export interface WaveformPlayerOptions {
78
78
  src?: string;
79
79
  /** Waveform height in pixels. @default 60 */
80
80
  height?: number;
81
- /** Number of peak samples to extract when decoding. @default 200 */
81
+ /** Source peak resolution for live decode (ignored when `waveform` peaks are
82
+ * supplied); resampled to fit the visible bars. @default 1800 */
82
83
  samples?: number;
83
84
  /** `<audio>` preload hint. @default 'metadata' */
84
85
  preload?: AudioPreload;
@@ -139,6 +140,13 @@ export interface WaveformPlayerOptions {
139
140
  * @default 'circle'
140
141
  */
141
142
  buttonStyle?: 'circle' | 'minimal';
143
+ /**
144
+ * Play/pause button size. A number is treated as px; a string (e.g. `'4rem'`)
145
+ * is used verbatim. Sets the `--wfp-btn-size` CSS variable, scaling both the
146
+ * `circle` and `minimal` styles — box and glyph — proportionally.
147
+ * @default null
148
+ */
149
+ buttonSize?: number | string | null;
142
150
  /** Show transport controls. @default true */
143
151
  showControls?: boolean;
144
152
  /** Show the info (title/subtitle) block. @default true */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/waveform-player",
3
- "version": "1.13.1",
3
+ "version": "1.15.0",
4
4
  "description": "Lightweight, customizable audio player with waveform visualization",
5
5
  "type": "module",
6
6
  "types": "./index.d.ts",
@@ -27,11 +27,15 @@
27
27
  position: relative;
28
28
  }
29
29
 
30
- /* Play button */
30
+ /* Play button.
31
+ Size knob: set `--wfp-btn-size` (via the `buttonSize` option /
32
+ `data-button-size`) to scale BOTH button styles — box AND glyph —
33
+ proportionally. Defaults to 36px; every dimension below derives from it so
34
+ there is a single source of truth (no per-style magic numbers to drift). */
31
35
  .waveform-btn {
32
- width: 36px;
33
- height: 36px;
34
- min-width: 36px;
36
+ width: var(--wfp-btn-size, 36px);
37
+ height: var(--wfp-btn-size, 36px);
38
+ min-width: var(--wfp-btn-size, 36px);
35
39
  border-radius: 50%;
36
40
  border: 2px solid currentColor;
37
41
  background: transparent;
@@ -59,11 +63,11 @@
59
63
  nudged 1px) for the pause glyph would otherwise change the button's
60
64
  auto width, shifting the adjacent waveform — and re-sampling its bars —
61
65
  on every play/pause. Fixed width keeps the canvas (and bars) stable.
62
- Sized so the bare glyph reads at the same visual weight as the 36px
63
- circle button (the glyph, not a ring, is the whole control here). */
64
- width: 2.5rem;
65
- height: 2.5rem;
66
- min-width: 2.5rem;
66
+ Sized (1.1×) so the bare glyph reads at the same visual weight as the
67
+ circle button — the glyph, not a ring, is the whole control here. */
68
+ width: calc(var(--wfp-btn-size, 36px) * 1.1);
69
+ height: calc(var(--wfp-btn-size, 36px) * 1.1);
70
+ min-width: calc(var(--wfp-btn-size, 36px) * 1.1);
67
71
  border: none;
68
72
  border-radius: 0;
69
73
  opacity: 0.7;
@@ -74,9 +78,12 @@
74
78
  transform: none;
75
79
  }
76
80
 
77
- .waveform-btn-minimal svg {
78
- width: 36px;
79
- height: 36px;
81
+ /* NOTE: must out-specify `.waveform-btn svg { width:16px }` below — that rule
82
+ has equal specificity but later source order, so it was pinning the minimal
83
+ glyph to 16px. The compound `.waveform-btn.waveform-btn-minimal` wins. */
84
+ .waveform-btn.waveform-btn-minimal svg {
85
+ width: calc(var(--wfp-btn-size, 36px) * 0.94);
86
+ height: calc(var(--wfp-btn-size, 36px) * 0.94);
80
87
  }
81
88
 
82
89
  .waveform-btn:disabled {
@@ -94,8 +101,8 @@
94
101
  }
95
102
 
96
103
  .waveform-btn svg {
97
- width: 16px;
98
- height: 16px;
104
+ width: calc(var(--wfp-btn-size, 36px) * 0.45);
105
+ height: calc(var(--wfp-btn-size, 36px) * 0.45);
99
106
  fill: currentColor;
100
107
  display: block;
101
108
  }
package/src/js/audio.js CHANGED
@@ -10,11 +10,12 @@ import {clamp} from './utils.js';
10
10
  * Extract peaks from a decoded audio buffer for waveform visualization.
11
11
  *
12
12
  * Divides the buffer into `samples` equal-width windows and, within each
13
- * window, finds the largest absolute amplitude. To keep large files fast the
14
- * inner loop strides through every 10th frame (`sampleStep`) rather than
15
- * inspecting every frame. Across multiple channels the per-window peaks are
16
- * merged by taking the loudest channel, then the whole array is normalized so
17
- * the maximum peak becomes 1 (a silent buffer is returned unscaled).
13
+ * window, finds the largest absolute amplitude by inspecting every frame (so
14
+ * transients are never missed and the shape is stable across sample counts —
15
+ * matching WaveformGen's offline output). Across multiple channels the
16
+ * per-window peaks are merged by taking the loudest channel, then the whole
17
+ * array is normalized so the maximum peak becomes 1 (a silent buffer is
18
+ * returned unscaled).
18
19
  *
19
20
  * @param {AudioBuffer} buffer - Decoded audio buffer to analyse.
20
21
  * @param {number} [samples=200] - Number of peak windows (output array length).
@@ -22,7 +23,6 @@ import {clamp} from './utils.js';
22
23
  */
23
24
  export function extractPeaks(buffer, samples = 200) {
24
25
  const sampleSize = buffer.length / samples;
25
- const sampleStep = ~~(sampleSize / 10) || 1;
26
26
  const channels = buffer.numberOfChannels;
27
27
  const peaks = [];
28
28
 
@@ -36,7 +36,12 @@ export function extractPeaks(buffer, samples = 200) {
36
36
  let min = 0;
37
37
  let max = 0;
38
38
 
39
- for (let j = start; j < end; j += sampleStep) {
39
+ // Scan EVERY frame in the window. Previously this stepped by
40
+ // sampleSize/10 (~10 samples/window) for speed, but that misses
41
+ // transients and makes the shape change with the sample count.
42
+ // decodeAudioData dominates the cost, so a full scan is worth it —
43
+ // and it now matches WaveformGen's offline output exactly.
44
+ for (let j = start; j < end; j++) {
40
45
  const value = chan[j];
41
46
  if (value > max) max = value;
42
47
  if (value < min) min = value;
package/src/js/core.js CHANGED
@@ -246,6 +246,7 @@ export class WaveformPlayer {
246
246
  <button class="waveform-btn${this.options.buttonStyle === 'minimal' ? ' waveform-btn-minimal' : ''}" aria-label="Play/Pause" style="
247
247
  border-color: ${this.options.buttonColor};
248
248
  color: ${this.options.buttonColor};
249
+ ${this.options.buttonSize != null ? `--wfp-btn-size: ${typeof this.options.buttonSize === 'number' ? `${this.options.buttonSize}px` : this.options.buttonSize};` : ''}
249
250
  ">
250
251
  <span class="waveform-icon-play">${this.options.playIcon}</span>
251
252
  <span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
package/src/js/themes.js CHANGED
@@ -152,10 +152,12 @@ export const DEFAULT_OPTIONS = {
152
152
  // Core settings
153
153
  url: '',
154
154
  height: 64,
155
- // Source peak resolution. The drawer resamples these to fit
156
- // canvasWidth / (barWidth + barSpacing) bars, so this is fidelity headroom,
157
- // not the visible bar count.
158
- samples: 256,
155
+ // Source peak resolution for LIVE decode (ignored when peaks are supplied).
156
+ // The drawer resamples these to fit canvasWidth / (barWidth + barSpacing)
157
+ // bars, so this is fidelity headroom, not the visible bar count. 1800 (the
158
+ // SoundCloud/WaveformGen figure) keeps wide / high-DPI waveforms crisp; the
159
+ // every-frame scan means a higher value costs no extra extraction time.
160
+ samples: 1800,
159
161
  preload: 'metadata',
160
162
 
161
163
  // Audio mode — 'self' = player owns the <audio> element (default, current
@@ -181,6 +183,11 @@ export const DEFAULT_OPTIONS = {
181
183
  // 'minimal' = a bare play/pause glyph with no circle — the look sample-pack
182
184
  // and beat stores use in their preview grids.
183
185
  buttonStyle: 'circle',
186
+ // Play/pause button size. null = the stylesheet default (36px circle /
187
+ // proportional minimal). A number is treated as px; a string (e.g. '4rem')
188
+ // is used verbatim. Sets the `--wfp-btn-size` CSS var, which scales BOTH
189
+ // styles — box and glyph — proportionally.
190
+ buttonSize: null,
184
191
 
185
192
  // Default waveform style
186
193
  waveformStyle: 'mirror',
package/src/js/utils.js CHANGED
@@ -139,6 +139,12 @@ export function parseDataAttributes(element) {
139
139
  if (element.dataset.buttonAlign) options.buttonAlign = element.dataset.buttonAlign;
140
140
  if (element.dataset.layout) options.layout = element.dataset.layout;
141
141
  if (element.dataset.buttonStyle) options.buttonStyle = element.dataset.buttonStyle;
142
+ // buttonSize: a bare number is px (data-button-size="64"); a unit string
143
+ // (e.g. "4rem") is kept verbatim.
144
+ if (element.dataset.buttonSize) {
145
+ const bs = element.dataset.buttonSize;
146
+ options.buttonSize = /^\d+(\.\d+)?$/.test(bs.trim()) ? parseFloat(bs) : bs;
147
+ }
142
148
 
143
149
  // Color preset
144
150
  if (element.dataset.colorPreset) options.colorPreset = element.dataset.colorPreset;