{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slide-text",
  "title": "Slide Text",
  "description": "Words, characters or lines rising into place from below their own baseline.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/use-entrance"
  ],
  "files": [
    {
      "path": "registry/default/ui/slide-text.tsx",
      "content": "\"use client\";\n\nimport {\n  Fragment,\n  useMemo,\n  type AnimationEvent,\n  type ComponentProps,\n  type CSSProperties,\n  type Ref,\n} from \"react\";\n\nimport { useEntrance, type EntranceTrigger } from \"@/registry/default/hooks/use-entrance\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\n// One splitter for the module: user-perceived characters, so emoji and\n// accents stay whole wherever the runtime can tell them apart.\nconst characterSplitter =\n  typeof Intl === \"object\" && typeof Intl.Segmenter === \"function\"\n    ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n    : null;\n\nfunction graphemes(text: string) {\n  if (!characterSplitter) return [...text];\n  const pieces: string[] = [];\n  for (const { segment } of characterSplitter.segment(text)) pieces.push(segment);\n  return pieces;\n}\n\ntype SlideTextTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"p\" | \"span\" | \"div\";\n\ninterface SlideTextProps extends Omit<ComponentProps<\"p\">, \"children\" | \"onAnimationEnd\"> {\n  /** Plain text. With `split=\"lines\"`, lines are separated by \"\\n\". */\n  children: string;\n  as?: SlideTextTag;\n  /** What rises on its own: each word, each character or each line. */\n  split?: \"words\" | \"characters\" | \"lines\";\n  /** Where the wave starts. */\n  from?: \"first\" | \"last\" | \"center\";\n  /** \"load\" plays on first paint with CSS alone; \"in-view\" when the text scrolls into view. */\n  trigger?: EntranceTrigger;\n  /** In-view: play the first time only. */\n  once?: boolean;\n  /** Takes over from `trigger`: `false` holds the text below its line, `true` plays it. */\n  play?: boolean;\n  /** Wait before the first piece, in ms. */\n  delay?: number;\n  /** Time between pieces, in ms. */\n  stagger?: number;\n  /** How long each piece takes, in ms. */\n  duration?: number;\n  /** Called once the last piece is in place. */\n  onAnimationComplete?: () => void;\n}\n\n/**\n * Text that rises into place from just below its own line, piece by piece,\n * each one masked so it seems to surface through the baseline. The mask\n * leaves room for descenders. Screen readers get the text in one piece, and\n * with `prefers-reduced-motion` it is shown as is.\n *\n * @example\n * <SlideText as=\"h2\" split=\"characters\" from=\"center\">All hands on deck</SlideText>\n */\nfunction SlideText({\n  children,\n  as: Tag = \"p\",\n  split = \"words\",\n  from = \"first\",\n  trigger = \"load\",\n  once = true,\n  play,\n  delay = 0,\n  stagger = 80,\n  duration = 650,\n  onAnimationComplete,\n  className,\n  ref,\n  ...props\n}: SlideTextProps) {\n  const [observe, phase] = useEntrance<HTMLElement>({ trigger, once, play });\n  const mergedRef = useMemo(() => mergeRefs(ref, observe), [ref, observe]);\n\n  // Masks hold words or lines; each holds the pieces that rise inside it.\n  const masks = useMemo(() => {\n    let next = 0;\n    const units =\n      split === \"lines\"\n        ? children.split(\"\\n\").map((line) => line.trim())\n        : children.trim().split(/\\s+/);\n    return units.filter(Boolean).map((unit) =>\n      (split === \"characters\" ? graphemes(unit) : [unit]).map((text) => ({\n        text,\n        index: next++,\n      }))\n    );\n  }, [children, split]);\n  const count = masks.reduce((sum, mask) => sum + mask.length, 0);\n\n  const order = (index: number) => {\n    if (from === \"last\") return count - 1 - index;\n    if (from === \"center\") return Math.abs(Math.floor((count - 1) / 2) - index);\n    return index;\n  };\n\n  const pieceStyle = (index: number): CSSProperties =>\n    phase === \"static\"\n      ? {}\n      : {\n          animationDelay: `${delay + order(index) * stagger}ms`,\n          animationDuration: `${duration}ms`,\n          animationPlayState: phase === \"armed\" ? \"paused\" : undefined,\n        };\n\n  // The piece that moves last: the far end of the wave.\n  const last = from === \"last\" ? 0 : Math.max(count - 1, 0);\n  const handleAnimationEnd = (event: AnimationEvent<HTMLElement>) => {\n    if ((event.target as HTMLElement).dataset.last !== undefined) onAnimationComplete?.();\n  };\n\n  return (\n    <Tag\n      ref={mergedRef as Ref<never>}\n      data-slot=\"slide-text\"\n      data-state={phase}\n      className={cn(split === \"lines\" && \"flex flex-col\", className)}\n      onAnimationEnd={handleAnimationEnd}\n      {...props}\n    >\n      <span className=\"sr-only\">{children}</span>\n      {masks.map((mask, maskIndex) => (\n        <Fragment key={maskIndex}>\n          {maskIndex > 0 && split !== \"lines\" ? \" \" : null}\n          {/* Padding lets descenders show; the negative margin keeps the line height. */}\n          <span\n            aria-hidden=\"true\"\n            className={cn(\n              \"-mb-[0.15em] inline-block overflow-clip pb-[0.15em] align-top\",\n              split !== \"lines\" && \"whitespace-nowrap\"\n            )}\n          >\n            {mask.map(({ text, index }) => (\n              <span\n                key={index}\n                data-slot=\"slide-text-piece\"\n                data-last={index === last ? \"\" : undefined}\n                className={cn(\n                  \"inline-block\",\n                  phase !== \"static\" && \"motion-safe:animate-slide-text\"\n                )}\n                style={pieceStyle(index)}\n              >\n                {text}\n              </span>\n            ))}\n          </span>\n        </Fragment>\n      ))}\n    </Tag>\n  );\n}\n\nexport { SlideText, type SlideTextProps };\n",
      "type": "registry:ui"
    }
  ],
  "tailwind": {
    "config": {
      "theme": {
        "extend": {
          "keyframes": {
            "slide-text": {
              "from": {
                "transform": "translate3d(0, calc(100% + 0.2em), 0)"
              }
            }
          },
          "animation": {
            "slide-text": "slide-text 650ms cubic-bezier(0.3, 0.9, 0.2, 1) both"
          }
        }
      }
    }
  },
  "cssVars": {
    "theme": {
      "animate-slide-text": "slide-text 650ms cubic-bezier(0.3, 0.9, 0.2, 1) both"
    }
  },
  "css": {
    "@keyframes slide-text": {
      "from": {
        "transform": "translate3d(0, calc(100% + 0.2em), 0)"
      }
    }
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}