scrollfx
“We stopped animating our pages. Now the pen does it, and only when someone is reading.”

Ada Marlow · Founder, Okkara

  1. 1name · Hershey script
  2. 2flourish

Schedule of props

MarkPropTypeDefaultDescription
P1namestring'Ada Marlow'The name to write. Letters outside ASCII lose their accents; others are left out.
P2sizenumber56The size of the writing: px to the em.
P3slantnumber0.2How far the writing leans: x moved right per unit up.
P4flourishbooleantrueUnderline the name with a flourish in the accent pen.
P5pathsstring[]—Your own signature instead: SVG path data, one string per stroke, in the order they were written, inside `viewBox`. Each stroke takes one beat.
P6viewBoxstring—The box `paths` are drawn in, as an SVG viewBox ("0 0 w h").
P7colorstring'currentColor'The ink's colour.
P8accentstring'#e0482a'The flourish's colour.
P9strokeWidthnumber1.7—
P10seednumber1Shapes the flourish.
P11triggerInkTrigger'scroll'`scroll`: written as it rises, done at mid-screen. `view`: written once as it comes into view.
P12durationnumber2600With `view`, how long the writing takes, in ms.
P13classNamestring''—

Notes

  1. 1.
    A name written stroke by stroke at one steady speed in Hershey's single-stroke script, underlined with a flourish; or your own signature as SVG paths.
  2. 2.
    The words and content it marks stay in the server HTML. The marks are measured to them in the browser, and made again when the layout changes.
  3. 3.
    Tied to the scroll by default: the last stroke lands as the drawing reaches the middle of the screen. With trigger="view" it plays once as it comes into view instead. Reduced motion shows it drawn.
  1. 4.
    Detail A, Name. A name in Hershey’s script, written in order at one steady speed, then underlined with a flourish.
  2. 5.
    Usage, as drawn:
    import { InkSignature } from '@/components/scrollfx/ink-signature';
    
    export function NameExample() {
      return (
        <figure className="max-w-md">
          <blockquote className="font-serif text-2xl leading-snug tracking-[-0.015em]">“We stopped animating our pages. Now the pen does it, and only when someone is reading.”</blockquote>
          <figcaption className="mt-6">
            <InkSignature name="Ada Marlow" />
            <p className="mt-2 font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground">Ada Marlow · Founder, Okkara</p>
          </figcaption>
        </figure>
      );
    }
    
View source · components/scrollfx/ink-signature.tsx
'use client';

/**
 * ink-signature — a name written out by a pen, stroke by stroke, in writing
 * order and at one steady speed, then underlined with a flourish in the
 * accent pen. The name is set in Hershey's script, a single-stroke
 * handwriting font, so every line is drawn once, as a hand draws it. Or pass
 * your own signature as SVG paths.
 *
 * Built on svg-scroll-draw (MIT): https://github.com/DhruvilChauahan0210/scrollfx
 * Needs: react, svg-scroll-draw, lib/plotter and lib/ink (installed with it).
 * Styling: Tailwind CSS. The ink is `currentColor` unless you pass `color`.
 *
 * The name is in the server HTML (as the drawing's accessible name) and the
 * drawing's box is laid out there too, so nothing moves when it is drawn; the
 * strokes are made in the browser. Reduced motion shows the name written.
 */

import { useEffect, useMemo, useRef, useState } from 'react';
import 'svg-scroll-draw/no-flash.css';
import { paced, random, type Line, type Point, type Stroke } from '@/lib/plotter';
import { script, useInk, type InkTrigger } from '@/lib/ink';

export interface InkSignatureProps {
  /** The name to write. Letters outside ASCII lose their accents; others are left out. */
  name?: string;
  /** The size of the writing: px to the em. */
  size?: number;
  /** How far the writing leans: x moved right per unit up. */
  slant?: number;
  /** Underline the name with a flourish in the accent pen. */
  flourish?: boolean;
  /**
   * Your own signature instead: SVG path data, one string per stroke, in the
   * order they were written, inside `viewBox`. Each stroke takes one beat.
   */
  paths?: string[];
  /** The box `paths` are drawn in, as an SVG viewBox ("0 0 w h"). */
  viewBox?: string;
  /** The ink's colour. */
  color?: string;
  /** The flourish's colour. */
  accent?: string;
  strokeWidth?: number;
  /** Shapes the flourish. */
  seed?: number;
  /** `scroll`: written as it rises, done at mid-screen. `view`: written once as it comes into view. */
  trigger?: InkTrigger;
  /** With `view`, how long the writing takes, in ms. */
  duration?: number;
  className?: string;
}

/** A swash under the writing: in from below the first letters, a long shallow curve, and a lift at the end. */
function swash(w: number, baseline: number, size: number, seed: number): Point[] {
  const rand = random(seed);
  const x0 = w * (0.04 + rand() * 0.06), x1 = w * (0.97 + rand() * 0.02);
  const y = baseline + size * 0.16;
  const sag = size * (0.07 + rand() * 0.05);
  const pts: Point[] = [];
  const n = Math.max(30, Math.round((x1 - x0) / 3));
  for (let i = 0; i <= n; i++) {
    const t = i / n;
    // Down into the stroke, a long sag, then up and away at the end.
    pts.push([x0 + (x1 - x0) * t, y + sag * Math.sin(Math.PI * t * 0.92) - size * 0.12 * t ** 6 + (1 - t) ** 8 * -size * 0.06]);
  }
  return pts;
}

export function InkSignature({
  name = 'Ada Marlow',
  size = 56,
  slant = 0.2,
  flourish = true,
  paths,
  viewBox,
  color = 'currentColor',
  accent = '#e0482a',
  strokeWidth = 1.7,
  seed = 1,
  trigger = 'scroll',
  duration = 2600,
  className = '',
}: InkSignatureProps) {
  const ref = useRef<SVGSVGElement>(null);
  // Laid out on the server as well, so the box is the right size from the first paint.
  const laid = useMemo(() => script(name, { size, slant, pad: Math.ceil(strokeWidth * 2) }), [name, size, slant, strokeWidth]);
  const extra = flourish && !paths ? Math.round(size * 0.32) : 0;
  const box = paths ? viewBox ?? '0 0 300 120' : `0 0 ${laid.w} ${laid.h + extra}`;
  const [, , bw, bh] = box.split(/[\s,]+/).map(Number);

  const [strokes, setStrokes] = useState<Stroke[] | null>(null);
  useEffect(() => {
    if (paths) return setStrokes(paths.map((d) => ({ d, pen: 0 })));
    // Even pieces, one after another: the pen writes at one speed.
    const lines: Line[] = laid.lines.map((pts) => ({ pts, pen: 0 }));
    if (flourish) lines.push({ pts: swash(laid.w, laid.baseline, size, seed), pen: 1 });
    setStrokes(paced(lines, Math.max(4, size / 9)));
  }, [paths, laid, flourish, size, seed]);

  const n = strokes?.length ?? 0;
  useInk(ref, { paths: n, spread: Math.max(0, n - 1), trigger, duration, version: strokes });

  return (
    <span role="img" aria-label={paths ? `Signature: ${name}` : name} className={`inline-block align-middle ${className}`}>
      <svg
        ref={ref}
        key={strokes ? 'drawn' : 'empty'}
        data-scroll-draw-pending=""
        data-ink={trigger}
        aria-hidden
        width={bw}
        height={bh}
        viewBox={box}
        className="block h-auto max-w-full overflow-visible"
        fill="none"
        stroke={color}
        strokeWidth={strokeWidth}
        strokeLinecap="round"
        strokeLinejoin="round"
      >
        {strokes?.map((s, i) => <path key={i} d={s.d} stroke={s.pen ? accent : undefined} />)}
      </svg>
    </span>
  );
}

Parts list

ItemPart, as installed
1components/scrollfx/ink-signature.tsxThe component
2lib/ink.tsThe pen hook the ink pieces share, and Hershey’s script
3lib/plotter.tsStroke geometry: hatching, sketched lines, scroll windows
4svg-scroll-draw ^2.29.0Dependency, from npm
ViewName
Pens1ink2vermilion
Installnpx shadcn@latest add
https://scrollfx-ui.vercel.app/r/ink-signature.json
Title

Ink signature

scrollfx · Ink
Dwg no.
ink-signature
Sheet
13/14
Scale
1:1
Rev
2.29.0
Drawn by
svg-scroll-draw
Licence
MIT