import{j as H}from"./vendor-query-DxCcOIl8.js";import{r as u}from"./vendor-react-DO-R8FnS.js";function X({density:b=2e4,alphaMin:y=.45,alphaMax:E=.75}){const P=u.useRef(null),M=u.useRef(),f=u.useRef([]),x=u.useRef({x:-9999,y:-9999}),m=u.useRef({w:0,h:0});return u.useEffect(()=>{const l=P.current;if(!l)return;const o=l.getContext("2d");if(!o)return;const T=["rgba(242, 80, 106, ","rgba(242, 80, 106, ","rgba(242, 80, 106, ","rgba(182, 122, 236, ","rgba(182, 122, 236, ","rgba(182, 122, 236, ","rgba(155, 81, 224, "],k=()=>{const t=window.devicePixelRatio||1,e=l.offsetWidth,r=l.offsetHeight;l.width=e*t,l.height=r*t,o.setTransform(t,0,0,t,0,0),m.current={w:e,h:r}},D=(t,e,r)=>{if(!r)return{x:Math.random()*t,y:Math.random()*e};const s=t*.18,n=e*.15,a=Math.random()<.5,c=a?Math.random()<.5?Math.random()*s:t-Math.random()*s:Math.random()*t,i=a?Math.random()*e:Math.random()<.5?Math.random()*n:e-Math.random()*n;return{x:c,y:i}},L=()=>{const{w:t,h:e}=m.current,r=Math.floor(t*e/b),s=E-y,n=window.matchMedia("(pointer: coarse)").matches;f.current=Array.from({length:r},()=>{const{x:a,y:c}=D(t,e,n);return{x:a,y:c,vx:(Math.random()-.5)*.25,vy:(Math.random()-.5)*.25,radius:Math.random()*5+2,color:T[Math.floor(Math.random()*T.length)],alpha:Math.random()*s+y}})},q=t=>{o.beginPath(),o.arc(t.x,t.y,t.radius,0,Math.PI*2),o.fillStyle=t.color+t.alpha+")",o.fill()},j=()=>{const t=f.current,e=x.current,r=140,s=130;for(let n=0;n<t.length;n++){for(let a=n+1;a<t.length;a++){const c=t[n].x-t[a].x,i=t[n].y-t[a].y,d=Math.sqrt(c*c+i*i);d<r&&(o.beginPath(),o.strokeStyle=`rgba(182, 122, 236, ${(1-d/r)*.38})`,o.lineWidth=1.2,o.moveTo(t[n].x,t[n].y),o.lineTo(t[a].x,t[a].y),o.stroke())}if(e.x!==-9999){const a=t[n].x-e.x,c=t[n].y-e.y,i=Math.sqrt(a*a+c*c);i<s&&(o.beginPath(),o.strokeStyle=`rgba(242, 80, 106, ${(1-i/s)*.55})`,o.lineWidth=1,o.moveTo(e.x,e.y),o.lineTo(t[n].x,t[n].y),o.stroke())}}},z=t=>{const e=x.current,{w:r,h:s}=m.current,n=110,a=.35,c=4,i=.97;if(e.x!==-9999){const w=t.x-e.x,R=t.y-e.y,h=Math.sqrt(w*w+R*R);if(h<n&&h>0){const S=(n-h)/n*a;t.vx+=w/h*S,t.vy+=R/h*S}}t.vx*=i,t.vy*=i;const d=Math.sqrt(t.vx*t.vx+t.vy*t.vy);d>c&&(t.vx=t.vx/d*c,t.vy=t.vy/d*c),t.x+=t.vx,t.y+=t.vy,(t.x<0||t.x>r)&&(t.vx*=-1),(t.y<0||t.y>s)&&(t.vy*=-1),t.x=Math.max(0,Math.min(r,t.x)),t.y=Math.max(0,Math.min(s,t.y))},B=window.matchMedia("(pointer: coarse)").matches;if(k(),L(),B){const t=setTimeout(()=>{f.current.forEach(q)},300);return()=>clearTimeout(t)}const g=()=>{const{w:t,h:e}=m.current;o.clearRect(0,0,t,e),j(),f.current.forEach(r=>{z(r),q(r)}),M.current=requestAnimationFrame(g)};let v;"requestIdleCallback"in window?v=requestIdleCallback(()=>g(),{timeout:1500}):v=setTimeout(g,200);const C=()=>{k(),L()},I=t=>{const e=l.getBoundingClientRect(),r=t.clientX-e.left,s=t.clientY-e.top,{w:n,h:a}=m.current;x.current=r>=0&&r<=n&&s>=0&&s<=a?{x:r,y:s}:{x:-9999,y:-9999}},A=()=>{x.current={x:-9999,y:-9999}};return window.addEventListener("resize",C),window.addEventListener("mousemove",I),l.addEventListener("mouseleave",A),()=>{window.removeEventListener("resize",C),window.removeEventListener("mousemove",I),l.removeEventListener("mouseleave",A),M.current&&cancelAnimationFrame(M.current),"requestIdleCallback"in window&&v!==void 0&&cancelIdleCallback(v)}},[b,y,E]),H.jsx("canvas",{ref:P,className:"absolute inset-0 w-full h-full",style:{display:"block"}})}export{X as P};