Skip to main content

Path Text

Characters flow along built-in SVG curves or custom paths extracted with svgToPaths, morphing smoothly with spring physics whenever the path changes.

KINETIC UI * TYPOGRAPHY ON A CURVE *

Customize

Spacing (px)14

Installation

npx shadcn@latest add @kinetic/path-text

Usage

Pass a string to text and pick a built-in curve with preset ("arc", "wave", "circle", or "infinity"). Each grapheme is positioned by arc length and rotated to the local curve tangent inside an accessible SVG wrapper.

import { PathText } from "@/components/kinetic/ui/path-text";

interface CurvedLabelProps {
  readonly label: string;
}

export function CurvedLabel({ label }: CurvedLabelProps) {
  return (
    <PathText
      text={label}
      preset="wave"
      showPath={true}
      className="max-w-md"
    />
  );
}

Built-in presets, custom paths, and spring morphing

Pass a custom SVG path d attribute string or raw <svg>...</svg> markup to path; raw SVG markup is parsed automatically through svgToPaths to extract its first path. Adjust viewBox (default "0 0 420 180"), letterSpacing (default 14, clamped 4 to 80), and fontSize (default 20, clamped 8 to 96) to match custom coordinates.

Every path is resampled into a uniform 96-point polyline through icon-morph-engine. Whenever preset or path changes, all sampled points spring smoothly from the previous shape to the new shape using stiffness (default 180, clamped 40 to 1000) and damping (default 22, clamped 4 to 100), morphing both the guide curve and every glyph's tangent pose together.

Control continuous travel with animate (default true), paused (default false), direction (1 or -1), speed (default 1), and showPath (default true). Closed curves wrap seamlessly; open curves fade glyphs cleanly near both ends.

"use client";

import { useState } from "react";
import { PathText, type PathTextPreset } from "@/components/kinetic/ui/path-text";

const PRESETS: readonly PathTextPreset[] = ["wave", "arc", "circle", "infinity"];

interface MorphingPathProps {
  readonly label: string;
}

export function MorphingPath({ label }: MorphingPathProps) {
  const [index, setIndex] = useState(0);
  const preset = PRESETS[index] ?? "wave";

  return (
    <div className="flex flex-col items-start gap-4">
      <PathText
        text={label}
        preset={preset}
        animate={true}
        direction={1}
        showPath={true}
        letterSpacing={14}
        fontSize={20}
        className="max-w-lg"
      />
      <button
        type="button"
        onClick={() => setIndex((prev) => (prev + 1) % PRESETS.length)}
      >
        Next shape
      </button>
    </div>
  );
}

You can also pass raw SVG markup or a custom d string directly:

import { PathText } from "@/components/kinetic/ui/path-text";

interface CustomCurveProps {
  readonly label: string;
}

export function CustomCurve({ label }: CustomCurveProps) {
  return (
    <PathText
      text={label}
      path='<svg viewBox="0 0 420 180"><path d="M 30 130 C 140 20, 280 20, 390 130" /></svg>'
      viewBox="0 0 420 180"
      showPath={false}
      animate={false}
    />
  );
}

Imperative control

Attach a PathTextHandle ref and call replay() to reset flow offset, flatten the curve to a horizontal baseline, and spring both the path and glyphs back into the target shape.

"use client";

import { useRef } from "react";
import { PathText, type PathTextHandle } from "@/components/kinetic/ui/path-text";

export function ControlledPathText() {
  const pathRef = useRef<PathTextHandle>(null);

  return (
    <div className="flex flex-col items-start gap-3">
      <PathText
        ref={pathRef}
        text="SPRING MORPH ALONG SVG CURVES"
        preset="infinity"
        paused={false}
        className="max-w-lg"
      />
      <button type="button" onClick={() => pathRef.current?.replay()}>
        Replay morph
      </button>
    </div>
  );
}

Accessibility and reduced motion

PathText places the complete string (or custom aria-label) inside a single .sr-only span and marks the <svg> container aria-hidden="true", so screen readers announce one coherent phrase rather than fragmented SVG glyph elements.

The requestAnimationFrame loop pauses automatically whenever the component leaves the viewport (IntersectionObserver) or the tab becomes hidden (visibilitychange), and scales both flow speed and spring morphing with the global Kinetic tempo. Under reduced motion, PathText disables continuous flow and path morphing, snapping immediately to the static target curve.

API Reference

PathText

Resampled SVG path typography with spring-interpolated curve morphing and tangent glyph orientation.

PropTypeDefaultDescription
textstring-Grapheme-safe text placed along the curve.
preset"arc" | "wave" | "circle" | "infinity""wave"Built-in curve shape used when custom path is omitted.
pathstring-Custom SVG path d string or raw <svg> markup parsed via svgToPaths.
animatebooleantrueContinuously glides characters along the curve.
direction1 | -11Flow travel direction along the path.
showPathbooleantrueDisplays the underlying SVG stroke guide.
letterSpacingnumber14Arc-length distance between glyphs in SVG units.
fontSizenumber20Glyph font size in SVG user units.
pausedbooleanfalsePauses continuous flow animation.