'use strict' ; export interface Disposable { dispose : ( ) => void ; } export namespace DOM { export function on < K extends keyof DocumentEventMap , T extends Element > ( selector , name , listener , options ? , el ? ) ; export function on < K extends keyof DocumentEventMap , T extends Document | Element > ( el , name , listener , options ? ) ; export function on < K extends keyof WindowEventMap , T extends Window > ( el , name , listener , options ? ) ; export function on < K extends keyof ( DocumentEventMap | WindowEventMap ) , T extends Document | Element | Window > ( selectorOrElement , name , listener , options ? , el ? ) { let disposed = false ; if ( typeof selectorOrElement === 'string' ) { const $els = ( el ?? document ) . querySelectorAll ( selectorOrElement ) ; for ( const $el of $els ) { $el . addEventListener ( name , listener as EventListener , options ?? false ) ; } return { dispose : ( ) => { if ( disposed ) return ; disposed = true ; for ( const $el of $els ) { $el . removeEventListener ( name , listener as EventListener , options ?? false ) ; } } , } ; } selectorOrElement . addEventListener ( name , listener as EventListener , options ?? false ) ; return { dispose : ( ) => { if ( disposed ) return ; disposed = true ; selectorOrElement . removeEventListener ( name , listener as EventListener , options ?? false ) ; } , } ; } }