{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "interactive-grid-beam",
  "type": "registry:ui",
  "title": "Interactive Grid Beam",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Architectural matrix background surface with spring-smoothed radial cursor illumination and click-triggered orthogonal grid light beams.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/interactive-grid-beam.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState } from \"react\";\nimport {\n  motion,\n  useMotionTemplate,\n  useMotionValue,\n  useSpring,\n  useReducedMotion,\n} from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface InteractiveGridBeamProps {\n  /** Grid cell size in pixels. Default: 32 */\n  gridSize?: number;\n  /** Radius of the cursor-tracked grid illumination mask in pixels. Default: 220 */\n  glowRadius?: number;\n  /** Spring stiffness coefficient for cursor spotlight tracking. Default: 280 */\n  stiffness?: number;\n  /** Spring damping coefficient for cursor spotlight tracking. Default: 26 */\n  damping?: number;\n  /** Foreground content rendered above the interactive grid matrix */\n  children?: React.ReactNode;\n  className?: string;\n}\n\ninterface PulseTrace {\n  id: number;\n  x: number;\n  y: number;\n}\n\nexport function InteractiveGridBeam({\n  gridSize = 32,\n  glowRadius = 220,\n  stiffness = 280,\n  damping = 26,\n  children,\n  className,\n}: InteractiveGridBeamProps) {\n  const containerRef = useRef<HTMLDivElement | null>(null);\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const [isHovered, setIsHovered] = useState(false);\n  const [pulses, setPulses] = useState<PulseTrace[]>([]);\n\n  const mouseX = useMotionValue(-1000);\n  const mouseY = useMotionValue(-1000);\n\n  const smoothX = useSpring(mouseX, { stiffness, damping, mass: 0.3 });\n  const smoothY = useSpring(mouseY, { stiffness, damping, mass: 0.3 });\n\n  const activeX = shouldReduceMotion ? mouseX : smoothX;\n  const activeY = shouldReduceMotion ? mouseY : smoothY;\n\n  const maskImage = useMotionTemplate`radial-gradient(${glowRadius}px circle at ${activeX}px ${activeY}px, rgba(0,0,0,1) 0%, rgba(0,0,0,0.35) 55%, transparent 100%)`;\n\n  const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {\n    const el = containerRef.current;\n    if (!el) return;\n    const rect = el.getBoundingClientRect();\n    mouseX.set(e.clientX - rect.left);\n    mouseY.set(e.clientY - rect.top);\n  };\n\n  const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {\n    if (shouldReduceMotion) return;\n    const el = containerRef.current;\n    if (!el) return;\n    const rect = el.getBoundingClientRect();\n    const rawX = e.clientX - rect.left;\n    const rawY = e.clientY - rect.top;\n\n    // Snap beam origin to nearest grid intersection\n    const snappedX = Math.round(rawX / gridSize) * gridSize;\n    const snappedY = Math.round(rawY / gridSize) * gridSize;\n    const id = Date.now() + Math.random();\n\n    setPulses((prev) => [...prev.slice(-3), { id, x: snappedX, y: snappedY }]);\n  };\n\n  const gridBackgroundStyle: React.CSSProperties = {\n    backgroundSize: `${gridSize}px ${gridSize}px`,\n    backgroundImage:\n      \"linear-gradient(to right, currentColor 1px, transparent 1px), linear-gradient(to bottom, currentColor 1px, transparent 1px)\",\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      onMouseMove={handleMouseMove}\n      onMouseEnter={() => setIsHovered(true)}\n      onMouseLeave={() => setIsHovered(false)}\n      onClick={handleClick}\n      className={cn(\n        \"group relative flex min-h-[240px] w-full cursor-crosshair items-center justify-center overflow-hidden rounded-2xl border border-neutral-200 bg-white p-8 dark:border-[#222222] dark:bg-[#0A0A0A]\",\n        className\n      )}\n    >\n      {/* Base ambient low-contrast architectural grid */}\n      <div\n        aria-hidden=\"true\"\n        style={gridBackgroundStyle}\n        className=\"pointer-events-none absolute inset-0 text-neutral-200/55 dark:text-[#1A1A1A]\"\n      />\n\n      {/* Cursor-masked high-contrast kinetic grid overlay */}\n      <motion.div\n        aria-hidden=\"true\"\n        style={{\n          ...gridBackgroundStyle,\n          WebkitMaskImage: maskImage,\n          maskImage,\n          opacity: isHovered ? 1 : 0,\n        }}\n        className=\"pointer-events-none absolute inset-0 text-black/45 transition-opacity duration-300 dark:text-white/45\"\n      />\n\n      {/* Interactive orthogonal light beams emitted on click */}\n      {!shouldReduceMotion &&\n        pulses.map((pulse) => (\n          <React.Fragment key={pulse.id}>\n            {/* Horizontal propagating beam */}\n            <motion.div\n              aria-hidden=\"true\"\n              initial={{ scaleX: 0, opacity: 0.9 }}\n              animate={{ scaleX: 1.6, opacity: 0 }}\n              transition={{ duration: 0.75, ease: \"easeOut\" }}\n              style={{ top: pulse.y, left: 0, right: 0 }}\n              className=\"pointer-events-none absolute h-[1.5px] origin-center bg-gradient-to-r from-transparent via-black to-transparent dark:via-white\"\n            />\n            {/* Vertical propagating beam */}\n            <motion.div\n              aria-hidden=\"true\"\n              initial={{ scaleY: 0, opacity: 0.9 }}\n              animate={{ scaleY: 1.6, opacity: 0 }}\n              transition={{ duration: 0.75, ease: \"easeOut\" }}\n              style={{ left: pulse.x, top: 0, bottom: 0 }}\n              className=\"pointer-events-none absolute w-[1.5px] origin-center bg-gradient-to-b from-transparent via-black to-transparent dark:via-white\"\n            />\n            {/* Intersection node pulse */}\n            <motion.div\n              aria-hidden=\"true\"\n              initial={{ scale: 0.4, opacity: 1 }}\n              animate={{ scale: 2.8, opacity: 0 }}\n              transition={{ duration: 0.65, ease: \"easeOut\" }}\n              style={{ left: pulse.x - 4, top: pulse.y - 4 }}\n              className=\"pointer-events-none absolute h-2 w-2 rounded-full bg-black dark:bg-white\"\n            />\n          </React.Fragment>\n        ))}\n\n      {/* Foreground Content */}\n      <div className=\"relative z-10 text-center\">\n        {children || (\n          <div className=\"mx-auto max-w-xs rounded-2xl border border-neutral-200/90 bg-white/90 px-5 py-4 shadow-sm backdrop-blur-md dark:border-[#262626] dark:bg-[#111111]/90\">\n            <div className=\"text-xs font-semibold uppercase tracking-widest text-neutral-400\">\n              Interactive Grid Matrix\n            </div>\n            <div className=\"mt-1 text-sm font-semibold text-black dark:text-white\">\n              Move cursor or click any intersection\n            </div>\n            <p className=\"mt-1 text-[11px] text-neutral-500\">\n              Snaps orthogonal light beams to {gridSize}px coordinates.\n            </p>\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default InteractiveGridBeam;\n",
      "type": "registry:ui",
      "target": "components/ui/interactive-grid-beam.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
