{"version":3,"file":"nanoevents.cjs","sources":["../../src/core/nanoevents.ts"],"sourcesContent":["/**\n * The MIT License (MIT)\n *\n * Copyright 2016 Andrey Sitnik <andrey@sitnik.ru>\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nexport type EventsMap = Record<string, (...args: any[]) => void>;\n\nexport interface Emitter<Events extends EventsMap> {\n    events: { [K in keyof Events]?: Array<Events[K]> };\n    emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): void;\n    on<K extends keyof Events>(event: K, cb: Events[K]): () => void;\n}\n\nexport const createNanoEvents = <Events extends EventsMap = EventsMap>(): Emitter<Events> => ({\n    emit(event, ...args) {\n        let callbacks = this.events[event] || []\n        for (let i = 0, length = callbacks.length; i < length; i++) {\n            callbacks[i](...args)\n        }\n    },\n    events: {},\n    on(event, cb) {\n        this.events[event]?.push(cb) || (this.events[event] = [cb])\n        return () => {\n            this.events[event] = this.events[event]?.filter(i => cb !== i)\n        }\n    }\n});"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;AAqBG;AAUI,MAAM,gBAAgB,GAAG,OAA8D;AAC1F,IAAA,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,EAAA;QACf,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE;AACxC,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AACxD,YAAA,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QACzB;IACJ,CAAC;AACD,IAAA,MAAM,EAAE,EAAE;IACV,EAAE,CAAC,KAAK,EAAE,EAAE,EAAA;;QACR,CAAA,CAAA,EAAA,GAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,IAAI,CAAC,EAAE,CAAC,MAAK,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC3D,QAAA,OAAO,MAAK;;YACR,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAA,EAAA,GAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAClE,QAAA,CAAC;IACL;AACH,CAAA;;;;"}