{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"afterimage-type","type":"registry:ui","title":"Afterimage Type","description":"A headline trailed by fading echo copies that lag behind it, drifting on a loop or chasing the pointer.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/afterimage-type.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface AfterimageTypeProps {\n  text?: string;\n  /** Number of trailing copies. */\n  echoes?: number;\n  /** How fast each echo catches up with the one ahead (0-1). Lower is a longer trail. */\n  lag?: number;\n  /** Drift on a loop, or follow the pointer. */\n  mode?: \"loop\" | \"pointer\";\n  /** Maximum travel of the lead text, in px. */\n  amplitude?: number;\n  color?: string;\n  echoColor?: string;\n  /** Draw echoes as outlines instead of solid copies. */\n  outline?: boolean;\n  className?: string;\n}\n\nexport function AfterimageType({\n  text = \"ECHO\",\n  echoes = 7,\n  lag = 0.1,\n  mode = \"loop\",\n  amplitude = 60,\n  color = \"#fafafa\",\n  echoColor = \"#a3e635\",\n  outline = true,\n  className,\n}: AfterimageTypeProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const copies = useRef<(HTMLSpanElement | null)[]>([]);\n  const n = Math.max(0, Math.round(echoes));\n\n  useEffect(() => {\n    const el = root.current!;\n    const area = el.parentElement ?? el;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const pos = Array.from({ length: n + 1 }, () => ({ x: 0, y: 0 }));\n    const target = { x: 0, y: 0 };\n    let raf = 0;\n    let visible = true;\n\n    const loop = (now: number) => {\n      if (mode === \"loop\") {\n        const t = now / 1000;\n        target.x = Math.sin(t * 1.6) * amplitude;\n        target.y = Math.sin(t * 3.2) * amplitude * 0.35;\n      }\n      pos[0].x += (target.x - pos[0].x) * 0.18;\n      pos[0].y += (target.y - pos[0].y) * 0.18;\n      for (let i = 1; i <= n; i++) {\n        pos[i].x += (pos[i - 1].x - pos[i].x) * lag;\n        pos[i].y += (pos[i - 1].y - pos[i].y) * lag;\n      }\n      for (let i = 0; i <= n; i++) {\n        const c = copies.current[i];\n        if (c) c.style.transform = `translate3d(${pos[i].x}px, ${pos[i].y}px, 0)`;\n      }\n      raf = visible ? requestAnimationFrame(loop) : 0;\n    };\n    const move = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      const clamp = (v: number) => Math.max(-amplitude, Math.min(amplitude, v));\n      target.x = clamp((e.clientX - r.left - r.width / 2) * 0.3);\n      target.y = clamp((e.clientY - r.top - r.height / 2) * 0.3);\n    };\n    const leave = () => {\n      target.x = 0;\n      target.y = 0;\n    };\n\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf) raf = requestAnimationFrame(loop);\n    });\n    io.observe(el);\n    if (mode === \"pointer\") {\n      area.addEventListener(\"pointermove\", move, { passive: true });\n      area.addEventListener(\"pointerleave\", leave);\n    }\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      area.removeEventListener(\"pointermove\", move);\n      area.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [n, lag, mode, amplitude]);\n\n  return (\n    <div ref={root} className={className} style={{ position: \"relative\", display: \"inline-block\" }}>\n      <span className=\"sr-only\">{text}</span>\n      {Array.from({ length: n }, (_, k) => {\n        const i = n - k; // farthest echo first so the lead paints on top\n        const fade = 1 - i / (n + 1);\n        return (\n          <span\n            key={i}\n            ref={(node) => {\n              copies.current[i] = node;\n            }}\n            aria-hidden\n            style={{\n              position: \"absolute\",\n              inset: 0,\n              whiteSpace: \"pre\",\n              opacity: 0.15 + fade * 0.7,\n              color: outline ? \"transparent\" : echoColor,\n              WebkitTextStroke: outline ? `1.5px ${echoColor}` : undefined,\n              filter: `blur(${(i / (n + 1)) * 1.5}px)`,\n              willChange: \"transform\",\n            }}\n          >\n            {text}\n          </span>\n        );\n      })}\n      <span\n        ref={(node) => {\n          copies.current[0] = node;\n        }}\n        aria-hidden\n        style={{ position: \"relative\", display: \"block\", whiteSpace: \"pre\", color, willChange: \"transform\" }}\n      >\n        {text}\n      </span>\n    </div>\n  );\n}\n"}]}