getDOMSelectionPoints
functionResolves a DOM Selection's anchor/focus boundary points through any DOM ShadowRoots enclosing `rootElement`. Inside a shadow tree the boundary points come from getComposedStaticRange mapped back onto anchor/focus with the standard Selection.direction (https://developer.mozilla.org/docs/Web/API/Selection/direction); in the light DOM (or when `getComposedRanges` is unavailable) the Selection's own anchorNode/focusNode are already correct, so the Selection is returned as-is (it satisfies DOMSelectionBoundaryPoints). Use this instead of reading `Selection.anchorNode`/`focusNode` directly, which are retargeted to the shadow host inside a shadow tree.
Import
import { getDOMSelectionPoints } from '@modular/sdk/editor';Notes
- remarks
- The two return paths have different read semantics: - light DOM: the return aliases `domSelection`, so subsequent reads reflect any post-call selection changes. The aliasing is intentional; each `Selection` property read forces a synchronous style/layout recalculation, so `$updateDOMSelection` defers these reads until they are actually needed. - shadow DOM: the return is a snapshot taken at call time, including `direction`. If a future engine ships `getComposedRanges` without `Selection.direction` (no current shipping configuration matches), the snapshot's `direction` is `undefined` and anchor/focus default to the StaticRange's tree order — a backward selection will appear forward. Read the four points immediately after the call, or compare identity via `points === domSelection` to detect when the return aliases `domSelection`, rather than caching the returned reference across selection mutations.