From 362c6169987bb32c120e81ea267eeaa3bd8f63b8 Mon Sep 17 00:00:00 2001 From: Harvey Zhao Date: Fri, 11 Sep 2026 00:03:53 +0800 Subject: [PATCH] refactor(core): CORE-02 type emitter maps and fix nested once dispatch --- docs/compiled/artplayer.js | 2 +- docs/compiled/artplayer.legacy.js | 2 +- docs/compiled/artplayer.mjs | 29 +- packages/artplayer/ARCHITECTURE.md | 33 +- packages/artplayer/dist/artplayer.js | 2 +- packages/artplayer/dist/artplayer.legacy.js | 2 +- packages/artplayer/dist/artplayer.mjs | 29 +- packages/artplayer/src/utils/emitter.js | 44 -- packages/artplayer/src/utils/emitter.ts | 69 +++ refactor/baselines/emitter-validation.json | 548 ++++++++++++++++++ .../2026-09-11-CORE-02-typed-emitter.md | 36 ++ refactor/plan.md | 5 +- refactor/progress.md | 4 + refactor/risk-table.md | 2 + refactor/risks.json | 48 +- refactor/tasks.json | 7 +- test/browser/emitter.spec.js | 28 + test/contracts/emitter.js | 45 ++ test/package-check.test.js | 3 +- test/public-behavior.test.js | 35 ++ test/types/emitter-source.ts | 42 ++ 21 files changed, 943 insertions(+), 72 deletions(-) delete mode 100644 packages/artplayer/src/utils/emitter.js create mode 100644 packages/artplayer/src/utils/emitter.ts create mode 100644 refactor/baselines/emitter-validation.json create mode 100644 refactor/changes/2026-09-11-CORE-02-typed-emitter.md create mode 100644 test/browser/emitter.spec.js create mode 100644 test/types/emitter-source.ts diff --git a/docs/compiled/artplayer.js b/docs/compiled/artplayer.js index bb14495c1..542812ec5 100644 --- a/docs/compiled/artplayer.js +++ b/docs/compiled/artplayer.js @@ -4,4 +4,4 @@ * (c) 2017-2026 Harvey Zhao * Released under the MIT License. */ -!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2=1,p=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(s)||d,h="undefined"!==typeof window&&"undefined"!==typeof document;function u(t,e=document){return e.querySelector(t)}function m(t,e=document){return Array.from(e.querySelectorAll(t))}function f(t,e){return t.classList.add(e)}function g(t,e){return t.classList.remove(e)}function v(t,e){return t.classList.contains(e)}function y(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function b(t){return t.parentNode.removeChild(t)}function w(t,e,r){return t.style[e]=r,t}function x(t,e){for(const r in e)w(t,r,e[r]);return t}function k(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function $(t,e){k(t).forEach(t=>g(t,e)),f(t,e)}function T(t,e,r="top"){p||(t.setAttribute("aria-label",e),f(t,"hint--rounded"),f(t,`hint--${r}`))}function E(t,e=0){const r=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=a&&r.top+r.height+e>=0,i=r.left-e<=o+e&&r.left+r.width+e>=0;return n&&i}function C(t,e){return R(t).includes(e)}function z(t,e){return e.parentNode.replaceChild(t,e),t}function L(t){return document.createElement(t)}function S(t="",e=""){const r=L("i");return f(r,"art-icon"),f(r,`art-icon-${t}`),y(r,e),r}function M(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function I(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function A(t){return t.getBoundingClientRect()}function P(t,e){return new Promise((r,a)=>{const o=new Image;o.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=o.width*e,n.height=o.height*e,i.drawImage(o,0,0,n.width,n.height),n.toBlob(e=>{const o=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(o),a(new Error(`Image load failed: ${t}`))},n.src=o})}else r(o)},o.onerror=function(){a(new Error(`Image load failed: ${t}`))},o.src=t})}function R(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function O(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class _ extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function V(t,e){if(!t)throw new _(e);return t}function Y(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function N(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function D(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function F(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function B(t){return t.charAt(0).toUpperCase()+t.slice(1)}function H(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),a=Math.floor(t-3600*e-60*r);return(e>0?[e,r,a]:[r,a]).map(t=>t<10?`0${t}`:String(t)).join(":")}const W={"&":"&","<":"<",">":">","'":"'",'"':"""},j={"&":"&","<":"<",">":">","'":"'",""":'"'},U=/(&|<|>|'|")/g;function q(t){return t.replace(/[&<>'"]/g,t=>W[t]||t)}const X=Object.defineProperty,{hasOwnProperty:G}=Object.prototype;function K(t,e){return G.call(t,e)}function Z(t,e){return Object.getOwnPropertyDescriptor(t,e)}function J(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(a=>{const o=t[a],n=r[a];let i;i=Array.isArray(o)&&Array.isArray(n)?o.concat(...n):e(o)&&e(n)?J(o,n):n,X(t,a,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function Q(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let a=r.slice(0,3);return 1===r.length&&(a=`${r}00`),2===r.length&&(a=`${r}0`),`${e},${a}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function tt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function et(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const a=t.match(e);if(!a)return null;const[,o="",n="",,,i=""]=a;return{start:r(o.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function rt(t=0){return new Promise(e=>setTimeout(e,t))}function at(t,e){let r;return function(...a){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,a)),e)}}function ot(t,e){let r=!1;return function(...a){r||(t.apply(this,a),r=!0,setTimeout(()=>{r=!1},e))}}const nt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:_,addClass:f,append:y,assToVtt:et,capitalize:B,clamp:F,createElement:L,debounce:at,def:X,download:D,errorHandle:V,escape:q,get:Z,getComposedPath:R,getExt:N,getIcon:S,getRect:A,getSafeAreaInsets:O,getStyle:function(t,e,r=!0){const a=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(a):a},has:K,hasClass:v,includeFromEvent:C,inverseClass:$,isBrowser:h,isIOS:c,isIOS13:d,isInViewport:E,isMobile:p,isSafari:l,loadImg:P,mergeDeep:J,query:u,queryAll:m,remove:b,removeClass:g,replaceElement:z,secondToTime:H,setStyle:w,setStyleText:M,setStyles:x,siblings:k,silencePromise:Y,sleep:rt,srtToVtt:Q,supportsFlex:I,throttle:ot,tooltip:T,unescape:function(t){return t.replace(U,t=>j[t]||t)},userAgent:s,vttToBlob:tt},Symbol.toStringTag,{value:"Module"})),it="array",st="boolean",lt="string",ct="number",dt="object",pt="function";function ht(t,e,r){return V(e===lt||e===ct||t instanceof Element,`${r.join(".")} require '${lt}' or 'Element' type`)}const ut={html:ht,disable:`?${st}`,name:`?${lt}`,index:`?${ct}`,style:`?${dt}`,click:`?${pt}`,mounted:`?${pt}`,tooltip:`?${lt}|${ct}`,width:`?${ct}`,selector:`?${it}`,onSelect:`?${pt}`,switch:`?${st}`,onSwitch:`?${pt}`,range:`?${it}`,onRange:`?${pt}`,onChange:`?${pt}`},mt={id:lt,container:ht,url:lt,poster:lt,type:lt,theme:lt,lang:lt,volume:ct,isLive:st,muted:st,autoplay:st,autoSize:st,autoMini:st,loop:st,flip:st,playbackRate:st,aspectRatio:st,screenshot:st,setting:st,hotkey:st,pip:st,mutex:st,backdrop:st,fullscreen:st,fullscreenWeb:st,subtitleOffset:st,miniProgressBar:st,useSSR:st,playsInline:st,lock:st,gesture:st,fastForward:st,autoPlayback:st,autoOrientation:st,airplay:st,proxy:`?${pt}`,plugins:[pt],layers:[ut],contextmenu:[ut],settings:[ut],controls:[{...ut,position:(t,e,r)=>{const a=["top","left","right"];return V(a.includes(t),`${r.join(".")} only accept ${a.toString()} as parameters`)}}],quality:[{default:`?${st}`,html:lt,url:lt}],highlight:[{time:ct,text:lt}],thumbnails:{url:lt,number:ct,column:ct,width:ct,height:ct,scale:ct},subtitle:{url:lt,name:lt,type:lt,style:dt,escape:st,encoding:lt,onVttLoad:pt},moreVideoAttr:dt,i18n:dt,icons:dt,cssVar:dt,customType:dt};class ft{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return v(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?f(e,r):g(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",o(e,ut),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;V(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const a=L("div");f(a,`art-${this.name}`),f(a,`art-${this.name}-${r}`);const n=Array.from(this.$parent.children);a.dataset.index=e.index||this.id;const i=n.find(t=>Number(t.dataset.index)>=Number(a.dataset.index));i?i.insertAdjacentElement("beforebegin",a):y(this.$parent,a),e.html&&y(a,e.html),e.style&&x(a,e.style),e.tooltip&&T(a,e.tooltip);const s=[];if(e.click){const t=this.art.events.proxy(a,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});s.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,a,s),this[r]=a,this.cache.set(r,{$ref:a,events:s,option:e}),e.mounted&&e.mounted.call(this.art,a),a}remove(t){V(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],b(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class gt extends ft{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,p||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:a}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:a}}=e,o=a.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return{...t,html:`${r.get("Play Speed")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.playbackRate=Number(a),t.show=!1)},mounted:t=>{const r=u('[data-value="1"]',t);r&&$(r,"art-current"),e.on("video:ratechange",()=>{const r=m("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&$(r,"art-current")})}}}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:a}}=e,o=a.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return{...t,html:`${r.get("Aspect Ratio")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.aspectRatio=a,t.show=!1)},mounted:t=>{const r=u('[data-value="default"]',t);r&&$(r,"art-current"),e.on("aspectRatio",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:a}}=e,o=a.map(t=>`${r.get(B(t))}`).join("");return{...t,html:`${r.get("Video Flip")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.flip=a.toLowerCase(),t.show=!1)},mounted:t=>{const r=u('[data-value="normal"]',t);r&&$(r,"art-current"),e.on("flip",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"flip",index:30})),this.add(function(t){return e=>({...t,html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return{...t,html:`ArtPlayer ${n}`}}({name:"version",index:50})),this.add(function(t){return e=>({...t,html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let o=0;o{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,o=t.clientY,{height:n,width:i,left:s,top:l}=A(r),{height:c,width:d}=A(a);let p=e-s,h=o-l;e+d>s+i&&(p=i-d),o+c>l+n&&(h=n-c),x(a,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{C(t,a)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function vt(t,e){const{$progress:r}=t.template,{left:a}=A(r),o=F((p?e.touches[0].clientX:e.clientX)-a,0,r.clientWidth),n=o/r.clientWidth*t.duration;return{second:n,time:H(n),width:o,percentage:F(o/r.clientWidth,0,1)}}function yt(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,a=r*t.duration;t.emit("setBar","played",r,e),t.seek=a}else{const{second:r,percentage:a}=vt(t,e);t.emit("setBar","played",a,e),t.seek=r}}function bt(t){return e=>{const{icons:r,option:a,proxy:o}=e,{$player:n,$progress:i}=e.template;return{...t,html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=u(".art-progress-hover",t),d=u(".art-progress-loaded",t),h=u(".art-progress-played",t),m=u(".art-progress-highlight",t),v=u(".art-progress-indicator",t),b=u(".art-progress-tip",t);function x(r,a){const{width:o,time:n}=a||vt(e,r);b.textContent=n||"00:00";const i=b.clientWidth;o<=i/2?w(b,"left",0):o>t.clientWidth-i/2?w(b,"left",t.clientWidth-i+"px"):w(b,"left",o-i/2+"px")}r.indicator?y(v,r.indicator):w(v,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,a,o){const i="played"===r&&o&&p;if("loaded"===r&&w(d,"width",100*a+"%"),"hover"===r&&(w(c,"width",100*a+"%"),C(o,m)?function(r){const{width:a}=vt(e,r),{text:o}=r.target.dataset;b.textContent=o;const n=b.clientWidth;a<=n/2?w(b,"left",0):a>t.clientWidth-n/2?w(b,"left",t.clientWidth-n+"px"):w(b,"left",a-n/2+"px")}(o):x(o),0===a?g(n,"art-progress-hover"):f(n,"art-progress-hover")),"played"===r&&(w(h,"width",100*a+"%"),w(v,"left",100*a+"%")),i){f(n,"art-progress-hover");x(o,{width:t.clientWidth*a,time:H(a*e.duration)}),clearTimeout(s),s=setTimeout(()=>{g(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){m.textContent="";for(let t=0;t`;y(m,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),p||(o(i,"click",t=>{t.target!==v&&yt(e,t)}),o(i,"mousemove",t=>{const{percentage:r}=vt(e,t);e.emit("setBar","hover",r,t)}),o(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),o(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:a}=vt(e,t);e.emit("setBar","played",a,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}}}}class wt extends ft{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:a}=this.art.template;t.on("mousemove",()=>{p||(this.show=!0)}),t.on("click",()=>{p?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=C(t,a)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(g(r,"art-hide-cursor"),f(r,"art-hover"),this.timer=Date.now()):(f(r,"art-hide-cursor"),g(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(bt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.play),i=y(t,a.pause);function s(){w(n,"display","flex"),w(i,"display","none")}function l(){w(n,"display","none"),w(i,"display","flex")}T(n,o.get("Play")),T(i,o.get("Pause")),r(n,"click",()=>{Y(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a}=e,o=y(t,a.volume),n=y(t,a.volumeClose),i=y(t,'
'),s=y(i,'
'),l=y(s,'
'),c=y(s,'
'),d=y(c,'
'),h=y(d,'
'),u=y(c,'
');function m(t){const{top:e,height:r}=A(c);return 1-(t.clientY-e)/r}function f(){if(e.muted||0===e.volume)w(o,"display","none"),w(n,"display","flex"),w(u,"top","100%"),w(h,"top","100%"),l.textContent=0;else{const t=100*e.volume;w(o,"display","flex"),w(n,"display","none"),w(u,"top",100-t+"%"),w(h,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(f(),e.on("video:volumechange",f),r(o,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),p)w(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=m(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=m(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>({...t,style:p?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${H(e.currentTime)} / ${H(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const a=["video:loadedmetadata","video:timeupdate","video:progress"];for(let o=0;o{this.art.quality=t.quality}),t.screenshot&&!p&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{T(t,o.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{T(t,o.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenWebOn),i=y(t,a.fullscreenWebOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(T(t,o.get("Exit Web Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Web Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenOn),i=y(t,a.fullscreenOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(T(t,o.get("Exit Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),X(e,"$control_item",{get:()=>r}),X(e,"$control_value",{get:()=>o})}const i=a(n,"click",async e=>{const r=R(e),a=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(a),t.onSelect&&(o.innerHTML=await t.onSelect.call(this.art,a,a.$control_item,e))});r.push(i)}}function xt(t,e,r,a){const o=e-a,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(o)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,o);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class kt{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:a,$video:o}}=t;function n(e){C(e,a)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(o,"click",e=>{const a=Date.now();i.push(a);const{MOBILE_CLICK_PLAY:o,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>a-t<=n);switch(c.length){case 1:t.emit("click",e),p?!t.isLock&&o&&Y(t.toggle()):Y(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),p?!t.isLock&&s&&Y(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{f(r,"art-hover"),t.emit("hover",!0,e)},e=>{g(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:a}=t;t.on("resize",()=>{const{aspectRatio:e,notice:a}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,a.show=""});const o=at(()=>t.emit("resize"),a.RESIZE_TIME);t.on("window:orientationchange",()=>o()),t.on("window:resize",()=>o()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>o())}(t,this),function(t,e){if(p&&!t.option.isLive){const{$video:r,$progress:a}=t.template;let o=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){o===a&&yt(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:a,pageY:n}=e.touches[0],c=xt(i,s,a,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=F((a-i)/t.width,-1,1),d=F((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=o===r?t.constructor.TOUCH_MOVE_RATIO:1,u=F(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",F(u/t.duration,0,1),e),t.notice.show=`${H(u)} / ${H(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,o=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{o=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(a,"touchstart",t=>{o=a,c(t)}),e.proxy(a,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:a}}=t,o=ot(()=>{t.emit("view",E(a,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>o()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],a=["resize","scroll","orientationchange"],o=[];function n(n={}){for(let t=0;t{const a=n.document||i.ownerDocument||document,s=e.proxy(a,r,e=>{t.emit(`document:${r}`,e)});o.push(s)}),a.forEach(r=>{const a=n.window||i.ownerDocument?.defaultView||window,s=e.proxy(a,r,e=>{t.emit(`window:${r}`,e)});o.push(s)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,a={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,a));t.addEventListener(e,r,a);const o=()=>t.removeEventListener(e,r,a);return this.destroyEvents.add(o),o}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class $t{constructor(t){this.art=t,this.keys={},p||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{Y(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n',...t.option.icons};for(const r in e)X(this,r,{get:()=>S(r,e[r])})}}class zt extends ft{constructor(t){super(t),this.name="info",p||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:a,$video:o}}=this.art;t(a,"click",()=>{this.show=!1});let n=null;const i=m("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{w(o,"display","none"),w(n,"display",null)}),a.proxy(e.$state,"click",()=>Y(t.play()))}}class It{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:a}}=this.art;t?(a.textContent=t instanceof Error?t.message.trim():t,f(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{a.textContent="",g(r,"art-notice-show")},e.NOTICE_TIME)):g(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const At=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Pt=(()=>{if("undefined"===typeof document)return!1;const t=At[0],e={};for(const r of At){if(r[1]in document){for(const[a,o]of r.entries())e[t[a]]=o;return e}}return!1})(),Rt={change:Pt.fullscreenchange,error:Pt.fullscreenerror},Ot={request:(t=document.documentElement,e)=>new Promise((r,a)=>{const o=()=>{Ot.off("change",o),r()};Ot.on("change",o);const n=t[Pt.requestFullscreen](e);n instanceof Promise&&n.then(o).catch(a)}),exit:()=>new Promise((t,e)=>{if(!Ot.isFullscreen)return void t();const r=()=>{Ot.off("change",r),t()};Ot.on("change",r);const a=document[Pt.exitFullscreen]();a instanceof Promise&&a.then(r).catch(e)}),toggle:(t,e)=>Ot.isFullscreen?Ot.exit():Ot.request(t,e),onchange(t){Ot.on("change",t)},onerror(t){Ot.on("error",t)},on(t,e){const r=Rt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=Rt[t];r&&document.removeEventListener(r,e,!1)},raw:Pt};function _t(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;t.once("video:loadedmetadata",()=>{var n;Ot.isEnabled?(n=t,Ot.on("change",()=>{n.emit("fullscreen",Ot.isFullscreen),Ot.isFullscreen?(n.state="fullscreen",f(o,"art-fullscreen")):g(o,"art-fullscreen"),n.emit("resize")}),Ot.on("error",t=>{n.emit("fullscreenError",t)}),X(n,"fullscreen",{get:()=>Ot.isFullscreen,async set(t){t?await Ot.request(o):await Ot.exit()}})):a.webkitSupportsFullscreen?(t=>{t.on("document:webkitfullscreenchange",()=>{t.emit("fullscreen",t.fullscreen),t.emit("resize")}),X(t,"fullscreen",{get:()=>document.fullscreenElement===a,set(e){e?(t.state="fullscreen",a.webkitEnterFullscreen()):a.webkitExitFullscreen()}})})(t):X(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),X(t,"fullscreen",Z(t,"fullscreen"))})}function Vt(t){const{icons:e,proxy:r,storage:a,template:{$player:o,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(g(o,"art-mini"),w(e,"display","none"),o.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(w(e,"display","none"),w(r,"display","flex")):(w(e,"display","flex"),w(r,"display","none"))}function p(){const{$mini:e}=t.template,r=A(e),o=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;a.set("top",o),a.set("left",n),w(e,"top",`${o}px`),w(e,"left",`${n}px`)}X(t,"mini",{get:()=>v(o,"art-mini"),set(h){if(h){t.state="mini",f(o,"art-mini");const h=function(){const{$mini:o}=t.template;if(o)return y(o,n),w(o,"display","flex");{const o=L("div");f(o,"art-mini-popup"),y(document.body,o),t.template.$mini=o,y(o,n);const p=y(o,'
');y(p,e.close),r(p,"click",c);const h=y(o,'
'),u=y(h,e.play),m=y(h,e.pause);return r(u,"click",()=>Y(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(o,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){f(o,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;w(o,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,g(o,"art-mini-dragging");const t=A(o);a.set("left",t.left),a.set("top",t.top),w(o,"left",`${t.left}px`),w(o,"top",`${t.top}px`),w(o,"transform",null)}}),o}}(),u=a.get("top"),m=a.get("left");"number"===typeof u&&"number"===typeof m?(w(h,"top",`${u}px`),w(h,"left",`${m}px`),E(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Yt(t){const{i18n:e,notice:r,template:{$video:a}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:a}=t;e.disablePictureInPicture=!1,X(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw a.show=t,t})):document.exitPictureInPicture().catch(t=>{throw a.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):a.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),X(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):X(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Nt(t){const{option:e,template:{$progress:r,$video:a}}=t;let o=null,n=!1,i=null;t.on("setBar",async(o,s,l)=>{const c=t.controls?.thumbnails,{url:d,scale:h}=e.thumbnails;if(!c||!d)return;if("hover"===o||"played"===o&&l&&p){if(i||n||(n=!0,i=await P(d,h),n=!1),!i)return;const o=r.clientWidth*s;o>0&&or.clientWidth-h/2?w(n,"left",r.clientWidth-h+"px"):w(n,"left",o-h/2+"px")}(o)}}),X(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(o),o=null,n=!1,i=null)}})}Object.defineProperties(Ot,{isFullscreen:{get:()=>Boolean(document[Pt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Pt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Pt.fullscreenEnabled])}});class Dt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;X(t,"url",{get:()=>r.src,async set(a){if(a){const o=t.url,n=e.type||N(a),i=e.customType[n];n&&i?(await rt(),t.loading.show=!0,i.call(t,r,a,t)):(URL.revokeObjectURL(o),r.src=a),o!==t.url&&(t.option.url=a,t.isReady&&o&&t.once("video:canplay",()=>{t.emit("restart",a)}))}else await rt(),t.loading.show=!0}})}(t),function(t){const{template:{$video:e}}=t;X(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:a,constructor:{instances:o},template:{$video:n}}=t;X(t,"play",{async value(){const i=await n.play();if(r.show=e.get("Play"),t.emit("play"),a.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;X(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${H(t.currentTime)} / ${H(t.duration)}`),t.emit("seek",t.currentTime,r)}}),X(t,"forward",{set(e){t.seek=t.currentTime+e}}),X(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:a,storage:o}=t;X(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=F(t,0,1),a.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&o.set("volume",e.volume)}}),X(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;X(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=F(r,0,t.duration))}})}(t),function(t){X(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((a,o)=>{if(e===t.url)return void a();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),o(e)},metadata:()=>{t.currentTime=r},canplay:async()=>{t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&await Y(t.play()),t.notice.show="",a()}};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}X(t,"switchQuality",{value:r=>e(r,t.currentTime)}),X(t,"switchUrl",{value:t=>e(t,0)}),X(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:a}=t;X(t,"playbackRate",{get:()=>e.playbackRate,set(o){if(o){if(o===e.playbackRate)return;e.playbackRate=o,a.show=`${r.get("Rate")}: ${1===o?r.get("Normal"):`${o}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;X(t,"aspectRatio",{get:()=>o.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)w(a,"width",null),w(a,"height",null),w(a,"margin",null),delete o.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=o,i=e/r,s=t[0]/t[1];i>s?(w(a,"width",s*r+"px"),w(a,"height","100%"),w(a,"margin","0 auto")):(w(a,"width","100%"),w(a,"height",e/s+"px"),w(a,"margin","auto 0")),o.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,a=L("canvas");X(t,"getDataURL",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),t(a.toDataURL("image/png"))}catch(n){e.show=n,o(n)}})}),X(t,"getBlobUrl",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),a.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,o(n)}})}),X(t,"screenshot",{value:async e=>{const a=await t.getDataURL();return D(a,`${e||`artplayer_${H(r.currentTime)}`}.png`),t.emit("screenshot",a),a}})}(t),_t(t),function(t){const{constructor:e,template:{$container:r,$player:a}}=t;let o="";X(t,"fullscreenWeb",{get:()=>v(a,"art-fullscreen-web"),set(n){n?(o=a.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&y(document.body,a),t.state="fullscreenWeb",w(a,"width","100%"),w(a,"height","100%"),f(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&y(r,a),o&&(a.style.cssText=o,o=""),g(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Yt(t),function(t){const{$video:e}=t.template;X(t,"loaded",{get:()=>t.loadedTime/e.duration}),X(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){X(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;X(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:a}=t.template;X(t,"autoSize",{value(){const{videoWidth:o,videoHeight:n}=a,{width:i,height:s}=A(e),l=o/n;if(i/s>l)w(r,"width",s*l/i*100+"%"),w(r,"height","100%");else{const t=i/l/s*100;w(r,"width","100%"),w(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){X(t,"rect",{get:()=>A(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[a]})}X(t,"x",{get:()=>t.left+window.pageXOffset}),X(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:a}=t;X(t,"flip",{get:()=>e.dataset.flip||"normal",set(o){o||(o="normal"),"normal"===o?delete e.dataset.flip:e.dataset.flip=o,a.show=`${r.get("Video Flip")}: ${r.get(B(o))}`,t.emit("flip",o)}})}(t),Vt(t),function(t){const{template:{$poster:e}}=t;X(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch{return""}},set(t){w(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;X(t,"autoHeight",{value(){const{clientWidth:a}=e,{videoHeight:o,videoWidth:n}=r,i=o*(a/n);w(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;X(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){X(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){X(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];X(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let a=0;aa.$track?.offset||0,set(o){const{cues:n}=t.subtitle;if(!a.$track||0===n.length)return;const i=F(o,-10,10);a.$track.offset=i;for(let e=0;e{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,X(t,"airplay",{value(){n?(o.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){X(t,"quality",{set(e){const{controls:r,notice:a,i18n:o}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:n?.html||"",selector:e,onSelect:async e=>(await t.switchQuality(e.url),a.show=`${o.get("Switch Video")}: ${e.html}`,e.html)})}})}(t),Nt(t),function(t){const{i18n:e,notice:r,option:a,constructor:o,proxy:n,template:{$player:s,$video:l,$poster:c}}=t;let d=0;for(let p=0;p{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{d=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{a.loop?(t.seek=0,Y(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",async n=>{d{t.emit("resize"),p&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,w(c,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:a,$poster:o}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(a.volume=F(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(a.volume=F(n,0,1)),e.poster&&w(o,"backgroundImage",`url(${e.poster})`),e.autoplay&&(a.autoplay=e.autoplay),e.playsInline&&(a.playsInline=!0,a["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Ft(t){const{notice:e,constructor:r,template:{$player:a,$video:o}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=o,r=document.documentElement.clientWidth,a=document.documentElement.clientHeight;return t>e&&ra}return t.on("fullscreenWeb",e=>{if(e){if(l()){const e=Number(r.AUTO_ORIENTATION_TIME??0);setTimeout(()=>{t.fullscreenWeb&&!v(a,n)&&function(){const e=O(),r=document.documentElement.clientWidth,o=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;w(a,"width",`${o}px`),w(a,"height",`${i}px`),w(a,"transform-origin","0 0"),w(a,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),f(a,n),t.isRotate=!0,t.emit("resize")}()},e)}}else v(a,n)&&(w(a,"width",""),w(a,"height",""),w(a,"transform-origin",""),w(a,"transform",""),g(a,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",async t=>{const r=!!screen?.orientation?.lock;if(t){if(r&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";await screen.orientation.lock(t),s=!0,f(a,i)}catch(o){s=!1,e.show=o}}else if(v(a,i)&&g(a,i),r&&s){try{screen.orientation.unlock()}catch{}s=!1}}),{name:"autoOrientation",get state(){return v(a,n)}}}function Bt(t){const{i18n:e,icons:r,storage:a,constructor:o,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=u(".art-auto-playback-last",s),c=u(".art-auto-playback-jump",s),d=u(".art-auto-playback-close",s);y(d,r.close);let p=null;function h(){const r=(a.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),w(s,"display","none"),r&&r>=o.AUTO_PLAYBACK_MIN&&(w(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${H(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{w(s,"display","none")}),n(c,"click",()=>{t.seek=r,Y(t.play()),w(i,"display","none"),w(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{w(s,"display","none")},o.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=a.get("times")||{},r=Object.keys(e);r.length>o.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,a.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return a.get("times")||{}},clear:()=>a.del("times"),delete(t){const e=a.get("times")||{};return delete e[t],a.set("times",e),e}}}function Ht(t){const{constructor:e,proxy:r,template:{$player:a,$video:o}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,g(a,"art-fast-forward"))};return r(o,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,f(a,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return v(a,"art-fast-forward")}}}function Wt(t){const{layers:e,icons:r,template:{$player:a}}=t;function o(){return v(a,"art-lock")}function n(){f(a,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){g(a,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const a=y(e,r.lock),o=y(e,r.unlock);w(a,"display","none"),t.on("lock",t=>{t?(w(a,"display","inline-flex"),w(o,"display","none")):(w(a,"display","none"),w(o,"display","inline-flex"))})},click(){o()?i():n()}}),{name:"lock",get state(){return o()},set state(t){t?n():i()}}}function jt(t){return t.on("control",e=>{e?g(t.template.$player,"art-mini-progress-bar"):f(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class Ut{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(jt),e.lock&&p&&this.add(Wt),e.autoPlayback&&!e.isLive&&this.add(Bt),e.autoOrientation&&p&&this.add(Ft),e.fastForward&&p&&!e.isLive&&this.add(Ht);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return V(!K(this,r),`Cannot add a plugin that already has the same name: ${r}`),X(this,r,{value:e}),this}}class qt extends ft{constructor(t){super(t);const{option:e,controls:r,template:{$setting:a}}=t;this.name="setting",this.$parent=a,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=C(t,r.setting),a=C(t,this.$parent);!this.show||e||a||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,PLAYBACK_RATE:o}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:a,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:o.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,ASPECT_RATIO:o}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:a,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:o.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,FLIP:o}}=t;function n(t){return e.get(B(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:a,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:o.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:a}=t;return{width:a.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){for(let r=0;r{e.default=e===t,e.default&&e.$item&&$(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,a=[]){for(let o=0;oe}),X(n,"$parents",{get:()=>r}),X(n,"$option",{get:()=>t});const a=[];X(n,"$events",{get:()=>a}),X(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,a)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){const{controls:t,constructor:{SETTING_WIDTH:e,SETTING_ITEM_HEIGHT:r},template:{$player:a,$setting:o}}=this.art;if(t.setting&&this.show){const n=this.active[0]?.$parent?.width||e,{left:i,width:s}=A(t.setting),{left:l,width:c}=A(a),d=i-l+s/2-n/2;if(w(o,"height",`${this.active===this.option?this.active.length*r:(this.active.length+1)*r}px`),w(o,"width",`${n}px`),this.art.isRotate||p)return;d+n>c?(w(o,"left",null),w(o,"right",null)):(w(o,"left",`${d}px`),w(o,"right","auto"))}}inactivate(t){for(let e=0;e'),s=L("div");f(s,"art-setting-item-left-icon"),y(s,a),y(i,s),y(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),y(e,n)}createItem(t,e=!1){if(!this.cache.has(t.$option))return;const r=this.cache.get(t.$option),a=t.$item;let o="selector";K(t,"switch")&&(o="switch"),K(t,"range")&&(o="range"),K(t,"onClick")&&(o="button");const{icons:n,proxy:i,constructor:s}=this.art,l=L("div");f(l,"art-setting-item"),w(l,"height",`${s.SETTING_ITEM_HEIGHT}px`),l.dataset.name=t.name||"",l.dataset.value=t.value||"";const c=y(l,'
'),d=y(l,'
'),p=L("div");switch(f(p,"art-setting-item-left-icon"),o){case"button":case"switch":case"range":y(p,t.icon||n.config);break;case"selector":t.selector?.length?y(p,t.icon||n.config):y(p,n.check)}y(c,p),X(t,"$icon",{configurable:!0,get:()=>p}),X(t,"icon",{configurable:!0,get:()=>p.innerHTML,set(t){p.innerHTML="",y(p,t)}});const h=L("div");f(h,"art-setting-item-left-text"),y(h,t.html||""),y(c,h),X(t,"$html",{configurable:!0,get:()=>h}),X(t,"html",{configurable:!0,get:()=>h.innerHTML,set(t){h.innerHTML="",y(h,t)}});const u=L("div");switch(f(u,"art-setting-item-right-tooltip"),y(u,t.tooltip||""),y(d,u),X(t,"$tooltip",{configurable:!0,get:()=>u}),X(t,"tooltip",{configurable:!0,get:()=>u.innerHTML,set(t){u.innerHTML="",y(u,t)}}),o){case"switch":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,n.switchOn),a=y(e,n.switchOff);w(t.switch?a:r,"display","none"),y(d,e),X(t,"$switch",{configurable:!0,get:()=>e});let o=t.switch;X(t,"switch",{configurable:!0,get:()=>o,set(t){o=t,t?(w(a,"display","none"),w(r,"display",null)):(w(a,"display",null),w(r,"display","none"))}});break}case"range":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],f(r,"art-setting-range"),y(d,e),X(t,"$range",{configurable:!0,get:()=>r});let a=[...t.range];X(t,"range",{configurable:!0,get:()=>a,set(t){a=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(t.selector?.length){const t=L("div");f(t,"art-setting-item-right-icon"),y(t,n.arrowRight),y(d,t)}}switch(o){case"switch":if(t.onSwitch){const e=i(l,"click",async e=>{t.switch=await t.onSwitch.call(this.art,t,l,e)});t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=i(t.$range,"change",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onRange.call(this.art,t,l,e)});t.$events.push(e)}if(t.onChange){const e=i(t.$range,"input",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onChange.call(this.art,t,l,e)});t.$events.push(e)}}break;case"selector":{const e=i(l,"click",async e=>{t.selector?.length?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=await t.$parent.onSelect.call(this.art,t,l,e)))});t.$events.push(e),t.default&&f(l,"art-current")}break;case"button":if(t.onClick){const e=i(l,"click",async e=>{t.tooltip=await t.onClick.call(this.art,t,l,e)});t.$events.push(e)}}X(t,"$item",{configurable:!0,get:()=>l}),e?z(l,a):y(r,l),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){if(this.active=t,this.cache.has(t)){$(this.cache.get(t),"art-current")}else{const e=L("div");this.cache.set(t,e),f(e,"art-setting-panel"),y(this.$parent,e),$(e,"art-current"),t[0]?.$parent&&this.createHeader(t[0]);for(let r=0;rnull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){return this.art.template.$video?.textTracks?.[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?x(r,t):w(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?q(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}async switch(t,e={}){const{i18n:r,notice:a,option:o}=this.art,n={...o.subtitle,...e,url:t},i=await this.init(n);return e.name&&(a.show=`${r.get("Switch Subtitle")}: ${e.name}`),i}createTrack(t,e){const{template:r,proxy:a,option:o}=this.art,{$video:n,$track:i}=r,s=L("track");s.default=!0,s.kind=t,s.src=e,s.label=o.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,b(i),y(n,s),r.$track=s,this.destroyEvent=a(this.textTrack,"cuechange",()=>this.update())}async init(t){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(o(t,mt.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||N(t.url)){case"srt":{const e=Q(r);return tt(t.onVttLoad(e))}case"ass":{const e=et(r);return tt(t.onVttLoad(e))}case"vtt":return tt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null}}class Zt{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=u(e.container),V(this.$container,`No container element found by ${e.container}`)),V(I(),"The current browser does not support flex layout");const a=this.$container.tagName.toLowerCase();V("div"===a,`Unsupported container element type, only support 'div' but got '${a}'`),V(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${n}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return u(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=Zt.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);V(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),z(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&f(this.$player,"art-backdrop"),p&&f(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":f(this.$player,"art-destroy")}}class Jt{on(t,e,r){const a=this.e||(this.e={});return(a[t]||(a[t]=[])).push({fn:e,ctx:r}),this}once(t,e,r){const a=this;function o(...n){a.off(t,o),e.apply(r,n)}return o._=e,this.on(t,o,r)}emit(t,...e){const r=((this.e||(this.e={}))[t]||[]).slice();for(let a=0;ae.call(this,this)),ee.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${ee.version}`);for(let e=0;et(`Event@${e.type}`))}te.push(this)}static get instances(){return te}static get version(){return n}static get config(){return i}static get utils(){return nt}static get scheme(){return mt}static get Emitter(){return Jt}static get validator(){return o}static get kindOf(){return o.kindOf}static get html(){return Zt.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:l?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:navigator?.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){ee.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),te.splice(te.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return ee.STYLE=Gt,ee.DEBUG=!1,ee.CONTEXTMENU=!0,ee.NOTICE_TIME=2e3,ee.SETTING_WIDTH=250,ee.SETTING_ITEM_WIDTH=200,ee.SETTING_ITEM_HEIGHT=35,ee.RESIZE_TIME=200,ee.SCROLL_TIME=200,ee.SCROLL_GAP=50,ee.AUTO_PLAYBACK_MAX=10,ee.AUTO_PLAYBACK_MIN=5,ee.AUTO_PLAYBACK_TIMEOUT=3e3,ee.RECONNECT_TIME_MAX=5,ee.RECONNECT_SLEEP_TIME=1e3,ee.CONTROL_HIDE_TIME=3e3,ee.DBCLICK_TIME=300,ee.DBCLICK_FULLSCREEN=!0,ee.MOBILE_DBCLICK_PLAY=!0,ee.MOBILE_CLICK_PLAY=!1,ee.AUTO_ORIENTATION_TIME=200,ee.INFO_LOOP_TIME=1e3,ee.FAST_FORWARD_VALUE=3,ee.FAST_FORWARD_TIME=1e3,ee.TOUCH_MOVE_RATIO=.5,ee.VOLUME_STEP=.1,ee.SEEK_STEP=5,ee.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],ee.ASPECT_RATIO=["default","4:3","16:9"],ee.FLIP=["normal","horizontal","vertical"],ee.FULLSCREEN_WEB_IN_BODY=!0,ee.LOG_VERSION=!0,ee.USE_RAF=!1,ee.REMOVE_SRC_WHEN_DESTROY=!0,h&&(window.Artplayer=ee,M("artplayer-style",Gt),setTimeout(()=>{ee.LOG_VERSION&&console.log(`%c ArtPlayer %c ${ee.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),ee}); +!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2=1,p=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(s)||d,h="undefined"!==typeof window&&"undefined"!==typeof document;function u(t,e=document){return e.querySelector(t)}function m(t,e=document){return Array.from(e.querySelectorAll(t))}function f(t,e){return t.classList.add(e)}function g(t,e){return t.classList.remove(e)}function v(t,e){return t.classList.contains(e)}function y(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function b(t){return t.parentNode.removeChild(t)}function w(t,e,r){return t.style[e]=r,t}function x(t,e){for(const r in e)w(t,r,e[r]);return t}function k(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function $(t,e){k(t).forEach(t=>g(t,e)),f(t,e)}function T(t,e,r="top"){p||(t.setAttribute("aria-label",e),f(t,"hint--rounded"),f(t,`hint--${r}`))}function E(t,e=0){const r=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=a&&r.top+r.height+e>=0,i=r.left-e<=o+e&&r.left+r.width+e>=0;return n&&i}function C(t,e){return R(t).includes(e)}function z(t,e){return e.parentNode.replaceChild(t,e),t}function L(t){return document.createElement(t)}function S(t="",e=""){const r=L("i");return f(r,"art-icon"),f(r,`art-icon-${t}`),y(r,e),r}function M(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function I(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function P(t){return t.getBoundingClientRect()}function A(t,e){return new Promise((r,a)=>{const o=new Image;o.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=o.width*e,n.height=o.height*e,i.drawImage(o,0,0,n.width,n.height),n.toBlob(e=>{const o=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(o),a(new Error(`Image load failed: ${t}`))},n.src=o})}else r(o)},o.onerror=function(){a(new Error(`Image load failed: ${t}`))},o.src=t})}function R(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function O(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class _ extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function V(t,e){if(!t)throw new _(e);return t}function Y(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function N(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function D(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function F(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function B(t){return t.charAt(0).toUpperCase()+t.slice(1)}function H(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),a=Math.floor(t-3600*e-60*r);return(e>0?[e,r,a]:[r,a]).map(t=>t<10?`0${t}`:String(t)).join(":")}const W={"&":"&","<":"<",">":">","'":"'",'"':"""},j={"&":"&","<":"<",">":">","'":"'",""":'"'},U=/(&|<|>|'|")/g;function q(t){return t.replace(/[&<>'"]/g,t=>W[t]||t)}const X=Object.defineProperty,{hasOwnProperty:G}=Object.prototype;function K(t,e){return G.call(t,e)}function Z(t,e){return Object.getOwnPropertyDescriptor(t,e)}function J(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(a=>{const o=t[a],n=r[a];let i;i=Array.isArray(o)&&Array.isArray(n)?o.concat(...n):e(o)&&e(n)?J(o,n):n,X(t,a,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function Q(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let a=r.slice(0,3);return 1===r.length&&(a=`${r}00`),2===r.length&&(a=`${r}0`),`${e},${a}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function tt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function et(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const a=t.match(e);if(!a)return null;const[,o="",n="",,,i=""]=a;return{start:r(o.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function rt(t=0){return new Promise(e=>setTimeout(e,t))}function at(t,e){let r;return function(...a){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,a)),e)}}function ot(t,e){let r=!1;return function(...a){r||(t.apply(this,a),r=!0,setTimeout(()=>{r=!1},e))}}const nt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:_,addClass:f,append:y,assToVtt:et,capitalize:B,clamp:F,createElement:L,debounce:at,def:X,download:D,errorHandle:V,escape:q,get:Z,getComposedPath:R,getExt:N,getIcon:S,getRect:P,getSafeAreaInsets:O,getStyle:function(t,e,r=!0){const a=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(a):a},has:K,hasClass:v,includeFromEvent:C,inverseClass:$,isBrowser:h,isIOS:c,isIOS13:d,isInViewport:E,isMobile:p,isSafari:l,loadImg:A,mergeDeep:J,query:u,queryAll:m,remove:b,removeClass:g,replaceElement:z,secondToTime:H,setStyle:w,setStyleText:M,setStyles:x,siblings:k,silencePromise:Y,sleep:rt,srtToVtt:Q,supportsFlex:I,throttle:ot,tooltip:T,unescape:function(t){return t.replace(U,t=>j[t]||t)},userAgent:s,vttToBlob:tt},Symbol.toStringTag,{value:"Module"})),it="array",st="boolean",lt="string",ct="number",dt="object",pt="function";function ht(t,e,r){return V(e===lt||e===ct||t instanceof Element,`${r.join(".")} require '${lt}' or 'Element' type`)}const ut={html:ht,disable:`?${st}`,name:`?${lt}`,index:`?${ct}`,style:`?${dt}`,click:`?${pt}`,mounted:`?${pt}`,tooltip:`?${lt}|${ct}`,width:`?${ct}`,selector:`?${it}`,onSelect:`?${pt}`,switch:`?${st}`,onSwitch:`?${pt}`,range:`?${it}`,onRange:`?${pt}`,onChange:`?${pt}`},mt={id:lt,container:ht,url:lt,poster:lt,type:lt,theme:lt,lang:lt,volume:ct,isLive:st,muted:st,autoplay:st,autoSize:st,autoMini:st,loop:st,flip:st,playbackRate:st,aspectRatio:st,screenshot:st,setting:st,hotkey:st,pip:st,mutex:st,backdrop:st,fullscreen:st,fullscreenWeb:st,subtitleOffset:st,miniProgressBar:st,useSSR:st,playsInline:st,lock:st,gesture:st,fastForward:st,autoPlayback:st,autoOrientation:st,airplay:st,proxy:`?${pt}`,plugins:[pt],layers:[ut],contextmenu:[ut],settings:[ut],controls:[{...ut,position:(t,e,r)=>{const a=["top","left","right"];return V(a.includes(t),`${r.join(".")} only accept ${a.toString()} as parameters`)}}],quality:[{default:`?${st}`,html:lt,url:lt}],highlight:[{time:ct,text:lt}],thumbnails:{url:lt,number:ct,column:ct,width:ct,height:ct,scale:ct},subtitle:{url:lt,name:lt,type:lt,style:dt,escape:st,encoding:lt,onVttLoad:pt},moreVideoAttr:dt,i18n:dt,icons:dt,cssVar:dt,customType:dt};class ft{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return v(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?f(e,r):g(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",o(e,ut),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;V(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const a=L("div");f(a,`art-${this.name}`),f(a,`art-${this.name}-${r}`);const n=Array.from(this.$parent.children);a.dataset.index=e.index||this.id;const i=n.find(t=>Number(t.dataset.index)>=Number(a.dataset.index));i?i.insertAdjacentElement("beforebegin",a):y(this.$parent,a),e.html&&y(a,e.html),e.style&&x(a,e.style),e.tooltip&&T(a,e.tooltip);const s=[];if(e.click){const t=this.art.events.proxy(a,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});s.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,a,s),this[r]=a,this.cache.set(r,{$ref:a,events:s,option:e}),e.mounted&&e.mounted.call(this.art,a),a}remove(t){V(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],b(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class gt extends ft{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,p||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:a}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:a}}=e,o=a.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return{...t,html:`${r.get("Play Speed")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.playbackRate=Number(a),t.show=!1)},mounted:t=>{const r=u('[data-value="1"]',t);r&&$(r,"art-current"),e.on("video:ratechange",()=>{const r=m("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&$(r,"art-current")})}}}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:a}}=e,o=a.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return{...t,html:`${r.get("Aspect Ratio")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.aspectRatio=a,t.show=!1)},mounted:t=>{const r=u('[data-value="default"]',t);r&&$(r,"art-current"),e.on("aspectRatio",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:a}}=e,o=a.map(t=>`${r.get(B(t))}`).join("");return{...t,html:`${r.get("Video Flip")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.flip=a.toLowerCase(),t.show=!1)},mounted:t=>{const r=u('[data-value="normal"]',t);r&&$(r,"art-current"),e.on("flip",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"flip",index:30})),this.add(function(t){return e=>({...t,html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return{...t,html:`ArtPlayer ${n}`}}({name:"version",index:50})),this.add(function(t){return e=>({...t,html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let o=0;o{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,o=t.clientY,{height:n,width:i,left:s,top:l}=P(r),{height:c,width:d}=P(a);let p=e-s,h=o-l;e+d>s+i&&(p=i-d),o+c>l+n&&(h=n-c),x(a,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{C(t,a)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function vt(t,e){const{$progress:r}=t.template,{left:a}=P(r),o=F((p?e.touches[0].clientX:e.clientX)-a,0,r.clientWidth),n=o/r.clientWidth*t.duration;return{second:n,time:H(n),width:o,percentage:F(o/r.clientWidth,0,1)}}function yt(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,a=r*t.duration;t.emit("setBar","played",r,e),t.seek=a}else{const{second:r,percentage:a}=vt(t,e);t.emit("setBar","played",a,e),t.seek=r}}function bt(t){return e=>{const{icons:r,option:a,proxy:o}=e,{$player:n,$progress:i}=e.template;return{...t,html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=u(".art-progress-hover",t),d=u(".art-progress-loaded",t),h=u(".art-progress-played",t),m=u(".art-progress-highlight",t),v=u(".art-progress-indicator",t),b=u(".art-progress-tip",t);function x(r,a){const{width:o,time:n}=a||vt(e,r);b.textContent=n||"00:00";const i=b.clientWidth;o<=i/2?w(b,"left",0):o>t.clientWidth-i/2?w(b,"left",t.clientWidth-i+"px"):w(b,"left",o-i/2+"px")}r.indicator?y(v,r.indicator):w(v,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,a,o){const i="played"===r&&o&&p;if("loaded"===r&&w(d,"width",100*a+"%"),"hover"===r&&(w(c,"width",100*a+"%"),C(o,m)?function(r){const{width:a}=vt(e,r),{text:o}=r.target.dataset;b.textContent=o;const n=b.clientWidth;a<=n/2?w(b,"left",0):a>t.clientWidth-n/2?w(b,"left",t.clientWidth-n+"px"):w(b,"left",a-n/2+"px")}(o):x(o),0===a?g(n,"art-progress-hover"):f(n,"art-progress-hover")),"played"===r&&(w(h,"width",100*a+"%"),w(v,"left",100*a+"%")),i){f(n,"art-progress-hover");x(o,{width:t.clientWidth*a,time:H(a*e.duration)}),clearTimeout(s),s=setTimeout(()=>{g(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){m.textContent="";for(let t=0;t`;y(m,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),p||(o(i,"click",t=>{t.target!==v&&yt(e,t)}),o(i,"mousemove",t=>{const{percentage:r}=vt(e,t);e.emit("setBar","hover",r,t)}),o(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),o(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:a}=vt(e,t);e.emit("setBar","played",a,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}}}}class wt extends ft{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:a}=this.art.template;t.on("mousemove",()=>{p||(this.show=!0)}),t.on("click",()=>{p?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=C(t,a)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(g(r,"art-hide-cursor"),f(r,"art-hover"),this.timer=Date.now()):(f(r,"art-hide-cursor"),g(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(bt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.play),i=y(t,a.pause);function s(){w(n,"display","flex"),w(i,"display","none")}function l(){w(n,"display","none"),w(i,"display","flex")}T(n,o.get("Play")),T(i,o.get("Pause")),r(n,"click",()=>{Y(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a}=e,o=y(t,a.volume),n=y(t,a.volumeClose),i=y(t,'
'),s=y(i,'
'),l=y(s,'
'),c=y(s,'
'),d=y(c,'
'),h=y(d,'
'),u=y(c,'
');function m(t){const{top:e,height:r}=P(c);return 1-(t.clientY-e)/r}function f(){if(e.muted||0===e.volume)w(o,"display","none"),w(n,"display","flex"),w(u,"top","100%"),w(h,"top","100%"),l.textContent=0;else{const t=100*e.volume;w(o,"display","flex"),w(n,"display","none"),w(u,"top",100-t+"%"),w(h,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(f(),e.on("video:volumechange",f),r(o,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),p)w(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=m(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=m(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>({...t,style:p?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${H(e.currentTime)} / ${H(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const a=["video:loadedmetadata","video:timeupdate","video:progress"];for(let o=0;o{this.art.quality=t.quality}),t.screenshot&&!p&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{T(t,o.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{T(t,o.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenWebOn),i=y(t,a.fullscreenWebOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(T(t,o.get("Exit Web Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Web Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenOn),i=y(t,a.fullscreenOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(T(t,o.get("Exit Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),X(e,"$control_item",{get:()=>r}),X(e,"$control_value",{get:()=>o})}const i=a(n,"click",async e=>{const r=R(e),a=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(a),t.onSelect&&(o.innerHTML=await t.onSelect.call(this.art,a,a.$control_item,e))});r.push(i)}}function xt(t,e,r,a){const o=e-a,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(o)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,o);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class kt{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:a,$video:o}}=t;function n(e){C(e,a)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(o,"click",e=>{const a=Date.now();i.push(a);const{MOBILE_CLICK_PLAY:o,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>a-t<=n);switch(c.length){case 1:t.emit("click",e),p?!t.isLock&&o&&Y(t.toggle()):Y(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),p?!t.isLock&&s&&Y(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{f(r,"art-hover"),t.emit("hover",!0,e)},e=>{g(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:a}=t;t.on("resize",()=>{const{aspectRatio:e,notice:a}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,a.show=""});const o=at(()=>t.emit("resize"),a.RESIZE_TIME);t.on("window:orientationchange",()=>o()),t.on("window:resize",()=>o()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>o())}(t,this),function(t,e){if(p&&!t.option.isLive){const{$video:r,$progress:a}=t.template;let o=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){o===a&&yt(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:a,pageY:n}=e.touches[0],c=xt(i,s,a,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=F((a-i)/t.width,-1,1),d=F((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=o===r?t.constructor.TOUCH_MOVE_RATIO:1,u=F(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",F(u/t.duration,0,1),e),t.notice.show=`${H(u)} / ${H(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,o=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{o=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(a,"touchstart",t=>{o=a,c(t)}),e.proxy(a,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:a}}=t,o=ot(()=>{t.emit("view",E(a,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>o()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],a=["resize","scroll","orientationchange"],o=[];function n(n={}){for(let t=0;t{const a=n.document||i.ownerDocument||document,s=e.proxy(a,r,e=>{t.emit(`document:${r}`,e)});o.push(s)}),a.forEach(r=>{const a=n.window||i.ownerDocument?.defaultView||window,s=e.proxy(a,r,e=>{t.emit(`window:${r}`,e)});o.push(s)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,a={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,a));t.addEventListener(e,r,a);const o=()=>t.removeEventListener(e,r,a);return this.destroyEvents.add(o),o}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class $t{constructor(t){this.art=t,this.keys={},p||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{Y(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n',...t.option.icons};for(const r in e)X(this,r,{get:()=>S(r,e[r])})}}class zt extends ft{constructor(t){super(t),this.name="info",p||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:a,$video:o}}=this.art;t(a,"click",()=>{this.show=!1});let n=null;const i=m("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{w(o,"display","none"),w(n,"display",null)}),a.proxy(e.$state,"click",()=>Y(t.play()))}}class It{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:a}}=this.art;t?(a.textContent=t instanceof Error?t.message.trim():t,f(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{a.textContent="",g(r,"art-notice-show")},e.NOTICE_TIME)):g(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Pt=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],At=(()=>{if("undefined"===typeof document)return!1;const t=Pt[0],e={};for(const r of Pt){if(r[1]in document){for(const[a,o]of r.entries())e[t[a]]=o;return e}}return!1})(),Rt={change:At.fullscreenchange,error:At.fullscreenerror},Ot={request:(t=document.documentElement,e)=>new Promise((r,a)=>{const o=()=>{Ot.off("change",o),r()};Ot.on("change",o);const n=t[At.requestFullscreen](e);n instanceof Promise&&n.then(o).catch(a)}),exit:()=>new Promise((t,e)=>{if(!Ot.isFullscreen)return void t();const r=()=>{Ot.off("change",r),t()};Ot.on("change",r);const a=document[At.exitFullscreen]();a instanceof Promise&&a.then(r).catch(e)}),toggle:(t,e)=>Ot.isFullscreen?Ot.exit():Ot.request(t,e),onchange(t){Ot.on("change",t)},onerror(t){Ot.on("error",t)},on(t,e){const r=Rt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=Rt[t];r&&document.removeEventListener(r,e,!1)},raw:At};function _t(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;t.once("video:loadedmetadata",()=>{var n;Ot.isEnabled?(n=t,Ot.on("change",()=>{n.emit("fullscreen",Ot.isFullscreen),Ot.isFullscreen?(n.state="fullscreen",f(o,"art-fullscreen")):g(o,"art-fullscreen"),n.emit("resize")}),Ot.on("error",t=>{n.emit("fullscreenError",t)}),X(n,"fullscreen",{get:()=>Ot.isFullscreen,async set(t){t?await Ot.request(o):await Ot.exit()}})):a.webkitSupportsFullscreen?(t=>{t.on("document:webkitfullscreenchange",()=>{t.emit("fullscreen",t.fullscreen),t.emit("resize")}),X(t,"fullscreen",{get:()=>document.fullscreenElement===a,set(e){e?(t.state="fullscreen",a.webkitEnterFullscreen()):a.webkitExitFullscreen()}})})(t):X(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),X(t,"fullscreen",Z(t,"fullscreen"))})}function Vt(t){const{icons:e,proxy:r,storage:a,template:{$player:o,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(g(o,"art-mini"),w(e,"display","none"),o.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(w(e,"display","none"),w(r,"display","flex")):(w(e,"display","flex"),w(r,"display","none"))}function p(){const{$mini:e}=t.template,r=P(e),o=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;a.set("top",o),a.set("left",n),w(e,"top",`${o}px`),w(e,"left",`${n}px`)}X(t,"mini",{get:()=>v(o,"art-mini"),set(h){if(h){t.state="mini",f(o,"art-mini");const h=function(){const{$mini:o}=t.template;if(o)return y(o,n),w(o,"display","flex");{const o=L("div");f(o,"art-mini-popup"),y(document.body,o),t.template.$mini=o,y(o,n);const p=y(o,'
');y(p,e.close),r(p,"click",c);const h=y(o,'
'),u=y(h,e.play),m=y(h,e.pause);return r(u,"click",()=>Y(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(o,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){f(o,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;w(o,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,g(o,"art-mini-dragging");const t=P(o);a.set("left",t.left),a.set("top",t.top),w(o,"left",`${t.left}px`),w(o,"top",`${t.top}px`),w(o,"transform",null)}}),o}}(),u=a.get("top"),m=a.get("left");"number"===typeof u&&"number"===typeof m?(w(h,"top",`${u}px`),w(h,"left",`${m}px`),E(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Yt(t){const{i18n:e,notice:r,template:{$video:a}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:a}=t;e.disablePictureInPicture=!1,X(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw a.show=t,t})):document.exitPictureInPicture().catch(t=>{throw a.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):a.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),X(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):X(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Nt(t){const{option:e,template:{$progress:r,$video:a}}=t;let o=null,n=!1,i=null;t.on("setBar",async(o,s,l)=>{const c=t.controls?.thumbnails,{url:d,scale:h}=e.thumbnails;if(!c||!d)return;if("hover"===o||"played"===o&&l&&p){if(i||n||(n=!0,i=await A(d,h),n=!1),!i)return;const o=r.clientWidth*s;o>0&&or.clientWidth-h/2?w(n,"left",r.clientWidth-h+"px"):w(n,"left",o-h/2+"px")}(o)}}),X(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(o),o=null,n=!1,i=null)}})}Object.defineProperties(Ot,{isFullscreen:{get:()=>Boolean(document[At.fullscreenElement])},element:{enumerable:!0,get:()=>document[At.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[At.fullscreenEnabled])}});class Dt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;X(t,"url",{get:()=>r.src,async set(a){if(a){const o=t.url,n=e.type||N(a),i=e.customType[n];n&&i?(await rt(),t.loading.show=!0,i.call(t,r,a,t)):(URL.revokeObjectURL(o),r.src=a),o!==t.url&&(t.option.url=a,t.isReady&&o&&t.once("video:canplay",()=>{t.emit("restart",a)}))}else await rt(),t.loading.show=!0}})}(t),function(t){const{template:{$video:e}}=t;X(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:a,constructor:{instances:o},template:{$video:n}}=t;X(t,"play",{async value(){const i=await n.play();if(r.show=e.get("Play"),t.emit("play"),a.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;X(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${H(t.currentTime)} / ${H(t.duration)}`),t.emit("seek",t.currentTime,r)}}),X(t,"forward",{set(e){t.seek=t.currentTime+e}}),X(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:a,storage:o}=t;X(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=F(t,0,1),a.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&o.set("volume",e.volume)}}),X(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;X(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=F(r,0,t.duration))}})}(t),function(t){X(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((a,o)=>{if(e===t.url)return void a();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),o(e)},metadata:()=>{t.currentTime=r},canplay:async()=>{t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&await Y(t.play()),t.notice.show="",a()}};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}X(t,"switchQuality",{value:r=>e(r,t.currentTime)}),X(t,"switchUrl",{value:t=>e(t,0)}),X(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:a}=t;X(t,"playbackRate",{get:()=>e.playbackRate,set(o){if(o){if(o===e.playbackRate)return;e.playbackRate=o,a.show=`${r.get("Rate")}: ${1===o?r.get("Normal"):`${o}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;X(t,"aspectRatio",{get:()=>o.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)w(a,"width",null),w(a,"height",null),w(a,"margin",null),delete o.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=o,i=e/r,s=t[0]/t[1];i>s?(w(a,"width",s*r+"px"),w(a,"height","100%"),w(a,"margin","0 auto")):(w(a,"width","100%"),w(a,"height",e/s+"px"),w(a,"margin","auto 0")),o.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,a=L("canvas");X(t,"getDataURL",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),t(a.toDataURL("image/png"))}catch(n){e.show=n,o(n)}})}),X(t,"getBlobUrl",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),a.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,o(n)}})}),X(t,"screenshot",{value:async e=>{const a=await t.getDataURL();return D(a,`${e||`artplayer_${H(r.currentTime)}`}.png`),t.emit("screenshot",a),a}})}(t),_t(t),function(t){const{constructor:e,template:{$container:r,$player:a}}=t;let o="";X(t,"fullscreenWeb",{get:()=>v(a,"art-fullscreen-web"),set(n){n?(o=a.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&y(document.body,a),t.state="fullscreenWeb",w(a,"width","100%"),w(a,"height","100%"),f(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&y(r,a),o&&(a.style.cssText=o,o=""),g(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Yt(t),function(t){const{$video:e}=t.template;X(t,"loaded",{get:()=>t.loadedTime/e.duration}),X(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){X(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;X(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:a}=t.template;X(t,"autoSize",{value(){const{videoWidth:o,videoHeight:n}=a,{width:i,height:s}=P(e),l=o/n;if(i/s>l)w(r,"width",s*l/i*100+"%"),w(r,"height","100%");else{const t=i/l/s*100;w(r,"width","100%"),w(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){X(t,"rect",{get:()=>P(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[a]})}X(t,"x",{get:()=>t.left+window.pageXOffset}),X(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:a}=t;X(t,"flip",{get:()=>e.dataset.flip||"normal",set(o){o||(o="normal"),"normal"===o?delete e.dataset.flip:e.dataset.flip=o,a.show=`${r.get("Video Flip")}: ${r.get(B(o))}`,t.emit("flip",o)}})}(t),Vt(t),function(t){const{template:{$poster:e}}=t;X(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch{return""}},set(t){w(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;X(t,"autoHeight",{value(){const{clientWidth:a}=e,{videoHeight:o,videoWidth:n}=r,i=o*(a/n);w(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;X(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){X(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){X(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];X(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let a=0;aa.$track?.offset||0,set(o){const{cues:n}=t.subtitle;if(!a.$track||0===n.length)return;const i=F(o,-10,10);a.$track.offset=i;for(let e=0;e{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,X(t,"airplay",{value(){n?(o.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){X(t,"quality",{set(e){const{controls:r,notice:a,i18n:o}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:n?.html||"",selector:e,onSelect:async e=>(await t.switchQuality(e.url),a.show=`${o.get("Switch Video")}: ${e.html}`,e.html)})}})}(t),Nt(t),function(t){const{i18n:e,notice:r,option:a,constructor:o,proxy:n,template:{$player:s,$video:l,$poster:c}}=t;let d=0;for(let p=0;p{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{d=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{a.loop?(t.seek=0,Y(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",async n=>{d{t.emit("resize"),p&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,w(c,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:a,$poster:o}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(a.volume=F(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(a.volume=F(n,0,1)),e.poster&&w(o,"backgroundImage",`url(${e.poster})`),e.autoplay&&(a.autoplay=e.autoplay),e.playsInline&&(a.playsInline=!0,a["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Ft(t){const{notice:e,constructor:r,template:{$player:a,$video:o}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=o,r=document.documentElement.clientWidth,a=document.documentElement.clientHeight;return t>e&&ra}return t.on("fullscreenWeb",e=>{if(e){if(l()){const e=Number(r.AUTO_ORIENTATION_TIME??0);setTimeout(()=>{t.fullscreenWeb&&!v(a,n)&&function(){const e=O(),r=document.documentElement.clientWidth,o=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;w(a,"width",`${o}px`),w(a,"height",`${i}px`),w(a,"transform-origin","0 0"),w(a,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),f(a,n),t.isRotate=!0,t.emit("resize")}()},e)}}else v(a,n)&&(w(a,"width",""),w(a,"height",""),w(a,"transform-origin",""),w(a,"transform",""),g(a,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",async t=>{const r=!!screen?.orientation?.lock;if(t){if(r&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";await screen.orientation.lock(t),s=!0,f(a,i)}catch(o){s=!1,e.show=o}}else if(v(a,i)&&g(a,i),r&&s){try{screen.orientation.unlock()}catch{}s=!1}}),{name:"autoOrientation",get state(){return v(a,n)}}}function Bt(t){const{i18n:e,icons:r,storage:a,constructor:o,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=u(".art-auto-playback-last",s),c=u(".art-auto-playback-jump",s),d=u(".art-auto-playback-close",s);y(d,r.close);let p=null;function h(){const r=(a.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),w(s,"display","none"),r&&r>=o.AUTO_PLAYBACK_MIN&&(w(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${H(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{w(s,"display","none")}),n(c,"click",()=>{t.seek=r,Y(t.play()),w(i,"display","none"),w(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{w(s,"display","none")},o.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=a.get("times")||{},r=Object.keys(e);r.length>o.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,a.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return a.get("times")||{}},clear:()=>a.del("times"),delete(t){const e=a.get("times")||{};return delete e[t],a.set("times",e),e}}}function Ht(t){const{constructor:e,proxy:r,template:{$player:a,$video:o}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,g(a,"art-fast-forward"))};return r(o,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,f(a,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return v(a,"art-fast-forward")}}}function Wt(t){const{layers:e,icons:r,template:{$player:a}}=t;function o(){return v(a,"art-lock")}function n(){f(a,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){g(a,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const a=y(e,r.lock),o=y(e,r.unlock);w(a,"display","none"),t.on("lock",t=>{t?(w(a,"display","inline-flex"),w(o,"display","none")):(w(a,"display","none"),w(o,"display","inline-flex"))})},click(){o()?i():n()}}),{name:"lock",get state(){return o()},set state(t){t?n():i()}}}function jt(t){return t.on("control",e=>{e?g(t.template.$player,"art-mini-progress-bar"):f(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class Ut{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(jt),e.lock&&p&&this.add(Wt),e.autoPlayback&&!e.isLive&&this.add(Bt),e.autoOrientation&&p&&this.add(Ft),e.fastForward&&p&&!e.isLive&&this.add(Ht);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return V(!K(this,r),`Cannot add a plugin that already has the same name: ${r}`),X(this,r,{value:e}),this}}class qt extends ft{constructor(t){super(t);const{option:e,controls:r,template:{$setting:a}}=t;this.name="setting",this.$parent=a,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=C(t,r.setting),a=C(t,this.$parent);!this.show||e||a||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,PLAYBACK_RATE:o}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:a,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:o.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,ASPECT_RATIO:o}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:a,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:o.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,FLIP:o}}=t;function n(t){return e.get(B(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:a,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:o.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:a}=t;return{width:a.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){for(let r=0;r{e.default=e===t,e.default&&e.$item&&$(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,a=[]){for(let o=0;oe}),X(n,"$parents",{get:()=>r}),X(n,"$option",{get:()=>t});const a=[];X(n,"$events",{get:()=>a}),X(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,a)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){const{controls:t,constructor:{SETTING_WIDTH:e,SETTING_ITEM_HEIGHT:r},template:{$player:a,$setting:o}}=this.art;if(t.setting&&this.show){const n=this.active[0]?.$parent?.width||e,{left:i,width:s}=P(t.setting),{left:l,width:c}=P(a),d=i-l+s/2-n/2;if(w(o,"height",`${this.active===this.option?this.active.length*r:(this.active.length+1)*r}px`),w(o,"width",`${n}px`),this.art.isRotate||p)return;d+n>c?(w(o,"left",null),w(o,"right",null)):(w(o,"left",`${d}px`),w(o,"right","auto"))}}inactivate(t){for(let e=0;e'),s=L("div");f(s,"art-setting-item-left-icon"),y(s,a),y(i,s),y(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),y(e,n)}createItem(t,e=!1){if(!this.cache.has(t.$option))return;const r=this.cache.get(t.$option),a=t.$item;let o="selector";K(t,"switch")&&(o="switch"),K(t,"range")&&(o="range"),K(t,"onClick")&&(o="button");const{icons:n,proxy:i,constructor:s}=this.art,l=L("div");f(l,"art-setting-item"),w(l,"height",`${s.SETTING_ITEM_HEIGHT}px`),l.dataset.name=t.name||"",l.dataset.value=t.value||"";const c=y(l,'
'),d=y(l,'
'),p=L("div");switch(f(p,"art-setting-item-left-icon"),o){case"button":case"switch":case"range":y(p,t.icon||n.config);break;case"selector":t.selector?.length?y(p,t.icon||n.config):y(p,n.check)}y(c,p),X(t,"$icon",{configurable:!0,get:()=>p}),X(t,"icon",{configurable:!0,get:()=>p.innerHTML,set(t){p.innerHTML="",y(p,t)}});const h=L("div");f(h,"art-setting-item-left-text"),y(h,t.html||""),y(c,h),X(t,"$html",{configurable:!0,get:()=>h}),X(t,"html",{configurable:!0,get:()=>h.innerHTML,set(t){h.innerHTML="",y(h,t)}});const u=L("div");switch(f(u,"art-setting-item-right-tooltip"),y(u,t.tooltip||""),y(d,u),X(t,"$tooltip",{configurable:!0,get:()=>u}),X(t,"tooltip",{configurable:!0,get:()=>u.innerHTML,set(t){u.innerHTML="",y(u,t)}}),o){case"switch":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,n.switchOn),a=y(e,n.switchOff);w(t.switch?a:r,"display","none"),y(d,e),X(t,"$switch",{configurable:!0,get:()=>e});let o=t.switch;X(t,"switch",{configurable:!0,get:()=>o,set(t){o=t,t?(w(a,"display","none"),w(r,"display",null)):(w(a,"display",null),w(r,"display","none"))}});break}case"range":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],f(r,"art-setting-range"),y(d,e),X(t,"$range",{configurable:!0,get:()=>r});let a=[...t.range];X(t,"range",{configurable:!0,get:()=>a,set(t){a=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(t.selector?.length){const t=L("div");f(t,"art-setting-item-right-icon"),y(t,n.arrowRight),y(d,t)}}switch(o){case"switch":if(t.onSwitch){const e=i(l,"click",async e=>{t.switch=await t.onSwitch.call(this.art,t,l,e)});t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=i(t.$range,"change",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onRange.call(this.art,t,l,e)});t.$events.push(e)}if(t.onChange){const e=i(t.$range,"input",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onChange.call(this.art,t,l,e)});t.$events.push(e)}}break;case"selector":{const e=i(l,"click",async e=>{t.selector?.length?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=await t.$parent.onSelect.call(this.art,t,l,e)))});t.$events.push(e),t.default&&f(l,"art-current")}break;case"button":if(t.onClick){const e=i(l,"click",async e=>{t.tooltip=await t.onClick.call(this.art,t,l,e)});t.$events.push(e)}}X(t,"$item",{configurable:!0,get:()=>l}),e?z(l,a):y(r,l),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){if(this.active=t,this.cache.has(t)){$(this.cache.get(t),"art-current")}else{const e=L("div");this.cache.set(t,e),f(e,"art-setting-panel"),y(this.$parent,e),$(e,"art-current"),t[0]?.$parent&&this.createHeader(t[0]);for(let r=0;rnull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){return this.art.template.$video?.textTracks?.[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?x(r,t):w(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?q(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}async switch(t,e={}){const{i18n:r,notice:a,option:o}=this.art,n={...o.subtitle,...e,url:t},i=await this.init(n);return e.name&&(a.show=`${r.get("Switch Subtitle")}: ${e.name}`),i}createTrack(t,e){const{template:r,proxy:a,option:o}=this.art,{$video:n,$track:i}=r,s=L("track");s.default=!0,s.kind=t,s.src=e,s.label=o.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,b(i),y(n,s),r.$track=s,this.destroyEvent=a(this.textTrack,"cuechange",()=>this.update())}async init(t){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(o(t,mt.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||N(t.url)){case"srt":{const e=Q(r);return tt(t.onVttLoad(e))}case"ass":{const e=et(r);return tt(t.onVttLoad(e))}case"vtt":return tt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null}}class Zt{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=u(e.container),V(this.$container,`No container element found by ${e.container}`)),V(I(),"The current browser does not support flex layout");const a=this.$container.tagName.toLowerCase();V("div"===a,`Unsupported container element type, only support 'div' but got '${a}'`),V(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${n}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return u(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=Zt.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);V(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),z(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&f(this.$player,"art-backdrop"),p&&f(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":f(this.$player,"art-destroy")}}const Jt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class Qt{on(t,e,r){const a=this.e||(this.e={});let o=Jt(a,t)?a[t]:void 0;return o||(o=[],Object.defineProperty(a,t,{value:o,enumerable:!0,configurable:!0,writable:!0})),o.push({fn:e,ctx:r}),this}once(t,e,r){const a=this,o=e;let n=!1;function i(...e){n||(n=!0,a.off(t,i),o.apply(r,e))}return i._=e,this.on(t,i,r)}emit(t,...e){const r=this.e||(this.e={}),a=(Jt(r,t)&&r[t]||[]).slice();for(const o of a)o.fn.apply(o.ctx,e);return this}off(t,e){const r=this.e||(this.e={}),a=Jt(r,t)?r[t]:void 0,o=[];if(a&&e)for(let n=0,i=a.length;ne.call(this,this)),re.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${re.version}`);for(let e=0;et(`Event@${e.type}`))}ee.push(this)}static get instances(){return ee}static get version(){return n}static get config(){return i}static get utils(){return nt}static get scheme(){return mt}static get Emitter(){return Qt}static get validator(){return o}static get kindOf(){return o.kindOf}static get html(){return Zt.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:l?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:navigator?.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){re.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),ee.splice(ee.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return re.STYLE=Gt,re.DEBUG=!1,re.CONTEXTMENU=!0,re.NOTICE_TIME=2e3,re.SETTING_WIDTH=250,re.SETTING_ITEM_WIDTH=200,re.SETTING_ITEM_HEIGHT=35,re.RESIZE_TIME=200,re.SCROLL_TIME=200,re.SCROLL_GAP=50,re.AUTO_PLAYBACK_MAX=10,re.AUTO_PLAYBACK_MIN=5,re.AUTO_PLAYBACK_TIMEOUT=3e3,re.RECONNECT_TIME_MAX=5,re.RECONNECT_SLEEP_TIME=1e3,re.CONTROL_HIDE_TIME=3e3,re.DBCLICK_TIME=300,re.DBCLICK_FULLSCREEN=!0,re.MOBILE_DBCLICK_PLAY=!0,re.MOBILE_CLICK_PLAY=!1,re.AUTO_ORIENTATION_TIME=200,re.INFO_LOOP_TIME=1e3,re.FAST_FORWARD_VALUE=3,re.FAST_FORWARD_TIME=1e3,re.TOUCH_MOVE_RATIO=.5,re.VOLUME_STEP=.1,re.SEEK_STEP=5,re.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],re.ASPECT_RATIO=["default","4:3","16:9"],re.FLIP=["normal","horizontal","vertical"],re.FULLSCREEN_WEB_IN_BODY=!0,re.LOG_VERSION=!0,re.USE_RAF=!1,re.REMOVE_SRC_WHEN_DESTROY=!0,h&&(window.Artplayer=re,M("artplayer-style",Gt),setTimeout(()=>{re.LOG_VERSION&&console.log(`%c ArtPlayer %c ${re.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),re}); diff --git a/docs/compiled/artplayer.legacy.js b/docs/compiled/artplayer.legacy.js index 7fdf2363d..6f456b7bc 100644 --- a/docs/compiled/artplayer.legacy.js +++ b/docs/compiled/artplayer.legacy.js @@ -4,4 +4,4 @@ * (c) 2017-2026 Harvey Zhao * Released under the MIT License. */ -!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2=1,k=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(y)||x,$="undefined"!==typeof window&&"undefined"!==typeof document;function T(t,e=document){return e.querySelector(t)}function E(t,e=document){return Array.from(e.querySelectorAll(t))}function C(t,e){return t.classList.add(e)}function z(t,e){return t.classList.remove(e)}function L(t,e){return t.classList.contains(e)}function S(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function M(t){return t.parentNode.removeChild(t)}function I(t,e,r){return t.style[e]=r,t}function P(t,e){for(const r in e)I(t,r,e[r]);return t}function A(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function O(t,e){A(t).forEach(t=>z(t,e)),C(t,e)}function R(t,e,r="top"){k||(t.setAttribute("aria-label",e),C(t,"hint--rounded"),C(t,`hint--${r}`))}function _(t,e=0){const r=t.getBoundingClientRect(),o=window.innerHeight||document.documentElement.clientHeight,a=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=o&&r.top+r.height+e>=0,i=r.left-e<=a+e&&r.left+r.width+e>=0;return n&&i}function V(t,e){return j(t).includes(e)}function Y(t,e){return e.parentNode.replaceChild(t,e),t}function N(t){return document.createElement(t)}function D(t="",e=""){const r=N("i");return C(r,"art-icon"),C(r,`art-icon-${t}`),S(r,e),r}function F(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function B(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function H(t){return t.getBoundingClientRect()}function W(t,e){return new Promise((r,o)=>{const a=new Image;a.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=a.width*e,n.height=a.height*e,i.drawImage(a,0,0,n.width,n.height),n.toBlob(e=>{const a=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(a),o(new Error(`Image load failed: ${t}`))},n.src=a})}else r(a)},a.onerror=function(){o(new Error(`Image load failed: ${t}`))},a.src=t})}function j(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function U(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class q extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function X(t,e){if(!t)throw new q(e);return t}function G(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function K(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function Z(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function J(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function Q(t){return t.charAt(0).toUpperCase()+t.slice(1)}function tt(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),o=Math.floor(t-3600*e-60*r);return(e>0?[e,r,o]:[r,o]).map(t=>t<10?`0${t}`:String(t)).join(":")}const et={"&":"&","<":"<",">":">","'":"'",'"':"""},rt={"&":"&","<":"<",">":">","'":"'",""":'"'},ot=/(&|<|>|'|")/g;function at(t){return t.replace(/[&<>'"]/g,t=>et[t]||t)}const nt=Object.defineProperty,{hasOwnProperty:it}=Object.prototype;function st(t,e){return it.call(t,e)}function lt(t,e){return Object.getOwnPropertyDescriptor(t,e)}function ct(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(o=>{const a=t[o],n=r[o];let i;i=Array.isArray(a)&&Array.isArray(n)?a.concat(...n):e(a)&&e(n)?ct(a,n):n,nt(t,o,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function dt(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let o=r.slice(0,3);return 1===r.length&&(o=`${r}00`),2===r.length&&(o=`${r}0`),`${e},${o}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function pt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function ht(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const o=t.match(e);if(!o)return null;const[,a="",n="",,,i=""]=o;return{start:r(a.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function ut(t=0){return new Promise(e=>setTimeout(e,t))}function mt(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,o)),e)}}function ft(t,e){let r=!1;return function(...o){r||(t.apply(this,o),r=!0,setTimeout(()=>{r=!1},e))}}const gt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:q,addClass:C,append:S,assToVtt:ht,capitalize:Q,clamp:J,createElement:N,debounce:mt,def:nt,download:Z,errorHandle:X,escape:at,get:lt,getComposedPath:j,getExt:K,getIcon:D,getRect:H,getSafeAreaInsets:U,getStyle:function(t,e,r=!0){const o=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(o):o},has:st,hasClass:L,includeFromEvent:V,inverseClass:O,isBrowser:$,isIOS:w,isIOS13:x,isInViewport:_,isMobile:k,isSafari:b,loadImg:W,mergeDeep:ct,query:T,queryAll:E,remove:M,removeClass:z,replaceElement:Y,secondToTime:tt,setStyle:I,setStyleText:F,setStyles:P,siblings:A,silencePromise:G,sleep:ut,srtToVtt:dt,supportsFlex:B,throttle:ft,tooltip:R,unescape:function(t){return t.replace(ot,t=>rt[t]||t)},userAgent:y,vttToBlob:pt},Symbol.toStringTag,{value:"Module"})),vt="array",yt="boolean",bt="string",wt="number",xt="object",kt="function";function $t(t,e,r){return X(e===bt||e===wt||t instanceof Element,`${r.join(".")} require '${bt}' or 'Element' type`)}const Tt={html:$t,disable:`?${yt}`,name:`?${bt}`,index:`?${wt}`,style:`?${xt}`,click:`?${kt}`,mounted:`?${kt}`,tooltip:`?${bt}|${wt}`,width:`?${wt}`,selector:`?${vt}`,onSelect:`?${kt}`,switch:`?${yt}`,onSwitch:`?${kt}`,range:`?${vt}`,onRange:`?${kt}`,onChange:`?${kt}`},Et={id:bt,container:$t,url:bt,poster:bt,type:bt,theme:bt,lang:bt,volume:wt,isLive:yt,muted:yt,autoplay:yt,autoSize:yt,autoMini:yt,loop:yt,flip:yt,playbackRate:yt,aspectRatio:yt,screenshot:yt,setting:yt,hotkey:yt,pip:yt,mutex:yt,backdrop:yt,fullscreen:yt,fullscreenWeb:yt,subtitleOffset:yt,miniProgressBar:yt,useSSR:yt,playsInline:yt,lock:yt,gesture:yt,fastForward:yt,autoPlayback:yt,autoOrientation:yt,airplay:yt,proxy:`?${kt}`,plugins:[kt],layers:[Tt],contextmenu:[Tt],settings:[Tt],controls:[c(l({},Tt),{position:(t,e,r)=>{const o=["top","left","right"];return X(o.includes(t),`${r.join(".")} only accept ${o.toString()} as parameters`)}})],quality:[{default:`?${yt}`,html:bt,url:bt}],highlight:[{time:wt,text:bt}],thumbnails:{url:bt,number:wt,column:wt,width:wt,height:wt,scale:wt},subtitle:{url:bt,name:bt,type:bt,style:xt,escape:yt,encoding:bt,onVttLoad:kt},moreVideoAttr:xt,i18n:xt,icons:xt,cssVar:xt,customType:xt};class Ct{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return L(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?C(e,r):z(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",f(e,Tt),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;X(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const o=N("div");C(o,`art-${this.name}`),C(o,`art-${this.name}-${r}`);const a=Array.from(this.$parent.children);o.dataset.index=e.index||this.id;const n=a.find(t=>Number(t.dataset.index)>=Number(o.dataset.index));n?n.insertAdjacentElement("beforebegin",o):S(this.$parent,o),e.html&&S(o,e.html),e.style&&P(o,e.style),e.tooltip&&R(o,e.tooltip);const i=[];if(e.click){const t=this.art.events.proxy(o,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});i.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,o,i),this[r]=o,this.cache.set(r,{$ref:o,events:i,option:e}),e.mounted&&e.mounted.call(this.art,o),o}remove(t){X(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],M(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class zt extends Ct{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,k||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:o}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:o}}=e,a=o.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return c(l({},t),{html:`${r.get("Play Speed")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.playbackRate=Number(o),t.show=!1)},mounted:t=>{const r=T('[data-value="1"]',t);r&&O(r,"art-current"),e.on("video:ratechange",()=>{const r=E("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&O(r,"art-current")})}})}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:o}}=e,a=o.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return c(l({},t),{html:`${r.get("Aspect Ratio")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.aspectRatio=o,t.show=!1)},mounted:t=>{const r=T('[data-value="default"]',t);r&&O(r,"art-current"),e.on("aspectRatio",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&O(r,"art-current")})}})}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:o}}=e,a=o.map(t=>`${r.get(Q(t))}`).join("");return c(l({},t),{html:`${r.get("Video Flip")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.flip=o.toLowerCase(),t.show=!1)},mounted:t=>{const r=T('[data-value="normal"]',t);r&&O(r,"art-current"),e.on("flip",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&O(r,"art-current")})}})}}({name:"flip",index:30})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return c(l({},t),{html:`ArtPlayer ${g}`})}({name:"version",index:50})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let a=0;a{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,a=t.clientY,{height:n,width:i,left:s,top:l}=H(r),{height:c,width:d}=H(o);let p=e-s,h=a-l;e+d>s+i&&(p=i-d),a+c>l+n&&(h=n-c),P(o,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{V(t,o)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function Lt(t,e){const{$progress:r}=t.template,{left:o}=H(r),a=J((k?e.touches[0].clientX:e.clientX)-o,0,r.clientWidth),n=a/r.clientWidth*t.duration;return{second:n,time:tt(n),width:a,percentage:J(a/r.clientWidth,0,1)}}function St(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,o=r*t.duration;t.emit("setBar","played",r,e),t.seek=o}else{const{second:r,percentage:o}=Lt(t,e);t.emit("setBar","played",o,e),t.seek=r}}function Mt(t){return e=>{const{icons:r,option:o,proxy:a}=e,{$player:n,$progress:i}=e.template;return c(l({},t),{html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=T(".art-progress-hover",t),d=T(".art-progress-loaded",t),p=T(".art-progress-played",t),h=T(".art-progress-highlight",t),u=T(".art-progress-indicator",t),m=T(".art-progress-tip",t);function f(r,o){const{width:a,time:n}=o||Lt(e,r);m.textContent=n||"00:00";const i=m.clientWidth;a<=i/2?I(m,"left",0):a>t.clientWidth-i/2?I(m,"left",t.clientWidth-i+"px"):I(m,"left",a-i/2+"px")}r.indicator?S(u,r.indicator):I(u,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,o,a){const i="played"===r&&a&&k;if("loaded"===r&&I(d,"width",100*o+"%"),"hover"===r&&(I(c,"width",100*o+"%"),V(a,h)?function(r){const{width:o}=Lt(e,r),{text:a}=r.target.dataset;m.textContent=a;const n=m.clientWidth;o<=n/2?I(m,"left",0):o>t.clientWidth-n/2?I(m,"left",t.clientWidth-n+"px"):I(m,"left",o-n/2+"px")}(a):f(a),0===o?z(n,"art-progress-hover"):C(n,"art-progress-hover")),"played"===r&&(I(p,"width",100*o+"%"),I(u,"left",100*o+"%")),i){C(n,"art-progress-hover");f(a,{width:t.clientWidth*o,time:tt(o*e.duration)}),clearTimeout(s),s=setTimeout(()=>{z(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){h.textContent="";for(let t=0;t`;S(h,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),k||(a(i,"click",t=>{t.target!==u&&St(e,t)}),a(i,"mousemove",t=>{const{percentage:r}=Lt(e,t);e.emit("setBar","hover",r,t)}),a(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),a(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:o}=Lt(e,t);e.emit("setBar","played",o,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}})}}class It extends Ct{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:o}=this.art.template;t.on("mousemove",()=>{k||(this.show=!0)}),t.on("click",()=>{k?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=V(t,o)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(z(r,"art-hide-cursor"),C(r,"art-hover"),this.timer=Date.now()):(C(r,"art-hide-cursor"),z(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(Mt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.play),i=S(t,o.pause);function s(){I(n,"display","flex"),I(i,"display","none")}function l(){I(n,"display","none"),I(i,"display","flex")}R(n,a.get("Play")),R(i,a.get("Pause")),r(n,"click",()=>{G(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o}=e,a=S(t,o.volume),n=S(t,o.volumeClose),i=S(t,'
'),s=S(i,'
'),l=S(s,'
'),c=S(s,'
'),d=S(c,'
'),p=S(d,'
'),h=S(c,'
');function u(t){const{top:e,height:r}=H(c);return 1-(t.clientY-e)/r}function m(){if(e.muted||0===e.volume)I(a,"display","none"),I(n,"display","flex"),I(h,"top","100%"),I(p,"top","100%"),l.textContent=0;else{const t=100*e.volume;I(a,"display","flex"),I(n,"display","none"),I(h,"top",100-t+"%"),I(p,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(m(),e.on("video:volumechange",m),r(a,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),k)I(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=u(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=u(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>c(l({},t),{style:k?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${tt(e.currentTime)} / ${tt(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const o=["video:loadedmetadata","video:timeupdate","video:progress"];for(let a=0;a{this.art.quality=t.quality}),t.screenshot&&!k&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{R(t,a.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{R(t,a.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenWebOn),i=S(t,o.fullscreenWebOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(R(t,a.get("Exit Web Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Web Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenOn),i=S(t,o.fullscreenOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(R(t,a.get("Exit Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),nt(e,"$control_item",{get:()=>r}),nt(e,"$control_value",{get:()=>a})}const i=o(n,"click",e=>d(this,null,function*(){const r=j(e),o=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(o),t.onSelect&&(a.innerHTML=yield t.onSelect.call(this.art,o,o.$control_item,e))}));r.push(i)}}function Pt(t,e,r,o){const a=e-o,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(a)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,a);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class At{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:o,$video:a}}=t;function n(e){V(e,o)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(a,"click",e=>{const o=Date.now();i.push(o);const{MOBILE_CLICK_PLAY:a,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>o-t<=n);switch(c.length){case 1:t.emit("click",e),k?!t.isLock&&a&&G(t.toggle()):G(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),k?!t.isLock&&s&&G(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{C(r,"art-hover"),t.emit("hover",!0,e)},e=>{z(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:o}=t;t.on("resize",()=>{const{aspectRatio:e,notice:o}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,o.show=""});const a=mt(()=>t.emit("resize"),o.RESIZE_TIME);t.on("window:orientationchange",()=>a()),t.on("window:resize",()=>a()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>a())}(t,this),function(t,e){if(k&&!t.option.isLive){const{$video:r,$progress:o}=t.template;let a=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){a===o&&St(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:o,pageY:n}=e.touches[0],c=Pt(i,s,o,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=J((o-i)/t.width,-1,1),d=J((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=a===r?t.constructor.TOUCH_MOVE_RATIO:1,u=J(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",J(u/t.duration,0,1),e),t.notice.show=`${tt(u)} / ${tt(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,a=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{a=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(o,"touchstart",t=>{a=o,c(t)}),e.proxy(o,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:o}}=t,a=ft(()=>{t.emit("view",_(o,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>a()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],o=["resize","scroll","orientationchange"],a=[];function n(n={}){for(let t=0;t{const o=n.document||i.ownerDocument||document,s=e.proxy(o,r,e=>{t.emit(`document:${r}`,e)});a.push(s)}),o.forEach(r=>{var o;const s=n.window||(null==(o=i.ownerDocument)?void 0:o.defaultView)||window,l=e.proxy(s,r,e=>{t.emit(`window:${r}`,e)});a.push(l)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,o={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,o));t.addEventListener(e,r,o);const a=()=>t.removeEventListener(e,r,o);return this.destroyEvents.add(a),a}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class Ot{constructor(t){this.art=t,this.keys={},k||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{G(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n'},t.option.icons);for(const r in e)nt(this,r,{get:()=>D(r,e[r])})}}class Yt extends Ct{constructor(t){super(t),this.name="info",k||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:o,$video:a}}=this.art;t(o,"click",()=>{this.show=!1});let n=null;const i=E("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{I(a,"display","none"),I(n,"display",null)}),o.proxy(e.$state,"click",()=>G(t.play()))}}class Bt{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:o}}=this.art;t?(o.textContent=t instanceof Error?t.message.trim():t,C(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{o.textContent="",z(r,"art-notice-show")},e.NOTICE_TIME)):z(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Ht=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Wt=(()=>{if("undefined"===typeof document)return!1;const t=Ht[0],e={};for(const r of Ht){if(r[1]in document){for(const[o,a]of r.entries())e[t[o]]=a;return e}}return!1})(),jt={change:Wt.fullscreenchange,error:Wt.fullscreenerror},Ut={request:(t=document.documentElement,e)=>new Promise((r,o)=>{const a=()=>{Ut.off("change",a),r()};Ut.on("change",a);const n=t[Wt.requestFullscreen](e);n instanceof Promise&&n.then(a).catch(o)}),exit:()=>new Promise((t,e)=>{if(!Ut.isFullscreen)return void t();const r=()=>{Ut.off("change",r),t()};Ut.on("change",r);const o=document[Wt.exitFullscreen]();o instanceof Promise&&o.then(r).catch(e)}),toggle:(t,e)=>Ut.isFullscreen?Ut.exit():Ut.request(t,e),onchange(t){Ut.on("change",t)},onerror(t){Ut.on("error",t)},on(t,e){const r=jt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=jt[t];r&&document.removeEventListener(r,e,!1)},raw:Wt};function qt(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t,n=t=>{Ut.on("change",()=>{t.emit("fullscreen",Ut.isFullscreen),Ut.isFullscreen?(t.state="fullscreen",C(a,"art-fullscreen")):z(a,"art-fullscreen"),t.emit("resize")}),Ut.on("error",e=>{t.emit("fullscreenError",e)}),nt(t,"fullscreen",{get:()=>Ut.isFullscreen,set(t){return d(this,null,function*(){t?yield Ut.request(a):yield Ut.exit()})}})};t.once("video:loadedmetadata",()=>{var a;Ut.isEnabled?n(t):o.webkitSupportsFullscreen?((a=t).on("document:webkitfullscreenchange",()=>{a.emit("fullscreen",a.fullscreen),a.emit("resize")}),nt(a,"fullscreen",{get:()=>document.fullscreenElement===o,set(t){t?(a.state="fullscreen",o.webkitEnterFullscreen()):o.webkitExitFullscreen()}})):nt(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),nt(t,"fullscreen",lt(t,"fullscreen"))})}function Xt(t){const{icons:e,proxy:r,storage:o,template:{$player:a,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(z(a,"art-mini"),I(e,"display","none"),a.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(I(e,"display","none"),I(r,"display","flex")):(I(e,"display","flex"),I(r,"display","none"))}function p(){const{$mini:e}=t.template,r=H(e),a=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;o.set("top",a),o.set("left",n),I(e,"top",`${a}px`),I(e,"left",`${n}px`)}nt(t,"mini",{get:()=>L(a,"art-mini"),set(h){if(h){t.state="mini",C(a,"art-mini");const h=function(){const{$mini:a}=t.template;if(a)return S(a,n),I(a,"display","flex");{const a=N("div");C(a,"art-mini-popup"),S(document.body,a),t.template.$mini=a,S(a,n);const p=S(a,'
');S(p,e.close),r(p,"click",c);const h=S(a,'
'),u=S(h,e.play),m=S(h,e.pause);return r(u,"click",()=>G(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(a,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){C(a,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;I(a,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,z(a,"art-mini-dragging");const t=H(a);o.set("left",t.left),o.set("top",t.top),I(a,"left",`${t.left}px`),I(a,"top",`${t.top}px`),I(a,"transform",null)}}),a}}(),u=o.get("top"),m=o.get("left");"number"===typeof u&&"number"===typeof m?(I(h,"top",`${u}px`),I(h,"left",`${m}px`),_(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Gt(t){const{i18n:e,notice:r,template:{$video:o}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:o}=t;e.disablePictureInPicture=!1,nt(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw o.show=t,t})):document.exitPictureInPicture().catch(t=>{throw o.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):o.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),nt(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):nt(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Kt(t){const{option:e,template:{$progress:r,$video:o}}=t;let a=null,n=!1,i=null;t.on("setBar",(a,s,l)=>d(null,null,function*(){var c;const d=null==(c=t.controls)?void 0:c.thumbnails,{url:p,scale:h}=e.thumbnails;if(!d||!p)return;if("hover"===a||"played"===a&&l&&k){if(i||n||(n=!0,i=yield W(p,h),n=!1),!i)return;const a=r.clientWidth*s;a>0&&ar.clientWidth-u/2?I(s,"left",r.clientWidth-u+"px"):I(s,"left",a-u/2+"px")}(a)}})),nt(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(a),a=null,n=!1,i=null)}})}Object.defineProperties(Ut,{isFullscreen:{get:()=>Boolean(document[Wt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Wt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Wt.fullscreenEnabled])}});class Zt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;nt(t,"url",{get:()=>r.src,set(o){return d(this,null,function*(){if(o){const a=t.url,n=e.type||K(o),i=e.customType[n];n&&i?(yield ut(),t.loading.show=!0,i.call(t,r,o,t)):(URL.revokeObjectURL(a),r.src=o),a!==t.url&&(t.option.url=o,t.isReady&&a&&t.once("video:canplay",()=>{t.emit("restart",o)}))}else yield ut(),t.loading.show=!0})}})}(t),function(t){const{template:{$video:e}}=t;nt(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:o,constructor:{instances:a},template:{$video:n}}=t;nt(t,"play",{value(){return d(this,null,function*(){const i=yield n.play();if(r.show=e.get("Play"),t.emit("play"),o.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;nt(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${tt(t.currentTime)} / ${tt(t.duration)}`),t.emit("seek",t.currentTime,r)}}),nt(t,"forward",{set(e){t.seek=t.currentTime+e}}),nt(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:o,storage:a}=t;nt(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=J(t,0,1),o.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&a.set("volume",e.volume)}}),nt(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;nt(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=J(r,0,t.duration))}})}(t),function(t){nt(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((o,a)=>{if(e===t.url)return void o();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),a(e)},metadata:()=>{t.currentTime=r},canplay:()=>d(null,null,function*(){t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&(yield G(t.play())),t.notice.show="",o()})};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}nt(t,"switchQuality",{value:r=>e(r,t.currentTime)}),nt(t,"switchUrl",{value:t=>e(t,0)}),nt(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:o}=t;nt(t,"playbackRate",{get:()=>e.playbackRate,set(a){if(a){if(a===e.playbackRate)return;e.playbackRate=a,o.show=`${r.get("Rate")}: ${1===a?r.get("Normal"):`${a}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t;nt(t,"aspectRatio",{get:()=>a.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)I(o,"width",null),I(o,"height",null),I(o,"margin",null),delete a.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=a,i=e/r,s=t[0]/t[1];i>s?(I(o,"width",s*r+"px"),I(o,"height","100%"),I(o,"margin","0 auto")):(I(o,"width","100%"),I(o,"height",e/s+"px"),I(o,"margin","auto 0")),a.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,o=N("canvas");nt(t,"getDataURL",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),t(o.toDataURL("image/png"))}catch(n){e.show=n,a(n)}})}),nt(t,"getBlobUrl",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),o.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,a(n)}})}),nt(t,"screenshot",{value:e=>d(null,null,function*(){const o=yield t.getDataURL();return Z(o,`${e||`artplayer_${tt(r.currentTime)}`}.png`),t.emit("screenshot",o),o})})}(t),qt(t),function(t){const{constructor:e,template:{$container:r,$player:o}}=t;let a="";nt(t,"fullscreenWeb",{get:()=>L(o,"art-fullscreen-web"),set(n){n?(a=o.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&S(document.body,o),t.state="fullscreenWeb",I(o,"width","100%"),I(o,"height","100%"),C(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&S(r,o),a&&(o.style.cssText=a,a=""),z(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Gt(t),function(t){const{$video:e}=t.template;nt(t,"loaded",{get:()=>t.loadedTime/e.duration}),nt(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){nt(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;nt(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:o}=t.template;nt(t,"autoSize",{value(){const{videoWidth:a,videoHeight:n}=o,{width:i,height:s}=H(e),l=a/n;if(i/s>l)I(r,"width",s*l/i*100+"%"),I(r,"height","100%");else{const t=i/l/s*100;I(r,"width","100%"),I(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){nt(t,"rect",{get:()=>H(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[o]})}nt(t,"x",{get:()=>t.left+window.pageXOffset}),nt(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:o}=t;nt(t,"flip",{get:()=>e.dataset.flip||"normal",set(a){a||(a="normal"),"normal"===a?delete e.dataset.flip:e.dataset.flip=a,o.show=`${r.get("Video Flip")}: ${r.get(Q(a))}`,t.emit("flip",a)}})}(t),Xt(t),function(t){const{template:{$poster:e}}=t;nt(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch(t){return""}},set(t){I(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;nt(t,"autoHeight",{value(){const{clientWidth:o}=e,{videoHeight:a,videoWidth:n}=r,i=a*(o/n);I(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;nt(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){nt(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){nt(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];nt(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let o=0;o{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,nt(t,"airplay",{value(){n?(a.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){nt(t,"quality",{set(e){const{controls:r,notice:o,i18n:a}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:(null==n?void 0:n.html)||"",selector:e,onSelect(e){return d(this,null,function*(){return yield t.switchQuality(e.url),o.show=`${a.get("Switch Video")}: ${e.html}`,e.html})}})}})}(t),Kt(t),function(t){const{i18n:e,notice:r,option:o,constructor:a,proxy:n,template:{$player:i,$video:s,$poster:l}}=t;let c=0;for(let d=0;d{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{c=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{o.loop?(t.seek=0,G(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",n=>d(null,null,function*(){c{t.emit("resize"),k&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,I(l,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:o,$poster:a}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(o.volume=J(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(o.volume=J(n,0,1)),e.poster&&I(a,"backgroundImage",`url(${e.poster})`),e.autoplay&&(o.autoplay=e.autoplay),e.playsInline&&(o.playsInline=!0,o["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Jt(t){const{notice:e,constructor:r,template:{$player:o,$video:a}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=a,r=document.documentElement.clientWidth,o=document.documentElement.clientHeight;return t>e&&ro}return t.on("fullscreenWeb",e=>{var a;if(e){if(l()){const e=Number(null!=(a=r.AUTO_ORIENTATION_TIME)?a:0);setTimeout(()=>{t.fullscreenWeb&&!L(o,n)&&function(){const e=U(),r=document.documentElement.clientWidth,a=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;I(o,"width",`${a}px`),I(o,"height",`${i}px`),I(o,"transform-origin","0 0"),I(o,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),C(o,n),t.isRotate=!0,t.emit("resize")}()},e)}}else L(o,n)&&(I(o,"width",""),I(o,"height",""),I(o,"transform-origin",""),I(o,"transform",""),z(o,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",t=>d(null,null,function*(){var r;const a=!!(null==(r=null==screen?void 0:screen.orientation)?void 0:r.lock);if(t){if(a&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";yield screen.orientation.lock(t),s=!0,C(o,i)}catch(n){s=!1,e.show=n}}else if(L(o,i)&&z(o,i),a&&s){try{screen.orientation.unlock()}catch(c){}s=!1}})),{name:"autoOrientation",get state(){return L(o,n)}}}function Qt(t){const{i18n:e,icons:r,storage:o,constructor:a,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=T(".art-auto-playback-last",s),c=T(".art-auto-playback-jump",s),d=T(".art-auto-playback-close",s);S(d,r.close);let p=null;function h(){const r=(o.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),I(s,"display","none"),r&&r>=a.AUTO_PLAYBACK_MIN&&(I(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${tt(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{I(s,"display","none")}),n(c,"click",()=>{t.seek=r,G(t.play()),I(i,"display","none"),I(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{I(s,"display","none")},a.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=o.get("times")||{},r=Object.keys(e);r.length>a.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,o.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return o.get("times")||{}},clear:()=>o.del("times"),delete(t){const e=o.get("times")||{};return delete e[t],o.set("times",e),e}}}function te(t){const{constructor:e,proxy:r,template:{$player:o,$video:a}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,z(o,"art-fast-forward"))};return r(a,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,C(o,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return L(o,"art-fast-forward")}}}function ee(t){const{layers:e,icons:r,template:{$player:o}}=t;function a(){return L(o,"art-lock")}function n(){C(o,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){z(o,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const o=S(e,r.lock),a=S(e,r.unlock);I(o,"display","none"),t.on("lock",t=>{t?(I(o,"display","inline-flex"),I(a,"display","none")):(I(o,"display","none"),I(a,"display","inline-flex"))})},click(){a()?i():n()}}),{name:"lock",get state(){return a()},set state(t){t?n():i()}}}function re(t){return t.on("control",e=>{e?z(t.template.$player,"art-mini-progress-bar"):C(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class oe{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(re),e.lock&&k&&this.add(ee),e.autoPlayback&&!e.isLive&&this.add(Qt),e.autoOrientation&&k&&this.add(Jt),e.fastForward&&k&&!e.isLive&&this.add(te);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return X(!st(this,r),`Cannot add a plugin that already has the same name: ${r}`),nt(this,r,{value:e}),this}}class ae extends Ct{constructor(t){super(t);const{option:e,controls:r,template:{$setting:o}}=t;this.name="setting",this.$parent=o,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=V(t,r.setting),o=V(t,this.$parent);!this.show||e||o||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,PLAYBACK_RATE:a}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:o,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:a.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,ASPECT_RATIO:a}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:o,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:a.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,FLIP:a}}=t;function n(t){return e.get(Q(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:o,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:a.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:o}=t;return{width:o.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){var r;for(let o=0;o{e.default=e===t,e.default&&e.$item&&O(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,o=[]){for(let a=0;ae}),nt(n,"$parents",{get:()=>r}),nt(n,"$option",{get:()=>t});const o=[];nt(n,"$events",{get:()=>o}),nt(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,o)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){var t,e;const{controls:r,constructor:{SETTING_WIDTH:o,SETTING_ITEM_HEIGHT:a},template:{$player:n,$setting:i}}=this.art;if(r.setting&&this.show){const s=(null==(e=null==(t=this.active[0])?void 0:t.$parent)?void 0:e.width)||o,{left:l,width:c}=H(r.setting),{left:d,width:p}=H(n),h=l-d+c/2-s/2;if(I(i,"height",`${this.active===this.option?this.active.length*a:(this.active.length+1)*a}px`),I(i,"width",`${s}px`),this.art.isRotate||k)return;h+s>p?(I(i,"left",null),I(i,"right",null)):(I(i,"left",`${h}px`),I(i,"right","auto"))}}inactivate(t){for(let e=0;e'),s=N("div");C(s,"art-setting-item-left-icon"),S(s,o),S(i,s),S(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),S(e,n)}createItem(t,e=!1){var r,o;if(!this.cache.has(t.$option))return;const a=this.cache.get(t.$option),n=t.$item;let i="selector";st(t,"switch")&&(i="switch"),st(t,"range")&&(i="range"),st(t,"onClick")&&(i="button");const{icons:s,proxy:l,constructor:c}=this.art,p=N("div");C(p,"art-setting-item"),I(p,"height",`${c.SETTING_ITEM_HEIGHT}px`),p.dataset.name=t.name||"",p.dataset.value=t.value||"";const h=S(p,'
'),u=S(p,'
'),m=N("div");switch(C(m,"art-setting-item-left-icon"),i){case"button":case"switch":case"range":S(m,t.icon||s.config);break;case"selector":(null==(r=t.selector)?void 0:r.length)?S(m,t.icon||s.config):S(m,s.check)}S(h,m),nt(t,"$icon",{configurable:!0,get:()=>m}),nt(t,"icon",{configurable:!0,get:()=>m.innerHTML,set(t){m.innerHTML="",S(m,t)}});const f=N("div");C(f,"art-setting-item-left-text"),S(f,t.html||""),S(h,f),nt(t,"$html",{configurable:!0,get:()=>f}),nt(t,"html",{configurable:!0,get:()=>f.innerHTML,set(t){f.innerHTML="",S(f,t)}});const g=N("div");switch(C(g,"art-setting-item-right-tooltip"),S(g,t.tooltip||""),S(u,g),nt(t,"$tooltip",{configurable:!0,get:()=>g}),nt(t,"tooltip",{configurable:!0,get:()=>g.innerHTML,set(t){g.innerHTML="",S(g,t)}}),i){case"switch":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,s.switchOn),o=S(e,s.switchOff);I(t.switch?o:r,"display","none"),S(u,e),nt(t,"$switch",{configurable:!0,get:()=>e});let a=t.switch;nt(t,"switch",{configurable:!0,get:()=>a,set(t){a=t,t?(I(o,"display","none"),I(r,"display",null)):(I(o,"display",null),I(r,"display","none"))}});break}case"range":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],C(r,"art-setting-range"),S(u,e),nt(t,"$range",{configurable:!0,get:()=>r});let o=[...t.range];nt(t,"range",{configurable:!0,get:()=>o,set(t){o=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(null==(o=t.selector)?void 0:o.length){const t=N("div");C(t,"art-setting-item-right-icon"),S(t,s.arrowRight),S(u,t)}}switch(i){case"switch":if(t.onSwitch){const e=l(p,"click",e=>d(this,null,function*(){t.switch=yield t.onSwitch.call(this.art,t,p,e)}));t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=l(t.$range,"change",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onRange.call(this.art,t,p,e)}));t.$events.push(e)}if(t.onChange){const e=l(t.$range,"input",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onChange.call(this.art,t,p,e)}));t.$events.push(e)}}break;case"selector":{const e=l(p,"click",e=>d(this,null,function*(){var r;(null==(r=t.selector)?void 0:r.length)?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=yield t.$parent.onSelect.call(this.art,t,p,e)))}));t.$events.push(e),t.default&&C(p,"art-current")}break;case"button":if(t.onClick){const e=l(p,"click",e=>d(this,null,function*(){t.tooltip=yield t.onClick.call(this.art,t,p,e)}));t.$events.push(e)}}nt(t,"$item",{configurable:!0,get:()=>p}),e?Y(p,n):S(a,p),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){var e;if(this.active=t,this.cache.has(t)){O(this.cache.get(t),"art-current")}else{const r=N("div");this.cache.set(t,r),C(r,"art-setting-panel"),S(this.$parent,r),O(r,"art-current"),(null==(e=t[0])?void 0:e.$parent)&&this.createHeader(t[0]);for(let e=0;enull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){var t,e;return null==(e=null==(t=this.art.template.$video)?void 0:t.textTracks)?void 0:e[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?P(r,t):I(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?at(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}switch(t){return d(this,arguments,function*(t,e={}){const{i18n:r,notice:o,option:a}=this.art,n=c(l(l({},a.subtitle),e),{url:t}),i=yield this.init(n);return e.name&&(o.show=`${r.get("Switch Subtitle")}: ${e.name}`),i})}createTrack(t,e){const{template:r,proxy:o,option:a}=this.art,{$video:n,$track:i}=r,s=N("track");s.default=!0,s.kind=t,s.src=e,s.label=a.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,M(i),S(n,s),r.$track=s,this.destroyEvent=o(this.textTrack,"cuechange",()=>this.update())}init(t){return d(this,null,function*(){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(f(t,Et.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||K(t.url)){case"srt":{const e=dt(r);return pt(t.onVttLoad(e))}case"ass":{const e=ht(r);return pt(t.onVttLoad(e))}case"vtt":return pt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null})}}class le{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=T(e.container),X(this.$container,`No container element found by ${e.container}`)),X(B(),"The current browser does not support flex layout");const o=this.$container.tagName.toLowerCase();X("div"===o,`Unsupported container element type, only support 'div' but got '${o}'`),X(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${g}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return T(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=le.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);X(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),Y(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&C(this.$player,"art-backdrop"),k&&C(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":C(this.$player,"art-destroy")}}class ce{on(t,e,r){const o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:r}),this}once(t,e,r){const o=this;function a(...n){o.off(t,a),e.apply(r,n)}return a._=e,this.on(t,a,r)}emit(t,...e){const r=((this.e||(this.e={}))[t]||[]).slice();for(let o=0;oe.call(this,this)),he.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${he.version}`);for(let e=0;et(`Event@${e.type}`))}pe.push(this)}static get instances(){return pe}static get version(){return g}static get config(){return v}static get utils(){return gt}static get scheme(){return Et}static get Emitter(){return ce}static get validator(){return f}static get kindOf(){return f.kindOf}static get html(){return le.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:b?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:null==navigator?void 0:navigator.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){he.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),pe.splice(pe.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return he.STYLE=ie,he.DEBUG=!1,he.CONTEXTMENU=!0,he.NOTICE_TIME=2e3,he.SETTING_WIDTH=250,he.SETTING_ITEM_WIDTH=200,he.SETTING_ITEM_HEIGHT=35,he.RESIZE_TIME=200,he.SCROLL_TIME=200,he.SCROLL_GAP=50,he.AUTO_PLAYBACK_MAX=10,he.AUTO_PLAYBACK_MIN=5,he.AUTO_PLAYBACK_TIMEOUT=3e3,he.RECONNECT_TIME_MAX=5,he.RECONNECT_SLEEP_TIME=1e3,he.CONTROL_HIDE_TIME=3e3,he.DBCLICK_TIME=300,he.DBCLICK_FULLSCREEN=!0,he.MOBILE_DBCLICK_PLAY=!0,he.MOBILE_CLICK_PLAY=!1,he.AUTO_ORIENTATION_TIME=200,he.INFO_LOOP_TIME=1e3,he.FAST_FORWARD_VALUE=3,he.FAST_FORWARD_TIME=1e3,he.TOUCH_MOVE_RATIO=.5,he.VOLUME_STEP=.1,he.SEEK_STEP=5,he.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],he.ASPECT_RATIO=["default","4:3","16:9"],he.FLIP=["normal","horizontal","vertical"],he.FULLSCREEN_WEB_IN_BODY=!0,he.LOG_VERSION=!0,he.USE_RAF=!1,he.REMOVE_SRC_WHEN_DESTROY=!0,$&&(window.Artplayer=he,F("artplayer-style",ie),setTimeout(()=>{he.LOG_VERSION&&console.log(`%c ArtPlayer %c ${he.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),he}); +!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2=1,k=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(y)||x,$="undefined"!==typeof window&&"undefined"!==typeof document;function T(t,e=document){return e.querySelector(t)}function E(t,e=document){return Array.from(e.querySelectorAll(t))}function C(t,e){return t.classList.add(e)}function z(t,e){return t.classList.remove(e)}function L(t,e){return t.classList.contains(e)}function S(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function M(t){return t.parentNode.removeChild(t)}function I(t,e,r){return t.style[e]=r,t}function P(t,e){for(const r in e)I(t,r,e[r]);return t}function O(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function A(t,e){O(t).forEach(t=>z(t,e)),C(t,e)}function R(t,e,r="top"){k||(t.setAttribute("aria-label",e),C(t,"hint--rounded"),C(t,`hint--${r}`))}function _(t,e=0){const r=t.getBoundingClientRect(),o=window.innerHeight||document.documentElement.clientHeight,a=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=o&&r.top+r.height+e>=0,i=r.left-e<=a+e&&r.left+r.width+e>=0;return n&&i}function V(t,e){return j(t).includes(e)}function Y(t,e){return e.parentNode.replaceChild(t,e),t}function N(t){return document.createElement(t)}function D(t="",e=""){const r=N("i");return C(r,"art-icon"),C(r,`art-icon-${t}`),S(r,e),r}function F(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function B(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function H(t){return t.getBoundingClientRect()}function W(t,e){return new Promise((r,o)=>{const a=new Image;a.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=a.width*e,n.height=a.height*e,i.drawImage(a,0,0,n.width,n.height),n.toBlob(e=>{const a=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(a),o(new Error(`Image load failed: ${t}`))},n.src=a})}else r(a)},a.onerror=function(){o(new Error(`Image load failed: ${t}`))},a.src=t})}function j(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function U(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class q extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function X(t,e){if(!t)throw new q(e);return t}function G(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function K(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function Z(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function J(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function Q(t){return t.charAt(0).toUpperCase()+t.slice(1)}function tt(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),o=Math.floor(t-3600*e-60*r);return(e>0?[e,r,o]:[r,o]).map(t=>t<10?`0${t}`:String(t)).join(":")}const et={"&":"&","<":"<",">":">","'":"'",'"':"""},rt={"&":"&","<":"<",">":">","'":"'",""":'"'},ot=/(&|<|>|'|")/g;function at(t){return t.replace(/[&<>'"]/g,t=>et[t]||t)}const nt=Object.defineProperty,{hasOwnProperty:it}=Object.prototype;function st(t,e){return it.call(t,e)}function lt(t,e){return Object.getOwnPropertyDescriptor(t,e)}function ct(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(o=>{const a=t[o],n=r[o];let i;i=Array.isArray(a)&&Array.isArray(n)?a.concat(...n):e(a)&&e(n)?ct(a,n):n,nt(t,o,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function dt(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let o=r.slice(0,3);return 1===r.length&&(o=`${r}00`),2===r.length&&(o=`${r}0`),`${e},${o}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function pt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function ht(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const o=t.match(e);if(!o)return null;const[,a="",n="",,,i=""]=o;return{start:r(a.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function ut(t=0){return new Promise(e=>setTimeout(e,t))}function mt(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,o)),e)}}function ft(t,e){let r=!1;return function(...o){r||(t.apply(this,o),r=!0,setTimeout(()=>{r=!1},e))}}const gt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:q,addClass:C,append:S,assToVtt:ht,capitalize:Q,clamp:J,createElement:N,debounce:mt,def:nt,download:Z,errorHandle:X,escape:at,get:lt,getComposedPath:j,getExt:K,getIcon:D,getRect:H,getSafeAreaInsets:U,getStyle:function(t,e,r=!0){const o=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(o):o},has:st,hasClass:L,includeFromEvent:V,inverseClass:A,isBrowser:$,isIOS:w,isIOS13:x,isInViewport:_,isMobile:k,isSafari:b,loadImg:W,mergeDeep:ct,query:T,queryAll:E,remove:M,removeClass:z,replaceElement:Y,secondToTime:tt,setStyle:I,setStyleText:F,setStyles:P,siblings:O,silencePromise:G,sleep:ut,srtToVtt:dt,supportsFlex:B,throttle:ft,tooltip:R,unescape:function(t){return t.replace(ot,t=>rt[t]||t)},userAgent:y,vttToBlob:pt},Symbol.toStringTag,{value:"Module"})),vt="array",yt="boolean",bt="string",wt="number",xt="object",kt="function";function $t(t,e,r){return X(e===bt||e===wt||t instanceof Element,`${r.join(".")} require '${bt}' or 'Element' type`)}const Tt={html:$t,disable:`?${yt}`,name:`?${bt}`,index:`?${wt}`,style:`?${xt}`,click:`?${kt}`,mounted:`?${kt}`,tooltip:`?${bt}|${wt}`,width:`?${wt}`,selector:`?${vt}`,onSelect:`?${kt}`,switch:`?${yt}`,onSwitch:`?${kt}`,range:`?${vt}`,onRange:`?${kt}`,onChange:`?${kt}`},Et={id:bt,container:$t,url:bt,poster:bt,type:bt,theme:bt,lang:bt,volume:wt,isLive:yt,muted:yt,autoplay:yt,autoSize:yt,autoMini:yt,loop:yt,flip:yt,playbackRate:yt,aspectRatio:yt,screenshot:yt,setting:yt,hotkey:yt,pip:yt,mutex:yt,backdrop:yt,fullscreen:yt,fullscreenWeb:yt,subtitleOffset:yt,miniProgressBar:yt,useSSR:yt,playsInline:yt,lock:yt,gesture:yt,fastForward:yt,autoPlayback:yt,autoOrientation:yt,airplay:yt,proxy:`?${kt}`,plugins:[kt],layers:[Tt],contextmenu:[Tt],settings:[Tt],controls:[c(l({},Tt),{position:(t,e,r)=>{const o=["top","left","right"];return X(o.includes(t),`${r.join(".")} only accept ${o.toString()} as parameters`)}})],quality:[{default:`?${yt}`,html:bt,url:bt}],highlight:[{time:wt,text:bt}],thumbnails:{url:bt,number:wt,column:wt,width:wt,height:wt,scale:wt},subtitle:{url:bt,name:bt,type:bt,style:xt,escape:yt,encoding:bt,onVttLoad:kt},moreVideoAttr:xt,i18n:xt,icons:xt,cssVar:xt,customType:xt};class Ct{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return L(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?C(e,r):z(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",f(e,Tt),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;X(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const o=N("div");C(o,`art-${this.name}`),C(o,`art-${this.name}-${r}`);const a=Array.from(this.$parent.children);o.dataset.index=e.index||this.id;const n=a.find(t=>Number(t.dataset.index)>=Number(o.dataset.index));n?n.insertAdjacentElement("beforebegin",o):S(this.$parent,o),e.html&&S(o,e.html),e.style&&P(o,e.style),e.tooltip&&R(o,e.tooltip);const i=[];if(e.click){const t=this.art.events.proxy(o,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});i.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,o,i),this[r]=o,this.cache.set(r,{$ref:o,events:i,option:e}),e.mounted&&e.mounted.call(this.art,o),o}remove(t){X(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],M(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class zt extends Ct{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,k||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:o}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:o}}=e,a=o.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return c(l({},t),{html:`${r.get("Play Speed")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.playbackRate=Number(o),t.show=!1)},mounted:t=>{const r=T('[data-value="1"]',t);r&&A(r,"art-current"),e.on("video:ratechange",()=>{const r=E("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&A(r,"art-current")})}})}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:o}}=e,a=o.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return c(l({},t),{html:`${r.get("Aspect Ratio")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.aspectRatio=o,t.show=!1)},mounted:t=>{const r=T('[data-value="default"]',t);r&&A(r,"art-current"),e.on("aspectRatio",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&A(r,"art-current")})}})}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:o}}=e,a=o.map(t=>`${r.get(Q(t))}`).join("");return c(l({},t),{html:`${r.get("Video Flip")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.flip=o.toLowerCase(),t.show=!1)},mounted:t=>{const r=T('[data-value="normal"]',t);r&&A(r,"art-current"),e.on("flip",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&A(r,"art-current")})}})}}({name:"flip",index:30})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return c(l({},t),{html:`ArtPlayer ${g}`})}({name:"version",index:50})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let a=0;a{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,a=t.clientY,{height:n,width:i,left:s,top:l}=H(r),{height:c,width:d}=H(o);let p=e-s,h=a-l;e+d>s+i&&(p=i-d),a+c>l+n&&(h=n-c),P(o,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{V(t,o)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function Lt(t,e){const{$progress:r}=t.template,{left:o}=H(r),a=J((k?e.touches[0].clientX:e.clientX)-o,0,r.clientWidth),n=a/r.clientWidth*t.duration;return{second:n,time:tt(n),width:a,percentage:J(a/r.clientWidth,0,1)}}function St(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,o=r*t.duration;t.emit("setBar","played",r,e),t.seek=o}else{const{second:r,percentage:o}=Lt(t,e);t.emit("setBar","played",o,e),t.seek=r}}function Mt(t){return e=>{const{icons:r,option:o,proxy:a}=e,{$player:n,$progress:i}=e.template;return c(l({},t),{html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=T(".art-progress-hover",t),d=T(".art-progress-loaded",t),p=T(".art-progress-played",t),h=T(".art-progress-highlight",t),u=T(".art-progress-indicator",t),m=T(".art-progress-tip",t);function f(r,o){const{width:a,time:n}=o||Lt(e,r);m.textContent=n||"00:00";const i=m.clientWidth;a<=i/2?I(m,"left",0):a>t.clientWidth-i/2?I(m,"left",t.clientWidth-i+"px"):I(m,"left",a-i/2+"px")}r.indicator?S(u,r.indicator):I(u,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,o,a){const i="played"===r&&a&&k;if("loaded"===r&&I(d,"width",100*o+"%"),"hover"===r&&(I(c,"width",100*o+"%"),V(a,h)?function(r){const{width:o}=Lt(e,r),{text:a}=r.target.dataset;m.textContent=a;const n=m.clientWidth;o<=n/2?I(m,"left",0):o>t.clientWidth-n/2?I(m,"left",t.clientWidth-n+"px"):I(m,"left",o-n/2+"px")}(a):f(a),0===o?z(n,"art-progress-hover"):C(n,"art-progress-hover")),"played"===r&&(I(p,"width",100*o+"%"),I(u,"left",100*o+"%")),i){C(n,"art-progress-hover");f(a,{width:t.clientWidth*o,time:tt(o*e.duration)}),clearTimeout(s),s=setTimeout(()=>{z(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){h.textContent="";for(let t=0;t`;S(h,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),k||(a(i,"click",t=>{t.target!==u&&St(e,t)}),a(i,"mousemove",t=>{const{percentage:r}=Lt(e,t);e.emit("setBar","hover",r,t)}),a(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),a(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:o}=Lt(e,t);e.emit("setBar","played",o,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}})}}class It extends Ct{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:o}=this.art.template;t.on("mousemove",()=>{k||(this.show=!0)}),t.on("click",()=>{k?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=V(t,o)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(z(r,"art-hide-cursor"),C(r,"art-hover"),this.timer=Date.now()):(C(r,"art-hide-cursor"),z(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(Mt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.play),i=S(t,o.pause);function s(){I(n,"display","flex"),I(i,"display","none")}function l(){I(n,"display","none"),I(i,"display","flex")}R(n,a.get("Play")),R(i,a.get("Pause")),r(n,"click",()=>{G(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o}=e,a=S(t,o.volume),n=S(t,o.volumeClose),i=S(t,'
'),s=S(i,'
'),l=S(s,'
'),c=S(s,'
'),d=S(c,'
'),p=S(d,'
'),h=S(c,'
');function u(t){const{top:e,height:r}=H(c);return 1-(t.clientY-e)/r}function m(){if(e.muted||0===e.volume)I(a,"display","none"),I(n,"display","flex"),I(h,"top","100%"),I(p,"top","100%"),l.textContent=0;else{const t=100*e.volume;I(a,"display","flex"),I(n,"display","none"),I(h,"top",100-t+"%"),I(p,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(m(),e.on("video:volumechange",m),r(a,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),k)I(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=u(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=u(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>c(l({},t),{style:k?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${tt(e.currentTime)} / ${tt(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const o=["video:loadedmetadata","video:timeupdate","video:progress"];for(let a=0;a{this.art.quality=t.quality}),t.screenshot&&!k&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{R(t,a.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{R(t,a.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenWebOn),i=S(t,o.fullscreenWebOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(R(t,a.get("Exit Web Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Web Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenOn),i=S(t,o.fullscreenOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(R(t,a.get("Exit Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),nt(e,"$control_item",{get:()=>r}),nt(e,"$control_value",{get:()=>a})}const i=o(n,"click",e=>d(this,null,function*(){const r=j(e),o=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(o),t.onSelect&&(a.innerHTML=yield t.onSelect.call(this.art,o,o.$control_item,e))}));r.push(i)}}function Pt(t,e,r,o){const a=e-o,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(a)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,a);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class Ot{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:o,$video:a}}=t;function n(e){V(e,o)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(a,"click",e=>{const o=Date.now();i.push(o);const{MOBILE_CLICK_PLAY:a,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>o-t<=n);switch(c.length){case 1:t.emit("click",e),k?!t.isLock&&a&&G(t.toggle()):G(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),k?!t.isLock&&s&&G(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{C(r,"art-hover"),t.emit("hover",!0,e)},e=>{z(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:o}=t;t.on("resize",()=>{const{aspectRatio:e,notice:o}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,o.show=""});const a=mt(()=>t.emit("resize"),o.RESIZE_TIME);t.on("window:orientationchange",()=>a()),t.on("window:resize",()=>a()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>a())}(t,this),function(t,e){if(k&&!t.option.isLive){const{$video:r,$progress:o}=t.template;let a=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){a===o&&St(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:o,pageY:n}=e.touches[0],c=Pt(i,s,o,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=J((o-i)/t.width,-1,1),d=J((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=a===r?t.constructor.TOUCH_MOVE_RATIO:1,u=J(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",J(u/t.duration,0,1),e),t.notice.show=`${tt(u)} / ${tt(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,a=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{a=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(o,"touchstart",t=>{a=o,c(t)}),e.proxy(o,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:o}}=t,a=ft(()=>{t.emit("view",_(o,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>a()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],o=["resize","scroll","orientationchange"],a=[];function n(n={}){for(let t=0;t{const o=n.document||i.ownerDocument||document,s=e.proxy(o,r,e=>{t.emit(`document:${r}`,e)});a.push(s)}),o.forEach(r=>{var o;const s=n.window||(null==(o=i.ownerDocument)?void 0:o.defaultView)||window,l=e.proxy(s,r,e=>{t.emit(`window:${r}`,e)});a.push(l)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,o={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,o));t.addEventListener(e,r,o);const a=()=>t.removeEventListener(e,r,o);return this.destroyEvents.add(a),a}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class At{constructor(t){this.art=t,this.keys={},k||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{G(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n'},t.option.icons);for(const r in e)nt(this,r,{get:()=>D(r,e[r])})}}class Yt extends Ct{constructor(t){super(t),this.name="info",k||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:o,$video:a}}=this.art;t(o,"click",()=>{this.show=!1});let n=null;const i=E("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{I(a,"display","none"),I(n,"display",null)}),o.proxy(e.$state,"click",()=>G(t.play()))}}class Bt{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:o}}=this.art;t?(o.textContent=t instanceof Error?t.message.trim():t,C(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{o.textContent="",z(r,"art-notice-show")},e.NOTICE_TIME)):z(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Ht=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Wt=(()=>{if("undefined"===typeof document)return!1;const t=Ht[0],e={};for(const r of Ht){if(r[1]in document){for(const[o,a]of r.entries())e[t[o]]=a;return e}}return!1})(),jt={change:Wt.fullscreenchange,error:Wt.fullscreenerror},Ut={request:(t=document.documentElement,e)=>new Promise((r,o)=>{const a=()=>{Ut.off("change",a),r()};Ut.on("change",a);const n=t[Wt.requestFullscreen](e);n instanceof Promise&&n.then(a).catch(o)}),exit:()=>new Promise((t,e)=>{if(!Ut.isFullscreen)return void t();const r=()=>{Ut.off("change",r),t()};Ut.on("change",r);const o=document[Wt.exitFullscreen]();o instanceof Promise&&o.then(r).catch(e)}),toggle:(t,e)=>Ut.isFullscreen?Ut.exit():Ut.request(t,e),onchange(t){Ut.on("change",t)},onerror(t){Ut.on("error",t)},on(t,e){const r=jt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=jt[t];r&&document.removeEventListener(r,e,!1)},raw:Wt};function qt(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t,n=t=>{Ut.on("change",()=>{t.emit("fullscreen",Ut.isFullscreen),Ut.isFullscreen?(t.state="fullscreen",C(a,"art-fullscreen")):z(a,"art-fullscreen"),t.emit("resize")}),Ut.on("error",e=>{t.emit("fullscreenError",e)}),nt(t,"fullscreen",{get:()=>Ut.isFullscreen,set(t){return d(this,null,function*(){t?yield Ut.request(a):yield Ut.exit()})}})};t.once("video:loadedmetadata",()=>{var a;Ut.isEnabled?n(t):o.webkitSupportsFullscreen?((a=t).on("document:webkitfullscreenchange",()=>{a.emit("fullscreen",a.fullscreen),a.emit("resize")}),nt(a,"fullscreen",{get:()=>document.fullscreenElement===o,set(t){t?(a.state="fullscreen",o.webkitEnterFullscreen()):o.webkitExitFullscreen()}})):nt(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),nt(t,"fullscreen",lt(t,"fullscreen"))})}function Xt(t){const{icons:e,proxy:r,storage:o,template:{$player:a,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(z(a,"art-mini"),I(e,"display","none"),a.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(I(e,"display","none"),I(r,"display","flex")):(I(e,"display","flex"),I(r,"display","none"))}function p(){const{$mini:e}=t.template,r=H(e),a=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;o.set("top",a),o.set("left",n),I(e,"top",`${a}px`),I(e,"left",`${n}px`)}nt(t,"mini",{get:()=>L(a,"art-mini"),set(h){if(h){t.state="mini",C(a,"art-mini");const h=function(){const{$mini:a}=t.template;if(a)return S(a,n),I(a,"display","flex");{const a=N("div");C(a,"art-mini-popup"),S(document.body,a),t.template.$mini=a,S(a,n);const p=S(a,'
');S(p,e.close),r(p,"click",c);const h=S(a,'
'),u=S(h,e.play),m=S(h,e.pause);return r(u,"click",()=>G(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(a,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){C(a,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;I(a,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,z(a,"art-mini-dragging");const t=H(a);o.set("left",t.left),o.set("top",t.top),I(a,"left",`${t.left}px`),I(a,"top",`${t.top}px`),I(a,"transform",null)}}),a}}(),u=o.get("top"),m=o.get("left");"number"===typeof u&&"number"===typeof m?(I(h,"top",`${u}px`),I(h,"left",`${m}px`),_(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Gt(t){const{i18n:e,notice:r,template:{$video:o}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:o}=t;e.disablePictureInPicture=!1,nt(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw o.show=t,t})):document.exitPictureInPicture().catch(t=>{throw o.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):o.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),nt(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):nt(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Kt(t){const{option:e,template:{$progress:r,$video:o}}=t;let a=null,n=!1,i=null;t.on("setBar",(a,s,l)=>d(null,null,function*(){var c;const d=null==(c=t.controls)?void 0:c.thumbnails,{url:p,scale:h}=e.thumbnails;if(!d||!p)return;if("hover"===a||"played"===a&&l&&k){if(i||n||(n=!0,i=yield W(p,h),n=!1),!i)return;const a=r.clientWidth*s;a>0&&ar.clientWidth-u/2?I(s,"left",r.clientWidth-u+"px"):I(s,"left",a-u/2+"px")}(a)}})),nt(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(a),a=null,n=!1,i=null)}})}Object.defineProperties(Ut,{isFullscreen:{get:()=>Boolean(document[Wt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Wt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Wt.fullscreenEnabled])}});class Zt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;nt(t,"url",{get:()=>r.src,set(o){return d(this,null,function*(){if(o){const a=t.url,n=e.type||K(o),i=e.customType[n];n&&i?(yield ut(),t.loading.show=!0,i.call(t,r,o,t)):(URL.revokeObjectURL(a),r.src=o),a!==t.url&&(t.option.url=o,t.isReady&&a&&t.once("video:canplay",()=>{t.emit("restart",o)}))}else yield ut(),t.loading.show=!0})}})}(t),function(t){const{template:{$video:e}}=t;nt(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:o,constructor:{instances:a},template:{$video:n}}=t;nt(t,"play",{value(){return d(this,null,function*(){const i=yield n.play();if(r.show=e.get("Play"),t.emit("play"),o.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;nt(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${tt(t.currentTime)} / ${tt(t.duration)}`),t.emit("seek",t.currentTime,r)}}),nt(t,"forward",{set(e){t.seek=t.currentTime+e}}),nt(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:o,storage:a}=t;nt(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=J(t,0,1),o.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&a.set("volume",e.volume)}}),nt(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;nt(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=J(r,0,t.duration))}})}(t),function(t){nt(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((o,a)=>{if(e===t.url)return void o();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),a(e)},metadata:()=>{t.currentTime=r},canplay:()=>d(null,null,function*(){t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&(yield G(t.play())),t.notice.show="",o()})};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}nt(t,"switchQuality",{value:r=>e(r,t.currentTime)}),nt(t,"switchUrl",{value:t=>e(t,0)}),nt(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:o}=t;nt(t,"playbackRate",{get:()=>e.playbackRate,set(a){if(a){if(a===e.playbackRate)return;e.playbackRate=a,o.show=`${r.get("Rate")}: ${1===a?r.get("Normal"):`${a}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t;nt(t,"aspectRatio",{get:()=>a.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)I(o,"width",null),I(o,"height",null),I(o,"margin",null),delete a.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=a,i=e/r,s=t[0]/t[1];i>s?(I(o,"width",s*r+"px"),I(o,"height","100%"),I(o,"margin","0 auto")):(I(o,"width","100%"),I(o,"height",e/s+"px"),I(o,"margin","auto 0")),a.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,o=N("canvas");nt(t,"getDataURL",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),t(o.toDataURL("image/png"))}catch(n){e.show=n,a(n)}})}),nt(t,"getBlobUrl",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),o.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,a(n)}})}),nt(t,"screenshot",{value:e=>d(null,null,function*(){const o=yield t.getDataURL();return Z(o,`${e||`artplayer_${tt(r.currentTime)}`}.png`),t.emit("screenshot",o),o})})}(t),qt(t),function(t){const{constructor:e,template:{$container:r,$player:o}}=t;let a="";nt(t,"fullscreenWeb",{get:()=>L(o,"art-fullscreen-web"),set(n){n?(a=o.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&S(document.body,o),t.state="fullscreenWeb",I(o,"width","100%"),I(o,"height","100%"),C(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&S(r,o),a&&(o.style.cssText=a,a=""),z(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Gt(t),function(t){const{$video:e}=t.template;nt(t,"loaded",{get:()=>t.loadedTime/e.duration}),nt(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){nt(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;nt(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:o}=t.template;nt(t,"autoSize",{value(){const{videoWidth:a,videoHeight:n}=o,{width:i,height:s}=H(e),l=a/n;if(i/s>l)I(r,"width",s*l/i*100+"%"),I(r,"height","100%");else{const t=i/l/s*100;I(r,"width","100%"),I(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){nt(t,"rect",{get:()=>H(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[o]})}nt(t,"x",{get:()=>t.left+window.pageXOffset}),nt(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:o}=t;nt(t,"flip",{get:()=>e.dataset.flip||"normal",set(a){a||(a="normal"),"normal"===a?delete e.dataset.flip:e.dataset.flip=a,o.show=`${r.get("Video Flip")}: ${r.get(Q(a))}`,t.emit("flip",a)}})}(t),Xt(t),function(t){const{template:{$poster:e}}=t;nt(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch(t){return""}},set(t){I(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;nt(t,"autoHeight",{value(){const{clientWidth:o}=e,{videoHeight:a,videoWidth:n}=r,i=a*(o/n);I(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;nt(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){nt(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){nt(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];nt(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let o=0;o{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,nt(t,"airplay",{value(){n?(a.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){nt(t,"quality",{set(e){const{controls:r,notice:o,i18n:a}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:(null==n?void 0:n.html)||"",selector:e,onSelect(e){return d(this,null,function*(){return yield t.switchQuality(e.url),o.show=`${a.get("Switch Video")}: ${e.html}`,e.html})}})}})}(t),Kt(t),function(t){const{i18n:e,notice:r,option:o,constructor:a,proxy:n,template:{$player:i,$video:s,$poster:l}}=t;let c=0;for(let d=0;d{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{c=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{o.loop?(t.seek=0,G(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",n=>d(null,null,function*(){c{t.emit("resize"),k&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,I(l,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:o,$poster:a}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(o.volume=J(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(o.volume=J(n,0,1)),e.poster&&I(a,"backgroundImage",`url(${e.poster})`),e.autoplay&&(o.autoplay=e.autoplay),e.playsInline&&(o.playsInline=!0,o["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Jt(t){const{notice:e,constructor:r,template:{$player:o,$video:a}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=a,r=document.documentElement.clientWidth,o=document.documentElement.clientHeight;return t>e&&ro}return t.on("fullscreenWeb",e=>{var a;if(e){if(l()){const e=Number(null!=(a=r.AUTO_ORIENTATION_TIME)?a:0);setTimeout(()=>{t.fullscreenWeb&&!L(o,n)&&function(){const e=U(),r=document.documentElement.clientWidth,a=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;I(o,"width",`${a}px`),I(o,"height",`${i}px`),I(o,"transform-origin","0 0"),I(o,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),C(o,n),t.isRotate=!0,t.emit("resize")}()},e)}}else L(o,n)&&(I(o,"width",""),I(o,"height",""),I(o,"transform-origin",""),I(o,"transform",""),z(o,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",t=>d(null,null,function*(){var r;const a=!!(null==(r=null==screen?void 0:screen.orientation)?void 0:r.lock);if(t){if(a&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";yield screen.orientation.lock(t),s=!0,C(o,i)}catch(n){s=!1,e.show=n}}else if(L(o,i)&&z(o,i),a&&s){try{screen.orientation.unlock()}catch(c){}s=!1}})),{name:"autoOrientation",get state(){return L(o,n)}}}function Qt(t){const{i18n:e,icons:r,storage:o,constructor:a,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=T(".art-auto-playback-last",s),c=T(".art-auto-playback-jump",s),d=T(".art-auto-playback-close",s);S(d,r.close);let p=null;function h(){const r=(o.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),I(s,"display","none"),r&&r>=a.AUTO_PLAYBACK_MIN&&(I(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${tt(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{I(s,"display","none")}),n(c,"click",()=>{t.seek=r,G(t.play()),I(i,"display","none"),I(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{I(s,"display","none")},a.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=o.get("times")||{},r=Object.keys(e);r.length>a.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,o.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return o.get("times")||{}},clear:()=>o.del("times"),delete(t){const e=o.get("times")||{};return delete e[t],o.set("times",e),e}}}function te(t){const{constructor:e,proxy:r,template:{$player:o,$video:a}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,z(o,"art-fast-forward"))};return r(a,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,C(o,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return L(o,"art-fast-forward")}}}function ee(t){const{layers:e,icons:r,template:{$player:o}}=t;function a(){return L(o,"art-lock")}function n(){C(o,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){z(o,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const o=S(e,r.lock),a=S(e,r.unlock);I(o,"display","none"),t.on("lock",t=>{t?(I(o,"display","inline-flex"),I(a,"display","none")):(I(o,"display","none"),I(a,"display","inline-flex"))})},click(){a()?i():n()}}),{name:"lock",get state(){return a()},set state(t){t?n():i()}}}function re(t){return t.on("control",e=>{e?z(t.template.$player,"art-mini-progress-bar"):C(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class oe{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(re),e.lock&&k&&this.add(ee),e.autoPlayback&&!e.isLive&&this.add(Qt),e.autoOrientation&&k&&this.add(Jt),e.fastForward&&k&&!e.isLive&&this.add(te);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return X(!st(this,r),`Cannot add a plugin that already has the same name: ${r}`),nt(this,r,{value:e}),this}}class ae extends Ct{constructor(t){super(t);const{option:e,controls:r,template:{$setting:o}}=t;this.name="setting",this.$parent=o,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=V(t,r.setting),o=V(t,this.$parent);!this.show||e||o||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,PLAYBACK_RATE:a}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:o,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:a.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,ASPECT_RATIO:a}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:o,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:a.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,FLIP:a}}=t;function n(t){return e.get(Q(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:o,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:a.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:o}=t;return{width:o.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){var r;for(let o=0;o{e.default=e===t,e.default&&e.$item&&A(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,o=[]){for(let a=0;ae}),nt(n,"$parents",{get:()=>r}),nt(n,"$option",{get:()=>t});const o=[];nt(n,"$events",{get:()=>o}),nt(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,o)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){var t,e;const{controls:r,constructor:{SETTING_WIDTH:o,SETTING_ITEM_HEIGHT:a},template:{$player:n,$setting:i}}=this.art;if(r.setting&&this.show){const s=(null==(e=null==(t=this.active[0])?void 0:t.$parent)?void 0:e.width)||o,{left:l,width:c}=H(r.setting),{left:d,width:p}=H(n),h=l-d+c/2-s/2;if(I(i,"height",`${this.active===this.option?this.active.length*a:(this.active.length+1)*a}px`),I(i,"width",`${s}px`),this.art.isRotate||k)return;h+s>p?(I(i,"left",null),I(i,"right",null)):(I(i,"left",`${h}px`),I(i,"right","auto"))}}inactivate(t){for(let e=0;e'),s=N("div");C(s,"art-setting-item-left-icon"),S(s,o),S(i,s),S(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),S(e,n)}createItem(t,e=!1){var r,o;if(!this.cache.has(t.$option))return;const a=this.cache.get(t.$option),n=t.$item;let i="selector";st(t,"switch")&&(i="switch"),st(t,"range")&&(i="range"),st(t,"onClick")&&(i="button");const{icons:s,proxy:l,constructor:c}=this.art,p=N("div");C(p,"art-setting-item"),I(p,"height",`${c.SETTING_ITEM_HEIGHT}px`),p.dataset.name=t.name||"",p.dataset.value=t.value||"";const h=S(p,'
'),u=S(p,'
'),m=N("div");switch(C(m,"art-setting-item-left-icon"),i){case"button":case"switch":case"range":S(m,t.icon||s.config);break;case"selector":(null==(r=t.selector)?void 0:r.length)?S(m,t.icon||s.config):S(m,s.check)}S(h,m),nt(t,"$icon",{configurable:!0,get:()=>m}),nt(t,"icon",{configurable:!0,get:()=>m.innerHTML,set(t){m.innerHTML="",S(m,t)}});const f=N("div");C(f,"art-setting-item-left-text"),S(f,t.html||""),S(h,f),nt(t,"$html",{configurable:!0,get:()=>f}),nt(t,"html",{configurable:!0,get:()=>f.innerHTML,set(t){f.innerHTML="",S(f,t)}});const g=N("div");switch(C(g,"art-setting-item-right-tooltip"),S(g,t.tooltip||""),S(u,g),nt(t,"$tooltip",{configurable:!0,get:()=>g}),nt(t,"tooltip",{configurable:!0,get:()=>g.innerHTML,set(t){g.innerHTML="",S(g,t)}}),i){case"switch":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,s.switchOn),o=S(e,s.switchOff);I(t.switch?o:r,"display","none"),S(u,e),nt(t,"$switch",{configurable:!0,get:()=>e});let a=t.switch;nt(t,"switch",{configurable:!0,get:()=>a,set(t){a=t,t?(I(o,"display","none"),I(r,"display",null)):(I(o,"display",null),I(r,"display","none"))}});break}case"range":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],C(r,"art-setting-range"),S(u,e),nt(t,"$range",{configurable:!0,get:()=>r});let o=[...t.range];nt(t,"range",{configurable:!0,get:()=>o,set(t){o=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(null==(o=t.selector)?void 0:o.length){const t=N("div");C(t,"art-setting-item-right-icon"),S(t,s.arrowRight),S(u,t)}}switch(i){case"switch":if(t.onSwitch){const e=l(p,"click",e=>d(this,null,function*(){t.switch=yield t.onSwitch.call(this.art,t,p,e)}));t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=l(t.$range,"change",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onRange.call(this.art,t,p,e)}));t.$events.push(e)}if(t.onChange){const e=l(t.$range,"input",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onChange.call(this.art,t,p,e)}));t.$events.push(e)}}break;case"selector":{const e=l(p,"click",e=>d(this,null,function*(){var r;(null==(r=t.selector)?void 0:r.length)?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=yield t.$parent.onSelect.call(this.art,t,p,e)))}));t.$events.push(e),t.default&&C(p,"art-current")}break;case"button":if(t.onClick){const e=l(p,"click",e=>d(this,null,function*(){t.tooltip=yield t.onClick.call(this.art,t,p,e)}));t.$events.push(e)}}nt(t,"$item",{configurable:!0,get:()=>p}),e?Y(p,n):S(a,p),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){var e;if(this.active=t,this.cache.has(t)){A(this.cache.get(t),"art-current")}else{const r=N("div");this.cache.set(t,r),C(r,"art-setting-panel"),S(this.$parent,r),A(r,"art-current"),(null==(e=t[0])?void 0:e.$parent)&&this.createHeader(t[0]);for(let e=0;enull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){var t,e;return null==(e=null==(t=this.art.template.$video)?void 0:t.textTracks)?void 0:e[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?P(r,t):I(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?at(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}switch(t){return d(this,arguments,function*(t,e={}){const{i18n:r,notice:o,option:a}=this.art,n=c(l(l({},a.subtitle),e),{url:t}),i=yield this.init(n);return e.name&&(o.show=`${r.get("Switch Subtitle")}: ${e.name}`),i})}createTrack(t,e){const{template:r,proxy:o,option:a}=this.art,{$video:n,$track:i}=r,s=N("track");s.default=!0,s.kind=t,s.src=e,s.label=a.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,M(i),S(n,s),r.$track=s,this.destroyEvent=o(this.textTrack,"cuechange",()=>this.update())}init(t){return d(this,null,function*(){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(f(t,Et.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||K(t.url)){case"srt":{const e=dt(r);return pt(t.onVttLoad(e))}case"ass":{const e=ht(r);return pt(t.onVttLoad(e))}case"vtt":return pt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null})}}class le{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=T(e.container),X(this.$container,`No container element found by ${e.container}`)),X(B(),"The current browser does not support flex layout");const o=this.$container.tagName.toLowerCase();X("div"===o,`Unsupported container element type, only support 'div' but got '${o}'`),X(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${g}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return T(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=le.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);X(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),Y(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&C(this.$player,"art-backdrop"),k&&C(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":C(this.$player,"art-destroy")}}const ce=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class de{on(t,e,r){const o=this.e||(this.e={});let a=ce(o,t)?o[t]:void 0;return a||(a=[],Object.defineProperty(o,t,{value:a,enumerable:!0,configurable:!0,writable:!0})),a.push({fn:e,ctx:r}),this}once(t,e,r){const o=this,a=e;let n=!1;function i(...e){n||(n=!0,o.off(t,i),a.apply(r,e))}return i._=e,this.on(t,i,r)}emit(t,...e){const r=this.e||(this.e={}),o=(ce(r,t)&&r[t]||[]).slice();for(const a of o)a.fn.apply(a.ctx,e);return this}off(t,e){const r=this.e||(this.e={}),o=ce(r,t)?r[t]:void 0,a=[];if(o&&e)for(let n=0,i=o.length;ne.call(this,this)),ue.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${ue.version}`);for(let e=0;et(`Event@${e.type}`))}he.push(this)}static get instances(){return he}static get version(){return g}static get config(){return v}static get utils(){return gt}static get scheme(){return Et}static get Emitter(){return de}static get validator(){return f}static get kindOf(){return f.kindOf}static get html(){return le.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:b?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:null==navigator?void 0:navigator.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){ue.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),he.splice(he.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return ue.STYLE=ie,ue.DEBUG=!1,ue.CONTEXTMENU=!0,ue.NOTICE_TIME=2e3,ue.SETTING_WIDTH=250,ue.SETTING_ITEM_WIDTH=200,ue.SETTING_ITEM_HEIGHT=35,ue.RESIZE_TIME=200,ue.SCROLL_TIME=200,ue.SCROLL_GAP=50,ue.AUTO_PLAYBACK_MAX=10,ue.AUTO_PLAYBACK_MIN=5,ue.AUTO_PLAYBACK_TIMEOUT=3e3,ue.RECONNECT_TIME_MAX=5,ue.RECONNECT_SLEEP_TIME=1e3,ue.CONTROL_HIDE_TIME=3e3,ue.DBCLICK_TIME=300,ue.DBCLICK_FULLSCREEN=!0,ue.MOBILE_DBCLICK_PLAY=!0,ue.MOBILE_CLICK_PLAY=!1,ue.AUTO_ORIENTATION_TIME=200,ue.INFO_LOOP_TIME=1e3,ue.FAST_FORWARD_VALUE=3,ue.FAST_FORWARD_TIME=1e3,ue.TOUCH_MOVE_RATIO=.5,ue.VOLUME_STEP=.1,ue.SEEK_STEP=5,ue.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],ue.ASPECT_RATIO=["default","4:3","16:9"],ue.FLIP=["normal","horizontal","vertical"],ue.FULLSCREEN_WEB_IN_BODY=!0,ue.LOG_VERSION=!0,ue.USE_RAF=!1,ue.REMOVE_SRC_WHEN_DESTROY=!0,$&&(window.Artplayer=ue,F("artplayer-style",ie),setTimeout(()=>{ue.LOG_VERSION&&console.log(`%c ArtPlayer %c ${ue.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),ue}); diff --git a/docs/compiled/artplayer.mjs b/docs/compiled/artplayer.mjs index bca7fa5e5..1749e58a3 100644 --- a/docs/compiled/artplayer.mjs +++ b/docs/compiled/artplayer.mjs @@ -4780,36 +4780,49 @@ class Template { } } } +const owns = (object, key) => Object.prototype.hasOwnProperty.call(object, key); class Emitter { on(name, fn, ctx) { const e = this.e || (this.e = {}); - (e[name] || (e[name] = [])).push({ fn, ctx }); + let listeners = owns(e, name) ? e[name] : void 0; + if (!listeners) { + listeners = []; + Object.defineProperty(e, name, { value: listeners, enumerable: true, configurable: true, writable: true }); + } + listeners.push({ fn, ctx }); return this; } once(name, fn, ctx) { const self = this; + const callback = fn; + let fired = false; function listener(...args) { + if (fired) + return; + fired = true; self.off(name, listener); - fn.apply(ctx, args); + callback.apply(ctx, args); } listener._ = fn; return this.on(name, listener, ctx); } emit(name, ...data) { - const evtArr = ((this.e || (this.e = {}))[name] || []).slice(); - for (let i = 0; i < evtArr.length; i += 1) { - evtArr[i].fn.apply(evtArr[i].ctx, data); + const e = this.e || (this.e = {}); + const snapshot = (owns(e, name) ? e[name] || [] : []).slice(); + for (const event of snapshot) { + event.fn.apply(event.ctx, data); } return this; } off(name, callback) { const e = this.e || (this.e = {}); - const evts = e[name]; + const evts = owns(e, name) ? e[name] : void 0; const liveEvents = []; if (evts && callback) { for (let i = 0, len = evts.length; i < len; i += 1) { - if (evts[i].fn !== callback && evts[i].fn._ !== callback) - liveEvents.push(evts[i]); + const event = evts[i]; + if (event.fn !== callback && event.fn._ !== callback) + liveEvents.push(event); } } if (liveEvents.length) { diff --git a/packages/artplayer/ARCHITECTURE.md b/packages/artplayer/ARCHITECTURE.md index 7ad7510ba..7a2f6ccb1 100644 --- a/packages/artplayer/ARCHITECTURE.md +++ b/packages/artplayer/ARCHITECTURE.md @@ -18,9 +18,38 @@ boundaries rather than describing the entire core as TypeScript. These modules do not import the player, UI components or each other except for the barrel. Existing DOM and browser capability utilities remain JS and are re-exported -unchanged. Emitter and Component are separate migration tasks. Imports from the +unchanged. Emitter is now typed as described below; Component remains a later task. Imports from the barrel must not silently add runtime fields to `Artplayer.utils`. +## Typed Emitter + +`src/utils/emitter.ts` keeps the original on/once/emit/off class and a lazy ordinary +object registry. `declare e` emits no instance field; a fresh emitter still has no +own keys. There are no additional prototype methods or mandatory constructor options. + +The generic event map associates event names with payload tuples, including readonly +tuples, symbols and optional arguments. An open Record default preserves arbitrary +JS event channels; internal typed consumers can use a closed map or intersect their +known events with an open map. Receiver inference is checked on registration and +erased inside each stored registration, where the original callback and ctx remain paired. +Current JS player consumers remain incremental; public declaration expansion is CORE-07. + +Dispatch takes a shallow registration-array snapshot. Normal listeners removed during +dispatch still run if already captured, additions wait for a later dispatch, and a +throw stops that dispatch and propagates unchanged. Off accepts either a once wrapper +or its original callback; duplicate registrations of a callback are removed together. +The once wrapper unsubscribes before invoking user code and now records consumption, +so a nested dispatch cannot execute a captured copy twice. This fixes a demonstrated +old defect without changing ordinary snapshot behavior. Event names such as __proto__ +and toString use own properties rather than inherited Object.prototype values. + +Shared contracts in test/contracts/emitter.js run against published, workspace and +installed versions. Candidate corrections have separate published-defect observations +in test/public-behavior.test.js and test/browser/emitter.spec.js. The source type fixture +checks event name/payload correlation, receiver types, custom channels and chain typing. +Emitter owns registrations only; instance teardown must remove the relevant callbacks, +not clear unrelated subscribers before destroy dispatch. Resource scopes follow in CORE-03. + ## Observable utility behavior - `def` is the native Object.defineProperty function. Property keys include symbols; @@ -77,5 +106,5 @@ core files in docs/compiled when committing a shippable core change. For new utility behavior, extend the same old/new contract tests. Clearly separate intentional defect corrections from preserved behavior. For timers or Blob URLs, also identify the owner and verify cleanup in the consuming module. Remaining -constructor, playback, UI, Emitter, Component and capability migrations are recorded +constructor, playback, UI, Component and capability migrations are recorded in refactor/tasks.json and should extend this map as they land. diff --git a/packages/artplayer/dist/artplayer.js b/packages/artplayer/dist/artplayer.js index bb14495c1..542812ec5 100644 --- a/packages/artplayer/dist/artplayer.js +++ b/packages/artplayer/dist/artplayer.js @@ -4,4 +4,4 @@ * (c) 2017-2026 Harvey Zhao * Released under the MIT License. */ -!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2=1,p=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(s)||d,h="undefined"!==typeof window&&"undefined"!==typeof document;function u(t,e=document){return e.querySelector(t)}function m(t,e=document){return Array.from(e.querySelectorAll(t))}function f(t,e){return t.classList.add(e)}function g(t,e){return t.classList.remove(e)}function v(t,e){return t.classList.contains(e)}function y(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function b(t){return t.parentNode.removeChild(t)}function w(t,e,r){return t.style[e]=r,t}function x(t,e){for(const r in e)w(t,r,e[r]);return t}function k(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function $(t,e){k(t).forEach(t=>g(t,e)),f(t,e)}function T(t,e,r="top"){p||(t.setAttribute("aria-label",e),f(t,"hint--rounded"),f(t,`hint--${r}`))}function E(t,e=0){const r=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=a&&r.top+r.height+e>=0,i=r.left-e<=o+e&&r.left+r.width+e>=0;return n&&i}function C(t,e){return R(t).includes(e)}function z(t,e){return e.parentNode.replaceChild(t,e),t}function L(t){return document.createElement(t)}function S(t="",e=""){const r=L("i");return f(r,"art-icon"),f(r,`art-icon-${t}`),y(r,e),r}function M(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function I(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function A(t){return t.getBoundingClientRect()}function P(t,e){return new Promise((r,a)=>{const o=new Image;o.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=o.width*e,n.height=o.height*e,i.drawImage(o,0,0,n.width,n.height),n.toBlob(e=>{const o=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(o),a(new Error(`Image load failed: ${t}`))},n.src=o})}else r(o)},o.onerror=function(){a(new Error(`Image load failed: ${t}`))},o.src=t})}function R(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function O(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class _ extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function V(t,e){if(!t)throw new _(e);return t}function Y(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function N(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function D(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function F(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function B(t){return t.charAt(0).toUpperCase()+t.slice(1)}function H(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),a=Math.floor(t-3600*e-60*r);return(e>0?[e,r,a]:[r,a]).map(t=>t<10?`0${t}`:String(t)).join(":")}const W={"&":"&","<":"<",">":">","'":"'",'"':"""},j={"&":"&","<":"<",">":">","'":"'",""":'"'},U=/(&|<|>|'|")/g;function q(t){return t.replace(/[&<>'"]/g,t=>W[t]||t)}const X=Object.defineProperty,{hasOwnProperty:G}=Object.prototype;function K(t,e){return G.call(t,e)}function Z(t,e){return Object.getOwnPropertyDescriptor(t,e)}function J(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(a=>{const o=t[a],n=r[a];let i;i=Array.isArray(o)&&Array.isArray(n)?o.concat(...n):e(o)&&e(n)?J(o,n):n,X(t,a,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function Q(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let a=r.slice(0,3);return 1===r.length&&(a=`${r}00`),2===r.length&&(a=`${r}0`),`${e},${a}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function tt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function et(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const a=t.match(e);if(!a)return null;const[,o="",n="",,,i=""]=a;return{start:r(o.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function rt(t=0){return new Promise(e=>setTimeout(e,t))}function at(t,e){let r;return function(...a){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,a)),e)}}function ot(t,e){let r=!1;return function(...a){r||(t.apply(this,a),r=!0,setTimeout(()=>{r=!1},e))}}const nt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:_,addClass:f,append:y,assToVtt:et,capitalize:B,clamp:F,createElement:L,debounce:at,def:X,download:D,errorHandle:V,escape:q,get:Z,getComposedPath:R,getExt:N,getIcon:S,getRect:A,getSafeAreaInsets:O,getStyle:function(t,e,r=!0){const a=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(a):a},has:K,hasClass:v,includeFromEvent:C,inverseClass:$,isBrowser:h,isIOS:c,isIOS13:d,isInViewport:E,isMobile:p,isSafari:l,loadImg:P,mergeDeep:J,query:u,queryAll:m,remove:b,removeClass:g,replaceElement:z,secondToTime:H,setStyle:w,setStyleText:M,setStyles:x,siblings:k,silencePromise:Y,sleep:rt,srtToVtt:Q,supportsFlex:I,throttle:ot,tooltip:T,unescape:function(t){return t.replace(U,t=>j[t]||t)},userAgent:s,vttToBlob:tt},Symbol.toStringTag,{value:"Module"})),it="array",st="boolean",lt="string",ct="number",dt="object",pt="function";function ht(t,e,r){return V(e===lt||e===ct||t instanceof Element,`${r.join(".")} require '${lt}' or 'Element' type`)}const ut={html:ht,disable:`?${st}`,name:`?${lt}`,index:`?${ct}`,style:`?${dt}`,click:`?${pt}`,mounted:`?${pt}`,tooltip:`?${lt}|${ct}`,width:`?${ct}`,selector:`?${it}`,onSelect:`?${pt}`,switch:`?${st}`,onSwitch:`?${pt}`,range:`?${it}`,onRange:`?${pt}`,onChange:`?${pt}`},mt={id:lt,container:ht,url:lt,poster:lt,type:lt,theme:lt,lang:lt,volume:ct,isLive:st,muted:st,autoplay:st,autoSize:st,autoMini:st,loop:st,flip:st,playbackRate:st,aspectRatio:st,screenshot:st,setting:st,hotkey:st,pip:st,mutex:st,backdrop:st,fullscreen:st,fullscreenWeb:st,subtitleOffset:st,miniProgressBar:st,useSSR:st,playsInline:st,lock:st,gesture:st,fastForward:st,autoPlayback:st,autoOrientation:st,airplay:st,proxy:`?${pt}`,plugins:[pt],layers:[ut],contextmenu:[ut],settings:[ut],controls:[{...ut,position:(t,e,r)=>{const a=["top","left","right"];return V(a.includes(t),`${r.join(".")} only accept ${a.toString()} as parameters`)}}],quality:[{default:`?${st}`,html:lt,url:lt}],highlight:[{time:ct,text:lt}],thumbnails:{url:lt,number:ct,column:ct,width:ct,height:ct,scale:ct},subtitle:{url:lt,name:lt,type:lt,style:dt,escape:st,encoding:lt,onVttLoad:pt},moreVideoAttr:dt,i18n:dt,icons:dt,cssVar:dt,customType:dt};class ft{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return v(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?f(e,r):g(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",o(e,ut),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;V(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const a=L("div");f(a,`art-${this.name}`),f(a,`art-${this.name}-${r}`);const n=Array.from(this.$parent.children);a.dataset.index=e.index||this.id;const i=n.find(t=>Number(t.dataset.index)>=Number(a.dataset.index));i?i.insertAdjacentElement("beforebegin",a):y(this.$parent,a),e.html&&y(a,e.html),e.style&&x(a,e.style),e.tooltip&&T(a,e.tooltip);const s=[];if(e.click){const t=this.art.events.proxy(a,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});s.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,a,s),this[r]=a,this.cache.set(r,{$ref:a,events:s,option:e}),e.mounted&&e.mounted.call(this.art,a),a}remove(t){V(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],b(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class gt extends ft{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,p||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:a}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:a}}=e,o=a.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return{...t,html:`${r.get("Play Speed")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.playbackRate=Number(a),t.show=!1)},mounted:t=>{const r=u('[data-value="1"]',t);r&&$(r,"art-current"),e.on("video:ratechange",()=>{const r=m("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&$(r,"art-current")})}}}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:a}}=e,o=a.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return{...t,html:`${r.get("Aspect Ratio")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.aspectRatio=a,t.show=!1)},mounted:t=>{const r=u('[data-value="default"]',t);r&&$(r,"art-current"),e.on("aspectRatio",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:a}}=e,o=a.map(t=>`${r.get(B(t))}`).join("");return{...t,html:`${r.get("Video Flip")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.flip=a.toLowerCase(),t.show=!1)},mounted:t=>{const r=u('[data-value="normal"]',t);r&&$(r,"art-current"),e.on("flip",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"flip",index:30})),this.add(function(t){return e=>({...t,html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return{...t,html:`ArtPlayer ${n}`}}({name:"version",index:50})),this.add(function(t){return e=>({...t,html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let o=0;o{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,o=t.clientY,{height:n,width:i,left:s,top:l}=A(r),{height:c,width:d}=A(a);let p=e-s,h=o-l;e+d>s+i&&(p=i-d),o+c>l+n&&(h=n-c),x(a,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{C(t,a)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function vt(t,e){const{$progress:r}=t.template,{left:a}=A(r),o=F((p?e.touches[0].clientX:e.clientX)-a,0,r.clientWidth),n=o/r.clientWidth*t.duration;return{second:n,time:H(n),width:o,percentage:F(o/r.clientWidth,0,1)}}function yt(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,a=r*t.duration;t.emit("setBar","played",r,e),t.seek=a}else{const{second:r,percentage:a}=vt(t,e);t.emit("setBar","played",a,e),t.seek=r}}function bt(t){return e=>{const{icons:r,option:a,proxy:o}=e,{$player:n,$progress:i}=e.template;return{...t,html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=u(".art-progress-hover",t),d=u(".art-progress-loaded",t),h=u(".art-progress-played",t),m=u(".art-progress-highlight",t),v=u(".art-progress-indicator",t),b=u(".art-progress-tip",t);function x(r,a){const{width:o,time:n}=a||vt(e,r);b.textContent=n||"00:00";const i=b.clientWidth;o<=i/2?w(b,"left",0):o>t.clientWidth-i/2?w(b,"left",t.clientWidth-i+"px"):w(b,"left",o-i/2+"px")}r.indicator?y(v,r.indicator):w(v,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,a,o){const i="played"===r&&o&&p;if("loaded"===r&&w(d,"width",100*a+"%"),"hover"===r&&(w(c,"width",100*a+"%"),C(o,m)?function(r){const{width:a}=vt(e,r),{text:o}=r.target.dataset;b.textContent=o;const n=b.clientWidth;a<=n/2?w(b,"left",0):a>t.clientWidth-n/2?w(b,"left",t.clientWidth-n+"px"):w(b,"left",a-n/2+"px")}(o):x(o),0===a?g(n,"art-progress-hover"):f(n,"art-progress-hover")),"played"===r&&(w(h,"width",100*a+"%"),w(v,"left",100*a+"%")),i){f(n,"art-progress-hover");x(o,{width:t.clientWidth*a,time:H(a*e.duration)}),clearTimeout(s),s=setTimeout(()=>{g(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){m.textContent="";for(let t=0;t`;y(m,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),p||(o(i,"click",t=>{t.target!==v&&yt(e,t)}),o(i,"mousemove",t=>{const{percentage:r}=vt(e,t);e.emit("setBar","hover",r,t)}),o(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),o(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:a}=vt(e,t);e.emit("setBar","played",a,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}}}}class wt extends ft{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:a}=this.art.template;t.on("mousemove",()=>{p||(this.show=!0)}),t.on("click",()=>{p?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=C(t,a)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(g(r,"art-hide-cursor"),f(r,"art-hover"),this.timer=Date.now()):(f(r,"art-hide-cursor"),g(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(bt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.play),i=y(t,a.pause);function s(){w(n,"display","flex"),w(i,"display","none")}function l(){w(n,"display","none"),w(i,"display","flex")}T(n,o.get("Play")),T(i,o.get("Pause")),r(n,"click",()=>{Y(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a}=e,o=y(t,a.volume),n=y(t,a.volumeClose),i=y(t,'
'),s=y(i,'
'),l=y(s,'
'),c=y(s,'
'),d=y(c,'
'),h=y(d,'
'),u=y(c,'
');function m(t){const{top:e,height:r}=A(c);return 1-(t.clientY-e)/r}function f(){if(e.muted||0===e.volume)w(o,"display","none"),w(n,"display","flex"),w(u,"top","100%"),w(h,"top","100%"),l.textContent=0;else{const t=100*e.volume;w(o,"display","flex"),w(n,"display","none"),w(u,"top",100-t+"%"),w(h,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(f(),e.on("video:volumechange",f),r(o,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),p)w(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=m(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=m(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>({...t,style:p?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${H(e.currentTime)} / ${H(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const a=["video:loadedmetadata","video:timeupdate","video:progress"];for(let o=0;o{this.art.quality=t.quality}),t.screenshot&&!p&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{T(t,o.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{T(t,o.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenWebOn),i=y(t,a.fullscreenWebOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(T(t,o.get("Exit Web Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Web Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenOn),i=y(t,a.fullscreenOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(T(t,o.get("Exit Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),X(e,"$control_item",{get:()=>r}),X(e,"$control_value",{get:()=>o})}const i=a(n,"click",async e=>{const r=R(e),a=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(a),t.onSelect&&(o.innerHTML=await t.onSelect.call(this.art,a,a.$control_item,e))});r.push(i)}}function xt(t,e,r,a){const o=e-a,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(o)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,o);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class kt{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:a,$video:o}}=t;function n(e){C(e,a)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(o,"click",e=>{const a=Date.now();i.push(a);const{MOBILE_CLICK_PLAY:o,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>a-t<=n);switch(c.length){case 1:t.emit("click",e),p?!t.isLock&&o&&Y(t.toggle()):Y(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),p?!t.isLock&&s&&Y(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{f(r,"art-hover"),t.emit("hover",!0,e)},e=>{g(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:a}=t;t.on("resize",()=>{const{aspectRatio:e,notice:a}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,a.show=""});const o=at(()=>t.emit("resize"),a.RESIZE_TIME);t.on("window:orientationchange",()=>o()),t.on("window:resize",()=>o()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>o())}(t,this),function(t,e){if(p&&!t.option.isLive){const{$video:r,$progress:a}=t.template;let o=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){o===a&&yt(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:a,pageY:n}=e.touches[0],c=xt(i,s,a,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=F((a-i)/t.width,-1,1),d=F((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=o===r?t.constructor.TOUCH_MOVE_RATIO:1,u=F(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",F(u/t.duration,0,1),e),t.notice.show=`${H(u)} / ${H(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,o=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{o=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(a,"touchstart",t=>{o=a,c(t)}),e.proxy(a,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:a}}=t,o=ot(()=>{t.emit("view",E(a,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>o()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],a=["resize","scroll","orientationchange"],o=[];function n(n={}){for(let t=0;t{const a=n.document||i.ownerDocument||document,s=e.proxy(a,r,e=>{t.emit(`document:${r}`,e)});o.push(s)}),a.forEach(r=>{const a=n.window||i.ownerDocument?.defaultView||window,s=e.proxy(a,r,e=>{t.emit(`window:${r}`,e)});o.push(s)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,a={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,a));t.addEventListener(e,r,a);const o=()=>t.removeEventListener(e,r,a);return this.destroyEvents.add(o),o}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class $t{constructor(t){this.art=t,this.keys={},p||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{Y(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n',...t.option.icons};for(const r in e)X(this,r,{get:()=>S(r,e[r])})}}class zt extends ft{constructor(t){super(t),this.name="info",p||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:a,$video:o}}=this.art;t(a,"click",()=>{this.show=!1});let n=null;const i=m("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{w(o,"display","none"),w(n,"display",null)}),a.proxy(e.$state,"click",()=>Y(t.play()))}}class It{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:a}}=this.art;t?(a.textContent=t instanceof Error?t.message.trim():t,f(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{a.textContent="",g(r,"art-notice-show")},e.NOTICE_TIME)):g(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const At=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Pt=(()=>{if("undefined"===typeof document)return!1;const t=At[0],e={};for(const r of At){if(r[1]in document){for(const[a,o]of r.entries())e[t[a]]=o;return e}}return!1})(),Rt={change:Pt.fullscreenchange,error:Pt.fullscreenerror},Ot={request:(t=document.documentElement,e)=>new Promise((r,a)=>{const o=()=>{Ot.off("change",o),r()};Ot.on("change",o);const n=t[Pt.requestFullscreen](e);n instanceof Promise&&n.then(o).catch(a)}),exit:()=>new Promise((t,e)=>{if(!Ot.isFullscreen)return void t();const r=()=>{Ot.off("change",r),t()};Ot.on("change",r);const a=document[Pt.exitFullscreen]();a instanceof Promise&&a.then(r).catch(e)}),toggle:(t,e)=>Ot.isFullscreen?Ot.exit():Ot.request(t,e),onchange(t){Ot.on("change",t)},onerror(t){Ot.on("error",t)},on(t,e){const r=Rt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=Rt[t];r&&document.removeEventListener(r,e,!1)},raw:Pt};function _t(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;t.once("video:loadedmetadata",()=>{var n;Ot.isEnabled?(n=t,Ot.on("change",()=>{n.emit("fullscreen",Ot.isFullscreen),Ot.isFullscreen?(n.state="fullscreen",f(o,"art-fullscreen")):g(o,"art-fullscreen"),n.emit("resize")}),Ot.on("error",t=>{n.emit("fullscreenError",t)}),X(n,"fullscreen",{get:()=>Ot.isFullscreen,async set(t){t?await Ot.request(o):await Ot.exit()}})):a.webkitSupportsFullscreen?(t=>{t.on("document:webkitfullscreenchange",()=>{t.emit("fullscreen",t.fullscreen),t.emit("resize")}),X(t,"fullscreen",{get:()=>document.fullscreenElement===a,set(e){e?(t.state="fullscreen",a.webkitEnterFullscreen()):a.webkitExitFullscreen()}})})(t):X(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),X(t,"fullscreen",Z(t,"fullscreen"))})}function Vt(t){const{icons:e,proxy:r,storage:a,template:{$player:o,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(g(o,"art-mini"),w(e,"display","none"),o.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(w(e,"display","none"),w(r,"display","flex")):(w(e,"display","flex"),w(r,"display","none"))}function p(){const{$mini:e}=t.template,r=A(e),o=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;a.set("top",o),a.set("left",n),w(e,"top",`${o}px`),w(e,"left",`${n}px`)}X(t,"mini",{get:()=>v(o,"art-mini"),set(h){if(h){t.state="mini",f(o,"art-mini");const h=function(){const{$mini:o}=t.template;if(o)return y(o,n),w(o,"display","flex");{const o=L("div");f(o,"art-mini-popup"),y(document.body,o),t.template.$mini=o,y(o,n);const p=y(o,'
');y(p,e.close),r(p,"click",c);const h=y(o,'
'),u=y(h,e.play),m=y(h,e.pause);return r(u,"click",()=>Y(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(o,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){f(o,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;w(o,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,g(o,"art-mini-dragging");const t=A(o);a.set("left",t.left),a.set("top",t.top),w(o,"left",`${t.left}px`),w(o,"top",`${t.top}px`),w(o,"transform",null)}}),o}}(),u=a.get("top"),m=a.get("left");"number"===typeof u&&"number"===typeof m?(w(h,"top",`${u}px`),w(h,"left",`${m}px`),E(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Yt(t){const{i18n:e,notice:r,template:{$video:a}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:a}=t;e.disablePictureInPicture=!1,X(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw a.show=t,t})):document.exitPictureInPicture().catch(t=>{throw a.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):a.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),X(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):X(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Nt(t){const{option:e,template:{$progress:r,$video:a}}=t;let o=null,n=!1,i=null;t.on("setBar",async(o,s,l)=>{const c=t.controls?.thumbnails,{url:d,scale:h}=e.thumbnails;if(!c||!d)return;if("hover"===o||"played"===o&&l&&p){if(i||n||(n=!0,i=await P(d,h),n=!1),!i)return;const o=r.clientWidth*s;o>0&&or.clientWidth-h/2?w(n,"left",r.clientWidth-h+"px"):w(n,"left",o-h/2+"px")}(o)}}),X(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(o),o=null,n=!1,i=null)}})}Object.defineProperties(Ot,{isFullscreen:{get:()=>Boolean(document[Pt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Pt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Pt.fullscreenEnabled])}});class Dt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;X(t,"url",{get:()=>r.src,async set(a){if(a){const o=t.url,n=e.type||N(a),i=e.customType[n];n&&i?(await rt(),t.loading.show=!0,i.call(t,r,a,t)):(URL.revokeObjectURL(o),r.src=a),o!==t.url&&(t.option.url=a,t.isReady&&o&&t.once("video:canplay",()=>{t.emit("restart",a)}))}else await rt(),t.loading.show=!0}})}(t),function(t){const{template:{$video:e}}=t;X(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:a,constructor:{instances:o},template:{$video:n}}=t;X(t,"play",{async value(){const i=await n.play();if(r.show=e.get("Play"),t.emit("play"),a.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;X(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${H(t.currentTime)} / ${H(t.duration)}`),t.emit("seek",t.currentTime,r)}}),X(t,"forward",{set(e){t.seek=t.currentTime+e}}),X(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:a,storage:o}=t;X(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=F(t,0,1),a.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&o.set("volume",e.volume)}}),X(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;X(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=F(r,0,t.duration))}})}(t),function(t){X(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((a,o)=>{if(e===t.url)return void a();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),o(e)},metadata:()=>{t.currentTime=r},canplay:async()=>{t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&await Y(t.play()),t.notice.show="",a()}};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}X(t,"switchQuality",{value:r=>e(r,t.currentTime)}),X(t,"switchUrl",{value:t=>e(t,0)}),X(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:a}=t;X(t,"playbackRate",{get:()=>e.playbackRate,set(o){if(o){if(o===e.playbackRate)return;e.playbackRate=o,a.show=`${r.get("Rate")}: ${1===o?r.get("Normal"):`${o}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;X(t,"aspectRatio",{get:()=>o.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)w(a,"width",null),w(a,"height",null),w(a,"margin",null),delete o.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=o,i=e/r,s=t[0]/t[1];i>s?(w(a,"width",s*r+"px"),w(a,"height","100%"),w(a,"margin","0 auto")):(w(a,"width","100%"),w(a,"height",e/s+"px"),w(a,"margin","auto 0")),o.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,a=L("canvas");X(t,"getDataURL",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),t(a.toDataURL("image/png"))}catch(n){e.show=n,o(n)}})}),X(t,"getBlobUrl",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),a.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,o(n)}})}),X(t,"screenshot",{value:async e=>{const a=await t.getDataURL();return D(a,`${e||`artplayer_${H(r.currentTime)}`}.png`),t.emit("screenshot",a),a}})}(t),_t(t),function(t){const{constructor:e,template:{$container:r,$player:a}}=t;let o="";X(t,"fullscreenWeb",{get:()=>v(a,"art-fullscreen-web"),set(n){n?(o=a.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&y(document.body,a),t.state="fullscreenWeb",w(a,"width","100%"),w(a,"height","100%"),f(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&y(r,a),o&&(a.style.cssText=o,o=""),g(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Yt(t),function(t){const{$video:e}=t.template;X(t,"loaded",{get:()=>t.loadedTime/e.duration}),X(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){X(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;X(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:a}=t.template;X(t,"autoSize",{value(){const{videoWidth:o,videoHeight:n}=a,{width:i,height:s}=A(e),l=o/n;if(i/s>l)w(r,"width",s*l/i*100+"%"),w(r,"height","100%");else{const t=i/l/s*100;w(r,"width","100%"),w(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){X(t,"rect",{get:()=>A(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[a]})}X(t,"x",{get:()=>t.left+window.pageXOffset}),X(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:a}=t;X(t,"flip",{get:()=>e.dataset.flip||"normal",set(o){o||(o="normal"),"normal"===o?delete e.dataset.flip:e.dataset.flip=o,a.show=`${r.get("Video Flip")}: ${r.get(B(o))}`,t.emit("flip",o)}})}(t),Vt(t),function(t){const{template:{$poster:e}}=t;X(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch{return""}},set(t){w(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;X(t,"autoHeight",{value(){const{clientWidth:a}=e,{videoHeight:o,videoWidth:n}=r,i=o*(a/n);w(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;X(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){X(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){X(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];X(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let a=0;aa.$track?.offset||0,set(o){const{cues:n}=t.subtitle;if(!a.$track||0===n.length)return;const i=F(o,-10,10);a.$track.offset=i;for(let e=0;e{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,X(t,"airplay",{value(){n?(o.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){X(t,"quality",{set(e){const{controls:r,notice:a,i18n:o}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:n?.html||"",selector:e,onSelect:async e=>(await t.switchQuality(e.url),a.show=`${o.get("Switch Video")}: ${e.html}`,e.html)})}})}(t),Nt(t),function(t){const{i18n:e,notice:r,option:a,constructor:o,proxy:n,template:{$player:s,$video:l,$poster:c}}=t;let d=0;for(let p=0;p{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{d=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{a.loop?(t.seek=0,Y(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",async n=>{d{t.emit("resize"),p&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,w(c,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:a,$poster:o}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(a.volume=F(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(a.volume=F(n,0,1)),e.poster&&w(o,"backgroundImage",`url(${e.poster})`),e.autoplay&&(a.autoplay=e.autoplay),e.playsInline&&(a.playsInline=!0,a["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Ft(t){const{notice:e,constructor:r,template:{$player:a,$video:o}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=o,r=document.documentElement.clientWidth,a=document.documentElement.clientHeight;return t>e&&ra}return t.on("fullscreenWeb",e=>{if(e){if(l()){const e=Number(r.AUTO_ORIENTATION_TIME??0);setTimeout(()=>{t.fullscreenWeb&&!v(a,n)&&function(){const e=O(),r=document.documentElement.clientWidth,o=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;w(a,"width",`${o}px`),w(a,"height",`${i}px`),w(a,"transform-origin","0 0"),w(a,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),f(a,n),t.isRotate=!0,t.emit("resize")}()},e)}}else v(a,n)&&(w(a,"width",""),w(a,"height",""),w(a,"transform-origin",""),w(a,"transform",""),g(a,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",async t=>{const r=!!screen?.orientation?.lock;if(t){if(r&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";await screen.orientation.lock(t),s=!0,f(a,i)}catch(o){s=!1,e.show=o}}else if(v(a,i)&&g(a,i),r&&s){try{screen.orientation.unlock()}catch{}s=!1}}),{name:"autoOrientation",get state(){return v(a,n)}}}function Bt(t){const{i18n:e,icons:r,storage:a,constructor:o,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=u(".art-auto-playback-last",s),c=u(".art-auto-playback-jump",s),d=u(".art-auto-playback-close",s);y(d,r.close);let p=null;function h(){const r=(a.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),w(s,"display","none"),r&&r>=o.AUTO_PLAYBACK_MIN&&(w(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${H(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{w(s,"display","none")}),n(c,"click",()=>{t.seek=r,Y(t.play()),w(i,"display","none"),w(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{w(s,"display","none")},o.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=a.get("times")||{},r=Object.keys(e);r.length>o.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,a.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return a.get("times")||{}},clear:()=>a.del("times"),delete(t){const e=a.get("times")||{};return delete e[t],a.set("times",e),e}}}function Ht(t){const{constructor:e,proxy:r,template:{$player:a,$video:o}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,g(a,"art-fast-forward"))};return r(o,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,f(a,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return v(a,"art-fast-forward")}}}function Wt(t){const{layers:e,icons:r,template:{$player:a}}=t;function o(){return v(a,"art-lock")}function n(){f(a,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){g(a,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const a=y(e,r.lock),o=y(e,r.unlock);w(a,"display","none"),t.on("lock",t=>{t?(w(a,"display","inline-flex"),w(o,"display","none")):(w(a,"display","none"),w(o,"display","inline-flex"))})},click(){o()?i():n()}}),{name:"lock",get state(){return o()},set state(t){t?n():i()}}}function jt(t){return t.on("control",e=>{e?g(t.template.$player,"art-mini-progress-bar"):f(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class Ut{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(jt),e.lock&&p&&this.add(Wt),e.autoPlayback&&!e.isLive&&this.add(Bt),e.autoOrientation&&p&&this.add(Ft),e.fastForward&&p&&!e.isLive&&this.add(Ht);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return V(!K(this,r),`Cannot add a plugin that already has the same name: ${r}`),X(this,r,{value:e}),this}}class qt extends ft{constructor(t){super(t);const{option:e,controls:r,template:{$setting:a}}=t;this.name="setting",this.$parent=a,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=C(t,r.setting),a=C(t,this.$parent);!this.show||e||a||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,PLAYBACK_RATE:o}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:a,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:o.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,ASPECT_RATIO:o}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:a,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:o.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,FLIP:o}}=t;function n(t){return e.get(B(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:a,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:o.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:a}=t;return{width:a.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){for(let r=0;r{e.default=e===t,e.default&&e.$item&&$(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,a=[]){for(let o=0;oe}),X(n,"$parents",{get:()=>r}),X(n,"$option",{get:()=>t});const a=[];X(n,"$events",{get:()=>a}),X(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,a)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){const{controls:t,constructor:{SETTING_WIDTH:e,SETTING_ITEM_HEIGHT:r},template:{$player:a,$setting:o}}=this.art;if(t.setting&&this.show){const n=this.active[0]?.$parent?.width||e,{left:i,width:s}=A(t.setting),{left:l,width:c}=A(a),d=i-l+s/2-n/2;if(w(o,"height",`${this.active===this.option?this.active.length*r:(this.active.length+1)*r}px`),w(o,"width",`${n}px`),this.art.isRotate||p)return;d+n>c?(w(o,"left",null),w(o,"right",null)):(w(o,"left",`${d}px`),w(o,"right","auto"))}}inactivate(t){for(let e=0;e'),s=L("div");f(s,"art-setting-item-left-icon"),y(s,a),y(i,s),y(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),y(e,n)}createItem(t,e=!1){if(!this.cache.has(t.$option))return;const r=this.cache.get(t.$option),a=t.$item;let o="selector";K(t,"switch")&&(o="switch"),K(t,"range")&&(o="range"),K(t,"onClick")&&(o="button");const{icons:n,proxy:i,constructor:s}=this.art,l=L("div");f(l,"art-setting-item"),w(l,"height",`${s.SETTING_ITEM_HEIGHT}px`),l.dataset.name=t.name||"",l.dataset.value=t.value||"";const c=y(l,'
'),d=y(l,'
'),p=L("div");switch(f(p,"art-setting-item-left-icon"),o){case"button":case"switch":case"range":y(p,t.icon||n.config);break;case"selector":t.selector?.length?y(p,t.icon||n.config):y(p,n.check)}y(c,p),X(t,"$icon",{configurable:!0,get:()=>p}),X(t,"icon",{configurable:!0,get:()=>p.innerHTML,set(t){p.innerHTML="",y(p,t)}});const h=L("div");f(h,"art-setting-item-left-text"),y(h,t.html||""),y(c,h),X(t,"$html",{configurable:!0,get:()=>h}),X(t,"html",{configurable:!0,get:()=>h.innerHTML,set(t){h.innerHTML="",y(h,t)}});const u=L("div");switch(f(u,"art-setting-item-right-tooltip"),y(u,t.tooltip||""),y(d,u),X(t,"$tooltip",{configurable:!0,get:()=>u}),X(t,"tooltip",{configurable:!0,get:()=>u.innerHTML,set(t){u.innerHTML="",y(u,t)}}),o){case"switch":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,n.switchOn),a=y(e,n.switchOff);w(t.switch?a:r,"display","none"),y(d,e),X(t,"$switch",{configurable:!0,get:()=>e});let o=t.switch;X(t,"switch",{configurable:!0,get:()=>o,set(t){o=t,t?(w(a,"display","none"),w(r,"display",null)):(w(a,"display",null),w(r,"display","none"))}});break}case"range":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],f(r,"art-setting-range"),y(d,e),X(t,"$range",{configurable:!0,get:()=>r});let a=[...t.range];X(t,"range",{configurable:!0,get:()=>a,set(t){a=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(t.selector?.length){const t=L("div");f(t,"art-setting-item-right-icon"),y(t,n.arrowRight),y(d,t)}}switch(o){case"switch":if(t.onSwitch){const e=i(l,"click",async e=>{t.switch=await t.onSwitch.call(this.art,t,l,e)});t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=i(t.$range,"change",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onRange.call(this.art,t,l,e)});t.$events.push(e)}if(t.onChange){const e=i(t.$range,"input",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onChange.call(this.art,t,l,e)});t.$events.push(e)}}break;case"selector":{const e=i(l,"click",async e=>{t.selector?.length?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=await t.$parent.onSelect.call(this.art,t,l,e)))});t.$events.push(e),t.default&&f(l,"art-current")}break;case"button":if(t.onClick){const e=i(l,"click",async e=>{t.tooltip=await t.onClick.call(this.art,t,l,e)});t.$events.push(e)}}X(t,"$item",{configurable:!0,get:()=>l}),e?z(l,a):y(r,l),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){if(this.active=t,this.cache.has(t)){$(this.cache.get(t),"art-current")}else{const e=L("div");this.cache.set(t,e),f(e,"art-setting-panel"),y(this.$parent,e),$(e,"art-current"),t[0]?.$parent&&this.createHeader(t[0]);for(let r=0;rnull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){return this.art.template.$video?.textTracks?.[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?x(r,t):w(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?q(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}async switch(t,e={}){const{i18n:r,notice:a,option:o}=this.art,n={...o.subtitle,...e,url:t},i=await this.init(n);return e.name&&(a.show=`${r.get("Switch Subtitle")}: ${e.name}`),i}createTrack(t,e){const{template:r,proxy:a,option:o}=this.art,{$video:n,$track:i}=r,s=L("track");s.default=!0,s.kind=t,s.src=e,s.label=o.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,b(i),y(n,s),r.$track=s,this.destroyEvent=a(this.textTrack,"cuechange",()=>this.update())}async init(t){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(o(t,mt.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||N(t.url)){case"srt":{const e=Q(r);return tt(t.onVttLoad(e))}case"ass":{const e=et(r);return tt(t.onVttLoad(e))}case"vtt":return tt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null}}class Zt{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=u(e.container),V(this.$container,`No container element found by ${e.container}`)),V(I(),"The current browser does not support flex layout");const a=this.$container.tagName.toLowerCase();V("div"===a,`Unsupported container element type, only support 'div' but got '${a}'`),V(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${n}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return u(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=Zt.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);V(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),z(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&f(this.$player,"art-backdrop"),p&&f(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":f(this.$player,"art-destroy")}}class Jt{on(t,e,r){const a=this.e||(this.e={});return(a[t]||(a[t]=[])).push({fn:e,ctx:r}),this}once(t,e,r){const a=this;function o(...n){a.off(t,o),e.apply(r,n)}return o._=e,this.on(t,o,r)}emit(t,...e){const r=((this.e||(this.e={}))[t]||[]).slice();for(let a=0;ae.call(this,this)),ee.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${ee.version}`);for(let e=0;et(`Event@${e.type}`))}te.push(this)}static get instances(){return te}static get version(){return n}static get config(){return i}static get utils(){return nt}static get scheme(){return mt}static get Emitter(){return Jt}static get validator(){return o}static get kindOf(){return o.kindOf}static get html(){return Zt.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:l?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:navigator?.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){ee.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),te.splice(te.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return ee.STYLE=Gt,ee.DEBUG=!1,ee.CONTEXTMENU=!0,ee.NOTICE_TIME=2e3,ee.SETTING_WIDTH=250,ee.SETTING_ITEM_WIDTH=200,ee.SETTING_ITEM_HEIGHT=35,ee.RESIZE_TIME=200,ee.SCROLL_TIME=200,ee.SCROLL_GAP=50,ee.AUTO_PLAYBACK_MAX=10,ee.AUTO_PLAYBACK_MIN=5,ee.AUTO_PLAYBACK_TIMEOUT=3e3,ee.RECONNECT_TIME_MAX=5,ee.RECONNECT_SLEEP_TIME=1e3,ee.CONTROL_HIDE_TIME=3e3,ee.DBCLICK_TIME=300,ee.DBCLICK_FULLSCREEN=!0,ee.MOBILE_DBCLICK_PLAY=!0,ee.MOBILE_CLICK_PLAY=!1,ee.AUTO_ORIENTATION_TIME=200,ee.INFO_LOOP_TIME=1e3,ee.FAST_FORWARD_VALUE=3,ee.FAST_FORWARD_TIME=1e3,ee.TOUCH_MOVE_RATIO=.5,ee.VOLUME_STEP=.1,ee.SEEK_STEP=5,ee.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],ee.ASPECT_RATIO=["default","4:3","16:9"],ee.FLIP=["normal","horizontal","vertical"],ee.FULLSCREEN_WEB_IN_BODY=!0,ee.LOG_VERSION=!0,ee.USE_RAF=!1,ee.REMOVE_SRC_WHEN_DESTROY=!0,h&&(window.Artplayer=ee,M("artplayer-style",Gt),setTimeout(()=>{ee.LOG_VERSION&&console.log(`%c ArtPlayer %c ${ee.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),ee}); +!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2=1,p=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(s)||d,h="undefined"!==typeof window&&"undefined"!==typeof document;function u(t,e=document){return e.querySelector(t)}function m(t,e=document){return Array.from(e.querySelectorAll(t))}function f(t,e){return t.classList.add(e)}function g(t,e){return t.classList.remove(e)}function v(t,e){return t.classList.contains(e)}function y(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function b(t){return t.parentNode.removeChild(t)}function w(t,e,r){return t.style[e]=r,t}function x(t,e){for(const r in e)w(t,r,e[r]);return t}function k(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function $(t,e){k(t).forEach(t=>g(t,e)),f(t,e)}function T(t,e,r="top"){p||(t.setAttribute("aria-label",e),f(t,"hint--rounded"),f(t,`hint--${r}`))}function E(t,e=0){const r=t.getBoundingClientRect(),a=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=a&&r.top+r.height+e>=0,i=r.left-e<=o+e&&r.left+r.width+e>=0;return n&&i}function C(t,e){return R(t).includes(e)}function z(t,e){return e.parentNode.replaceChild(t,e),t}function L(t){return document.createElement(t)}function S(t="",e=""){const r=L("i");return f(r,"art-icon"),f(r,`art-icon-${t}`),y(r,e),r}function M(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function I(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function P(t){return t.getBoundingClientRect()}function A(t,e){return new Promise((r,a)=>{const o=new Image;o.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=o.width*e,n.height=o.height*e,i.drawImage(o,0,0,n.width,n.height),n.toBlob(e=>{const o=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(o),a(new Error(`Image load failed: ${t}`))},n.src=o})}else r(o)},o.onerror=function(){a(new Error(`Image load failed: ${t}`))},o.src=t})}function R(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function O(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class _ extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function V(t,e){if(!t)throw new _(e);return t}function Y(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function N(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function D(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function F(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function B(t){return t.charAt(0).toUpperCase()+t.slice(1)}function H(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),a=Math.floor(t-3600*e-60*r);return(e>0?[e,r,a]:[r,a]).map(t=>t<10?`0${t}`:String(t)).join(":")}const W={"&":"&","<":"<",">":">","'":"'",'"':"""},j={"&":"&","<":"<",">":">","'":"'",""":'"'},U=/(&|<|>|'|")/g;function q(t){return t.replace(/[&<>'"]/g,t=>W[t]||t)}const X=Object.defineProperty,{hasOwnProperty:G}=Object.prototype;function K(t,e){return G.call(t,e)}function Z(t,e){return Object.getOwnPropertyDescriptor(t,e)}function J(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(a=>{const o=t[a],n=r[a];let i;i=Array.isArray(o)&&Array.isArray(n)?o.concat(...n):e(o)&&e(n)?J(o,n):n,X(t,a,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function Q(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let a=r.slice(0,3);return 1===r.length&&(a=`${r}00`),2===r.length&&(a=`${r}0`),`${e},${a}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function tt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function et(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const a=t.match(e);if(!a)return null;const[,o="",n="",,,i=""]=a;return{start:r(o.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function rt(t=0){return new Promise(e=>setTimeout(e,t))}function at(t,e){let r;return function(...a){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,a)),e)}}function ot(t,e){let r=!1;return function(...a){r||(t.apply(this,a),r=!0,setTimeout(()=>{r=!1},e))}}const nt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:_,addClass:f,append:y,assToVtt:et,capitalize:B,clamp:F,createElement:L,debounce:at,def:X,download:D,errorHandle:V,escape:q,get:Z,getComposedPath:R,getExt:N,getIcon:S,getRect:P,getSafeAreaInsets:O,getStyle:function(t,e,r=!0){const a=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(a):a},has:K,hasClass:v,includeFromEvent:C,inverseClass:$,isBrowser:h,isIOS:c,isIOS13:d,isInViewport:E,isMobile:p,isSafari:l,loadImg:A,mergeDeep:J,query:u,queryAll:m,remove:b,removeClass:g,replaceElement:z,secondToTime:H,setStyle:w,setStyleText:M,setStyles:x,siblings:k,silencePromise:Y,sleep:rt,srtToVtt:Q,supportsFlex:I,throttle:ot,tooltip:T,unescape:function(t){return t.replace(U,t=>j[t]||t)},userAgent:s,vttToBlob:tt},Symbol.toStringTag,{value:"Module"})),it="array",st="boolean",lt="string",ct="number",dt="object",pt="function";function ht(t,e,r){return V(e===lt||e===ct||t instanceof Element,`${r.join(".")} require '${lt}' or 'Element' type`)}const ut={html:ht,disable:`?${st}`,name:`?${lt}`,index:`?${ct}`,style:`?${dt}`,click:`?${pt}`,mounted:`?${pt}`,tooltip:`?${lt}|${ct}`,width:`?${ct}`,selector:`?${it}`,onSelect:`?${pt}`,switch:`?${st}`,onSwitch:`?${pt}`,range:`?${it}`,onRange:`?${pt}`,onChange:`?${pt}`},mt={id:lt,container:ht,url:lt,poster:lt,type:lt,theme:lt,lang:lt,volume:ct,isLive:st,muted:st,autoplay:st,autoSize:st,autoMini:st,loop:st,flip:st,playbackRate:st,aspectRatio:st,screenshot:st,setting:st,hotkey:st,pip:st,mutex:st,backdrop:st,fullscreen:st,fullscreenWeb:st,subtitleOffset:st,miniProgressBar:st,useSSR:st,playsInline:st,lock:st,gesture:st,fastForward:st,autoPlayback:st,autoOrientation:st,airplay:st,proxy:`?${pt}`,plugins:[pt],layers:[ut],contextmenu:[ut],settings:[ut],controls:[{...ut,position:(t,e,r)=>{const a=["top","left","right"];return V(a.includes(t),`${r.join(".")} only accept ${a.toString()} as parameters`)}}],quality:[{default:`?${st}`,html:lt,url:lt}],highlight:[{time:ct,text:lt}],thumbnails:{url:lt,number:ct,column:ct,width:ct,height:ct,scale:ct},subtitle:{url:lt,name:lt,type:lt,style:dt,escape:st,encoding:lt,onVttLoad:pt},moreVideoAttr:dt,i18n:dt,icons:dt,cssVar:dt,customType:dt};class ft{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return v(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?f(e,r):g(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",o(e,ut),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;V(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const a=L("div");f(a,`art-${this.name}`),f(a,`art-${this.name}-${r}`);const n=Array.from(this.$parent.children);a.dataset.index=e.index||this.id;const i=n.find(t=>Number(t.dataset.index)>=Number(a.dataset.index));i?i.insertAdjacentElement("beforebegin",a):y(this.$parent,a),e.html&&y(a,e.html),e.style&&x(a,e.style),e.tooltip&&T(a,e.tooltip);const s=[];if(e.click){const t=this.art.events.proxy(a,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});s.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,a,s),this[r]=a,this.cache.set(r,{$ref:a,events:s,option:e}),e.mounted&&e.mounted.call(this.art,a),a}remove(t){V(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],b(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class gt extends ft{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,p||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:a}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:a}}=e,o=a.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return{...t,html:`${r.get("Play Speed")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.playbackRate=Number(a),t.show=!1)},mounted:t=>{const r=u('[data-value="1"]',t);r&&$(r,"art-current"),e.on("video:ratechange",()=>{const r=m("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&$(r,"art-current")})}}}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:a}}=e,o=a.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return{...t,html:`${r.get("Aspect Ratio")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.aspectRatio=a,t.show=!1)},mounted:t=>{const r=u('[data-value="default"]',t);r&&$(r,"art-current"),e.on("aspectRatio",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:a}}=e,o=a.map(t=>`${r.get(B(t))}`).join("");return{...t,html:`${r.get("Video Flip")}: ${o}`,click:(t,r)=>{const{value:a}=r.target.dataset;a&&(e.flip=a.toLowerCase(),t.show=!1)},mounted:t=>{const r=u('[data-value="normal"]',t);r&&$(r,"art-current"),e.on("flip",e=>{const r=m("span",t).find(t=>t.dataset.value===e);r&&$(r,"art-current")})}}}}({name:"flip",index:30})),this.add(function(t){return e=>({...t,html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return{...t,html:`ArtPlayer ${n}`}}({name:"version",index:50})),this.add(function(t){return e=>({...t,html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let o=0;o{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,o=t.clientY,{height:n,width:i,left:s,top:l}=P(r),{height:c,width:d}=P(a);let p=e-s,h=o-l;e+d>s+i&&(p=i-d),o+c>l+n&&(h=n-c),x(a,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{C(t,a)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function vt(t,e){const{$progress:r}=t.template,{left:a}=P(r),o=F((p?e.touches[0].clientX:e.clientX)-a,0,r.clientWidth),n=o/r.clientWidth*t.duration;return{second:n,time:H(n),width:o,percentage:F(o/r.clientWidth,0,1)}}function yt(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,a=r*t.duration;t.emit("setBar","played",r,e),t.seek=a}else{const{second:r,percentage:a}=vt(t,e);t.emit("setBar","played",a,e),t.seek=r}}function bt(t){return e=>{const{icons:r,option:a,proxy:o}=e,{$player:n,$progress:i}=e.template;return{...t,html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=u(".art-progress-hover",t),d=u(".art-progress-loaded",t),h=u(".art-progress-played",t),m=u(".art-progress-highlight",t),v=u(".art-progress-indicator",t),b=u(".art-progress-tip",t);function x(r,a){const{width:o,time:n}=a||vt(e,r);b.textContent=n||"00:00";const i=b.clientWidth;o<=i/2?w(b,"left",0):o>t.clientWidth-i/2?w(b,"left",t.clientWidth-i+"px"):w(b,"left",o-i/2+"px")}r.indicator?y(v,r.indicator):w(v,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,a,o){const i="played"===r&&o&&p;if("loaded"===r&&w(d,"width",100*a+"%"),"hover"===r&&(w(c,"width",100*a+"%"),C(o,m)?function(r){const{width:a}=vt(e,r),{text:o}=r.target.dataset;b.textContent=o;const n=b.clientWidth;a<=n/2?w(b,"left",0):a>t.clientWidth-n/2?w(b,"left",t.clientWidth-n+"px"):w(b,"left",a-n/2+"px")}(o):x(o),0===a?g(n,"art-progress-hover"):f(n,"art-progress-hover")),"played"===r&&(w(h,"width",100*a+"%"),w(v,"left",100*a+"%")),i){f(n,"art-progress-hover");x(o,{width:t.clientWidth*a,time:H(a*e.duration)}),clearTimeout(s),s=setTimeout(()=>{g(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){m.textContent="";for(let t=0;t`;y(m,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),p||(o(i,"click",t=>{t.target!==v&&yt(e,t)}),o(i,"mousemove",t=>{const{percentage:r}=vt(e,t);e.emit("setBar","hover",r,t)}),o(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),o(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:a}=vt(e,t);e.emit("setBar","played",a,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}}}}class wt extends ft{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:a}=this.art.template;t.on("mousemove",()=>{p||(this.show=!0)}),t.on("click",()=>{p?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=C(t,a)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(g(r,"art-hide-cursor"),f(r,"art-hover"),this.timer=Date.now()):(f(r,"art-hide-cursor"),g(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(bt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.play),i=y(t,a.pause);function s(){w(n,"display","flex"),w(i,"display","none")}function l(){w(n,"display","none"),w(i,"display","flex")}T(n,o.get("Play")),T(i,o.get("Pause")),r(n,"click",()=>{Y(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>({...t,mounted:t=>{const{proxy:r,icons:a}=e,o=y(t,a.volume),n=y(t,a.volumeClose),i=y(t,'
'),s=y(i,'
'),l=y(s,'
'),c=y(s,'
'),d=y(c,'
'),h=y(d,'
'),u=y(c,'
');function m(t){const{top:e,height:r}=P(c);return 1-(t.clientY-e)/r}function f(){if(e.muted||0===e.volume)w(o,"display","none"),w(n,"display","flex"),w(u,"top","100%"),w(h,"top","100%"),l.textContent=0;else{const t=100*e.volume;w(o,"display","flex"),w(n,"display","none"),w(u,"top",100-t+"%"),w(h,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(f(),e.on("video:volumechange",f),r(o,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),p)w(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=m(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=m(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>({...t,style:p?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${H(e.currentTime)} / ${H(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const a=["video:loadedmetadata","video:timeupdate","video:progress"];for(let o=0;o{this.art.quality=t.quality}),t.screenshot&&!p&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{T(t,o.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e;y(t,a.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{T(t,o.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:a}=e;y(t,a.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenWebOn),i=y(t,a.fullscreenWebOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(T(t,o.get("Exit Web Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Web Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>({...t,tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:a,i18n:o}=e,n=y(t,a.fullscreenOn),i=y(t,a.fullscreenOff);w(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(T(t,o.get("Exit Fullscreen")),w(n,"display","none"),w(i,"display","inline-flex")):(T(t,o.get("Fullscreen")),w(n,"display","inline-flex"),w(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),X(e,"$control_item",{get:()=>r}),X(e,"$control_value",{get:()=>o})}const i=a(n,"click",async e=>{const r=R(e),a=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(a),t.onSelect&&(o.innerHTML=await t.onSelect.call(this.art,a,a.$control_item,e))});r.push(i)}}function xt(t,e,r,a){const o=e-a,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(o)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,o);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class kt{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:a,$video:o}}=t;function n(e){C(e,a)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(o,"click",e=>{const a=Date.now();i.push(a);const{MOBILE_CLICK_PLAY:o,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>a-t<=n);switch(c.length){case 1:t.emit("click",e),p?!t.isLock&&o&&Y(t.toggle()):Y(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),p?!t.isLock&&s&&Y(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{f(r,"art-hover"),t.emit("hover",!0,e)},e=>{g(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:a}=t;t.on("resize",()=>{const{aspectRatio:e,notice:a}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,a.show=""});const o=at(()=>t.emit("resize"),a.RESIZE_TIME);t.on("window:orientationchange",()=>o()),t.on("window:resize",()=>o()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>o())}(t,this),function(t,e){if(p&&!t.option.isLive){const{$video:r,$progress:a}=t.template;let o=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){o===a&&yt(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:a,pageY:n}=e.touches[0],c=xt(i,s,a,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=F((a-i)/t.width,-1,1),d=F((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=o===r?t.constructor.TOUCH_MOVE_RATIO:1,u=F(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",F(u/t.duration,0,1),e),t.notice.show=`${H(u)} / ${H(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,o=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{o=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(a,"touchstart",t=>{o=a,c(t)}),e.proxy(a,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:a}}=t,o=ot(()=>{t.emit("view",E(a,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>o()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],a=["resize","scroll","orientationchange"],o=[];function n(n={}){for(let t=0;t{const a=n.document||i.ownerDocument||document,s=e.proxy(a,r,e=>{t.emit(`document:${r}`,e)});o.push(s)}),a.forEach(r=>{const a=n.window||i.ownerDocument?.defaultView||window,s=e.proxy(a,r,e=>{t.emit(`window:${r}`,e)});o.push(s)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,a={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,a));t.addEventListener(e,r,a);const o=()=>t.removeEventListener(e,r,a);return this.destroyEvents.add(o),o}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class $t{constructor(t){this.art=t,this.keys={},p||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{Y(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n',...t.option.icons};for(const r in e)X(this,r,{get:()=>S(r,e[r])})}}class zt extends ft{constructor(t){super(t),this.name="info",p||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:a,$video:o}}=this.art;t(a,"click",()=>{this.show=!1});let n=null;const i=m("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{w(o,"display","none"),w(n,"display",null)}),a.proxy(e.$state,"click",()=>Y(t.play()))}}class It{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:a}}=this.art;t?(a.textContent=t instanceof Error?t.message.trim():t,f(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{a.textContent="",g(r,"art-notice-show")},e.NOTICE_TIME)):g(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Pt=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],At=(()=>{if("undefined"===typeof document)return!1;const t=Pt[0],e={};for(const r of Pt){if(r[1]in document){for(const[a,o]of r.entries())e[t[a]]=o;return e}}return!1})(),Rt={change:At.fullscreenchange,error:At.fullscreenerror},Ot={request:(t=document.documentElement,e)=>new Promise((r,a)=>{const o=()=>{Ot.off("change",o),r()};Ot.on("change",o);const n=t[At.requestFullscreen](e);n instanceof Promise&&n.then(o).catch(a)}),exit:()=>new Promise((t,e)=>{if(!Ot.isFullscreen)return void t();const r=()=>{Ot.off("change",r),t()};Ot.on("change",r);const a=document[At.exitFullscreen]();a instanceof Promise&&a.then(r).catch(e)}),toggle:(t,e)=>Ot.isFullscreen?Ot.exit():Ot.request(t,e),onchange(t){Ot.on("change",t)},onerror(t){Ot.on("error",t)},on(t,e){const r=Rt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=Rt[t];r&&document.removeEventListener(r,e,!1)},raw:At};function _t(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;t.once("video:loadedmetadata",()=>{var n;Ot.isEnabled?(n=t,Ot.on("change",()=>{n.emit("fullscreen",Ot.isFullscreen),Ot.isFullscreen?(n.state="fullscreen",f(o,"art-fullscreen")):g(o,"art-fullscreen"),n.emit("resize")}),Ot.on("error",t=>{n.emit("fullscreenError",t)}),X(n,"fullscreen",{get:()=>Ot.isFullscreen,async set(t){t?await Ot.request(o):await Ot.exit()}})):a.webkitSupportsFullscreen?(t=>{t.on("document:webkitfullscreenchange",()=>{t.emit("fullscreen",t.fullscreen),t.emit("resize")}),X(t,"fullscreen",{get:()=>document.fullscreenElement===a,set(e){e?(t.state="fullscreen",a.webkitEnterFullscreen()):a.webkitExitFullscreen()}})})(t):X(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),X(t,"fullscreen",Z(t,"fullscreen"))})}function Vt(t){const{icons:e,proxy:r,storage:a,template:{$player:o,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(g(o,"art-mini"),w(e,"display","none"),o.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(w(e,"display","none"),w(r,"display","flex")):(w(e,"display","flex"),w(r,"display","none"))}function p(){const{$mini:e}=t.template,r=P(e),o=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;a.set("top",o),a.set("left",n),w(e,"top",`${o}px`),w(e,"left",`${n}px`)}X(t,"mini",{get:()=>v(o,"art-mini"),set(h){if(h){t.state="mini",f(o,"art-mini");const h=function(){const{$mini:o}=t.template;if(o)return y(o,n),w(o,"display","flex");{const o=L("div");f(o,"art-mini-popup"),y(document.body,o),t.template.$mini=o,y(o,n);const p=y(o,'
');y(p,e.close),r(p,"click",c);const h=y(o,'
'),u=y(h,e.play),m=y(h,e.pause);return r(u,"click",()=>Y(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(o,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){f(o,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;w(o,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,g(o,"art-mini-dragging");const t=P(o);a.set("left",t.left),a.set("top",t.top),w(o,"left",`${t.left}px`),w(o,"top",`${t.top}px`),w(o,"transform",null)}}),o}}(),u=a.get("top"),m=a.get("left");"number"===typeof u&&"number"===typeof m?(w(h,"top",`${u}px`),w(h,"left",`${m}px`),E(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Yt(t){const{i18n:e,notice:r,template:{$video:a}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:a}=t;e.disablePictureInPicture=!1,X(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw a.show=t,t})):document.exitPictureInPicture().catch(t=>{throw a.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):a.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),X(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):X(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Nt(t){const{option:e,template:{$progress:r,$video:a}}=t;let o=null,n=!1,i=null;t.on("setBar",async(o,s,l)=>{const c=t.controls?.thumbnails,{url:d,scale:h}=e.thumbnails;if(!c||!d)return;if("hover"===o||"played"===o&&l&&p){if(i||n||(n=!0,i=await A(d,h),n=!1),!i)return;const o=r.clientWidth*s;o>0&&or.clientWidth-h/2?w(n,"left",r.clientWidth-h+"px"):w(n,"left",o-h/2+"px")}(o)}}),X(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(o),o=null,n=!1,i=null)}})}Object.defineProperties(Ot,{isFullscreen:{get:()=>Boolean(document[At.fullscreenElement])},element:{enumerable:!0,get:()=>document[At.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[At.fullscreenEnabled])}});class Dt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;X(t,"url",{get:()=>r.src,async set(a){if(a){const o=t.url,n=e.type||N(a),i=e.customType[n];n&&i?(await rt(),t.loading.show=!0,i.call(t,r,a,t)):(URL.revokeObjectURL(o),r.src=a),o!==t.url&&(t.option.url=a,t.isReady&&o&&t.once("video:canplay",()=>{t.emit("restart",a)}))}else await rt(),t.loading.show=!0}})}(t),function(t){const{template:{$video:e}}=t;X(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:a,constructor:{instances:o},template:{$video:n}}=t;X(t,"play",{async value(){const i=await n.play();if(r.show=e.get("Play"),t.emit("play"),a.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;X(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${H(t.currentTime)} / ${H(t.duration)}`),t.emit("seek",t.currentTime,r)}}),X(t,"forward",{set(e){t.seek=t.currentTime+e}}),X(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:a,storage:o}=t;X(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=F(t,0,1),a.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&o.set("volume",e.volume)}}),X(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;X(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=F(r,0,t.duration))}})}(t),function(t){X(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((a,o)=>{if(e===t.url)return void a();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),o(e)},metadata:()=>{t.currentTime=r},canplay:async()=>{t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&await Y(t.play()),t.notice.show="",a()}};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}X(t,"switchQuality",{value:r=>e(r,t.currentTime)}),X(t,"switchUrl",{value:t=>e(t,0)}),X(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:a}=t;X(t,"playbackRate",{get:()=>e.playbackRate,set(o){if(o){if(o===e.playbackRate)return;e.playbackRate=o,a.show=`${r.get("Rate")}: ${1===o?r.get("Normal"):`${o}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:a,$player:o}}=t;X(t,"aspectRatio",{get:()=>o.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)w(a,"width",null),w(a,"height",null),w(a,"margin",null),delete o.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=o,i=e/r,s=t[0]/t[1];i>s?(w(a,"width",s*r+"px"),w(a,"height","100%"),w(a,"margin","0 auto")):(w(a,"width","100%"),w(a,"height",e/s+"px"),w(a,"margin","auto 0")),o.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,a=L("canvas");X(t,"getDataURL",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),t(a.toDataURL("image/png"))}catch(n){e.show=n,o(n)}})}),X(t,"getBlobUrl",{value:()=>new Promise((t,o)=>{try{a.width=r.videoWidth,a.height=r.videoHeight,a.getContext("2d").drawImage(r,0,0),a.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,o(n)}})}),X(t,"screenshot",{value:async e=>{const a=await t.getDataURL();return D(a,`${e||`artplayer_${H(r.currentTime)}`}.png`),t.emit("screenshot",a),a}})}(t),_t(t),function(t){const{constructor:e,template:{$container:r,$player:a}}=t;let o="";X(t,"fullscreenWeb",{get:()=>v(a,"art-fullscreen-web"),set(n){n?(o=a.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&y(document.body,a),t.state="fullscreenWeb",w(a,"width","100%"),w(a,"height","100%"),f(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&y(r,a),o&&(a.style.cssText=o,o=""),g(a,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Yt(t),function(t){const{$video:e}=t.template;X(t,"loaded",{get:()=>t.loadedTime/e.duration}),X(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){X(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;X(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:a}=t.template;X(t,"autoSize",{value(){const{videoWidth:o,videoHeight:n}=a,{width:i,height:s}=P(e),l=o/n;if(i/s>l)w(r,"width",s*l/i*100+"%"),w(r,"height","100%");else{const t=i/l/s*100;w(r,"width","100%"),w(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){X(t,"rect",{get:()=>P(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[a]})}X(t,"x",{get:()=>t.left+window.pageXOffset}),X(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:a}=t;X(t,"flip",{get:()=>e.dataset.flip||"normal",set(o){o||(o="normal"),"normal"===o?delete e.dataset.flip:e.dataset.flip=o,a.show=`${r.get("Video Flip")}: ${r.get(B(o))}`,t.emit("flip",o)}})}(t),Vt(t),function(t){const{template:{$poster:e}}=t;X(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch{return""}},set(t){w(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;X(t,"autoHeight",{value(){const{clientWidth:a}=e,{videoHeight:o,videoWidth:n}=r,i=o*(a/n);w(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;X(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){X(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){X(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];X(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let a=0;aa.$track?.offset||0,set(o){const{cues:n}=t.subtitle;if(!a.$track||0===n.length)return;const i=F(o,-10,10);a.$track.offset=i;for(let e=0;e{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,X(t,"airplay",{value(){n?(o.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){X(t,"quality",{set(e){const{controls:r,notice:a,i18n:o}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:n?.html||"",selector:e,onSelect:async e=>(await t.switchQuality(e.url),a.show=`${o.get("Switch Video")}: ${e.html}`,e.html)})}})}(t),Nt(t),function(t){const{i18n:e,notice:r,option:a,constructor:o,proxy:n,template:{$player:s,$video:l,$poster:c}}=t;let d=0;for(let p=0;p{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{d=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{a.loop?(t.seek=0,Y(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",async n=>{d{t.emit("resize"),p&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,w(c,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:a,$poster:o}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(a.volume=F(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(a.volume=F(n,0,1)),e.poster&&w(o,"backgroundImage",`url(${e.poster})`),e.autoplay&&(a.autoplay=e.autoplay),e.playsInline&&(a.playsInline=!0,a["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Ft(t){const{notice:e,constructor:r,template:{$player:a,$video:o}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=o,r=document.documentElement.clientWidth,a=document.documentElement.clientHeight;return t>e&&ra}return t.on("fullscreenWeb",e=>{if(e){if(l()){const e=Number(r.AUTO_ORIENTATION_TIME??0);setTimeout(()=>{t.fullscreenWeb&&!v(a,n)&&function(){const e=O(),r=document.documentElement.clientWidth,o=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;w(a,"width",`${o}px`),w(a,"height",`${i}px`),w(a,"transform-origin","0 0"),w(a,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),f(a,n),t.isRotate=!0,t.emit("resize")}()},e)}}else v(a,n)&&(w(a,"width",""),w(a,"height",""),w(a,"transform-origin",""),w(a,"transform",""),g(a,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",async t=>{const r=!!screen?.orientation?.lock;if(t){if(r&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";await screen.orientation.lock(t),s=!0,f(a,i)}catch(o){s=!1,e.show=o}}else if(v(a,i)&&g(a,i),r&&s){try{screen.orientation.unlock()}catch{}s=!1}}),{name:"autoOrientation",get state(){return v(a,n)}}}function Bt(t){const{i18n:e,icons:r,storage:a,constructor:o,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=u(".art-auto-playback-last",s),c=u(".art-auto-playback-jump",s),d=u(".art-auto-playback-close",s);y(d,r.close);let p=null;function h(){const r=(a.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),w(s,"display","none"),r&&r>=o.AUTO_PLAYBACK_MIN&&(w(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${H(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{w(s,"display","none")}),n(c,"click",()=>{t.seek=r,Y(t.play()),w(i,"display","none"),w(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{w(s,"display","none")},o.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=a.get("times")||{},r=Object.keys(e);r.length>o.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,a.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return a.get("times")||{}},clear:()=>a.del("times"),delete(t){const e=a.get("times")||{};return delete e[t],a.set("times",e),e}}}function Ht(t){const{constructor:e,proxy:r,template:{$player:a,$video:o}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,g(a,"art-fast-forward"))};return r(o,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,f(a,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return v(a,"art-fast-forward")}}}function Wt(t){const{layers:e,icons:r,template:{$player:a}}=t;function o(){return v(a,"art-lock")}function n(){f(a,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){g(a,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const a=y(e,r.lock),o=y(e,r.unlock);w(a,"display","none"),t.on("lock",t=>{t?(w(a,"display","inline-flex"),w(o,"display","none")):(w(a,"display","none"),w(o,"display","inline-flex"))})},click(){o()?i():n()}}),{name:"lock",get state(){return o()},set state(t){t?n():i()}}}function jt(t){return t.on("control",e=>{e?g(t.template.$player,"art-mini-progress-bar"):f(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class Ut{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(jt),e.lock&&p&&this.add(Wt),e.autoPlayback&&!e.isLive&&this.add(Bt),e.autoOrientation&&p&&this.add(Ft),e.fastForward&&p&&!e.isLive&&this.add(Ht);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return V(!K(this,r),`Cannot add a plugin that already has the same name: ${r}`),X(this,r,{value:e}),this}}class qt extends ft{constructor(t){super(t);const{option:e,controls:r,template:{$setting:a}}=t;this.name="setting",this.$parent=a,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=C(t,r.setting),a=C(t,this.$parent);!this.show||e||a||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,PLAYBACK_RATE:o}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:a,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:o.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,ASPECT_RATIO:o}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:a,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:o.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:a,FLIP:o}}=t;function n(t){return e.get(B(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:a,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:o.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:a}=t;return{width:a.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){for(let r=0;r{e.default=e===t,e.default&&e.$item&&$(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,a=[]){for(let o=0;oe}),X(n,"$parents",{get:()=>r}),X(n,"$option",{get:()=>t});const a=[];X(n,"$events",{get:()=>a}),X(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,a)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){const{controls:t,constructor:{SETTING_WIDTH:e,SETTING_ITEM_HEIGHT:r},template:{$player:a,$setting:o}}=this.art;if(t.setting&&this.show){const n=this.active[0]?.$parent?.width||e,{left:i,width:s}=P(t.setting),{left:l,width:c}=P(a),d=i-l+s/2-n/2;if(w(o,"height",`${this.active===this.option?this.active.length*r:(this.active.length+1)*r}px`),w(o,"width",`${n}px`),this.art.isRotate||p)return;d+n>c?(w(o,"left",null),w(o,"right",null)):(w(o,"left",`${d}px`),w(o,"right","auto"))}}inactivate(t){for(let e=0;e'),s=L("div");f(s,"art-setting-item-left-icon"),y(s,a),y(i,s),y(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),y(e,n)}createItem(t,e=!1){if(!this.cache.has(t.$option))return;const r=this.cache.get(t.$option),a=t.$item;let o="selector";K(t,"switch")&&(o="switch"),K(t,"range")&&(o="range"),K(t,"onClick")&&(o="button");const{icons:n,proxy:i,constructor:s}=this.art,l=L("div");f(l,"art-setting-item"),w(l,"height",`${s.SETTING_ITEM_HEIGHT}px`),l.dataset.name=t.name||"",l.dataset.value=t.value||"";const c=y(l,'
'),d=y(l,'
'),p=L("div");switch(f(p,"art-setting-item-left-icon"),o){case"button":case"switch":case"range":y(p,t.icon||n.config);break;case"selector":t.selector?.length?y(p,t.icon||n.config):y(p,n.check)}y(c,p),X(t,"$icon",{configurable:!0,get:()=>p}),X(t,"icon",{configurable:!0,get:()=>p.innerHTML,set(t){p.innerHTML="",y(p,t)}});const h=L("div");f(h,"art-setting-item-left-text"),y(h,t.html||""),y(c,h),X(t,"$html",{configurable:!0,get:()=>h}),X(t,"html",{configurable:!0,get:()=>h.innerHTML,set(t){h.innerHTML="",y(h,t)}});const u=L("div");switch(f(u,"art-setting-item-right-tooltip"),y(u,t.tooltip||""),y(d,u),X(t,"$tooltip",{configurable:!0,get:()=>u}),X(t,"tooltip",{configurable:!0,get:()=>u.innerHTML,set(t){u.innerHTML="",y(u,t)}}),o){case"switch":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,n.switchOn),a=y(e,n.switchOff);w(t.switch?a:r,"display","none"),y(d,e),X(t,"$switch",{configurable:!0,get:()=>e});let o=t.switch;X(t,"switch",{configurable:!0,get:()=>o,set(t){o=t,t?(w(a,"display","none"),w(r,"display",null)):(w(a,"display",null),w(r,"display","none"))}});break}case"range":{const e=L("div");f(e,"art-setting-item-right-icon");const r=y(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],f(r,"art-setting-range"),y(d,e),X(t,"$range",{configurable:!0,get:()=>r});let a=[...t.range];X(t,"range",{configurable:!0,get:()=>a,set(t){a=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(t.selector?.length){const t=L("div");f(t,"art-setting-item-right-icon"),y(t,n.arrowRight),y(d,t)}}switch(o){case"switch":if(t.onSwitch){const e=i(l,"click",async e=>{t.switch=await t.onSwitch.call(this.art,t,l,e)});t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=i(t.$range,"change",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onRange.call(this.art,t,l,e)});t.$events.push(e)}if(t.onChange){const e=i(t.$range,"input",async e=>{t.range[0]=t.$range.valueAsNumber,t.tooltip=await t.onChange.call(this.art,t,l,e)});t.$events.push(e)}}break;case"selector":{const e=i(l,"click",async e=>{t.selector?.length?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=await t.$parent.onSelect.call(this.art,t,l,e)))});t.$events.push(e),t.default&&f(l,"art-current")}break;case"button":if(t.onClick){const e=i(l,"click",async e=>{t.tooltip=await t.onClick.call(this.art,t,l,e)});t.$events.push(e)}}X(t,"$item",{configurable:!0,get:()=>l}),e?z(l,a):y(r,l),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){if(this.active=t,this.cache.has(t)){$(this.cache.get(t),"art-current")}else{const e=L("div");this.cache.set(t,e),f(e,"art-setting-panel"),y(this.$parent,e),$(e,"art-current"),t[0]?.$parent&&this.createHeader(t[0]);for(let r=0;rnull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){return this.art.template.$video?.textTracks?.[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?x(r,t):w(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?q(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}async switch(t,e={}){const{i18n:r,notice:a,option:o}=this.art,n={...o.subtitle,...e,url:t},i=await this.init(n);return e.name&&(a.show=`${r.get("Switch Subtitle")}: ${e.name}`),i}createTrack(t,e){const{template:r,proxy:a,option:o}=this.art,{$video:n,$track:i}=r,s=L("track");s.default=!0,s.kind=t,s.src=e,s.label=o.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,b(i),y(n,s),r.$track=s,this.destroyEvent=a(this.textTrack,"cuechange",()=>this.update())}async init(t){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(o(t,mt.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||N(t.url)){case"srt":{const e=Q(r);return tt(t.onVttLoad(e))}case"ass":{const e=et(r);return tt(t.onVttLoad(e))}case"vtt":return tt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null}}class Zt{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=u(e.container),V(this.$container,`No container element found by ${e.container}`)),V(I(),"The current browser does not support flex layout");const a=this.$container.tagName.toLowerCase();V("div"===a,`Unsupported container element type, only support 'div' but got '${a}'`),V(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${n}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return u(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=Zt.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);V(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),z(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&f(this.$player,"art-backdrop"),p&&f(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":f(this.$player,"art-destroy")}}const Jt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class Qt{on(t,e,r){const a=this.e||(this.e={});let o=Jt(a,t)?a[t]:void 0;return o||(o=[],Object.defineProperty(a,t,{value:o,enumerable:!0,configurable:!0,writable:!0})),o.push({fn:e,ctx:r}),this}once(t,e,r){const a=this,o=e;let n=!1;function i(...e){n||(n=!0,a.off(t,i),o.apply(r,e))}return i._=e,this.on(t,i,r)}emit(t,...e){const r=this.e||(this.e={}),a=(Jt(r,t)&&r[t]||[]).slice();for(const o of a)o.fn.apply(o.ctx,e);return this}off(t,e){const r=this.e||(this.e={}),a=Jt(r,t)?r[t]:void 0,o=[];if(a&&e)for(let n=0,i=a.length;ne.call(this,this)),re.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${re.version}`);for(let e=0;et(`Event@${e.type}`))}ee.push(this)}static get instances(){return ee}static get version(){return n}static get config(){return i}static get utils(){return nt}static get scheme(){return mt}static get Emitter(){return Qt}static get validator(){return o}static get kindOf(){return o.kindOf}static get html(){return Zt.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:l?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:navigator?.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){re.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),ee.splice(ee.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return re.STYLE=Gt,re.DEBUG=!1,re.CONTEXTMENU=!0,re.NOTICE_TIME=2e3,re.SETTING_WIDTH=250,re.SETTING_ITEM_WIDTH=200,re.SETTING_ITEM_HEIGHT=35,re.RESIZE_TIME=200,re.SCROLL_TIME=200,re.SCROLL_GAP=50,re.AUTO_PLAYBACK_MAX=10,re.AUTO_PLAYBACK_MIN=5,re.AUTO_PLAYBACK_TIMEOUT=3e3,re.RECONNECT_TIME_MAX=5,re.RECONNECT_SLEEP_TIME=1e3,re.CONTROL_HIDE_TIME=3e3,re.DBCLICK_TIME=300,re.DBCLICK_FULLSCREEN=!0,re.MOBILE_DBCLICK_PLAY=!0,re.MOBILE_CLICK_PLAY=!1,re.AUTO_ORIENTATION_TIME=200,re.INFO_LOOP_TIME=1e3,re.FAST_FORWARD_VALUE=3,re.FAST_FORWARD_TIME=1e3,re.TOUCH_MOVE_RATIO=.5,re.VOLUME_STEP=.1,re.SEEK_STEP=5,re.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],re.ASPECT_RATIO=["default","4:3","16:9"],re.FLIP=["normal","horizontal","vertical"],re.FULLSCREEN_WEB_IN_BODY=!0,re.LOG_VERSION=!0,re.USE_RAF=!1,re.REMOVE_SRC_WHEN_DESTROY=!0,h&&(window.Artplayer=re,M("artplayer-style",Gt),setTimeout(()=>{re.LOG_VERSION&&console.log(`%c ArtPlayer %c ${re.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),re}); diff --git a/packages/artplayer/dist/artplayer.legacy.js b/packages/artplayer/dist/artplayer.legacy.js index 7fdf2363d..6f456b7bc 100644 --- a/packages/artplayer/dist/artplayer.legacy.js +++ b/packages/artplayer/dist/artplayer.legacy.js @@ -4,4 +4,4 @@ * (c) 2017-2026 Harvey Zhao * Released under the MIT License. */ -!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2=1,k=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(y)||x,$="undefined"!==typeof window&&"undefined"!==typeof document;function T(t,e=document){return e.querySelector(t)}function E(t,e=document){return Array.from(e.querySelectorAll(t))}function C(t,e){return t.classList.add(e)}function z(t,e){return t.classList.remove(e)}function L(t,e){return t.classList.contains(e)}function S(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function M(t){return t.parentNode.removeChild(t)}function I(t,e,r){return t.style[e]=r,t}function P(t,e){for(const r in e)I(t,r,e[r]);return t}function A(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function O(t,e){A(t).forEach(t=>z(t,e)),C(t,e)}function R(t,e,r="top"){k||(t.setAttribute("aria-label",e),C(t,"hint--rounded"),C(t,`hint--${r}`))}function _(t,e=0){const r=t.getBoundingClientRect(),o=window.innerHeight||document.documentElement.clientHeight,a=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=o&&r.top+r.height+e>=0,i=r.left-e<=a+e&&r.left+r.width+e>=0;return n&&i}function V(t,e){return j(t).includes(e)}function Y(t,e){return e.parentNode.replaceChild(t,e),t}function N(t){return document.createElement(t)}function D(t="",e=""){const r=N("i");return C(r,"art-icon"),C(r,`art-icon-${t}`),S(r,e),r}function F(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function B(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function H(t){return t.getBoundingClientRect()}function W(t,e){return new Promise((r,o)=>{const a=new Image;a.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=a.width*e,n.height=a.height*e,i.drawImage(a,0,0,n.width,n.height),n.toBlob(e=>{const a=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(a),o(new Error(`Image load failed: ${t}`))},n.src=a})}else r(a)},a.onerror=function(){o(new Error(`Image load failed: ${t}`))},a.src=t})}function j(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function U(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class q extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function X(t,e){if(!t)throw new q(e);return t}function G(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function K(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function Z(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function J(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function Q(t){return t.charAt(0).toUpperCase()+t.slice(1)}function tt(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),o=Math.floor(t-3600*e-60*r);return(e>0?[e,r,o]:[r,o]).map(t=>t<10?`0${t}`:String(t)).join(":")}const et={"&":"&","<":"<",">":">","'":"'",'"':"""},rt={"&":"&","<":"<",">":">","'":"'",""":'"'},ot=/(&|<|>|'|")/g;function at(t){return t.replace(/[&<>'"]/g,t=>et[t]||t)}const nt=Object.defineProperty,{hasOwnProperty:it}=Object.prototype;function st(t,e){return it.call(t,e)}function lt(t,e){return Object.getOwnPropertyDescriptor(t,e)}function ct(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(o=>{const a=t[o],n=r[o];let i;i=Array.isArray(a)&&Array.isArray(n)?a.concat(...n):e(a)&&e(n)?ct(a,n):n,nt(t,o,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function dt(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let o=r.slice(0,3);return 1===r.length&&(o=`${r}00`),2===r.length&&(o=`${r}0`),`${e},${o}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function pt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function ht(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const o=t.match(e);if(!o)return null;const[,a="",n="",,,i=""]=o;return{start:r(a.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function ut(t=0){return new Promise(e=>setTimeout(e,t))}function mt(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,o)),e)}}function ft(t,e){let r=!1;return function(...o){r||(t.apply(this,o),r=!0,setTimeout(()=>{r=!1},e))}}const gt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:q,addClass:C,append:S,assToVtt:ht,capitalize:Q,clamp:J,createElement:N,debounce:mt,def:nt,download:Z,errorHandle:X,escape:at,get:lt,getComposedPath:j,getExt:K,getIcon:D,getRect:H,getSafeAreaInsets:U,getStyle:function(t,e,r=!0){const o=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(o):o},has:st,hasClass:L,includeFromEvent:V,inverseClass:O,isBrowser:$,isIOS:w,isIOS13:x,isInViewport:_,isMobile:k,isSafari:b,loadImg:W,mergeDeep:ct,query:T,queryAll:E,remove:M,removeClass:z,replaceElement:Y,secondToTime:tt,setStyle:I,setStyleText:F,setStyles:P,siblings:A,silencePromise:G,sleep:ut,srtToVtt:dt,supportsFlex:B,throttle:ft,tooltip:R,unescape:function(t){return t.replace(ot,t=>rt[t]||t)},userAgent:y,vttToBlob:pt},Symbol.toStringTag,{value:"Module"})),vt="array",yt="boolean",bt="string",wt="number",xt="object",kt="function";function $t(t,e,r){return X(e===bt||e===wt||t instanceof Element,`${r.join(".")} require '${bt}' or 'Element' type`)}const Tt={html:$t,disable:`?${yt}`,name:`?${bt}`,index:`?${wt}`,style:`?${xt}`,click:`?${kt}`,mounted:`?${kt}`,tooltip:`?${bt}|${wt}`,width:`?${wt}`,selector:`?${vt}`,onSelect:`?${kt}`,switch:`?${yt}`,onSwitch:`?${kt}`,range:`?${vt}`,onRange:`?${kt}`,onChange:`?${kt}`},Et={id:bt,container:$t,url:bt,poster:bt,type:bt,theme:bt,lang:bt,volume:wt,isLive:yt,muted:yt,autoplay:yt,autoSize:yt,autoMini:yt,loop:yt,flip:yt,playbackRate:yt,aspectRatio:yt,screenshot:yt,setting:yt,hotkey:yt,pip:yt,mutex:yt,backdrop:yt,fullscreen:yt,fullscreenWeb:yt,subtitleOffset:yt,miniProgressBar:yt,useSSR:yt,playsInline:yt,lock:yt,gesture:yt,fastForward:yt,autoPlayback:yt,autoOrientation:yt,airplay:yt,proxy:`?${kt}`,plugins:[kt],layers:[Tt],contextmenu:[Tt],settings:[Tt],controls:[c(l({},Tt),{position:(t,e,r)=>{const o=["top","left","right"];return X(o.includes(t),`${r.join(".")} only accept ${o.toString()} as parameters`)}})],quality:[{default:`?${yt}`,html:bt,url:bt}],highlight:[{time:wt,text:bt}],thumbnails:{url:bt,number:wt,column:wt,width:wt,height:wt,scale:wt},subtitle:{url:bt,name:bt,type:bt,style:xt,escape:yt,encoding:bt,onVttLoad:kt},moreVideoAttr:xt,i18n:xt,icons:xt,cssVar:xt,customType:xt};class Ct{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return L(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?C(e,r):z(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",f(e,Tt),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;X(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const o=N("div");C(o,`art-${this.name}`),C(o,`art-${this.name}-${r}`);const a=Array.from(this.$parent.children);o.dataset.index=e.index||this.id;const n=a.find(t=>Number(t.dataset.index)>=Number(o.dataset.index));n?n.insertAdjacentElement("beforebegin",o):S(this.$parent,o),e.html&&S(o,e.html),e.style&&P(o,e.style),e.tooltip&&R(o,e.tooltip);const i=[];if(e.click){const t=this.art.events.proxy(o,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});i.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,o,i),this[r]=o,this.cache.set(r,{$ref:o,events:i,option:e}),e.mounted&&e.mounted.call(this.art,o),o}remove(t){X(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],M(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class zt extends Ct{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,k||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:o}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:o}}=e,a=o.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return c(l({},t),{html:`${r.get("Play Speed")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.playbackRate=Number(o),t.show=!1)},mounted:t=>{const r=T('[data-value="1"]',t);r&&O(r,"art-current"),e.on("video:ratechange",()=>{const r=E("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&O(r,"art-current")})}})}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:o}}=e,a=o.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return c(l({},t),{html:`${r.get("Aspect Ratio")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.aspectRatio=o,t.show=!1)},mounted:t=>{const r=T('[data-value="default"]',t);r&&O(r,"art-current"),e.on("aspectRatio",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&O(r,"art-current")})}})}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:o}}=e,a=o.map(t=>`${r.get(Q(t))}`).join("");return c(l({},t),{html:`${r.get("Video Flip")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.flip=o.toLowerCase(),t.show=!1)},mounted:t=>{const r=T('[data-value="normal"]',t);r&&O(r,"art-current"),e.on("flip",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&O(r,"art-current")})}})}}({name:"flip",index:30})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return c(l({},t),{html:`ArtPlayer ${g}`})}({name:"version",index:50})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let a=0;a{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,a=t.clientY,{height:n,width:i,left:s,top:l}=H(r),{height:c,width:d}=H(o);let p=e-s,h=a-l;e+d>s+i&&(p=i-d),a+c>l+n&&(h=n-c),P(o,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{V(t,o)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function Lt(t,e){const{$progress:r}=t.template,{left:o}=H(r),a=J((k?e.touches[0].clientX:e.clientX)-o,0,r.clientWidth),n=a/r.clientWidth*t.duration;return{second:n,time:tt(n),width:a,percentage:J(a/r.clientWidth,0,1)}}function St(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,o=r*t.duration;t.emit("setBar","played",r,e),t.seek=o}else{const{second:r,percentage:o}=Lt(t,e);t.emit("setBar","played",o,e),t.seek=r}}function Mt(t){return e=>{const{icons:r,option:o,proxy:a}=e,{$player:n,$progress:i}=e.template;return c(l({},t),{html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=T(".art-progress-hover",t),d=T(".art-progress-loaded",t),p=T(".art-progress-played",t),h=T(".art-progress-highlight",t),u=T(".art-progress-indicator",t),m=T(".art-progress-tip",t);function f(r,o){const{width:a,time:n}=o||Lt(e,r);m.textContent=n||"00:00";const i=m.clientWidth;a<=i/2?I(m,"left",0):a>t.clientWidth-i/2?I(m,"left",t.clientWidth-i+"px"):I(m,"left",a-i/2+"px")}r.indicator?S(u,r.indicator):I(u,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,o,a){const i="played"===r&&a&&k;if("loaded"===r&&I(d,"width",100*o+"%"),"hover"===r&&(I(c,"width",100*o+"%"),V(a,h)?function(r){const{width:o}=Lt(e,r),{text:a}=r.target.dataset;m.textContent=a;const n=m.clientWidth;o<=n/2?I(m,"left",0):o>t.clientWidth-n/2?I(m,"left",t.clientWidth-n+"px"):I(m,"left",o-n/2+"px")}(a):f(a),0===o?z(n,"art-progress-hover"):C(n,"art-progress-hover")),"played"===r&&(I(p,"width",100*o+"%"),I(u,"left",100*o+"%")),i){C(n,"art-progress-hover");f(a,{width:t.clientWidth*o,time:tt(o*e.duration)}),clearTimeout(s),s=setTimeout(()=>{z(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){h.textContent="";for(let t=0;t`;S(h,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),k||(a(i,"click",t=>{t.target!==u&&St(e,t)}),a(i,"mousemove",t=>{const{percentage:r}=Lt(e,t);e.emit("setBar","hover",r,t)}),a(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),a(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:o}=Lt(e,t);e.emit("setBar","played",o,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}})}}class It extends Ct{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:o}=this.art.template;t.on("mousemove",()=>{k||(this.show=!0)}),t.on("click",()=>{k?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=V(t,o)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(z(r,"art-hide-cursor"),C(r,"art-hover"),this.timer=Date.now()):(C(r,"art-hide-cursor"),z(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(Mt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.play),i=S(t,o.pause);function s(){I(n,"display","flex"),I(i,"display","none")}function l(){I(n,"display","none"),I(i,"display","flex")}R(n,a.get("Play")),R(i,a.get("Pause")),r(n,"click",()=>{G(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o}=e,a=S(t,o.volume),n=S(t,o.volumeClose),i=S(t,'
'),s=S(i,'
'),l=S(s,'
'),c=S(s,'
'),d=S(c,'
'),p=S(d,'
'),h=S(c,'
');function u(t){const{top:e,height:r}=H(c);return 1-(t.clientY-e)/r}function m(){if(e.muted||0===e.volume)I(a,"display","none"),I(n,"display","flex"),I(h,"top","100%"),I(p,"top","100%"),l.textContent=0;else{const t=100*e.volume;I(a,"display","flex"),I(n,"display","none"),I(h,"top",100-t+"%"),I(p,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(m(),e.on("video:volumechange",m),r(a,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),k)I(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=u(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=u(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>c(l({},t),{style:k?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${tt(e.currentTime)} / ${tt(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const o=["video:loadedmetadata","video:timeupdate","video:progress"];for(let a=0;a{this.art.quality=t.quality}),t.screenshot&&!k&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{R(t,a.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{R(t,a.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenWebOn),i=S(t,o.fullscreenWebOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(R(t,a.get("Exit Web Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Web Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenOn),i=S(t,o.fullscreenOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(R(t,a.get("Exit Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),nt(e,"$control_item",{get:()=>r}),nt(e,"$control_value",{get:()=>a})}const i=o(n,"click",e=>d(this,null,function*(){const r=j(e),o=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(o),t.onSelect&&(a.innerHTML=yield t.onSelect.call(this.art,o,o.$control_item,e))}));r.push(i)}}function Pt(t,e,r,o){const a=e-o,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(a)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,a);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class At{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:o,$video:a}}=t;function n(e){V(e,o)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(a,"click",e=>{const o=Date.now();i.push(o);const{MOBILE_CLICK_PLAY:a,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>o-t<=n);switch(c.length){case 1:t.emit("click",e),k?!t.isLock&&a&&G(t.toggle()):G(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),k?!t.isLock&&s&&G(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{C(r,"art-hover"),t.emit("hover",!0,e)},e=>{z(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:o}=t;t.on("resize",()=>{const{aspectRatio:e,notice:o}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,o.show=""});const a=mt(()=>t.emit("resize"),o.RESIZE_TIME);t.on("window:orientationchange",()=>a()),t.on("window:resize",()=>a()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>a())}(t,this),function(t,e){if(k&&!t.option.isLive){const{$video:r,$progress:o}=t.template;let a=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){a===o&&St(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:o,pageY:n}=e.touches[0],c=Pt(i,s,o,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=J((o-i)/t.width,-1,1),d=J((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=a===r?t.constructor.TOUCH_MOVE_RATIO:1,u=J(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",J(u/t.duration,0,1),e),t.notice.show=`${tt(u)} / ${tt(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,a=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{a=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(o,"touchstart",t=>{a=o,c(t)}),e.proxy(o,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:o}}=t,a=ft(()=>{t.emit("view",_(o,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>a()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],o=["resize","scroll","orientationchange"],a=[];function n(n={}){for(let t=0;t{const o=n.document||i.ownerDocument||document,s=e.proxy(o,r,e=>{t.emit(`document:${r}`,e)});a.push(s)}),o.forEach(r=>{var o;const s=n.window||(null==(o=i.ownerDocument)?void 0:o.defaultView)||window,l=e.proxy(s,r,e=>{t.emit(`window:${r}`,e)});a.push(l)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,o={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,o));t.addEventListener(e,r,o);const a=()=>t.removeEventListener(e,r,o);return this.destroyEvents.add(a),a}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class Ot{constructor(t){this.art=t,this.keys={},k||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{G(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n'},t.option.icons);for(const r in e)nt(this,r,{get:()=>D(r,e[r])})}}class Yt extends Ct{constructor(t){super(t),this.name="info",k||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:o,$video:a}}=this.art;t(o,"click",()=>{this.show=!1});let n=null;const i=E("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{I(a,"display","none"),I(n,"display",null)}),o.proxy(e.$state,"click",()=>G(t.play()))}}class Bt{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:o}}=this.art;t?(o.textContent=t instanceof Error?t.message.trim():t,C(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{o.textContent="",z(r,"art-notice-show")},e.NOTICE_TIME)):z(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Ht=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Wt=(()=>{if("undefined"===typeof document)return!1;const t=Ht[0],e={};for(const r of Ht){if(r[1]in document){for(const[o,a]of r.entries())e[t[o]]=a;return e}}return!1})(),jt={change:Wt.fullscreenchange,error:Wt.fullscreenerror},Ut={request:(t=document.documentElement,e)=>new Promise((r,o)=>{const a=()=>{Ut.off("change",a),r()};Ut.on("change",a);const n=t[Wt.requestFullscreen](e);n instanceof Promise&&n.then(a).catch(o)}),exit:()=>new Promise((t,e)=>{if(!Ut.isFullscreen)return void t();const r=()=>{Ut.off("change",r),t()};Ut.on("change",r);const o=document[Wt.exitFullscreen]();o instanceof Promise&&o.then(r).catch(e)}),toggle:(t,e)=>Ut.isFullscreen?Ut.exit():Ut.request(t,e),onchange(t){Ut.on("change",t)},onerror(t){Ut.on("error",t)},on(t,e){const r=jt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=jt[t];r&&document.removeEventListener(r,e,!1)},raw:Wt};function qt(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t,n=t=>{Ut.on("change",()=>{t.emit("fullscreen",Ut.isFullscreen),Ut.isFullscreen?(t.state="fullscreen",C(a,"art-fullscreen")):z(a,"art-fullscreen"),t.emit("resize")}),Ut.on("error",e=>{t.emit("fullscreenError",e)}),nt(t,"fullscreen",{get:()=>Ut.isFullscreen,set(t){return d(this,null,function*(){t?yield Ut.request(a):yield Ut.exit()})}})};t.once("video:loadedmetadata",()=>{var a;Ut.isEnabled?n(t):o.webkitSupportsFullscreen?((a=t).on("document:webkitfullscreenchange",()=>{a.emit("fullscreen",a.fullscreen),a.emit("resize")}),nt(a,"fullscreen",{get:()=>document.fullscreenElement===o,set(t){t?(a.state="fullscreen",o.webkitEnterFullscreen()):o.webkitExitFullscreen()}})):nt(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),nt(t,"fullscreen",lt(t,"fullscreen"))})}function Xt(t){const{icons:e,proxy:r,storage:o,template:{$player:a,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(z(a,"art-mini"),I(e,"display","none"),a.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(I(e,"display","none"),I(r,"display","flex")):(I(e,"display","flex"),I(r,"display","none"))}function p(){const{$mini:e}=t.template,r=H(e),a=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;o.set("top",a),o.set("left",n),I(e,"top",`${a}px`),I(e,"left",`${n}px`)}nt(t,"mini",{get:()=>L(a,"art-mini"),set(h){if(h){t.state="mini",C(a,"art-mini");const h=function(){const{$mini:a}=t.template;if(a)return S(a,n),I(a,"display","flex");{const a=N("div");C(a,"art-mini-popup"),S(document.body,a),t.template.$mini=a,S(a,n);const p=S(a,'
');S(p,e.close),r(p,"click",c);const h=S(a,'
'),u=S(h,e.play),m=S(h,e.pause);return r(u,"click",()=>G(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(a,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){C(a,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;I(a,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,z(a,"art-mini-dragging");const t=H(a);o.set("left",t.left),o.set("top",t.top),I(a,"left",`${t.left}px`),I(a,"top",`${t.top}px`),I(a,"transform",null)}}),a}}(),u=o.get("top"),m=o.get("left");"number"===typeof u&&"number"===typeof m?(I(h,"top",`${u}px`),I(h,"left",`${m}px`),_(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Gt(t){const{i18n:e,notice:r,template:{$video:o}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:o}=t;e.disablePictureInPicture=!1,nt(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw o.show=t,t})):document.exitPictureInPicture().catch(t=>{throw o.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):o.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),nt(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):nt(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Kt(t){const{option:e,template:{$progress:r,$video:o}}=t;let a=null,n=!1,i=null;t.on("setBar",(a,s,l)=>d(null,null,function*(){var c;const d=null==(c=t.controls)?void 0:c.thumbnails,{url:p,scale:h}=e.thumbnails;if(!d||!p)return;if("hover"===a||"played"===a&&l&&k){if(i||n||(n=!0,i=yield W(p,h),n=!1),!i)return;const a=r.clientWidth*s;a>0&&ar.clientWidth-u/2?I(s,"left",r.clientWidth-u+"px"):I(s,"left",a-u/2+"px")}(a)}})),nt(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(a),a=null,n=!1,i=null)}})}Object.defineProperties(Ut,{isFullscreen:{get:()=>Boolean(document[Wt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Wt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Wt.fullscreenEnabled])}});class Zt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;nt(t,"url",{get:()=>r.src,set(o){return d(this,null,function*(){if(o){const a=t.url,n=e.type||K(o),i=e.customType[n];n&&i?(yield ut(),t.loading.show=!0,i.call(t,r,o,t)):(URL.revokeObjectURL(a),r.src=o),a!==t.url&&(t.option.url=o,t.isReady&&a&&t.once("video:canplay",()=>{t.emit("restart",o)}))}else yield ut(),t.loading.show=!0})}})}(t),function(t){const{template:{$video:e}}=t;nt(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:o,constructor:{instances:a},template:{$video:n}}=t;nt(t,"play",{value(){return d(this,null,function*(){const i=yield n.play();if(r.show=e.get("Play"),t.emit("play"),o.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;nt(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${tt(t.currentTime)} / ${tt(t.duration)}`),t.emit("seek",t.currentTime,r)}}),nt(t,"forward",{set(e){t.seek=t.currentTime+e}}),nt(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:o,storage:a}=t;nt(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=J(t,0,1),o.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&a.set("volume",e.volume)}}),nt(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;nt(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=J(r,0,t.duration))}})}(t),function(t){nt(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((o,a)=>{if(e===t.url)return void o();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),a(e)},metadata:()=>{t.currentTime=r},canplay:()=>d(null,null,function*(){t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&(yield G(t.play())),t.notice.show="",o()})};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}nt(t,"switchQuality",{value:r=>e(r,t.currentTime)}),nt(t,"switchUrl",{value:t=>e(t,0)}),nt(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:o}=t;nt(t,"playbackRate",{get:()=>e.playbackRate,set(a){if(a){if(a===e.playbackRate)return;e.playbackRate=a,o.show=`${r.get("Rate")}: ${1===a?r.get("Normal"):`${a}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t;nt(t,"aspectRatio",{get:()=>a.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)I(o,"width",null),I(o,"height",null),I(o,"margin",null),delete a.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=a,i=e/r,s=t[0]/t[1];i>s?(I(o,"width",s*r+"px"),I(o,"height","100%"),I(o,"margin","0 auto")):(I(o,"width","100%"),I(o,"height",e/s+"px"),I(o,"margin","auto 0")),a.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,o=N("canvas");nt(t,"getDataURL",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),t(o.toDataURL("image/png"))}catch(n){e.show=n,a(n)}})}),nt(t,"getBlobUrl",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),o.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,a(n)}})}),nt(t,"screenshot",{value:e=>d(null,null,function*(){const o=yield t.getDataURL();return Z(o,`${e||`artplayer_${tt(r.currentTime)}`}.png`),t.emit("screenshot",o),o})})}(t),qt(t),function(t){const{constructor:e,template:{$container:r,$player:o}}=t;let a="";nt(t,"fullscreenWeb",{get:()=>L(o,"art-fullscreen-web"),set(n){n?(a=o.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&S(document.body,o),t.state="fullscreenWeb",I(o,"width","100%"),I(o,"height","100%"),C(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&S(r,o),a&&(o.style.cssText=a,a=""),z(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Gt(t),function(t){const{$video:e}=t.template;nt(t,"loaded",{get:()=>t.loadedTime/e.duration}),nt(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){nt(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;nt(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:o}=t.template;nt(t,"autoSize",{value(){const{videoWidth:a,videoHeight:n}=o,{width:i,height:s}=H(e),l=a/n;if(i/s>l)I(r,"width",s*l/i*100+"%"),I(r,"height","100%");else{const t=i/l/s*100;I(r,"width","100%"),I(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){nt(t,"rect",{get:()=>H(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[o]})}nt(t,"x",{get:()=>t.left+window.pageXOffset}),nt(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:o}=t;nt(t,"flip",{get:()=>e.dataset.flip||"normal",set(a){a||(a="normal"),"normal"===a?delete e.dataset.flip:e.dataset.flip=a,o.show=`${r.get("Video Flip")}: ${r.get(Q(a))}`,t.emit("flip",a)}})}(t),Xt(t),function(t){const{template:{$poster:e}}=t;nt(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch(t){return""}},set(t){I(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;nt(t,"autoHeight",{value(){const{clientWidth:o}=e,{videoHeight:a,videoWidth:n}=r,i=a*(o/n);I(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;nt(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){nt(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){nt(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];nt(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let o=0;o{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,nt(t,"airplay",{value(){n?(a.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){nt(t,"quality",{set(e){const{controls:r,notice:o,i18n:a}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:(null==n?void 0:n.html)||"",selector:e,onSelect(e){return d(this,null,function*(){return yield t.switchQuality(e.url),o.show=`${a.get("Switch Video")}: ${e.html}`,e.html})}})}})}(t),Kt(t),function(t){const{i18n:e,notice:r,option:o,constructor:a,proxy:n,template:{$player:i,$video:s,$poster:l}}=t;let c=0;for(let d=0;d{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{c=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{o.loop?(t.seek=0,G(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",n=>d(null,null,function*(){c{t.emit("resize"),k&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,I(l,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:o,$poster:a}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(o.volume=J(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(o.volume=J(n,0,1)),e.poster&&I(a,"backgroundImage",`url(${e.poster})`),e.autoplay&&(o.autoplay=e.autoplay),e.playsInline&&(o.playsInline=!0,o["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Jt(t){const{notice:e,constructor:r,template:{$player:o,$video:a}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=a,r=document.documentElement.clientWidth,o=document.documentElement.clientHeight;return t>e&&ro}return t.on("fullscreenWeb",e=>{var a;if(e){if(l()){const e=Number(null!=(a=r.AUTO_ORIENTATION_TIME)?a:0);setTimeout(()=>{t.fullscreenWeb&&!L(o,n)&&function(){const e=U(),r=document.documentElement.clientWidth,a=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;I(o,"width",`${a}px`),I(o,"height",`${i}px`),I(o,"transform-origin","0 0"),I(o,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),C(o,n),t.isRotate=!0,t.emit("resize")}()},e)}}else L(o,n)&&(I(o,"width",""),I(o,"height",""),I(o,"transform-origin",""),I(o,"transform",""),z(o,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",t=>d(null,null,function*(){var r;const a=!!(null==(r=null==screen?void 0:screen.orientation)?void 0:r.lock);if(t){if(a&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";yield screen.orientation.lock(t),s=!0,C(o,i)}catch(n){s=!1,e.show=n}}else if(L(o,i)&&z(o,i),a&&s){try{screen.orientation.unlock()}catch(c){}s=!1}})),{name:"autoOrientation",get state(){return L(o,n)}}}function Qt(t){const{i18n:e,icons:r,storage:o,constructor:a,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=T(".art-auto-playback-last",s),c=T(".art-auto-playback-jump",s),d=T(".art-auto-playback-close",s);S(d,r.close);let p=null;function h(){const r=(o.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),I(s,"display","none"),r&&r>=a.AUTO_PLAYBACK_MIN&&(I(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${tt(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{I(s,"display","none")}),n(c,"click",()=>{t.seek=r,G(t.play()),I(i,"display","none"),I(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{I(s,"display","none")},a.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=o.get("times")||{},r=Object.keys(e);r.length>a.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,o.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return o.get("times")||{}},clear:()=>o.del("times"),delete(t){const e=o.get("times")||{};return delete e[t],o.set("times",e),e}}}function te(t){const{constructor:e,proxy:r,template:{$player:o,$video:a}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,z(o,"art-fast-forward"))};return r(a,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,C(o,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return L(o,"art-fast-forward")}}}function ee(t){const{layers:e,icons:r,template:{$player:o}}=t;function a(){return L(o,"art-lock")}function n(){C(o,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){z(o,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const o=S(e,r.lock),a=S(e,r.unlock);I(o,"display","none"),t.on("lock",t=>{t?(I(o,"display","inline-flex"),I(a,"display","none")):(I(o,"display","none"),I(a,"display","inline-flex"))})},click(){a()?i():n()}}),{name:"lock",get state(){return a()},set state(t){t?n():i()}}}function re(t){return t.on("control",e=>{e?z(t.template.$player,"art-mini-progress-bar"):C(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class oe{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(re),e.lock&&k&&this.add(ee),e.autoPlayback&&!e.isLive&&this.add(Qt),e.autoOrientation&&k&&this.add(Jt),e.fastForward&&k&&!e.isLive&&this.add(te);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return X(!st(this,r),`Cannot add a plugin that already has the same name: ${r}`),nt(this,r,{value:e}),this}}class ae extends Ct{constructor(t){super(t);const{option:e,controls:r,template:{$setting:o}}=t;this.name="setting",this.$parent=o,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=V(t,r.setting),o=V(t,this.$parent);!this.show||e||o||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,PLAYBACK_RATE:a}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:o,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:a.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,ASPECT_RATIO:a}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:o,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:a.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,FLIP:a}}=t;function n(t){return e.get(Q(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:o,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:a.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:o}=t;return{width:o.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){var r;for(let o=0;o{e.default=e===t,e.default&&e.$item&&O(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,o=[]){for(let a=0;ae}),nt(n,"$parents",{get:()=>r}),nt(n,"$option",{get:()=>t});const o=[];nt(n,"$events",{get:()=>o}),nt(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,o)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){var t,e;const{controls:r,constructor:{SETTING_WIDTH:o,SETTING_ITEM_HEIGHT:a},template:{$player:n,$setting:i}}=this.art;if(r.setting&&this.show){const s=(null==(e=null==(t=this.active[0])?void 0:t.$parent)?void 0:e.width)||o,{left:l,width:c}=H(r.setting),{left:d,width:p}=H(n),h=l-d+c/2-s/2;if(I(i,"height",`${this.active===this.option?this.active.length*a:(this.active.length+1)*a}px`),I(i,"width",`${s}px`),this.art.isRotate||k)return;h+s>p?(I(i,"left",null),I(i,"right",null)):(I(i,"left",`${h}px`),I(i,"right","auto"))}}inactivate(t){for(let e=0;e'),s=N("div");C(s,"art-setting-item-left-icon"),S(s,o),S(i,s),S(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),S(e,n)}createItem(t,e=!1){var r,o;if(!this.cache.has(t.$option))return;const a=this.cache.get(t.$option),n=t.$item;let i="selector";st(t,"switch")&&(i="switch"),st(t,"range")&&(i="range"),st(t,"onClick")&&(i="button");const{icons:s,proxy:l,constructor:c}=this.art,p=N("div");C(p,"art-setting-item"),I(p,"height",`${c.SETTING_ITEM_HEIGHT}px`),p.dataset.name=t.name||"",p.dataset.value=t.value||"";const h=S(p,'
'),u=S(p,'
'),m=N("div");switch(C(m,"art-setting-item-left-icon"),i){case"button":case"switch":case"range":S(m,t.icon||s.config);break;case"selector":(null==(r=t.selector)?void 0:r.length)?S(m,t.icon||s.config):S(m,s.check)}S(h,m),nt(t,"$icon",{configurable:!0,get:()=>m}),nt(t,"icon",{configurable:!0,get:()=>m.innerHTML,set(t){m.innerHTML="",S(m,t)}});const f=N("div");C(f,"art-setting-item-left-text"),S(f,t.html||""),S(h,f),nt(t,"$html",{configurable:!0,get:()=>f}),nt(t,"html",{configurable:!0,get:()=>f.innerHTML,set(t){f.innerHTML="",S(f,t)}});const g=N("div");switch(C(g,"art-setting-item-right-tooltip"),S(g,t.tooltip||""),S(u,g),nt(t,"$tooltip",{configurable:!0,get:()=>g}),nt(t,"tooltip",{configurable:!0,get:()=>g.innerHTML,set(t){g.innerHTML="",S(g,t)}}),i){case"switch":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,s.switchOn),o=S(e,s.switchOff);I(t.switch?o:r,"display","none"),S(u,e),nt(t,"$switch",{configurable:!0,get:()=>e});let a=t.switch;nt(t,"switch",{configurable:!0,get:()=>a,set(t){a=t,t?(I(o,"display","none"),I(r,"display",null)):(I(o,"display",null),I(r,"display","none"))}});break}case"range":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],C(r,"art-setting-range"),S(u,e),nt(t,"$range",{configurable:!0,get:()=>r});let o=[...t.range];nt(t,"range",{configurable:!0,get:()=>o,set(t){o=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(null==(o=t.selector)?void 0:o.length){const t=N("div");C(t,"art-setting-item-right-icon"),S(t,s.arrowRight),S(u,t)}}switch(i){case"switch":if(t.onSwitch){const e=l(p,"click",e=>d(this,null,function*(){t.switch=yield t.onSwitch.call(this.art,t,p,e)}));t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=l(t.$range,"change",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onRange.call(this.art,t,p,e)}));t.$events.push(e)}if(t.onChange){const e=l(t.$range,"input",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onChange.call(this.art,t,p,e)}));t.$events.push(e)}}break;case"selector":{const e=l(p,"click",e=>d(this,null,function*(){var r;(null==(r=t.selector)?void 0:r.length)?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=yield t.$parent.onSelect.call(this.art,t,p,e)))}));t.$events.push(e),t.default&&C(p,"art-current")}break;case"button":if(t.onClick){const e=l(p,"click",e=>d(this,null,function*(){t.tooltip=yield t.onClick.call(this.art,t,p,e)}));t.$events.push(e)}}nt(t,"$item",{configurable:!0,get:()=>p}),e?Y(p,n):S(a,p),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){var e;if(this.active=t,this.cache.has(t)){O(this.cache.get(t),"art-current")}else{const r=N("div");this.cache.set(t,r),C(r,"art-setting-panel"),S(this.$parent,r),O(r,"art-current"),(null==(e=t[0])?void 0:e.$parent)&&this.createHeader(t[0]);for(let e=0;enull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){var t,e;return null==(e=null==(t=this.art.template.$video)?void 0:t.textTracks)?void 0:e[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?P(r,t):I(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?at(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}switch(t){return d(this,arguments,function*(t,e={}){const{i18n:r,notice:o,option:a}=this.art,n=c(l(l({},a.subtitle),e),{url:t}),i=yield this.init(n);return e.name&&(o.show=`${r.get("Switch Subtitle")}: ${e.name}`),i})}createTrack(t,e){const{template:r,proxy:o,option:a}=this.art,{$video:n,$track:i}=r,s=N("track");s.default=!0,s.kind=t,s.src=e,s.label=a.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,M(i),S(n,s),r.$track=s,this.destroyEvent=o(this.textTrack,"cuechange",()=>this.update())}init(t){return d(this,null,function*(){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(f(t,Et.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||K(t.url)){case"srt":{const e=dt(r);return pt(t.onVttLoad(e))}case"ass":{const e=ht(r);return pt(t.onVttLoad(e))}case"vtt":return pt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null})}}class le{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=T(e.container),X(this.$container,`No container element found by ${e.container}`)),X(B(),"The current browser does not support flex layout");const o=this.$container.tagName.toLowerCase();X("div"===o,`Unsupported container element type, only support 'div' but got '${o}'`),X(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${g}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return T(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=le.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);X(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),Y(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&C(this.$player,"art-backdrop"),k&&C(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":C(this.$player,"art-destroy")}}class ce{on(t,e,r){const o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:r}),this}once(t,e,r){const o=this;function a(...n){o.off(t,a),e.apply(r,n)}return a._=e,this.on(t,a,r)}emit(t,...e){const r=((this.e||(this.e={}))[t]||[]).slice();for(let o=0;oe.call(this,this)),he.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${he.version}`);for(let e=0;et(`Event@${e.type}`))}pe.push(this)}static get instances(){return pe}static get version(){return g}static get config(){return v}static get utils(){return gt}static get scheme(){return Et}static get Emitter(){return ce}static get validator(){return f}static get kindOf(){return f.kindOf}static get html(){return le.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:b?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:null==navigator?void 0:navigator.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){he.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),pe.splice(pe.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return he.STYLE=ie,he.DEBUG=!1,he.CONTEXTMENU=!0,he.NOTICE_TIME=2e3,he.SETTING_WIDTH=250,he.SETTING_ITEM_WIDTH=200,he.SETTING_ITEM_HEIGHT=35,he.RESIZE_TIME=200,he.SCROLL_TIME=200,he.SCROLL_GAP=50,he.AUTO_PLAYBACK_MAX=10,he.AUTO_PLAYBACK_MIN=5,he.AUTO_PLAYBACK_TIMEOUT=3e3,he.RECONNECT_TIME_MAX=5,he.RECONNECT_SLEEP_TIME=1e3,he.CONTROL_HIDE_TIME=3e3,he.DBCLICK_TIME=300,he.DBCLICK_FULLSCREEN=!0,he.MOBILE_DBCLICK_PLAY=!0,he.MOBILE_CLICK_PLAY=!1,he.AUTO_ORIENTATION_TIME=200,he.INFO_LOOP_TIME=1e3,he.FAST_FORWARD_VALUE=3,he.FAST_FORWARD_TIME=1e3,he.TOUCH_MOVE_RATIO=.5,he.VOLUME_STEP=.1,he.SEEK_STEP=5,he.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],he.ASPECT_RATIO=["default","4:3","16:9"],he.FLIP=["normal","horizontal","vertical"],he.FULLSCREEN_WEB_IN_BODY=!0,he.LOG_VERSION=!0,he.USE_RAF=!1,he.REMOVE_SRC_WHEN_DESTROY=!0,$&&(window.Artplayer=he,F("artplayer-style",ie),setTimeout(()=>{he.LOG_VERSION&&console.log(`%c ArtPlayer %c ${he.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),he}); +!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2=1,k=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(y)||x,$="undefined"!==typeof window&&"undefined"!==typeof document;function T(t,e=document){return e.querySelector(t)}function E(t,e=document){return Array.from(e.querySelectorAll(t))}function C(t,e){return t.classList.add(e)}function z(t,e){return t.classList.remove(e)}function L(t,e){return t.classList.contains(e)}function S(t,e){return e instanceof Element?t.appendChild(e):t.insertAdjacentHTML("beforeend",String(e)),t.lastElementChild||t.lastChild}function M(t){return t.parentNode.removeChild(t)}function I(t,e,r){return t.style[e]=r,t}function P(t,e){for(const r in e)I(t,r,e[r]);return t}function O(t){return Array.from(t.parentElement.children).filter(e=>e!==t)}function A(t,e){O(t).forEach(t=>z(t,e)),C(t,e)}function R(t,e,r="top"){k||(t.setAttribute("aria-label",e),C(t,"hint--rounded"),C(t,`hint--${r}`))}function _(t,e=0){const r=t.getBoundingClientRect(),o=window.innerHeight||document.documentElement.clientHeight,a=window.innerWidth||document.documentElement.clientWidth,n=r.top-e<=o&&r.top+r.height+e>=0,i=r.left-e<=a+e&&r.left+r.width+e>=0;return n&&i}function V(t,e){return j(t).includes(e)}function Y(t,e){return e.parentNode.replaceChild(t,e),t}function N(t){return document.createElement(t)}function D(t="",e=""){const r=N("i");return C(r,"art-icon"),C(r,`art-icon-${t}`),S(r,e),r}function F(t,e){let r=document.getElementById(t);r||(r=document.createElement("style"),r.id=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.head.appendChild(r)}):(document.head||document.documentElement).appendChild(r)),r.textContent=e}function B(){const t=document.createElement("div");return t.style.display="flex","flex"===t.style.display}function H(t){return t.getBoundingClientRect()}function W(t,e){return new Promise((r,o)=>{const a=new Image;a.onload=function(){if(e&&1!==e){const n=document.createElement("canvas"),i=n.getContext("2d");n.width=a.width*e,n.height=a.height*e,i.drawImage(a,0,0,n.width,n.height),n.toBlob(e=>{const a=URL.createObjectURL(e),n=new Image;n.onload=function(){r(n)},n.onerror=function(){URL.revokeObjectURL(a),o(new Error(`Image load failed: ${t}`))},n.src=a})}else r(a)},a.onerror=function(){o(new Error(`Image load failed: ${t}`))},a.src=t})}function j(t){if(t.composedPath)return t.composedPath();const e=[];let r=t.target;for(;r;)e.push(r),r=r.parentNode;return e.includes(window)||void 0===window||e.push(window),e}function U(){const t=document.createElement("div");t.style.cssText="position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);pointer-events:none;visibility:hidden;",document.body.appendChild(t);const e=getComputedStyle(t),r={top:Number.parseFloat(e.top)||0,right:Number.parseFloat(e.right)||0,bottom:Number.parseFloat(e.bottom)||0,left:Number.parseFloat(e.left)||0};return t.remove(),r}class q extends Error{constructor(t,e){super(t),"captureStackTrace"in Error&&"function"===typeof Error.captureStackTrace&&Error.captureStackTrace(this,e||this.constructor),this.name="ArtPlayerError"}}function X(t,e){if(!t)throw new q(e);return t}function G(t){const e=t;return e&&"function"===typeof e.catch?e.catch(()=>{}):t}function K(t){const e=t.search(/[?#]/),r=(e<0?t:t.slice(0,e)).trim().toLowerCase();return r.slice(r.lastIndexOf(".")+1)}function Z(t,e){const r=document.createElement("a");r.style.display="none",r.href=t,r.download=e,document.body.appendChild(r);try{r.click()}finally{r.remove()}}function J(t,e,r){return Math.max(Math.min(t,Math.max(e,r)),Math.min(e,r))}function Q(t){return t.charAt(0).toUpperCase()+t.slice(1)}function tt(t){if(!t)return"00:00";const e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),o=Math.floor(t-3600*e-60*r);return(e>0?[e,r,o]:[r,o]).map(t=>t<10?`0${t}`:String(t)).join(":")}const et={"&":"&","<":"<",">":">","'":"'",'"':"""},rt={"&":"&","<":"<",">":">","'":"'",""":'"'},ot=/(&|<|>|'|")/g;function at(t){return t.replace(/[&<>'"]/g,t=>et[t]||t)}const nt=Object.defineProperty,{hasOwnProperty:it}=Object.prototype;function st(t,e){return it.call(t,e)}function lt(t,e){return Object.getOwnPropertyDescriptor(t,e)}function ct(...t){const e=t=>!!t&&"object"===typeof t&&!Array.isArray(t);return t.reduce((t,r)=>(Object.keys(r).forEach(o=>{const a=t[o],n=r[o];let i;i=Array.isArray(a)&&Array.isArray(n)?a.concat(...n):e(a)&&e(n)?ct(a,n):n,nt(t,o,{value:i,enumerable:!0,configurable:!0,writable:!0})}),t),{})}function dt(t){return"WEBVTT \r\n\r\n".concat((e=t,e.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g,(t,e,r)=>{let o=r.slice(0,3);return 1===r.length&&(o=`${r}00`),2===r.length&&(o=`${r}0`),`${e},${o}`})).replace(/\{\\([ibu])\}/g,"").replace(/\{\\([ibu])1\}/g,"<$1>").replace(/\{([ibu])\}/g,"<$1>").replace(/\{\/([ibu])\}/g,"").replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g,"$1.$2").replace(/\{[\s\S]*?\}/g,"").concat("\r\n\r\n"));var e}function pt(t){return URL.createObjectURL(new Blob([t],{type:"text/vtt"}))}function ht(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(t=""){return t.split(/[:.]/).map((t,e,r)=>{if(e===r.length-1){if(1===t.length)return`.${t}00`;if(2===t.length)return`.${t}0`}else if(1===t.length)return(0===e?"0":":0")+t;return 0===e?t:e===r.length-1?`.${t}`:`:${t}`}).join("")}return`WEBVTT\n\n${t.split(/\r?\n/).map(t=>{const o=t.match(e);if(!o)return null;const[,a="",n="",,,i=""]=o;return{start:r(a.trim()),end:r(n.trim()),text:i.replace(/\{[\s\S]*?\}/g,"").replace(/(\\N)/g,"\n").trim().split(/\r?\n/).map(t=>t.trim()).join("\n")}}).filter(t=>t).map((t,e)=>t?`${e+1}\n${t.start} --\x3e ${t.end}\n${t.text}`:"").filter(t=>t.trim()).join("\n\n")}`}function ut(t=0){return new Promise(e=>setTimeout(e,t))}function mt(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout(()=>(r=void 0,t.apply(this,o)),e)}}function ft(t,e){let r=!1;return function(...o){r||(t.apply(this,o),r=!0,setTimeout(()=>{r=!1},e))}}const gt=Object.freeze(Object.defineProperty({__proto__:null,ArtPlayerError:q,addClass:C,append:S,assToVtt:ht,capitalize:Q,clamp:J,createElement:N,debounce:mt,def:nt,download:Z,errorHandle:X,escape:at,get:lt,getComposedPath:j,getExt:K,getIcon:D,getRect:H,getSafeAreaInsets:U,getStyle:function(t,e,r=!0){const o=window.getComputedStyle(t,null).getPropertyValue(e);return r?Number.parseFloat(o):o},has:st,hasClass:L,includeFromEvent:V,inverseClass:A,isBrowser:$,isIOS:w,isIOS13:x,isInViewport:_,isMobile:k,isSafari:b,loadImg:W,mergeDeep:ct,query:T,queryAll:E,remove:M,removeClass:z,replaceElement:Y,secondToTime:tt,setStyle:I,setStyleText:F,setStyles:P,siblings:O,silencePromise:G,sleep:ut,srtToVtt:dt,supportsFlex:B,throttle:ft,tooltip:R,unescape:function(t){return t.replace(ot,t=>rt[t]||t)},userAgent:y,vttToBlob:pt},Symbol.toStringTag,{value:"Module"})),vt="array",yt="boolean",bt="string",wt="number",xt="object",kt="function";function $t(t,e,r){return X(e===bt||e===wt||t instanceof Element,`${r.join(".")} require '${bt}' or 'Element' type`)}const Tt={html:$t,disable:`?${yt}`,name:`?${bt}`,index:`?${wt}`,style:`?${xt}`,click:`?${kt}`,mounted:`?${kt}`,tooltip:`?${bt}|${wt}`,width:`?${wt}`,selector:`?${vt}`,onSelect:`?${kt}`,switch:`?${yt}`,onSwitch:`?${kt}`,range:`?${vt}`,onRange:`?${kt}`,onChange:`?${kt}`},Et={id:bt,container:$t,url:bt,poster:bt,type:bt,theme:bt,lang:bt,volume:wt,isLive:yt,muted:yt,autoplay:yt,autoSize:yt,autoMini:yt,loop:yt,flip:yt,playbackRate:yt,aspectRatio:yt,screenshot:yt,setting:yt,hotkey:yt,pip:yt,mutex:yt,backdrop:yt,fullscreen:yt,fullscreenWeb:yt,subtitleOffset:yt,miniProgressBar:yt,useSSR:yt,playsInline:yt,lock:yt,gesture:yt,fastForward:yt,autoPlayback:yt,autoOrientation:yt,airplay:yt,proxy:`?${kt}`,plugins:[kt],layers:[Tt],contextmenu:[Tt],settings:[Tt],controls:[c(l({},Tt),{position:(t,e,r)=>{const o=["top","left","right"];return X(o.includes(t),`${r.join(".")} only accept ${o.toString()} as parameters`)}})],quality:[{default:`?${yt}`,html:bt,url:bt}],highlight:[{time:wt,text:bt}],thumbnails:{url:bt,number:wt,column:wt,width:wt,height:wt,scale:wt},subtitle:{url:bt,name:bt,type:bt,style:xt,escape:yt,encoding:bt,onVttLoad:kt},moreVideoAttr:xt,i18n:xt,icons:xt,cssVar:xt,customType:xt};class Ct{constructor(t){this.id=0,this.art=t,this.cache=new Map,this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.update=this.update.bind(this)}get show(){return L(this.art.template.$player,`art-${this.name}-show`)}set show(t){const{$player:e}=this.art.template,r=`art-${this.name}-show`;t?C(e,r):z(e,r),this.art.emit(this.name,t)}toggle(){this.show=!this.show}add(t){const e="function"===typeof t?t(this.art):t;if(e.html=e.html||"",f(e,Tt),!this.$parent||!this.name||e.disable)return;const r=e.name||`${this.name}${this.id}`;X(!this.cache.has(r),`Can't add an existing [${r}] to the [${this.name}]`),this.id+=1;const o=N("div");C(o,`art-${this.name}`),C(o,`art-${this.name}-${r}`);const a=Array.from(this.$parent.children);o.dataset.index=e.index||this.id;const n=a.find(t=>Number(t.dataset.index)>=Number(o.dataset.index));n?n.insertAdjacentElement("beforebegin",o):S(this.$parent,o),e.html&&S(o,e.html),e.style&&P(o,e.style),e.tooltip&&R(o,e.tooltip);const i=[];if(e.click){const t=this.art.events.proxy(o,"click",t=>{t.preventDefault(),e.click.call(this.art,this,t)});i.push(t)}return e.selector&&["left","right"].includes(e.position)&&this.selector(e,o,i),this[r]=o,this.cache.set(r,{$ref:o,events:i,option:e}),e.mounted&&e.mounted.call(this.art,o),o}remove(t){X(this.cache.has(t),`Can't find [${t}] from the [${this.name}]`);const e=this.cache.get(t);e.option.beforeUnmount&&e.option.beforeUnmount.call(this.art,e.$ref);for(const r of e.events)this.art.events.remove(r);this.cache.delete(t),delete this[t],M(e.$ref)}update(t){if(this.cache.has(t.name)){const e=this.cache.get(t.name);t=Object.assign(e.option,t),this.remove(t.name)}return this.add(t)}}class zt extends Ct{constructor(t){super(t),this.name="contextmenu",this.$parent=t.template.$contextmenu,k||this.init()}init(){const{option:t,proxy:e,template:{$player:r,$contextmenu:o}}=this.art;t.playbackRate&&this.add(function(t){return e=>{const{i18n:r,constructor:{PLAYBACK_RATE:o}}=e,a=o.map(t=>`${1===t?r.get("Normal"):t.toFixed(1)}`).join("");return c(l({},t),{html:`${r.get("Play Speed")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.playbackRate=Number(o),t.show=!1)},mounted:t=>{const r=T('[data-value="1"]',t);r&&A(r,"art-current"),e.on("video:ratechange",()=>{const r=E("span",t).find(t=>Number(t.dataset.value)===e.playbackRate);r&&A(r,"art-current")})}})}}({name:"playbackRate",index:10})),t.aspectRatio&&this.add(function(t){return e=>{const{i18n:r,constructor:{ASPECT_RATIO:o}}=e,a=o.map(t=>`${"default"===t?r.get("Default"):t}`).join("");return c(l({},t),{html:`${r.get("Aspect Ratio")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.aspectRatio=o,t.show=!1)},mounted:t=>{const r=T('[data-value="default"]',t);r&&A(r,"art-current"),e.on("aspectRatio",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&A(r,"art-current")})}})}}({name:"aspectRatio",index:20})),t.flip&&this.add(function(t){return e=>{const{i18n:r,constructor:{FLIP:o}}=e,a=o.map(t=>`${r.get(Q(t))}`).join("");return c(l({},t),{html:`${r.get("Video Flip")}: ${a}`,click:(t,r)=>{const{value:o}=r.target.dataset;o&&(e.flip=o.toLowerCase(),t.show=!1)},mounted:t=>{const r=T('[data-value="normal"]',t);r&&A(r,"art-current"),e.on("flip",e=>{const r=E("span",t).find(t=>t.dataset.value===e);r&&A(r,"art-current")})}})}}({name:"flip",index:30})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Video Info"),click:t=>{e.info.show=!0,t.show=!1}})}({name:"info",index:40})),this.add(function(t){return c(l({},t),{html:`ArtPlayer ${g}`})}({name:"version",index:50})),this.add(function(t){return e=>c(l({},t),{html:e.i18n.get("Close"),click:t=>{t.show=!1}})}({name:"close",index:60}));for(let a=0;a{if(!this.art.constructor.CONTEXTMENU)return;t.preventDefault(),this.show=!0;const e=t.clientX,a=t.clientY,{height:n,width:i,left:s,top:l}=H(r),{height:c,width:d}=H(o);let p=e-s,h=a-l;e+d>s+i&&(p=i-d),a+c>l+n&&(h=n-c),P(o,{top:`${h}px`,left:`${p}px`})}),e(r,"click",t=>{V(t,o)||(this.show=!1)}),this.art.on("blur",()=>{this.show=!1})}}function Lt(t,e){const{$progress:r}=t.template,{left:o}=H(r),a=J((k?e.touches[0].clientX:e.clientX)-o,0,r.clientWidth),n=a/r.clientWidth*t.duration;return{second:n,time:tt(n),width:a,percentage:J(a/r.clientWidth,0,1)}}function St(t,e){if(t.isRotate){const r=(e.touches[0].clientY-t.top)/t.height,o=r*t.duration;t.emit("setBar","played",r,e),t.seek=o}else{const{second:r,percentage:o}=Lt(t,e);t.emit("setBar","played",o,e),t.seek=r}}function Mt(t){return e=>{const{icons:r,option:o,proxy:a}=e,{$player:n,$progress:i}=e.template;return c(l({},t),{html:'\n
\n
\n
\n
\n
\n
\n
00:00
\n
\n ',mounted:t=>{let s=null,l=!1;const c=T(".art-progress-hover",t),d=T(".art-progress-loaded",t),p=T(".art-progress-played",t),h=T(".art-progress-highlight",t),u=T(".art-progress-indicator",t),m=T(".art-progress-tip",t);function f(r,o){const{width:a,time:n}=o||Lt(e,r);m.textContent=n||"00:00";const i=m.clientWidth;a<=i/2?I(m,"left",0):a>t.clientWidth-i/2?I(m,"left",t.clientWidth-i+"px"):I(m,"left",a-i/2+"px")}r.indicator?S(u,r.indicator):I(u,"backgroundColor","var(--art-theme)"),e.on("setBar",function(r,o,a){const i="played"===r&&a&&k;if("loaded"===r&&I(d,"width",100*o+"%"),"hover"===r&&(I(c,"width",100*o+"%"),V(a,h)?function(r){const{width:o}=Lt(e,r),{text:a}=r.target.dataset;m.textContent=a;const n=m.clientWidth;o<=n/2?I(m,"left",0):o>t.clientWidth-n/2?I(m,"left",t.clientWidth-n+"px"):I(m,"left",o-n/2+"px")}(a):f(a),0===o?z(n,"art-progress-hover"):C(n,"art-progress-hover")),"played"===r&&(I(p,"width",100*o+"%"),I(u,"left",100*o+"%")),i){C(n,"art-progress-hover");f(a,{width:t.clientWidth*o,time:tt(o*e.duration)}),clearTimeout(s),s=setTimeout(()=>{z(n,"art-progress-hover")},500)}}),e.on("video:loadedmetadata",function(){h.textContent="";for(let t=0;t`;S(h,n)}}),e.constructor.USE_RAF?e.on("raf",()=>{e.emit("setBar","played",e.played),e.emit("setBar","loaded",e.loaded)}):(e.on("video:timeupdate",()=>{e.emit("setBar","played",e.played)}),e.on("video:progress",()=>{e.emit("setBar","loaded",e.loaded)}),e.on("video:ended",()=>{e.emit("setBar","played",1)})),e.emit("setBar","loaded",e.loaded||0),k||(a(i,"click",t=>{t.target!==u&&St(e,t)}),a(i,"mousemove",t=>{const{percentage:r}=Lt(e,t);e.emit("setBar","hover",r,t)}),a(i,"mouseleave",t=>{e.emit("setBar","hover",0,t)}),a(i,"mousedown",t=>{l=0===t.button}),e.on("document:mousemove",t=>{if(l){const{second:r,percentage:o}=Lt(e,t);e.emit("setBar","played",o,t),e.seek=r}}),e.on("document:mouseup",()=>{l&&(l=!1)}))}})}}class It extends Ct{constructor(t){super(t),this.isHover=!1,this.name="control",this.timer=Date.now();const{constructor:e}=t,{$player:r,$bottom:o}=this.art.template;t.on("mousemove",()=>{k||(this.show=!0)}),t.on("click",()=>{k?this.toggle():this.show=!0}),t.on("document:mousemove",t=>{this.isHover=V(t,o)}),t.on("video:timeupdate",()=>{!t.setting.show&&!this.isHover&&!t.isInput&&t.playing&&this.show&&Date.now()-this.timer>=e.CONTROL_HIDE_TIME&&(this.show=!1)}),t.on("control",t=>{t?(z(r,"art-hide-cursor"),C(r,"art-hover"),this.timer=Date.now()):(C(r,"art-hide-cursor"),z(r,"art-hover"))}),this.init()}init(){const{option:t}=this.art;t.isLive||this.add(Mt({name:"progress",position:"top",index:10})),this.add({name:"thumbnails",position:"top",index:20}),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.play),i=S(t,o.pause);function s(){I(n,"display","flex"),I(i,"display","none")}function l(){I(n,"display","none"),I(i,"display","flex")}R(n,a.get("Play")),R(i,a.get("Pause")),r(n,"click",()=>{G(e.play())}),r(i,"click",()=>{e.pause()}),e.playing?l():s(),e.on("video:playing",()=>{l()}),e.on("video:pause",()=>{s()})}})}({name:"playAndPause",position:"left",index:10})),this.add(function(t){return e=>c(l({},t),{mounted:t=>{const{proxy:r,icons:o}=e,a=S(t,o.volume),n=S(t,o.volumeClose),i=S(t,'
'),s=S(i,'
'),l=S(s,'
'),c=S(s,'
'),d=S(c,'
'),p=S(d,'
'),h=S(c,'
');function u(t){const{top:e,height:r}=H(c);return 1-(t.clientY-e)/r}function m(){if(e.muted||0===e.volume)I(a,"display","none"),I(n,"display","flex"),I(h,"top","100%"),I(p,"top","100%"),l.textContent=0;else{const t=100*e.volume;I(a,"display","flex"),I(n,"display","none"),I(h,"top",100-t+"%"),I(p,"top",100-t+"%"),l.textContent=Math.floor(t)}}if(m(),e.on("video:volumechange",m),r(a,"click",()=>{e.muted=!0}),r(n,"click",()=>{e.muted=!1}),k)I(i,"display","none");else{let t=!1;r(c,"mousedown",r=>{t=0===r.button,e.volume=u(r)}),e.on("document:mousemove",r=>{t&&(e.muted=!1,e.volume=u(r))}),e.on("document:mouseup",()=>{t&&(t=!1)})}}})}({name:"volume",position:"left",index:20})),t.isLive||this.add(function(t){return e=>c(l({},t),{style:k?{fontSize:"12px",padding:"0 5px"}:{cursor:"auto",padding:"0 10px"},mounted:t=>{function r(){const r=`${tt(e.currentTime)} / ${tt(e.duration)}`;r!==t.textContent&&(t.textContent=r)}r();const o=["video:loadedmetadata","video:timeupdate","video:progress"];for(let a=0;a{this.art.quality=t.quality}),t.screenshot&&!k&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Screenshot"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.screenshot),r(t,"click",()=>{e.screenshot()})}})}({name:"screenshot",position:"right",index:20})),t.setting&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Show Setting"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.setting),r(t,"click",()=>{e.setting.toggle(),e.setting.resize()}),e.on("setting",e=>{R(t,a.get(e?"Hide Setting":"Show Setting"))})}})}({name:"setting",position:"right",index:30})),t.pip&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("PIP Mode"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e;S(t,o.pip),r(t,"click",()=>{e.pip=!e.pip}),e.on("pip",e=>{R(t,a.get(e?"Exit PIP Mode":"PIP Mode"))})}})}({name:"pip",position:"right",index:40})),t.airplay&&window.WebKitPlaybackTargetAvailabilityEvent&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("AirPlay"),mounted:t=>{const{proxy:r,icons:o}=e;S(t,o.airplay),r(t,"click",()=>e.airplay())}})}({name:"airplay",position:"right",index:50})),t.fullscreenWeb&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Web Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenWebOn),i=S(t,o.fullscreenWebOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreenWeb=!e.fullscreenWeb}),e.on("fullscreenWeb",e=>{e?(R(t,a.get("Exit Web Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Web Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreenWeb",position:"right",index:60})),t.fullscreen&&this.add(function(t){return e=>c(l({},t),{tooltip:e.i18n.get("Fullscreen"),mounted:t=>{const{proxy:r,icons:o,i18n:a}=e,n=S(t,o.fullscreenOn),i=S(t,o.fullscreenOff);I(i,"display","none"),r(t,"click",()=>{e.fullscreen=!e.fullscreen}),e.on("fullscreen",e=>{e?(R(t,a.get("Exit Fullscreen")),I(n,"display","none"),I(i,"display","inline-flex")):(R(t,a.get("Fullscreen")),I(n,"display","inline-flex"),I(i,"display","none"))})}})}({name:"fullscreen",position:"right",index:70}));for(let e=0;et.selector}),nt(e,"$control_item",{get:()=>r}),nt(e,"$control_value",{get:()=>a})}const i=o(n,"click",e=>d(this,null,function*(){const r=j(e),o=t.selector.find(t=>t.$control_item===r.find(e=>t.$control_item===e));this.check(o),t.onSelect&&(a.innerHTML=yield t.onSelect.call(this.art,o,o.$control_item,e))}));r.push(i)}}function Pt(t,e,r,o){const a=e-o,n=r-t;let i=0;if(Math.abs(n)<2&&Math.abs(a)<2)return i;const s=function(t,e){return 180*Math.atan2(e,t)/Math.PI}(n,a);return s>=-45&&s<45?i=4:s>=45&&s<135?i=1:s>=-135&&s<-45?i=2:(s>=135&&s<=180||s>=-180&&s<-135)&&(i=3),i}class Ot{constructor(t){this.destroyEvents=new Set,this.proxy=this.proxy.bind(this),this.hover=this.hover.bind(this),function(t,e){const{constructor:r,template:{$player:o,$video:a}}=t;function n(e){V(e,o)?(t.isInput="INPUT"===e.target.tagName,t.isFocus=!0,t.emit("focus",e)):(t.isInput=!1,t.isFocus=!1,t.emit("blur",e))}t.on("document:click",n),t.on("document:contextmenu",n);let i=[];e.proxy(a,"click",e=>{const o=Date.now();i.push(o);const{MOBILE_CLICK_PLAY:a,DBCLICK_TIME:n,MOBILE_DBCLICK_PLAY:s,DBCLICK_FULLSCREEN:l}=r,c=i.filter(t=>o-t<=n);switch(c.length){case 1:t.emit("click",e),k?!t.isLock&&a&&G(t.toggle()):G(t.toggle()),i=c;break;case 2:t.emit("dblclick",e),k?!t.isLock&&s&&G(t.toggle()):l&&(t.fullscreen=!t.fullscreen),i=[];break;default:i=[]}})}(t,this),function(t,e){const{$player:r}=t.template;e.hover(r,e=>{C(r,"art-hover"),t.emit("hover",!0,e)},e=>{z(r,"art-hover"),t.emit("hover",!1,e)})}(t,this),function(t,e){const{$player:r}=t.template;e.proxy(r,"mousemove",e=>{t.emit("mousemove",e)})}(t,this),function(t,e){const{option:r,constructor:o}=t;t.on("resize",()=>{const{aspectRatio:e,notice:o}=t;"standard"===t.state&&r.autoSize&&t.autoSize(),t.aspectRatio=e,o.show=""});const a=mt(()=>t.emit("resize"),o.RESIZE_TIME);t.on("window:orientationchange",()=>a()),t.on("window:resize",()=>a()),screen&&screen.orientation&&screen.orientation.onchange&&e.proxy(screen.orientation,"change",()=>a())}(t,this),function(t,e){if(k&&!t.option.isLive){const{$video:r,$progress:o}=t.template;let a=null,n=!1,i=0,s=0,l=0;const c=e=>{if(1===e.touches.length&&!t.isLock){a===o&&St(t,e),n=!0;const{pageX:r,pageY:c}=e.touches[0];i=r,s=c,l=t.currentTime}},d=e=>{if(1===e.touches.length&&n&&t.duration){const{pageX:o,pageY:n}=e.touches[0],c=Pt(i,s,o,n),d=[3,4].includes(c),p=[1,2].includes(c);if(d&&!t.isRotate||p&&t.isRotate){const c=J((o-i)/t.width,-1,1),d=J((n-s)/t.height,-1,1),p=t.isRotate?d:c,h=a===r?t.constructor.TOUCH_MOVE_RATIO:1,u=J(l+t.duration*p*h,0,t.duration);t.seek=u,t.emit("setBar","played",J(u/t.duration,0,1),e),t.notice.show=`${tt(u)} / ${tt(t.duration)}`}}},p=()=>{n&&(i=0,s=0,l=0,n=!1,a=null)};t.option.gesture&&(e.proxy(r,"touchstart",t=>{a=r,c(t)}),e.proxy(r,"touchmove",d)),e.proxy(o,"touchstart",t=>{a=o,c(t)}),e.proxy(o,"touchmove",d),t.on("document:touchend",p)}}(t,this),function(t){const{option:e,constructor:r,template:{$container:o}}=t,a=ft(()=>{t.emit("view",_(o,r.SCROLL_GAP))},r.SCROLL_TIME);t.on("window:scroll",()=>a()),t.on("view",r=>{e.autoMini&&(t.mini=!r)})}(t),function(t,e){const r=["click","mouseup","keydown","touchend","touchmove","mousemove","pointerup","contextmenu","pointermove","visibilitychange","webkitfullscreenchange"],o=["resize","scroll","orientationchange"],a=[];function n(n={}){for(let t=0;t{const o=n.document||i.ownerDocument||document,s=e.proxy(o,r,e=>{t.emit(`document:${r}`,e)});a.push(s)}),o.forEach(r=>{var o;const s=n.window||(null==(o=i.ownerDocument)?void 0:o.defaultView)||window,l=e.proxy(s,r,e=>{t.emit(`window:${r}`,e)});a.push(l)})}n(),e.bindGlobalEvents=n}(t,this),function(t){if(t.constructor.USE_RAF){let e=null;!function r(){t.playing&&t.emit("raf"),t.isDestroy||(e=requestAnimationFrame(r))}(),t.on("destroy",()=>{cancelAnimationFrame(e)})}}(t)}proxy(t,e,r,o={}){if(Array.isArray(e))return e.map(e=>this.proxy(t,e,r,o));t.addEventListener(e,r,o);const a=()=>t.removeEventListener(e,r,o);return this.destroyEvents.add(a),a}hover(t,e,r){e&&this.proxy(t,"mouseenter",e),r&&this.proxy(t,"mouseleave",r)}remove(t){if(this.destroyEvents.has(t))try{t()}catch(e){console.warn("Failed to remove event listener:",e)}finally{this.destroyEvents.delete(t)}}destroy(){for(const e of this.destroyEvents)try{e()}catch(t){console.warn("Failed to destroy event listener:",t)}this.destroyEvents.clear()}}class At{constructor(t){this.art=t,this.keys={},k||this.init()}init(){const{constructor:t}=this.art;this.art.option.hotkey&&(this.add("Escape",()=>{this.art.fullscreenWeb&&(this.art.fullscreenWeb=!1)}),this.add("Space",()=>{G(this.art.toggle())}),this.add("ArrowLeft",()=>{this.art.backward=t.SEEK_STEP}),this.add("ArrowUp",()=>{this.art.volume+=t.VOLUME_STEP}),this.add("ArrowRight",()=>{this.art.forward=t.SEEK_STEP}),this.add("ArrowDown",()=>{this.art.volume-=t.VOLUME_STEP})),this.art.on("document:keydown",t=>{if(this.art.isFocus){const e=document.activeElement.tagName.toUpperCase(),r=document.activeElement.getAttribute("contenteditable");if("INPUT"!==e&&"TEXTAREA"!==e&&""!==r&&"true"!==r&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){const e=this.keys[t.code];if(e){t.preventDefault();for(let r=0;r\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n',state:'\r\n\r\n\r\n',play:'\r\n \r\n',pause:'\r\n \r\n',check:'\r\n\r\n',volume:'\r\n \r\n \r\n',volumeClose:'\r\n \r\n \r\n',screenshot:'\r\n\t\r\n\r\n',setting:'\r\n \r\n \r\n',pip:'\r\n\r\n',arrowLeft:'\r\n \r\n',arrowRight:'\r\n \r\n',playbackRate:'',aspectRatio:'',config:'',lock:'\r\n\r\n\r\n\r\n\r\n',flip:'\r\n\r\n\r\n\r\n\r\n\r\n',unlock:'\r\n\r\n\r\n',fullscreenOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenOn:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOff:'\r\n\r\n\r\n\r\n\r\n',fullscreenWebOn:'\r\n\r\n\r\n\r\n\r\n',switchOn:'\r\n\r\n\r\n \r\n',switchOff:'\r\n\r\n\r\n \r\n\r\n',error:'\r\n\r\n\r\n\r\n\r\n',close:'\r\n\r\n\r\n\r\n\r\n',airplay:'\r\n \r\n \r\n \r\n \r\n\r\n'},t.option.icons);for(const r in e)nt(this,r,{get:()=>D(r,e[r])})}}class Yt extends Ct{constructor(t){super(t),this.name="info",k||this.init()}init(){const{proxy:t,constructor:e,template:{$infoPanel:r,$infoClose:o,$video:a}}=this.art;t(o,"click",()=>{this.show=!1});let n=null;const i=E("[data-video]",r)||[];this.art.on("destroy",()=>clearTimeout(n)),function t(){for(let e=0;e{I(a,"display","none"),I(n,"display",null)}),o.proxy(e.$state,"click",()=>G(t.play()))}}class Bt{constructor(t){this.art=t,this.timer=null,t.on("destroy",()=>this.destroy())}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}set show(t){const{constructor:e,template:{$player:r,$noticeInner:o}}=this.art;t?(o.textContent=t instanceof Error?t.message.trim():t,C(r,"art-notice-show"),clearTimeout(this.timer),this.timer=setTimeout(()=>{o.textContent="",z(r,"art-notice-show")},e.NOTICE_TIME)):z(r,"art-notice-show")}get show(){const{template:{$player:t}}=this.art;return t.classList.contains("art-notice-show")}}const Ht=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],Wt=(()=>{if("undefined"===typeof document)return!1;const t=Ht[0],e={};for(const r of Ht){if(r[1]in document){for(const[o,a]of r.entries())e[t[o]]=a;return e}}return!1})(),jt={change:Wt.fullscreenchange,error:Wt.fullscreenerror},Ut={request:(t=document.documentElement,e)=>new Promise((r,o)=>{const a=()=>{Ut.off("change",a),r()};Ut.on("change",a);const n=t[Wt.requestFullscreen](e);n instanceof Promise&&n.then(a).catch(o)}),exit:()=>new Promise((t,e)=>{if(!Ut.isFullscreen)return void t();const r=()=>{Ut.off("change",r),t()};Ut.on("change",r);const o=document[Wt.exitFullscreen]();o instanceof Promise&&o.then(r).catch(e)}),toggle:(t,e)=>Ut.isFullscreen?Ut.exit():Ut.request(t,e),onchange(t){Ut.on("change",t)},onerror(t){Ut.on("error",t)},on(t,e){const r=jt[t];r&&document.addEventListener(r,e,!1)},off(t,e){const r=jt[t];r&&document.removeEventListener(r,e,!1)},raw:Wt};function qt(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t,n=t=>{Ut.on("change",()=>{t.emit("fullscreen",Ut.isFullscreen),Ut.isFullscreen?(t.state="fullscreen",C(a,"art-fullscreen")):z(a,"art-fullscreen"),t.emit("resize")}),Ut.on("error",e=>{t.emit("fullscreenError",e)}),nt(t,"fullscreen",{get:()=>Ut.isFullscreen,set(t){return d(this,null,function*(){t?yield Ut.request(a):yield Ut.exit()})}})};t.once("video:loadedmetadata",()=>{var a;Ut.isEnabled?n(t):o.webkitSupportsFullscreen?((a=t).on("document:webkitfullscreenchange",()=>{a.emit("fullscreen",a.fullscreen),a.emit("resize")}),nt(a,"fullscreen",{get:()=>document.fullscreenElement===o,set(t){t?(a.state="fullscreen",o.webkitEnterFullscreen()):o.webkitExitFullscreen()}})):nt(t,"fullscreen",{get:()=>!1,set(){r.show=e.get("Fullscreen Not Supported")}}),nt(t,"fullscreen",lt(t,"fullscreen"))})}function Xt(t){const{icons:e,proxy:r,storage:o,template:{$player:a,$video:n}}=t;let i=!1,s=0,l=0;function c(){const{$mini:e}=t.template;e&&(z(a,"art-mini"),I(e,"display","none"),a.prepend(n),t.emit("mini",!1))}function d(e,r){t.playing?(I(e,"display","none"),I(r,"display","flex")):(I(e,"display","flex"),I(r,"display","none"))}function p(){const{$mini:e}=t.template,r=H(e),a=window.innerHeight-r.height-50,n=window.innerWidth-r.width-50;o.set("top",a),o.set("left",n),I(e,"top",`${a}px`),I(e,"left",`${n}px`)}nt(t,"mini",{get:()=>L(a,"art-mini"),set(h){if(h){t.state="mini",C(a,"art-mini");const h=function(){const{$mini:a}=t.template;if(a)return S(a,n),I(a,"display","flex");{const a=N("div");C(a,"art-mini-popup"),S(document.body,a),t.template.$mini=a,S(a,n);const p=S(a,'
');S(p,e.close),r(p,"click",c);const h=S(a,'
'),u=S(h,e.play),m=S(h,e.pause);return r(u,"click",()=>G(t.play())),r(m,"click",()=>t.pause()),d(u,m),t.on("video:playing",()=>d(u,m)),t.on("video:pause",()=>d(u,m)),t.on("video:timeupdate",()=>d(u,m)),r(a,"mousedown",t=>{i=0===t.button,s=t.pageX,l=t.pageY}),t.on("document:mousemove",t=>{if(i){C(a,"art-mini-dragging");const e=t.pageX-s,r=t.pageY-l;I(a,"transform",`translate(${e}px, ${r}px)`)}}),t.on("document:mouseup",()=>{if(i){i=!1,z(a,"art-mini-dragging");const t=H(a);o.set("left",t.left),o.set("top",t.top),I(a,"left",`${t.left}px`),I(a,"top",`${t.top}px`),I(a,"transform",null)}}),a}}(),u=o.get("top"),m=o.get("left");"number"===typeof u&&"number"===typeof m?(I(h,"top",`${u}px`),I(h,"left",`${m}px`),_(h)||p()):p(),t.emit("mini",!0)}else c()}})}function Gt(t){const{i18n:e,notice:r,template:{$video:o}}=t;document.pictureInPictureEnabled?function(t){const{template:{$video:e},proxy:r,notice:o}=t;e.disablePictureInPicture=!1,nt(t,"pip",{get:()=>document.pictureInPictureElement,set(r){r?(t.state="pip",e.requestPictureInPicture().catch(t=>{throw o.show=t,t})):document.exitPictureInPicture().catch(t=>{throw o.show=t,t})}}),r(e,"enterpictureinpicture",()=>{t.emit("pip",!0)}),r(e,"leavepictureinpicture",()=>{t.emit("pip",!1)})}(t):o.webkitSupportsPresentationMode?function(t){const{$video:e}=t.template;e.webkitSetPresentationMode("inline"),nt(t,"pip",{get:()=>"picture-in-picture"===e.webkitPresentationMode,set(r){r?(t.state="pip",e.webkitSetPresentationMode("picture-in-picture"),t.emit("pip",!0)):(e.webkitSetPresentationMode("inline"),t.emit("pip",!1))}})}(t):nt(t,"pip",{get:()=>!1,set(){r.show=e.get("PIP Not Supported")}})}function Kt(t){const{option:e,template:{$progress:r,$video:o}}=t;let a=null,n=!1,i=null;t.on("setBar",(a,s,l)=>d(null,null,function*(){var c;const d=null==(c=t.controls)?void 0:c.thumbnails,{url:p,scale:h}=e.thumbnails;if(!d||!p)return;if("hover"===a||"played"===a&&l&&k){if(i||n||(n=!0,i=yield W(p,h),n=!1),!i)return;const a=r.clientWidth*s;a>0&&ar.clientWidth-u/2?I(s,"left",r.clientWidth-u+"px"):I(s,"left",a-u/2+"px")}(a)}})),nt(t,"thumbnails",{get:()=>t.option.thumbnails,set(e){e.url&&!t.option.isLive&&(t.option.thumbnails=e,clearTimeout(a),a=null,n=!1,i=null)}})}Object.defineProperties(Ut,{isFullscreen:{get:()=>Boolean(document[Wt.fullscreenElement])},element:{enumerable:!0,get:()=>document[Wt.fullscreenElement]},isEnabled:{enumerable:!0,get:()=>Boolean(document[Wt.fullscreenEnabled])}});class Zt{constructor(t){!function(t){const{option:e,template:{$video:r}}=t;nt(t,"url",{get:()=>r.src,set(o){return d(this,null,function*(){if(o){const a=t.url,n=e.type||K(o),i=e.customType[n];n&&i?(yield ut(),t.loading.show=!0,i.call(t,r,o,t)):(URL.revokeObjectURL(a),r.src=o),a!==t.url&&(t.option.url=o,t.isReady&&a&&t.once("video:canplay",()=>{t.emit("restart",o)}))}else yield ut(),t.loading.show=!0})}})}(t),function(t){const{template:{$video:e}}=t;nt(t,"attr",{value(t,r){if(void 0===r)return e[t];e[t]=r}})}(t),function(t){const{i18n:e,notice:r,option:o,constructor:{instances:a},template:{$video:n}}=t;nt(t,"play",{value(){return d(this,null,function*(){const i=yield n.play();if(r.show=e.get("Play"),t.emit("play"),o.mutex)for(let e=0;et.playing?t.pause():t.play()})}(t),function(t){const{notice:e}=t;nt(t,"seek",{set(r){t.currentTime=r,t.duration&&(e.show=`${tt(t.currentTime)} / ${tt(t.duration)}`),t.emit("seek",t.currentTime,r)}}),nt(t,"forward",{set(e){t.seek=t.currentTime+e}}),nt(t,"backward",{set(e){t.seek=t.currentTime-e}})}(t),function(t){const{template:{$video:e},i18n:r,notice:o,storage:a}=t;nt(t,"volume",{get:()=>e.volume||0,set:t=>{e.volume=J(t,0,1),o.show=`${r.get("Volume")}: ${Number.parseInt(100*e.volume,10)}`,0!==e.volume&&a.set("volume",e.volume)}}),nt(t,"muted",{get:()=>e.muted,set:r=>{e.muted=r,t.emit("muted",r)}})}(t),function(t){const{$video:e}=t.template;nt(t,"currentTime",{get:()=>e.currentTime||0,set:r=>{r=Number.parseFloat(r),Number.isNaN(r)||(e.currentTime=J(r,0,t.duration))}})}(t),function(t){nt(t,"duration",{get:()=>{const{duration:e}=t.template.$video;return e===1/0?0:e||0}})}(t),function(t){function e(e,r){return new Promise((o,a)=>{if(e===t.url)return void o();const{playing:n,aspectRatio:i,playbackRate:s}=t;t.pause(),t.url=e,t.notice.show="";const l={error:e=>{t.off("video:canplay",l.canplay),t.off("video:loadedmetadata",l.metadata),a(e)},metadata:()=>{t.currentTime=r},canplay:()=>d(null,null,function*(){t.off("video:error",l.error),t.playbackRate=s,t.aspectRatio=i,n&&(yield G(t.play())),t.notice.show="",o()})};t.once("video:error",l.error),t.once("video:loadedmetadata",l.metadata),t.once("video:canplay",l.canplay)})}nt(t,"switchQuality",{value:r=>e(r,t.currentTime)}),nt(t,"switchUrl",{value:t=>e(t,0)}),nt(t,"switch",{set:t.switchUrl})}(t),function(t){const{template:{$video:e},i18n:r,notice:o}=t;nt(t,"playbackRate",{get:()=>e.playbackRate,set(a){if(a){if(a===e.playbackRate)return;e.playbackRate=a,o.show=`${r.get("Rate")}: ${1===a?r.get("Normal"):`${a}x`}`}else t.playbackRate=1}})}(t),function(t){const{i18n:e,notice:r,template:{$video:o,$player:a}}=t;nt(t,"aspectRatio",{get:()=>a.dataset.aspectRatio||"default",set(n){if(n||(n="default"),"default"===n)I(o,"width",null),I(o,"height",null),I(o,"margin",null),delete a.dataset.aspectRatio;else{const t=n.split(":").map(Number),{clientWidth:e,clientHeight:r}=a,i=e/r,s=t[0]/t[1];i>s?(I(o,"width",s*r+"px"),I(o,"height","100%"),I(o,"margin","0 auto")):(I(o,"width","100%"),I(o,"height",e/s+"px"),I(o,"margin","auto 0")),a.dataset.aspectRatio=n}r.show=`${e.get("Aspect Ratio")}: ${"default"===n?e.get("Default"):n}`,t.emit("aspectRatio",n)}})}(t),function(t){const{notice:e,template:{$video:r}}=t,o=N("canvas");nt(t,"getDataURL",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),t(o.toDataURL("image/png"))}catch(n){e.show=n,a(n)}})}),nt(t,"getBlobUrl",{value:()=>new Promise((t,a)=>{try{o.width=r.videoWidth,o.height=r.videoHeight,o.getContext("2d").drawImage(r,0,0),o.toBlob(e=>{t(URL.createObjectURL(e))})}catch(n){e.show=n,a(n)}})}),nt(t,"screenshot",{value:e=>d(null,null,function*(){const o=yield t.getDataURL();return Z(o,`${e||`artplayer_${tt(r.currentTime)}`}.png`),t.emit("screenshot",o),o})})}(t),qt(t),function(t){const{constructor:e,template:{$container:r,$player:o}}=t;let a="";nt(t,"fullscreenWeb",{get:()=>L(o,"art-fullscreen-web"),set(n){n?(a=o.style.cssText,e.FULLSCREEN_WEB_IN_BODY&&S(document.body,o),t.state="fullscreenWeb",I(o,"width","100%"),I(o,"height","100%"),C(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!0)):(e.FULLSCREEN_WEB_IN_BODY&&S(r,o),a&&(o.style.cssText=a,a=""),z(o,"art-fullscreen-web"),t.emit("fullscreenWeb",!1)),t.emit("resize")}})}(t),Gt(t),function(t){const{$video:e}=t.template;nt(t,"loaded",{get:()=>t.loadedTime/e.duration}),nt(t,"loadedTime",{get:()=>e.buffered.length?e.buffered.end(e.buffered.length-1):0})}(t),function(t){nt(t,"played",{get:()=>t.currentTime/t.duration})}(t),function(t){const{$video:e}=t.template;nt(t,"playing",{get:()=>"boolean"===typeof e.playing?e.playing:!!(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2)})}(t),function(t){const{$container:e,$player:r,$video:o}=t.template;nt(t,"autoSize",{value(){const{videoWidth:a,videoHeight:n}=o,{width:i,height:s}=H(e),l=a/n;if(i/s>l)I(r,"width",s*l/i*100+"%"),I(r,"height","100%");else{const t=i/l/s*100;I(r,"width","100%"),I(r,"height",`${t}%`)}t.emit("autoSize",{width:t.width,height:t.height})}})}(t),function(t){nt(t,"rect",{get:()=>H(t.template.$player)});const e=["bottom","height","left","right","top","width"];for(let r=0;rt.rect[o]})}nt(t,"x",{get:()=>t.left+window.pageXOffset}),nt(t,"y",{get:()=>t.top+window.pageYOffset})}(t),function(t){const{template:{$player:e},i18n:r,notice:o}=t;nt(t,"flip",{get:()=>e.dataset.flip||"normal",set(a){a||(a="normal"),"normal"===a?delete e.dataset.flip:e.dataset.flip=a,o.show=`${r.get("Video Flip")}: ${r.get(Q(a))}`,t.emit("flip",a)}})}(t),Xt(t),function(t){const{template:{$poster:e}}=t;nt(t,"poster",{get:()=>{try{return e.style.backgroundImage.match(/"(.*)"/)[1]}catch(t){return""}},set(t){I(e,"backgroundImage",`url(${t})`)}})}(t),function(t){const{template:{$container:e,$video:r}}=t;nt(t,"autoHeight",{value(){const{clientWidth:o}=e,{videoHeight:a,videoWidth:n}=r,i=a*(o/n);I(e,"height",`${i}px`),t.emit("autoHeight",i)}})}(t),function(t){const{$player:e}=t.template;nt(t,"cssVar",{value:(t,r)=>r?e.style.setProperty(t,r):getComputedStyle(e).getPropertyValue(t)})}(t),function(t){nt(t,"theme",{get:()=>t.cssVar("--art-theme"),set(e){t.cssVar("--art-theme",e)}})}(t),function(t){nt(t,"type",{get:()=>t.option.type,set(e){t.option.type=e}})}(t),function(t){const e=["mini","pip","fullscreen","fullscreenWeb"];nt(t,"state",{get:()=>e.find(e=>t[e])||"standard",set(r){for(let o=0;o{switch(t.availability){case"available":n=!0;break;case"not-available":n=!1}}):n=!1,nt(t,"airplay",{value(){n?(a.webkitShowPlaybackTargetPicker(),t.emit("airplay")):r.show=e.get("AirPlay Not Available")}})}(t),function(t){nt(t,"quality",{set(e){const{controls:r,notice:o,i18n:a}=t,n=e.find(t=>t.default)||e[0];r.update({name:"quality",position:"right",index:10,style:{marginRight:"10px"},html:(null==n?void 0:n.html)||"",selector:e,onSelect(e){return d(this,null,function*(){return yield t.switchQuality(e.url),o.show=`${a.get("Switch Video")}: ${e.html}`,e.html})}})}})}(t),Kt(t),function(t){const{i18n:e,notice:r,option:o,constructor:a,proxy:n,template:{$player:i,$video:s,$poster:l}}=t;let c=0;for(let d=0;d{t.emit(`video:${e.type}`,e)});t.on("video:canplay",()=>{c=0,t.loading.show=!1}),t.once("video:canplay",()=>{t.loading.show=!1,t.controls.show=!0,t.mask.show=!0,t.isReady=!0,t.emit("ready")}),t.on("video:ended",()=>{o.loop?(t.seek=0,G(t.play()),t.controls.show=!1,t.mask.show=!1):(t.controls.show=!0,t.mask.show=!0)}),t.on("video:error",n=>d(null,null,function*(){c{t.emit("resize"),k&&(t.loading.show=!1,t.controls.show=!0,t.mask.show=!0)}),t.on("video:loadstart",()=>{t.loading.show=!0,t.mask.show=!1,t.controls.show=!0}),t.on("video:pause",()=>{t.controls.show=!0,t.mask.show=!0}),t.on("video:play",()=>{t.mask.show=!1,I(l,"display","none")}),t.on("video:playing",()=>{t.mask.show=!1}),t.on("video:progress",()=>{t.playing&&(t.loading.show=!1)}),t.on("video:seeked",()=>{t.loading.show=!1,t.mask.show=!0}),t.on("video:seeking",()=>{t.loading.show=!0,t.mask.show=!1}),t.on("video:timeupdate",()=>{t.mask.show=!1}),t.on("video:waiting",()=>{t.loading.show=!0,t.mask.show=!1})}(t),function(t){const{option:e,storage:r,template:{$video:o,$poster:a}}=t;for(const i in e.moreVideoAttr)t.attr(i,e.moreVideoAttr[i]);e.muted&&(t.muted=e.muted),e.volume&&(o.volume=J(e.volume,0,1));const n=r.get("volume");"number"===typeof n&&(o.volume=J(n,0,1)),e.poster&&I(a,"backgroundImage",`url(${e.poster})`),e.autoplay&&(o.autoplay=e.autoplay),e.playsInline&&(o.playsInline=!0,o["webkit-playsinline"]=!0),e.theme&&(e.cssVar["--art-theme"]=e.theme);for(const i in e.cssVar)t.cssVar(i,e.cssVar[i]);t.url=e.url}(t)}}function Jt(t){const{notice:e,constructor:r,template:{$player:o,$video:a}}=t,n="art-auto-orientation",i="art-auto-orientation-fullscreen";let s=!1;function l(){const{videoWidth:t,videoHeight:e}=a,r=document.documentElement.clientWidth,o=document.documentElement.clientHeight;return t>e&&ro}return t.on("fullscreenWeb",e=>{var a;if(e){if(l()){const e=Number(null!=(a=r.AUTO_ORIENTATION_TIME)?a:0);setTimeout(()=>{t.fullscreenWeb&&!L(o,n)&&function(){const e=U(),r=document.documentElement.clientWidth,a=document.documentElement.clientHeight-e.top-e.bottom,i=r-e.left-e.right;I(o,"width",`${a}px`),I(o,"height",`${i}px`),I(o,"transform-origin","0 0"),I(o,"transform",`rotate(90deg) translate(${e.top}px, -${r-e.right}px)`),C(o,n),t.isRotate=!0,t.emit("resize")}()},e)}}else L(o,n)&&(I(o,"width",""),I(o,"height",""),I(o,"transform-origin",""),I(o,"transform",""),z(o,n),t.isRotate=!1,t.emit("resize"))}),t.on("fullscreen",t=>d(null,null,function*(){var r;const a=!!(null==(r=null==screen?void 0:screen.orientation)?void 0:r.lock);if(t){if(a&&l())try{const t=screen.orientation.type.startsWith("portrait")?"landscape":"portrait";yield screen.orientation.lock(t),s=!0,C(o,i)}catch(n){s=!1,e.show=n}}else if(L(o,i)&&z(o,i),a&&s){try{screen.orientation.unlock()}catch(c){}s=!1}})),{name:"autoOrientation",get state(){return L(o,n)}}}function Qt(t){const{i18n:e,icons:r,storage:o,constructor:a,proxy:n,template:{$poster:i}}=t,s=t.layers.add({name:"auto-playback",html:'\n
\n
\n
\n '}),l=T(".art-auto-playback-last",s),c=T(".art-auto-playback-jump",s),d=T(".art-auto-playback-close",s);S(d,r.close);let p=null;function h(){const r=(o.get("times")||{})[t.option.id||t.option.url];clearTimeout(p),I(s,"display","none"),r&&r>=a.AUTO_PLAYBACK_MIN&&(I(s,"display","flex"),l.textContent=`${e.get("Last Seen")} ${tt(r)}`,c.textContent=e.get("Jump Play"),n(d,"click",()=>{I(s,"display","none")}),n(c,"click",()=>{t.seek=r,G(t.play()),I(i,"display","none"),I(s,"display","none")}),t.once("video:timeupdate",()=>{p=setTimeout(()=>{I(s,"display","none")},a.AUTO_PLAYBACK_TIMEOUT)}))}return t.on("video:timeupdate",()=>{if(t.playing){const e=o.get("times")||{},r=Object.keys(e);r.length>a.AUTO_PLAYBACK_MAX&&delete e[r[0]],e[t.option.id||t.option.url]=t.currentTime,o.set("times",e)}}),t.on("ready",h),t.on("restart",h),{name:"auto-playback",get times(){return o.get("times")||{}},clear:()=>o.del("times"),delete(t){const e=o.get("times")||{};return delete e[t],o.set("times",e),e}}}function te(t){const{constructor:e,proxy:r,template:{$player:o,$video:a}}=t;let n=null,i=!1,s=1;const l=()=>{clearTimeout(n),i&&(i=!1,t.playbackRate=s,z(o,"art-fast-forward"))};return r(a,"touchstart",r=>{1===r.touches.length&&t.playing&&!t.isLock&&(n=setTimeout(()=>{i=!0,s=t.playbackRate,t.playbackRate=e.FAST_FORWARD_VALUE,C(o,"art-fast-forward")},e.FAST_FORWARD_TIME))}),t.on("document:touchmove",l),t.on("document:touchend",l),{name:"fastForward",get state(){return L(o,"art-fast-forward")}}}function ee(t){const{layers:e,icons:r,template:{$player:o}}=t;function a(){return L(o,"art-lock")}function n(){C(o,"art-lock"),t.isLock=!0,t.emit("lock",!0)}function i(){z(o,"art-lock"),t.isLock=!1,t.emit("lock",!1)}return e.add({name:"lock",mounted(e){const o=S(e,r.lock),a=S(e,r.unlock);I(o,"display","none"),t.on("lock",t=>{t?(I(o,"display","inline-flex"),I(a,"display","none")):(I(o,"display","none"),I(a,"display","inline-flex"))})},click(){a()?i():n()}}),{name:"lock",get state(){return a()},set state(t){t?n():i()}}}function re(t){return t.on("control",e=>{e?z(t.template.$player,"art-mini-progress-bar"):C(t.template.$player,"art-mini-progress-bar")}),{name:"mini-progress-bar"}}class oe{constructor(t){this.art=t,this.id=0;const{option:e}=t;e.miniProgressBar&&!e.isLive&&this.add(re),e.lock&&k&&this.add(ee),e.autoPlayback&&!e.isLive&&this.add(Qt),e.autoOrientation&&k&&this.add(Jt),e.fastForward&&k&&!e.isLive&&this.add(te);for(let r=0;rthis.next(t,e)):this.next(t,e)}next(t,e){const r=e&&e.name||t.name||`plugin${this.id}`;return X(!st(this,r),`Cannot add a plugin that already has the same name: ${r}`),nt(this,r,{value:e}),this}}class ae extends Ct{constructor(t){super(t);const{option:e,controls:r,template:{$setting:o}}=t;this.name="setting",this.$parent=o,this.id=0,this.active=null,this.cache=new Map,this.option=[...this.builtin,...e.settings],e.setting&&(this.format(),this.render(),t.on("blur",()=>{this.show&&(this.show=!1,this.render())}),t.on("focus",t=>{const e=V(t,r.setting),o=V(t,this.$parent);!this.show||e||o||(this.show=!1,this.render())}),t.on("resize",()=>this.resize()))}get builtin(){const t=[],{option:e}=this.art;return e.playbackRate&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,PLAYBACK_RATE:a}}=t;function n(t){return 1===t?e.get("Normal"):t.toFixed(1)}function i(){const e=t.setting.find(`playback-rate-${t.playbackRate}`);t.setting.check(e)}return{width:o,name:"playback-rate",html:e.get("Play Speed"),tooltip:n(t.playbackRate),icon:r.playbackRate,selector:a.map(e=>({value:e,name:`playback-rate-${e}`,default:e===t.playbackRate,html:n(e)})),onSelect:e=>(t.playbackRate=e.value,e.html),mounted:()=>{i(),t.on("video:ratechange",()=>i())}}}(this.art)),e.aspectRatio&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,ASPECT_RATIO:a}}=t;function n(t){return"default"===t?e.get("Default"):t}function i(){const e=t.setting.find(`aspect-ratio-${t.aspectRatio}`);t.setting.check(e)}return{width:o,name:"aspect-ratio",html:e.get("Aspect Ratio"),icon:r.aspectRatio,tooltip:n(t.aspectRatio),selector:a.map(e=>({value:e,name:`aspect-ratio-${e}`,default:e===t.aspectRatio,html:n(e)})),onSelect:e=>(t.aspectRatio=e.value,e.html),mounted:()=>{i(),t.on("aspectRatio",()=>i())}}}(this.art)),e.flip&&t.push(function(t){const{i18n:e,icons:r,constructor:{SETTING_ITEM_WIDTH:o,FLIP:a}}=t;function n(t){return e.get(Q(t))}function i(){const e=t.setting.find(`flip-${t.flip}`);t.setting.check(e)}return{width:o,name:"flip",html:e.get("Video Flip"),tooltip:n(t.flip),icon:r.flip,selector:a.map(e=>({value:e,name:`flip-${e}`,default:e===t.flip,html:n(e)})),onSelect:e=>(t.flip=e.value,e.html),mounted:()=>{i(),t.on("flip",()=>i())}}}(this.art)),e.subtitleOffset&&t.push(function(t){const{i18n:e,icons:r,constructor:o}=t;return{width:o.SETTING_ITEM_WIDTH,name:"subtitle-offset",html:e.get("Subtitle Offset"),icon:r.subtitle,tooltip:"0s",range:[0,-10,10,.1],onChange:e=>(t.subtitleOffset=e.range[0],`${e.range[0]}s`),mounted:(e,r)=>{t.on("subtitleOffset",t=>{r.$range.value=t,r.tooltip=`${t}s`})}}}(this.art)),t}traverse(t,e=this.option){var r;for(let o=0;o{e.default=e===t,e.default&&e.$item&&A(e.$item,"art-current")},t.$option),this.render(t.$parents))}format(t=this.option,e,r,o=[]){for(let a=0;ae}),nt(n,"$parents",{get:()=>r}),nt(n,"$option",{get:()=>t});const o=[];nt(n,"$events",{get:()=>o}),nt(n,"$formatted",{get:()=>!0})}this.format(n.selector||[],n,t,o)}this.option=t}find(t=""){let e=null;return this.traverse(r=>{r.name===t&&(e=r)}),e}resize(){var t,e;const{controls:r,constructor:{SETTING_WIDTH:o,SETTING_ITEM_HEIGHT:a},template:{$player:n,$setting:i}}=this.art;if(r.setting&&this.show){const s=(null==(e=null==(t=this.active[0])?void 0:t.$parent)?void 0:e.width)||o,{left:l,width:c}=H(r.setting),{left:d,width:p}=H(n),h=l-d+c/2-s/2;if(I(i,"height",`${this.active===this.option?this.active.length*a:(this.active.length+1)*a}px`),I(i,"width",`${s}px`),this.art.isRotate||k)return;h+s>p?(I(i,"left",null),I(i,"right",null)):(I(i,"left",`${h}px`),I(i,"right","auto"))}}inactivate(t){for(let e=0;e'),s=N("div");C(s,"art-setting-item-left-icon"),S(s,o),S(i,s),S(i,t.$parent.html);const l=r(n,"click",()=>this.render(t.$parents));t.$parent.$events.push(l),S(e,n)}createItem(t,e=!1){var r,o;if(!this.cache.has(t.$option))return;const a=this.cache.get(t.$option),n=t.$item;let i="selector";st(t,"switch")&&(i="switch"),st(t,"range")&&(i="range"),st(t,"onClick")&&(i="button");const{icons:s,proxy:l,constructor:c}=this.art,p=N("div");C(p,"art-setting-item"),I(p,"height",`${c.SETTING_ITEM_HEIGHT}px`),p.dataset.name=t.name||"",p.dataset.value=t.value||"";const h=S(p,'
'),u=S(p,'
'),m=N("div");switch(C(m,"art-setting-item-left-icon"),i){case"button":case"switch":case"range":S(m,t.icon||s.config);break;case"selector":(null==(r=t.selector)?void 0:r.length)?S(m,t.icon||s.config):S(m,s.check)}S(h,m),nt(t,"$icon",{configurable:!0,get:()=>m}),nt(t,"icon",{configurable:!0,get:()=>m.innerHTML,set(t){m.innerHTML="",S(m,t)}});const f=N("div");C(f,"art-setting-item-left-text"),S(f,t.html||""),S(h,f),nt(t,"$html",{configurable:!0,get:()=>f}),nt(t,"html",{configurable:!0,get:()=>f.innerHTML,set(t){f.innerHTML="",S(f,t)}});const g=N("div");switch(C(g,"art-setting-item-right-tooltip"),S(g,t.tooltip||""),S(u,g),nt(t,"$tooltip",{configurable:!0,get:()=>g}),nt(t,"tooltip",{configurable:!0,get:()=>g.innerHTML,set(t){g.innerHTML="",S(g,t)}}),i){case"switch":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,s.switchOn),o=S(e,s.switchOff);I(t.switch?o:r,"display","none"),S(u,e),nt(t,"$switch",{configurable:!0,get:()=>e});let a=t.switch;nt(t,"switch",{configurable:!0,get:()=>a,set(t){a=t,t?(I(o,"display","none"),I(r,"display",null)):(I(o,"display",null),I(r,"display","none"))}});break}case"range":{const e=N("div");C(e,"art-setting-item-right-icon");const r=S(e,'');r.value=t.range[0],r.min=t.range[1],r.max=t.range[2],r.step=t.range[3],C(r,"art-setting-range"),S(u,e),nt(t,"$range",{configurable:!0,get:()=>r});let o=[...t.range];nt(t,"range",{configurable:!0,get:()=>o,set(t){o=[...t],r.value=t[0],r.min=t[1],r.max=t[2],r.step=t[3]}})}break;case"selector":if(null==(o=t.selector)?void 0:o.length){const t=N("div");C(t,"art-setting-item-right-icon"),S(t,s.arrowRight),S(u,t)}}switch(i){case"switch":if(t.onSwitch){const e=l(p,"click",e=>d(this,null,function*(){t.switch=yield t.onSwitch.call(this.art,t,p,e)}));t.$events.push(e)}break;case"range":if(t.$range){if(t.onRange){const e=l(t.$range,"change",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onRange.call(this.art,t,p,e)}));t.$events.push(e)}if(t.onChange){const e=l(t.$range,"input",e=>d(this,null,function*(){t.range[0]=t.$range.valueAsNumber,t.tooltip=yield t.onChange.call(this.art,t,p,e)}));t.$events.push(e)}}break;case"selector":{const e=l(p,"click",e=>d(this,null,function*(){var r;(null==(r=t.selector)?void 0:r.length)?this.render(t.selector):(this.check(t),t.$parent.onSelect&&(t.$parent.tooltip=yield t.$parent.onSelect.call(this.art,t,p,e)))}));t.$events.push(e),t.default&&C(p,"art-current")}break;case"button":if(t.onClick){const e=l(p,"click",e=>d(this,null,function*(){t.tooltip=yield t.onClick.call(this.art,t,p,e)}));t.$events.push(e)}}nt(t,"$item",{configurable:!0,get:()=>p}),e?Y(p,n):S(a,p),t.mounted&&setTimeout(()=>t.mounted.call(this.art,t.$item,t),0)}render(t=this.option){var e;if(this.active=t,this.cache.has(t)){A(this.cache.get(t),"art-current")}else{const r=N("div");this.cache.set(t,r),C(r,"art-setting-panel"),S(this.$parent,r),A(r,"art-current"),(null==(e=t[0])?void 0:e.$parent)&&this.createHeader(t[0]);for(let e=0;enull,this.init(t.option.subtitle);let e=!1;t.on("video:timeupdate",()=>{if(!this.url)return;const t=this.art.template.$video.webkitDisplayingFullscreen;"boolean"===typeof t&&t!==e&&(e=t,this.createTrack(t?"subtitles":"metadata",this.url))})}get url(){return this.art.template.$track.src}set url(t){this.switch(t)}get textTrack(){var t,e;return null==(e=null==(t=this.art.template.$video)?void 0:t.textTracks)?void 0:e[0]}get activeCues(){return this.textTrack?Array.from(this.textTrack.activeCues):[]}get cues(){return this.textTrack?Array.from(this.textTrack.cues):[]}style(t,e){const{$subtitle:r}=this.art.template;return"object"===typeof t?P(r,t):I(r,t,e)}update(){const{option:{subtitle:t},template:{$subtitle:e}}=this.art;e.innerHTML="",this.activeCues.length&&(this.art.emit("subtitleBeforeUpdate",this.activeCues),e.innerHTML=this.activeCues.map((e,r)=>e.text.split(/\r?\n/).filter(t=>t.trim()).map(e=>`
\n ${t.escape?at(e):e}\n
`).join("")).join(""),this.art.emit("subtitleAfterUpdate",this.activeCues))}switch(t){return d(this,arguments,function*(t,e={}){const{i18n:r,notice:o,option:a}=this.art,n=c(l(l({},a.subtitle),e),{url:t}),i=yield this.init(n);return e.name&&(o.show=`${r.get("Switch Subtitle")}: ${e.name}`),i})}createTrack(t,e){const{template:r,proxy:o,option:a}=this.art,{$video:n,$track:i}=r,s=N("track");s.default=!0,s.kind=t,s.src=e,s.label=a.subtitle.name||"Artplayer",s.track.mode="hidden",s.onload=()=>{this.art.emit("subtitleLoad",this.cues,this.option)},this.art.events.remove(this.destroyEvent),i.onload=null,M(i),S(n,s),r.$track=s,this.destroyEvent=o(this.textTrack,"cuechange",()=>this.update())}init(t){return d(this,null,function*(){const{notice:e,template:{$subtitle:r}}=this.art;return this.textTrack?(f(t,Et.subtitle),t.url?(this.option=t,this.style(t.style),fetch(t.url).then(t=>t.arrayBuffer()).then(e=>{const r=new TextDecoder(t.encoding).decode(e);switch(t.type||K(t.url)){case"srt":{const e=dt(r);return pt(t.onVttLoad(e))}case"ass":{const e=ht(r);return pt(t.onVttLoad(e))}case"vtt":return pt(t.onVttLoad(r));default:return t.url}}).then(t=>(r.innerHTML="",this.url===t||(URL.revokeObjectURL(this.url),this.createTrack("metadata",t)),t)).catch(t=>{throw r.innerHTML="",e.show=t,t})):void 0):null})}}class le{constructor(t){this.art=t;const{option:e,constructor:r}=t;e.container instanceof Element?this.$container=e.container:(this.$container=T(e.container),X(this.$container,`No container element found by ${e.container}`)),X(B(),"The current browser does not support flex layout");const o=this.$container.tagName.toLowerCase();X("div"===o,`Unsupported container element type, only support 'div' but got '${o}'`),X(r.instances.every(t=>t.template.$container!==this.$container),"Cannot mount multiple instances on the same dom element"),this.query=this.query.bind(this),this.$container.dataset.artId=t.id,this.init()}static get html(){return`\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Player version:
\n
${g}
\n
\n
\n
Video url:
\n
\n
\n
\n
Video volume:
\n
\n
\n
\n
Video time:
\n
\n
\n
\n
Video duration:
\n
\n
\n
\n
Video resolution:
\n
\n x \n
\n
\n
\n
[x]
\n
\n
\n
\n `}query(t){return T(t,this.$container)}init(){const{option:t}=this.art;if(t.useSSR||(this.$container.innerHTML=le.html),this.$player=this.query(".art-video-player"),this.$video=this.query(".art-video"),this.$track=this.query("track"),this.$poster=this.query(".art-poster"),this.$subtitle=this.query(".art-subtitle"),this.$danmuku=this.query(".art-danmuku"),this.$bottom=this.query(".art-bottom"),this.$progress=this.query(".art-progress"),this.$controls=this.query(".art-controls"),this.$controlsLeft=this.query(".art-controls-left"),this.$controlsCenter=this.query(".art-controls-center"),this.$controlsRight=this.query(".art-controls-right"),this.$layer=this.query(".art-layers"),this.$loading=this.query(".art-loading"),this.$notice=this.query(".art-notice"),this.$noticeInner=this.query(".art-notice-inner"),this.$mask=this.query(".art-mask"),this.$state=this.query(".art-state"),this.$setting=this.query(".art-settings"),this.$info=this.query(".art-info"),this.$infoPanel=this.query(".art-info-panel"),this.$infoClose=this.query(".art-info-close"),this.$contextmenu=this.query(".art-contextmenus"),t.proxy){const e=t.proxy.call(this.art,this.art);X(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement,"Function 'option.proxy' needs to return 'HTMLVideoElement' or 'HTMLCanvasElement'"),Y(e,this.$video),e.className="art-video",this.$video=e}t.backdrop&&C(this.$player,"art-backdrop"),k&&C(this.$player,"art-mobile")}destroy(t){t?this.$container.innerHTML="":C(this.$player,"art-destroy")}}const ce=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class de{on(t,e,r){const o=this.e||(this.e={});let a=ce(o,t)?o[t]:void 0;return a||(a=[],Object.defineProperty(o,t,{value:a,enumerable:!0,configurable:!0,writable:!0})),a.push({fn:e,ctx:r}),this}once(t,e,r){const o=this,a=e;let n=!1;function i(...e){n||(n=!0,o.off(t,i),a.apply(r,e))}return i._=e,this.on(t,i,r)}emit(t,...e){const r=this.e||(this.e={}),o=(ce(r,t)&&r[t]||[]).slice();for(const a of o)a.fn.apply(a.ctx,e);return this}off(t,e){const r=this.e||(this.e={}),o=ce(r,t)?r[t]:void 0,a=[];if(o&&e)for(let n=0,i=o.length;ne.call(this,this)),ue.DEBUG){const t=t=>console.log(`[ART.${this.id}] -> ${t}`);t(`Version@${ue.version}`);for(let e=0;et(`Event@${e.type}`))}he.push(this)}static get instances(){return he}static get version(){return g}static get config(){return v}static get utils(){return gt}static get scheme(){return Et}static get Emitter(){return de}static get validator(){return f}static get kindOf(){return f.kindOf}static get html(){return le.html}static get option(){return{id:"",container:"#artplayer",url:"",poster:"",type:"",theme:"#f00",volume:.7,isLive:!1,muted:!1,autoplay:!1,autoSize:!1,autoMini:!1,loop:!1,flip:!1,playbackRate:!1,aspectRatio:!1,screenshot:!1,setting:!1,hotkey:!0,pip:!1,mutex:!0,backdrop:!0,fullscreen:!1,fullscreenWeb:!1,subtitleOffset:!1,miniProgressBar:!1,useSSR:!1,playsInline:!0,lock:!1,gesture:!0,fastForward:!1,autoPlayback:!1,autoOrientation:!1,airplay:!1,proxy:void 0,layers:[],contextmenu:[],controls:[],settings:[],quality:[],highlight:[],plugins:[],thumbnails:{url:"",number:60,column:10,width:0,height:0,scale:1},subtitle:{url:"",type:"",style:{},name:"",escape:!0,encoding:"utf-8",onVttLoad:t=>t},moreVideoAttr:{controls:!1,preload:b?"auto":"metadata"},i18n:{},icons:{},cssVar:{},customType:{},lang:null==navigator?void 0:navigator.language.toLowerCase()}}get proxy(){return this.events.proxy}get query(){return this.template.query}get video(){return this.template.$video}reset(){this.video.removeAttribute("src"),this.video.load()}destroy(t=!0){ue.REMOVE_SRC_WHEN_DESTROY&&this.reset(),this.events.destroy(),this.template.destroy(t),he.splice(he.indexOf(this),1),this.isDestroy=!0,this.emit("destroy")}}return ue.STYLE=ie,ue.DEBUG=!1,ue.CONTEXTMENU=!0,ue.NOTICE_TIME=2e3,ue.SETTING_WIDTH=250,ue.SETTING_ITEM_WIDTH=200,ue.SETTING_ITEM_HEIGHT=35,ue.RESIZE_TIME=200,ue.SCROLL_TIME=200,ue.SCROLL_GAP=50,ue.AUTO_PLAYBACK_MAX=10,ue.AUTO_PLAYBACK_MIN=5,ue.AUTO_PLAYBACK_TIMEOUT=3e3,ue.RECONNECT_TIME_MAX=5,ue.RECONNECT_SLEEP_TIME=1e3,ue.CONTROL_HIDE_TIME=3e3,ue.DBCLICK_TIME=300,ue.DBCLICK_FULLSCREEN=!0,ue.MOBILE_DBCLICK_PLAY=!0,ue.MOBILE_CLICK_PLAY=!1,ue.AUTO_ORIENTATION_TIME=200,ue.INFO_LOOP_TIME=1e3,ue.FAST_FORWARD_VALUE=3,ue.FAST_FORWARD_TIME=1e3,ue.TOUCH_MOVE_RATIO=.5,ue.VOLUME_STEP=.1,ue.SEEK_STEP=5,ue.PLAYBACK_RATE=[.5,.75,1,1.25,1.5,2],ue.ASPECT_RATIO=["default","4:3","16:9"],ue.FLIP=["normal","horizontal","vertical"],ue.FULLSCREEN_WEB_IN_BODY=!0,ue.LOG_VERSION=!0,ue.USE_RAF=!1,ue.REMOVE_SRC_WHEN_DESTROY=!0,$&&(window.Artplayer=ue,F("artplayer-style",ie),setTimeout(()=>{ue.LOG_VERSION&&console.log(`%c ArtPlayer %c ${ue.version} %c https://artplayer.org`,"color: #fff; background: #5f5f5f","color: #fff; background: #4bc729","")},100)),ue}); diff --git a/packages/artplayer/dist/artplayer.mjs b/packages/artplayer/dist/artplayer.mjs index bca7fa5e5..1749e58a3 100644 --- a/packages/artplayer/dist/artplayer.mjs +++ b/packages/artplayer/dist/artplayer.mjs @@ -4780,36 +4780,49 @@ class Template { } } } +const owns = (object, key) => Object.prototype.hasOwnProperty.call(object, key); class Emitter { on(name, fn, ctx) { const e = this.e || (this.e = {}); - (e[name] || (e[name] = [])).push({ fn, ctx }); + let listeners = owns(e, name) ? e[name] : void 0; + if (!listeners) { + listeners = []; + Object.defineProperty(e, name, { value: listeners, enumerable: true, configurable: true, writable: true }); + } + listeners.push({ fn, ctx }); return this; } once(name, fn, ctx) { const self = this; + const callback = fn; + let fired = false; function listener(...args) { + if (fired) + return; + fired = true; self.off(name, listener); - fn.apply(ctx, args); + callback.apply(ctx, args); } listener._ = fn; return this.on(name, listener, ctx); } emit(name, ...data) { - const evtArr = ((this.e || (this.e = {}))[name] || []).slice(); - for (let i = 0; i < evtArr.length; i += 1) { - evtArr[i].fn.apply(evtArr[i].ctx, data); + const e = this.e || (this.e = {}); + const snapshot = (owns(e, name) ? e[name] || [] : []).slice(); + for (const event of snapshot) { + event.fn.apply(event.ctx, data); } return this; } off(name, callback) { const e = this.e || (this.e = {}); - const evts = e[name]; + const evts = owns(e, name) ? e[name] : void 0; const liveEvents = []; if (evts && callback) { for (let i = 0, len = evts.length; i < len; i += 1) { - if (evts[i].fn !== callback && evts[i].fn._ !== callback) - liveEvents.push(evts[i]); + const event = evts[i]; + if (event.fn !== callback && event.fn._ !== callback) + liveEvents.push(event); } } if (liveEvents.length) { diff --git a/packages/artplayer/src/utils/emitter.js b/packages/artplayer/src/utils/emitter.js deleted file mode 100644 index 988662583..000000000 --- a/packages/artplayer/src/utils/emitter.js +++ /dev/null @@ -1,44 +0,0 @@ -export default class Emitter { - on(name, fn, ctx) { - const e = this.e || (this.e = {}); - (e[name] || (e[name] = [])).push({ fn, ctx }) - return this - } - - once(name, fn, ctx) { - const self = this - function listener(...args) { - self.off(name, listener) - fn.apply(ctx, args) - } - listener._ = fn - return this.on(name, listener, ctx) - } - - emit(name, ...data) { - const evtArr = ((this.e || (this.e = {}))[name] || []).slice() - for (let i = 0; i < evtArr.length; i += 1) { - evtArr[i].fn.apply(evtArr[i].ctx, data) - } - return this - } - - off(name, callback) { - const e = this.e || (this.e = {}) - const evts = e[name] - const liveEvents = [] - if (evts && callback) { - for (let i = 0, len = evts.length; i < len; i += 1) { - if (evts[i].fn !== callback && evts[i].fn._ !== callback) - liveEvents.push(evts[i]) - } - } - if (liveEvents.length) { - e[name] = liveEvents - } - else { - delete e[name] - } - return this - } -} diff --git a/packages/artplayer/src/utils/emitter.ts b/packages/artplayer/src/utils/emitter.ts new file mode 100644 index 000000000..dbe99911d --- /dev/null +++ b/packages/artplayer/src/utils/emitter.ts @@ -0,0 +1,69 @@ +type EventMap = { [Name in keyof Events]: readonly unknown[] } +type Listener = ((...args: Args) => unknown) & { _?: (...args: Args) => unknown } +interface Registration { + fn: Listener + ctx: unknown +} +type Registry> = { [Name in keyof Events]?: Registration<[...Events[Name]]>[] } +const owns = (object: object, key: PropertyKey) => Object.prototype.hasOwnProperty.call(object, key) + +export default class Emitter = Record> { + declare e?: Registry + + on(name: Name, fn: (this: Context, ...args: [...Events[Name]]) => unknown, ctx?: Context): this { + const e: Registry = this.e || (this.e = {}) + let listeners = owns(e, name) ? e[name] : undefined + if (!listeners) { + listeners = [] + Object.defineProperty(e, name, { value: listeners, enumerable: true, configurable: true, writable: true }) + } + listeners.push({ fn, ctx }) + return this + } + + once(name: Name, fn: (this: Context, ...args: [...Events[Name]]) => unknown, ctx?: Context): this { + // eslint-disable-next-line ts/no-this-alias -- The once wrapper unsubscribes its owner, independently of callback ctx. + const self = this + const callback: Listener<[...Events[Name]]> = fn + let fired = false + function listener(...args: [...Events[Name]]) { + if (fired) + return + fired = true + self.off(name, listener) + callback.apply(ctx, args) + } + listener._ = fn + return this.on(name, listener, ctx) + } + + emit(name: Name, ...data: [...Events[Name]]): this { + const e: Registry = this.e || (this.e = {}) + const snapshot = (owns(e, name) ? e[name] || [] : []).slice() + for (const event of snapshot) { + event.fn.apply(event.ctx, data) + } + return this + } + + off(name: Name, callback?: Listener<[...Events[Name]]>): this { + const e: Registry = this.e || (this.e = {}) + const evts = owns(e, name) ? e[name] : undefined + const liveEvents: Registration<[...Events[Name]]>[] = [] + if (evts && callback) { + for (let i = 0, len = evts.length; i < len; i += 1) { + // Registrations are inserted densely; retain the captured-length traversal. + const event = evts[i]! + if (event.fn !== callback && event.fn._ !== callback) + liveEvents.push(event) + } + } + if (liveEvents.length) { + e[name] = liveEvents + } + else { + delete e[name] + } + return this + } +} diff --git a/refactor/baselines/emitter-validation.json b/refactor/baselines/emitter-validation.json new file mode 100644 index 000000000..08682b686 --- /dev/null +++ b/refactor/baselines/emitter-validation.json @@ -0,0 +1,548 @@ +{ + "task": "CORE-02", + "capturedAt": "2026-09-10T16:02:48.874Z", + "source": "26a93d3ff35b53e71a5f3bb22c252a854559d8151ede50a66a28d9eefae6c008", + "packages": [ + { + "name": "artplayer", + "version": "5.4.1", + "archive": "artplayer.tgz", + "sha256": "1850bab2601b6b5c0fac6a4c3010edf4a5e700f00a6c26a29e8d35730f56dba3", + "files": { + "package/ARCHITECTURE.md": "bd26a46f62bac3aac033a9ea8b881d65aec162e8b697ddb37b3837748c4355b4", + "package/README.md": "1e185e65f67fc2081b4182bbc6c4558ea05b6e3fa3acc5dd0c3ac7df1d542b09", + "package/dist/artplayer.js": "fb9c8dca1d789631dd87cb0cf43f2e66c8419a751cdd3a188c2ee1a6481e04c1", + "package/dist/artplayer.legacy.js": "a0c0adb9c48d7a96ddba43eab7a7f6d91e920fde41ee8010e294ebe6efcc0062", + "package/dist/artplayer.mjs": "d1e206489b72001dfb570c9c8b358085eb18317c10e2fc8cc8c83148319ff7ff", + "package/dist/i18n/ar.js": "61c43469ee95a00dc624583f418653e3dcbf48b24ae6a4c203ad986234852365", + "package/dist/i18n/ar.mjs": "68922fdc9f80d3321ea0654c8ff8f5875b6715103d2b14ffcf17f93738b39cf9", + "package/dist/i18n/cs.js": "ad7bbf8853204a6955ef84bfbd932cab3f141a7e73a8145f28ba7a5b2b83b7c0", + "package/dist/i18n/cs.mjs": "29a489be767fda9d46b59c9adbaad323f17a5e67daf7f7aa78b7ce8fb5b4d63c", + "package/dist/i18n/es.js": "aaa95cc9645b734c58fba06fdbcdda962c4cb3a0e7eb6206f06d6168208cd86b", + "package/dist/i18n/es.mjs": "331d2ef74da2eec8f3304fec0b5340c795d9c1eec24e08167c9a7b66bf30973b", + "package/dist/i18n/fa.js": "c998467261cbdfd2c3fb16c0ae4b2c48c409f42f41aea35ed94766f1e12819d5", + "package/dist/i18n/fa.mjs": "b4c98894b46975cebf5ea9088bcf0b5bdfd408bc3c82f4e2e9128133c7de2d4d", + "package/dist/i18n/fr.js": "6b06e16b1fb01c8695fb5c10b32a00421399180de5dc5d845ce17010f2fd3e66", + "package/dist/i18n/fr.mjs": "abe8e3548fa7304f302e2c74818a6176edee8c3b65e33cb6f62e96d130749ee5", + "package/dist/i18n/id.js": "a5832c4bfc03c7f16418bf4b324d9773895541dc823ece9114741794737aad74", + "package/dist/i18n/id.mjs": "a40a433be6ca1ac1ee1810fe805ee60784d349e59b9ad82ea80201d660db4e68", + "package/dist/i18n/pl.js": "2491487062bdfc91d60f17c6e9a83ee196c991216d15f525fe3536b98873da2c", + "package/dist/i18n/pl.mjs": "ad8ea2c03785edbfe1f35761bec21b8a04213f9fa88a794d850bb3973564930f", + "package/dist/i18n/ru.js": "2d3a9ee6533cb6fa961f0a24a25ce63cc76992fca17e1769b6fa75104f8a1529", + "package/dist/i18n/ru.mjs": "a89b8c36cfd7c181c2b31aa823deda3d7c37b56b2b81746338c52ea1c1d93352", + "package/dist/i18n/tr.js": "438b06a4c3f479a2901b0085eaa7bdba8eaef87bdb07ff3faa559c85403fe433", + "package/dist/i18n/tr.mjs": "cc96f9cbb9c1587d5cd8f25b0b9800678ad76e93de089ae42c38dee16e6fe8fa", + "package/dist/i18n/vi.js": "1ffbd62843a902ea2967eab46432d3fc548f5633e53eed104314b523cacc46a8", + "package/dist/i18n/vi.mjs": "7872ded84622bcda20e8c1d70c597c2ba071b50701900efa47cc4683ee17f1a2", + "package/dist/i18n/zh-tw.js": "2d43577f98456488196921e1ec721695a95e1b8c827077286b02ce3fb987e8ff", + "package/dist/i18n/zh-tw.mjs": "7ec638b4babe59d3ab1d3e64abdd74a96fefb260a50e2cd7240f8d50a1340925", + "package/package.json": "b343df9955df9ac0ea71ea775bd0743c6b26c06d3bb7699128f7eac484fa769f", + "package/types/README.md": "d38bb63f9e96f995273f9da6833a8b936a74718ef7b710dbd316530d41ccae07", + "package/types/artplayer.d.cts": "be67cbb6c352944741bca88f969ad1bafa9898049595930e2dc6693d5e7262f5", + "package/types/artplayer.d.mts": "87d1f0e2a7bf7b7bdf700875cb2c77dea8be34ba3ac943e5fd35e8daa99bf241", + "package/types/artplayer.d.ts": "98d3e7b65f9f81fba155da08fd47e4fb25f4c69279e3afd993c4a55070f8a850", + "package/types/component.d.ts": "facfa29d9092fe2c63a7d8357ce7d0faa5e32811d2fedeef6dc8b28ad5d04891", + "package/types/config.d.ts": "c4fd8681bf32b10c743e3e561c532520c8f32e43fd765524850b15e55cb91c72", + "package/types/cssVar.d.ts": "e027d82fb4f01c9ce7559cf679b2d5ee1962d3f7e5b4dd64ca21f472b933efb6", + "package/types/events.d.ts": "98c74aebb82455accc0b3523af5a1145bc9119da58c884200adc36e70a164b02", + "package/types/i18n.d.ts": "3e14759caf71f97f01650839248c8737c42d2c2979dabc43ad92b724da648708", + "package/types/icons.d.ts": "0d8e8e52e52130dd4a29bab551dd7a2a954797e42e92a6e068c85d583e23e6a4", + "package/types/language.d.cts": "1c9e0c47fae3c2d68c3e144d95a55071318a03bb31554dd049109efd3d0f95a4", + "package/types/language.d.mts": "c391e863012c77769e661afbf8fa949e9373aa88d17f58cbba7f5696edb8077f", + "package/types/legacy/language.d.ts": "c452ffd764ff9b29b819b3475c42395d2ea7a33560d8c186ef5df3844b9524c3", + "package/types/option.d.ts": "d4de53930c2fa9d59c77c4324d63f24b057bce6c4d0273c34a0ab06094dcea2c", + "package/types/player.d.ts": "986382bb6b4e82746fd2405092e69d0ef413988887a557a0fd4db85d64b78d54", + "package/types/quality.d.ts": "7ed6ed78cea52991b2f6ddd2bd3b7bd8c5146fdfff7486fe8b814c3e632f1567", + "package/types/setting.d.ts": "d12a75b656fff70cbb30be4bffec46d9c4273636e8722bce971a4d2b188712a1", + "package/types/subtitle.d.ts": "d25b470e47d6a9bd696d9c1ad8adb58e56a208f05695186d513bc8c43c2e8acf", + "package/types/template.d.ts": "68aed9e97d006d6be4fabb8504ca84dafab770b0925f4d6e7319e67c82f21b0d", + "package/types/utils.d.ts": "d3fb67b9187e1c81c6b3850694cf2627e927225ace160ae58c11631e9f673a98" + } + }, + { + "name": "artplayer-plugin-chapter", + "version": "1.1.0", + "archive": "artplayer-plugin-chapter.tgz", + "sha256": "df90b76c987209cecaed5a3b5a480a85e0c300e463d7dc5cc508c9aad002bb4c", + "files": { + "package/ARCHITECTURE.md": "20743bad87a174b0450e0d876b6aa6b2a9f47df296d479511ce7cc9298fdb57c", + "package/README.md": "b95400ff3d525621a15268bb56a2d353aacaaadefde7e735d7abd91a34edd96f", + "package/dist/artplayer-plugin-chapter.js": "6ac3dfe28f46084ac7caedd571b1a97dcee3cf9d708112f1b8bbd6566e1dc5c5", + "package/dist/artplayer-plugin-chapter.legacy.js": "6d9bff885412169e701670961aa00c2e46c4b42c9b9647ff4e6d198777d2a359", + "package/dist/artplayer-plugin-chapter.mjs": "26415cecab2c0198c566cef0232e20123413782d5bad7534a32939b3298617af", + "package/package.json": "24eec6907b3218439189adab6af3f932c1497c47c2d41209311c01042b07fd4f", + "package/types/artplayer-plugin-chapter.d.cts": "4f07514b37453cd6cea8e5aa28fa018ff31738e0d423c11a3b5eccd50ed30bcc", + "package/types/artplayer-plugin-chapter.d.mts": "610179754db36276e161a07bccf4eaba8b4480f053e716a2bcc5a1574871a171", + "package/types/artplayer-plugin-chapter.d.ts": "581aa2862e709601c87a23585f54a969ebd350be56a7469a31ff53f1311b578d" + } + } + ], + "runtimeChecks": 27, + "knownTypeBlockers": 0, + "ciChecks": 85, + "artifactEmitterChecks": { + "umd": 29, + "legacy": 29, + "esm": 29 + }, + "browser": { + "startTime": "2026-09-10T15:59:51.244Z", + "duration": 31373.444, + "expected": 75, + "skipped": 0, + "unexpected": 0, + "flaky": 0 + }, + "tests": [ + { + "title": "published-only observations: blank title, NaN and once-only metadata are historical defects", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate clears titles on blank chapters, zero hover and replacement", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate rejects NaN and can recover after an invalid update", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate releases only its listeners and DOM across multiple instances and early destruction", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate ignores pending metadata initialization after immediate destroy", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate deduplicates stylesheet injection while the document is loading", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "published-only observations: blank title, NaN and once-only metadata are historical defects", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate clears titles on blank chapters, zero hover and replacement", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate rejects NaN and can recover after an invalid update", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate releases only its listeners and DOM across multiple instances and early destruction", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate ignores pending metadata initialization after immediate destroy", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate deduplicates stylesheet injection while the document is loading", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "published-only observations: blank title, NaN and once-only metadata are historical defects", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate clears titles on blank chapters, zero hover and replacement", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate rejects NaN and can recover after an invalid update", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate releases only its listeners and DOM across multiple instances and early destruction", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate ignores pending metadata initialization after immediate destroy", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate deduplicates stylesheet injection while the document is loading", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "factory, registration, input normalization and safe title text", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "progress bars, real hover, title edges and boundary seek", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "sync update, Infinity, object identity, empty lists and invalid data", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "explicit source update and core-owned destruction", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "published: emitter event names and once across nested dispatch", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate: emitter event names and once across nested dispatch", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "published: emitter event names and once across nested dispatch", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate: emitter event names and once across nested dispatch", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "published: emitter event names and once across nested dispatch", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate: emitter event names and once across nested dispatch", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "published: real playback, pause, seek, switch and destroy", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate: real playback, pause, seek, switch and destroy", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "controlled HTTP media failure emits a real video error", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "Range, media identity and docs candidate routes", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "published: real playback, pause, seek, switch and destroy", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate: real playback, pause, seek, switch and destroy", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "controlled HTTP media failure emits a real video error", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "Range, media identity and docs candidate routes", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "published: real playback, pause, seek, switch and destroy", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate: real playback, pause, seek, switch and destroy", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "controlled HTTP media failure emits a real video error", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "Range, media identity and docs candidate routes", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "published: subtitle object URL contains real VTT data", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "published: download starts and removes its temporary anchor", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate: subtitle object URL contains real VTT data", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate: download starts and removes its temporary anchor", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "candidate download releases the anchor even when click fails", + "project": "chromium", + "status": "passed", + "browser": "153.0.8010.12" + }, + { + "title": "published: subtitle object URL contains real VTT data", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "published: download starts and removes its temporary anchor", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate: subtitle object URL contains real VTT data", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate: download starts and removes its temporary anchor", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "candidate download releases the anchor even when click fails", + "project": "firefox", + "status": "passed", + "browser": "155.0" + }, + { + "title": "published: subtitle object URL contains real VTT data", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "published: download starts and removes its temporary anchor", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate: subtitle object URL contains real VTT data", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate: download starts and removes its temporary anchor", + "project": "webkit", + "status": "passed", + "browser": "26.6" + }, + { + "title": "candidate download releases the anchor even when click fails", + "project": "webkit", + "status": "passed", + "browser": "26.6" + } + ] +} diff --git a/refactor/changes/2026-09-11-CORE-02-typed-emitter.md b/refactor/changes/2026-09-11-CORE-02-typed-emitter.md new file mode 100644 index 000000000..b66942cd0 --- /dev/null +++ b/refactor/changes/2026-09-11-CORE-02-typed-emitter.md @@ -0,0 +1,36 @@ +# CORE-02:带事件映射的 Emitter + +## 实现与保留契约 + +Emitter 迁移为 src/utils/emitter.ts,支持事件名到参数 tuple 的映射、可选/readonly 参数、symbol、 +ctx 推导和子类链式返回。默认开放通道;已知事件可与开放自定义事件组合,已知 payload 不被放宽。 +当前 JS 播放器与现有公开声明继续渐进迁移,不在本任务改变 Artplayer 构造或新增公开方法。 + +保留懒创建的普通对象 e、原始 fn/ctx、once wrapper 的 `_` 引用、方法参数个数和描述符。 +declare 字段不生成运行时初始化。派发浅拷贝数组,普通订阅移除/追加、原始 callback 移除 once、 +异常传播和停止当前派发等语义由发布/工作区/产物共享的九组契约覆盖。一次受控的密集数组索引 +断言保留 off 的原固定长度遍历;没有引入通用 any 或事件库依赖。 + +## 两处有意修复 + +- EVENT-NAME-01:旧版使用继承属性查询,toString/constructor/hasOwnProperty/__proto__ 不能 + 正常注册。现在只读 own entries 并定义 own data property,registry 原型不变。 +- EVENT-ONCE-01:较早的普通 listener 嵌套 emit 时,旧版的 once 被内外两个已捕获快照重复执行。 + wrapper 现在先记录 consumed 再取消订阅,跨快照只调用一次。普通 listener 的快照行为不变。 + +这两项是已复现缺陷,不作为必须保留的旧行为。Node 对照和三个真实浏览器都分别保留旧失败观察 +与候选修复断言;不会通过更新冻结发布结果来制造兼容结论。 + +## 验证 + +- 严格源码类型检查包含七个必须拒绝的错误调用;名字/payload/receiver/自定义通道都有正例。 +- `yarn ci:check` 共 85 项 Node/基线测试通过。 +- 实际 UMD、legacy、ESM 各 29 项 Emitter 对照及修复测试通过。 +- `yarn build artplayer` / `yarn build:i18n` 重建 dist 与 docs/compiled。 +- 严格 tarball 安装消费:27 项运行时、五组类型零诊断;共享 Emitter 契约已随安装检查增加。 +- 安装产物三浏览器 75 项通过,无重试/跳过,包括真实播放器和 chapter 的既有回归。 + [执行指纹](../baselines/emitter-validation.json) 记录最终 runtime 与浏览器资源的一致性。 + +[核心架构](../../packages/artplayer/ARCHITECTURE.md) 已更新数据和事件所有权。新修复在统一风险台账关闭, +公共 Emitter 声明扩展仍属于 CORE-07。下一项 CORE-03 建立内部资源作用域,再接初始化/销毁修复。 +独立提交包含生成产物;未升级版本、推送或发布。回退该提交即可恢复本次行为及源码。 diff --git a/refactor/plan.md b/refactor/plan.md index a9b2cd0ef..aa9902058 100644 --- a/refactor/plan.md +++ b/refactor/plan.md @@ -4,7 +4,7 @@ 基线:`40fcda6a37d0049d42e49c1e64e70d4fd9ba5f7f`。总任务 214 项,范围 22 个包及工作区/示例。 -状态:todo 177 / doing 0 / blocked 0 / done 37 / deferred 0。风险 L/M/H 表示兼容风险,不表示工期。 +状态:todo 176 / doing 0 / blocked 0 / done 38 / deferred 0。风险 L/M/H 表示兼容风险,不表示工期。 前置依赖是启动条件;验收是完成条件。任务可以继续拆分,但不能复用或悄悄删除旧 ID。 @@ -105,7 +105,7 @@ | ID | 范围 / 步骤 | 前置依赖 | 交付物 | 验收条件 | 风险 | 状态 | | --- | --- | --- | --- | --- | --- | --- | | CORE-01 | artplayer
迁移纯工具并冻结导出 | ENG-03, ENG-04, ENG-06, PILOT-01 | utils/time/property/format/file/error/subtitle 的分批 TS 迁移 | Artplayer.utils 导出/参数/绑定保持,纯逻辑与类型测试通过 | M | done | -| CORE-02 | artplayer
迁移内部 Emitter | CORE-01, BASE-03 | 带类型事件映射的原 Emitter 实现 | ctx、once/off、重入/异常和链式返回保持 | H | todo | +| CORE-02 | artplayer
迁移内部 Emitter | CORE-01, BASE-03 | 带类型事件映射的原 Emitter 实现 | ctx、once/off、重入/异常和链式返回保持 | H | done | | CORE-03 | artplayer
建立内部资源作用域 | CORE-02 | 监听/订阅/定时器/RAF/请求/URL 的资源登记 | 实例与操作作用域分离,单项清理失败不阻断其他资源 | H | todo | | CORE-04 | artplayer
修复初始化与销毁生命周期 | CORE-03, ENG-05, BASE-07 | 构造失败回收、重复/重入 destroy、instances 修复 | 事件顺序、removeHtml、多实例和销毁中异步有真实回归;处理 baselines/lifecycle-coverage.md 的 BASE-LIFE-04/05 并增加候选正向回归;协调 BASE-PERF-01 销毁后定时器与回调归属 | H | todo | | CORE-05 | artplayer
区分输入配置和内部配置 | CORE-01, ENG-04 | Option/ResolvedOption、默认值与校验整理 | 配置合并/错误时机不变,JS 输入仍运行时校验 | M | todo | @@ -436,6 +436,7 @@ - ENG-10: [记录](changes/2026-09-10-ENG-10-test-reliability.md) [记录](test-reliability.md) - PILOT-01: [记录](changes/2026-09-10-PILOT-01-chapter.md) [记录](baselines/pilot-validation.json) - CORE-01: [记录](changes/2026-09-10-CORE-01-typed-utils.md) [记录](baselines/core-utils-validation.json) +- CORE-02: [记录](changes/2026-09-11-CORE-02-typed-emitter.md) [记录](baselines/emitter-validation.json) - PKG-CHAPTER-01: [记录](changes/2026-09-10-PKG-CHAPTER-01-contract.md) [记录](baselines/chapter-contract.md) - PKG-CHAPTER-02: [记录](changes/2026-09-10-PKG-CHAPTER-02-tests.md) [记录](baselines/chapter-validation.json) - PKG-CHAPTER-03: [记录](changes/2026-09-10-PKG-CHAPTER-03-typescript-modules.md) [记录](baselines/chapter-migration-validation.json) diff --git a/refactor/progress.md b/refactor/progress.md index 06a6d1c4a..f2e05f7a9 100644 --- a/refactor/progress.md +++ b/refactor/progress.md @@ -1,5 +1,9 @@ # 进度与证据 +## 当前实施:CORE-02 Emitter TS 迁移完成 + +事件映射、payload/ctx 和链式类型已加入;九组普通契约保持,另修复原型事件名与嵌套快照重复 once。85 项 Node/基线、75 项三浏览器、三格式各 29 项 Emitter 检查通过;严格打包 27 项运行时/五组类型零诊断。见 [交付](changes/2026-09-11-CORE-02-typed-emitter.md)。当前 214 项,38 完成、176 待办。核心八个 TS 文件、chapter 五个 TS 文件;下一项 CORE-03 内部资源作用域。 + ## 当前实施:CORE-01 核心工具 TS 迁移完成 七个核心 utils 文件已迁移为 TS,保留导出、属性与定时器契约,修复合并结果原型和下载失败清理;核心产物与 docs/compiled 已由脚本更新。75 项 Node/基线检查、69 项安装产物三浏览器测试、三格式各 18 项工具契约通过;严格打包零诊断。见 [交付](changes/2026-09-10-CORE-01-typed-utils.md)。当前 214 项,37 完成、177 待办。生产迁移:chapter 五个 TS 文件、核心 utils 七个 TS 文件;核心其他模块仍待迁移。下一项 CORE-02 内部 Emitter。公开 Utils 声明差异单独登记 BASE-TYPE-05,交 CORE-07 协调,不计为已修复。 diff --git a/refactor/risk-table.md b/refactor/risk-table.md index 6036c4e50..c76c23722 100644 --- a/refactor/risk-table.md +++ b/refactor/risk-table.md @@ -47,3 +47,5 @@ | UTIL-MERGE-01 | resolved / 已复现 | mergeDeep lets a JSON __proto__ key replace the result prototype | CORE-01 | | UTIL-DOWNLOAD-01 | resolved / 源码/产物事实 | Temporary download anchor remains if click throws | CORE-01 | | BASE-TYPE-05 | open / 源码/产物事实 | Public Utils declarations omit exports and misstate timer/descriptor signatures | CORE-07 | +| EVENT-NAME-01 | resolved / 已复现 | Emitter event names collide with Object.prototype | CORE-02 | +| EVENT-ONCE-01 | resolved / 已复现 | Nested dispatch snapshots invoke the same once registration twice | CORE-02 | diff --git a/refactor/risks.json b/refactor/risks.json index 38e68c939..6e504dbe3 100644 --- a/refactor/risks.json +++ b/refactor/risks.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "task": "BASE-07", "sourceCommit": "e01f39ff", - "updatedAt": "2026-09-10T15:48:43.324Z", + "updatedAt": "2026-09-10T16:03:52.413Z", "note": "Open means closure evidence is outstanding; source-observed and unverified are not reproduced runtime bugs. A source issue already mitigated in the workspace still requires candidate regression evidence. No accepted-with-scope item is implied by baseline task completion.", "items": [ { @@ -715,6 +715,52 @@ ], "compatibleResolution": "Coordinate compatible public overloads/exports separately; use accurate strict types in migrated source.", "closureCriteria": "Cover missing unescape/ArtPlayerError, def identity/property keys, optional sleep, timer void returns and ignored debounce context; retain legal old consumers in new/old compilers." + }, + { + "id": "EVENT-NAME-01", + "title": "Emitter event names collide with Object.prototype", + "confirmation": "reproduced", + "status": "resolved", + "owners": [ + "CORE-02" + ], + "evidence": [ + "refactor/changes/2026-09-11-CORE-02-typed-emitter.md", + "test/public-behavior.test.js", + "test/browser/emitter.spec.js" + ], + "compatibleResolution": "Own property lookup and data descriptors accept reserved event names while preserving registry prototype.", + "closureCriteria": "Published observation and candidate regression pass in Node, all three artifact formats and three browsers.", + "resolutionEvidence": [ + "refactor/changes/2026-09-11-CORE-02-typed-emitter.md", + "refactor/baselines/emitter-validation.json", + "test/public-behavior.test.js", + "test/browser/emitter.spec.js" + ], + "resolutionRationale": "Own property lookup and data descriptors accept reserved event names while preserving registry prototype." + }, + { + "id": "EVENT-ONCE-01", + "title": "Nested dispatch snapshots invoke the same once registration twice", + "confirmation": "reproduced", + "status": "resolved", + "owners": [ + "CORE-02" + ], + "evidence": [ + "refactor/changes/2026-09-11-CORE-02-typed-emitter.md", + "test/public-behavior.test.js", + "test/browser/emitter.spec.js" + ], + "compatibleResolution": "The wrapper records consumption before unsubscribe/invocation; ordinary dispatch snapshot semantics are retained.", + "closureCriteria": "Published observation and candidate regression pass in Node, all three artifact formats and three browsers.", + "resolutionEvidence": [ + "refactor/changes/2026-09-11-CORE-02-typed-emitter.md", + "refactor/baselines/emitter-validation.json", + "test/public-behavior.test.js", + "test/browser/emitter.spec.js" + ], + "resolutionRationale": "The wrapper records consumption before unsubscribe/invocation; ordinary dispatch snapshot semantics are retained." } ] } diff --git a/refactor/tasks.json b/refactor/tasks.json index 63125ad20..e69674df8 100644 --- a/refactor/tasks.json +++ b/refactor/tasks.json @@ -770,11 +770,14 @@ "CORE-01", "BASE-03" ], - "status": "todo", + "status": "done", "risk": "H", "deliverable": "带类型事件映射的原 Emitter 实现", "acceptance": "ctx、once/off、重入/异常和链式返回保持", - "evidence": [] + "evidence": [ + "changes/2026-09-11-CORE-02-typed-emitter.md", + "baselines/emitter-validation.json" + ] }, { "id": "CORE-03", diff --git a/test/browser/emitter.spec.js b/test/browser/emitter.spec.js new file mode 100644 index 000000000..8a98c3b41 --- /dev/null +++ b/test/browser/emitter.spec.js @@ -0,0 +1,28 @@ +import { expect, test } from './fixtures.js' + +for (const core of ['published', 'candidate']) { + test(`${core}: emitter event names and once across nested dispatch`, async ({ page }) => { + await page.goto(`/test/player.html?core=${core}&chapter=published`) + const result = await page.evaluate(() => { + const emitter = new window.Artplayer.Emitter() + const freshKeys = Object.keys(emitter) + let reservedCalls = 0 + let errorName + try { + emitter.on('__proto__', () => reservedCalls++).emit('__proto__').off('__proto__') + } + catch (error) { errorName = error.name } + let nested = false + let onceCalls = 0 + emitter.on('value', () => { + if (!nested) { + nested = true + emitter.emit('value') + } + }).once('value', () => onceCalls++) + emitter.emit('value') + return { freshKeys, reservedCalls, errorName, onceCalls } + }) + expect(result).toEqual({ freshKeys: [], reservedCalls: core === 'published' ? 0 : 1, errorName: core === 'published' ? 'TypeError' : undefined, onceCalls: core === 'published' ? 2 : 1 }) + }) +} diff --git a/test/contracts/emitter.js b/test/contracts/emitter.js index 5a08957c6..d42837e7a 100644 --- a/test/contracts/emitter.js +++ b/test/contracts/emitter.js @@ -1,6 +1,51 @@ import assert from 'node:assert/strict' export const emitterContracts = { + 'EVENT.lazy-registry': function (Emitter) { + const emitter = new Emitter() + assert.deepEqual(Object.keys(emitter), []) + emitter.emit('empty').off('empty') + assert.equal(Object.getOwnPropertyDescriptor(emitter, 'e').enumerable, true) + assert.deepEqual(Object.keys(emitter.e), []) + assert.equal(typeof emitter.e.hasOwnProperty, 'function') + }, + 'EVENT.symbol-number-channels': function (Emitter) { + const emitter = new Emitter() + const symbol = Symbol('channel') + const seen = [] + emitter.on(symbol, value => seen.push(value)).on(1, value => seen.push(value)) + emitter.emit(symbol, 'symbol').emit('1', 'numeric') + emitter.off(symbol).off(1).emit(symbol).emit('1') + assert.deepEqual(seen, ['symbol', 'numeric']) + }, + 'EVENT.context-removal': function (Emitter) { + const emitter = new Emitter() + const seen = [] + function fn() { + seen.push(this) + } + const a = {} + const b = {} + emitter.on('value', fn, a).once('value', fn, b) + const wrapper = emitter.e.value[1].fn + assert.equal(wrapper._, fn) + emitter.off('value', wrapper).emit('value') + assert.deepEqual(seen, [a]) + emitter.on('value', fn, b).off('value', fn).emit('value') + assert.deepEqual(seen, [a]) + }, + 'EVENT.once-throw-consumed': function (Emitter) { + const emitter = new Emitter() + const marker = new Error('once failed') + let calls = 0 + emitter.once('value', () => { + calls++ + throw marker + }) + assert.throws(() => emitter.emit('value'), error => error === marker) + emitter.emit('value') + assert.equal(calls, 1) + }, 'EVENT.chain-context-arguments': function (Emitter) { const emitter = new Emitter() const context = {} diff --git a/test/package-check.test.js b/test/package-check.test.js index 79ed66f59..1117c2cf7 100644 --- a/test/package-check.test.js +++ b/test/package-check.test.js @@ -5,6 +5,7 @@ import path from 'node:path' import { test } from 'node:test' import { checkFiles, publishedConsumer } from '../scripts/package-check.mjs' import { removeConsumer, runtimeConsumer } from '../scripts/package-consumer.mjs' +import { emitterContracts } from './contracts/emitter.js' test('Package checks reject missing files, missing wildcard exports and internal configuration', () => { const manifest = { name: 'fixture', main: './dist/main.js', module: './dist/main.mjs', types: './types/main.d.ts', legacy: './dist/legacy.js', exports: { '.': './dist/main.js', './lang/*': './dist/lang/*.js' } } @@ -19,7 +20,7 @@ test('Package checks reject missing files, missing wildcard exports and internal test('Actual isolated runtime rejects removed default exports and required files', async () => { const { dir } = await publishedConsumer() try { - assert.equal(runtimeConsumer(dir).checks.length, 23) + assert.equal(runtimeConsumer(dir).checks.length, 18 + Object.keys(emitterContracts).length) const esm = path.join(dir, 'node_modules/artplayer-plugin-chapter/dist/artplayer-plugin-chapter.mjs') const original = fs.readFileSync(esm) fs.writeFileSync(esm, 'export const removedDefault = true\n') diff --git a/test/public-behavior.test.js b/test/public-behavior.test.js index 7b230a7fc..5f9f2c89f 100644 --- a/test/public-behavior.test.js +++ b/test/public-behavior.test.js @@ -1,3 +1,4 @@ +import assert from 'node:assert/strict' import process from 'node:process' // eslint-disable-next-line test/no-import-node-test -- Run the same public contract against each actual implementation. import { test } from 'node:test' @@ -12,3 +13,37 @@ for (const { name, Artplayer } of targets) { for (const [id, verify] of Object.entries(emitterContracts)) test(`${id}: ${name}`, () => verify(Artplayer.Emitter)) } + +test('EVENT.prototype-event-names: candidate supports names that collide with Object.prototype', () => { + for (const name of ['__proto__', 'constructor', 'toString', 'hasOwnProperty']) { + assert.throws(() => new targets[0].Artplayer.Emitter().on(name, () => {}), error => error.name === 'TypeError') + for (const { Artplayer } of targets.slice(1)) { + const emitter = new Artplayer.Emitter() + let calls = 0 + const fn = () => calls++ + emitter.emit(name).off(name) + const prototype = Object.getPrototypeOf(emitter.e) + emitter.on(name, fn).once(name, fn) + emitter.emit(name).emit(name).off(name, fn).emit(name) + assert.equal(calls, 3) + assert.equal(Object.prototype.hasOwnProperty.call(emitter.e, name), false) + assert.equal(Object.getPrototypeOf(emitter.e), prototype) + } + } +}) + +test('EVENT.once-nested-snapshot: candidate consumes a once registration across nested dispatch snapshots', () => { + for (const [index, { Artplayer }] of targets.entries()) { + const emitter = new Artplayer.Emitter() + let nested = false + let calls = 0 + emitter.on('value', () => { + if (!nested) { + nested = true + emitter.emit('value') + } + }).once('value', () => calls++) + emitter.emit('value') + assert.equal(calls, index === 0 ? 2 : 1) + } +}) diff --git a/test/types/emitter-source.ts b/test/types/emitter-source.ts new file mode 100644 index 000000000..68721b933 --- /dev/null +++ b/test/types/emitter-source.ts @@ -0,0 +1,42 @@ +import type { Events } from 'artplayer' +import Emitter from '../../packages/artplayer/src/utils/emitter' + +const symbol = Symbol('message') +interface Messages { + ready: [] + value: [count: number, label?: string] + readonly: readonly [value: number] + [symbol]: [message: string] +} +class TypedEmitter extends Emitter { + count = 0 +} +const events = new TypedEmitter() +const context = { total: 0 } +const chain: TypedEmitter = events.on('value', function (count, label) { + this.total += count + label?.toUpperCase() +}, context).once('ready', () => {}).emit('value', 1).off('ready') +events.emit(symbol, 'message') +events.emit('readonly', 1) +const playerEvents = new Emitter>() +playerEvents.emit('setBar', 'loaded', 0.5) +playerEvents.emit('custom:event', { extra: true }) +// @ts-expect-error Known events retain their payload types with open custom names. +playerEvents.emit('setBar', 'invalid', 0.5) +// @ts-expect-error A declared map rejects unknown names. +events.emit('missing') +// @ts-expect-error Payload types are correlated with the event name. +events.emit('value', 'one') +// @ts-expect-error Required payloads cannot be omitted. +events.emit('value') +// @ts-expect-error Empty events reject extra values. +events.emit('ready', 1) +// @ts-expect-error Listener arguments must match the event. +events.on('value', (count: string) => count) +// @ts-expect-error Explicit receiver types must agree with the provided context. +events.on('ready', contextListener, { total: 'zero' }) +function contextListener(this: { total: number }) { + return this.total +} +void chain