@creejs/commons-collection 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==typeof t}function l$1(t){return null!=t&&"object"==typeof t&&!A(t)}function y(t){return null==t}function p$1(t){return !!m$1(t)&&t>0}function h$1(t){return !!m$1(t)&&t>=0}function g$1(t){return !!m$1(t)&&t<0}function w$1(t){return null===t}function d$1(t){return void 0===t}function m$1(t){return null!=t&&"number"==typeof t}function b$1(t){return null!=t&&"object"==typeof t}function A(t){return null!==t&&"object"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function E(t){return null!=t&&"function"==typeof t.then}function N(t){return null!=t&&"string"==typeof t}function $(t){return null!=t&&"symbol"==typeof t}function O$1(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v$1(t){return t instanceof Int8Array}function j(t){return t instanceof Uint8Array}function P(t){return t instanceof Uint8ClampedArray}function S(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function I(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function k$1(t){return t instanceof BigInt64Array}function L$1(t){return t instanceof BigUint64Array}function F(t){return t instanceof ArrayBuffer}var C={assertNumber:q,assertPositive:_$1,assertNegative:function(t,r){if(!g$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Negative: ${t}`)},assertNotNegative:J,assertBoolean:function(t,r){if(!a$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Boolean: type=${typeof t} value=${Z(t)}`)},assertObject:R,assertPlainObject:function(t,r){if(!A(t))throw new Error(`${r?'"'+r+'" ':""}Not PlainObject: type=${typeof t} value=${Z(t)}`)},assertSymbol:function(t,r){if(!$(t))throw new Error(`${r?'"'+r+'" ':""}Not Symbol: type=${typeof t} value=${Z(t)}`)},assertFunction:W,assertInstance:function(t,r){if(!l$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Class Instance: type=${typeof t} value=${Z(t)}`)},assertPromise:H,assertNil:function(t,r){if(!y(t))throw new Error(`${r?'"'+r+'" ':""}Neither Null nor Undefined: type=${typeof t} value=${Z(t)}`)},assertNotNil:V,assertNull:function(t,r){if(!w$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Null: type=${typeof t} value=${Z(t)}`)},assertNotNull:function(t,r){if(w$1(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Null")},assertUndefined:function(t,r){if(!d$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Undefined: type=${typeof t} value=${Z(t)}`)},assertString:M,assertArray:D,assertStringOrSymbol:function(t,r){if(!N(t)&&!$(t))throw new Error(`${r?'"'+r+'" ':""}Not String or Symbol: type=${typeof t} value=${Z(t)}`)},assertInt8Array:function(t,r){if(v$1(t))throw new Error((r?'"'+r+'" ':"")+"Not Int8Array")},assertUint8Array:function(t,r){if(j(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8Array")},assertUint8ClampedArray:function(t,r){if(P(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8ClampedArray")},assertInt16Array:function(t,r){if(S(t))throw new Error((r?'"'+r+'" ':"")+"Not Int16Array")},assertUint16Array:function(t,r){if(x(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint16Array")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'"'+r+'" ':"")+"Not Int32Array")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint32Array")},assertFloat32Array:function(t,r){if(I(t))throw new Error((r?'"'+r+'" ':"")+"Not Float32Array")},assertFloat64Array:function(t,r){if(B(t))throw new Error((r?'"'+r+'" ':"")+"Not Float64Array")},assertBigInt64Array:function(t,r){if(k$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigInt64Array")},assertBigUint64Array:function(t,r){if(L$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigUint64Array")},assertTypedArray:function(t,r){if(O$1(t))throw new Error((r?'"'+r+'" ':"")+"Not TypedArray")},assertArrayBuffer:z};function D(t,r){if(!Array.isArray(t))throw new Error(`${r?'"'+r+'" ':""}Not Array: type=${typeof t} value=${Z(t)}`)}function M(t,r){if(!N(t))throw new Error(`${r?'"'+r+'" ':""}Not String: type=${typeof t} value=${Z(t)}`)}function q(t,r){if(!m$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Number: type=${typeof t} value=${Z(t)}`)}function _$1(t,r){if(!p$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Positive: ${t}`)}function J(t,r){if(!h$1(t))throw new Error(`${r?'"'+r+'" ':""}Not "0 or Positive": ${t}`)}function R(t,r){if(!b$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Object: type=${typeof t} value=${Z(t)}`)}function W(t,r){if(!c$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Function: type=${typeof t} value=${Z(t)}`)}function H(t,r){if(!E(t))throw new Error(`${r?'"'+r+'" ':""}Not Promise: type=${typeof t} value=${Z(t)}`)}function V(t,r){if(y(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Nil")}function z(t,r){if(!F(t))throw new Error((r?'"'+r+'" ':"")+"Not ArrayBuffer")}function Z(t){if(null===t)return "null";if(void 0===t)return "undefined";let r;try{r=JSON.stringify(t);}catch(e){r=t.toString();}return r}new TextDecoder;new TextEncoder;const dt=1e6;var mt={s2ns:1e9,ms2ns:dt,timestamp:function(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/dt)}return Date.now()},timestamp64:bt,lapseNano:At,lapseMillis:Et,timeoutNano:function(t,r){return At(t)>r},timeoutMillis:function(t,r){return Et(t)>r}};function bt(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*dt)}return BigInt(Date.now()*dt)}function At(t,r){return (r??bt())-t}function Et(t,r){r=r??bt();return BigInt(r-t)/BigInt(dt)}
1
+ function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==typeof t}function l$1(t){return null!=t&&"object"==typeof t&&!A(t)}function y(t){return null==t}function p$1(t){return !!m$1(t)&&t>0}function h$1(t){return !!m$1(t)&&t>=0}function g$1(t){return !!m$1(t)&&t<0}function w$1(t){return null===t}function d$1(t){return void 0===t}function m$1(t){return null!=t&&"number"==typeof t}function b$1(t){return null!=t&&"object"==typeof t}function A(t){return null!==t&&"object"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function E(t){return null!=t&&"function"==typeof t.then}function N(t){return null!=t&&"string"==typeof t}function $(t){return null!=t&&"symbol"==typeof t}function O$1(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v$1(t){return t instanceof Int8Array}function P(t){return t instanceof Uint8Array}function j(t){return t instanceof Uint8ClampedArray}function S(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function I(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function k$1(t){return t instanceof BigInt64Array}function L$1(t){return t instanceof BigUint64Array}function F(t){return t instanceof ArrayBuffer}var C={assertNumber:q,assertPositive:_$1,assertNegative:function(t,r){if(!g$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Negative: ${t}`)},assertNotNegative:R,assertBoolean:function(t,r){if(!a$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Boolean: type=${typeof t} value=${Z(t)}`)},assertObject:J,assertPlainObject:function(t,r){if(!A(t))throw new Error(`${r?'"'+r+'" ':""}Not PlainObject: type=${typeof t} value=${Z(t)}`)},assertSymbol:function(t,r){if(!$(t))throw new Error(`${r?'"'+r+'" ':""}Not Symbol: type=${typeof t} value=${Z(t)}`)},assertFunction:W,assertInstance:function(t,r){if(!l$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Class Instance: type=${typeof t} value=${Z(t)}`)},assertPromise:H,assertNil:function(t,r){if(!y(t))throw new Error(`${r?'"'+r+'" ':""}Neither Null nor Undefined: type=${typeof t} value=${Z(t)}`)},assertNotNil:V,assertNull:function(t,r){if(!w$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Null: type=${typeof t} value=${Z(t)}`)},assertNotNull:function(t,r){if(w$1(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Null")},assertUndefined:function(t,r){if(!d$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Undefined: type=${typeof t} value=${Z(t)}`)},assertString:D,assertArray:M,assertStringOrSymbol:function(t,r){if(!N(t)&&!$(t))throw new Error(`${r?'"'+r+'" ':""}Not String or Symbol: type=${typeof t} value=${Z(t)}`)},assertInt8Array:function(t,r){if(v$1(t))throw new Error((r?'"'+r+'" ':"")+"Not Int8Array")},assertUint8Array:function(t,r){if(P(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8Array")},assertUint8ClampedArray:function(t,r){if(j(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8ClampedArray")},assertInt16Array:function(t,r){if(S(t))throw new Error((r?'"'+r+'" ':"")+"Not Int16Array")},assertUint16Array:function(t,r){if(x(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint16Array")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'"'+r+'" ':"")+"Not Int32Array")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint32Array")},assertFloat32Array:function(t,r){if(I(t))throw new Error((r?'"'+r+'" ':"")+"Not Float32Array")},assertFloat64Array:function(t,r){if(B(t))throw new Error((r?'"'+r+'" ':"")+"Not Float64Array")},assertBigInt64Array:function(t,r){if(k$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigInt64Array")},assertBigUint64Array:function(t,r){if(L$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigUint64Array")},assertTypedArray:function(t,r){if(O$1(t))throw new Error((r?'"'+r+'" ':"")+"Not TypedArray")},assertArrayBuffer:z};function M(t,r){if(!Array.isArray(t))throw new Error(`${r?'"'+r+'" ':""}Not Array: type=${typeof t} value=${Z(t)}`)}function D(t,r){if(!N(t))throw new Error(`${r?'"'+r+'" ':""}Not String: type=${typeof t} value=${Z(t)}`)}function q(t,r){if(!m$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Number: type=${typeof t} value=${Z(t)}`)}function _$1(t,r){if(!p$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Positive: ${t}`)}function R(t,r){if(!h$1(t))throw new Error(`${r?'"'+r+'" ':""}Not "0 or Positive": ${t}`)}function J(t,r){if(!b$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Object: type=${typeof t} value=${Z(t)}`)}function W(t,r){if(!c$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Function: type=${typeof t} value=${Z(t)}`)}function H(t,r){if(!E(t))throw new Error(`${r?'"'+r+'" ':""}Not Promise: type=${typeof t} value=${Z(t)}`)}function V(t,r){if(y(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Nil")}function z(t,r){if(!F(t))throw new Error((r?'"'+r+'" ':"")+"Not ArrayBuffer")}var G={isEmpty:K,assertNotEmpty:Y,isBlank:Q,assertNotBlank:function(t,r){if(Q(t))throw new Error(`${r?'"'+r+'" ':""}Is Blank: ${t}`)},capitalize:function(t){if(D(t),0===t.length)return t;const r=t.charAt(0),e=r.toUpperCase();return r===e?t:e+t.slice(1)},decapitalize:function(t){if(D(t),0===t.length)return t;const r=t.charAt(0),e=r.toLowerCase();return r===e?t:e+t.slice(1)},splitWithFixedLength:function(t,r,e=" "){if(D(t),q(r),D(e),0===t.length)return [];if(r<=0)throw new Error("length muse >=0");if(t.length<r)return [t.padEnd(r,e)];const n=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);n.push(i.padEnd(r,e));}return n},split:function(t,...r){D(t);if(0===t.length)return [];const e=[...r];0===r.length&&r.push(",");const n=X(t,...e);if(0===n.length)return [];const o=[];let i="",s=0;for(const{marker:r,index:e}of n)i=t.substring(s,e),o.push(i),s=e+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(D(t),0===r.length)throw new Error("At least one marker must be provided");const e=[];for(const n of new Set(r)){if(K(n))continue;D(n);let r=t.indexOf(n);for(;-1!==r;)e.push({marker:n,index:r}),r=t.indexOf(n,r+n.length);}return e.sort((t,r)=>t.index-r.index),e},findMarkerPositionsRegex:X,substringBefore:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(0,e)},substringBeforeLast:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(0,e)},substringAfter:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringAfterLast:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.indexOf(e,n+r.length);if(-1===o)return;return t.substring(n+r.length,o)},substringBetweenGreedy:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.lastIndexOf(e);if(-1===o||o<=n)return;return t.substring(n+r.length,o)},substringsBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(e,i+r.length);if(-1===s)break;n.push(t.substring(i+r.length,s)),o=s+e.length;}return n},safeToString:Z};function K(t){return null==t||(D(t),0===t.length)}function Y(t,r){if(K(t))throw new Error(`${r?'"'+r+'" ':""}IsEmpty String: ${t}`)}function Q(t){return null==t||(D(t),0===t.trim().length)}function X(t,...r){if(D(t),0===r.length)throw new Error("At least one marker must be provided");const e=[...new Set(r.filter(t=>null!=t))].map(t=>(D(t),t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))),n=new RegExp(e.map(t=>`(${t})`).join("|"),"g"),o=[];let i=null;for(;null!==(i=n.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&n.lastIndex++;}return o}function Z(t){if(null===t)return "null";if(void 0===t)return "undefined";const r=typeof t;if("string"===r)return t;if("symbol"===r)return `Symbol(${t.description})`;if("function"===r)return `Function ${t.name}(){}`;if(t instanceof String)return t.toString();if(Number.isNaN(t))return "NaN";if(t===1/0)return "Infinity";if(t===-1/0)return "-Infinity";if(t instanceof Error)return `${t.constructor.name}: ${t.message}`;if(t instanceof Promise)return "Promise";if(t instanceof Set)return `Set: ${Z(Array.from(t))}`;if(t instanceof Map)return `Map: ${Z(Array.from(t.entries()))}`;if(t instanceof RegExp)return t.toString();if(Array.isArray(t))return `[${t.map(Z).join(", ")}]`;let e;try{e=JSON.stringify(t);}catch(r){e=t.toString();}return e}new TextDecoder;new TextEncoder;const dt=1e6;var mt={s2ns:1e9,ms2ns:dt,timestamp:function(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/dt)}return Date.now()},timestamp64:bt,lapseNano:At,lapseMillis:Et,timeoutNano:function(t,r){return At(t)>r},timeoutMillis:function(t,r){return Et(t)>r}};function bt(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*dt)}return BigInt(Date.now()*dt)}function At(t,r){return (r??bt())-t}function Et(t,r){r=r??bt();return BigInt(r-t)/BigInt(dt)}
2
2
 
3
3
  // internal
4
4
  // owned
@@ -12,7 +12,7 @@ function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==ty
12
12
  */
13
13
 
14
14
  // module vars
15
- const { assertPositive } = C;
15
+ const { assertPositive: assertPositive$2 } = C;
16
16
 
17
17
  /**
18
18
  * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
@@ -27,7 +27,7 @@ class CappedSet {
27
27
  * @throws {Error} If capacity is less than or equal to 0
28
28
  */
29
29
  constructor (capacity) {
30
- assertPositive(capacity, 'capacity');
30
+ assertPositive$2(capacity, 'capacity');
31
31
  this.capacity = capacity;
32
32
  /**
33
33
  * 1. key is the Value stored in CappedSet
@@ -171,7 +171,7 @@ class CappedSet {
171
171
  }
172
172
  }
173
173
 
174
- var e={isFunction:t,isNil:s};function t(e){return "function"==typeof e}function s(e){return null==e}function n(e){return null!=e&&"string"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&"number"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,s){if(!t(e))throw new Error(`${s?'"'+s+'" ':""}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(s(e))throw new Error((t?'"'+t+'" ':"")+"Should Not Nil")},assertString:function(e,t){if(!n(e))throw new Error(`${t?'"'+t+'" ':""}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!n(e)&&!function(e){return null!=e&&"symbol"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return "null";if(void 0===e)return "undefined";let t;try{t=JSON.stringify(e);}catch(s){t=e.toString();}return t}new TextDecoder,new TextEncoder;const l="DOwner$#$",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,s=false){o(e,"event"),a(t,"callback"),this._event=e,this._callback=t,this._isOnce=!!s,this._owner=void 0;}set owner(e){this._owner=e;}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this);}catch(e){console.warn(e);}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,"eventName"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map;}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return [...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return [...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return false;for(const t of [...this._listeners])t.invoke(...e);return true}emitOwner(e,...t){if(0===this._listeners.length)return false;const s=this._owner2Listeners.get(e);if(null==s)return false;for(const e of [...s])e.invoke(...t);return true}hasListener(e){return !!h(e)&&this._callbacks.has(e)}hasOwner(e){return !u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,false,false)}prependListener(e,t){return this._addListener(e,t,false,true)}addOnceListener(e,t){return this._addListener(e,t,true,false)}prependOnceListener(e,t){return this._addListener(e,t,true,true)}_addListener(e,t,s,n){if(u(e))return false;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,s);r.owner=t,n?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),true}removeListener(e){if(u(e))return false;if(!this._callbacks.has(e))return false;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return false;this._callback2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const s=this._owner2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&this._owner2Listeners.delete(t));}return true}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:s}=e,n=this._callback2Listeners.get(s);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(s),this._callbacks.delete(s)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r));}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,s=this._callback2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)));}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=["on","once","addListener","prependListener","prependOnceListener","off","offAll","offOwner","removeAllListeners","removeListener","emit","emitOwner","setMaxListeners","getMaxListeners","hasOwner","listeners","listenerCount","eventNames","rawListeners"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const s of b){const n=t[s];e[s]=n.bind(t);}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10;}constructor(){this._name2Event=new Map,this._maxListeners=O;}addListener(e,t,s){return this.on(e,t,s)}prependListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,s),this}prependOnceListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,s),this}emit(e,...t){const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emit(...t),true)}emitOwner(e,t,...s){if(null==t)throw new Error('Missing "owner"');const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emitOwner(t,...s),true)}eventNames(){return [...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s||s.isEmpty()?0:s.listenerCount(t)}listeners(e){g(e,"eventName");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const s=this._name2Event.get(e);return null==s?this:(s.removeListener(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s?this:(s.removeAllListeners(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,"owner");const t=[...this._name2Event.values()];for(const s of t)s.removeAllListeners(e),s.isEmpty()&&this._name2Event.delete(s.name);return this}on(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,s),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`);}once(e,t,s){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,s),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError("maxListeners must >=0");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return false;for(const t of this._name2Event.values())if(t.hasOwner(e))return true;return false}}
174
+ var e={isFunction:t,isNil:n};function t(e){return "function"==typeof e}function n(e){return null==e}function s(e){return null!=e&&"string"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&"number"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,n){if(!t(e))throw new Error(`${n?'"'+n+'" ':""}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(n(e))throw new Error((t?'"'+t+'" ':"")+"Should Not Nil")},assertString:function(e,t){if(!s(e))throw new Error(`${t?'"'+t+'" ':""}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!s(e)&&!function(e){return null!=e&&"symbol"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return "null";if(void 0===e)return "undefined";const t=typeof e;if("string"===t)return e;if("symbol"===t)return `Symbol(${e.description})`;if("function"===t)return `Function ${e.name}(){}`;if(e instanceof String)return e.toString();if(Number.isNaN(e))return "NaN";if(e===1/0)return "Infinity";if(e===-1/0)return "-Infinity";if(e instanceof Error)return `${e.constructor.name}: ${e.message}`;if(e instanceof Promise)return "Promise";if(e instanceof Set)return `Set: ${i(Array.from(e))}`;if(e instanceof Map)return `Map: ${i(Array.from(e.entries()))}`;if(e instanceof RegExp)return e.toString();if(Array.isArray(e))return `[${e.map(i).join(", ")}]`;let n;try{n=JSON.stringify(e);}catch(t){n=e.toString();}return n}new TextDecoder,new TextEncoder;const l="DOwner$#$",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,n=false){o(e,"event"),a(t,"callback"),this._event=e,this._callback=t,this._isOnce=!!n,this._owner=void 0;}set owner(e){this._owner=e;}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this);}catch(e){console.warn(e);}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,"eventName"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map;}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return [...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return [...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return false;for(const t of [...this._listeners])t.invoke(...e);return true}emitOwner(e,...t){if(0===this._listeners.length)return false;const n=this._owner2Listeners.get(e);if(null==n)return false;for(const e of [...n])e.invoke(...t);return true}hasListener(e){return !!h(e)&&this._callbacks.has(e)}hasOwner(e){return !u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,false,false)}prependListener(e,t){return this._addListener(e,t,false,true)}addOnceListener(e,t){return this._addListener(e,t,true,false)}prependOnceListener(e,t){return this._addListener(e,t,true,true)}_addListener(e,t,n,s){if(u(e))return false;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,n);r.owner=t,s?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),true}removeListener(e){if(u(e))return false;if(!this._callbacks.has(e))return false;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return false;this._callback2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const n=this._owner2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&this._owner2Listeners.delete(t));}return true}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:n}=e,s=this._callback2Listeners.get(n);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(n),this._callbacks.delete(n)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r));}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,n=this._callback2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)));}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=["on","once","addListener","prependListener","prependOnceListener","off","offAll","offOwner","removeAllListeners","removeListener","emit","emitOwner","setMaxListeners","getMaxListeners","hasOwner","listeners","listenerCount","eventNames","rawListeners"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const n of b){const s=t[n];e[n]=s.bind(t);}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10;}constructor(){this._name2Event=new Map,this._maxListeners=O;}addListener(e,t,n){return this.on(e,t,n)}prependListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,n),this}prependOnceListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,n),this}emit(e,...t){const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emit(...t),true)}emitOwner(e,t,...n){if(null==t)throw new Error('Missing "owner"');const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emitOwner(t,...n),true)}eventNames(){return [...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,"eventName");const n=this._name2Event.get(e);return null==n||n.isEmpty()?0:n.listenerCount(t)}listeners(e){g(e,"eventName");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const n=this._name2Event.get(e);return null==n?this:(n.removeListener(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,"eventName");const n=this._name2Event.get(e);return null==n?this:(n.removeAllListeners(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,"owner");const t=[...this._name2Event.values()];for(const n of t)n.removeAllListeners(e),n.isEmpty()&&this._name2Event.delete(n.name);return this}on(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,n),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`);}once(e,t,n){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,n),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError("maxListeners must >=0");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return false;for(const t of this._name2Event.values())if(t.hasOwner(e))return true;return false}}
175
175
 
176
176
  // 3rd
177
177
  // internal
@@ -718,7 +718,720 @@ class Hour24TimeWheelCache extends k {
718
718
  }
719
719
  }
720
720
 
721
- var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache };
721
+ // internal
722
+ // owned
723
+
724
+ /**
725
+ * @typedef {{
726
+ * value: any,
727
+ * prev: Node|undefined,
728
+ * next: Node|undefined
729
+ * }} Node
730
+ */
731
+
732
+ // module vars
733
+ const { assertNotNegative, assertPositive: assertPositive$1 } = C;
734
+
735
+ /**
736
+ * A doubly linked list implementation.
737
+ *
738
+ * @class LinkedList
739
+ */
740
+ class LinkedList {
741
+ /**
742
+ * Creates a new LinkedList instance.
743
+ * @constructor
744
+ */
745
+ constructor () {
746
+ /**
747
+ * @type {Node|undefined}
748
+ */
749
+ this._head = undefined;
750
+ /**
751
+ * @type {Node|undefined}
752
+ */
753
+ this._tail = undefined;
754
+ /**
755
+ * @type {number}
756
+ */
757
+ this._size = 0;
758
+ }
759
+
760
+ get size () {
761
+ return this._size
762
+ }
763
+
764
+ /**
765
+ * get the first element
766
+ */
767
+ get first () {
768
+ return this._head?.value
769
+ }
770
+
771
+ /**
772
+ * get the last element
773
+ */
774
+ get last () {
775
+ return this._tail?.value
776
+ }
777
+
778
+ [Symbol.iterator] () {
779
+ let current = this._head;
780
+ const iterator = {
781
+ next () {
782
+ if (current) {
783
+ const value = current.value;
784
+ current = current.next;
785
+ return { value, done: false }
786
+ }
787
+ return { value: undefined, done: true }
788
+ },
789
+ [Symbol.iterator] () {
790
+ return this
791
+ }
792
+ };
793
+ return iterator
794
+ }
795
+
796
+ /**
797
+ * Adds a value to the beginning of the linked list.
798
+ * @param {*} value - The value to add
799
+ * @returns {LinkedList} This linked list instance for chaining
800
+ */
801
+ addFirst (value) {
802
+ /**
803
+ * @type {Node}
804
+ */
805
+ const node = { value, prev: undefined, next: this._head };
806
+
807
+ if (this._head) {
808
+ this._head.prev = node;
809
+ } else {
810
+ this._tail = node;
811
+ }
812
+
813
+ this._head = node;
814
+ this._size++;
815
+ return this
816
+ }
817
+
818
+ /**
819
+ * Adds a value to the end of the linked list.
820
+ * @param {*} value - The value to add
821
+ * @returns {LinkedList} This linked list instance for chaining
822
+ */
823
+ addLast (value) {
824
+ /**
825
+ * @type {Node}
826
+ */
827
+ const node = { value, prev: this._tail, next: undefined };
828
+
829
+ if (this._tail) {
830
+ this._tail.next = node;
831
+ } else {
832
+ this._head = node;
833
+ }
834
+
835
+ this._tail = node;
836
+ this._size++;
837
+ return this
838
+ }
839
+
840
+ /**
841
+ * Adds a value to the end of the linked list.
842
+ * @param {*} value - The value to add
843
+ * @returns {LinkedList} This linked list instance for chaining
844
+ */
845
+ add (value) {
846
+ return this.addLast(value)
847
+ }
848
+
849
+ /**
850
+ * Removes and returns the first element from the linked list.
851
+ * @returns {*} The removed value, or undefined if the list is empty
852
+ */
853
+ removeFirst () {
854
+ if (!this._head) {
855
+ return undefined
856
+ }
857
+
858
+ const value = this._head.value;
859
+ this._head = this._head.next;
860
+
861
+ if (this._head) {
862
+ this._head.prev = undefined;
863
+ } else {
864
+ this._tail = undefined;
865
+ }
866
+
867
+ this._size--;
868
+ return value
869
+ }
870
+
871
+ /**
872
+ * Removes and returns the last element from the linked list.
873
+ * @returns {*} The removed value, or undefined if the list is empty
874
+ */
875
+ removeLast () {
876
+ if (!this._tail) {
877
+ return undefined
878
+ }
879
+
880
+ const value = this._tail.value;
881
+ this._tail = this._tail.prev;
882
+
883
+ if (this._tail) {
884
+ this._tail.next = undefined;
885
+ } else {
886
+ this._head = undefined;
887
+ }
888
+
889
+ this._size--;
890
+ return value
891
+ }
892
+
893
+ /**
894
+ * Removes the first occurrence of the specified value from the linked list.
895
+ * @param {*} value - The value to remove
896
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
897
+ * @returns {boolean} True if the value was found and removed, false otherwise
898
+ */
899
+ remove (value, comparator) {
900
+ const compare = comparator || this._defaultComparator;
901
+ let current = this._head;
902
+
903
+ while (current) {
904
+ if (compare(current.value, value)) {
905
+ this._removeNode(current);
906
+ return true
907
+ }
908
+ current = current.next;
909
+ }
910
+
911
+ return false
912
+ }
913
+
914
+ /**
915
+ * Removes all occurrences of the specified value from the linked list.
916
+ * @param {*} value - The value to remove
917
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
918
+ * @returns {number} The number of elements removed
919
+ */
920
+ removeAll (value, comparator) {
921
+ const compare = comparator || this._defaultComparator;
922
+ let removedCount = 0;
923
+ let current = this._head;
924
+
925
+ while (current) {
926
+ const next = current.next; // Store next before potential removal
927
+ if (compare(current.value, value)) {
928
+ this._removeNode(current);
929
+ removedCount++;
930
+ }
931
+ current = next;
932
+ }
933
+
934
+ return removedCount
935
+ }
936
+
937
+ /**
938
+ * Removes the element at the specified index.
939
+ * @param {number} index - The index of the element to remove
940
+ * @returns {*} The removed value, or undefined if index is out of bounds
941
+ */
942
+ removeAt (index) {
943
+ assertNotNegative(index, 'index');
944
+
945
+ if (index >= this._size) {
946
+ return undefined
947
+ }
948
+
949
+ if (index === 0) {
950
+ return this.removeFirst()
951
+ }
952
+
953
+ if (index === this._size - 1) {
954
+ return this.removeLast()
955
+ }
956
+
957
+ let current = this._head;
958
+ for (let i = 0; i < index; i++) {
959
+ current = current?.next;
960
+ }
961
+
962
+ if (current) {
963
+ const value = current.value;
964
+ this._removeNode(current);
965
+ return value
966
+ }
967
+
968
+ return undefined
969
+ }
970
+
971
+ /**
972
+ * Remove speicied count elements from head
973
+ * @param {number} count - The count of elements to remove
974
+ * @returns {boolean} True if any element was removed, false otherwise
975
+ */
976
+ removeFromHead (count) {
977
+ assertPositive$1(count, 'count');
978
+
979
+ // do nothing, it list is empty
980
+ if (this._size === 0) {
981
+ return false
982
+ }
983
+
984
+ // beyond size, remove all elements
985
+ if (count >= this._size) {
986
+ this.clear();
987
+ return true
988
+ }
989
+
990
+ // Find the node at the specified index
991
+ let current = this._head;
992
+ for (let i = 1; i < count; i++) {
993
+ if (!current) {
994
+ return false
995
+ }
996
+ current = current.next;
997
+ }
998
+ // Remove the nodes
999
+ if (current) {
1000
+ if (current.next) {
1001
+ this._head = current.next;
1002
+ this._head.prev = undefined;
1003
+ } else {
1004
+ this._head = undefined;
1005
+ this._tail = undefined;
1006
+ }
1007
+ this._size = this._size - count;
1008
+ return true
1009
+ }
1010
+
1011
+ return false
1012
+ }
1013
+
1014
+ /**
1015
+ * Remove specified count elements from tail
1016
+ * @param {number} count - The count of elements to remove
1017
+ * @returns {boolean} True if any element was removed, false otherwise
1018
+ */
1019
+ removeFromTail (count) {
1020
+ assertPositive$1(count, 'count');
1021
+
1022
+ // do nothing, if list is empty
1023
+ if (this._size === 0) {
1024
+ return false
1025
+ }
1026
+
1027
+ // beyond size, remove all elements
1028
+ if (count >= this._size) {
1029
+ this.clear();
1030
+ return true
1031
+ }
1032
+
1033
+ // Find the node at the specified position from tail
1034
+ let current = this._tail;
1035
+ for (let i = 1; i < count; i++) {
1036
+ if (!current) {
1037
+ return false
1038
+ }
1039
+ current = current.prev;
1040
+ }
1041
+ // Remove the nodes
1042
+ if (current) {
1043
+ if (current.prev) {
1044
+ this._tail = current.prev;
1045
+ this._tail.next = undefined;
1046
+ } else {
1047
+ this._head = undefined;
1048
+ this._tail = undefined;
1049
+ }
1050
+ this._size = this._size - count;
1051
+ return true
1052
+ }
1053
+
1054
+ return false
1055
+ }
1056
+
1057
+ /**
1058
+ * Checks if the linked list contains the specified value.
1059
+ * @param {*} value - The value to check for
1060
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1061
+ * @returns {boolean} True if the value exists, false otherwise
1062
+ */
1063
+ contains (value, comparator) {
1064
+ const compare = comparator || this._defaultComparator;
1065
+ let current = this._head;
1066
+ while (current) {
1067
+ if (compare(current.value, value)) {
1068
+ return true
1069
+ }
1070
+ current = current.next;
1071
+ }
1072
+ return false
1073
+ }
1074
+
1075
+ /**
1076
+ * Returns the index of the first occurrence of the specified value.
1077
+ * @param {*} value - The value to find
1078
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1079
+ * @returns {number} The index of the value, or -1 if not found
1080
+ */
1081
+ indexOf (value, comparator) {
1082
+ const compare = comparator || this._defaultComparator;
1083
+ let current = this._head;
1084
+ let index = 0;
1085
+ while (current) {
1086
+ if (compare(current.value, value)) {
1087
+ return index
1088
+ }
1089
+ current = current.next;
1090
+ index++;
1091
+ }
1092
+ return -1
1093
+ }
1094
+
1095
+ /**
1096
+ * Returns the index of the last occurrence of the specified value.
1097
+ * @param {*} value - The value to find
1098
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1099
+ * @returns {number} The index of the last occurrence, or -1 if not found
1100
+ */
1101
+ indexLastOf (value, comparator) {
1102
+ const compare = comparator || this._defaultComparator;
1103
+ let current = this._tail;
1104
+ let index = this._size - 1;
1105
+ while (current) {
1106
+ if (compare(current.value, value)) {
1107
+ return index
1108
+ }
1109
+ current = current.prev;
1110
+ index--;
1111
+ }
1112
+ return -1
1113
+ }
1114
+
1115
+ /**
1116
+ * Gets the value at the specified index.
1117
+ * @param {number} index - The index of the value to get
1118
+ * @returns {*} The value at the index, or undefined if index is out of bounds
1119
+ */
1120
+ get (index) {
1121
+ assertNotNegative(index, 'index');
1122
+
1123
+ if (index >= this._size) {
1124
+ return undefined
1125
+ }
1126
+
1127
+ let current = this._head;
1128
+ for (let i = 0; i < index; i++) {
1129
+ current = current?.next;
1130
+ }
1131
+
1132
+ return current?.value
1133
+ }
1134
+
1135
+ /**
1136
+ * Inserts a value at the specified index.
1137
+ * @param {number} index - The index at which to insert the value
1138
+ * @param {*} value - The value to insert
1139
+ * @returns {LinkedList} This linked list instance for chaining
1140
+ */
1141
+ insertAt (index, value) {
1142
+ assertNotNegative(index, 'index');
1143
+
1144
+ if (index === 0) {
1145
+ return this.addFirst(value)
1146
+ }
1147
+
1148
+ if (index >= this._size) {
1149
+ return this.addLast(value)
1150
+ }
1151
+
1152
+ let current = this._head;
1153
+ for (let i = 0; i < index - 1; i++) {
1154
+ current = current?.next;
1155
+ }
1156
+
1157
+ if (current) {
1158
+ /**
1159
+ * @type {Node}
1160
+ */
1161
+ const node = { value, prev: current, next: current.next };
1162
+ if (current.next) {
1163
+ current.next.prev = node;
1164
+ }
1165
+ current.next = node;
1166
+ this._size++;
1167
+ }
1168
+
1169
+ return this
1170
+ }
1171
+
1172
+ /**
1173
+ * Removes all elements from the linked list.
1174
+ */
1175
+ clear () {
1176
+ this._head = undefined;
1177
+ this._tail = undefined;
1178
+ this._size = 0;
1179
+ }
1180
+
1181
+ /**
1182
+ * Returns an array containing all the values in the linked list.
1183
+ * @returns {any[]} An array of all values
1184
+ */
1185
+ toArray () {
1186
+ const result = [];
1187
+ let current = this._head;
1188
+ while (current) {
1189
+ result.push(current.value);
1190
+ current = current.next;
1191
+ }
1192
+ return result
1193
+ }
1194
+
1195
+ /**
1196
+ * Returns an iterator of the values in the linked list.
1197
+ * @returns {Iterator<any>} An iterator object that yields the values of the linked list
1198
+ */
1199
+ values () {
1200
+ return this[Symbol.iterator]()
1201
+ }
1202
+
1203
+ /**
1204
+ * Returns a slice of the linked list as an array.
1205
+ * @param {number} [start=0] - The start index (inclusive). If negative, counts from the end.
1206
+ * @param {number} [end=this.size] - The end index (exclusive). If negative, counts from the end.
1207
+ * @returns {any[]} An array containing the sliced elements
1208
+ */
1209
+ slice (start = 0, end = this.size) {
1210
+ // Handle negative indices
1211
+ const normalizedStart = start < 0 ? Math.max(this.size + start, 0) : Math.min(start, this.size);
1212
+ const normalizedEnd = end < 0 ? Math.max(this.size + end, 0) : Math.min(end, this.size);
1213
+
1214
+ if (normalizedStart >= normalizedEnd) {
1215
+ return []
1216
+ }
1217
+
1218
+ if (start < 0) {
1219
+ return this._sliceNegative(normalizedStart, normalizedEnd)
1220
+ } else {
1221
+ return this._slicePositive(normalizedStart, normalizedEnd)
1222
+ }
1223
+ }
1224
+
1225
+ /**
1226
+ * Returns a string representation of the FixedLinkedList.
1227
+ * @returns {string} String representation
1228
+ */
1229
+ toString () {
1230
+ const partialElements = this.slice(0, 3);
1231
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1232
+ return `LinkedList[${this.size}](${partialString})`
1233
+ }
1234
+
1235
+ /**
1236
+ * Slice implementation for positive indices (iterates from head to tail)
1237
+ * @param {number} start - Normalized start index (inclusive)
1238
+ * @param {number} end - Normalized end index (exclusive)
1239
+ * @returns {any[]} An array containing the sliced elements
1240
+ * @private
1241
+ */
1242
+ _slicePositive (start, end) {
1243
+ const result = [];
1244
+ let current = this._head;
1245
+ let index = 0;
1246
+
1247
+ // Move to the starting position
1248
+ while (current && index < start) {
1249
+ current = current.next;
1250
+ index++;
1251
+ }
1252
+
1253
+ // Collect elements from start to end
1254
+ while (current && index < end) {
1255
+ result.push(current.value);
1256
+ current = current.next;
1257
+ index++;
1258
+ }
1259
+
1260
+ return result
1261
+ }
1262
+
1263
+ /**
1264
+ * Slice implementation for negative indices (iterates from tail to head)
1265
+ * @param {number} start - Normalized start index (inclusive)
1266
+ * @param {number} end - Normalized end index (exclusive)
1267
+ * @returns {any[]} An array containing the sliced elements
1268
+ * @private
1269
+ */
1270
+ _sliceNegative (start, end) {
1271
+ const result = [];
1272
+ let current = this._tail;
1273
+ let index = this.size - 1;
1274
+
1275
+ // Move to the starting position
1276
+ while (current && index > start) {
1277
+ current = current.prev;
1278
+ index--;
1279
+ }
1280
+
1281
+ // Collect elements from start to end
1282
+ while (current && index < end) {
1283
+ result.push(current.value);
1284
+ current = current.next;
1285
+ index++;
1286
+ }
1287
+
1288
+ return result
1289
+ }
1290
+
1291
+ /**
1292
+ * Removes a node from the linked list.
1293
+ * @param {Node} node - The node to be removed
1294
+ * @private
1295
+ */
1296
+ _removeNode (node) {
1297
+ if (node.prev) {
1298
+ node.prev.next = node.next;
1299
+ } else {
1300
+ this._head = node.next;
1301
+ }
1302
+
1303
+ if (node.next) {
1304
+ node.next.prev = node.prev;
1305
+ } else {
1306
+ this._tail = node.prev;
1307
+ }
1308
+
1309
+ this._size--;
1310
+ }
1311
+
1312
+ /**
1313
+ * Default comparator for strict equality comparison.
1314
+ * @param {*} a - First value to compare
1315
+ * @param {*} b - Second value to compare
1316
+ * @returns {boolean} True if values are strictly equal
1317
+ * @private
1318
+ */
1319
+ _defaultComparator (a, b) {
1320
+ return a === b
1321
+ }
1322
+ }
1323
+
1324
+ // internal
1325
+ // owned
1326
+
1327
+ // module vars
1328
+ const { assertPositive } = C;
1329
+
1330
+ /**
1331
+ * A fixed-capacity linked list that automatically removes elements when capacity is exceeded.
1332
+ * When adding to the end (addLast), it removes the first element if capacity is full.
1333
+ * When adding to the beginning (addFirst), it removes the last element if capacity is full.
1334
+ *
1335
+ * @class FixedLinkedList
1336
+ * @extends LinkedList
1337
+ */
1338
+ class FixedLinkedList extends LinkedList {
1339
+ /**
1340
+ * Creates a new FixedLinkedList instance with a fixed capacity.
1341
+ * @constructor
1342
+ * @param {number} capacity - The maximum number of elements the list can hold (must be > 0)
1343
+ * @throws {Error} If capacity is less than or equal to 0
1344
+ */
1345
+ constructor (capacity) {
1346
+ assertPositive(capacity, 'capacity');
1347
+ super();
1348
+ this.capacity = Math.ceil(capacity);
1349
+ }
1350
+
1351
+ /**
1352
+ * Adds a value to the beginning of the linked list.
1353
+ * If the list is at capacity, removes the last element before adding.
1354
+ * @param {*} value - The value to add
1355
+ * @returns {FixedLinkedList} This linked list instance for chaining
1356
+ */
1357
+ addFirst (value) {
1358
+ if (this.size >= this.capacity) {
1359
+ this.removeLast();
1360
+ }
1361
+ super.addFirst(value);
1362
+ return this
1363
+ }
1364
+
1365
+ /**
1366
+ * Adds a value to the end of the linked list.
1367
+ * If the list is at capacity, removes the first element before adding.
1368
+ * @param {*} value - The value to add
1369
+ * @returns {FixedLinkedList} This linked list instance for chaining
1370
+ */
1371
+ addLast (value) {
1372
+ if (this.size >= this.capacity) {
1373
+ this.removeFirst();
1374
+ }
1375
+ super.addLast(value);
1376
+ return this
1377
+ }
1378
+
1379
+ /**
1380
+ * Adds a value to the end of the linked list.
1381
+ * If the list is at capacity, removes the first element before adding.
1382
+ * @param {*} value - The value to add
1383
+ * @returns {FixedLinkedList} This linked list instance for chaining
1384
+ */
1385
+ add (value) {
1386
+ return this.addLast(value)
1387
+ }
1388
+
1389
+ /**
1390
+ * Inserts a value at the specified index.
1391
+ * If the list is at capacity and index is not at the end, removes the first element before adding.
1392
+ * If the list is at capacity and index is at the end, removes the first element before adding.
1393
+ * @param {number} index - The index at which to insert the value
1394
+ * @param {*} value - The value to insert
1395
+ * @returns {FixedLinkedList} This linked list instance for chaining
1396
+ */
1397
+ insertAt (index, value) {
1398
+ // Remove an element if we're at capacity and not adding beyond current size
1399
+ if (this.size >= this.capacity) {
1400
+ // Always remove first element to maintain capacity
1401
+ this.removeFirst();
1402
+ }
1403
+ super.insertAt(index, value);
1404
+ return this
1405
+ }
1406
+
1407
+ /**
1408
+ * Returns the remaining capacity of the list.
1409
+ * @returns {number} The number of additional elements that can be added
1410
+ */
1411
+ get remainingCapacity () {
1412
+ return this.capacity - this.size
1413
+ }
1414
+
1415
+ /**
1416
+ * Checks if the list is at full capacity.
1417
+ * @returns {boolean} True if the list is full, false otherwise
1418
+ */
1419
+ get isFull () {
1420
+ return this.size >= this.capacity
1421
+ }
1422
+
1423
+ /**
1424
+ * Returns a string representation of the FixedLinkedList.
1425
+ * @returns {string} String representation
1426
+ */
1427
+ toString () {
1428
+ const partialElements = this.slice(0, 3);
1429
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1430
+ return `FixedLinkedList[${this.size}/${this.capacity}](${partialString})`
1431
+ }
1432
+ }
1433
+
1434
+ var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache, LinkedList, FixedLinkedList };
722
1435
 
723
- export { CappedSet, Hour24TimeWheelCache, TimeWheelCache, index as default };
1436
+ export { CappedSet, FixedLinkedList, Hour24TimeWheelCache, LinkedList, TimeWheelCache, index as default };
724
1437
  //# sourceMappingURL=index-dev.js.map