@supr-design/flux-player 1.1.0 → 1.2.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/README.md +6 -0
- package/flux-player.es.js +41 -13
- package/flux-player.umd.js +2 -2
- package/package.json +1 -1
- package/styles.css +12 -0
- package/types.d.ts +5 -0
package/README.md
CHANGED
|
@@ -28,6 +28,12 @@ const player = createPlayer('#player', {
|
|
|
28
28
|
|
|
29
29
|
Click Play to start. Call `await player.destroy()` when removing the player. TypeScript declarations are included. For script-tag integration, serve `flux-player.umd.js` and `styles.css` from the package and call `window.Flux.createPlayer()`.
|
|
30
30
|
|
|
31
|
+
## Custom icons
|
|
32
|
+
|
|
33
|
+
Pass image URLs under `ui.icons` when creating a player. To change the artwork
|
|
34
|
+
during playback, call `player.setIcons({ play: '/icons/play.svg', pause: '/icons/pause.svg' })`.
|
|
35
|
+
Pass `{}` to restore the default icons. [Theme and icon guide](https://supr-design.github.io/Flux/#docs-icons).
|
|
36
|
+
|
|
31
37
|
## Licensing
|
|
32
38
|
|
|
33
39
|
Flux is source-available under the included PolyForm Noncommercial License 1.0.0. Commercial use outside its grant requires a separate agreement. [Request commercial terms](https://github.com/Supr-Design/Flux/issues/new?title=Commercial%20licensing%20inquiry).
|
package/flux-player.es.js
CHANGED
|
@@ -741,6 +741,8 @@ var v = class {
|
|
|
741
741
|
uiPaused = !0;
|
|
742
742
|
isDragging = !1;
|
|
743
743
|
uiConfig;
|
|
744
|
+
iconOverrides;
|
|
745
|
+
renderedIcons = /* @__PURE__ */ new Map();
|
|
744
746
|
cleans = [];
|
|
745
747
|
domCleans = [];
|
|
746
748
|
idleTimeout;
|
|
@@ -766,7 +768,7 @@ var v = class {
|
|
|
766
768
|
}
|
|
767
769
|
}
|
|
768
770
|
constructor(e, t, n = {}) {
|
|
769
|
-
if (this.player = e, this.uiConfig = n, typeof t == "string") {
|
|
771
|
+
if (this.player = e, this.uiConfig = n, this.iconOverrides = { ...n.icons }, typeof t == "string") {
|
|
770
772
|
let e = document.querySelector(t);
|
|
771
773
|
if (!e) throw Error(`Target ${t} not found`);
|
|
772
774
|
this.container = e;
|
|
@@ -774,7 +776,7 @@ var v = class {
|
|
|
774
776
|
this.videoEl = document.createElement("video"), this.videoEl.className = "flux-player-video", this.player.attachVideo(this.videoEl), this.render(), this.bindEvents(), this.updateState(this.player.getState());
|
|
775
777
|
}
|
|
776
778
|
render() {
|
|
777
|
-
this.container.innerHTML = "", this.wrapper = document.createElement("div"), this.wrapper.className = "flux-player-wrapper", this.wrapper.appendChild(this.videoEl), this.spinner = document.createElement("div"), this.spinner.className = "flux-player-spinner", this.wrapper.appendChild(this.spinner), this.bigPlay = document.createElement("div"), this.bigPlay.className = "flux-player-big-play", this.bigPlay.
|
|
779
|
+
this.container.innerHTML = "", this.wrapper = document.createElement("div"), this.wrapper.className = "flux-player-wrapper", this.wrapper.appendChild(this.videoEl), this.spinner = document.createElement("div"), this.spinner.className = "flux-player-spinner", this.wrapper.appendChild(this.spinner), this.bigPlay = document.createElement("div"), this.bigPlay.className = "flux-player-big-play", this.bigPlay.setAttribute("aria-label", "Play"), this.renderIcon(this.bigPlay, "play"), this.wrapper.appendChild(this.bigPlay), f.makeClickable(this.bigPlay, () => this.handlePrimaryAction()), this.replayBtn = document.createElement("div"), this.replayBtn.className = "flux-player-replay flux-hidden", this.replayBtn.setAttribute("aria-label", "Replay"), this.renderIcon(this.replayBtn, "replay"), this.wrapper.appendChild(this.replayBtn), f.makeClickable(this.replayBtn, () => this.replay()), this.errorPanel = document.createElement("div"), this.errorPanel.className = "flux-player-error flux-hidden", this.errorPanel.innerHTML = "<div class=\"flux-player-error-title\">Playback Error</div>", this.errorTextEl = document.createElement("div"), this.errorTextEl.className = "flux-player-error-text", this.errorPanel.appendChild(this.errorTextEl), this.wrapper.appendChild(this.errorPanel), this.overlay = document.createElement("div"), this.overlay.className = "flux-player-overlay";
|
|
778
780
|
let e = document.createElement("div");
|
|
779
781
|
e.className = "flux-player-controls", this.timeline = document.createElement("div"), this.timeline.className = "flux-player-timeline", this.timeline.setAttribute("role", "slider"), this.timeline.setAttribute("aria-label", "Seek timeline"), this.timeline.tabIndex = -1, this.bufferedFill = document.createElement("div"), this.bufferedFill.className = "flux-player-timeline-buffered", this.progressFill = document.createElement("div"), this.progressFill.className = "flux-player-timeline-progress", this.timelineThumbnailPreview = document.createElement("div"), this.timelineThumbnailPreview.className = "flux-player-thumbnail-preview flux-hidden", this.timelineThumbnailImage = document.createElement("img"), this.timelineThumbnailImage.className = "flux-player-thumbnail-image", this.timelineThumbnailImage.alt = "", this.timelineThumbnailImage.setAttribute("aria-hidden", "true"), this.timelineThumbnailImage.onload = () => {
|
|
780
782
|
this.thumbnailVttUrl && this.timelineThumbnailPreview.classList.remove("flux-hidden");
|
|
@@ -784,18 +786,37 @@ var v = class {
|
|
|
784
786
|
let t = document.createElement("div");
|
|
785
787
|
t.className = "flux-player-toolbar";
|
|
786
788
|
let n = document.createElement("div");
|
|
787
|
-
n.className = "flux-player-toolbar-group", this.playBtn = this.createBtn("play",
|
|
789
|
+
n.className = "flux-player-toolbar-group", this.playBtn = this.createBtn("play", "play", "Play"), this.muteBtn = this.createBtn("mute", "volume", "Mute"), this.volumeSlider = document.createElement("input"), this.volumeSlider.type = "range", this.volumeSlider.min = "0", this.volumeSlider.max = "1", this.volumeSlider.step = "0.05", this.volumeSlider.className = "flux-player-volume-slider", this.volumeSlider.setAttribute("role", "slider"), this.volumeSlider.setAttribute("aria-label", "Volume");
|
|
788
790
|
let r = document.createElement("div");
|
|
789
791
|
r.className = "flux-player-volume-container", r.appendChild(this.muteBtn), r.appendChild(this.volumeSlider), this.timeDisplay = document.createElement("div"), this.timeDisplay.className = "flux-player-time", this.timeDisplay.innerText = "0:00 / 0:00", this.timeDisplay.setAttribute("aria-live", "polite"), this.timeDisplay.setAttribute("aria-atomic", "true"), n.appendChild(this.playBtn), n.appendChild(r), n.appendChild(this.timeDisplay);
|
|
790
792
|
let i = document.createElement("div");
|
|
791
|
-
i.className = "flux-player-toolbar-group", this.liveBadge = document.createElement("div"), this.liveBadge.className = "flux-player-live-badge flux-hidden", this.liveBadge.innerHTML = "<span></span>LIVE", this.liveBadge.setAttribute("aria-live", "polite"), this.liveBadge.setAttribute("aria-label", "Live stream"), this.pipBtn = this.createBtn("pip",
|
|
793
|
+
i.className = "flux-player-toolbar-group", this.liveBadge = document.createElement("div"), this.liveBadge.className = "flux-player-live-badge flux-hidden", this.liveBadge.innerHTML = "<span></span>LIVE", this.liveBadge.setAttribute("aria-live", "polite"), this.liveBadge.setAttribute("aria-label", "Live stream"), this.pipBtn = this.createBtn("pip", "pip", "Picture in Picture"), this.fullscreenBtn = this.createBtn("fullscreen", "fullscreen", "Fullscreen"), this.settingsBtn = this.createBtn("settings", "settings", "Settings"), this.settingsBtn.setAttribute("aria-haspopup", "menu"), this.settingsBtn.setAttribute("aria-expanded", "false"), i.appendChild(this.liveBadge), this.extraButtons = document.createElement("div"), this.extraButtons.className = "flux-player-toolbar-group", i.appendChild(this.extraButtons), i.appendChild(this.pipBtn), i.appendChild(this.settingsBtn), i.appendChild(this.fullscreenBtn), t.appendChild(n), t.appendChild(i), e.appendChild(t), this.settingsMenu = document.createElement("div"), this.settingsMenu.className = "flux-player-settings-menu flux-hidden", this.settingsMenu.setAttribute("role", "menu"), this.settingsMenu.setAttribute("aria-label", "Player settings"), e.appendChild(this.settingsMenu), this.overlay.appendChild(e), this.subtitleDisplay = document.createElement("div"), this.subtitleDisplay.className = "flux-player-subtitles flux-subs-raised", this.wrapper.appendChild(this.subtitleDisplay), this.wrapper.appendChild(this.overlay), this.container.appendChild(this.wrapper), this.setToolbar(this.uiConfig.toolbar ?? {}), _(this.wrapper, "dark");
|
|
792
794
|
}
|
|
793
795
|
setControlsIdle(e) {
|
|
794
796
|
e ? (this.overlay.classList.add("flux-idle"), this.subtitleDisplay.classList.remove("flux-subs-raised")) : (this.overlay.classList.remove("flux-idle"), this.subtitleDisplay.classList.add("flux-subs-raised"));
|
|
795
797
|
}
|
|
798
|
+
setIcons(e) {
|
|
799
|
+
this.iconOverrides = { ...e };
|
|
800
|
+
for (let [e, { name: t }] of this.renderedIcons) this.renderIcon(e, t);
|
|
801
|
+
}
|
|
802
|
+
renderIcon(e, t) {
|
|
803
|
+
let n = this.iconOverrides[t], r = this.renderedIcons.get(e);
|
|
804
|
+
if (r?.name === t && r.url === n) return;
|
|
805
|
+
if (this.renderedIcons.set(e, {
|
|
806
|
+
name: t,
|
|
807
|
+
url: n
|
|
808
|
+
}), !n) {
|
|
809
|
+
e.innerHTML = u[t];
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
let i = document.createElement("img");
|
|
813
|
+
i.alt = "", i.draggable = !1, i.onerror = () => {
|
|
814
|
+
i.parentElement === e && (e.innerHTML = u[t]);
|
|
815
|
+
}, i.src = n, e.replaceChildren(i);
|
|
816
|
+
}
|
|
796
817
|
createBtn(e, t, n) {
|
|
797
818
|
let r = document.createElement("button");
|
|
798
|
-
return r.className = `flux-player-icon-btn flux-btn-${e}`, r
|
|
819
|
+
return r.className = `flux-player-icon-btn flux-btn-${e}`, this.renderIcon(r, t), r.setAttribute("aria-label", n), r;
|
|
799
820
|
}
|
|
800
821
|
formatTime(e) {
|
|
801
822
|
if (isNaN(e)) return "0:00";
|
|
@@ -820,7 +841,8 @@ var v = class {
|
|
|
820
841
|
}), this.listen(this.fullscreenBtn, "click", () => {
|
|
821
842
|
document.fullscreenElement ? document.exitFullscreen().catch(() => {}) : this.wrapper.requestFullscreen().catch(() => {});
|
|
822
843
|
}), this.fullscreenChangeHandler = () => {
|
|
823
|
-
|
|
844
|
+
let e = document.fullscreenElement === this.wrapper;
|
|
845
|
+
this.renderIcon(this.fullscreenBtn, e ? "fullscreenExit" : "fullscreen"), this.fullscreenBtn.setAttribute("aria-label", e ? "Exit fullscreen" : "Fullscreen");
|
|
824
846
|
}, this.listen(document, "fullscreenchange", this.fullscreenChangeHandler);
|
|
825
847
|
let t = (e) => {
|
|
826
848
|
let t = this.getTimelineHoverData(e.clientX);
|
|
@@ -1176,15 +1198,20 @@ var v = class {
|
|
|
1176
1198
|
}
|
|
1177
1199
|
e.selectedSubtitle === null && !e.availableSubtitles.some((e) => e.selected) && this.subtitleDisplay.replaceChildren(), this.syncThumbnailTrack(e).catch((e) => {
|
|
1178
1200
|
console.warn("[DefaultUI] Thumbnail sync failed", e);
|
|
1179
|
-
})
|
|
1201
|
+
});
|
|
1202
|
+
let r = e.ended && !e.error ? "replay" : e.paused ? "play" : "pause";
|
|
1203
|
+
this.renderIcon(this.playBtn, r);
|
|
1204
|
+
let i = r === "replay" ? "Replay" : e.paused ? "Play" : "Pause";
|
|
1205
|
+
this.playBtn.ariaLabel !== i && (this.playBtn.ariaLabel = i), e.paused ? this.uiPaused || (this.uiPaused = !0, !e.error && !e.ended && this.bigPlay.classList.remove("flux-hidden"), this.setControlsIdle(!1), clearTimeout(this.idleTimeout)) : this.uiPaused && (this.uiPaused = !1, this.bigPlay.classList.add("flux-hidden"), this.replayBtn.classList.add("flux-hidden"), this.setControlsIdle(!1), clearTimeout(this.idleTimeout), this.menuOpen || (this.idleTimeout = setTimeout(() => {
|
|
1180
1206
|
this.setControlsIdle(!0);
|
|
1181
|
-
}, 3e3))), e.buffering ? this.spinner.classList.remove("flux-hidden") : this.spinner.classList.add("flux-hidden"), e.error ? (this.errorPanel.classList.remove("flux-hidden"), this.errorTextEl.innerText = e.error.message, this.spinner.classList.add("flux-hidden"), this.bigPlay.classList.add("flux-hidden"), this.replayBtn.classList.add("flux-hidden")) : this.errorPanel.classList.add("flux-hidden"), e.ended && !e.error ? (this.bigPlay.classList.add("flux-hidden"), this.replayBtn.classList.remove("flux-hidden"), this.setControlsIdle(!1)
|
|
1182
|
-
let
|
|
1183
|
-
if (!this.isDragging && (this.timeDisplay.innerText = `${this.formatTime(e.currentTime)} / ${this.formatTime(
|
|
1207
|
+
}, 3e3))), e.buffering ? this.spinner.classList.remove("flux-hidden") : this.spinner.classList.add("flux-hidden"), e.error ? (this.errorPanel.classList.remove("flux-hidden"), this.errorTextEl.innerText = e.error.message, this.spinner.classList.add("flux-hidden"), this.bigPlay.classList.add("flux-hidden"), this.replayBtn.classList.add("flux-hidden")) : this.errorPanel.classList.add("flux-hidden"), e.ended && !e.error ? (this.bigPlay.classList.add("flux-hidden"), this.replayBtn.classList.remove("flux-hidden"), this.setControlsIdle(!1)) : this.replayBtn.classList.add("flux-hidden"), e.isLive ? (this.liveBadge.classList.remove("flux-hidden"), this.timeline.classList.add("flux-disabled"), this.timeDisplay.classList.add("flux-hidden")) : (this.liveBadge.classList.add("flux-hidden"), this.timeline.classList.remove("flux-disabled"), this.timeDisplay.classList.remove("flux-hidden"));
|
|
1208
|
+
let a = e.duration || 0;
|
|
1209
|
+
if (!this.isDragging && (this.timeDisplay.innerText = `${this.formatTime(e.currentTime)} / ${this.formatTime(a)}`, this.timeDisplay.setAttribute("aria-label", e.isLive ? `Live stream, current position ${this.formatTime(e.currentTime)}` : `Current time ${this.formatTime(e.currentTime)} of ${this.formatTime(a)}`), this.timeline.setAttribute("aria-valuemin", "0"), this.timeline.setAttribute("aria-valuenow", String(Math.round(e.currentTime))), this.timeline.setAttribute("aria-valuemax", String(Number.isFinite(a) ? Math.round(a) : 0)), this.timeline.setAttribute("aria-valuetext", `${this.formatTime(e.currentTime)} of ${this.formatTime(a)}`), a > 0)) if (this.progressFill.style.width = `${e.currentTime / a * 100}%`, e.buffered.length > 0) {
|
|
1184
1210
|
let t = e.buffered[e.buffered.length - 1];
|
|
1185
|
-
this.bufferedFill.style.width = `${t.end /
|
|
1211
|
+
this.bufferedFill.style.width = `${t.end / a * 100}%`;
|
|
1186
1212
|
} else this.bufferedFill.style.width = "0%";
|
|
1187
|
-
|
|
1213
|
+
let o = e.muted ? "Unmute" : "Mute";
|
|
1214
|
+
this.muteBtn.ariaLabel !== o && (this.muteBtn.ariaLabel = o), e.muted || e.volume === 0 ? (this.renderIcon(this.muteBtn, "mute"), this.volumeSlider.value = "0") : (this.renderIcon(this.muteBtn, "volume"), this.volumeSlider.value = String(e.volume));
|
|
1188
1215
|
}
|
|
1189
1216
|
toggleMenu(e) {
|
|
1190
1217
|
this.menuOpen = typeof e == "boolean" ? e : !this.menuOpen, this.menuOpen ? (this.renderMenu(), this.settingsMenu.classList.remove("flux-hidden"), this.settingsBtn.setAttribute("aria-expanded", "true"), this.menuFocusIndex = 0, this.updateMenuA11yState(), this.focusMenuItem(this.menuFocusIndex), clearTimeout(this.idleTimeout)) : (this.settingsMenu.classList.add("flux-hidden"), this.settingsBtn.setAttribute("aria-expanded", "false"), this.wrapper.dispatchEvent(new Event("mousemove")));
|
|
@@ -1250,7 +1277,7 @@ var v = class {
|
|
|
1250
1277
|
this.settingsMenu.appendChild(n);
|
|
1251
1278
|
}
|
|
1252
1279
|
destroy() {
|
|
1253
|
-
this.thumbnailFetchAbort?.abort(), this.cleans.forEach((e) => e()), this.domCleans.forEach((e) => e()), this.domCleans = [], clearTimeout(this.idleTimeout), this.container.innerHTML = "";
|
|
1280
|
+
this.renderedIcons.clear(), this.thumbnailFetchAbort?.abort(), this.cleans.forEach((e) => e()), this.domCleans.forEach((e) => e()), this.domCleans = [], clearTimeout(this.idleTimeout), this.container.innerHTML = "";
|
|
1254
1281
|
}
|
|
1255
1282
|
}, y = class {
|
|
1256
1283
|
player;
|
|
@@ -1831,6 +1858,7 @@ function T(e, t) {
|
|
|
1831
1858
|
setVolume: (e) => n.setVolume(e),
|
|
1832
1859
|
setMuted: (e) => n.setMuted(e),
|
|
1833
1860
|
setPlaybackRate: (e) => n.setPlaybackRate(e),
|
|
1861
|
+
setIcons: (e) => u?.setIcons(e),
|
|
1834
1862
|
setToolbar: (e) => u?.setToolbar(e),
|
|
1835
1863
|
setTheme: (e) => {
|
|
1836
1864
|
i && _(i.querySelector(".flux-player-wrapper") || i, e);
|