Skip to content
Lalit Puri
← All work

Kinetic Type Lab

A foundry lab bench for typography in motion.

Year
2026
Role
Design & engineering
Status
Live

Stack

  • React
  • TypeScript
  • GSAP
  • Matter.js
  • Zustand
  • Radix UI
  • Tailwind CSS
  • Vite
  • Vitest
01

The brief

A single-screen typography animation playground: type text, pick from 12 animation presets, tune parameters, and export GIF, WebM (or MP4 via WebCodecs), CSS + HTML, GSAP JS, React TSX or PNG. Everything is shareable through a URL hash that encodes the entire state.

02

The problem

One screen where you type, choose a motion, tune it, and leave with something usable: a GIF, a video, or production code. And a link that reproduces the exact setup for whoever opens it next.

03

The approach

Built as a "foundry lab bench" dark studio tool: monospace labels, hairline rules, a restrained palette, and all the personality on stage. Zustand holds the lab state, each of the 12 presets builds a GSAP timeline from the split text, and the whole state serialises into the URL hash, so sharing is copying a link.

04

The interesting part

01

A splitter that never tears a glyph

Splitting text with Array.from or split('') breaks anything built from more than one code point: family emoji joined with zero-width joiners, flags made of two regional indicators, accented letters typed as base + combining mark. Animate those per character and half a flag flies off on its own.

The splitter segments by grapheme cluster with Intl.Segmenter, falling back to Array.from where it's missing. Lines are detected after layout by grouping words on offsetTop with a ±2px tolerance. Every span is aria-hidden while the container keeps an aria-label with the original string, so screen readers read a sentence, not a list of letters. A ResizeObserver re-splits on resize, and teardown kills the GSAP tweens and restores plain text.

Splitting by code point versus by grapheme clusterinput👨‍👩‍👧 🇳🇵Array.from(text) → 7 units, two of them invisible joiners👨ZWJ👩ZWJ👧🇳🇵Intl.Segmenter granularity:'grapheme' → 2 units👨‍👩‍👧🇳🇵
Array.from splits a family emoji into five pieces and a flag into two letters. Intl.Segmenter keeps each as one character, so nothing tears apart mid-animation.
From src/lib/split.ts
function splitGraphemes(text: string): string[] {
  if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
    try {
      const IntlAny = Intl as any
      const segmenter = new IntlAny.Segmenter(undefined, { granularity: 'grapheme' })
      const segments = segmenter.segment(text)
      const result: string[] = []
      for (const seg of segments) {
        result.push(seg.segment)
      }
      return result
    } catch {
      return Array.from(text)
    }
  }
  return Array.from(text)
}

02

Exporting the DOM, frame by frame

GIF and video export rasterise the live stage: DOM → SVG foreignObject → canvas, once per frame. The catch is fonts. A webfont referenced by URL either doesn't render inside the SVG image or taints the canvas so it can't be read back.

Before each export the lab fetches the Google Fonts CSS for every family in use, downloads each WOFF2 file as binary, base64-encodes it, and rebuilds the @font-face rules as data: URLs inside the SVG's <defs><style>. Only the ~85 computed style properties that matter for typography, layout and transforms are inlined on each node rather than all 500-plus, which keeps the SVG small. Results are cached, so the second frame onward is fast enough for 30fps scrub captures on a 1080p stage.

The per-frame export pipelineStage DOMsplit spansSVGforeignObject<canvas>drawImageEncoderGIF · WebM · MP4Google Fonts CSS → WOFF2fetched once, cached@font-face src: data:font/woff2;base64~85 computed styles inlined per nodenext frame
Each frame: the stage DOM is serialised into an SVG foreignObject with its fonts inlined as base64, drawn onto a canvas, and handed to the encoder. Fonts are fetched once and cached.

03

A parameter panel that renders itself

Twelve presets with different knobs would normally mean twelve hand-built control panels. Instead, each preset exports a typed ParamSpec[]: a discriminated union of range, select, toggle, color, easing and string parameters.

The right-hand panel renders itself from that spec with no per-preset UI code. A ParamControl switches on spec.type: ranges get a Radix slider with a number field and double-click-to-reset, easings get a curve editor, colours get a swatch popover with hex input. Adding a preset is one new file and one line in the registry.

From a typed ParamSpec array to a rendered control panelpreset.params: ParamSpec[]type: 'range'speed 0.2–4type: 'select'axis: wghttype: 'color'fill #C6FF4Ftype: 'toggle'loop: onParamControlswitch (spec.type)wght ▾#C6FF4Fno per-preset UI code
A preset declares data, not UI. ParamControl switches on each spec's type and renders the matching control.
From src/presets/index.ts
export type RangeParam = {
  type: 'range';
  id: string;
  label: string;
  min: number;
  max: number;
  step: number;
  default: number;
  unit?: string;
};

// … SelectParam, ToggleParam, ColorParam, EasingParam, StringParam

export type ParamSpec =
  | RangeParam
  | SelectParam
  | ToggleParam
  | ColorParam
  | EasingParam
  | StringParam;

04

Variable-font axes at 60fps across 120 characters

Cursor weight mode drives a variable-font axis (weight, width, slant or optical size) from each character's distance to the pointer. Done naively, that's a listener per character and a style write per character per frame.

All pointer and touch listeners live on window. A gsap.quickSetter is created once per character and kept in a Map. Every frame's writes are batched into a single gsap.ticker callback, a churn guard skips any write that would change the value by less than 0.05, and with no pointer on stage the loop is a single early return: zero DOM writes and zero allocations per frame.

Cursor proximity driving a variable-font axisK200I200N506E799T458I200C200wght per glyph = min + falloff(dist / radius) × (max − min)one gsap.ticker callback · quickSetter per glyph · listeners on window|value − lastWrite| < 0.05 → skip the DOM writeno pointer on stage → early return, 0 writes
Inside the radius, each glyph's axis value follows a falloff curve from the pointer. Writes are batched into one ticker callback and skipped when the change is under 0.05.
From src/modes/cursorWeight.ts
function tickerLoop() {
  if (
    !currentContainer ||
    !currentOptions ||
    !currentGetSplitUnits ||
    pointerX === Infinity ||
    pointerY === Infinity
  ) {
    return;
  }
  // …
  for (let i = 0; i < limit; i++) {
    // …
    const rawValue =
      opts.minWeight + falloff * (opts.maxWeight - opts.minWeight);
    const value = Math.max(cache.axisMin, Math.min(cache.axisMax, rawValue));

    const lastWritten = lastWrittenValues.get(el);
    if (lastWritten !== undefined && Math.abs(value - lastWritten) < 0.05) {
      continue;
    }

    lastWrittenValues.set(el, value);
    const fvs = buildFvs(cache.baseParts, cache.axisTag, value);
    qs(fvs);
  }
}

05

Glyph physics that cleans up after itself

Physics mode hands every character to Matter.js: letters fall, collide, and can be thrown around with the mouse. Toggling it twenty times in a row must not leak.

Teardown runs in a fixed order: stop the runner, clear the engine, remove every body from the world, unbind every Matter event, disconnect the ResizeObserver and visibility handler, remove the mouse constraint, restore each span's transform, delete the body↔span cross-reference so both can be garbage-collected, then null every internal reference.

05

What I'd do next

Move GIF encoding into a Web Worker so long exports don't block the main thread, and shrink share URLs by compressing the state before it's base64-encoded into the hash.