@arraypress/waveform-player 1.19.0 → 1.19.3
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 +62 -16
- package/dist/waveform-player.cjs.map +2 -2
- package/dist/waveform-player.esm.js +8 -8
- package/dist/waveform-player.esm.js.map +3 -3
- package/dist/waveform-player.js +62 -16
- package/dist/waveform-player.min.js +8 -8
- package/dist/waveform-player.min.js.map +3 -3
- package/package.json +1 -1
- package/src/js/core.js +63 -25
package/package.json
CHANGED
package/src/js/core.js
CHANGED
|
@@ -295,12 +295,12 @@ export class WaveformPlayer {
|
|
|
295
295
|
` : ''}
|
|
296
296
|
${this.options.showPlaybackSpeed ? `
|
|
297
297
|
<div class="waveform-speed">
|
|
298
|
-
<button class="speed-btn" aria-label="Playback speed" aria-haspopup="
|
|
298
|
+
<button class="speed-btn" aria-label="Playback speed" aria-haspopup="menu" aria-expanded="false">
|
|
299
299
|
<span class="speed-value">1x</span>
|
|
300
300
|
</button>
|
|
301
|
-
<div class="speed-menu" style="display: none;">
|
|
301
|
+
<div class="speed-menu" role="menu" aria-label="Playback speed" style="display: none;">
|
|
302
302
|
${this.options.playbackRates.map(rate =>
|
|
303
|
-
`<button class="speed-option" data-rate="${rate}">${rate}x</button>`
|
|
303
|
+
`<button class="speed-option" role="menuitemradio" tabindex="-1" aria-checked="false" data-rate="${rate}">${rate}x</button>`
|
|
304
304
|
).join('')}
|
|
305
305
|
</div>
|
|
306
306
|
</div>
|
|
@@ -427,40 +427,68 @@ export class WaveformPlayer {
|
|
|
427
427
|
|
|
428
428
|
if (!speedBtn || !speedMenu) return;
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
const options = () => Array.from(speedMenu.querySelectorAll('.speed-option'));
|
|
431
|
+
const isOpen = () => speedMenu.style.display !== 'none';
|
|
432
|
+
|
|
433
|
+
// Open/close the menu (a proper role="menu"): keep aria-expanded in sync
|
|
434
|
+
// and, on open, move focus into the menu — the checked rate, else the
|
|
435
|
+
// first option — so arrow keys drive it.
|
|
433
436
|
const setSpeedMenu = (open) => {
|
|
434
437
|
speedMenu.style.display = open ? 'block' : 'none';
|
|
435
438
|
speedBtn.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
439
|
+
if (open) {
|
|
440
|
+
const opts = options();
|
|
441
|
+
(opts.find((o) => o.getAttribute('aria-checked') === 'true') || opts[0])?.focus();
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const focusOption = (i) => {
|
|
446
|
+
const opts = options();
|
|
447
|
+
if (opts.length) opts[(i + opts.length) % opts.length].focus();
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const selectOption = (opt) => {
|
|
451
|
+
this.setPlaybackRate(parseFloat(opt.dataset.rate));
|
|
452
|
+
setSpeedMenu(false);
|
|
453
|
+
speedBtn.focus();
|
|
436
454
|
};
|
|
437
455
|
|
|
438
|
-
// Toggle
|
|
456
|
+
// Toggle from the trigger.
|
|
439
457
|
speedBtn.addEventListener('click', (e) => {
|
|
440
458
|
e.stopPropagation();
|
|
441
|
-
setSpeedMenu(
|
|
459
|
+
setSpeedMenu(!isOpen());
|
|
442
460
|
}, {signal: this._ac.signal});
|
|
443
461
|
|
|
444
|
-
// Close
|
|
462
|
+
// Close when clicking outside.
|
|
445
463
|
document.addEventListener('click', () => setSpeedMenu(false), {signal: this._ac.signal});
|
|
446
464
|
|
|
447
|
-
//
|
|
448
|
-
// the trigger.
|
|
465
|
+
// Pointer + native-button (Enter/Space on an option) selection.
|
|
449
466
|
speedMenu.addEventListener('click', (e) => {
|
|
450
467
|
e.stopPropagation();
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
setSpeedMenu(false);
|
|
454
|
-
speedBtn.focus();
|
|
455
|
-
}
|
|
468
|
+
const opt = e.target.closest('.speed-option');
|
|
469
|
+
if (opt) selectOption(opt);
|
|
456
470
|
}, {signal: this._ac.signal});
|
|
457
471
|
|
|
458
|
-
//
|
|
459
|
-
//
|
|
472
|
+
// Keyboard menu: arrows/Home/End roam, Enter/Space select (via the
|
|
473
|
+
// native button click above), Escape/Tab close. ArrowDown/Up on the
|
|
474
|
+
// trigger opens and focuses the first/checked option.
|
|
460
475
|
speedBtn.closest('.waveform-speed')?.addEventListener('keydown', (e) => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
476
|
+
const opts = options();
|
|
477
|
+
const i = opts.indexOf(document.activeElement);
|
|
478
|
+
if (!isOpen()) {
|
|
479
|
+
if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && document.activeElement === speedBtn) {
|
|
480
|
+
e.preventDefault();
|
|
481
|
+
setSpeedMenu(true);
|
|
482
|
+
}
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
switch (e.key) {
|
|
486
|
+
case 'ArrowDown': e.preventDefault(); focusOption(i < 0 ? 0 : i + 1); break;
|
|
487
|
+
case 'ArrowUp': e.preventDefault(); focusOption(i < 0 ? opts.length - 1 : i - 1); break;
|
|
488
|
+
case 'Home': e.preventDefault(); focusOption(0); break;
|
|
489
|
+
case 'End': e.preventDefault(); focusOption(opts.length - 1); break;
|
|
490
|
+
case 'Escape': e.preventDefault(); setSpeedMenu(false); speedBtn.focus(); break;
|
|
491
|
+
case 'Tab': setSpeedMenu(false); break;
|
|
464
492
|
}
|
|
465
493
|
}, {signal: this._ac.signal});
|
|
466
494
|
|
|
@@ -761,7 +789,10 @@ export class WaveformPlayer {
|
|
|
761
789
|
_updateMediaSession(state) {
|
|
762
790
|
if (!('mediaSession' in navigator) || !this.options.enableMediaSession || !this.audio) return;
|
|
763
791
|
try {
|
|
764
|
-
|
|
792
|
+
// Claim the (global, singleton) Media Session for THIS player on play —
|
|
793
|
+
// (re)register our action handlers + metadata so the lock-screen controls
|
|
794
|
+
// drive the player you're actually listening to, not the last one loaded.
|
|
795
|
+
if (state === 'playing') this.initMediaSession();
|
|
765
796
|
navigator.mediaSession.playbackState = state;
|
|
766
797
|
const d = this.audio.duration;
|
|
767
798
|
if (navigator.mediaSession.setPositionState && d && isFinite(d)) {
|
|
@@ -982,7 +1013,6 @@ export class WaveformPlayer {
|
|
|
982
1013
|
|
|
983
1014
|
this.drawWaveform();
|
|
984
1015
|
this.renderMarkers();
|
|
985
|
-
this.initMediaSession();
|
|
986
1016
|
|
|
987
1017
|
// Fire callback
|
|
988
1018
|
if (this.options.onLoad) {
|
|
@@ -1362,12 +1392,18 @@ export class WaveformPlayer {
|
|
|
1362
1392
|
this.progress = clamp((clientX - rect.left) / rect.width);
|
|
1363
1393
|
this.drawWaveform();
|
|
1364
1394
|
this._updateSeekHandle();
|
|
1365
|
-
this._updateHoverTip(clientX);
|
|
1366
1395
|
// Live time readout while scrubbing (Spotify-style): the audio keeps
|
|
1367
1396
|
// playing at its old position; the display shows where release lands.
|
|
1368
1397
|
const dur = this.getSeekDuration();
|
|
1369
1398
|
if (dur && this.currentTimeEl) {
|
|
1370
1399
|
this.currentTimeEl.textContent = formatTime(this.progress * dur);
|
|
1400
|
+
// The current-time already shows the target — don't also pop the
|
|
1401
|
+
// hover tooltip with the same value (that duplicate is the bug).
|
|
1402
|
+
this._hideHoverTip();
|
|
1403
|
+
} else {
|
|
1404
|
+
// No current-time readout to fall back on — keep the tooltip as the
|
|
1405
|
+
// only scrub feedback.
|
|
1406
|
+
this._updateHoverTip(clientX);
|
|
1371
1407
|
}
|
|
1372
1408
|
}
|
|
1373
1409
|
|
|
@@ -1806,7 +1842,9 @@ export class WaveformPlayer {
|
|
|
1806
1842
|
|
|
1807
1843
|
// Update active state in menu
|
|
1808
1844
|
this.container.querySelectorAll('.speed-option').forEach(btn => {
|
|
1809
|
-
|
|
1845
|
+
const on = parseFloat(btn.dataset.rate) === this.audio.playbackRate;
|
|
1846
|
+
btn.classList.toggle('active', on);
|
|
1847
|
+
btn.setAttribute('aria-checked', on ? 'true' : 'false');
|
|
1810
1848
|
});
|
|
1811
1849
|
}
|
|
1812
1850
|
|