{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-reveal",
  "type": "registry:component",
  "title": "Text Reveal",
  "description": "Reveals a heading word by word, or line by line, when it scrolls into view.",
  "categories": [
    "motion"
  ],
  "dependencies": [],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/motion"
  ],
  "files": [
    {
      "path": "registry/motion/text-reveal.tsx",
      "type": "registry:component",
      "target": "components/motion/text-reveal.tsx",
      "content": "\"use client\";\n/**\n * @name text-reveal\n * @category motion\n * @description Reveals a heading word by word, or line by line, when it scrolls into view.\n * @when A headline or a short statement. Not for paragraphs of body text (use reveal on the block), and not for text that changes while it is shown.\n * @example\n * <TextReveal as=\"h1\" className=\"text-4xl font-medium\" playOnLoad>\n *   Websites, apps and systems that last\n * </TextReveal>\n * <TextReveal as=\"p\" by=\"line\" interval={0.12} className=\"max-w-prose text-xl\">\n *   We design the brand, build the product and stay to run it.\n * </TextReveal>\n */\nimport { Fragment, useImperativeHandle, useRef, type HTMLAttributes, type Ref } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useEntrance, type EntranceOptions } from \"@/lib/motion\";\n\nexport type TextRevealProps = Omit<HTMLAttributes<HTMLElement>, \"children\"> & {\n  ref?: Ref<HTMLElement>;\n  /** The text. A plain string; a line break (\"\\n\") in it is kept. */\n  children: string;\n  /** The element to render. Default \"h2\". */\n  as?: \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"p\" | \"span\" | \"div\";\n  /** Reveal each word in turn, or each line as it wraps on screen (measured once, when it starts). Default \"word\". */\n  by?: \"word\" | \"line\";\n  /** Seconds between one word (or line) and the next. Default 0.04 by word, 0.1 by line. */\n  interval?: number;\n  /** Seconds before the first one. Default 0. */\n  delay?: number;\n  /** Seconds each word takes. Default: the scene duration (0.7). */\n  duration?: number;\n  /** How far each word rises, in pixels. Default 12. */\n  distance?: number;\n  /** Play once (default), or again each time it comes back into view. */\n  once?: boolean;\n  /** Also play when it is already in view as the page loads (a hero heading). Default false: left as it is. */\n  playOnLoad?: boolean;\n  /** Grows or shrinks the viewport edge used for \"in view\", as a CSS margin. */\n  margin?: EntranceOptions[\"margin\"];\n};\n\nfunction wordsOf(root: HTMLElement): HTMLElement[] {\n  return Array.from(root.querySelectorAll<HTMLElement>(\"[data-word]\"));\n}\n\n/** The index of the wrapped line each word sits on, read from where the words landed. */\nfunction lineIndexes(words: HTMLElement[]): number[] {\n  let line = -1;\n  let top = Number.NaN;\n  return words.map((word) => {\n    if (word.offsetTop !== top) {\n      top = word.offsetTop;\n      line += 1;\n    }\n    return line;\n  });\n}\n\nexport function TextReveal({\n  className,\n  children,\n  as: Tag = \"h2\",\n  by = \"word\",\n  interval,\n  delay = 0,\n  duration,\n  distance = 12,\n  once = true,\n  playOnLoad = false,\n  margin,\n  ref,\n  ...props\n}: TextRevealProps) {\n  const rootRef = useRef<HTMLElement | null>(null);\n  useImperativeHandle(ref, () => rootRef.current as HTMLElement, []);\n  const step = interval ?? (by === \"line\" ? 0.1 : 0.04);\n  const lines = useRef<number[] | null>(null);\n  useEntrance(rootRef, wordsOf, {\n    direction: \"up\",\n    distance,\n    duration,\n    delay: (index, words) => {\n      if (by === \"word\") return delay + index * step;\n      if (index === 0 || !lines.current) lines.current = lineIndexes(words);\n      return delay + (lines.current[index] ?? 0) * step;\n    },\n    once,\n    playOnLoad,\n    margin,\n  });\n\n  // One accessible reading: the real text is rendered once, whole, in a visually hidden span that screen\n  // readers and crawlers read; the per-word spans people see are aria-hidden. Splitting the only copy into\n  // inline-block spans would make some screen readers announce it word by word, and an aria-label is not\n  // allowed on a p, span or div, so this is the form that works for every `as`.\n  return (\n    <Tag\n      ref={(node: HTMLElement | null) => {\n        rootRef.current = node;\n      }}\n      data-slot=\"text-reveal\"\n      className={cn(className)}\n      {...props}\n    >\n      <span className=\"sr-only\">{children}</span>\n      <span aria-hidden=\"true\" data-slot=\"text-reveal-visual\">\n        {children.split(\"\\n\").map((line, lineIndex) => (\n          <Fragment key={lineIndex}>\n            {lineIndex > 0 ? <br /> : null}\n            {line\n              .split(/\\s+/)\n              .filter(Boolean)\n              .map((word, wordIndex) => (\n                <Fragment key={wordIndex}>\n                  {wordIndex > 0 ? \" \" : null}\n                  <span data-word=\"\" className=\"inline-block\">\n                    {word}\n                  </span>\n                </Fragment>\n              ))}\n          </Fragment>\n        ))}\n      </span>\n    </Tag>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "motion",
    "when": "A headline or a short statement. Not for paragraphs of body text (use reveal on the block), and not for text that changes while it is shown.",
    "example": "<TextReveal as=\"h1\" className=\"text-4xl font-medium\" playOnLoad>\n  Websites, apps and systems that last\n</TextReveal>\n<TextReveal as=\"p\" by=\"line\" interval={0.12} className=\"max-w-prose text-xl\">\n  We design the brand, build the product and stay to run it.\n</TextReveal>",
    "client": true
  }
}
