mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
87 lines
30 KiB
JavaScript
87 lines
30 KiB
JavaScript
import{e as S,k as R,f as b,d as G,r as P,o as X,a as Y,c as O,w as B,Q as z,b as H,j as L,h as F,i as V,m as M,B as U,R as j,u as W}from"./index-GuFRd4Ob.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 x(p,t,e,i){return new(e||(e=Promise))(function(s,n){function o(l){try{c(i.next(l))}catch(r){n(r)}}function a(l){try{c(i.throw(l))}catch(r){n(r)}}function c(l){var r;l.done?s(l.value):(r=l.value,r instanceof e?r:new e(function(h){h(r)})).then(o,a)}c((i=i.apply(p,t||[])).next())})}const q={decode:function(p,t){return x(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(p).finally(()=>e.close())})},createBuffer:function(p,t){return typeof p[0]=="number"&&(p=[p]),function(e){const i=e[0];if(i.some(s=>s>1||s<-1)){const s=i.length;let n=0;for(let o=0;o<s;o++){const a=Math.abs(i[o]);a>n&&(n=a)}for(const o of e)for(let a=0;a<s;a++)o[a]/=n}}(p),{duration:t,length:p[0].length,sampleRate:p[0].length/t,numberOfChannels:p.length,getChannelData:e=>p==null?void 0:p[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}},Q={fetchBlob:function(p,t,e){return x(this,void 0,void 0,function*(){const i=yield fetch(p,e);if(i.status>=400)throw new Error(`Failed to fetch ${p}: ${i.status} (${i.statusText})`);return function(s,n){x(this,void 0,void 0,function*(){if(!s.body||!s.headers)return;const o=s.body.getReader(),a=Number(s.headers.get("Content-Length"))||0;let c=0;const l=h=>x(this,void 0,void 0,function*(){c+=(h==null?void 0:h.length)||0;const d=Math.round(c/a*100);n(d)}),r=()=>x(this,void 0,void 0,function*(){let h;try{h=yield o.read()}catch(d){return}h.done||(l(h.value),yield r())});r()})}(i.clone(),t),i.blob()})}};class ${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))}}class J extends ${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.onceMediaEvent("canplay",()=>{t.playbackRate!=null&&(this.media.playbackRate=t.playbackRate)})}onMediaEvent(t,e,i){return this.media.addEventListener(t,e,i),()=>this.media.removeEventListener(t,e)}onceMediaEvent(t,e){return this.onMediaEvent(t,e,{once:!0})}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 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}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 N extends ${constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,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=i=>{const s=this.wrapper.getBoundingClientRect(),n=i.clientX-s.left,o=i.clientX-s.left;return[n/s.width,o/s.height]};this.wrapper.addEventListener("click",i=>{const[s,n]=t(i);this.emit("click",s,n)}),this.wrapper.addEventListener("dblclick",i=>{const[s,n]=t(i);this.emit("dblclick",s,n)}),this.options.dragToSeek&&this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:i,scrollWidth:s,clientWidth:n}=this.scrollContainer,o=i/s,a=(i+n)/s;this.emit("scroll",o,a)});const e=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{e(()=>this.onContainerResize())}),this.resizeObserver.observe(this.scrollContainer)}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=t,this.reRender())}initDrag(){(function(t,e,i,s,n=3,o=0){if(!t)return()=>{};let a=()=>{};const c=l=>{if(l.button!==o)return;l.preventDefault(),l.stopPropagation();let r=l.clientX,h=l.clientY,d=!1;const u=v=>{v.preventDefault(),v.stopPropagation();const y=v.clientX,E=v.clientY,T=y-r,D=E-h;if(d||Math.abs(T)>n||Math.abs(D)>n){const k=t.getBoundingClientRect(),{left:g,top:C}=k;d||(i==null||i(r-g,h-C),d=!0),e(T,D,y-g,E-C),r=y,h=E}},m=()=>{d&&(s==null||s()),a()},f=v=>{v.relatedTarget&&v.relatedTarget!==document.documentElement||m()},w=v=>{d&&(v.stopPropagation(),v.preventDefault())},_=v=>{d&&v.preventDefault()};document.addEventListener("pointermove",u),document.addEventListener("pointerup",m),document.addEventListener("pointerout",f),document.addEventListener("pointercancel",f),document.addEventListener("touchmove",_,{passive:!1}),document.addEventListener("click",w,{capture:!0}),a=()=>{document.removeEventListener("pointermove",u),document.removeEventListener("pointerup",m),document.removeEventListener("pointerout",f),document.removeEventListener("pointercancel",f),document.removeEventListener("touchmove",_),setTimeout(()=>{document.removeEventListener("click",w,{capture:!0})},10)}};t.addEventListener("pointerdown",c)})(this.wrapper,(t,e,i)=>{this.emit("drag",Math.max(0,Math.min(1,i/this.wrapper.getBoundingClientRect().width)))},()=>this.isDragging=!0,()=>this.isDragging=!1)}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"></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&&!this.options.dragToSeek&&this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getScroll(){return this.scrollContainer.scrollLeft}destroy(){var t;this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect()}createDelay(t=10){const e={};return this.timeouts.push(e),i=>{e.timeout&&clearTimeout(e.timeout),e.timeout=setTimeout(i,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),n=i.createLinearGradient(0,0,0,s),o=1/(t.length-1);return t.forEach((a,c)=>{const l=c*o;n.addColorStop(l,a)}),n}renderBarWaveform(t,e,i,s){const n=t[0],o=t[1]||t[0],a=n.length,{width:c,height:l}=i.canvas,r=l/2,h=window.devicePixelRatio||1,d=e.barWidth?e.barWidth*h:1,u=e.barGap?e.barGap*h:e.barWidth?d/2:0,m=e.barRadius||0,f=c/(d+u)/a,w=m&&"roundRect"in i?"roundRect":"rect";i.beginPath();let _=0,v=0,y=0;for(let E=0;E<=a;E++){const T=Math.round(E*f);if(T>_){const g=Math.round(v*r*s),C=g+Math.round(y*r*s)||1;let A=r-g;e.barAlign==="top"?A=0:e.barAlign==="bottom"&&(A=l-C),i[w](_*(d+u),A,d,C,m),_=T,v=0,y=0}const D=Math.abs(n[E]||0),k=Math.abs(o[E]||0);D>v&&(v=D),k>y&&(y=k)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,s){const n=o=>{const a=t[o]||t[0],c=a.length,{height:l}=i.canvas,r=l/2,h=i.canvas.width/c;i.moveTo(0,r);let d=0,u=0;for(let m=0;m<=c;m++){const f=Math.round(m*h);if(f>d){const _=r+(Math.round(u*r*s)||1)*(o===0?-1:1);i.lineTo(d,_),d=f,u=0}const w=Math.abs(a[m]||0);w>u&&(u=w)}i.lineTo(d,r)};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((o,a)=>Math.max(o,Math.abs(a)),0);s=n?1/n:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,s):this.renderLineWaveform(t,e,i,s)}renderSingleCanvas(t,e,i,s,n,o,a,c){const l=window.devicePixelRatio||1,r=document.createElement("canvas"),h=t[0].length;r.width=Math.round(i*(o-n)/h),r.height=s*l,r.style.width=`${Math.floor(r.width/l)}px`,r.style.height=`${s}px`,r.style.left=`${Math.floor(n*i/l/h)}px`,a.appendChild(r);const d=r.getContext("2d");if(this.renderWaveform(t.map(u=>u.slice(n,o)),e,d),r.width>0&&r.height>0){const u=r.cloneNode(),m=u.getContext("2d");m.drawImage(r,0,0),m.globalCompositeOperation="source-in",m.fillStyle=this.convertColorValues(e.progressColor),m.fillRect(0,0,r.width,r.height),c.appendChild(u)}}renderChannel(t,e,i,s){const n=document.createElement("div"),o=this.getHeight(e.height);n.style.height=`${o}px`,this.canvasWrapper.style.minHeight=`${o}px`,this.canvasWrapper.appendChild(n);const a=n.cloneNode();this.progressWrapper.appendChild(a);const{scrollLeft:c,scrollWidth:l,clientWidth:r}=this.scrollContainer,h=t[0].length,d=h/l;let u=Math.min(N.MAX_CANVAS_WIDTH,r);if(e.barWidth||e.barGap){const g=e.barWidth||.5,C=g+(e.barGap||g/2);u%C!=0&&(u=Math.floor(u/C)*C)}const m=Math.floor(Math.abs(c)*d),f=Math.floor(m+u*d),w=f-m,_=(g,C)=>{this.renderSingleCanvas(t,e,i,o,Math.max(0,g),Math.min(C,h),n,a)},v={head:!1,tail:f>=h},y=g=>{v[g]=!0,v.head&&v.tail&&s()},E=this.createDelay(),T=this.createDelay(),D=(g,C)=>{_(g,C),g>0?E(()=>{D(g-w,C-w)}):y("head")},k=(g,C)=>{_(g,C),C<h?T(()=>{k(g+w,C+w)}):y("tail")};D(m,f),f<h&&k(f,f+w)}render(t){this.timeouts.forEach(a=>a.timeout&&clearTimeout(a.timeout)),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 n=this.options.fillParent&&!this.isScrollable,o=(n?i:s)*e;if(this.wrapper.style.width=n?"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.options.splitChannels){let a=0;const c=()=>{a++,a===t.numberOfChannels&&this.emit("rendered")};for(let l=0;l<t.numberOfChannels;l++){const r=Object.assign(Object.assign({},this.options),this.options.splitChannels[l]);this.renderChannel([t.getChannelData(l)],r,o,c)}}else{const a=[t.getChannelData(0)];t.numberOfChannels>1&&a.push(t.getChannelData(1)),this.renderChannel(a,this.options,o,()=>this.emit("rendered"))}this.audioData=t,this.emit("render")}reRender(){if(!this.audioData)return;const{scrollWidth:t}=this.scrollContainer,e=this.progressWrapper.clientWidth;if(this.render(this.audioData),this.isScrollable&&t!==this.scrollContainer.scrollWidth){const i=this.progressWrapper.clientWidth;this.scrollContainer.scrollLeft+=i-e}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:s,clientWidth:n}=this.scrollContainer,o=t*s,a=i,c=i+n,l=n/2;if(this.isDragging)o+30>c?this.scrollContainer.scrollLeft+=30:o-30<a&&(this.scrollContainer.scrollLeft-=30);else{(o<a||o>c)&&(this.scrollContainer.scrollLeft=o-(this.options.autoCenter?l:0));const r=o-i-l;e&&this.options.autoCenter&&r>0&&(this.scrollContainer.scrollLeft+=Math.min(r,10))}{const r=this.scrollContainer.scrollLeft,h=r/s,d=(r+n)/s;this.emit("scroll",h,d)}}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.marginLeft=Math.round(i)===100?`-${this.options.cursorWidth}px`:"",this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return x(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(o=>o.toDataURL(t,e));return Promise.resolve(n)}return Promise.all(Array.from(s).map(n=>new Promise((o,a)=>{n.toBlob(c=>{c?o(c):a(new Error("Could not export image"))},t,e)})))})}}N.MAX_CANVAS_WIDTH=4e3;class K extends ${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 Z extends ${constructor(t=new AudioContext){super(),this.bufferNode=null,this.autoplay=!1,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return x(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then(e=>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;this.paused&&(this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.bufferNode.buffer=this.buffer,this.bufferNode.connect(this.gainNode),this.playedDuration>=this.duration&&(this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,this.playedDuration),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))})}_pause(){var t;this.paused||(this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime)}play(){return x(this,void 0,void 0,function*(){this._play(),this.emit("play")})}pause(){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 x(this,void 0,void 0,function*(){return this.audioContext.setSinkId(t)})}get playbackRate(){var t,e;return(e=(t=this.bufferNode)===null||t===void 0?void 0:t.playbackRate.value)!==null&&e!==void 0?e:1}set playbackRate(t){this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return this.paused?this.playedDuration:this.playedDuration+this.audioContext.currentTime-this.playStartTime}set currentTime(t){this.emit("seeking"),this.paused?this.playedDuration=t:(this._pause(),this.playedDuration=t,this._play()),this.emit("timeupdate")}get duration(){var t;return((t=this.buffer)===null||t===void 0?void 0:t.duration)||0}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 tt={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class I extends J{static create(t){return new I(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new Z:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.subscriptions=[],this.mediaSubscriptions=[],this.options=Object.assign({},tt,t),this.timer=new K;const i=e?void 0:this.getMediaElement();this.renderer=new N(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)})}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{const t=this.getCurrentTime();this.renderer.renderProgress(t/this.getDuration(),!0),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.getCurrentTime();this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),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())}))}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")}));{let t;this.subscriptions.push(this.renderer.on("drag",e=>{this.options.interact&&(this.renderer.renderProgress(e),clearTimeout(t),t=setTimeout(()=>{this.seekTo(e)},this.isPlaying()?0:200),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()}getActivePlugins(){return this.plugins}loadAudio(t,e,i,s){return x(this,void 0,void 0,function*(){if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!e&&!i){const o=a=>this.emit("loading",a);e=yield Q.fetchBlob(t,o,this.options.fetchParams)}this.setSrc(t,e);const n=s||this.getDuration()||(yield new Promise(o=>{this.onceMediaEvent("loadedmetadata",()=>o(this.getDuration()))}));if(i)this.decodedData=q.createBuffer(i,n||0);else if(e){const o=yield e.arrayBuffer();this.decodedData=yield q.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 x(this,void 0,void 0,function*(){yield this.loadAudio(t,void 0,e,i)})}loadBlob(t,e,i){return x(this,void 0,void 0,function*(){yield this.loadAudio("blob",t,e,i)})}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 o=0;o<s;o++){const a=this.decodedData.getChannelData(o),c=[],l=Math.round(a.length/e);for(let r=0;r<e;r++){const h=a.slice(r*l,(r+1)*l);let d=0;for(let u=0;u<h.length;u++){const m=h[u];Math.abs(m)>Math.abs(d)&&(d=m)}c.push(Math.round(d*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}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return x(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 x(this,void 0,void 0,function*(){return this.renderer.exportImage(t,e,i)})}destroy(){this.emit("destroy"),this.plugins.forEach(t=>t.destroy()),this.subscriptions.forEach(t=>t()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}const et={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"},it=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),st=[it];function nt(p,t){return S(),R("svg",et,[...st])}const ot={render:nt},rt={xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",class:"icon",viewBox:"0 0 1024 1024"},at=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),lt=[at];function ht(p,t){return S(),R("svg",rt,[...lt])}const dt={render:ht},ct={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"},ut=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),pt=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),mt=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),vt=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),ft=[ut,pt,mt,vt];function gt(p,t){return S(),R("svg",ct,[...ft])}const bt={render:gt},yt={xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",class:"icon",viewBox:"0 0 1024 1024"},Ct=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),wt=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),_t=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),Et=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),xt=[Ct,wt,_t,Et];function St(p,t){return S(),R("svg",yt,[...xt])}const Dt={render:St};var Mt={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 Tt={class:"card-header"},kt={class:"font-medium"},Pt=b("span",{class:"text-[red]"}," (温馨提示:音频默认最大声音,播放时请调低电脑声音,以免影响到您) ",-1),Rt={class:"w-8/12 !m-auto !mt-[20px]","element-loading-background":"transparent"},Lt={class:"flex justify-between"},Wt=b("span",{class:"text-[#81888f]"},"00:00",-1),$t={class:"text-4xl mt-2"},Nt={class:"text-[#81888f]"},At={class:"flex mt-2 w-[180px] justify-around m-auto"},Bt=G({name:"Wavesurfer",__name:"index",setup(p){const t=P(!0),e=P(null),i=P(),s=P(),n=P(),o=P(),a=P(!1),{VITE_PUBLIC_PATH:c}=Mt,l=`${c}audio/海阔天空.mp3`;function r(){e.value=I.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:h}=e.value;n.value=h.duration;const{m:d,s:u}=z(h.duration);s.value=`${d}:${u}`,e.value.setTime(h.duration/2)}),e.value.on("timeupdate",h=>{if(h>n.value)return;const{m:d,s:u}=z(h);o.value=`${d}:${u}`}),e.value.on("play",()=>a.value=!0),e.value.on("pause",()=>a.value=!1)}return X(r),Y(()=>{e.value&&(e.value.destroy(),e.value=null)}),(h,d)=>{const u=H("el-link"),m=H("el-card"),f=L("tippy"),w=L("longpress"),_=L("motion-pop"),v=L("loading");return S(),O(m,{shadow:"never"},{header:B(()=>[b("div",Tt,[b("span",kt,[F(" 音频可视化,采用开源的 "),V(u,{href:"https://wavesurfer-js.org/",target:"_blank",style:{margin:"0 4px 5px","font-size":"16px"}},{default:B(()=>[F(" wavesurfer.js ")]),_:1}),Pt])])]),default:B(()=>[M((S(),R("div",Rt,[b("div",{ref_key:"wavesurferRef",ref:i},null,512),M(b("div",Lt,[Wt,b("h1",$t,U(o.value),1),b("span",Nt,U(s.value),1)],512),[[j,s.value]]),M(b("div",At,[M(V(W(Dt),{class:"cursor-pointer"},null,512),[[f,{content:"快退(可长按)",placement:"bottom"}],[w,()=>{var y;return(y=e.value)==null?void 0:y.skip(-1)},"0:100"]]),M((S(),R("div",{class:"cursor-pointer",onClick:d[0]||(d[0]=y=>{var E;return(E=e.value)==null?void 0:E.playPause()})},[a.value?M((S(),O(W(ot),{key:0},null,512)),[[_]]):M((S(),O(W(dt),{key:1},null,512)),[[_]])])),[[f,{content:a.value?"暂停":"播放",placement:"bottom"}]]),M(V(W(bt),{class:"cursor-pointer"},null,512),[[f,{content:"快进(可长按)",placement:"bottom"}],[w,()=>{var y;return(y=e.value)==null?void 0:y.skip(1)},"0:100"]])],512),[[j,s.value]])])),[[v,t.value]])]),_:1})}}});export{Bt as default};
|