{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "word-roller",
  "type": "registry:component",
  "title": "Word Roller",
  "description": "A word rolls vertically between options on a spring-loaded drum, and its pill changes width along with it.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Text"
  ],
  "docs": "Installed in components/furin/word-roller/. Docs, live controls and props table: https://furin.dev/components/word-roller/",
  "files": [
    {
      "path": "registry/word-roller/WordRoller.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./WordRoller.css\";\n\nexport interface WordRollerProps {\n  /** Palabras separadas por \"|\" (alternativa a `words`). */\n  children?: string;\n  /** Lista de palabras que ruedan una tras otra. */\n  words?: string[];\n  /** Texto fijo antes del rodillo. */\n  prefix?: string;\n  /** Texto fijo después del rodillo. */\n  suffix?: string;\n  /** Tamaño de la letra, en px. */\n  size?: number;\n  /** Milisegundos entre cada cambio de palabra. */\n  interval?: number;\n  /** Ángulo entre una palabra y la siguiente en el tambor, en grados. */\n  curvature?: number;\n  /** Dibuja una cápsula detrás de la palabra que cambia. */\n  pill?: boolean;\n  /** Color del texto fijo. */\n  color?: string;\n  /** Color de la palabra del rodillo. */\n  accent?: string;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst DEG = Math.PI / 180;\n\n/** Una palabra rueda verticalmente entre opciones, sobre un tambor 3D con resorte, y su ancho se anima con ella. */\nexport function WordRoller({\n  children = \"build|design|launch|scale\",\n  words,\n  prefix = \"Your team\",\n  suffix = \"\",\n  size = 40,\n  interval = 2300,\n  curvature = 42,\n  pill = true,\n  color = \"#F4F5F7\",\n  accent = \"#7CF5C6\",\n  className = \"\",\n  style,\n}: WordRollerProps) {\n  const rootRef = useRef<HTMLSpanElement>(null);\n  const ventanaRef = useRef<HTMLSpanElement>(null);\n  const lista = (words && words.length ? words : String(children ?? \"\").split(\"|\")).map((s) => s.trim()).filter(Boolean);\n  const clave = lista.join(\"\\u0001\");\n  const cfg = useRef({ interval, curvature });\n  cfg.current = { interval, curvature };\n  const avanzar = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    const root = rootRef.current, ventana = ventanaRef.current;\n    if (!root || !ventana) return;\n    const vent: HTMLSpanElement = ventana;\n    const caras = Array.from(ventana.querySelectorAll<HTMLElement>(\"[data-cara]\"));\n    const medidas = Array.from(root.querySelectorAll<HTMLElement>(\"[data-medida]\"));\n    const n = lista.length;\n    const reducido = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let anchos = new Array<number>(n).fill(0);\n    let alto = 0, pad = 0, R = 0;\n    // Resorte con un ligero rebote: llega, se pasa un poco y se asienta.\n    const E = { pos: 0, vel: 0, meta: 0, ultimo: 0 };\n    let raf = 0, timer = 0, visible = true, muerto = false, dormidoTimer = false;\n\n    const medir = () => {\n      // Si \"prefijo + la palabra más larga\" no cabe en el contenedor, encoge la letra lo justo.\n      root.style.setProperty(\"--furin-wr-fit\", \"1\");\n      const masAncha = Math.max(...medidas.map((m) => m.getBoundingClientRect().width));\n      const fs0 = parseFloat(getComputedStyle(root).fontSize) || 40;\n      const natural = root.scrollWidth - vent.offsetWidth + masAncha + fs0 * 0.6;\n      const libre = (root.parentElement?.clientWidth ?? 0) - 28;\n      root.style.setProperty(\"--furin-wr-fit\", (libre > 40 && natural > libre ? Math.max(0.4, libre / natural) : 1).toFixed(3));\n      anchos = medidas.map((m) => m.getBoundingClientRect().width);\n      const fs = parseFloat(getComputedStyle(root).fontSize) || 40;\n      alto = ventana.clientHeight || fs * 1.2;\n      pad = fs * 0.3;\n      const paso = cfg.current.curvature * DEG;\n      R = alto / 2 / Math.tan(Math.max(0.2, paso / 2));\n      pintar();\n    };\n\n    const mod = (a: number) => ((a % n) + n) % n;\n    function pintar() {\n      const paso = cfg.current.curvature;\n      const base = mod(Math.floor(E.pos));\n      const f = E.pos - Math.floor(E.pos);\n      const w = anchos[base] + (anchos[mod(base + 1)] - anchos[base]) * f;\n      vent.style.width = `${(w + pad * 2).toFixed(2)}px`;\n      for (let j = 0; j < n; j++) {\n        let d = mod(j - E.pos);\n        if (d > n / 2) d -= n;\n        const a = d * paso;\n        const c = caras[j];\n        if (Math.abs(a) > 88) { c.style.visibility = \"hidden\"; continue; }\n        c.style.visibility = \"visible\";\n        c.style.transform = `translateZ(${(-R).toFixed(1)}px) rotateX(${(-a).toFixed(2)}deg) translateZ(${R.toFixed(1)}px)`;\n        const o = Math.max(0, Math.cos(a * DEG * 1.12));\n        c.style.opacity = (o * o * o * o).toFixed(3);\n        c.style.filter = Math.abs(a) > 4 ? `blur(${(Math.abs(a) / 90 * 2.2).toFixed(2)}px)` : \"\";\n      }\n    }\n\n    const paso = (now: number) => {\n      raf = 0;\n      if (muerto || !visible) return;\n      const dt = Math.min(0.033, (now - (E.ultimo || now)) / 1000 || 0.016);\n      E.ultimo = now;\n      const k = 190, c = 19;\n      // Dos subpasos para que el resorte sea estable aunque un cuadro tarde.\n      for (let i = 0; i < 2; i++) {\n        E.vel += ((E.meta - E.pos) * k - E.vel * c) * (dt / 2);\n        E.pos += E.vel * (dt / 2);\n      }\n      if (Math.abs(E.meta - E.pos) < 0.0006 && Math.abs(E.vel) < 0.004) { E.pos = E.meta; E.vel = 0; pintar(); E.ultimo = 0; return; }\n      pintar();\n      raf = requestAnimationFrame(paso);\n    };\n    const wake = () => { if (!raf && visible && !muerto) { E.ultimo = 0; raf = requestAnimationFrame(paso); } };\n\n    const siguiente = () => {\n      if (muerto) return;\n      E.meta += 1;\n      if (reducido) { E.pos = E.meta; pintar(); } else wake();\n      root.dataset.i = String(mod(E.meta));\n    };\n    avanzar.current = () => { clearTimeout(timer); siguiente(); programar(); };\n    function programar() {\n      clearTimeout(timer);\n      if (muerto || reducido || n < 2) return;\n      if (!visible) { dormidoTimer = true; return; }\n      timer = window.setTimeout(() => { siguiente(); programar(); }, cfg.current.interval);\n    }\n\n    medir();\n    const ro = new ResizeObserver(medir);\n    ro.observe(root.parentElement ?? root);\n    document.fonts?.ready.then(medir);\n    document.fonts?.addEventListener?.(\"loadingdone\", medir);\n    const io = new IntersectionObserver(([e]) => {\n      visible = e.isIntersecting;\n      if (visible) { wake(); if (dormidoTimer) { dormidoTimer = false; programar(); } }\n    }, { rootMargin: \"40px\" });\n    io.observe(root);\n    programar();\n    return () => {\n      muerto = true; avanzar.current = () => {};\n      cancelAnimationFrame(raf); clearTimeout(timer);\n      ro.disconnect(); io.disconnect();\n      document.fonts?.removeEventListener?.(\"loadingdone\", medir);\n    };\n  }, [clave, curvature, size]);\n\n  const vars = { \"--furin-wr-size\": `${size}px`, \"--furin-wr-color\": color, \"--furin-wr-accent\": accent } as CSSProperties;\n  return (\n    <span\n      ref={rootRef}\n      className={`furin-word-roller ${className}`}\n      data-pill={pill ? \"1\" : \"0\"}\n      style={{ ...vars, ...style }}\n      onClick={() => avanzar.current()}\n    >\n      <span className=\"furin-word-roller__sr\">{`${prefix} ${lista.join(\", \")} ${suffix}`.trim()}</span>\n      <span className=\"furin-word-roller__vis\" aria-hidden=\"true\">\n        {prefix ? <span className=\"furin-word-roller__fijo\">{prefix}</span> : null}\n        <span ref={ventanaRef} className=\"furin-word-roller__ventana\">\n          <span className=\"furin-word-roller__tambor\">\n            {lista.map((w, j) => (\n              <span key={j} data-cara=\"\" className=\"furin-word-roller__cara\">{w}</span>\n            ))}\n          </span>\n        </span>\n        {suffix ? <span className=\"furin-word-roller__fijo\">{suffix}</span> : null}\n        {/* Medidores invisibles: dan el ancho natural de cada palabra para animar la cápsula. */}\n        <span className=\"furin-word-roller__medidas\">\n          {lista.map((w, j) => <span key={j} data-medida=\"\">{w}</span>)}\n        </span>\n      </span>\n    </span>\n  );\n}\n\nexport default WordRoller;\n",
      "type": "registry:component",
      "target": "components/furin/word-roller/WordRoller.tsx"
    },
    {
      "path": "registry/word-roller/WordRoller.css",
      "content": ".furin-word-roller {\n  position: relative;\n  display: inline-block;\n  max-width: 100%;\n  font-family: \"Geist\", \"Inter\", \"SF Pro Display\", system-ui, -apple-system, \"Helvetica Neue\", Arial, sans-serif;\n  font-size: calc(var(--furin-wr-size) * var(--furin-wr-fit, 1));\n  font-weight: 600;\n  line-height: 1.2;\n  letter-spacing: -0.03em;\n  color: var(--furin-wr-color);\n  white-space: nowrap;\n  cursor: pointer;\n  -webkit-user-select: none;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  -webkit-font-smoothing: antialiased;\n}\n.furin-word-roller__vis { display: inline-flex; align-items: center; gap: 0.28em; }\n.furin-word-roller__fijo { display: block; }\n/* La ventana mide su ancho desde JS: sigue a la palabra que está al frente del tambor. */\n.furin-word-roller__ventana {\n  position: relative;\n  display: block;\n  height: 1.32em;\n  perspective: 560px;\n  perspective-origin: 50% 50%;\n  border-radius: 0.3em;\n}\n.furin-word-roller[data-pill=\"1\"] .furin-word-roller__ventana {\n  background: linear-gradient(180deg, color-mix(in srgb, var(--furin-wr-accent) 16%, transparent), color-mix(in srgb, var(--furin-wr-accent) 7%, transparent));\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--furin-wr-accent) 30%, transparent), 0 8px 28px -12px color-mix(in srgb, var(--furin-wr-accent) 45%, transparent);\n}\n.furin-word-roller__tambor { position: absolute; inset: 0; transform-style: preserve-3d; }\n.furin-word-roller__cara {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  color: var(--furin-wr-accent);\n  backface-visibility: hidden;\n  will-change: transform, opacity;\n}\n.furin-word-roller__medidas { position: absolute; left: 0; top: 0; display: block; visibility: hidden; pointer-events: none; }\n.furin-word-roller__medidas > span { position: absolute; left: 0; top: 0; white-space: nowrap; }\n.furin-word-roller__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n",
      "type": "registry:file",
      "target": "components/furin/word-roller/WordRoller.css"
    }
  ]
}
