{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lens-ascii-magnify",
  "title": "Lens ASCII Magnify",
  "description": "A circular lens that resolves the text under it into a denser dot-matrix of ASCII glyphs: every character it passes over is redrawn as its own 5x7 grid of ramp characters, more glyphs per glyph rather than the same glyph bigger.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/lens-ascii-magnify/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// AsciiMagnifyLens — a lens that resolves the region under it into DENSER\n// glyphs, not a bigger version of the same glyph. Distinct from slider-loupe\n// (optically scales the same canvas-drawn tick marks bigger) and from\n// text-prism-split (tears a headline into RGB channel offsets): here every\n// character has a small 5x7 dot-matrix representation, and the lens redraws\n// whichever characters fall inside it as that matrix — a grid of ascii-ramp\n// cells finer than the flat glyph outside the lens, i.e. genuinely more\n// characters per character. The base text is real, plain DOM text the whole\n// time; the lens is a purely decorative aria-hidden canvas overlay on top of\n// it, so accessibility is never in question. Direct-DOM rAF: the lens springs\n// toward the pointer (slight optical lag) and parks at the block's center at\n// rest and on pointer-leave, so the resting screenshot already shows the\n// mechanic rather than plain text with nothing happening.\n// ---------------------------------------------------------------------------\n\nconst CELL_COLS = 5;\nconst CELL_ROWS = 7;\nconst RAMP = \" .:-=+*#%@\";\n\n// Compact 5x7 dot-matrix font. \"1\" = ink, \"0\" = empty. Characters outside\n// this table fall back to a light 40%-fill block so nothing renders blank.\nconst FONT: Record<string, string[]> = {\n  A: [\"01110\", \"10001\", \"10001\", \"11111\", \"10001\", \"10001\", \"10001\"],\n  B: [\"11110\", \"10001\", \"10001\", \"11110\", \"10001\", \"10001\", \"11110\"],\n  C: [\"01111\", \"10000\", \"10000\", \"10000\", \"10000\", \"10000\", \"01111\"],\n  D: [\"11110\", \"10001\", \"10001\", \"10001\", \"10001\", \"10001\", \"11110\"],\n  E: [\"11111\", \"10000\", \"10000\", \"11110\", \"10000\", \"10000\", \"11111\"],\n  F: [\"11111\", \"10000\", \"10000\", \"11110\", \"10000\", \"10000\", \"10000\"],\n  G: [\"01111\", \"10000\", \"10000\", \"10011\", \"10001\", \"10001\", \"01111\"],\n  H: [\"10001\", \"10001\", \"10001\", \"11111\", \"10001\", \"10001\", \"10001\"],\n  I: [\"01110\", \"00100\", \"00100\", \"00100\", \"00100\", \"00100\", \"01110\"],\n  J: [\"00111\", \"00010\", \"00010\", \"00010\", \"00010\", \"10010\", \"01100\"],\n  K: [\"10001\", \"10010\", \"10100\", \"11000\", \"10100\", \"10010\", \"10001\"],\n  L: [\"10000\", \"10000\", \"10000\", \"10000\", \"10000\", \"10000\", \"11111\"],\n  M: [\"10001\", \"11011\", \"10101\", \"10101\", \"10001\", \"10001\", \"10001\"],\n  N: [\"10001\", \"11001\", \"10101\", \"10101\", \"10011\", \"10001\", \"10001\"],\n  O: [\"01110\", \"10001\", \"10001\", \"10001\", \"10001\", \"10001\", \"01110\"],\n  P: [\"11110\", \"10001\", \"10001\", \"11110\", \"10000\", \"10000\", \"10000\"],\n  Q: [\"01110\", \"10001\", \"10001\", \"10001\", \"10101\", \"10010\", \"01101\"],\n  R: [\"11110\", \"10001\", \"10001\", \"11110\", \"10100\", \"10010\", \"10001\"],\n  S: [\"01111\", \"10000\", \"10000\", \"01110\", \"00001\", \"00001\", \"11110\"],\n  T: [\"11111\", \"00100\", \"00100\", \"00100\", \"00100\", \"00100\", \"00100\"],\n  U: [\"10001\", \"10001\", \"10001\", \"10001\", \"10001\", \"10001\", \"01110\"],\n  V: [\"10001\", \"10001\", \"10001\", \"10001\", \"10001\", \"01010\", \"00100\"],\n  W: [\"10001\", \"10001\", \"10001\", \"10101\", \"10101\", \"10101\", \"01010\"],\n  X: [\"10001\", \"10001\", \"01010\", \"00100\", \"01010\", \"10001\", \"10001\"],\n  Y: [\"10001\", \"10001\", \"01010\", \"00100\", \"00100\", \"00100\", \"00100\"],\n  Z: [\"11111\", \"00001\", \"00010\", \"00100\", \"01000\", \"10000\", \"11111\"],\n  \"0\": [\"01110\", \"10011\", \"10101\", \"10101\", \"11001\", \"10001\", \"01110\"],\n  \"1\": [\"00100\", \"01100\", \"00100\", \"00100\", \"00100\", \"00100\", \"01110\"],\n  \"2\": [\"01110\", \"10001\", \"00001\", \"00010\", \"00100\", \"01000\", \"11111\"],\n  \"3\": [\"11111\", \"00010\", \"00100\", \"00010\", \"00001\", \"10001\", \"01110\"],\n  \"4\": [\"00010\", \"00110\", \"01010\", \"10010\", \"11111\", \"00010\", \"00010\"],\n  \"5\": [\"11111\", \"10000\", \"11110\", \"00001\", \"00001\", \"10001\", \"01110\"],\n  \"6\": [\"00110\", \"01000\", \"10000\", \"11110\", \"10001\", \"10001\", \"01110\"],\n  \"7\": [\"11111\", \"00001\", \"00010\", \"00100\", \"01000\", \"01000\", \"01000\"],\n  \"8\": [\"01110\", \"10001\", \"10001\", \"01110\", \"10001\", \"10001\", \"01110\"],\n  \"9\": [\"01110\", \"10001\", \"10001\", \"01111\", \"00001\", \"00010\", \"01100\"],\n  \".\": [\"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"01100\", \"01100\"],\n  \",\": [\"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"01100\", \"01000\"],\n  \"-\": [\"00000\", \"00000\", \"00000\", \"11111\", \"00000\", \"00000\", \"00000\"],\n  \":\": [\"00000\", \"01100\", \"01100\", \"00000\", \"01100\", \"01100\", \"00000\"],\n  \"'\": [\"01100\", \"01100\", \"01000\", \"00000\", \"00000\", \"00000\", \"00000\"],\n  \"/\": [\"00001\", \"00010\", \"00010\", \"00100\", \"01000\", \"01000\", \"10000\"],\n  \" \": [\"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00000\"],\n};\n\nfunction glyphRows(ch: string): string[] {\n  return FONT[ch.toUpperCase()] ?? [\"01010\", \"10101\", \"01010\", \"10101\", \"01010\", \"10101\", \"01010\"];\n}\n\nexport interface AsciiMagnifyLensProps {\n  /** the magnified text */\n  text: string;\n  /** lens diameter in px */\n  lensSize?: number;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nexport function AsciiMagnifyLens({ text, lensSize = 130, className = \"\" }: AsciiMagnifyLensProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const ringRef = useRef<HTMLDivElement>(null);\n  const charRefs = useRef<(HTMLSpanElement | null)[]>([]);\n  const [reduced, setReduced] = useState(false);\n\n  const chars = useMemo(() => Array.from(text), [text]);\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    setReduced(mq.matches);\n    const onChange = () => setReduced(mq.matches);\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n\n  useEffect(() => {\n    const container = containerRef.current;\n    const canvas = canvasRef.current;\n    const ring = ringRef.current;\n    if (!container || !canvas || !ring) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let ink = \"rgb(237,237,237)\";\n    let bg = \"rgb(10,10,10)\";\n    let monoFam = \"ui-monospace, SFMono-Regular, Menlo, monospace\";\n    const derive = () => {\n      const cs = getComputedStyle(container);\n      const root = getComputedStyle(document.documentElement);\n      ink = root.getPropertyValue(\"--foreground\").trim() || cs.color || ink;\n      bg = root.getPropertyValue(\"--background\").trim() || bg;\n      const fam = cs.fontFamily;\n      if (fam) monoFam = fam;\n    };\n    derive();\n\n    let dpr = Math.min(2, window.devicePixelRatio || 1);\n    let w = 0;\n    let h = 0;\n    let lx = 0;\n    let ly = 0;\n    let tx = 0;\n    let ty = 0;\n    let raf = 0;\n    let lastT = 0;\n    let visible = true;\n\n    const resize = () => {\n      const rect = container.getBoundingClientRect();\n      w = rect.width;\n      h = rect.height;\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      canvas.style.width = `${w}px`;\n      canvas.style.height = `${h}px`;\n      tx = w / 2;\n      ty = h / 2;\n      if (!raf) {\n        lx = tx;\n        ly = ty;\n        render();\n      }\n    };\n\n    const render = () => {\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n\n      const r = lensSize / 2;\n      ctx.save();\n      ctx.beginPath();\n      ctx.arc(lx, ly, r, 0, Math.PI * 2);\n      ctx.clip();\n      ctx.fillStyle = bg;\n      ctx.fillRect(lx - r, ly - r, r * 2, r * 2);\n\n      const containerRect = container.getBoundingClientRect();\n      for (let i = 0; i < chars.length; i++) {\n        const el = charRefs.current[i];\n        if (!el || !chars[i] || /\\s/.test(chars[i]!)) continue;\n        const box = el.getBoundingClientRect();\n        const cx = box.left - containerRect.left + box.width / 2;\n        const cy = box.top - containerRect.top + box.height / 2;\n        const dist = Math.hypot(cx - lx, cy - ly);\n        if (dist > r + Math.max(box.width, box.height)) continue;\n\n        const rows = glyphRows(chars[i]!);\n        const cellW = box.width / CELL_COLS;\n        const cellH = box.height / CELL_ROWS;\n        const fontPx = Math.max(6, Math.min(cellW, cellH) * 1.6);\n        ctx.font = `${fontPx}px ${monoFam}`;\n        ctx.textAlign = \"center\";\n        ctx.textBaseline = \"middle\";\n        const originX = box.left - containerRect.left;\n        const originY = box.top - containerRect.top;\n        for (let row = 0; row < CELL_ROWS; row++) {\n          const bits = rows[row] ?? \"00000\";\n          for (let col = 0; col < CELL_COLS; col++) {\n            const on = bits[col] === \"1\";\n            const px = originX + col * cellW + cellW / 2;\n            const py = originY + row * cellH + cellH / 2;\n            if (Math.hypot(px - lx, py - ly) > r) continue;\n            const glyph = on ? RAMP[RAMP.length - 2] : RAMP[2];\n            ctx.globalAlpha = on ? 1 : 0.28;\n            ctx.fillStyle = ink;\n            ctx.fillText(glyph!, px, py);\n          }\n        }\n      }\n      ctx.globalAlpha = 1;\n      ctx.restore();\n\n      const ringR = lensSize / 2;\n      ring.style.transform = `translate3d(${(lx - ringR).toFixed(1)}px, ${(ly - ringR).toFixed(1)}px, 0)`;\n    };\n\n    if (reduced) {\n      resize();\n      const ro = new ResizeObserver(resize);\n      ro.observe(container);\n      return () => ro.disconnect();\n    }\n\n    const loop = (now: number) => {\n      const dt = lastT ? Math.min(0.05, (now - lastT) / 1000) : 1 / 60;\n      lastT = now;\n      // exponential chase toward the pointer (or the parked center) — a\n      // slight optical lag, not an instant snap\n      lx += (tx - lx) * Math.min(1, dt * 10);\n      ly += (ty - ly) * Math.min(1, dt * 10);\n      render();\n      const settled = Math.abs(lx - tx) < 0.2 && Math.abs(ly - ty) < 0.2;\n      if (!settled && visible && !document.hidden) {\n        raf = requestAnimationFrame(loop);\n      } else {\n        raf = 0;\n      }\n    };\n    const wake = () => {\n      if (!raf) {\n        lastT = 0;\n        raf = requestAnimationFrame(loop);\n      }\n    };\n\n    resize();\n\n    const onMove = (e: PointerEvent) => {\n      const rect = container.getBoundingClientRect();\n      tx = e.clientX - rect.left;\n      ty = e.clientY - rect.top;\n      wake();\n    };\n    const onLeave = () => {\n      const rect = container.getBoundingClientRect();\n      tx = rect.width / 2;\n      ty = rect.height / 2;\n      wake();\n    };\n\n    container.addEventListener(\"pointermove\", onMove);\n    container.addEventListener(\"pointerleave\", onLeave);\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(container);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[0]?.isIntersecting ?? true;\n      if (visible) wake();\n    });\n    io.observe(container);\n    const mo = new MutationObserver(() => {\n      derive();\n      render();\n    });\n    mo.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\"] });\n    const onVis = () => {\n      if (!document.hidden) wake();\n    };\n    document.addEventListener(\"visibilitychange\", onVis);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      mo.disconnect();\n      container.removeEventListener(\"pointermove\", onMove);\n      container.removeEventListener(\"pointerleave\", onLeave);\n      document.removeEventListener(\"visibilitychange\", onVis);\n    };\n  }, [chars, lensSize, reduced]);\n\n  return (\n    <div\n      ref={containerRef}\n      className={`relative touch-none select-none font-mono leading-relaxed text-foreground ${className}`}\n    >\n      <p className=\"relative z-0 whitespace-pre-wrap\">\n        {chars.map((c, i) => (\n          <span\n            key={i}\n            ref={(el) => {\n              charRefs.current[i] = el;\n            }}\n            className=\"inline-block\"\n          >\n            {c}\n          </span>\n        ))}\n      </p>\n      <canvas ref={canvasRef} aria-hidden className=\"pointer-events-none absolute left-0 top-0 z-10\" />\n      <div\n        ref={ringRef}\n        aria-hidden\n        className=\"pointer-events-none absolute left-0 top-0 z-20 rounded-full border border-border shadow-[0_4px_18px_-6px_rgba(0,0,0,0.4)] will-change-transform\"\n        style={{ width: lensSize, height: lensSize }}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/lens-ascii-magnify.tsx"
    }
  ],
  "meta": {
    "collection": "core",
    "tags": [
      "lens",
      "magnifier",
      "ascii",
      "text",
      "mono",
      "canvas",
      "cursor"
    ],
    "instruction": "A circular lens, driven by a `text` prop rendered as real plain DOM text (one `<span>` per character, plain content, no aria-hidden anywhere on the real text — it's never hidden, so accessibility needs nothing special here). Layered on top is a purely decorative `aria-hidden` `<canvas>` plus a DOM ring div; together they are the lens. Every character in `text` has a hand-built 5x7 dot-matrix representation (a compact bitmap font covering A-Z, 0-9, space and basic punctuation; an unmapped character falls back to a light diagonal-hatch placeholder rather than rendering blank). On every frame, for each character whose measured `getBoundingClientRect()` falls within the lens radius of its current center, the canvas fills the lens circle's background with a `--background`-token flat fill (occluding the flat glyph underneath) and then redraws that character as its OWN 5x7 grid of cells, each cell either a solid ramp glyph (`--foreground` at full alpha, for an 'on' bit) or a faint one (28% alpha, for an 'off' bit) — that grid is strictly finer than the single flat character it replaces, which is the entire mechanic: MORE glyphs resolving one glyph, not the same glyph scaled up (that's slider-loupe's job) and not a channel-split refraction (text-prism-split's job). The lens position chases the pointer with an exponential lag (10/s time-constant) via one direct-DOM `requestAnimationFrame` loop that sleeps once settled, wakes on `pointermove`, and returns to a PARKED position at the text block's own center on `pointerleave` — so the resting/default screenshot already shows the lens sitting mid-block resolving whatever text is there, not a plain, unmagnified paragraph waiting for a cursor. All canvas ink (`--foreground` fill/background fill) and the mono font family are read via `getComputedStyle` at mount and re-derived on a `MutationObserver` watching `documentElement` class changes, so both themes render correctly with no baked-in hex. `prefers-reduced-motion: reduce` disables the chase loop and the pointer-follow entirely: the lens renders once, parked at center, with no rAF running — still legible as the concept, just not animated. ResizeObserver and IntersectionObserver keep it correctly sized and paused off-screen. Zero dependencies."
  },
  "type": "registry:ui"
}