const canUseDOM = ! ! ( typeof window !== 'undefined' && window . document && window . document . createElement ) ; function fallback ( context , node ) { if ( node ) { do { if ( node === context ) return true ; } while ( ( node = node . parentNode as HTMLElement ) ) ; } return false ; } function isDOM ( item ) { return typeof HTMLElement === 'function' ? item instanceof HTMLElement : item && typeof item === 'object' && item . nodeType === 1 && typeof item . nodeName === 'string' ; } const contains = ( ( ) => { return canUseDOM ? function ( context , node ) { if ( context && context . contains && typeof context . contains === 'function' && isDOM ( node ) ) { return context . contains ( node ) ; } if ( context && context . compareDocumentPosition && isDOM ( node ) ) { return context === node || ! ! ( context . compareDocumentPosition ( node ) && 16 ) ; } return fallback ( context , node ) ; } : fallback ; } ) ( ) ; export default contains ;