{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-dot-swell",
  "type": "registry:component",
  "title": "Dot Swell",
  "description": "A perspective sea of dots rolling under interfering swells, with crests brightening toward the accent color and the far rows fading into fog at the horizon.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "dots",
    "wave",
    "perspective",
    "canvas",
    "3d"
  ],
  "docs": "https://hyperblur.dev/effects/bg-dot-swell",
  "files": [
    {
      "path": "registry/hyperblur/bg-dot-swell.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-dot-swell.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgDotSwellProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  background?: string;\n  columns?: number;\n  rows?: number;\n  height?: number;\n  horizon?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-ve4 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-ve4-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ve4-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nfunction rgbOf(value: string, fallback: [number, number, number]): [number, number, number] {\n  const raw = value.trim().replace(\"#\", \"\");\n  const hex = raw.length === 3 ? raw.split(\"\").map((c) => c + c).join(\"\") : raw;\n  const n = parseInt(hex.slice(0, 6), 16);\n  if (hex.length < 6 || Number.isNaN(n)) return fallback;\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nexport function BgDotSwell({\n  color = \"#5b6a86\",\n  accent = \"#7fb3ff\",\n  background = \"#05060a\",\n  columns = 80,\n  rows = 40,\n  height = 1,\n  horizon = 0.34,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgDotSwellProps) {\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 canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!wrap || !canvas || !ctx) return;\n    const g: CanvasRenderingContext2D = ctx;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n\n    const ca = rgbOf(color, [91, 106, 134]);\n    const cb = rgbOf(accent, [127, 179, 255]);\n    const cols = Math.max(12, Math.min(140, Math.round(columns)));\n    const rws = Math.max(8, Math.min(90, Math.round(rows)));\n    const B = 10;\n    const fills: string[] = [];\n    for (let i = 0; i < B; i++) {\n      const k = i / (B - 1);\n      fills.push(`rgb(${Math.round(ca[0] + (cb[0] - ca[0]) * k)},${Math.round(ca[1] + (cb[1] - ca[1]) * k)},${Math.round(ca[2] + (cb[2] - ca[2]) * k)})`);\n    }\n    const A = 6;\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n\n    function surface(x: number, z: number) {\n      const r1 = Math.sqrt((x + 0.9) ** 2 + (z - 2.2) ** 2);\n      const r2 = Math.sqrt((x - 1.1) ** 2 + (z - 3.4) ** 2);\n      return (\n        0.09 * Math.sin(x * 1.9 + t * 0.9) +\n        0.07 * Math.sin(z * 2.6 - t * 1.25) +\n        0.06 * Math.sin(r1 * 6 - t * 2.1) +\n        0.05 * Math.sin(r2 * 5.2 - t * 1.7)\n      ) * height;\n    }\n\n    function render() {\n      if (!w || !h) return;\n      g.clearRect(0, 0, w, h);\n      const f = Math.max(w, h * 1.4) * 0.5;\n      const hy = h * horizon;\n      const cam = 0.62;\n      const zNear = 0.75;\n      const zFar = 5.2;\n      const spanX = 3.4 * Math.max(1, w / h / 1.4);\n      const buckets: Path2D[][] = [];\n      for (let a = 0; a < A; a++) {\n        const row: Path2D[] = [];\n        for (let c = 0; c < B; c++) row.push(new Path2D());\n        buckets.push(row);\n      }\n      for (let r = rws - 1; r >= 0; r--) {\n        const z = zNear + (zFar - zNear) * (r / (rws - 1));\n        const depth = (z - zNear) / (zFar - zNear);\n        const di = Math.min(A - 1, Math.floor(depth * A));\n        const size = Math.max(0.45, (2.2 / z) * (f / 300));\n        for (let c = 0; c < cols; c++) {\n          const x = -spanX + (2 * spanX * c) / (cols - 1);\n          const y = surface(x, z);\n          const px = w / 2 + (x / z) * f;\n          if (px < -10 || px > w + 10) continue;\n          const py = hy + ((cam - y) / z) * f;\n          if (py < -10 || py > h + 10) continue;\n          const k = Math.max(0, Math.min(B - 1, Math.round(((y / Math.max(0.05, height)) + 0.27) / 0.54 * (B - 1))));\n          const p = buckets[di][k];\n          p.moveTo(px + size, py);\n          p.arc(px, py, size * (1 + (k / (B - 1)) * 0.35), 0, 6.2832);\n        }\n      }\n      for (let a = A - 1; a >= 0; a--) {\n        g.globalAlpha = Math.max(0.08, 1 - a / A) * 0.95;\n        for (let c = 0; c < B; c++) {\n          g.fillStyle = fills[c];\n          g.fill(buckets[a][c]);\n        }\n      }\n      g.globalAlpha = 1;\n      const fog = g.createLinearGradient(0, hy - 10, 0, hy + h * 0.22);\n      fog.addColorStop(0, background);\n      fog.addColorStop(1, \"rgba(0,0,0,0)\");\n      g.fillStyle = fog;\n      g.fillRect(0, 0, w, hy + h * 0.22);\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 = 2.4;\n      render();\n    }\n\n    function resize() {\n      const nw = el.clientWidth;\n      const nh = el.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      cv.width = Math.max(1, Math.round(w * dpr));\n      cv.height = Math.max(1, Math.round(h * dpr));\n      g.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (motion.matches) still();\n      else render();\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      render();\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    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(el);\n    io.observe(el);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\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    };\n  }, [color, accent, background, columns, rows, height, horizon, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-ve4 ${className}`} style={{ background, ...style }} {...rest}>\n      <style href=\"hb-bg-dot-swell\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-ve4-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-ve4-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}