# bhagyashree-vaidya/pretext architecture

> Architecture diagram of the GitHub repository bhagyashree-vaidya/pretext, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhagyashree-vaidya/pretext
- Repository: https://github.com/bhagyashree-vaidya/pretext

## Overview

Pretext is a text-measurement and line-layout library. Its main workflow prepares text once—normalizing and segmenting it at break opportunities, then measuring widths—and reuses that prepared data to calculate line counts and height or to produce line ranges and text. A separate rich-inline API handles mixed-font fragments. The graph emphasizes these documented runtime paths; detailed wiring among preparation helpers is not fully shown in the sampled source.

Main entry points: [`src/layout.ts`](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/layout.ts) (Layout API), [`src/prepare.ts`](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/prepare.ts) (Preparation), [`src/rich-inline.ts`](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/rich-inline.ts) (Rich Inline API), [`src/analysis.ts`](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/analysis.ts) (Text Analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public APIs"]
  node_layout_api["Layout API<br/>[layout.ts]"]
  node_rich_api["Rich Inline API<br/>[rich-inline.ts]"]
end

subgraph group_prep["Text Preparation"]
  node_prepare["Preparation<br/>[prepare.ts]"]
  node_analysis["Text Analysis<br/>[analysis.ts]"]
  node_graphemes["Grapheme Segmentation<br/>[graphemes.ts]"]
  node_break_opportunities["Break Opportunities<br/>[line-breaks.ts]"]
  node_measurement["Font Measurement<br/>[measurement.ts]"]
  node_han_kerning["Han Kerning<br/>[han-kerning.ts]"]
  node_gecko_breaks["Gecko Break Rules"]
  node_gecko_bidi["Gecko Bidi Levels"]
end

subgraph group_layout["Line Layout"]
  node_line_break["Line Breaking<br/>[line-break.ts]"]
  node_entry_geometry["Entry Geometry<br/>[entry-geometry.ts]"]
  node_line_text["Line Materialization<br/>[line-text.ts]"]
end

subgraph group_rich["Rich Inline"]
  node_rich_inline["Rich Preparation and Layout<br/>[rich-inline.ts]"]
end

node_app(("Application"))
node_browser(("Browser Font Engine"))
node_result(("Layout Results"))

node_app -->|"provides text"| node_layout_api
node_layout_api -->|"prepares text"| node_prepare
node_prepare -->|"analyzes text"| node_analysis
node_analysis -->|"segments graphemes"| node_graphemes
node_analysis -->|"finds breaks"| node_break_opportunities
node_prepare -->|"measures segments"| node_measurement
node_measurement -->|"measures fonts"| node_browser
node_prepare -->|"accounts for kerning"| node_han_kerning
node_layout_api -->|"lays out prepared text"| node_line_break
node_line_break -->|"checks line fit"| node_entry_geometry
node_layout_api -->|"materializes lines"| node_line_text
node_line_break -->|"returns line metrics"| node_result
node_line_text -->|"returns line text"| node_result
node_app -->|"provides inline items"| node_rich_api
node_rich_api -->|"measures fragments"| node_measurement
node_rich_api -->|"returns rich line ranges"| node_result
node_gecko_breaks -.->|"supplies engine rules"| node_break_opportunities
node_gecko_bidi -.->|"supplies bidi data"| node_break_opportunities

click node_layout_api "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/layout.ts"
click node_rich_api "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/rich-inline.ts"
click node_prepare "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/prepare.ts"
click node_analysis "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/analysis.ts"
click node_graphemes "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/graphemes.ts"
click node_break_opportunities "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-breaks.ts"
click node_measurement "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/measurement.ts"
click node_han_kerning "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/han-kerning.ts"
click node_line_break "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-break.ts"
click node_entry_geometry "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/entry-geometry.ts"
click node_line_text "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-text.ts"
click node_rich_inline "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/rich-inline.ts"
click node_gecko_breaks "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/gecko-line-breaks.ts"
click node_gecko_bidi "https://github.com/bhagyashree-vaidya/pretext/blob/main/src/gecko-bidi-levels.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_layout_api,node_rich_api,node_browser toneBlue
class node_prepare,node_analysis,node_graphemes,node_break_opportunities,node_measurement,node_han_kerning,node_gecko_breaks,node_gecko_bidi toneAmber
class node_line_break,node_entry_geometry,node_line_text toneMint
class node_rich_inline toneRose
class node_app,node_result toneIndigo
```

## Components

### Public APIs

- [Layout API](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/layout.ts): `src/layout.ts`
- [Rich Inline API](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/rich-inline.ts): `src/rich-inline.ts`

### Text Preparation

- [Preparation](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/prepare.ts): `src/prepare.ts`
- [Text Analysis](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/analysis.ts): `src/analysis.ts`
- [Grapheme Segmentation](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/graphemes.ts): `src/graphemes.ts`
- [Break Opportunities](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-breaks.ts): `src/line-breaks.ts`
- [Font Measurement](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/measurement.ts): `src/measurement.ts`
- [Han Kerning](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/han-kerning.ts): `src/han-kerning.ts`
- [Gecko Break Rules](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/gecko-line-breaks.ts): `src/gecko-line-breaks.ts`
- [Gecko Bidi Levels](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/gecko-bidi-levels.ts): `src/gecko-bidi-levels.ts`

### Line Layout

- [Line Breaking](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-break.ts): `src/line-break.ts`
- [Entry Geometry](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/entry-geometry.ts): `src/entry-geometry.ts`
- [Line Materialization](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/line-text.ts): `src/line-text.ts`

### Rich Inline

- [Rich Preparation and Layout](https://github.com/bhagyashree-vaidya/pretext/blob/main/src/rich-inline.ts): `src/rich-inline.ts`

### Other components

- **Application**
- **Browser Font Engine**
- **Layout Results**

## Connections

- Application → Layout API: provides text
- Layout API → Preparation: prepares text
- Preparation → Text Analysis: analyzes text
- Text Analysis → Grapheme Segmentation: segments graphemes
- Text Analysis → Break Opportunities: finds breaks
- Preparation → Font Measurement: measures segments
- Font Measurement → Browser Font Engine: measures fonts
- Preparation → Han Kerning: accounts for kerning
- Layout API → Line Breaking: lays out prepared text
- Line Breaking → Entry Geometry: checks line fit
- Layout API → Line Materialization: materializes lines
- Line Breaking → Layout Results: returns line metrics
- Line Materialization → Layout Results: returns line text
- Application → Rich Inline API: provides inline items
- Rich Inline API → Font Measurement: measures fragments
- Rich Inline API → Layout Results: returns rich line ranges
- Gecko Break Rules → Break Opportunities: supplies engine rules
- Gecko Bidi Levels → Break Opportunities: supplies bidi data
