# chenglou/pretext

Fast, accurate & comprehensive text measurement & layout

Repository: https://github.com/chenglou/pretext
Canonical: https://ross.abutalabs.com/products/pretext
Homepage: http://chenglou.me/pretext/
Language: TypeScript
License: MIT
License Family: permissive
Last push: 2026-06-23T05:01:09+00:00

## Health v2 (maintenance only)
Score: 55/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 89, release rhythm 35, longevity 12
- inputs: {"age_days": 179, "days_push": 71, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: no_releases, young
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 50059, forks 2734 (observed 2026-08-28T04:12:11.706164+00:00)

## What it is
Pretext is a pure TypeScript library for fast, accurate multiline text measurement and layout that avoids DOM reflows by using the browser's font engine for measurement and pure arithmetic for layout. It supports rendering to DOM, Canvas, and SVG, handles international text, and offers both height prediction and manual line-level layout APIs.

## Use cases
- measure paragraph height without touching the DOM
- build virtualized lists with accurate text heights
- implement masonry layouts with text cards
- prevent layout shift when text loads
- do Knuth-Plass paragraph justification in the browser
- lay out text lines manually on canvas or SVG
- verify button labels don't overflow during development

## When to choose
- you need text height or line breaks without triggering layout reflow
- you're building virtualization, masonry, or custom layout systems
- you need accurate measurement for multilingual text including CJK and RTL
- you render text to Canvas or SVG and need line-level control

## When to avoid
- you only need simple CSS text wrapping with no measurement needs
- you need server-side text measurement today (not yet supported)
- your project doesn't use JavaScript in the browser

## Facets
- artifact type: library
- maturity: active
- function: templating, ui-components, developer-tools
- domain: frontend, web-development, performance
- platform: browser
- tags: text-measurement, text-layout, line-breaking, knuth-plass, canvas-measurement, virtualization, no-dom-reflow, multilingual, nodejs, web-server, typescript

## Member repositories
- chenglou/pretext (main) score 55

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:12:11.706164+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T16:20:01.864122+00:00, confidence not recorded.
  - readme: https://github.com/chenglou/pretext (fetched 2026-08-28T04:12:11.706164+00:00, sha f78ab8f7b135)
  - homepage: http://chenglou.me/pretext/ (fetched 2026-08-28T18:12:36.713521+00:00, sha 585c33c2440f)
- Data as of 2026-08-30T08:39:29.467469+00:00.
