{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-ripple-water",
  "type": "registry:component",
  "title": "Ripple Water",
  "description": "A dark water surface where the pointer leaves trails of wavy rings and a click drops a stone. Raindrops fall on their own while nobody is touching it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "water",
    "ripple",
    "click",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-ripple-water",
  "files": [
    {
      "path": "registry/hyperblur/bg-ripple-water.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-ripple-water.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgRippleWaterProps extends React.HTMLAttributes<HTMLDivElement> {\n  background?: string;\n  color?: string;\n  speed?: number;\n  interval?: number;\n  maxRipples?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-qj4 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-qj4-c { display: block; width: 100%; height: 100%; }\n`;\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\ninterface Drop {\n  x: number;\n  y: number;\n  age: number;\n  amp: number;\n  phase: number;\n}\n\nexport function BgRippleWater({\n  background = \"#061122\",\n  color = \"#9cc4ff\",\n  speed = 1,\n  interval = 1.4,\n  maxRipples = 26,\n  seed = 3,\n  className = \"\",\n  style,\n  ...rest\n}: BgRippleWaterProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\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    if (!wrap || !host || !canvas || !ctx) return;\n\n    const TAU = Math.PI * 2;\n    const life = 3.4;\n    const velocity = 70;\n    const cap = Math.max(4, Math.min(80, Math.floor(maxRipples)));\n    const every = Math.max(0.3, interval);\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let drops: Drop[] = [];\n    let inside = false;\n    let lastX = -999;\n    let lastY = -999;\n    let lastT = -1;\n    let idleClock = 0;\n    let idleCount = 0;\n    let dropCount = 0;\n    let shade: CanvasGradient | null = null;\n\n    function add(x: number, y: number, amp: number, age = 0) {\n      dropCount++;\n      drops.push({ x, y, age, amp, phase: rnd(seed, dropCount) * TAU });\n      if (drops.length > cap) drops.splice(0, drops.length - cap);\n    }\n\n    function idleDrop(age = 0) {\n      idleCount++;\n      const x = w * (0.12 + 0.76 * rnd(seed, idleCount * 2 + 101));\n      const y = h * (0.14 + 0.72 * rnd(seed, idleCount * 2 + 102));\n      add(x, y, 0.75 + 0.25 * rnd(seed, idleCount + 303), age);\n    }\n\n    function seedDrops() {\n      drops = [];\n      idleCount = 0;\n      dropCount = 0;\n      idleDrop(2.2);\n      idleDrop(1.3);\n      idleDrop(0.4);\n      idleClock = 0;\n    }\n\n    function step(dt: number) {\n      const adv = dt * speed;\n      for (const d of drops) d.age += adv;\n      drops = drops.filter((d) => d.age < life);\n      if (!inside) {\n        idleClock += adv;\n        if (idleClock >= every) {\n          idleClock = 0;\n          idleDrop();\n        }\n      }\n    }\n\n    function ring(x: number, y: number, r: number, wob: number, ph: number) {\n      if (!ctx) return;\n      ctx.beginPath();\n      const seg = Math.max(28, Math.min(96, Math.round(r / 3)));\n      for (let i = 0; i <= seg; i++) {\n        const a = (i / seg) * TAU;\n        const rr = r + Math.sin(a * 6 + ph) * wob + Math.sin(a * 11 - ph * 1.7) * wob * 0.5;\n        const X = x + Math.cos(a) * rr;\n        const Y = y + Math.sin(a) * rr * 0.92;\n        if (i === 0) ctx.moveTo(X, Y);\n        else ctx.lineTo(X, Y);\n      }\n      ctx.closePath();\n    }\n\n    function draw() {\n      if (!ctx || !w || !h) return;\n      ctx.globalAlpha = 1;\n      ctx.fillStyle = background;\n      ctx.fillRect(0, 0, w, h);\n      if (shade) {\n        ctx.fillStyle = shade;\n        ctx.fillRect(0, 0, w, h);\n      }\n      for (const d of drops) {\n        if (d.age < 0) continue;\n        const p = d.age / life;\n        const fade = Math.pow(1 - p, 1.6) * d.amp;\n        const front = d.age * velocity;\n        const wob = 1.8 * (1 - p) * d.amp;\n        const ph = d.phase + d.age * 3;\n        const glow = ctx.createRadialGradient(d.x, d.y, Math.max(0, front - 26), d.x, d.y, front + 8);\n        glow.addColorStop(0, \"rgba(0,0,0,0)\");\n        glow.addColorStop(0.78, color);\n        glow.addColorStop(1, \"rgba(0,0,0,0)\");\n        ctx.globalAlpha = fade * 0.1;\n        ctx.fillStyle = glow;\n        ctx.fillRect(d.x - front - 10, d.y - front - 10, (front + 10) * 2, (front + 10) * 2);\n        for (let j = 0; j < 3; j++) {\n          const r = front - j * 15;\n          if (r <= 2) continue;\n          const a = fade * (1 - j * 0.3);\n          ctx.globalAlpha = a * 0.55;\n          ctx.strokeStyle = \"rgba(0,0,0,0.9)\";\n          ctx.lineWidth = 2;\n          ctx.save();\n          ctx.translate(1, 1.6);\n          ring(d.x, d.y, r, wob, ph + j);\n          ctx.stroke();\n          ctx.restore();\n          ctx.globalAlpha = a * 0.85;\n          ctx.strokeStyle = color;\n          ctx.lineWidth = 1.3 - j * 0.25;\n          ring(d.x, d.y, r, wob, ph + j);\n          ctx.stroke();\n        }\n      }\n      ctx.globalAlpha = 1;\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      const first = !w;\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      shade = ctx.createLinearGradient(0, 0, 0, h);\n      shade.addColorStop(0, \"rgba(255,255,255,0.05)\");\n      shade.addColorStop(0.5, \"rgba(255,255,255,0)\");\n      shade.addColorStop(1, \"rgba(0,0,0,0.3)\");\n      if (first || motion.matches) seedDrops();\n      draw();\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 frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      t += 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) {\n        seedDrops();\n        draw();\n      }\n    }\n\n    function point(e: PointerEvent) {\n      if (!host) return [0, 0];\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      return [(e.clientX - rect.left) * sx, (e.clientY - rect.top) * sy];\n    }\n\n    function move(e: PointerEvent) {\n      if (motion.matches) return;\n      inside = true;\n      const [x, y] = point(e);\n      const dx = x - lastX;\n      const dy = y - lastY;\n      if (dx * dx + dy * dy > 1600 && t - lastT > 0.09) {\n        add(x, y, 0.5);\n        lastX = x;\n        lastY = y;\n        lastT = t;\n      }\n    }\n\n    function down(e: PointerEvent) {\n      if (motion.matches) return;\n      inside = true;\n      const [x, y] = point(e);\n      add(x, y, 1);\n      lastX = x;\n      lastY = y;\n      lastT = t;\n    }\n\n    function leave(e: PointerEvent) {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\n      idleClock = every * 0.5;\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\", down, { 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\", down);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [background, color, speed, interval, maxRipples, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qj4 ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-bg-ripple-water\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qj4-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}