export function nodeContainsDescendant ( rootNode , descendant ) { if ( rootNode === descendant ) { return true ; } let parent = descendant . parentNode ; while ( parent != null ) { if ( parent === rootNode ) { return true ; } parent = parent . parentNode ; } return false ; } export function matches ( node , selector ) { if ( node . matches ) { return node . matches ( selector ) ; } const matches = ( node . ownerDocument || document ) . querySelectorAll ( selector ) ; let i = matches . length ; while ( -- i >= 0 && matches . item ( i ) !== node ) { } return i > - 1 ; } ; export function closest ( node , selector ) { if ( node . closest ) { return node . closest ( selector ) ; } const matches = document . querySelectorAll ( selector ) ; let i ; let el = node ; do { el = el . parentElement ; i = matches . length ; while ( -- i >= 0 && matches . item ( i ) !== el ) { continue ; } ; } while ( ( i < 0 ) && ( el ) ) ; return el ; }