license /** IE 11 compatible matches implementation. */ export function matches ( element , selector ) { return element . matches ? element . matches ( selector ) : ( element as any ) [ 'msMatchesSelector' ] ( selector ) ; } /** IE 11 compatible closest implementation that is able to start from non-Element Nodes. */ export function closest ( element , selector ) { if ( ! ( element instanceof Node ) ) { return null ; } let curr = element ; while ( curr != null && ! ( curr instanceof Element ) ) { curr = curr . parentNode ; } return ( curr && ( ( hasNativeClosest ? curr . closest ( selector ) : polyfillClosest ( curr , selector ) ) as Element | null ) ) ; } /** Polyfill for browsers without Element.closest. */ function polyfillClosest ( element , selector ) { let curr = element ; while ( curr != null && ! ( curr instanceof Element && matches ( curr , selector ) ) ) { curr = curr . parentNode ; } return ( curr || null ) as Element | null ; } const hasNativeClosest = ! ! Element . prototype . closest ;