1- var I = Object . defineProperty ;
2- var L = ( i , e , t ) => e in i ? I ( i , e , { enumerable : ! 0 , configurable : ! 0 , writable : ! 0 , value : t } ) : i [ e ] = t ;
3- var l = ( i , e , t ) => ( L ( i , typeof e != "symbol" ? e + "" : e , t ) , t ) ;
4- import { defineComponent as $ , ref as d , onMounted as E , watchEffect as g , onUnmounted as P , openBlock as O , createElementBlock as X , createVNode as Y , Transition as V , withCtx as q , withDirectives as m , createElementVNode as y , normalizeStyle as _ , vShow as A } from "vue" ;
1+ var $ = Object . defineProperty ;
2+ var I = ( i , e , t ) => e in i ? $ ( i , e , { enumerable : ! 0 , configurable : ! 0 , writable : ! 0 , value : t } ) : i [ e ] = t ;
3+ var u = ( i , e , t ) => ( I ( i , typeof e != "symbol" ? e + "" : e , t ) , t ) ;
4+ import { defineComponent as L , ref as d , onMounted as E , watchEffect as m , onUnmounted as O , openBlock as P , createElementBlock as X , normalizeStyle as y , createVNode as Y , Transition as V , withCtx as q , withDirectives as _ , createElementVNode as C , vShow as A } from "vue" ;
55class U {
66 constructor ( e , t , a ) {
7- l ( this , "canvasCtx" ) ;
7+ u ( this , "canvasCtx" ) ;
88 var n ;
99 this . canvas = e , this . props = t , this . filteredData = a , this . canvas = e , this . canvasCtx = ( n = this . canvas ) == null ? void 0 : n . getContext ( "2d" ) , this . props = t , this . filteredData = a ;
1010 }
@@ -32,12 +32,12 @@ class U {
3232 drawCanvasLines ( ) {
3333 const { canvas : e , canvasCtx : t , filteredData : a } = this ;
3434 a . forEach ( ( n , o ) => {
35- const c = e . width / a . length , r = c * o - c / 2 ;
35+ const c = e . width / a . length , l = c * o - c / 2 ;
3636 t . moveTo (
37- r ,
37+ l ,
3838 e . height / 2 - Math . abs ( n [ 0 ] ) * e . height * 0.4
3939 ) , t . lineTo (
40- r ,
40+ l ,
4141 e . height / 2 + Math . abs ( n [ 0 ] ) * e . height * 0.4
4242 ) ;
4343 } ) ;
@@ -57,40 +57,49 @@ class U {
5757}
5858class j {
5959 constructor ( e ) {
60- l ( this , "props" ) ;
61- l ( this , "audioCtx" ) ;
62- l ( this , "audioBuffer" ) ;
63- l ( this , "audioBufferSourceNode" ) ;
60+ u ( this , "props" ) ;
61+ u ( this , "audioCtx" ) ;
62+ u ( this , "audioBuffer" ) ;
63+ u ( this , "audioBufferSourceNode" ) ;
64+ u ( this , "filterData" ) ;
65+ u ( this , "response" ) ;
6466 this . props = e , this . audioCtx = new AudioContext ( ) ;
6567 }
6668 get _filterData ( ) {
67- return this . createFilterData ( ) ;
69+ return this . filterData ;
6870 }
6971 get _audioDuration ( ) {
7072 if ( ! this . audioBuffer )
7173 throw new Error ( "can not get duration before audio inited" ) ;
7274 return this . audioBuffer . duration ;
7375 }
7476 async setupAudio ( ) {
75- await this . createAudioBuffer ( ) ;
77+ await this . createAudioBuffer ( ) , this . createFilterData ( ) ;
78+ }
79+ async fetchAudioFile ( ) {
80+ try {
81+ this . response = await fetch ( this . props . url ) ;
82+ } catch ( e ) {
83+ console . error ( e ) ;
84+ }
7685 }
7786 async createAudioBuffer ( ) {
78- const t = await ( await fetch ( this . props . url ) ) . arrayBuffer ( ) ;
79- this . audioBuffer = await this . audioCtx . decodeAudioData ( t ) ;
87+ const e = await this . response . arrayBuffer ( ) ;
88+ this . audioBuffer = await this . audioCtx . decodeAudioData ( e ) ;
8089 }
8190 createFilterData ( ) {
8291 const e = this . props . samplingRate , t = this . audioBuffer . numberOfChannels , a = [ ] , n = [ ] ;
8392 for ( let o = 0 ; o < t ; o ++ )
8493 a . push ( this . audioBuffer . getChannelData ( o ) ) ;
8594 for ( let o = 0 ; o < e ; o ++ ) {
8695 const c = [ 0 , 0 ] ;
87- for ( let r = 0 ; r < t ; r ++ ) {
88- const u = Math . floor ( a [ r ] . length / e ) ;
89- c [ r ] = a [ r ] [ o * u ] ;
96+ for ( let l = 0 ; l < t ; l ++ ) {
97+ const r = Math . floor ( a [ l ] . length / e ) ;
98+ c [ l ] = a [ l ] [ o * r ] ;
9099 }
91100 n . push ( c ) ;
92101 }
93- return Promise . resolve ( n ) ;
102+ this . filterData = n ;
94103 }
95104 connectDestination ( ) {
96105 this . createAudioBufferSourceNode ( ) , this . disconnectDestination ( ) , this . audioBufferSourceNode . connect ( this . audioCtx . destination ) ;
@@ -105,10 +114,10 @@ class j {
105114class G extends j {
106115 constructor ( t ) {
107116 super ( t ) ;
108- l ( this , "startAt" ) ;
109- l ( this , "pauseAt" ) ;
110- l ( this , "pickAt" ) ;
111- l ( this , "playing" ) ;
117+ u ( this , "startAt" ) ;
118+ u ( this , "pauseAt" ) ;
119+ u ( this , "pickAt" ) ;
120+ u ( this , "playing" ) ;
112121 this . startAt = 0 , this . pauseAt = 0 , this . pickAt = 0 , this . playing = ! 1 ;
113122 }
114123 get _playing ( ) {
@@ -141,7 +150,7 @@ class G extends j {
141150 this . playing = ! 1 , this . startAt = 0 , this . pauseAt = 0 , this . pickAt = 0 ;
142151 }
143152}
144- function S ( i ) {
153+ function D ( i ) {
145154 const e = Math . floor ( i / 60 ) , t = Math . floor ( i % 60 ) ;
146155 return `${ e } :${ t < 10 ? "0" : "" } ${ t } ` ;
147156}
@@ -164,7 +173,7 @@ function Q(i, e) {
164173 } , e ) ) ;
165174 } ;
166175}
167- const Z = /* @__PURE__ */ $ ( {
176+ const Z = /* @__PURE__ */ L ( {
168177 __name : "IllestWaveform" ,
169178 props : {
170179 url : null ,
@@ -175,13 +184,14 @@ const Z = /* @__PURE__ */ $({
175184 cursorWidth : { default : 2 } ,
176185 cursorColor : { default : "#fff" } ,
177186 maskColor : { default : "#fff" } ,
178- lazy : { type : Boolean , default : ! 0 } ,
179- skeleton : { type : Boolean , default : ! 0 } ,
187+ lazy : { type : [ Boolean , null ] , default : ! 0 } ,
188+ skeleton : { type : [ Boolean , null ] , default : ! 0 } ,
180189 skeletonColor : { default : "#232323" } ,
181- interact : { type : Boolean , default : ! 0 }
190+ interact : { type : [ Boolean , null ] , default : ! 0 }
182191 } ,
183192 emits : [
184193 "onInit" ,
194+ "onFetched" ,
185195 "onReady" ,
186196 "onPlay" ,
187197 "onPause" ,
@@ -194,121 +204,122 @@ const Z = /* @__PURE__ */ $({
194204 a . lazy ? ( k ( o . value , c ) , J (
195205 o . value ,
196206 c
197- ) , g ( async ( ) => {
207+ ) , m ( async ( ) => {
198208 n . value && await x ( ) ;
199209 } ) ) : await x ( ) ;
200- } ) , P ( ( ) => {
210+ } ) , O ( ( ) => {
201211 a . lazy && K ( o . value , c ) ;
202212 } ) ;
203213 function c ( ) {
204214 n . value = ! 0 ;
205215 }
206- const r = d ( null ) , u = d ( ! 1 ) ;
207- let s , h ;
216+ const l = d ( null ) , r = d ( ! 1 ) ;
217+ let s , f ;
208218 async function x ( ) {
209- u . value || ( t ( "onInit" , ! 0 ) , await D ( ) , await Promise . all ( [ W ( ) ] ) , u . value = ! 0 , t ( "onReady" , u . value ) ) ;
219+ r . value || ( t ( "onInit" , ! 0 ) , await S ( ) , await W ( ) , r . value = ! 0 , t ( "onReady" , r . value ) ) ;
210220 }
211- async function D ( ) {
212- s = new G ( a ) , await s . setupAudio ( ) , z ( ) ;
221+ async function S ( ) {
222+ s = new G ( a ) , await s . fetchAudioFile ( ) , t ( "onFetched" , ! 0 ) , await s . setupAudio ( ) , R ( ) ;
213223 }
214224 async function W ( ) {
215- h = new U (
216- r . value ,
225+ f = new U (
226+ l . value ,
217227 a ,
218- await s . _filterData
219- ) , h . setupCanvas ( ) , g ( ( ) => {
220- h . _props = a , h . setWaveStyle ( w . value ) ;
228+ s . _filterData
229+ ) , f . setupCanvas ( ) , m ( ( ) => {
230+ f . _props = a , f . setWaveStyle ( w . value ) ;
221231 } ) ;
222232 }
223233 const v = d ( 0 ) , p = d ( 0 ) , w = d ( 0 ) ;
224- function C ( ) {
225- ! s . _playing || ( requestAnimationFrame ( C ) , p . value = s . _currentTime , w . value = p . value / s . _audioDuration * h . _canvas . width ) ;
234+ function g ( ) {
235+ ! s . _playing || ( requestAnimationFrame ( g ) , p . value = s . _currentTime , w . value = p . value / s . _audioDuration * f . _canvas . width ) ;
226236 }
227- function T ( f ) {
228- ! u . value || ! a . interact || ( f . layerX <= 0 ? v . value = 0 : f . layerX >= h . _canvas . width ? v . value = h . _canvas . width : v . value = f . layerX ) ;
237+ function T ( h ) {
238+ ! r . value || ! a . interact || ( h . layerX <= 0 ? v . value = 0 : h . layerX >= f . _canvas . width ? v . value = f . _canvas . width : v . value = h . layerX ) ;
229239 }
230- function b ( ) {
231- if ( ! u . value || ! a . interact )
240+ function N ( ) {
241+ if ( ! r . value || ! a . interact )
232242 return ;
233243 w . value = v . value ;
234- const f = v . value / h . _canvas . width * s . _audioDuration ;
235- s . pick ( f ) , p . value = f , t ( "onClick" , o ) , t ( "onFinish" , ! 1 ) ;
244+ const h = v . value / f . _canvas . width * s . _audioDuration ;
245+ s . pick ( h ) , p . value = h , t ( "onClick" , o ) , t ( "onFinish" , ! 1 ) ;
236246 }
237- function N ( ) {
238- ! u . value || ( s . play ( ) , t ( "onPlay" , ! 0 ) , C ( ) ) ;
247+ function b ( ) {
248+ ! r . value || ( s . play ( ) , t ( "onPlay" , ! 0 ) , g ( ) ) ;
239249 }
240- function M ( ) {
241- s . replay ( ) , t ( "onFinish" , ! 1 ) , t ( "onPlay" , ! 0 ) , C ( ) ;
250+ function F ( ) {
251+ s . replay ( ) , t ( "onFinish" , ! 1 ) , t ( "onPlay" , ! 0 ) , g ( ) ;
242252 }
243253 function B ( ) {
244254 s . pause ( ) , t ( "onPause" , ! 1 ) ;
245255 }
246- function R ( ) {
256+ function M ( ) {
247257 t ( "onFinish" , ! 0 ) ;
248258 }
249- function z ( ) {
250- g ( ( ) => {
251- p . value < s . _audioDuration || ( B ( ) , R ( ) ) ;
259+ function R ( ) {
260+ m ( ( ) => {
261+ p . value < s . _audioDuration || ( B ( ) , M ( ) ) ;
252262 } ) ;
253263 }
254- function H ( ) {
255- return S ( p . value ) ;
264+ function z ( ) {
265+ return D ( p . value ) ;
256266 }
257- function F ( ) {
258- const f = s . _audioDuration ;
259- return S ( f ) ;
267+ function H ( ) {
268+ const h = s . _audioDuration ;
269+ return D ( h ) ;
260270 }
261271 return e ( {
262- play : N ,
272+ play : b ,
263273 pause : B ,
264- replay : M ,
265- getCurrentTime : H ,
266- getDuration : F
267- } ) , ( f , at ) => ( O ( ) , X ( "section" , {
274+ replay : F ,
275+ getCurrentTime : z ,
276+ getDuration : H
277+ } ) , ( h , at ) => ( P ( ) , X ( "section" , {
268278 id : "illest-wave-container" ,
269279 ref_key : "waveformContainer" ,
270280 ref : o ,
281+ style : y ( `${ r . value && i . interact ? "cursor: pointer" : "" } ` ) ,
271282 onMousemove : T ,
272- onClick : b
283+ onClick : N
273284 } , [
274285 Y ( V , { name : "fade" } , {
275286 default : q ( ( ) => [
276- m ( y ( "div" , {
287+ _ ( C ( "div" , {
277288 id : "illest-skeleton" ,
278- style : _ ( `background-color: ${ i . skeletonColor } ` )
289+ style : y ( `background-color: ${ i . skeletonColor } ` )
279290 } , [
280- m ( y ( "div" , {
291+ _ ( C ( "div" , {
281292 id : "illest-skeleton__load" ,
282- style : _ ( `background-color: ${ i . skeletonColor } ` )
293+ style : y ( `background-color: ${ i . skeletonColor } ` )
283294 } , null , 4 ) , [
284- [ A , ! u . value ]
295+ [ A , ! r . value ]
285296 ] )
286297 ] , 4 ) , [
287- [ A , a . skeleton && ! u . value ]
298+ [ A , a . skeleton && ! r . value ]
288299 ] )
289300 ] ) ,
290301 _ : 1
291302 } ) ,
292- y ( "canvas" , {
303+ C ( "canvas" , {
293304 id : "illest-wave" ,
294305 ref_key : "waveRef" ,
295- ref : r
306+ ref : l
296307 } , null , 512 ) ,
297- m ( y ( "div" , {
308+ _ ( C ( "div" , {
298309 id : "illest-cursor" ,
299- style : _ ( `width:${ a . cursorWidth } px; transform: translateX(${ v . value } px);background-color: ${ a . cursorColor } ; ` )
310+ style : y ( `width:${ a . cursorWidth } px; transform: translateX(${ v . value } px);background-color: ${ a . cursorColor } ; ` )
300311 } , null , 4 ) , [
301- [ A , u . value && a . interact ]
312+ [ A , r . value && a . interact ]
302313 ] )
303- ] , 544 ) ) ;
314+ ] , 36 ) ) ;
304315 }
305316} ) ;
306317const tt = ( i , e ) => {
307318 const t = i . __vccOpts || i ;
308319 for ( const [ a , n ] of e )
309320 t [ a ] = n ;
310321 return t ;
311- } , et = /* @__PURE__ */ tt ( Z , [ [ "__scopeId" , "data-v-d8823252 " ] ] ) , ot = {
322+ } , et = /* @__PURE__ */ tt ( Z , [ [ "__scopeId" , "data-v-10d3d361 " ] ] ) , ot = {
312323 install : ( i ) => {
313324 i . component ( "IllestWaveform" , et ) ;
314325 }
0 commit comments