{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "curved-text-marquee",
  "title": "Curved Text Marquee",
  "description": "A marquee on a bendy line: text runs along a curve that sags at rest, and the pointer pulls the whole band up or down.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/curved-text-marquee/curved-text-marquee.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CurvedTextMarqueeProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  text?: string;\n  /** Pixels per second. */\n  speed?: number;\n  /** How far the band sags at rest, in px. Negative arches it upward. */\n  bend?: number;\n  /** Size of the text, in px. */\n  size?: number;\n  /** Height of the band, in px. */\n  height?: number;\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function CurvedTextMarquee({\n  text = \"Bend the line\",\n  speed = 90,\n  bend = 70,\n  size = 56,\n  height = 300,\n  className,\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: CurvedTextMarqueeProps) {\n  const reduce = useReducedMotion();\n  const id = `curved-${React.useId().replace(/[^a-zA-Z0-9]/g, \"\")}`;\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const flowRef = React.useRef<SVGTextPathElement>(null);\n  const rulerRef = React.useRef<SVGTextElement>(null);\n  const sag = React.useRef(bend);\n  const [width, setWidth] = React.useState(800);\n  const [copies, setCopies] = React.useState(6);\n  const line = `${text} — `;\n  const mid = height / 2;\n  const curve = (depth: number) =>\n    `M-60 ${mid - depth / 2}Q${width / 2} ${mid + depth * 1.5} ${width + 60} ${mid - depth / 2}`;\n\n  React.useEffect(() => {\n    const box = boxRef.current;\n    if (!box) return;\n    const ro = new ResizeObserver(([entry]) =>\n      setWidth(Math.max(240, Math.round(entry.contentRect.width))),\n    );\n    ro.observe(box);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    sag.current = bend;\n  }, [bend]);\n\n  // The text slides by one copy and wraps, and the curve eases toward wherever the pointer has pulled it.\n  React.useEffect(() => {\n    const box = boxRef.current;\n    const path = pathRef.current;\n    const flow = flowRef.current;\n    const ruler = rulerRef.current;\n    if (!box || !path || !flow || !ruler) return;\n    const copy = Math.max(1, ruler.getComputedTextLength());\n    const count = requestAnimationFrame(() =>\n      setCopies(Math.ceil((width + 240) / copy) + 2),\n    );\n    if (reduce) return () => cancelAnimationFrame(count);\n    let raf = 0;\n    let prev = 0;\n    let offset = 0;\n    let depth = bend;\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, prev ? (now - prev) / 1000 : 1 / 60);\n      prev = now;\n      offset = (offset + speed * dt) % copy;\n      depth += (sag.current - depth) * (1 - Math.exp(-dt * 6));\n      path.setAttribute(\"d\", curve(depth));\n      flow.setAttribute(\"startOffset\", (-offset).toFixed(2));\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      prev = 0;\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(box);\n    return () => {\n      cancelAnimationFrame(count);\n      cancelAnimationFrame(raf);\n      io.disconnect();\n    };\n    // curve() only depends on the sizes listed here.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [line, size, speed, width, height, reduce]);\n\n  return (\n    <div\n      ref={boxRef}\n      className={`w-full overflow-hidden ${className ?? \"\"}`}\n      style={style}\n      role=\"text\"\n      aria-label={text}\n      onPointerMove={(e) => {\n        onPointerMove?.(e);\n        if (e.pointerType !== \"mouse\") return;\n        const r = e.currentTarget.getBoundingClientRect();\n        sag.current = ((e.clientY - r.top) / r.height - 0.5) * height * 0.8;\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        sag.current = bend;\n      }}\n      {...props}\n    >\n      <svg\n        viewBox={`0 0 ${width} ${height}`}\n        className=\"block w-full\"\n        style={{ height }}\n        aria-hidden=\"true\"\n      >\n        <defs>\n          <path ref={pathRef} id={id} d={curve(bend)} />\n        </defs>\n        <text\n          ref={rulerRef}\n          fontSize={size}\n          opacity=\"0\"\n          style={{ fontWeight: \"inherit\", letterSpacing: \"inherit\" }}\n        >\n          {line}\n        </text>\n        <text\n          fontSize={size}\n          fill=\"currentColor\"\n          style={{ fontWeight: \"inherit\", letterSpacing: \"inherit\" }}\n        >\n          <textPath ref={flowRef} href={`#${id}`} startOffset=\"0\">\n            {line.repeat(copies)}\n          </textPath>\n        </text>\n      </svg>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}