{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-spotlight-grid",
  "type": "registry:component",
  "title": "Spotlight Grid",
  "description": "A dim grid where a spotlight follows the pointer, or roams on its own, and reveals bright lines, crossing dots and glowing tiles that blink on and off.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "grid",
    "spotlight",
    "pointer",
    "tiles",
    "css"
  ],
  "docs": "https://hyperblur.dev/effects/bg-spotlight-grid",
  "files": [
    {
      "path": "registry/hyperblur/bg-spotlight-grid.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-spotlight-grid.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgSpotlightGridProps extends React.HTMLAttributes<HTMLDivElement> {\n  cell?: number;\n  radius?: number;\n  color?: string;\n  accent?: string;\n  background?: string;\n  cells?: number;\n  follow?: boolean;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-vd11 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; background: var(--hb-vd11-bg); --hb-vd11-x: 50%; --hb-vd11-y: 40%; }\n.hb-vd11 *, .hb-vd11 *::before, .hb-vd11 *::after { box-sizing: border-box; }\n.hb-vd11-dim { position: absolute; inset: 0; background-image: linear-gradient(to right, color-mix(in srgb, var(--hb-vd11-c) 7%, transparent) 1px, transparent 1px), linear-gradient(to bottom, color-mix(in srgb, var(--hb-vd11-c) 7%, transparent) 1px, transparent 1px); background-size: var(--hb-vd11-cell) var(--hb-vd11-cell); }\n.hb-vd11-halo { position: absolute; inset: 0; background: radial-gradient(circle var(--hb-vd11-r) at var(--hb-vd11-x) var(--hb-vd11-y), color-mix(in srgb, var(--hb-vd11-a) 20%, transparent), transparent 70%); }\n.hb-vd11-lit { position: absolute; inset: 0; -webkit-mask-image: radial-gradient(circle var(--hb-vd11-r) at var(--hb-vd11-x) var(--hb-vd11-y), #000 0%, rgba(0,0,0,0.5) 45%, transparent 100%); mask-image: radial-gradient(circle var(--hb-vd11-r) at var(--hb-vd11-x) var(--hb-vd11-y), #000 0%, rgba(0,0,0,0.5) 45%, transparent 100%); }\n.hb-vd11-lines { position: absolute; inset: 0; background-image: radial-gradient(circle at 0.5px 0.5px, #fff 0 1px, transparent 1.6px), linear-gradient(to right, color-mix(in srgb, var(--hb-vd11-c) 34%, transparent) 1px, transparent 1px), linear-gradient(to bottom, color-mix(in srgb, var(--hb-vd11-c) 34%, transparent) 1px, transparent 1px); background-size: var(--hb-vd11-cell) var(--hb-vd11-cell); }\n.hb-vd11-cell { position: absolute; left: var(--x); top: var(--y); width: var(--hb-vd11-cell); height: var(--hb-vd11-cell); background: linear-gradient(160deg, color-mix(in srgb, var(--hb-vd11-a) 42%, transparent), color-mix(in srgb, var(--hb-vd11-a) 12%, transparent)); box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 30%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--hb-vd11-a) 70%, transparent), 0 0 22px color-mix(in srgb, var(--hb-vd11-a) 45%, transparent); opacity: 0; animation: hb-vd11-blink calc(var(--d) * var(--hb-vd11-k)) cubic-bezier(0.4, 0, 0.2, 1) infinite; animation-delay: var(--dl); }\n.hb-vd11-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n@keyframes hb-vd11-blink {\n  0%, 100% { opacity: 0; }\n  12% { opacity: 1; }\n  40% { opacity: 0.8; }\n  58% { opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vd11-cell { animation: none; opacity: var(--rest); }\n}\n`;\n\nfunction hash(i: number) {\n  let x = Math.imul(i ^ 0x082efa98, 0xec4e6c89);\n  x ^= x >>> 15;\n  x = Math.imul(x, 0x452821e6);\n  x ^= x >>> 14;\n  return (x >>> 0) / 4294967296;\n}\n\nexport function BgSpotlightGrid({\n  cell = 34,\n  radius = 220,\n  color = \"#ffffff\",\n  accent = \"#2f7bff\",\n  background = \"#060607\",\n  cells = 22,\n  follow = true,\n  speed = 1,\n  children,\n  className = \"\",\n  style,\n  ...rest\n}: BgSpotlightGridProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const [size, setSize] = React.useState({ cols: 24, rows: 14 });\n  const c = Math.max(12, cell);\n\n  React.useEffect(() => {\n    const el = wrapRef.current;\n    const host = el?.parentElement;\n    if (!el || !host) return;\n    const node: HTMLDivElement = el;\n    const parent: HTMLElement = host;\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let raf = 0;\n    let prev = 0;\n    let visible = true;\n    let inside = false;\n    let tx = 0;\n    let ty = 0;\n    let px = 0;\n    let py = 0;\n    let placed = false;\n\n    function apply() {\n      node.style.setProperty(\"--hb-vd11-x\", `${px.toFixed(1)}px`);\n      node.style.setProperty(\"--hb-vd11-y\", `${py.toFixed(1)}px`);\n    }\n\n    function idle() {\n      return {\n        x: w * (0.5 + 0.34 * Math.sin(t * 0.37)),\n        y: h * (0.45 + 0.28 * Math.sin(t * 0.53 + 1.2)),\n      };\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      const target = inside && follow ? { x: tx, y: ty } : idle();\n      if (!placed) {\n        px = target.x;\n        py = target.y;\n        placed = true;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 9 : 2.4));\n      px += (target.x - px) * k;\n      py += (target.y - py) * k;\n      apply();\n      raf = requestAnimationFrame(frame);\n    }\n\n    function resize() {\n      w = node.clientWidth;\n      h = node.clientHeight;\n      const cols = Math.max(2, Math.floor(w / c));\n      const rows = Math.max(2, Math.floor(h / c));\n      setSize((s) => (s.cols === cols && s.rows === rows ? s : { cols, rows }));\n      if (motion.matches || !placed) {\n        px = w * 0.5;\n        py = h * 0.42;\n        apply();\n      }\n    }\n\n    function sync() {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      if (motion.matches) {\n        px = w * 0.5;\n        py = h * 0.42;\n        apply();\n      }\n    }\n\n    function move(e: PointerEvent) {\n      const rect = node.getBoundingClientRect();\n      const sx = rect.width ? node.clientWidth / rect.width : 1;\n      const sy = rect.height ? node.clientHeight / rect.height : 1;\n      tx = (e.clientX - rect.left) * sx;\n      ty = (e.clientY - rect.top) * sy;\n      inside = true;\n    }\n\n    function leave() {\n      inside = false;\n    }\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(node);\n    io.observe(node);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    parent.addEventListener(\"pointermove\", move, { passive: true });\n    parent.addEventListener(\"pointerleave\", leave);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", sync);\n      parent.removeEventListener(\"pointermove\", move);\n      parent.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [c, follow, speed]);\n\n  const n = Math.max(0, Math.min(120, Math.round(cells)));\n  const lit = Array.from({ length: n }, (_, i) => ({\n    x: Math.floor(hash(i * 4 + 1) * size.cols) * c,\n    y: Math.floor(hash(i * 4 + 2) * size.rows) * c,\n    d: 3 + hash(i * 4 + 3) * 4,\n    dl: -hash(i * 4 + 4) * 7,\n    rest: hash(i * 4 + 5) > 0.6 ? 0.8 : 0,\n  }));\n\n  return (\n    <div\n      ref={wrapRef}\n      className={`hb-vd11 ${className}`}\n      style={\n        {\n          \"--hb-vd11-bg\": background,\n          \"--hb-vd11-a\": accent,\n          \"--hb-vd11-c\": color,\n          \"--hb-vd11-cell\": `${c}px`,\n          \"--hb-vd11-r\": `${Math.max(40, radius)}px`,\n          \"--hb-vd11-k\": (1 / Math.max(0.05, speed)).toFixed(3),\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-bg-spotlight-grid\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vd11-dim\" aria-hidden=\"true\" />\n      <div className=\"hb-vd11-halo\" aria-hidden=\"true\" />\n      <div className=\"hb-vd11-lit\" aria-hidden=\"true\">\n        {lit.map((l, i) => (\n          <span\n            key={i}\n            className=\"hb-vd11-cell\"\n            style={{ \"--x\": `${l.x}px`, \"--y\": `${l.y}px`, \"--d\": `${l.d.toFixed(2)}s`, \"--dl\": `${l.dl.toFixed(2)}s`, \"--rest\": l.rest } as React.CSSProperties}\n          />\n        ))}\n        <div className=\"hb-vd11-lines\" />\n      </div>\n      {children ? <div className=\"hb-vd11-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}