@arraypress/waveform-player 1.19.3 → 1.20.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 +36 -6
- package/dist/waveform-player.cjs.map +2 -2
- package/dist/waveform-player.esm.js +7 -7
- package/dist/waveform-player.esm.js.map +3 -3
- package/dist/waveform-player.js +36 -6
- package/dist/waveform-player.min.js +7 -7
- package/dist/waveform-player.min.js.map +3 -3
- package/index.d.ts +17 -0
- package/package.json +1 -1
- package/src/js/core.js +11 -6
- package/src/js/themes.js +15 -0
- package/src/js/utils.js +26 -0
package/dist/waveform-player.cjs
CHANGED
|
@@ -128,11 +128,23 @@ function parseDataAttributes(element) {
|
|
|
128
128
|
setBool("showMarkers");
|
|
129
129
|
setBool("accessibleSeek");
|
|
130
130
|
if (element.dataset.seekLabel) options.seekLabel = element.dataset.seekLabel;
|
|
131
|
+
if (element.dataset.seekValueText) options.seekValueText = element.dataset.seekValueText;
|
|
131
132
|
if (element.dataset.errorText) options.errorText = element.dataset.errorText;
|
|
133
|
+
if (element.dataset.playPauseLabel) options.playPauseLabel = element.dataset.playPauseLabel;
|
|
134
|
+
if (element.dataset.speedLabel) options.speedLabel = element.dataset.speedLabel;
|
|
135
|
+
if (element.dataset.artworkAlt) options.artworkAlt = element.dataset.artworkAlt;
|
|
136
|
+
if (element.dataset.unknownTrackText) options.unknownTrackText = element.dataset.unknownTrackText;
|
|
132
137
|
if (element.dataset.playIcon) options.playIcon = element.dataset.playIcon;
|
|
133
138
|
if (element.dataset.pauseIcon) options.pauseIcon = element.dataset.pauseIcon;
|
|
134
139
|
return options;
|
|
135
140
|
}
|
|
141
|
+
function formatSeekValueText(template, ...args) {
|
|
142
|
+
let sequentialIndex = 0;
|
|
143
|
+
return template.replace(/%(?:(\d+)\$)?s/g, (match, position) => {
|
|
144
|
+
const index = position ? Number(position) - 1 : sequentialIndex++;
|
|
145
|
+
return args[index] ?? match;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
136
148
|
function formatTime(seconds) {
|
|
137
149
|
if (!seconds || isNaN(seconds) || seconds < 0) return "0:00";
|
|
138
150
|
const hrs = Math.floor(seconds / 3600);
|
|
@@ -752,8 +764,13 @@ var DEFAULT_OPTIONS = {
|
|
|
752
764
|
// (role="slider" + ARIA value attributes + arrow/page/home/end seeking).
|
|
753
765
|
// seekLabel sets the slider's accessible name; when null it falls back
|
|
754
766
|
// to the track title, then 'Seek'.
|
|
767
|
+
// seekValueText templates the slider's spoken aria-valuetext: %1$s is the
|
|
768
|
+
// current time and %2$s the total duration (both formatted M:SS). When null
|
|
769
|
+
// it falls back to '%1$s of %2$s'. Lets consumers localize the connective
|
|
770
|
+
// text without reformatting the times.
|
|
755
771
|
accessibleSeek: true,
|
|
756
772
|
seekLabel: null,
|
|
773
|
+
seekValueText: null,
|
|
757
774
|
// Content
|
|
758
775
|
title: null,
|
|
759
776
|
artist: null,
|
|
@@ -761,6 +778,15 @@ var DEFAULT_OPTIONS = {
|
|
|
761
778
|
album: "",
|
|
762
779
|
// Message shown in the error state when audio fails to load.
|
|
763
780
|
errorText: "Unable to load audio",
|
|
781
|
+
// Localizable UI strings (alongside seekLabel / seekValueText / errorText).
|
|
782
|
+
// These are screen-reader / assistive-tech facing, so translate them for
|
|
783
|
+
// non-English UIs. playPauseLabel/speedLabel are aria-labels; artworkAlt is
|
|
784
|
+
// the cover image alt text; unknownTrackText is the Media Session (lock-
|
|
785
|
+
// screen) title fallback used when no track title is set.
|
|
786
|
+
playPauseLabel: "Play/Pause",
|
|
787
|
+
speedLabel: "Playback speed",
|
|
788
|
+
artworkAlt: "Album artwork",
|
|
789
|
+
unknownTrackText: "Unknown Track",
|
|
764
790
|
// Icons (SVG)
|
|
765
791
|
playIcon: '<svg viewBox="0 0 24 24" width="16" height="16"><path d="M8 5v14l11-7z"/></svg>',
|
|
766
792
|
pauseIcon: '<svg viewBox="0 0 24 24" width="16" height="16"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>',
|
|
@@ -958,7 +984,7 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
958
984
|
}
|
|
959
985
|
this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
|
|
960
986
|
const buttonHTML = this.options.showControls ? `
|
|
961
|
-
<button class="waveform-btn${this.options.buttonStyle === "minimal" ? " waveform-btn-minimal" : ""}" aria-label="
|
|
987
|
+
<button class="waveform-btn${this.options.buttonStyle === "minimal" ? " waveform-btn-minimal" : ""}" aria-label="${escapeHtml(this.options.playPauseLabel)}"${this.options.buttonSize != null ? ` style="--wfp-btn-size: ${typeof this.options.buttonSize === "number" ? `${this.options.buttonSize}px` : this.options.buttonSize};"` : ""}>
|
|
962
988
|
<span class="waveform-icon-play">${this.options.playIcon}</span>
|
|
963
989
|
<span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
|
|
964
990
|
</button>
|
|
@@ -966,7 +992,7 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
966
992
|
const infoHTML = this.options.showInfo ? `
|
|
967
993
|
<div class="waveform-info">
|
|
968
994
|
${this.options.artwork ? `
|
|
969
|
-
<img class="waveform-artwork" src="${this.options.artwork}" alt="
|
|
995
|
+
<img class="waveform-artwork" src="${this.options.artwork}" alt="${escapeHtml(this.options.artworkAlt)}" style="
|
|
970
996
|
width: 40px;
|
|
971
997
|
height: 40px;
|
|
972
998
|
border-radius: 4px;
|
|
@@ -986,10 +1012,10 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
986
1012
|
` : ""}
|
|
987
1013
|
${this.options.showPlaybackSpeed ? `
|
|
988
1014
|
<div class="waveform-speed">
|
|
989
|
-
<button class="speed-btn" aria-label="
|
|
1015
|
+
<button class="speed-btn" aria-label="${escapeHtml(this.options.speedLabel)}" aria-haspopup="menu" aria-expanded="false">
|
|
990
1016
|
<span class="speed-value">1x</span>
|
|
991
1017
|
</button>
|
|
992
|
-
<div class="speed-menu" role="menu" aria-label="
|
|
1018
|
+
<div class="speed-menu" role="menu" aria-label="${escapeHtml(this.options.speedLabel)}" style="display: none;">
|
|
993
1019
|
${this.options.playbackRates.map(
|
|
994
1020
|
(rate) => `<button class="speed-option" role="menuitemradio" tabindex="-1" aria-checked="false" data-rate="${rate}">${rate}x</button>`
|
|
995
1021
|
).join("")}
|
|
@@ -1340,7 +1366,11 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1340
1366
|
this.seekEl.setAttribute("aria-valuenow", String(Math.round(current)));
|
|
1341
1367
|
this.seekEl.setAttribute(
|
|
1342
1368
|
"aria-valuetext",
|
|
1343
|
-
|
|
1369
|
+
formatSeekValueText(
|
|
1370
|
+
this.options.seekValueText || "%1$s of %2$s",
|
|
1371
|
+
formatTime(current),
|
|
1372
|
+
formatTime(duration)
|
|
1373
|
+
)
|
|
1344
1374
|
);
|
|
1345
1375
|
}
|
|
1346
1376
|
/**
|
|
@@ -1382,7 +1412,7 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1382
1412
|
_applyMediaMetadata() {
|
|
1383
1413
|
if (!("mediaSession" in navigator) || !this.options.enableMediaSession) return;
|
|
1384
1414
|
navigator.mediaSession.metadata = new MediaMetadata({
|
|
1385
|
-
title: this.options.title ||
|
|
1415
|
+
title: this.options.title || this.options.unknownTrackText,
|
|
1386
1416
|
artist: this.options.artist || "",
|
|
1387
1417
|
album: this.options.album || "",
|
|
1388
1418
|
artwork: this.options.artwork ? [
|