{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-on-path",
  "title": "Text on Path",
  "description": "Words that flow along a wave, an arc or a circle, looping without a seam and scaling with their container.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/text-on-path/text-on-path.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type TextPathShape = \"wave\" | \"arc\" | \"circle\";\n\nexport interface TextOnPathProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  text?: string;\n  shape?: TextPathShape;\n  /** Seconds for one full trip. 0 holds the text still. */\n  seconds?: number;\n  /** Size of the text on an 800-wide canvas. */\n  size?: 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\nconst PATHS: Record<TextPathShape, { view: string; d: string }> = {\n  wave: {\n    view: \"0 0 800 240\",\n    d: \"M-40 150C60 40 160 40 260 130S460 240 560 130 760 40 860 130\",\n  },\n  arc: { view: \"0 0 800 300\", d: \"M20 270C170 30 630 30 780 270\" },\n  circle: {\n    view: \"0 0 400 400\",\n    d: \"M200 40a160 160 0 1 1-.01 0Z\",\n  },\n};\n\nexport function TextOnPath({\n  text = \"Set your words on any line you like\",\n  shape = \"wave\",\n  seconds = 8,\n  size = 42,\n  className,\n  style,\n  ...props\n}: TextOnPathProps) {\n  const reduce = useReducedMotion();\n  const id = `text-path-${React.useId().replace(/[^a-zA-Z0-9]/g, \"\")}`;\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const flowRef = React.useRef<SVGTextPathElement>(null);\n  const measureRef = React.useRef<SVGTextElement>(null);\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const line = `${text} · `;\n  const shapeInfo = PATHS[shape];\n\n  // Enough copies to cover the line twice, slid along by exactly one copy, so the loop has no seam.\n  const [copies, setCopies] = React.useState(4);\n  React.useEffect(() => {\n    const path = pathRef.current;\n    const ruler = measureRef.current;\n    const flow = flowRef.current;\n    const box = boxRef.current;\n    if (!path || !ruler || !flow || !box) return;\n    const width = Math.max(1, ruler.getComputedTextLength());\n    const length = path.getTotalLength();\n    const frame = requestAnimationFrame(() =>\n      setCopies(Math.ceil(length / width) + 2),\n    );\n    if (reduce || !seconds) {\n      flow.setAttribute(\"startOffset\", \"0\");\n      return () => cancelAnimationFrame(frame);\n    }\n    let raf = 0;\n    const cycle = seconds * 1000;\n    const tick = (now: number) => {\n      flow.setAttribute(\n        \"startOffset\",\n        `${(-((now % cycle) / cycle) * width).toFixed(2)}`,\n      );\n      raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(tick);\n    });\n    io.observe(box);\n    return () => {\n      cancelAnimationFrame(frame);\n      cancelAnimationFrame(raf);\n      io.disconnect();\n    };\n  }, [line, size, shape, seconds, reduce]);\n\n  return (\n    <div\n      ref={boxRef}\n      className={`w-full ${className ?? \"\"}`}\n      style={style}\n      role=\"img\"\n      aria-label={text}\n      {...props}\n    >\n      <svg\n        viewBox={shapeInfo.view}\n        className=\"block h-auto w-full overflow-visible\"\n        aria-hidden=\"true\"\n      >\n        <defs>\n          <path ref={pathRef} id={id} d={shapeInfo.d} />\n        </defs>\n        <text\n          ref={measureRef}\n          fontSize={size}\n          fill=\"none\"\n          opacity=\"0\"\n          style={{ fontWeight: \"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"
}