{"version":3,"file":"browser.js","sources":["src/Event.js","src/EventEmitter.js","index.js"],"sourcesContent":["const returnTrue = () => {\n return true;\n};\n\nconst returnFalse = () => {\n return false;\n};\n\nclass Event {\n\n /**\n * @param {*} target\n * @param {String} type\n * @param {Array} args\n */\n constructor(target, type, args) {\n Object.defineProperties(this, {\n 'target': {\n get : () => {\n return target;\n },\n set : () => {},\n enumerable: true\n },\n 'type' : {\n get : () => {\n return type;\n },\n set : () => {},\n enumerable: true\n },\n 'args' : {\n get : () => {\n return args;\n },\n set : () => {},\n enumerable: true\n }\n });\n\n this.isDefaultPrevented = returnFalse;\n this.isPropagationStopped = returnFalse;\n }\n\n preventDefault() {\n this.isDefaultPrevented = returnTrue;\n }\n\n stopPropagation() {\n this.isPropagationStopped = returnTrue;\n }\n\n}\n\nmodule.exports = Event;\n","const Event = require('./Event');\n\n/**\n * @typedef {Object.} Callbacks\n */\n\nclass EventEmitter {\n\n /**\n * Add one or many event handlers\n *\n * @example\n * obj.on('event', callback)\n * obj.on('event', listener) // listener has an `handleEvent` method\n * obj.on('event1 event2', callback)\n * obj.on({ event1: callback1, event2: callback2 })\n *\n * @param {String|Callbacks} events\n * @param {Function} [callback]\n * @return {this}\n */\n on(events, callback) {\n this.__events = this.__events || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n this.__events[event] = this.__events[event] || [];\n this.__events[event].push(events[event]);\n }\n }\n }\n else {\n events.split(' ').forEach((event) => {\n this.__events[event] = this.__events[event] || [];\n this.__events[event].push(callback);\n });\n }\n\n return this;\n }\n\n /**\n * Remove one or many or all event handlers\n *\n * @example\n * obj.off('event')\n * obj.off('event', callback)\n * obj.off('event1 event2')\n * obj.off({ event1: callback1, event2: callback2 })\n * obj.off()\n *\n * @param {String|Callbacks} [events]\n * @param {Function} [callback]\n * @return {this}\n */\n off(events, callback) {\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n if (this.__events && (event in this.__events)) {\n const index = this.__events[event].indexOf(events[event]);\n if (index !== -1) this.__events[event].splice(index, 1);\n }\n if (this.__once && (event in this.__once)) {\n const index = this.__once[event].indexOf(events[event]);\n if (index !== -1) this.__once[event].splice(index, 1);\n }\n }\n }\n }\n else if (!!events) {\n events.split(' ').forEach((event) => {\n if (this.__events && (event in this.__events)) {\n if (callback) {\n const index = this.__events[event].indexOf(callback);\n if (index !== -1) this.__events[event].splice(index, 1);\n }\n else {\n this.__events[event].length = 0;\n }\n }\n if (this.__once && (event in this.__once)) {\n if (callback) {\n const index = this.__once[event].indexOf(callback);\n if (index !== -1) this.__once[event].splice(index, 1);\n }\n else {\n this.__once[event].length = 0;\n }\n }\n });\n }\n else {\n this.__events = {};\n this.__once = {};\n }\n\n return this;\n }\n\n /**\n * Add one or many event handlers that will be called only once\n * This handlers are only applicable to \"trigger\", not \"change\"\n *\n * @example\n * obj.once('event', callback)\n * obj.once('event1 event2', callback)\n * obj.once({ event1: callback1, event2: callback2 })\n *\n * @param {String|Callbacks} events\n * @param {Function} [callback]\n * @return {this}\n */\n once(events, callback) {\n this.__once = this.__once || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n this.__once[event] = this.__once[event] || [];\n this.__once[event].push(events[event]);\n }\n }\n }\n else {\n events.split(' ').forEach((event) => {\n this.__once[event] = this.__once[event] || [];\n this.__once[event].push(callback);\n });\n }\n\n return this;\n }\n\n /**\n * Trigger all handlers for an event\n *\n * @param {String} event\n * @param {*...} [arguments]\n * @return {Event}\n */\n trigger(event /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 1);\n const e = new Event(this, event, args);\n\n if (this.__events && (event in this.__events)) {\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n const f = this.__events[event][i];\n if (typeof f === 'object') {\n f.handleEvent(e);\n }\n else {\n f.call(this, e, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n }\n\n if (this.__once && (event in this.__once)) {\n for (let i = 0, l = this.__once[event].length; i < l; i++) {\n const f = this.__once[event][i];\n if (typeof f === 'object') {\n f.handleEvent(e);\n }\n else {\n f.call(this, e, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n delete this.__once[event];\n }\n\n return e;\n }\n\n /**\n * Trigger all modificators for an event, each handler must return a value\n *\n * @param {String} event\n * @param {*} value\n * @param {*...} [arguments]\n * @return {*} modified value\n */\n change(event, value /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 2);\n const e = new Event(this, event, args);\n e.value = value;\n\n if (this.__events && event in this.__events) {\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n const f = this.__events[event][i];\n if (typeof f === 'object') {\n e.value = f.handleEvent(e);\n }\n else {\n e.value = f.call(this, e, e.value, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n }\n\n return e.value;\n }\n\n}\n\nmodule.exports = EventEmitter;\n","const EventEmitter = require('./src/EventEmitter');\nconst Event = require('./src/Event');\n\nfunction mixin(target) {\n target = typeof target === 'function' ? target.prototype : target;\n\n ['on', 'off', 'once', 'trigger', 'change'].forEach((name) => {\n target[name] = EventEmitter.prototype[name];\n });\n\n return target;\n}\n\nmodule.exports = {\n EventEmitter: EventEmitter,\n Event : Event,\n mixin : mixin,\n};\n"],"names":["returnTrue","returnFalse","Event","target","type","args","Object","defineProperties","get","set","enumerable","isDefaultPrevented","isPropagationStopped","preventDefault","stopPropagation","EventEmitter","on","events","callback","__events","event","hasOwnProperty","push","split","forEach","off","index","indexOf","splice","__once","length","once","trigger","Array","prototype","slice","call","arguments","e","i","l","f","handleEvent","change","value","mixin","name"],"mappings":";;;;;;;;;;;IAAA,IAAMA,UAAU,GAAG,SAAbA,UAAa,GAAM;IACrB,SAAO,IAAP;IACH,CAFD;;IAIA,IAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;IACtB,SAAO,KAAP;IACH,CAFD;;QAIMC;;IAGN;IACA;IACA;IACA;IACI,iBAAYC,MAAZ,EAAoBC,IAApB,EAA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