src/Range.php
/**
     * Compares the position of two boundary points.
     *
     * @internal
     *
     * @see https://dom.spec.whatwg.org/#concept-range-bp-position
     *
     * @param array{0: \Rowbot\DOM\Node, 1: int} $boundaryPointA An array containing a Node and an offset within that
     *                                                           Node representing a boundary.
     * @param array{0: \Rowbot\DOM\Node, 1: int} $boundaryPointB An array containing a Node and an offset within that
     *                                                           Node representing a boundary.
     *
     * @return string Returns before, equal, or after based on the position of the first boundary relative to the second
     *                boundary.
     */
Compares the position of two boundary points.
@internal



@param array{0: \Rowbot\DOM\Node, 1: int} $boundaryPointA An array containing a Node and an offset within that
Node representing a boundary.
@param array{0: \Rowbot\DOM\Node, 1: int} $boundaryPointB An array containing a Node and an offset within that
Node representing a boundary.

@return string Returns before, equal, or after based on the position of the first boundary relative to the second
boundary.
Compares the position of two boundary points . @internal @param array { 0 : \ Rowbot \ DOM \ Node 1 : int } $boundaryPointA An array containing a Node and an offset within that Node representing a boundary . @param array { 0 : \ Rowbot \ DOM \ Node 1 : int } $boundaryPointB An array containing a Node and an offset within that Node representing a boundary . @return string Returns before equal or after based on the position of the first boundary relative to the second boundary .
private function computePosition(array $boundaryPointA, array $boundaryPointB): string
    {
        if ($boundaryPointA[0] === $boundaryPointB[0]) {
            if ($boundaryPointA[1] === $boundaryPointB[1]) {
                return 'equal';
            } elseif ($boundaryPointA[1] < $boundaryPointB[1]) {
                return 'before';
            } else {
                return 'after';
            }
        }
        $commonAncestor = Node::getCommonAncestor($boundaryPointB[0], $boundaryPointA[0]);
        if ($commonAncestor === $boundaryPointA[0]) {
            $AFollowsB = false;
        } elseif ($commonAncestor === $boundaryPointB[0]) {
            $AFollowsB = true;
        } else {
            $b = $boundaryPointB[0];
            while ($b->parentNode !== $commonAncestor) {
                $b = $b->parentNode;
            }
            $a = $boundaryPointA[0];
            while ($a->parentNode !== $commonAncestor) {
                $a = $a->parentNode;
            }
            $AFollowsB = false;
            while ($b) {
                if ($a === $b) {
                    $AFollowsB = true;
                    break;
                }
                $b = $b->nextSibling;
            }
        }
        if ($AFollowsB) {
            [$boundaryPointB, $boundaryPointA] = [$boundaryPointA, $boundaryPointB];
        }
        $ancestor = $boundaryPointB[0]->parentNode;
        while ($ancestor) {
            if ($ancestor === $boundaryPointA[0]) {
                break;
            }
            $ancestor = $ancestor->parentNode;
        }
        if ($ancestor) {
            $child = $boundaryPointB[0];
            while ($child) {
                if ($child->parentNode === $boundaryPointA[0]) {
                    break;
                }
                $child = $child->parentNode;
            }
            if ($child->getTreeIndex() < $boundaryPointA[1]) {
                return $AFollowsB ? 'before' : 'after';
            }
        }
        return $AFollowsB ? 'after' : 'before';
    }
private function computePosition ( array $ boundaryPointA , array $ boundaryPointB ) : string { if ( $ boundaryPointA [ 0 ] === $ boundaryPointB [ 0 ] ) { if ( $ boundaryPointA [ 1 ] === $ boundaryPointB [ 1 ] ) { return 'equal' ; } elseif ( $ boundaryPointA [ 1 ] < $ boundaryPointB [ 1 ] ) { return 'before' ; } else { return 'after' ; } } $ commonAncestor = Node :: getCommonAncestor ( $ boundaryPointB [ 0 ] , $ boundaryPointA [ 0 ] ) ; if ( $ commonAncestor === $ boundaryPointA [ 0 ] ) { $ AFollowsB = false ; } elseif ( $ commonAncestor === $ boundaryPointB [ 0 ] ) { $ AFollowsB = true ; } else { $ b = $ boundaryPointB [ 0 ] ; while ( $ b -> parentNode !== $ commonAncestor ) { $ b = $ b -> parentNode ; } $ a = $ boundaryPointA [ 0 ] ; while ( $ a -> parentNode !== $ commonAncestor ) { $ a = $ a -> parentNode ; } $ AFollowsB = false ; while ( $ b ) { if ( $ a === $ b ) { $ AFollowsB = true ; break ; } $ b = $ b -> nextSibling ; } } if ( $ AFollowsB ) { [ $ boundaryPointB , $ boundaryPointA ] = [ $ boundaryPointA , $ boundaryPointB ] ; } $ ancestor = $ boundaryPointB [ 0 ] -> parentNode ; while ( $ ancestor ) { if ( $ ancestor === $ boundaryPointA [ 0 ] ) { break ; } $ ancestor = $ ancestor -> parentNode ; } if ( $ ancestor ) { $ child = $ boundaryPointB [ 0 ] ; while ( $ child ) { if ( $ child -> parentNode === $ boundaryPointA [ 0 ] ) { break ; } $ child = $ child -> parentNode ; } if ( $ child -> getTreeIndex ( ) < $ boundaryPointA [ 1 ] ) { return $ AFollowsB ? 'before' : 'after' ; } } return $ AFollowsB ? 'after' : 'before' ; }
Compares the position of two boundary points.
Compares the position of two boundary points .
// A was not found inside B. Traverse both A & B up to the nodes // before their common ancestor, then see if A is in the nextSibling // chain of B. // Swap variables