11var L = Object . defineProperty ;
2- var M = ( i , e , t ) => e in i ? L ( i , e , { enumerable : ! 0 , configurable : ! 0 , writable : ! 0 , value : t } ) : i [ e ] = t ;
3- var o = ( i , e , t ) => ( M ( i , typeof e != "symbol" ? e + "" : e , t ) , t ) ;
4- import { defineComponent as G , ref as h , onMounted as H , watchEffect as w , onUnmounted as O , openBlock as $ , createElementBlock as V , normalizeStyle as y , createVNode as P , Transition as U , withCtx as X , withDirectives as C , createElementVNode as g , vShow as A } from "vue" ;
5- class Y {
6- constructor ( e , t , a ) {
7- o ( this , "canvasCtx" ) ;
2+ var M = ( a , e , t ) => e in a ? L ( a , e , { enumerable : ! 0 , configurable : ! 0 , writable : ! 0 , value : t } ) : a [ e ] = t ;
3+ var s = ( a , e , t ) => ( M ( a , typeof e != "symbol" ? e + "" : e , t ) , t ) ;
4+ import { defineComponent as O , ref as h , onMounted as G , watchEffect as g , onUnmounted as $ , openBlock as V , createElementBlock as P , normalizeStyle as y , createVNode as U , Transition as X , withCtx as H , withDirectives as w , createElementVNode as m , vShow as A } from "vue" ;
5+ class q {
6+ constructor ( e , t , i ) {
7+ s ( this , "canvasCtx" ) ;
88 var n ;
9- 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 ;
9+ this . canvas = e , this . props = t , this . filteredData = i , this . canvas = e , this . canvasCtx = ( n = this . canvas ) == null ? void 0 : n . getContext ( "2d" ) , this . props = t , this . filteredData = i ;
1010 }
1111 get _canvas ( ) {
1212 return this . canvas ;
@@ -30,39 +30,39 @@ class Y {
3030 ) ;
3131 }
3232 drawCanvasLines ( ) {
33- const { canvas : e , canvasCtx : t , filteredData : a } = this ;
34- a . forEach ( ( n , u ) => {
35- const c = e . width / a . length , p = c * u - c / 2 ;
33+ const { canvas : e , canvasCtx : t , filteredData : i } = this ;
34+ i . forEach ( ( n , c ) => {
35+ const d = e . width / i . length , v = d * c - d / 2 ;
3636 t . moveTo (
37- p ,
37+ v ,
3838 e . height / 2 - Math . abs ( n ) * e . height * 0.4
3939 ) , t . lineTo (
40- p ,
40+ v ,
4141 e . height / 2 + Math . abs ( n ) * e . height * 0.4
4242 ) ;
4343 } ) ;
4444 }
4545 drawMask ( e ) {
46- const { canvas : t , canvasCtx : a , props : n } = this ;
47- a . globalCompositeOperation = "destination-atop" , a . fillStyle = n . maskColor , a . fillRect ( 0 , 0 , e , t . height ) ;
46+ const { canvas : t , canvasCtx : i , props : n } = this ;
47+ i . globalCompositeOperation = "destination-atop" , i . fillStyle = n . maskColor , i . fillRect ( 0 , 0 , e , t . height ) ;
4848 }
4949 drawWave ( ) {
5050 const { canvasCtx : e , props : t } = this ;
5151 e . lineWidth = t . lineWidth , e . lineCap = t . lineCap , e . strokeStyle = t . lineColor , e . stroke ( ) ;
5252 }
5353 setWaveStyle ( e ) {
54- const { canvas : t , canvasCtx : a } = this ;
55- a . clearRect ( 0 , 0 , t . width , t . height ) , this . drawMask ( e ) , this . drawWave ( ) ;
54+ const { canvas : t , canvasCtx : i } = this ;
55+ i . clearRect ( 0 , 0 , t . width , t . height ) , this . drawMask ( e ) , this . drawWave ( ) ;
5656 }
5757}
58- class q {
58+ class Y {
5959 constructor ( e ) {
60- o ( this , "props" ) ;
61- o ( this , "audioCtx" ) ;
62- o ( this , "audioBuffer" ) ;
63- o ( this , "gainNode" ) ;
64- o ( this , "filteredData" ) ;
65- o ( this , "arrayBuffer" ) ;
60+ s ( this , "props" ) ;
61+ s ( this , "audioCtx" ) ;
62+ s ( this , "audioBuffer" ) ;
63+ s ( this , "gainNode" ) ;
64+ s ( this , "filteredData" ) ;
65+ s ( this , "arrayBuffer" ) ;
6666 this . props = e , this . audioCtx = new AudioContext ( ) ;
6767 }
6868 get _filteredData ( ) {
@@ -91,26 +91,26 @@ class q {
9191 this . gainNode = this . audioCtx . createGain ( ) , this . gainNode . gain . setValueAtTime ( 0 , this . audioCtx . currentTime ) ;
9292 }
9393 createFilterData ( ) {
94- const e = this . props . samplingRate , t = [ ] , a = this . audioBuffer . getChannelData ( 0 ) ;
94+ const e = this . props . samplingRate , t = [ ] , i = this . audioBuffer . getChannelData ( 0 ) ;
9595 for ( let n = 0 ; n < e ; n ++ ) {
96- const u = Math . floor ( a . length / e ) , c = a [ n * u ] ;
97- t . push ( c ) ;
96+ const c = Math . floor ( i . length / e ) , d = i [ n * c ] ;
97+ t . push ( d ) ;
9898 }
9999 this . filteredData = t ;
100100 }
101101}
102- function j ( i ) {
103- return new Promise ( ( e ) => setTimeout ( e , i ) ) ;
102+ function j ( a ) {
103+ return new Promise ( ( e ) => setTimeout ( e , a ) ) ;
104104}
105- class J extends q {
105+ class J extends Y {
106106 constructor ( t ) {
107107 super ( t ) ;
108- o ( this , "startAt" ) ;
109- o ( this , "pauseAt" ) ;
110- o ( this , "pickAt" ) ;
111- o ( this , "playing" ) ;
112- o ( this , "audioBufferSourceNode" ) ;
113- o ( this , "FADE_DURATION" ) ;
108+ s ( this , "startAt" ) ;
109+ s ( this , "pauseAt" ) ;
110+ s ( this , "pickAt" ) ;
111+ s ( this , "playing" ) ;
112+ s ( this , "audioBufferSourceNode" ) ;
113+ s ( this , "FADE_DURATION" ) ;
114114 this . startAt = 0 , this . pauseAt = 0 , this . pickAt = 0 , this . playing = ! 1 , this . FADE_DURATION = this . props . fade ? 0.08 : 0 ;
115115 }
116116 get _playing ( ) {
@@ -159,30 +159,42 @@ class J extends q {
159159 ) ;
160160 }
161161}
162- function x ( i ) {
163- const e = Math . floor ( i / 60 ) , t = Math . floor ( i % 60 ) ;
162+ function x ( a ) {
163+ const e = Math . floor ( a / 60 ) , t = Math . floor ( a % 60 ) ;
164164 return `${ e } :${ t < 10 ? "0" : "" } ${ t } ` ;
165165}
166- function K ( i , e ) {
167- const t = Z ( ( ) => D ( i , e ) , 500 ) ;
168- document . addEventListener ( "scroll" , ( ) => t ( ) ) ;
169- }
170- function Q ( i , e ) {
171- document . removeEventListener ( "scroll" , ( ) => D ( i , e ) ) ;
166+ class K {
167+ constructor ( e , t ) {
168+ s ( this , "el" ) ;
169+ s ( this , "handler" ) ;
170+ s ( this , "intersectionObserver" ) ;
171+ s ( this , "timer" ) ;
172+ s ( this , "rended" ) ;
173+ this . el = e , this . handler = t , this . timer = null , this . rended = ! 1 ;
174+ }
175+ observe ( ) {
176+ const e = ( t ) => {
177+ if ( this . rended )
178+ return this . unobserve ( ) ;
179+ const i = t [ 0 ] , n = 260 ;
180+ i . intersectionRatio > 0 ? this . timer = setTimeout ( ( ) => {
181+ this . handler ( ) , this . rended = ! 0 ;
182+ } , n ) : this . timer && ( clearTimeout ( this . timer ) , this . timer = null ) ;
183+ } ;
184+ this . intersectionObserver = new IntersectionObserver ( e ) , this . intersectionObserver . observe ( this . el ) ;
185+ }
186+ unobserve ( ) {
187+ this . intersectionObserver . unobserve ( this . el ) ;
188+ }
172189}
173- function D ( i , e ) {
174- const t = window . innerHeight , a = window . scrollY , n = window . pageYOffset + i . getBoundingClientRect ( ) . top ;
175- n >= a - t / 4 && n - a - t < t / 4 && e ( ) ;
190+ let D ;
191+ function Q ( a , e ) {
192+ D = new K ( a , e ) , D . observe ( ) ;
176193}
177- function Z ( i , e ) {
178- let t ;
179- return ( ) => {
180- t || ( t = setTimeout ( ( ) => {
181- i ( ) , t = void 0 ;
182- } , e ) ) ;
183- } ;
194+ function Z ( ) {
195+ D . unobserve ( ) ;
184196}
185- const tt = /* @__PURE__ */ G ( {
197+ const tt = /* @__PURE__ */ O ( {
186198 __name : "IllestWaveform" ,
187199 props : {
188200 url : null ,
@@ -208,136 +220,130 @@ const tt = /* @__PURE__ */ G({
208220 "onFinish" ,
209221 "onClick"
210222 ] ,
211- setup ( i , { expose : e , emit : t } ) {
212- const a = i , n = h ( ! 1 ) , u = h ( null ) ;
213- H ( async ( ) => {
214- a . lazy ? ( D ( u . value , c ) , K (
215- u . value ,
216- c
217- ) , w ( async ( ) => {
223+ setup ( a , { expose : e , emit : t } ) {
224+ const i = a , n = h ( ! 1 ) , c = h ( null ) ;
225+ G ( async ( ) => {
226+ i . lazy ? ( Q ( c . value , d ) , g ( async ( ) => {
218227 n . value && await k ( ) ;
219228 } ) ) : await k ( ) ;
220- } ) , O ( ( ) => {
221- a . lazy && Q (
222- u . value ,
223- c
224- ) ;
229+ } ) , $ ( ( ) => {
230+ i . lazy && Z ( ) , o && o . pause ( ) ;
225231 } ) ;
226- function c ( ) {
232+ function d ( ) {
227233 n . value = ! 0 ;
228234 }
229- const p = h ( null ) , r = h ( ! 1 ) ;
230- let s , f ;
235+ const v = h ( null ) , r = h ( ! 1 ) ;
236+ let o , l ;
231237 async function k ( ) {
232238 r . value || ( t ( "onInit" , ! 0 ) , await B ( ) , await T ( ) , r . value = ! 0 , t ( "onReady" , r . value ) ) ;
233239 }
234240 async function B ( ) {
235- s = new J ( a ) , await s . fetchAudioFile ( ) , t ( "onFetched" , ! 0 ) , await s . setupAudio ( ) , I ( ) ;
241+ o = new J ( i ) , await o . fetchAudioFile ( ) , t ( "onFetched" , ! 0 ) , await o . setupAudio ( ) , I ( ) ;
236242 }
237243 async function T ( ) {
238- f = new Y (
239- p . value ,
240- a ,
241- s . _filteredData
242- ) , f . setupCanvas ( ) , w ( ( ) => {
243- f . _props = a , f . setWaveStyle ( m . value ) ;
244+ l = new q (
245+ v . value ,
246+ i ,
247+ o . _filteredData
248+ ) , l . setupCanvas ( ) , g ( ( ) => {
249+ l . _props = i , l . setWaveStyle ( _ . value ) ;
244250 } ) ;
245251 }
246- const d = h ( 0 ) , v = h ( 0 ) , m = h ( 0 ) ;
247- function _ ( ) {
248- ! s . _playing || ( requestAnimationFrame ( _ ) , v . value = s . _currentTime , m . value = v . value / s . _audioDuration * f . _canvas . width ) ;
252+ const f = h ( 0 ) , p = h ( 0 ) , _ = h ( 0 ) ;
253+ function C ( ) {
254+ ! o . _playing || ( requestAnimationFrame ( C ) , p . value = o . _currentTime , _ . value = p . value / o . _audioDuration * l . _canvas . width ) ;
249255 }
250- function N ( l ) {
251- ! r . value || ! a . interact || ( l . layerX <= 0 ? d . value = 0 : l . layerX >= f . _canvas . width ? d . value = f . _canvas . width : d . value = l . layerX ) ;
256+ function N ( u ) {
257+ ! r . value || ! i . interact || ( u . layerX <= 0 ? f . value = 0 : u . layerX >= l . _canvas . width ? f . value = l . _canvas . width : f . value = u . layerX ) ;
252258 }
253259 function S ( ) {
254- if ( ! r . value || ! a . interact )
260+ if ( ! r . value || ! i . interact )
255261 return ;
256- m . value = d . value ;
257- const l = d . value / f . _canvas . width * s . _audioDuration ;
258- s . pick ( l ) , v . value = l , t ( "onClick" , u ) , t ( "onFinish" , ! 1 ) ;
262+ _ . value = f . value ;
263+ const u = f . value / l . _canvas . width * o . _audioDuration ;
264+ o . pick ( u ) , p . value = u , t ( "onClick" , c ) , t ( "onFinish" , ! 1 ) ;
265+ }
266+ function b ( ) {
267+ ! r . value || ( o . play ( ) , t ( "onPlay" , ! 0 ) , C ( ) ) ;
259268 }
260269 function W ( ) {
261- ! r . value || ( s . play ( ) , t ( "onPlay" , ! 0 ) , _ ( ) ) ;
270+ o . replay ( ) , t ( "onFinish" , ! 1 ) , t ( "onPlay" , ! 0 ) , C ( ) ;
262271 }
263272 function R ( ) {
264- s . replay ( ) , t ( "onFinish " , ! 1 ) , t ( "onPlay" , ! 0 ) , _ ( ) ;
273+ o . pause ( ) , t ( "onPause " , ! 1 ) ;
265274 }
266275 function F ( ) {
267- s . pause ( ) , t ( "onPause" , ! 1 ) ;
268- }
269- function b ( ) {
270- s . finish ( ) , t ( "onPlay" , ! 1 ) , t ( "onFinish" , ! 0 ) ;
276+ o . finish ( ) , t ( "onPlay" , ! 1 ) , t ( "onFinish" , ! 0 ) ;
271277 }
272278 function I ( ) {
273- w ( ( ) => {
274- v . value <= s . _audioDuration || b ( ) ;
279+ g ( ( ) => {
280+ p . value <= o . _audioDuration || F ( ) ;
275281 } ) ;
276282 }
277- function E ( ) {
278- return x ( v . value ) ;
279- }
280283 function z ( ) {
281- const l = s . _audioDuration ;
282- return x ( l ) ;
284+ return x ( p . value ) ;
285+ }
286+ function E ( ) {
287+ const u = o . _audioDuration ;
288+ return x ( u ) ;
283289 }
284290 return e ( {
285- play : W ,
286- pause : F ,
287- replay : R ,
288- getCurrentTime : E ,
289- getDuration : z
290- } ) , ( l , it ) => ( $ ( ) , V ( "section" , {
291+ play : b ,
292+ pause : R ,
293+ replay : W ,
294+ getCurrentTime : z ,
295+ getDuration : E
296+ } ) , ( u , at ) => ( V ( ) , P ( "section" , {
291297 id : "illest-waveform" ,
292298 ref_key : "__illestWaveformRef__" ,
293- ref : u ,
294- style : y ( `${ r . value && i . interact ? "cursor: pointer" : "" } ` ) ,
299+ ref : c ,
300+ style : y ( `${ r . value && a . interact ? "cursor: pointer" : "" } ` ) ,
295301 onMousemove : N ,
296302 onClick : S
297303 } , [
298- P ( U , { name : "fade" } , {
299- default : X ( ( ) => [
300- C ( g ( "div" , {
304+ U ( X , { name : "fade" } , {
305+ default : H ( ( ) => [
306+ w ( m ( "div" , {
301307 id : "illest-waveform__skeleton" ,
302- style : y ( `background-color: ${ i . skeletonColor } ` )
308+ style : y ( `background-color: ${ a . skeletonColor } ` )
303309 } , [
304- C ( g ( "div" , {
310+ w ( m ( "div" , {
305311 id : "illest-waveform__skeleton__load" ,
306- style : y ( `background-color: ${ i . skeletonColor } ` )
312+ style : y ( `background-color: ${ a . skeletonColor } ` )
307313 } , null , 4 ) , [
308314 [ A , ! r . value ]
309315 ] )
310316 ] , 4 ) , [
311- [ A , a . skeleton && ! r . value ]
317+ [ A , i . skeleton && ! r . value ]
312318 ] )
313319 ] ) ,
314320 _ : 1
315321 } ) ,
316- g ( "canvas" , {
322+ m ( "canvas" , {
317323 id : "illest-waveform__view" ,
318324 ref_key : "waveRef" ,
319- ref : p
325+ ref : v
320326 } , null , 512 ) ,
321- C ( g ( "div" , {
327+ w ( m ( "div" , {
322328 id : "illest-waveform__cursor" ,
323- style : y ( `width:${ a . cursorWidth } px; transform: translateX(${ d . value } px);background-color: ${ a . cursorColor } ; ` )
329+ style : y ( `width:${ i . cursorWidth } px; transform: translateX(${ f . value } px);background-color: ${ i . cursorColor } ; ` )
324330 } , null , 4 ) , [
325- [ A , r . value && a . interact ]
331+ [ A , r . value && i . interact ]
326332 ] )
327333 ] , 36 ) ) ;
328334 }
329335} ) ;
330- const et = ( i , e ) => {
331- const t = i . __vccOpts || i ;
332- for ( const [ a , n ] of e )
333- t [ a ] = n ;
336+ const et = ( a , e ) => {
337+ const t = a . __vccOpts || a ;
338+ for ( const [ i , n ] of e )
339+ t [ i ] = n ;
334340 return t ;
335- } , at = /* @__PURE__ */ et ( tt , [ [ "__scopeId" , "data-v-bff6afca " ] ] ) , ot = {
336- install : ( i ) => {
337- i . component ( "IllestWaveform" , at ) ;
341+ } , it = /* @__PURE__ */ et ( tt , [ [ "__scopeId" , "data-v-6d613eae " ] ] ) , ot = {
342+ install : ( a ) => {
343+ a . component ( "IllestWaveform" , it ) ;
338344 }
339345} ;
340346export {
341- at as IllestWaveform ,
347+ it as IllestWaveform ,
342348 ot as default
343349} ;
0 commit comments