@byloth/core 2.1.8 → 2.2.0

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.
package/dist/core.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=typeof window<"u"&&typeof window.document<"u",$=typeof process<"u"&&!!process.versions?.node,A=typeof self=="object"&&self.constructor?.name==="DedicatedWorkerGlobalScope";class c extends Error{static FromUnknown(e){if(e instanceof c)return e;if(e instanceof Error){const t=new c(e.message);return t.stack=e.stack,t.name=e.name,t}return new c(`${e}`)}constructor(e,t,n="Exception"){super(e),this.cause=t,this.name=n,t&&(t instanceof Error?this.stack+=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=typeof window<"u"&&typeof window.document<"u",A=typeof process<"u"&&!!process.versions?.node,$=typeof self=="object"&&self.constructor?.name==="DedicatedWorkerGlobalScope";class c extends Error{static FromUnknown(e){if(e instanceof c)return e;if(e instanceof Error){const t=new c(e.message);return t.stack=e.stack,t.name=e.name,t}return new c(`${e}`)}constructor(e,t,n="Exception"){super(e),this.cause=t,this.name=n,t&&(t instanceof Error?this.stack+=`
2
2
 
3
3
  Caused by ${t.stack}`:this.stack+=`
4
4
 
5
- Caused by ${t}`)}[Symbol.toStringTag]="Exception"}class x extends c{constructor(e,t,n="FatalErrorException"){e===void 0&&(e="The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team."),super(e,t,n)}[Symbol.toStringTag]="FatalErrorException"}class P extends x{constructor(e,t,n="NotImplementedException"){e===void 0&&(e="This feature isn't implemented yet. Please, try again later."),super(e,t,n)}[Symbol.toStringTag]="NotImplementedException"}class T extends c{constructor(e,t,n="FileException"){super(e,t,n)}[Symbol.toStringTag]="FileException"}class D extends T{constructor(e,t,n="FileExistsException"){super(e,t,n)}[Symbol.toStringTag]="FileExistsException"}class V extends T{constructor(e,t,n="FileNotFoundException"){super(e,t,n)}[Symbol.toStringTag]="FileNotFoundException"}class _ extends c{constructor(e,t,n="KeyException"){super(e,t,n)}[Symbol.toStringTag]="KeyException"}class B extends c{constructor(e,t,n="NetworkException"){super(e,t,n)}[Symbol.toStringTag]="NetworkException"}class J extends c{constructor(e,t,n="PermissionException"){super(e,t,n)}[Symbol.toStringTag]="PermissionException"}class v extends c{constructor(e,t,n="ReferenceException"){super(e,t,n)}[Symbol.toStringTag]="ReferenceException"}class p extends c{constructor(e,t,n="RuntimeException"){super(e,t,n)}[Symbol.toStringTag]="RuntimeException"}class C extends p{constructor(e,t,n="EnvironmentException"){super(e,t,n)}[Symbol.toStringTag]="EnvironmentException"}class j extends c{constructor(e,t,n="TimeoutException"){super(e,t,n)}[Symbol.toStringTag]="TimeoutException"}class L extends c{constructor(e,t,n="TypeException"){super(e,t,n)}[Symbol.toStringTag]="TypeException"}class f extends c{constructor(e,t,n="ValueException"){super(e,t,n)}[Symbol.toStringTag]="ValueException"}class y extends f{constructor(e,t,n="RangeException"){super(e,t,n)}[Symbol.toStringTag]="RangeException"}class a{_iterator;constructor(e){e instanceof Function?this._iterator=e():Symbol.iterator in e?this._iterator=e[Symbol.iterator]():this._iterator=e}every(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!0;if(!e(n.value,t))return!1;t+=1}}some(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!1;if(e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;e(s.value,n)&&(yield s.value),n+=1}})}map(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;yield e(s.value,n),n+=1}})}reduce(e,t){let n=0,s=t;if(s===void 0){const i=this._iterator.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value,n+=1}for(;;){const i=this._iterator.next();if(i.done)return s;s=e(s,i.value,n),n+=1}}flatMap(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;const i=e(s.value,n);if(i instanceof Array)for(const o of i)yield o;else yield i;n+=1}})}drop(e){const t=this._iterator;return new a(function*(){let n=0;for(;n<e;){if(t.next().done)return;n+=1}for(;;){const s=t.next();if(s.done)return s.value;yield s.value}})}take(e){const t=this._iterator;return new a(function*(){let n=0;for(;n<e;){const s=t.next();if(s.done)return s.value;yield s.value,n+=1}})}find(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return;if(e(n.value,t))return n.value;t+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new a(function*(){const t=new Set;for(;;){const n=e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}count(){let e=0;for(;;){if(this._iterator.next().done)return e;e+=1}}forEach(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return;e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}return(e){return this._iterator.return?this._iterator.return(e):{done:!0,value:e}}throw(e){if(this._iterator.throw)return this._iterator.throw(e);throw e}groupBy(e){return new h(this.map((t,n)=>[e(t,n),t]))}toArray(){return Array.from(this)}[Symbol.toStringTag]="SmartIterator";[Symbol.iterator](){return this}}class u{_elements;constructor(e){this._elements=new a(e)}every(e){for(const[t,[n,s]]of this._elements.enumerate())if(!e(n,s,t))return!1;return!0}some(e){for(const[t,[n,s]]of this._elements.enumerate())if(e(n,s,t))return!0;return!1}filter(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)e(s,i,n)&&(yield[s,i])})}map(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)yield[s,e(s,i,n)]})}reduce(e,t){let n=0,s=t;if(s===void 0){const i=this._elements.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value[1],n+=1}for(const[i,o]of this._elements)s=e(i,s,o,n),n+=1;return s}flatMap(e){const t=this._elements.enumerate();return new h(function*(){for(const[n,[s,i]]of t){const o=e(s,i,n);if(o instanceof Array)for(const l of o)yield[s,l];else yield[s,o]}})}drop(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)n>=e&&(yield[s,i])})}take(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t){if(n>=e)break;yield[s,i]}})}find(e){for(const[t,[n,s]]of this._elements.enumerate())if(e(n,s,t))return s}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new u(function*(){const t=new Set;for(const[n,s]of e)t.has(s)||(t.add(s),yield[n,s])})}count(){let e=0;for(const t of this._elements)e+=1;return e}forEach(e){for(const[t,[n,s]]of this._elements.enumerate())e(n,s,t)}reorganizeBy(e){const t=this._elements.enumerate();return new h(function*(){for(const[n,[s,i]]of t)yield[e(s,i,n),i]})}keys(){const e=this._elements;return new a(function*(){for(const[t]of e)yield t})}entries(){return this._elements}values(){const e=this._elements;return new a(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.entries())}toObject(){return Object.fromEntries(this.entries())}[Symbol.toStringTag]="ReducedIterator"}class w{_elements;constructor(e){this._elements=new d(e)}async every(e){const t=new Map;for await(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!0];o&&t.set(n,[i+1,await e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}async some(e){const t=new Map;for await(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!1];o||t.set(n,[i+1,await e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}filter(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;await e(s,i,o)&&(yield[s,i]),n.set(s,o+1)}})}map(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;yield[s,await e(s,i,o)],n.set(s,o+1)}})}async reduce(e,t){const n=new Map;for await(const[s,i]of this._elements){let o,l;if(n.has(s))[o,l]=n.get(s);else if(t!==void 0)o=0,t instanceof Function?l=await t(s):l=await t;else{n.set(s,[0,i]);continue}n.set(s,[o+1,await e(s,l,i,o)])}return new u(function*(){for(const[s,[i,o]]of n)yield[s,o]})}flatMap(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0,l=await e(s,i,o);if(l instanceof Array)for(const b of l)yield[s,b];else yield[s,l];n.set(s,o+1)}})}drop(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;if(o<e){n.set(s,o+1);continue}yield[s,i]}})}take(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;o>=e||(yield[s,i],n.set(s,o+1))}})}async find(e){const t=new Map;for await(const[n,s]of this._elements){let[i,o]=t.get(n)??[0,void 0];o===void 0&&(await e(n,s,i)&&(o=s),t.set(n,[i+1,o]))}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new w(async function*(){const t=new Map;for await(const[n,s]of e){const i=t.get(n)??new Set;i.has(s)||(i.add(s),t.set(n,i),yield[n,s])}})}async count(){const e=new Map;for await(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new u(function*(){for(const[t,n]of e)yield[t,n]})}async forEach(e){const t=new Map;for await(const[n,s]of this._elements){const i=t.get(n)??0;await e(n,s,i),t.set(n,i+1)}}reorganizeBy(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;yield[await e(s,i,o),i],n.set(s,o+1)}})}keys(){const e=this._elements;return new d(async function*(){const t=new Set;for await(const[n]of e)t.has(n)||(t.add(n),yield n)})}entries(){return this._elements}values(){const e=this._elements;return new d(async function*(){for await(const[t,n]of e)yield n})}async toArray(){const e=await this.toMap();return Array.from(e.values())}async toMap(){const e=new Map;for await(const[t,n]of this._elements){const s=e.get(t)??[];s.push(n),e.set(t,s)}return e}async toObject(){const e={};for await(const[t,n]of this._elements){const s=e[t]??[];s.push(n),e[t]=s}return e}[Symbol.toStringTag]="AggregatedAsyncIterator"}class d{_iterator;constructor(e){if(e instanceof Function){const t=e();Symbol.asyncIterator in t?this._iterator=t:this._iterator=(async function*(){let n=[];for(;;){const s=t.next(...n);if(s.done)return s.value;n=[yield s.value]}})()}else if(Symbol.asyncIterator in e)this._iterator=e[Symbol.asyncIterator]();else if(Symbol.iterator in e){const t=e[Symbol.iterator]();this._iterator=(async function*(){for(;;){const n=t.next();if(n.done)return n.value;yield n.value}})()}else this._iterator=(async function*(){let t=[];for(;;){const n=await e.next(...t);if(n.done)return n.value;t=[yield n.value]}})()}async every(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!0;if(!await e(n.value,t))return!1;t+=1}}async some(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!1;if(await e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;await e(s.value,n)&&(yield s.value),n+=1}})}map(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;yield await e(s.value,n),n+=1}})}async reduce(e,t){let n=0,s=t;if(s===void 0){const i=await this._iterator.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value,n+=1}for(;;){const i=await this._iterator.next();if(i.done)return s;s=await e(s,i.value,n),n+=1}}flatMap(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;const i=await e(s.value,n);if(i instanceof Array)for(const o of i)yield o;else yield i;n+=1}})}drop(e){const t=this._iterator;return new d(async function*(){let n=0;for(;n<e;){if((await t.next()).done)return;n+=1}for(;;){const s=await t.next();if(s.done)return s.value;yield s.value}})}take(e){const t=this._iterator;return new d(async function*(){let n=0;for(;n<e;){const s=await t.next();if(s.done)return s.value;yield s.value,n+=1}})}async find(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return;if(await e(n.value,t))return n.value;t+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new d(async function*(){const t=new Set;for(;;){const n=await e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}async count(){let e=0;for(;;){if((await this._iterator.next()).done)return e;e+=1}}async forEach(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return;await e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}async return(e){const t=await e;return this._iterator.return?await this._iterator.return(t):{done:!0,value:t}}throw(e){if(this._iterator.throw)return this._iterator.throw(e);throw e}groupBy(e){return new w(this.map(async(t,n)=>[await e(t,n),t]))}toArray(){return Array.fromAsync(this)}[Symbol.toStringTag]="SmartAsyncIterator";[Symbol.asyncIterator](){return this}}class h{_elements;constructor(e){this._elements=new a(e)}every(e){const t=new Map;for(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!0];o&&t.set(n,[i+1,e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}some(e){const t=new Map;for(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!1];o||t.set(n,[i+1,e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}filter(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;e(s,i,o)&&(yield[s,i]),n.set(s,o+1)}})}map(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;yield[s,e(s,i,o)],n.set(s,o+1)}})}reduce(e,t){const n=new Map;for(const[s,i]of this._elements){let o,l;if(n.has(s))[o,l]=n.get(s);else if(t!==void 0)o=0,t instanceof Function?l=t(s):l=t;else{n.set(s,[0,i]);continue}n.set(s,[o+1,e(s,l,i,o)])}return new u(function*(){for(const[s,[i,o]]of n)yield[s,o]})}flatMap(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0,l=e(s,i,o);if(l instanceof Array)for(const b of l)yield[s,b];else yield[s,l];n.set(s,o+1)}})}drop(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;if(o<e){n.set(s,o+1);continue}yield[s,i]}})}take(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;o>=e||(yield[s,i],n.set(s,o+1))}})}find(e){const t=new Map;for(const[n,s]of this._elements){let[i,o]=t.get(n)??[0,void 0];o===void 0&&(e(n,s,i)&&(o=s),t.set(n,[i+1,o]))}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new h(function*(){const t=new Map;for(const[n,s]of e){const i=t.get(n)??new Set;i.has(s)||(i.add(s),t.set(n,i),yield[n,s])}})}count(){const e=new Map;for(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new u(function*(){for(const[t,n]of e)yield[t,n]})}forEach(e){const t=new Map;for(const[n,s]of this._elements){const i=t.get(n)??0;e(n,s,i),t.set(n,i+1)}}reorganizeBy(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;yield[e(s,i,o),i],n.set(s,o+1)}})}keys(){const e=this._elements;return new a(function*(){const t=new Set;for(const[n]of e)t.has(n)||(t.add(n),yield n)})}entries(){return this._elements}values(){const e=this._elements;return new a(function*(){for(const[t,n]of e)yield n})}toArray(){const e=this.toMap();return Array.from(e.values())}toMap(){const e=new Map;for(const[t,n]of this._elements){const s=e.get(t)??[];s.push(n),e.set(t,s)}return e}toObject(){const e={};for(const[t,n]of this._elements){const s=e[t]??[];s.push(n),e[t]=s}return e}[Symbol.toStringTag]="AggregatedIterator"}const Y=Function;class N extends Y{constructor(){super("return this._invoke(...arguments);");const e=this.bind(this);return Object.setPrototypeOf(this,e),e}[Symbol.toStringTag]="CallableObject"}class g{_subscribers;constructor(){this._subscribers=new Map}createScope(){const e=new g;return this.subscribe("__internals__:clear",()=>e.clear()),this.subscribe("*",(t,...n)=>{e.publish(t,...n)}),e}publish(e,...t){let n,s=this._subscribers.get(e);return s?n=s.slice().map(i=>i(...t)):n=[],e.startsWith("__")||(s=this._subscribers.get("*"),s&&s.slice().forEach(i=>i(e,...t))),n}subscribe(e,t){const n=this._subscribers.get(e)??[];return n.push(t),this._subscribers.set(e,n),()=>{const s=n.indexOf(t);if(s<0)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");n.splice(s,1)}}unsubscribe(e,t){const n=this._subscribers.get(e);if(!n)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");const s=n.indexOf(t);if(s<0)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");n.splice(s,1),n.length===0&&this._subscribers.delete(e)}unsubscribeAll(e){this._subscribers.delete(e)}clear(){this.publish("__internals__:clear"),this._subscribers.clear()}[Symbol.toStringTag]="Publisher"}const G=()=>{};class K extends N{_callback;_callbacks;_isEnabled;get isEnabled(){return this._isEnabled}_key;get key(){return this._key}_invoke;constructor(e,t="default"){super(),this._callbacks=new Map,this._isEnabled=!0,e?this._callbacks.set(t,e):(t="",e=(()=>{throw new P("The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?")})),this._key=t,this._callback=e,this._invoke=(...n)=>this._callback(...n)}enable(e){if(e===void 0){if(!this._key)throw new _("The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?");e=this._key}else if(e){if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`)}else throw new _("The key must be a non-empty string.");if(this._isEnabled)throw new p("The `SwitchableCallback` is already enabled.");this._callback=this._callbacks.get(e),this._isEnabled=!0}disable(){if(!this._isEnabled)throw new p("The `SwitchableCallback` is already disabled.");this._callback=G,this._isEnabled=!1}register(e,t){if(this._callbacks.size===0)this._key=e,this._callback=t;else if(this._callbacks.has(e))throw new _(`The key '${e}' has already been used for another callback.`);this._callbacks.set(e,t)}unregister(e){if(this._key===e)throw new _("Unable to unregister the currently selected callback.");if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`);this._callbacks.delete(e)}switch(e){if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`);this._key!==e&&(this._key=e,this._isEnabled&&(this._callback=this._callbacks.get(e)))}[Symbol.toStringTag]="SwitchableCallback"}class Q extends Map{_publisher;constructor(e){if(super(),this._publisher=new g,e)for(const[t,n]of e)this.set(t,n)}set(e,t){return super.set(e,t),this._publisher.publish("entry:add",e,t),this}delete(e){const t=this.get(e);return t===void 0?!1:(super.delete(e),this._publisher.publish("entry:remove",e,t),!0)}clear(){const e=this.size;super.clear(),e>0&&this._publisher.publish("collection:clear")}subscribe(e,t){return this._publisher.subscribe(e,t)}unsubscribe(e,t){this._publisher.unsubscribe(e,t)}[Symbol.toStringTag]="MapView"}class H extends Set{_publisher;constructor(e){if(super(),this._publisher=new g,e)for(const t of e)this.add(t)}add(e){return super.add(e),this._publisher.publish("entry:add",e),this}delete(e){const t=super.delete(e);return t&&this._publisher.publish("entry:remove",e),t}clear(){const e=this.size;super.clear(),e>0&&this._publisher.publish("collection:clear")}subscribe(e,t){return this._publisher.subscribe(e,t)}unsubscribe(e,t){this._publisher.unsubscribe(e,t)}[Symbol.toStringTag]="SetView"}class X{_preferPersistence;_volatile;_persistent;constructor(e=!0){if(!E)throw new C("The `JSONStorage` class can only be instantiated within a browser environment.");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const s=e.getItem(t);if(s)try{return JSON.parse(s)}catch{console.warn(`The "${s}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const s=JSON.stringify(n);s?e.setItem(t,s):e.removeItem(t)}get(e,t,n=this._preferPersistence){const s=n?this._persistent:this._volatile;return this._get(s,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,n=this._preferPersistence){const s=n?this._persistent:this._volatile;this._set(s,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}delete(e,t){(t?this._persistent:this._volatile).removeItem(e)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}[Symbol.toStringTag]="JSONStorage"}class m{static FromPromise(e){return new m((t,n)=>e.then(t,n))}_isPending;get isPending(){return this._isPending}_isFulfilled;get isFulfilled(){return this._isFulfilled}_isRejected;get isRejected(){return this._isRejected}_promise;constructor(e){this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const t=s=>(this._isPending=!1,this._isFulfilled=!0,s),n=s=>{throw this._isPending=!1,this._isRejected=!0,s};this._promise=new Promise(e).then(t,n)}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}[Symbol.toStringTag]="SmartPromise"}class M extends m{_resolve;get resolve(){return this._resolve}_reject;get reject(){return this._reject}constructor(e,t){let n,s;super((i,o)=>{n=i,s=o}),this._promise=this._promise.then(e,t),this._resolve=n,this._reject=s}watch(e){return e.then(this.resolve,this.reject),this}[Symbol.toStringTag]="DeferredPromise"}class O extends m{constructor(e,t){super((n,s)=>{const i=k=>{clearTimeout(b),n(k)},o=k=>{clearTimeout(b),s(k)},b=setTimeout(()=>o(new j("The operation has timed out.")),t);e(i,o)})}[Symbol.toStringTag]="TimedPromise"}class Z extends m{_count;get isPending(){return this._count>0}get isFulfilled(){return this._count===0}get isRejected(){throw new f("`PromiseQueue` doesn't support rejection states.")}constructor(){super(e=>e()),this._count=0,this._isPending=!1,this._isFulfilled=!1,this._isRejected=!1}enqueue(e,t){if(this._count+=1,e instanceof M){const s=e;e=()=>(s.resolve(),s)}const n=(s,i)=>{this._promise=this._promise.then(e).then(o=>{this._count-=1,s(o)}).catch(o=>{this._count-=1,i(o)})};return t?new O(n,t):new m(n)}[Symbol.toStringTag]="PromiseQueue"}var S=(r=>(r[r.Millisecond=1]="Millisecond",r[r.Second=1e3]="Second",r[r.Minute=6e4]="Minute",r[r.Hour=36e5]="Hour",r[r.Day=864e5]="Day",r[r.Week=6048e5]="Week",r[r.Month=2592e6]="Month",r[r.Year=31536e6]="Year",r))(S||{}),I=(r=>(r[r.Sunday=0]="Sunday",r[r.Monday=1]="Monday",r[r.Tuesday=2]="Tuesday",r[r.Wednesday=3]="Wednesday",r[r.Thursday=4]="Thursday",r[r.Friday=5]="Friday",r[r.Saturday=6]="Saturday",r))(I||{});function W(r,e,t=864e5){let n;return r=new Date(r),e=new Date(e),r<e?n=Math.floor:n=Math.ceil,n((e.getTime()-r.getTime())/t)}function U(r,e,t=864e5){if(r=new Date(r),e=new Date(e),r>=e)throw new y("The end date must be greater than the start date.");return new a(function*(){const n=e.getTime();let s=r.getTime();for(;s<n;)yield new Date(s),s+=t})}function q(r,e=864e5){if(e<=1)throw new y("Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead.");if(e>864e5)throw new y("Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years.");return r=new Date(r),new Date(Math.floor(r.getTime()/e)*e)}function ee(r,e=0){r=new Date(r);const t=7-e,n=(r.getUTCDay()+t)%7,s=r.getTime()-864e5*n;return q(new Date(s))}class R{_handle;_startTime;get startTime(){return this._startTime}_isRunning;get isRunning(){return this._isRunning}get elapsedTime(){return performance.now()-this._startTime}_publisher;_start;_stop;constructor(e,t=40){this._startTime=0,this._isRunning=!1,E?(this._start=()=>{e(this.elapsedTime),this._handle=window.requestAnimationFrame(this._start)},this._stop=()=>window.cancelAnimationFrame(this._handle)):(console.warn(`Not a browser environment detected. Using setInterval@${t}ms instead of requestAnimationFrame...`),this._start=()=>{this._handle=setInterval(()=>e(this.elapsedTime),t)},this._stop=()=>clearInterval(this._handle)),this._publisher=new g}start(e=0){if(this._isRunning)throw new p("The game loop has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0,this._publisher.publish("start")}stop(){if(!this._isRunning)throw new p("The game loop had already stopped or hadn't yet started.");if(!this._handle)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,this._publisher.publish("stop")}onStart(e){return this._publisher.subscribe("start",e)}onStop(e){return this._publisher.subscribe("stop",e)}[Symbol.toStringTag]="GameLoop"}class te extends R{constructor(e=S.Second){super(t=>this._publisher.publish("tick",t),e)}start(e=0){if(this._isRunning)throw new p("The clock has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0,this._publisher.publish("start")}stop(){if(!this._isRunning)throw new p("The clock had already stopped or hadn't yet started.");if(!this._handle)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,this._publisher.publish("stop")}onTick(e,t=0){if(t<0)throw new y("The tick step must be a non-negative number.");if(t===0)return this._publisher.subscribe("tick",e);let n=0;return this._publisher.subscribe("tick",s=>{s-n<t||(e(s),n=s)})}[Symbol.toStringTag]="Clock"}class ne extends R{_duration;get duration(){return this._duration}get remainingTime(){return this._duration-this.elapsedTime}_deferrer;constructor(e,t=S.Second){const n=()=>{const s=this.remainingTime;s<=0?(this._deferrerStop(),this._publisher.publish("tick",0),this._publisher.publish("expire")):this._publisher.publish("tick",s)};super(n,t),this._duration=e}_deferrerStop(e){if(!this._isRunning)throw new p("The countdown hadn't yet started.");if(!this._deferrer)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,e!==void 0?this._deferrer.reject(e):this._deferrer.resolve(),this._deferrer=void 0}start(e=this.duration){if(this._isRunning)throw new p("The countdown had already stopped or hadn't yet started.");if(this._deferrer)throw new x;return this._deferrer=new M,super.start(this.duration-e),this._publisher.publish("start"),this._deferrer}stop(e){this._deferrerStop(e),this._publisher.publish("stop",e)}onExpire(e){return this._publisher.subscribe("expire",e)}onTick(e,t=0){if(t<0)throw new y("The tick step must be a non-negative number.");if(t===0)return this._publisher.subscribe("tick",e);let n=this.remainingTime;return this._publisher.subscribe("tick",s=>{n-s<t||(e(s),n=s)})}[Symbol.toStringTag]="Countdown"}class se{static Linear(e){const t=e-1;return new a(function*(){for(let n=0;n<e;n+=1)yield n/t})}static Exponential(e,t=2){if(t<0)throw new f("The base of the exponential curve cannot be negative.");const n=e-1;return new a(function*(){for(let s=0;s<e;s+=1)yield Math.pow(s/n,t)})}constructor(){}[Symbol.toStringTag]="Curve"}class F{static Boolean(e=.5){return Math.random()<e}static Integer(e,t){return Math.floor(t===void 0?Math.random()*e:Math.random()*(t-e)+e)}static Decimal(e,t){return e===void 0?Math.random():t===void 0?Math.random()*e:Math.random()*(t-e)+e}static Index(e){if(e.length===0)throw new f("You must provide at least one element.");return this.Integer(e.length)}static Choice(e){return e[F.Index(e)]}constructor(){}[Symbol.toStringTag]="Random"}function ie(r){return new m(e=>setTimeout(e,r))}function re(){return new m(r=>requestAnimationFrame(()=>r()))}function oe(){return new m(r=>setTimeout(r))}function ae(r,e="text/javascript"){return new m((t,n)=>{const s=document.createElement("script");s.async=!0,s.defer=!0,s.src=r,s.type=e,s.onload=i=>t(),s.onerror=i=>n(i),document.body.appendChild(s)})}function le(...r){return new a(function*(){for(const e of r)for(const t of e)yield t})}function ue(r){if(r instanceof Array)return r.length;let e=0;for(const t of r)e+=1;return e}function ce(r){return new a(function*(){let e=0;for(const t of r)yield[e,t],e+=1})}function he(r,e,t=1){if(t<=0)throw new y("Step must be always a positive number, even when generating numbers in reverse order.");return e===void 0&&(e=r,r=0),r>e?new a(function*(){for(let n=r;n>e;n-=t)yield n}):new a(function*(){for(let n=r;n<e;n+=t)yield n})}function fe(r){const e=Array.from(r);for(let t=e.length-1;t>0;t-=1){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}function de(r){return new a(function*(){const e=new Set;for(const t of r)e.has(t)||(e.add(t),yield t)})}function z(r,e){const t=r[Symbol.iterator](),n=e[Symbol.iterator]();return new a(function*(){for(;;){const s=t.next(),i=n.next();if(s.done||i.done)break;yield[s.value,i.value]}})}function me(r,e){if(e===void 0){let i=0,o=0;for(const l of r)i+=l,o+=1;if(o===0)throw new f("You must provide at least one value.");return i/o}let t=0,n=0,s=0;for(const[i,o]of z(r,e)){if(o<=0)throw new f(`The weight for the value #${s} must be greater than zero.`);t+=i*o,n+=o,s+=1}if(s===0)throw new f("You must provide at least one value and weight.");if(n<=0)throw new f("The sum of weights must be greater than zero.");return t/n}function we(r){let e=0;for(let t=0;t<r.length;t+=1){const n=r.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function pe(r){let e=0;for(const t of r)e+=t;return e}function _e(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const ye="2.1.8";exports.AggregatedAsyncIterator=w;exports.AggregatedIterator=h;exports.CallableObject=N;exports.Clock=te;exports.Countdown=ne;exports.Curve=se;exports.DeferredPromise=M;exports.EnvironmentException=C;exports.Exception=c;exports.FatalErrorException=x;exports.FileException=T;exports.FileExistsException=D;exports.FileNotFoundException=V;exports.GameLoop=R;exports.JSONStorage=X;exports.KeyException=_;exports.MapView=Q;exports.NetworkException=B;exports.NotImplementedException=P;exports.PermissionException=J;exports.PromiseQueue=Z;exports.Publisher=g;exports.Random=F;exports.RangeException=y;exports.ReducedIterator=u;exports.ReferenceException=v;exports.RuntimeException=p;exports.SetView=H;exports.SmartAsyncIterator=d;exports.SmartIterator=a;exports.SmartPromise=m;exports.SwitchableCallback=K;exports.TimeUnit=S;exports.TimedPromise=O;exports.TimeoutException=j;exports.TypeException=L;exports.VERSION=ye;exports.ValueException=f;exports.WeekDay=I;exports.average=me;exports.capitalize=_e;exports.chain=le;exports.count=ue;exports.dateDifference=W;exports.dateRange=U;exports.dateRound=q;exports.delay=ie;exports.enumerate=ce;exports.getWeek=ee;exports.hash=we;exports.isBrowser=E;exports.isNode=$;exports.isWorker=A;exports.loadScript=ae;exports.nextAnimationFrame=re;exports.range=he;exports.shuffle=fe;exports.sum=pe;exports.unique=de;exports.yieldToEventLoop=oe;exports.zip=z;
5
+ Caused by ${t}`)}[Symbol.toStringTag]="Exception"}class x extends c{constructor(e,t,n="FatalErrorException"){e===void 0&&(e="The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team."),super(e,t,n)}[Symbol.toStringTag]="FatalErrorException"}class P extends x{constructor(e,t,n="NotImplementedException"){e===void 0&&(e="This feature isn't implemented yet. Please, try again later."),super(e,t,n)}[Symbol.toStringTag]="NotImplementedException"}class T extends c{constructor(e,t,n="FileException"){super(e,t,n)}[Symbol.toStringTag]="FileException"}class D extends T{constructor(e,t,n="FileExistsException"){super(e,t,n)}[Symbol.toStringTag]="FileExistsException"}class V extends T{constructor(e,t,n="FileNotFoundException"){super(e,t,n)}[Symbol.toStringTag]="FileNotFoundException"}class _ extends c{constructor(e,t,n="KeyException"){super(e,t,n)}[Symbol.toStringTag]="KeyException"}class B extends c{constructor(e,t,n="NetworkException"){super(e,t,n)}[Symbol.toStringTag]="NetworkException"}class J extends c{constructor(e,t,n="PermissionException"){super(e,t,n)}[Symbol.toStringTag]="PermissionException"}class v extends c{constructor(e,t,n="ReferenceException"){super(e,t,n)}[Symbol.toStringTag]="ReferenceException"}class p extends c{constructor(e,t,n="RuntimeException"){super(e,t,n)}[Symbol.toStringTag]="RuntimeException"}class C extends p{constructor(e,t,n="EnvironmentException"){super(e,t,n)}[Symbol.toStringTag]="EnvironmentException"}class j extends c{constructor(e,t,n="TimeoutException"){super(e,t,n)}[Symbol.toStringTag]="TimeoutException"}class L extends c{constructor(e,t,n="TypeException"){super(e,t,n)}[Symbol.toStringTag]="TypeException"}class f extends c{constructor(e,t,n="ValueException"){super(e,t,n)}[Symbol.toStringTag]="ValueException"}class y extends f{constructor(e,t,n="RangeException"){super(e,t,n)}[Symbol.toStringTag]="RangeException"}class a{_iterator;constructor(e){e instanceof Function?this._iterator=e():Symbol.iterator in e?this._iterator=e[Symbol.iterator]():this._iterator=e}every(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!0;if(!e(n.value,t))return!1;t+=1}}some(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!1;if(e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;e(s.value,n)&&(yield s.value),n+=1}})}map(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;yield e(s.value,n),n+=1}})}reduce(e,t){let n=0,s=t;if(s===void 0){const i=this._iterator.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value,n+=1}for(;;){const i=this._iterator.next();if(i.done)return s;s=e(s,i.value,n),n+=1}}flatMap(e){const t=this._iterator;return new a(function*(){let n=0;for(;;){const s=t.next();if(s.done)return s.value;const i=e(s.value,n);if(i instanceof Array)for(const o of i)yield o;else yield i;n+=1}})}drop(e){const t=this._iterator;return new a(function*(){let n=0;for(;n<e;){if(t.next().done)return;n+=1}for(;;){const s=t.next();if(s.done)return s.value;yield s.value}})}take(e){const t=this._iterator;return new a(function*(){let n=0;for(;n<e;){const s=t.next();if(s.done)return s.value;yield s.value,n+=1}})}find(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return;if(e(n.value,t))return n.value;t+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new a(function*(){const t=new Set;for(;;){const n=e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}count(){let e=0;for(;;){if(this._iterator.next().done)return e;e+=1}}forEach(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return;e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}return(e){return this._iterator.return?this._iterator.return(e):{done:!0,value:e}}throw(e){if(this._iterator.throw)return this._iterator.throw(e);throw e}groupBy(e){return new h(this.map((t,n)=>[e(t,n),t]))}toArray(){return Array.from(this)}[Symbol.toStringTag]="SmartIterator";[Symbol.iterator](){return this}}class u{_elements;constructor(e){this._elements=new a(e)}every(e){for(const[t,[n,s]]of this._elements.enumerate())if(!e(n,s,t))return!1;return!0}some(e){for(const[t,[n,s]]of this._elements.enumerate())if(e(n,s,t))return!0;return!1}filter(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)e(s,i,n)&&(yield[s,i])})}map(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)yield[s,e(s,i,n)]})}reduce(e,t){let n=0,s=t;if(s===void 0){const i=this._elements.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value[1],n+=1}for(const[i,o]of this._elements)s=e(i,s,o,n),n+=1;return s}flatMap(e){const t=this._elements.enumerate();return new h(function*(){for(const[n,[s,i]]of t){const o=e(s,i,n);if(o instanceof Array)for(const l of o)yield[s,l];else yield[s,o]}})}drop(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t)n>=e&&(yield[s,i])})}take(e){const t=this._elements.enumerate();return new u(function*(){for(const[n,[s,i]]of t){if(n>=e)break;yield[s,i]}})}find(e){for(const[t,[n,s]]of this._elements.enumerate())if(e(n,s,t))return s}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new u(function*(){const t=new Set;for(const[n,s]of e)t.has(s)||(t.add(s),yield[n,s])})}count(){let e=0;for(const t of this._elements)e+=1;return e}forEach(e){for(const[t,[n,s]]of this._elements.enumerate())e(n,s,t)}reorganizeBy(e){const t=this._elements.enumerate();return new h(function*(){for(const[n,[s,i]]of t)yield[e(s,i,n),i]})}keys(){const e=this._elements;return new a(function*(){for(const[t]of e)yield t})}entries(){return this._elements}values(){const e=this._elements;return new a(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.entries())}toObject(){return Object.fromEntries(this.entries())}[Symbol.toStringTag]="ReducedIterator"}class w{_elements;constructor(e){this._elements=new d(e)}async every(e){const t=new Map;for await(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!0];o&&t.set(n,[i+1,await e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}async some(e){const t=new Map;for await(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!1];o||t.set(n,[i+1,await e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}filter(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;await e(s,i,o)&&(yield[s,i]),n.set(s,o+1)}})}map(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;yield[s,await e(s,i,o)],n.set(s,o+1)}})}async reduce(e,t){const n=new Map;for await(const[s,i]of this._elements){let o,l;if(n.has(s))[o,l]=n.get(s);else if(t!==void 0)o=0,t instanceof Function?l=await t(s):l=await t;else{n.set(s,[0,i]);continue}n.set(s,[o+1,await e(s,l,i,o)])}return new u(function*(){for(const[s,[i,o]]of n)yield[s,o]})}flatMap(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0,l=await e(s,i,o);if(l instanceof Array)for(const b of l)yield[s,b];else yield[s,l];n.set(s,o+1)}})}drop(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;if(o<e){n.set(s,o+1);continue}yield[s,i]}})}take(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;o>=e||(yield[s,i],n.set(s,o+1))}})}async find(e){const t=new Map;for await(const[n,s]of this._elements){let[i,o]=t.get(n)??[0,void 0];o===void 0&&(await e(n,s,i)&&(o=s),t.set(n,[i+1,o]))}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new w(async function*(){const t=new Map;for await(const[n,s]of e){const i=t.get(n)??new Set;i.has(s)||(i.add(s),t.set(n,i),yield[n,s])}})}async count(){const e=new Map;for await(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new u(function*(){for(const[t,n]of e)yield[t,n]})}async forEach(e){const t=new Map;for await(const[n,s]of this._elements){const i=t.get(n)??0;await e(n,s,i),t.set(n,i+1)}}reorganizeBy(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[s,i]of t){const o=n.get(s)??0;yield[await e(s,i,o),i],n.set(s,o+1)}})}keys(){const e=this._elements;return new d(async function*(){const t=new Set;for await(const[n]of e)t.has(n)||(t.add(n),yield n)})}entries(){return this._elements}values(){const e=this._elements;return new d(async function*(){for await(const[t,n]of e)yield n})}async toArray(){const e=await this.toMap();return Array.from(e.values())}async toMap(){const e=new Map;for await(const[t,n]of this._elements){const s=e.get(t)??[];s.push(n),e.set(t,s)}return e}async toObject(){const e={};for await(const[t,n]of this._elements){const s=e[t]??[];s.push(n),e[t]=s}return e}[Symbol.toStringTag]="AggregatedAsyncIterator"}class d{_iterator;constructor(e){if(e instanceof Function){const t=e();Symbol.asyncIterator in t?this._iterator=t:this._iterator=(async function*(){let n=[];for(;;){const s=t.next(...n);if(s.done)return s.value;n=[yield s.value]}})()}else if(Symbol.asyncIterator in e)this._iterator=e[Symbol.asyncIterator]();else if(Symbol.iterator in e){const t=e[Symbol.iterator]();this._iterator=(async function*(){for(;;){const n=t.next();if(n.done)return n.value;yield n.value}})()}else this._iterator=(async function*(){let t=[];for(;;){const n=await e.next(...t);if(n.done)return n.value;t=[yield n.value]}})()}async every(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!0;if(!await e(n.value,t))return!1;t+=1}}async some(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!1;if(await e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;await e(s.value,n)&&(yield s.value),n+=1}})}map(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;yield await e(s.value,n),n+=1}})}async reduce(e,t){let n=0,s=t;if(s===void 0){const i=await this._iterator.next();if(i.done)throw new f("Cannot reduce an empty iterator without an initial value.");s=i.value,n+=1}for(;;){const i=await this._iterator.next();if(i.done)return s;s=await e(s,i.value,n),n+=1}}flatMap(e){const t=this._iterator;return new d(async function*(){let n=0;for(;;){const s=await t.next();if(s.done)return s.value;const i=await e(s.value,n);if(i instanceof Array)for(const o of i)yield o;else yield i;n+=1}})}drop(e){const t=this._iterator;return new d(async function*(){let n=0;for(;n<e;){if((await t.next()).done)return;n+=1}for(;;){const s=await t.next();if(s.done)return s.value;yield s.value}})}take(e){const t=this._iterator;return new d(async function*(){let n=0;for(;n<e;){const s=await t.next();if(s.done)return s.value;yield s.value,n+=1}})}async find(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return;if(await e(n.value,t))return n.value;t+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new d(async function*(){const t=new Set;for(;;){const n=await e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}async count(){let e=0;for(;;){if((await this._iterator.next()).done)return e;e+=1}}async forEach(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return;await e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}async return(e){const t=await e;return this._iterator.return?await this._iterator.return(t):{done:!0,value:t}}throw(e){if(this._iterator.throw)return this._iterator.throw(e);throw e}groupBy(e){return new w(this.map(async(t,n)=>[await e(t,n),t]))}toArray(){return Array.fromAsync(this)}[Symbol.toStringTag]="SmartAsyncIterator";[Symbol.asyncIterator](){return this}}class h{_elements;constructor(e){this._elements=new a(e)}every(e){const t=new Map;for(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!0];o&&t.set(n,[i+1,e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}some(e){const t=new Map;for(const[n,s]of this._elements){const[i,o]=t.get(n)??[0,!1];o||t.set(n,[i+1,e(n,s,i)])}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}filter(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;e(s,i,o)&&(yield[s,i]),n.set(s,o+1)}})}map(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;yield[s,e(s,i,o)],n.set(s,o+1)}})}reduce(e,t){const n=new Map;for(const[s,i]of this._elements){let o,l;if(n.has(s))[o,l]=n.get(s);else if(t!==void 0)o=0,t instanceof Function?l=t(s):l=t;else{n.set(s,[0,i]);continue}n.set(s,[o+1,e(s,l,i,o)])}return new u(function*(){for(const[s,[i,o]]of n)yield[s,o]})}flatMap(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0,l=e(s,i,o);if(l instanceof Array)for(const b of l)yield[s,b];else yield[s,l];n.set(s,o+1)}})}drop(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;if(o<e){n.set(s,o+1);continue}yield[s,i]}})}take(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;o>=e||(yield[s,i],n.set(s,o+1))}})}find(e){const t=new Map;for(const[n,s]of this._elements){let[i,o]=t.get(n)??[0,void 0];o===void 0&&(e(n,s,i)&&(o=s),t.set(n,[i+1,o]))}return new u(function*(){for(const[n,[s,i]]of t)yield[n,i]})}enumerate(){return this.map((e,t,n)=>[n,t])}unique(){const e=this._elements;return new h(function*(){const t=new Map;for(const[n,s]of e){const i=t.get(n)??new Set;i.has(s)||(i.add(s),t.set(n,i),yield[n,s])}})}count(){const e=new Map;for(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new u(function*(){for(const[t,n]of e)yield[t,n]})}forEach(e){const t=new Map;for(const[n,s]of this._elements){const i=t.get(n)??0;e(n,s,i),t.set(n,i+1)}}reorganizeBy(e){const t=this._elements;return new h(function*(){const n=new Map;for(const[s,i]of t){const o=n.get(s)??0;yield[e(s,i,o),i],n.set(s,o+1)}})}keys(){const e=this._elements;return new a(function*(){const t=new Set;for(const[n]of e)t.has(n)||(t.add(n),yield n)})}entries(){return this._elements}values(){const e=this._elements;return new a(function*(){for(const[t,n]of e)yield n})}toArray(){const e=this.toMap();return Array.from(e.values())}toMap(){const e=new Map;for(const[t,n]of this._elements){const s=e.get(t)??[];s.push(n),e.set(t,s)}return e}toObject(){const e={};for(const[t,n]of this._elements){const s=e[t]??[];s.push(n),e[t]=s}return e}[Symbol.toStringTag]="AggregatedIterator"}const Y=Function;class N extends Y{constructor(){super("return this._invoke(...arguments);");const e=this.bind(this);return Object.setPrototypeOf(this,e),e}[Symbol.toStringTag]="CallableObject"}class g{_subscribers;constructor(){this._subscribers=new Map}createScope(){const e=new g;return this.subscribe("__internals__:clear",()=>e.clear()),this.subscribe("*",(t,...n)=>{e.publish(t,...n)}),e}publish(e,...t){let n,s=this._subscribers.get(e);return s?n=s.slice().map(i=>i(...t)):n=[],e.startsWith("__")||(s=this._subscribers.get("*"),s&&s.slice().forEach(i=>i(e,...t))),n}subscribe(e,t){const n=this._subscribers.get(e)??[];return n.push(t),this._subscribers.set(e,n),()=>{const s=n.indexOf(t);if(s<0)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");n.splice(s,1)}}unsubscribe(e,t){const n=this._subscribers.get(e);if(!n)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");const s=n.indexOf(t);if(s<0)throw new v("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");n.splice(s,1),n.length===0&&this._subscribers.delete(e)}unsubscribeAll(e){this._subscribers.delete(e)}clear(){this.publish("__internals__:clear"),this._subscribers.clear()}[Symbol.toStringTag]="Publisher"}const G=()=>{};class K extends N{_callback;_callbacks;_isEnabled;get isEnabled(){return this._isEnabled}_key;get key(){return this._key}_invoke;constructor(e,t="default"){super(),this._callbacks=new Map,this._isEnabled=!0,e?this._callbacks.set(t,e):(t="",e=(()=>{throw new P("The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?")})),this._key=t,this._callback=e,this._invoke=(...n)=>this._callback(...n)}enable(e){if(e===void 0){if(!this._key)throw new _("The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?");e=this._key}else if(e){if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`)}else throw new _("The key must be a non-empty string.");if(this._isEnabled)throw new p("The `SwitchableCallback` is already enabled.");this._callback=this._callbacks.get(e),this._isEnabled=!0}disable(){if(!this._isEnabled)throw new p("The `SwitchableCallback` is already disabled.");this._callback=G,this._isEnabled=!1}register(e,t){if(this._callbacks.size===0)this._key=e,this._callback=t;else if(this._callbacks.has(e))throw new _(`The key '${e}' has already been used for another callback.`);this._callbacks.set(e,t)}unregister(e){if(this._key===e)throw new _("Unable to unregister the currently selected callback.");if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`);this._callbacks.delete(e)}switch(e){if(!this._callbacks.has(e))throw new _(`The key '${e}' doesn't yet have any associated callback.`);this._key!==e&&(this._key=e,this._isEnabled&&(this._callback=this._callbacks.get(e)))}[Symbol.toStringTag]="SwitchableCallback"}class Q extends Map{_publisher;constructor(e){if(super(),this._publisher=new g,e)for(const[t,n]of e)this.set(t,n)}set(e,t){return super.set(e,t),this._publisher.publish("add",e,t),this}delete(e){const t=this.get(e);return t===void 0?!1:(super.delete(e),this._publisher.publish("remove",e,t),!0)}clear(){const e=this.size;super.clear(),e>0&&this._publisher.publish("clear")}onAdd(e){return this._publisher.subscribe("add",e)}onRemove(e){return this._publisher.subscribe("remove",e)}onClear(e){return this._publisher.subscribe("clear",e)}[Symbol.toStringTag]="MapView"}class H extends Set{_publisher;constructor(e){if(super(),this._publisher=new g,e)for(const t of e)this.add(t)}add(e){return super.add(e),this._publisher.publish("add",e),this}delete(e){const t=super.delete(e);return t&&this._publisher.publish("remove",e),t}clear(){const e=this.size;super.clear(),e>0&&this._publisher.publish("clear")}onAdd(e){return this._publisher.subscribe("add",e)}onRemove(e){return this._publisher.subscribe("remove",e)}onClear(e){return this._publisher.subscribe("clear",e)}[Symbol.toStringTag]="SetView"}class X{_preferPersistence;_volatile;_persistent;constructor(e=!0){if(!E)throw new C("The `JSONStorage` class can only be instantiated within a browser environment.");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const s=e.getItem(t);if(s)try{return JSON.parse(s)}catch{console.warn(`The "${s}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const s=JSON.stringify(n);s?e.setItem(t,s):e.removeItem(t)}get(e,t,n=this._preferPersistence){const s=n?this._persistent:this._volatile;return this._get(s,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,n=this._preferPersistence){const s=n?this._persistent:this._volatile;this._set(s,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}delete(e,t){(t?this._persistent:this._volatile).removeItem(e)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}[Symbol.toStringTag]="JSONStorage"}class m{static FromPromise(e){return new m((t,n)=>e.then(t,n))}_isPending;get isPending(){return this._isPending}_isFulfilled;get isFulfilled(){return this._isFulfilled}_isRejected;get isRejected(){return this._isRejected}_promise;constructor(e){this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const t=s=>(this._isPending=!1,this._isFulfilled=!0,s),n=s=>{throw this._isPending=!1,this._isRejected=!0,s};this._promise=new Promise(e).then(t,n)}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}[Symbol.toStringTag]="SmartPromise"}class M extends m{_resolve;get resolve(){return this._resolve}_reject;get reject(){return this._reject}constructor(e,t){let n,s;super((i,o)=>{n=i,s=o}),this._promise=this._promise.then(e,t),this._resolve=n,this._reject=s}watch(e){return e.then(this.resolve,this.reject),this}[Symbol.toStringTag]="DeferredPromise"}class O extends m{constructor(e,t){super((n,s)=>{const i=k=>{clearTimeout(b),n(k)},o=k=>{clearTimeout(b),s(k)},b=setTimeout(()=>o(new j("The operation has timed out.")),t);e(i,o)})}[Symbol.toStringTag]="TimedPromise"}class Z extends m{_count;get isPending(){return this._count>0}get isFulfilled(){return this._count===0}get isRejected(){throw new f("`PromiseQueue` doesn't support rejection states.")}constructor(){super(e=>e()),this._count=0,this._isPending=!1,this._isFulfilled=!1,this._isRejected=!1}enqueue(e,t){if(this._count+=1,e instanceof M){const s=e;e=()=>(s.resolve(),s)}const n=(s,i)=>{this._promise=this._promise.then(e).then(o=>{this._count-=1,s(o)}).catch(o=>{this._count-=1,i(o)})};return t?new O(n,t):new m(n)}[Symbol.toStringTag]="PromiseQueue"}var S=(r=>(r[r.Millisecond=1]="Millisecond",r[r.Second=1e3]="Second",r[r.Minute=6e4]="Minute",r[r.Hour=36e5]="Hour",r[r.Day=864e5]="Day",r[r.Week=6048e5]="Week",r[r.Month=2592e6]="Month",r[r.Year=31536e6]="Year",r))(S||{}),I=(r=>(r[r.Sunday=0]="Sunday",r[r.Monday=1]="Monday",r[r.Tuesday=2]="Tuesday",r[r.Wednesday=3]="Wednesday",r[r.Thursday=4]="Thursday",r[r.Friday=5]="Friday",r[r.Saturday=6]="Saturday",r))(I||{});function W(r,e,t=864e5){let n;return r=new Date(r),e=new Date(e),r<e?n=Math.floor:n=Math.ceil,n((e.getTime()-r.getTime())/t)}function U(r,e,t=864e5){if(r=new Date(r),e=new Date(e),r>=e)throw new y("The end date must be greater than the start date.");return new a(function*(){const n=e.getTime();let s=r.getTime();for(;s<n;)yield new Date(s),s+=t})}function q(r,e=864e5){if(e<=1)throw new y("Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead.");if(e>864e5)throw new y("Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years.");return r=new Date(r),new Date(Math.floor(r.getTime()/e)*e)}function ee(r,e=0){r=new Date(r);const t=7-e,n=(r.getUTCDay()+t)%7,s=r.getTime()-864e5*n;return q(new Date(s))}class R{_handle;_startTime;get startTime(){return this._startTime}_isRunning;get isRunning(){return this._isRunning}get elapsedTime(){return performance.now()-this._startTime}_publisher;_start;_stop;constructor(e,t=40){this._startTime=0,this._isRunning=!1,E?(this._start=()=>{e(this.elapsedTime),this._handle=window.requestAnimationFrame(this._start)},this._stop=()=>window.cancelAnimationFrame(this._handle)):(console.warn(`Not a browser environment detected. Using setInterval@${t}ms instead of requestAnimationFrame...`),this._start=()=>{this._handle=setInterval(()=>e(this.elapsedTime),t)},this._stop=()=>clearInterval(this._handle)),this._publisher=new g}start(e=0){if(this._isRunning)throw new p("The game loop has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0,this._publisher.publish("start")}stop(){if(!this._isRunning)throw new p("The game loop had already stopped or hadn't yet started.");if(!this._handle)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,this._publisher.publish("stop")}onStart(e){return this._publisher.subscribe("start",e)}onStop(e){return this._publisher.subscribe("stop",e)}[Symbol.toStringTag]="GameLoop"}class te extends R{constructor(e=S.Second){super(t=>this._publisher.publish("tick",t),e)}start(e=0){if(this._isRunning)throw new p("The clock has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0,this._publisher.publish("start")}stop(){if(!this._isRunning)throw new p("The clock had already stopped or hadn't yet started.");if(!this._handle)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,this._publisher.publish("stop")}onTick(e,t=0){if(t<0)throw new y("The tick step must be a non-negative number.");if(t===0)return this._publisher.subscribe("tick",e);let n=0;return this._publisher.subscribe("tick",s=>{s-n<t||(e(s),n=s)})}[Symbol.toStringTag]="Clock"}class ne extends R{_duration;get duration(){return this._duration}get remainingTime(){return this._duration-this.elapsedTime}_deferrer;constructor(e,t=S.Second){const n=()=>{const s=this.remainingTime;s<=0?(this._deferrerStop(),this._publisher.publish("tick",0),this._publisher.publish("expire")):this._publisher.publish("tick",s)};super(n,t),this._duration=e}_deferrerStop(e){if(!this._isRunning)throw new p("The countdown hadn't yet started.");if(!this._deferrer)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1,e!==void 0?this._deferrer.reject(e):this._deferrer.resolve(),this._deferrer=void 0}start(e=this.duration){if(this._isRunning)throw new p("The countdown had already stopped or hadn't yet started.");if(this._deferrer)throw new x;return this._deferrer=new M,super.start(this.duration-e),this._publisher.publish("start"),this._deferrer}stop(e){this._deferrerStop(e),this._publisher.publish("stop",e)}onTick(e,t=0){if(t<0)throw new y("The tick step must be a non-negative number.");if(t===0)return this._publisher.subscribe("tick",e);let n=this.remainingTime;return this._publisher.subscribe("tick",s=>{n-s<t||(e(s),n=s)})}onExpire(e){return this._publisher.subscribe("expire",e)}[Symbol.toStringTag]="Countdown"}class se{static Linear(e){const t=e-1;return new a(function*(){for(let n=0;n<e;n+=1)yield n/t})}static Exponential(e,t=2){if(t<0)throw new f("The base of the exponential curve cannot be negative.");const n=e-1;return new a(function*(){for(let s=0;s<e;s+=1)yield Math.pow(s/n,t)})}constructor(){}[Symbol.toStringTag]="Curve"}class F{static Boolean(e=.5){return Math.random()<e}static Integer(e,t){return Math.floor(t===void 0?Math.random()*e:Math.random()*(t-e)+e)}static Decimal(e,t){return e===void 0?Math.random():t===void 0?Math.random()*e:Math.random()*(t-e)+e}static Index(e){if(e.length===0)throw new f("You must provide at least one element.");return this.Integer(e.length)}static Choice(e){return e[F.Index(e)]}constructor(){}[Symbol.toStringTag]="Random"}function ie(r){return new m(e=>setTimeout(e,r))}function re(){return new m(r=>requestAnimationFrame(()=>r()))}function oe(){return new m(r=>setTimeout(r))}function ae(r,e="text/javascript"){return new m((t,n)=>{const s=document.createElement("script");s.async=!0,s.defer=!0,s.src=r,s.type=e,s.onload=i=>t(),s.onerror=i=>n(i),document.body.appendChild(s)})}function le(...r){return new a(function*(){for(const e of r)for(const t of e)yield t})}function ue(r){if(r instanceof Array)return r.length;let e=0;for(const t of r)e+=1;return e}function ce(r){return new a(function*(){let e=0;for(const t of r)yield[e,t],e+=1})}function he(r,e,t=1){if(t<=0)throw new y("Step must be always a positive number, even when generating numbers in reverse order.");return e===void 0&&(e=r,r=0),r>e?new a(function*(){for(let n=r;n>e;n-=t)yield n}):new a(function*(){for(let n=r;n<e;n+=t)yield n})}function fe(r){const e=Array.from(r);for(let t=e.length-1;t>0;t-=1){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}function de(r){return new a(function*(){const e=new Set;for(const t of r)e.has(t)||(e.add(t),yield t)})}function z(r,e){const t=r[Symbol.iterator](),n=e[Symbol.iterator]();return new a(function*(){for(;;){const s=t.next(),i=n.next();if(s.done||i.done)break;yield[s.value,i.value]}})}function me(r,e){if(e===void 0){let i=0,o=0;for(const l of r)i+=l,o+=1;if(o===0)throw new f("You must provide at least one value.");return i/o}let t=0,n=0,s=0;for(const[i,o]of z(r,e)){if(o<=0)throw new f(`The weight for the value #${s} must be greater than zero.`);t+=i*o,n+=o,s+=1}if(s===0)throw new f("You must provide at least one value and weight.");if(n<=0)throw new f("The sum of weights must be greater than zero.");return t/n}function we(r){let e=0;for(let t=0;t<r.length;t+=1){const n=r.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function pe(r){let e=0;for(const t of r)e+=t;return e}function _e(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const ye="2.2.0";exports.AggregatedAsyncIterator=w;exports.AggregatedIterator=h;exports.CallableObject=N;exports.Clock=te;exports.Countdown=ne;exports.Curve=se;exports.DeferredPromise=M;exports.EnvironmentException=C;exports.Exception=c;exports.FatalErrorException=x;exports.FileException=T;exports.FileExistsException=D;exports.FileNotFoundException=V;exports.GameLoop=R;exports.JSONStorage=X;exports.KeyException=_;exports.MapView=Q;exports.NetworkException=B;exports.NotImplementedException=P;exports.PermissionException=J;exports.PromiseQueue=Z;exports.Publisher=g;exports.Random=F;exports.RangeException=y;exports.ReducedIterator=u;exports.ReferenceException=v;exports.RuntimeException=p;exports.SetView=H;exports.SmartAsyncIterator=d;exports.SmartIterator=a;exports.SmartPromise=m;exports.SwitchableCallback=K;exports.TimeUnit=S;exports.TimedPromise=O;exports.TimeoutException=j;exports.TypeException=L;exports.VERSION=ye;exports.ValueException=f;exports.WeekDay=I;exports.average=me;exports.capitalize=_e;exports.chain=le;exports.count=ue;exports.dateDifference=W;exports.dateRange=U;exports.dateRound=q;exports.delay=ie;exports.enumerate=ce;exports.getWeek=ee;exports.hash=we;exports.isBrowser=E;exports.isNode=A;exports.isWorker=$;exports.loadScript=ae;exports.nextAnimationFrame=re;exports.range=he;exports.shuffle=fe;exports.sum=pe;exports.unique=de;exports.yieldToEventLoop=oe;exports.zip=z;
6
6
  //# sourceMappingURL=core.cjs.map