{
  "$schema": "https://www.cooki-ui.design/schema/registry-item.json",
  "name": "animated-bubble-particles",
  "type": "registry:ui",
  "title": "Animated Bubble Particles",
  "description": "Glassmorphic bubble particle canvas with organic buoyancy, specular reflections, mouse repulsion, and pop burst animations.",
  "category": "backgrounds",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "tags": [
    "backgrounds",
    "particles",
    "bubbles",
    "canvas",
    "interactive",
    "physics"
  ],
  "files": [
    {
      "path": "registry/backgrounds/animated-bubble-particles/animated-bubble-particles.tsx",
      "type": "registry:ui",
      "target": "components/ui/animated-bubble-particles.tsx",
      "content": "\"use client\";\n\nimport React, {\n  useEffect,\n  useRef,\n  useCallback,\n  useState,\n} from \"react\";\nimport { cn } from \"@/lib/utils\";\n\ninterface Bubble {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n  radius: number;\n  baseRadius: number;\n  opacity: number;\n  color: string;\n  hue: number;\n  phase: number;\n  wobble: number;\n  depth: number;\n  glowIntensity: number;\n  shimmerOffset: number;\n  life: number;\n  popped: boolean;\n  popProgress: number;\n}\n\nexport interface AnimatedBubbleParticlesProps {\n  className?: string;\n  colorHueStart?: number;\n  colorHueEnd?: number;\n  saturation?: number;\n  lightness?: number;\n  maxBubbles?: number;\n  spawnInterval?: number;\n  minRadius?: number;\n  maxRadius?: number;\n  speed?: number;\n  mouseRepelRadius?: number;\n  mouseInteraction?: boolean;\n  enableGlow?: boolean;\n  enablePop?: boolean;\n  backgroundColor?: string;\n  zIndex?: number;\n  children?: React.ReactNode;\n}\n\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\nconst clamp = (v: number, lo: number, hi: number) =>\n  Math.max(lo, Math.min(hi, v));\nconst rand = (min: number, max: number) => min + Math.random() * (max - min);\n\nfunction createBubble(\n  w: number,\n  h: number,\n  hueStart: number,\n  hueEnd: number,\n  sat: number,\n  lit: number,\n  minR: number,\n  maxR: number\n): Bubble {\n  const depth = rand(0.15, 1);\n  const baseRadius = lerp(minR, maxR, depth) * rand(0.7, 1.3);\n  const hue = rand(hueStart, hueEnd);\n  return {\n    x: rand(baseRadius, Math.max(baseRadius + 10, w - baseRadius)),\n    y: h + baseRadius + rand(0, 80),\n    vx: rand(-0.4, 0.4),\n    vy: -rand(0.5, 1.8) * (0.4 + depth * 0.8),\n    radius: baseRadius,\n    baseRadius,\n    opacity: rand(0.25, 0.7) * depth,\n    color: `hsl(${hue}, ${sat}%, ${lit}%)`,\n    hue,\n    phase: rand(0, Math.PI * 2),\n    wobble: rand(8, 40) * (1 - depth * 0.6),\n    depth,\n    glowIntensity: rand(6, 22) * depth,\n    shimmerOffset: rand(0, Math.PI * 2),\n    life: 1,\n    popped: false,\n    popProgress: 0,\n  };\n}\n\nexport const AnimatedBubbleParticles: React.FC<AnimatedBubbleParticlesProps> = ({\n  className,\n  colorHueStart = 200,\n  colorHueEnd = 260,\n  saturation = 80,\n  lightness = 65,\n  maxBubbles = 45,\n  spawnInterval = 280,\n  minRadius = 8,\n  maxRadius = 45,\n  speed = 1,\n  mouseRepelRadius = 120,\n  mouseInteraction = true,\n  enableGlow = true,\n  enablePop = true,\n  backgroundColor = \"transparent\",\n  zIndex = 0,\n  children,\n}) => {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const bubblesRef = useRef<Bubble[]>([]);\n  const mouseRef = useRef({ x: -9999, y: -9999, active: false });\n  const rafRef = useRef<number>(0);\n  const lastSpawnRef = useRef<number>(0);\n  const [dims, setDims] = useState({ w: 0, h: 0 });\n\n  useEffect(() => {\n    const container = containerRef.current;\n    if (!container) return;\n\n    const updateSize = () => {\n      const w = container.clientWidth || container.offsetWidth || 300;\n      const h = container.clientHeight || container.offsetHeight || 300;\n      if (w > 0 && h > 0) {\n        setDims({ w, h });\n        if (canvasRef.current) {\n          canvasRef.current.width = w;\n          canvasRef.current.height = h;\n        }\n      }\n    };\n\n    updateSize();\n\n    const ro = new ResizeObserver((entries) => {\n      for (const e of entries) {\n        const { width, height } = e.contentRect;\n        const w = Math.round(width) || container.clientWidth;\n        const h = Math.round(height) || container.clientHeight;\n        if (w > 0 && h > 0) {\n          setDims({ w, h });\n          if (canvasRef.current) {\n            canvasRef.current.width = w;\n            canvasRef.current.height = h;\n          }\n        }\n      }\n    });\n    ro.observe(container);\n\n    window.addEventListener(\"resize\", updateSize);\n\n    return () => {\n      ro.disconnect();\n      window.removeEventListener(\"resize\", updateSize);\n    };\n  }, []);\n\n  useEffect(() => {\n    if (!mouseInteraction) return;\n    const container = containerRef.current;\n    if (!container) return;\n\n    const onMove = (e: MouseEvent) => {\n      const rect = container.getBoundingClientRect();\n      mouseRef.current = {\n        x: e.clientX - rect.left,\n        y: e.clientY - rect.top,\n        active: true,\n      };\n    };\n    const onLeave = () => {\n      mouseRef.current.active = false;\n    };\n    const onClick = (e: MouseEvent) => {\n      if (!enablePop) return;\n      const rect = container.getBoundingClientRect();\n      const cx = e.clientX - rect.left;\n      const cy = e.clientY - rect.top;\n      bubblesRef.current.forEach((b) => {\n        const dx = b.x - cx;\n        const dy = b.y - cy;\n        if (Math.sqrt(dx * dx + dy * dy) < b.radius * 1.4 && !b.popped) {\n          b.popped = true;\n        }\n      });\n    };\n\n    container.addEventListener(\"mousemove\", onMove);\n    container.addEventListener(\"mouseleave\", onLeave);\n    container.addEventListener(\"click\", onClick);\n    return () => {\n      container.removeEventListener(\"mousemove\", onMove);\n      container.removeEventListener(\"mouseleave\", onLeave);\n      container.removeEventListener(\"click\", onClick);\n    };\n  }, [mouseInteraction, enablePop]);\n\n  const drawBubble = useCallback(\n    (ctx: CanvasRenderingContext2D, b: Bubble, t: number) => {\n      if (b.popped) {\n        const p = b.popProgress;\n        const r = b.radius * (1 + p * 1.6);\n        ctx.save();\n        ctx.globalAlpha = (1 - p) * b.opacity * 1.2;\n        ctx.beginPath();\n        ctx.arc(b.x, b.y, r, 0, Math.PI * 2);\n        ctx.strokeStyle = b.color;\n        ctx.lineWidth = lerp(3, 0.5, p);\n        ctx.stroke();\n        for (let i = 0; i < 7; i++) {\n          const angle = (i / 7) * Math.PI * 2 + p * 2;\n          const dist = r * 0.9 * p;\n          const sx = b.x + Math.cos(angle) * dist;\n          const sy = b.y + Math.sin(angle) * dist;\n          ctx.beginPath();\n          ctx.arc(sx, sy, lerp(3, 0.5, p), 0, Math.PI * 2);\n          ctx.fillStyle = b.color;\n          ctx.fill();\n        }\n        ctx.restore();\n        return;\n      }\n\n      const shimmer = Math.sin(t * 1.6 + b.shimmerOffset);\n      const wobbleX = Math.sin(t * 0.9 + b.phase) * b.wobble * 0.1;\n\n      if (enableGlow && b.glowIntensity > 0) {\n        ctx.save();\n        ctx.globalAlpha = b.opacity * 0.35;\n        const glowGrad = ctx.createRadialGradient(\n          b.x + wobbleX,\n          b.y,\n          b.radius * 0.1,\n          b.x + wobbleX,\n          b.y,\n          b.radius + b.glowIntensity\n        );\n        glowGrad.addColorStop(0, b.color);\n        glowGrad.addColorStop(1, \"transparent\");\n        ctx.fillStyle = glowGrad;\n        ctx.beginPath();\n        ctx.arc(\n          b.x + wobbleX,\n          b.y,\n          b.radius + b.glowIntensity,\n          0,\n          Math.PI * 2\n        );\n        ctx.fill();\n        ctx.restore();\n      }\n\n      ctx.save();\n      ctx.globalAlpha = clamp(b.opacity * (0.8 + shimmer * 0.2), 0, 1);\n\n      const bodyGrad = ctx.createRadialGradient(\n        b.x + wobbleX - b.radius * 0.3,\n        b.y - b.radius * 0.3,\n        b.radius * 0.05,\n        b.x + wobbleX,\n        b.y,\n        b.radius\n      );\n      bodyGrad.addColorStop(0, `hsla(${b.hue}, ${saturation}%, 95%, 0.9)`);\n      bodyGrad.addColorStop(0.35, `${b.color}`);\n      bodyGrad.addColorStop(\n        0.75,\n        `hsla(${b.hue + 20}, ${saturation}%, ${lightness - 15}%, 0.85)`\n      );\n      bodyGrad.addColorStop(\n        1,\n        `hsla(${b.hue + 40}, ${saturation}%, ${lightness - 25}%, 0.5)`\n      );\n\n      ctx.fillStyle = bodyGrad;\n      ctx.beginPath();\n      ctx.arc(b.x + wobbleX, b.y, b.radius, 0, Math.PI * 2);\n      ctx.fill();\n\n      ctx.strokeStyle = `hsla(${b.hue}, ${saturation}%, 95%, ${\n        0.3 + shimmer * 0.15\n      })`;\n      ctx.lineWidth = clamp(b.radius * 0.07, 0.5, 2.5);\n      ctx.stroke();\n\n      const specR = b.radius * 0.38;\n      const specGrad = ctx.createRadialGradient(\n        b.x + wobbleX - b.radius * 0.28,\n        b.y - b.radius * 0.35,\n        0,\n        b.x + wobbleX - b.radius * 0.28,\n        b.y - b.radius * 0.35,\n        specR\n      );\n      specGrad.addColorStop(0, `rgba(255,255,255,${0.7 + shimmer * 0.15})`);\n      specGrad.addColorStop(0.6, `rgba(255,255,255,0.12)`);\n      specGrad.addColorStop(1, `rgba(255,255,255,0)`);\n      ctx.globalAlpha = 1;\n      ctx.fillStyle = specGrad;\n      ctx.beginPath();\n      ctx.arc(\n        b.x + wobbleX - b.radius * 0.28,\n        b.y - b.radius * 0.35,\n        specR,\n        0,\n        Math.PI * 2\n      );\n      ctx.fill();\n\n      const refGrad = ctx.createRadialGradient(\n        b.x + wobbleX + b.radius * 0.2,\n        b.y + b.radius * 0.5,\n        0,\n        b.x + wobbleX + b.radius * 0.2,\n        b.y + b.radius * 0.5,\n        b.radius * 0.25\n      );\n      refGrad.addColorStop(0, `rgba(255,255,255,0.18)`);\n      refGrad.addColorStop(1, `rgba(255,255,255,0)`);\n      ctx.fillStyle = refGrad;\n      ctx.beginPath();\n      ctx.arc(\n        b.x + wobbleX + b.radius * 0.2,\n        b.y + b.radius * 0.5,\n        b.radius * 0.25,\n        0,\n        Math.PI * 2\n      );\n      ctx.fill();\n\n      ctx.restore();\n    },\n    [enableGlow, saturation, lightness]\n  );\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas || dims.w === 0 || dims.h === 0) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let running = true;\n    const { w, h } = dims;\n\n    const tick = (ts: number) => {\n      if (!running) return;\n      const t = ts / 1000;\n\n      if (\n        t - lastSpawnRef.current > spawnInterval / 1000 &&\n        bubblesRef.current.length < maxBubbles\n      ) {\n        bubblesRef.current.push(\n          createBubble(\n            w,\n            h,\n            colorHueStart,\n            colorHueEnd,\n            saturation,\n            lightness,\n            minRadius,\n            maxRadius\n          )\n        );\n        lastSpawnRef.current = t;\n      }\n\n      ctx.clearRect(0, 0, w, h);\n\n      const mx = mouseRef.current.x;\n      const my = mouseRef.current.y;\n      const mActive = mouseRef.current.active && mouseInteraction;\n\n      bubblesRef.current.sort((a, b) => a.depth - b.depth);\n\n      bubblesRef.current = bubblesRef.current.filter((b) => {\n        if (b.popped) {\n          b.popProgress += 0.055;\n          drawBubble(ctx, b, t);\n          return b.popProgress < 1;\n        }\n\n        const wobble = Math.sin(t * 0.9 + b.phase) * b.wobble * 0.012;\n        b.x += b.vx + wobble;\n        b.y += b.vy * speed;\n\n        if (mActive) {\n          const dx = b.x - mx;\n          const dy = b.y - my;\n          const dist = Math.sqrt(dx * dx + dy * dy);\n          if (dist < mouseRepelRadius && dist > 0) {\n            const force = ((mouseRepelRadius - dist) / mouseRepelRadius) * 1.8;\n            b.vx += (dx / dist) * force * 0.06;\n            b.vy += (dy / dist) * force * 0.04;\n          }\n        }\n\n        b.vx *= 0.978;\n        b.vy = lerp(\n          b.vy,\n          -rand(0.5, 1.8) * (0.4 + b.depth * 0.8) * speed,\n          0.015\n        );\n\n        const xOff = Math.sin(t * 0.9 + b.phase) * b.wobble * 0.1;\n        if (b.x + xOff < b.radius || b.x + xOff > w - b.radius) {\n          b.vx *= -0.5;\n        }\n\n        b.radius =\n          b.baseRadius * (1 + Math.sin(t * 1.1 + b.shimmerOffset) * 0.035);\n\n        drawBubble(ctx, b, t);\n\n        return b.y + b.radius > -80;\n      });\n\n      rafRef.current = requestAnimationFrame(tick);\n    };\n\n    rafRef.current = requestAnimationFrame(tick);\n    return () => {\n      running = false;\n      cancelAnimationFrame(rafRef.current);\n    };\n  }, [\n    dims,\n    colorHueStart,\n    colorHueEnd,\n    saturation,\n    lightness,\n    maxBubbles,\n    spawnInterval,\n    minRadius,\n    maxRadius,\n    speed,\n    mouseRepelRadius,\n    mouseInteraction,\n    enableGlow,\n    drawBubble,\n  ]);\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\n        \"relative overflow-hidden w-full h-full min-h-[300px] select-none\",\n        className\n      )}\n      style={{ backgroundColor, zIndex }}\n    >\n      <canvas\n        ref={canvasRef}\n        width={dims.w}\n        height={dims.h}\n        className=\"absolute inset-0 w-full h-full pointer-events-none\"\n        style={{ zIndex: 0 }}\n      />\n      {children && (\n        <div className=\"absolute inset-0 z-10 flex items-center justify-center pointer-events-none\">\n          {children}\n        </div>\n      )}\n    </div>\n  );\n};\n\nexport default AnimatedBubbleParticles;\n"
    }
  ]
}