Demo

# Shrinkwrap showdown

CSS `width: fit-content` sizes a bubble to its widest wrapped line, which leaves dead space when the last line is short. Pretext finds the tightest width that still wraps to the exact same number of lines.

Container width: 340px

## CSS fit-content

Uses `width: fit-content; max-width: 80%`. The browser wraps the text, then sizes the bubble to the longest wrapped line. Shorter lines leave empty bubble area behind.

Wasted pixels: ...
Yo did you see the new Pretext library?
yeah! It measures text without the DOM. Pure JavaScript arithmetic
That shrinkwrap demo is wild it finds the exact minimum width for multiline text. CSS can't do that.
성능 최적화가 정말 많이 되었더라고요 🎉
Oh wow it handles CJK and emoji too??
كل شيء! Mixed bidi, grapheme clusters, whatever you want. Try resizing
the best part: zero layout reflow. You could shrinkwrap 10,000 bubbles and the browser wouldn't even blink

## Pretext shrinkwrap

Uses `walkLineRanges()` to binary-search the tightest width that produces the same line count. Zero wasted pixels. No DOM text measurement in the resize path.

Wasted pixels: 0
Yo did you see the new Pretext library?
yeah! It measures text without the DOM. Pure JavaScript arithmetic
That shrinkwrap demo is wild it finds the exact minimum width for multiline text. CSS can't do that.
성능 최적화가 정말 많이 되었더라고요 🎉
Oh wow it handles CJK and emoji too??
كل شيء! Mixed bidi, grapheme clusters, whatever you want. Try resizing
the best part: zero layout reflow. You could shrinkwrap 10,000 bubbles and the browser wouldn't even blink

## Why can't CSS do this?

CSS only knows `fit-content`, which is the width of the widest line after wrapping. If a paragraph wraps to 3 lines and the last line is short, CSS still sizes the container to the longest line. There's no CSS property to say “find the narrowest width that still produces exactly 3 lines.” That requires measuring the text at multiple widths and comparing line counts, which is exactly what Pretext's `walkLineRanges()` does, without DOM text measurement in the resize path. Pure arithmetic, no reflows, instant results.