{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ascii-rain",
  "title": "ASCII Rain",
  "description": "Falling streams of glyphs whose color fades along each tail.",
  "dependencies": [],
  "registryDependencies": [
    "@atroui/utils",
    "@atroui/ascii-rig"
  ],
  "files": [
    {
      "path": "registry/default/ui/ascii-rain.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport { readAsciiColor, setupAsciiCanvas, useAsciiTick } from \"@/lib/ascii-rig\"\n\nexport type AsciiRainProps = {\n  /** Columns (streams). Rows derive from the 1:2 cell ratio. */\n  cols?: number\n  /** Fall-speed multiplier. */\n  speed?: number\n  /** Characters that fall — any string; position order is random. */\n  chars?: string\n  /** Accessible description of the decorative scene. */\n  label?: string\n  className?: string\n}\n\nconst DEFAULT_CHARS =\n  \"ｦｧｨｩｪｫｬｭｮｯｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾗﾘﾜ0123456789Z+*:.\"\n\nfunction clampInt(v: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, Math.round(v)))\n}\n\n/** Stable pseudo-random 0..1 for a (col,row) cell, so glyphs don't churn. */\nfunction cellHash(col: number, row: number) {\n  let h = (col * 73856093) ^ (row * 19349663)\n  h = (h ^ (h >> 13)) * 1274126177\n  return Math.abs(h % 100000) / 100000\n}\n\ntype Drop = { y: number; v: number; len: number }\n\n/**\n * ASCII Rain — procedural field effect: per-stream cascades of glyphs whose\n * color fades along each tail. Head cell stays bright; glyph per cell is\n * stable so the field reads solid rather than flickering.\n */\nexport function AsciiRain({\n  cols: colsProp = 52,\n  speed = 1,\n  chars = DEFAULT_CHARS,\n  label = \"Falling columns of characters\",\n  className,\n}: AsciiRainProps) {\n  const cols = clampInt(colsProp, 16, 120)\n  const rows = Math.round(cols * 0.42)\n  const hostRef = React.useRef<HTMLDivElement>(null)\n  const canvasRef = React.useRef<HTMLCanvasElement>(null)\n\n  const dropsRef = React.useRef<Drop[]>([])\n\n  const draw = React.useCallback(\n    (t: number, dt: number) => {\n      const canvas = canvasRef.current\n      if (!canvas) return\n      const setup = setupAsciiCanvas(canvas, cols, rows, 10)\n      if (!setup) return\n      const { ctx, cellH, cellW } = setup\n      ctx.clearRect(0, 0, setup.w, setup.h)\n      const color = readAsciiColor(hostRef.current)\n      ctx.fillStyle = color\n\n      // Reset streams when the grid shape changes.\n      if (dropsRef.current.length !== cols) {\n        dropsRef.current = Array.from({ length: cols }, (_, c) => ({\n          y: -cellHash(c, 7) * rows * 2,\n          v: 5 + cellHash(c, 11) * 9,\n          len: 6 + Math.round(cellHash(c, 13) * 10),\n        }))\n      }\n\n      for (let c = 0; c < cols; c++) {\n        const drop = dropsRef.current[c]!\n        const head = Math.floor(drop.y)\n        for (let r = 1; r <= drop.len; r++) {\n          const row = head - r\n          if (row < 0 || row >= rows) continue\n          const fade = 1 - r / drop.len\n          const a = Math.pow(fade, 1.7) * 0.9\n          if (a < 0.04) continue\n          ctx.globalAlpha = r === 1 ? 1 : a\n          const ch =\n            chars[\n              Math.floor(cellHash(c, row) * chars.length) % chars.length\n            ] ?? \" \"\n          ctx.fillText(ch, c * cellW, row * cellH)\n        }\n      }\n      ctx.globalAlpha = 1\n\n      // Advance: clamped dt keeps the cascade steady across tab switches.\n      const step = Math.min(dt, 0.12)\n      for (const drop of dropsRef.current) {\n        drop.y += drop.v * speed * step\n        if (drop.y - drop.len > rows) {\n          drop.y = -drop.len * 0.5\n          drop.v = 5 + Math.random() * 9\n          drop.len = 6 + Math.round(Math.random() * 10)\n        }\n      }\n    },\n    [cols, rows, speed, chars]\n  )\n\n  useAsciiTick(hostRef, draw, { fps: 16 })\n\n  return (\n    <div\n      ref={hostRef}\n      role=\"img\"\n      aria-label={label}\n      className={cn(\"flex justify-center overflow-hidden\", className)}\n    >\n      <canvas ref={canvasRef} className=\"max-w-full\" aria-hidden=\"true\" />\n    </div>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/ui/ascii-rain.tsx"
    }
  ],
  "type": "registry:ui"
}