Thread Text

embroidered text rendering


npm ↗
GitHub ↗
TypeScriptZero dependenciesReact + Vanilla JS

Turn a short word in a loaded font into embroidery on a transparent canvas. Satin threads run across the strokes, with shading that suggests raised floss. Choose a stitch texture, adjust the thread colours, then replay the sew-in.

Live demo — type a word

Size80%
Weight680
Sew rate140/s
Sew style
Stitch
Colour
Sheen
Backstitch

Type a short word on the artwork or in the Word field. Colour, font and size redraw the result; Stitch and Sew style changes also replay it. Hit Replay sew-in to watch the selected stitch texture appear.

How it works

Glyphs drive the flow

The word is rasterised, then an exact distance transform gives a flow field — smoothed in double-angle orientation space so opposite edge-normals reinforce. Threads run across each stroke and follow the curves; the result depends on the font, size and stitch spacing.

Shading gives the thread depth

Thousands of pre-shaded thread sprites are laid along the flow and shaded with a dome-shade normal map, so each strand catches the light along its length. The floss sits on a transparent ground — drop it over any background — and a cursor-following sheen adds a moving highlight.

Sewn in, one row at a time

A breadth-first pass over the stitch graph reveals the word one satin cross-row at a time — the needle following each stroke, letters filling left to right. The sew-in plays on load and whenever you hit Replay; typing redraws the word without a sew-in. Changing stitch mode or sew style also replays the animation in this demo.

Accessibility & motion

The canvases are hidden from assistive tech. The renderer keeps a visually hidden text copy for display mode; in this editable demo, a real text input carries the word. The host keeps its own role. prefers-reduced-motion: reduce is honoured — the sew-in is skipped and the word is drawn instantly.

Usage

Drop-in component

import { ThreadText } from '@overpunch/threadtext'

<ThreadText text="Thread" font='"Your Font", serif' weight={680} />

Hook

import { useThreadText } from '@overpunch/threadtext'

const ref = useThreadText({ text: 'Thread', font: '"Your Font", serif', weight: 680 })
<div ref={ref} />

Vanilla JS

import { createThreadText } from '@overpunch/threadtext'

// Load the face first (any @font-face / next/font / CSS Font Loading API), then:
const thread = createThreadText(document.getElementById('host'), {
  text: 'Thread', font: '"Your Font", serif', weight: 680,
})

thread.setText('Threads') // re-fit and redraw without a sew-in
thread.replay()           // re-run the full sew-in
thread.destroy()          // cancel rAF, remove listeners, free canvases

Options

ThreadText options reference
OptionDefaultDescription
text—The word (or short phrase) to embroider. Required.
font'Georgia, serif'CSS font-family of an already-loaded font. The glyph geometry drives the stitch flow — load it however you like before calling.
weight680Numeric font weight (100–900). Drives the wght axis via the standard font shorthand.
axes—Variable-font axes, e.g. { opsz: 40, SOFT: 60 }. Applied only where the 2D context exposes fontVariationSettings; ignored where unsupported. Use for opsz and custom axes.
threadColor'#fffbf3'Floss colour — the lit crest of each thread. Hex or rgb(). Changes live, no re-stitch.
fill0.9Fraction of the container width the word spans — its size. The word re-fits to width (with the remainder as padding) on load and resize.
pitchautoThread spacing in px. Smaller = finer, denser stitching (and more work). Derived from the fitted height if unset.
sewStyle'machine''machine' — satin cross-rows fill each stroke in parallel. 'hand' — one letter at a time (left to right), entering at the widest part near the top and working down, thin edges last, like hand embroidery.
stitchMode'satin'The stitch texture: 'satin' (smooth parallel floss), 'cross' (little X's), 'chain' (looped links), or 'running' (short dashes).
sewRate110Cross-rows (machine) or stitches (hand) laid per second during the sew-in.
sheentrueCursor-following radial sheen on the overlay canvas.
animatetruePlay the sew-in on mount and on replay(). When false (or reduced-motion), the word is drawn instantly.
editablefalseMake the surface typeable — adds a real (transparent) input over the artwork, so clicking focuses it, the soft keyboard opens on touch, and typing/paste/IME all work. Enter replays. Shows a caret; pair with onTextChange.
onTextChange—Callback fired with the new text whenever the user edits it in editable mode.
reducedMotionautoForce reduced-motion. Auto-detected from prefers-reduced-motion if omitted.

no-code

Use it in Webflow & Framer

The same effect, no build step — drop it straight into your design tool.

Webflow

One script tag, then mark any element with data-threadtext. Configure it with data-* attributes.

<!-- Site Settings → Custom Code → Footer, or an Embed element -->
<script src="https://cdn.jsdelivr.net/npm/@overpunch/threadtext/dist/threadtext.webflow.min.js"></script>

<!-- Then add data-threadtext to any text element -->
<h1 data-threadtext>Your headline</h1>

Framer

Insert → Code → New Component, then paste ThreadText.tsx ↗. It imports the core from esm.sh and exposes every option in the property panel — no build step.

import { /* core */ } from "https://esm.sh/@overpunch/threadtext"