{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-reveal",
  "title": "Text reveal",
  "description": "Reveals text by line, word or character as it enters the viewport.",
  "dependencies": [
    "motion@^12.23.12"
  ],
  "registryDependencies": [
    "@khaeli/ease",
    "@khaeli/use-split-lines",
    "@khaeli/utils"
  ],
  "files": [
    {
      "path": "registry/khaeli/ui/text-reveal.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useReducedMotion } from \"motion/react\"\nimport * as m from \"motion/react-m\"\n\nimport { cn } from \"@/lib/utils\"\nimport { EASE_OUT } from \"@/lib/ease\"\nimport { useSplitLines } from \"@/hooks/use-split-lines\"\n\nexport type RevealBy = \"lines\" | \"words\" | \"chars\"\n\nconst revealConfig: Record<RevealBy, { duration: number; stagger: number }> = {\n  lines: { duration: 0.8, stagger: 0.08 },\n  words: { duration: 0.6, stagger: 0.06 },\n  chars: { duration: 0.4, stagger: 0.01 },\n}\n\n// A unit rests at 110% behind its line's mask, fully clipped, so the viewport\n// can never observe it. The line is observed instead and its units follow.\nconst unitVariants = {\n  hidden: { y: \"110%\" },\n  shown: { y: \"0%\" },\n}\n\n// The server cannot read the device's motion setting. The hydrating render\n// ignores it too, so both produce the same markup; the setting applies right\n// after. A render that hydrates nothing reads the setting at once.\nconst subscribeToNothing = () => () => {}\nfunction useHydrated() {\n  return React.useSyncExternalStore(\n    subscribeToNothing,\n    () => true,\n    () => false\n  )\n}\n\ninterface TextRevealProps extends Omit<React.ComponentProps<\"div\">, \"children\"> {\n  children: string\n  /** Granularity of the reveal. Text always masks per line; units slide up within it. */\n  by?: RevealBy\n  /** Element the wrapper renders as (default `div`). Use for heading semantics. */\n  as?: React.ElementType\n  /** Replay every time the text scrolls into view instead of only once. */\n  replay?: boolean\n}\n\nfunction TextReveal({\n  children,\n  by = \"lines\",\n  as: Comp = \"div\",\n  replay = false,\n  className,\n  ...props\n}: TextRevealProps) {\n  const text = typeof children === \"string\" ? children : \"\"\n  const { measureRef, words, lines } = useSplitLines(text)\n  const hydrated = useHydrated()\n  const reduced = useReducedMotion() && hydrated\n\n  const { duration, stagger } = revealConfig[by]\n  const viewport = { once: !replay, amount: 0.15 as const }\n\n  // Continuous stagger index shared across every animated unit.\n  let unitIndex = 0\n  const unit = (content: React.ReactNode, key: React.Key, inline: boolean) => {\n    const delay = unitIndex++ * stagger\n    return (\n      <m.span\n        key={key}\n        aria-hidden\n        className={inline ? \"inline-block\" : \"block\"}\n        variants={unitVariants}\n        transition={{ duration, delay, ease: EASE_OUT }}\n      >\n        {content}\n      </m.span>\n    )\n  }\n\n  const renderLine = (lineWords: string[], lineIndex: number) => {\n    let content: React.ReactNode\n    if (by === \"lines\") {\n      content = unit(lineWords.join(\" \"), `l${lineIndex}`, false)\n    } else if (by === \"words\") {\n      content = lineWords.map((word, i) => (\n        <React.Fragment key={i}>\n          {unit(word, `w${lineIndex}-${i}`, true)}\n          {i < lineWords.length - 1 ? \" \" : null}\n        </React.Fragment>\n      ))\n    } else {\n      content = lineWords.map((word, i) => (\n        <React.Fragment key={i}>\n          {Array.from(word).map((char, c) => unit(char, `c${lineIndex}-${i}-${c}`, true))}\n          {i < lineWords.length - 1 ? \" \" : null}\n        </React.Fragment>\n      ))\n    }\n    return (\n      <m.span\n        key={lineIndex}\n        aria-hidden\n        className=\"block overflow-hidden pb-[0.12em]\"\n        initial=\"hidden\"\n        whileInView=\"shown\"\n        viewport={viewport}\n      >\n        {content}\n      </m.span>\n    )\n  }\n\n  return (\n    <Comp\n      data-slot=\"text-reveal\"\n      className={cn(\"relative\", className)}\n      {...props}\n    >\n      {text ? <span className=\"sr-only\">{text}</span> : null}\n      {/* Hidden measuring layer — natural word wrap drives the line split. */}\n      <span\n        ref={measureRef as React.Ref<HTMLSpanElement>}\n        aria-hidden\n        className=\"pointer-events-none invisible absolute inset-0 block\"\n      >\n        {words.map((word, i) => (\n          <React.Fragment key={i}>\n            <span className=\"inline-block\">{word}</span>\n            {i < words.length - 1 ? \" \" : null}\n          </React.Fragment>\n        ))}\n      </span>\n\n      {reduced || !text ? (\n        <span aria-hidden={!!text}>{children}</span>\n      ) : lines ? (\n        lines.map(renderLine)\n      ) : (\n        // Pre-measurement: reserve layout height without a flash of static text.\n        <span aria-hidden className=\"invisible\">\n          {text}\n        </span>\n      )}\n    </Comp>\n  )\n}\n\nexport { TextReveal }\n",
      "type": "registry:ui"
    }
  ],
  "docs": "Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.",
  "type": "registry:ui"
}