const t="sfxEnabled",e="sfxVolume";let n="false"!==localStorage.getItem(t),a=parseFloat(localStorage.getItem(e)??"0.8");function r(){return n}function c(){return a}function s(e){n=e,localStorage.setItem(t,String(e))}function o(t){a=Math.max(0,Math.min(1,t)),localStorage.setItem(e,String(a))}(Number.isNaN(a)||a<0||a>1)&&(a=.8);let u=null,i=null,f=null,l=null,d=!1,m=!1;async function g(t,e){const n=await fetch(e),a=await n.arrayBuffer();return t.decodeAudioData(a)}async function y(){if(!d&&!m){m=!0;try{u=new AudioContext;const[t,e]=await Promise.all([g(u,"/assets/sfx/key-down.m4a"),g(u,"/assets/sfx/key-up.m4a")]);i=t,f=e,d=!0}catch(t){}finally{m=!1}}}function S(t){const e=u.createGain();return e.gain.value=t,e}function p(){if(!n)return;if(!d||!u||!i)return void y();"suspended"===u.state&&u.resume();const t=u.createBufferSource();t.buffer=i,t.connect(S(a)).connect(u.destination),t.start(u.currentTime+.01),l=t}function w(){if(!n)return;if(!d||!u||!f)return;if("suspended"===u.state&&u.resume(),l){try{l.stop()}catch{}l=null}const t=u.createBufferSource();t.buffer=f,t.connect(S(.75*a)).connect(u.destination),t.start()}async function b(){if(!(d&&u&&i&&f||(await y(),d&&u&&i&&f)))return;"suspended"===u.state&&await u.resume();const t=u.createBufferSource();return t.buffer=i,t.connect(S(a)).connect(u.destination),t.start(u.currentTime+.01),new Promise(e=>{setTimeout(()=>{try{t.stop()}catch{}const n=u.createBufferSource();n.buffer=f,n.connect(S(.75*a)).connect(u.destination),n.start(),n.onended=()=>e()},120)})}export{o as a,p as b,w as c,c as g,r as i,b as k,s};
