{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typed-text",
  "type": "registry:ui",
  "title": "Typed Text",
  "description": "Text that types itself in when an agent changes it.",
  "categories": [
    "ai-&-chat"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/typed-text.tsx",
      "type": "registry:ui",
      "target": "components/ui/typed-text.tsx",
      "content": "import { useLayoutEffect, useRef, useState, type ComponentProps } from 'react';\nimport { cn } from '@/lib/sprout/classes';\n\nexport const typedTextCharacterDuration = 25;\n\nexport const typedTextMaxDuration = 800;\n\nlet segmenter: Intl.Segmenter | undefined;\n\nfunction graphemes(text: string) {\n  segmenter ??= new Intl.Segmenter('und', { granularity: 'grapheme' });\n  return Array.from(segmenter.segment(text), item => item.segment);\n}\n\nexport interface TypedTextProps extends Omit<ComponentProps<'span'>, 'children'> {\n  text: string;\n  animate?: boolean | undefined;\n}\n\nexport function TypedText({ text, animate = true, className, ...rest }: TypedTextProps) {\n  const previous = useRef(text);\n  const [visible, setVisible] = useState(text);\n\n  useLayoutEffect(() => {\n    const changed = previous.current !== text;\n    previous.current = text;\n    const motion = window.matchMedia('(prefers-reduced-motion: reduce)');\n    if (!changed || !animate || motion.matches) {\n      setVisible(text);\n      return;\n    }\n    const characters = graphemes(text);\n    const start = performance.now();\n    const duration = Math.min(typedTextMaxDuration, characters.length * typedTextCharacterDuration);\n    let frame = 0;\n    setVisible(characters[0] ?? '');\n    function tick(now: number) {\n      const progress = duration ? Math.min(1, (now - start) / duration) : 1;\n      setVisible(characters.slice(0, Math.max(1, Math.ceil(progress * characters.length))).join(''));\n      if (progress < 1) frame = requestAnimationFrame(tick);\n    }\n    function reduceMotion() {\n      if (!motion.matches) return;\n      cancelAnimationFrame(frame);\n      setVisible(text);\n    }\n    frame = requestAnimationFrame(tick);\n    motion.addEventListener('change', reduceMotion);\n    return () => {\n      cancelAnimationFrame(frame);\n      motion.removeEventListener('change', reduceMotion);\n    };\n  }, [text, animate]);\n\n  return (\n    <span\n      data-slot=\"typed-text\"\n      data-state={visible === text ? 'idle' : 'typing'}\n      className={cn('sprout-typed-text', className)}\n      {...rest}\n    >\n      <span className=\"sprout-typed-text-sr-only\">{text}</span>\n      <span aria-hidden=\"true\">{visible}</span>\n    </span>\n  );\n}\n"
    }
  ],
  "css": {
    "@layer components": {
      ".sprout-typed-text": {
        "color": "inherit"
      },
      ".sprout-typed-text-sr-only": {
        "clip": "rect(0, 0, 0, 0)",
        "white-space": "nowrap",
        "border": "0",
        "width": "1px",
        "height": "1px",
        "margin": "-1px",
        "padding": "0",
        "position": "absolute",
        "overflow": "hidden"
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/typed-text/",
  "meta": {
    "source": "packages/sprout/src/components/typed-text.tsx"
  }
}
