{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-glare-grid",
  "type": "registry:component",
  "title": "Cursor Glare Grid",
  "description": "A field of tiny needles turns to face the pointer like compasses, growing and lighting up the closer they are.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "grid",
    "needles",
    "compass",
    "field",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-glare-grid",
  "files": [
    {
      "path": "registry/hyperblur/cursor-glare-grid.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-glare-grid.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorGlareGridProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  spacing?: number;\n  size?: number;\n  radius?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qia { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qia *, .hb-qia *::before, .hb-qia *::after { box-sizing: border-box; }\n.hb-qia-canvas { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }\n.hb-qia-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n`;\n\nexport function CursorGlareGrid({\n  color = \"#4a4a4a\",\n  accent = \"#2f7bff\",\n  spacing = 18,\n  size = 7,\n  radius = 150,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorGlareGridProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!root || !canvas || !ctx) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const gap = Math.max(6, spacing);\n    const reach = Math.max(20, radius);\n    let w = 0;\n    let h = 0;\n    let dpr = 1;\n    let px = 0;\n    let py = 0;\n    let cx = 0;\n    let cy = 0;\n    let active = false;\n    let mix = 0;\n    let raf = 0;\n    let last = 0;\n    let t = 0;\n    let visible = true;\n    let placed = false;\n\n    const draw = () => {\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n      const cols = Math.ceil(w / gap) + 1;\n      const rows = Math.ceil(h / gap) + 1;\n      const ox = (w - (cols - 1) * gap) / 2;\n      const oy = (h - (rows - 1) * gap) / 2;\n      for (let r = 0; r < rows; r++) {\n        for (let c = 0; c < cols; c++) {\n          const x = ox + c * gap;\n          const y = oy + r * gap;\n          const dx = cx - x;\n          const dy = cy - y;\n          const d = Math.hypot(dx, dy);\n          const q = d / reach;\n          const f = 1 / (1 + q * q * 2.2);\n          const a = Math.atan2(dy, dx);\n          const len = size * (0.5 + f * 1.1);\n          const thick = size * (0.32 + f * 0.25);\n          const cos = Math.cos(a);\n          const sin = Math.sin(a);\n          ctx.setTransform(dpr * cos, dpr * sin, -dpr * sin, dpr * cos, dpr * x, dpr * y);\n          ctx.globalAlpha = 0.45 + 0.3 * f;\n          ctx.fillStyle = color;\n          ctx.fillRect(-len / 2, -thick / 2, len, thick);\n          if (f > 0.08) {\n            ctx.globalAlpha = Math.min(1, (f - 0.08) * 1.25);\n            ctx.fillStyle = accent;\n            ctx.fillRect(-len / 2, -thick / 2, len, thick);\n          }\n        }\n      }\n      ctx.globalAlpha = 1;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    };\n\n    const step = (dt: number) => {\n      t += dt;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 3.5));\n      const ix = idle ? w * (0.5 + 0.34 * Math.sin(t * 0.45) + 0.05 * Math.sin(t * 1.4)) : px;\n      const iy = idle ? h * (0.5 + 0.3 * Math.sin(t * 0.72 + 0.5)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      const k = 1 - Math.exp(-dt * 8);\n      cx += (tx - cx) * k;\n      cy += (ty - cy) * k;\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      step(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    };\n\n    const start = () => {\n      if (raf || reduced || !visible || !w) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n\n    const resize = () => {\n      const nw = root.clientWidth;\n      const nh = root.clientHeight;\n      if (!nw || !nh) return;\n      w = nw;\n      h = nh;\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      if (!placed) {\n        placed = true;\n        px = w / 2;\n        py = h / 2;\n        cx = idle ? w * 0.5 : px;\n        cy = idle ? h * (0.5 + 0.3 * Math.sin(0.5)) : py;\n      }\n      if (reduced) {\n        cx = w * 0.66;\n        cy = h * 0.42;\n        draw();\n      } else {\n        draw();\n        start();\n      }\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? w / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      active = true;\n      if (reduced) {\n        cx = px;\n        cy = py;\n        draw();\n      }\n    };\n    const onLeave = () => {\n      active = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointercancel\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    const ro = new ResizeObserver(resize);\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    resize();\n\n    return () => {\n      stop();\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointercancel\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [color, accent, spacing, size, radius, idle]);\n\n  return (\n    <div ref={rootRef} className={`hb-qia ${className}`} style={style} {...rest}>\n      <style href=\"hb-cursor-glare-grid\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qia-canvas\" aria-hidden=\"true\" />\n      <div className=\"hb-qia-content\">{children}</div>\n    </div>\n  );\n}\n"
    }
  ]
}