{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-dot-field",
  "type": "registry:component",
  "title": "Dot Field",
  "description": "A dense grid of dots that swell and scatter away from the pointer, then spring back into place with a little overshoot.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "dots",
    "spring",
    "pointer",
    "canvas",
    "repel"
  ],
  "docs": "https://hyperblur.dev/effects/bg-dot-field",
  "files": [
    {
      "path": "registry/hyperblur/bg-dot-field.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-dot-field.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgDotFieldProps extends React.HTMLAttributes<HTMLDivElement> {\n  spacing?: number;\n  size?: number;\n  color?: string;\n  accent?: string;\n  radius?: number;\n  push?: number;\n  grow?: number;\n  speed?: number;\n}\n\nconst css = `\n.hb-qj3 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-qj3-c { display: block; width: 100%; height: 100%; }\n`;\n\nexport function BgDotField({\n  spacing = 16,\n  size = 1.3,\n  color = \"rgba(255,255,255,0.3)\",\n  accent = \"#2f7bff\",\n  radius = 110,\n  push = 22,\n  grow = 1.8,\n  speed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: BgDotFieldProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx) return;\n\n    const R = Math.max(20, radius);\n    const R2 = R * R;\n    const TAU = Math.PI * 2;\n    let w = 0;\n    let h = 0;\n    let t = 0;\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    let gap = Math.max(6, spacing);\n    let n = 0;\n    let bx = new Float32Array(0);\n    let by = new Float32Array(0);\n    let ox = new Float32Array(0);\n    let oy = new Float32Array(0);\n    let vx = new Float32Array(0);\n    let vy = new Float32Array(0);\n    let kk = new Float32Array(0);\n\n    function idleX(tt: number) {\n      return w * (0.5 + 0.34 * Math.sin(tt * 0.43 + 2.1));\n    }\n    function idleY(tt: number) {\n      return h * (0.5 + 0.3 * Math.sin(tt * 0.71 + 0.3));\n    }\n\n    function track(dt: number) {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed) {\n        px = gx;\n        py = gy;\n        placed = true;\n        return;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 12 : 2.6));\n      px += (gx - px) * k;\n      py += (gy - py) * k;\n    }\n\n    function layout() {\n      gap = Math.max(6, spacing);\n      while ((w / gap + 1) * (h / gap + 1) > 14000) gap *= 1.15;\n      const cols = Math.floor(w / gap) + 1;\n      const rows = Math.floor(h / gap) + 1;\n      const sx = (w - (cols - 1) * gap) / 2;\n      const sy = (h - (rows - 1) * gap) / 2;\n      n = cols * rows;\n      bx = new Float32Array(n);\n      by = new Float32Array(n);\n      ox = new Float32Array(n);\n      oy = new Float32Array(n);\n      vx = new Float32Array(n);\n      vy = new Float32Array(n);\n      kk = new Float32Array(n);\n      for (let r = 0; r < rows; r++) {\n        for (let c = 0; c < cols; c++) {\n          const i = r * cols + c;\n          bx[i] = sx + c * gap;\n          by[i] = sy + r * gap;\n        }\n      }\n    }\n\n    function settle() {\n      for (let i = 0; i < n; i++) {\n        const dx = bx[i] - px;\n        const dy = by[i] - py;\n        const d2 = dx * dx + dy * dy;\n        if (d2 < R2 && d2 > 0.01) {\n          const d = Math.sqrt(d2);\n          const k = 1 - d / R;\n          ox[i] = (dx / d) * k * k * push;\n          oy[i] = (dy / d) * k * k * push;\n          kk[i] = k;\n        } else {\n          ox[i] = 0;\n          oy[i] = 0;\n          kk[i] = 0;\n        }\n        vx[i] = 0;\n        vy[i] = 0;\n      }\n    }\n\n    function step(dt: number) {\n      const stiff = 130;\n      const damp = 11;\n      const pulse = 0.85 + 0.15 * Math.sin(t * 1.7);\n      for (let i = 0; i < n; i++) {\n        const dx = bx[i] - px;\n        const dy = by[i] - py;\n        const d2 = dx * dx + dy * dy;\n        let gx = 0;\n        let gy = 0;\n        let k = 0;\n        if (d2 < R2 && d2 > 0.01) {\n          const d = Math.sqrt(d2);\n          k = 1 - d / R;\n          const f = k * k * push * pulse;\n          gx = (dx / d) * f;\n          gy = (dy / d) * f;\n        }\n        kk[i] += (k - kk[i]) * Math.min(1, dt * 10);\n        vx[i] += ((gx - ox[i]) * stiff - vx[i] * damp) * dt;\n        vy[i] += ((gy - oy[i]) * stiff - vy[i] * damp) * dt;\n        ox[i] += vx[i] * dt;\n        oy[i] += vy[i] * dt;\n      }\n    }\n\n    function draw() {\n      if (!ctx || !w || !h) return;\n      ctx.clearRect(0, 0, w, h);\n      ctx.fillStyle = color;\n      ctx.beginPath();\n      for (let i = 0; i < n; i++) {\n        const x = bx[i] + ox[i];\n        const y = by[i] + oy[i];\n        ctx.moveTo(x + size, y);\n        ctx.arc(x, y, size, 0, TAU);\n      }\n      ctx.fill();\n      ctx.fillStyle = accent;\n      for (let i = 0; i < n; i++) {\n        const k = kk[i];\n        if (k < 0.02) continue;\n        ctx.globalAlpha = Math.min(1, k * 1.4);\n        ctx.beginPath();\n        ctx.arc(bx[i] + ox[i], by[i] + oy[i], size * (1 + grow * k), 0, TAU);\n        ctx.fill();\n      }\n      ctx.globalAlpha = 1;\n    }\n\n    function resize() {\n      if (!wrap || !canvas || !ctx) return;\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      layout();\n      if (motion.matches) still();\n      else {\n        track(0);\n        settle();\n        draw();\n      }\n    }\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function still() {\n      t = 1.4;\n      inside = false;\n      placed = false;\n      track(0);\n      settle();\n      draw();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      track(dt);\n      step(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\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) still();\n    }\n\n    function move(e: PointerEvent) {\n      if (!host || motion.matches) return;\n      const rect = host.getBoundingClientRect();\n      const sx = rect.width ? host.clientWidth / rect.width : 1;\n      const sy = rect.height ? host.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(e: PointerEvent) {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\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(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", 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      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [spacing, size, color, accent, radius, push, grow, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qj3 ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-bg-dot-field\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qj3-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}