{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pin-matrix","type":"registry:ui","title":"Pin Matrix","description":"A calm dot matrix that lights up around the cursor. Redraws only on movement.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/pin-matrix.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface PinMatrixProps {\n  /** Px between dots. */\n  gap?: number;\n  dotSize?: number;\n  baseColor?: string;\n  activeColor?: string;\n  /** Px radius around the cursor that lights up. */\n  proximity?: number;\n  className?: string;\n}\n\nfunction hexToRgb(hex: string) {\n  const n = parseInt(hex.replace(\"#\", \"\").padEnd(6, \"0\").slice(0, 6), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nexport function PinMatrix({\n  gap = 24,\n  dotSize = 2,\n  baseColor = \"#3f3f46\",\n  activeColor = \"#c6ff3d\",\n  proximity = 120,\n  className,\n}: PinMatrixProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const canvas = ref.current!;\n    const ctx = canvas.getContext(\"2d\")!;\n    const base = hexToRgb(baseColor);\n    const active = hexToRgb(activeColor);\n    const mouse = { x: -9999, y: -9999 };\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n\n    // Draws only on resize and pointer movement; a still grid costs nothing.\n    const draw = () => {\n      raf = 0;\n      ctx.clearRect(0, 0, w, h);\n      for (let x = gap / 2; x < w; x += gap) {\n        for (let y = gap / 2; y < h; y += gap) {\n          const d = Math.hypot(x - mouse.x, y - mouse.y);\n          const t = Math.max(0, 1 - d / proximity);\n          const c = base.map((b, i) => Math.round(b + (active[i] - b) * t));\n          ctx.fillStyle = `rgb(${c[0]},${c[1]},${c[2]})`;\n          ctx.beginPath();\n          ctx.arc(x, y, dotSize * (1 + t * 0.8), 0, Math.PI * 2);\n          ctx.fill();\n        }\n      }\n    };\n    const schedule = () => {\n      if (!raf) raf = requestAnimationFrame(draw);\n    };\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = canvas.offsetWidth;\n      h = canvas.offsetHeight;\n      canvas.width = w * dpr;\n      canvas.height = h * dpr;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      schedule();\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      mouse.x = e.clientX - r.left;\n      mouse.y = e.clientY - r.top;\n      schedule();\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    window.addEventListener(\"pointermove\", onMove, { passive: true });\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      window.removeEventListener(\"pointermove\", onMove);\n    };\n  }, [gap, dotSize, baseColor, activeColor, proximity]);\n\n  return (\n    <canvas\n      ref={ref}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" }}\n    />\n  );\n}\n"}]}