in packages/dom/src/text-node-chunker.ts [124:145]
constructor(scope: Node | Range) {
this.scope = toRange(scope);
this.iter = ownerDocument(scope).createNodeIterator(
this.scope.commonAncestorContainer,
NodeFilter.SHOW_TEXT,
{
acceptNode: (node: Text) => {
return this.scope.intersectsNode(node)
? NodeFilter.FILTER_ACCEPT
: NodeFilter.FILTER_REJECT;
},
},
);
// Move the iterator to after the start (= root) node.
this.iter.nextNode();
// If the start node is not a text node, move it to the first text node.
if (!isText(this.iter.referenceNode)) {
const nextNode = this.iter.nextNode();
if (nextNode === null) throw new EmptyScopeError();
}
}