{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-path-flow",
  "type": "registry:component",
  "title": "Text Path Flow",
  "description": "A line of text streams along a wave that slowly breathes and shifts, with a dotted guide underneath and soft fades at both ends. Drawn in SVG, so it scales cleanly to any width.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "svg",
    "path",
    "wave",
    "marquee",
    "ribbon",
    "flow"
  ],
  "docs": "https://hyperblur.dev/effects/text-path-flow",
  "files": [
    {
      "path": "registry/hyperblur/text-path-flow.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-path-flow.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextPathFlowProps extends React.HTMLAttributes<HTMLDivElement> {\n  text: string;\n  separator?: string;\n  speed?: number;\n  amplitude?: number;\n  waves?: number;\n  fontSize?: number;\n  width?: number;\n  height?: number;\n  accent?: string;\n  guide?: boolean;\n  reverse?: boolean;\n}\n\nconst css = `\n.hb-vi8 { display: block; width: 100%; font-family: inherit; box-sizing: border-box; }\n.hb-vi8-svg { display: block; width: 100%; height: auto; overflow: visible; }\n.hb-vi8-text { font-family: inherit; letter-spacing: 0.01em; }\n.hb-vi8-guide {\n  fill: none;\n  stroke: var(--hb-vi8-accent);\n  stroke-opacity: 0.32;\n  stroke-width: 1;\n  stroke-dasharray: 2 7;\n  stroke-linecap: round;\n}\n`;\n\nfunction wavePath(w: number, h: number, amp: number, waves: number, phase: number) {\n  const steps = 64;\n  const mid = h / 2;\n  let d = \"\";\n  for (let i = 0; i <= steps; i++) {\n    const t = i / steps;\n    const x = -w * 0.05 + t * w * 1.1;\n    const env = Math.sin(Math.PI * Math.min(1, Math.max(0, t))) * 0.35 + 0.65;\n    const y = mid + Math.sin(t * Math.PI * 2 * waves + phase) * amp * env;\n    d += `${i === 0 ? \"M\" : \"L\"}${x.toFixed(1)} ${y.toFixed(1)} `;\n  }\n  return d.trim();\n}\n\nexport function TextPathFlow({\n  text,\n  separator = \"  •  \",\n  speed = 60,\n  amplitude = 28,\n  waves = 1.5,\n  fontSize = 34,\n  width = 600,\n  height = 160,\n  accent = \"#7fb3ff\",\n  guide = true,\n  reverse = false,\n  className = \"\",\n  style,\n  ...rest\n}: TextPathFlowProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const pathId = `hb-vi8-p${uid}`;\n  const gradId = `hb-vi8-g${uid}`;\n  const maskId = `hb-vi8-m${uid}`;\n  const fadeId = `hb-vi8-f${uid}`;\n  const svgRef = React.useRef<SVGSVGElement>(null);\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const guideRef = React.useRef<SVGPathElement>(null);\n  const tpRef = React.useRef<SVGTextPathElement>(null);\n  const unitRef = React.useRef<SVGTextElement>(null);\n  const [repeat, setRepeat] = React.useState(4);\n  const unit = `${text}${separator}`;\n  const initial = React.useMemo(() => wavePath(width, height, amplitude, waves, 0), [width, height, amplitude, waves]);\n\n  React.useEffect(() => {\n    const path = pathRef.current;\n    const tp = tpRef.current;\n    const probe = unitRef.current;\n    const svg = svgRef.current;\n    if (!path || !tp || !probe || !svg) return;\n    let unitLen = 1;\n    const measure = () => {\n      unitLen = Math.max(1, probe.getComputedTextLength());\n      const need = Math.ceil(path.getTotalLength() / unitLen) + 2;\n      setRepeat((r) => (r === need ? r : need));\n    };\n    measure();\n    if (document.fonts?.ready) document.fonts.ready.then(measure).catch(() => undefined);\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let raf = 0;\n    let visible = true;\n    let begin = 0;\n    const frame = (now: number) => {\n      if (!begin) begin = now;\n      const t = (now - begin) / 1000;\n      const amp = amplitude * (0.82 + Math.sin(t * 0.9) * 0.18);\n      const d = wavePath(width, height, amp, waves, t * 0.8 * (reverse ? -1 : 1));\n      path.setAttribute(\"d\", d);\n      guideRef.current?.setAttribute(\"d\", d);\n      const travel = (t * speed) % unitLen;\n      const off = reverse ? travel - unitLen : -travel;\n      tp.setAttribute(\"startOffset\", off.toFixed(1));\n      raf = visible ? requestAnimationFrame(frame) : 0;\n    };\n    const io =\n      typeof IntersectionObserver !== \"undefined\"\n        ? new IntersectionObserver((entries) => {\n            visible = entries.some((e) => e.isIntersecting);\n            if (visible && !raf) raf = requestAnimationFrame(frame);\n          })\n        : null;\n    io?.observe(svg);\n    raf = requestAnimationFrame(frame);\n    return () => {\n      cancelAnimationFrame(raf);\n      io?.disconnect();\n    };\n  }, [amplitude, waves, width, height, speed, reverse, unit]);\n\n  const vars = { \"--hb-vi8-accent\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-vi8 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-text-path-flow\" precedence=\"default\">{css}</style>\n      <svg\n        ref={svgRef}\n        className=\"hb-vi8-svg\"\n        viewBox={`0 0 ${width} ${height}`}\n        role=\"img\"\n        aria-label={text}\n      >\n        <title>{text}</title>\n        <defs>\n          <path id={pathId} ref={pathRef} d={initial} />\n          <linearGradient id={gradId} x1=\"0\" y1=\"0\" x2={width} y2=\"0\" gradientUnits=\"userSpaceOnUse\">\n            <stop offset=\"0\" stopColor={accent} />\n            <stop offset=\"0.5\" stopColor=\"#f4f6fb\" />\n            <stop offset=\"1\" stopColor={accent} />\n          </linearGradient>\n          <linearGradient id={fadeId} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n            <stop offset=\"0\" stopColor=\"#fff\" stopOpacity=\"0\" />\n            <stop offset=\"0.12\" stopColor=\"#fff\" stopOpacity=\"1\" />\n            <stop offset=\"0.88\" stopColor=\"#fff\" stopOpacity=\"1\" />\n            <stop offset=\"1\" stopColor=\"#fff\" stopOpacity=\"0\" />\n          </linearGradient>\n          <mask id={maskId} maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width={width} height={height}>\n            <rect x=\"0\" y=\"0\" width={width} height={height} fill={`url(#${fadeId})`} />\n          </mask>\n        </defs>\n        <text ref={unitRef} className=\"hb-vi8-text\" fontSize={fontSize} opacity=\"0\" aria-hidden=\"true\" style={{ whiteSpace: \"pre\" }}>\n          {unit}\n        </text>\n        <g mask={`url(#${maskId})`} aria-hidden=\"true\">\n          {guide ? <path ref={guideRef} className=\"hb-vi8-guide\" d={initial} transform={`translate(0 ${(fontSize * 0.42).toFixed(1)})`} /> : null}\n          <text className=\"hb-vi8-text\" fontSize={fontSize} fill={`url(#${gradId})`} fontWeight={600} style={{ whiteSpace: \"pre\" }}>\n            <textPath ref={tpRef} href={`#${pathId}`} startOffset=\"0\">\n              {Array.from({ length: repeat }, () => unit).join(\"\")}\n            </textPath>\n          </text>\n        </g>\n      </svg>\n    </div>\n  );\n}\n"
    }
  ]
}