“We stopped animating our pages. Now the pen does it, and only when someone is reading.”
Ada Marlow · Founder, Okkara
- 1name · Hershey script
- 2flourish
Schedule of props
| Mark | Prop | Type | Default | Description |
|---|---|---|---|---|
| P1 | name | string | 'Ada Marlow' | The name to write. Letters outside ASCII lose their accents; others are left out. |
| P2 | size | number | 56 | The size of the writing: px to the em. |
| P3 | slant | number | 0.2 | How far the writing leans: x moved right per unit up. |
| P4 | flourish | boolean | true | Underline the name with a flourish in the accent pen. |
| P5 | paths | string[] | — | Your own signature instead: SVG path data, one string per stroke, in the order they were written, inside `viewBox`. Each stroke takes one beat. |
| P6 | viewBox | string | — | The box `paths` are drawn in, as an SVG viewBox ("0 0 w h"). |
| P7 | color | string | 'currentColor' | The ink's colour. |
| P8 | accent | string | '#e0482a' | The flourish's colour. |
| P9 | strokeWidth | number | 1.7 | — |
| P10 | seed | number | 1 | Shapes the flourish. |
| P11 | trigger | InkTrigger | 'scroll' | `scroll`: written as it rises, done at mid-screen. `view`: written once as it comes into view. |
| P12 | duration | number | 2600 | With `view`, how long the writing takes, in ms. |
| P13 | className | string | '' | — |
Notes
- 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.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.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.
- 4.Detail A, Name. A name in Hershey’s script, written in order at one steady speed, then underlined with a flourish.
- 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> ); }
- 4.Detail B, Written on arrival. With trigger="view" the name is written once, over
durationms, as it comes into view, rather than with the scroll. - 5.Usage, as drawn:
import { InkSignature } from '@/components/scrollfx/ink-signature'; export function WrittenOnArrivalExample() { return ( <InkSignature name="With thanks, Tom" size={48} trigger="view" duration={2400} seed={3} /> ); }
- 4.Detail C, Your own signature. Pass SVG path data, one string per stroke in writing order, and the viewBox they sit in.
- 5.Usage, as drawn:
import { InkSignature } from '@/components/scrollfx/ink-signature'; export function YourOwnSignatureExample() { return ( <InkSignature name="J. Okafor" viewBox="0 0 300 120" paths={[ 'M58 20C66 34 70 58 64 78C58 98 34 100 28 86C24 76 40 70 56 74', 'M80 84L81 85', 'M118 46C100 44 92 68 104 80C116 92 136 78 134 60C132 46 120 42 110 50', 'M146 36C149 56 149 72 146 88', 'M147 72C155 62 163 60 161 69C159 77 151 77 155 81C161 87 169 79 173 71C175 65 181 63 181 71C181 79 189 81 193 71C197 60 195 48 192 40', 'M187 64L201 62', 'M200 80C204 70 212 68 216 74C218 80 210 84 208 78C214 82 222 72 228 68C232 66 236 68 238 72', 'M30 102C110 94 200 92 272 72', ]} /> ); }
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
| Item | Part, as installed |
|---|---|
| 1 | components/scrollfx/ink-signature.tsxThe component |
| 2 | lib/ink.tsThe pen hook the ink pieces share, and Hershey’s script |
| 3 | lib/plotter.tsStroke geometry: hatching, sketched lines, scroll windows |
| 4 | svg-scroll-draw ^2.29.0Dependency, from npm |
ViewName
Pens1ink2vermilion
Install
npx shadcn@latest add
https://scrollfx-ui.vercel.app/r/ink-signature.jsonTitle
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