{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"neon-checker","type":"registry:ui","title":"Neon Checker","description":"A grid of rounded squares cycling through acid neon colors in interfering waves; the cursor lights them up. WebGL.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/neon-checker.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface NeonCheckerProps {\n  /** Up to four neon colors the squares cycle through. */\n  colors?: string[];\n  /** Square size in px, including the gap. */\n  cellSize?: number;\n  /** Gap between squares in px. */\n  gap?: number;\n  /** Wave speed multiplier; 0 freezes the motion. */\n  speed?: number;\n  /** Px radius the cursor lights up. */\n  cursorRadius?: number;\n  className?: string;\n}\n\nconst VERT = \"attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}\";\n\nconst FRAG = `\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uActive;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform vec3 uC3;\nuniform float uCell;\nuniform float uGap;\nuniform float uRadius;\nuniform float uDpr;\n\nfloat hash(vec2 p) {\n  p = fract(p * vec2(123.34, 456.21));\n  p += dot(p, p + 45.32);\n  return fract(p.x * p.y);\n}\n\n// Smooth cyclic blend through the four colors.\nvec3 palette(float t) {\n  t = fract(t) * 4.0;\n  vec3 c = mix(uC0, uC1, smoothstep(0.0, 1.0, clamp(t, 0.0, 1.0)));\n  c = mix(c, uC2, smoothstep(0.0, 1.0, clamp(t - 1.0, 0.0, 1.0)));\n  c = mix(c, uC3, smoothstep(0.0, 1.0, clamp(t - 2.0, 0.0, 1.0)));\n  return mix(c, uC0, smoothstep(0.0, 1.0, clamp(t - 3.0, 0.0, 1.0)));\n}\n\nvoid main() {\n  float cs = uCell * uDpr;\n  vec2 id = floor(gl_FragCoord.xy / cs);\n  vec2 center = (id + 0.5) * cs;\n  vec2 f = (gl_FragCoord.xy - center) / cs;\n  vec2 c = center / uRes.y;\n  float aspect = uRes.x / uRes.y;\n  float t = uTime;\n  float h = hash(id);\n\n  // Three interfering waves: a diagonal sweep, a ripple and a slow meander.\n  float w = sin(c.x * 3.1 + c.y * 1.7 - t * 1.1)\n          + 0.8 * sin(length(c - vec2(aspect * 0.3, 0.25)) * 6.0 - t * 1.6)\n          + 0.6 * sin(c.y * 4.2 - t * 0.7 + sin(c.x * 2.3 + t * 0.4) * 1.6);\n\n  float crest = 0.5 + 0.5 * sin(w * 1.7 + h * 0.9);\n  float b = 0.1 + 0.95 * pow(crest, 4.0);\n  b *= 0.85 + 0.15 * sin(t * 2.7 + h * 40.0);\n\n  float md = length(center - uMouse * uRes) / (uRadius * uDpr);\n  b += uActive * 1.3 * exp(-md * md * 2.4);\n\n  vec3 col = palette(w * 0.2 + t * 0.05 + h * 0.05);\n  col = mix(col, vec3(1.0), clamp(b - 1.0, 0.0, 1.0) * 0.45);\n\n  // Rounded square that swells a little as it brightens.\n  float hs = (0.5 - 0.5 * uGap / uCell) * (0.88 + 0.12 * min(b, 1.0));\n  float r = hs * 0.22;\n  float d = (length(max(abs(f) - hs + r, 0.0)) - r) * cs;\n  float mask = 1.0 - smoothstep(-0.75, 0.75, d);\n  float glow = exp(-max(d, 0.0) / (cs * 0.16)) * 0.3 * min(b, 1.4);\n\n  float e = clamp(mask * b + (1.0 - mask) * glow, 0.0, 1.0);\n  gl_FragColor = vec4(col * e, e);\n}\n`;\n\nfunction rgb(hex: string) {\n  let h = hex.replace(\"#\", \"\");\n  if (h.length === 3) h = h.replace(/./g, \"$&$&\");\n  const n = parseInt(h.padEnd(6, \"0\").slice(0, 6), 16) || 0;\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\n/** Compiles a full-screen-triangle program and returns a cached uniform lookup, or null. */\nfunction fullscreen(gl: WebGLRenderingContext, frag: string) {\n  const prog = gl.createProgram();\n  if (!prog) return null;\n  for (const [type, src] of [\n    [gl.VERTEX_SHADER, VERT],\n    [gl.FRAGMENT_SHADER, frag],\n  ] as const) {\n    const sh = gl.createShader(type);\n    if (!sh) return null;\n    gl.shaderSource(sh, src);\n    gl.compileShader(sh);\n    if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.warn(gl.getShaderInfoLog(sh));\n    gl.attachShader(prog, sh);\n  }\n  gl.bindAttribLocation(prog, 0, \"p\");\n  gl.linkProgram(prog);\n  if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return null;\n  gl.useProgram(prog);\n  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n  gl.enableVertexAttribArray(0);\n  gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n  const cache = new Map<string, WebGLUniformLocation | null>();\n  return (name: string) => {\n    if (!cache.has(name)) cache.set(name, gl.getUniformLocation(prog, name));\n    return cache.get(name) ?? null;\n  };\n}\n\nexport function NeonChecker({\n  colors = [\"#c6ff3d\", \"#00e5ff\", \"#ff2bd6\", \"#ffb800\"],\n  cellSize = 28,\n  gap = 4,\n  speed = 1,\n  cursorRadius = 180,\n  className,\n}: NeonCheckerProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const opts = useRef({ colors, cellSize, gap, speed, cursorRadius });\n  const redraw = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    opts.current = { colors, cellSize, gap, speed, cursorRadius };\n    redraw.current?.();\n  }, [colors, cellSize, gap, speed, cursorRadius]);\n\n  useEffect(() => {\n    const el = host.current!;\n    const canvas = document.createElement(\"canvas\");\n    canvas.style.cssText = \"position:absolute;inset:0;width:100%;height:100%;display:block\";\n    el.appendChild(canvas);\n    const gl = canvas.getContext(\"webgl\", { antialias: false, powerPreference: \"low-power\" });\n    const u = gl && fullscreen(gl, FRAG);\n    if (!gl || !u) {\n      canvas.remove();\n      return;\n    }\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const pointer = { x: 0.5, y: 0.5, active: 0, tx: 0.5, ty: 0.5, ta: 0 };\n    let raf = 0;\n    let visible = true;\n    let time = 3;\n    let last = 0;\n    let dpr = 1;\n\n    const draw = () => {\n      const o = opts.current;\n      const list = o.colors.length ? o.colors : [\"#ffffff\"];\n      for (let i = 0; i < 4; i++) gl.uniform3fv(u(`uC${i}`), rgb(list[i % list.length]));\n      gl.uniform2f(u(\"uRes\"), canvas.width, canvas.height);\n      gl.uniform1f(u(\"uTime\"), time);\n      gl.uniform2f(u(\"uMouse\"), pointer.x, pointer.y);\n      gl.uniform1f(u(\"uActive\"), pointer.active);\n      gl.uniform1f(u(\"uCell\"), Math.max(o.cellSize, 4));\n      gl.uniform1f(u(\"uGap\"), Math.min(Math.max(o.gap, 0), o.cellSize - 2));\n      gl.uniform1f(u(\"uRadius\"), Math.max(o.cursorRadius, 1));\n      gl.uniform1f(u(\"uDpr\"), dpr);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n    const loop = (now: number) => {\n      time += (Math.min(now - last, 50) / 1000) * opts.current.speed;\n      last = now;\n      pointer.x += (pointer.tx - pointer.x) * 0.2;\n      pointer.y += (pointer.ty - pointer.y) * 0.2;\n      pointer.active += (pointer.ta - pointer.active) * 0.08;\n      draw();\n      raf = requestAnimationFrame(loop);\n    };\n    const play = () => {\n      if (raf || !visible || reduced) return;\n      last = performance.now();\n      raf = requestAnimationFrame(loop);\n    };\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      canvas.width = Math.max(1, Math.round(el.clientWidth * dpr));\n      canvas.height = Math.max(1, Math.round(el.clientHeight * dpr));\n      gl.viewport(0, 0, canvas.width, canvas.height);\n      draw();\n    };\n    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      pointer.tx = (e.clientX - r.left) / r.width;\n      pointer.ty = 1 - (e.clientY - r.top) / r.height;\n      if (!pointer.ta) {\n        pointer.x = pointer.tx;\n        pointer.y = pointer.ty;\n      }\n      pointer.ta = 1;\n    };\n    const onLeave = () => {\n      pointer.ta = 0;\n    };\n\n    const target = el.parentElement ?? el;\n    target.addEventListener(\"pointermove\", onMove, { passive: true });\n    target.addEventListener(\"pointerleave\", onLeave);\n    const ro = new ResizeObserver(resize);\n    ro.observe(el);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) play();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    redraw.current = draw;\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      target.removeEventListener(\"pointermove\", onMove);\n      target.removeEventListener(\"pointerleave\", onLeave);\n      redraw.current = null;\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    };\n  }, []);\n\n  return (\n    <div\n      ref={host}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, overflow: \"hidden\", pointerEvents: \"none\" }}\n    />\n  );\n}\n"}]}