-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.min.js
3 lines (3 loc) · 28.8 KB
/
index.min.js
1
2
3
const L=/mobile/i.test(window.navigator.userAgent);function b(e){const a=o=>o<10?"0"+o:""+o,l=Math.floor(e/3600),t=Math.floor((e-l*3600)/60),i=Math.floor(e-l*3600-t*60);return(l>0?[l,t,i]:[t,i]).map(a).join(":")}function S(e){let a=e.offsetLeft,l=e.offsetParent;const t=document.body.scrollLeft+document.documentElement.scrollLeft;if(!document.fullscreenElement&&!document.mozFullScreenElement&&!document.webkitFullscreenElement)for(;l!==null;)a+=l.offsetLeft,l=l.offsetParent;else for(;l!==null&&l!==e;)a+=l.offsetLeft,l=l.offsetParent;return a-t}function I(e,a){let l=e.offsetTop,t=e.offsetParent,i=0;for(;t!==null;)l+=t.offsetTop,t=t.offsetParent;return i=document.body.scrollTop+document.documentElement.scrollTop,a?l:l-i}const h={dragStart:L?"touchstart":"mousedown",dragMove:L?"touchmove":"mousemove",dragEnd:L?"touchend":"mouseup"};function P(e){function a(l){for(let t=l.length-1;t>=0;t--){const i=Math.floor(Math.random()*(t+1)),o=l[i];l[i]=l[t],l[t]=o}return l}return a([...Array(e)].map(function(l,t){return t}))}const W='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M22.667 4l7 6-7 6 7 6-7 6v-4h-3.653l-3.76-3.76 2.827-2.827 2.587 2.587h2v-8h-2l-12 12h-6v-4h4.347l12-12h3.653v-4zM2.667 8h6l3.76 3.76-2.827 2.827-2.587-2.587h-4.347v-4z"></path></svg>',C='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 17 32"><path d="M14.080 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048zM2.88 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048z"></path></svg>',_='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32"><path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528zM25.152 16q0 2.72-1.536 5.056t-4 3.36q-0.256 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.704 0.672-1.056 1.024-0.512 1.376-0.8 1.312-0.96 2.048-2.4t0.736-3.104-0.736-3.104-2.048-2.4q-0.352-0.288-1.376-0.8-0.672-0.352-0.672-1.056 0-0.448 0.32-0.8t0.8-0.352q0.224 0 0.48 0.096 2.496 1.056 4 3.36t1.536 5.056zM29.728 16q0 4.096-2.272 7.552t-6.048 5.056q-0.224 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.64 0.704-1.056 0.128-0.064 0.384-0.192t0.416-0.192q0.8-0.448 1.44-0.896 2.208-1.632 3.456-4.064t1.216-5.152-1.216-5.152-3.456-4.064q-0.64-0.448-1.44-0.896-0.128-0.096-0.416-0.192t-0.384-0.192q-0.704-0.416-0.704-1.056 0-0.448 0.32-0.8t0.832-0.352q0.224 0 0.448 0.096 3.776 1.632 6.048 5.056t2.272 7.552z"></path></svg>',F='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32"><path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528z"></path></svg>',$='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M25.468 6.947c-0.326-0.172-0.724-0.151-1.030 0.057l-6.438 4.38v-3.553c0-0.371-0.205-0.71-0.532-0.884-0.326-0.172-0.724-0.151-1.030 0.057l-12 8.164c-0.274 0.186-0.438 0.496-0.438 0.827s0.164 0.641 0.438 0.827l12 8.168c0.169 0.115 0.365 0.174 0.562 0.174 0.16 0 0.321-0.038 0.468-0.116 0.327-0.173 0.532-0.514 0.532-0.884v-3.556l6.438 4.382c0.169 0.115 0.365 0.174 0.562 0.174 0.16 0 0.321-0.038 0.468-0.116 0.327-0.173 0.532-0.514 0.532-0.884v-16.333c0-0.371-0.205-0.71-0.532-0.884z"></path></svg>',ee='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32"><path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8z"></path></svg>',Y='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 33 32"><path d="M9.333 9.333h13.333v4l5.333-5.333-5.333-5.333v4h-16v8h2.667v-5.333zM22.667 22.667h-13.333v-4l-5.333 5.333 5.333 5.333v-4h16v-8h-2.667v5.333zM17.333 20v-8h-1.333l-2.667 1.333v1.333h2v5.333h2z"></path></svg>',ae='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 22 32"><path d="M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z"></path></svg>',k='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 16 31"><path d="M15.552 15.168q0.448 0.32 0.448 0.832 0 0.448-0.448 0.768l-13.696 8.512q-0.768 0.512-1.312 0.192t-0.544-1.28v-16.448q0-0.96 0.544-1.28t1.312 0.192z"></path></svg>',te='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M22 16l-10.105-10.6-1.895 1.987 8.211 8.613-8.211 8.612 1.895 1.988 8.211-8.613z"></path></svg>',le='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M4 16c0-6.6 5.4-12 12-12s12 5.4 12 12c0 1.2-0.8 2-2 2s-2-0.8-2-2c0-4.4-3.6-8-8-8s-8 3.6-8 8 3.6 8 8 8c1.2 0 2 0.8 2 2s-0.8 2-2 2c-6.6 0-12-5.4-12-12z"></path></svg>',R='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z"></path></svg>',O='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 29 32"><path d="M9.333 9.333h13.333v4l5.333-5.333-5.333-5.333v4h-16v8h2.667v-5.333zM22.667 22.667h-13.333v-4l-5.333 5.333 5.333 5.333v-4h16v-8h-2.667v5.333z"></path></svg>',A='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 29 32"><path d="M2.667 7.027l1.707-1.693 22.293 22.293-1.693 1.707-4-4h-11.64v4l-5.333-5.333 5.333-5.333v4h8.973l-8.973-8.973v0.973h-2.667v-3.64l-4-4zM22.667 17.333h2.667v5.573l-2.667-2.667v-2.907zM22.667 6.667v-4l5.333 5.333-5.333 5.333v-4h-10.907l-2.667-2.667h13.573z"></path></svg>',ie='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M26.667 5.333h-21.333c-0 0-0.001 0-0.001 0-1.472 0-2.666 1.194-2.666 2.666 0 0 0 0.001 0 0.001v-0 16c0 0 0 0.001 0 0.001 0 1.472 1.194 2.666 2.666 2.666 0 0 0.001 0 0.001 0h21.333c0 0 0.001 0 0.001 0 1.472 0 2.666-1.194 2.666-2.666 0-0 0-0.001 0-0.001v0-16c0-0 0-0.001 0-0.001 0-1.472-1.194-2.666-2.666-2.666-0 0-0.001 0-0.001 0h0zM5.333 16h5.333v2.667h-5.333v-2.667zM18.667 24h-13.333v-2.667h13.333v2.667zM26.667 24h-5.333v-2.667h5.333v2.667zM26.667 18.667h-13.333v-2.667h13.333v2.667z"></path></svg>';function j(e){return Object.prototype.toString.call(e)!=="[object Array]"&&(e=[e]),e.map(a=>({...a,name:a.name||a.title||"Audio name",artist:a.artist||a.author||"Audio artist",cover:a.cover||a.pic,type:a.type||"normal"}))}const ne=e=>{const a={container:e.element||document.getElementsByClassName("aplayer")[0],mini:e.narrow||e.fixed||!1,fixed:!1,autoplay:!1,mutex:!0,lrcType:e.showlrc||e.lrc||0,preload:"auto",theme:"#b7daff",loop:"all",order:"list",volume:.7,listFolded:e.fixed,listMaxHeight:e.listmaxheight||"250px",audio:e.music||[],storageName:"aplayer-setting"};return e=Object.assign(a,e),e.audio=j(e.audio),e.audio.length<=1&&e.loop==="one"&&(e.loop="all"),e},w={};w.$escape=function(e){return oe(V(e))},w.$each=function(e,a){if(Array.isArray(e))for(var l=0,t=e.length;l<t;l++)a(e[l],l);else for(var i in e)a(e[i],i)};function V(e){return typeof e!="string"&&(e==null?e="":typeof e=="function"?e=V(e.call(e)):e=JSON.stringify(e)),e}function oe(e){return e.replace(/[<>&'"]/g,a=>`&${{"<":"lt",">":"gt","&":"amp","'":"apos",'"':"quot"}[a]};`)}function N(e){e=e||{};let a="",l=w.$each,t=e.audio,i=w.$escape,o=e.theme,r=e.index;return l(t,function(p,d){a+=' <li><span class="aplayer-list-cur" style="background-color: ',a+=i(p.theme||o),a+='"></span> <span class="aplayer-list-index">',a+=i(d+r),a+='</span><span class="aplayer-list-title">',a+=i(p.name),a+='</span><span class="aplayer-list-author">',a+=i(p.artist),a+="</span></li> "}),a}const y=w.$escape,re=[(e,a)=>{a('<div class="aplayer-body"><div class="aplayer-pic" style="')},(e,a)=>{a('</div></div><div class="aplayer-info"><div class="aplayer-music"><span class="aplayer-title">No audio</span> <span class="aplayer-author"></span></div><div class="aplayer-lrc"><div class="aplayer-lrc-contents" style="transform:translateY(0);-webkit-transform:translateY(0)"></div></div><div class="aplayer-controller"><div class="aplayer-bar-wrap"><div class="aplayer-bar"><div class="aplayer-loaded" style="width:0"></div><div class="aplayer-played" style="width:0;background: ')},(e,a)=>{a('</button></div></div><div class="aplayer-list'),e.listFolded&&a(" aplayer-list-hide"),a('" '),e.listMaxHeight&&(a(' style="max-height: '),a(y(e.listMaxHeight)),a('" ')),a("><ol "),e.listMaxHeight&&(a(' style="max-height: '),a(y(e.listMaxHeight)),a('" ')),a("> "),a(N({theme:e.theme,audio:e.audio,index:1})),a(" </ol></div> ")}],se=[(e,a)=>{a(' <div class="aplayer-list'),e.listFolded&&a(" aplayer-list-hide"),a('" '),e.listMaxHeight&&(a(' style="max-height: '),a(y(e.listMaxHeight)),a('" ')),a("><ol "),e.listMaxHeight&&(a(' style="max-height: '),a(y(e.listMaxHeight)),a('" ')),a("> "),a(N({theme:e.theme,audio:e.audio,index:1})),a(' </ol></div><div class="aplayer-body"><div class="aplayer-pic" style="')},(e,a)=>{a('</div></div><div class="aplayer-info" style="display:none"><div class="aplayer-music"><span class="aplayer-title">No audio</span> <span class="aplayer-author"></span></div><div class="aplayer-controller"><div class="aplayer-bar-wrap"><div class="aplayer-bar"><div class="aplayer-loaded" style="width:0"></div><div class="aplayer-played" style="width:0;background: ')},(e,a)=>{a('</button></div></div><div class="aplayer-lrc"><div class="aplayer-lrc-contents" style="transform:translateY(0);-webkit-transform:translateY(0)"></div></div> ')}];function de(e,a,l){let t="",i=function(o){return t+=o,t};return l[0](e,i),a&&(t+="background-image:url("",t+=y(a),t+="");"),t+="background-color: ",t+=y(e.theme),t+='"><div class="aplayer-button aplayer-play">',t+=k,l[1](e,i),t+=y(e.theme),t+='"><span class="aplayer-thumb" style="background: ',t+=y(e.theme),t+='"><span class="aplayer-loading-icon">',t+=le,t+='</span></span></div></div></div><div class="aplayer-time"><span class="aplayer-time-inner"><span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span> </span><span class="aplayer-icon aplayer-icon-back"> ',t+=$,t+=' </span><span class="aplayer-icon aplayer-icon-play"> ',t+=k,t+=' </span><span class="aplayer-icon aplayer-icon-forward"> ',t+=$,t+=' </span><div class="aplayer-volume-wrap"><button type="button" class="aplayer-icon aplayer-icon-volume-down"> ',t+=F,t+=' </button><div class="aplayer-volume-bar-wrap"><div class="aplayer-volume-bar"><div class="aplayer-volume" style="height:80%;background: ',t+=y(e.theme),t+='"></div></div></div></div><button type="button" class="aplayer-icon aplayer-icon-order"> ',e.order==="list"?t+=R:e.order==="random"&&(t+=W),t+=' </button> <button type="button" class="aplayer-icon aplayer-icon-loop"> ',e.loop==="one"?t+=Y:e.loop==="all"?t+=O:e.loop==="none"&&(t+=A),t+=' </button> <button type="button" class="aplayer-icon aplayer-icon-menu"> ',t+=ae,t+=' </button> <button type="button" class="aplayer-icon aplayer-icon-lrc"> ',t+=ie,t+=' </button></div></div></div><div class="aplayer-notice"></div><div class="aplayer-miniswitcher"><button class="aplayer-icon">',t+=te,l[2](e,i),t}function ce(e,a,l,t){let i="";a.audio.length&&(a.order==="random"?i=a.audio[l[0]].cover:i=a.audio[0].cover),e.innerHTML=de(a,i,t);const o=r=>e.querySelector(r);return{lrc:o(".aplayer-lrc-contents"),lrcWrap:o(".aplayer-lrc"),ptime:o(".aplayer-ptime"),info:o(".aplayer-info"),time:o(".aplayer-time"),barWrap:o(".aplayer-bar-wrap"),button:o(".aplayer-button"),body:o(".aplayer-body"),list:o(".aplayer-list"),listOl:o(".aplayer-list ol"),listCurs:e.querySelectorAll(".aplayer-list-cur"),played:o(".aplayer-played"),loaded:o(".aplayer-loaded"),thumb:o(".aplayer-thumb"),volume:o(".aplayer-volume"),volumeBar:o(".aplayer-volume-bar"),volumeButton:o(".aplayer-time button"),volumeBarWrap:o(".aplayer-volume-bar-wrap"),loop:o(".aplayer-icon-loop"),order:o(".aplayer-icon-order"),menu:o(".aplayer-icon-menu"),pic:o(".aplayer-pic"),title:o(".aplayer-title"),author:o(".aplayer-author"),dtime:o(".aplayer-dtime"),notice:o(".aplayer-notice"),miniSwitcher:o(".aplayer-miniswitcher"),skipBackButton:o(".aplayer-icon-back"),skipForwardButton:o(".aplayer-icon-forward"),skipPlayButton:o(".aplayer-icon-play"),lrcButton:o(".aplayer-icon-lrc")}}const pe=e=>{const a={...e};function l(i,o,r){o=Math.max(o,0),o=Math.min(o,1),a[i].style[r]=o*100+"%"}function t(i,o){return parseFloat(a[i].style[o])/100}return{get:t,set:l}};function X(e){e=e||{};let a="",l=w.$each,t=e.lyrics,i=w.$escape;return l(t,function(o,r){a+=" <p ",r===0&&(a+=' class="aplayer-lrc-current" '),a+=">",a+=i(o[1]),a+="</p> "}),a}const ue=e=>{const a=e.container,l=e.player,t=e.async;let i=[],o=0,r=[];function p(){l.events.trigger("lrcshow"),l.template.lrcWrap.classList.remove("aplayer-lrc-hide")}function d(){l.events.trigger("lrchide"),l.template.lrcWrap.classList.add("aplayer-lrc-hide")}function c(){l.template.lrcWrap.classList.contains("aplayer-lrc-hide")?p():d()}function g(u=l.audio.currentTime){if(o>r.length-1||u<r[o][0]||!r[o+1]||u>=r[o+1][0])for(let m=0;m<r.length;m++)u>=r[m][0]&&(!r[m+1]||u<r[m+1][0])&&(o=m,a.style.transform=`translateY(${-o*16}px)`,a.style.webkitTransform=`translateY(${-o*16}px)`,a.getElementsByClassName("aplayer-lrc-current")[0].classList.remove("aplayer-lrc-current"),a.getElementsByTagName("p")[m].classList.add("aplayer-lrc-current"))}function q(u){if(!i[u])if(!t)l.list.audios[u].lrc?i[u]=T(l.list.audios[u].lrc):i[u]=[["00:00","Not available"]];else{i[u]=[["00:00","Loading"]];const m=new XMLHttpRequest;m.onreadystatechange=()=>{u===l.list.index&&m.readyState===4&&(m.status>=200&&m.status<300||m.status===304?i[u]=T(m.responseText):(l.notice(`LRC file request fails: status ${m.status}`),i[u]=[["00:00","Not available"]]),a.innerHTML=X({lyrics:i[u]}),g(0),r=i[u])};const v=l.list.audios[u].lrc;m.open("get",v,!0),m.send(null)}a.innerHTML=X({lyrics:i[u]}),r=i[u]}function T(u){if(u){u=u.replace(/([^\]^\n])\[/g,(n,s)=>s+`
[`);const m=u.split(`
`);let v=[];const M=m.length;for(let n=0;n<M;n++){const s=m[n].match(/\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g),f=m[n].replace(/.*\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g,"").replace(/<(\d{2}):(\d{2})(\.(\d{2,3}))?>/g,"").replace(/^\s+|\s+$/g,"");if(s){const D=s.length;for(let z=0;z<D;z++){const x=/\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/.exec(s[z]),G=x[1]*60,K=parseInt(x[2]),Q=x[4]?parseInt(x[4])/((x[4]+"").length===2?100:1e3):0,Z=G+K+Q;v.push([Z,f])}}}return v=v.filter(n=>n[1]),v.sort((n,s)=>n[0]-s[0]),v}else return[]}function B(u){i.splice(u,1)}function E(){i=[],a.innerHTML=""}return{show:p,hide:d,toggle:c,update:g,switch:q,remove:B,clear:E}},me=e=>{he(e),ve(e),ge(e),fe(e),we(e),L||ye(e),be(e),Me(e),xe(e)};function he(e){e.template.pic.addEventListener("click",()=>{e.toggle()})}function ve(e){const a=t=>{let i=((t.clientX||t.changedTouches[0].clientX)-S(e.template.barWrap))/e.template.barWrap.clientWidth;i=Math.max(i,0),i=Math.min(i,1),e.bar.set("played",i,"width"),e.lrc&&e.lrc.update(i*e.duration),e.template.ptime.innerHTML=b(i*e.duration)},l=t=>{document.removeEventListener(h.dragEnd,l),document.removeEventListener(h.dragMove,a);let i=((t.clientX||t.changedTouches[0].clientX)-S(e.template.barWrap))/e.template.barWrap.clientWidth;i=Math.max(i,0),i=Math.min(i,1),e.bar.set("played",i,"width"),e.seek(e.bar.get("played","width")*e.duration),e.disableTimeupdate=!1};e.template.barWrap.addEventListener(h.dragStart,()=>{e.disableTimeupdate=!0,document.addEventListener(h.dragMove,a),document.addEventListener(h.dragEnd,l)})}function ye(e){e.template.volumeButton.addEventListener("click",()=>{e.audio.muted?(e.audio.muted=!1,e.switchVolumeIcon(),e.bar.set("volume",e.volume(),"height")):(e.audio.muted=!0,e.switchVolumeIcon(),e.bar.set("volume",0,"height"))});const a=t=>{let i=1-((t.clientY||t.changedTouches[0].clientY)-I(e.template.volumeBar,e.options.fixed))/e.template.volumeBar.clientHeight;i=Math.max(i,0),i=Math.min(i,1),e.volume(i)},l=t=>{e.template.volumeBarWrap.classList.remove("aplayer-volume-bar-wrap-active"),document.removeEventListener(h.dragEnd,l),document.removeEventListener(h.dragMove,a);let i=1-((t.clientY||t.changedTouches[0].clientY)-I(e.template.volumeBar,e.options.fixed))/e.template.volumeBar.clientHeight;i=Math.max(i,0),i=Math.min(i,1),e.volume(i)};e.template.volumeBarWrap.addEventListener(h.dragStart,()=>{e.template.volumeBarWrap.classList.add("aplayer-volume-bar-wrap-active"),document.addEventListener(h.dragMove,a),document.addEventListener(h.dragEnd,l)})}function ge(e){e.template.order.addEventListener("click",()=>{e.options.order==="list"?(e.options.order="random",e.template.order.innerHTML=W):e.options.order==="random"&&(e.options.order="list",e.template.order.innerHTML=R)})}function fe(e){e.template.loop.addEventListener("click",()=>{e.list.audios.length>1?e.options.loop==="one"?(e.options.loop="none",e.template.loop.innerHTML=A):e.options.loop==="none"?(e.options.loop="all",e.template.loop.innerHTML=O):e.options.loop==="all"&&(e.options.loop="one",e.template.loop.innerHTML=Y):e.options.loop==="one"||e.options.loop==="all"?(e.options.loop="none",e.template.loop.innerHTML=A):e.options.loop==="none"&&(e.options.loop="all",e.template.loop.innerHTML=O)})}function we(e){e.template.menu.addEventListener("click",()=>{e.list.toggle()})}function be(e){e.template.miniSwitcher.addEventListener("click",()=>{e.setMode(e.mode==="mini"?"normal":"mini")})}function Me(e){e.template.skipBackButton.addEventListener("click",()=>{e.skipBack()}),e.template.skipForwardButton.addEventListener("click",()=>{e.skipForward()}),e.template.skipPlayButton.addEventListener("click",()=>{e.toggle()})}function xe(e){e.template.lrcButton.addEventListener("click",()=>{e.template.lrcButton.classList.contains("aplayer-icon-lrc-inactivity")?(e.template.lrcButton.classList.remove("aplayer-icon-lrc-inactivity"),e.lrc&&e.lrc.show()):(e.template.lrcButton.classList.add("aplayer-icon-lrc-inactivity"),e.lrc&&e.lrc.hide())})}const Le=e=>{let a=0,l=0,t=!1,i=!1,o=setInterval(()=>{i&&(l=e.audio.currentTime,!t&&l===a&&!e.audio.paused&&(e.container.classList.add("aplayer-loading"),t=!0),t&&l>a&&!e.audio.paused&&(e.container.classList.remove("aplayer-loading"),t=!1),a=l)},100);return{enable(){i=!0},disable(){i=!1},destroy(){i=!1,o&&clearInterval(o)}}},Te=["destroy","listshow","listhide","listadd","listremove","listswitch","listclear","noticeshow","noticehide","lrcshow","lrchide"],J=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","mozaudioavailable","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"];function ke(e){if(Te.indexOf(e)!==-1)return"player";if(J.indexOf(e)!==-1)return"audio"}const He=()=>{const e={};return{on:function(a,l){ke(a)&&typeof l=="function"&&(e[a]||(e[a]=[]),e[a].push(l))},trigger:function(a,l){var t;(t=e[a])==null||t.forEach(i=>i(l))}}};function qe(e,a){e.events.trigger("listadd",{audios:a}),a=j(a);const l=!(e.list.audios.length>1),t=e.list.audios.length===0;e.template.listOl.innerHTML+=N({theme:e.options.theme,audio:a,index:e.list.audios.length+1}),e.list.audios=e.list.audios.concat(a),l&&e.list.audios.length>1&&e.container.classList.add("aplayer-withlist"),e.randomOrder=P(e.list.audios.length),e.template.listCurs=e.container.querySelectorAll(".aplayer-list-cur"),e.template.listCurs[e.list.audios.length-1].style.backgroundColor=a.theme||e.options.theme,t&&(e.options.order==="random"?e.list.switch(e.randomOrder[0]):e.list.switch(0))}function Be(e,a){if(e.events.trigger("listremove",{index:a}),e.list.audios[a])if(e.list.audios.length>1){const l=e.container.querySelectorAll(".aplayer-list li");l[a].remove(),e.list.audios.splice(a,1),e.lrc&&e.lrc.remove(a),a===e.list.index&&(e.list.audios[a]?e.list.switch(a):e.list.switch(a-1)),e.list.index>a&&e.list.index--;for(let t=a;t<l.length;t++)l[t].getElementsByClassName("aplayer-list-index")[0].textContent=t;e.list.audios.length===1&&e.container.classList.remove("aplayer-withlist"),e.template.listCurs=e.container.querySelectorAll(".aplayer-list-cur")}else U(e)}function U(e){e.events.trigger("listclear"),e.list.index=0,e.container.classList.remove("aplayer-withlist"),e.pause(),e.list.audios=[],e.lrc&&e.lrc.clear(),e.audio.src="",e.template.listOl.innerHTML="",e.template.pic.style.backgroundImage="",e.theme(e.options.theme,e.list.index,!1),e.template.title.innerHTML="No audio",e.template.author.innerHTML="",e.bar.set("loaded",0,"width"),e.template.dtime.innerHTML=b(0)}const Ee=e=>{let a=0,l=e.options.audio;e.template.list.addEventListener("click",p=>{let d;p.target.tagName.toUpperCase()==="LI"?d=p.target:d=p.target.parentElement;const c=parseInt(d.getElementsByClassName("aplayer-list-index")[0].innerHTML)-1;c!==a?(r(c),e.play()):e.toggle()});function t(){e.events.trigger("listshow"),e.template.list.classList.remove("aplayer-list-hide"),e.template.listOl.scrollTop=a*33}function i(){e.events.trigger("listhide"),e.template.list.classList.add("aplayer-list-hide")}function o(){e.template.list.classList.contains("aplayer-list-hide")?t():i()}function r(p){if(e.events.trigger("listswitch",{index:p}),typeof p<"u"&&l[p]){a=p;const d=l[a];e.template.pic.style.backgroundImage=d.cover?`url('${d.cover}')`:"",e.theme(l[a].theme||e.options.theme,a,!1),e.template.title.innerHTML=d.name,e.template.author.innerHTML=d.artist?" - "+d.artist:"";const c=e.container.getElementsByClassName("aplayer-list-light")[0];c&&c.classList.remove("aplayer-list-light");const g=e.container.querySelectorAll(".aplayer-list li")[a];g.classList.add("aplayer-list-light"),g.scrollIntoView({behavior:"smooth"}),e.setAudio(d),e.lrc&&e.lrc.switch(a),e.lrc&&e.lrc.update(0),e.duration!==1&&(e.template.dtime.innerHTML=b(e.duration))}}return{get index(){return a},set index(p){a=p},get audios(){return l},set audios(p){l=p},show:t,hide:i,toggle:o,switch:r}},H=[],ze=()=>{const e={tplRenderers:re,hlsHandler:()=>{},events:He(),mode:"normal",afterInitHooks:[],get duration(){return isNaN(e.audio.duration)?0:e.audio.duration}};return e},Oe=()=>{const e=ze();let a,l=!0,t=null,i=Le(e),o,r,p,d,c;function g(){if(r.lrcType===2||r.lrcType===!0){const n=p.getElementsByClassName("aplayer-lrc-content");for(let s=0;s<n.length;s++)r.audio[s]&&(r.audio[s].lrc=n[s].innerHTML)}r.lrcType&&(e.lrc=ue({container:d.lrc,async:r.lrcType===3,player:e}))}function q(){p.classList.add("aplayer"),r.lrcType&&!r.fixed&&p.classList.add("aplayer-withlrc"),r.audio.length>1&&p.classList.add("aplayer-withlist"),L&&p.classList.add("aplayer-mobile"),p.offsetWidth<=300&&p.classList.add("aplayer-arrow"),r.fixed&&(p.classList.add("aplayer-fixed"),d.body.style.width=d.body.offsetWidth-18+"px"),r.mini&&(e.setMode("mini"),d.info.style.display="block"),d.info.offsetWidth<200&&d.time.classList.add("aplayer-time-narrow")}function T(){const n=r.storageName,s=JSON.parse(localStorage.getItem(n))||{};return s.volume||(s.volume=r.volume),{get(){return s.volume},set(f){s.volume=f,localStorage.setItem(n,JSON.stringify(s))}}}function B(){e.audio=document.createElement("audio"),e.audio.preload=r.preload,J.forEach(n=>{e.audio.addEventListener(n,s=>{e.events.trigger(n,s)})}),e.volume(a.get(),!0)}function E(){e.on("play",()=>{l&&u()}),e.on("pause",()=>{l||m()}),e.on("timeupdate",()=>{if(!e.disableTimeupdate){e.bar.set("played",e.audio.currentTime/e.duration,"width"),e.lrc&&e.lrc.update();const s=b(e.audio.currentTime);d.ptime.innerHTML!==s&&(d.ptime.innerHTML=s)}}),e.on("durationchange",()=>{e.duration!==1&&(d.dtime.innerHTML=b(e.duration))}),e.on("progress",()=>{const s=e.audio.buffered.length?e.audio.buffered.end(e.audio.buffered.length-1)/e.duration:0;e.bar.set("loaded",s,"width")});let n;e.on("error",()=>{c.audios.length>1?(e.notice("An audio error has occurred, player will skip forward in 2 seconds."),n=setTimeout(()=>{e.skipForward(),l||e.play()},2e3)):c.audios.length===1&&e.notice("An audio error has occurred.")}),e.events.on("listswitch",()=>{n&&clearTimeout(n)}),e.on("ended",()=>{r.loop==="none"?r.order==="list"?c.index<c.audios.length-1?(c.switch((c.index+1)%c.audios.length),e.play()):(c.switch((c.index+1)%c.audios.length),e.pause()):r.order==="random"&&(e.randomOrder.indexOf(c.index)<e.randomOrder.length-1?(c.switch(M()),e.play()):(c.switch(M()),e.pause())):r.loop==="one"?(c.switch(c.index),e.play()):r.loop==="all"&&(e.skipForward(),e.play())})}function u(){l&&(l=!1,d.button.classList.remove("aplayer-play"),d.button.classList.add("aplayer-pause"),d.button.innerHTML="",setTimeout(()=>{d.button.innerHTML=C},100),d.skipPlayButton.innerHTML=C),i.enable(),r.mutex&&H.filter(n=>n!==e).forEach(n=>{n.pause()})}function m(){l||(l=!0,d.button.classList.remove("aplayer-pause"),d.button.classList.add("aplayer-play"),d.button.innerHTML="",setTimeout(()=>{d.button.innerHTML=k},100),d.skipPlayButton.innerHTML=k),p.classList.remove("aplayer-loading"),i.disable()}function v(){if(c.audios.length>1){if(r.order==="list")return c.index-1<0?c.audios.length-1:c.index-1;if(r.order==="random"){const n=e.randomOrder.indexOf(c.index);return n===0?e.randomOrder[e.randomOrder.length-1]:e.randomOrder[n-1]}}else return 0}function M(){if(c.audios.length>1){if(r.order==="list")return(c.index+1)%c.audios.length;if(r.order==="random"){const n=e.randomOrder.indexOf(c.index);return n===e.randomOrder.length-1?e.randomOrder[0]:e.randomOrder[n+1]}}else return 0}return e.init=n=>(r=ne(n),e.options=r,p=r.container,e.container=p,d=ce(p,r,e.randomOrder,e.tplRenderers),e.template=d,e.controller=me(e),q(),e.randomOrder=P(r.audio.length),a=T(),g(),e.bar=pe(d),c=Ee(e),e.list=c,B(),E(),r.order==="random"?c.switch(e.randomOrder[0]):c.switch(0),r.autoplay&&e.play(),H.push(e),e.afterInitHooks.forEach(s=>{s(e)}),e),e.setAudio=n=>{t&&(t.destroy(),t=null);let s=n.type;r.customAudioType&&r.customAudioType[s]?Object.prototype.toString.call(r.customAudioType[s])==="[object Function]"?r.customAudioType[s](e.audio,n,e):console.error(`Illegal customType: ${s}`):((!s||s==="auto")&&(/m3u8(#|\?|$)/i.exec(n.url)?s="hls":s="normal"),s==="hls"?t=e.hlsHandler(n):s==="normal"&&(e.audio.src=n.url)),e.seek(0),l||e.audio.play()},e.destroy=()=>{H.splice(H.indexOf(e),1),e.pause(),p.innerHTML="",e.audio.src="",i.destroy(),e.events.trigger("destroy")},e.setMode=(n="normal")=>{e.mode=n,n==="mini"?p.classList.add("aplayer-narrow"):n==="normal"&&p.classList.remove("aplayer-narrow")},e.notice=(n,s=2e3,f=.8)=>{d.notice.innerHTML=n,d.notice.style.opacity=f,o&&clearTimeout(o),e.events.trigger("noticeshow",{text:n}),s&&(o=setTimeout(()=>{d.notice.style.opacity=0,e.events.trigger("noticehide")},s))},e.theme=(n=c.audios[c.index].theme||r.theme,s=c.index,f=!0)=>{f&&c.audios[s]&&(c.audios[s].theme=n),d.listCurs[s]&&(d.listCurs[s].style.backgroundColor=n),s===c.index&&(d.pic.style.backgroundColor=n,d.played.style.background=n,d.thumb.style.background=n,d.volume.style.background=n)},e.seek=n=>{n=Math.max(n,0),n=Math.min(n,e.duration),e.audio.currentTime=n,e.bar.set("played",n/e.duration,"width"),d.ptime.innerHTML=b(n)},e.play=()=>{u();const n=e.audio.play();n&&n.catch(s=>{console.warn(s),s.name==="NotAllowedError"&&m()})},e.pause=()=>{m(),e.audio.pause()},e.switchVolumeIcon=()=>{e.volume()>=.95?d.volumeButton.innerHTML=_:e.volume()>0?d.volumeButton.innerHTML=F:d.volumeButton.innerHTML=ee},e.volume=(n,s)=>(n=parseFloat(n),isNaN(n)||(n=Math.max(n,0),n=Math.min(n,1),e.bar.set("volume",n,"height"),s||a.set(n),e.audio.volume=n,e.audio.muted&&(e.audio.muted=!1),e.switchVolumeIcon()),e.audio.muted?0:e.audio.volume),e.on=(n,s)=>{e.events.on(n,s)},e.toggle=()=>{d.button.classList.contains("aplayer-play")?e.play():d.button.classList.contains("aplayer-pause")&&e.pause()},e.skipBack=()=>{c.switch(v())},e.skipForward=()=>{c.switch(M())},e.use=n=>(n(e),e),e};function Ae(e){e.tplRenderers=se;const a=e.init;e.init=l=>(l.fixed=!0,a(l))}function Ne(e){e.afterInitHooks.push(()=>{e.list.add=a=>{qe(e,a)}})}function Se(e){e.afterInitHooks.push(()=>{e.list.remove=a=>{Be(e,a)}})}function Ie(e){e.afterInitHooks.push(()=>{e.list.clear=()=>{U(e)}})}function Pe(e){e.hlsHandler=a=>{if(Hls.isSupported()){const l=new Hls;return l.loadSource(a.url),l.attachMedia(e.audio),l}else e.audio.canPlayType("application/x-mpegURL")||e.audio.canPlayType("application/vnd.apple.mpegURL")?e.audio.src=a.url:e.notice("Error: HLS is not supported.")}}export{Ae as APlayerFixedModePlugin,Pe as APlayerHlsPlugin,Ne as addMusicPlugin,Ie as clearMusicPlugin,Oe as default,Se as removeMusicPlugin};