{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"typing-headline","type":"registry:block","title":"Typing headline","description":"A headline with a rotating word typed and erased behind a caret, plus a quiet list that tracks the word currently in rotation.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/typing-headline/typing-headline.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TypingHeadlineProps = {\n  className?: string;\n  /** Text shown before the rotating word. */\n  prefix?: string;\n  /** Words typed in rotation after the prefix. */\n  words?: string[];\n  /** Text shown after the rotating word. */\n  suffix?: string;\n  /** Supporting sentence under the headline. */\n  description?: string;\n  /** Milliseconds per typed character. */\n  typeSpeed?: number;\n  /** How long a finished word stays on screen, in milliseconds. */\n  holdMs?: number;\n};\n\nconst DEFAULT_WORDS = [\"watch\", \"move\", \"question\", \"answer\", \"forecast\"];\n\nexport function TypingHeadline({\n  className,\n  prefix = \"Built for the people who\",\n  words = DEFAULT_WORDS,\n  suffix = \"the numbers.\",\n  description = \"Free, MIT-licensed dashboard blocks for shadcn/ui. Install one, keep the file, and shape it to the data your team actually argues about.\",\n  typeSpeed = 70,\n  holdMs = 1700,\n}: TypingHeadlineProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const inView = useInView(rootRef, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n\n  const list = words.filter((word) => word.trim().length > 0);\n  const safeWords = list.length > 0 ? list : DEFAULT_WORDS;\n  const signature = safeWords.join(\"\\u0000\");\n\n  const [typed, setTyped] = useState(\"\");\n  const [active, setActive] = useState(0);\n  const [done, setDone] = useState(false);\n\n  useEffect(() => {\n    if (reduce) {\n      setTyped(safeWords[0] ?? \"\");\n      setActive(0);\n      setDone(true);\n      return;\n    }\n    if (!inView) return;\n\n    let cancelled = false;\n    let timeout: ReturnType<typeof setTimeout> | undefined;\n    let wordIndex = 0;\n    let char = 0;\n    let deleting = false;\n\n    setTyped(\"\");\n    setActive(0);\n    setDone(false);\n\n    const tick = () => {\n      if (cancelled) return;\n      const word = safeWords[wordIndex % safeWords.length] ?? \"\";\n\n      if (!deleting) {\n        char += 1;\n        setTyped(word.slice(0, char));\n\n        if (char >= word.length) {\n          if (safeWords.length === 1) {\n            setDone(true);\n            return;\n          }\n          deleting = true;\n          timeout = setTimeout(tick, Math.max(400, holdMs));\n        } else {\n          timeout = setTimeout(tick, Math.max(28, typeSpeed));\n        }\n        return;\n      }\n\n      char -= 1;\n      setTyped(word.slice(0, Math.max(0, char)));\n\n      if (char <= 0) {\n        deleting = false;\n        wordIndex = (wordIndex + 1) % safeWords.length;\n        setActive(wordIndex);\n        timeout = setTimeout(tick, Math.max(120, typeSpeed * 2));\n      } else {\n        timeout = setTimeout(tick, Math.max(18, typeSpeed / 2));\n      }\n    };\n\n    timeout = setTimeout(tick, 420);\n\n    return () => {\n      cancelled = true;\n      if (timeout) clearTimeout(timeout);\n    };\n  }, [inView, reduce, signature, typeSpeed, holdMs]);\n\n  const showCaret = !reduce && !done;\n  const displayed = reduce ? (safeWords[0] ?? \"\") : typed;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <section\n        ref={rootRef}\n        className={cn(\"w-full max-w-3xl text-left\", className)}\n      >\n        <h2 className=\"text-balance text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl md:text-6xl\">\n          <span className=\"text-muted-foreground\">{prefix}</span>{\" \"}\n          <span className=\"text-foreground\">{displayed || \"\\u00A0\"}</span>\n          {showCaret ? (\n            <motion.span\n              aria-hidden=\"true\"\n              initial={false}\n              animate={{ opacity: [1, 1, 0] }}\n              transition={{\n                duration: 1.05,\n                times: [0, 0.55, 1],\n                repeat: Infinity,\n                ease: \"linear\",\n              }}\n              className=\"ml-0.5 inline-block h-[0.86em] w-[2px] translate-y-[0.08em] rounded-[1px] bg-foreground\"\n            />\n          ) : null}{\" \"}\n          <span className=\"text-muted-foreground\">{suffix}</span>\n        </h2>\n\n        <p className=\"mt-5 max-w-xl text-[14px] leading-relaxed text-muted-foreground sm:text-[15px]\">\n          {description}\n        </p>\n\n        <div className=\"mt-8 flex flex-wrap items-center gap-x-5 gap-y-2 border-t border-border pt-4\">\n          <span className=\"text-[11px] font-medium text-muted-foreground\">\n            In rotation\n          </span>\n          <ul className=\"flex list-none flex-wrap items-center gap-x-5 gap-y-2 text-[12px]\">\n            {safeWords.map((word, index) => {\n              const isActive = index === active;\n              return (\n                <li\n                  key={`${word}-${index}`}\n                  className={cn(\n                    \"inline-flex items-center gap-1.5 transition-colors duration-300\",\n                    isActive ? \"text-foreground\" : \"text-muted-foreground\"\n                  )}\n                >\n                  <span\n                    aria-hidden=\"true\"\n                    className={cn(\n                      \"h-1 w-1 rounded-full transition-colors duration-300\",\n                      isActive ? \"bg-foreground\" : \"bg-border\"\n                    )}\n                  />\n                  {word}\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n      </section>\n    </MotionConfig>\n  );\n}\n\nexport default TypingHeadline;\n"}]}