New

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

API Referencev1.0.2

@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(3)

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

declare function clickToPositionDom(container: HTMLElement, clientX: number, clientY: number, zoom?: number): 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