{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typewriter",
  "title": "Typewriter",
  "author": "VenusUI",
  "description": "Types, pauses and deletes a list of words with a blinking caret.",
  "files": [
    {
      "path": "registry/default/ui/typewriter.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TypewriterProps extends Omit<React.ComponentProps<\"span\">, \"children\"> {\n  /** Words or phrases to type, one after another. */\n  words: string[]\n  /** Milliseconds per typed character. */\n  typeSpeed?: number\n  /** Milliseconds per deleted character. */\n  deleteSpeed?: number\n  /** Milliseconds to wait after a word is fully typed. */\n  pause?: number\n  /** Start over after the last word. When false, the last word stays. */\n  loop?: boolean\n  /** Show a blinking caret. */\n  cursor?: boolean\n}\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\"\n\n/** Tracks the user's reduced-motion setting. The server assumes motion is allowed. */\nfunction usePrefersReducedMotion() {\n  return React.useSyncExternalStore(\n    (onChange) => {\n      const query = window.matchMedia(REDUCED_MOTION)\n      query.addEventListener(\"change\", onChange)\n      return () => query.removeEventListener(\"change\", onChange)\n    },\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false\n  )\n}\n\n/**\n * Types each word, pauses, deletes it and moves to the next. Screen readers\n * read all words once instead of every keystroke. With reduced motion, the\n * first word is shown without animation.\n */\nfunction Typewriter({\n  words,\n  typeSpeed = 70,\n  deleteSpeed = 40,\n  pause = 1600,\n  loop = true,\n  cursor = true,\n  className,\n  ...props\n}: TypewriterProps) {\n  const [wordIndex, setWordIndex] = React.useState(0)\n  const [length, setLength] = React.useState(0)\n  const [deleting, setDeleting] = React.useState(false)\n  const reducedMotion = usePrefersReducedMotion()\n\n  const word = words[wordIndex % Math.max(words.length, 1)] ?? \"\"\n  const isLast = wordIndex === words.length - 1\n\n  React.useEffect(() => {\n    if (reducedMotion || words.length === 0) return\n    let delay = deleting ? deleteSpeed : typeSpeed\n    let next: () => void\n\n    if (!deleting && length < word.length) {\n      next = () => setLength((l) => l + 1)\n    } else if (!deleting && length === word.length) {\n      if (isLast && !loop) return\n      delay = pause\n      next = () => setDeleting(true)\n    } else if (deleting && length > 0) {\n      next = () => setLength((l) => l - 1)\n    } else {\n      next = () => {\n        setDeleting(false)\n        setWordIndex((i) => (i + 1) % words.length)\n      }\n    }\n    const timeout = setTimeout(next, delay)\n    return () => clearTimeout(timeout)\n  }, [length, deleting, word, isLast, loop, pause, typeSpeed, deleteSpeed, reducedMotion, words.length])\n\n  const visible = reducedMotion ? (words[0] ?? \"\") : word.slice(0, length)\n\n  return (\n    <span data-slot=\"typewriter\" className={cn(\"inline\", className)} {...props}>\n      <span className=\"sr-only\">{words.join(\", \")}</span>\n      <span aria-hidden=\"true\">\n        {visible}\n        {cursor ? (\n          <span className=\"ml-0.5 inline-block h-[1em] w-0.5 translate-y-[0.12em] animate-typewriter-caret bg-current motion-reduce:animate-none\" />\n        ) : null}\n      </span>\n    </span>\n  )\n}\n\nexport { Typewriter, type TypewriterProps }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-typewriter-caret": "typewriter-caret 1s steps(1) infinite"
    }
  },
  "css": {
    "@keyframes typewriter-caret": {
      "0%, 100%": {
        "opacity": "1"
      },
      "50%": {
        "opacity": "0"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "text",
    "animations"
  ],
  "type": "registry:ui"
}