{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"echo-text","type":"registry:ui","title":"Echo Text","description":"A headline with trailing copies that fade out behind it, breathe in a slow loop and swing toward the pointer.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/echo-text.tsx","type":"registry:ui","content":"\"use client\";\n\nimport {\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\nimport { useEffect, type PointerEvent } from \"react\";\n\ntype Direction = \"up\" | \"down\" | \"left\" | \"right\" | \"up-left\" | \"up-right\" | \"down-left\" | \"down-right\";\n\nconst D = Math.SQRT1_2;\nconst VECTORS: Record<Direction, [number, number]> = {\n  up: [0, -1],\n  down: [0, 1],\n  left: [-1, 0],\n  right: [1, 0],\n  \"up-left\": [-D, -D],\n  \"up-right\": [D, -D],\n  \"down-left\": [-D, D],\n  \"down-right\": [D, D],\n};\n\ntype EchoTextProps = {\n  text: string;\n  /** Number of trailing copies. */\n  count?: number;\n  /** Pixels between one echo and the next. */\n  offset?: number;\n  direction?: Direction;\n  /** Echo colors, used in turn from the nearest echo outward. */\n  colors?: string[];\n  /** Solid copies or outlined ones. */\n  variant?: \"solid\" | \"outline\";\n  /** Seconds for one breath in and out. */\n  speed?: number;\n  /** On hover, the echoes swing toward the pointer. */\n  followPointer?: boolean;\n  className?: string;\n};\n\n/** A headline with trailing copies that fade out behind it and breathe in a slow loop. */\nexport function EchoText({\n  text,\n  count = 4,\n  offset = 8,\n  direction = \"down-right\",\n  colors = [\"#ff784f\", \"#ffc24a\"],\n  variant = \"outline\",\n  speed = 3,\n  followPointer = true,\n  className = \"\",\n}: EchoTextProps) {\n  const reduce = useReducedMotion();\n  const [dx, dy] = VECTORS[direction] ?? VECTORS[\"down-right\"];\n  const dirX = useSpring(dx, { stiffness: 120, damping: 18 });\n  const dirY = useSpring(dy, { stiffness: 120, damping: 18 });\n  const time = useMotionValue(0);\n\n  useEffect(() => {\n    dirX.set(dx);\n    dirY.set(dy);\n  }, [dx, dy, dirX, dirY]);\n\n  useAnimationFrame((t) => {\n    if (!reduce) time.set(t);\n  });\n\n  const follow = followPointer && !reduce;\n\n  function onMove(e: PointerEvent<HTMLSpanElement>) {\n    const r = e.currentTarget.getBoundingClientRect();\n    const vx = e.clientX - (r.left + r.width / 2);\n    const vy = e.clientY - (r.top + r.height / 2);\n    const len = Math.hypot(vx, vy) || 1;\n    dirX.set(vx / len);\n    dirY.set(vy / len);\n  }\n\n  function onLeave() {\n    dirX.set(dx);\n    dirY.set(dy);\n  }\n\n  const echoes = Array.from({ length: Math.max(0, Math.round(count)) }, (_, i) => i + 1).reverse();\n  const palette = colors.length ? colors : [\"#ff784f\"];\n\n  return (\n    <span\n      className={`relative isolate inline-block ${className}`}\n      onPointerMove={follow ? onMove : undefined}\n      onPointerLeave={follow ? onLeave : undefined}\n    >\n      {echoes.map((i) => (\n        <Echo\n          key={i}\n          text={text}\n          step={i}\n          count={echoes.length}\n          dirX={dirX}\n          dirY={dirY}\n          time={time}\n          offset={offset}\n          speed={Math.max(0.5, speed)}\n          color={palette[(i - 1) % palette.length]}\n          outline={variant === \"outline\"}\n          still={Boolean(reduce)}\n        />\n      ))}\n      <span className=\"relative\">{text}</span>\n    </span>\n  );\n}\n\nfunction Echo({\n  text,\n  step,\n  count,\n  dirX,\n  dirY,\n  time,\n  offset,\n  speed,\n  color,\n  outline,\n  still,\n}: {\n  text: string;\n  step: number;\n  count: number;\n  dirX: MotionValue<number>;\n  dirY: MotionValue<number>;\n  time: MotionValue<number>;\n  offset: number;\n  speed: number;\n  color: string;\n  outline: boolean;\n  still: boolean;\n}) {\n  // Each echo breathes a little later than the one in front, so the stack ripples.\n  const breath = () => (still ? 1 : 1 + 0.35 * Math.sin((time.get() / 1000 / speed) * Math.PI * 2 - step * 0.6));\n  const x = useTransform(() => dirX.get() * offset * step * breath());\n  const y = useTransform(() => dirY.get() * offset * step * breath());\n\n  return (\n    <motion.span\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute inset-0 select-none\"\n      style={{\n        x,\n        y,\n        opacity: (1 - step / (count + 1)) * 0.9,\n        color: outline ? \"transparent\" : color,\n        WebkitTextStroke: outline ? `0.022em ${color}` : undefined,\n      }}\n    >\n      {text}\n    </motion.span>\n  );\n}\n"}]}