{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-soft-clouds",
  "type": "registry:component",
  "title": "Soft Clouds",
  "description": "Three layers of shaded clouds, lit on top and tinted underneath, drifting at different speeds over a sky with a low sun glow. Comes in dusk, night and day.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "clouds",
    "sky",
    "parallax",
    "canvas",
    "calm"
  ],
  "docs": "https://hyperblur.dev/effects/bg-soft-clouds",
  "files": [
    {
      "path": "registry/hyperblur/bg-soft-clouds.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-soft-clouds.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgSoftCloudsProps extends React.HTMLAttributes<HTMLDivElement> {\n  time?: \"dusk\" | \"night\" | \"day\";\n  accent?: string;\n  density?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-vd14 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-vd14-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-vd14-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nconst skies = {\n  dusk: { sky: [\"#121733\", \"#3a3466\", \"#c9837a\", \"#f0b48a\"], lit: \"#ffe6d2\", shade: \"#5d4f80\", glow: \"#ffb37a\" },\n  night: { sky: [\"#03050c\", \"#08102a\", \"#13224a\", \"#1e3466\"], lit: \"#a9bde6\", shade: \"#141b36\", glow: \"#7fb3ff\" },\n  day: { sky: [\"#2f6fd6\", \"#5b94ea\", \"#9cc3f5\", \"#d8e9ff\"], lit: \"#ffffff\", shade: \"#9db3d6\", glow: \"#fff1cf\" },\n};\n\nfunction hash(i: number) {\n  let x = Math.imul(i ^ 0xa4093822, 0x299f31d0);\n  x ^= x >>> 16;\n  x = Math.imul(x, 0x082efa98);\n  x ^= x >>> 13;\n  return (x >>> 0) / 4294967296;\n}\n\nfunction cloudSprite(seed: number, lit: string, shade: string) {\n  const W = 320;\n  const H = 150;\n  const cv = document.createElement(\"canvas\");\n  cv.width = W;\n  cv.height = H;\n  const g = cv.getContext(\"2d\");\n  if (!g) return cv;\n  const puffs = 7 + Math.floor(hash(seed) * 5);\n  for (let i = 0; i < puffs; i++) {\n    const u = (i + 0.5) / puffs;\n    const hump = Math.sin(u * Math.PI);\n    const r = H * (0.16 + 0.2 * hump + 0.08 * hash(seed * 13 + i));\n    const x = W * (0.1 + 0.8 * u) + (hash(seed * 17 + i) - 0.5) * 18;\n    const y = H * 0.72 - hump * H * 0.18 - hash(seed * 19 + i) * H * 0.1;\n    const grad = g.createRadialGradient(x, y, r * 0.2, x, y, r);\n    grad.addColorStop(0, \"rgba(255,255,255,1)\");\n    grad.addColorStop(0.65, \"rgba(255,255,255,0.75)\");\n    grad.addColorStop(1, \"rgba(255,255,255,0)\");\n    g.fillStyle = grad;\n    g.beginPath();\n    g.arc(x, y, r, 0, Math.PI * 2);\n    g.fill();\n  }\n  const base = g.createLinearGradient(0, 0, 0, H);\n  base.addColorStop(0, \"rgba(255,255,255,1)\");\n  base.addColorStop(0.68, \"rgba(255,255,255,1)\");\n  base.addColorStop(1, \"rgba(255,255,255,0)\");\n  g.globalCompositeOperation = \"destination-in\";\n  g.fillStyle = base;\n  g.fillRect(0, 0, W, H);\n  g.globalCompositeOperation = \"source-atop\";\n  const tone = g.createLinearGradient(0, H * 0.15, 0, H * 0.9);\n  tone.addColorStop(0, lit);\n  tone.addColorStop(0.45, lit);\n  tone.addColorStop(1, shade);\n  g.fillStyle = tone;\n  g.fillRect(0, 0, W, H);\n  return cv;\n}\n\nexport function BgSoftClouds({\n  time = \"dusk\",\n  accent,\n  density = 1,\n  speed = 1,\n  children,\n  className = \"\",\n  style,\n  ...rest\n}: BgSoftCloudsProps) {\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 context = canvas?.getContext(\"2d\");\n    if (!wrap || !canvas || !context) return;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n    const g: CanvasRenderingContext2D = context;\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const sky = skies[time] ?? skies.dusk;\n    const glow = accent ?? sky.glow;\n    const sprites = Array.from({ length: 6 }, (_, i) => cloudSprite(i * 31 + 7, sky.lit, sky.shade));\n    const layers = [\n      { scale: 0.42, top: 0.5, spread: 0.18, v: 0.006, a: 0.55, n: 6 },\n      { scale: 0.7, top: 0.3, spread: 0.26, v: 0.012, a: 0.78, n: 5 },\n      { scale: 1.15, top: 0.08, spread: 0.42, v: 0.022, a: 0.95, n: 4 },\n    ];\n    const clouds = layers.flatMap((L, li) =>\n      Array.from({ length: Math.max(1, Math.round(L.n * Math.max(0.2, density))) }, (_, i) => ({\n        li,\n        x: (i + hash(li * 50 + i * 3 + 1) * 0.8) / Math.max(1, Math.round(L.n * Math.max(0.2, density))),\n        y: L.top + hash(li * 50 + i * 3 + 2) * L.spread,\n        s: 0.75 + 0.5 * hash(li * 50 + i * 3 + 3),\n        sp: Math.floor(hash(li * 50 + i * 3 + 4) * sprites.length),\n        flip: hash(li * 50 + i * 3 + 5) > 0.5,\n      })),\n    );\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let raf = 0;\n    let prev = 0;\n    let visible = true;\n\n    function draw() {\n      if (!w || !h) return;\n      g.globalCompositeOperation = \"source-over\";\n      g.globalAlpha = 1;\n      const bg = g.createLinearGradient(0, 0, 0, h);\n      sky.sky.forEach((c, i) => bg.addColorStop(i / (sky.sky.length - 1), c));\n      g.fillStyle = bg;\n      g.fillRect(0, 0, w, h);\n      const sx = w * 0.72;\n      const sy = h * 0.86;\n      const sun = g.createRadialGradient(sx, sy, 0, sx, sy, Math.max(w, h) * 0.7);\n      sun.addColorStop(0, glow);\n      sun.addColorStop(1, \"rgba(0,0,0,0)\");\n      g.globalAlpha = 0.55;\n      g.fillStyle = sun;\n      g.fillRect(0, 0, w, h);\n      const unit = Math.max(w * 0.55, h * 0.9);\n      for (let li = 0; li < layers.length; li++) {\n        const L = layers[li];\n        for (const c of clouds) {\n          if (c.li !== li) continue;\n          const cw = unit * L.scale * c.s;\n          const ch = cw * (150 / 320);\n          const span = w + cw * 1.2;\n          const x = ((((c.x + t * L.v) % 1) + 1) % 1) * span - cw * 0.6;\n          const y = c.y * h + Math.sin(t * 0.2 + c.x * 9) * 3 * L.scale;\n          g.globalAlpha = L.a;\n          if (c.flip) {\n            g.save();\n            g.translate(x + cw, y);\n            g.scale(-1, 1);\n            g.drawImage(sprites[c.sp], 0, 0, cw, ch);\n            g.restore();\n          } else g.drawImage(sprites[c.sp], x, y, cw, ch);\n        }\n        if (li < layers.length - 1) {\n          const haze = g.createLinearGradient(0, h * 0.4, 0, h);\n          haze.addColorStop(0, \"rgba(0,0,0,0)\");\n          haze.addColorStop(1, sky.sky[sky.sky.length - 1]);\n          g.globalAlpha = 0.18;\n          g.fillStyle = haze;\n          g.fillRect(0, 0, w, h);\n        }\n      }\n      g.globalAlpha = 1;\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      g.imageSmoothingEnabled = true;\n      g.imageSmoothingQuality = \"high\";\n      if (motion.matches) t = 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      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) draw();\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  }, [time, accent, density, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-vd14 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-soft-clouds\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-vd14-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-vd14-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}