{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "word-rotate",
  "title": "Word rotate",
  "description": "Swaps words in place with a vertical slide and blur while the box springs to each word's width, so the sentence glides instead of jumping.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/text/word-rotate.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useInView, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { spring } from \"@/lib/goodui-motion\"\n\nexport type WordRotateProps = Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> & {\n  /** Words or short phrases shown one at a time, in order. */\n  words: string[]\n  /** Milliseconds each word stays before the next one. */\n  interval?: number\n  /** Controlled index of the visible word. */\n  index?: number\n  /** Starting word when uncontrolled. */\n  defaultIndex?: number\n  /** Called with the next index on every automatic rotation. */\n  onIndexChange?: (index: number) => void\n  /** Stop auto-rotating (controls and `index` still work). */\n  paused?: boolean\n  /** Where the word sits while the box resizes. */\n  align?: \"start\" | \"center\" | \"end\"\n}\n\n/**\n * Rotates words in place with a vertical slide and blur. The box width springs to each word, so the\n * surrounding sentence glides instead of jumping. Pauses while off-screen or when the tab is hidden.\n */\nexport function WordRotate({\n  words,\n  interval = 2400,\n  index,\n  defaultIndex = 0,\n  onIndexChange,\n  paused = false,\n  align = \"start\",\n  className,\n  ...props\n}: WordRotateProps) {\n  const reduce = useReducedMotion() ?? false\n  const n = words.length\n  const [inner, setInner] = React.useState(defaultIndex)\n  const controlled = index !== undefined\n  const raw = controlled ? index : inner\n  const current = n ? ((raw % n) + n) % n : 0\n\n  const rootRef = React.useRef<HTMLSpanElement>(null)\n  const measureRef = React.useRef<HTMLSpanElement>(null)\n  const inView = useInView(rootRef)\n  const [width, setWidth] = React.useState<number | null>(null)\n  const measured = React.useRef(false)\n\n  const changeRef = React.useRef(onIndexChange)\n  changeRef.current = onIndexChange\n\n  React.useEffect(() => {\n    if (paused || !inView || n < 2) return\n    const t = setTimeout(() => {\n      if (document.hidden) return\n      const next = (current + 1) % n\n      if (!controlled) setInner(next)\n      changeRef.current?.(next)\n    }, interval)\n    return () => clearTimeout(t)\n  }, [paused, inView, n, current, interval, controlled])\n\n  // Measure the incoming word (also after web fonts load) so the box can spring to it.\n  React.useEffect(() => {\n    const el = measureRef.current\n    if (!el) return\n    const update = () => setWidth(el.getBoundingClientRect().width)\n    update()\n    const ro = new ResizeObserver(update)\n    ro.observe(el)\n    return () => ro.disconnect()\n  }, [])\n\n  const firstMeasure = width !== null && !measured.current\n  React.useEffect(() => {\n    if (width !== null) measured.current = true\n  }, [width])\n\n  const word = words[current] ?? \"\"\n  const slide = reduce\n    ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n    : {\n        initial: { opacity: 0, y: \"0.7em\", filter: \"blur(6px)\" },\n        animate: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n        exit: { opacity: 0, y: \"-0.7em\", filter: \"blur(6px)\" },\n      }\n\n  return (\n    <span ref={rootRef} className={cn(\"relative inline-block align-bottom\", className)} {...props}>\n      <span className=\"sr-only\">{word}</span>\n      <span ref={measureRef} aria-hidden=\"true\" className=\"invisible absolute top-0 left-0 whitespace-nowrap\">\n        {word}\n      </span>\n      <motion.span\n        aria-hidden=\"true\"\n        className=\"relative -my-[0.15em] inline-grid overflow-hidden py-[0.15em] align-bottom whitespace-nowrap\"\n        style={{ justifyItems: align }}\n        initial={false}\n        animate={width === null ? undefined : { width }}\n        transition={reduce || firstMeasure ? { duration: 0 } : spring.morph}\n      >\n        <AnimatePresence initial={false}>\n          <motion.span\n            key={current}\n            className=\"[grid-area:1/1]\"\n            {...slide}\n            transition={reduce ? { duration: 0.15 } : spring.morph}\n          >\n            {word}\n          </motion.span>\n        </AnimatePresence>\n      </motion.span>\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/word-rotate.tsx"
    }
  ],
  "categories": [
    "components",
    "text"
  ],
  "type": "registry:component"
}