{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-roll-words",
  "type": "registry:component",
  "title": "Text Roll Words",
  "description": "Every letter position is a reel that rolls to the next word at its own speed, and each reel resizes to the exact width of its new letter. The cycle wraps without rewinding.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "reel",
    "words",
    "rotate",
    "slot",
    "inline",
    "headline"
  ],
  "docs": "https://hyperblur.dev/effects/text-roll-words",
  "files": [
    {
      "path": "registry/hyperblur/text-roll-words.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-roll-words.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextRollWordsProps extends React.HTMLAttributes<HTMLSpanElement> {\n  words?: string[];\n  interval?: number;\n  duration?: number;\n  stagger?: number;\n  pauseOnHover?: boolean;\n  paused?: boolean;\n}\n\nconst css = `\n.hb-vi10 {\n  position: relative;\n  display: inline-flex;\n  align-items: flex-start;\n  vertical-align: bottom;\n  height: 1.18em;\n  line-height: 1.18;\n  font-family: inherit;\n  white-space: pre;\n  box-sizing: border-box;\n}\n.hb-vi10 *, .hb-vi10 *::before, .hb-vi10 *::after { box-sizing: border-box; }\n.hb-vi10-sr {\n  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;\n  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;\n}\n.hb-vi10-measure {\n  position: absolute;\n  left: 0; top: 0;\n  visibility: hidden;\n  pointer-events: none;\n  white-space: pre;\n}\n.hb-vi10-col {\n  position: relative;\n  display: inline-block;\n  height: 1.18em;\n  overflow: hidden;\n  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 12%, #000 88%, transparent 100%);\n  mask-image: linear-gradient(180deg, transparent 0, #000 12%, #000 88%, transparent 100%);\n  transition: width var(--hb-vi10-cd) cubic-bezier(.65, 0, .2, 1);\n  transition-delay: var(--hb-vi10-cdl);\n}\n.hb-vi10-strip {\n  display: flex;\n  flex-direction: column;\n  transform: translate3d(0, calc(var(--hb-vi10-idx) * -1.18em), 0);\n  transition: transform var(--hb-vi10-cd) cubic-bezier(.7, -0.12, .22, 1.18);\n  transition-delay: var(--hb-vi10-cdl);\n  will-change: transform;\n}\n.hb-vi10-strip > span { display: block; height: 1.18em; }\n.hb-vi10[data-snap] .hb-vi10-strip, .hb-vi10[data-snap] .hb-vi10-col { transition: none; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vi10 .hb-vi10-strip, .hb-vi10 .hb-vi10-col { transition: none; }\n}\n`;\n\nfunction hash(n: number) {\n  let x = (n | 0) ^ 0x9e3779b9;\n  x = Math.imul(x ^ (x >>> 16), 0x85ebca6b);\n  x = Math.imul(x ^ (x >>> 13), 0xc2b2ae35);\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nexport function TextRollWords({\n  words = [\"Ship\", \"Scale\", \"Shine\"],\n  interval = 2.2,\n  duration = 0.9,\n  stagger = 0.045,\n  pauseOnHover = true,\n  paused = false,\n  className = \"\",\n  style,\n  onMouseEnter,\n  onMouseLeave,\n  ...rest\n}: TextRollWordsProps) {\n  const list = words.length ? words : [\"\"];\n  const L = list.length;\n  const key = list.join(\"\\u0001\");\n  const chars = React.useMemo(() => key.split(\"\\u0001\").map((w) => Array.from(w)), [key]);\n  const cols = Math.max(...chars.map((c) => c.length));\n  const seq = React.useMemo(() => [...chars, chars[0]], [chars]);\n  const measureRef = React.useRef<HTMLSpanElement>(null);\n  const [widths, setWidths] = React.useState<number[][] | null>(null);\n  const [idx, setIdx] = React.useState(0);\n  const [snap, setSnap] = React.useState(false);\n  const [hover, setHover] = React.useState(false);\n  const halt = paused || (pauseOnHover && hover) || L < 2;\n  const total = duration * 1.15 + stagger * cols;\n\n  React.useLayoutEffect(() => {\n    const box = measureRef.current;\n    if (!box) return;\n    const measure = () => {\n      const rows = Array.from(box.children) as HTMLElement[];\n      const next = rows.map((row) => Array.from(row.children).map((c) => (c as HTMLElement).getBoundingClientRect().width));\n      setWidths((prev) => (prev && JSON.stringify(prev) === JSON.stringify(next) ? prev : next));\n    };\n    measure();\n    if (document.fonts?.ready) document.fonts.ready.then(measure).catch(() => undefined);\n    if (typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(measure);\n    ro.observe(box);\n    return () => ro.disconnect();\n  }, [chars]);\n\n  React.useEffect(() => {\n    if (halt) return;\n    const id = setTimeout(() => setIdx((i) => i + 1), interval * 1000);\n    return () => clearTimeout(id);\n  }, [halt, interval, idx]);\n\n  React.useEffect(() => {\n    if (idx < L) return;\n    const id = setTimeout(() => {\n      setSnap(true);\n      setIdx(0);\n    }, total * 1000 + 40);\n    return () => clearTimeout(id);\n  }, [idx, L, total]);\n\n  React.useEffect(() => {\n    if (!snap) return;\n    const id = requestAnimationFrame(() => requestAnimationFrame(() => setSnap(false)));\n    return () => cancelAnimationFrame(id);\n  }, [snap]);\n\n  const shown = idx % L;\n  const vars = { ...style } as React.CSSProperties;\n\n  return (\n    <span\n      className={`hb-vi10 ${className}`}\n      style={vars}\n      data-snap={snap ? \"\" : undefined}\n      onMouseEnter={(e) => {\n        setHover(true);\n        onMouseEnter?.(e);\n      }}\n      onMouseLeave={(e) => {\n        setHover(false);\n        onMouseLeave?.(e);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-text-roll-words\" precedence=\"default\">{css}</style>\n      <span className=\"hb-vi10-sr\">{list[shown]}</span>\n      <span ref={measureRef} className=\"hb-vi10-measure\" aria-hidden=\"true\">\n        {chars.map((c, w) => (\n          <span key={w} style={{ display: \"block\" }}>\n            {c.map((ch, k) => (\n              <span key={k} style={{ display: \"inline-block\" }}>{ch}</span>\n            ))}\n          </span>\n        ))}\n      </span>\n      {Array.from({ length: cols }, (_, k) => {\n        const d = duration * (0.82 + (hash(k * 97 + 13) % 36) / 100);\n        const w = widths ? widths[shown]?.[k] ?? 0 : undefined;\n        return (\n          <span\n            key={k}\n            className=\"hb-vi10-col\"\n            aria-hidden=\"true\"\n            style={\n              {\n                width: w === undefined ? undefined : `${w.toFixed(2)}px`,\n                \"--hb-vi10-cd\": `${d.toFixed(3)}s`,\n                \"--hb-vi10-cdl\": `${(k * stagger).toFixed(3)}s`,\n              } as React.CSSProperties\n            }\n          >\n            <span className=\"hb-vi10-strip\" style={{ \"--hb-vi10-idx\": idx } as React.CSSProperties}>\n              {seq.map((c, r) => (\n                <span key={r}>{c[k] ?? \" \"}</span>\n              ))}\n            </span>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n"
    }
  ]
}