import {MagicEventBase} from "./base.js" import {GetDetail} from "./types/get-detail.js" import {Constructor} from "../toolbox/handy-types.js" import {DispatchOptions} from "./types/dispatch-options.js" export const ev = > & {readonly type: string}> (Event: E) => ({ target: (target: EventTarget) => ({ dispatch( detail: GetDetail>, options?: Partial, ) { target.dispatchEvent(new Event(Event.type, {...options, detail})) }, listen( listener: (event: InstanceType) => void, options?: boolean | AddEventListenerOptions, ) { target.addEventListener(Event.type, listener, options) return () => target .removeEventListener(Event.type, listener, options) }, }) })