{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ascii-art-title",
  "title": "ASCII Art Title",
  "description": "Any word rebuilt from plain text characters, with a slow shimmer across its surface and ripples that spread from the pointer.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/ascii-art-title/ascii-art-title.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface AsciiArtTitleProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  text?: string;\n  /** Characters across and down. */\n  columns?: number;\n  rows?: number;\n  /** Characters from empty to full. */\n  ramp?: string;\n  /** Font the word is drawn with before it turns into characters. */\n  font?: string;\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nconst CELL_W = 6;\nconst CELL_H = 10;\n/** Width of a monospace character against its height. */\nconst ADVANCE = 0.6;\n/** The surface shimmer repeats every two seconds. */\nconst CYCLE = 2000;\n\n/** Draws the word once, off screen, and reads how full each character cell is. */\nfunction sample(text: string, font: string, columns: number, rows: number) {\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = columns * CELL_W;\n  canvas.height = rows * CELL_H;\n  const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n  if (!ctx) return [];\n  let size = canvas.height;\n  ctx.font = `900 ${size}px ${font}`;\n  const fit = (canvas.width * 0.96) / Math.max(1, ctx.measureText(text).width);\n  size = Math.min(size * 0.98, size * fit);\n  ctx.font = `900 ${size}px ${font}`;\n  ctx.textAlign = \"center\";\n  ctx.textBaseline = \"middle\";\n  ctx.fillStyle = \"#fff\";\n  ctx.fillText(text, canvas.width / 2, canvas.height / 2);\n  const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;\n  return Array.from({ length: rows }, (_, r) =>\n    Array.from({ length: columns }, (_, c) => {\n      let sum = 0;\n      for (let y = 0; y < CELL_H; y++) {\n        for (let x = 0; x < CELL_W; x++) {\n          const px = c * CELL_W + x;\n          const py = r * CELL_H + y;\n          sum += data[(py * canvas.width + px) * 4 + 3];\n        }\n      }\n      return sum / (CELL_W * CELL_H * 255);\n    }),\n  );\n}\n\nexport function AsciiArtTitle({\n  text = \"FRAME\",\n  columns = 88,\n  rows = 15,\n  ramp = \" .:-=+*#%@\",\n  font = \"Inter, Arial, sans-serif\",\n  className,\n  style,\n  ...props\n}: AsciiArtTitleProps) {\n  const reduce = useReducedMotion();\n  const preRef = React.useRef<HTMLPreElement>(null);\n  const pointer = React.useRef<{ c: number; r: number } | null>(null);\n\n  // Characters are written straight into one text node, so a whole frame costs a single DOM update.\n  React.useEffect(() => {\n    const pre = preRef.current;\n    if (!pre) return;\n    let grid: number[][] = [];\n    let raf = 0;\n    const last = ramp.length - 1;\n    const draw = (now: number) => {\n      const phase = ((now % CYCLE) / CYCLE) * Math.PI * 2;\n      const hit = pointer.current;\n      pre.textContent = grid\n        .map((row, r) =>\n          row\n            .map((full, c) => {\n              let level = full;\n              if (full > 0.04 && !reduce) {\n                level *= 0.82 + 0.18 * Math.sin(c * 0.3 + r * 0.5 - phase);\n              }\n              if (hit) {\n                const dx = (c - hit.c) * ADVANCE;\n                const dy = r - hit.r;\n                const d = Math.sqrt(dx * dx + dy * dy);\n                level +=\n                  Math.exp(-d / 5) *\n                  (0.55 + 0.4 * Math.sin(d * 1.2 - phase * 3));\n              }\n              return ramp[\n                Math.max(0, Math.min(last, Math.round(level * last)))\n              ];\n            })\n            .join(\"\"),\n        )\n        .join(\"\\n\");\n    };\n    const frame = (now: number) => {\n      draw(now);\n      raf = requestAnimationFrame(frame);\n    };\n    let live = true;\n    const begin = () => {\n      if (!live) return;\n      grid = sample(text, font, columns, rows);\n      draw(0);\n    };\n    const ready = document.fonts?.ready;\n    if (ready) ready.then(begin);\n    else begin();\n    if (reduce) {\n      return () => {\n        live = false;\n      };\n    }\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(pre);\n    return () => {\n      live = false;\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [text, font, columns, rows, ramp, reduce]);\n\n  return (\n    <div\n      className={`@container w-full ${className ?? \"\"}`}\n      style={style}\n      role=\"img\"\n      aria-label={text}\n      onPointerMove={(e) => {\n        if (e.pointerType !== \"mouse\") return;\n        const r = e.currentTarget.getBoundingClientRect();\n        pointer.current = {\n          c: ((e.clientX - r.left) / r.width) * columns,\n          r: ((e.clientY - r.top) / r.height) * rows,\n        };\n      }}\n      onPointerLeave={() => {\n        pointer.current = null;\n      }}\n      {...props}\n    >\n      <pre\n        ref={preRef}\n        aria-hidden=\"true\"\n        className=\"m-0 overflow-hidden select-none\"\n        style={{\n          fontFamily:\n            'ui-monospace, \"SF Mono\", SFMono-Regular, Menlo, Consolas, monospace',\n          fontSize: `calc(100cqw / ${(columns * ADVANCE).toFixed(2)})`,\n          lineHeight: 1,\n          aspectRatio: `${columns * ADVANCE} / ${rows}`,\n        }}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}