chenglou/pretext
↗ GitHub35,263
Stars
1,826
Forks
114
Watchers
63
Open Issues
Safety Rating A
No security concerns identified. The repository is a pure text measurement and layout library with no network calls, no hardcoded secrets, no suspicious dependencies, and no prompt injection patterns in the README. It is a straightforward open-source utility library with a legitimate and clearly documented purpose.
ℹAI-assisted review, not a professional security audit.
AI Analysis
Pretext is a pure JavaScript/TypeScript library for fast, accurate multiline text measurement and layout without triggering DOM reflow. It implements its own text measurement logic using the browser's canvas font engine, providing precise paragraph height calculation, line segmentation, and bi-directional (bidi) text support across all languages and emoji. It offers two main use-case APIs: a simple prepare/layout pair for height measurement only, and a richer prepareWithSegments set for manual line-by-line layout enabling rendering to Canvas, SVG, WebGL, or server-side contexts. An experimental inline-flow sidecar handles mixed inline runs with atomic items and boundary whitespace collapse.
Use Cases
- Measuring paragraph height without DOM reflow for virtualized list implementations
- Performing accurate text layout for canvas, SVG, or WebGL rendering
- Implementing masonry and other custom JS-driven layout engines
- Verifying at development/test time that UI labels do not overflow their containers
- Re-anchoring scroll position when new text loads by predicting height before render
- Flowing text around floated elements with variable per-line widths
- Computing the tightest container width that fits multiline text via shrink-wrap
Tags
Project Connections
itshover/itshover
Pretext provides accurate text measurement for layout calculations, while ItsHover provides animated React UI components. A UI component library benefits directly from accurate text metrics to prevent label overflow and enable precise sizing.
emdash-cms/emdash
A full-stack CMS like EmDash rendering rich text content to the DOM or canvas would benefit from Pretext's reflow-free text measurement for accurate height prediction and layout, especially for content preview or virtualized content lists.
microsoft/markitdown
MarkItDown converts documents to Markdown text for LLM pipelines; Pretext could complement it on the rendering/display side by accurately measuring and laying out the resulting Markdown text for display without DOM reflow.