{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-liquid-ether",
  "type": "registry:component",
  "title": "Liquid Ether",
  "description": "Soft pastel clouds that drift on a slow current and get swept along by the speed and direction of the pointer, leaving a colored wake.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "fluid",
    "pastel",
    "gradient",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-liquid-ether",
  "files": [
    {
      "path": "registry/hyperblur/bg-liquid-ether.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-liquid-ether.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgLiquidEtherProps extends React.HTMLAttributes<HTMLDivElement> {\n  colors?: string[];\n  background?: string;\n  blobSize?: number;\n  intensity?: number;\n  force?: number;\n  speed?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-qj5 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-qj5-c { display: block; width: 100%; height: 100%; }\n`;\n\nconst defaultColors = [\"#ff9ecf\", \"#9ec5ff\", \"#b9a6ff\", \"#8ff0d6\", \"#ffd59e\"];\n\nfunction rnd(seed: number, i: number) {\n  let x = (Math.imul(i + 1, 0x9e3779b1) + Math.imul(seed | 0, 0x85ebca6b)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nfunction rgb(hex: string) {\n  const m = hex.trim().replace(\"#\", \"\");\n  const full = m.length === 3 ? m.split(\"\").map((c) => c + c).join(\"\") : m.slice(0, 6);\n  const v = parseInt(full, 16);\n  if (Number.isNaN(v)) return [255, 255, 255];\n  return [(v >> 16) & 255, (v >> 8) & 255, v & 255];\n}\n\nexport function BgLiquidEther({\n  colors = defaultColors,\n  background = \"#0b0a12\",\n  blobSize = 0.42,\n  intensity = 0.8,\n  force = 1,\n  speed = 1,\n  seed = 5,\n  className = \"\",\n  style,\n  ...rest\n}: BgLiquidEtherProps) {\n  const wrapRef = 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 wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    const buffer = document.createElement(\"canvas\");\n    const bctx = buffer.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx || !bctx) return;\n\n    const tones = palette.split(\"|\").map(rgb);\n    const count = Math.max(4, Math.min(14, tones.length * 2));\n    const scale = 0.25;\n    const bx = new Float32Array(count);\n    const by = new Float32Array(count);\n    const vx = new Float32Array(count);\n    const vy = new Float32Array(count);\n    const sz = new Float32Array(count);\n    const p1 = new Float32Array(count);\n    const p2 = new Float32Array(count);\n    for (let i = 0; i < count; i++) {\n      bx[i] = 0.1 + rnd(seed, i * 6 + 1) * 0.8;\n      by[i] = 0.1 + rnd(seed, i * 6 + 2) * 0.8;\n      sz[i] = 0.7 + rnd(seed, i * 6 + 3) * 0.6;\n      p1[i] = rnd(seed, i * 6 + 4) * 6.283;\n      p2[i] = rnd(seed, i * 6 + 5) * 6.283;\n    }\n\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 pvx = 0;\n    let pvy = 0;\n    let placed = false;\n    let hue = 0;\n\n    function idleX(tt: number) {\n      return w * (0.5 + 0.34 * Math.sin(tt * 0.5 + 0.7));\n    }\n    function idleY(tt: number) {\n      return h * (0.5 + 0.3 * Math.sin(tt * 0.83 + 2.4));\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 ? 14 : 3));\n      const nx = px + (gx - px) * k;\n      const ny = py + (gy - py) * k;\n      if (dt > 0) {\n        const m = 1 - Math.exp(-dt * 8);\n        pvx += ((nx - px) / dt - pvx) * m;\n        pvy += ((ny - py) / dt - pvy) * m;\n      }\n      px = nx;\n      py = ny;\n    }\n\n    function step(dt: number) {\n      const reach = Math.max(w, h) * 0.45;\n      for (let i = 0; i < count; i++) {\n        const x = bx[i] * w;\n        const y = by[i] * h;\n        const a =\n          (Math.sin(x * 0.0035 + t * 0.21 + p1[i]) +\n            Math.cos(y * 0.0042 - t * 0.17 + p2[i]) +\n            Math.sin((x + y) * 0.0021 + t * 0.11)) *\n          Math.PI *\n          0.7;\n        const flow = 26 * speed;\n        vx[i] += (Math.cos(a) * flow - vx[i]) * Math.min(1, dt * 0.9);\n        vy[i] += (Math.sin(a) * flow - vy[i]) * Math.min(1, dt * 0.9);\n        const dx = x - px;\n        const dy = y - py;\n        const d = Math.sqrt(dx * dx + dy * dy);\n        if (d < reach) {\n          const k = 1 - d / reach;\n          vx[i] += pvx * k * k * dt * 2.4 * force;\n          vy[i] += pvy * k * k * dt * 2.4 * force;\n        }\n        if (x < w * 0.05) vx[i] += 60 * dt;\n        if (x > w * 0.95) vx[i] -= 60 * dt;\n        if (y < h * 0.05) vy[i] += 60 * dt;\n        if (y > h * 0.95) vy[i] -= 60 * dt;\n        bx[i] += (vx[i] * dt) / w;\n        by[i] += (vy[i] * dt) / h;\n      }\n      hue += dt * 0.35;\n    }\n\n    function blob(x: number, y: number, r: number, vxx: number, vyy: number, c: number[], alpha: number) {\n      if (!bctx || !c) return;\n      const mag = Math.sqrt(vxx * vxx + vyy * vyy);\n      const stretch = 1 + Math.min(1.1, mag / 140);\n      bctx.save();\n      bctx.translate(x, y);\n      bctx.rotate(Math.atan2(vyy, vxx));\n      bctx.scale(stretch, 1 / Math.sqrt(stretch));\n      const g = bctx.createRadialGradient(0, 0, 0, 0, 0, r);\n      g.addColorStop(0, `rgba(${c[0]},${c[1]},${c[2]},${alpha.toFixed(3)})`);\n      g.addColorStop(0.55, `rgba(${c[0]},${c[1]},${c[2]},${(alpha * 0.38).toFixed(3)})`);\n      g.addColorStop(1, `rgba(${c[0]},${c[1]},${c[2]},0)`);\n      bctx.fillStyle = g;\n      bctx.fillRect(-r, -r, r * 2, r * 2);\n      bctx.restore();\n    }\n\n    function draw() {\n      if (!ctx || !bctx || !w || !h) return;\n      const W = buffer.width;\n      const H = buffer.height;\n      bctx.globalCompositeOperation = \"source-over\";\n      bctx.globalAlpha = 1;\n      bctx.fillStyle = background;\n      bctx.fillRect(0, 0, W, H);\n      bctx.globalCompositeOperation = \"screen\";\n      const base = Math.min(W, H) * blobSize;\n      for (let i = 0; i < count; i++) {\n        blob(bx[i] * W, by[i] * H, base * sz[i], vx[i], vy[i], tones[i % tones.length], intensity);\n      }\n      const pm = Math.sqrt(pvx * pvx + pvy * pvy);\n      const splash = Math.min(1, pm / 420) * intensity * force;\n      if (splash > 0.02) {\n        const c = tones[(((Math.floor(hue) || 0) % tones.length) + tones.length) % tones.length];\n        blob(px * scale, py * scale, base * 0.55, pvx, pvy, c, splash * 0.85);\n      }\n      bctx.globalCompositeOperation = \"source-over\";\n      ctx.clearRect(0, 0, w, h);\n      ctx.imageSmoothingEnabled = true;\n      ctx.imageSmoothingQuality = \"high\";\n      ctx.drawImage(buffer, 0, 0, w, h);\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      buffer.width = Math.max(1, Math.round(w * scale));\n      buffer.height = Math.max(1, Math.round(h * scale));\n      if (motion.matches) still();\n      else {\n        track(0);\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 = 0;\n      inside = false;\n      placed = false;\n      pvx = 0;\n      pvy = 0;\n      track(0);\n      draw();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (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  }, [palette, background, blobSize, intensity, force, speed, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qj5 ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-bg-liquid-ether\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qj5-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}