@byloth/core 1.5.3 → 2.0.0-rc.10

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.
Files changed (45) hide show
  1. package/dist/core.js +1468 -826
  2. package/dist/core.js.map +1 -1
  3. package/dist/core.umd.cjs +3 -3
  4. package/dist/core.umd.cjs.map +1 -1
  5. package/package.json +8 -10
  6. package/src/helpers.ts +10 -0
  7. package/src/index.ts +33 -16
  8. package/src/models/aggregators/aggregated-async-iterator.ts +129 -81
  9. package/src/models/aggregators/aggregated-iterator.ts +128 -82
  10. package/src/models/aggregators/index.ts +1 -3
  11. package/src/models/aggregators/reduced-iterator.ts +119 -31
  12. package/src/models/aggregators/types.ts +15 -10
  13. package/src/models/callbacks/callable-object.ts +23 -0
  14. package/src/models/callbacks/index.ts +5 -0
  15. package/src/models/callbacks/publisher.ts +45 -0
  16. package/src/models/callbacks/switchable-callback.ts +108 -0
  17. package/src/models/callbacks/types.ts +1 -0
  18. package/src/models/exceptions/core.ts +6 -7
  19. package/src/models/exceptions/index.ts +50 -10
  20. package/src/models/game-loop.ts +83 -0
  21. package/src/models/index.ts +10 -7
  22. package/src/models/iterators/smart-async-iterator.ts +112 -24
  23. package/src/models/iterators/smart-iterator.ts +108 -13
  24. package/src/models/iterators/types.ts +17 -7
  25. package/src/models/json/index.ts +3 -0
  26. package/src/models/{json-storage.ts → json/json-storage.ts} +40 -28
  27. package/src/models/json/types.ts +5 -0
  28. package/src/models/promises/deferred-promise.ts +1 -1
  29. package/src/models/promises/index.ts +3 -1
  30. package/src/models/promises/long-running-task.ts +294 -0
  31. package/src/models/promises/smart-promise.ts +6 -1
  32. package/src/models/promises/thenable.ts +97 -0
  33. package/src/models/promises/timed-promise.ts +1 -1
  34. package/src/models/promises/types.ts +2 -0
  35. package/src/models/timers/clock.ts +69 -0
  36. package/src/models/timers/countdown.ts +117 -0
  37. package/src/models/timers/index.ts +4 -0
  38. package/src/models/types.ts +20 -9
  39. package/src/utils/async.ts +9 -4
  40. package/src/utils/date.ts +7 -4
  41. package/src/utils/index.ts +2 -2
  42. package/src/utils/random.ts +4 -3
  43. package/src/models/aggregators/aggregator.ts +0 -46
  44. package/src/models/aggregators/async-aggregator.ts +0 -56
  45. package/src/models/subscribers.ts +0 -35
package/dist/core.js CHANGED
@@ -1,813 +1,1170 @@
1
- var S = Object.defineProperty;
2
- var b = (s, e, t) => e in s ? S(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var u = (s, e, t) => b(s, typeof e != "symbol" ? e + "" : e, t);
4
- class c {
5
- constructor(e) {
6
- u(this, "_iterator");
7
- u(this, "return");
8
- u(this, "throw");
9
- 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));
1
+ var Ne = Object.defineProperty;
2
+ var Ye = (i, t, e) => t in i ? Ne(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var a = (i, t, e) => Ye(i, typeof t != "symbol" ? t + "" : t, e);
4
+ const Oe = typeof window < "u" && typeof window.document < "u";
5
+ var O;
6
+ const Qe = typeof process < "u" && ((O = process.versions) == null ? void 0 : O.node);
7
+ var A;
8
+ const Xe = typeof self == "object" && ((A = self.constructor) == null ? void 0 : A.name) === "DedicatedWorkerGlobalScope";
9
+ var $, q;
10
+ class f extends (q = Error, $ = Symbol.toStringTag, q) {
11
+ constructor(e, n, s = "Exception") {
12
+ super(e);
13
+ a(this, $, "Exception");
14
+ this.cause = n, this.name = s, n && (n instanceof Error ? this.stack += `
15
+
16
+ Caused by ${n.stack}` : this.stack += `
17
+
18
+ Caused by ${n}`);
10
19
  }
11
- every(e) {
12
- let t = 0;
20
+ static FromUnknown(e) {
21
+ if (e instanceof f)
22
+ return e;
23
+ if (e instanceof Error) {
24
+ const n = new f(e.message);
25
+ return n.stack = e.stack, n.name = e.name, n;
26
+ }
27
+ return new f(`${e}`);
28
+ }
29
+ }
30
+ var N, Y;
31
+ class k extends (Y = f, N = Symbol.toStringTag, Y) {
32
+ constructor(e, n, s = "FatalErrorException") {
33
+ 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.");
34
+ super(e, n, s);
35
+ a(this, N, "FatalErrorException");
36
+ }
37
+ }
38
+ var z, J;
39
+ class ze extends (J = k, z = Symbol.toStringTag, J) {
40
+ constructor(e, n, s = "NotImplementedException") {
41
+ e === void 0 && (e = "This feature is not implemented yet. Please, try again later.");
42
+ super(e, n, s);
43
+ a(this, z, "NotImplementedException");
44
+ }
45
+ }
46
+ var V, W;
47
+ class Ae extends (W = f, V = Symbol.toStringTag, W) {
48
+ constructor(e, n, s = "FileException") {
49
+ super(e, n, s);
50
+ a(this, V, "FileException");
51
+ }
52
+ }
53
+ var B, G;
54
+ class Ze extends (G = Ae, B = Symbol.toStringTag, G) {
55
+ constructor(e, n, s = "FileExistsException") {
56
+ super(e, n, s);
57
+ a(this, B, "FileExistsException");
58
+ }
59
+ }
60
+ var K, L;
61
+ class Ue extends (L = Ae, K = Symbol.toStringTag, L) {
62
+ constructor(e, n, s = "FileNotFoundException") {
63
+ super(e, n, s);
64
+ a(this, K, "FileNotFoundException");
65
+ }
66
+ }
67
+ var H, Q;
68
+ class x extends (Q = f, H = Symbol.toStringTag, Q) {
69
+ constructor(e, n, s = "KeyException") {
70
+ super(e, n, s);
71
+ a(this, H, "KeyException");
72
+ }
73
+ }
74
+ var X, Z;
75
+ class et extends (Z = f, X = Symbol.toStringTag, Z) {
76
+ constructor(e, n, s = "NetworkException") {
77
+ super(e, n, s);
78
+ a(this, X, "NetworkException");
79
+ }
80
+ }
81
+ var U, ee;
82
+ class tt extends (ee = f, U = Symbol.toStringTag, ee) {
83
+ constructor(e, n, s = "PermissionException") {
84
+ super(e, n, s);
85
+ a(this, U, "PermissionException");
86
+ }
87
+ }
88
+ var te, ne;
89
+ class Je extends (ne = f, te = Symbol.toStringTag, ne) {
90
+ constructor(e, n, s = "ReferenceException") {
91
+ super(e, n, s);
92
+ a(this, te, "ReferenceException");
93
+ }
94
+ }
95
+ var se, re;
96
+ class m extends (re = f, se = Symbol.toStringTag, re) {
97
+ constructor(e, n, s = "RuntimeException") {
98
+ super(e, n, s);
99
+ a(this, se, "RuntimeException");
100
+ }
101
+ }
102
+ var ie, oe;
103
+ class Ve extends (oe = m, ie = Symbol.toStringTag, oe) {
104
+ constructor(e, n, s = "EnvironmentException") {
105
+ super(e, n, s);
106
+ a(this, ie, "EnvironmentException");
107
+ }
108
+ }
109
+ var ae, le;
110
+ class We extends (le = f, ae = Symbol.toStringTag, le) {
111
+ constructor(e, n, s = "TimeoutException") {
112
+ super(e, n, s);
113
+ a(this, ae, "TimeoutException");
114
+ }
115
+ }
116
+ var ue, ce;
117
+ class nt extends (ce = f, ue = Symbol.toStringTag, ce) {
118
+ constructor(e, n, s = "TypeException") {
119
+ super(e, n, s);
120
+ a(this, ue, "TypeException");
121
+ }
122
+ }
123
+ var he, fe;
124
+ class p extends (fe = f, he = Symbol.toStringTag, fe) {
125
+ constructor(e, n, s = "ValueException") {
126
+ super(e, n, s);
127
+ a(this, he, "ValueException");
128
+ }
129
+ }
130
+ var de, me;
131
+ class $e extends (me = p, de = Symbol.toStringTag, me) {
132
+ constructor(e, n, s = "RangeException") {
133
+ super(e, n, s);
134
+ a(this, de, "RangeException");
135
+ }
136
+ }
137
+ var _e;
138
+ class c {
139
+ constructor(t) {
140
+ a(this, "_iterator");
141
+ a(this, "return");
142
+ a(this, "throw");
143
+ a(this, _e, "SmartIterator");
144
+ 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));
145
+ }
146
+ every(t) {
147
+ let e = 0;
13
148
  for (; ; ) {
14
149
  const n = this._iterator.next();
15
150
  if (n.done)
16
151
  return !0;
17
- if (!e(n.value, t))
152
+ if (!t(n.value, e))
18
153
  return !1;
19
- t += 1;
154
+ e += 1;
20
155
  }
21
156
  }
22
- some(e) {
23
- let t = 0;
157
+ some(t) {
158
+ let e = 0;
24
159
  for (; ; ) {
25
160
  const n = this._iterator.next();
26
161
  if (n.done)
27
162
  return !1;
28
- if (e(n.value, t))
163
+ if (t(n.value, e))
29
164
  return !0;
30
- t += 1;
165
+ e += 1;
31
166
  }
32
167
  }
33
- filter(e) {
34
- const t = this._iterator;
168
+ filter(t) {
169
+ const e = this._iterator;
35
170
  return new c(function* () {
36
171
  let n = 0;
37
172
  for (; ; ) {
38
- const r = t.next();
39
- if (r.done)
40
- return r.value;
41
- e(r.value, n) && (yield r.value), n += 1;
173
+ const s = e.next();
174
+ if (s.done)
175
+ return s.value;
176
+ t(s.value, n) && (yield s.value), n += 1;
42
177
  }
43
178
  });
44
179
  }
45
- map(e) {
46
- const t = this._iterator;
180
+ map(t) {
181
+ const e = this._iterator;
47
182
  return new c(function* () {
48
183
  let n = 0;
49
184
  for (; ; ) {
50
- const r = t.next();
51
- if (r.done)
52
- return r.value;
53
- yield e(r.value, n), n += 1;
185
+ const s = e.next();
186
+ if (s.done)
187
+ return s.value;
188
+ yield t(s.value, n), n += 1;
54
189
  }
55
190
  });
56
191
  }
57
- reduce(e, t) {
58
- let n = 0, r = t;
59
- if (r === void 0) {
60
- const o = this._iterator.next();
61
- if (o.done)
62
- throw new TypeError("Reduce of empty iterator with no initial value");
63
- r = o.value, n += 1;
192
+ reduce(t, e) {
193
+ let n = 0, s = e;
194
+ if (s === void 0) {
195
+ const r = this._iterator.next();
196
+ if (r.done)
197
+ throw new p("Cannot reduce an empty iterator without an initial value.");
198
+ s = r.value, n += 1;
64
199
  }
65
200
  for (; ; ) {
66
- const o = this._iterator.next();
67
- if (o.done)
68
- return r;
69
- r = e(r, o.value, n), n += 1;
201
+ const r = this._iterator.next();
202
+ if (r.done)
203
+ return s;
204
+ s = t(s, r.value, n), n += 1;
70
205
  }
71
206
  }
72
- enumerate() {
73
- return this.map((e, t) => [t, e]);
74
- }
75
- unique() {
207
+ flatMap(t) {
76
208
  const e = this._iterator;
77
209
  return new c(function* () {
78
- const t = /* @__PURE__ */ new Set();
210
+ let n = 0;
79
211
  for (; ; ) {
80
- const n = e.next();
81
- if (n.done)
82
- return n.value;
83
- t.has(n.value) || (t.add(n.value), yield n.value);
212
+ const s = e.next();
213
+ if (s.done)
214
+ return s.value;
215
+ const r = t(s.value, n);
216
+ for (const o of r)
217
+ yield o;
218
+ n += 1;
84
219
  }
85
220
  });
86
221
  }
87
- count() {
88
- let e = 0;
89
- for (; ; ) {
90
- if (this._iterator.next().done)
91
- return e;
92
- e += 1;
93
- }
94
- }
95
- forEach(e) {
96
- let t = 0;
97
- for (; ; ) {
98
- const n = this._iterator.next();
99
- if (n.done)
100
- return;
101
- e(n.value, t), t += 1;
102
- }
103
- }
104
- next(...e) {
105
- return this._iterator.next(...e);
106
- }
107
- toArray() {
108
- return Array.from(this);
109
- }
110
- get [Symbol.toStringTag]() {
111
- return "SmartIterator";
112
- }
113
- [Symbol.iterator]() {
114
- return this;
115
- }
116
- }
117
- class h {
118
- constructor(e) {
119
- u(this, "_iterator");
120
- u(this, "return");
121
- u(this, "throw");
122
- if (e instanceof Function) {
123
- const t = e();
124
- Symbol.asyncIterator in t ? this._iterator = t : this._iterator = async function* () {
125
- let n = [];
126
- for (; ; ) {
127
- const r = t.next(...n);
128
- if (r.done)
129
- return r.value;
130
- n = [yield r.value];
131
- }
132
- }();
133
- } else if (Symbol.asyncIterator in e)
134
- this._iterator = e[Symbol.asyncIterator]();
135
- else if (Symbol.iterator in e) {
136
- const t = e[Symbol.iterator]();
137
- this._iterator = async function* () {
138
- for (; ; ) {
139
- const n = t.next();
140
- if (n.done)
141
- return n.value;
142
- yield n.value;
143
- }
144
- }();
145
- } else
146
- this._iterator = async function* () {
147
- let t = [];
148
- for (; ; ) {
149
- const n = await e.next(...t);
150
- if (n.done)
151
- return n.value;
152
- t = [yield n.value];
153
- }
154
- }();
155
- this._iterator.return && (this.return = (t) => this._iterator.return(t)), this._iterator.throw && (this.throw = (t) => this._iterator.throw(t));
156
- }
157
- async every(e) {
158
- let t = 0;
159
- for (; ; ) {
160
- const n = await this._iterator.next();
161
- if (n.done)
162
- return !0;
163
- if (!e(n.value, t))
164
- return !1;
165
- t += 1;
166
- }
167
- }
168
- async some(e) {
169
- let t = 0;
170
- for (; ; ) {
171
- const n = await this._iterator.next();
172
- if (n.done)
173
- return !1;
174
- if (e(n.value, t))
175
- return !0;
176
- t += 1;
177
- }
178
- }
179
- filter(e) {
180
- const t = this._iterator;
181
- return new h(async function* () {
222
+ drop(t) {
223
+ const e = this._iterator;
224
+ return new c(function* () {
182
225
  let n = 0;
226
+ for (; n < t; ) {
227
+ if (e.next().done)
228
+ return;
229
+ n += 1;
230
+ }
183
231
  for (; ; ) {
184
- const r = await t.next();
185
- if (r.done)
186
- return r.value;
187
- e(r.value, n) && (yield r.value), n += 1;
232
+ const s = e.next();
233
+ if (s.done)
234
+ return s.value;
235
+ yield s.value;
188
236
  }
189
237
  });
190
238
  }
191
- map(e) {
192
- const t = this._iterator;
193
- return new h(async function* () {
239
+ take(t) {
240
+ const e = this._iterator;
241
+ return new c(function* () {
194
242
  let n = 0;
195
- for (; ; ) {
196
- const r = await t.next();
197
- if (r.done)
198
- return r.value;
199
- yield e(r.value, n), n += 1;
243
+ for (; n < t; ) {
244
+ const s = e.next();
245
+ if (s.done)
246
+ return s.value;
247
+ yield s.value, n += 1;
200
248
  }
201
249
  });
202
250
  }
203
- async reduce(e, t) {
204
- let n = 0, r = t;
205
- if (r === void 0) {
206
- const o = await this._iterator.next();
207
- if (o.done)
208
- throw new TypeError("Reduce of empty iterator with no initial value");
209
- r = o.value, n += 1;
210
- }
251
+ find(t) {
252
+ let e = 0;
211
253
  for (; ; ) {
212
- const o = await this._iterator.next();
213
- if (o.done)
214
- return r;
215
- r = await e(r, o.value, n), n += 1;
254
+ const n = this._iterator.next();
255
+ if (n.done)
256
+ return;
257
+ if (t(n.value, e))
258
+ return n.value;
259
+ e += 1;
216
260
  }
217
261
  }
218
262
  enumerate() {
219
- return this.map((e, t) => [t, e]);
263
+ return this.map((t, e) => [e, t]);
220
264
  }
221
265
  unique() {
222
- const e = this._iterator;
223
- return new h(async function* () {
224
- const t = /* @__PURE__ */ new Set();
266
+ const t = this._iterator;
267
+ return new c(function* () {
268
+ const e = /* @__PURE__ */ new Set();
225
269
  for (; ; ) {
226
- const n = await e.next();
270
+ const n = t.next();
227
271
  if (n.done)
228
272
  return n.value;
229
- t.has(n.value) || (t.add(n.value), yield n.value);
273
+ e.has(n.value) || (e.add(n.value), yield n.value);
230
274
  }
231
275
  });
232
276
  }
233
- async count() {
234
- let e = 0;
277
+ count() {
278
+ let t = 0;
235
279
  for (; ; ) {
236
- if ((await this._iterator.next()).done)
237
- return e;
238
- e += 1;
280
+ if (this._iterator.next().done)
281
+ return t;
282
+ t += 1;
239
283
  }
240
284
  }
241
- async forEach(e) {
242
- let t = 0;
285
+ forEach(t) {
286
+ let e = 0;
243
287
  for (; ; ) {
244
- const n = await this._iterator.next();
288
+ const n = this._iterator.next();
245
289
  if (n.done)
246
290
  return;
247
- await e(n.value, t), t += 1;
291
+ t(n.value, e), e += 1;
248
292
  }
249
293
  }
250
- next(...e) {
251
- return this._iterator.next(...e);
294
+ next(...t) {
295
+ return this._iterator.next(...t);
252
296
  }
253
- async toArray() {
254
- const e = [];
255
- for (; ; ) {
256
- const t = await this._iterator.next();
257
- if (t.done)
258
- return e;
259
- e.push(t.value);
260
- }
297
+ groupBy(t) {
298
+ return new S(this.map((e, n) => [t(e, n), e]));
261
299
  }
262
- get [Symbol.toStringTag]() {
263
- return "SmartAsyncIterator";
300
+ toArray() {
301
+ return Array.from(this);
264
302
  }
265
- [Symbol.asyncIterator]() {
303
+ [(_e = Symbol.toStringTag, Symbol.iterator)]() {
266
304
  return this;
267
305
  }
268
306
  }
269
- class f extends Error {
270
- static FromUnknown(e) {
271
- if (e instanceof f)
272
- return e;
273
- if (e instanceof Error) {
274
- const t = new f(e.message);
275
- return t.stack = e.stack, t.name = e.name, t;
276
- }
277
- return new f(`${e}`);
307
+ var we;
308
+ we = Symbol.toStringTag;
309
+ const b = class b {
310
+ constructor(t) {
311
+ a(this, "_elements");
312
+ a(this, we, "ReducedIterator");
313
+ this._elements = new c(t);
314
+ }
315
+ every(t) {
316
+ for (const [e, [n, s]] of this._elements.enumerate())
317
+ if (!t(n, s, e))
318
+ return !1;
319
+ return !0;
278
320
  }
279
- constructor(e, t, n = "Exception") {
280
- super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
281
-
282
- Caused by ${t.stack}` : this.stack += `
283
-
284
- Caused by ${t}`);
321
+ some(t) {
322
+ for (const [e, [n, s]] of this._elements.enumerate())
323
+ if (t(n, s, e))
324
+ return !0;
325
+ return !1;
285
326
  }
286
- get [Symbol.toStringTag]() {
287
- return "Exception";
327
+ filter(t) {
328
+ const e = this._elements.enumerate();
329
+ return new b(function* () {
330
+ for (const [n, [s, r]] of e)
331
+ t(s, r, n) && (yield [s, r]);
332
+ });
288
333
  }
289
- }
290
- class j extends f {
291
- constructor(e, t, n = "FatalErrorException") {
292
- e === void 0 && (e = "The routine has encountered an unrecoverable error and cannot continue as expected. Please, refresh the page and try again. If the problem persists, contact the support team."), super(e, t, n);
334
+ map(t) {
335
+ const e = this._elements.enumerate();
336
+ return new b(function* () {
337
+ for (const [n, [s, r]] of e)
338
+ yield [s, t(s, r, n)];
339
+ });
293
340
  }
294
- get [Symbol.toStringTag]() {
295
- return "FatalErrorException";
341
+ reduce(t, e) {
342
+ let n = 0, s = e;
343
+ if (s === void 0) {
344
+ const r = this._elements.next();
345
+ if (r.done)
346
+ throw new p("Cannot reduce an empty iterator without an initial value.");
347
+ s = r.value[1], n += 1;
348
+ }
349
+ for (const [r, o] of this._elements)
350
+ s = t(r, s, o, n), n += 1;
351
+ return s;
352
+ }
353
+ flatMap(t) {
354
+ const e = this._elements.enumerate();
355
+ return new S(function* () {
356
+ for (const [n, [s, r]] of e)
357
+ for (const o of t(s, r, n))
358
+ yield [s, o];
359
+ });
296
360
  }
297
- }
298
- class F extends f {
299
- constructor(e, t, n = "NotImplementedException") {
300
- e === void 0 && (e = "This feature is not implemented yet. Please, try again later."), super(e, t, n);
361
+ drop(t) {
362
+ const e = this._elements.enumerate();
363
+ return new b(function* () {
364
+ for (const [n, [s, r]] of e)
365
+ n >= t && (yield [s, r]);
366
+ });
301
367
  }
302
- get [Symbol.toStringTag]() {
303
- return "NotImplementedException";
368
+ take(t) {
369
+ const e = this._elements.enumerate();
370
+ return new b(function* () {
371
+ for (const [n, [s, r]] of e) {
372
+ if (n >= t)
373
+ break;
374
+ yield [s, r];
375
+ }
376
+ });
304
377
  }
305
- }
306
- class R extends f {
307
- constructor(e, t, n = "FileNotFoundException") {
308
- super(e, t, n);
378
+ enumerate() {
379
+ return this.map((t, e, n) => [n, e]);
309
380
  }
310
- get [Symbol.toStringTag]() {
311
- return "FileNotFoundException";
381
+ unique() {
382
+ const t = this._elements;
383
+ return new b(function* () {
384
+ const e = /* @__PURE__ */ new Set();
385
+ for (const [n, s] of t)
386
+ e.has(s) || (e.add(s), yield [n, s]);
387
+ });
312
388
  }
313
- }
314
- class q extends f {
315
- constructor(e, t, n = "KeyException") {
316
- super(e, t, n);
389
+ count() {
390
+ let t = 0;
391
+ for (const e of this._elements)
392
+ t += 1;
393
+ return t;
317
394
  }
318
- get [Symbol.toStringTag]() {
319
- return "KeyException";
395
+ forEach(t) {
396
+ for (const [e, [n, s]] of this._elements.enumerate())
397
+ t(n, s, e);
320
398
  }
321
- }
322
- class A extends f {
323
- constructor(e, t, n = "NetworkException") {
324
- super(e, t, n);
399
+ keys() {
400
+ const t = this._elements;
401
+ return new c(function* () {
402
+ for (const [e] of t)
403
+ yield e;
404
+ });
325
405
  }
326
- get [Symbol.toStringTag]() {
327
- return "NetworkException";
406
+ items() {
407
+ return this._elements;
328
408
  }
329
- }
330
- class O extends f {
331
- constructor(e, t, n = "PermissionException") {
332
- super(e, t, n);
409
+ values() {
410
+ const t = this._elements;
411
+ return new c(function* () {
412
+ for (const [e, n] of t)
413
+ yield n;
414
+ });
333
415
  }
334
- get [Symbol.toStringTag]() {
335
- return "PermissionException";
416
+ toArray() {
417
+ return Array.from(this.values());
336
418
  }
337
- }
338
- class k extends f {
339
- constructor(e, t, n = "ReferenceException") {
340
- super(e, t, n);
419
+ toMap() {
420
+ return new Map(this.items());
341
421
  }
342
- get [Symbol.toStringTag]() {
343
- return "ReferenceException";
422
+ toObject() {
423
+ return Object.fromEntries(this.items());
344
424
  }
345
- }
346
- class $ extends f {
347
- constructor(e, t, n = "RuntimeException") {
348
- super(e, t, n);
425
+ };
426
+ let d = b;
427
+ var pe;
428
+ pe = Symbol.toStringTag;
429
+ const y = class y {
430
+ constructor(t) {
431
+ a(this, "_elements");
432
+ a(this, pe, "AggregatedAsyncIterator");
433
+ this._elements = new w(t);
434
+ }
435
+ async every(t) {
436
+ const e = /* @__PURE__ */ new Map();
437
+ for await (const [n, s] of this._elements) {
438
+ const [r, o] = e.get(n) ?? [0, !0];
439
+ o && e.set(n, [r + 1, await t(n, s, r)]);
440
+ }
441
+ return new d(function* () {
442
+ for (const [n, [s, r]] of e)
443
+ yield [n, r];
444
+ });
349
445
  }
350
- get [Symbol.toStringTag]() {
351
- return "RuntimeException";
446
+ async some(t) {
447
+ const e = /* @__PURE__ */ new Map();
448
+ for await (const [n, s] of this._elements) {
449
+ const [r, o] = e.get(n) ?? [0, !1];
450
+ o || e.set(n, [r + 1, await t(n, s, r)]);
451
+ }
452
+ return new d(function* () {
453
+ for (const [n, [s, r]] of e)
454
+ yield [n, r];
455
+ });
352
456
  }
353
- }
354
- class T extends f {
355
- constructor(e, t, n = "TimeoutException") {
356
- super(e, t, n);
457
+ filter(t) {
458
+ const e = this._elements;
459
+ return new y(async function* () {
460
+ const n = /* @__PURE__ */ new Map();
461
+ for await (const [s, r] of e) {
462
+ const o = n.get(s) ?? 0;
463
+ await t(s, r, o) && (yield [s, r]), n.set(s, o + 1);
464
+ }
465
+ });
357
466
  }
358
- get [Symbol.toStringTag]() {
359
- return "TimeoutException";
467
+ map(t) {
468
+ const e = this._elements;
469
+ return new y(async function* () {
470
+ const n = /* @__PURE__ */ new Map();
471
+ for await (const [s, r] of e) {
472
+ const o = n.get(s) ?? 0;
473
+ yield [s, await t(s, r, o)], n.set(s, o + 1);
474
+ }
475
+ });
360
476
  }
361
- }
362
- class E extends f {
363
- constructor(e, t, n = "TypeException") {
364
- super(e, t, n);
477
+ async reduce(t, e) {
478
+ const n = /* @__PURE__ */ new Map();
479
+ for await (const [s, r] of this._elements) {
480
+ let o, l;
481
+ if (n.has(s))
482
+ [o, l] = n.get(s);
483
+ else if (e !== void 0)
484
+ o = 0, l = await e(s);
485
+ else {
486
+ n.set(s, [0, r]);
487
+ continue;
488
+ }
489
+ n.set(s, [o + 1, await t(s, l, r, o)]);
490
+ }
491
+ return new d(function* () {
492
+ for (const [s, [r, o]] of n)
493
+ yield [s, o];
494
+ });
365
495
  }
366
- get [Symbol.toStringTag]() {
367
- return "TypeException";
496
+ flatMap(t) {
497
+ const e = this._elements;
498
+ return new y(async function* () {
499
+ const n = /* @__PURE__ */ new Map();
500
+ for await (const [s, r] of e) {
501
+ const o = n.get(s) ?? 0, l = await t(s, r, o);
502
+ for await (const u of l)
503
+ yield [s, u];
504
+ n.set(s, o + 1);
505
+ }
506
+ });
368
507
  }
369
- }
370
- class m extends f {
371
- constructor(e, t, n = "ValueException") {
372
- super(e, t, n);
508
+ drop(t) {
509
+ const e = this._elements;
510
+ return new y(async function* () {
511
+ const n = /* @__PURE__ */ new Map();
512
+ for await (const [s, r] of e) {
513
+ const o = n.get(s) ?? 0;
514
+ if (o < t) {
515
+ n.set(s, o + 1);
516
+ continue;
517
+ }
518
+ yield [s, r];
519
+ }
520
+ });
373
521
  }
374
- get [Symbol.toStringTag]() {
375
- return "ValueException";
522
+ take(t) {
523
+ const e = this._elements;
524
+ return new y(async function* () {
525
+ const n = /* @__PURE__ */ new Map();
526
+ for await (const [s, r] of e) {
527
+ const o = n.get(s) ?? 0;
528
+ o >= t || (yield [s, r], n.set(s, o + 1));
529
+ }
530
+ });
376
531
  }
377
- }
378
- class a {
379
- constructor(e) {
380
- u(this, "_elements");
381
- this._elements = new c(e);
532
+ async find(t) {
533
+ const e = /* @__PURE__ */ new Map();
534
+ for await (const [n, s] of this._elements) {
535
+ let [r, o] = e.get(n) ?? [0, void 0];
536
+ o === void 0 && (await t(n, s, r) && (o = s), e.set(n, [r + 1, o]));
537
+ }
538
+ return new d(function* () {
539
+ for (const [n, [s, r]] of e)
540
+ yield [n, r];
541
+ });
382
542
  }
383
- filter(e) {
543
+ unique() {
384
544
  const t = this._elements;
385
- return new a(function* () {
386
- for (const [n, [r, o]] of t.enumerate())
387
- e(r, o, n) && (yield [r, o]);
545
+ return new y(async function* () {
546
+ const e = /* @__PURE__ */ new Map();
547
+ for await (const [n, s] of t) {
548
+ const r = e.get(n) ?? /* @__PURE__ */ new Set();
549
+ r.has(s) || (r.add(s), e.set(n, r), yield [n, s]);
550
+ }
388
551
  });
389
552
  }
390
- map(e) {
391
- const t = this._elements;
392
- return new a(function* () {
393
- for (const [n, [r, o]] of t.enumerate())
394
- yield [r, e(r, o, n)];
553
+ async count() {
554
+ const t = /* @__PURE__ */ new Map();
555
+ for await (const [e] of this._elements) {
556
+ const n = t.get(e) ?? 0;
557
+ t.set(e, n + 1);
558
+ }
559
+ return new d(function* () {
560
+ for (const [e, n] of t)
561
+ yield [e, n];
395
562
  });
396
563
  }
397
- reduce(e, t) {
398
- let n = 0, r;
399
- if (t !== void 0)
400
- r = t;
401
- else {
402
- const o = this._elements.next();
403
- if (o.done)
404
- throw new E("Reduce of empty iterator with no initial value");
405
- n += 1, r = o.value[1];
564
+ async forEach(t) {
565
+ const e = /* @__PURE__ */ new Map();
566
+ for await (const [n, s] of this._elements) {
567
+ const r = e.get(n) ?? 0;
568
+ t(n, s, r), e.set(n, r + 1);
406
569
  }
407
- for (const [o, i] of this._elements)
408
- r = e(o, r, i, n), n += 1;
409
- return r;
410
570
  }
411
571
  keys() {
412
- const e = this._elements;
413
- return new c(function* () {
414
- for (const [t] of e)
415
- yield t;
572
+ const t = this._elements;
573
+ return new w(async function* () {
574
+ const e = /* @__PURE__ */ new Set();
575
+ for await (const [n] of t)
576
+ e.has(n) || (e.add(n), yield n);
416
577
  });
417
578
  }
418
579
  items() {
419
580
  return this._elements;
420
581
  }
421
582
  values() {
422
- const e = this._elements;
423
- return new c(function* () {
424
- for (const [t, n] of e)
583
+ const t = this._elements;
584
+ return new w(async function* () {
585
+ for await (const [e, n] of t)
425
586
  yield n;
426
587
  });
427
588
  }
428
- toArray() {
429
- return Array.from(this.values());
430
- }
431
- toMap() {
432
- return new Map(this.items());
589
+ async toArray() {
590
+ const t = await this.toMap();
591
+ return Array.from(t.values());
433
592
  }
434
- toObject() {
435
- return Object.fromEntries(this.items());
593
+ async toMap() {
594
+ const t = /* @__PURE__ */ new Map();
595
+ for await (const [e, n] of this._elements) {
596
+ const s = t.get(e) ?? [];
597
+ s.push(n), t.set(e, s);
598
+ }
599
+ return t;
436
600
  }
437
- get [Symbol.toStringTag]() {
438
- return "ReducedIterator";
601
+ async toObject() {
602
+ const t = {};
603
+ for await (const [e, n] of this._elements) {
604
+ const s = t[e] ?? [];
605
+ s.push(n), t[e] = s;
606
+ }
607
+ return t;
439
608
  }
440
- }
441
- class d {
442
- constructor(e) {
443
- u(this, "_elements");
444
- this._elements = new c(e);
609
+ };
610
+ let E = y;
611
+ var ye;
612
+ class w {
613
+ constructor(t) {
614
+ a(this, "_iterator");
615
+ a(this, "return");
616
+ a(this, "throw");
617
+ a(this, ye, "SmartAsyncIterator");
618
+ if (t instanceof Function) {
619
+ const e = t();
620
+ Symbol.asyncIterator in e ? this._iterator = e : this._iterator = async function* () {
621
+ let n = [];
622
+ for (; ; ) {
623
+ const s = e.next(...n);
624
+ if (s.done)
625
+ return s.value;
626
+ n = [yield s.value];
627
+ }
628
+ }();
629
+ } else if (Symbol.asyncIterator in t)
630
+ this._iterator = t[Symbol.asyncIterator]();
631
+ else if (Symbol.iterator in t) {
632
+ const e = t[Symbol.iterator]();
633
+ this._iterator = async function* () {
634
+ for (; ; ) {
635
+ const n = e.next();
636
+ if (n.done)
637
+ return n.value;
638
+ yield n.value;
639
+ }
640
+ }();
641
+ } else
642
+ this._iterator = async function* () {
643
+ let e = [];
644
+ for (; ; ) {
645
+ const n = await t.next(...e);
646
+ if (n.done)
647
+ return n.value;
648
+ e = [yield n.value];
649
+ }
650
+ }();
651
+ this._iterator.return && (this.return = (e) => this._iterator.return(e)), this._iterator.throw && (this.throw = (e) => this._iterator.throw(e));
445
652
  }
446
- every(e) {
447
- const t = /* @__PURE__ */ new Map();
448
- for (const [n, r] of this._elements) {
449
- const [o, i] = t.get(n) ?? [0, !0];
450
- i && t.set(n, [o + 1, e(n, r, o)]);
653
+ async every(t) {
654
+ let e = 0;
655
+ for (; ; ) {
656
+ const n = await this._iterator.next();
657
+ if (n.done)
658
+ return !0;
659
+ if (!await t(n.value, e))
660
+ return !1;
661
+ e += 1;
451
662
  }
452
- return new a(function* () {
453
- for (const [n, [r, o]] of t)
454
- yield [n, o];
455
- });
456
663
  }
457
- some(e) {
458
- const t = /* @__PURE__ */ new Map();
459
- for (const [n, r] of this._elements) {
460
- const [o, i] = t.get(n) ?? [0, !1];
461
- i || t.set(n, [o + 1, e(n, r, o)]);
664
+ async some(t) {
665
+ let e = 0;
666
+ for (; ; ) {
667
+ const n = await this._iterator.next();
668
+ if (n.done)
669
+ return !1;
670
+ if (await t(n.value, e))
671
+ return !0;
672
+ e += 1;
462
673
  }
463
- return new a(function* () {
464
- for (const [n, [r, o]] of t)
465
- yield [n, o];
466
- });
467
674
  }
468
- filter(e) {
469
- const t = this._elements;
470
- return new d(function* () {
471
- const n = /* @__PURE__ */ new Map();
472
- for (const [r, o] of t) {
473
- const i = n.get(r) ?? 0;
474
- n.set(r, i + 1), e(r, o, i) && (yield [r, o]);
675
+ filter(t) {
676
+ const e = this._iterator;
677
+ return new w(async function* () {
678
+ let n = 0;
679
+ for (; ; ) {
680
+ const s = await e.next();
681
+ if (s.done)
682
+ return s.value;
683
+ await t(s.value, n) && (yield s.value), n += 1;
475
684
  }
476
685
  });
477
686
  }
478
- map(e) {
479
- const t = this._elements;
480
- return new d(function* () {
481
- const n = /* @__PURE__ */ new Map();
482
- for (const [r, o] of t) {
483
- const i = n.get(r) ?? 0;
484
- n.set(r, i + 1), yield [r, e(r, o, i)];
687
+ map(t) {
688
+ const e = this._iterator;
689
+ return new w(async function* () {
690
+ let n = 0;
691
+ for (; ; ) {
692
+ const s = await e.next();
693
+ if (s.done)
694
+ return s.value;
695
+ yield await t(s.value, n), n += 1;
485
696
  }
486
697
  });
487
698
  }
488
- reduce(e, t) {
489
- const n = /* @__PURE__ */ new Map();
490
- for (const [r, o] of this._elements) {
491
- let i, l;
492
- if (n.has(r))
493
- [i, l] = n.get(r), i += 1;
494
- else if (t !== void 0)
495
- i = 0, l = t(r);
496
- else {
497
- n.set(r, [0, o]);
498
- continue;
499
- }
500
- l = e(r, l, o, i), n.set(r, [i, l]);
699
+ async reduce(t, e) {
700
+ let n = 0, s = e;
701
+ if (s === void 0) {
702
+ const r = await this._iterator.next();
703
+ if (r.done)
704
+ throw new p("Cannot reduce an empty iterator without an initial value.");
705
+ s = r.value, n += 1;
706
+ }
707
+ for (; ; ) {
708
+ const r = await this._iterator.next();
709
+ if (r.done)
710
+ return s;
711
+ s = await t(s, r.value, n), n += 1;
501
712
  }
502
- return new a(function* () {
503
- for (const [r, [o, i]] of n)
504
- yield [r, i];
505
- });
506
713
  }
507
- unique() {
508
- const e = this._elements;
509
- return new d(function* () {
510
- const t = /* @__PURE__ */ new Map();
511
- for (const [n, r] of e) {
512
- const o = t.get(n) ?? /* @__PURE__ */ new Set();
513
- o.has(r) || (o.add(r), t.set(n, o), yield [n, r]);
714
+ flatMap(t) {
715
+ const e = this._iterator;
716
+ return new w(async function* () {
717
+ let n = 0;
718
+ for (; ; ) {
719
+ const s = await e.next();
720
+ if (s.done)
721
+ return s.value;
722
+ const r = await t(s.value, n);
723
+ for await (const o of r)
724
+ yield o;
725
+ n += 1;
514
726
  }
515
727
  });
516
728
  }
517
- count() {
518
- const e = /* @__PURE__ */ new Map();
519
- for (const [t] of this._elements) {
520
- const n = e.get(t) ?? 0;
521
- e.set(t, n + 1);
522
- }
523
- return new a(function* () {
524
- for (const [t, n] of e)
525
- yield [t, n];
526
- });
527
- }
528
- first() {
529
- const e = /* @__PURE__ */ new Map();
530
- for (const [t, n] of this._elements)
531
- e.has(t) || e.set(t, n);
532
- return new a(function* () {
533
- for (const [t, n] of e)
534
- yield [t, n];
729
+ drop(t) {
730
+ const e = this._iterator;
731
+ return new w(async function* () {
732
+ let n = 0;
733
+ for (; n < t; ) {
734
+ if ((await e.next()).done)
735
+ return;
736
+ n += 1;
737
+ }
738
+ for (; ; ) {
739
+ const s = await e.next();
740
+ if (s.done)
741
+ return s.value;
742
+ yield s.value;
743
+ }
535
744
  });
536
745
  }
537
- last() {
538
- const e = /* @__PURE__ */ new Map();
539
- for (const [t, n] of this._elements)
540
- e.set(t, n);
541
- return new a(function* () {
542
- for (const [t, n] of e)
543
- yield [t, n];
746
+ take(t) {
747
+ const e = this._iterator;
748
+ return new w(async function* () {
749
+ let n = 0;
750
+ for (; n < t; ) {
751
+ const s = await e.next();
752
+ if (s.done)
753
+ return s.value;
754
+ yield s.value, n += 1;
755
+ }
544
756
  });
545
757
  }
546
- keys() {
547
- const e = this._elements;
548
- return new c(function* () {
549
- const t = /* @__PURE__ */ new Set();
550
- for (const [n] of e)
551
- t.has(n) || (t.add(n), yield n);
552
- });
758
+ async find(t) {
759
+ let e = 0;
760
+ for (; ; ) {
761
+ const n = await this._iterator.next();
762
+ if (n.done)
763
+ return;
764
+ if (await t(n.value, e))
765
+ return n.value;
766
+ e += 1;
767
+ }
553
768
  }
554
- items() {
555
- return this._elements;
769
+ enumerate() {
770
+ return this.map((t, e) => [e, t]);
556
771
  }
557
- values() {
558
- const e = this._elements;
559
- return new c(function* () {
560
- for (const [t, n] of e)
561
- yield n;
772
+ unique() {
773
+ const t = this._iterator;
774
+ return new w(async function* () {
775
+ const e = /* @__PURE__ */ new Set();
776
+ for (; ; ) {
777
+ const n = await t.next();
778
+ if (n.done)
779
+ return n.value;
780
+ e.has(n.value) || (e.add(n.value), yield n.value);
781
+ }
562
782
  });
563
783
  }
564
- toArray() {
565
- return Array.from(this.toMap().values());
566
- }
567
- toMap() {
568
- const e = /* @__PURE__ */ new Map();
569
- for (const [t, n] of this._elements) {
570
- const r = e.get(t) ?? [];
571
- r.push(n), e.set(t, r);
784
+ async count() {
785
+ let t = 0;
786
+ for (; ; ) {
787
+ if ((await this._iterator.next()).done)
788
+ return t;
789
+ t += 1;
572
790
  }
573
- return e;
574
791
  }
575
- toObject() {
576
- const e = {};
577
- for (const [t, n] of this._elements) {
578
- const r = e[t] ?? [];
579
- r.push(n), e[t] = r;
792
+ async forEach(t) {
793
+ let e = 0;
794
+ for (; ; ) {
795
+ const n = await this._iterator.next();
796
+ if (n.done)
797
+ return;
798
+ await t(n.value, e), e += 1;
580
799
  }
581
- return e;
582
800
  }
583
- get [Symbol.toStringTag]() {
584
- return "AggregatedIterator";
801
+ next(...t) {
802
+ return this._iterator.next(...t);
585
803
  }
586
- }
587
- class w {
588
- constructor(e) {
589
- u(this, "_elements");
590
- this._elements = new c(e);
591
- }
592
- filter(e) {
593
- return new w(this._elements.filter(e));
594
- }
595
- map(e) {
596
- return new w(this._elements.map(e));
804
+ groupBy(t) {
805
+ return new E(this.map(async (e, n) => [await t(e, n), e]));
597
806
  }
598
- unique() {
599
- return new w(this._elements.unique());
600
- }
601
- groupBy(e) {
602
- return new d(this._elements.map((t, n) => [e(t, n), t]));
807
+ toArray() {
808
+ return Array.fromAsync(this);
603
809
  }
604
- get [Symbol.toStringTag]() {
605
- return "Aggregator";
810
+ [(ye = Symbol.toStringTag, Symbol.asyncIterator)]() {
811
+ return this;
606
812
  }
607
813
  }
608
- class y {
609
- constructor(e) {
610
- u(this, "_elements");
611
- this._elements = new h(e);
612
- }
613
- async every(e) {
614
- const t = /* @__PURE__ */ new Map();
615
- for await (const [n, r] of this._elements) {
616
- const [o, i] = t.get(n) ?? [0, !0];
617
- i && t.set(n, [o + 1, await e(n, r, o)]);
814
+ var ge;
815
+ ge = Symbol.toStringTag;
816
+ const g = class g {
817
+ constructor(t) {
818
+ a(this, "_elements");
819
+ a(this, ge, "AggregatedIterator");
820
+ this._elements = new c(t);
821
+ }
822
+ every(t) {
823
+ const e = /* @__PURE__ */ new Map();
824
+ for (const [n, s] of this._elements) {
825
+ const [r, o] = e.get(n) ?? [0, !0];
826
+ o && e.set(n, [r + 1, t(n, s, r)]);
618
827
  }
619
- return new a(function* () {
620
- for (const [n, [r, o]] of t)
621
- yield [n, o];
828
+ return new d(function* () {
829
+ for (const [n, [s, r]] of e)
830
+ yield [n, r];
622
831
  });
623
832
  }
624
- async some(e) {
625
- const t = /* @__PURE__ */ new Map();
626
- for await (const [n, r] of this._elements) {
627
- const [o, i] = t.get(n) ?? [0, !1];
628
- i || t.set(n, [o + 1, await e(n, r, o)]);
833
+ some(t) {
834
+ const e = /* @__PURE__ */ new Map();
835
+ for (const [n, s] of this._elements) {
836
+ const [r, o] = e.get(n) ?? [0, !1];
837
+ o || e.set(n, [r + 1, t(n, s, r)]);
629
838
  }
630
- return new a(function* () {
631
- for (const [n, [r, o]] of t)
632
- yield [n, o];
839
+ return new d(function* () {
840
+ for (const [n, [s, r]] of e)
841
+ yield [n, r];
633
842
  });
634
843
  }
635
- filter(e) {
636
- const t = this._elements;
637
- return new y(async function* () {
844
+ filter(t) {
845
+ const e = this._elements;
846
+ return new g(function* () {
638
847
  const n = /* @__PURE__ */ new Map();
639
- for await (const [r, o] of t) {
640
- const i = n.get(r) ?? 0;
641
- n.set(r, i + 1), await e(r, o, i) && (yield [r, o]);
848
+ for (const [s, r] of e) {
849
+ const o = n.get(s) ?? 0;
850
+ t(s, r, o) && (yield [s, r]), n.set(s, o + 1);
642
851
  }
643
852
  });
644
853
  }
645
- map(e) {
646
- const t = this._elements;
647
- return new y(async function* () {
854
+ map(t) {
855
+ const e = this._elements;
856
+ return new g(function* () {
648
857
  const n = /* @__PURE__ */ new Map();
649
- for await (const [r, o] of t) {
650
- const i = n.get(r) ?? 0;
651
- n.set(r, i + 1), yield [r, await e(r, o, i)];
858
+ for (const [s, r] of e) {
859
+ const o = n.get(s) ?? 0;
860
+ yield [s, t(s, r, o)], n.set(s, o + 1);
652
861
  }
653
862
  });
654
863
  }
655
- async reduce(e, t) {
864
+ reduce(t, e) {
656
865
  const n = /* @__PURE__ */ new Map();
657
- for await (const [r, o] of this._elements) {
658
- let i, l;
659
- if (n.has(r))
660
- [i, l] = n.get(r), i += 1;
661
- else if (t !== void 0)
662
- i = 0, l = await t(r);
866
+ for (const [s, r] of this._elements) {
867
+ let o, l;
868
+ if (n.has(s))
869
+ [o, l] = n.get(s);
870
+ else if (e !== void 0)
871
+ o = 0, l = e(s);
663
872
  else {
664
- n.set(r, [0, o]);
873
+ n.set(s, [0, r]);
665
874
  continue;
666
875
  }
667
- l = await e(r, l, o, i), n.set(r, [i, l]);
876
+ n.set(s, [o + 1, t(s, l, r, o)]);
668
877
  }
669
- return new a(function* () {
670
- for (const [r, [o, i]] of n)
671
- yield [r, i];
878
+ return new d(function* () {
879
+ for (const [s, [r, o]] of n)
880
+ yield [s, o];
672
881
  });
673
882
  }
674
- unique() {
883
+ flatMap(t) {
675
884
  const e = this._elements;
676
- return new y(async function* () {
677
- const t = /* @__PURE__ */ new Map();
678
- for await (const [n, r] of e) {
679
- const o = t.get(n) ?? /* @__PURE__ */ new Set();
680
- o.has(r) || (o.add(r), t.set(n, o), yield [n, r]);
885
+ return new g(function* () {
886
+ const n = /* @__PURE__ */ new Map();
887
+ for (const [s, r] of e) {
888
+ const o = n.get(s) ?? 0, l = t(s, r, o);
889
+ for (const u of l)
890
+ yield [s, u];
891
+ n.set(s, o + 1);
681
892
  }
682
893
  });
683
894
  }
684
- async count() {
895
+ drop(t) {
896
+ const e = this._elements;
897
+ return new g(function* () {
898
+ const n = /* @__PURE__ */ new Map();
899
+ for (const [s, r] of e) {
900
+ const o = n.get(s) ?? 0;
901
+ if (o < t) {
902
+ n.set(s, o + 1);
903
+ continue;
904
+ }
905
+ yield [s, r];
906
+ }
907
+ });
908
+ }
909
+ take(t) {
910
+ const e = this._elements;
911
+ return new g(function* () {
912
+ const n = /* @__PURE__ */ new Map();
913
+ for (const [s, r] of e) {
914
+ const o = n.get(s) ?? 0;
915
+ o >= t || (yield [s, r], n.set(s, o + 1));
916
+ }
917
+ });
918
+ }
919
+ find(t) {
685
920
  const e = /* @__PURE__ */ new Map();
686
- for await (const [t] of this._elements) {
687
- const n = e.get(t) ?? 0;
688
- e.set(t, n + 1);
921
+ for (const [n, s] of this._elements) {
922
+ let [r, o] = e.get(n) ?? [0, void 0];
923
+ o === void 0 && (t(n, s, r) && (o = s), e.set(n, [r + 1, o]));
689
924
  }
690
- return new a(function* () {
691
- for (const [t, n] of e)
692
- yield [t, n];
925
+ return new d(function* () {
926
+ for (const [n, [s, r]] of e)
927
+ yield [n, r];
693
928
  });
694
929
  }
695
- async first() {
696
- const e = /* @__PURE__ */ new Map();
697
- for await (const [t, n] of this._elements)
698
- e.has(t) || e.set(t, n);
699
- return new a(function* () {
700
- for (const [t, n] of e)
701
- yield [t, n];
930
+ enumerate() {
931
+ return this.map((t, e, n) => [n, e]);
932
+ }
933
+ unique() {
934
+ const t = this._elements;
935
+ return new g(function* () {
936
+ const e = /* @__PURE__ */ new Map();
937
+ for (const [n, s] of t) {
938
+ const r = e.get(n) ?? /* @__PURE__ */ new Set();
939
+ r.has(s) || (r.add(s), e.set(n, r), yield [n, s]);
940
+ }
702
941
  });
703
942
  }
704
- async last() {
705
- const e = /* @__PURE__ */ new Map();
706
- for await (const [t, n] of this._elements)
707
- e.set(t, n);
708
- return new a(function* () {
709
- for (const [t, n] of e)
710
- yield [t, n];
943
+ count() {
944
+ const t = /* @__PURE__ */ new Map();
945
+ for (const [e] of this._elements) {
946
+ const n = t.get(e) ?? 0;
947
+ t.set(e, n + 1);
948
+ }
949
+ return new d(function* () {
950
+ for (const [e, n] of t)
951
+ yield [e, n];
711
952
  });
712
953
  }
954
+ forEach(t) {
955
+ const e = /* @__PURE__ */ new Map();
956
+ for (const [n, s] of this._elements) {
957
+ const r = e.get(n) ?? 0;
958
+ t(n, s, r), e.set(n, r + 1);
959
+ }
960
+ }
713
961
  keys() {
714
- const e = this._elements;
715
- return new h(async function* () {
716
- const t = /* @__PURE__ */ new Set();
717
- for await (const [n] of e)
718
- t.has(n) || (t.add(n), yield n);
962
+ const t = this._elements;
963
+ return new c(function* () {
964
+ const e = /* @__PURE__ */ new Set();
965
+ for (const [n] of t)
966
+ e.has(n) || (e.add(n), yield n);
719
967
  });
720
968
  }
721
969
  items() {
722
970
  return this._elements;
723
971
  }
724
972
  values() {
725
- const e = this._elements;
726
- return new h(async function* () {
727
- for await (const [t, n] of e)
973
+ const t = this._elements;
974
+ return new c(function* () {
975
+ for (const [e, n] of t)
728
976
  yield n;
729
977
  });
730
978
  }
731
- async toArray() {
732
- const e = await this.toMap();
733
- return Array.from(e.values());
979
+ toArray() {
980
+ const t = this.toMap();
981
+ return Array.from(t.values());
734
982
  }
735
- async toMap() {
736
- const e = /* @__PURE__ */ new Map();
737
- for await (const [t, n] of this._elements) {
738
- const r = e.get(t) ?? [];
739
- r.push(n), e.set(t, r);
983
+ toMap() {
984
+ const t = /* @__PURE__ */ new Map();
985
+ for (const [e, n] of this._elements) {
986
+ const s = t.get(e) ?? [];
987
+ s.push(n), t.set(e, s);
740
988
  }
741
- return e;
989
+ return t;
742
990
  }
743
- async toObject() {
744
- const e = {};
745
- for await (const [t, n] of this._elements) {
746
- const r = e[t] ?? [];
747
- r.push(n), e[t] = r;
991
+ toObject() {
992
+ const t = {};
993
+ for (const [e, n] of this._elements) {
994
+ const s = t[e] ?? [];
995
+ s.push(n), t[e] = s;
748
996
  }
749
- return e;
997
+ return t;
750
998
  }
751
- get [Symbol.toStringTag]() {
752
- return "AggregatedAsyncIterator";
999
+ };
1000
+ let S = g;
1001
+ const Be = Function;
1002
+ class Ge extends Be {
1003
+ constructor() {
1004
+ super("return this.invoke(...arguments);");
1005
+ const t = this.bind(this);
1006
+ return Object.setPrototypeOf(this, t), t;
753
1007
  }
754
1008
  }
755
- class _ {
756
- constructor(e) {
757
- u(this, "_elements");
758
- this._elements = new h(e);
759
- }
760
- filter(e) {
761
- return new _(this._elements.filter(e));
762
- }
763
- map(e) {
764
- return new _(this._elements.map(e));
1009
+ var be;
1010
+ be = Symbol.toStringTag;
1011
+ class M {
1012
+ constructor() {
1013
+ a(this, "_subscribers");
1014
+ a(this, be, "Publisher");
1015
+ this._subscribers = /* @__PURE__ */ new Map();
1016
+ }
1017
+ subscribe(t, e) {
1018
+ this._subscribers.has(t) || this._subscribers.set(t, []);
1019
+ const n = this._subscribers.get(t);
1020
+ return n.push(e), () => {
1021
+ const s = n.indexOf(e);
1022
+ if (s < 0)
1023
+ throw new Je("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");
1024
+ n.splice(s, 1);
1025
+ };
765
1026
  }
766
- unique() {
767
- return new _(this._elements.unique());
1027
+ publish(t, ...e) {
1028
+ const n = this._subscribers.get(t);
1029
+ return n ? n.slice().map((s) => s(...e)) : [];
768
1030
  }
769
- groupBy(e) {
770
- return new y(this._elements.map(async (t, n) => [await e(t, n), t]));
1031
+ }
1032
+ class st extends Ge {
1033
+ constructor() {
1034
+ const e = () => {
1035
+ throw new ze(
1036
+ "The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
1037
+ );
1038
+ };
1039
+ super();
1040
+ a(this, "_callback");
1041
+ a(this, "_callbacks");
1042
+ a(this, "_isEnabled");
1043
+ a(this, "_key");
1044
+ a(this, "invoke");
1045
+ this._callback = e, this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, this._key = "", this.invoke = (...n) => this._callback(...n);
1046
+ }
1047
+ get isEnabled() {
1048
+ return this._isEnabled;
1049
+ }
1050
+ get key() {
1051
+ return this._key;
1052
+ }
1053
+ enable() {
1054
+ if (!this._key)
1055
+ throw new x(
1056
+ "The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
1057
+ );
1058
+ if (this._isEnabled)
1059
+ throw new m("The `SwitchableCallback` is already enabled.");
1060
+ this._callback = this._callbacks.get(this._key), this._isEnabled = !0;
1061
+ }
1062
+ disable() {
1063
+ if (!this._isEnabled)
1064
+ throw new m("The `SwitchableCallback` is already disabled.");
1065
+ this._callback = () => {
1066
+ }, this._isEnabled = !1;
1067
+ }
1068
+ register(e, n) {
1069
+ if (this._callbacks.size === 0)
1070
+ this._key = e, this._callback = n;
1071
+ else if (this._callbacks.has(e))
1072
+ throw new x(`The key '${e}' has already been used for another callback.`);
1073
+ this._callbacks.set(e, n);
1074
+ }
1075
+ unregister(e) {
1076
+ if (!this._callbacks.has(e))
1077
+ throw new x(`The key '${e}' doesn't yet have any associated callback.`);
1078
+ this._callbacks.delete(e);
1079
+ }
1080
+ switch(e) {
1081
+ if (!this._callbacks.has(e))
1082
+ throw new x(`The key '${e}' doesn't yet have any associated callback.`);
1083
+ this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e));
771
1084
  }
772
- get [Symbol.toStringTag]() {
773
- return "AsyncAggregator";
1085
+ }
1086
+ var xe;
1087
+ xe = Symbol.toStringTag;
1088
+ class qe {
1089
+ constructor(t, e = 40) {
1090
+ a(this, "_handle");
1091
+ a(this, "_startTime");
1092
+ a(this, "_isRunning");
1093
+ a(this, "_start");
1094
+ a(this, "_stop");
1095
+ a(this, xe, "GameLoop");
1096
+ this._startTime = 0, this._isRunning = !1, Oe ? (this._start = () => {
1097
+ t(this.elapsedTime), this._handle = window.requestAnimationFrame(this._start);
1098
+ }, this._stop = () => window.cancelAnimationFrame(this._handle)) : (console.warn(
1099
+ `Not a browser environment detected. Using setInterval@${e}ms instead of requestAnimationFrame...`
1100
+ ), this._start = () => {
1101
+ this._handle = setInterval(() => t(this.elapsedTime), e);
1102
+ }, this._stop = () => clearInterval(this._handle));
1103
+ }
1104
+ get startTime() {
1105
+ return this._startTime;
1106
+ }
1107
+ get isRunning() {
1108
+ return this._isRunning;
1109
+ }
1110
+ get elapsedTime() {
1111
+ return performance.now() - this._startTime;
1112
+ }
1113
+ start(t = 0) {
1114
+ if (this._isRunning)
1115
+ throw new m("The game loop has already been started.");
1116
+ this._startTime = performance.now() - t, this._start(), this._isRunning = !0;
1117
+ }
1118
+ stop() {
1119
+ if (!this._isRunning)
1120
+ throw new m("The game loop hadn't yet started.");
1121
+ if (!this._handle)
1122
+ throw new k();
1123
+ this._stop(), this._handle = void 0, this._isRunning = !1;
774
1124
  }
775
1125
  }
776
- class C {
777
- constructor(e = !0) {
778
- u(this, "_preferPersistence");
779
- u(this, "_volatile");
780
- u(this, "_persistent");
781
- this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
782
- }
783
- _get(e, t, n) {
784
- const r = e.getItem(t);
785
- if (r)
1126
+ var ve;
1127
+ ve = Symbol.toStringTag;
1128
+ class rt {
1129
+ constructor(t = !0) {
1130
+ a(this, "_preferPersistence");
1131
+ a(this, "_volatile");
1132
+ a(this, "_persistent");
1133
+ a(this, ve, "JSONStorage");
1134
+ if (this._preferPersistence = t, !Oe)
1135
+ throw new Ve(
1136
+ "The `JSONStorage` class can only be instantiated within a browser environment."
1137
+ );
1138
+ this._volatile = window.sessionStorage, this._persistent = window.localStorage;
1139
+ }
1140
+ _get(t, e, n) {
1141
+ const s = t.getItem(e);
1142
+ if (s)
786
1143
  try {
787
- return JSON.parse(r);
1144
+ return JSON.parse(s);
788
1145
  } catch {
789
1146
  console.warn(
790
- `The "${r}" value for "${t}" property cannot be parsed. Clearing the storage...`
791
- ), e.removeItem(t);
1147
+ `The "${s}" value for "${e}" property cannot be parsed. Clearing the storage...`
1148
+ ), t.removeItem(e);
792
1149
  }
793
1150
  return n;
794
1151
  }
795
- _set(e, t, n) {
796
- const r = JSON.stringify(n);
797
- r ? e.setItem(t, r) : e.removeItem(t);
1152
+ _set(t, e, n) {
1153
+ const s = JSON.stringify(n);
1154
+ s ? t.setItem(e, s) : t.removeItem(e);
798
1155
  }
799
- get(e, t, n = this._preferPersistence) {
800
- const r = n ? this._persistent : this._volatile;
801
- return this._get(r, e, t);
1156
+ get(t, e, n = this._preferPersistence) {
1157
+ const s = n ? this._persistent : this._volatile;
1158
+ return this._get(s, t, e);
802
1159
  }
803
- recall(e, t) {
804
- return this._get(this._volatile, e, t);
1160
+ recall(t, e) {
1161
+ return this._get(this._volatile, t, e);
805
1162
  }
806
- retrieve(e, t) {
807
- return this.recall(e) ?? this.read(e, t);
1163
+ retrieve(t, e) {
1164
+ return this.recall(t) ?? this.read(t, e);
808
1165
  }
809
- read(e, t) {
810
- return this._get(this._persistent, e, t);
1166
+ read(t, e) {
1167
+ return this._get(this._persistent, t, e);
811
1168
  }
812
1169
  /**
813
1170
  * Checks whether the property with the specified name exists in the corresponding storage.
@@ -817,8 +1174,8 @@ class C {
817
1174
  *
818
1175
  * @returns `true` if the property exists, `false` otherwise.
819
1176
  */
820
- has(e, t) {
821
- return (t ? this._persistent : this._volatile).getItem(e) !== null;
1177
+ has(t, e) {
1178
+ return (e ? this._persistent : this._volatile).getItem(t) !== null;
822
1179
  }
823
1180
  /**
824
1181
  * Checks whether the property with the specified name exists in the volatile `sessionStorage`.
@@ -827,8 +1184,8 @@ class C {
827
1184
  *
828
1185
  * @returns `true` if the property exists, `false` otherwise.
829
1186
  */
830
- knows(e) {
831
- return this._volatile.getItem(e) !== null;
1187
+ knows(t) {
1188
+ return this._volatile.getItem(t) !== null;
832
1189
  }
833
1190
  /**
834
1191
  * Checks whether the property with the specified name exists looking first in the
@@ -838,8 +1195,8 @@ class C {
838
1195
  *
839
1196
  * @returns `true` if the property exists, `false` otherwise.
840
1197
  */
841
- find(e) {
842
- return this.knows(e) ?? this.exists(e);
1198
+ find(t) {
1199
+ return this.knows(t) ?? this.exists(t);
843
1200
  }
844
1201
  /**
845
1202
  * Checks whether the property with the specified name exists in the persistent `localStorage`.
@@ -848,8 +1205,8 @@ class C {
848
1205
  *
849
1206
  * @returns `true` if the property exists, `false` otherwise.
850
1207
  */
851
- exists(e) {
852
- return this._persistent.getItem(e) !== null;
1208
+ exists(t) {
1209
+ return this._persistent.getItem(t) !== null;
853
1210
  }
854
1211
  /**
855
1212
  * Sets the value with the specified name in the corresponding storage.
@@ -859,9 +1216,9 @@ class C {
859
1216
  * @param newValue The new value to set.
860
1217
  * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.
861
1218
  */
862
- set(e, t, n = this._preferPersistence) {
863
- const r = n ? this._persistent : this._volatile;
864
- this._set(r, e, t);
1219
+ set(t, e, n = this._preferPersistence) {
1220
+ const s = n ? this._persistent : this._volatile;
1221
+ this._set(s, t, e);
865
1222
  }
866
1223
  /**
867
1224
  * Sets the value with the specified name in the volatile `sessionStorage`.
@@ -870,8 +1227,8 @@ class C {
870
1227
  * @param propertyName The name of the property to set.
871
1228
  * @param newValue The new value to set.
872
1229
  */
873
- remember(e, t) {
874
- this._set(this._volatile, e, t);
1230
+ remember(t, e) {
1231
+ this._set(this._volatile, t, e);
875
1232
  }
876
1233
  /**
877
1234
  * Sets the value with the specified name in the persistent `localStorage`.
@@ -880,69 +1237,51 @@ class C {
880
1237
  * @param propertyName The name of the property to set.
881
1238
  * @param newValue The new value to set.
882
1239
  */
883
- write(e, t) {
884
- this._set(this._persistent, e, t);
1240
+ write(t, e) {
1241
+ this._set(this._persistent, t, e);
885
1242
  }
886
1243
  /**
887
1244
  * Removes the value with the specified name from the volatile `sessionStorage`.
888
1245
  *
889
1246
  * @param propertyName The name of the property to remove.
890
1247
  */
891
- forget(e) {
892
- this._volatile.removeItem(e);
1248
+ forget(t) {
1249
+ this._volatile.removeItem(t);
893
1250
  }
894
1251
  /**
895
1252
  * Removes the value with the specified name from the persistent `localStorage`.
896
1253
  *
897
1254
  * @param propertyName The name of the property to remove.
898
1255
  */
899
- erase(e) {
900
- this._persistent.removeItem(e);
1256
+ erase(t) {
1257
+ this._persistent.removeItem(t);
901
1258
  }
902
1259
  /**
903
1260
  * Removes the value with the specified name from all the storages.
904
1261
  *
905
1262
  * @param propertyName The name of the property to remove.
906
1263
  */
907
- clear(e) {
908
- this._volatile.removeItem(e), this._persistent.removeItem(e);
909
- }
910
- get [Symbol.toStringTag]() {
911
- return "JsonStorage";
912
- }
913
- }
914
- class N {
915
- constructor() {
916
- u(this, "_subscribers");
917
- this._subscribers = [];
918
- }
919
- add(e) {
920
- this._subscribers.push(e);
921
- }
922
- remove(e) {
923
- const t = this._subscribers.indexOf(e);
924
- if (t < 0)
925
- throw new k("Unable to remove the requested subscriber. It was not found.");
926
- this._subscribers.splice(t, 1);
927
- }
928
- call(...e) {
929
- return this._subscribers.slice().map((t) => t(...e));
930
- }
931
- get [Symbol.toStringTag]() {
932
- return "Subscribers";
1264
+ clear(t) {
1265
+ this._volatile.removeItem(t), this._persistent.removeItem(t);
933
1266
  }
934
1267
  }
935
- class g {
936
- constructor(e) {
937
- u(this, "_isPending");
938
- u(this, "_isFulfilled");
939
- u(this, "_isRejected");
940
- u(this, "_promise");
1268
+ var ke;
1269
+ ke = Symbol.toStringTag;
1270
+ const R = class R {
1271
+ constructor(t) {
1272
+ a(this, "_isPending");
1273
+ a(this, "_isFulfilled");
1274
+ a(this, "_isRejected");
1275
+ a(this, "_promise");
1276
+ a(this, ke, "SmartPromise");
941
1277
  this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
942
- const t = (r) => (this._isPending = !1, this._isFulfilled = !0, r), n = (r) => {
943
- throw this._isPending = !1, this._isRejected = !0, r;
1278
+ const e = (s) => (this._isPending = !1, this._isFulfilled = !0, s), n = (s) => {
1279
+ throw this._isPending = !1, this._isRejected = !0, s;
944
1280
  };
945
- this._promise = new Promise(e).then(t, n);
1281
+ this._promise = new Promise(t).then(e, n);
1282
+ }
1283
+ static FromPromise(t) {
1284
+ return new R((e, n) => t.then(e, n));
946
1285
  }
947
1286
  get isPending() {
948
1287
  return this._isPending;
@@ -953,28 +1292,28 @@ class g {
953
1292
  get isRejected() {
954
1293
  return this._isRejected;
955
1294
  }
956
- then(e, t) {
957
- return this._promise.then(e, t);
1295
+ then(t, e) {
1296
+ return this._promise.then(t, e);
958
1297
  }
959
- catch(e) {
960
- return this._promise.catch(e);
1298
+ catch(t) {
1299
+ return this._promise.catch(t);
961
1300
  }
962
- finally(e) {
963
- return this._promise.finally(e);
1301
+ finally(t) {
1302
+ return this._promise.finally(t);
964
1303
  }
965
- get [Symbol.toStringTag]() {
966
- return "SmartPromise";
967
- }
968
- }
969
- class Y extends g {
970
- constructor(t, n) {
971
- let r, o;
972
- super((i, l) => {
973
- r = i, o = l;
1304
+ };
1305
+ let T = R;
1306
+ var Se, Te;
1307
+ class Ke extends (Te = T, Se = Symbol.toStringTag, Te) {
1308
+ constructor(e, n) {
1309
+ let s, r;
1310
+ super((o, l) => {
1311
+ s = o, r = l;
974
1312
  });
975
- u(this, "_resolve");
976
- u(this, "_reject");
977
- this._promise.then(t, n), this._resolve = r, this._reject = o;
1313
+ a(this, "_resolve");
1314
+ a(this, "_reject");
1315
+ a(this, Se, "DeferredPromise");
1316
+ this._promise.then(e, n), this._resolve = s, this._reject = r;
978
1317
  }
979
1318
  get resolve() {
980
1319
  return this._resolve;
@@ -982,215 +1321,518 @@ class Y extends g {
982
1321
  get reject() {
983
1322
  return this._reject;
984
1323
  }
985
- watch(t) {
986
- return t.then(this.resolve, this.reject), this;
987
- }
988
- get [Symbol.toStringTag]() {
989
- return "DeferredPromise";
1324
+ watch(e) {
1325
+ return e.then(this.resolve, this.reject), this;
990
1326
  }
991
1327
  }
992
- class z extends g {
993
- constructor(e, t) {
994
- super((n, r) => {
995
- const o = (p) => {
996
- clearTimeout(x), n(p);
997
- }, i = (p) => {
998
- clearTimeout(x), r(p);
999
- }, x = setTimeout(() => i(new T("The operation has timed out.")), t);
1000
- e(o, i);
1001
- });
1328
+ function it(i) {
1329
+ return new Promise((t) => setTimeout(t, i));
1330
+ }
1331
+ function ot() {
1332
+ return new Promise((i) => requestAnimationFrame(() => i()));
1333
+ }
1334
+ function v() {
1335
+ return new Promise((i) => setTimeout(i));
1336
+ }
1337
+ var Ee;
1338
+ Ee = Symbol.toStringTag;
1339
+ const P = class P {
1340
+ constructor(t, e) {
1341
+ a(this, "_startTime");
1342
+ a(this, "_estimatedTime");
1343
+ a(this, "_endTime");
1344
+ a(this, "_currentStep");
1345
+ a(this, "_percentage");
1346
+ a(this, "_isRunning");
1347
+ a(this, "_hasCompleted");
1348
+ a(this, "_hasFailed");
1349
+ a(this, "_promise");
1350
+ a(this, "_publisher");
1351
+ a(this, Ee, "LongRunningTask");
1352
+ this._startTime = 0, this._estimatedTime = 0, this._currentStep = 0, this._percentage = 0, this._isRunning = !0, this._hasCompleted = !1, this._hasFailed = !1;
1353
+ const n = (o) => (this._estimatedTime = 0, this._endTime = Date.now(), this._percentage = 100, this._isRunning = !1, this._hasCompleted = !0, o), s = (o) => {
1354
+ throw this._endTime = Date.now(), this._isRunning = !1, this._hasFailed = !0, o;
1355
+ };
1356
+ let r;
1357
+ if (e = { ...P._DefaultOptions, ...e }, e.trackProgress) {
1358
+ let o;
1359
+ this._publisher = new M(), e.totalSteps ? e.stepIncrement ? o = (l) => {
1360
+ l ? this._currentStep += l : this._currentStep += e.stepIncrement, this._percentage = this._currentStep / e.totalSteps * 100;
1361
+ const u = Date.now() - this._startTime, h = e.totalSteps - this._currentStep;
1362
+ this._estimatedTime = u / this._currentStep * h;
1363
+ } : o = (l) => {
1364
+ if (l) {
1365
+ this._currentStep += l, this._percentage = this._currentStep / e.totalSteps * 100;
1366
+ const u = Date.now() - this._startTime, h = e.totalSteps - this._currentStep;
1367
+ this._estimatedTime = u / this._currentStep * h;
1368
+ }
1369
+ } : e.stepIncrement ? o = (l) => {
1370
+ l ? this._currentStep += l : this._currentStep += e.stepIncrement;
1371
+ } : o = (l) => {
1372
+ l && (this._currentStep += l);
1373
+ }, e.ignoreErrors ? r = async (l) => {
1374
+ const u = t();
1375
+ for (this._startTime = Date.now(); ; ) {
1376
+ try {
1377
+ const { done: h, value: _ } = await u.next();
1378
+ if (h)
1379
+ return l(_);
1380
+ o(_);
1381
+ } catch (h) {
1382
+ console.error(h);
1383
+ }
1384
+ this._publisher.publish("progress"), await v();
1385
+ }
1386
+ } : r = async (l, u) => {
1387
+ try {
1388
+ const h = t();
1389
+ for (this._startTime = Date.now(); ; ) {
1390
+ const { done: _, value: I } = await h.next();
1391
+ if (_)
1392
+ return l(I);
1393
+ o(I), this._publisher.publish("progress"), await v();
1394
+ }
1395
+ } catch (h) {
1396
+ u(h);
1397
+ }
1398
+ };
1399
+ } else e.ignoreErrors ? r = async (o) => {
1400
+ const l = t();
1401
+ for (this._startTime = Date.now(); ; ) {
1402
+ try {
1403
+ const { done: u, value: h } = await l.next();
1404
+ if (u)
1405
+ return o(h);
1406
+ } catch (u) {
1407
+ console.error(u);
1408
+ }
1409
+ await v();
1410
+ }
1411
+ } : r = async (o, l) => {
1412
+ try {
1413
+ const u = t();
1414
+ for (this._startTime = Date.now(); ; ) {
1415
+ const { done: h, value: _ } = await u.next();
1416
+ if (h)
1417
+ return o(_);
1418
+ await v();
1419
+ }
1420
+ } catch (u) {
1421
+ l(u);
1422
+ }
1423
+ };
1424
+ this._promise = new Promise(r).then(n, s);
1425
+ }
1426
+ static get _DefaultOptions() {
1427
+ return {
1428
+ ignoreErrors: !1,
1429
+ stepIncrement: 1,
1430
+ totalSteps: null,
1431
+ trackProgress: !1
1432
+ };
1002
1433
  }
1003
- get [Symbol.toStringTag]() {
1004
- return "TimedPromise";
1434
+ get startTime() {
1435
+ return this._startTime;
1005
1436
  }
1006
- }
1007
- class v {
1008
- static Boolean(e = 0.5) {
1009
- return Math.random() < e;
1437
+ get elapsedTime() {
1438
+ return this._isRunning ? Date.now() - this._startTime : this._endTime - this._startTime;
1439
+ }
1440
+ get estimatedTime() {
1441
+ return this._estimatedTime;
1442
+ }
1443
+ get endTime() {
1444
+ if (this._isRunning)
1445
+ throw new m("The task is still running and has no end time yet.");
1446
+ return this._endTime;
1447
+ }
1448
+ get currentStep() {
1449
+ return this._currentStep;
1450
+ }
1451
+ get percentage() {
1452
+ return this._percentage;
1453
+ }
1454
+ get isRunning() {
1455
+ return this._isRunning;
1456
+ }
1457
+ get hasCompleted() {
1458
+ return this._hasCompleted;
1010
1459
  }
1011
- static Integer(e, t) {
1012
- return Math.floor(t === void 0 ? Math.random() * e : Math.random() * (t - e) + e);
1460
+ get hasFailed() {
1461
+ return this._hasFailed;
1013
1462
  }
1014
- static Decimal(e, t) {
1015
- return e === void 0 ? Math.random() : t === void 0 ? Math.random() * e : Math.random() * (t - e) + e;
1463
+ then(t, e) {
1464
+ return this._promise.then(t, e);
1016
1465
  }
1017
- static Index(e) {
1018
- if (e.length === 0)
1019
- throw new m("You must provide at least one element.");
1020
- return this.Integer(e.length);
1466
+ catch(t) {
1467
+ return this._promise.catch(t);
1021
1468
  }
1022
- static Choice(e) {
1023
- return e[v.Index(e)];
1469
+ finally(t) {
1470
+ return this._promise.finally(t);
1024
1471
  }
1025
- // eslint-disable-next-line no-useless-constructor
1472
+ onProgress(t) {
1473
+ if (!this._publisher)
1474
+ throw new m(
1475
+ "You cannot subscribe to progress events without enabling progress tracking. Did you forget to set the `trackProgress` option to `true` when creating the task?"
1476
+ );
1477
+ return this._publisher.subscribe("progress", t);
1478
+ }
1479
+ };
1480
+ let C = P;
1481
+ var Me;
1482
+ Me = Symbol.toStringTag;
1483
+ class at {
1026
1484
  constructor() {
1485
+ a(this, "_onFulfilled");
1486
+ a(this, Me, "Thenable");
1487
+ this._onFulfilled = (t) => t;
1488
+ }
1489
+ _resolve(t) {
1490
+ return this._onFulfilled(t);
1491
+ }
1492
+ then(t, e) {
1493
+ if (e) {
1494
+ const n = this._onFulfilled;
1495
+ this._onFulfilled = (s) => {
1496
+ try {
1497
+ return s = n(s), t(s);
1498
+ } catch (r) {
1499
+ return e(r);
1500
+ }
1501
+ };
1502
+ } else if (t) {
1503
+ const n = this._onFulfilled;
1504
+ this._onFulfilled = (s) => (s = n(s), t(s));
1505
+ }
1506
+ return this;
1507
+ }
1508
+ catch(t) {
1509
+ if (t) {
1510
+ const e = this._onFulfilled;
1511
+ this._onFulfilled = (n) => {
1512
+ try {
1513
+ return e(n);
1514
+ } catch (s) {
1515
+ return t(s);
1516
+ }
1517
+ };
1518
+ }
1519
+ return this;
1520
+ }
1521
+ finally(t) {
1522
+ if (t) {
1523
+ const e = this._onFulfilled;
1524
+ this._onFulfilled = (n) => {
1525
+ try {
1526
+ return e(n);
1527
+ } finally {
1528
+ t();
1529
+ }
1530
+ };
1531
+ }
1532
+ return this;
1027
1533
  }
1028
1534
  }
1029
- async function J(s) {
1030
- return new Promise((e, t) => setTimeout(e, s));
1031
- }
1032
- async function V() {
1033
- return new Promise((s, e) => requestAnimationFrame(() => s()));
1535
+ var Fe, Re;
1536
+ class lt extends (Re = T, Fe = Symbol.toStringTag, Re) {
1537
+ constructor(e, n) {
1538
+ super((s, r) => {
1539
+ const o = (_) => {
1540
+ clearTimeout(h), s(_);
1541
+ }, l = (_) => {
1542
+ clearTimeout(h), r(_);
1543
+ }, h = setTimeout(() => l(new We("The operation has timed out.")), n);
1544
+ e(o, l);
1545
+ });
1546
+ a(this, Fe, "TimedPromise");
1547
+ }
1034
1548
  }
1035
- var M = /* @__PURE__ */ ((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))(M || {});
1036
- function B(s, e, t = 864e5) {
1037
- return s = new Date(s), e = new Date(e), Math.floor((e.getTime() - s.getTime()) / t);
1549
+ var F = /* @__PURE__ */ ((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))(F || {});
1550
+ function ut(i, t, e = 864e5) {
1551
+ return i = new Date(i), t = new Date(t), Math.floor((t.getTime() - i.getTime()) / e);
1038
1552
  }
1039
- function K(s, e, t = 864e5) {
1040
- return s = new Date(s), e = new Date(e), new c(function* () {
1041
- const n = e.getTime();
1042
- let r = s.getTime();
1043
- for (; r < n; )
1044
- yield new Date(r), r += t;
1553
+ function ct(i, t, e = 864e5) {
1554
+ return i = new Date(i), t = new Date(t), new c(function* () {
1555
+ const n = t.getTime();
1556
+ let s = i.getTime();
1557
+ for (; s < n; )
1558
+ yield new Date(s), s += e;
1045
1559
  });
1046
1560
  }
1047
- function H(s, e = 864e5) {
1048
- return s = new Date(s), new Date(Math.floor(s.getTime() / e) * e);
1561
+ function ht(i, t = 864e5) {
1562
+ return i = new Date(i), new Date(Math.floor(i.getTime() / t) * t);
1049
1563
  }
1050
- function W(s, e = "text/javascript") {
1051
- return new Promise((t, n) => {
1052
- const r = document.createElement("script");
1053
- r.async = !0, r.defer = !0, r.src = s, r.type = e, r.onload = () => t(), r.onerror = () => n(), document.body.appendChild(r);
1564
+ var Pe, De;
1565
+ class ft extends (De = qe, Pe = Symbol.toStringTag, De) {
1566
+ constructor(e = F.Second) {
1567
+ super((n) => this._publisher.publish("tick", n), e);
1568
+ a(this, "_publisher");
1569
+ a(this, Pe, "Clock");
1570
+ this._publisher = new M();
1571
+ }
1572
+ start(e = 0) {
1573
+ if (this._isRunning)
1574
+ throw new m("The clock has already been started.");
1575
+ super.start(e), this._publisher.publish("start");
1576
+ }
1577
+ stop() {
1578
+ if (!this._isRunning)
1579
+ throw new m("The clock hadn't yet started.");
1580
+ super.stop(), this._publisher.publish("stop");
1581
+ }
1582
+ onStart(e) {
1583
+ return this._publisher.subscribe("start", e);
1584
+ }
1585
+ onStop(e) {
1586
+ return this._publisher.subscribe("stop", e);
1587
+ }
1588
+ onTick(e, n = 0) {
1589
+ if (n < 0)
1590
+ throw new $e("The tick step must be a non-negative number.");
1591
+ if (n === 0)
1592
+ return this._publisher.subscribe("tick", e);
1593
+ let s = 0;
1594
+ return this._publisher.subscribe("tick", (r) => {
1595
+ r - s < n || (e(r), s = r);
1596
+ });
1597
+ }
1598
+ }
1599
+ var Ie, Ce;
1600
+ class dt extends (Ce = qe, Ie = Symbol.toStringTag, Ce) {
1601
+ constructor(e, n = F.Second) {
1602
+ super(() => {
1603
+ const r = this.remainingTime;
1604
+ this._publisher.publish("tick", r), r <= 0 && (this._deferrerStop(), this._publisher.publish("expire"));
1605
+ }, n);
1606
+ a(this, "_deferrer");
1607
+ a(this, "_publisher");
1608
+ a(this, "_duration");
1609
+ a(this, Ie, "Countdown");
1610
+ this._publisher = new M(), this._duration = e;
1611
+ }
1612
+ get duration() {
1613
+ return this._duration;
1614
+ }
1615
+ get remainingTime() {
1616
+ return this._duration - this.elapsedTime;
1617
+ }
1618
+ _deferrerStop(e) {
1619
+ if (!this._isRunning)
1620
+ throw new m("The countdown hadn't yet started.");
1621
+ if (!this._deferrer)
1622
+ throw new k();
1623
+ super.stop(), e !== void 0 ? this._deferrer.reject(e) : this._deferrer.resolve(), this._deferrer = void 0;
1624
+ }
1625
+ start(e = this.duration) {
1626
+ if (this._isRunning)
1627
+ throw new m("The countdown has already been started.");
1628
+ if (this._deferrer)
1629
+ throw new k();
1630
+ return this._deferrer = new Ke(), super.start(this.duration - e), this._publisher.publish("start"), this._deferrer;
1631
+ }
1632
+ stop(e) {
1633
+ this._deferrerStop(e), this._publisher.publish("stop", e);
1634
+ }
1635
+ onExpire(e) {
1636
+ return this._publisher.subscribe("expire", e);
1637
+ }
1638
+ onStart(e) {
1639
+ return this._publisher.subscribe("start", e);
1640
+ }
1641
+ onStop(e) {
1642
+ return this._publisher.subscribe("stop", e);
1643
+ }
1644
+ onTick(e, n = 0) {
1645
+ if (n < 0)
1646
+ throw new $e("The tick step must be a non-negative number.");
1647
+ if (n === 0)
1648
+ return this._publisher.subscribe("tick", e);
1649
+ let s = 0;
1650
+ return this._publisher.subscribe("tick", (r) => {
1651
+ s - r < n || (e(r), s = r);
1652
+ });
1653
+ }
1654
+ }
1655
+ var je;
1656
+ je = Symbol.toStringTag;
1657
+ const D = class D {
1658
+ constructor() {
1659
+ a(this, je, "Random");
1660
+ }
1661
+ static Boolean(t = 0.5) {
1662
+ return Math.random() < t;
1663
+ }
1664
+ static Integer(t, e) {
1665
+ return Math.floor(e === void 0 ? Math.random() * t : Math.random() * (e - t) + t);
1666
+ }
1667
+ static Decimal(t, e) {
1668
+ return t === void 0 ? Math.random() : e === void 0 ? Math.random() * t : Math.random() * (e - t) + t;
1669
+ }
1670
+ static Index(t) {
1671
+ if (t.length === 0)
1672
+ throw new p("You must provide at least one element.");
1673
+ return this.Integer(t.length);
1674
+ }
1675
+ static Choice(t) {
1676
+ return t[D.Index(t)];
1677
+ }
1678
+ };
1679
+ let j = D;
1680
+ function mt(i, t = "text/javascript") {
1681
+ return new Promise((e, n) => {
1682
+ const s = document.createElement("script");
1683
+ s.async = !0, s.defer = !0, s.src = i, s.type = t, s.onload = () => e(), s.onerror = () => n(), document.body.appendChild(s);
1054
1684
  });
1055
1685
  }
1056
- function G(...s) {
1686
+ function _t(...i) {
1057
1687
  return new c(function* () {
1058
- for (const e of s)
1059
- for (const t of e)
1060
- yield t;
1688
+ for (const t of i)
1689
+ for (const e of t)
1690
+ yield e;
1061
1691
  });
1062
1692
  }
1063
- function L(s) {
1064
- if (Array.isArray(s))
1065
- return s.length;
1066
- let e = 0;
1067
- for (const t of s)
1068
- e += 1;
1069
- return e;
1693
+ function wt(i) {
1694
+ if (Array.isArray(i))
1695
+ return i.length;
1696
+ let t = 0;
1697
+ for (const e of i)
1698
+ t += 1;
1699
+ return t;
1070
1700
  }
1071
- function Q(s) {
1701
+ function pt(i) {
1072
1702
  return new c(function* () {
1073
- let e = 0;
1074
- for (const t of s)
1075
- yield [e, t], e += 1;
1703
+ let t = 0;
1704
+ for (const e of i)
1705
+ yield [t, e], t += 1;
1076
1706
  });
1077
1707
  }
1078
- function X(s, e, t = 1) {
1708
+ function yt(i, t, e = 1) {
1079
1709
  return new c(function* () {
1080
- e === void 0 && (e = s, s = 0), s > e && (t = t ?? -1);
1081
- for (let n = s; n < e; n += t)
1710
+ t === void 0 && (t = i, i = 0), i > t && (e = e ?? -1);
1711
+ for (let n = i; n < t; n += e)
1082
1712
  yield n;
1083
1713
  });
1084
1714
  }
1085
- function Z(s) {
1086
- const e = Array.from(s);
1087
- for (let t = e.length - 1; t > 0; t -= 1) {
1088
- const n = Math.floor(Math.random() * (t + 1));
1089
- [e[t], e[n]] = [e[n], e[t]];
1715
+ function gt(i) {
1716
+ const t = Array.from(i);
1717
+ for (let e = t.length - 1; e > 0; e -= 1) {
1718
+ const n = Math.floor(Math.random() * (e + 1));
1719
+ [t[e], t[n]] = [t[n], t[e]];
1090
1720
  }
1091
- return e;
1721
+ return t;
1092
1722
  }
1093
- function D(s) {
1723
+ function bt(i) {
1094
1724
  return new c(function* () {
1095
- const e = /* @__PURE__ */ new Set();
1096
- for (const t of s)
1097
- e.has(t) || (e.add(t), yield t);
1725
+ const t = /* @__PURE__ */ new Set();
1726
+ for (const e of i)
1727
+ t.has(e) || (t.add(e), yield e);
1098
1728
  });
1099
1729
  }
1100
- function P(s, e) {
1730
+ function Le(i, t) {
1101
1731
  return new c(function* () {
1102
- const t = s[Symbol.iterator](), n = e[Symbol.iterator]();
1732
+ const e = i[Symbol.iterator](), n = t[Symbol.iterator]();
1103
1733
  for (; ; ) {
1104
- const r = t.next(), o = n.next();
1105
- if (r.done || o.done)
1734
+ const s = e.next(), r = n.next();
1735
+ if (s.done || r.done)
1106
1736
  break;
1107
- yield [r.value, o.value];
1737
+ yield [s.value, r.value];
1108
1738
  }
1109
1739
  });
1110
1740
  }
1111
- function U(s, e) {
1112
- if (e === void 0) {
1113
- let o = 0, i = 0;
1114
- for (const l of s)
1115
- o += l, i += 1;
1116
- if (i === 0)
1117
- throw new m("You must provide at least one value.");
1118
- return o / i;
1119
- }
1120
- let t = 0, n = 0, r = 0;
1121
- for (const [o, i] of P(s, e)) {
1122
- if (i <= 0)
1123
- throw new m(`The weight for the value #${r} must be greater than zero.`);
1124
- t += o * i, n += i, r += 1;
1125
- }
1126
- if (r === 0)
1127
- throw new m("You must provide at least one value and weight.");
1741
+ function xt(i, t) {
1742
+ if (t === void 0) {
1743
+ let r = 0, o = 0;
1744
+ for (const l of i)
1745
+ r += l, o += 1;
1746
+ if (o === 0)
1747
+ throw new p("You must provide at least one value.");
1748
+ return r / o;
1749
+ }
1750
+ let e = 0, n = 0, s = 0;
1751
+ for (const [r, o] of Le(i, t)) {
1752
+ if (o <= 0)
1753
+ throw new p(`The weight for the value #${s} must be greater than zero.`);
1754
+ e += r * o, n += o, s += 1;
1755
+ }
1756
+ if (s === 0)
1757
+ throw new p("You must provide at least one value and weight.");
1128
1758
  if (n > 0)
1129
- throw new m("The sum of weights must be greater than zero.");
1130
- return t / n;
1759
+ throw new p("The sum of weights must be greater than zero.");
1760
+ return e / n;
1131
1761
  }
1132
- function ee(s) {
1133
- let e = 0;
1134
- for (let t = 0; t < s.length; t += 1) {
1135
- const n = s.charCodeAt(t);
1136
- e = (e << 5) - e + n, e |= 0;
1762
+ function vt(i) {
1763
+ let t = 0;
1764
+ for (let e = 0; e < i.length; e += 1) {
1765
+ const n = i.charCodeAt(e);
1766
+ t = (t << 5) - t + n, t |= 0;
1137
1767
  }
1138
- return e;
1768
+ return t;
1139
1769
  }
1140
- function te(s) {
1141
- let e = 0;
1142
- for (const t of s)
1143
- e += t;
1144
- return e;
1770
+ function kt(i) {
1771
+ let t = 0;
1772
+ for (const e of i)
1773
+ t += e;
1774
+ return t;
1145
1775
  }
1146
- function ne(s) {
1147
- return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
1776
+ function St(i) {
1777
+ return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
1148
1778
  }
1149
- const re = "1.5.3";
1779
+ const Tt = "2.0.0-rc.10";
1150
1780
  export {
1151
- y as AggregatedAsyncIterator,
1152
- d as AggregatedIterator,
1153
- w as Aggregator,
1154
- _ as AsyncAggregator,
1155
- M as DateUnit,
1156
- Y as DeferredPromise,
1781
+ E as AggregatedAsyncIterator,
1782
+ S as AggregatedIterator,
1783
+ Ge as CallableObject,
1784
+ ft as Clock,
1785
+ dt as Countdown,
1786
+ Ke as DeferredPromise,
1157
1787
  f as Exception,
1158
- j as FatalErrorException,
1159
- R as FileNotFoundException,
1160
- C as JsonStorage,
1161
- q as KeyException,
1162
- A as NetworkException,
1163
- F as NotImplementedException,
1164
- O as PermissionException,
1165
- v as Random,
1166
- a as ReducedIterator,
1167
- k as ReferenceException,
1168
- $ as RuntimeException,
1169
- h as SmartAsyncIterator,
1788
+ k as FatalErrorException,
1789
+ Ae as FileException,
1790
+ Ze as FileExistsException,
1791
+ Ue as FileNotFoundException,
1792
+ qe as GameLoop,
1793
+ rt as JSONStorage,
1794
+ x as KeyException,
1795
+ C as LongRunningTask,
1796
+ et as NetworkException,
1797
+ ze as NotImplementedException,
1798
+ tt as PermissionException,
1799
+ M as Publisher,
1800
+ j as Random,
1801
+ $e as RangeException,
1802
+ d as ReducedIterator,
1803
+ Je as ReferenceException,
1804
+ m as RuntimeException,
1805
+ w as SmartAsyncIterator,
1170
1806
  c as SmartIterator,
1171
- g as SmartPromise,
1172
- N as Subscribers,
1173
- z as TimedPromise,
1174
- T as TimeoutException,
1175
- E as TypeException,
1176
- re as VERSION,
1177
- m as ValueException,
1178
- U as average,
1179
- ne as capitalize,
1180
- G as chain,
1181
- L as count,
1182
- B as dateDifference,
1183
- K as dateRange,
1184
- H as dateRound,
1185
- J as delay,
1186
- Q as enumerate,
1187
- ee as hash,
1188
- W as loadScript,
1189
- V as nextAnimationFrame,
1190
- X as range,
1191
- Z as shuffle,
1192
- te as sum,
1193
- D as unique,
1194
- P as zip
1807
+ T as SmartPromise,
1808
+ st as SwitchableCallback,
1809
+ at as Thenable,
1810
+ F as TimeUnit,
1811
+ lt as TimedPromise,
1812
+ We as TimeoutException,
1813
+ nt as TypeException,
1814
+ Tt as VERSION,
1815
+ p as ValueException,
1816
+ xt as average,
1817
+ St as capitalize,
1818
+ _t as chain,
1819
+ wt as count,
1820
+ ut as dateDifference,
1821
+ ct as dateRange,
1822
+ ht as dateRound,
1823
+ it as delay,
1824
+ pt as enumerate,
1825
+ vt as hash,
1826
+ Oe as isBrowser,
1827
+ Qe as isNode,
1828
+ Xe as isWebWorker,
1829
+ mt as loadScript,
1830
+ ot as nextAnimationFrame,
1831
+ yt as range,
1832
+ gt as shuffle,
1833
+ kt as sum,
1834
+ bt as unique,
1835
+ v as yieldToEventLoop,
1836
+ Le as zip
1195
1837
  };
1196
1838
  //# sourceMappingURL=core.js.map