{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-metaballs",
  "type": "registry:component",
  "title": "Cursor Metaballs",
  "description": "A gooey blob follows the pointer while smaller blobs orbit it, stretch away and melt back in through an SVG goo filter.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "metaballs",
    "goo",
    "blob",
    "svg",
    "liquid"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-metaballs",
  "files": [
    {
      "path": "registry/hyperblur/cursor-metaballs.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-metaballs.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorMetaballsProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  color2?: string;\n  size?: number;\n  count?: number;\n  goo?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi6 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qi6 *, .hb-qi6 *::before, .hb-qi6 *::after { box-sizing: border-box; }\n.hb-qi6-svg { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; overflow: visible; }\n.hb-qi6-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n`;\n\nfunction hash(n: number) {\n  let x = (Math.imul(n | 0, 374761393) + 668265263) | 0;\n  x = Math.imul(x ^ (x >>> 13), 1274126177);\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967296;\n}\n\nexport function CursorMetaballs({\n  color = \"#2f7bff\",\n  color2 = \"#7fb3ff\",\n  size = 34,\n  count = 5,\n  goo = 10,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorMetaballsProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const svgRef = React.useRef<SVGSVGElement>(null);\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const filterId = `hb-qi6-f${uid}`;\n  const gradId = `hb-qi6-g${uid}`;\n  const n = Math.max(1, Math.min(12, Math.floor(count)));\n  const sats = Array.from({ length: n }, (_, i) => ({\n    r: size * (0.38 + hash(i * 7 + 1) * 0.26),\n    speed: (0.7 + hash(i * 7 + 2) * 0.9) * (i % 2 ? -1 : 1),\n    phase: hash(i * 7 + 3) * Math.PI * 2,\n    lag: 3 + hash(i * 7 + 4) * 5,\n  }));\n  const satKey = sats.map((s) => `${s.r.toFixed(2)},${s.speed.toFixed(3)},${s.phase.toFixed(3)},${s.lag.toFixed(2)}`).join(\";\");\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const svg = svgRef.current;\n    if (!root || !svg) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const data = satKey.split(\";\").map((row) => {\n      const [r, speed, phase, lag] = row.split(\",\").map(Number);\n      return { r, speed, phase, lag, x: 0, y: 0 };\n    });\n    const nodes = Array.from(svg.querySelectorAll<SVGCircleElement>(\"circle\"));\n    const main = nodes[0];\n    const others = nodes.slice(1);\n    let w = root.clientWidth;\n    let h = root.clientHeight;\n    let px = w / 2;\n    let py = h / 2;\n    let mx = w / 2;\n    let my = h / 2;\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\n    const set = (el: SVGCircleElement | undefined, x: number, y: number) => {\n      if (!el) return;\n      el.setAttribute(\"cx\", x.toFixed(2));\n      el.setAttribute(\"cy\", y.toFixed(2));\n    };\n\n    const step = (dt: number, snap: boolean) => {\n      t += dt;\n      w = root.clientWidth;\n      h = root.clientHeight;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 3));\n      const ix = idle ? w * (0.5 + 0.3 * Math.sin(t * 0.5) + 0.05 * Math.sin(t * 1.7)) : px;\n      const iy = idle ? h * (0.5 + 0.24 * Math.sin(t * 0.8 + 0.6)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      const km = snap ? 1 : 1 - Math.exp(-dt * 9);\n      mx += (tx - mx) * km;\n      my += (ty - my) * km;\n      set(main, mx, my);\n      data.forEach((s, i) => {\n        const breathe = 0.5 + 0.5 * Math.sin(t * 0.9 + i * 1.7);\n        const orbit = size * (0.75 + breathe * 0.95);\n        const a = t * s.speed + s.phase;\n        const gx = mx + Math.cos(a) * orbit;\n        const gy = my + Math.sin(a) * orbit * 0.8;\n        const k = snap ? 1 : 1 - Math.exp(-dt * s.lag);\n        s.x += (gx - s.x) * k;\n        s.y += (gy - s.y) * k;\n        set(others[i], s.x, s.y);\n      });\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.04, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      step(dt, false);\n      raf = requestAnimationFrame(frame);\n    };\n\n    const start = () => {\n      if (raf || reduced || !visible) 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 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) step(0, true);\n    };\n    const onLeave = () => {\n      active = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n\n    step(0, true);\n    if (reduced) {\n      t = 1.3;\n      step(0, true);\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 io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    start();\n\n    return () => {\n      stop();\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  }, [satKey, size, idle]);\n\n  return (\n    <div ref={rootRef} className={`hb-qi6 ${className}`} style={style} {...rest}>\n      <style href=\"hb-cursor-metaballs\" precedence=\"default\">{css}</style>\n      <svg ref={svgRef} className=\"hb-qi6-svg\" aria-hidden=\"true\">\n        <defs>\n          <filter id={filterId} filterUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" colorInterpolationFilters=\"sRGB\">\n            <feGaussianBlur in=\"SourceGraphic\" stdDeviation={goo} result=\"blur\" />\n            <feColorMatrix in=\"blur\" mode=\"matrix\" values=\"1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 24 -10\" />\n          </filter>\n          <linearGradient id={gradId} gradientUnits=\"userSpaceOnUse\" x1=\"0%\" y1=\"0%\" x2=\"100%\" y2=\"100%\">\n            <stop offset=\"0\" stopColor={color} />\n            <stop offset=\"1\" stopColor={color2} />\n          </linearGradient>\n        </defs>\n        <g filter={`url(#${filterId})`} fill={`url(#${gradId})`}>\n          <circle cx=\"50%\" cy=\"50%\" r={size.toFixed(2)} />\n          {sats.map((s, i) => (\n            <circle key={i} cx=\"50%\" cy=\"50%\" r={s.r.toFixed(2)} />\n          ))}\n        </g>\n      </svg>\n      <div className=\"hb-qi6-content\">{children}</div>\n    </div>\n  );\n}\n"
    }
  ]
}