import{n as e}from"./rolldown-runtime-DAXXjFlN.js";import{Bi as t,Dt as n,Mi as r,Ot as i,ji as a,x as o,y as s,zi as c}from"./ws-DjAvcWfg.js";var l,u=e((()=>{l=``+new URL(`shuffle-rApL6oT7.mp3`,import.meta.url).href}));function d(){return s().accessibility?.sounds?.enabled===!0}function f(){return Math.min(1,Math.max(0,s().accessibility?.sounds?.volume??.4))}function p(){if(b)return!0;let e=typeof window<`u`?window.AudioContext??window.webkitAudioContext:void 0;return e?(b=new e,x=b.createGain(),x.connect(b.destination),!0):!1}function m(e,t){let n=e.createBuffer(t.numberOfChannels,t.length,t.sampleRate);for(let e=0;e<t.numberOfChannels;e++){let r=t.getChannelData(e),i=n.getChannelData(e);for(let e=0,n=t.length;e<n;e++)i[e]=r[n-1-e]??0}return n}function h(e){let t=C.get(e);if(t)return t;let n=(async()=>{if(!p()||!b)return null;let t=await(await fetch(y[e])).arrayBuffer(),n=await b.decodeAudioData(t),r={forward:n,reversed:m(b,n)};return S.set(e,r),r})().catch(()=>null);return C.set(e,n),n}function g(e,t){if(!b||!x)return;b.state===`suspended`&&b.resume().catch(()=>{}),x.gain.value=f();let n=b.createBufferSource();n.buffer=t.reverse?e.reversed:e.forward,t.detune&&(n.detune.value=t.detune),t.rate&&(n.playbackRate.value=t.rate),n.connect(x),n.start()}function _(e={}){if(!d())return;let t=e.sample??`shuffle`,n=S.get(t);if(n){g(n,e);return}h(t).then(t=>{t&&d()&&g(t,e)})}function v(){_()}var y,b,x,S,C,w=e((()=>{u(),o(),y={shuffle:l},b=null,x=null,S=new Map,C=new Map}));async function T(){let e=await a.getJSON(`library/songs`);if(!e||!Array.isArray(e)){console.warn(`[shuffle-library] Library songs data is not an array or empty`),e&&a.del(`library/songs`);return}let n=e;if(n.length===0)return;v();let r=i(),o=t();await r.setQueueFromItems(n,0,{shuffle:!0,play:!0,containerContext:{type:`songs`,id:`library-songs`,name:o.getString(`term.songs`),artwork:void 0,isManuallyQueued:!1}})}var E=e((()=>{w(),r(),n(),c()}));export{T as n,E as t};