New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.3.3

@eigenpal/docx-editor-core/layout-bridge/clickToPositionDom

DOM-based Click-to-Position Mapping

Uses the browser's actual rendered DOM to find ProseMirror positions. This is more accurate than geometry-based calculation because it uses the browser's own text rendering with document.elementsFromPoint().

DOM elements are tagged with data-pm-start and data-pm-end attributes, enabling binary search to find exact character positions.

Functions(4)

Find ProseMirror position from a click using DOM-based detection.

declare function clickToPositionDom(container: HTMLElement, clientX: number, clientY: number, zoom?: number): number | null;

Vertically clip a client rect to the enclosing page-fragment table's visible box. A table that breaks across a page sits in a `.layout-table` with `overflow:hidden` and `height = visibleHeight`; getClientRects() still reports the geometry of lines that are visually clipped (off the page / in the inter-page gap), so selection highlights must be clipped to the same box.

Uses `.layout-table:not(.layout-nested-table)` because only the page-fragment table carries the window clip — the inner nested table has no overflow:hidden. Clips vertically only (the gap bug is vertical; horizontal clipping could trim change bars on tracked-change tables that set overflow-x: visible).

Returns null when the rect is fully outside the window.

declare function clipRectToTableWindow(spanEl: Element, rect: {
    readonly left: number;
    readonly top: number;
    readonly right: number;
    readonly bottom: number;
}): {
    left: number;
    top: number;
    right: number;
    bottom: number;
} | null;
declare function getCaretPositionFromDom(container: HTMLElement, pmPos: number, overlayRect: DOMRect): DomCaretPosition | null;
declare function getSelectionRectsFromDom(container: HTMLElement, from: number, to: number, overlayRect: DOMRect): DomSelectionRect[];

Interfaces(2)

Get caret position from DOM for a PM position.

interface DomCaretPosition
MemberTypeSummary
heightnumber
pageIndexnumber
xnumber
ynumber

Get selection rectangles for a PM range using DOM-based detection.

interface DomSelectionRect
MemberTypeSummary
heightnumber
pageIndexnumber
widthnumber
xnumber
ynumber