@byloth/core 2.0.0-rc.2 → 2.0.0-rc.4
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.js +1070 -862
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +3 -3
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +7 -11
- package/src/helpers.ts +7 -0
- package/src/index.ts +10 -12
- package/src/models/aggregators/aggregated-async-iterator.ts +134 -81
- package/src/models/aggregators/aggregated-iterator.ts +133 -82
- package/src/models/aggregators/index.ts +1 -3
- package/src/models/aggregators/reduced-iterator.ts +118 -30
- package/src/models/aggregators/types.ts +15 -10
- package/src/models/exceptions/core.ts +3 -3
- package/src/models/exceptions/index.ts +13 -13
- package/src/models/game-loop.ts +2 -0
- package/src/models/index.ts +0 -2
- package/src/models/iterators/smart-async-iterator.ts +109 -23
- package/src/models/iterators/smart-iterator.ts +105 -12
- package/src/models/iterators/types.ts +17 -7
- package/src/models/json/json-storage.ts +2 -3
- package/src/models/json/types.ts +5 -1
- package/src/models/promises/deferred-promise.ts +1 -1
- package/src/models/promises/smart-promise.ts +6 -1
- package/src/models/promises/timed-promise.ts +1 -1
- package/src/models/publisher.ts +1 -1
- package/src/models/timers/clock.ts +3 -1
- package/src/models/timers/countdown.ts +3 -1
- package/src/models/types.ts +9 -9
- package/src/utils/async.ts +4 -4
- package/src/utils/date.ts +3 -0
- package/src/utils/random.ts +4 -3
- package/src/models/aggregators/aggregator.ts +0 -46
- package/src/models/aggregators/async-aggregator.ts +0 -56
package/dist/core.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(a,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(a=typeof globalThis<"u"?globalThis:a||self,f(a.Core={}))})(this,function(a){"use strict";var mt=Object.defineProperty;var wt=(a,f,v)=>f in a?mt(a,f,{enumerable:!0,configurable:!0,writable:!0,value:v}):a[f]=v;var u=(a,f,v)=>wt(a,typeof f!="symbol"?f+"":f,v);var $,V,W,z,J,Y,B,G,K,L,H,Q,X,Z,U,ee,te,ne,re,ie,se,oe,ae,ue,ce,le,fe,he,de,me,we,ye,_e,pe,ge,ve,xe,be,ke,Se,Ee,Te,Me,Re,Fe,Pe,Ie,je,Ae,Ce,De,Ne;const f=typeof window<"u"&&typeof window.document<"u",v=typeof process<"u"&&(($=process.versions)==null?void 0:$.node),qe=typeof self=="object"&&((V=self.constructor)==null?void 0:V.name)==="DedicatedWorkerGlobalScope";class h extends(z=Error,W=Symbol.toStringTag,z){constructor(e,n,r="Exception"){super(e);u(this,W,"Exception");this.cause=n,this.name=r,n&&(n instanceof Error?this.stack+=`
|
|
2
2
|
|
|
3
|
-
Caused by ${
|
|
3
|
+
Caused by ${n.stack}`:this.stack+=`
|
|
4
4
|
|
|
5
|
-
Caused by ${t}`)}get[Symbol.toStringTag](){return"Exception"}}class v extends d{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)}get[Symbol.toStringTag](){return"FatalErrorException"}}class $ extends v{constructor(e,t,n="NotImplementedException"){e===void 0&&(e="This feature is not implemented yet. Please, try again later."),super(e,t,n)}get[Symbol.toStringTag](){return"NotImplementedException"}}class E extends d{constructor(e,t,n="FileException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileException"}}class W extends E{constructor(e,t,n="FileExistsException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileExistsException"}}class z extends E{constructor(e,t,n="FileNotFoundException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileNotFoundException"}}class J extends d{constructor(e,t,n="KeyException"){super(e,t,n)}get[Symbol.toStringTag](){return"KeyException"}}class V extends d{constructor(e,t,n="NetworkException"){super(e,t,n)}get[Symbol.toStringTag](){return"NetworkException"}}class Y extends d{constructor(e,t,n="PermissionException"){super(e,t,n)}get[Symbol.toStringTag](){return"PermissionException"}}class I extends d{constructor(e,t,n="ReferenceException"){super(e,t,n)}get[Symbol.toStringTag](){return"ReferenceException"}}class y extends d{constructor(e,t,n="RuntimeException"){super(e,t,n)}get[Symbol.toStringTag](){return"RuntimeException"}}class B extends y{constructor(e,t,n="EnvironmentException"){super(e,t,n)}get[Symbol.toStringTag](){return"EnvironmentException"}}class j extends d{constructor(e,t,n="TimeoutException"){super(e,t,n)}get[Symbol.toStringTag](){return"TimeoutException"}}class K extends d{constructor(e,t,n="TypeException"){super(e,t,n)}get[Symbol.toStringTag](){return"TypeException"}}class m extends d{constructor(e,t,n="ValueException"){super(e,t,n)}get[Symbol.toStringTag](){return"ValueException"}}class k extends m{constructor(e,t,n="RangeException"){super(e,t,n)}get[Symbol.toStringTag](){return"RangeException"}}class c{constructor(e){a(this,"_iterator");a(this,"return");a(this,"throw");e instanceof Function?this._iterator=e():Symbol.iterator in e?this._iterator=e[Symbol.iterator]():this._iterator=e,this._iterator.return&&(this.return=t=>this._iterator.return(t)),this._iterator.throw&&(this.throw=t=>this._iterator.throw(t))}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 c(function*(){let n=0;for(;;){const r=t.next();if(r.done)return r.value;e(r.value,n)&&(yield r.value),n+=1}})}map(e){const t=this._iterator;return new c(function*(){let n=0;for(;;){const r=t.next();if(r.done)return r.value;yield e(r.value,n),n+=1}})}reduce(e,t){let n=0,r=t;if(r===void 0){const s=this._iterator.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");r=s.value,n+=1}for(;;){const s=this._iterator.next();if(s.done)return r;r=e(r,s.value,n),n+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new c(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)}toArray(){return Array.from(this)}get[Symbol.toStringTag](){return"SmartIterator"}[Symbol.iterator](){return this}}class w{constructor(e){a(this,"_iterator");a(this,"return");a(this,"throw");if(e instanceof Function){const t=e();Symbol.asyncIterator in t?this._iterator=t:this._iterator=async function*(){let n=[];for(;;){const r=t.next(...n);if(r.done)return r.value;n=[yield r.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]}}();this._iterator.return&&(this.return=t=>this._iterator.return(t)),this._iterator.throw&&(this.throw=t=>this._iterator.throw(t))}async every(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!0;if(!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(e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new w(async function*(){let n=0;for(;;){const r=await t.next();if(r.done)return r.value;e(r.value,n)&&(yield r.value),n+=1}})}map(e){const t=this._iterator;return new w(async function*(){let n=0;for(;;){const r=await t.next();if(r.done)return r.value;yield e(r.value,n),n+=1}})}async reduce(e,t){let n=0,r=t;if(r===void 0){const s=await this._iterator.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");r=s.value,n+=1}for(;;){const s=await this._iterator.next();if(s.done)return r;r=await e(r,s.value,n),n+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new w(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 toArray(){const e=[];for(;;){const t=await this._iterator.next();if(t.done)return e;e.push(t.value)}}get[Symbol.toStringTag](){return"SmartAsyncIterator"}[Symbol.asyncIterator](){return this}}class l{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){const t=this._elements;return new l(function*(){for(const[n,[r,s]]of t.enumerate())e(r,s,n)&&(yield[r,s])})}map(e){const t=this._elements;return new l(function*(){for(const[n,[r,s]]of t.enumerate())yield[r,e(r,s,n)]})}reduce(e,t){let n=0,r;if(t!==void 0)r=t;else{const s=this._elements.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");n+=1,r=s.value[1]}for(const[s,u]of this._elements)r=e(s,r,u,n),n+=1;return r}keys(){const e=this._elements;return new c(function*(){for(const[t]of e)yield t})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.items())}toObject(){return Object.fromEntries(this.items())}get[Symbol.toStringTag](){return"ReducedIterator"}}class g{constructor(e){a(this,"_elements");this._elements=new c(e)}every(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}some(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new g(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new g(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,e(r,s,u)]}})}reduce(e,t){const n=new Map;for(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=t(r);else{n.set(r,[0,s]);continue}h=e(r,h,s,u),n.set(r,[u,h])}return new l(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new g(function*(){const t=new Map;for(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}count(){const e=new Map;for(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new l(function*(){for(const[t,n]of e)yield[t,n]})}first(){const e=new Map;for(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}last(){const e=new Map;for(const[t,n]of this._elements)e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new c(function*(){const t=new Set;for(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.toMap().values())}toMap(){const e=new Map;for(const[t,n]of this._elements){const r=e.get(t)??[];r.push(n),e.set(t,r)}return e}toObject(){const e={};for(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedIterator"}}class x{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){return new x(this._elements.filter(e))}map(e){return new x(this._elements.map(e))}unique(){return new x(this._elements.unique())}groupBy(e){return new g(this._elements.map((t,n)=>[e(t,n),t]))}get[Symbol.toStringTag](){return"Aggregator"}}class p{constructor(e){a(this,"_elements");this._elements=new w(e)}async every(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,await e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}async some(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,await e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new p(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),await e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new p(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,await e(r,s,u)]}})}async reduce(e,t){const n=new Map;for await(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=await t(r);else{n.set(r,[0,s]);continue}h=await e(r,h,s,u),n.set(r,[u,h])}return new l(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new p(async function*(){const t=new Map;for await(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}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 l(function*(){for(const[t,n]of e)yield[t,n]})}async first(){const e=new Map;for await(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}async last(){const e=new Map;for await(const[t,n]of this._elements)e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new w(async function*(){const t=new Set;for await(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new w(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 r=e.get(t)??[];r.push(n),e.set(t,r)}return e}async toObject(){const e={};for await(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedAsyncIterator"}}class b{constructor(e){a(this,"_elements");this._elements=new w(e)}filter(e){return new b(this._elements.filter(e))}map(e){return new b(this._elements.map(e))}unique(){return new b(this._elements.unique())}groupBy(e){return new p(this._elements.map(async(t,n)=>[await e(t,n),t]))}get[Symbol.toStringTag](){return"AsyncAggregator"}}var S=(i=>(i[i.Millisecond=1]="Millisecond",i[i.Second=1e3]="Second",i[i.Minute=6e4]="Minute",i[i.Hour=36e5]="Hour",i[i.Day=864e5]="Day",i[i.Week=6048e5]="Week",i[i.Month=2592e6]="Month",i[i.Year=31536e6]="Year",i))(S||{});function G(i,e,t=864e5){return i=new Date(i),e=new Date(e),Math.floor((e.getTime()-i.getTime())/t)}function H(i,e,t=864e5){return i=new Date(i),e=new Date(e),new c(function*(){const n=e.getTime();let r=i.getTime();for(;r<n;)yield new Date(r),r+=t})}function L(i,e=864e5){return i=new Date(i),new Date(Math.floor(i.getTime()/e)*e)}class T{constructor(e,t=30){a(this,"_handle");a(this,"_startTime");a(this,"_isRunning");a(this,"_start");a(this,"_stop");this._startTime=0,this._isRunning=!1,f?(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}fps instead of requestAnimationFrame...`),this._start=()=>{const n=S.Second/t;this._handle=setInterval(()=>e(this.elapsedTime),n)},this._stop=()=>clearInterval(this._handle))}get startTime(){return this._startTime}get isRunning(){return this._isRunning}get elapsedTime(){return performance.now()-this._startTime}start(e=0){if(this._isRunning)throw new y("The game loop has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0}stop(){if(!this._isRunning)throw new y("The game loop hadn't yet started.");if(!this._handle)throw new v;this._stop(),this._handle=void 0,this._isRunning=!1}}class Q{constructor(e=!0){a(this,"_preferPersistence");a(this,"_volatile");a(this,"_persistent");if(this._preferPersistence=e,!f)throw new B("The `JSONStorage` class can only be instantiated within a browser environment.");this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const r=e.getItem(t);if(r)try{return JSON.parse(r)}catch{console.warn(`The "${r}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const r=JSON.stringify(n);r?e.setItem(t,r):e.removeItem(t)}get(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;return this._get(r,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 r=n?this._persistent:this._volatile;this._set(r,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}get[Symbol.toStringTag](){return"JSONStorage"}}class M{constructor(e){a(this,"_isPending");a(this,"_isFulfilled");a(this,"_isRejected");a(this,"_promise");this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const t=r=>(this._isPending=!1,this._isFulfilled=!0,r),n=r=>{throw this._isPending=!1,this._isRejected=!0,r};this._promise=new Promise(e).then(t,n)}get isPending(){return this._isPending}get isFulfilled(){return this._isFulfilled}get isRejected(){return this._isRejected}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}get[Symbol.toStringTag](){return"SmartPromise"}}class A extends M{constructor(t,n){let r,s;super((u,h)=>{r=u,s=h});a(this,"_resolve");a(this,"_reject");this._promise.then(t,n),this._resolve=r,this._reject=s}get resolve(){return this._resolve}get reject(){return this._reject}watch(t){return t.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class X extends M{constructor(e,t){super((n,r)=>{const s=P=>{clearTimeout(q),n(P)},u=P=>{clearTimeout(q),r(P)},q=setTimeout(()=>u(new j("The operation has timed out.")),t);e(s,u)})}get[Symbol.toStringTag](){return"TimedPromise"}}class R{constructor(){a(this,"_subscribers");this._subscribers=[]}subscribe(e){return this._subscribers.push(e),()=>{const t=this._subscribers.indexOf(e);if(t<0)throw new I("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");this._subscribers.splice(t,1)}}publish(...e){return this._subscribers.slice().map(t=>t(...e))}get[Symbol.toStringTag](){return"Publisher"}}class Z extends T{constructor(t=S.Second){super(n=>this._publisher.publish(n),t);a(this,"_publisher");this._publisher=new R}start(t=0){if(this._isRunning)throw new y("The clock has already been started.");super.start(t)}stop(){if(!this._isRunning)throw new y("The clock hadn't yet started.");super.stop()}onTick(t,n=0){if(n<0)throw new k("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(t);let r=0;return this._publisher.subscribe(s=>{s-r<n||(t(s),r=s)})}}class U extends T{constructor(t,n=S.Second){super(()=>{const s=this.remainingTime;this._publisher.publish(s),s<=0&&this.stop()},n);a(this,"_deferrer");a(this,"_publisher");a(this,"_duration");this._publisher=new R,this._duration=t}get duration(){return this._duration}get remainingTime(){return this._duration-this.elapsedTime}start(t=this.duration){if(this._isRunning)throw new y("The countdown has already been started.");if(this._deferrer)throw new v;return this._deferrer=new A,super.start(this.duration-t),this._deferrer}stop(t){if(!this._isRunning)throw new y("The countdown hadn't yet started.");if(!this._deferrer)throw new v;super.stop(),t!==void 0?this._deferrer.reject(t):this._deferrer.resolve(),this._deferrer=void 0}onTick(t,n=0){if(n<0)throw new k("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(t);let r=0;return this._publisher.subscribe(s=>{r-s<n||(t(s),r=s)})}}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 m("You must provide at least one element.");return this.Integer(e.length)}static Choice(e){return e[F.Index(e)]}constructor(){}}async function ee(i){return new Promise((e,t)=>setTimeout(e,i))}async function te(){return new Promise((i,e)=>requestAnimationFrame(()=>i()))}function ne(i,e="text/javascript"){return new Promise((t,n)=>{const r=document.createElement("script");r.async=!0,r.defer=!0,r.src=i,r.type=e,r.onload=()=>t(),r.onerror=()=>n(),document.body.appendChild(r)})}function re(...i){return new c(function*(){for(const e of i)for(const t of e)yield t})}function se(i){if(Array.isArray(i))return i.length;let e=0;for(const t of i)e+=1;return e}function ie(i){return new c(function*(){let e=0;for(const t of i)yield[e,t],e+=1})}function oe(i,e,t=1){return new c(function*(){e===void 0&&(e=i,i=0),i>e&&(t=t??-1);for(let n=i;n<e;n+=t)yield n})}function ue(i){const e=Array.from(i);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 ae(i){return new c(function*(){const e=new Set;for(const t of i)e.has(t)||(e.add(t),yield t)})}function D(i,e){return new c(function*(){const t=i[Symbol.iterator](),n=e[Symbol.iterator]();for(;;){const r=t.next(),s=n.next();if(r.done||s.done)break;yield[r.value,s.value]}})}function ce(i,e){if(e===void 0){let s=0,u=0;for(const h of i)s+=h,u+=1;if(u===0)throw new m("You must provide at least one value.");return s/u}let t=0,n=0,r=0;for(const[s,u]of D(i,e)){if(u<=0)throw new m(`The weight for the value #${r} must be greater than zero.`);t+=s*u,n+=u,r+=1}if(r===0)throw new m("You must provide at least one value and weight.");if(n>0)throw new m("The sum of weights must be greater than zero.");return t/n}function le(i){let e=0;for(let t=0;t<i.length;t+=1){const n=i.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function he(i){let e=0;for(const t of i)e+=t;return e}function fe(i){return`${i.charAt(0).toUpperCase()}${i.slice(1)}`}const de="2.0.0-rc.2";o.AggregatedAsyncIterator=p,o.AggregatedIterator=g,o.Aggregator=x,o.AsyncAggregator=b,o.Clock=Z,o.Countdown=U,o.DeferredPromise=A,o.Exception=d,o.FatalErrorException=v,o.FileException=E,o.FileExistsException=W,o.FileNotFoundException=z,o.GameLoop=T,o.JSONStorage=Q,o.KeyException=J,o.NetworkException=V,o.NotImplementedException=$,o.PermissionException=Y,o.Publisher=R,o.Random=F,o.RangeException=k,o.ReducedIterator=l,o.ReferenceException=I,o.RuntimeException=y,o.SmartAsyncIterator=w,o.SmartIterator=c,o.SmartPromise=M,o.TimeUnit=S,o.TimedPromise=X,o.TimeoutException=j,o.TypeException=K,o.VERSION=de,o.ValueException=m,o.average=ce,o.capitalize=fe,o.chain=re,o.count=se,o.dateDifference=G,o.dateRange=H,o.dateRound=L,o.delay=ee,o.enumerate=ie,o.hash=le,o.isBrowser=f,o.isNode=_,o.isWebWorker=O,o.loadScript=ne,o.nextAnimationFrame=te,o.range=oe,o.shuffle=ue,o.sum=he,o.unique=ae,o.zip=D,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
5
|
+
Caused by ${n}`)}static FromUnknown(e){if(e instanceof h)return e;if(e instanceof Error){const n=new h(e.message);return n.stack=e.stack,n.name=e.name,n}return new h(`${e}`)}}class x extends(Y=h,J=Symbol.toStringTag,Y){constructor(e,n,r="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,n,r);u(this,J,"FatalErrorException")}}class $e extends(G=x,B=Symbol.toStringTag,G){constructor(e,n,r="NotImplementedException"){e===void 0&&(e="This feature is not implemented yet. Please, try again later.");super(e,n,r);u(this,B,"NotImplementedException")}}class M extends(L=h,K=Symbol.toStringTag,L){constructor(e,n,r="FileException"){super(e,n,r);u(this,K,"FileException")}}class Ve extends(Q=M,H=Symbol.toStringTag,Q){constructor(e,n,r="FileExistsException"){super(e,n,r);u(this,H,"FileExistsException")}}class We extends(Z=M,X=Symbol.toStringTag,Z){constructor(e,n,r="FileNotFoundException"){super(e,n,r);u(this,X,"FileNotFoundException")}}class ze extends(ee=h,U=Symbol.toStringTag,ee){constructor(e,n,r="KeyException"){super(e,n,r);u(this,U,"KeyException")}}class Je extends(ne=h,te=Symbol.toStringTag,ne){constructor(e,n,r="NetworkException"){super(e,n,r);u(this,te,"NetworkException")}}class Ye extends(ie=h,re=Symbol.toStringTag,ie){constructor(e,n,r="PermissionException"){super(e,n,r);u(this,re,"PermissionException")}}class D extends(oe=h,se=Symbol.toStringTag,oe){constructor(e,n,r="ReferenceException"){super(e,n,r);u(this,se,"ReferenceException")}}class y extends(ue=h,ae=Symbol.toStringTag,ue){constructor(e,n,r="RuntimeException"){super(e,n,r);u(this,ae,"RuntimeException")}}class Be extends(le=y,ce=Symbol.toStringTag,le){constructor(e,n,r="EnvironmentException"){super(e,n,r);u(this,ce,"EnvironmentException")}}class N extends(he=h,fe=Symbol.toStringTag,he){constructor(e,n,r="TimeoutException"){super(e,n,r);u(this,fe,"TimeoutException")}}class Ge extends(me=h,de=Symbol.toStringTag,me){constructor(e,n,r="TypeException"){super(e,n,r);u(this,de,"TypeException")}}class w extends(ye=h,we=Symbol.toStringTag,ye){constructor(e,n,r="ValueException"){super(e,n,r);u(this,we,"ValueException")}}class R extends(pe=w,_e=Symbol.toStringTag,pe){constructor(e,n,r="RangeException"){super(e,n,r);u(this,_e,"RangeException")}}class l{constructor(t){u(this,"_iterator");u(this,"return");u(this,"throw");u(this,ge,"SmartIterator");t instanceof Function?this._iterator=t():Symbol.iterator in t?this._iterator=t[Symbol.iterator]():this._iterator=t,this._iterator.return&&(this.return=e=>this._iterator.return(e)),this._iterator.throw&&(this.throw=e=>this._iterator.throw(e))}every(t){let e=0;for(;;){const n=this._iterator.next();if(n.done)return!0;if(!t(n.value,e))return!1;e+=1}}some(t){let e=0;for(;;){const n=this._iterator.next();if(n.done)return!1;if(t(n.value,e))return!0;e+=1}}filter(t){const e=this._iterator;return new l(function*(){let n=0;for(;;){const r=e.next();if(r.done)return r.value;t(r.value,n)&&(yield r.value),n+=1}})}map(t){const e=this._iterator;return new l(function*(){let n=0;for(;;){const r=e.next();if(r.done)return r.value;yield t(r.value,n),n+=1}})}reduce(t,e){let n=0,r=e;if(r===void 0){const i=this._iterator.next();if(i.done)throw new w("Cannot reduce an empty iterator without an initial value.");r=i.value,n+=1}for(;;){const i=this._iterator.next();if(i.done)return r;r=t(r,i.value,n),n+=1}}flatMap(t){const e=this._iterator;return new l(function*(){let n=0;for(;;){const r=e.next();if(r.done)return r.value;const i=t(r.value,n);for(const o of i)yield o;n+=1}})}drop(t){const e=this._iterator;return new l(function*(){let n=0;for(;n<t;){if(e.next().done)return;n+=1}for(;;){const r=e.next();if(r.done)return r.value;yield r.value}})}take(t){const e=this._iterator;return new l(function*(){let n=0;for(;n<t;){const r=e.next();if(r.done)return r.value;yield r.value,n+=1}})}find(t){let e=0;for(;;){const n=this._iterator.next();if(n.done)return;if(t(n.value,e))return n.value;e+=1}}enumerate(){return this.map((t,e)=>[e,t])}unique(){const t=this._iterator;return new l(function*(){const e=new Set;for(;;){const n=t.next();if(n.done)return n.value;e.has(n.value)||(e.add(n.value),yield n.value)}})}count(){let t=0;for(;;){if(this._iterator.next().done)return t;t+=1}}forEach(t){let e=0;for(;;){const n=this._iterator.next();if(n.done)return;t(n.value,e),e+=1}}next(...t){return this._iterator.next(...t)}groupBy(t){return new b(this.map((e,n)=>[t(e,n),e]))}toArray(){return Array.from(this)}[(ge=Symbol.toStringTag,Symbol.iterator)](){return this}}ve=Symbol.toStringTag;const g=class g{constructor(t){u(this,"_elements");u(this,ve,"ReducedIterator");this._elements=new l(t)}every(t){for(const[e,[n,r]]of this._elements.enumerate())if(!t(n,r,e))return!1;return!0}some(t){for(const[e,[n,r]]of this._elements.enumerate())if(t(n,r,e))return!0;return!1}filter(t){const e=this._elements.enumerate();return new g(function*(){for(const[n,[r,i]]of e)t(r,i,n)&&(yield[r,i])})}map(t){const e=this._elements.enumerate();return new g(function*(){for(const[n,[r,i]]of e)yield[r,t(r,i,n)]})}reduce(t,e){let n=0,r=e;if(r===void 0){const i=this._elements.next();if(i.done)throw new w("Cannot reduce an empty iterator without an initial value.");r=i.value[1],n+=1}for(const[i,o]of this._elements)r=t(i,r,o,n),n+=1;return r}flatMap(t){const e=this._elements.enumerate();return new b(function*(){for(const[n,[r,i]]of e)for(const o of t(r,i,n))yield[r,o]})}drop(t){const e=this._elements.enumerate();return new g(function*(){for(const[n,[r,i]]of e)n>=t&&(yield[r,i])})}take(t){const e=this._elements.enumerate();return new g(function*(){for(const[n,[r,i]]of e){if(n>=t)break;yield[r,i]}})}enumerate(){return this.map((t,e,n)=>[n,e])}unique(){const t=this._elements;return new g(function*(){const e=new Set;for(const[n,r]of t)e.has(r)||(e.add(r),yield[n,r])})}count(){let t=0;for(const e of this._elements)t+=1;return t}forEach(t){for(const[e,[n,r]]of this._elements.enumerate())t(n,r,e)}keys(){const t=this._elements;return new l(function*(){for(const[e]of t)yield e})}items(){return this._elements}values(){const t=this._elements;return new l(function*(){for(const[e,n]of t)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.items())}toObject(){return Object.fromEntries(this.items())}};let d=g;xe=Symbol.toStringTag;const _=class _{constructor(t){u(this,"_elements");u(this,xe,"AggregatedAsyncIterator");this._elements=new m(t)}async every(t){const e=new Map;for await(const[n,r]of this._elements){const[i,o]=e.get(n)??[0,!0];o&&e.set(n,[i+1,await t(n,r,i)])}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}async some(t){const e=new Map;for await(const[n,r]of this._elements){const[i,o]=e.get(n)??[0,!1];o||e.set(n,[i+1,await t(n,r,i)])}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}filter(t){const e=this._elements;return new _(async function*(){const n=new Map;for await(const[r,i]of e){const o=n.get(r)??0;await t(r,i,o)&&(yield[r,i]),n.set(r,o+1)}})}map(t){const e=this._elements;return new _(async function*(){const n=new Map;for await(const[r,i]of e){const o=n.get(r)??0;yield[r,await t(r,i,o)],n.set(r,o+1)}})}async reduce(t,e){const n=new Map;for await(const[r,i]of this._elements){let o,c;if(n.has(r))[o,c]=n.get(r);else if(e!==void 0)o=0,c=await e(r);else{n.set(r,[0,i]);continue}n.set(r,[o+1,await t(r,c,i,o)])}return new d(function*(){for(const[r,[i,o]]of n)yield[r,o]})}flatMap(t){const e=this._elements;return new _(async function*(){const n=new Map;for await(const[r,i]of e){const o=n.get(r)??0,c=await t(r,i,o);for await(const T of c)yield[r,T];n.set(r,o+1)}})}drop(t){const e=this._elements;return new _(async function*(){const n=new Map;for await(const[r,i]of e){const o=n.get(r)??0;if(o<t){n.set(r,o+1);continue}yield[r,i]}})}take(t){const e=this._elements;return new _(async function*(){const n=new Map;for await(const[r,i]of e){const o=n.get(r)??0;if(o>=t){if(n.values().every(c=>c>=t))break;continue}yield[r,i],n.set(r,o+1)}})}async find(t){const e=new Map;for await(const[n,r]of this._elements){let[i,o]=e.get(n)??[0,void 0];o===void 0&&(await t(n,r,i)&&(o=r),e.set(n,[i+1,o]))}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}unique(){const t=this._elements;return new _(async function*(){const e=new Map;for await(const[n,r]of t){const i=e.get(n)??new Set;i.has(r)||(i.add(r),e.set(n,i),yield[n,r])}})}async count(){const t=new Map;for await(const[e]of this._elements){const n=t.get(e)??0;t.set(e,n+1)}return new d(function*(){for(const[e,n]of t)yield[e,n]})}async forEach(t){const e=new Map;for await(const[n,r]of this._elements){const i=e.get(n)??0;t(n,r,i),e.set(n,i+1)}}keys(){const t=this._elements;return new m(async function*(){const e=new Set;for await(const[n]of t)e.has(n)||(e.add(n),yield n)})}items(){return this._elements}values(){const t=this._elements;return new m(async function*(){for await(const[e,n]of t)yield n})}async toArray(){const t=await this.toMap();return Array.from(t.values())}async toMap(){const t=new Map;for await(const[e,n]of this._elements){const r=t.get(e)??[];r.push(n),t.set(e,r)}return t}async toObject(){const t={};for await(const[e,n]of this._elements){const r=t[e]??[];r.push(n),t[e]=r}return t}};let E=_;class m{constructor(t){u(this,"_iterator");u(this,"return");u(this,"throw");u(this,be,"SmartAsyncIterator");if(t instanceof Function){const e=t();Symbol.asyncIterator in e?this._iterator=e:this._iterator=async function*(){let n=[];for(;;){const r=e.next(...n);if(r.done)return r.value;n=[yield r.value]}}()}else if(Symbol.asyncIterator in t)this._iterator=t[Symbol.asyncIterator]();else if(Symbol.iterator in t){const e=t[Symbol.iterator]();this._iterator=async function*(){for(;;){const n=e.next();if(n.done)return n.value;yield n.value}}()}else this._iterator=async function*(){let e=[];for(;;){const n=await t.next(...e);if(n.done)return n.value;e=[yield n.value]}}();this._iterator.return&&(this.return=e=>this._iterator.return(e)),this._iterator.throw&&(this.throw=e=>this._iterator.throw(e))}async every(t){let e=0;for(;;){const n=await this._iterator.next();if(n.done)return!0;if(!await t(n.value,e))return!1;e+=1}}async some(t){let e=0;for(;;){const n=await this._iterator.next();if(n.done)return!1;if(await t(n.value,e))return!0;e+=1}}filter(t){const e=this._iterator;return new m(async function*(){let n=0;for(;;){const r=await e.next();if(r.done)return r.value;await t(r.value,n)&&(yield r.value),n+=1}})}map(t){const e=this._iterator;return new m(async function*(){let n=0;for(;;){const r=await e.next();if(r.done)return r.value;yield await t(r.value,n),n+=1}})}async reduce(t,e){let n=0,r=e;if(r===void 0){const i=await this._iterator.next();if(i.done)throw new w("Cannot reduce an empty iterator without an initial value.");r=i.value,n+=1}for(;;){const i=await this._iterator.next();if(i.done)return r;r=await t(r,i.value,n),n+=1}}flatMap(t){const e=this._iterator;return new m(async function*(){let n=0;for(;;){const r=await e.next();if(r.done)return r.value;const i=await t(r.value,n);for await(const o of i)yield o;n+=1}})}drop(t){const e=this._iterator;return new m(async function*(){let n=0;for(;n<t;){if((await e.next()).done)return;n+=1}for(;;){const r=await e.next();if(r.done)return r.value;yield r.value}})}take(t){const e=this._iterator;return new m(async function*(){let n=0;for(;n<t;){const r=await e.next();if(r.done)return r.value;yield r.value,n+=1}})}async find(t){let e=0;for(;;){const n=await this._iterator.next();if(n.done)return;if(await t(n.value,e))return n.value;e+=1}}enumerate(){return this.map((t,e)=>[e,t])}unique(){const t=this._iterator;return new m(async function*(){const e=new Set;for(;;){const n=await t.next();if(n.done)return n.value;e.has(n.value)||(e.add(n.value),yield n.value)}})}async count(){let t=0;for(;;){if((await this._iterator.next()).done)return t;t+=1}}async forEach(t){let e=0;for(;;){const n=await this._iterator.next();if(n.done)return;await t(n.value,e),e+=1}}next(...t){return this._iterator.next(...t)}groupBy(t){return new E(this.map(async(e,n)=>[await t(e,n),e]))}toArray(){return Array.fromAsync(this)}[(be=Symbol.toStringTag,Symbol.asyncIterator)](){return this}}ke=Symbol.toStringTag;const p=class p{constructor(t){u(this,"_elements");u(this,ke,"AggregatedIterator");this._elements=new l(t)}every(t){const e=new Map;for(const[n,r]of this._elements){const[i,o]=e.get(n)??[0,!0];o&&e.set(n,[i+1,t(n,r,i)])}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}some(t){const e=new Map;for(const[n,r]of this._elements){const[i,o]=e.get(n)??[0,!1];o||e.set(n,[i+1,t(n,r,i)])}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}filter(t){const e=this._elements;return new p(function*(){const n=new Map;for(const[r,i]of e){const o=n.get(r)??0;t(r,i,o)&&(yield[r,i]),n.set(r,o+1)}})}map(t){const e=this._elements;return new p(function*(){const n=new Map;for(const[r,i]of e){const o=n.get(r)??0;yield[r,t(r,i,o)],n.set(r,o+1)}})}reduce(t,e){const n=new Map;for(const[r,i]of this._elements){let o,c;if(n.has(r))[o,c]=n.get(r);else if(e!==void 0)o=0,c=e(r);else{n.set(r,[0,i]);continue}n.set(r,[o+1,t(r,c,i,o)])}return new d(function*(){for(const[r,[i,o]]of n)yield[r,o]})}flatMap(t){const e=this._elements;return new p(function*(){const n=new Map;for(const[r,i]of e){const o=n.get(r)??0,c=t(r,i,o);for(const T of c)yield[r,T];n.set(r,o+1)}})}drop(t){const e=this._elements;return new p(function*(){const n=new Map;for(const[r,i]of e){const o=n.get(r)??0;if(o<t){n.set(r,o+1);continue}yield[r,i]}})}take(t){const e=this._elements;return new p(function*(){const n=new Map;for(const[r,i]of e){const o=n.get(r)??0;if(o>=t){if(n.values().every(c=>c>=t))break;continue}yield[r,i],n.set(r,o+1)}})}find(t){const e=new Map;for(const[n,r]of this._elements){let[i,o]=e.get(n)??[0,void 0];o===void 0&&(t(n,r,i)&&(o=r),e.set(n,[i+1,o]))}return new d(function*(){for(const[n,[r,i]]of e)yield[n,i]})}enumerate(){return this.map((t,e,n)=>[n,e])}unique(){const t=this._elements;return new p(function*(){const e=new Map;for(const[n,r]of t){const i=e.get(n)??new Set;i.has(r)||(i.add(r),e.set(n,i),yield[n,r])}})}count(){const t=new Map;for(const[e]of this._elements){const n=t.get(e)??0;t.set(e,n+1)}return new d(function*(){for(const[e,n]of t)yield[e,n]})}forEach(t){const e=new Map;for(const[n,r]of this._elements){const i=e.get(n)??0;t(n,r,i),e.set(n,i+1)}}keys(){const t=this._elements;return new l(function*(){const e=new Set;for(const[n]of t)e.has(n)||(e.add(n),yield n)})}items(){return this._elements}values(){const t=this._elements;return new l(function*(){for(const[e,n]of t)yield n})}toArray(){const t=this.toMap();return Array.from(t.values())}toMap(){const t=new Map;for(const[e,n]of this._elements){const r=t.get(e)??[];r.push(n),t.set(e,r)}return t}toObject(){const t={};for(const[e,n]of this._elements){const r=t[e]??[];r.push(n),t[e]=r}return t}};let b=p;var k=(s=>(s[s.Millisecond=1]="Millisecond",s[s.Second=1e3]="Second",s[s.Minute=6e4]="Minute",s[s.Hour=36e5]="Hour",s[s.Day=864e5]="Day",s[s.Week=6048e5]="Week",s[s.Month=2592e6]="Month",s[s.Year=31536e6]="Year",s))(k||{});function Ke(s,t,e=864e5){return s=new Date(s),t=new Date(t),Math.floor((t.getTime()-s.getTime())/e)}function Le(s,t,e=864e5){return s=new Date(s),t=new Date(t),new l(function*(){const n=t.getTime();let r=s.getTime();for(;r<n;)yield new Date(r),r+=e})}function He(s,t=864e5){return s=new Date(s),new Date(Math.floor(s.getTime()/t)*t)}Se=Symbol.toStringTag;class F{constructor(t,e=30){u(this,"_handle");u(this,"_startTime");u(this,"_isRunning");u(this,"_start");u(this,"_stop");u(this,Se,"GameLoop");this._startTime=0,this._isRunning=!1,f?(this._start=()=>{t(this.elapsedTime),this._handle=window.requestAnimationFrame(this._start)},this._stop=()=>window.cancelAnimationFrame(this._handle)):(console.warn(`Not a browser environment detected. Using setInterval@${e}fps instead of requestAnimationFrame...`),this._start=()=>{const n=k.Second/e;this._handle=setInterval(()=>t(this.elapsedTime),n)},this._stop=()=>clearInterval(this._handle))}get startTime(){return this._startTime}get isRunning(){return this._isRunning}get elapsedTime(){return performance.now()-this._startTime}start(t=0){if(this._isRunning)throw new y("The game loop has already been started.");this._startTime=performance.now()-t,this._start(),this._isRunning=!0}stop(){if(!this._isRunning)throw new y("The game loop hadn't yet started.");if(!this._handle)throw new x;this._stop(),this._handle=void 0,this._isRunning=!1}}Ee=Symbol.toStringTag;class Qe{constructor(t=!0){u(this,"_preferPersistence");u(this,"_volatile");u(this,"_persistent");u(this,Ee,"JSONStorage");if(this._preferPersistence=t,!f)throw new Be("The `JSONStorage` class can only be instantiated within a browser environment.");this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(t,e,n){const r=t.getItem(e);if(r)try{return JSON.parse(r)}catch{console.warn(`The "${r}" value for "${e}" property cannot be parsed. Clearing the storage...`),t.removeItem(e)}return n}_set(t,e,n){const r=JSON.stringify(n);r?t.setItem(e,r):t.removeItem(e)}get(t,e,n=this._preferPersistence){const r=n?this._persistent:this._volatile;return this._get(r,t,e)}recall(t,e){return this._get(this._volatile,t,e)}retrieve(t,e){return this.recall(t)??this.read(t,e)}read(t,e){return this._get(this._persistent,t,e)}has(t,e){return(e?this._persistent:this._volatile).getItem(t)!==null}knows(t){return this._volatile.getItem(t)!==null}find(t){return this.knows(t)??this.exists(t)}exists(t){return this._persistent.getItem(t)!==null}set(t,e,n=this._preferPersistence){const r=n?this._persistent:this._volatile;this._set(r,t,e)}remember(t,e){this._set(this._volatile,t,e)}write(t,e){this._set(this._persistent,t,e)}forget(t){this._volatile.removeItem(t)}erase(t){this._persistent.removeItem(t)}clear(t){this._volatile.removeItem(t),this._persistent.removeItem(t)}}Te=Symbol.toStringTag;const j=class j{constructor(t){u(this,"_isPending");u(this,"_isFulfilled");u(this,"_isRejected");u(this,"_promise");u(this,Te,"SmartPromise");this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const e=r=>(this._isPending=!1,this._isFulfilled=!0,r),n=r=>{throw this._isPending=!1,this._isRejected=!0,r};this._promise=new Promise(t).then(e,n)}static FromPromise(t){return new j((e,n)=>t.then(e,n))}get isPending(){return this._isPending}get isFulfilled(){return this._isFulfilled}get isRejected(){return this._isRejected}then(t,e){return this._promise.then(t,e)}catch(t){return this._promise.catch(t)}finally(t){return this._promise.finally(t)}};let S=j;class O extends(Re=S,Me=Symbol.toStringTag,Re){constructor(e,n){let r,i;super((o,c)=>{r=o,i=c});u(this,"_resolve");u(this,"_reject");u(this,Me,"DeferredPromise");this._promise.then(e,n),this._resolve=r,this._reject=i}get resolve(){return this._resolve}get reject(){return this._reject}watch(e){return e.then(this.resolve,this.reject),this}}class Xe extends(Pe=S,Fe=Symbol.toStringTag,Pe){constructor(e,n){super((r,i)=>{const o=C=>{clearTimeout(Oe),r(C)},c=C=>{clearTimeout(Oe),i(C)},Oe=setTimeout(()=>c(new N("The operation has timed out.")),n);e(o,c)});u(this,Fe,"TimedPromise")}}Ie=Symbol.toStringTag;class P{constructor(){u(this,"_subscribers");u(this,Ie,"Publisher");this._subscribers=[]}subscribe(t){return this._subscribers.push(t),()=>{const e=this._subscribers.indexOf(t);if(e<0)throw new D("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");this._subscribers.splice(e,1)}}publish(...t){return this._subscribers.slice().map(e=>e(...t))}}class Ze extends(Ae=F,je=Symbol.toStringTag,Ae){constructor(e=k.Second){super(n=>this._publisher.publish(n),e);u(this,"_publisher");u(this,je,"Clock");this._publisher=new P}start(e=0){if(this._isRunning)throw new y("The clock has already been started.");super.start(e)}stop(){if(!this._isRunning)throw new y("The clock hadn't yet started.");super.stop()}onTick(e,n=0){if(n<0)throw new R("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(e);let r=0;return this._publisher.subscribe(i=>{i-r<n||(e(i),r=i)})}}class Ue extends(De=F,Ce=Symbol.toStringTag,De){constructor(e,n=k.Second){super(()=>{const i=this.remainingTime;this._publisher.publish(i),i<=0&&this.stop()},n);u(this,"_deferrer");u(this,"_publisher");u(this,"_duration");u(this,Ce,"Countdown");this._publisher=new P,this._duration=e}get duration(){return this._duration}get remainingTime(){return this._duration-this.elapsedTime}start(e=this.duration){if(this._isRunning)throw new y("The countdown has already been started.");if(this._deferrer)throw new x;return this._deferrer=new O,super.start(this.duration-e),this._deferrer}stop(e){if(!this._isRunning)throw new y("The countdown hadn't yet started.");if(!this._deferrer)throw new x;super.stop(),e!==void 0?this._deferrer.reject(e):this._deferrer.resolve(),this._deferrer=void 0}onTick(e,n=0){if(n<0)throw new R("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(e);let r=0;return this._publisher.subscribe(i=>{r-i<n||(e(i),r=i)})}}Ne=Symbol.toStringTag;const A=class A{constructor(){u(this,Ne,"Random")}static Boolean(t=.5){return Math.random()<t}static Integer(t,e){return Math.floor(e===void 0?Math.random()*t:Math.random()*(e-t)+t)}static Decimal(t,e){return t===void 0?Math.random():e===void 0?Math.random()*t:Math.random()*(e-t)+t}static Index(t){if(t.length===0)throw new w("You must provide at least one element.");return this.Integer(t.length)}static Choice(t){return t[A.Index(t)]}};let I=A;function et(s){return new Promise(t=>setTimeout(t,s))}function tt(){return new Promise(s=>requestAnimationFrame(()=>s()))}function nt(s,t="text/javascript"){return new Promise((e,n)=>{const r=document.createElement("script");r.async=!0,r.defer=!0,r.src=s,r.type=t,r.onload=()=>e(),r.onerror=()=>n(),document.body.appendChild(r)})}function rt(...s){return new l(function*(){for(const t of s)for(const e of t)yield e})}function it(s){if(Array.isArray(s))return s.length;let t=0;for(const e of s)t+=1;return t}function st(s){return new l(function*(){let t=0;for(const e of s)yield[t,e],t+=1})}function ot(s,t,e=1){return new l(function*(){t===void 0&&(t=s,s=0),s>t&&(e=e??-1);for(let n=s;n<t;n+=e)yield n})}function at(s){const t=Array.from(s);for(let e=t.length-1;e>0;e-=1){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function ut(s){return new l(function*(){const t=new Set;for(const e of s)t.has(e)||(t.add(e),yield e)})}function q(s,t){return new l(function*(){const e=s[Symbol.iterator](),n=t[Symbol.iterator]();for(;;){const r=e.next(),i=n.next();if(r.done||i.done)break;yield[r.value,i.value]}})}function ct(s,t){if(t===void 0){let i=0,o=0;for(const c of s)i+=c,o+=1;if(o===0)throw new w("You must provide at least one value.");return i/o}let e=0,n=0,r=0;for(const[i,o]of q(s,t)){if(o<=0)throw new w(`The weight for the value #${r} must be greater than zero.`);e+=i*o,n+=o,r+=1}if(r===0)throw new w("You must provide at least one value and weight.");if(n>0)throw new w("The sum of weights must be greater than zero.");return e/n}function lt(s){let t=0;for(let e=0;e<s.length;e+=1){const n=s.charCodeAt(e);t=(t<<5)-t+n,t|=0}return t}function ft(s){let t=0;for(const e of s)t+=e;return t}function ht(s){return`${s.charAt(0).toUpperCase()}${s.slice(1)}`}const dt="2.0.0-rc.4";a.AggregatedAsyncIterator=E,a.AggregatedIterator=b,a.Clock=Ze,a.Countdown=Ue,a.DeferredPromise=O,a.Exception=h,a.FatalErrorException=x,a.FileException=M,a.FileExistsException=Ve,a.FileNotFoundException=We,a.GameLoop=F,a.JSONStorage=Qe,a.KeyException=ze,a.NetworkException=Je,a.NotImplementedException=$e,a.PermissionException=Ye,a.Publisher=P,a.Random=I,a.RangeException=R,a.ReducedIterator=d,a.ReferenceException=D,a.RuntimeException=y,a.SmartAsyncIterator=m,a.SmartIterator=l,a.SmartPromise=S,a.TimeUnit=k,a.TimedPromise=Xe,a.TimeoutException=N,a.TypeException=Ge,a.VERSION=dt,a.ValueException=w,a.average=ct,a.capitalize=ht,a.chain=rt,a.count=it,a.dateDifference=Ke,a.dateRange=Le,a.dateRound=He,a.delay=et,a.enumerate=st,a.hash=lt,a.isBrowser=f,a.isNode=v,a.isWebWorker=qe,a.loadScript=nt,a.nextAnimationFrame=tt,a.range=ot,a.shuffle=at,a.sum=ft,a.unique=ut,a.zip=q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
6
6
|
//# sourceMappingURL=core.umd.cjs.map
|