Documentation Index
Fetch the complete documentation index at: https://mintlify.com/chenglou/pretext/llms.txt
Use this file to discover all available pages before exploring further.
How the cache works
Pretext maintains a two-level segment metrics cache:"16px Inter"). The inner key is the segment text. Each entry stores the metrics measured for that segment at that font — including segment width, per-grapheme widths for overflow-wrap: break-word segments, and emoji correction values.
What gets cached per (segment, font) entry:
- Segment width — the canvas
measureTextresult for the full segment - Grapheme widths — individual grapheme widths for word segments that may need mid-word breaking
- Emoji correction — one cached DOM read per font, used to correct canvas emoji inflation at small sizes
prepare() and prepareWithSegments() calls that use the same font. Once a segment has been measured, subsequent prepare() calls reuse the cached result with no canvas or DOM work.
clearCache()
CallclearCache() to release all cached metrics. This is useful if your app cycles through many different fonts over time and you want to reclaim the accumulated memory.
clearCache(), the next prepare() call for any font will re-measure from scratch.
setLocale() and the cache
setLocale(locale?) retargets the word segmenter used by future prepare() calls for a different Intl.Segmenter locale. Internally, it calls clearCache() as part of that reset.
Memory considerations
The cache grows as you prepare unique(segment, font) pairs. For apps that display a bounded set of fonts and natural-language text, the cache reaches a stable size quickly — most words recur across texts.
The cache can grow unboundedly if your app:
- Cycles through many different font strings (different sizes, weights, families)
- Prepares a large number of unique technical strings with little repetition
clearCache() at a natural transition point (e.g. after a font settings change) to release accumulated memory.