import noop from '../utils/noop' ; let supportsPassive = false ; try { const opts = Object . defineProperty ( { } , 'passive' , { get : ( ) => { supportsPassive = true ; return true ; } , } ) ; window . addEventListener ( 'test' , noop , opts ) ; } catch ( e ) { } interface IEEvent { attachEvent ( event , listener ) : boolean ; detachEvent ( event , listener ) : void ; } declare global { interface Element extends IEEvent { } interface Window extends IEEvent { } interface Document extends IEEvent { } } export default { supportsPassiveEvents : supportsPassive , on ( el , type , callback , options = { passive : false } ) { if ( el . addEventListener ) { el . addEventListener ( type , callback , supportsPassive ? options : false ) ; } else { el . attachEvent ( `on${ type }` , ( ) => { callback . call ( el ) ; } ) ; } } , off ( el , type , callback , options = { passive : false } ) { if ( el . removeEventListener ) { el . removeEventListener ( type , callback , supportsPassive ? options : false ) ; } else { el . detachEvent ( `on${ type }` , callback ) ; } } , once ( el , type , callback , options = { passive : false } ) { const typeArray = type . split ( ' ' ) ; const recursiveFunction = ( e ) => { if ( e . target ) { e . target . removeEventListener ( e . type , recursiveFunction , supportsPassive ? options : false ) ; } return callback ( e ) ; } ; for ( let i = typeArray . length - 1 ; i >= 0 ; i -= 1 ) { this . on ( el , typeArray [ i ] , recursiveFunction ) ; } } , } ;