1import{r as w,j}from"./vendor-react-B9zYIx_v.js";import{u as H}from"./index-BUnRSC5N.js";let h=null;const R=()=>((!h||h.state==="closed")&&(h=new AudioContext),h);function z(){if(!h)return;const n=h;h=null,n.state!=="closed"&&n.close()}function P(){const n=R(),i=n.createOscillator(),r=n.createGain();i.type="square",i.frequency.setValueAtTime(880,n.currentTime),i.frequency.exponentialRampToValueAtTime(220,n.currentTime+.1),r.gain.setValueAtTime(.12,n.currentTime),r.gain.exponentialRampToValueAtTime(.001,n.currentTime+.1),i.connect(r).connect(n.destination),i.start(),i.stop(n.currentTime+.1)}function K(){const n=R(),i=n.sampleRate*.15,r=n.createBuffer(1,i,n.sampleRate),m=r.getChannelData(0);for(let f=0;f<i;f++)m[f]=(Math.random()*2-1)*(1-f/i);const l=n.createBufferSource();l.buffer=r;const s=n.createGain();s.gain.setValueAtTime(.15,n.currentTime),s.gain.exponentialRampToValueAtTime(.001,n.currentTime+.15);const e=n.createBiquadFilter();e.type="lowpass",e.frequency.setValueAtTime(1200,n.currentTime),e.frequency.exponentialRampToValueAtTime(200,n.currentTime+.15),l.connect(e).connect(s).connect(n.destination),l.start()}function J(){const n=R(),i=n.createOscillator(),r=n.createGain();i.type="sawtooth",i.frequency.setValueAtTime(120,n.currentTime),i.frequency.exponentialRampToValueAtTime(60,n.currentTime+.15),r.gain.setValueAtTime(.08,n.currentTime),r.gain.exponentialRampToValueAtTime(.001,n.currentTime+.15),i.connect(r).connect(n.destination),i.start(),i.stop(n.currentTime+.15)}function F(){const n=R();[440,370,311,261].forEach((r,m)=>{const l=n.createOscillator(),s=n.createGain();l.type="square";const e=n.currentTime+m*.2;l.frequency.setValueAtTime(r,e),s.gain.setValueAtTime(.1,e),s.gain.exponentialRampToValueAtTime(.001,e+.2),l.connect(s).connect(n.destination),l.start(e),l.stop(e+.2)})}function Q(){const n=R();[523,659,784,1047].forEach((r,m)=>{const l=n.createOscillator(),s=n.createGain();l.type="square";const e=n.currentTime+m*.15;l.frequency.setValueAtTime(r,e),s.gain.setValueAtTime(.1,e),s.gain.exponentialRampToValueAtTime(.001,e+.18),l.connect(s).connect(n.destination),l.start(e),l.stop(e+.18)})}const I=1e3/60,U=250,N=1e3;function Z({onClose:n}){const i=w.useRef(null),{t:r}=H(),m=w.useRef(n),l=w.useRef(r.game);return w.useEffect(()=>{m.current=n,l.current=r.game}),w.useEffect(()=>{const s=i.current;if(!s)return;const e=s.getContext("2d");if(!e)return;const f=600,y=400,b=Math.min(window.devicePixelRatio||1,2);s.width=f*b,s.height=y*b,e.scale(b,b);const a={x:f/2-16,y:y-40,w:32,h:20},v={},x=[],p=[],d=[];for(let o=0;o<4;o++)for(let c=0;c<8;c++)d.push({x:60+c*52,y:30+o*36,w:28,h:20,alive:!0});let M=.6,V=0,g=!1,E=!1,C=-1/0,k=0,q=0,O=0;function S(o){if(o.key==="Escape"){_(),m.current();return}v[o.key]=o.type==="keydown",(o.key==="ArrowLeft"||o.key==="ArrowRight"||o.key===" ")&&o.preventDefault()}window.addEventListener("keydown",S),window.addEventListener("keyup",S);let L;function W(){e.fillStyle="hsl(152, 59%, 45%)",e.fillRect(a.x+4,a.y+6,24,14),e.fillRect(a.x+12,a.y,8,8),e.fillRect(a.x,a.y+14,6,6),e.fillRect(a.x+26,a.y+14,6,6)}function B(o){const A=[[0,0,1,0,0,1,0,0],[0,0,0,1,1,0,0,0],[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,1,1,1,1,1,1],[1,0,1,1,1,1,0,1]];e.fillStyle="rgba(255,255,255,0.9)";for(let t=0;t<A.length;t++)for(let u=0;u<A[t].length;u++)A[t][u]&&e.fillRect(o.x+u*3+2,o.y+t*3,3,3)}function D(o){const c=o/I;q+=o,k+=o,v.ArrowLeft&&(a.x=Math.max(4,a.x-3.5*c)),v.ArrowRight&&(a.x=Math.min(f-a.w-4,a.x+3.5*c)),v[" "]&&q-C>U&&(x.push({x:a.x+14,y:a.y-4,dy:-5}),C=q,P());for(let t=x.length-1;t>=0;t--)x[t].y+=x[t].dy*c,x[t].y<-10&&x.splice(t,1);for(let t=p.length-1;t>=0;t--)p[t].y+=p[t].dy*c,p[t].y>y+10&&p.splice(t,1);if(k>=N){k-=N;const t=d.filter(u=>u.alive);if(t.length>0){const u=t[Math.floor(Math.random()*t.length)];p.push({x:u.x+12,y:u.y+20,dy:2.5}),J()}}let A=!1;for(const t of d)t.alive&&(t.x+=M*c,(t.x<4||t.x+t.w>f-4)&&(A=!0));if(A){M*=-1;for(const t of d)t.alive&&(t.y+=12)}for(let t=x.length-1;t>=0;t--){const u=x[t];for(const T of d)if(T.alive&&u.x>T.x&&u.x<T.x+T.w&&u.y>T.y&&u.y<T.y+T.h){T.alive=!1,x.splice(t,1),V+=10,K();break}}for(const t of p)t.x>a.x&&t.x<a.x+a.w&&t.y>a.y&&t.y<a.y+a.h&&(g||F(),g=!0);for(const t of d)t.alive&&t.y+t.h>a.y&&(g||F(),g=!0);d.every(t=>!t.alive)&&(E=!0,g=!0,Q())}function $(){const o=l.current;e.clearRect(0,0,f,y),W(),e.fillStyle="hsl(152, 59%, 45%)";for(const c of x)e.fillRect(c.x,c.y,3,8);e.fillStyle="rgba(255,100,100,0.9)";for(const c of p)e.fillRect(c.x,c.y,3,8);for(const c of d)c.alive&&B(c);e.fillStyle="rgba(255,255,255,0.7)",e.font="12px monospace",e.fillText(`${o.score}: ${V}`,10,18),e.fillStyle="rgba(255,255,255,0.35)",e.font="10px monospace",e.textAlign="right",e.fillText(o.escToExit,f-10,18),e.textAlign="left",g&&(e.fillStyle="rgba(0,0,0,0.6)",e.fillRect(0,0,f,y),e.fillStyle=E?"hsl(152, 59%, 45%)":"rgba(255,100,100,0.9)",e.font="bold 28px monospace",e.textAlign="center",e.fillText(E?o.youWin:o.gameOver,f/2,y/2-10),e.fillStyle="rgba(255,255,255,0.6)",e.font="14px monospace",e.fillText(`${o.score}: ${V}`,f/2,y/2+20),e.fillText(o.pressEscToClose,f/2,y/2+44),e.textAlign="left")}function G(o){const c=O?Math.min(o-O,50):I;O=o,g||D(c),$(),L=requestAnimationFrame(G)}L=requestAnimationFrame(G);function _(){cancelAnimationFrame(L),window.removeEventListener("keydown",S),window.removeEventListener("keyup",S)}return()=>{_(),z()}},[]),j.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:j.jsx("canvas",{ref:i,role:"img","aria-label":r.game.label,className:"rounded-2xl border border-white/10 shadow-2xl",style:{width:600,maxWidth:"100%",height:"auto",aspectRatio:"3 / 2",background:"hsl(220, 20%, 6%)"}})})}export{Z as default};
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.