@tktb-tess/util-fns 0.11.2 → 0.11.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/README.md CHANGED
@@ -1 +1,3 @@
1
1
  # util-fns
2
+
3
+ Utility functions for personal use
package/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
1
+ const J = (n, t) => [n].includes(t), h = (n, t) => {
2
2
  if (typeof n != typeof t) return !1;
3
3
  const e = Object.prototype.toString.call(n), r = Object.prototype.toString.call(t);
4
4
  if (e !== r) return !1;
@@ -11,33 +11,33 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
11
11
  if (Array.isArray(n) && Array.isArray(t)) {
12
12
  if (n.length !== t.length) return !1;
13
13
  for (let s = 0; s < n.length; s++)
14
- if (!d(n[s], t[s])) return !1;
14
+ if (!h(n[s], t[s])) return !1;
15
15
  return !0;
16
16
  }
17
17
  if (n instanceof Set && t instanceof Set) {
18
18
  const s = [...n.values()], o = [...t.values()];
19
- return !!d(s, o);
19
+ return !!h(s, o);
20
20
  }
21
21
  if (n instanceof Map && t instanceof Map) {
22
22
  const s = [...n.keys()], o = [...t.keys()];
23
- if (!d(s, o)) return !1;
23
+ if (!h(s, o)) return !1;
24
24
  const i = [...n.values()], c = [...t.values()];
25
- return !!d(i, c);
25
+ return !!h(i, c);
26
26
  }
27
27
  if (e === "[object Object]") {
28
28
  const s = n, o = t, i = Object.keys(s), c = Object.keys(o);
29
29
  for (const l of i) {
30
- const u = c.find((M) => M === l);
30
+ const u = c.find((L) => L === l);
31
31
  if (u === void 0) return !1;
32
- const [f, h] = [s[l], o[u]];
33
- if (!d(f, h)) return !1;
32
+ const [f, d] = [s[l], o[u]];
33
+ if (!h(f, d)) return !1;
34
34
  }
35
35
  return !0;
36
36
  }
37
- throw Error(`comparing these objects is unavailable: ${n}, ${t}`, {
37
+ throw TypeError(`comparing these objects is unavailable: ${n}, ${t}`, {
38
38
  cause: [n, t]
39
39
  });
40
- }, H = () => {
40
+ }, Y = () => {
41
41
  let n, t;
42
42
  return {
43
43
  promise: new Promise((r, s) => {
@@ -46,12 +46,9 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
46
46
  resolve: n,
47
47
  reject: t
48
48
  };
49
- }, J = (n) => new Promise((t) => {
50
- setTimeout(() => t(), n);
51
- }), Y = (n) => {
52
- const t = Object.prototype.toString.call(n);
53
- return t.slice(8, t.length - 1);
54
- }, Z = (n) => (...t) => () => n(...t), Q = (n) => {
49
+ }, k = (n) => new Promise((t) => {
50
+ setTimeout(t, n);
51
+ }), Z = (n) => Object.prototype.toString.call(n).slice(8, -1), Q = (n) => (...t) => () => n(...t), tt = (n) => {
55
52
  const t = [];
56
53
  let e = [], r = "", s = !1;
57
54
  for (let o = 0; o < n.length; o++) {
@@ -60,23 +57,23 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
60
57
  ` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
61
58
  }
62
59
  return e.push(r.trim()), t.push(e), t;
63
- }, tt = async (n, t) => {
64
- const e = x.encode(n), r = await crypto.subtle.digest(t, e);
60
+ }, nt = async (n, t) => {
61
+ const e = new TextEncoder().encode(n), r = await crypto.subtle.digest(t, e);
65
62
  return new Uint8Array(r);
66
- }, nt = (n) => encodeURIComponent(n).replace(
63
+ }, et = (n) => encodeURIComponent(n).replace(
67
64
  /[!'()*]/g,
68
65
  (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`
69
- ), et = (n) => {
66
+ ), rt = (n) => {
70
67
  if (n.includes("+"))
71
- throw Error("An input string has '+'");
68
+ throw URIError("an input string must not include `+`");
72
69
  return decodeURIComponent(n);
73
- }, rt = async (n, t) => {
74
- const r = new Blob([n]).stream().pipeThrough(new CompressionStream(t));
75
- return new Response(r).bytes();
76
- }, st = async (n, t) => {
77
- const r = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
78
- return new Response(r).bytes();
79
- }, ot = (n, t) => new Promise((e, r) => {
70
+ }, st = (n, t) => {
71
+ const e = new Blob([n]).stream().pipeThrough(new CompressionStream(t));
72
+ return new Response(e).bytes();
73
+ }, ot = (n, t) => {
74
+ const e = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
75
+ return new Response(e).bytes();
76
+ }, it = (n, t) => new Promise((e, r) => {
80
77
  setTimeout(async () => {
81
78
  try {
82
79
  const s = await n();
@@ -85,53 +82,32 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
85
82
  r(s);
86
83
  }
87
84
  }, t);
88
- }), B = "NamedError";
89
- class I extends Error {
90
- constructor(t, e, r) {
91
- super(e, r), this.errName = t;
92
- }
93
- static name = B;
94
- toJSON() {
95
- const t = (() => {
96
- const o = this.cause;
97
- return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" && o !== null ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
98
- })(), { errName: e, message: r, stack: s } = this;
99
- return {
100
- errName: e,
101
- message: r,
102
- stack: s,
103
- cause: t
104
- };
105
- }
106
- }
107
- Object.defineProperty(I.prototype, Symbol.toStringTag, {
108
- value: B
109
- });
110
- const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
85
+ }), ct = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
111
86
  t < 0n && (t *= -1n);
112
87
  const e = n % t;
113
88
  return e < 0n ? e + t : e;
114
- }, N = (n, t = !1) => {
115
- if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
116
- if (n <= 0) throw Error("`length` must be positive");
89
+ }, S = (n, t = !1) => {
90
+ if (!Number.isFinite(n))
91
+ throw RangeError("`length` is not a valid number");
92
+ if (n <= 0) throw RangeError("`length` must be positive");
117
93
  const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
118
94
  let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
119
95
  return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
120
96
  }, T = (n, t) => {
121
97
  if (n >= t)
122
- throw new I("RangeError", "min is larger than max");
98
+ throw RangeError("`min` must be smaller than `max`");
123
99
  const e = t - n, r = e.toString(2).length, s = (() => {
124
100
  for (let i = 0; i < 1e5; i++) {
125
- const c = N(r);
126
- if (c >= m(2n, BigInt(r), e))
101
+ const c = S(r);
102
+ if (c >= p(2n, BigInt(r), e))
127
103
  return c % e;
128
104
  }
129
105
  throw Error("Failed to generate a random bigint");
130
106
  })();
131
107
  return n + s;
132
- }, m = (n, t, e) => {
133
- if (e < 1n) throw Error("`mod` must be positive");
134
- if (t < 0n) throw Error("`power` must not be negative");
108
+ }, p = (n, t, e) => {
109
+ if (e < 1n) throw RangeError("`mod` must be positive");
110
+ if (t < 0n) throw RangeError("`power` must not be negative");
135
111
  if (n = g(n, e), e === 1n) return 0n;
136
112
  if (n % e === 1n || n % e === 0n) return n;
137
113
  if (n === e - 1n) return t & 1n ? e - 1n : 1n;
@@ -139,7 +115,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
139
115
  for (; t > 0n; )
140
116
  t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
141
117
  return r;
142
- }, R = (n, t) => {
118
+ }, M = (n, t) => {
143
119
  if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
144
120
  if (n === 0n)
145
121
  return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
@@ -163,7 +139,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
163
139
  }
164
140
  const s = n + r | 1n, o = y(n, s), i = y(s, t);
165
141
  return o * i;
166
- }, P = (n) => {
142
+ }, A = (n) => {
167
143
  let t = 3n, e = 1n, r = 1n;
168
144
  const s = BigInt(n.toString(2).length) - 1n;
169
145
  for (let o = s - 1n; o > -1n; --o) {
@@ -171,14 +147,14 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
171
147
  r *= y(t, i), t = i, e *= r;
172
148
  }
173
149
  return e;
174
- }, ct = (n) => {
175
- if (n < 0n) throw Error("'n' must be non-negative");
150
+ }, lt = (n) => {
151
+ if (n < 0n) throw RangeError("'n' must be non-negative");
176
152
  if (n === 0n) return 1n;
177
153
  const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
178
- return P(n) << t;
179
- }, j = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), E = (n, t) => {
154
+ return A(n) << t;
155
+ }, j = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), I = (n, t) => {
180
156
  if (t < 1n || t % 2n === 0n)
181
- throw Error("`n` is invalid");
157
+ throw RangeError("`n` is out of range");
182
158
  for (; n < 0n; )
183
159
  n += t;
184
160
  n %= t;
@@ -192,7 +168,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
192
168
  [n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
193
169
  }
194
170
  return t === 1n ? e : 0n;
195
- }, _ = (n) => {
171
+ }, P = (n) => {
196
172
  if (n < 0n) return !1;
197
173
  if (n === 0n) return !0;
198
174
  let t = 1n, e = n;
@@ -201,50 +177,50 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
201
177
  r * r < n ? t = r : e = r;
202
178
  }
203
179
  return n === t ** 2n || n === (t + 1n) ** 2n;
204
- }, C = (n) => {
180
+ }, _ = (n) => {
205
181
  if (n <= 1n) return !1;
206
182
  if (n % 2n === 0n) return n === 2n;
207
183
  let t = n - 1n, e = 0n;
208
184
  for (; t % 2n === 0n; )
209
185
  t >>= 1n, e += 1n;
210
186
  const [r, s] = [t, e];
211
- let i = m(2n, r, n);
187
+ let i = p(2n, r, n);
212
188
  if (i === 1n) return !0;
213
189
  for (let c = 0n; c < s; c++) {
214
190
  if (i === n - 1n) return !0;
215
191
  i = i * i % n;
216
192
  }
217
193
  return !1;
218
- }, O = (n) => {
219
- let t = 5n, e = E(t, n);
194
+ }, C = (n) => {
195
+ let t = 5n, e = I(t, n);
220
196
  for (; e > 0n; ) {
221
- if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && _(n))
197
+ if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && P(n))
222
198
  return [0n, 0n];
223
- e = E(t, n);
199
+ e = I(t, n);
224
200
  }
225
201
  return [t, e];
226
- }, p = (n, t) => (n & 1n) === 1n ? g(n + t >> 1n, t) : g(n >> 1n, t), V = (n, t, e, r) => {
202
+ }, m = (n, t) => (n & 1n) === 1n ? g(n + t >> 1n, t) : g(n >> 1n, t), O = (n, t, e, r) => {
227
203
  let s = 1n, o = e;
228
204
  const i = n.toString(2).slice(1);
229
205
  for (const c of i)
230
- [s, o] = [g(s * o, t), p(o * o + r * s * s, t)], c === "1" && ([s, o] = [p(e * s + o, t), p(r * s + e * o, t)]);
206
+ [s, o] = [g(s * o, t), m(o * o + r * s * s, t)], c === "1" && ([s, o] = [m(e * s + o, t), m(r * s + e * o, t)]);
231
207
  return [s, o];
232
- }, F = (n, t, e, r) => {
208
+ }, V = (n, t, e, r) => {
233
209
  if (n % 2n !== 1n)
234
- throw Error("`n` must be odd");
210
+ throw RangeError("`n` must be odd");
235
211
  let s = n + 1n, o = 0n;
236
212
  for (; s % 2n === 0n; )
237
213
  s >>= 1n, o += 1n;
238
- const [i, c] = V(s, n, e, t);
214
+ const [i, c] = O(s, n, e, t);
239
215
  let l = c;
240
216
  if (i === 0n) return !0;
241
- r = m(r, s, n);
217
+ r = p(r, s, n);
242
218
  for (let u = 0n; u < o; u++) {
243
219
  if (l === 0n) return !0;
244
- l = g(l * l - 2n * r, n), r = m(r, 2n, n);
220
+ l = g(l * l - 2n * r, n), r = p(r, 2n, n);
245
221
  }
246
222
  return !1;
247
- }, U = (n) => {
223
+ }, B = (n) => {
248
224
  if (n <= 1n) return !1;
249
225
  if (n % 2n === 0n) return n === 2n;
250
226
  const t = [
@@ -278,33 +254,33 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
278
254
  for (const o of t)
279
255
  if (n % o === 0n)
280
256
  return n === o;
281
- if (!C(n))
257
+ if (!_(n))
282
258
  return !1;
283
- const [e, r] = O(n);
259
+ const [e, r] = C(n);
284
260
  if (r === 0n) return !1;
285
261
  const s = (1n - e) / 4n;
286
- return F(n, e, 1n, s);
287
- }, lt = (n, t) => {
262
+ return V(n, e, 1n, s);
263
+ }, ut = (n, t) => {
288
264
  if (t < 2n)
289
- throw Error("NoPrimesFound");
265
+ throw RangeError("`max` must be 2 or larger");
290
266
  for (let r = 0; r < 1e5; r++) {
291
267
  const s = T(n, t);
292
- if (U(s)) return s;
268
+ if (B(s)) return s;
293
269
  }
294
- throw Error("NoPrimesFound");
295
- }, ut = (n, t = !1) => {
270
+ throw Error("No primes were found");
271
+ }, at = (n, t = !1) => {
296
272
  if (n < 2)
297
- throw Error("NoPrimesFound");
273
+ throw RangeError("`bitLength` must be 2 or larger");
298
274
  for (let r = 0; r < 1e5; r++) {
299
- const s = N(n, t);
300
- if (U(s)) return s;
275
+ const s = S(n, t);
276
+ if (B(s)) return s;
301
277
  }
302
278
  throw Error("NoPrimesFound");
303
- }, v = "Rational";
279
+ }, R = "Rational";
304
280
  class a {
305
281
  #t;
306
282
  #n;
307
- static name = v;
283
+ static name = R;
308
284
  /**
309
285
  * fraction (rational) class
310
286
  * @param numerator
@@ -331,10 +307,10 @@ class a {
331
307
  t = 1 / o;
332
308
  let [i, c] = [1n, s], [l, u] = [0n, 1n];
333
309
  for (; `${u}`.length < e + 1; ) {
334
- const f = BigInt(Math.floor(t)), h = t - Number(f);
335
- if ([i, c] = [c, f * c + i], [l, u] = [u, f * u + l], h === 0)
310
+ const f = BigInt(Math.floor(t)), d = t - Number(f);
311
+ if ([i, c] = [c, f * c + i], [l, u] = [u, f * u + l], d === 0)
336
312
  return new a(r ? -c : c, u);
337
- t = 1 / h;
313
+ t = 1 / d;
338
314
  }
339
315
  return new a(r ? -i : i, l);
340
316
  }
@@ -342,7 +318,7 @@ class a {
342
318
  * reduction
343
319
  */
344
320
  #e() {
345
- const { gcd: t } = R(this.#t, this.#n);
321
+ const { gcd: t } = M(this.#t, this.#n);
346
322
  t !== 0n && (this.#t /= t, this.#n /= t);
347
323
  }
348
324
  /**
@@ -395,9 +371,9 @@ class a {
395
371
  }
396
372
  /**
397
373
  * returns mediant
398
- * @param this `a/b`
399
- * @param right `c/d`
400
- * @returns `(a+c)/(b+d)`
374
+ * @param this `a / b`
375
+ * @param right `c / d`
376
+ * @returns `(a + c) / (b + d)`
401
377
  */
402
378
  mediant(t) {
403
379
  const e = this.#n + t.#n, r = this.#t + t.#t;
@@ -451,100 +427,95 @@ class a {
451
427
  }
452
428
  }
453
429
  Object.defineProperty(a.prototype, Symbol.toStringTag, {
454
- value: v
430
+ value: R
455
431
  });
456
432
  const $ = (n) => {
457
433
  const t = Array.from(n, (e) => String.fromCharCode(e));
458
434
  return btoa(t.join(""));
459
- }, D = (n) => {
435
+ }, F = (n) => {
460
436
  const t = atob(n);
461
437
  return Uint8Array.from(t, (e) => e.charCodeAt(0));
462
- }, at = (n) => $(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), ft = (n) => {
463
- const t = n.length & 3;
464
- t > 0 && (n = n + "=".repeat(4 - t));
465
- const e = n.replaceAll("-", "+").replaceAll("_", "/");
466
- return D(e);
467
- }, ht = (n) => {
468
- let t = Array.from(n, (o) => o.toString(16).padStart(2, "0")).join("");
469
- const e = t.length % 6;
470
- e && (t = "0".repeat(6 - e) + t);
471
- const r = t.matchAll(/.{6}/g);
438
+ }, ft = (n) => $(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), ht = (n) => {
439
+ const t = 4 - (n.length & 3) & 3, e = n.concat("=".repeat(t)).replaceAll("-", "+").replaceAll("_", "/");
440
+ return F(e);
441
+ }, gt = (n) => {
442
+ const t = Array.from(n, (i) => i.toString(16).padStart(2, "0")).join(
443
+ ""
444
+ ), e = (6 - t.length % 6) % 6, s = "0".repeat(e).concat(t).matchAll(/.{6}/g);
472
445
  return Array.from(
473
- r,
474
- (o) => Number.parseInt(o[0], 16).toString(8).padStart(8, "0")
446
+ s,
447
+ (i) => Number.parseInt(i[0], 16).toString(8).padStart(8, "0")
475
448
  ).join("").replace(/^0+/, "");
476
449
  }, dt = (n) => {
477
- const t = n.length & 7;
478
- t && (n = "0".repeat(8 - t) + n);
479
- const e = n.matchAll(/.{8}/g), s = Array.from(e, (o) => {
480
- const i = o[0];
481
- return Number.parseInt(i, 8).toString(16).padStart(6, "0");
482
- }).join("").matchAll(/.{2}/g);
483
- return Uint8Array.from(s, (o) => Number.parseInt(o[0], 16));
484
- }, q = (n) => {
485
- const t = n < 0n;
486
- t && (n *= -1n);
487
- const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, s = Math.floor(e / 7) + 1;
488
- return r ? s - 1 : s;
489
- }, gt = (n) => {
490
- const t = q(n);
491
- n = BigInt.asUintN(t * 7, n);
492
- const e = new Uint8Array(t);
493
- for (let s = 0; s < t - 1; ++s) {
494
- const o = Number(n & 127n) | 128;
495
- e[s] = o, n >>= 7n;
450
+ const t = 8 - (n.length & 7) & 7, r = "0".repeat(t).concat(n).matchAll(/.{8}/g), o = Array.from(r, (i) => Number.parseInt(i[0], 8).toString(16).padStart(6, "0")).join("").matchAll(/.{2}/g);
451
+ return Uint8Array.from(o, (i) => Number.parseInt(i[0], 16));
452
+ }, N = "NamedError";
453
+ class D extends Error {
454
+ static name = N;
455
+ errName;
456
+ constructor(t, e, r) {
457
+ super(e, r), this.errName = t;
496
458
  }
497
- const r = Number(n & 127n);
498
- return e[t - 1] = r, n >>= 7n, e;
499
- }, mt = (n) => {
500
- const t = n.length;
501
- let e = 0n;
502
- for (let r = 0; r < t; ++r) {
503
- const s = BigInt(n[r] & 127);
504
- e += s << BigInt(7 * r);
459
+ toJSON() {
460
+ const t = (() => {
461
+ const o = this.cause;
462
+ if (o != null)
463
+ return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
464
+ })(), { errName: e, message: r, stack: s } = this;
465
+ return {
466
+ name: e,
467
+ message: r,
468
+ stack: s,
469
+ cause: t
470
+ };
505
471
  }
506
- return BigInt.asIntN(7 * t, e);
507
- }, b = (n) => {
472
+ }
473
+ Object.defineProperty(D.prototype, Symbol.toStringTag, {
474
+ value: N
475
+ });
476
+ const E = (n) => {
508
477
  if (n === 0n) return 64n;
509
478
  let t = 0n;
510
479
  for (; n > 0n && !(n & 1n); )
511
480
  ++t, n >>= 1n;
512
481
  return BigInt.asUintN(64, t);
482
+ }, b = (n, t) => {
483
+ const e = 0n, r = 1023n, s = n & 0x7ffn;
484
+ let o = r - 1n;
485
+ if (s > 0n)
486
+ return o -= E(s), o;
487
+ o -= 11n;
488
+ const i = 1e5;
489
+ for (let c = 0; c < i; ++c) {
490
+ const l = t();
491
+ if (l > 0n)
492
+ return o -= E(l), o;
493
+ if (o -= 64n, o < e)
494
+ return e;
495
+ }
496
+ throw Error("loop exceeded limit");
513
497
  }, pt = (n) => {
514
- const t = 0n, e = 1023n, r = () => BigInt.asUintN(64, n()), s = (i) => {
515
- const c = i & 0x7ffn;
516
- let l = e - 1n;
517
- if (c > 0n)
518
- return l -= b(c), l;
519
- l -= 11n;
520
- const u = 1e5;
521
- for (let f = 0; f < u; ++f) {
522
- const h = r();
523
- if (h > 0n)
524
- return l -= b(h), l;
525
- if (l -= 64n, l < t)
526
- return t;
527
- }
528
- throw Error("loop exceeded limit");
529
- }, o = () => {
530
- const i = r(), c = BigInt.asUintN(52, i >> 11n), u = c === 0n && i >> 63n === 1n ? s(i) + 1n : s(i), { buffer: f } = BigUint64Array.from([u << 52n | c]);
531
- return new Float64Array(f)[0];
498
+ const t = () => BigInt.asUintN(64, n()), e = () => {
499
+ const r = t(), s = BigInt.asUintN(52, r >> 11n), i = s === 0n && r >> 63n === 1n ? b(r, t) + 1n : b(r, t), { buffer: c } = BigUint64Array.from([i << 52n | s]), l = new Float64Array(c)[0];
500
+ if (l == null)
501
+ throw Error("unexpected");
502
+ return l;
532
503
  };
533
504
  return () => {
534
- for (let c = 0; c < 1e5; ++c) {
535
- const l = o();
536
- if (l < 1)
537
- return l;
505
+ for (let s = 0; s < 1e5; ++s) {
506
+ const o = e();
507
+ if (o < 1)
508
+ return o;
538
509
  }
539
510
  throw Error("Loop limit exceeded");
540
511
  };
541
- }, K = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], G = 0x5851f42d4c957f2dn, L = "PCGMinimal";
542
- class W {
512
+ }, q = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], K = 0x5851f42d4c957f2dn, U = "PCGMinimal";
513
+ class G {
543
514
  /**
544
515
  * length = 2, `[state, increment]`
545
516
  */
546
517
  #t;
547
- static name = L;
518
+ static name = U;
548
519
  /**
549
520
  * @param seeds
550
521
  * `BigUint64Array` with length 2. \
@@ -559,14 +530,23 @@ class W {
559
530
  * const betterRng = new PCGMinimal(seed);
560
531
  */
561
532
  constructor(t) {
562
- t && t.length >= 2 ? (this.#t = new BigUint64Array(2), this.#t[1] = t[1] << 1n | 1n, this.#n(), this.#t[0] += t[0], this.#n()) : this.#t = BigUint64Array.from(K);
533
+ if (t && t[0] != null && t[1] != null) {
534
+ if (this.#t = new BigUint64Array(2), this.#t[0] == null || this.#t[1] == null)
535
+ throw TypeError("unexpected");
536
+ this.#t[1] = t[1] << 1n | 1n, this.#n(), this.#t[0] += t[0], this.#n();
537
+ } else
538
+ this.#t = BigUint64Array.from(q);
563
539
  }
564
540
  /** step inner state */
565
541
  #n() {
566
- this.#t[0] = this.#t[0] * G + this.#t[1];
542
+ if (this.#t[0] == null || this.#t[1] == null)
543
+ throw TypeError("unexpected");
544
+ this.#t[0] = this.#t[0] * K + this.#t[1];
567
545
  }
568
546
  /** 32bit 乱数を返す (内部状態は変わらない) */
569
547
  get #e() {
548
+ if (this.#t[0] == null || this.#t[1] == null)
549
+ throw TypeError("unexpected");
570
550
  const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
571
551
  return j(r, e);
572
552
  }
@@ -581,9 +561,9 @@ class W {
581
561
  * @returns a random 32-bit unsigned integer less than `bound`
582
562
  */
583
563
  getBoundedRandU32(t) {
584
- if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
564
+ if (t > 4294967296) throw RangeError("`bound` exceeded limit (2^32)");
585
565
  if (t <= 0)
586
- throw Error("'bound' must be positive");
566
+ throw RangeError("'bound' must be positive");
587
567
  const r = 4294967296 % t, s = 1e5;
588
568
  for (let o = 0; o < s; ++o) {
589
569
  const i = this.getRandU32();
@@ -602,24 +582,24 @@ class W {
602
582
  */
603
583
  *genRandU32s(t, e) {
604
584
  if (t <= 0)
605
- throw Error("'step' must be positive");
585
+ throw RangeError("'step' must be positive");
606
586
  for (let r = 0; r < t; r++)
607
587
  yield typeof e == "number" ? this.getBoundedRandU32(e) : this.getRandU32();
608
588
  }
609
589
  }
610
- Object.defineProperty(W.prototype, Symbol.toStringTag, {
611
- value: L
590
+ Object.defineProperty(G.prototype, Symbol.toStringTag, {
591
+ value: U
612
592
  });
613
- const X = [
593
+ const W = [
614
594
  0xbe562cb412e2260en,
615
595
  0x2e4284137d641affn,
616
596
  0x4e19b36ee933e27en,
617
597
  0x7581cf8c4f4d4f7dn
618
- ];
619
- class S {
598
+ ], x = "XoshiroMinimal";
599
+ class X {
620
600
  bits = 64;
621
601
  #t;
622
- static name = "XoshiroMinimal";
602
+ static name = x;
623
603
  /**
624
604
  * @param seeds
625
605
  * `BigUint64Array` with length 4. \
@@ -634,13 +614,22 @@ class S {
634
614
  * const betterRng = new XoshiroMinimal(seed);
635
615
  */
636
616
  constructor(t) {
637
- t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#n(), this.#t[2] += t[2], this.#t[3] += t[3]) : this.#t = BigUint64Array.from(X);
617
+ if (t && t[0] != null && t[1] != null && t[2] != null && t[3] != null) {
618
+ if (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#n(), this.#t[2] == null || this.#t[3] == null)
619
+ throw TypeError("unexpected");
620
+ this.#t[2] += t[2], this.#t[3] += t[3];
621
+ } else
622
+ this.#t = BigUint64Array.from(W);
638
623
  }
639
624
  #n() {
625
+ if (this.#t[0] == null || this.#t[1] == null || this.#t[2] == null || this.#t[3] == null)
626
+ throw TypeError("unexpected");
640
627
  const t = this.#t[1] << 17n;
641
628
  this.#t[2] ^= this.#t[0], this.#t[3] ^= this.#t[1], this.#t[1] ^= this.#t[2], this.#t[0] ^= this.#t[3], this.#t[2] ^= t, this.#t[3] = w(this.#t[3], 45n);
642
629
  }
643
630
  get value() {
631
+ if (this.#t[0] == null || this.#t[3] == null)
632
+ throw TypeError("unexpected");
644
633
  const t = w(this.#t[0] + this.#t[3], 23n) + this.#t[0];
645
634
  return BigInt.asUintN(64, t);
646
635
  }
@@ -655,9 +644,9 @@ class S {
655
644
  getBoundedRandU64(t) {
656
645
  const e = 1n << 64n;
657
646
  if (t > e)
658
- throw Error("'bound' exceeded limit");
647
+ throw RangeError("`bound` exceeded limit");
659
648
  if (t <= 0n)
660
- throw Error("'bound' must be positive");
649
+ throw RangeError("`bound` must be positive");
661
650
  const r = e % t, s = 1e5;
662
651
  for (let o = 0; o < s; ++o) {
663
652
  const i = this.getRandU64();
@@ -668,33 +657,33 @@ class S {
668
657
  }
669
658
  getBoundedRandU32(t) {
670
659
  if (t > 4294967296)
671
- throw Error("'bound' exceeded limit");
660
+ throw RangeError("`bound` exceeded limit");
672
661
  if (t <= 0n)
673
- throw Error("'bound' must be positive");
662
+ throw RangeError("`bound` must be positive");
674
663
  const r = this.getBoundedRandU64(BigInt(t));
675
664
  return Number(r);
676
665
  }
677
666
  *genRandU64s(t, e) {
678
667
  if (t <= 0)
679
- throw Error("'step' must be positive");
668
+ throw RangeError("`step` must be positive");
680
669
  for (let r = 0; r < t; ++r)
681
670
  yield e === void 0 ? this.getRandU64() : this.getBoundedRandU64(e);
682
671
  }
683
672
  *genRandU32s(t, e) {
684
673
  if (t <= 0)
685
- throw Error("'step' must be positive");
674
+ throw RangeError("`step` must be positive");
686
675
  for (let r = 0; r < t; ++r)
687
676
  yield e === void 0 ? this.getRandU32() : this.getBoundedRandU32(e);
688
677
  }
689
678
  }
690
- Object.defineProperty(S.prototype, Symbol.toStringTag, {
691
- value: S.name
679
+ Object.defineProperty(X.prototype, Symbol.toStringTag, {
680
+ value: x
692
681
  });
693
- const A = "WorkerStream";
694
- class k extends ReadableStream {
682
+ const v = "WorkerStream";
683
+ class z extends ReadableStream {
695
684
  close;
696
685
  #t;
697
- static name = A;
686
+ static name = v;
698
687
  constructor(t, e) {
699
688
  let r, s, o;
700
689
  super(
@@ -703,69 +692,89 @@ class k extends ReadableStream {
703
692
  r = (c) => {
704
693
  i.enqueue(c.data);
705
694
  }, s = (c) => {
706
- t.removeEventListener("message", r), t.removeEventListener("error", s);
707
- const l = new I("WorkerStreamError", c.message, {
708
- cause: c.error
709
- });
710
- i.error(l);
695
+ t.removeEventListener("message", r), t.removeEventListener("error", s), i.error(Error(c.message, { cause: c.error }));
711
696
  }, o = () => {
712
697
  t.removeEventListener("message", r), t.removeEventListener("error", s), i.close();
713
698
  }, t.addEventListener("message", r), t.addEventListener("error", s);
714
699
  },
715
- cancel: (i) => {
716
- console.log("Canceled reason:", i), t.removeEventListener("message", r), t.removeEventListener("error", s);
700
+ cancel: () => {
701
+ t.removeEventListener("message", r), t.removeEventListener("error", s);
717
702
  }
718
703
  },
719
704
  e
720
705
  ), this.close = o, this.#t = t;
721
706
  }
722
- postMessage(t, e) {
707
+ postMessage = (t, e) => {
723
708
  this.#t.postMessage(t, e);
724
- }
709
+ };
725
710
  }
726
- Object.defineProperty(k.prototype, Symbol.toStringTag, {
727
- value: A
711
+ Object.defineProperty(z.prototype, Symbol.toStringTag, {
712
+ value: v
728
713
  });
714
+ const H = (n) => {
715
+ const t = n < 0n;
716
+ t && (n *= -1n);
717
+ const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, s = Math.floor(e / 7) + 1;
718
+ return r ? s - 1 : s;
719
+ }, mt = (n) => {
720
+ const t = H(n);
721
+ n = BigInt.asUintN(t * 7, n);
722
+ const e = new Uint8Array(t);
723
+ for (let s = 0; s < t - 1; ++s) {
724
+ const o = Number(n & 127n) | 128;
725
+ e[s] = o, n >>= 7n;
726
+ }
727
+ const r = Number(n & 127n);
728
+ return e[t - 1] = r, n >>= 7n, e;
729
+ }, yt = (n) => {
730
+ const t = n.length;
731
+ let e = 0n;
732
+ for (const [r, s] of n.entries()) {
733
+ const o = BigInt(s & 127);
734
+ e += o << BigInt(7 * r);
735
+ }
736
+ return BigInt.asIntN(7 * t, e);
737
+ };
729
738
  export {
730
- I as NamedError,
731
- W as PCGMinimal,
739
+ D as NamedError,
740
+ G as PCGMinimal,
732
741
  a as Rational,
733
- k as WorkerStream,
734
- S as XoshiroMinimal,
735
- U as bailliePSW,
736
- rt as compress,
737
- mt as decodeLEB128,
738
- et as decodeRFC3986URIComponent,
739
- st as decompress,
740
- gt as encodeLEB128,
741
- nt as encodeRFC3986URIComponent,
742
- R as exEuclidean,
743
- ct as factorial,
742
+ z as WorkerStream,
743
+ X as XoshiroMinimal,
744
+ B as bailliePSW,
745
+ st as compress,
746
+ yt as decodeLEB128,
747
+ rt as decodeRFC3986URIComponent,
748
+ ot as decompress,
749
+ mt as encodeLEB128,
750
+ et as encodeRFC3986URIComponent,
751
+ M as exEuclidean,
752
+ lt as factorial,
744
753
  pt as floatRng,
745
- D as fromBase64,
746
- ft as fromBase64Url,
754
+ F as fromBase64,
755
+ ht as fromBase64Url,
747
756
  dt as fromOct,
748
- tt as getHash,
749
- N as getRandBIByBitLength,
757
+ nt as getHash,
758
+ S as getRandBIByBitLength,
750
759
  T as getRandBIByRange,
751
- ut as getRandPrimeByBitLength,
752
- lt as getRandPrimeByRange,
753
- it as getRndInt,
754
- Y as getStringTag,
755
- d as isDeepStrictEqual,
756
- _ as isSquare,
757
- E as jacobiSymbol,
758
- Z as lazify,
759
- m as modPow,
760
- Q as parseCSV,
760
+ at as getRandPrimeByBitLength,
761
+ ut as getRandPrimeByRange,
762
+ ct as getRndInt,
763
+ Z as getStringTag,
764
+ h as isDeepStrictEqual,
765
+ P as isSquare,
766
+ I as jacobiSymbol,
767
+ Q as lazify,
768
+ p as modPow,
769
+ tt as parseCSV,
761
770
  g as residue,
762
771
  j as rot32,
763
772
  w as rot64,
764
- z as sameValueZero,
765
- ot as setTimeoutPromise,
766
- J as sleep,
773
+ J as sameValueZero,
774
+ it as setTimeoutPromise,
775
+ k as sleep,
767
776
  $ as toBase64,
768
- at as toBase64Url,
769
- ht as toOct,
770
- H as withResolvers
777
+ ft as toBase64Url,
778
+ gt as toOct,
779
+ Y as withResolvers
771
780
  };
@@ -1,2 +1,2 @@
1
- var UtilFns=(function(a){"use strict";const V=new TextEncoder,$=(n,t)=>[n].includes(t),g=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;s++)if(!g(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],o=[...t.values()];return!!g(s,o)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],o=[...t.keys()];if(!g(s,o))return!1;const i=[...n.values()],c=[...t.values()];return!!g(i,c)}if(e==="[object Object]"){const s=n,o=t,i=Object.keys(s),c=Object.keys(o);for(const l of i){const u=c.find(pt=>pt===l);if(u===void 0)return!1;const[h,d]=[s[l],o[u]];if(!g(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},D=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},q=n=>new Promise(t=>{setTimeout(()=>t(),n)}),K=n=>{const t=Object.prototype.toString.call(n);return t.slice(8,t.length-1)},W=n=>(...t)=>()=>n(...t),G=n=>{const t=[];let e=[],r="",s=!1;for(let o=0;o<n.length;o++){const i=n[o];i==='"'&&(o===0||n[o-1]!=="\\")?s=!s:i===","&&!s?(e.push(r.trim()),r=""):i===`
2
- `&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=i}return e.push(r.trim()),t.push(e),t},X=async(n,t)=>{const e=V.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},k=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),z=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},H=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},J=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},Y=(n,t)=>new Promise((e,r)=>{setTimeout(async()=>{try{const s=await n();e(s)}catch(s){r(s)}},t)}),N="NamedError";class p extends Error{constructor(t,e,r){super(e,r),this.errName=t}static name=N;toJSON(){const t=(()=>{const o=this.cause;return typeof o=="string"||typeof o=="number"||typeof o=="boolean"?o:typeof o=="bigint"?o.toString():typeof o=="object"&&o!==null?o instanceof Set||o instanceof Map?Object.fromEntries(o):o:void 0})(),{errName:e,message:r,stack:s}=this;return{errName:e,message:r,stack:s,cause:t}}}Object.defineProperty(p.prototype,Symbol.toStringTag,{value:N});const Z=(n,t)=>Math.floor(Math.random()*(t-n)+n),m=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},I=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let s=Array.from(r,o=>o.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},v=(n,t)=>{if(n>=t)throw new p("RangeError","min is larger than max");const e=t-n,r=e.toString(2).length,s=(()=>{for(let i=0;i<1e5;i++){const c=I(r);if(c>=y(2n,BigInt(r),e))return c%e}throw Error("Failed to generate a random bigint")})();return n+s},y=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=m(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},R=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,s]=[1n,0n,n],[o,i,c]=[0n,-1n,t];for(;;){const l=s/c,u=s-l*c;if(u===0n)break;[e,o]=[o,e-l*o],[r,i]=[i,r-l*i],[s,c]=[c,u]}return c<0n&&(o*=-1n,i*=-1n,c*=-1n),{x:o,y:i,gcd:c}},w=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let c=n;for(let l=n+2n;l<t;l+=2n)c*=l;return c}const s=n+r|1n,o=w(n,s),i=w(s,t);return o*i},Q=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let o=s-1n;o>-1n;--o){const i=(n>>o)+1n|1n;r*=w(t,i),t=i,e*=r}return e},x=n=>{if(n<0n)throw Error("'n' must be non-negative");if(n===0n)return 1n;const t=n-BigInt(n.toString(2).match(/1/g)?.length??0);return Q(n)<<t},L=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,B=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),E=(n,t)=>{if(t<1n||t%2n===0n)throw Error("`n` is invalid");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},M=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r*r<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},tt=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,s]=[t,e];let i=y(2n,r,n);if(i===1n)return!0;for(let c=0n;c<s;c++){if(i===n-1n)return!0;i=i*i%n}return!1},nt=n=>{let t=5n,e=E(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&M(n))return[0n,0n];e=E(t,n)}return[t,e]},b=(n,t)=>(n&1n)===1n?m(n+t>>1n,t):m(n>>1n,t),et=(n,t,e,r)=>{let s=1n,o=e;const i=n.toString(2).slice(1);for(const c of i)[s,o]=[m(s*o,t),b(o*o+r*s*s,t)],c==="1"&&([s,o]=[b(e*s+o,t),b(r*s+e*o,t)]);return[s,o]},rt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,o=0n;for(;s%2n===0n;)s>>=1n,o+=1n;const[i,c]=et(s,n,e,t);let l=c;if(i===0n)return!0;r=y(r,s,n);for(let u=0n;u<o;u++){if(l===0n)return!0;l=m(l*l-2n*r,n),r=y(r,2n,n)}return!1},S=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const o of t)if(n%o===0n)return n===o;if(!tt(n))return!1;const[e,r]=nt(n);if(r===0n)return!1;const s=(1n-e)/4n;return rt(n,e,1n,s)},st=(n,t)=>{if(t<2n)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=v(n,t);if(S(s))return s}throw Error("NoPrimesFound")},ot=(n,t=!1)=>{if(n<2)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=I(n,t);if(S(s))return s}throw Error("NoPrimesFound")},A="Rational";class f{#t;#n;static name=A;constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const s=BigInt(Math.floor(t)),o=t-Number(s);if(o===0)return new f(r?-s:s,1n);t=1/o;let[i,c]=[1n,s],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([i,c]=[c,h*c+i],[l,u]=[u,h*u+l],d===0)return new f(r?-c:c,u);t=1/d}return new f(r?-i:i,l)}#e(){const{gcd:t}=R(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new f(-this.#t,this.#n)}inverse(){return new f(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new f(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new f(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new f(r,e)}toDecimal(){return Number(this.#t)/Number(this.#n)}toString(){return this.#t===0n&&this.#n===0n?"NaN":this.#t===0n?"0":this.#n===0n?this.#t<0n?"-Infinity":"Infinity":this.#n===1n?`${this.#t}`:`${this.#t}/${this.#n}`}valueOf(){return this.toDecimal()}toJSON(){return{type:"Rational",value:["0x"+this.#t.toString(16),"0x"+this.#n.toString(16)]}}static fromData(t){const e=BigInt(t.value[0]),r=BigInt(t.value[1]);return new f(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const s=r.at(1),o=r.at(2);if(!s||!o)throw Error("cannot parse");return new f(BigInt(s),BigInt(o))}}Object.defineProperty(f.prototype,Symbol.toStringTag,{value:A});const T=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},P=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},it=n=>T(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),ct=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return P(e)},at=n=>{let t=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const e=t.length%6;e&&(t="0".repeat(6-e)+t);const r=t.matchAll(/.{6}/g);return Array.from(r,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},lt=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),s=Array.from(e,o=>{const i=o[0];return Number.parseInt(i,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,o=>Number.parseInt(o[0],16))},ut=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,s=Math.floor(e/7)+1;return r?s-1:s},ft=n=>{const t=ut(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const o=Number(n&127n)|128;e[s]=o,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},ht=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const s=BigInt(n[r]&127);e+=s<<BigInt(7*r)}return BigInt.asIntN(7*t,e)},C=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)},dt=n=>{const t=0n,e=1023n,r=()=>BigInt.asUintN(64,n()),s=i=>{const c=i&0x7ffn;let l=e-1n;if(c>0n)return l-=C(c),l;l-=11n;const u=1e5;for(let h=0;h<u;++h){const d=r();if(d>0n)return l-=C(d),l;if(l-=64n,l<t)return t}throw Error("loop exceeded limit")},o=()=>{const i=r(),c=BigInt.asUintN(52,i>>11n),u=c===0n&&i>>63n===1n?s(i)+1n:s(i),{buffer:h}=BigUint64Array.from([u<<52n|c]);return new Float64Array(h)[0]};return()=>{for(let c=0;c<1e5;++c){const l=o();if(l<1)return l}throw Error("Loop limit exceeded")}},gt=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],mt=0x5851f42d4c957f2dn,j="PCGMinimal";class _{#t;static name=j;constructor(t){t&&t.length>=2?(this.#t=new BigUint64Array(2),this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]+=t[0],this.#n()):this.#t=BigUint64Array.from(gt)}#n(){this.#t[0]=this.#t[0]*mt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return L(r,e)}getRandU32(){return this.#n(),this.#e}getBoundedRandU32(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,s=1e5;for(let o=0;o<s;++o){const i=this.getRandU32();if(i>=r)return i%t}throw Error("exceeded loop limit")}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedRandU32(e):this.getRandU32()}}Object.defineProperty(_.prototype,Symbol.toStringTag,{value:j});const yt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class U{bits=64;#t;static name="XoshiroMinimal";constructor(t){t&&t.length>=4?(this.#t=new BigUint64Array(4),this.#t[0]=t[0],this.#t[1]=t[1],this.#n(),this.#t[2]+=t[2],this.#t[3]+=t[3]):this.#t=BigUint64Array.from(yt)}#n(){const t=this.#t[1]<<17n;this.#t[2]^=this.#t[0],this.#t[3]^=this.#t[1],this.#t[1]^=this.#t[2],this.#t[0]^=this.#t[3],this.#t[2]^=t,this.#t[3]=B(this.#t[3],45n)}get value(){const t=B(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}getRandU64(){const t=this.value;return this.#n(),t}getRandU32(){const t=BigInt.asUintN(32,this.getRandU64());return Number(t)}getBoundedRandU64(t){const e=1n<<64n;if(t>e)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=e%t,s=1e5;for(let o=0;o<s;++o){const i=this.getRandU64();if(i>=r)return i%t}throw Error("exceeded loop limit")}getBoundedRandU32(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedRandU64(BigInt(t));return Number(r)}*genRandU64s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU64():this.getBoundedRandU64(e)}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU32():this.getBoundedRandU32(e)}}Object.defineProperty(U.prototype,Symbol.toStringTag,{value:U.name});const O="WorkerStream";class F extends ReadableStream{close;#t;static name=O;constructor(t,e){let r,s,o;super({start:i=>{r=c=>{i.enqueue(c.data)},s=c=>{t.removeEventListener("message",r),t.removeEventListener("error",s);const l=new p("WorkerStreamError",c.message,{cause:c.error});i.error(l)},o=()=>{t.removeEventListener("message",r),t.removeEventListener("error",s),i.close()},t.addEventListener("message",r),t.addEventListener("error",s)},cancel:i=>{console.log("Canceled reason:",i),t.removeEventListener("message",r),t.removeEventListener("error",s)}},e),this.close=o,this.#t=t}postMessage(t,e){this.#t.postMessage(t,e)}}return Object.defineProperty(F.prototype,Symbol.toStringTag,{value:O}),a.NamedError=p,a.PCGMinimal=_,a.Rational=f,a.WorkerStream=F,a.XoshiroMinimal=U,a.bailliePSW=S,a.compress=H,a.decodeLEB128=ht,a.decodeRFC3986URIComponent=z,a.decompress=J,a.encodeLEB128=ft,a.encodeRFC3986URIComponent=k,a.exEuclidean=R,a.factorial=x,a.floatRng=dt,a.fromBase64=P,a.fromBase64Url=ct,a.fromOct=lt,a.getHash=X,a.getRandBIByBitLength=I,a.getRandBIByRange=v,a.getRandPrimeByBitLength=ot,a.getRandPrimeByRange=st,a.getRndInt=Z,a.getStringTag=K,a.isDeepStrictEqual=g,a.isSquare=M,a.jacobiSymbol=E,a.lazify=W,a.modPow=y,a.parseCSV=G,a.residue=m,a.rot32=L,a.rot64=B,a.sameValueZero=$,a.setTimeoutPromise=Y,a.sleep=q,a.toBase64=T,a.toBase64Url=it,a.toOct=at,a.withResolvers=D,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),a})({});
1
+ var UtilFns=(function(c){"use strict";const D=(n,t)=>[n].includes(t),h=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;s++)if(!h(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],o=[...t.values()];return!!h(s,o)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],o=[...t.keys()];if(!h(s,o))return!1;const i=[...n.values()],l=[...t.values()];return!!h(i,l)}if(e==="[object Object]"){const s=n,o=t,i=Object.keys(s),l=Object.keys(o);for(const a of i){const f=l.find(It=>It===a);if(f===void 0)return!1;const[m,y]=[s[a],o[f]];if(!h(m,y))return!1}return!0}throw TypeError(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},q=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},K=n=>new Promise(t=>{setTimeout(t,n)}),G=n=>Object.prototype.toString.call(n).slice(8,-1),W=n=>(...t)=>()=>n(...t),X=n=>{const t=[];let e=[],r="",s=!1;for(let o=0;o<n.length;o++){const i=n[o];i==='"'&&(o===0||n[o-1]!=="\\")?s=!s:i===","&&!s?(e.push(r.trim()),r=""):i===`
2
+ `&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=i}return e.push(r.trim()),t.push(e),t},x=async(n,t)=>{const e=new TextEncoder().encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},z=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),H=n=>{if(n.includes("+"))throw URIError("an input string must not include `+`");return decodeURIComponent(n)},k=(n,t)=>{const e=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(e).bytes()},J=(n,t)=>{const e=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(e).bytes()},Y=(n,t)=>new Promise((e,r)=>{setTimeout(async()=>{try{const s=await n();e(s)}catch(s){r(s)}},t)}),Z=(n,t)=>Math.floor(Math.random()*(t-n)+n),g=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},p=(n,t=!1)=>{if(!Number.isFinite(n))throw RangeError("`length` is not a valid number");if(n<=0)throw RangeError("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let s=Array.from(r,o=>o.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},R=(n,t)=>{if(n>=t)throw RangeError("`min` must be smaller than `max`");const e=t-n,r=e.toString(2).length,s=(()=>{for(let i=0;i<1e5;i++){const l=p(r);if(l>=d(2n,BigInt(r),e))return l%e}throw Error("Failed to generate a random bigint")})();return n+s},d=(n,t,e)=>{if(e<1n)throw RangeError("`mod` must be positive");if(t<0n)throw RangeError("`power` must not be negative");if(n=g(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},S=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,s]=[1n,0n,n],[o,i,l]=[0n,-1n,t];for(;;){const a=s/l,f=s-a*l;if(f===0n)break;[e,o]=[o,e-a*o],[r,i]=[i,r-a*i],[s,l]=[l,f]}return l<0n&&(o*=-1n,i*=-1n,l*=-1n),{x:o,y:i,gcd:l}},I=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let l=n;for(let a=n+2n;a<t;a+=2n)l*=a;return l}const s=n+r|1n,o=I(n,s),i=I(s,t);return o*i},Q=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let o=s-1n;o>-1n;--o){const i=(n>>o)+1n|1n;r*=I(t,i),t=i,e*=r}return e},tt=n=>{if(n<0n)throw RangeError("'n' must be non-negative");if(n===0n)return 1n;const t=n-BigInt(n.toString(2).match(/1/g)?.length??0);return Q(n)<<t},U=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,w=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),E=(n,t)=>{if(t<1n||t%2n===0n)throw RangeError("`n` is out of range");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},N=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r*r<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},nt=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,s]=[t,e];let i=d(2n,r,n);if(i===1n)return!0;for(let l=0n;l<s;l++){if(i===n-1n)return!0;i=i*i%n}return!1},et=n=>{let t=5n,e=E(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&N(n))return[0n,0n];e=E(t,n)}return[t,e]},b=(n,t)=>(n&1n)===1n?g(n+t>>1n,t):g(n>>1n,t),rt=(n,t,e,r)=>{let s=1n,o=e;const i=n.toString(2).slice(1);for(const l of i)[s,o]=[g(s*o,t),b(o*o+r*s*s,t)],l==="1"&&([s,o]=[b(e*s+o,t),b(r*s+e*o,t)]);return[s,o]},st=(n,t,e,r)=>{if(n%2n!==1n)throw RangeError("`n` must be odd");let s=n+1n,o=0n;for(;s%2n===0n;)s>>=1n,o+=1n;const[i,l]=rt(s,n,e,t);let a=l;if(i===0n)return!0;r=d(r,s,n);for(let f=0n;f<o;f++){if(a===0n)return!0;a=g(a*a-2n*r,n),r=d(r,2n,n)}return!1},B=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const o of t)if(n%o===0n)return n===o;if(!nt(n))return!1;const[e,r]=et(n);if(r===0n)return!1;const s=(1n-e)/4n;return st(n,e,1n,s)},ot=(n,t)=>{if(t<2n)throw RangeError("`max` must be 2 or larger");for(let r=0;r<1e5;r++){const s=R(n,t);if(B(s))return s}throw Error("No primes were found")},it=(n,t=!1)=>{if(n<2)throw RangeError("`bitLength` must be 2 or larger");for(let r=0;r<1e5;r++){const s=p(n,t);if(B(s))return s}throw Error("NoPrimesFound")},v="Rational";class u{#t;#n;static name=v;constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new u(0n,0n);if(Math.abs(t)===1/0)return new u(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const s=BigInt(Math.floor(t)),o=t-Number(s);if(o===0)return new u(r?-s:s,1n);t=1/o;let[i,l]=[1n,s],[a,f]=[0n,1n];for(;`${f}`.length<e+1;){const m=BigInt(Math.floor(t)),y=t-Number(m);if([i,l]=[l,m*l+i],[a,f]=[f,m*f+a],y===0)return new u(r?-l:l,f);t=1/y}return new u(r?-i:i,a)}#e(){const{gcd:t}=S(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new u(-this.#t,this.#n)}inverse(){return new u(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new u(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new u(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new u(r,e)}toDecimal(){return Number(this.#t)/Number(this.#n)}toString(){return this.#t===0n&&this.#n===0n?"NaN":this.#t===0n?"0":this.#n===0n?this.#t<0n?"-Infinity":"Infinity":this.#n===1n?`${this.#t}`:`${this.#t}/${this.#n}`}valueOf(){return this.toDecimal()}toJSON(){return{type:"Rational",value:["0x"+this.#t.toString(16),"0x"+this.#n.toString(16)]}}static fromData(t){const e=BigInt(t.value[0]),r=BigInt(t.value[1]);return new u(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const s=r.at(1),o=r.at(2);if(!s||!o)throw Error("cannot parse");return new u(BigInt(s),BigInt(o))}}Object.defineProperty(u.prototype,Symbol.toStringTag,{value:v});const L=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},T=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},ct=n=>L(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),lt=n=>{const t=4-(n.length&3)&3,e=n.concat("=".repeat(t)).replaceAll("-","+").replaceAll("_","/");return T(e)},at=n=>{const t=Array.from(n,i=>i.toString(16).padStart(2,"0")).join(""),e=(6-t.length%6)%6,s="0".repeat(e).concat(t).matchAll(/.{6}/g);return Array.from(s,i=>Number.parseInt(i[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},ut=n=>{const t=8-(n.length&7)&7,r="0".repeat(t).concat(n).matchAll(/.{8}/g),o=Array.from(r,i=>Number.parseInt(i[0],8).toString(16).padStart(6,"0")).join("").matchAll(/.{2}/g);return Uint8Array.from(o,i=>Number.parseInt(i[0],16))},M="NamedError";class A extends Error{static name=M;errName;constructor(t,e,r){super(e,r),this.errName=t}toJSON(){const t=(()=>{const o=this.cause;if(o!=null)return typeof o=="string"||typeof o=="number"||typeof o=="boolean"?o:typeof o=="bigint"?o.toString():typeof o=="object"?o instanceof Set||o instanceof Map?Object.fromEntries(o):o:void 0})(),{errName:e,message:r,stack:s}=this;return{name:e,message:r,stack:s,cause:t}}}Object.defineProperty(A.prototype,Symbol.toStringTag,{value:M});const P=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)},C=(n,t)=>{const e=0n,r=1023n,s=n&0x7ffn;let o=r-1n;if(s>0n)return o-=P(s),o;o-=11n;const i=1e5;for(let l=0;l<i;++l){const a=t();if(a>0n)return o-=P(a),o;if(o-=64n,o<e)return e}throw Error("loop exceeded limit")},ft=n=>{const t=()=>BigInt.asUintN(64,n()),e=()=>{const r=t(),s=BigInt.asUintN(52,r>>11n),i=s===0n&&r>>63n===1n?C(r,t)+1n:C(r,t),{buffer:l}=BigUint64Array.from([i<<52n|s]),a=new Float64Array(l)[0];if(a==null)throw Error("unexpected");return a};return()=>{for(let s=0;s<1e5;++s){const o=e();if(o<1)return o}throw Error("Loop limit exceeded")}},ht=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],gt=0x5851f42d4c957f2dn,j="PCGMinimal";class O{#t;static name=j;constructor(t){if(t&&t[0]!=null&&t[1]!=null){if(this.#t=new BigUint64Array(2),this.#t[0]==null||this.#t[1]==null)throw TypeError("unexpected");this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]+=t[0],this.#n()}else this.#t=BigUint64Array.from(ht)}#n(){if(this.#t[0]==null||this.#t[1]==null)throw TypeError("unexpected");this.#t[0]=this.#t[0]*gt+this.#t[1]}get#e(){if(this.#t[0]==null||this.#t[1]==null)throw TypeError("unexpected");const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return U(r,e)}getRandU32(){return this.#n(),this.#e}getBoundedRandU32(t){if(t>4294967296)throw RangeError("`bound` exceeded limit (2^32)");if(t<=0)throw RangeError("'bound' must be positive");const r=4294967296%t,s=1e5;for(let o=0;o<s;++o){const i=this.getRandU32();if(i>=r)return i%t}throw Error("exceeded loop limit")}*genRandU32s(t,e){if(t<=0)throw RangeError("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedRandU32(e):this.getRandU32()}}Object.defineProperty(O.prototype,Symbol.toStringTag,{value:j});const dt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn],_="XoshiroMinimal";class V{bits=64;#t;static name=_;constructor(t){if(t&&t[0]!=null&&t[1]!=null&&t[2]!=null&&t[3]!=null){if(this.#t=new BigUint64Array(4),this.#t[0]=t[0],this.#t[1]=t[1],this.#n(),this.#t[2]==null||this.#t[3]==null)throw TypeError("unexpected");this.#t[2]+=t[2],this.#t[3]+=t[3]}else this.#t=BigUint64Array.from(dt)}#n(){if(this.#t[0]==null||this.#t[1]==null||this.#t[2]==null||this.#t[3]==null)throw TypeError("unexpected");const t=this.#t[1]<<17n;this.#t[2]^=this.#t[0],this.#t[3]^=this.#t[1],this.#t[1]^=this.#t[2],this.#t[0]^=this.#t[3],this.#t[2]^=t,this.#t[3]=w(this.#t[3],45n)}get value(){if(this.#t[0]==null||this.#t[3]==null)throw TypeError("unexpected");const t=w(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}getRandU64(){const t=this.value;return this.#n(),t}getRandU32(){const t=BigInt.asUintN(32,this.getRandU64());return Number(t)}getBoundedRandU64(t){const e=1n<<64n;if(t>e)throw RangeError("`bound` exceeded limit");if(t<=0n)throw RangeError("`bound` must be positive");const r=e%t,s=1e5;for(let o=0;o<s;++o){const i=this.getRandU64();if(i>=r)return i%t}throw Error("exceeded loop limit")}getBoundedRandU32(t){if(t>4294967296)throw RangeError("`bound` exceeded limit");if(t<=0n)throw RangeError("`bound` must be positive");const r=this.getBoundedRandU64(BigInt(t));return Number(r)}*genRandU64s(t,e){if(t<=0)throw RangeError("`step` must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU64():this.getBoundedRandU64(e)}*genRandU32s(t,e){if(t<=0)throw RangeError("`step` must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU32():this.getBoundedRandU32(e)}}Object.defineProperty(V.prototype,Symbol.toStringTag,{value:_});const $="WorkerStream";class F extends ReadableStream{close;#t;static name=$;constructor(t,e){let r,s,o;super({start:i=>{r=l=>{i.enqueue(l.data)},s=l=>{t.removeEventListener("message",r),t.removeEventListener("error",s),i.error(Error(l.message,{cause:l.error}))},o=()=>{t.removeEventListener("message",r),t.removeEventListener("error",s),i.close()},t.addEventListener("message",r),t.addEventListener("error",s)},cancel:()=>{t.removeEventListener("message",r),t.removeEventListener("error",s)}},e),this.close=o,this.#t=t}postMessage=(t,e)=>{this.#t.postMessage(t,e)}}Object.defineProperty(F.prototype,Symbol.toStringTag,{value:$});const mt=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,s=Math.floor(e/7)+1;return r?s-1:s},yt=n=>{const t=mt(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const o=Number(n&127n)|128;e[s]=o,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},pt=n=>{const t=n.length;let e=0n;for(const[r,s]of n.entries()){const o=BigInt(s&127);e+=o<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};return c.NamedError=A,c.PCGMinimal=O,c.Rational=u,c.WorkerStream=F,c.XoshiroMinimal=V,c.bailliePSW=B,c.compress=k,c.decodeLEB128=pt,c.decodeRFC3986URIComponent=H,c.decompress=J,c.encodeLEB128=yt,c.encodeRFC3986URIComponent=z,c.exEuclidean=S,c.factorial=tt,c.floatRng=ft,c.fromBase64=T,c.fromBase64Url=lt,c.fromOct=ut,c.getHash=x,c.getRandBIByBitLength=p,c.getRandBIByRange=R,c.getRandPrimeByBitLength=it,c.getRandPrimeByRange=ot,c.getRndInt=Z,c.getStringTag=G,c.isDeepStrictEqual=h,c.isSquare=N,c.jacobiSymbol=E,c.lazify=W,c.modPow=d,c.parseCSV=X,c.residue=g,c.rot32=U,c.rot64=w,c.sameValueZero=D,c.setTimeoutPromise=Y,c.sleep=K,c.toBase64=L,c.toBase64Url=ct,c.toOct=at,c.withResolvers=q,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
@@ -1,8 +1,8 @@
1
- export type RationalData = {
1
+ export interface RationalData {
2
2
  type: 'Rational';
3
3
  /** `[numerator, denominator]` */
4
4
  value: [string, string];
5
- };
5
+ }
6
6
  export declare class Rational {
7
7
  #private;
8
8
  static readonly name = "Rational";
@@ -54,9 +54,9 @@ export declare class Rational {
54
54
  divide(right: Rational): Rational;
55
55
  /**
56
56
  * returns mediant
57
- * @param this `a/b`
58
- * @param right `c/d`
59
- * @returns `(a+c)/(b+d)`
57
+ * @param this `a / b`
58
+ * @param right `c / d`
59
+ * @returns `(a + c) / (b + d)`
60
60
  */
61
61
  mediant(right: Rational): Rational;
62
62
  /**
@@ -0,0 +1,2 @@
1
+ export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
2
+ export declare const decodeLEB128: (leb128: Uint8Array<ArrayBuffer>) => bigint;
package/dist/main.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './random';
8
8
  export * from './pcg_minimal';
9
9
  export * from './xoshiro_minimal';
10
10
  export * from './worker_stream';
11
+ export * from './leb128';
package/dist/math.d.ts CHANGED
@@ -51,8 +51,8 @@ export declare const exEuclidean: (a: bigint, b: bigint) => {
51
51
  /**
52
52
  * returns factorial of an input \
53
53
  * ref: https://qiita.com/AkariLuminous/items/1b2e964ebabde9419224
54
- * @param n 整数
55
- * @returns 引数の階乗
54
+ * @param n integer
55
+ * @returns factorial of `n`
56
56
  */
57
57
  export declare const factorial: (n: bigint) => bigint;
58
58
  /**
@@ -4,11 +4,11 @@ interface NamedError<EName extends string> {
4
4
  readonly cause?: unknown;
5
5
  }
6
6
  declare class NamedError<EName extends string> extends Error {
7
- readonly errName: EName;
8
7
  static readonly name = "NamedError";
8
+ readonly errName: EName;
9
9
  constructor(errName: EName, message: string, options?: ErrorOptions);
10
10
  toJSON(): {
11
- errName: EName;
11
+ name: EName;
12
12
  message: string;
13
13
  stack: string | undefined;
14
14
  cause: string | number | boolean | object | undefined;
@@ -4,5 +4,3 @@ export declare const toBase64Url: (bin: Uint8Array) => string;
4
4
  export declare const fromBase64Url: (base64Url: string) => Uint8Array<ArrayBuffer>;
5
5
  export declare const toOct: (bin: Uint8Array) => string;
6
6
  export declare const fromOct: (oct: string) => Uint8Array<ArrayBuffer>;
7
- export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
8
- export declare const decodeLEB128: (leb128: Uint8Array<ArrayBuffer>) => bigint;
@@ -3,5 +3,5 @@ export declare class WorkerStream<TPost = unknown, TRecv = unknown> extends Read
3
3
  readonly close: () => void;
4
4
  static readonly name = "WorkerStream";
5
5
  constructor(worker: Worker, strategy?: CountQueuingStrategy);
6
- postMessage(message: TPost, options?: StructuredSerializeOptions): void;
6
+ postMessage: (message: TPost, options?: StructuredSerializeOptions) => void;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
@@ -17,8 +17,8 @@
17
17
  "import": "./dist/bundle.js"
18
18
  },
19
19
  "engines": {
20
- "node": "^22",
21
- "pnpm": "^10"
20
+ "node": ">=22",
21
+ "pnpm": ">=10"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -26,15 +26,16 @@
26
26
  },
27
27
  "homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
28
28
  "devDependencies": {
29
- "@types/node": "^25.0.3",
29
+ "@types/node": "^25.5.0",
30
30
  "tsx": "^4.21.0",
31
31
  "typescript": "^5.9.3",
32
- "vite": "^7.3.0",
33
- "vite-plugin-dts": "^4.5.4",
34
- "vitest": "^4.0.16"
32
+ "unplugin-dts": "1.0.0-beta.6",
33
+ "vite": "^7.3.1",
34
+ "vitest": "^4.1.0"
35
35
  },
36
36
  "volta": {
37
- "node": "22.21.0"
37
+ "node": "24.13.0",
38
+ "pnpm": "10.28.0"
38
39
  },
39
40
  "scripts": {
40
41
  "dev": "vite",