export const closest = ( element , selector ) : HTMLElement | null => { if ( element instanceof Element ) { if ( element && element . closest ) { return element . closest ( selector ) as HTMLElement | null ; } else { let el = element ; while ( el ) { if ( matches ( el , selector ) ) { return el ; } el = el . parentElement ; } } } return null ; } ; export const matches = ( element , selector ) => { const nativeMatches = element . matches || element . webkitMatchesSelector || element . msMatchesSelector ; return nativeMatches . call ( element , selector ) ; } ;