{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-slot-rotate",
  "title": "Text Slot Rotate",
  "description": "A rotating-word slot: each character column spins through a slot-machine reel of glyphs before landing on the next word, with the slot's own pixel width carried between words of different lengths so the layout never jump-cuts.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/text-slot-rotate/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// SlotWordRotate — a rotating-word slot. Distinct from this registry's other\n// character-swap mechanics: split-flap-board hinges a single fixed-width\n// character card 180deg on a change; counter-carry-ripple diffs a NUMBER by\n// place value and flips only the digits that differ. This is neither — it is\n// a continuous SLOT-MACHINE REEL per character column (a long vertical strip\n// of glyphs scrolls downward and decelerates onto the target letter, always\n// travelling the same direction, never a 2-state flip) driving a WHOLE-WORD\n// swap on a timer, with the slot's pixel width carried (FLIP) between words\n// of different lengths so shorter/longer words don't jump-cut the layout.\n// Direct-DOM: reels are CSS transitions on translateY set imperatively via\n// refs; only the settled word lives in React state.\n// ---------------------------------------------------------------------------\n\nexport interface SlotWordRotateProps {\n  /** words cycled through, in order, looping */\n  words: string[];\n  /** ms each word holds before rotating to the next */\n  interval?: number;\n  /** glyphs a reel spins through before landing (visual only) */\n  charset?: string;\n  /** number of intermediate glyphs a reel scrolls through before landing */\n  reelSteps?: number;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst DEFAULT_CHARSET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\nconst REEL_MS_PER_STEP = 90;\nconst REEL_STAGGER_MS = 45;\nconst REEL_EASE = \"cubic-bezier(0.2, 0.85, 0.1, 1)\";\nconst WIDTH_MS = 320;\nconst WIDTH_EASE = \"cubic-bezier(0.34, 1.4, 0.64, 1)\";\n\nfunction pick(charset: string) {\n  return charset[Math.floor(Math.random() * charset.length)] ?? \"A\";\n}\n\ninterface ColumnHandle {\n  strip: HTMLDivElement | null;\n  cellHeight: number;\n}\n\nexport function SlotWordRotate({\n  words,\n  interval = 2400,\n  charset = DEFAULT_CHARSET,\n  reelSteps = 5,\n  className = \"\",\n}: SlotWordRotateProps) {\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const rowRef = useRef<HTMLDivElement>(null);\n  const probeRef = useRef<HTMLSpanElement>(null);\n  const columnsRef = useRef<ColumnHandle[]>([]);\n  const reducedRef = useRef(false);\n  const pausedRef = useRef(false);\n  const indexRef = useRef(0);\n  const timerRef = useRef<number | undefined>(undefined);\n  const tokenRef = useRef(0);\n\n  const [index, setIndex] = useState(0);\n  const [displayed, setDisplayed] = useState(() => words[0] ?? \"\");\n  const maxLen = useMemo(() => Math.max(1, ...words.map((w) => w.length)), [words]);\n  const chars = useMemo(() => Array.from(displayed), [displayed]);\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    reducedRef.current = mq.matches;\n    const onChange = () => {\n      reducedRef.current = mq.matches;\n    };\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n\n  // measures the target word's pixel width from the probe (per-char cell\n  // width x length) and eases the row's own width toward it — the width\n  // carry that keeps a shorter/longer incoming word from jump-cutting.\n  const carryWidth = (word: string) => {\n    const row = rowRef.current;\n    const probe = probeRef.current;\n    if (!row || !probe) return;\n    const cellWidth = probe.getBoundingClientRect().width || 10;\n    const targetWidth = cellWidth * word.length;\n    if (reducedRef.current) {\n      row.style.transition = \"none\";\n      row.style.width = `${targetWidth}px`;\n      return;\n    }\n    row.style.transition = `width ${WIDTH_MS}ms ${WIDTH_EASE}`;\n    row.style.width = `${targetWidth}px`;\n  };\n\n  const spinTo = (word: string) => {\n    const myToken = ++tokenRef.current;\n    carryWidth(word);\n    if (reducedRef.current) {\n      setDisplayed(word);\n      return;\n    }\n    const cols = columnsRef.current;\n    const len = Math.max(word.length, cols.length);\n    for (let i = 0; i < len; i++) {\n      const col = cols[i];\n      if (!col?.strip) continue;\n      if (!col.cellHeight) {\n        col.cellHeight = col.strip.parentElement?.getBoundingClientRect().height || 0;\n      }\n      const target = word[i] ?? \" \";\n      const steps: string[] = [];\n      for (let s = 0; s < reelSteps; s++) steps.push(pick(charset));\n      steps.push(target === \" \" ? \" \" : target);\n      col.strip.textContent = \"\";\n      for (const g of steps) {\n        const cell = document.createElement(\"div\");\n        cell.textContent = g;\n        cell.style.height = `${col.cellHeight}px`;\n        cell.style.display = \"flex\";\n        cell.style.alignItems = \"center\";\n        cell.style.justifyContent = \"center\";\n        col.strip.appendChild(cell);\n      }\n      col.strip.style.transition = \"none\";\n      col.strip.style.transform = \"translateY(0px)\";\n      void col.strip.offsetHeight;\n      const delay = i * REEL_STAGGER_MS;\n      const duration = reelSteps * REEL_MS_PER_STEP;\n      col.strip.style.transition = `transform ${duration}ms ${REEL_EASE} ${delay}ms`;\n      col.strip.style.transform = `translateY(-${reelSteps * col.cellHeight}px)`;\n    }\n    const settleMs = reelSteps * REEL_MS_PER_STEP + len * REEL_STAGGER_MS + 40;\n    window.setTimeout(() => {\n      if (tokenRef.current === myToken) setDisplayed(word);\n    }, settleMs);\n  };\n\n  const goTo = (next: number) => {\n    const n = words.length;\n    if (n === 0) return;\n    const wrapped = ((next % n) + n) % n;\n    indexRef.current = wrapped;\n    setIndex(wrapped);\n    spinTo(words[wrapped] ?? \"\");\n  };\n\n  const scheduleNext = () => {\n    window.clearTimeout(timerRef.current);\n    if (words.length < 2) return;\n    timerRef.current = window.setTimeout(() => {\n      if (!pausedRef.current) goTo(indexRef.current + 1);\n      scheduleNext();\n    }, interval);\n  };\n\n  useEffect(() => {\n    indexRef.current = 0;\n    setIndex(0);\n    setDisplayed(words[0] ?? \"\");\n    scheduleNext();\n    return () => window.clearTimeout(timerRef.current);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [words.join(\"\u0000\"), interval]);\n\n  const onMouseEnter = () => {\n    pausedRef.current = true;\n  };\n  const onMouseLeave = () => {\n    pausedRef.current = false;\n  };\n\n  return (\n    <div\n      ref={wrapRef}\n      className={`inline-flex items-center gap-2 ${className}`}\n      onPointerEnter={onMouseEnter}\n      onPointerLeave={onMouseLeave}\n    >\n      <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n        {displayed}\n      </span>\n\n      <button\n        type=\"button\"\n        aria-label=\"Previous word\"\n        onClick={() => goTo(indexRef.current - 1)}\n        className=\"flex h-7 w-7 shrink-0 items-center justify-center rounded-[6px] border border-border font-mono text-xs text-ns-muted transition-colors hover:border-foreground/40 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n      >\n        ‹\n      </button>\n\n      <div\n        ref={rowRef}\n        aria-hidden=\"true\"\n        className=\"relative inline-flex h-[1.4em] items-center overflow-hidden whitespace-nowrap font-mono text-foreground\"\n        style={{ width: `${maxLen}ch` }}\n      >\n        <span\n          ref={probeRef}\n          className=\"pointer-events-none absolute -left-[9999px] top-0\"\n          style={{ visibility: \"hidden\", whiteSpace: \"pre\" }}\n        >\n          0\n        </span>\n        {Array.from({ length: maxLen }).map((_, i) => (\n          <div\n            key={i}\n            className=\"relative h-[1.4em] overflow-hidden\"\n            style={{ width: \"1ch\" }}\n          >\n            <div\n              ref={(el) => {\n                if (!columnsRef.current[i]) columnsRef.current[i] = { strip: null, cellHeight: 0 };\n                columnsRef.current[i]!.strip = el;\n                if (el) columnsRef.current[i]!.cellHeight = el.parentElement?.getBoundingClientRect().height || 0;\n              }}\n              className=\"absolute left-0 top-0 flex flex-col will-change-transform\"\n            >\n              <div className=\"flex h-[1.4em] items-center justify-center\">\n                {chars[i] ?? \" \"}\n              </div>\n            </div>\n          </div>\n        ))}\n      </div>\n\n      <button\n        type=\"button\"\n        aria-label=\"Next word\"\n        onClick={() => goTo(indexRef.current + 1)}\n        className=\"flex h-7 w-7 shrink-0 items-center justify-center rounded-[6px] border border-border font-mono text-xs text-ns-muted transition-colors hover:border-foreground/40 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n      >\n        ›\n      </button>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/text-slot-rotate.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff"
    },
    "dark": {
      "ns-muted": "#8f8f8f"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "text",
      "slot-machine",
      "reel",
      "mono",
      "rotate",
      "headline",
      "micro-interaction"
    ],
    "instruction": "A rotating-word slot driven by a `words: string[]` prop, cycling automatically to the next word every `interval` ms (default 2400) and looping. The mechanic is a continuous SLOT-MACHINE REEL per character column, distinct from this registry's other character-swap components: split-flap-board hinges one fixed-width card 180deg on a change, and counter-carry-ripple diffs a number by place value with a 2-state vertical flip. Here, each column is an overflow-hidden cell containing a vertical strip of `reelSteps` (default 5) random glyphs from `charset` followed by the target character; a CSS transform transition (`translateY`, `cubic-bezier(0.2,0.85,0.1,1)`, ~90ms per step) scrolls the whole strip downward in one continuous motion so it decelerates onto the landing glyph like a real slot reel, never a discrete 2-state flip. Columns are staggered 45ms apart left to right so the reel-stop visibly ripples across the word. The slot's own pixel width (measured per-character from a hidden monospace probe span x the incoming word's length) eases via a `width` transition (320ms, `cubic-bezier(0.34,1.4,0.64,1)`) toward the new word's width at the same time the reels spin — the width-carry that keeps a shorter or longer incoming word from jump-cutting the layout. All of this is direct-DOM: reel strips are rebuilt and their `style.transform`/`style.transition` set imperatively via refs on each rotation; only the fully-settled word lives in React state. Two real, keyboard-reachable `<button aria-label=\"Previous/Next word\">` controls (‹ ›) let a visitor step the rotation manually at any time, which also resets the automatic interval; hovering or focusing the whole control pauses the automatic timer (manual stepping still works while paused). Accessibility: the entire visual reel is `aria-hidden`; the real, always-current word is exposed via a `role=status aria-live=polite aria-atomic=true` sr-only span that updates once the spin has fully settled, never mid-spin. `prefers-reduced-motion: reduce` skips the reel animation and the width transition entirely — a rotation jumps straight to the new word's final width and glyphs. Zero dependencies, no canvas, no SVG — pure DOM + CSS transforms."
  },
  "type": "registry:ui"
}