@arraypress/waveform-player 1.20.0 → 1.21.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 +109 -17
- package/dist/waveform-player.cjs.map +2 -2
- package/dist/waveform-player.esm.js +2 -2
- package/dist/waveform-player.esm.js.map +3 -3
- package/dist/waveform-player.js +109 -17
- package/dist/waveform-player.min.js +2 -2
- package/dist/waveform-player.min.js.map +3 -3
- package/package.json +1 -1
- package/src/js/core.js +130 -21
package/dist/waveform-player.cjs
CHANGED
|
@@ -1056,11 +1056,7 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1056
1056
|
this.titleEl = this.container.querySelector(".waveform-title");
|
|
1057
1057
|
this.artistEl = this.container.querySelector(".waveform-artist");
|
|
1058
1058
|
this.artworkEl = this.container.querySelector(".waveform-artwork");
|
|
1059
|
-
|
|
1060
|
-
this.artworkEl.addEventListener("error", () => {
|
|
1061
|
-
if (!this.artworkEl.src.startsWith("data:")) this.artworkEl.src = ARTWORK_FALLBACK;
|
|
1062
|
-
});
|
|
1063
|
-
}
|
|
1059
|
+
this.bindArtworkFallback(this.artworkEl);
|
|
1064
1060
|
this.currentTimeEl = this.container.querySelector(".time-current");
|
|
1065
1061
|
this.totalTimeEl = this.container.querySelector(".time-total");
|
|
1066
1062
|
this.bpmEl = this.container.querySelector(".waveform-bpm");
|
|
@@ -1073,6 +1069,94 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1073
1069
|
this.resizeCanvas();
|
|
1074
1070
|
this.updateBPMDisplay();
|
|
1075
1071
|
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Bind the artwork error fallback to an image element.
|
|
1074
|
+
*
|
|
1075
|
+
* @param {HTMLImageElement|null} img - Artwork image element.
|
|
1076
|
+
* @private
|
|
1077
|
+
*/
|
|
1078
|
+
bindArtworkFallback(img) {
|
|
1079
|
+
if (!img) return;
|
|
1080
|
+
img.addEventListener("error", () => {
|
|
1081
|
+
if (!img.src.startsWith("data:")) img.src = ARTWORK_FALLBACK;
|
|
1082
|
+
}, { signal: this._ac.signal });
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Create an artwork image element matching the initial player markup.
|
|
1086
|
+
*
|
|
1087
|
+
* @returns {HTMLImageElement} Artwork image element.
|
|
1088
|
+
* @private
|
|
1089
|
+
*/
|
|
1090
|
+
createArtworkElement() {
|
|
1091
|
+
const img = document.createElement("img");
|
|
1092
|
+
img.className = "waveform-artwork";
|
|
1093
|
+
img.style.width = "40px";
|
|
1094
|
+
img.style.height = "40px";
|
|
1095
|
+
img.style.borderRadius = "4px";
|
|
1096
|
+
img.style.objectFit = "cover";
|
|
1097
|
+
img.style.flexShrink = "0";
|
|
1098
|
+
this.bindArtworkFallback(img);
|
|
1099
|
+
return img;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Create an artist text element matching the initial player markup.
|
|
1103
|
+
*
|
|
1104
|
+
* @returns {HTMLSpanElement} Artist text element.
|
|
1105
|
+
* @private
|
|
1106
|
+
*/
|
|
1107
|
+
createArtistElement() {
|
|
1108
|
+
const span = document.createElement("span");
|
|
1109
|
+
span.className = "waveform-artist";
|
|
1110
|
+
return span;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Reconcile artist metadata and markup for the current track.
|
|
1114
|
+
*
|
|
1115
|
+
* @param {string|null} artist - Artist text, or a falsy value to remove it.
|
|
1116
|
+
* @private
|
|
1117
|
+
*/
|
|
1118
|
+
syncArtist(artist) {
|
|
1119
|
+
this.options.artist = artist || null;
|
|
1120
|
+
if (!this.options.showInfo) return;
|
|
1121
|
+
if (!artist) {
|
|
1122
|
+
this.artistEl?.remove();
|
|
1123
|
+
this.artistEl = null;
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (!this.artistEl) {
|
|
1127
|
+
const titleEl = this.container.querySelector(".waveform-title");
|
|
1128
|
+
if (!titleEl) return;
|
|
1129
|
+
this.artistEl = this.createArtistElement();
|
|
1130
|
+
titleEl.after(this.artistEl);
|
|
1131
|
+
}
|
|
1132
|
+
this.artistEl.textContent = artist;
|
|
1133
|
+
this.artistEl.style.display = "";
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Reconcile artwork metadata and markup for the current track.
|
|
1137
|
+
*
|
|
1138
|
+
* @param {string|null} artwork - Artwork image URL, or a falsy value to remove artwork.
|
|
1139
|
+
* @param {string} artworkAlt - Artwork alt text.
|
|
1140
|
+
* @private
|
|
1141
|
+
*/
|
|
1142
|
+
syncArtwork(artwork, artworkAlt = "") {
|
|
1143
|
+
this.options.artwork = artwork || null;
|
|
1144
|
+
this.options.artworkAlt = artworkAlt || "";
|
|
1145
|
+
if (!this.options.showInfo) return;
|
|
1146
|
+
if (!artwork) {
|
|
1147
|
+
this.artworkEl?.remove();
|
|
1148
|
+
this.artworkEl = null;
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
if (!this.artworkEl) {
|
|
1152
|
+
const textEl = this.container.querySelector(".waveform-text");
|
|
1153
|
+
if (!textEl) return;
|
|
1154
|
+
this.artworkEl = this.createArtworkElement();
|
|
1155
|
+
textEl.before(this.artworkEl);
|
|
1156
|
+
}
|
|
1157
|
+
this.artworkEl.src = artwork;
|
|
1158
|
+
this.artworkEl.alt = artworkAlt || "";
|
|
1159
|
+
}
|
|
1076
1160
|
/**
|
|
1077
1161
|
* Create audio element
|
|
1078
1162
|
* @private
|
|
@@ -1622,10 +1706,12 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1622
1706
|
* @param {string|null} [artist=null] - Track artist; pass `''` to hide
|
|
1623
1707
|
* the artist row, or null to keep the existing one.
|
|
1624
1708
|
* @param {Object} [options={}] - Additional options to merge (e.g.
|
|
1625
|
-
* `preload`, `artwork`, `markers`, `autoplay`).
|
|
1709
|
+
* `preload`, `artwork`, `artworkAlt`, `markers`, `autoplay`).
|
|
1626
1710
|
* @returns {Promise<void>}
|
|
1627
1711
|
*/
|
|
1628
1712
|
async loadTrack(url, title = null, artist = null, options = {}) {
|
|
1713
|
+
const hasArtworkOption = Object.prototype.hasOwnProperty.call(options, "artwork");
|
|
1714
|
+
const hasArtworkAltOption = Object.prototype.hasOwnProperty.call(options, "artworkAlt");
|
|
1629
1715
|
if (this.isPlaying) {
|
|
1630
1716
|
this.pause();
|
|
1631
1717
|
}
|
|
@@ -1647,23 +1733,29 @@ var WaveformPlayer = class _WaveformPlayer {
|
|
|
1647
1733
|
this.waveformData = [];
|
|
1648
1734
|
this.options = mergeOptions(this.options, {
|
|
1649
1735
|
url,
|
|
1650
|
-
title: title
|
|
1651
|
-
artist: artist
|
|
1736
|
+
title: title === null ? this.options.title : title,
|
|
1737
|
+
artist: artist === null ? this.options.artist : artist,
|
|
1652
1738
|
...options
|
|
1653
1739
|
});
|
|
1740
|
+
if (hasArtworkOption) {
|
|
1741
|
+
this.options.artwork = options.artwork || null;
|
|
1742
|
+
}
|
|
1743
|
+
if (hasArtworkAltOption) {
|
|
1744
|
+
this.options.artworkAlt = options.artworkAlt || "";
|
|
1745
|
+
} else if (hasArtworkOption) {
|
|
1746
|
+
this.options.artworkAlt = this.options.artwork ? DEFAULT_OPTIONS.artworkAlt : "";
|
|
1747
|
+
}
|
|
1654
1748
|
if (options.preload && this.audio) {
|
|
1655
1749
|
this.audio.preload = options.preload;
|
|
1656
1750
|
}
|
|
1657
|
-
if (
|
|
1658
|
-
|
|
1659
|
-
this.artistEl.textContent = artist;
|
|
1660
|
-
this.artistEl.style.display = "";
|
|
1661
|
-
} else if (artist === "") {
|
|
1662
|
-
this.artistEl.style.display = "none";
|
|
1663
|
-
}
|
|
1751
|
+
if (artist !== null) {
|
|
1752
|
+
this.syncArtist(artist);
|
|
1664
1753
|
}
|
|
1665
|
-
if (
|
|
1666
|
-
this.
|
|
1754
|
+
if (hasArtworkOption || hasArtworkAltOption) {
|
|
1755
|
+
this.syncArtwork(
|
|
1756
|
+
hasArtworkOption ? options.artwork : this.options.artwork,
|
|
1757
|
+
hasArtworkAltOption ? options.artworkAlt : this.options.artworkAlt
|
|
1758
|
+
);
|
|
1667
1759
|
}
|
|
1668
1760
|
this.options.markers = options.markers || [];
|
|
1669
1761
|
this.options.waveform = options.waveform || null;
|