pretext

Measure text and calculate layout without DOM reflow using canvas arithmetic.

1|Updated May 24, 2026
One-click install
npx skills add https://github.com/PTKDrake/FIT-vmu --skill pretext-ptkdrake
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/PTKDrake/FIT-vmu/tree/main/.agents/skills/pretext
Command: npx skills add https://github.com/PTKDrake/FIT-vmu --skill pretext-ptkdrake

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @chenglou/pretext, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides a pure JavaScript/TypeScript library for efficient, accurate text measurement and layout, overcoming the limitations of DOM-based methods and enabling high-performance text processing in AI applications.

Core Features & Use Cases

  • DOM-Free Text Measurement: Avoids layout reflow for faster, more efficient text measurement.
  • Multilingual Support: Handles text layout for all major languages, including CJK, Arabic, Thai, and more.
  • Custom Rendering: Supports rendering text to DOM, Canvas, SVG, and server-side.
  • Use Case: Imagine you need to dynamically size text within a UI component or measure text for a virtualized list. This Skill allows you to calculate text height and layout without the overhead of DOM operations, improving performance and responsiveness.

Quick Start

Use the pretext skill to measure the height of the text 'AGI 春天到了. 开始了旅程 🚀' with font '16px Inter' and maximum width 400.

Frequently Asked Questions about pretext

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I measure text height and width without causing DOM layout reflow?

You can perform DOM-free text measurement and layout using pure arithmetic and canvas calculations. This approach avoids layout reflow entirely, enabling faster text height prediction and dynamic UI component sizing without browser overhead.

Does canvas text measurement support multilingual layout for CJK, Arabic, and Thai?

Canvas text measurement supports multilingual layout for all major languages, including CJK, Arabic, and Thai. It handles complex text rendering requirements without relying on DOM operations, ensuring accurate layout across diverse character sets.

How do I calculate row sizing for a virtualized list without DOM operations?

You can calculate virtualized list row sizing using pure JavaScript text measurement functions. By predicting text height based on font properties and maximum width, you determine row dimensions efficiently without triggering DOM layout reflow.

Can I render measured text to SVG and Canvas instead of the DOM?

You can render measured text to SVG, Canvas, and server-side environments. The measurement functions provide layout coordinates that support custom rendering across multiple platforms, enabling flexible text output beyond standard DOM elements.

What is the best way to handle text layout for AI-driven UI processing?

The best way to handle AI-driven UI text layout is through pure JavaScript measurement functions that bypass DOM reflow. This provides accurate text height prediction and width calculation, ensuring high-performance document processing for AI applications.

Do I need @chenglou/pretext to perform DOM-free text measurement?

Yes, you need @chenglou/pretext installed to access the core text measurement and layout functions. This dependency provides the arithmetic calculations required to compute text dimensions without relying on DOM layout operations.