Layout caching and projections

Reuse unchanged native geometry and collaborative content projections.

Reuse layout work

Unchanged paragraphs retain their objects. Layout caches prepared paragraph geometry and reuses positioned lines and pages when their geometry and content remain unchanged. Wrapping, list markers, available width, and measurer identity participate in invalidation.

Keep one measurer object while its font metrics remain valid; replace it when fonts or measurement behavior change.

cache.measuredParagraphs is a cumulative measurement counter for diagnostics. Updates still walk the authored tree and pagination still visits content. This API does not promise constant-time edits or viewport-only pagination. A small edit can move following content and require new page geometry.

layout returns WordLayout, with page, column, line, table, and fragment geometry in points. The application owns rendering, input, selection, and converting points to screen coordinates. Optional maxPages and maxFragments are caller-controlled layout work budgets; exceeding them throws rather than truncating content.

Reuse unchanged paragraphs and tables

WordParagraphProjection(body, project) consumes transaction deltas and calls project only for changed slices when paragraphs is read. Slices include stable terminator identity, UTF-16 length, formatted parts, and the terminating newline when present. Call destroy when finished. wordParagraphIdentity exposes the underlying terminator identity.

WordTableProjection.update(paragraphs) reuses unchanged table trees while checking table contiguity. Treat slices and projected values as immutable. NativeWordDocument({ immutableContent: true }) additionally caches authored signatures by object identity; every supplied descendant must remain immutable.

Updates still require document traversal for offsets, numbering, and source continuations. Export at download or persistence boundaries rather than rebuilding and reparsing DOCX on every keystroke.

Composed placement and page numbers

positionedWordEdit stages a composed placement edit. wordPageNumberRange and wordItemAlignment inspect existing content; pageNumberEdit and alignWordItem create edits for numbering and alignment. clickAndTypeEdit applies the intent returned by wordClickAndTypeTarget. Use these shared operations for human gestures and agent edits.

Positioning and page geometry

Next Word compatibility