const eventNames = [ 'click' , 'touchend' ] ; export default function ( el , callback ) { let isTouch = false ; function handler ( ev ) { if ( eventNames [ 1 ] === ev . type ) isTouch = true ; if ( eventNames [ 0 ] === ev . type && isTouch ) return ; if ( ! el . contains ( ev . target as Node ) ) { callback ( ev ) ; } } eventNames . forEach ( name => { document . addEventListener ( name , handler ) ; } ) ; return ( ) => { eventNames . forEach ( name => { document . removeEventListener ( name , handler ) ; } ) ; } ; }