Pretext Layout

    by Roy Yuen

    2

    High-performance browser-based text layout and measurement for virtualization, canvas, and layout-heavy applications.

    Free

    15 installsSecurity scanned

    Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLIVVS CodeWWindsurfMManus+14 more

    See it in action

    You say

    Measure the 200px width layout for "Hello World" using 24px line-height, then provide the per-line ranges and performance stats after ensuring fonts are loaded.

    Your agent does

    Prepared handle cached for "Hello World". Height: 48px at 200px width. Line 1: "Hello " (0-6) Line 2: "World" (6-11) Performance: <0.1ms layout time. Verified against document.fonts.ready status.

    About this skill

    Efficient Text Measurement & Layout

    The Pretext Layout skill enables AI agents to integrate and debug high-performance multiline text measurement using the @chenglou/pretext library. It solves the common frontend performance bottleneck of "layout thrashing" by replacing slow DOM-based height probes with a fast, browser-native API approach.

    What it does

    This skill provides developers with a structured methodology for measuring text width and height without repeated DOM reflows. It supports high-level block height calculation for virtualization and low-level line-by-line geometry for custom Canvas or SVG rendering workflows. It handles complex edge cases including web fonts, emoji, and bidirectional text.

    Supported Workflows

    • Virtualization: Pre-measure list item heights for smooth scroll anchoring.
    • Custom Rendering: Extract per-line ranges for manual drawing in Canvas or SVG.
    • Responsive Design: Rapidly recalculate layouts during window resize events on the hot path.
    • Debugging: Verify layout accuracy against real-world CSS styles and font loading states.

    Why use this skill?

    While a general AI can write basic JavaScript, this skill understands the specific lifecycle of the Pretext library—such as partitioning the expensive "prepare" phase from the lightweight "layout" phase. It ensures your agent correctly manages browser-only runtime constraints, font loading promises, and locale-specific white-space behaviors to prevent layout shifts and flickering.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    15 installs

    Downloaded by developers to date

    Free forever

    No account required to browse

    Trust & safety

    Security scanned

    Verified clean 4 months ago

    • Free to download with an account

    Installs15
    Listed4 months ago

    Creator

    Roy Yuen
    Roy Yuen

    1124+ total installs · 111 skills on Agensi

    Frequently Asked Questions

    Popular in Web & App UI Design

    Free