@asicupv/paella-core
Version:
Multi stream HTML video player
1,523 lines (1,522 loc) • 233 kB
JavaScript
//#region \0rolldown/runtime.js
var e = Object.defineProperty, t = (t, n) => {
let r = {};
for (var i in t) e(r, i, {
get: t[i],
enumerable: !0
});
return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
}, n = /* @__PURE__ */ function(e) {
return e.PLAY = "paella:play", e.PAUSE = "paella:pause", e.STOP = "paella:stop", e.ENDED = "paella:ended", e.SEEK = "paella:seek", e.FULLSCREEN_CHANGED = "paella:fullscreenchanged", e.ENTER_FULLSCREEN = "paella:enterfullscreen", e.EXIT_FULLSCREEN = "paella:exitfullscreen", e.VOLUME_CHANGED = "paella:volumeChanged", e.TIMEUPDATE = "paella:timeupdate", e.TRIMMING_CHANGED = "paella:trimmingChanged", e.CAPTIONS_CHANGED = "paella:captionsChanged", e.CAPTIONS_ENABLED = "paella:captionsEnabled", e.CAPTIONS_DISABLED = "paella:captionsDisabled", e.BUTTON_PRESS = "paella:buttonPress", e.SHOW_POPUP = "paella:showPopUp", e.HIDE_POPUP = "paella:hidePopUp", e.MANIFEST_LOADED = "paella:manifestLoaded", e.STREAM_LOADED = "paella:streamLoaded", e.PLAYER_LOADED = "paella:playerLoaded", e.PLAYER_UNLOADED = "paella:playerUnloaded", e.RESIZE = "paella:resize", e.RESIZE_END = "paella:resizeEnd", e.LAYOUT_CHANGED = "paella:layoutChanged", e.PLAYBACK_RATE_CHANGED = "paella:playbackRateChanged", e.VIDEO_QUALITY_CHANGED = "paella:videoQualityChanged", e.HIDE_UI = "paella:hideUI", e.SHOW_UI = "paella:showUI", e.COOKIE_CONSENT_CHANGED = "paella:cookieConsentChanged", e.LOG = "paella:log", e.MENU_ITEM_SELECTED = "paella:menuItemSelected", e;
}(n || {});
function r(e, t, n, r = !0) {
return e.__eventListeners__ = e.__eventListeners__ || {}, Array.isArray(t) || (t = [t]), t.forEach((t) => {
e.__eventListeners__[t] = e.__eventListeners__[t] || [], e.__eventListeners__[t].push({
callback: n,
unregisterOnUnload: r
});
}), n;
}
function i(e, t, n = {}) {
e.__eventListeners__ && e.__eventListeners__[t] && e.__eventListeners__[t].forEach((e) => e.callback(n));
}
function a(e, t, n = {}) {
e.ready && i(e, t, n);
}
function o(e) {
if (e.__eventListeners__) for (let t in e.__eventListeners__) e.__eventListeners__[t] = e.__eventListeners__[t].filter((e) => e.unregisterOnUnload == 0), e.log.debug("Unregister event: " + e.__eventListeners__[t]);
}
//#endregion
//#region src/js/core/utils.ts
var s = /* @__PURE__ */ t({
clearAutoHideTimer: () => re,
getCookie: () => C,
getFileExtension: () => ee,
getHashParameter: () => d,
getJSONCookie: () => se,
getNumericCookie: () => oe,
getRandomUUID: () => pe,
getUrlFileName: () => h,
getUrlParameter: () => u,
isAbsoluteUrl: () => p,
isBase64: () => m,
isSvgString: () => l,
joinPath: () => f,
loadStyle: () => ce,
loadSvgIcon: () => c,
mergeObjects: () => w,
pauseAutoHideUiTimer: () => te,
removeExtension: () => g,
removeFileName: () => _,
resolveResourcePath: () => v,
resumeAutoHideUiTimer: () => ne,
sanitizeHTML: () => ue,
secondsToTime: () => b,
setCookie: () => S,
setCookieIfAllowed: () => ae,
setupAutoHideUiTimer: () => y,
supportsVideoType: () => fe,
timeToMilliseconds: () => ie,
timeToSeconds: () => x,
unloadStyle: () => le
});
function c(e) {
return new Promise((t, n) => {
fetch(e).then((e) => e.text()).then((e) => {
t(e);
}).catch((e) => n(e));
});
}
function l(e) {
return typeof e == "string" ? /<svg[^>]*>/i.test(e) : !1;
}
function u(e) {
let t = new URLSearchParams(window.location.search);
return t.has(e) ? t.get(e) : null;
}
function d(e) {
let t = window.location.hash.replace("#", "?"), n = new URLSearchParams(t);
return n.has(e) ? n.get(e) : null;
}
function f(e, t = "/") {
let n = t;
return e = e.map((t, r) => (r && (t = t.replace(RegExp("^" + n), "")), r !== e.length - 1 && (t = t.replace(RegExp(n + "$"), "")), t)), e.join(n);
}
function p(e) {
return (/* @__PURE__ */ RegExp("^([a-z]+://|//)", "i")).test(e) || /^\//.test(e);
}
function m(e) {
return /^data:([a-zA-Z]+\/[a-zA-Z0-9-.+]+)?;base64,/.test(e);
}
function h(e) {
try {
return new URL(e).pathname.split("/").pop();
} catch {
return e.split("/").pop();
}
}
function g(e) {
return e.split(".").reduce((e, t, n, r) => n < r.length - 1 ? e === "" ? t : `${e}.${t}` : e, "");
}
function _(e) {
let t = (e) => {
let t = e.split("/").reduce((e, t, n, r) => n < r.length - 1 ? e === "" ? t : `${e}/${t}` : e, "");
return (e[0] === "/" ? `/${t}` : t) + "/";
};
try {
let n = new URL(e);
return n.origin + t(n.pathname);
} catch {
return t(e);
}
}
function ee(e) {
return h(e)?.split(".").pop() || "";
}
function v(e, t) {
return p(t) || m(t) ? t : f([e.manifestUrl || "", t]);
}
function te(e) {
e.__hideTimerPaused__ = !0;
}
function ne(e) {
e.__hideTimerPaused__ = !1;
}
function y(e, t = "hideUiTime") {
e.__hideTimer__ = null;
let i = async () => e.__hideTimerPaused__ ? (e.log.debug("UI not hidden because the auto hide timer is paused"), !1) : a() ? (e.log.debug("UI not hidden because there is a focused element"), !1) : (await e.hideUserInterface(), !0);
e.config.ui?.hideOnMouseLeave && e.containerElement.addEventListener("mouseleave", () => {
i();
});
let a = () => {
let t = document.activeElement, n = document.querySelector(":focus-visible");
return (e.playbackBar?.element?.contains(t) || e.videoContainer?.element?.contains(t)) && [
"input",
"textarea",
"button"
].find((e) => t?.tagName.toLowerCase() === e) && n;
}, o = async () => {
e.__hideTimer__ && clearTimeout(e.__hideTimer__), await e.showUserInterface(), e.__hideTimer__ = setTimeout(async () => {
e.__hideTimer__ = null, i() || o();
}, e[t]);
};
e.containerElement.addEventListener("mousemove", async (e) => {
o();
}), r(e, n.PLAY, async () => {
o();
}), r(e, n.PAUSE, async () => {
await e.showUserInterface();
}), r(e, n.ENDED, async () => {
await e.showUserInterface();
}), document.addEventListener("keydown", async () => {
o();
});
}
function re(e) {
e.__hideTimer__ && (clearTimeout(e.__hideTimer__), delete e.__hideTimer__);
}
function b(e) {
let t = Math.floor(e / 60 / 60), n = Math.floor(e / 60) - t * 60, r = Math.floor(e % 60);
return (t > 0 ? t.toString().padStart(2, "0") + ":" : "") + n.toString().padStart(2, "0") + ":" + r.toString().padStart(2, "0");
}
function x(e) {
let t = /^(?:(\d+):){0,1}(\d+):(\d+)(\.\d+)?$/.exec(e);
if (t) {
let e = t[1] === void 0 ? 0 : Number(t[1]), n = Number(t[2]), r = Number(t[3]);
return e * 3600 + n * 60 + r;
}
return null;
}
function ie(e) {
let t = /^(?:(\d+):){0,1}(\d+):(\d+)\.(\d+)?$/.exec(e);
if (t) {
let e = t[1] === void 0 ? 0 : Number(t[1]), n = Number(t[2]), r = Number(t[3]), i = t[4] && Number(t[4]) || 0;
return e * 36e5 + n * 6e4 + r * 1e3 + i;
}
return null;
}
function S(e, t, n = 365) {
let r = /* @__PURE__ */ new Date();
r.setTime(r.getTime() + n * 24 * 60 * 60 * 1e3);
let i = `expires=${r.toUTCString()}`;
document.cookie = `${e}=${t};${i};path=/;SameSite=None;` + (/Apple/.test(navigator.vendor) ? "" : "Secure;");
}
function ae(e, t, n, r, i = 365) {
e.cookieConsent?.getConsentForType(t) && S(n, r, i);
}
function C(e) {
let t = e + "=", n = decodeURIComponent(document.cookie).split(";");
for (let e = 0; e < n.length; ++e) {
let r = n[e];
for (; r.charAt(0) == " ";) r = r.substring(1);
if (r.indexOf(t) == 0) return r.substring(t.length, r.length);
}
return "";
}
function oe(e) {
let t = C(e), n = Number(t);
return t !== "" && !isNaN(n) ? n : null;
}
function se(e) {
try {
return JSON.parse(C(e));
} catch {
return null;
}
}
function ce(e, { addToHeader: t = !0, timeoutMs: n = 3e3 } = {}) {
return new Promise((r, i) => {
let a = document.createElement("link");
a.setAttribute("rel", "stylesheet"), a.setAttribute("href", e);
let o = setTimeout(() => {
s(), r(a);
}, n), s = () => {
clearTimeout(o), a.onload = null, a.onerror = null;
};
a.onload = () => {
clearTimeout(o), r(a);
}, a.onerror = () => {
clearTimeout(o), i();
};
let c = document.getElementsByTagName("head")[0];
t && c.appendChild(a);
});
}
function le(e) {
e && document.getElementsByTagName("head")[0].removeChild(e);
}
function w(e, t, n = !0) {
for (let r in t) {
let i = e[r], a = t[r];
n && Array.isArray(i) && Array.isArray(a) ? (i.forEach((e) => {
a = a.filter((t) => typeof e == "object" && typeof t == "object" && e.id === t.id ? (w(e, t, n), !1) : !0);
}), a.forEach((e) => {
i.push(e);
})) : typeof i == "object" && a ? w(i, a, n) : e[r] = t[r];
}
}
function ue(e, { excludedTags: t = null } = {}) {
let n = document.createElement("div");
n.innerHTML = e;
let r = ["script"];
return Array.isArray(t) && r.push(...t), r.flatMap((e) => Array.from(n.getElementsByTagName(e))).forEach((e) => {
e.parentElement?.removeChild(e);
}), n.innerHTML;
}
var de = null;
function fe(e) {
if (!e) return !1;
de ||= document.createElement("video");
let t = de.canPlayType(e);
if (t === "maybe" || t === "probably") return !0;
if (/video\/mp4/i.test(e)) return t = de.canPlayType("video/mp4"), t === "maybe" || t === "probably";
}
function pe() {
if (self.crypto?.randomUUID) return self.crypto.randomUUID();
let e = new Uint8Array(16);
self.crypto.getRandomValues(e), e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
let t = [...e].map((e) => e.toString(16).padStart(2, "0"));
return t[0] + t[1] + t[2] + t[3] + "-" + t[4] + t[5] + "-" + t[6] + t[7] + "-" + t[8] + t[9] + "-" + t[10] + t[11] + t[12] + t[13] + t[14] + t[15];
}
//#endregion
//#region src/js/core/initFunctions.ts
async function me(e, t) {
return t.log.debug("Using default configuration loading function."), (await fetch(e)).json();
}
async function he(e, t) {
return t.log.debug("Using default getVideoId function"), d("id") || u("id") || e.fallbackId;
}
async function ge(e, t, n, r) {
return r.log.debug("Using default getManifestUrl function"), f([e, t]);
}
async function _e(e, t, n, r) {
return r.log.debug("Using default getManifestFileUrl function"), f([e, t]);
}
async function ve(e, t, n) {
n.log.debug("Using default loadVideoManifest function");
let r = await fetch(e);
if (r.ok) try {
return await r.json();
} catch {
throw Error(n.translate("Error parsing video manifest. Unexpected file format."));
}
else throw Error(n.translate("Error loading video manifest: $1 $2", [r.status, r.statusText]));
}
//#endregion
//#region src/js/core/PlayerResource.ts
var T = class {
#e;
constructor(e) {
this.#e = e;
}
get player() {
return this.#e;
}
};
//#endregion
//#region src/js/core/dom.ts
function ye({ tag: e = "div", attributes: t = {}, children: n = "", innerText: r = "", parent: i = null }) {
let a = document.createElement(e);
r !== null && (a.innerText = r);
for (let e in t) a.setAttribute(e, t[e]);
return n !== null && (a.innerHTML = n), i && i.appendChild(a), a;
}
var be = new Set([
"script",
"iframe",
"object",
"embed",
"base",
"meta",
"link",
"form",
"input",
"textarea",
"select",
"math",
"template"
]), xe = new Set([
"href",
"src",
"action",
"formaction",
"xlink:href",
"poster",
"background"
]);
function Se(e) {
for (let t of be) Array.from(e.getElementsByTagName(t)).forEach((e) => e.remove());
let t = (e) => {
Array.from(e.attributes).forEach((t) => {
(t.name.startsWith("on") || xe.has(t.name) && /^\s*javascript\s*:/i.test(t.value)) && e.removeAttribute(t.name);
}), Array.from(e.children).forEach(t);
};
t(e);
}
function E(e, t = null) {
let n = new DOMParser().parseFromString(e, "text/html");
Se(n.body);
let r = n.body.firstElementChild;
return r && (document.adoptNode(r), t && t.appendChild(r)), r;
}
var D = class extends T {
#e;
constructor(e, { tag: t = "div", attributes: n = {}, children: r = "", parent: i = null }) {
super(e), this.#e = ye({
tag: t,
attributes: n,
children: r,
parent: i
}), Object.defineProperty(this, t, { get: () => this.#e });
}
get element() {
return this.#e;
}
get parent() {
return this.#e.parentElement;
}
hide() {
this.element.style.display = "none";
}
show(e = "block") {
this.element.style.display = "";
}
get isVisible() {
let e = window.getComputedStyle(this.element);
return e.display !== "none" && e.display !== "";
}
setAttribute(e, t) {
this.#e.setAttribute(e, t);
}
removeFromParent() {
this.#e.parentElement?.removeChild(this.#e);
}
setParent(e) {
this.removeFromParent(), e.appendChild(this.#e);
}
}, Ce = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 256 256\" stroke=\"none\" fill=\"currentColor\" style=\"fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;\">\n <g transform=\"matrix(1,0,0,1,3,-3.88857)\">\n <path d=\"M128,35.819C65.633,35.819 14.999,86.453 14.999,148.82C14.999,163.127 17.663,176.817 22.549,189.403L22.475,189.447C11.612,170.791 5.889,149.588 5.889,128C5.889,60.56 60.56,5.889 128,5.889L128,35.819Z\" style=\"fill:url(#_Linear1);\"/>\n </g>\n <g transform=\"matrix(-1,1.22465e-16,-1.22465e-16,-1,258,251.914)\">\n <path d=\"M128,35.819C65.633,35.819 14.999,86.453 14.999,148.82C14.999,163.127 17.663,176.817 22.549,189.403L22.475,189.447C11.612,170.791 5.889,149.588 5.889,128C5.889,60.56 60.56,5.889 128,5.889L128,35.819Z\" style=\"fill:url(#_Linear2);\"/>\n </g>\n <defs>\n <linearGradient id=\"_Linear1\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\" gradientUnits=\"userSpaceOnUse\" gradientTransform=\"matrix(-89.3028,140.734,-140.734,-89.3028,144.417,48.7125)\"><stop offset=\"0\" style=\"stop-color:rgb(13,13,13);stop-opacity:1\"/><stop offset=\"1\" style=\"stop-color:rgb(175,175,175);stop-opacity:0.5\"/></linearGradient>\n <linearGradient id=\"_Linear2\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\" gradientUnits=\"userSpaceOnUse\" gradientTransform=\"matrix(-89.3028,140.734,-140.734,-89.3028,144.417,48.7125)\"><stop offset=\"0\" style=\"stop-color:rgb(13,13,13);stop-opacity:1\"/><stop offset=\"1\" style=\"stop-color:rgb(175,175,175);stop-opacity:0.5\"/></linearGradient>\n </defs>\n</svg>\n", we = class extends D {
constructor(e) {
super(e, { parent: e.containerElement }), this.element.className = "loader-container", this._icon = e.getCustomPluginIcon("@asicupv/paella-core", "LoaderIcon") || Ce;
}
async create() {
E(`<i>${this._icon}</i>`, this.element);
}
get debug() {
return !1;
}
}, Te = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 256 256\" stroke=\"none\" fill=\"currentColor\" style=\"fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;\">\n <g id=\"Cancel\" transform=\"matrix(5.54545,6.8353e-32,6.8353e-32,5.54545,-2567.37,-10735.5)\">\n <path d=\"M486.05,1937C498.192,1937 508.05,1946.86 508.05,1959C508.05,1971.14 498.192,1981 486.05,1981C473.908,1981 464.05,1971.14 464.05,1959C464.05,1946.86 473.908,1937 486.05,1937ZM478.979,1950.52L477.565,1951.93L484.636,1959L477.565,1966.07L478.979,1967.49L486.05,1960.41L493.121,1967.49L494.535,1966.07L487.464,1959L494.535,1951.93L493.121,1950.52L486.05,1957.59L478.979,1950.52Z\" style=\"fill:rgb(210,0,0);\"/>\n </g>\n</svg>\n", Ee = class extends D {
constructor(e, t = "") {
super(e, { parent: e.containerElement }), this.element.className = "error-container", E(`
<div>
<i>${Te}</i>
<p>${t}</p>
</div>`, this.element);
}
}, O = class extends T {
#e;
constructor(e, t) {
super(e), this._config = {}, this.__uiPlugin = !1, this.#e = t, this._config = {};
}
getPluginModuleInstance() {
return null;
}
get config() {
return this._config;
}
get type() {
return "none";
}
get order() {
return this._config?.order || 0;
}
get description() {
return this._config?.description || "";
}
get name() {
return this.#e;
}
preload() {}
async isEnabled() {
return this._config?.enabled || !1;
}
async load() {}
async unload() {}
}, k = class extends O {
get type() {
return "video";
}
get streamType() {
return "mp4";
}
async isCompatible(e) {
return !1;
}
async getVideoInstance(e, t) {
return null;
}
getCompatibleFileExtensions() {
return [];
}
getManifestData(e) {}
}, De = [];
async function Oe(e) {
await U(e, "video", async (e) => {
De.push(e);
});
}
async function ke(e) {
De.slice(0);
}
function Ae(e) {
if (De.length === 0) throw Error("No video plugins loaded. Note that `loadVideoPlugins()` must to be called before using `getVideoPlugins()`.");
return De;
}
function je(e, t) {
let n = ee(t);
return Ae(e).find((e) => e.getCompatibleFileExtensions().indexOf(n) !== -1);
}
async function Me(e, t) {
let n = Ae(e), r = null;
for (let e of n) if (await e.isCompatible(t)) {
r = e;
break;
}
return r;
}
async function Ne() {
return await new Promise((e) => {
let t = document.createElement("audio"), n = setTimeout(() => e(!1), 100);
t.addEventListener("volumechange", (t) => {
clearTimeout(n), e(!0);
}), t.volume = .5;
});
}
var A = class extends D {
constructor(e, t, n = null) {
super(t, {
tag: e,
attributes: { class: "video-player" },
parent: n
}), this._streamProvider = null, this._streamDData = null, this._ready = !1;
}
async isVolumeApiAvailable() {
return await Ne();
}
get streamData() {
return this._streamData;
}
get ready() {
return this._ready;
}
async load(e, t) {
return this._streamProvider = t, this._streamData = e, await this.loadStreamData(e);
}
get isMainAudioPlayer() {
return this._streamProvider.mainAudioPlayer === this;
}
onVideoEnded(e) {
this._videoEndedCallback = e;
}
async play() {
return !1;
}
async pause() {
return !1;
}
async duration() {
return -1;
}
get currentTimeSync() {
return -1;
}
async currentTime() {
return -1;
}
async setCurrentTime(e) {
return !1;
}
async volume() {
return -1;
}
async setVolume(e) {
return !1;
}
initVolume(e) {
this._initialVolume = e;
}
async paused() {
return !0;
}
async playbackRate() {
return -1;
}
async setPlaybackRate(e) {
return !1;
}
async getQualities() {
return null;
}
async setQuality(e) {
return !1;
}
get currentQuality() {
return null;
}
async getDimensions() {
return null;
}
async supportsMultiaudio() {
return !1;
}
async getAudioTracks() {
return null;
}
async setCurrentAudioTrack(e) {
return null;
}
get currentAudioTrack() {
return null;
}
async loadStreamData(e) {
return !1;
}
get isEnabled() {
return this._enabled;
}
async enable() {
this._enabled = !0;
}
async disable() {
this._enabled = !1;
}
}, j = class {
get moduleName() {
return console.warn(`Incomplete player module definition: '${__filename}.moduleName'`), "-";
}
get moduleVersion() {
return console.warn(`Incomplete player module definition: '${__filename}.moduleVersion'`), "0.0.0";
}
async getDictionaries() {
return null;
}
}, M = {
name: "@asicupv/paella-core",
exports: {
".": "./dist/paella-core.js",
"./src/": "./src/",
"./paella-core.css": "./dist/paella-core.css"
},
version: "2.12.11",
description: "Multi stream HTML video player",
main: "./dist/paella-core.js",
publishConfig: { access: "public" },
files: [
"dist/paella-core.css",
"dist/paella-core.js",
"dist/paella-core.js.map",
"dist/paella-core.d.ts"
],
module: "./dist/paella-core.js",
types: "./dist/paella-core.d.ts",
type: "module",
scripts: {
dev: "vite build --watch",
build: "vite build --emptyOutDir && npm run bundle:types",
"bundle:types": "dts-bundle-generator --project tsconfig.bundle-types.json -o dist/paella-core.d.ts dist/index.d.ts --no-check",
types: "tsc -p tsconfig.debug.json",
"i18n:check": "i18n-check -s es-ES -l ./src/i18n",
"clean:build": "rimraf .turbo dist",
"clean:deps": "rimraf node_modules"
},
repository: {
type: "git",
url: "git+https://github.com/polimediaupv/paella-player.git"
},
keywords: [
"html",
"player",
"video",
"hls"
],
author: "Fernando Serrano Carpena <ferserc1@gmail.com>",
license: "ECL-2.0",
bugs: { url: "https://github.com/polimediaupv/paella-player/issues" },
homepage: "https://github.com/polimediaupv/paella-player#readme",
devDependencies: {
"dts-bundle-generator": "^9.5.1",
typescript: "^6.0.3",
vite: "^8.0.10",
"vite-plugin-dts": "^4.5.4"
},
dependencies: { "@ferserc1/input-style-unifier": "^0.0.2" }
}, Pe = null, Fe = class e extends j {
static Get() {
return Pe ||= new e(), Pe;
}
get moduleName() {
return "paella-core default video formats";
}
get moduleVersion() {
return M.version;
}
};
//#endregion
//#region src/js/videoFormats/es.upv.paella.audioVideoFormat.ts
function Ie(e) {
return new Promise((t, n) => {
let r = new Image();
r.addEventListener("load", (e) => {
t(r);
}), r.addEventListener("error", (e) => {
n(/* @__PURE__ */ Error("Could not load preview image. The preview image is required in audio only streams"));
}), r.src = e;
});
}
function Le(e, t, n, r = 6e4) {
return new Promise((i, a) => {
let o = !1, s = setTimeout(() => {
o || (o = !0, a(Error(e.translate("Timeout loading audio after $1 seconds", [String(r / 1e3)]))));
}, r), c = () => {
clearTimeout(s), t.oncanplaythrough = null, t.onerror = null;
};
t.oncanplaythrough = () => {
o || (o = !0, c(), i());
}, t.onerror = () => {
o || (o = !0, c(), a(Error(e.translate("Error loading audio: $1", [n]))));
}, t.src = v(e, n);
});
}
var Re = class extends A {
constructor(e, t, n) {
super("audio", e, t), this.isMainAudio = n, this._ready = !1;
}
get streamType() {
return "audio";
}
waitForLoaded() {
return new Promise((e) => {
let t = () => {
this._ready ? e() : setTimeout(t, 100);
};
t();
});
}
async play() {
return await this.waitForLoaded(), await this.audio.play(), !0;
}
async pause() {
return await this.waitForLoaded(), this.audio.pause(), !0;
}
async duration() {
return await this.waitForLoaded(), this.audio.duration;
}
get currentTimeSync() {
return this.audio?.currentTime || 0;
}
async currentTime() {
return await this.waitForLoaded(), this.audio.currentTime;
}
async setCurrentTime(e) {
return await this.waitForLoaded(), this.audio.currentTime = e, !0;
}
async volume() {
return await this.waitForLoaded(), this.audio.volume;
}
async setVolume(e) {
return await this.waitForLoaded(), this.audio.volume = e, !0;
}
async paused() {
return await this.waitForLoaded(), this.audio.paused;
}
async playbackRate() {
return await this.waitForLoaded(), this.audio.playbackRate;
}
async setPlaybackRate(e) {
return await this.waitForLoaded(), this.audio.playbackRate = e, !0;
}
async getDimensions() {
return {
w: this._previewImage.width,
h: this._previewImage.height
};
}
async loadStreamData(e = null) {
this._streamData = this._streamData || e, this.player.log.debug("es.upv.paella.audioVideoFormat: loadStreamData");
let t = this.player.videoManifest.metadata.preview;
if (!t || t == null) throw Error("Invalid video manifest data: preview image is required");
if (this._previewImage = await Ie(t), this._imageContainer = document.createElement("div"), this._imageContainer.className = "image-container", this.parent && (this.parent.appendChild(this._imageContainer), this._imageContainer.appendChild(this._previewImage)), this._source = e.sources.audio?.[0], !this._source) throw Error("Invalid source in audio only video stream");
if (!this.isMainAudioPlayer) throw Error("Audio only video stream must be main audio player. Check the role property at video manifest");
await Le(this.player, this.audio, this._source.src);
let n = () => {
!this.player.videoContainer?.baseVideoRect.offsetWidth || !this.player.videoContainer?.baseVideoRect.offsetHeight || (this.player.videoContainer?.baseVideoRect.offsetWidth / this.player.videoContainer?.baseVideoRect.offsetHeight > this._previewImage.width / this._previewImage.height ? (this._previewImage.classList.add("landscape"), this._previewImage.classList.remove("portrait")) : (this._previewImage.classList.add("portrait"), this._previewImage.classList.remove("landscape")));
};
return this.player.frameList.frames.length > 0 && this.audio.addEventListener("timeupdate", (e) => {
let t = this.player.frameList.getImage(e.target.currentTime, !0);
this._previewImage.src != t.url && (this._previewImage.src = t.url, this._previewImage.onload = () => n());
}), window.addEventListener("resize", (e) => n()), n(), this._ready = !0, !0;
}
}, ze = class extends k {
getPluginModuleInstance() {
return Fe.Get();
}
get name() {
return "es.upv.paella.audioVideoFormat";
}
get streamType() {
return "audio";
}
async isCompatible(e) {
return e.sources.audio != null;
}
async getVideoInstance(e, t) {
return new Re(this.player, e, t);
}
getCompatibleFileExtensions() {
return ["m4a", "mp3"];
}
getManifestData(e) {
return { audio: e.map((e) => ({ src: e })) };
}
}, Be = class extends A {
constructor(e, t, n, r) {
super("video", e, t), this._config = r || {};
let i = this._config.crossOrigin ?? "";
this.element.setAttribute("playsinline", ""), i !== !1 && this.element.setAttribute("crossorigin", i), this.isMainAudio = n, this.element.setAttribute("autoplay", ""), this.element.autoplay = !0, n || (this.element.muted = !0), this._videoEnabled = !0;
}
async play() {
if (this._videoEnabled) try {
return await this.waitForLoaded(), await this.video.play(), !0;
} catch {
return !1;
}
else return this._disabledProperties.paused = !1, !0;
}
async pause() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.pause(), !0) : (this._disabledProperties.paused = !0, !0);
}
async duration() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.duration) : this._disabledProperties.duration;
}
get currentTimeSync() {
return this._videoEnabled ? this.ready ? this.video.currentTime : -1 : this._disabledProperties.currentTime;
}
async currentTime() {
return this._videoEnabled ? (await this.waitForLoaded(), this.currentTimeSync) : this._disabledProperties.currentTime;
}
async setCurrentTime(e) {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.currentTime = e, !0) : (this._disabledProperties.currentTime = e, !0);
}
async volume() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.volume) : this._disabledProperties.volume;
}
async setVolume(e) {
return this._videoEnabled ? (await this.waitForLoaded(), e === 0 ? this.video.setAttribute("muted", "") : this.video.removeAttribute("muted"), this.video.volume = e, !0) : (this._disabledProperties.volume = e, !0);
}
async paused() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.paused) : this._disabledProperties.paused;
}
async playbackRate() {
return this._videoEnabled ? (await this.waitForLoaded(), await this.video.playbackRate) : this._disabledProperties.playbackRate;
}
async setPlaybackRate(e) {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.playbackRate = e, !0) : (this._disabledProperties.playbackRate = e, !0);
}
async getQualities() {
return [];
}
async setQuality(e) {
return !1;
}
get currentQuality() {
return null;
}
async getDimensions() {
return this._videoEnabled ? (await this.waitForLoaded(), {
w: this.video.videoWidth,
h: this.video.videoHeight
}) : {
w: this._disabledProperties.videoWidth,
h: this._disabledProperties.videoHeight
};
}
saveDisabledProperties(e) {
this._disabledProperties = {
duration: e.duration,
volume: e.volume,
videoWidth: e.videoWidth,
videoHeight: e.videoHeight,
playbackRate: e.playbackRate,
paused: e.paused,
currentTime: e.currentTime
};
}
async loadStreamData(e = null) {
this._streamData = this._streamData || e, this.player.log.debug("es.upv.paella.htmlVideoFormat: loadStreamData"), this._sources = e.sources.html, this._currentQuality = 0, this.isMainAudioPlayer || (this.video.muted = !0), this._sources.forEach(({ src: e, mimetype: t }) => {
e = v(this.player, e);
let n = document.createElement("source");
n.src = e, n.type = t, this.video.appendChild(n);
}), this._endedCallback = this._endedCallback || (() => {
typeof this._videoEndedCallback == "function" && this._videoEndedCallback();
}), this.video.addEventListener("ended", this._endedCallback);
try {
await this.video.play();
} catch {}
return await this.waitForLoaded(), this.player.log.debug(`es.upv.paella.htmlVideoFormat (${this.streamData.content}): video loaded and ready.`), this.saveDisabledProperties(this.video), !0;
}
async clearStreamData() {
this.video.src = "", this._endedCallback && this.video.removeEventListener("ended", this._endedCallback), this._handleLoadedCallback && this.video.removeEventListener("loadeddata", this._handleLoadedCallback), this._ready = !1;
}
get isEnabled() {
return this._videoEnabled;
}
async enable() {
this._videoEnabled = !0;
}
async disable() {
this.isMainAudio ? this.player.log.debug("video.disable() - the video is not disabled because it is the main audio source.") : this._videoEnabled = !1;
}
waitForLoaded() {
return new Promise((e, t) => {
this.video.readyState >= 2 && (this._ready = !0), this.ready ? e() : (this._handleLoadedCallback = (t) => {
this.video.readyState >= 2 && (this.video.pause(), this._ready = !0, e());
}, this.video.addEventListener("loadeddata", this._handleLoadedCallback));
});
}
}, Ve = class extends k {
getPluginModuleInstance() {
return Fe.Get();
}
get name() {
return "es.upv.paella.htmlVideoFormat";
}
get streamType() {
return "html";
}
async isCompatible(e) {
let { html: t } = e.sources;
return t != null && t.some((e) => fe(e.mimetype));
}
async getVideoInstance(e, t) {
return new Be(this.player, e, t, this.config);
}
getCompatibleFileExtensions() {
return [
"m4v",
"mp4",
"ogg",
"webm",
"ogv"
];
}
getManifestData(e) {
let t = (e) => {
switch (ee(e)) {
case "mp4":
case "m4v": return "video/mp4";
case "webm": return "video/webm";
case "ogg":
case "ogv": return "video/ogg";
default: return null;
}
};
return { html: e.map((e) => ({
src: e,
mimetype: t(e)
})) };
}
}, He = class {
constructor({ label: e, shortLabel: t, isAuto: n = !1, index: r = 0, src: i = "", width: a = -1, height: o = -1, bitrate: s = -1 }) {
this._label = e, this._shortLabel = t, this._index = r, this._src = i, this._res = {
w: a,
h: o
}, this._bitrate = s, this._isAuto = n;
}
get label() {
return this._label;
}
get shortLabel() {
return this._shortLabel;
}
get index() {
return this._index;
}
get src() {
return this._src;
}
get res() {
return this._res;
}
get bitrate() {
return this._bitrate;
}
get isAuto() {
return this._isAuto;
}
get quality() {
return this._res.w !== -1 && this._res.h !== -1 ? this._res.w * this._res.h : this._bitrate;
}
compare(e) {
return e.quality - this.quality;
}
};
//#endregion
//#region src/js/videoFormats/es.upv.paella.imageVideoFormat.ts
function Ue(e) {
let t = this._currentSource.frames[0];
this._currentSource.frames.some((e) => {
if (e.time <= this._currentTime) t = e;
else return !0;
}), this.img.src = t.src;
}
function We() {
this._startTimestamp = Date.now();
let e = () => {
this._timer = setTimeout(e, 250);
let t = Date.now(), n = t - this._startTimestamp;
this._currentTime += n / 1e3, this._startTimestamp = t, Ue.apply(this, [this._currentTime]);
};
e();
}
function Ge() {
this._timer !== null && (clearTimeout(this._timer), this._timer = null);
}
var Ke = class extends A {
constructor(e, t) {
super("img", e, t), this._currentTime = 0, this._startTimestamp = 0, this._playbackRate = 1, this._timer = null, this.video = this.element;
}
async play() {
return We.apply(this), !0;
}
async pause() {
return Ge.apply(this), !0;
}
async duration() {
return this._currentSource.duration;
}
get currentTimeSync() {
return this._currentTime;
}
async currentTime() {
return this._currentTime;
}
async setCurrentTime(e) {
return this._currentTime = e, Ue.apply(this, [e]), !0;
}
async volume() {
return 0;
}
async setVolume(e) {
return !0;
}
async paused() {
return this._timer === null;
}
async playbackRate() {
return this._playbackRate;
}
async setPlaybackRate(e) {
return this._playbackRate = e, !0;
}
async getQualities() {
return this._qualities;
}
async setQuality(e) {
return !1;
}
get currentQuality() {
return this._qualities[this._currentQuality];
}
async getDimensions() {
return {
w: this._currentSource.res.w,
h: this._currentSource.res.h
};
}
async loadStreamData(e) {
return this._sources = e.sources.image, this._qualities = this._sources.map((e) => new He({
src: e.frames[0].src,
label: `${e.res.w}x${e.res.h}`,
shortLabel: `${e.res.h}p`,
width: e.res.w,
height: e.res.h
})), this._currentQuality = this._qualities.length - 1, this._qualities.forEach((e, t) => {
this._qualities[this._currentQuality].compare(e) > 0 && (this._currentQuality = t);
}), this._currentSource = this._sources[this._currentQuality], this._sources.forEach((e) => {
e.frames.sort((e, t) => e.time - t.time);
}), !0;
}
}, qe = class extends k {
getPluginModuleInstance() {
return Fe.Get();
}
get name() {
return "es.upv.paella.imageVideoFormat";
}
get streamType() {
return "image";
}
async isCompatible(e) {
return e.sources.image != null;
}
async getVideoInstance(e, t) {
return new Ke(this.player, e);
}
}, Je = class extends A {
constructor(e, t, n, r) {
super("video", e, t), this._config = r || {};
let i = this._config.crossOrigin ?? "";
this.element.setAttribute("playsinline", ""), i !== !1 && this.element.setAttribute("crossorigin", i), this.isMainAudio = n, this.element.setAttribute("autoplay", ""), this.element.autoplay = !0, n || (this.element.muted = !0), this._videoEnabled = !0;
}
async play() {
if (this._videoEnabled) try {
return await this.waitForLoaded(), await this.video.play(), !0;
} catch {
return !1;
}
else return this._disabledProperties.paused = !1, !0;
}
async pause() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.pause(), !0) : (this._disabledProperties.paused = !0, !0);
}
async duration() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.duration) : this._disabledProperties.duration;
}
get currentTimeSync() {
return this._videoEnabled ? this.ready ? this.video.currentTime : -1 : this._disabledProperties.currentTime;
}
async currentTime() {
return this._videoEnabled ? (await this.waitForLoaded(), this.currentTimeSync) : this._disabledProperties.currentTime;
}
async setCurrentTime(e) {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.currentTime = e, !0) : (this._disabledProperties.currentTime = e, !0);
}
async volume() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.volume) : this._disabledProperties.volume;
}
async setVolume(e) {
return this._videoEnabled ? (await this.waitForLoaded(), e === 0 ? this.video.setAttribute("muted", "") : this.video.removeAttribute("muted"), this.video.volume = e, !0) : (this._disabledProperties.volume = e, !0);
}
async paused() {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.paused) : this._disabledProperties.paused;
}
async playbackRate() {
return this._videoEnabled ? (await this.waitForLoaded(), await this.video.playbackRate) : this._disabledProperties.playbackRate;
}
async setPlaybackRate(e) {
return this._videoEnabled ? (await this.waitForLoaded(), this.video.playbackRate = e, !0) : (this._disabledProperties.playbackRate = e, !0);
}
async getQualities() {
return [];
}
async setQuality(e) {
return !1;
}
get currentQuality() {
return null;
}
async getDimensions() {
return this._videoEnabled ? (await this.waitForLoaded(), {
w: this.video.videoWidth,
h: this.video.videoHeight
}) : {
w: this._disabledProperties.videoWidth,
h: this._disabledProperties.videoHeight
};
}
saveDisabledProperties(e) {
this._disabledProperties = {
duration: e.duration,
volume: e.volume,
videoWidth: e.videoWidth,
videoHeight: e.videoHeight,
playbackRate: e.playbackRate,
paused: e.paused,
currentTime: e.currentTime
};
}
async loadStreamData(e = null) {
this._streamData = this._streamData || e, this.player.log.debug("es.upv.paella.mp4VideoFormat: loadStreamData"), this._currentSource ||= (this._sources = e.sources.mp4, this._sources.sort((e, t) => Number(e.res.w) - Number(t.res.w)), this._currentQuality = this._sources.length - 1, this._sources[this._currentQuality]), this.isMainAudioPlayer || (this.video.muted = !0), this._initialVolume && (this.video.volume = this._initialVolume, this._initialVolume === 0 && (this.video.muted = !0)), this.video.src = v(this.player, this._currentSource.src), this._endedCallback = this._endedCallback || (() => {
typeof this._videoEndedCallback == "function" && this._videoEndedCallback();
}), this.video.addEventListener("ended", this._endedCallback);
try {
await this.video.play();
} catch {}
return await this.waitForLoaded(), this.player.log.debug(`es.upv.paella.mp4VideoFormat (${this.streamData.content}): video loaded and ready.`), this.saveDisabledProperties(this.video), !0;
}
async clearStreamData() {
this.video.src = "", this._endedCallback && this.video.removeEventListener("ended", this._endedCallback), this._handleLoadedCallback && this.video.removeEventListener("loadeddata", this._handleLoadedCallback), this._ready = !1;
}
get isEnabled() {
return this._videoEnabled;
}
async enable() {
this._videoEnabled = !0;
}
async disable() {
this.isMainAudio ? this.player.log.debug("video.disable() - the video is not disabled because it is the main audio source.") : this._videoEnabled = !1;
}
waitForLoaded() {
return new Promise((e, t) => {
this.video.readyState >= 2 && (this._ready = !0), this.ready ? e() : (this._handleLoadedCallback = (t) => {
this.video.readyState >= 2 && (this.video.pause(), this._ready = !0, e());
}, this.video.addEventListener("loadeddata", this._handleLoadedCallback));
});
}
}, Ye = class extends k {
getPluginModuleInstance() {
return Fe.Get();
}
get name() {
return "es.upv.paella.mp4VideoFormat";
}
get streamType() {
return "mp4";
}
async isCompatible(e) {
let { mp4: t } = e.sources;
return t != null && t[0]?.mimetype && fe(t[0].mimetype);
}
async getVideoInstance(e, t) {
return new Je(this.player, e, t, this.config);
}
getCompatibleFileExtensions() {
return ["m4v", "mp4"];
}
getManifestData(e) {
return { mp4: e.map((e) => ({
src: e,
mimetype: "video/mp4",
res: {
w: 0,
h: 0
}
})) };
}
};
//#endregion
//#region src/js/captions/CaptionsPlugin.ts
async function Xe(e) {
let t = [];
await U(e, "captions", async (e) => {
t.push(e);
});
for (let n in t) {
let r = t[n];
if (r.type === "captions") {
let t = await r.getCaptions(), n = e.captionsCanvas;
t.forEach((e) => n?.addCaptions(e));
}
}
}
var Ze = class extends O {
get type() {
return "captions";
}
async load() {
this.player.log.debug("load captions plugin");
}
async getCaptions() {
return this.player.log.warn(`CaptionsPlugin ${this.name}: getCaptions() is not implemented.`), [];
}
}, Qe = class {
get cues() {
return this._cues;
}
get label() {
return this._label;
}
get language() {
return this._lang;
}
set label(e) {
this._label = e;
}
set language(e) {
this._lang = e;
}
constructor(e = "", t = "") {
this._cues = [], this._label = e, this._lang = t;
}
addCue({ label: e = "", start: t, end: n, captions: r }) {
let i = {
label: e,
start: 0,
end: 0,
captions: []
};
if (typeof r == "string") i.captions = [r];
else if (Array.isArray(r)) i.captions = r;
else throw Error("Invalid cue caption format: must be an array of strings or a string");
if (typeof t == "string") i.start = x(t) || 0, i.startString = t;
else if (typeof t == "number") i.start = t, i.startString = b(t);
else throw Error("Invalid cue timestamp format: must be a valid time string or a number of seconds");
if (typeof n == "string") i.end = x(n) || 0, i.endString = n;
else if (typeof n == "number") i.end = n, i.endString = b(n);
else throw Error("Invalid cue timestamp format: must be a valid time string or a number of seconds");
return this._cues.push(i), i;
}
getCue(e) {
if (typeof e == "string") e = x(e) || 0;
else if (typeof e != "number") throw Error("Invalid time instant format getting cue");
let t = null;
return this._cues.some((n) => {
if (e >= n.start && e <= n.end) return t = n, !0;
}), t;
}
};
//#endregion
//#region src/js/captions/DFXPParser.ts
function $e(e, t) {
let n = {}, r = new DOMParser().parseFromString(t, "text/xml");
return Array.from(r.getElementsByTagName("div")).forEach((t) => {
let r = t.getAttribute("xml:lang") || "unknonw";
n[r] = n[r] || new Qe(e.translate(r), r), Array.from(t.getElementsByTagName("p")).forEach((e) => {
let t = ie(e.getAttribute("begin") || "0s") ?? 0;
n[r].addCue({
label: `caption_${e.getAttribute("xml:id") || t}`,
start: t / 1e3,
end: (ie(e.getAttribute("end") || "0s") ?? 0) / 1e3,
captions: [e.textContent || ""]
});
});
}), n;
}
var et = class {
constructor(e, t = "") {
this.player = e, this._text = t, this._captions = $e(this.player, t);
}
get text() {
return this._text;
}
set text(e) {
this._text = e, this._captions = $e(this.player, e);
}
get captions() {
return this._captions;
}
}, tt = null, N = class e extends j {
static Get() {
return tt ||= new e(), tt;
}
get moduleName() {
return "paella-core default plugins";
}
get moduleVersion() {
return M.version;
}
async getDictionaries() {
return {
es: {
"playPauseButtonHelp.title": "Ayuda del botón de reproducción/pausa",
"playPauseButtonHelp.description": "Este botón permite reproducir o pausar el video."
},
en: {
"playPauseButtonHelp.title": "Play/Pause button help",
"playPauseButtonHelp.description": "This button allows you to play or pause the video."
}
};
}
}, nt = class extends Ze {
getPluginModuleInstance() {
return N.Get();
}
get name() {
return "es.upv.paella.dfxpManifestCaptionsPlugin";
}
async isEnabled() {
return await super.isEnabled() && this.player.videoManifest.captions && this.player.videoManifest.captions.length > 0;
}
async getCaptions() {
let e = [], t = [];
return (this.player.videoManifest.captions || []).forEach((n) => {
t.push((async () => {
if (!/dfxp/i.test(n.format)) return;
let t = v(this.player, n.url), r = await fetch(t);
if (!r.ok) return;
let i = await r.text();
i = i.replace(/[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, ""), i = i.replace(/&\w+;/gim, ""), i = i.replace(/<br>/g, "");
let a = new et(this.player, i);
Object.entries(a.captions).forEach(([, t]) => {
e.push(t);
});
})());
}), await Promise.allSettled(t), e;
}
}, rt = class extends O {
constructor(e, t) {
super(e, t), this.__uiPlugin = !0;
}
async getDictionaries() {
return null;
}
async getHelp() {
return null;
}
async getTranslatedHelp() {
let e = await this.getHelp();
return e ? {
title: this.player.translate(e.title),
description: this.player.translate(e.description)
} : null;
}
onResize({ width: e, height: t }) {}
get hidden() {
return !1;
}
};
//#endregion
//#region src/js/core/ButtonPlugin.ts
async function P(e, t) {
return await F.AddButtonPlugin(e, t);
}
var it = () => {
let e = document.createElement("span");
return e.classList.add("side-container"), e.classList.add("hidden"), e;
}, at = class {
onIconChanged(e, t, n) {}
onTitleChanged(e, t, n) {}
onStateChanged(e, t, n, r, i) {}
}, F = class extends rt {
constructor(...e) {
super(...e), this._button = null, this._container = null, this._isAnchor = !1, this._observer = null, this._menuIcon = "", this._icon = "", this._title = "", this._statusText = null, this._statusIcon = null, this._enabled = !0, this.#t = null, this.#n = null, this.#r = [];
}
static async AddButtonPlugin(e, t) {
e._isAnchor = await e.getAnchorUrl() !== null;
let r = E("<li></li>", t);
r.plugin = e;
let a = e.ariaLabel, o = e.description, s = e.dynamicWidth ? "dynamic-width" : "fixed-width", c = e.id ? `id="${e.id}" ` : "", l = e.buttonName ? `name="${e.buttonName}" ` : `name="${e.name}" `, u = e.tabIndex ? ` tabindex="${e.tabIndex}" ` : "";
if (e.interactive) {
let t = e.anchorTarget === null ? "" : `target="${e.anchorTarget}" `, d = e.anchorDownloadFilename === null ? "" : `download="${e.anchorDownloadFilename}" `, f = e.anchorReferrerPolicy === null ? "" : `referrerpolicy="${e.anchorReferrerPolicy}" `, p = e.isAnchor ? E(`
<a href="${await e.getAnchorUrl()}" ${c}${l}class="${s}"${u}aria-label="${a}" title="${o}" ${t}${d}${f}>
</a>
`, r) : E(`
<button type="button" ${c}${l}class="${s}"${u}aria-label="${a}" title="${o}">
</button>
`, r);
e.className !== "" && p.classList.add(e.className), e._button = p, e._container = r, p._pluginData = e, r._pluginData = e, p.addEventListener("click", (e) => {
let t = p._pluginData;
i(t.player, n.BUTTON_PRESS, { plugin: t }), t.action(e, null), e.stopPropagation(), e.pageX !== 0 && e.pageY !== 0 && document.activeElement?.blur();
});
let m = null, h = () => {
m &&= (clearTimeout(m), null);
}, g = () => {
h(), m = setTimeout(() => {
e.leftSideContainerPresent && e.leftSideContainer?.classList.add("hidden"), e.rightSideContainerPresent && e.rightSideContainer?.classList.add("hidden"), m = null;
}, 300);
}, _ = () => {
h(), e.leftSideContainerPresent && e.leftSideContainer.classList.remove("hidden"), e.rightSideContainerPresent && e.rightSideContainer.classList.remove("hidden");
};
p.addEventListener("focus", _), p.addEventListener("mouseover", _), p.addEventListener("mouseout", g), p.addEventListener("blur", g), e.player.config.accessibility?.clickWithSpacebar === void 0 || e.player.config.accessibility?.clickWithSpacebar || (p.addEventListener("keyup", (e) => {
e.keyCode == 32 && e.preventDefault();
}), p.addEventListener("keydown", (e) => {
e.keyCode == 32 && e.preventDefault();
})), e.className !== "" && p.classList.add(e.className);
} else {
let t = E(`
<div ${c}${l} class="non-interactive ${s}" title="${o}">
</div>
`, r);
e._button = t, e._container = r, t._pluginData = e, r._pluginData = e, e.className !== "" && t.classList.add(e.className);
}
}
get type() {
return "button";
}
get container() {
return this._container;
}
get button() {
return this._button;
}
get interactive() {
return !0;
}
get dynamicWidth() {
return !1;
}
getId() {
return null;
}
get id() {
return this.config.id || this.getId();
}
getButtonName() {
return null;
}
get buttonName() {
return this.config.name || this.getButtonName() || this.name;
}
getAriaLabel() {
return "";
}
get ariaLabel() {
return this.player.translate(this.config.ariaLabel || this.getAriaLabel());
}
getTabIndex() {
return null;
}
get tabIndex() {
return this.config.tabIndex || this.getTabIndex();
}
getDescription() {
return "";
}
get description() {
return this.player.translate(this.config.description || this.getDescription());
}
get minContainerSize() {
return this.config.minContainerSize || this.getMinContainerSize();
}
getMinContainerSize() {
return 0;
}
setObserver(e) {
if (e instanceof at) this._observer = e;
else if (typeof e.onIconChanged == "function" || typeof e.onTitleChanged == "function" || typeof e.onStateChanged == "function") this._observer = e;
else throw Error("Invalid observer for ButtonPlugin");
}
#e() {
let e = this._button, t = this._menuIcon, n = this._icon, r = this.isMenuButton ? t : n, i = this._observer, a = this.isMenuButton && this.haveMenuIcon ? this.menuIcon : this.icon;
if (a && e instanceof HTMLElement) {
let t = e.querySelector("i") || E("<i></i>", e);
t.innerHTML = a;
} else if (e instanceof HTMLElement) {
let t = e.querySelector("i");
t && e.removeChild(t);
}
i?.onIconChanged && i.onIconChanged(this, r, a);
}
get icon() {
return this._icon ||= "", this._icon;
}
set icon(e) {
this._icon = e, this.#e();
}
get haveIcon() {
return this.icon !== "";
}
get menuIcon() {
return this._menuIcon ||= "", this._menuIcon;
}
set menuIcon(e) {
this._menuIcon = e, this.#e();
}
get haveMenuIcon() {
return this.menuIcon !== "";
}
get isMenuButton() {
let e = this.config?.parentContainer === "playbackBar" || !this.config?.parentContainer, t = this.config?.parentContainer === "videoContainer";
return !e && !t;
}
get title() {
return this._title || "";
}
set title(e) {
let t = this._button;
if (e && t instanceof HTMLElement) {
let n = t.querySelector("span") || E(`<span class="button-title-${this.titleSize}"></span>`, t);
n.innerHTML = e;
} else if (t instanceof HTMLElement) {
let e = t.querySelector("span");
e && t.removeChild(e);
}
this._observer?.onTitleChanged && this._observer.onTitleChanged(this, this._title, e), this._title = e;
}
get titleSize() {
return "medium";
}
get side() {
return this.config?.side || "left";
}
get closePopUps() {
return this.config.closePopUps || this.getClosePopUps();
}
getClosePopUps() {
return !0;
}
get parentContainer() {
return this.config?.parentContainer || "playbackBar";
}
get className() {
return "";
}