{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "snowfall",
  "type": "registry:ui",
  "title": "Snowfall",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Depth-sorted Canvas 2D snowfall simulation where larger foreground particles fall faster with higher opacity while drifting horizontally on sine waves.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/snowfall.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { Snowflake } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SnowfallProps {\n  /** Total number of snowflakes. Default: 140 */\n  flakeCount?: number;\n  /** Fall speed multiplier. Default: 1 */\n  speed?: number;\n  /** Horizontal wind drift (-2 to 2). Default: 0.3 */\n  wind?: number;\n  /** Maximum snowflake radius in pixels. Default: 4.2 */\n  maxSize?: number;\n  /** Optional foreground content */\n  children?: React.ReactNode;\n  className?: string;\n}\n\ninterface Flake {\n  x: number;\n  y: number;\n  r: number;\n  depth: number; // 0.2 to 1.0 (bigger = faster & more opaque)\n  phase: number;\n  swayAmp: number;\n}\n\nexport function Snowfall({\n  flakeCount = 140,\n  speed = 1,\n  wind = 0.3,\n  maxSize = 4.2,\n  children,\n  className,\n}: SnowfallProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [blizzard, setBlizzard] = useState(false);\n\n  const activeSpeed = blizzard ? speed * 2.4 : speed;\n  const activeWind = blizzard ? wind + 1.4 : wind;\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let rafId: number;\n    let width = (canvas.width = canvas.offsetWidth || 600);\n    let height = (canvas.height = canvas.offsetHeight || 360);\n\n    const flakes: Flake[] = Array.from({ length: flakeCount }, () => {\n      const depth = 0.2 + Math.random() * 0.8;\n      return {\n        x: Math.random() * width,\n        y: Math.random() * height,\n        r: 0.8 + depth * (maxSize - 0.8),\n        depth,\n        phase: Math.random() * Math.PI * 2,\n        swayAmp: 12 + Math.random() * 22,\n      };\n    });\n\n    const handleResize = () => {\n      if (!canvas) return;\n      width = canvas.width = canvas.offsetWidth || 600;\n      height = canvas.height = canvas.offsetHeight || 360;\n    };\n\n    window.addEventListener(\"resize\", handleResize);\n\n    let last = performance.now();\n    const render = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      const t = now * 0.001;\n      last = now;\n\n      ctx.clearRect(0, 0, width, height);\n\n      for (let i = 0; i < flakes.length; i++) {\n        const f = flakes[i];\n        // Bigger particles move faster and are more opaque for depth\n        const vy = (24 + f.depth * 68) * activeSpeed;\n        const vx =\n          activeWind * 28 * f.depth +\n          Math.sin(t * 1.4 + f.phase) * f.swayAmp * f.depth;\n\n        f.y += vy * dt;\n        f.x += vx * dt;\n\n        if (f.y > height + f.r) {\n          f.y = -f.r;\n          f.x = Math.random() * width;\n        }\n        if (f.x > width + f.r) f.x = -f.r;\n        if (f.x < -f.r) f.x = width + f.r;\n\n        const alpha = 0.22 + f.depth * 0.72;\n        ctx.beginPath();\n        ctx.arc(f.x, f.y, f.r, 0, Math.PI * 2);\n        ctx.fillStyle = `rgba(255, 255, 255, ${alpha.toFixed(3)})`;\n        ctx.fill();\n      }\n\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n    return () => {\n      cancelAnimationFrame(rafId);\n      window.removeEventListener(\"resize\", handleResize);\n    };\n  }, [flakeCount, activeSpeed, activeWind, maxSize]);\n\n  return (\n    <div\n      data-fullscreen-scroll\n      className={cn(\n        \"relative flex min-h-[360px] w-full flex-col justify-between overflow-hidden rounded-3xl border border-neutral-800 bg-gradient-to-b from-[#060B16] via-[#0B1528] to-[#16243E] p-6 text-white shadow-sm\",\n        className\n      )}\n    >\n      <canvas\n        ref={canvasRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 h-full w-full\"\n      />\n\n      <div className=\"relative z-10 flex flex-1 flex-col justify-between\">\n        {children ?? (\n          <>\n            <div className=\"flex items-center justify-between gap-2\">\n              <span className=\"inline-flex items-center gap-1.5 rounded-full border border-white/15 bg-white/10 px-3 py-1 font-mono text-[11px] font-medium text-white backdrop-blur-md\">\n                <Snowflake className=\"h-3.5 w-3.5 text-sky-200\" />\n                Snowfall · Depth Parallax\n              </span>\n\n              <button\n                type=\"button\"\n                onClick={() => setBlizzard((b) => !b)}\n                className=\"rounded-full border border-white/15 bg-white/10 px-3 py-1 font-mono text-[11px] text-white backdrop-blur-md transition-colors hover:bg-white/20\"\n              >\n                Mode: {blizzard ? \"Winter Gale\" : \"Gentle Flurry\"}\n              </button>\n            </div>\n\n            <div className=\"my-auto max-w-md py-8\">\n              <h3 className=\"text-2xl font-bold tracking-tight text-white sm:text-3xl\">\n                Depth-Sorted Snowfall\n              </h3>\n              <p className=\"mt-2 text-xs leading-relaxed text-white/80 sm:text-sm\">\n                Larger foreground flakes fall faster with higher opacity while\n                distant micro-flakes drift gently on horizontal sine waves.\n              </p>\n            </div>\n\n            <div className=\"font-mono text-[11px] text-white/50\">\n              {flakeCount} Particles · Sine Drift · Z-Depth Velocity\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default Snowfall;\n",
      "type": "registry:ui",
      "target": "components/ui/snowfall.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
