var __exports=(()=>{var A=Object.create;var S=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var x=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var L=(o,t,e,b)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of G(t))!Y.call(o,c)&&c!==e&&S(o,c,{get:()=>t[c],enumerable:!(b=F(t,c))||b.enumerable});return o};var f=(o,t,e)=>(e=o!=null?A(O(o)):{},L(t||!o||!o.__esModule?S(e,"default",{value:o,enumerable:!0}):e,o));var T=x((Z,R)=>{R.exports=__ojExternals.react});var _=x((ee,M)=>{M.exports=__ojExternals.oj});var v=x((oe,V)=>{V.exports=__ojExternals["react/jsx-runtime"]});var u=f(T()),n=f(_());var y=class{constructor(t){this.size=t;for(let e=0;e<t;e++)this.free.push(e)}live=[];free=[];get inUse(){return this.live.length}take(){let t=this.free.shift();if(t!==void 0)return this.live.push(t),{body:t,recycled:null};let e=this.live.shift();if(e===void 0)throw new Error("a pool with no bodies cannot hand one out");return this.live.push(e),{body:e,recycled:e}}clear(){let t=[...this.live];this.live.length=0,this.free.length=0;for(let e=0;e<this.size;e++)this.free.push(e);return t}snapshot(){return[...this.live]}};var s=f(v()),w=90,U=.08,B=["rgb(122, 173, 255)","rgb(255, 168, 108)","rgb(126, 220, 168)","rgb(232, 138, 196)","rgb(246, 214, 120)","rgb(160, 152, 246)"],E=[];for(let o=0;o<w;o++){let t=o%3===0?"box":"circle",e=[16,22,28,34][o%4];E.push({kind:t,size:e,tone:B[o%B.length]})}var K=[{u:.233,v:.5,w:.333,rotation:14},{u:.733,v:.417,w:.289,rotation:-18},{u:.489,v:.753,w:.244,rotation:0},{u:.133,v:.833,w:.167,rotation:-26},{u:.867,v:.783,w:.189,rotation:22}],W=16;function D(o,t){return K.map(e=>({x:e.u*o,y:e.v*t,w:Math.round(e.w*o),h:W,rotation:e.rotation}))}function q(o,t){return[...D(o,t).map(e=>({type:"static",shape:"box",size:[e.w,e.h],x:e.x,y:e.y,rotation:e.rotation,friction:.4})),...E.map(e=>({type:"dynamic",shape:e.kind,radius:e.size/2,size:[e.size,e.size],x:-400,y:-400,density:1,friction:.35,restitution:.28}))]}function J(){let o=(0,n.useStage)(),t=Math.max(320,Math.round(o.width)),e=Math.max(320,Math.round(o.height));return(0,s.jsx)(Q,{width:t,height:e},`${t}x${e}`)}function Q({width:o,height:t}){let e=(0,u.useMemo)(()=>D(o,t),[o,t]),b=(0,u.useMemo)(()=>q(o,t),[o,t]),c=(0,u.useRef)(null),I=(0,u.useRef)((0,n.random)()).current,m=(0,u.useRef)(new y(w)).current,d=(0,u.useRef)([]).current,[P,k]=(0,u.useState)(0),[C,$]=(0,u.useState)(!1),p=(0,u.useRef)(0),a=(0,n.usePhysics)(c,{gravity:[0,980],bounds:!0,boundsRestitution:.15,boundsFriction:.5,bodies:b}),g=a===null?[]:a.bodies.slice(e.length);(0,u.useEffect)(()=>{if(a!==null){a.bodies.forEach((r,i)=>{d[i]&&r.bind(d[i])});for(let r of g)r.enabled=!1}},[a]);let H=(r,i)=>{if(a===null)return;let{body:l}=m.take(),h=g[l];h.enabled=!0,h.moveTo(r,i),h.setVelocity(I.range(-60,60),0);let z=d[h.index];z&&(z.style.opacity=1),k(m.inUse)},N=()=>{if(a!==null){for(let r of m.clear()){let i=g[r];i.enabled=!1,i.moveTo(-400,-400);let l=d[i.index];l&&(l.style.opacity=0)}k(0)}},j=()=>{if(a===null)return;let r=!C;$(r),a.setGravity(0,r?-980:980)};return(0,n.useFrame)(r=>{p.current-=r;let i=null;n.input.mouse.leftButton&&(i={x:n.input.mouse.position.x,y:n.input.mouse.position.y});for(let l of n.input.touches)l.phase==="ended"||l.phase==="canceled"||(i={x:l.position.x,y:l.position.y});i!==null&&p.current<=0&&(p.current=U,H(i.x,i.y))},[a]),(0,s.jsxs)(n.View,{style:{width:"100%",height:"100%",backgroundColor:"rgb(16, 19, 26)"},children:[(0,s.jsxs)(n.View,{ref:c,style:{position:"absolute",left:0,top:0,right:0,bottom:0},children:[e.map((r,i)=>(0,s.jsx)(n.View,{ref:l=>{d[i]=l},style:{position:"absolute",width:r.w,height:r.h,backgroundColor:"rgb(58, 66, 82)",borderRadius:4}},`scenery-${i}`)),E.map((r,i)=>(0,s.jsx)(n.View,{ref:l=>{d[e.length+i]=l},pickingMode:"Ignore",style:{position:"absolute",width:r.size,height:r.size,backgroundColor:r.tone,borderRadius:r.kind==="circle"?r.size/2:5,opacity:0}},`shape-${i}`))]}),(0,s.jsxs)(n.View,{style:{position:"absolute",left:24,top:20},pickingMode:"Ignore",children:[(0,s.jsx)(n.Text,{style:{fontSize:21,color:"rgb(226, 234, 247)"},children:"DROP EVERYTHING"}),(0,s.jsx)(n.Text,{style:{fontSize:11,marginTop:3,color:"rgb(122, 134, 156)"},children:`Hold anywhere to pour shapes in. ${P} of ${w} in play.`})]}),(0,s.jsxs)(n.View,{style:{position:"absolute",right:24,top:20,flexDirection:"row"},children:[(0,s.jsx)(n.Button,{text:C?"Gravity down":"Gravity up",onClick:j,style:{marginRight:8}}),(0,s.jsx)(n.Button,{text:"Clear",onClick:N})]})]})}(0,n.mount)((0,s.jsx)(J,{}));})();
