{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "word-rotator",
  "title": "Word Rotator",
  "description": "A headline with one word that keeps changing: each word rolls in while the space around it eases to fit, so the sentence never jumps.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/word-rotator/word-rotator.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface WordRotatorProps extends Omit<\n  React.HTMLAttributes<HTMLHeadingElement>,\n  \"children\"\n> {\n  /** Text before the changing word. */\n  prefix?: string;\n  words?: string[];\n  /** Text after the changing word. */\n  suffix?: string;\n  /** Milliseconds each word stays. */\n  interval?: number;\n  /** Colour of the changing word. Defaults to the text colour. */\n  color?: string;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n// Kept outside the component: a new array on every render would restart the measuring effect forever.\nconst WORDS = [\"designers\", \"founders\", \"engineers\"];\n\nexport function WordRotator({\n  prefix = \"Built for\",\n  words = WORDS,\n  suffix = \"\",\n  interval = 2000,\n  color,\n  as: Tag = \"h2\",\n  className,\n  style,\n  ...props\n}: WordRotatorProps) {\n  const reduce = useReducedMotion();\n  const sizerRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const [index, setIndex] = React.useState(0);\n  const [widths, setWidths] = React.useState<number[]>([]);\n\n  // Measured once per font load, so the slot can ease to each word's own width.\n  React.useEffect(() => {\n    const measure = () =>\n      setWidths(\n        sizerRefs.current\n          .slice(0, words.length)\n          .map((el) => el?.getBoundingClientRect().width ?? 0),\n      );\n    const frame = requestAnimationFrame(measure);\n    document.fonts?.ready.then(measure);\n    window.addEventListener(\"resize\", measure);\n    return () => {\n      cancelAnimationFrame(frame);\n      window.removeEventListener(\"resize\", measure);\n    };\n  }, [words]);\n\n  React.useEffect(() => {\n    if (reduce || words.length < 2) return;\n    const timer = window.setInterval(\n      () => setIndex((i) => (i + 1) % words.length),\n      interval,\n    );\n    return () => window.clearInterval(timer);\n  }, [reduce, words.length, interval]);\n\n  return (\n    <Tag\n      aria-label={`${prefix} ${words.join(\", \")} ${suffix}`.trim()}\n      className={className}\n      style={style}\n      {...props}\n    >\n      <span aria-hidden=\"true\">\n        {prefix}{\" \"}\n        <span\n          className=\"relative inline-block overflow-hidden align-bottom transition-[width] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\"\n          style={{ width: widths[index] || undefined, height: \"1.2em\" }}\n        >\n          {words.map((word, i) => {\n            const offset = (i - index + words.length) % words.length;\n            const on = offset === 0;\n            const leaving = offset === words.length - 1;\n            return (\n              <span\n                key={word}\n                ref={(el) => {\n                  sizerRefs.current[i] = el;\n                }}\n                className=\"absolute top-0 left-0 whitespace-nowrap motion-safe:transition-[transform,opacity] motion-safe:duration-500 motion-safe:ease-[cubic-bezier(0.22,1,0.36,1)]\"\n                style={{\n                  color,\n                  lineHeight: 1.2,\n                  opacity: on ? 1 : 0,\n                  transform: on\n                    ? \"translateY(0)\"\n                    : leaving\n                      ? \"translateY(-100%)\"\n                      : \"translateY(100%)\",\n                }}\n              >\n                {word}\n              </span>\n            );\n          })}\n        </span>\n        {suffix ? ` ${suffix}` : \"\"}\n      </span>\n    </Tag>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}