@creejs/commons-events
Version:
Commons EventEmitter
1 lines • 56.1 kB
Source Map (JSON)
{"version":3,"file":"index-dev.cjs","sources":["../../../lang/dist/esm/index-min.js","../../lib/constants.js","../../lib/listener.js","../../lib/event.js","../../lib/event-emitter.js"],"sourcesContent":["var t={constructorName:function(t){return t?.constructor?.name},defaults:function(t,...e){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n)void 0===t[e]&&(t[e]=n[e]);return t},extend:e,extends:e,equals:function(t,e){if(t===e)return!0;if(\"function\"==typeof t?.equals)return t.equals(e);if(\"function\"==typeof e?.equals)return e.equals(t);return!1},isBrowser:n,isNode:function(){return!n()}};function e(t,...e){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n)t[e]=n[e];return t}function n(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var r={isArray:o,isBoolean:i,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:s,isInstance:u,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:y,isPositive:l,isNegative:c,isNil:f,isNullOrUndefined:function(t){return null==t},isNull:a,isUndefined:p,isPlainObject:g,isObject:h,isPromise:w,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:d,isSymbol:m,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)}};function o(t){return Array.isArray(t)}function i(t){return\"boolean\"==typeof t}function s(t){return\"function\"==typeof t}function u(t){return null!=t&&\"object\"==typeof t&&!g(t)}function f(t){return null==t}function l(t){return!!y(t)&&t>0}function c(t){return!!y(t)&&t<0}function a(t){return null===t}function p(t){return void 0===t}function y(t){return null!=t&&\"number\"==typeof t}function h(t){return null!=t&&\"object\"==typeof t}function g(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function w(t){return null!=t&&\"function\"==typeof t.then}function d(t){return null!=t&&\"string\"==typeof t}function m(t){return null!=t&&\"symbol\"==typeof t}var b={assertNumber:$,assertPositive:function(t,e){if(!l(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Positive: ${t}`)},assertNegative:function(t,e){if(!c(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Negative: ${t}`)},assertBoolean:function(t,e){if(!i(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:v,assertPlainObject:function(t,e){if(!g(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,e){if(!m(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:E,assertInstance:function(t,e){if(!u(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:S,assertNil:function(t,e){if(!f(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:function(t,e){if(f(t))throw new Error((e?'\"'+e+'\" ':\" \")+\"Should Not Nil\")},assertNull:function(t,e){if(!a(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,e){if(a(t))throw new Error((e?'\"'+e+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,e){if(!p(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:O,assertArray:N,assertStringOrSymbol:function(t,e){if(!d(t)&&!m(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)}};function N(t,e){if(!Array.isArray(t))throw new Error(`${e?e+\"\":\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function O(t,e){if(!d(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function $(t,e){if(!y(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function v(t,e){if(!h(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function E(t,e){if(!s(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function S(t,e){if(!w(t))throw new Error(`${e?'\"'+e+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}var j={isEmpty:P,assertNotEmpty:x,isBlank:k,assertNotBlank:function(t){if(k(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(O(t),0===t.length)return t;const e=t.charAt(0),n=e.toUpperCase();return e===n?t:n+t.slice(1)},decapitalize:function(t){if(O(t),0===t.length)return t;const e=t.charAt(0),n=e.toLowerCase();return e===n?t:n+t.slice(1)},splitWithFixedLength:function(t,e,n=\" \"){if(O(t),$(e),O(n),0===t.length)return[];if(e<=0)throw new Error(\"length muse >=0\");if(t.length<e)return[t.padEnd(e,n)];const r=[];for(let o=0;o<t.length;o+=e){const i=t.substring(o,o+e);r.push(i.padEnd(e,n))}return r},split:function(t,...e){O(t);if(0===t.length)return[];const n=[...e];0===e.length&&e.push(\",\");const r=T(t,...n);if(0===r.length)return[];const o=[];let i=\"\",s=0;for(const{marker:e,index:n}of r)i=t.substring(s,n),o.push(i),s=n+e.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...e){if(O(t),0===e.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const r of new Set(e)){if(P(r))continue;O(r);let e=t.indexOf(r);for(;-1!==e;)n.push({marker:r,index:e}),e=t.indexOf(r,e+r.length)}return n.sort((t,e)=>t.index-e.index),n},findMarkerPositionsRegex:T,substringBefore:function(t,e){if(O(t),O(e),0===t.length||0===e.length)return;const n=t.indexOf(e);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,e){if(O(t),O(e),0===t.length||0===e.length)return;const n=t.lastIndexOf(e);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,e){if(O(t),O(e),0===t.length||0===e.length)return;const n=t.indexOf(e);if(-1===n)return;return t.substring(n+e.length)},substringAfterLast:function(t,e){if(O(t),O(e),0===t.length||0===e.length)return;const n=t.lastIndexOf(e);if(-1===n)return;return t.substring(n+e.length)},substringBetween:function(t,e,n){x(t),x(e),x(n);const r=t.indexOf(e);if(-1===r)return;const o=t.indexOf(n,r+e.length);if(-1===o)return;return t.substring(r+e.length,o)},substringBetweenGreedy:function(t,e,n){x(t),x(e),x(n);const r=t.indexOf(e);if(-1===r)return;const o=t.lastIndexOf(n);if(-1===o||o<=r)return;return t.substring(r+e.length,o)},substringsBetween:function(t,e,n){x(t),x(e),x(n);const r=[];let o=0;for(;;){const i=t.indexOf(e,o);if(-1===i)break;const s=t.indexOf(n,i+e.length);if(-1===s)break;r.push(t.substring(i+e.length,s)),o=s+n.length}return r}};function P(t){return null==t||(O(t),0===t.length)}function x(t){if(P(t))throw new Error(`Empty String: ${t}`)}function k(t){return null==t||(O(t),0===t.trim().length)}function T(t,...e){if(O(t),0===e.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(e.filter(t=>null!=t))].map(t=>(O(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),r=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=r.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:e[t-1],index:i.index});break}0===i[0].length&&r.lastIndex++}return o}var J={quiet:function(t){E(t);try{const e=t();return w(e)?e.catch(()=>{}):e}catch(t){}},quietKeepError:function(t,e){E(t),N(e);try{const n=t();return w(n)?n.catch(t=>e.push(t)):n}catch(t){e.push(t)}}},A={defer:B,delay:function(t,e){y(t)?(e=t,t=Promise.resolve()):null==t&&null==e&&(e=1,t=Promise.resolve());null!=t&&S(t),$(e=e??1e3);const n=B(),r=Date.now();return t.then((...t)=>{const o=Date.now()-r;o<e?setTimeout(()=>n.resolve(...t),e-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-r;o<e?setTimeout(()=>n.reject(t),e-o):n.reject(t)}),n.promise},timeout:function(t,e,n){S(t),$(e=e??1);const r=B(e,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=e?r.resolve(...t):r.reject(new Error(n??`Promise Timeout: ${e}ms`))}).catch(t=>{!r.resolved&&!r.rejected&&r.reject(t)}),r.promise},allSettled:U,returnValuePromised:C,series:async function(t){N(t);const e=[];for(const n of t)E(n),e.push(await n());return e},seriesAllSettled:async function(t){N(t);const e=[];for(const n of t){E(n);try{e.push({ok:!0,result:await n()})}catch(t){e.push({ok:!1,result:t})}}return e},parallel:async function(t,e=5){if(N(t),$(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>E(t));const n=[];if(t.length<=e){const e=await Promise.all(t.map(t=>C(t)));return n.push(...e),n}const r=[];for(const o of t)if(E(o),r.push(o),r.length>=e){const t=await Promise.all(r.map(t=>C(t)));n.push(...t),r.length=0}if(r.length>0&&r.length<e){const t=await Promise.all(r.map(t=>C(t)));n.push(...t)}return n},parallelAllSettled:async function(t,e=5){if(N(t),$(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>E(t));const n=[];if(t.length<=e){const e=await U(t.map(t=>C(t)));return n.push(...e),n}const r=[];for(const o of t)if(E(o),r.push(o),r.length>=e){const t=await U(r.map(t=>C(t)));n.push(...t),r.length=0}if(r.length>0&&r.length<e){const t=await U(r.map(t=>C(t)));n.push(...t)}return n}};function B(t=-1,e){$(t);const n={};let r;return t>=0&&(n.timerHandler=r=setTimeout(()=>{clearTimeout(r),n.timerCleared=!0,n.reject(new Error(e??`Promise Timeout: ${t}ms`))},t),n.timerHandler=r),n.promise=new Promise((t,e)=>{n.resolve=(...e)=>{null!=r&&(clearTimeout(r),n.timerCleared=!0),n.resolved=!0,t(...e)},n.reject=t=>{null!=r&&(clearTimeout(r),n.timerCleared=!0),n.rejected=!0,e(t)}}),n.promise.cancel=()=>{null!=r&&(clearTimeout(r),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function U(t){N(t);const e=await Promise.allSettled(t),n=[];for(const t of e)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function C(t){try{const e=t();return w(e)?e:Promise.resolve(e)}catch(t){return Promise.reject(t)}}const{isPlainObject:I}=r;var M={proxy:q,newProxyInstance:function(t,e,n,r=!0){const o=q(t,n,r);return Reflect.construct(o,e??[])}};function q(t,e,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=e){if(!I(e))throw new TypeError(`Not PropertyHandler: type=${typeof e}, value=${JSON.stringify(e)}`);const{get:t,set:n}=e;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const r={construct(t,r,o){const i=Reflect.construct(t,r);return new Proxy(n?Object.preventExtensions(i):i,e??{})}};return new Proxy(t,r)}var D={proxy:function(t,e,n=!0){if(f(t)||!h(t)||o(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,e??{})}};function L(t){v(t,\"obj\");const e=new Set;let n=t;for(;n&&n!==Object.prototype;){const r=Object.getOwnPropertyNames(n);for(const n of r)\"constructor\"!==n&&\"function\"==typeof t[n]&&e.add(n);n=Object.getPrototypeOf(n)}return[...new Set(e)]}var R={getMethodsOfClass:function(t){E(t,\"cls\");const e=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const r of t)\"constructor\"!==r&&\"function\"==typeof n[r]&&e.add(r);n=Object.getPrototypeOf(n)}return[...new Set(e)]},getStaticMethodsOfClass:function(t){E(t,\"cls\");const e=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const r of t)\"function\"==typeof n[r]&&e.add(r);n=Object.getPrototypeOf(n)}return[...e]},getMethods:L,getMethodsOfObject:L},H={LangUtils:t,StringUtils:j,TypeUtils:r,TypeAssert:b,ExecUtils:J,PromiseUtils:A,Lang:t,Type:r,Exec:J,ClassProxyUtils:M,InstanceProxyUtils:D,ReflectUtils:R};export{M as ClassProxyUtils,J as Exec,J as ExecUtils,D as InstanceProxyUtils,t as Lang,t as LangUtils,A as PromiseUtils,R as ReflectUtils,j as StringUtils,r as Type,b as TypeAssert,r as TypeUtils,H as default};\n//# sourceMappingURL=index-min.js.map\n","export const DefaultOwner = 'DOwner$#$'\nexport default {\n DefaultOwner\n}\n","// 3rd\n// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n\n// owned\nimport { DefaultOwner } from './constants.js'\n\n// module vars\nconst { assertFunction, assertNotNil } = TypeAssert\n/**\n * Wraps a function to be called when an event is fired.\n * @typedef {import('./event.js').default} Event\n * @class Listener\n */\nexport default class Listener {\n /**\n * @param {Event} event\n * @param {function} callback - The function to be called when event is fired\n * @param {boolean} [isOnce=false] - is a one time listener?\n */\n constructor (event, callback, isOnce = false) {\n assertNotNil(event, 'event')\n assertFunction(callback, 'callback')\n this._event = event\n this._callback = callback\n this._isOnce = !!isOnce // is Once Listener?\n this._owner = undefined\n }\n\n /**\n * Sets the owner of this listener.\n * @param {*} owner - The owner object to be associated with this listener.\n */\n set owner (owner) {\n this._owner = owner\n }\n\n get owner () {\n return this._owner === DefaultOwner ? undefined : this._owner\n }\n\n get event () {\n return this._event\n }\n\n get isOnce () {\n return this._isOnce\n }\n\n /**\n * Checks if the provided function is the same as the listener's wrapped function.\n * @param {Function} callback - The function to compare against.\n * @returns {boolean} True if the functions are the same, false otherwise.\n */\n isSameCallback (callback) {\n return this._callback === callback\n }\n\n get callback () {\n return this._callback\n }\n\n /**\n * Invokes the stored function with the provided arguments.\n * @param {...*} args - Arguments to pass to the function.\n * @returns {*} The result of the function invocation.\n */\n invoke (...args) {\n try {\n return this._callback(...args)\n } finally {\n if (this._isOnce) {\n try {\n this._event._remove(this)\n } catch (err) {\n // do nothing\n console.warn(err)\n }\n }\n }\n }\n\n /**\n * Invokes the listener with the provided arguments.\n * Alias for {@linkcode Listener.invoke}\n * @param {...*} args - Arguments to be passed to the listener.\n * @returns {*} The result of the listener invocation.\n */\n listener (...args) {\n return this.invoke(...args)\n }\n}\nexport { Listener as ListenerType }\n","// 3rd\n// internal\nimport { TypeUtils, TypeAssert } from '@creejs/commons-lang'\n\n// owned\n// eslint-disable-next-line no-unused-vars\nimport Listener from './listener.js'\nimport { DefaultOwner } from './constants.js'\n\n// module vars\nconst { isFunction, isNil } = TypeUtils\nconst { assertStringOrSymbol, assertFunction } = TypeAssert\n\n/**\n * An Event definition\n * 1. listeners are grouped by owner\n * * if not specified, group it into one Default owner\n * 2. one listener may belong to multiple owners\n * 3. one owner may have multiple listeners\n */\nexport default class Event {\n static get DefaultOwner () {\n return DefaultOwner\n }\n\n /**\n * Creates a new Event instance with the specified name.\n * @param {string|Symbol} eventName - The name of the event.\n */\n constructor (eventName) {\n assertStringOrSymbol(eventName, 'eventName')\n this._name = eventName\n /**\n * use Set to store unique listeners\n * @type {Set<function>}\n */\n this._callbacks = new Set()\n /**\n * @type {Array<Listener>}\n */\n this._listeners = [] // user array to keep order\n /**\n * @type {Map<function, Set<Listener>>}\n */\n this._callback2Listeners = new Map()\n /**\n * use listener to index owners. One Listener Instance only belongs to one owner\n * @type {Map<Listener, *>}\n */\n this._listener2Owner = new Map()\n /**\n * use \"owner\" to group listeners; one owner may have multiple listeners\n * @type {Map<*, Set<Listener>>}\n */\n this._owner2Listeners = new Map()\n }\n\n /**\n * Name of the event.\n * @returns {string|Symbol}\n */\n get name () {\n return this._name\n }\n\n isEmpty () {\n return this._callbacks.size === 0\n }\n\n /**\n * Returns a copy of the raw listeners array.\n * @returns {Array<Listener>} A shallow copy of the listeners array.\n */\n rawListeners () {\n return [...this._listeners]\n }\n\n /**\n * Returns the number of listeners listening for the event.\n * If callback is provided, it will return how many times the callback is found in the list of the listeners\n * @param {Function} [callback] - The callback function to count\n * @returns {number}\n */\n listenerCount (callback) {\n if (callback == null) {\n return this._listeners.length\n }\n return this._callback2Listeners.get(callback)?.size ?? 0\n }\n\n /**\n * Returns a shallow copy of the registered callbacks array.\n * if one callback function is added multiple times, it will be returned multiple times.\n * @returns {Array<function>} A new array containing all registered callbacks.\n */\n callbacks () {\n return [...this.rawListeners().map(listener => listener.callback)]\n }\n\n /**\n * Emits current event, invoking all registered listeners by order.\n * @param {...*} args - Arguments to be passed to each listener.\n * @returns {boolean} True if the event had listeners, false otherwise.\n */\n emit (...args) {\n if (this._listeners.length === 0) {\n return false\n }\n // Clone _listeners, it may be changed during call listener\n for (const listener of [...this._listeners]) {\n listener.invoke(...args)\n }\n return true\n }\n\n /**\n * Checks if listener is registered with this event.\n * @param {function} callback - The listener function to check.\n * @returns {boolean} True if the listener is registered, false otherwise.\n */\n hasListener (callback) {\n if (!isFunction(callback)) {\n return false\n }\n return this._callbacks.has(callback)\n }\n\n /**\n * Checks if owner has any registered listeners.\n * @param {*} owner - The owner to check for registered listeners.\n * @returns {boolean} True if the owner has listeners, false otherwise.\n */\n hasOwner (owner) {\n if (isNil(owner)) {\n return false\n }\n return this._owner2Listeners.has(owner)\n }\n\n /**\n * Adds an event listener\n * @param {function} callback - The callback function to be invoked when the event occurs.\n * @param {*} [owner] - use \"owner\" to group listeners, then can remove all listeners for an owner.\n * @returns {boolean} true if added, false otherwise.\n */\n addListener (callback, owner) {\n return this._addListener(callback, owner, false, false)\n }\n\n /**\n * Prepends a listener callback to the beginning of the listeners array.\n * No checks are made to see if the listener has already been added.\n * Multiple calls passing the same combination of eventName and listener will result in the listener being added,\n * and called, multiple times.\n * @param {Function} callback - The callback function to be executed when the event is emitted.\n * @param {Object} owner - The owner object to which the listener belongs.\n * @returns {boolean}\n */\n prependListener (callback, owner) {\n return this._addListener(callback, owner, false, true)\n }\n\n /**\n * Adds a one-time listener for the event. The listener is automatically removed after being invoked once.\n * @param {Function} callback - The function to call when the event is triggered.\n * @param {Object} [owner] - The object that owns the callback (used for binding `this` context).\n * @returns {boolean}\n */\n addOnceListener (callback, owner) {\n return this._addListener(callback, owner, true, false)\n }\n\n /**\n * Adds a one-time event listener that will be automatically removed after being triggered once.\n * The listener will only be triggered if the event is pretended (simulated).\n * @param {Function} callback - The function to call when the event is triggered.\n * @param {Object} owner - The object that owns the listener (used for reference tracking).\n * @returns {boolean} The listener function that was added.\n */\n prependOnceListener (callback, owner) {\n return this._addListener(callback, owner, true, true)\n }\n\n /**\n * Adds a listener for the event.\n * @param {Function} callback - The callback function to be executed when the event occurs\n * @param {*} [owner] - The owner object that the listener belongs to (defaults to DeaultOwner)\n * @param {boolean} [isOnce=false] - Whether the listener should be removed after first invocation\n * @param {boolean} [isPrepend=false] - Whether the listener should be inert at the beginning of the listeners array\n * @returns {boolean} Returns true if listener was added successfully, false if callback is nil or duplicate\n * @protected\n */\n _addListener (callback, owner, isOnce, isPrepend) {\n if (isNil(callback)) {\n return false\n }\n assertFunction(callback)\n if (!this._callbacks.has(callback)) {\n this._callbacks.add(callback)\n }\n // a listener must belong to an owner\n owner = owner ?? DefaultOwner\n\n // use Listener to wrap callback\n const listener = new Listener(this, callback, isOnce)\n listener.owner = owner\n if (isPrepend) {\n this._listeners.unshift(listener)\n } else {\n this._listeners.push(listener)\n }\n\n // index, rapadly find one listener's owner\n this._listener2Owner.set(listener, owner)\n\n // one callback function may be registered many times\n let callbackListeners = this._callback2Listeners.get(callback)\n if (callbackListeners == null) {\n callbackListeners = new Set()\n this._callback2Listeners.set(callback, callbackListeners)\n }\n callbackListeners.add(listener)\n\n // group by owner\n let ownerListeners = this._owner2Listeners.get(owner)\n if (ownerListeners == null) {\n ownerListeners = new Set()\n this._owner2Listeners.set(owner, ownerListeners)\n }\n ownerListeners.add(listener)\n\n return true\n }\n\n /**\n * Removes a callback\n * @param {Function} callback - The callback function to remove.\n * @returns {boolean} true if removed, false otherwise.\n */\n removeListener (callback) {\n if (isNil(callback)) {\n return false\n }\n if (!this._callbacks.has(callback)) {\n return false\n }\n this._callbacks.delete(callback)\n\n const listeners = this._callback2Listeners.get(callback)\n if (listeners == null) { // should not happen\n return false\n }\n this._callback2Listeners.delete(callback)\n for (const listener of listeners) {\n // remove from global index\n const index = this._listeners.indexOf(listener)\n index !== -1 && this._listeners.splice(this._listeners.indexOf(listener), 1)\n\n // remove from owner index\n const owner = this._listener2Owner.get(listener)\n if (owner == null) {\n continue\n }\n this._listener2Owner.delete(listener)\n const ownerListeners = this._owner2Listeners.get(owner)\n if (ownerListeners == null) {\n continue\n }\n ownerListeners.delete(listener)\n if (ownerListeners.size === 0) {\n this._owner2Listeners.delete(owner)\n }\n }\n return true\n }\n\n /**\n * Removes a listener from both global and owner indexes.\n * @param {Listener} listener - The listener function to remove\n */\n _remove (listener) {\n // remove from global index\n const index = this._listeners.indexOf(listener)\n index !== -1 && this._listeners.splice(index, 1)\n\n // clean callback index\n const { callback } = listener\n const callbackListeners = this._callback2Listeners.get(callback)\n if (callbackListeners != null) {\n callbackListeners.delete(listener)\n if (callbackListeners.size === 0) {\n this._callback2Listeners.delete(callback)\n this._callbacks.delete(callback)\n }\n }\n\n // remove from owner index\n const owner = this._listener2Owner.get(listener)\n if (owner == null) {\n return\n }\n this._listener2Owner.delete(listener)\n const ownerListeners = this._owner2Listeners.get(owner)\n if (ownerListeners == null) {\n return\n }\n ownerListeners.delete(listener)\n if (ownerListeners.size === 0) {\n this._owner2Listeners.delete(owner)\n }\n }\n\n /**\n * Removes all event listeners\n * @param {*} [owner] - Without owner, all listeners will be removed; otherwise, only listeners of \"owner\" will be removed.\n * @returns {this}\n */\n removeAllListeners (owner) {\n // remove listeners of owner\n if (isNil(owner)) {\n // remove all Listeners\n this._callbacks.clear()\n this._listeners.length = 0\n this._callback2Listeners.clear()\n this._listener2Owner.clear()\n this._owner2Listeners.clear()\n return this\n }\n // all listeners of the owner\n const ownerListeners = this._owner2Listeners.get(owner)\n // no owner\n if (ownerListeners == null) {\n return this\n }\n // clear owner index\n this._owner2Listeners.delete(owner)\n // clearn listeners of owner one by one\n for (const listener of ownerListeners) {\n // remove from global index\n const index = this._listeners.indexOf(listener)\n index !== -1 && this._listeners.splice(this._listeners.indexOf(listener), 1)\n\n // clean listener-owner index\n this._listener2Owner.delete(listener)\n\n // one callback function may be registered many times, has many Listeners\n const { callback } = listener\n const callbackListeners = this._callback2Listeners.get(callback)\n if (callbackListeners == null) {\n continue\n }\n callbackListeners.delete(listener)\n if (callbackListeners.size === 0) {\n this._callback2Listeners.delete(callback)\n this._callbacks.delete(callback)\n }\n }\n return this\n }\n}\n\nexport { Event as EventType }\n","// 3rd\n// internal\nimport { TypeUtils, TypeAssert } from '@creejs/commons-lang'\n\n// owned\nimport Event from './event.js'\n// eslint-disable-next-line no-unused-vars\nimport Listener from './listener.js'\n\n// module vars\nconst { isNil } = TypeUtils\nconst {\n assertString, assertFunction, assertNumber,\n assertStringOrSymbol, assertNotNil\n} = TypeAssert\n\n/**\n * methods allowed to mixin other objects\n */\nconst MixinMethods = [\n 'on', 'once', 'addListener', 'prependListener', 'prependOnceListener',\n 'off', 'offAll', 'offOwner', 'removeAllListeners', 'removeListener',\n 'emit', 'setMaxListeners', 'getMaxListeners', 'hasOwner',\n 'listeners', 'listenerCount', 'eventNames', 'rawListeners'\n]\nlet DefaultMaxListeners = 10\n/**\n * 1. An EventEmitter follows the API of NodeJS EventEmitter.\n * 2. Enhancement:\n * * Listeners are grouped by \"owner\".\n * * Operation via \"owner\"\n * * Duplicate listeners are filtered out. Only unique One kept.\n */\nexport default class EventEmitter {\n /**\n * Mixes EventEmitter methods into the given object.\n * @template T\n * @param {T} obj - The target object to mix methods into.\n * @returns {T} The modified object with EventEmitter methods.\n */\n static mixin (obj) {\n const emitter = new EventEmitter()\n // @ts-ignore\n obj.__emitter = emitter\n for (const name of MixinMethods) {\n // @ts-ignore\n const method = emitter[name]\n // @ts-ignore\n obj[name] = method.bind(emitter)\n }\n return obj\n }\n\n static get defaultMaxListeners () {\n return DefaultMaxListeners\n }\n\n static set defaultMaxListeners (maxListeners) {\n assertNumber(maxListeners)\n DefaultMaxListeners = maxListeners ?? 10\n }\n\n /**\n */\n constructor () {\n /**\n * @type {Map<string|Symbol, Event>}\n */\n this._name2Event = new Map()\n this._maxListeners = DefaultMaxListeners\n }\n\n /**\n * Alias of {@linkcode EventEmitter.addListener}\n * @param {string|Symbol} eventName\n * @param {function} listener\n * @param {*} [owner]\n * @returns {this}\n */\n addListener (eventName, listener, owner) {\n return this.on(eventName, listener, owner)\n }\n\n /**\n * Adds the listener function to the beginning of the listeners array for the event named eventName.\n * @param {string|Symbol} eventName\n * @param {function} listener\n * @param {*} [owner]\n * @returns {this}\n */\n prependListener (eventName, listener, owner) {\n assertString(eventName)\n assertFunction(listener)\n this._checkMaxListeners(eventName)\n\n const event = this._getOrCreateEvent(eventName)\n event.prependListener(listener, owner)\n return this\n }\n\n /**\n * Adds a one-time listener function for the event named eventName to the beginning of the listeners array.\n * @param {string|Symbol} eventName\n * @param {function} listener\n * @param {*} [owner]\n * @returns {this}\n */\n prependOnceListener (eventName, listener, owner) {\n assertString(eventName)\n assertFunction(listener)\n this._checkMaxListeners(eventName)\n\n const event = this._getOrCreateEvent(eventName)\n event.prependOnceListener(listener, owner)\n return this\n }\n\n /**\n * Synchronously calls each of the listeners registered for the event named eventName,\n * in the order they were registered, passing the supplied arguments to each.\n * Returns true if the event had listeners, false otherwise.\n * @param {string|Symbol} eventName - The name of the event.\n * @param {...*} args arguments to pass to the listeners.\n * @returns {boolean}\n */\n emit (eventName, ...args) {\n const event = this._name2Event.get(eventName)\n if (event == null || event.isEmpty()) {\n return false\n }\n event.emit(...args)\n return true\n }\n\n /**\n * Returns an array listing the events for which the emitter has registered listeners.\n * @returns {Array<string|Symbol>} An array of event names.\n */\n eventNames () {\n return [...this._name2Event.keys()]\n }\n\n getMaxListeners () {\n return this._maxListeners\n }\n\n /**\n * Returns the number of listeners listening for the event named eventName.\n * If listener is provided, it will return how many times the listener is found\n * in the list of the listeners of the event.\n * @param {string|Symbol} eventName - The name of the event to check\n * @param {function} [listener] - Optional specific listener to count\n * @returns {number} The number of listeners for the event\n */\n listenerCount (eventName, listener) {\n assertStringOrSymbol(eventName, 'eventName')\n const event = this._name2Event.get(eventName)\n if (event == null || event.isEmpty()) {\n return 0\n }\n return event.listenerCount(listener)\n }\n\n /**\n * Returns a copy of the array of listeners for the event named eventName.\n * 1. if a callback function added multiple times, it will be returned multiple times.\n * @param {string} eventName\n * @returns {Array<function>}\n */\n listeners (eventName) {\n assertStringOrSymbol(eventName, 'eventName')\n const event = this._name2Event.get(eventName)\n if (event == null || event.isEmpty()) {\n return []\n }\n return event.callbacks()\n }\n\n /**\n * Removes a callback function from a specific event.\n * 1. If the event doesn't exist or has no listeners, do nothing\n * 2. if one callback function added multiple times, all of them will be removed.\n * * !!! This is different from the behavior of Node.js EventEmitter.\n *\n * @param {string} eventName - The name of the event to remove callback from\n * @param {function} callback - The callback function to remove\n * @returns {EventEmitter} Returns the emitter instance for chaining\n */\n off (eventName, callback) {\n const event = this._name2Event.get(eventName)\n if (event == null) {\n return this\n }\n event.removeListener(callback)\n if (event.isEmpty()) {\n this._name2Event.delete(eventName)\n return this\n }\n return this\n }\n\n /**\n * Removes all listeners for the specified event.\n * if owner is limited, only the listeners of the owner will be removed.\n *\n * @param {string|Symbol} eventName - The name of the event to clear listeners for.\n * @param {*} owner - The owner whose listeners should be removed.\n * @returns {EventEmitter} The emitter instance for chaining.\n */\n offAll (eventName, owner) {\n assertStringOrSymbol(eventName, 'eventName')\n const event = this._name2Event.get(eventName)\n if (event == null) {\n return this\n }\n event.removeAllListeners(owner)\n if (event.isEmpty()) {\n this._name2Event.delete(eventName)\n return this\n }\n return this\n }\n\n /**\n * Removes all event listeners belonging to the specified owner.\n * @param {*} owner - The owner whose listeners should be removed.\n * @returns {this}\n */\n offOwner (owner) {\n assertNotNil(owner, 'owner')\n const events = [...this._name2Event.values()]\n for (const event of events) {\n event.removeAllListeners(owner)\n if (event.isEmpty()) {\n this._name2Event.delete(event.name)\n }\n }\n return this\n }\n\n /**\n * Adds the listener function to the end of the listeners array for the event named eventName.\n * @param {string|Symbol} eventName\n * @param {function} callback\n * @param {*} [owner]\n * @returns {this}\n */\n on (eventName, callback, owner) {\n assertString(eventName)\n assertFunction(callback)\n this._checkMaxListeners(eventName)\n\n const event = this._getOrCreateEvent(eventName)\n event.addListener(callback, owner)\n return this\n }\n\n /**\n * Checks if the number of listeners for the given event exceeds the maximum allowed.\n * Emits a warning if the listener count reaches or exceeds the maxListeners threshold.\n * @private\n * @param {string|Symbol} eventName - The name of the event to check\n * @returns {void}\n */\n _checkMaxListeners (eventName) {\n let listenerCount = 0\n if (this._maxListeners !== 0 && this._maxListeners !== Infinity && (listenerCount = this.listenerCount(eventName)) >= this._maxListeners) {\n console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${listenerCount} ${eventName} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`)\n }\n }\n\n /**\n * Adds a listener that will be invoked only once for the event named eventName.SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit`)\n }\n }\n\n /**\n * Adds a one-time callback function for the specified event.\n * The callback is invoked only once and then automatically removed.\n *\n * @param {string} eventName - The name of the event to listen for.\n * @param {Function} callback - The callback function to execute when the event is emitted.\n * @param {*} [owner] - Optional owner used to group listener callbacks.\n * @returns {EventEmitter} Returns the emitter instance for chaining.\n */\n once (eventName, callback, owner) {\n assertString(eventName)\n assertFunction(callback)\n\n const event = this._getOrCreateEvent(eventName)\n event.addOnceListener(callback, owner)\n return this\n }\n\n /**\n * Returns a copy of the array of listeners for the event named eventName,\n * including any wrappers (such as those created by .once()).\n * @param {string} eventName - The name of the event.\n * @returns {Listener[]} An array of raw listener functions, or empty array if none exist.\n */\n rawListeners (eventName) {\n return this._name2Event.get(eventName)?.rawListeners() || []\n }\n\n /**\n * Alias of {@linkcode EventEmitter.offAll}\n * @param {string|Symbol} eventName - The name of the event to remove listeners for.\n * @param {*} owner - The owner of the listeners to be removed.\n * @returns {EventEmitter} The emitter instance for chaining.\n */\n removeAllListeners (eventName, owner) {\n return this.offAll(eventName, owner)\n }\n\n /**\n * Alias of {@linkcode EventEmitter.off}\n * @param {string} eventName - The name of the event.\n * @param {Function} callback - The callback function to remove.\n * @returns {EventEmitter} The emitter instance for chaining.\n */\n removeListener (eventName, callback) {\n return this.off(eventName, callback)\n }\n\n /**\n * Sets the maximum number of listeners that can be added to this event emitter.\n * @param {number} max - The maximum number of listeners.\n * @returns {this} The set maximum number of listeners.\n */\n setMaxListeners (max) {\n assertNumber(max)\n if (max < 0) {\n throw new RangeError('maxListeners must >=0')\n }\n this._maxListeners = max\n return this\n }\n\n /**\n * Gets an existing event by name or creates a new one if it doesn't exist.\n * @private\n * @param {string|Symbol} eventName - The name of the event to get or create.\n * @returns {Event} The existing or newly created Event instance.\n */\n _getOrCreateEvent (eventName) {\n if (this._name2Event.has(eventName)) {\n // @ts-ignore\n return this._name2Event.get(eventName)\n }\n const event = new Event(eventName)\n this._name2Event.set(eventName, event)\n return event\n }\n\n /**\n * Checks if the specified owner has any registered events.\n * @param {Object} owner - The owner object to check for registered events.\n * @returns {boolean} True if the owner has any registered events, false otherwise.\n */\n hasOwner (owner) {\n if (isNil(owner)) {\n return false\n }\n for (const event of this._name2Event.values()) {\n if (event.hasOwner(owner)) {\n return true\n }\n }\n return false\n }\n}\n\nexport { EventEmitter as EventEmitterType }\n"],"names":["assertFunction","assertNotNil","TypeAssert","isNil","TypeUtils","assertStringOrSymbol"],"mappings":";;;;AAAkrB,IAAI,CAAC,CAAC,CAAgF,UAAU,CAAC,CAAC,CAA6Y,KAAK,CAAC,CAA0hB,CAAC,CAA+E,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAM,UAAU,EAAE,OAAO,CAAC,CAAyD,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAA+H,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAA8M,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAqmB,cAAc,CAAC,CAAC,CAA8S,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAoW,YAAY,CAAC,CAAC,CAAe,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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