"use client"
import{j as s}from"./chunk-KDP6L5T4.mjs";import{useEffect as F,useRef as T}from"react";import{jsx as m}from"react/jsx-runtime";var b=`
attribute vec2 position;

void main() 
{
    gl_Position = vec4(position, 0.0, 1.0);
}
`,x=`
precision mediump float;

uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;

// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459; 
float random(in vec2 xy){
    return fract(tan(distance(xy*PHI, xy))*xy.x);
}

void main(void) {
  vec2 uv = gl_FragCoord.xy;

  vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
  float id = random(cellUv + 1.0);

  float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
  
  vec2 dotUv = fract(uv / cellSize);
  float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);

  float opacity = dot * fadeEffect;

  vec4 fragColor = vec4(vec3(0.0), opacity);
  fragColor.rgb *= fragColor.a;

  gl_FragColor = fragColor;
}
`;function L({dotSize:d=1,cellSize:u=3,speed:g=5,className:v}){let n=T(null);return F(()=>{let t=n.current;if(!t||!t.parentElement)return;let a=t.parentElement,c=window.devicePixelRatio||1;t.width=a.clientWidth*c,t.height=a.clientHeight*c;let e=t.getContext("webgl");if(e===null){alert("Failed to initialize WebGL");return}let o=e.createProgram();if(!o){console.error("Failed to create shader program");return}for(let r=0;r<2;++r){let U=r===0?b:x,i=e.createShader(r===0?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(!i){console.error("Failed to create shader");return}e.shaderSource(i,U),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)||console.error(e.getShaderInfoLog(i)),e.attachShader(o,i),e.linkProgram(o)}e.getProgramParameter(o,e.LINK_STATUS)||console.error(e.getProgramInfoLog(o));let l=e.getAttribLocation(o,"position"),S=e.getUniformLocation(o,"time"),h=e.getUniformLocation(o,"resolution"),p=e.getUniformLocation(o,"dotSize"),R=e.getUniformLocation(o,"cellSize"),A=e.getUniformLocation(o,"speed");e.useProgram(o);let E=[1,1,-1,1,1,-1,-1,-1],P=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,P),e.bufferData(e.ARRAY_BUFFER,new Float32Array(E),e.STATIC_DRAW),e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0),e.enable(e.DEPTH_TEST),e.uniform1f(p,d*window.devicePixelRatio),e.uniform1f(R,u*window.devicePixelRatio),e.uniform1f(A,g);function f(r){e&&t&&o&&(e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),e.uniform1f(S,r/1e3),e.uniform2f(h,t.width,t.height),e.drawArrays(e.TRIANGLE_STRIP,0,4)),requestAnimationFrame(f)}requestAnimationFrame(f)},[]),m("div",{className:s("absolute inset-0",v),children:m("canvas",{ref:n,width:"100%",height:"100%",className:"size-full"})})}export{L as a};
