@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/dist/waveform-player.cjs +17 -6
- package/dist/waveform-player.cjs.map +2 -2
- package/dist/waveform-player.css +1 -1
- package/dist/waveform-player.esm.js +3 -2
- package/dist/waveform-player.esm.js.map +3 -3
- package/dist/waveform-player.js +17 -6
- package/dist/waveform-player.min.js +3 -2
- package/dist/waveform-player.min.js.map +3 -3
- package/index.d.ts +9 -1
- package/package.json +1 -1
- package/src/css/waveform-player.css +21 -14
- package/src/js/audio.js +12 -7
- package/src/js/core.js +1 -0
- package/src/js/themes.js +11 -4
- package/src/js/utils.js +6 -0
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
|
-
/**
|
|
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
|
@@ -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
|
|
63
|
-
circle button
|
|
64
|
-
width:
|
|
65
|
-
height:
|
|
66
|
-
min-width:
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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:
|
|
98
|
-
height:
|
|
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
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* merged by taking the loudest channel, then the whole
|
|
17
|
-
* the maximum peak becomes 1 (a silent buffer is
|
|
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
|
-
|
|
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
|
|
156
|
-
// canvasWidth / (barWidth + barSpacing)
|
|
157
|
-
// not the visible bar count.
|
|
158
|
-
|
|
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;
|