mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
87 lines
34 KiB
JavaScript
87 lines
34 KiB
JavaScript
import{f as E,k as P,g as b,d as J,a as M,m as K,z as Q,b as V,w as $,a4 as j,e as H,A as O,h as z,i as N,B as T,t as F,a5 as U,u as A}from"./index-BFzOQFgB.js";/*! *****************************************************************************
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
PERFORMANCE OF THIS SOFTWARE.
|
|
***************************************************************************** */function y(u,t,e,i){return new(e||(e=Promise))(function(s,o){function a(d){try{l(i.next(d))}catch(n){o(n)}}function r(d){try{l(i.throw(d))}catch(n){o(n)}}function l(d){var n;d.done?s(d.value):(n=d.value,n instanceof e?n:new e(function(h){h(n)})).then(a,r)}l((i=i.apply(u,t||[])).next())})}class W{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i==null?void 0:i.once){const s=()=>{this.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>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 X={decode:function(u,t){return y(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(u).finally(()=>e.close())})},createBuffer:function(u,t){return typeof u[0]=="number"&&(u=[u]),function(e){const i=e[0];if(i.some(s=>s>1||s<-1)){const s=i.length;let o=0;for(let a=0;a<s;a++){const r=Math.abs(i[a]);r>o&&(o=r)}for(const a of e)for(let r=0;r<s;r++)a[r]/=o}}(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 Y(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")for(const[o,a]of Object.entries(t))typeof a=="string"?e.appendChild(document.createTextNode(a)):e.appendChild(Y(o,a));else i==="style"?Object.assign(e.style,s):i==="textContent"?e.textContent=s:e.setAttribute(i,s.toString());return e}function q(u,t,e){const i=Y(u,t||{});return e==null||e.appendChild(i),i}var Z=Object.freeze({__proto__:null,createElement:q,default:q});const tt={fetchBlob:function(u,t,e){return y(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,o){y(this,void 0,void 0,function*(){if(!s.body||!s.headers)return;const a=s.body.getReader(),r=Number(s.headers.get("Content-Length"))||0;let l=0;const d=h=>y(this,void 0,void 0,function*(){l+=(h==null?void 0:h.length)||0;const p=Math.round(l/r*100);o(p)}),n=()=>y(this,void 0,void 0,function*(){let h;try{h=yield a.read()}catch(p){return}h.done||(d(h.value),yield n())});n()})}(i.clone(),t),i.blob()})}};class et extends W{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){if(this.getSrc()===t)return;this.revokeSrc();const i=e instanceof Blob&&this.canPlayType(e.type)?URL.createObjectURL(e):t;this.media.src=i}destroy(){this.media.pause(),this.isExternalMedia||(this.media.remove(),this.revokeSrc(),this.media.src="",this.media.load())}setMediaElement(t){this.media=t}play(){return y(this,void 0,void 0,function*(){return this.media.play()})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=t}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 B extends W{constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.subscriptions=[],this.options=t;const i=this.parentFromOptionsContainer(t.container);this.parent=i;const[s,o]=this.initHtml();i.appendChild(s),this.container=s,this.scrollContainer=o.querySelector(".scroll"),this.wrapper=o.querySelector(".wrapper"),this.canvasWrapper=o.querySelector(".canvases"),this.progressWrapper=o.querySelector(".progress"),this.cursor=o.querySelector(".cursor"),e&&o.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=i=>{const s=this.wrapper.getBoundingClientRect(),o=i.clientX-s.left,a=i.clientX-s.left;return[o/s.width,a/s.height]};this.wrapper.addEventListener("click",i=>{const[s,o]=t(i);this.emit("click",s,o)}),this.wrapper.addEventListener("dblclick",i=>{const[s,o]=t(i);this.emit("dblclick",s,o)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:i,scrollWidth:s,clientWidth:o}=this.scrollContainer,a=i/s,r=(i+o)/s;this.emit("scroll",a,r)});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.subscriptions.push(function(t,e,i,s,o=3,a=0,r=100){if(!t)return()=>{};let l,d=!1,n=!1,h=0,p=0,m=0;const f=matchMedia("(pointer: coarse)").matches,_=c=>{c.button===a&&(c.stopPropagation(),d=!0,n=!1,m=Date.now(),l=t.getBoundingClientRect(),h=c.clientX-l.left,p=c.clientY-l.top)},w=c=>{if(d=!1,m=0,n){c.preventDefault(),c.stopPropagation(),setTimeout(()=>{n=!1},300);const S=c.clientX-l.left,k=c.clientY-l.top;s==null||s(S,k)}},C=c=>{if(!d||f&&Date.now()-m<r)return;c.preventDefault(),c.stopPropagation();const S=c.clientX-l.left,k=c.clientY-l.top,D=S-h,R=k-p;(n||Math.abs(D)>o||Math.abs(R)>o)&&(n||(i==null||i(h,p),n=!0),e(D,R,S,k),h=S,p=k)},x=c=>{c.relatedTarget&&c.relatedTarget!==document.documentElement||w(c)},g=c=>{n&&c.preventDefault()},v=c=>{n&&(c.stopPropagation(),c.preventDefault())};return t.addEventListener("pointerdown",_),t.addEventListener("click",v,!0),document.addEventListener("click",v,!0),document.addEventListener("pointermove",C),document.addEventListener("touchmove",g,{passive:!1}),document.addEventListener("pointerup",w),document.addEventListener("pointerleave",x),document.addEventListener("pointercancel",w),()=>{t.removeEventListener("pointerdown",_),t.removeEventListener("click",v,!0),document.removeEventListener("click",v,!0),document.removeEventListener("pointermove",C),document.removeEventListener("touchmove",g),document.removeEventListener("pointerup",w),document.removeEventListener("pointerleave",x),document.removeEventListener("pointercancel",w)}}(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)))}))}getHeight(t){return t==null?128:isNaN(Number(t))?t==="auto"&&this.parent.clientHeight||128:Number(t)}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"});return e.innerHTML=`
|
|
<style>
|
|
: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)}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}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(),(t=this.resizeObserver)===null||t===void 0||t.disconnect()}createDelay(t=10){let e,i;const s=()=>{e&&clearTimeout(e),i&&i()};return this.timeouts.push(s),()=>new Promise((o,a)=>{s(),i=a,e=setTimeout(()=>{e=void 0,i=void 0,o()},t)})}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),s=e.height*(window.devicePixelRatio||1),o=i.createLinearGradient(0,0,0,s),a=1/(t.length-1);return t.forEach((r,l)=>{const d=l*a;o.addColorStop(d,r)}),o}renderBarWaveform(t,e,i,s){const o=t[0],a=t[1]||t[0],r=o.length,{width:l,height:d}=i.canvas,n=d/2,h=window.devicePixelRatio||1,p=e.barWidth?e.barWidth*h:1,m=e.barGap?e.barGap*h:e.barWidth?p/2:0,f=e.barRadius||0,_=l/(p+m)/r,w=f&&"roundRect"in i?"roundRect":"rect";i.beginPath();let C=0,x=0,g=0;for(let v=0;v<=r;v++){const c=Math.round(v*_);if(c>C){const D=Math.round(x*n*s),R=D+Math.round(g*n*s)||1;let I=n-D;e.barAlign==="top"?I=0:e.barAlign==="bottom"&&(I=d-R),i[w](C*(p+m),I,p,R,f),C=c,x=0,g=0}const S=Math.abs(o[v]||0),k=Math.abs(a[v]||0);S>x&&(x=S),k>g&&(g=k)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,s){const o=a=>{const r=t[a]||t[0],l=r.length,{height:d}=i.canvas,n=d/2,h=i.canvas.width/l;i.moveTo(0,n);let p=0,m=0;for(let f=0;f<=l;f++){const _=Math.round(f*h);if(_>p){const C=n+(Math.round(m*n*s)||1)*(a===0?-1:1);i.lineTo(p,C),p=_,m=0}const w=Math.abs(r[f]||0);w>m&&(m=w)}i.lineTo(p,n)};i.beginPath(),o(0),o(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 o=Array.from(t[0]).reduce((a,r)=>Math.max(a,Math.abs(r)),0);s=o?1/o:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,s):this.renderLineWaveform(t,e,i,s)}renderSingleCanvas(t,e,i,s,o,a,r,l){const d=window.devicePixelRatio||1,n=document.createElement("canvas"),h=t[0].length;n.width=Math.round(i*(a-o)/h),n.height=s*d,n.style.width=`${Math.floor(n.width/d)}px`,n.style.height=`${s}px`,n.style.left=`${Math.floor(o*i/d/h)}px`,r.appendChild(n);const p=n.getContext("2d");if(this.renderWaveform(t.map(m=>m.slice(o,a)),e,p),n.width>0&&n.height>0){const m=n.cloneNode(),f=m.getContext("2d");f.drawImage(n,0,0),f.globalCompositeOperation="source-in",f.fillStyle=this.convertColorValues(e.progressColor),f.fillRect(0,0,n.width,n.height),l.appendChild(m)}}renderChannel(t,e,i,s){var{overlay:o}=e,a=function(r,l){var d={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&l.indexOf(n)<0&&(d[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function"){var h=0;for(n=Object.getOwnPropertySymbols(r);h<n.length;h++)l.indexOf(n[h])<0&&Object.prototype.propertyIsEnumerable.call(r,n[h])&&(d[n[h]]=r[n[h]])}return d}(e,["overlay"]);return y(this,void 0,void 0,function*(){const r=document.createElement("div"),l=this.getHeight(a.height);r.style.height=`${l}px`,o&&s>0&&(r.style.marginTop=`-${l}px`),this.canvasWrapper.style.minHeight=`${l}px`,this.canvasWrapper.appendChild(r);const d=r.cloneNode();this.progressWrapper.appendChild(d);const n=t[0].length,h=(v,c)=>{this.renderSingleCanvas(t,a,i,l,Math.max(0,v),Math.min(c,n),r,d)};if(!this.isScrollable)return void h(0,n);const{scrollLeft:p,scrollWidth:m,clientWidth:f}=this.scrollContainer,_=n/m;let w=Math.min(B.MAX_CANVAS_WIDTH,f);if(a.barWidth||a.barGap){const v=a.barWidth||.5,c=v+(a.barGap||v/2);w%c!=0&&(w=Math.floor(w/c)*c)}const C=Math.floor(Math.abs(p)*_),x=Math.floor(C+w*_),g=x-C;g<=0||(h(C,x),yield Promise.all([y(this,void 0,void 0,function*(){if(C===0)return;const v=this.createDelay();for(let c=C;c>=0;c-=g)yield v(),h(Math.max(0,c-g),c)}),y(this,void 0,void 0,function*(){if(x===n)return;const v=this.createDelay();for(let c=x;c<n;c+=g)yield v(),h(c,Math.min(n,c+g))})]))})}render(t){return y(this,void 0,void 0,function*(){this.timeouts.forEach(r=>r()),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 e=window.devicePixelRatio||1,i=this.scrollContainer.clientWidth,s=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=s>i;const o=this.options.fillParent&&!this.isScrollable,a=(o?i:s)*e;this.wrapper.style.width=o?"100%":`${s}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");try{if(this.options.splitChannels)yield Promise.all(Array.from({length:t.numberOfChannels}).map((r,l)=>{var d;const n=Object.assign(Object.assign({},this.options),(d=this.options.splitChannels)===null||d===void 0?void 0:d[l]);return this.renderChannel([t.getChannelData(l)],n,a,l)}));else{const r=[t.getChannelData(0)];t.numberOfChannels>1&&r.push(t.getChannelData(1)),yield this.renderChannel(r,this.options,a,0)}}catch(r){return}this.emit("rendered")})}reRender(){if(!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:o}=this.scrollContainer,a=t*s,r=i,l=i+o,d=o/2;if(this.isDragging)a+30>l?this.scrollContainer.scrollLeft+=30:a-30<r&&(this.scrollContainer.scrollLeft-=30);else{(a<r||a>l)&&(this.scrollContainer.scrollLeft=a-(this.options.autoCenter?d:0));const n=a-i-d;e&&this.options.autoCenter&&n>0&&(this.scrollContainer.scrollLeft+=Math.min(n,10))}{const n=this.scrollContainer.scrollLeft,h=n/s,p=(n+o)/s;this.emit("scroll",h,p)}}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=`translateX(-${Math.round(i)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return y(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 o=Array.from(s).map(a=>a.toDataURL(t,e));return Promise.resolve(o)}return Promise.all(Array.from(s).map(o=>new Promise((a,r)=>{o.toBlob(l=>{l?a(l):r(new Error("Could not export image"))},t,e)})))})}}B.MAX_CANVAS_WIDTH=4e3;class it extends W{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class G extends W{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 y(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(){var t;if(!this.paused)return;this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.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 e=this.playedDuration*this._playbackRate;e>=this.duration&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),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 y(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){var e,i;const s=t-this.currentTime;(e=this.bufferNode)===null||e===void 0||e.stop(this.audioContext.currentTime+s),(i=this.bufferNode)===null||i===void 0||i.addEventListener("ended",()=>{this.bufferNode=null,this.pause()},{once:!0})}setSinkId(t){return y(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}}const st={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class L extends et{static create(t){return new L(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new G:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},st,t),this.timer=new it;const i=e?void 0:this.getMediaElement();this.renderer=new B(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins(),Promise.resolve().then(()=>{this.emit("init");const s=this.options.url||this.getSrc()||"";(s||this.options.peaks&&this.options.duration)&&this.load(s,this.options.peaks,this.options.duration).catch(()=>null)})}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)}}))}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.onMediaEvent("emptied",()=>{this.timer.stop()}),this.onMediaEvent("ended",()=>{this.emit("finish")}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",t=>{this.emit("error",t.error)}))}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)=>{const i=this.getDuration();this.emit("scroll",t*i,e*i)}),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;this.subscriptions.push(this.renderer.on("drag",e=>{if(!this.options.interact)return;let i;this.renderer.renderProgress(e),clearTimeout(t),this.isPlaying()?i=0:this.options.dragToSeek===!0?i=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(i=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(e)},i),this.emit("interaction",e*this.getDuration()),this.emit("drag",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),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){return t._init(this),this.plugins.push(t),this.subscriptions.push(t.once("destroy",()=>{this.plugins=this.plugins.filter(e=>e!==t)})),t}getWrapper(){return this.renderer.getWrapper()}getScroll(){return this.renderer.getScroll()}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(t,e,i,s){var o;return y(this,void 0,void 0,function*(){if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!e&&!i){const r=this.options.fetchParams||{};window.AbortController&&!r.signal&&(this.abortController=new AbortController,r.signal=(o=this.abortController)===null||o===void 0?void 0:o.signal);const l=d=>this.emit("loading",d);e=yield tt.fetchBlob(t,l,r)}this.setSrc(t,e);const a=s||this.getDuration()||(yield new Promise(r=>{this.onMediaEvent("loadedmetadata",()=>r(this.getDuration()),{once:!0})}));if(!t&&!e){const r=this.getMediaElement();r instanceof G&&(r.duration=a)}if(i)this.decodedData=X.createBuffer(i,a||0);else if(e){const r=yield e.arrayBuffer();this.decodedData=yield X.decode(r,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 y(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 y(this,void 0,void 0,function*(){try{return yield this.loadAudio("blob",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),o=[];for(let a=0;a<s;a++){const r=this.decodedData.getChannelData(a),l=[],d=Math.round(r.length/e);for(let n=0;n<e;n++){const h=r.slice(n*d,(n+1)*d);let p=0;for(let m=0;m<h.length;m++){const f=h[m];Math.abs(f)>Math.abs(p)&&(p=f)}l.push(Math.round(p*i)/i)}o.push(l)}return o}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){super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return y(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(t="image/png",e=1,i="dataURL"){return y(this,void 0,void 0,function*(){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()}}L.BasePlugin=class extends W{constructor(u){super(),this.subscriptions=[],this.options=u}onInit(){}_init(u){this.wavesurfer=u,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(u=>u())}},L.dom=Z;const nt={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"},rt=b("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),ot=[rt];function at(u,t){return E(),P("svg",nt,[...ot])}const lt={render:at},ht={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"},dt=b("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),ct=[dt];function ut(u,t){return E(),P("svg",ht,[...ct])}const pt={render:ut},mt={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"},vt=b("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),ft=b("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),gt=b("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),bt=b("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),yt=[vt,ft,gt,bt];function wt(u,t){return E(),P("svg",mt,[...yt])}const Ct={render:wt},_t={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"},xt=b("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),Et=b("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),St=b("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),kt=b("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),Tt=[xt,Et,St,kt];function Mt(u,t){return E(),P("svg",_t,[...Tt])}const Pt={render:Mt};var Dt={VITE_PORT:"8848",VITE_HIDE_HOME:"false",VITE_PUBLIC_PATH:"/vue-pure-admin/",VITE_ROUTER_HISTORY:"hash",VITE_CDN:"false",VITE_COMPRESSION:"none",BASE_URL:"/vue-pure-admin/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const Rt={class:"card-header"},Lt={class:"font-medium"},Wt=b("span",{class:"text-[red]"}," (温馨提示:音频默认最大声音,播放时请调低电脑声音,以免影响到您) ",-1),$t={class:"w-8/12 !m-auto !mt-[20px]","element-loading-background":"transparent"},Ot={class:"flex justify-between"},Nt=b("span",{class:"text-[#81888f]"},"00:00",-1),At={class:"text-4xl mt-2"},Bt={class:"text-[#81888f]"},It={class:"flex mt-2 w-[180px] justify-around m-auto"},zt=J({name:"Wavesurfer",__name:"index",setup(u){const t=M(!0),e=M(null),i=M(),s=M(),o=M(),a=M(),r=M(!1),{VITE_PUBLIC_PATH:l}=Dt,d=`${l}audio/海阔天空.mp3`;function n(){e.value=L.create({container:i.value,height:"auto",waveColor:"rgb(200, 0, 200)",progressColor:"rgb(100, 0, 100)",cursorColor:"rgb(64, 158, 255)",cursorWidth:4,url:d}),e.value.on("decode",()=>t.value=!1),e.value.on("ready",()=>{if(!e.value)return;const{decodedData:h}=e.value;o.value=h.duration;const{m:p,s:m}=j(h.duration);s.value=`${p}:${m}`,e.value.setTime(h.duration/2)}),e.value.on("timeupdate",h=>{if(h>o.value)return;const{m:p,s:m}=j(h);a.value=`${p}:${m}`}),e.value.on("play",()=>r.value=!0),e.value.on("pause",()=>r.value=!1)}return K(n),Q(()=>{e.value&&(e.value.destroy(),e.value=null)}),(h,p)=>{const m=H("el-link"),f=H("el-card"),_=O("tippy"),w=O("longpress"),C=O("motion-pop"),x=O("loading");return E(),V(f,{shadow:"never"},{header:$(()=>[b("div",Rt,[b("span",Lt,[z(" 音频可视化,采用开源的 "),N(m,{href:"https://wavesurfer-js.org/",target:"_blank",style:{margin:"0 4px 5px","font-size":"16px"}},{default:$(()=>[z(" wavesurfer.js ")]),_:1}),Wt])]),N(m,{class:"mt-2",href:"https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/able/wavesurfer",target:"_blank"},{default:$(()=>[z(" 代码位置 src/views/able/wavesurfer ")]),_:1})]),default:$(()=>[T((E(),P("div",$t,[b("div",{ref_key:"wavesurferRef",ref:i},null,512),T(b("div",Ot,[Nt,b("h1",At,F(a.value),1),b("span",Bt,F(s.value),1)],512),[[U,s.value]]),T(b("div",It,[T(N(A(Pt),{class:"cursor-pointer"},null,512),[[_,{content:"快退(可长按)",placement:"bottom"}],[w,()=>{var g;return(g=e.value)==null?void 0:g.skip(-1)},"0:100"]]),T((E(),P("div",{class:"cursor-pointer",onClick:p[0]||(p[0]=g=>{var v;return(v=e.value)==null?void 0:v.playPause()})},[r.value?T((E(),V(A(lt),{key:0},null,512)),[[C]]):T((E(),V(A(pt),{key:1},null,512)),[[C]])])),[[_,{content:r.value?"暂停":"播放",placement:"bottom"}]]),T(N(A(Ct),{class:"cursor-pointer"},null,512),[[_,{content:"快进(可长按)",placement:"bottom"}],[w,()=>{var g;return(g=e.value)==null?void 0:g.skip(1)},"0:100"]])],512),[[U,s.value]])])),[[x,t.value]])]),_:1})}}});export{zt as default};
|