{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gooey-blob-merge",
  "title": "Gooey Blob Merge",
  "description": "Glossy liquid blobs that drift, stretch and fuse together like lava-lamp goo: your pointer becomes a blob of its own that pulls them into one shape, trails a drop behind it, and a click flicks off a little droplet.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/gooey-blob-merge/gooey-blob-merge.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface GooeyBlobMergeProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /** Three colours the goo blends between, top-left to bottom-right. */\n  colors?: [string, string, string];\n  background?: string;\n  /** Number of floating blobs (2–8). */\n  count?: number;\n  /** Size of the blobs, as a share of the shorter side. */\n  size?: number;\n  /** How readily blobs fuse together (0–1). */\n  goo?: number;\n}\n\nconst MAX = 16;\n\nconst VERTEX = `attribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `precision highp float;\nuniform vec2 uRes;\nuniform vec3 uBlobs[${MAX}];\nuniform vec3 uBg;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform float uGoo;\nvoid main() {\n  vec2 p = gl_FragCoord.xy;\n  float f = 0.0;\n  vec2 grad = vec2(0.0);\n  for (int i = 0; i < ${MAX}; i++) {\n    vec3 b = uBlobs[i];\n    if (b.z <= 0.0) continue;\n    vec2 d = p - b.xy;\n    // A soft kernel with a finite reach (2.4 radii): blobs only reach for neighbours that come close.\n    float R2 = b.z * b.z * 5.76;\n    float q = 1.0 - dot(d, d) / R2;\n    if (q <= 0.0) continue;\n    f += q * q;\n    grad += -4.0 * q / R2 * d;\n  }\n  // A lower threshold lets blobs reach further for each other before they meet.\n  float thr = mix(0.62, 0.36, uGoo);\n  float aa = 1.2 * length(grad) + 1e-4;\n  float inside = smoothstep(thr - aa * 0.5, thr + aa * 0.5, f);\n  vec2 uv = gl_FragCoord.xy / uRes;\n  vec3 base = mix(mix(uC0, uC1, smoothstep(0.0, 0.7, uv.x * 0.6 + (1.0 - uv.y) * 0.4)), uC2, smoothstep(0.45, 1.0, uv.x * 0.5 + (1.0 - uv.y) * 0.5));\n  // Light the goo as a dome that rises steeply from the edge and flattens on top (h = 1 - e^-k(f - thr)),\n  // so merged blobs read as one smooth drop, with no dimples at each blob's centre.\n  float e = exp(-max(f - thr, 0.0) * 9.0);\n  vec2 slope = grad * 9.0 * e * 26.0;\n  vec3 n = normalize(vec3(-slope, 1.0));\n  vec3 L = normalize(vec3(-0.45, 0.6, 0.65));\n  float diff = clamp(dot(n, L), 0.0, 1.0);\n  float spec = pow(clamp(dot(reflect(-L, n), vec3(0.0, 0.0, 1.0)), 0.0, 1.0), 28.0);\n  float rim = pow(1.0 - n.z, 1.5);\n  vec3 jelly = base * (0.62 + 0.5 * diff) + vec3(1.0) * spec * 0.6 + mix(base, vec3(1.0), 0.4) * rim * 0.25;\n  gl_FragColor = vec4(mix(uBg, jelly, inside), 1.0);\n}`;\n\nfunction rgb(hex: string): [number, number, number] {\n  const h = hex.replace(\"#\", \"\");\n  const full = h.length === 3 ? h.split(\"\").map((c) => c + c).join(\"\") : h.slice(0, 6);\n  const n = parseInt(full, 16) || 0;\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\ntype Drip = { x: number; y: number; vx: number; vy: number; r: number; age: number };\n\nexport function GooeyBlobMerge({ colors = [\"#ff6ac1\", \"#7b61ff\", \"#38d4ff\"], background = \"#0c0b12\", count = 6, size = 0.095, goo = 0.6, className, style, children, ...props }: GooeyBlobMergeProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const [failed, setFailed] = React.useState(false);\n  const live = React.useRef({ colors, background, count, size, goo });\n  const kick = React.useRef<() => void>(() => {});\n  React.useEffect(() => {\n    live.current = { colors, background, count, size, goo };\n    kick.current();\n  }, [colors, background, count, size, goo]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    const gl = canvas.getContext(\"webgl\", { antialias: false, premultipliedAlpha: false });\n    const fail = () => requestAnimationFrame(() => setFailed(true));\n    if (!gl) {\n      fail();\n      return;\n    }\n    const make = (type: number, src: string) => {\n      const sh = gl.createShader(type)!;\n      gl.shaderSource(sh, src);\n      gl.compileShader(sh);\n      return gl.getShaderParameter(sh, gl.COMPILE_STATUS) ? sh : null;\n    };\n    const vs = make(gl.VERTEX_SHADER, VERTEX);\n    const fs = make(gl.FRAGMENT_SHADER, FRAGMENT);\n    const program = gl.createProgram();\n    if (!vs || !fs || !program) {\n      fail();\n      return;\n    }\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.linkProgram(program);\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n      fail();\n      return;\n    }\n    gl.useProgram(program);\n    const buffer = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n    const aPos = gl.getAttribLocation(program, \"aPos\");\n    gl.enableVertexAttribArray(aPos);\n    gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);\n    const u = (n: string) => gl.getUniformLocation(program, n);\n    const U = { res: u(\"uRes\"), blobs: u(\"uBlobs\"), bg: u(\"uBg\"), c0: u(\"uC0\"), c1: u(\"uC1\"), c2: u(\"uC2\"), goo: u(\"uGoo\") };\n\n    const data = new Float32Array(MAX * 3);\n    const cursor = { x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0, r: 0, tr: 0 };\n    const drips: Drip[] = [];\n    let dpr = 1;\n    let time = 0;\n    let last = 0;\n    let raf = 0;\n    let visible = true;\n\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      canvas.width = Math.max(1, Math.round(root.clientWidth * dpr));\n      canvas.height = Math.max(1, Math.round(root.clientHeight * dpr));\n      gl.viewport(0, 0, canvas.width, canvas.height);\n    };\n    const draw = (dt: number) => {\n      const L = live.current;\n      const w = root.clientWidth;\n      const h = root.clientHeight;\n      const unit = Math.min(w, h) * L.size;\n      if (!reduce) time += dt;\n      data.fill(0);\n      let k = 0;\n      const put = (x: number, y: number, r: number) => {\n        if (k >= MAX) return;\n        data[k * 3] = x * dpr;\n        data[k * 3 + 1] = (h - y) * dpr;\n        data[k * 3 + 2] = r * dpr;\n        k++;\n      };\n      // Floating blobs drift on slow, looping paths around the middle.\n      const n = Math.max(2, Math.min(8, L.count));\n      for (let i = 0; i < n; i++) {\n        const a = (i / n) * Math.PI * 2;\n        const sp = 0.18 + (i % 3) * 0.07;\n        const x = w / 2 + Math.cos(a + time * sp) * w * (0.27 + 0.1 * Math.sin(time * 0.31 + i)) + Math.sin(time * 0.5 + i * 2.1) * w * 0.04;\n        const y = h / 2 + Math.sin(a * 1.3 + time * sp * 1.2) * h * (0.26 + 0.08 * Math.cos(time * 0.27 + i)) ;\n        put(x, y, unit * (0.75 + 0.35 * ((i * 7) % 5) / 4));\n      }\n      // The cursor blob: springs after the pointer and swells in when the pointer arrives.\n      const kk = 140;\n      const c = 2 * Math.sqrt(kk) * 0.55;\n      cursor.vx += (-(cursor.x - cursor.tx) * kk - cursor.vx * c) * dt;\n      cursor.vy += (-(cursor.y - cursor.ty) * kk - cursor.vy * c) * dt;\n      cursor.x += cursor.vx * dt;\n      cursor.y += cursor.vy * dt;\n      cursor.r += (cursor.tr - cursor.r) * (1 - Math.exp(-dt * 6));\n      if (cursor.r > 1) {\n        // Stretch along the motion: a smaller trailing blob makes it look like a drop of liquid.\n        put(cursor.x, cursor.y, cursor.r * unit);\n        put(cursor.x - cursor.vx * 0.06, cursor.y - cursor.vy * 0.06, cursor.r * unit * 0.6);\n      }\n      for (let i = drips.length - 1; i >= 0; i--) {\n        const d = drips[i];\n        d.age += dt;\n        d.vx *= Math.exp(-dt * 1.2);\n        d.vy *= Math.exp(-dt * 1.2);\n        d.x += d.vx * dt;\n        d.y += d.vy * dt;\n        const life = 1 - d.age / 2.4;\n        if (life <= 0) drips.splice(i, 1);\n        else put(d.x, d.y, d.r * unit * Math.min(1, life * 2));\n      }\n      gl.uniform2f(U.res, canvas.width, canvas.height);\n      gl.uniform3fv(U.blobs, data);\n      gl.uniform3fv(U.bg, rgb(L.background));\n      gl.uniform3fv(U.c0, rgb(L.colors[0]));\n      gl.uniform3fv(U.c1, rgb(L.colors[1]));\n      gl.uniform3fv(U.c2, rgb(L.colors[2]));\n      gl.uniform1f(U.goo, L.goo);\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n    };\n    const frame = (now: number) => {\n      const dt = Math.min(0.033, last ? (now - last) / 1000 : 1 / 60);\n      last = now;\n      draw(dt);\n      if (visible && !document.hidden && !reduce) raf = requestAnimationFrame(frame);\n      else last = 0;\n    };\n    const start = () => {\n      cancelAnimationFrame(raf);\n      raf = requestAnimationFrame(frame);\n    };\n    kick.current = start;\n    const local = (event: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width / root.offsetWidth || 1;\n      return { x: (event.clientX - r.left) / s, y: (event.clientY - r.top) / s };\n    };\n    const onEnter = (event: PointerEvent) => {\n      const p = local(event);\n      if (cursor.r < 0.05) {\n        cursor.x = p.x;\n        cursor.y = p.y;\n      }\n      cursor.tr = 0.85;\n    };\n    const onMove = (event: PointerEvent) => {\n      const p = local(event);\n      cursor.tx = p.x;\n      cursor.ty = p.y;\n      cursor.tr = 0.85;\n      if (reduce) {\n        cursor.x = p.x;\n        cursor.y = p.y;\n        cursor.r = 0.85;\n        draw(0);\n      }\n    };\n    const onLeave = () => (cursor.tr = 0);\n    const onDown = (event: PointerEvent) => {\n      if (reduce) return;\n      // A click flicks off a little drop in a random direction.\n      const p = local(event);\n      const a = Math.random() * Math.PI * 2;\n      const speed = 260 + Math.random() * 160;\n      drips.push({ x: p.x, y: p.y, vx: Math.cos(a) * speed, vy: Math.sin(a) * speed, r: 0.45, age: 0 });\n      if (drips.length > 6) drips.shift();\n    };\n    const ro = new ResizeObserver(() => {\n      resize();\n      draw(0);\n    });\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(root);\n    root.addEventListener(\"pointerenter\", onEnter);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerdown\", onDown);\n    resize();\n    start();\n    return () => {\n      cancelAnimationFrame(raf);\n      kick.current = () => {};\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointerenter\", onEnter);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointerdown\", onDown);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce]);\n\n  return (\n    <div ref={rootRef} className={cn(\"relative isolate overflow-hidden\", className)} style={{ background: failed ? `radial-gradient(circle at 40% 40%, ${colors[1]}55, transparent 60%), ${background}` : background, ...style }} {...props}>\n      {!failed && <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />}\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}