PageSourceSearch

https://svelte-audio-ui.vercel.app/_app/immutable/chunks/CMqz74XS.js

js svelte-audio-ui.vercel.app collected 2026-10-03 07:50:20 UTC 12,660 bytes, 1 lines download raw bytes

1import{i as u,j as n,g as a,M as b}from"./DAU-i0I7.js";class L{audio=null;isInitialized=!1;playPromise=null;lastVolume=1;fadeTimeout=null;retryAttempts=0;maxRetries=3;eventTarget=new EventTarget;LOAD_TIMEOUT_LIVE=6e4;LOAD_TIMEOUT_NORMAL=3e4;FADE_UPDATE_INTERVAL=16;init(){this.isInitialized||!this.isClient()||(this.isInitialized=!0,this.isClient()&&(this.audio=new Audio,this.setupEventListeners()))}setupEventListeners(){if(!this.isClient())return;const e=this.ensureAudio();e&&(e.addEventListener("error",()=>{this.retryAttempts<this.maxRetries&&(this.retryAttempts++,setTimeout(()=>this.reloadAudio(),1e3)),this.eventTarget.dispatchEvent(new CustomEvent("audioError"))}),e.addEventListener("playing",()=>{this.retryAttempts=0,this.eventTarget.dispatchEvent(new CustomEvent("bufferingEnd")),this.eventTarget.dispatchEvent(new CustomEvent("playbackStarted"))}),e.addEventListener("canplaythrough",()=>{this.retryAttempts=0,this.eventTarget.dispatchEvent(new CustomEvent("bufferingEnd"))}),e.addEventListener("waiting",()=>{this.eventTarget.dispatchEvent(new CustomEvent("bufferingStart"))}),e.addEventListener("progress",()=>{const t=e.buffered,i=e.currentTime;let r=0;if(t.length!==0){for(let s=t.length-1;s>=0;s--)if(t.start(s)<=i){r=t.end(s);break}r===0&&(r=t.end(0)),r>0&&this.eventTarget.dispatchEvent(new CustomEvent("bufferUpdate",{detail:{bufferedTime:r}}))}}))}cleanup(){this.audio&&(this.audio.pause(),this.audio.src="",this.audio.load()),this.fadeTimeout&&(clearTimeout(this.fadeTimeout),this.fadeTimeout=null),this.playPromise=null}getAudioElement(){return this.isClient()?this.audio:null}isClient(){return typeof window<"u"&&!!window.document}ensureAudio(){if(!this.isClient())throw new Error("Audio module not available on server side");if(!this.audio)throw new Error("Audio module not initialized");return this.audio}ifClient(e){if(this.isClient())return e()}async load(e){const{url:t,startTime:i=0,isLiveStream:r=!1}=e,s=this.ifClient(()=>this._load({url:t,startTime:i,isLiveStream:r}));s&&await s}async _load(e){const{url:t,startTime:i,isLiveStream:r}=e,s=this.ensureAudio();if(s)try{if(this.retryAttempts=0,s.src===t){s.currentTime!==i&&!r&&(s.currentTime=i);return}s.pause(),s.src="",s.src=t,s.preload="auto";const h=r?this.LOAD_TIMEOUT_LIVE:this.LOAD_TIMEOUT_NORMAL;await new Promise((g,f)=>{let l=null,d=!1;const T=()=>{l&&(clearTimeout(l),l=null),s.removeEventListener("loadedmetadata",c),s.removeEventListener("canplay",c),s.removeEventListener("canplaythrough",c),s.removeEventListener("error",p)},I=()=>{d||(d=!0,T(),f(new Error(`Audio load timeout (${h/1e3}s)`)))},c=()=>{d||(d=!0,T(),i>0&&!r&&(s.currentTime=i),g())},p=()=>{if(d)return;d=!0,T();const v=s.error;f(new Error(`Audio load failed: ${v?.message||`code ${v?.code??"unknown"}`}`))};l=setTimeout(I,h),s.addEventListener("loadedmetadata",c),s.addEventListener("canplay",c),s.addEventListener("canplaythrough",c),s.addEventListener("error",p),s.load()})}catch(h){throw console.error("Audio load process error:",h),h}}async play(){const e=this.ifClient(()=>this._play());e&&await e}async _play(){if(!this.audio)throw new Error("Audio module not initialized");try{if(!this.audio.paused)return;this.playPromise=this.audio.play(),await this.playPromise,this.playPromise=null}catch(e){throw this.playPromise=null,e}}reloadAudio(){if(!this.isClient())return;const e=this.ensureAudio(),t=e.currentTime,i=!e.paused,r=e.src;e.pause(),e.src="",e.load(),e.src=r,e.preload="auto",e.load();const s=()=>{e.readyState>=e.HAVE_METADATA&&(e.currentTime=t,i&&this.play().catch(()=>{}),e.removeEventListener("loadedmetadata",s))};e.addEventListener("loadedmetadata",s)}pause(){this.ifClient(()=>{this.ensureAudio().pause()})}setVolume(e){const{volume:t,fadeTime:i=0}=e;this.ifClient(()=>{const r=this.ensureAudio();if(this.fadeTimeout&&(clearTimeout(this.fadeTimeout),this.fadeTimeout=null),i<=0){r.volume=Math.max(0,Math.min(1,t)),t>0&&(this.lastVolume=t);return}this.fadeVolume({audio:r,targetVolume:t,duration:i})})}fadeVolume(e){const{audio:t,targetVolume:i,duration:r}=e;if(!this.isClient())return;const s=t.volume,h=Math.max(0,Math.min(1,i)),g=performance.now(),f=()=>{const l=performance.now()-g,d=Math.min(1,l/r);t.volume=s+(h-s)*d,d<1?this.fadeTimeout=setTimeout(f,this.FADE_UPDATE_INTERVAL):(h>0&&(this.lastVolume=h),this.fadeTimeout=null)};f()}getVolume(){return this.ifClient(()=>this.ensureAudio().volume)??0}setMuted(e){this.ifClient(()=>{const t=this.ensureAudio();t.muted!==e&&(e?(t.volume>0&&(this.lastVolume=t.volume),this.fadeVolume({audio:t,targetVolume:0,duration:200}),t.muted=!0):(t.muted=!1,this.fadeVolume({audio:t,targetVolume:this.lastVolume,duration:200})))})}getDuration(){return this.ifClient(()=>this.ensureAudio().duration)??0}getCurrentTime(){return this.ifClient(()=>this.ensureAudio().currentTime)??0}setCurrentTime(e){this.ifClient(()=>{const t=this.ensureAudio(),i=t.duration;if(Number.isNaN(i))return;const r=e>=0&&e<=i?e:Math.max(0,Math.min(e,i));t.readyState>=t.HAVE_METADATA&&(t.currentTime=r)})}addEventListener(e,t,i){this.eventTarget.addEventListener(e,t,i)}removeEventListener(e,t,i){this.eventTarget.removeEventListener(e,t,i)}getSource(){return this.ifClient(()=>this.ensureAudio().src)??""}isPaused(){return this.ifClient(()=>this.ensureAudio().paused)??!0}getBufferedRanges(){return!this.isClient()||!this.audio?null:this.audio.buffered}setPlaybackRate(e){this.ifClient(()=>{const t=this.ensureAudio();this.isLive(t.duration)||(t.playbackRate=Math.max(.25,Math.min(2,e)))})}getPlaybackRate(){return this.ifClient(()=>this.ensureAudio().playbackRate)??1}isLive(e){return e===0?!1:Number.isNaN(e)||e===Number.POSITIVE_INFINITY||e===Number.NEGATIVE_INFINITY}}const m=new L,E=60;function P(o){if(!Number.isFinite(o)||o<0)return"0:00";const e=Math.floor(o/E),t=Math.floor(o%E);return`${e}:${t<10?"0":""}${t}`}function y(){return typeof window<"u"&&!!window.document?.createElement}function x(o,e){if(o===1)return 0;let t;do t=Math.floor(Math.random()*o);while(t===e);return t}function A(o){const{queue:e,currentQueueIndex:t,shuffleEnabled:i,repeatMode:r,direction:s}=o;if(e.length===0)return-1;if(i)return e.length===1?r==="none"?-1:0:x(e.length,t);const h=t+s;return h>=e.length?r==="all"?0:-1:h<0?r==="all"?e.length-1:-1:h}function w(o){return A({...o,direction:1})}function q(o){return A({...o,direction:-1})}const M="audio:ui:store";class Q{#e=u(null);get currentTrack(){return n(this.#e)}set currentTrack(e){a(this.#e,e,!0)}#t=u(b([]));get queue(){return n(this.#t)}set queue(e){a(this.#t,e,!0)}#i=u(!1);get isPlaying(){return n(this.#i)}set isPlaying(e){a(this.#i,e,!0)}#r=u(!1);get isLoading(){return n(this.#r)}set isLoading(e){a(this.#r,e,!0)}#s=u(!1);get isBuffering(){return n(this.#s)}set isBuffering(e){a(this.#s,e,!0)}#u=u(1);get volume(){return n(this.#u)}set volume(e){a(this.#u,e,!0)}#n=u(!1);get isMuted(){return n(this.#n)}set isMuted(e){a(this.#n,e,!0)}#a=u(1);get playbackRate(){return n(this.#a)}set playbackRate(e){a(this.#a,e,!0)}#o=u("none");get repeatMode(){return n(this.#o)}set repeatMode(e){a(this.#o,e,!0)}#h=u(!1);get shuffleEnabled(){return n(this.#h)}set shuffleEnabled(e){a(this.#h,e,!0)}#d=u(0);get currentTime(){return n(this.#d)}set currentTime(e){a(this.#d,e,!0)}#l=u(0);get duration(){return n(this.#l)}set duration(e){a(this.#l,e,!0)}#c=u(0);get progress(){return n(this.#c)}set progress(e){a(this.#c,e,!0)}#f=u(0);get bufferedTime(){return n(this.#f)}set bufferedTime(e){a(this.#f,e,!0)}#m=u("last");get insertMode(){return n(this.#m)}set insertMode(e){a(this.#m,e,!0)}#g=u(!1);get isError(){return n(this.#g)}set isError(e){a(this.#g,e,!0)}#T=u(null);get errorMessage(){return n(this.#T)}
1set errorMessage(e){a(this.#T,e,!0)}#p=u(-1);get currentQueueIndex(){return n(this.#p)}set currentQueueIndex(e){a(this.#p,e,!0)}constructor(){y()&&this.loadFromStorage()}loadFromStorage(){try{const e=localStorage.getItem(M);if(!e)return;const t=JSON.parse(e);t.currentTrack!==void 0&&(this.currentTrack=t.currentTrack),t.queue!==void 0&&(this.queue=t.queue),t.volume!==void 0&&(this.volume=t.volume),t.isMuted!==void 0&&(this.isMuted=t.isMuted),t.playbackRate!==void 0&&(this.playbackRate=t.playbackRate),t.repeatMode!==void 0&&(this.repeatMode=t.repeatMode),t.shuffleEnabled!==void 0&&(this.shuffleEnabled=t.shuffleEnabled),t.currentTime!==void 0&&(this.currentTime=t.currentTime),t.insertMode!==void 0&&(this.insertMode=t.insertMode),t.currentQueueIndex!==void 0&&(this.currentQueueIndex=t.currentQueueIndex),this.duration>0&&(this.progress=this.currentTime/this.duration*100)}catch{}}saveToStorage(){if(y())try{localStorage.setItem(M,JSON.stringify({currentTrack:this.currentTrack,queue:this.queue,volume:this.volume,isMuted:this.isMuted,playbackRate:this.playbackRate,repeatMode:this.repeatMode,shuffleEnabled:this.shuffleEnabled,currentTime:this.currentTime,insertMode:this.insertMode,currentQueueIndex:this.currentQueueIndex}))}catch{}}play(){this.isLoading||(this.isPlaying=!0,m.play().catch(()=>{}))}pause(){this.isPlaying=!1,m.pause()}togglePlay(){this.isLoading||(this.isPlaying?this.pause():this.play())}seek(e){const t=this.duration>0?Math.max(0,Math.min(e,this.duration)):e;this.currentTime=t,this.progress=this.duration>0?t/this.duration*100:0}next(){const e=w({queue:this.queue,currentQueueIndex:this.currentQueueIndex,shuffleEnabled:this.shuffleEnabled,repeatMode:this.repeatMode}),t=this.queue[e];if(e===-1||!t){this.isLoading=!1,this.isPlaying=!1,this.isBuffering=!1;return}this.loadAndPlayTrack(t,e)}previous(){if(this.currentTime>3&&!this.shuffleEnabled){this.currentTime=0,this.progress=0;return}const e=q({queue:this.queue,currentQueueIndex:this.currentQueueIndex,shuffleEnabled:this.shuffleEnabled,repeatMode:this.repeatMode}),t=this.queue[e];if(e===-1||!t){this.isLoading=!1,this.isPlaying=!1,this.isBuffering=!1;return}this.loadAndPlayTrack(t,e)}setQueueAndPlay(e,t){const i=e[t];if(!i){this.clearQueue(),this.isPlaying=!1,this.isLoading=!1,this.currentTrack=null,this.currentQueueIndex=-1;return}this.setQueue(e,t),this.loadAndPlayTrack(i,t)}handleTrackEnd(){this.next()}setQueue(e,t=0){const i=e[t]??null;this.queue=e,this.currentQueueIndex=i?t:-1,this.currentTrack=i}getCurrentQueueIndex(){return this.currentQueueIndex}addToQueue(e,t="last"){if(!this.currentTrack){this.currentTrack=e,this.currentQueueIndex=0,this.queue=[e];return}switch(t){case"first":this.queue=[e,...this.queue],this.currentQueueIndex++;break;case"after":this.queue=[...this.queue.slice(0,this.currentQueueIndex+1),e,...this.queue.slice(this.currentQueueIndex+1)];break;default:this.queue=[...this.queue,e]}}removeFromQueue(e){const t=this.queue.findIndex(i=>i.id===e);t!==-1&&(this.queue=this.queue.filter(i=>i.id!==e),t<this.currentQueueIndex&&this.currentQueueIndex--)}clearQueue(){this.queue=[]}moveInQueue(e,t){const i=[...this.queue],[r]=i.splice(e,1);r&&(i.splice(t,0,r),this.queue=i)}addTracksToEndOfQueue(e){if(!e?.length)return;const t=new Set(this.queue.map(r=>r.id)),i=e.filter(r=>!t.has(r.id));i.length&&(this.queue=[...this.queue,...i])}setVolume(e){this.volume=e.volume,this.isMuted=e.volume===0}toggleMute(){this.isMuted=!this.isMuted}setPlaybackRate(e){this.duration&&m.isLive(this.duration)||(this.playbackRate=Math.max(.25,Math.min(2,e)))}changeRepeatMode(){const e=["none","one","all"],t=e.indexOf(this.repeatMode);this.repeatMode=e[(t+1)%e.length]}setRepeatMode(e){this.repeatMode=e}setInsertMode(e){this.insertMode=e}shuffle(){if(!this.queue.length||this.queue.length<2||!this.currentTrack)return;const t=[...this.queue.filter((i,r)=>r!==this.currentQueueIndex)];for(let i=t.length-1;i>0;i--){const r=Math.floor(Math.random()*(i+1));[t[i],t[r]]=[t[r],t[i]]}this.queue=[this.currentTrack,...t],this.currentQueueIndex=0,this.shuffleEnabled=!0}unshuffle(){this.shuffleEnabled=!1}setCurrentTrack(e){if(!e){this.currentTrack=null,this.currentQueueIndex=-1,this.isPlaying=!1,this.currentTime=0,this.duration=0,this.queue=[],this.isLoading=!1,this.isError=!1,this.errorMessage=null;return}this.currentTrack?.id!==e.id&&(this.currentTrack=e,this.queue=[e],this.currentQueueIndex=0,this.isLoading=!0,this.isPlaying=!1,this.currentTime=0,this.duration=0,this.isError=!1,this.errorMessage=null,this.loadAndPlayTrack(e,0))}syncTime(e,t){this.currentTime=e,this.duration=t,this.progress=t>0?e/t*100:0}setError(e){this.isError=!!e,this.errorMessage=e,this.isLoading=!1,this.isPlaying=!1}loadAndPlayTrack(e,t){const i=e.live===!0||e.duration!==void 0&&m.isLive(e.duration);this.currentTrack=e,this.currentQueueIndex=t,this.isError=!1,this.errorMessage=null,i&&this.playbackRate!==1&&(this.playbackRate=1),this.isLoading=!1,this.isBuffering=!1,this.isPlaying=!0}}const C=new Q;export{C as a,w as c,P as f,m as h};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.