vue-pure-admin/static/js/index-DUCn17Sh.js

74 lines
36 KiB
JavaScript

import{k as L,e as k,g as y,d as Q,a as R,m as Z,y as tt,b as j,w as N,z as P,A as $,t as G,$ as X,f as B,u as z,j as F,h as q,a0 as Y}from"./index-FkXh20BC.js";function C(u,t,e,i){return new(e||(e=Promise))((function(s,n){function r(l){try{c(i.next(l))}catch(h){n(h)}}function o(l){try{c(i.throw(l))}catch(h){n(h)}}function c(l){var h;l.done?s(l.value):(h=l.value,h instanceof e?h:new e((function(p){p(h)}))).then(r,o)}c((i=i.apply(u,t||[])).next())}))}class O{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),i==null?void 0:i.once){const s=(...n)=>{this.un(t,s),e(...n)};return this.listeners[t].add(s),()=>this.un(t,s)}return this.listeners[t].add(e),()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((i=>i(...e)))}}const I={decode:function(u,t){return C(this,void 0,void 0,(function*(){const e=new AudioContext({sampleRate:t});try{return yield e.decodeAudioData(u)}finally{e.close()}}))},createBuffer:function(u,t){if(!u||u.length===0)throw new Error("channelData must be a non-empty array");if(t<=0)throw new Error("duration must be greater than 0");if(typeof u[0]=="number"&&(u=[u]),!u[0]||u[0].length===0)throw new Error("channelData must contain non-empty channel arrays");return(function(e){const i=e[0];if(i.some((s=>s>1||s<-1))){const s=i.length;let n=0;for(let r=0;r<s;r++){const o=Math.abs(i[r]);o>n&&(n=o)}for(const r of e)for(let o=0;o<s;o++)r[o]/=n}})(u),{duration:t,length:u[0].length,sampleRate:u[0].length/t,numberOfChannels:u.length,getChannelData:e=>u==null?void 0:u[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function K(u,t){const e=t.xmlns?document.createElementNS(t.xmlns,u):document.createElement(u);for(const[i,s]of Object.entries(t))if(i==="children"&&s)for(const[n,r]of Object.entries(s))r instanceof Node?e.appendChild(r):typeof r=="string"?e.appendChild(document.createTextNode(r)):e.appendChild(K(n,r));else i==="style"?Object.assign(e.style,s):i==="textContent"?e.textContent=s:e.setAttribute(i,s.toString());return e}function J(u,t,e){const i=K(u,t||{});return e==null||e.appendChild(i),i}var et=Object.freeze({__proto__:null,createElement:J,default:J});const it={fetchBlob:function(u,t,e){return C(this,void 0,void 0,(function*(){const i=yield fetch(u,e);if(i.status>=400)throw new Error(`Failed to fetch ${u}: ${i.status} (${i.statusText})`);return(function(s,n){C(this,void 0,void 0,(function*(){if(!s.body||!s.headers)return;const r=s.body.getReader(),o=Number(s.headers.get("Content-Length"))||0;let c=0,l=0;const h=a=>C(this,void 0,void 0,(function*(){c+=(a==null?void 0:a.length)||0;const d=Math.round(c/o*100);n(d)})),p=()=>C(this,void 0,void 0,(function*(){if(l++>1e5)return void console.error("Fetcher: Maximum iterations reached, stopping read loop");let a;try{a=yield r.read()}catch(d){return}a.done||(h(a.value),yield p())}));p()}))})(i.clone(),t),i.blob()}))}};class st extends O{constructor(t){super(),this.isExternalMedia=!1,t.media?(this.media=t.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),t.mediaControls&&(this.media.controls=!0),t.autoplay&&(this.media.autoplay=!0),t.playbackRate!=null&&this.onMediaEvent("canplay",(()=>{t.playbackRate!=null&&(this.media.playbackRate=t.playbackRate)}),{once:!0})}onMediaEvent(t,e,i){return this.media.addEventListener(t,e,i),()=>this.media.removeEventListener(t,e,i)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const t=this.getSrc();t.startsWith("blob:")&&URL.revokeObjectURL(t)}canPlayType(t){return this.media.canPlayType(t)!==""}setSrc(t,e){const i=this.getSrc();if(t&&i===t)return;this.revokeSrc();const s=e instanceof Blob&&(this.canPlayType(e.type)||!t)?URL.createObjectURL(e):t;if(i&&this.media.removeAttribute("src"),s||t)try{this.media.src=s}catch(n){this.media.src=t}}destroy(){this.isExternalMedia||(this.media.pause(),this.revokeSrc(),this.media.removeAttribute("src"),this.media.load(),this.media.remove())}setMediaElement(t){this.media=t}play(){return C(this,void 0,void 0,(function*(){try{return yield this.media.play()}catch(t){if(t instanceof DOMException&&t.name==="AbortError")return;throw t}}))}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=Math.max(0,Math.min(t,this.getDuration()))}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(t){this.media.volume=t}getMuted(){return this.media.muted}setMuted(t){this.media.muted=t}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(t,e){e!=null&&(this.media.preservesPitch=e),this.media.playbackRate=t}getMediaElement(){return this.media}setSinkId(t){return this.media.setSinkId(t)}}class W extends O{constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.unsubscribeOnScroll=[],this.dragUnsubscribe=null,this.subscriptions=[],this.options=t;const i=this.parentFromOptionsContainer(t.container);this.parent=i;const[s,n]=this.initHtml();i.appendChild(s),this.container=s,this.scrollContainer=n.querySelector(".scroll"),this.wrapper=n.querySelector(".wrapper"),this.canvasWrapper=n.querySelector(".canvases"),this.progressWrapper=n.querySelector(".progress"),this.cursor=n.querySelector(".cursor"),e&&n.appendChild(e),this.initEvents()}parentFromOptionsContainer(t){let e;if(typeof t=="string"?e=document.querySelector(t):t instanceof HTMLElement&&(e=t),!e)throw new Error("Container not found");return e}initEvents(){const t=e=>{const i=this.wrapper.getBoundingClientRect(),s=e.clientX-i.left,n=e.clientY-i.top;return[s/i.width,n/i.height]};if(this.wrapper.addEventListener("click",(e=>{const[i,s]=t(e);this.emit("click",i,s)})),this.wrapper.addEventListener("dblclick",(e=>{const[i,s]=t(e);this.emit("dblclick",i,s)})),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",(()=>{const{scrollLeft:e,scrollWidth:i,clientWidth:s}=this.scrollContainer,n=e/i,r=(e+s)/i;this.emit("scroll",n,r,e,e+s)})),typeof ResizeObserver=="function"){const e=this.createDelay(100);this.resizeObserver=new ResizeObserver((()=>{e().then((()=>this.onContainerResize())).catch((()=>{}))})),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=t,this.reRender())}initDrag(){this.dragUnsubscribe||(this.dragUnsubscribe=(function(t,e,i,s,n=3,r=0,o=100){if(!t)return()=>{};const c=matchMedia("(pointer: coarse)").matches;let l=()=>{};const h=p=>{if(p.button!==r)return;p.preventDefault(),p.stopPropagation();let a=p.clientX,d=p.clientY,m=!1;const S=Date.now(),f=v=>{if(v.preventDefault(),v.stopPropagation(),c&&Date.now()-S<o)return;const E=v.clientX,M=v.clientY,D=E-a,T=M-d;if(m||Math.abs(D)>n||Math.abs(T)>n){const _=t.getBoundingClientRect(),{left:H,top:U}=_;m||(i==null||i(a-H,d-U),m=!0),e(D,T,E-H,M-U),a=E,d=M}},g=v=>{if(m){const E=v.clientX,M=v.clientY,D=t.getBoundingClientRect(),{left:T,top:_}=D;s==null||s(E-T,M-_)}l()},b=v=>{v.relatedTarget&&v.relatedTarget!==document.documentElement||g(v)},x=v=>{m&&(v.stopPropagation(),v.preventDefault())},w=v=>{m&&v.preventDefault()};document.addEventListener("pointermove",f),document.addEventListener("pointerup",g),document.addEventListener("pointerout",b),document.addEventListener("pointercancel",b),document.addEventListener("touchmove",w,{passive:!1}),document.addEventListener("click",x,{capture:!0}),l=()=>{document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",g),document.removeEventListener("pointerout",b),document.removeEventListener("pointercancel",b),document.removeEventListener("touchmove",w),setTimeout((()=>{document.removeEventListener("click",x,{capture:!0})}),10)}};return t.addEventListener("pointerdown",h),()=>{l(),t.removeEventListener("pointerdown",h)}})(this.wrapper,((t,e,i)=>{this.emit("drag",Math.max(0,Math.min(1,i/this.wrapper.getBoundingClientRect().width)))}),(t=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))}),(t=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))})),this.subscriptions.push(this.dragUnsubscribe))}getHeight(t,e){var i;const s=((i=this.audioData)===null||i===void 0?void 0:i.numberOfChannels)||1;if(t==null)return 128;if(!isNaN(Number(t)))return Number(t);if(t==="auto"){const n=this.parent.clientHeight||128;return e!=null&&e.every((r=>!r.overlay))?n/s:n}return 128}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"}),i=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return e.innerHTML=`
<style${i?` nonce="${i}"`:""}>
:host {
user-select: none;
min-width: 1px;
}
:host audio {
display: block;
width: 100%;
}
:host .scroll {
overflow-x: auto;
overflow-y: hidden;
width: 100%;
position: relative;
}
:host .noScrollbar {
scrollbar-color: transparent;
scrollbar-width: none;
}
:host .noScrollbar::-webkit-scrollbar {
display: none;
-webkit-appearance: none;
}
:host .wrapper {
position: relative;
overflow: visible;
z-index: 2;
}
:host .canvases {
min-height: ${this.getHeight(this.options.height,this.options.splitChannels)}px;
}
:host .canvases > div {
position: relative;
}
:host canvas {
display: block;
position: absolute;
top: 0;
image-rendering: pixelated;
}
:host .progress {
pointer-events: none;
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 0;
height: 100%;
overflow: hidden;
}
:host .progress > div {
position: relative;
}
:host .cursor {
pointer-events: none;
position: absolute;
z-index: 5;
top: 0;
left: 0;
height: 100%;
border-radius: 2px;
}
</style>
<div class="scroll" part="scroll">
<div class="wrapper" part="wrapper">
<div class="canvases" part="canvases"></div>
<div class="progress" part="progress"></div>
<div class="cursor" part="cursor"></div>
</div>
</div>
`,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:e}=this.scrollContainer,i=e*t;this.setScroll(i)}destroy(){var t;this.subscriptions.forEach((e=>e())),this.container.remove(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),(t=this.unsubscribeOnScroll)===null||t===void 0||t.forEach((e=>e())),this.unsubscribeOnScroll=[]}createDelay(t=10){let e,i;const s=()=>{e&&(clearTimeout(e),e=void 0),i&&(i(),i=void 0)};return this.timeouts.push(s),()=>new Promise(((n,r)=>{s(),i=r,e=setTimeout((()=>{e=void 0,i=void 0,n()}),t)}))}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length===0)return"#999";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),s=e.height*(window.devicePixelRatio||1),n=i.createLinearGradient(0,0,0,s),r=1/(t.length-1);return t.forEach(((o,c)=>{const l=c*r;n.addColorStop(l,o)})),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,s){const n=t[0],r=t[1]||t[0],o=n.length,{width:c,height:l}=i.canvas,h=l/2,p=this.getPixelRatio(),a=e.barWidth?e.barWidth*p:1,d=e.barGap?e.barGap*p:e.barWidth?a/2:0,m=e.barRadius||0,S=c/(a+d)/o,f=m&&"roundRect"in i?"roundRect":"rect";i.beginPath();let g=0,b=0,x=0;for(let w=0;w<=o;w++){const v=Math.round(w*S);if(v>g){const D=Math.round(b*h*s),T=D+Math.round(x*h*s)||1;let _=h-D;e.barAlign==="top"?_=0:e.barAlign==="bottom"&&(_=l-T),i[f](g*(a+d),_,a,T,m),g=v,b=0,x=0}const E=Math.abs(n[w]||0),M=Math.abs(r[w]||0);E>b&&(b=E),M>x&&(x=M)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,s){const n=r=>{const o=t[r]||t[0],c=o.length,{height:l}=i.canvas,h=l/2,p=i.canvas.width/c;i.moveTo(0,h);let a=0,d=0;for(let m=0;m<=c;m++){const S=Math.round(m*p);if(S>a){const g=h+(Math.round(d*h*s)||1)*(r===0?-1:1);i.lineTo(a,g),a=S,d=0}const f=Math.abs(o[m]||0);f>d&&(d=f)}i.lineTo(a,h)};i.beginPath(),n(0),n(1),i.fill(),i.closePath()}renderWaveform(t,e,i){if(i.fillStyle=this.convertColorValues(e.waveColor),e.renderFunction)return void e.renderFunction(t,i);let s=e.barHeight||1;if(e.normalize){const n=Array.from(t[0]).reduce(((r,o)=>Math.max(r,Math.abs(o))),0);s=n?s/n:s}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,s):this.renderLineWaveform(t,e,i,s)}renderSingleCanvas(t,e,i,s,n,r,o){const c=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(i*c),l.height=Math.round(s*c),l.style.width=`${i}px`,l.style.height=`${s}px`,l.style.left=`${Math.round(n)}px`,r.appendChild(l);const h=l.getContext("2d");if(this.renderWaveform(t,e,h),l.width>0&&l.height>0){const p=l.cloneNode(),a=p.getContext("2d");a.drawImage(l,0,0),a.globalCompositeOperation="source-in",a.fillStyle=this.convertColorValues(e.progressColor),a.fillRect(0,0,l.width,l.height),o.appendChild(p)}}renderMultiCanvas(t,e,i,s,n,r){const o=this.getPixelRatio(),{clientWidth:c}=this.scrollContainer,l=i/o;let h=Math.min(W.MAX_CANVAS_WIDTH,c,l),p={};if(e.barWidth||e.barGap){const f=e.barWidth||.5,g=f+(e.barGap||f/2);h%g!=0&&(h=Math.floor(h/g)*g)}if(h===0)return;const a=f=>{if(f<0||f>=d||p[f])return;p[f]=!0;const g=f*h;let b=Math.min(l-g,h);if(e.barWidth||e.barGap){const w=e.barWidth||.5,v=w+(e.barGap||w/2);b=Math.floor(b/v)*v}if(b<=0)return;const x=t.map((w=>{const v=Math.floor(g/l*w.length),E=Math.floor((g+b)/l*w.length);return w.slice(v,E)}));this.renderSingleCanvas(x,e,b,s,g,n,r)},d=Math.ceil(l/h);if(!this.isScrollable){for(let f=0;f<d;f++)a(f);return}const m=this.scrollContainer.scrollLeft/l,S=Math.floor(m*d);if(a(S-1),a(S),a(S+1),d>1){const f=this.on("scroll",(()=>{const{scrollLeft:g}=this.scrollContainer,b=Math.floor(g/l*d);Object.keys(p).length>W.MAX_NODES&&(n.innerHTML="",r.innerHTML="",p={}),a(b-1),a(b),a(b+1)}));this.unsubscribeOnScroll.push(f)}}renderChannel(t,e,i,s){var{overlay:n}=e,r=(function(h,p){var a={};for(var d in h)Object.prototype.hasOwnProperty.call(h,d)&&p.indexOf(d)<0&&(a[d]=h[d]);if(h!=null&&typeof Object.getOwnPropertySymbols=="function"){var m=0;for(d=Object.getOwnPropertySymbols(h);m<d.length;m++)p.indexOf(d[m])<0&&Object.prototype.propertyIsEnumerable.call(h,d[m])&&(a[d[m]]=h[d[m]])}return a})(e,["overlay"]);const o=document.createElement("div"),c=this.getHeight(r.height,r.splitChannels);o.style.height=`${c}px`,n&&s>0&&(o.style.marginTop=`-${c}px`),this.canvasWrapper.style.minHeight=`${c}px`,this.canvasWrapper.appendChild(o);const l=o.cloneNode();this.progressWrapper.appendChild(l),this.renderMultiCanvas(t,r,i,c,o,l)}render(t){return C(this,void 0,void 0,(function*(){var e;this.timeouts.forEach((c=>c())),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);const i=this.getPixelRatio(),s=this.scrollContainer.clientWidth,n=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=n>s;const r=this.options.fillParent&&!this.isScrollable,o=(r?s:n)*i;if(this.wrapper.style.width=r?"100%":`${n}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let c=0;c<t.numberOfChannels;c++){const l=Object.assign(Object.assign({},this.options),(e=this.options.splitChannels)===null||e===void 0?void 0:e[c]);this.renderChannel([t.getChannelData(c)],l,o,c)}else{const c=[t.getChannelData(0)];t.numberOfChannels>1&&c.push(t.getChannelData(1)),this.renderChannel(c,this.options,o,0)}Promise.resolve().then((()=>this.emit("rendered")))}))}reRender(){if(this.unsubscribeOnScroll.forEach((i=>i())),this.unsubscribeOnScroll=[],!this.audioData)return;const{scrollWidth:t}=this.scrollContainer,{right:e}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&t!==this.scrollContainer.scrollWidth){const{right:i}=this.progressWrapper.getBoundingClientRect();let s=i-e;s*=2,s=s<0?Math.floor(s):Math.ceil(s),s/=2,this.scrollContainer.scrollLeft+=s}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:s,clientWidth:n}=this.scrollContainer,r=t*s,o=i,c=i+n,l=n/2;if(this.isDragging)r+30>c?this.scrollContainer.scrollLeft+=30:r-30<o&&(this.scrollContainer.scrollLeft-=30);else{(r<o||r>c)&&(this.scrollContainer.scrollLeft=r-(this.options.autoCenter?l:0));const h=r-i-l;e&&this.options.autoCenter&&h>0&&(this.scrollContainer.scrollLeft+=Math.min(h,10))}{const h=this.scrollContainer.scrollLeft,p=h/s,a=(h+n)/s;this.emit("scroll",p,a,h,h+n)}}renderProgress(t,e){if(isNaN(t))return;const i=100*t;this.canvasWrapper.style.clipPath=`polygon(${i}% 0%, 100% 0%, 100% 100%, ${i}% 100%)`,this.progressWrapper.style.width=`${i}%`,this.cursor.style.left=`${i}%`,this.cursor.style.transform=this.options.cursorWidth?`translateX(-${t*this.options.cursorWidth}px)`:"",this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return C(this,void 0,void 0,(function*(){const s=this.canvasWrapper.querySelectorAll("canvas");if(!s.length)throw new Error("No waveform data");if(i==="dataURL"){const n=Array.from(s).map((r=>r.toDataURL(t,e)));return Promise.resolve(n)}return Promise.all(Array.from(s).map((n=>new Promise(((r,o)=>{n.toBlob((c=>{c?r(c):o(new Error("Could not export image"))}),t,e)})))))}))}}W.MAX_CANVAS_WIDTH=8e3,W.MAX_NODES=10;class nt extends O{constructor(){super(...arguments),this.animationFrameId=null,this.isRunning=!1}start(){if(this.isRunning)return;this.isRunning=!0;const t=()=>{this.isRunning&&(this.emit("tick"),this.animationFrameId=requestAnimationFrame(t))};t()}stop(){this.isRunning=!1,this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}destroy(){this.stop()}}class V extends O{constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return C(this,void 0,void 0,(function*(){}))}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then((e=>{if(e.status>=400)throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);return e.arrayBuffer()})).then((e=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(e))).then((e=>{this.currentSrc===t&&(this.buffer=e,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())}))}_play(){if(!this.paused)return;this.paused=!1,this.bufferNode&&(this.bufferNode.onended=null,this.bufferNode.disconnect()),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let t=this.playedDuration*this._playbackRate;(t>=this.duration||t<0)&&(t=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,t),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return C(this,void 0,void 0,(function*(){this.paused&&(this._play(),this.emit("play"))}))}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){const e=t-this.currentTime,i=this.bufferNode;i==null||i.stop(this.audioContext.currentTime+e),i==null||i.addEventListener("ended",(()=>{i===this.bufferNode&&(this.bufferNode=null,this.pause())}),{once:!0})}setSinkId(t){return C(this,void 0,void 0,(function*(){return this.audioContext.setSinkId(t)}))}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const e=!this.paused;e&&this._pause(),this.playedDuration=t/this._playbackRate,e&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,e;return(t=this._duration)!==null&&t!==void 0?t:((e=this.buffer)===null||e===void 0?void 0:e.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const e=this.buffer.numberOfChannels;for(let i=0;i<e;i++)t.push(this.buffer.getChannelData(i));return t}removeAttribute(t){switch(t){case"src":this.src="";break;case"playbackRate":this.playbackRate=0;break;case"currentTime":this.currentTime=0;break;case"duration":this.duration=0;break;case"volume":this.volume=0;break;case"muted":this.muted=!1}}}const rt={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class A extends st{static create(t){return new A(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new V:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},rt,t),this.timer=new nt;const i=e?void 0:this.getMediaElement();this.renderer=new W(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const s=this.options.url||this.getSrc()||"";Promise.resolve().then((()=>{this.emit("init");const{peaks:n,duration:r}=this.options;(s||n&&r)&&this.load(s,n,r).catch((o=>{console.error("WaveSurfer initial load error:",o)}))}))}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",(()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t),this.stopAtPosition!=null&&this.isPlaying()&&t>=this.stopAtPosition&&this.pause()}})))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",(()=>{const t=this.updateProgress();this.emit("timeupdate",t)})),this.onMediaEvent("play",(()=>{this.emit("play"),this.timer.start()})),this.onMediaEvent("pause",(()=>{this.emit("pause"),this.timer.stop(),this.stopAtPosition=null})),this.onMediaEvent("emptied",(()=>{this.timer.stop(),this.stopAtPosition=null})),this.onMediaEvent("ended",(()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null})),this.onMediaEvent("seeking",(()=>{this.emit("seeking",this.getCurrentTime())})),this.onMediaEvent("error",(()=>{var t;this.emit("error",(t=this.getMediaElement().error)!==null&&t!==void 0?t:new Error("Media error")),this.stopAtPosition=null})))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",((t,e)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,e))})),this.renderer.on("dblclick",((t,e)=>{this.emit("dblclick",t,e)})),this.renderer.on("scroll",((t,e,i,s)=>{const n=this.getDuration();this.emit("scroll",t*n,e*n,i,s)})),this.renderer.on("render",(()=>{this.emit("redraw")})),this.renderer.on("rendered",(()=>{this.emit("redrawcomplete")})),this.renderer.on("dragstart",(t=>{this.emit("dragstart",t)})),this.renderer.on("dragend",(t=>{this.emit("dragend",t)})));{let t;const e=this.renderer.on("drag",(i=>{if(!this.options.interact)return;let s;this.renderer.renderProgress(i),clearTimeout(t),this.isPlaying()?s=0:this.options.dragToSeek===!0?s=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(s=this.options.dragToSeek.debounceTime),t=setTimeout((()=>{this.seekTo(i)}),s),this.emit("interaction",i*this.getDuration()),this.emit("drag",i)}));this.subscriptions.push((()=>{clearTimeout(t),e()}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach((e=>{this.registerPlugin(e)}))}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach((t=>t())),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),t.duration&&!t.peaks&&(this.decodedData=I.createBuffer(this.exportPeaks(),t.duration)),t.peaks&&t.duration&&(this.decodedData=I.createBuffer(t.peaks,t.duration)),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){if(this.plugins.includes(t))return t;t._init(this),this.plugins.push(t);const e=t.once("destroy",(()=>{this.plugins=this.plugins.filter((i=>i!==t)),this.subscriptions=this.subscriptions.filter((i=>i!==e))}));return this.subscriptions.push(e),t}unregisterPlugin(t){this.plugins=this.plugins.filter((e=>e!==t)),t.destroy()}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(t,e,i,s){return C(this,void 0,void 0,(function*(){var n;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,(n=this.abortController)===null||n===void 0||n.abort(),this.abortController=null,!e&&!i){const o=this.options.fetchParams||{};window.AbortController&&!o.signal&&(this.abortController=new AbortController,o.signal=this.abortController.signal);const c=h=>this.emit("loading",h);e=yield it.fetchBlob(t,c,o);const l=this.options.blobMimeType;l&&(e=new Blob([e],{type:l}))}this.setSrc(t,e);const r=yield new Promise((o=>{const c=s||this.getDuration();c?o(c):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",(()=>o(this.getDuration())),{once:!0}))}));if(!t&&!e){const o=this.getMediaElement();o instanceof V&&(o.duration=r)}if(i)this.decodedData=I.createBuffer(i,r||0);else if(e){const o=yield e.arrayBuffer();this.decodedData=yield I.decode(o,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())}))}load(t,e,i){return C(this,void 0,void 0,(function*(){try{return yield this.loadAudio(t,void 0,e,i)}catch(s){throw this.emit("error",s),s}}))}loadBlob(t,e,i){return C(this,void 0,void 0,(function*(){try{return yield this.loadAudio("",t,e,i)}catch(s){throw this.emit("error",s),s}}))}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:e=8e3,precision:i=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const s=Math.min(t,this.decodedData.numberOfChannels),n=[];for(let r=0;r<s;r++){const o=this.decodedData.getChannelData(r),c=[],l=o.length/e;for(let h=0;h<e;h++){const p=o.slice(Math.floor(h*l),Math.ceil((h+1)*l));let a=0;for(let d=0;d<p.length;d++){const m=p[d];Math.abs(m)>Math.abs(a)&&(a=m)}c.push(Math.round(a*i)/i)}n.push(c)}return n}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){this.stopAtPosition=null,super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}play(t,e){const i=Object.create(null,{play:{get:()=>super.play}});return C(this,void 0,void 0,(function*(){t!=null&&this.setTime(t);const s=yield i.play.call(this);return e!=null&&(this.media instanceof V?this.media.stopAt(e):this.stopAtPosition=e),s}))}playPause(){return C(this,void 0,void 0,(function*(){return this.isPlaying()?this.pause():this.play()}))}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return C(this,arguments,void 0,(function*(t="image/png",e=1,i="dataURL"){return this.renderer.exportImage(t,e,i)}))}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach((e=>e.destroy())),this.subscriptions.forEach((e=>e())),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}A.BasePlugin=class extends O{constructor(u){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=u}onInit(){}_init(u){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=u,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((u=>u())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},A.dom=et;const ot={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"};function at(u,t){return k(),L("svg",ot,[...t[0]||(t[0]=[y("path",{fill:"#409eff",d:"M512 0C229.227 0 0 229.227 0 512s229.227 512 512 512 512-229.227 512-512S794.773 0 512 0m-33.023 704.742c0 34.191-25.028 62.18-55.617 62.18s-55.618-27.975-55.618-62.18V319.258c0-34.19 25.028-62.18 55.618-62.18s55.617 27.975 55.617 62.18zm170.328 0c0 34.191-25.027 62.18-55.617 62.18s-55.617-27.975-55.617-62.18V319.258c0-34.19 25.027-62.18 55.617-62.18s55.617 27.975 55.617 62.18z"},null,-1)])])}const lt={render:at},ht={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"};function ct(u,t){return k(),L("svg",ht,[...t[0]||(t[0]=[y("path",{fill:"#f56c6c",d:"M512 42.667C252.793 42.667 42.667 252.793 42.667 512S252.793 981.333 512 981.333 981.333 771.207 981.333 512 771.207 42.667 512 42.667M708.547 543.16l-266.667 176A37.333 37.333 0 0 1 384 688V336.033a37.333 37.333 0 0 1 57.893-31.16l266.667 176a37.333 37.333 0 0 1 0 62.32z"},null,-1)])])}const dt={render:ct},ut={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"};function pt(u,t){return k(),L("svg",ut,[...t[0]||(t[0]=[y("path",{fill:"#409EFF",d:"M515.5 91.5C747.4 91.5 936 280.1 936 512S747.4 932.5 515.5 932.5 95 743.9 95 512 283.6 91.5 515.5 91.5m0-87C235.2 4.5 8 231.7 8 512s227.2 507.5 507.5 507.5S1023 792.3 1023 512 795.8 4.5 515.5 4.5"},null,-1),y("path",{fill:"#81888f",d:"m337.7 450.8 84.1 61.2-84.1 61.2zm-28.8-115c-30.1 0-58.2 23.8-58.2 58.1v236.2c0 34.3 28.1 58.1 58.2 58.1 11.5 0 23.3-3.5 33.9-11.2l162.4-118.1c31.9-23.2 31.9-70.7 0-93.8L342.8 347c-10.6-7.7-22.4-11.2-33.9-11.2"},null,-1),y("path",{fill:"#81888f",d:"m529.1 450.8 84.1 61.2-84.1 61.2zm-28.8-115c-30.1 0-58.2 23.8-58.2 58.1v236.2c0 34.3 28.1 58.1 58.2 58.1 11.5 0 23.3-3.5 33.9-11.2l162.4-118.1c31.9-23.2 31.9-70.7 0-93.8L534.2 347c-10.6-7.7-22.4-11.2-33.9-11.2"},null,-1),y("path",{fill:"#81888f",d:"M736.8 367c-24 0-43.5 19.5-43.5 43.5v203c0 24 19.5 43.5 43.5 43.5s43.5-19.5 43.5-43.5v-203c0-24-19.5-43.5-43.5-43.5"},null,-1)])])}const mt={render:pt},ft={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"};function vt(u,t){return k(),L("svg",ft,[...t[0]||(t[0]=[y("path",{fill:"#409EFF",d:"M512 90.3c231.9 0 420.5 188.6 420.5 420.5S743.9 931.3 512 931.3 91.5 742.7 91.5 510.8 280.1 90.3 512 90.3m0-87C231.7 3.3 4.5 230.5 4.5 510.8s227.2 507.5 507.5 507.5 507.5-227.2 507.5-507.5S792.3 3.3 512 3.3"},null,-1),y("path",{fill:"#81888f",d:"M689.8 449.7V572l-84.1-61.2zm28.8-115.1c-11.5 0-23.3 3.5-33.9 11.2L522.3 463.9c-31.9 23.2-31.9 70.6 0 93.8l162.4 118.1c10.6 7.7 22.4 11.2 33.9 11.2 30.1 0 58.2-23.8 58.2-58.1V392.7c0-34.3-28.1-58.1-58.2-58.1"},null,-1),y("path",{fill:"#81888f",d:"M498.4 449.7V572l-84.1-61.2zm28.8-115.1c-11.5 0-23.3 3.5-33.9 11.2L330.9 463.9c-31.9 23.2-31.9 70.6 0 93.8l162.4 118.1c10.6 7.7 22.4 11.2 33.9 11.2 30.1 0 58.2-23.8 58.2-58.1V392.7c0-34.3-28.1-58.1-58.2-58.1"},null,-1),y("path",{fill:"#81888f",d:"M290.7 365.8c-24 0-43.5 19.5-43.5 43.5v203c0 24 19.5 43.5 43.5 43.5s43.5-19.5 43.5-43.5v-203c0-24-19.5-43.5-43.5-43.5"},null,-1)])])}const gt={render:vt},bt={VITE_PUBLIC_PATH:"/vue-pure-admin/"},yt={class:"card-header"},wt={class:"font-medium"},Ct={class:"w-8/12 m-auto! mt-[20px]!","element-loading-background":"transparent"},xt={class:"flex justify-between"},St={class:"text-4xl mt-2!"},Et={class:"text-[#81888f]"},kt={class:"flex mt-2 w-[180px] justify-around m-auto"},Pt=Q({name:"Wavesurfer",__name:"index",setup(u){const t=R(!0),e=R(null),i=R(),s=R(),n=R(),r=R(),o=R(!1),{VITE_PUBLIC_PATH:c}=bt,l=`${c}audio/海阔天空.mp3`;function h(){e.value=A.create({container:i.value,height:"auto",waveColor:"rgb(200, 0, 200)",progressColor:"rgb(100, 0, 100)",cursorColor:"rgb(64, 158, 255)",cursorWidth:4,url:l}),e.value.on("decode",()=>t.value=!1),e.value.on("ready",()=>{if(!e.value)return;const{decodedData:p}=e.value;n.value=p.duration;const{m:a,s:d}=Y(p.duration);s.value=`${a}:${d}`,e.value.setTime(p.duration/2)}),e.value.on("timeupdate",p=>{if(p>n.value)return;const{m:a,s:d}=Y(p);r.value=`${a}:${d}`}),e.value.on("play",()=>o.value=!0),e.value.on("pause",()=>o.value=!1)}return Z(h),tt(()=>{e.value&&(e.value.destroy(),e.value=null)}),(p,a)=>{const d=q("el-link"),m=q("el-card"),S=$("tippy"),f=$("longpress"),g=$("motion-pop"),b=$("loading");return k(),j(m,{shadow:"never"},{header:N(()=>[y("div",yt,[y("span",wt,[a[2]||(a[2]=F(" 音频可视化,采用开源的 ",-1)),B(d,{href:"https://wavesurfer-js.org/",target:"_blank",style:{margin:"0 4px 5px","font-size":"16px"}},{default:N(()=>[...a[1]||(a[1]=[F(" wavesurfer.js ",-1)])]),_:1}),a[3]||(a[3]=y("span",{class:"text-[red]"}," (温馨提示:音频默认最大声音,播放时请调低电脑声音,以免影响到您) ",-1))])]),B(d,{class:"mt-2",href:"https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/able/wavesurfer",target:"_blank"},{default:N(()=>[...a[4]||(a[4]=[F(" 代码位置 src/views/able/wavesurfer ",-1)])]),_:1})]),default:N(()=>[P((k(),L("div",Ct,[y("div",{ref_key:"wavesurferRef",ref:i},null,512),P(y("div",xt,[a[5]||(a[5]=y("span",{class:"text-[#81888f]"},"00:00",-1)),y("h1",St,G(r.value),1),y("span",Et,G(s.value),1)],512),[[X,s.value]]),P(y("div",kt,[P(B(z(gt),{class:"cursor-pointer"},null,512),[[S,{content:"快退(可长按)",placement:"bottom"}],[f,()=>{var x;return(x=e.value)==null?void 0:x.skip(-1)},"0:100"]]),P((k(),L("div",{class:"cursor-pointer",onClick:a[0]||(a[0]=x=>{var w;return(w=e.value)==null?void 0:w.playPause()})},[o.value?P((k(),j(z(lt),{key:0},null,512)),[[g]]):P((k(),j(z(dt),{key:1},null,512)),[[g]])])),[[S,{content:o.value?"暂停":"播放",placement:"bottom"}]]),P(B(z(mt),{class:"cursor-pointer"},null,512),[[S,{content:"快进(可长按)",placement:"bottom"}],[f,()=>{var x;return(x=e.value)==null?void 0:x.skip(1)},"0:100"]])],512),[[X,s.value]])])),[[b,t.value]])]),_:1})}}});export{Pt as default};