{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"letter-rise","type":"registry:ui","title":"Letter Rise","description":"Reveals text character by character or word by word when it scrolls into view.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/letter-rise.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Fragment, useEffect, useRef, useState } from \"react\";\n\nexport interface LetterRiseProps {\n  text: string;\n  /** Animate each character or each word. */\n  splitBy?: \"chars\" | \"words\";\n  variant?: \"slide\" | \"blur\" | \"fade\";\n  /** Delay between pieces, in ms. */\n  stagger?: number;\n  /** Duration of each piece, in ms. */\n  duration?: number;\n  as?: \"p\" | \"h1\" | \"h2\" | \"h3\" | \"span\" | \"div\";\n  className?: string;\n}\n\nexport function LetterRise({\n  text,\n  splitBy = \"chars\",\n  variant = \"slide\",\n  stagger = 35,\n  duration = 600,\n  as: Tag = \"p\",\n  className,\n}: LetterRiseProps) {\n  const ref = useRef<HTMLElement>(null);\n  const [shown, setShown] = useState(false);\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (entry.isIntersecting) {\n          setShown(true);\n          io.disconnect();\n        }\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  const words = text.split(\" \");\n  let index = 0;\n  const piece = (content: string, key: number) => {\n    const delay = index++ * stagger;\n    return (\n      <span\n        key={key}\n        style={{\n          display: \"inline-block\",\n          whiteSpace: \"pre\",\n          opacity: shown ? 1 : 0,\n          transform: shown || variant !== \"slide\" ? \"none\" : \"translateY(0.6em)\",\n          filter: shown || variant !== \"blur\" ? \"none\" : \"blur(10px)\",\n          transition: `opacity ${duration}ms ease ${delay}ms, transform ${duration}ms cubic-bezier(.2,.7,.2,1) ${delay}ms, filter ${duration}ms ease ${delay}ms`,\n        }}\n      >\n        {content}\n      </span>\n    );\n  };\n\n  return (\n    <Tag ref={ref as never} className={className}>\n      <span className=\"sr-only\">{text}</span>\n      {words.map((word, w) => (\n        <Fragment key={w}>\n          <span aria-hidden style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n            {splitBy === \"words\" ? piece(word, 0) : Array.from(word).map(piece)}\n          </span>\n          {w < words.length - 1 && \" \"}\n        </Fragment>\n      ))}\n    </Tag>\n  );\n}\n"}]}