I get anchorNode and focusNode of the window selection.
const { anchorNode, focusNode } = window.getSelection();
How can I determine which one of these is before another in DOM? In other words, I need a solution to detect the position of this element within the DOM tree.
For example, in strings we can use indexOf method to find the index of a word or substring. I need a method like document.indexOfNode(node).