{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"line-roll","type":"registry:ui","title":"Line Roll","description":"Lines of text roll endlessly through a soft-masked window, the active line sharp and its neighbours blurred.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/line-roll.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useState, type TransitionEvent } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface LineRollProps {\n  items: string[];\n  /** Ms between steps. */\n  interval?: number;\n  /** Ms for one slide. */\n  duration?: number;\n  /** Lines shown in the window (odd numbers keep the active line centered). */\n  visibleLines?: number;\n  /** Blur and dim lines that are not active. */\n  dimInactive?: boolean;\n  align?: \"left\" | \"center\" | \"right\";\n  className?: string;\n}\n\nconst LINE = 1.2; // em per line\n\nexport function LineRoll({\n  items,\n  interval = 2200,\n  duration = 800,\n  visibleLines = 3,\n  dimInactive = true,\n  align = \"left\",\n  className,\n}: LineRollProps) {\n  const [step, setStep] = useState(0);\n  const [instant, setInstant] = useState(false);\n  const n = items.length;\n  const pad = Math.floor(Math.max(1, visibleLines) / 2);\n  const i = Math.min(step, n);\n\n  useEffect(() => {\n    if (n < 2) return;\n    const id = window.setInterval(() => {\n      const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n      // At the cloned end, wait for the snap back to 0 before moving on.\n      setStep((s) => (still ? (s + 1) % n : s >= n ? s : s + 1));\n    }, interval);\n    return () => window.clearInterval(id);\n  }, [n, interval]);\n\n  useEffect(() => {\n    if (!instant) return;\n    let raf = requestAnimationFrame(() => (raf = requestAnimationFrame(() => setInstant(false))));\n    return () => cancelAnimationFrame(raf);\n  }, [instant]);\n\n  const onEnd = (e: TransitionEvent) => {\n    if (e.target !== e.currentTarget || e.propertyName !== \"transform\" || step < n) return;\n    setInstant(true);\n    setStep(0);\n  };\n\n  // pad lines before, the list, then pad + 1 wrapped lines so the loop point looks identical.\n  const track = Array.from({ length: n + pad * 2 + 1 }, (_, k) => items[(((k - pad) % n) + n) % n]);\n  const ease = \"cubic-bezier(.76,0,.24,1)\";\n  const transition = instant ? \"none\" : `${duration}ms ${ease}`;\n  const edge = (pad / Math.max(1, visibleLines)) * 90;\n  const fade = `linear-gradient(transparent, #000 ${edge}%, #000 ${100 - edge}%, transparent)`;\n\n  return (\n    <span\n      className={cn(\"relative inline-block overflow-hidden align-middle\", className)}\n      style={{ height: `${Math.max(1, visibleLines) * LINE}em`, maskImage: pad ? fade : undefined, WebkitMaskImage: pad ? fade : undefined }}\n    >\n      <span className=\"sr-only\">{items.join(\", \")}</span>\n      {n > 0 && (\n        <span\n          aria-hidden\n          onTransitionEnd={onEnd}\n          style={{\n            display: \"flex\",\n            flexDirection: \"column\",\n            textAlign: align,\n            transform: `translateY(${-i * LINE}em)`,\n            transition: instant ? \"none\" : `transform ${transition}`,\n          }}\n        >\n          {track.map((t, k) => {\n            const d = Math.abs(k - i - pad);\n            return (\n              <span\n                key={k}\n                style={{\n                  height: `${LINE}em`,\n                  lineHeight: `${LINE}em`,\n                  whiteSpace: \"nowrap\",\n                  opacity: dimInactive ? [1, 0.3, 0.12][Math.min(d, 2)] : 1,\n                  filter: dimInactive && d ? `blur(${Math.min(d, 2) * 1.5}px)` : \"none\",\n                  transition: instant ? \"none\" : `opacity ${transition}, filter ${transition}`,\n                }}\n              >\n                {t}\n              </span>\n            );\n          })}\n        </span>\n      )}\n    </span>\n  );\n}\n"}]}