Skip to content

feat(pagination): Line-level pagination with paragraph splitting #30

@JSv4

Description

@JSv4

Summary

Currently the pagination engine operates at the block (paragraph) level. If a paragraph is taller than a page, it overflows and gets clipped. This creates a poor user experience for documents with long paragraphs.

Proposed Solution

Implement line-level measurement and splitting:

  1. Line measurement: Use getClientRects() or range-based measurement to identify individual lines within a paragraph
  2. Paragraph splitting: When a paragraph doesn't fit, split it at a line boundary
  3. Orphan/widow control: Ensure at least N lines remain on each page (configurable)

Implementation Approach

interface MeasuredLine {
  startOffset: number;
  endOffset: number;
  height: number;
}

function measureLines(element: HTMLElement): MeasuredLine[] {
  // Use Range API to measure each line
  // Handle inline elements, images, etc.
}

function splitParagraph(element: HTMLElement, maxHeight: number): [HTMLElement, HTMLElement] {
  // Clone and split at line boundary
}

Challenges

  • Complex inline content (images, links spanning lines)
  • Maintaining semantic correctness when splitting
  • Performance for large documents
  • RTL and vertical text layouts

Acceptance Criteria

  • Paragraphs split cleanly at line boundaries
  • Minimum 2 lines on each page (no orphans/widows)
  • Inline elements handled correctly
  • No visual artifacts at split points

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions