Home GitHub

Interactive demos exploring programmable text layout with @chenglou/pretext. prepare() once, layout() at any width — instantly.

by Sergio Florez (XergioAleX) · Read the deep dive

All 39 Demos

Beginner

📐 Basic Paragraph Measurement

Prepare once, measure at any width instantly — the core Pretext workflow.

prepare()layout()
Beginner

↔️ Resize Relayout Playground

Drag a width slider and watch dozens of text blocks relayout in real time.

prepare()layout()
Intermediate

📦 Tight Multiline Shrink-Wrap

Compute the tightest bounding box for wrapped text — no trial-and-error needed.

prepareWithSegments()layoutWithLines()
Conceptual

DOM vs Pretext Architecture

A side-by-side comparison of traditional DOM measurement vs Pretext's prepare/layout model.

prepare()layout()
Intermediate

🧱 Text-Aware Masonry Cards

Pack cards into a masonry grid by predicting text heights before rendering.

prepare()layout()
Intermediate

💬 Chat & Feed Bubbles

Size chat bubbles perfectly and handle width changes gracefully.

prepare()layout()layoutWithLines()
Intermediate

🎨 Canvas Text Layout

Compute line breaks with Pretext and render to <canvas> — beyond the DOM.

prepareWithSegments()layoutWithLines()
Advanced

🌍 Multilingual Stress Test

Test Pretext against CJK, Arabic, emoji, bidi, and edge-case scripts.

prepare()layout()setLocale()
Advanced

🌊 Flow Around Obstacle

Text flows dynamically around a draggable shape — line by line layout control.

prepareWithSegments()layoutNextLine()
Advanced

Rich Inline Segments

Layout text with mixed styles, code spans, and inline badges using segments.

prepareWithSegments()layoutWithLines()
Flagship

📰 Editorial Engine

Editorial layout with floating orbs that displace text in real time.

prepareWithSegments()layoutNextLine()layoutWithLines()
Spectacular Flagship

🐉 Dragon Chase

A chain of 40 glowing spheres chases your cursor — text reflows around every orb at 60fps.

prepareWithSegments()layoutNextLine()
Spectacular

🌊 Wave Distortion

A sine wave continuously warps line widths — mesmerizing flowing text animation.

prepareWithSegments()layoutNextLine()
Game

🎮 Text Breakout

Classic Breakout, but the bricks are words. Smash them and watch text reflow live.

prepareWithSegments()layoutWithLines()
Spectacular

🪨 Gravity Letters

Letters fall, bounce, and explode with physics — then reassemble into readable text.

prepareWithSegments()layoutWithLines()
Spectacular

🌀 Text Vortex

Characters spin in a colorful vortex, then smoothly reassemble into readable text.

prepareWithSegments()layoutWithLines()
Advanced

🖤 Text Silhouette Fill

Text fills arbitrary shapes — heart, star, circle — each line matching the silhouette boundary.

prepareWithSegments()layoutNextLine()
Advanced

📰 Multi-Column Magazine

Text flows across multiple columns with pull quotes — an InDesign-like editorial layout.

prepareWithSegments()layoutNextLine()
Spectacular

💧 Text Waterfall Cascade

Text cascades down shelves of decreasing width — a typographic waterfall.

prepareWithSegments()layoutNextLine()
Spectacular

Text Hourglass

A functional hourglass timer — text shaped as an hourglass with sand trickling through.

prepareWithSegments()layoutNextLine()
Spectacular

🎵 Audio-Reactive Typography

Music drives text width, line height, and font size in real time — text breathes with sound.

prepare()layout()
Advanced

🗺️ Text Terrain Map

Sweep width from min to max and plot text height as a topographic landscape.

prepare()layout()walkLineRanges()
Advanced

🌡️ Typographic Heatmap

Lines color-coded by character density — reveals rivers of whitespace in real time.

prepareWithSegments()layoutWithLines()
Spectacular

🔷 Voronoi Text Cells

Drag seed points and watch text reflow inside shifting Voronoi cells.

prepareWithSegments()layoutNextLine()
Spectacular

🌧️ Text Rain

Letters fall like rain, land on your cursor, and accumulate into readable phrases.

prepareWithSegments()layoutWithLines()
Spectacular

💥 Text Collision World

Text blocks as physics objects — drag, collide, stack, and watch them reflow on impact.

prepare()layout()
Spectacular

🌋 Text Earthquake

Click to crack a paragraph along a fault line — both halves reflow to their broken shapes.

prepareWithSegments()layoutNextLine()
Intermediate

Streaming Text Prediction

Simulates LLM streaming with real-time height prediction — smooth layout as tokens arrive.

prepare()layout()
Flagship Flagship

🧠 Living Document System

An autonomous editorial surface that reprioritizes cards and reflows text blocks in real time.

prepare()layout()layoutNextLine()
Spectacular

🫧 Text Fluid Field

A paragraph bends through a simulated velocity field instead of a fixed container shape.

prepareWithSegments()layoutNextLine()
Spectacular

📄 Text Origami Panels

Text flows across foldable paper panels whose geometry changes with each crease.

prepareWithSegments()layoutNextLine()
Flagship Flagship

🕳️ Text Black Hole

Words orbit, compress, and lens around a singularity with radial line-width control.

prepareWithSegments()layoutNextLine()
Advanced

🗞️ PDF Reflow Engine

The same article is re-composed into phone, tablet, poster, and editorial spreads instantly.

prepare()layout()layoutNextLine()
Advanced

🎬 Subtitle Composer

A cinematic subtitle engine with safe zones, speaker separation, emphasis, and timing-aware wrapping.

prepareWithSegments()layoutWithLines()
Advanced

📊 Incremental Layout Profiler

Inspect what changes trigger prepare work versus cheap relayout in a devtool-style profiler.

prepare()layout()profilePrepare()
Advanced

🧬 Topology Morph

One document migrates across radically different region topologies while keeping reading continuity.

prepareWithSegments()layoutNextLine()
Flagship Flagship

Text Regatta

A sailboat cuts through a sea made of text, with swell, wake turbulence, and current-driven reflow.

prepareWithSegments()layoutNextLine()
Spectacular

🫧 Text Particle Pool

Characters rain down, pile up with physics collisions, and accumulate into a pool you can push around.

prepareWithSegments()layoutWithLines()
Flagship Flagship

🌊 Text Ocean SPH

Thousands of character particles form a fluid ocean via SPH simulation — a boat floats on the letter waves.

prepareWithSegments()layoutWithLines()