{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-flip-words",
  "type": "registry:component",
  "title": "Text Flip Words",
  "description": "A sentence with one slot that flips through a list of words in 3D while the line resizes to fit each one.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "flip",
    "words",
    "rotating",
    "headline",
    "3d"
  ],
  "docs": "https://hyperblur.dev/effects/text-flip-words",
  "files": [
    {
      "path": "registry/hyperblur/text-flip-words.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-flip-words.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextFlipWordsProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text?: string;\n  words?: string[];\n  interval?: number;\n  duration?: number;\n  accent?: string;\n  pauseOnHover?: boolean;\n}\n\nconst css = `\n@keyframes hb-qd9-in {\n  from { opacity: 0; transform: rotateX(-90deg) translateY(35%); }\n  to { opacity: 1; transform: rotateX(0deg) translateY(0); }\n}\n@keyframes hb-qd9-out {\n  from { opacity: 1; transform: rotateX(0deg) translateY(0); }\n  to { opacity: 0; transform: rotateX(90deg) translateY(-35%); }\n}\n.hb-qd9 {\n  position: relative;\n  display: inline-block;\n  line-height: 1.25;\n  font-family: inherit;\n  text-wrap: balance;\n  box-sizing: border-box;\n}\n.hb-qd9 *, .hb-qd9 *::before, .hb-qd9 *::after { box-sizing: border-box; }\n.hb-qd9-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip: rect(0, 0, 0, 0);\n  white-space: nowrap;\n  border: 0;\n}\n.hb-qd9-slot {\n  position: relative;\n  display: inline-block;\n  height: 1.25em;\n  vertical-align: bottom;\n  perspective: 640px;\n  color: var(--hb-qd9-accent);\n  white-space: nowrap;\n  transition: width var(--hb-qd9-dur) cubic-bezier(.3, .8, .25, 1);\n}\n.hb-qd9-in, .hb-qd9-out {\n  display: block;\n  white-space: nowrap;\n  transform-origin: 50% 50%;\n  backface-visibility: hidden;\n}\n.hb-qd9-slot[data-m] .hb-qd9-in, .hb-qd9-out { position: absolute; left: 0; top: 0; }\n.hb-qd9-in[data-fresh] { animation: hb-qd9-in var(--hb-qd9-dur) cubic-bezier(.25, .9, .3, 1) both; }\n.hb-qd9-out { animation: hb-qd9-out var(--hb-qd9-dur) cubic-bezier(.5, 0, .75, .3) both; pointer-events: none; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qd9-slot { transition: none; }\n  .hb-qd9-in, .hb-qd9-out { animation: none !important; }\n  .hb-qd9-out { display: none; }\n}\n`;\n\ninterface FlipState {\n  i: number;\n  prev: number | null;\n  n: number;\n}\n\nexport function TextFlipWords({\n  text = \"Build {} faster\",\n  words = [\"interfaces\", \"dashboards\", \"landing pages\"],\n  interval = 2.4,\n  duration = 0.6,\n  accent = \"#7fb3ff\",\n  pauseOnHover = true,\n  className = \"\",\n  style,\n  ...rest\n}: TextFlipWordsProps) {\n  const rootRef = React.useRef<HTMLSpanElement>(null);\n  const curRef = React.useRef<HTMLSpanElement>(null);\n  const [state, setState] = React.useState<FlipState>({ i: 0, prev: null, n: 0 });\n  const [width, setWidth] = React.useState<number | null>(null);\n  const count = words.length;\n\n  const at = text.indexOf(\"{}\");\n  const before = at === -1 ? `${text} ` : text.slice(0, at);\n  const after = at === -1 ? \"\" : text.slice(at + 2);\n  const safe = count > 0 ? state.i % count : 0;\n  const prevSafe = state.prev !== null && count > 0 ? state.prev % count : null;\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root || count < 2) return;\n    let paused = false;\n    const hold = () => {\n      paused = pauseOnHover;\n    };\n    const free = () => {\n      paused = false;\n    };\n    root.addEventListener(\"pointerenter\", hold);\n    root.addEventListener(\"pointerleave\", free);\n    root.addEventListener(\"focusin\", hold);\n    root.addEventListener(\"focusout\", free);\n    const id = setInterval(() => {\n      if (paused) return;\n      setState((s) => ({ i: (s.i + 1) % count, prev: s.i, n: s.n + 1 }));\n    }, Math.max(0.8, interval) * 1000);\n    return () => {\n      clearInterval(id);\n      root.removeEventListener(\"pointerenter\", hold);\n      root.removeEventListener(\"pointerleave\", free);\n      root.removeEventListener(\"focusin\", hold);\n      root.removeEventListener(\"focusout\", free);\n    };\n  }, [count, interval, pauseOnHover]);\n\n  React.useEffect(() => {\n    const el = curRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setWidth(el.offsetWidth));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [state.n, words]);\n\n  const vars = {\n    \"--hb-qd9-accent\": accent,\n    \"--hb-qd9-dur\": `${duration}s`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <span ref={rootRef} className={`hb-qd9 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-text-flip-words\" precedence=\"default\">{css}</style>\n      <span className=\"hb-qd9-sr\">\n        {before}\n        {words[safe] ?? \"\"}\n        {after}\n      </span>\n      <span aria-hidden=\"true\">\n        {before}\n        <span\n          className=\"hb-qd9-slot\"\n          style={width !== null ? { width } : undefined}\n          data-m={width !== null ? \"\" : undefined}\n        >\n          <span\n            key={`i${state.n}`}\n            ref={curRef}\n            className=\"hb-qd9-in\"\n            data-fresh={state.n > 0 ? \"\" : undefined}\n          >\n            {words[safe] ?? \"\"}\n          </span>\n          {prevSafe !== null ? (\n            <span key={`o${state.n}`} className=\"hb-qd9-out\">\n              {words[prevSafe] ?? \"\"}\n            </span>\n          ) : null}\n        </span>\n        {after}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}