RepositoryTypeScriptUSHoa Kỳ
chenglou

chenglou/pretext

Fast, accurate & comprehensive text measurement & layout

51.1ksao
2.8kfork
42issue
1lượt xem

Thành tựu nổi bật

Những danh hiệu mới nhất của dự án

1
TINIX TRENDING·Chủ đề: occlusion

#1 Repository Của Tháng

1
TINIX TRENDING·Chủ đề: text-measurement

#1 Repository Của Tuần

1
TINIX TRENDING·Chủ đề: text-measurement

#1 Repository Của Tháng

📏 Layout Text Without Touching the DOM

Pretext measures and lays out multiline text in pure TypeScript, skipping DOM reflows entirely.

Pretext is a pure JavaScript/TypeScript library for multiline text measurement and layout. Built by chenglou, it avoids expensive DOM operations like getBoundingClientRect or offsetHeight by using the browser's own font engine as ground truth via canvas measurement. Supports all languages, including CJK, Arabic, emoji, and mixed scripts.

✨ Highlights

  • DOM-free measurement: Uses canvas font metrics instead of triggering layout reflow
  • Multilingual support: Handles CJK, RTL, emoji, and mixed-language text
  • Two APIs: prepare() + layout() for height-only; prepareWithSegments() + layoutWithLines() for full line control
  • Cached precomputation: prepare() does heavy lifting once; layout() is pure arithmetic
  • whiteSpace: 'pre-wrap': Keeps spaces, tabs, and newlines visible for textarea-like layouts
  • wordBreak: 'keep-all': Prevents breaking CJK characters, matching CSS behavior
  • letterSpacing support: Matches CSS letter-spacing with px values
  • Rich inline helper: @chenglou/pretext/rich-inline for inline flows with mixed fonts and styles

💡 Why it matters

Pretext eliminates layout thrashing by precomputing text metrics without DOM access. This is critical for performant UIs with dynamic text, virtual lists, or server-side rendering. Especially useful for AI-driven content where text dimensions must be known before rendering.

Ideal for developers building canvas, SVG, or WebGL text renderers; implementing text-aware virtualization; or verifying label overflow during development without a browser.


#TextLayout #TypeScript #WebPerformance #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryTypeScript
n8n-io/n8n

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

211.9k
Nov 23, 2026
RepositoryTypeScript
microsoft/vscode

Visual Studio Code

195.8k
Nov 22, 2026
RepositoryTypeScript
angular/angular

Deliver web apps with confidence 🚀

101.6k
Nov 23, 2026
RepositoryTypeScript
ant-design/ant-design

An enterprise-class UI design language and React UI library

100.3k
Nov 20, 2026
RepositoryTypeScript
mermaid-js/mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown

91.2k
Nov 21, 2026
RepositoryTypeScript
heygen-com/hyperframes

Open-source AI video editor: edit your own footage, or create and remake any video with Claude Code, Codex or the free Studio app. Write HTML, render MP4. By HeyGen.

88.8k
Nov 23, 2026
RepositoryTypeScript
nestjs/nest

A progressive TypeScript framework for Node.js backends: from a small API in one file to efficient, scalable, enterprise-grade systems 🚀

77.1k
Nov 21, 2026
RepositoryTypeScript
twentyhq/twenty

The open alternative to Salesforce, designed for AI.

61.3k
Nov 22, 2026
RepositoryTypeScript
FlowiseAI/Flowise

Build AI Agents, Visually

55.6k
Aug 13, 2026