{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"scramble-text","type":"registry:ui","title":"Scramble Text","description":"Text that decodes from random glyphs, left to right, on hover or focus.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/scramble-text.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nconst GLYPHS = \"ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&*+=<>/\";\n\ntype ScrambleTextProps = {\n  text: string;\n  /** Milliseconds for the whole decode. */\n  duration?: number;\n  className?: string;\n};\n\n/** Text that decodes from random glyphs, left to right, on hover or focus. */\nexport function ScrambleText({ text, duration = 700, className = \"\" }: ScrambleTextProps) {\n  const [shown, setShown] = useState(text);\n  const frame = useRef<number | null>(null);\n  const reduce = useReducedMotion();\n\n  const run = useCallback(() => {\n    if (reduce) return;\n    if (frame.current) cancelAnimationFrame(frame.current);\n    const start = performance.now();\n    const tick = (now: number) => {\n      const t = Math.min(1, (now - start) / duration);\n      const settled = Math.floor(t * text.length);\n      setShown(\n        text\n          .split(\"\")\n          .map((ch, i) =>\n            ch === \" \" || i < settled ? ch : GLYPHS[Math.floor(Math.random() * GLYPHS.length)],\n          )\n          .join(\"\"),\n      );\n      if (t < 1) frame.current = requestAnimationFrame(tick);\n    };\n    frame.current = requestAnimationFrame(tick);\n  }, [text, duration, reduce]);\n\n  useEffect(() => () => {\n    if (frame.current) cancelAnimationFrame(frame.current);\n  }, []);\n\n  return (\n    <span className={className} onPointerEnter={run} onFocus={run} tabIndex={0} aria-label={text}>\n      <span aria-hidden=\"true\">{shown}</span>\n    </span>\n  );\n}\n"}]}