{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-fluid-splash",
  "type": "registry:component",
  "title": "Cursor Fluid Splash",
  "description": "Colorful blobs pour out along the pointer path, carry its velocity, swirl in a soft flow field and fade into streaks.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "fluid",
    "splash",
    "paint",
    "color",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-fluid-splash",
  "files": [
    {
      "path": "registry/hyperblur/cursor-fluid-splash.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-fluid-splash.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorFluidSplashProps extends React.HTMLAttributes<HTMLDivElement> {\n  colors?: string[];\n  size?: number;\n  intensity?: number;\n  trail?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi4 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qi4 *, .hb-qi4 *::before, .hb-qi4 *::after { box-sizing: border-box; }\n.hb-qi4-canvas { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }\n.hb-qi4-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n`;\n\nconst defaultColors = [\"#2f7bff\", \"#ff3d81\", \"#ffb02e\", \"#22d3a6\", \"#8b5cf6\"];\nconst POOL = 420;\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 CursorFluidSplash({\n  colors = defaultColors,\n  size = 26,\n  intensity = 1,\n  trail = 0.85,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorFluidSplashProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const palette = colors.length ? colors.join(\"|\") : defaultColors.join(\"|\");\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 list = palette.split(\"|\");\n    const sprites = list.map((c) => {\n      const s = document.createElement(\"canvas\");\n      s.width = 64;\n      s.height = 64;\n      const g = s.getContext(\"2d\");\n      if (g) {\n        g.fillStyle = c;\n        g.fillRect(0, 0, 64, 64);\n        g.globalCompositeOperation = \"destination-in\";\n        const grad = g.createRadialGradient(32, 32, 0, 32, 32, 32);\n        grad.addColorStop(0, \"rgba(0,0,0,1)\");\n        grad.addColorStop(0.45, \"rgba(0,0,0,0.55)\");\n        grad.addColorStop(1, \"rgba(0,0,0,0)\");\n        g.fillStyle = grad;\n        g.fillRect(0, 0, 64, 64);\n      }\n      return s;\n    });\n    const px0 = new Float32Array(POOL);\n    const py0 = new Float32Array(POOL);\n    const vx0 = new Float32Array(POOL);\n    const vy0 = new Float32Array(POOL);\n    const rad = new Float32Array(POOL);\n    const life = new Float32Array(POOL);\n    const decay = new Float32Array(POOL);\n    const hue = new Uint8Array(POOL);\n    const fadeAlpha = Math.max(0.03, Math.min(1, 0.04 + (1 - trail) * 0.6));\n    let w = 0;\n    let h = 0;\n    let px = 0;\n    let py = 0;\n    let lx = 0;\n    let ly = 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    let cursor = 0;\n    let serial = 0;\n    let carry = 0;\n\n    const emit = (x: number, y: number, mvx: number, mvy: number) => {\n      const i = cursor;\n      cursor = (cursor + 1) % POOL;\n      serial++;\n      const a = hash(serial * 5) * Math.PI * 2;\n      const sp = 20 + hash(serial * 5 + 1) * 70;\n      px0[i] = x;\n      py0[i] = y;\n      vx0[i] = mvx * 0.35 + Math.cos(a) * sp;\n      vy0[i] = mvy * 0.35 + Math.sin(a) * sp;\n      rad[i] = size * (0.55 + hash(serial * 5 + 2) * 0.8);\n      life[i] = 1;\n      decay[i] = 0.55 + hash(serial * 5 + 3) * 0.6;\n      hue[i] = Math.floor(serial / 7) % list.length;\n    };\n\n    const step = (dt: number) => {\n      t += dt;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 4));\n      const ix = idle ? w * (0.5 + 0.36 * Math.sin(t * 0.9)) : px;\n      const iy = idle ? h * (0.5 + 0.3 * Math.sin(t * 1.8 + 0.5)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      const dx = tx - lx;\n      const dy = ty - ly;\n      const dist = Math.hypot(dx, dy);\n      if (dist > 0.5 && (idle || active || mix > 0.02)) {\n        carry += dist * 0.3 * intensity;\n        const k = Math.min(10, Math.floor(carry));\n        carry -= k;\n        if (carry > 4) carry = 0;\n        for (let e = 0; e < k; e++) {\n          const u = (e + 1) / k;\n          emit(lx + dx * u, ly + dy * u, dx / dt, dy / dt);\n        }\n      }\n      lx = tx;\n      ly = ty;\n      const drag = Math.exp(-dt * 2.4);\n      for (let i = 0; i < POOL; i++) {\n        if (life[i] <= 0) continue;\n        vx0[i] = vx0[i] * drag + Math.sin(py0[i] * 0.025 + t * 1.3) * 60 * dt;\n        vy0[i] = vy0[i] * drag + Math.cos(px0[i] * 0.025 - t * 1.1) * 60 * dt;\n        px0[i] += vx0[i] * dt;\n        py0[i] += vy0[i] * dt;\n        rad[i] *= 1 + dt * 0.5;\n        life[i] -= decay[i] * dt;\n      }\n    };\n\n    const draw = (clear: boolean) => {\n      if (clear) {\n        ctx.clearRect(0, 0, w, h);\n      } else {\n        ctx.globalCompositeOperation = \"destination-out\";\n        ctx.globalAlpha = 1;\n        ctx.fillStyle = `rgba(0,0,0,${fadeAlpha.toFixed(3)})`;\n        ctx.fillRect(0, 0, w, h);\n      }\n      ctx.globalCompositeOperation = \"lighter\";\n      for (let i = 0; i < POOL; i++) {\n        const l = life[i];\n        if (l <= 0) continue;\n        const r = rad[i];\n        ctx.globalAlpha = Math.min(1, l) * 0.42;\n        ctx.drawImage(sprites[hue[i]], px0[i] - r, py0[i] - r, r * 2, r * 2);\n      }\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\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);\n      draw(false);\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      const 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      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (!placed) {\n        placed = true;\n        px = w / 2;\n        py = h / 2;\n        lx = idle ? w * 0.5 : px;\n        ly = idle ? h * (0.5 + 0.3 * Math.sin(0.5)) : py;\n      }\n      if (reduced) {\n        if (!idle) {\n          lx = w * 0.2;\n          ly = h * 0.5;\n          px = w * 0.8;\n        }\n        for (let i = 0; i < 70; i++) step(1 / 60);\n        draw(true);\n      } else {\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    };\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  }, [palette, size, intensity, trail, idle]);\n\n  return (\n    <div ref={rootRef} className={`hb-qi4 ${className}`} style={style} {...rest}>\n      <style href=\"hb-cursor-fluid-splash\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qi4-canvas\" aria-hidden=\"true\" />\n      <div className=\"hb-qi4-content\">{children}</div>\n    </div>\n  );\n}\n"
    }
  ]
}