@tktb-tess/util-fns 0.9.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,7 +30,7 @@ You can also use it via CDN such as jsDelivr.
30
30
 
31
31
  ```html
32
32
  <!-- You can import it as a global variable -->
33
- <script src="https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.9.3/dist/bundle.min.js"></script>
33
+ <script src="https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.10.0/dist/bundle.min.js"></script>
34
34
  <script type="module">
35
35
  const { modPow } = UtilFns;
36
36
  // ...
@@ -38,7 +38,7 @@ You can also use it via CDN such as jsDelivr.
38
38
 
39
39
  <!-- or as an ES Module -->
40
40
  <script type="module">
41
- import { modPow } from 'https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.9.3/+esm';
41
+ import { modPow } from 'https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.10.0/+esm';
42
42
  // ...
43
43
  </script>
44
44
  ```
package/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
1
+ const L = new TextEncoder(), X = (n, t) => [n].includes(t), g = (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;
@@ -10,55 +10,55 @@ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
10
10
  return !1;
11
11
  if (Array.isArray(n) && Array.isArray(t)) {
12
12
  if (n.length !== t.length) return !1;
13
- for (let s = 0; s < n.length; s++)
14
- if (!g(n[s], t[s])) return !1;
13
+ for (let o = 0; o < n.length; o++)
14
+ if (!g(n[o], t[o])) return !1;
15
15
  return !0;
16
16
  }
17
17
  if (n instanceof Set && t instanceof Set) {
18
- const s = [...n.values()], o = [...t.values()];
19
- return !!g(s, o);
18
+ const o = [...n.values()], s = [...t.values()];
19
+ return !!g(o, s);
20
20
  }
21
21
  if (n instanceof Map && t instanceof Map) {
22
- const s = [...n.keys()], o = [...t.keys()];
23
- if (!g(s, o)) return !1;
22
+ const o = [...n.keys()], s = [...t.keys()];
23
+ if (!g(o, s)) return !1;
24
24
  const i = [...n.values()], c = [...t.values()];
25
25
  return !!g(i, c);
26
26
  }
27
27
  if (e === "[object Object]") {
28
- const s = n, o = t, i = Object.keys(s), c = Object.keys(o);
29
- for (const a of i) {
30
- const l = c.find((d) => d === a);
28
+ const o = n, s = t, i = Object.keys(o), c = Object.keys(s);
29
+ for (const f of i) {
30
+ const l = c.find((d) => d === f);
31
31
  if (l === void 0) return !1;
32
- const [f, h] = [s[a], o[l]];
33
- if (!g(f, h)) return !1;
32
+ const [u, h] = [o[f], s[l]];
33
+ if (!g(u, h)) return !1;
34
34
  }
35
35
  return !0;
36
36
  }
37
37
  throw Error(`comparing these objects is unavailable: ${n}, ${t}`, {
38
38
  cause: [n, t]
39
39
  });
40
- }, X = () => {
40
+ }, H = () => {
41
41
  let n, t;
42
42
  return {
43
- promise: new Promise((r, s) => {
44
- n = r, t = s;
43
+ promise: new Promise((r, o) => {
44
+ n = r, t = o;
45
45
  }),
46
46
  resolve: n,
47
47
  reject: t
48
48
  };
49
- }, Y = (n) => new Promise((t) => {
49
+ }, J = (n) => new Promise((t) => {
50
50
  setTimeout(() => t(), n);
51
- }), H = (n) => (...t) => () => n(...t), Z = (n) => {
51
+ }), W = (n) => Object.prototype.toString.call(n).match(/^\[Object\s(.+)\]$/)?.at(1), Y = (n) => (...t) => () => n(...t), Z = (n) => {
52
52
  const t = [];
53
- let e = [], r = "", s = !1;
54
- for (let o = 0; o < n.length; o++) {
55
- const i = n[o];
56
- i === '"' && (o === 0 || n[o - 1] !== "\\") ? s = !s : i === "," && !s ? (e.push(r.trim()), r = "") : i === `
57
- ` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
53
+ let e = [], r = "", o = !1;
54
+ for (let s = 0; s < n.length; s++) {
55
+ const i = n[s];
56
+ i === '"' && (s === 0 || n[s - 1] !== "\\") ? o = !o : i === "," && !o ? (e.push(r.trim()), r = "") : i === `
57
+ ` && !o ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
58
58
  }
59
59
  return e.push(r.trim()), t.push(e), t;
60
60
  }, Q = async (n, t) => {
61
- const e = _.encode(n), r = await crypto.subtle.digest(t, e);
61
+ const e = L.encode(n), r = await crypto.subtle.digest(t, e);
62
62
  return new Uint8Array(r);
63
63
  }, tt = () => !!globalThis.process && typeof process.version < "u" && typeof process.versions.node < "u", nt = (n) => encodeURIComponent(n).replace(
64
64
  /[!'()*]/g,
@@ -73,66 +73,66 @@ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
73
73
  }, st = async (n, t) => {
74
74
  const r = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
75
75
  return new Response(r).bytes();
76
- }, ot = (n, t) => Math.floor(Math.random() * (t - n) + n), p = (n, t) => {
76
+ }, ot = (n, t) => Math.floor(Math.random() * (t - n) + n), m = (n, t) => {
77
77
  t < 0n && (t *= -1n);
78
78
  const e = n % t;
79
79
  return e < 0n ? e + t : e;
80
- }, v = (n, t = !1) => {
80
+ }, A = (n, t = !1) => {
81
81
  if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
82
82
  if (n <= 0) throw Error("`length` must be positive");
83
83
  const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
84
- let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
85
- return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
86
- }, L = (n, t) => {
84
+ let o = Array.from(r, (s) => s.toString(2).padStart(8, "0")).join("").slice(0, n);
85
+ return t && (o = o.replace(/^\d/, "1")), BigInt("0b" + o);
86
+ }, v = (n, t) => {
87
87
  if (n >= t) throw Error("rangeError");
88
- const e = t - n, r = e.toString(2).length, s = (() => {
88
+ const e = t - n, r = e.toString(2).length, o = (() => {
89
89
  for (let i = 0; i < 1e5; i++) {
90
- const c = v(r);
91
- if (c >= m(2n, BigInt(r), e))
90
+ const c = A(r);
91
+ if (c >= p(2n, BigInt(r), e))
92
92
  return c % e;
93
93
  }
94
94
  throw Error("Failed to generate a random bigint");
95
95
  })();
96
- return n + s;
97
- }, m = (n, t, e) => {
96
+ return n + o;
97
+ }, p = (n, t, e) => {
98
98
  if (e < 1n) throw Error("`mod` must be positive");
99
99
  if (t < 0n) throw Error("`power` must not be negative");
100
- if (n = p(n, e), e === 1n) return 0n;
100
+ if (n = m(n, e), e === 1n) return 0n;
101
101
  if (n % e === 1n || n % e === 0n) return n;
102
102
  if (n === e - 1n) return t & 1n ? e - 1n : 1n;
103
103
  let r = 1n;
104
104
  for (; t > 0n; )
105
105
  t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
106
106
  return r;
107
- }, j = (n, t) => {
107
+ }, _ = (n, t) => {
108
108
  if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
109
109
  if (n === 0n)
110
110
  return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
111
111
  if (t === 0n)
112
112
  return n > 0n ? { x: 1n, y: 0n, gcd: n } : { x: -1n, y: 0n, gcd: -n };
113
- let [e, r, s] = [1n, 0n, n], [o, i, c] = [0n, -1n, t];
113
+ let [e, r, o] = [1n, 0n, n], [s, i, c] = [0n, -1n, t];
114
114
  for (; ; ) {
115
- const a = s / c, l = s - a * c;
115
+ const f = o / c, l = o - f * c;
116
116
  if (l === 0n) break;
117
- [e, o] = [o, e - a * o], [r, i] = [i, r - a * i], [s, c] = [c, l];
117
+ [e, s] = [s, e - f * s], [r, i] = [i, r - f * i], [o, c] = [c, l];
118
118
  }
119
- return c < 0n && (o *= -1n, i *= -1n, c *= -1n), { x: o, y: i, gcd: c };
119
+ return c < 0n && (s *= -1n, i *= -1n, c *= -1n), { x: s, y: i, gcd: c };
120
120
  }, w = (n, t) => {
121
121
  if (n >= t) return 1n;
122
122
  const e = BigInt((t - 2n).toString(2).length), r = (t - n) / 2n;
123
123
  if (e * r < 63n) {
124
124
  let c = n;
125
- for (let a = n + 2n; a < t; a += 2n)
126
- c *= a;
125
+ for (let f = n + 2n; f < t; f += 2n)
126
+ c *= f;
127
127
  return c;
128
128
  }
129
- const s = n + r | 1n, o = w(n, s), i = w(s, t);
130
- return o * i;
131
- }, P = (n) => {
129
+ const o = n + r | 1n, s = w(n, o), i = w(o, t);
130
+ return s * i;
131
+ }, j = (n) => {
132
132
  let t = 3n, e = 1n, r = 1n;
133
- const s = BigInt(n.toString(2).length) - 1n;
134
- for (let o = s - 1n; o > -1n; --o) {
135
- const i = (n >> o) + 1n | 1n;
133
+ const o = BigInt(n.toString(2).length) - 1n;
134
+ for (let s = o - 1n; s > -1n; --s) {
135
+ const i = (n >> s) + 1n | 1n;
136
136
  r *= w(t, i), t = i, e *= r;
137
137
  }
138
138
  return e;
@@ -140,8 +140,8 @@ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
140
140
  if (n < 0n) throw Error("'n' must be non-negative");
141
141
  if (n === 0n) return 1n;
142
142
  const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
143
- return P(n) << t;
144
- }, C = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, I = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), U = (n, t) => {
143
+ return j(n) << t;
144
+ }, P = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, b = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), B = (n, t) => {
145
145
  if (t < 1n || t % 2n === 0n)
146
146
  throw Error("`n` is invalid");
147
147
  for (; n < 0n; )
@@ -166,49 +166,49 @@ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
166
166
  r ** 2n < n ? t = r : e = r;
167
167
  }
168
168
  return n === t ** 2n || n === (t + 1n) ** 2n;
169
- }, F = (n) => {
169
+ }, C = (n) => {
170
170
  if (n <= 1n) return !1;
171
171
  if (n % 2n === 0n) return n === 2n;
172
172
  let t = n - 1n, e = 0n;
173
173
  for (; t % 2n === 0n; )
174
174
  t >>= 1n, e += 1n;
175
- const [r, s] = [t, e];
176
- let i = m(2n, r, n);
175
+ const [r, o] = [t, e];
176
+ let i = p(2n, r, n);
177
177
  if (i === 1n) return !0;
178
- for (let c = 0n; c < s; c++) {
178
+ for (let c = 0n; c < o; c++) {
179
179
  if (i === n - 1n) return !0;
180
180
  i = i * i % n;
181
181
  }
182
182
  return !1;
183
- }, V = (n) => {
184
- let t = 5n, e = U(t, n);
183
+ }, F = (n) => {
184
+ let t = 5n, e = B(t, n);
185
185
  for (; e > 0n; ) {
186
186
  if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && O(n))
187
187
  return [0n, 0n];
188
- e = U(t, n);
188
+ e = B(t, n);
189
189
  }
190
190
  return [t, e];
191
- }, b = (n, t) => (n & 1n) === 1n ? p(n + t >> 1n, t) : p(n >> 1n, t), $ = (n, t, e, r) => {
192
- let s = 1n, o = e;
191
+ }, I = (n, t) => (n & 1n) === 1n ? m(n + t >> 1n, t) : m(n >> 1n, t), V = (n, t, e, r) => {
192
+ let o = 1n, s = e;
193
193
  const i = n.toString(2).slice(1);
194
194
  for (const c of i)
195
- [s, o] = [p(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)]);
196
- return [s, o];
195
+ [o, s] = [m(o * s, t), I(s * s + r * o * o, t)], c === "1" && ([o, s] = [I(e * o + s, t), I(r * o + e * s, t)]);
196
+ return [o, s];
197
197
  }, k = (n, t, e, r) => {
198
198
  if (n % 2n !== 1n) throw Error("`n` must be odd");
199
- let s = n + 1n, o = 0n;
200
- for (; s % 2n === 0n; )
201
- s >>= 1n, o += 1n;
202
- const [i, c] = $(s, n, e, t);
203
- let a = c;
199
+ let o = n + 1n, s = 0n;
200
+ for (; o % 2n === 0n; )
201
+ o >>= 1n, s += 1n;
202
+ const [i, c] = V(o, n, e, t);
203
+ let f = c;
204
204
  if (i === 0n) return !0;
205
- r = m(r, s, n);
206
- for (let l = 0n; l < o; l++) {
207
- if (a === 0n) return !0;
208
- a = p(a * a - 2n * r, n), r = m(r, 2n, n);
205
+ r = p(r, o, n);
206
+ for (let l = 0n; l < s; l++) {
207
+ if (f === 0n) return !0;
208
+ f = m(f * f - 2n * r, n), r = p(r, 2n, n);
209
209
  }
210
210
  return !1;
211
- }, M = (n) => {
211
+ }, T = (n) => {
212
212
  if (n <= 1n) return !1;
213
213
  if (n % 2n === 0n) return n === 2n;
214
214
  const t = [
@@ -239,33 +239,33 @@ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
239
239
  97n,
240
240
  101n
241
241
  ];
242
- for (const o of t)
243
- if (n % o === 0n)
244
- return n === o;
245
- if (!F(n))
242
+ for (const s of t)
243
+ if (n % s === 0n)
244
+ return n === s;
245
+ if (!C(n))
246
246
  return !1;
247
- const [e, r] = V(n);
247
+ const [e, r] = F(n);
248
248
  if (r === 0n) return !1;
249
- const s = (1n - e) / 4n;
250
- return k(n, e, 1n, s);
249
+ const o = (1n - e) / 4n;
250
+ return k(n, e, 1n, o);
251
251
  }, ct = (n, t) => {
252
252
  if (t < 2n)
253
253
  throw Error("noPrimesFound");
254
254
  for (let r = 0; r < 1e5; r++) {
255
- const s = L(n, t);
256
- if (M(s)) return s;
255
+ const o = v(n, t);
256
+ if (T(o)) return o;
257
257
  }
258
258
  throw Error("noPrimesFound");
259
- }, at = (n, t = !1) => {
259
+ }, ft = (n, t = !1) => {
260
260
  if (n < 2)
261
261
  throw Error("noPrimesFound");
262
262
  for (let r = 0; r < 1e5; r++) {
263
- const s = v(n, t);
264
- if (M(s)) return s;
263
+ const o = A(n, t);
264
+ if (T(o)) return o;
265
265
  }
266
266
  throw Error("noPrimesFound");
267
267
  };
268
- class u {
268
+ class a {
269
269
  #t;
270
270
  #n;
271
271
  static name = "Rational";
@@ -284,29 +284,29 @@ class u {
284
284
  */
285
285
  static fromDecimal(t, e = 5) {
286
286
  if (Number.isNaN(t))
287
- return new u(0n, 0n);
287
+ return new a(0n, 0n);
288
288
  if (Math.abs(t) === 1 / 0)
289
- return new u(t > 0 ? 1n : -1n, 0n);
289
+ return new a(t > 0 ? 1n : -1n, 0n);
290
290
  const r = t < 0;
291
291
  r && (t *= -1);
292
- const s = BigInt(Math.floor(t)), o = t - Number(s);
293
- if (o === 0)
294
- return new u(r ? -s : s, 1n);
295
- t = 1 / o;
296
- let [i, c] = [1n, s], [a, l] = [0n, 1n];
292
+ const o = BigInt(Math.floor(t)), s = t - Number(o);
293
+ if (s === 0)
294
+ return new a(r ? -o : o, 1n);
295
+ t = 1 / s;
296
+ let [i, c] = [1n, o], [f, l] = [0n, 1n];
297
297
  for (; `${l}`.length < e + 1; ) {
298
- const f = BigInt(Math.floor(t)), h = t - Number(f);
299
- if ([i, c] = [c, f * c + i], [a, l] = [l, f * l + a], h === 0)
300
- return new u(r ? -c : c, l);
298
+ const u = BigInt(Math.floor(t)), h = t - Number(u);
299
+ if ([i, c] = [c, u * c + i], [f, l] = [l, u * l + f], h === 0)
300
+ return new a(r ? -c : c, l);
301
301
  t = 1 / h;
302
302
  }
303
- return new u(r ? -i : i, a);
303
+ return new a(r ? -i : i, f);
304
304
  }
305
305
  /**
306
306
  * reduction
307
307
  */
308
308
  #e() {
309
- const { gcd: t } = j(this.#t, this.#n);
309
+ const { gcd: t } = _(this.#t, this.#n);
310
310
  t !== 0n && (this.#t /= t, this.#n /= t);
311
311
  }
312
312
  /**
@@ -314,14 +314,14 @@ class u {
314
314
  * @returns
315
315
  */
316
316
  minus() {
317
- return new u(-this.#t, this.#n);
317
+ return new a(-this.#t, this.#n);
318
318
  }
319
319
  /**
320
320
  * returns inverse of this fraction
321
321
  * @returns
322
322
  */
323
323
  inverse() {
324
- return new u(this.#n, this.#t);
324
+ return new a(this.#n, this.#t);
325
325
  }
326
326
  /**
327
327
  * returns `this + right`
@@ -330,7 +330,7 @@ class u {
330
330
  */
331
331
  add(t) {
332
332
  const e = this.#n * t.#n, r = this.#t * t.#n + t.#t * this.#n;
333
- return new u(r, e);
333
+ return new a(r, e);
334
334
  }
335
335
  /**
336
336
  * returns `this - right`
@@ -347,7 +347,7 @@ class u {
347
347
  */
348
348
  multiply(t) {
349
349
  const e = this.#n * t.#n, r = this.#t * t.#t;
350
- return new u(r, e);
350
+ return new a(r, e);
351
351
  }
352
352
  /**
353
353
  * returns `this / right`
@@ -365,7 +365,7 @@ class u {
365
365
  */
366
366
  mediant(t) {
367
367
  const e = this.#n + t.#n, r = this.#t + t.#t;
368
- return new u(r, e);
368
+ return new a(r, e);
369
369
  }
370
370
  /**
371
371
  * returns `number` type decimal
@@ -397,7 +397,7 @@ class u {
397
397
  */
398
398
  static fromData(t) {
399
399
  const e = BigInt(t.value[0]), r = BigInt(t.value[1]);
400
- return new u(e, r);
400
+ return new a(e, r);
401
401
  }
402
402
  /**
403
403
  * pases string whose form is `'numerator/denominator'`
@@ -408,152 +408,68 @@ class u {
408
408
  const r = /^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);
409
409
  if (!r)
410
410
  throw Error("cannot parse");
411
- const s = r.at(1), o = r.at(2);
412
- if (!s || !o)
411
+ const o = r.at(1), s = r.at(2);
412
+ if (!o || !s)
413
413
  throw Error("cannot parse");
414
- return new u(BigInt(s), BigInt(o));
414
+ return new a(BigInt(o), BigInt(s));
415
415
  }
416
416
  }
417
- Object.defineProperty(u.prototype, Symbol.toStringTag, {
418
- value: u.name
417
+ Object.defineProperty(a.prototype, Symbol.toStringTag, {
418
+ value: a.name
419
419
  });
420
- const D = new TextEncoder(), q = new TextDecoder(), lt = (n, t) => {
421
- switch (t) {
422
- case "utf-8":
423
- return D.encode(n);
424
- case "base64":
425
- return Uint8Array.from(atob(n), (e) => e.charCodeAt(0));
426
- case "base64url": {
427
- const e = n.length & 3;
428
- return e > 0 && (n = n + "=".repeat(4 - e)), n = n.replaceAll("-", "+").replaceAll("_", "/"), Uint8Array.from(atob(n), (r) => r.charCodeAt(0));
429
- }
430
- case "hex": {
431
- n.length & 1 && (n = "0" + n);
432
- const r = n.matchAll(/.{2}/g);
433
- return Uint8Array.from(r, (s) => Number.parseInt(s[0], 16));
434
- }
435
- case "oct": {
436
- const e = n.length & 7;
437
- e && (n = "0".repeat(8 - e) + n);
438
- const r = n.matchAll(/.{8}/g), o = Array.from(r, (i) => {
439
- const c = i[0];
440
- return Number.parseInt(c, 8).toString(16).padStart(6, "0");
441
- }).join("").matchAll(/.{2}/g);
442
- return Uint8Array.from(
443
- o,
444
- (i) => Number.parseInt(i[0], 16)
445
- );
446
- }
447
- case "bin": {
448
- const e = n.length & 7;
449
- e && (n = "0".repeat(8 - e) + n);
450
- const r = n.matchAll(/.{8}/g), s = Array.from(r, (o) => Number.parseInt(o[0], 2));
451
- return Uint8Array.from(s);
452
- }
453
- default:
454
- throw Error(`Invalid encoding: ${t}`, { cause: t });
455
- }
456
- }, ut = (n, t) => {
457
- switch (t) {
458
- case "utf-8":
459
- return q.decode(n);
460
- case "base64": {
461
- const e = Array.from(n, (r) => String.fromCharCode(r)).join("");
462
- return btoa(e);
463
- }
464
- case "base64url": {
465
- const e = Array.from(n, (s) => String.fromCharCode(s)).join("");
466
- return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
467
- }
468
- case "hex":
469
- return Array.from(n, (r) => r.toString(16).padStart(2, "0")).join("").replace(/^0+/, "");
470
- case "oct": {
471
- let e = Array.from(
472
- n,
473
- (i) => i.toString(16).padStart(2, "0")
474
- ).join("");
475
- const r = e.length % 6;
476
- r && (e = "0".repeat(6 - r) + e);
477
- const s = e.matchAll(/.{6}/g);
478
- return Array.from(
479
- s,
480
- (i) => Number.parseInt(i[0], 16).toString(8).padStart(8, "0")
481
- ).join("").replace(/^0+/, "");
482
- }
483
- case "bin":
484
- return Array.from(n, (r) => r.toString(2).padStart(8, "0")).join("").replace(/^0+/, "");
485
- default:
486
- throw Error(`Invalid encoding: ${t}`, { cause: t });
487
- }
420
+ const $ = (n) => {
421
+ const t = Array.from(n, (e) => String.fromCharCode(e));
422
+ return btoa(t.join(""));
423
+ }, D = (n) => {
424
+ const t = atob(n);
425
+ return Uint8Array.from(t, (e) => e.charCodeAt(0));
426
+ }, lt = (n) => $(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), at = (n) => {
427
+ const t = n.length & 3;
428
+ t > 0 && (n = n + "=".repeat(4 - t));
429
+ const e = n.replaceAll("-", "+").replaceAll("_", "/");
430
+ return D(e);
431
+ }, ut = (n) => {
432
+ let t = Array.from(n, (s) => s.toString(16).padStart(2, "0")).join("");
433
+ const e = t.length % 6;
434
+ e && (t = "0".repeat(6 - e) + t);
435
+ const r = t.matchAll(/.{6}/g);
436
+ return Array.from(
437
+ r,
438
+ (s) => Number.parseInt(s[0], 16).toString(8).padStart(8, "0")
439
+ ).join("").replace(/^0+/, "");
440
+ }, ht = (n) => {
441
+ const t = n.length & 7;
442
+ t && (n = "0".repeat(8 - t) + n);
443
+ const e = n.matchAll(/.{8}/g), o = Array.from(e, (s) => {
444
+ const i = s[0];
445
+ return Number.parseInt(i, 8).toString(16).padStart(6, "0");
446
+ }).join("").matchAll(/.{2}/g);
447
+ return Uint8Array.from(o, (s) => Number.parseInt(s[0], 16));
488
448
  }, K = (n) => {
489
449
  const t = n < 0n;
490
450
  t && (n *= -1n);
491
- const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, s = Math.floor(e / 7) + 1;
492
- return r ? s - 1 : s;
493
- }, ft = (n) => {
451
+ const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, o = Math.floor(e / 7) + 1;
452
+ return r ? o - 1 : o;
453
+ }, dt = (n) => {
494
454
  const t = K(n);
495
455
  n = BigInt.asUintN(t * 7, n);
496
456
  const e = new Uint8Array(t);
497
- for (let s = 0; s < t - 1; ++s) {
498
- const o = Number(n & 127n) | 128;
499
- e[s] = o, n >>= 7n;
457
+ for (let o = 0; o < t - 1; ++o) {
458
+ const s = Number(n & 127n) | 128;
459
+ e[o] = s, n >>= 7n;
500
460
  }
501
461
  const r = Number(n & 127n);
502
462
  return e[t - 1] = r, n >>= 7n, e;
503
- }, ht = (n) => {
463
+ }, gt = (n) => {
504
464
  const t = n.length;
505
465
  let e = 0n;
506
466
  for (let r = 0; r < t; ++r) {
507
- const s = BigInt(n[r] & 127);
508
- e += s << BigInt(7 * r);
467
+ const o = BigInt(n[r] & 127);
468
+ e += o << BigInt(7 * r);
509
469
  }
510
470
  return BigInt.asIntN(7 * t, e);
511
471
  };
512
- class S {
513
- #t;
514
- #n;
515
- static name = "Queue";
516
- /**
517
- * Queue
518
- * @param data
519
- */
520
- constructor(...t) {
521
- this.#t = t, this.#n = [];
522
- }
523
- /**
524
- * enqueue data
525
- * @param data
526
- * @returns current queue length
527
- */
528
- enqueue(...t) {
529
- return this.#t.push(...t), this.#t.length + this.#n.length;
530
- }
531
- /**
532
- * dequeue data
533
- * @returns data in the head
534
- */
535
- dequeue() {
536
- if (this.#n.length === 0)
537
- for (; this.#t.length > 0; ) {
538
- const t = this.#t.pop();
539
- this.#n.push(t);
540
- }
541
- return this.#n.pop();
542
- }
543
- toArray() {
544
- return this.#n.slice().reverse().concat(this.#t);
545
- }
546
- toJSON() {
547
- return this.toArray();
548
- }
549
- toString() {
550
- return this.toArray().toString();
551
- }
552
- }
553
- Object.defineProperty(S.prototype, Symbol.toStringTag, {
554
- value: S.name
555
- });
556
- class E extends Error {
472
+ class U extends Error {
557
473
  name;
558
474
  static name = "NamedError";
559
475
  constructor(t, e, r) {
@@ -561,34 +477,34 @@ class E extends Error {
561
477
  }
562
478
  toJSON() {
563
479
  const t = (() => {
564
- const o = this.cause;
565
- 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;
566
- })(), { name: e, message: r, stack: s } = this;
480
+ const s = this.cause;
481
+ return typeof s == "string" || typeof s == "number" || typeof s == "boolean" ? s : typeof s == "bigint" ? s.toString() : typeof s == "object" && s !== null ? s instanceof Set || s instanceof Map ? Object.fromEntries(s) : s : void 0;
482
+ })(), { name: e, message: r, stack: o } = this;
567
483
  return {
568
484
  name: e,
569
485
  message: r,
570
- stack: s,
486
+ stack: o,
571
487
  cause: t
572
488
  };
573
489
  }
574
490
  }
575
- Object.defineProperty(E.prototype, Symbol.toStringTag, {
576
- value: E.name
491
+ Object.defineProperty(U.prototype, Symbol.toStringTag, {
492
+ value: U.name
577
493
  });
578
- const B = (n) => {
494
+ const E = (n) => {
579
495
  if (n === 0) return 32;
580
496
  let t = 0;
581
497
  for (; n > 0 && !(n & 1); )
582
498
  ++t, n >>>= 1;
583
499
  return t;
584
- }, x = (n) => {
500
+ }, S = (n) => {
585
501
  if (n === 0n) return 64n;
586
502
  let t = 0n;
587
503
  for (; n > 0n && !(n & 1n); )
588
504
  ++t, n >>= 1n;
589
505
  return BigInt.asUintN(64, t);
590
506
  };
591
- class N {
507
+ class R {
592
508
  #t;
593
509
  static name = "FloatRng";
594
510
  constructor(t) {
@@ -600,18 +516,18 @@ class N {
600
516
  case 32:
601
517
  return this.#t.getU32Rand() >>> 0;
602
518
  case 64: {
603
- const f = this.#t.getU64Rand() & 0xffffffffn;
604
- return Number(f);
519
+ const u = this.#t.getU64Rand() & 0xffffffffn;
520
+ return Number(u);
605
521
  }
606
522
  }
607
- })(), s = r & 255;
608
- let o = 126;
609
- if (s === 0) {
610
- o -= 8;
611
- const f = 1e5;
523
+ })(), o = r & 255;
524
+ let s = 126;
525
+ if (o === 0) {
526
+ s -= 8;
527
+ const u = 1e5;
612
528
  let h = 0;
613
529
  t: for (; ; ) {
614
- if (h > f)
530
+ if (h > u)
615
531
  throw Error("loop exceeded limit");
616
532
  const d = (() => {
617
533
  switch (this.#t.bits) {
@@ -624,24 +540,24 @@ class N {
624
540
  }
625
541
  })();
626
542
  if (d === 0) {
627
- if (o -= 32, o < 0) {
628
- o = 0;
543
+ if (s -= 32, s < 0) {
544
+ s = 0;
629
545
  break t;
630
546
  }
631
547
  } else {
632
- o -= B(d);
548
+ s -= E(d);
633
549
  break t;
634
550
  }
635
551
  ++h;
636
552
  }
637
553
  } else
638
- o -= B(s);
554
+ s -= E(o);
639
555
  const i = r >>> 8 & 8388607;
640
- i === 0 && r >>> 31 && ++o;
641
- const { buffer: c, byteOffset: a, length: l } = Uint32Array.from([
642
- o << 23 | i
556
+ i === 0 && r >>> 31 && ++s;
557
+ const { buffer: c, byteOffset: f, length: l } = Uint32Array.from([
558
+ s << 23 | i
643
559
  ]);
644
- return new Float32Array(c, a, l)[0];
560
+ return new Float32Array(c, f, l)[0];
645
561
  }
646
562
  /**
647
563
  * returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
@@ -659,50 +575,50 @@ class N {
659
575
  const t = 0n, e = 1023n, r = (() => {
660
576
  switch (this.#t.bits) {
661
577
  case 32: {
662
- const f = BigInt(this.#t.getU32Rand() >>> 0), h = BigInt(this.#t.getU32Rand() >>> 0);
663
- return f << 32n | h;
578
+ const u = BigInt(this.#t.getU32Rand() >>> 0), h = BigInt(this.#t.getU32Rand() >>> 0);
579
+ return u << 32n | h;
664
580
  }
665
581
  case 64:
666
582
  return BigInt.asUintN(64, this.#t.getU64Rand());
667
583
  }
668
- })(), s = r & 0x7ffn;
669
- let o = e - 1n;
670
- if (s === 0n) {
671
- o -= 11n;
672
- const f = 1e5;
584
+ })(), o = r & 0x7ffn;
585
+ let s = e - 1n;
586
+ if (o === 0n) {
587
+ s -= 11n;
588
+ const u = 1e5;
673
589
  let h = 0;
674
590
  t: for (; ; ) {
675
- if (h > f)
591
+ if (h > u)
676
592
  throw Error("loop exceeded limit");
677
593
  const d = (() => {
678
594
  switch (this.#t.bits) {
679
595
  case 32: {
680
- const y = BigInt(this.#t.getU32Rand() >>> 0), T = BigInt(this.#t.getU32Rand() >>> 0);
681
- return y << 32n | T;
596
+ const y = BigInt(this.#t.getU32Rand() >>> 0), M = BigInt(this.#t.getU32Rand() >>> 0);
597
+ return y << 32n | M;
682
598
  }
683
599
  case 64:
684
600
  return BigInt.asUintN(64, this.#t.getU64Rand());
685
601
  }
686
602
  })();
687
603
  if (d === 0n) {
688
- if (o -= 64n, o < t) {
689
- o = t;
604
+ if (s -= 64n, s < t) {
605
+ s = t;
690
606
  break t;
691
607
  }
692
608
  } else {
693
- o -= x(d);
609
+ s -= S(d);
694
610
  break t;
695
611
  }
696
612
  ++h;
697
613
  }
698
614
  } else
699
- o -= x(s);
615
+ s -= S(o);
700
616
  const i = BigInt.asUintN(52, r >> 11n);
701
- i === 0n && r >> 63n && ++o;
702
- const { buffer: c, byteOffset: a, length: l } = BigUint64Array.from([
703
- o << 52n | i
617
+ i === 0n && r >> 63n && ++s;
618
+ const { buffer: c, byteOffset: f, length: l } = BigUint64Array.from([
619
+ s << 52n | i
704
620
  ]);
705
- return new Float64Array(c, a, l)[0];
621
+ return new Float64Array(c, f, l)[0];
706
622
  }
707
623
  /**
708
624
  * returns a random double-precision floating-point number (float64) in the range of [0.0, 1.0)
@@ -717,11 +633,11 @@ class N {
717
633
  throw Error("exceeded loop limit");
718
634
  }
719
635
  }
720
- Object.defineProperty(N.prototype, Symbol.toStringTag, {
721
- value: N.name
636
+ Object.defineProperty(R.prototype, Symbol.toStringTag, {
637
+ value: R.name
722
638
  });
723
- const z = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], J = 0x5851f42d4c957f2dn;
724
- class R {
639
+ const q = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], G = 0x5851f42d4c957f2dn;
640
+ class N {
725
641
  /**
726
642
  * length = 2, `[state, increment]`
727
643
  */
@@ -742,16 +658,16 @@ class R {
742
658
  * const betterRng = new PCGMinimal(seed);
743
659
  */
744
660
  constructor(t) {
745
- 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(z);
661
+ 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(q);
746
662
  }
747
663
  /** step inner state */
748
664
  #n() {
749
- this.#t[0] = this.#t[0] * J + this.#t[1];
665
+ this.#t[0] = this.#t[0] * G + this.#t[1];
750
666
  }
751
667
  /** 32bit 乱数を返す (内部状態は変わらない) */
752
668
  get #e() {
753
669
  const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
754
- return C(r, e);
670
+ return P(r, e);
755
671
  }
756
672
  /**
757
673
  *
@@ -767,8 +683,8 @@ class R {
767
683
  if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
768
684
  if (t <= 0)
769
685
  throw Error("'bound' must be positive");
770
- const r = 4294967296 % t, s = 1e5;
771
- for (let o = 0; o < s; ++o) {
686
+ const r = 4294967296 % t, o = 1e5;
687
+ for (let s = 0; s < o; ++s) {
772
688
  const i = this.getU32Rand();
773
689
  if (i >= r)
774
690
  return i % t;
@@ -790,16 +706,16 @@ class R {
790
706
  yield typeof e == "number" ? this.getBoundedU32Rand(e) : this.getU32Rand();
791
707
  }
792
708
  }
793
- Object.defineProperty(R.prototype, Symbol.toStringTag, {
794
- value: R.name
709
+ Object.defineProperty(N.prototype, Symbol.toStringTag, {
710
+ value: N.name
795
711
  });
796
- const G = [
712
+ const z = [
797
713
  0xbe562cb412e2260en,
798
714
  0x2e4284137d641affn,
799
715
  0x4e19b36ee933e27en,
800
716
  0x7581cf8c4f4d4f7dn
801
717
  ];
802
- class A {
718
+ class x {
803
719
  bits = 64;
804
720
  #t;
805
721
  static name = "XoshiroMinimal";
@@ -814,17 +730,18 @@ class A {
814
730
  *
815
731
  * // you should construct with random seeds.
816
732
  * const seed = crypto.getRandomValues(new BigUint64Array(4));
817
- * const betterRng = new PCGMinimal(seed);
733
+ * const betterRng = new XoshiroMinimal(seed);
818
734
  */
819
735
  constructor(t) {
820
- 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(G);
736
+ 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(z);
821
737
  }
822
738
  #n() {
823
739
  const t = this.#t[1] << 17n;
824
- 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] = I(this.#t[3], 45n);
740
+ 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);
825
741
  }
826
742
  get value() {
827
- return I(this.#t[0] + this.#t[3], 23n) + this.#t[0];
743
+ const t = b(this.#t[0] + this.#t[3], 23n) + this.#t[0];
744
+ return BigInt.asUintN(64, t);
828
745
  }
829
746
  getU64Rand() {
830
747
  const t = this.value;
@@ -840,8 +757,8 @@ class A {
840
757
  throw Error("'bound' exceeded limit");
841
758
  if (t <= 0n)
842
759
  throw Error("'bound' must be positive");
843
- const r = e % t, s = 1e5;
844
- for (let o = 0; o < s; ++o) {
760
+ const r = e % t, o = 1e5;
761
+ for (let s = 0; s < o; ++s) {
845
762
  const i = this.getU64Rand();
846
763
  if (i >= r)
847
764
  return i % t;
@@ -869,44 +786,48 @@ class A {
869
786
  yield e === void 0 ? this.getU32Rand() : this.getBoundedU32Rand(e);
870
787
  }
871
788
  }
872
- Object.defineProperty(A.prototype, Symbol.toStringTag, {
873
- value: A.name
789
+ Object.defineProperty(x.prototype, Symbol.toStringTag, {
790
+ value: x.name
874
791
  });
875
792
  export {
876
- N as FloatRng,
877
- E as NamedError,
878
- R as PCGMinimal,
879
- S as Queue,
880
- u as Rational,
881
- A as XoshiroMinimal,
882
- M as bailliePSW,
793
+ R as FloatRng,
794
+ U as NamedError,
795
+ N as PCGMinimal,
796
+ a as Rational,
797
+ x as XoshiroMinimal,
798
+ T as bailliePSW,
883
799
  rt as compress,
884
- ht as decodeLEB128,
800
+ gt as decodeLEB128,
885
801
  et as decodeRFC3986URIComponent,
886
802
  st as decompress,
887
- ft as encodeLEB128,
803
+ dt as encodeLEB128,
888
804
  nt as encodeRFC3986URIComponent,
889
- j as exEuclidean,
805
+ _ as exEuclidean,
890
806
  it as factorial,
891
- lt as fromString,
807
+ D as fromBase64,
808
+ at as fromBase64Url,
809
+ ht as fromOct,
892
810
  Q as getHash,
893
- v as getRandBIByBitLength,
894
- L as getRandBIByRange,
895
- at as getRandPrimeByBitLength,
811
+ A as getRandBIByBitLength,
812
+ v as getRandBIByRange,
813
+ ft as getRandPrimeByBitLength,
896
814
  ct as getRandPrimeByRange,
897
815
  ot as getRndInt,
816
+ W as getStringTag,
898
817
  g as isDeepStrictEqual,
899
818
  tt as isNode,
900
819
  O as isSquare,
901
- U as jacobiSymbol,
902
- H as lazify,
903
- m as modPow,
820
+ B as jacobiSymbol,
821
+ Y as lazify,
822
+ p as modPow,
904
823
  Z as parseCSV,
905
- X as promiseWithResolvers,
906
- p as residue,
907
- C as rot32,
908
- I as rot64,
909
- W as sameValueZero,
910
- Y as sleep,
911
- ut as toString
824
+ H as promiseWithResolvers,
825
+ m as residue,
826
+ P as rot32,
827
+ b as rot64,
828
+ X as sameValueZero,
829
+ J as sleep,
830
+ $ as toBase64,
831
+ lt as toBase64Url,
832
+ ut as toOct
912
833
  };
@@ -1,2 +1,2 @@
1
- (function(c,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(c=typeof globalThis<"u"?globalThis:c||self,y(c.UtilFns={}))})(this,(function(c){"use strict";const y=new TextEncoder,O=(n,t)=>[n].includes(t),m=(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 i=0;i<n.length;i++)if(!m(n[i],t[i]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const i=[...n.values()],s=[...t.values()];return!!m(i,s)}if(n instanceof Map&&t instanceof Map){const i=[...n.keys()],s=[...t.keys()];if(!m(i,s))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const i=n,s=t,o=Object.keys(i),a=Object.keys(s);for(const l of o){const u=a.find(g=>g===l);if(u===void 0)return!1;const[h,d]=[i[l],s[u]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},x=()=>{let n,t;return{promise:new Promise((r,i)=>{n=r,t=i}),resolve:n,reject:t}},V=n=>new Promise(t=>{setTimeout(()=>t(),n)}),$=n=>(...t)=>()=>n(...t),k=n=>{const t=[];let e=[],r="",i=!1;for(let s=0;s<n.length;s++){const o=n[s];o==='"'&&(s===0||n[s-1]!=="\\")?i=!i:o===","&&!i?(e.push(r.trim()),r=""):o===`
2
- `&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},D=async(n,t)=>{const e=y.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},q=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",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)},W=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},G=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},J=(n,t)=>Math.floor(Math.random()*(t-n)+n),p=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},w=(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 i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^\d/,"1")),BigInt("0b"+i)},T=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const a=w(r);if(a>=b(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+i},b=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=p(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},j=(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,i]=[1n,0n,n],[s,o,a]=[0n,-1n,t];for(;;){const l=i/a,u=i-l*a;if(u===0n)break;[e,s]=[s,e-l*s],[r,o]=[o,r-l*o],[i,a]=[a,u]}return a<0n&&(s*=-1n,o*=-1n,a*=-1n),{x:s,y:o,gcd:a}},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 a=n;for(let l=n+2n;l<t;l+=2n)a*=l;return a}const i=n+r|1n,s=I(n,i),o=I(i,t);return s*o},X=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=I(t,o),t=o,e*=r}return e},H=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 X(n)<<t},_=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,S=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),B=(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},P=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**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},Y=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,i]=[t,e];let o=b(2n,r,n);if(o===1n)return!0;for(let a=0n;a<i;a++){if(o===n-1n)return!0;o=o*o%n}return!1},Z=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?p(n+t>>1n,t):p(n>>1n,t),Q=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const a of o)[i,s]=[p(i*s,t),U(s*s+r*i*i,t)],a==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},tt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,a]=Q(i,n,e,t);let l=a;if(o===0n)return!0;r=b(r,i,n);for(let u=0n;u<s;u++){if(l===0n)return!0;l=p(l*l-2n*r,n),r=b(r,2n,n)}return!1},E=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 s of t)if(n%s===0n)return n===s;if(!Y(n))return!1;const[e,r]=Z(n);if(r===0n)return!1;const i=(1n-e)/4n;return tt(n,e,1n,i)},nt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=T(n,t);if(E(i))return i}throw Error("noPrimesFound")},et=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=w(n,t);if(E(i))return i}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";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 i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new f(r?-i:i,1n);t=1/s;let[o,a]=[1n,i],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,u]=[u,h*u+l],d===0)return new f(r?-a:a,u);t=1/d}return new f(r?-o:o,l)}#e(){const{gcd:t}=j(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 i=r.at(1),s=r.at(2);if(!i||!s)throw Error("cannot parse");return new f(BigInt(i),BigInt(s))}}Object.defineProperty(f.prototype,Symbol.toStringTag,{value:f.name});const rt=new TextEncoder,it=new TextDecoder,st=(n,t)=>{switch(t){case"utf-8":return rt.encode(n);case"base64":return Uint8Array.from(atob(n),e=>e.charCodeAt(0));case"base64url":{const e=n.length&3;return e>0&&(n=n+"=".repeat(4-e)),n=n.replaceAll("-","+").replaceAll("_","/"),Uint8Array.from(atob(n),r=>r.charCodeAt(0))}case"hex":{n.length&1&&(n="0"+n);const r=n.matchAll(/.{2}/g);return Uint8Array.from(r,i=>Number.parseInt(i[0],16))}case"oct":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),s=Array.from(r,o=>{const a=o[0];return Number.parseInt(a,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,o=>Number.parseInt(o[0],16))}case"bin":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),i=Array.from(r,s=>Number.parseInt(s[0],2));return Uint8Array.from(i)}default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ot=(n,t)=>{switch(t){case"utf-8":return it.decode(n);case"base64":{const e=Array.from(n,r=>String.fromCharCode(r)).join("");return btoa(e)}case"base64url":{const e=Array.from(n,i=>String.fromCharCode(i)).join("");return btoa(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}case"hex":return Array.from(n,r=>r.toString(16).padStart(2,"0")).join("").replace(/^0+/,"");case"oct":{let e=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const r=e.length%6;r&&(e="0".repeat(6-r)+e);const i=e.matchAll(/.{6}/g);return Array.from(i,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")}case"bin":return Array.from(n,r=>r.toString(2).padStart(8,"0")).join("").replace(/^0+/,"");default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ct=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,i=Math.floor(e/7)+1;return r?i-1:i},at=n=>{const t=ct(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let i=0;i<t-1;++i){const s=Number(n&127n)|128;e[i]=s,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},lt=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const i=BigInt(n[r]&127);e+=i<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class R{#t;#n;static name="Queue";constructor(...t){this.#t=t,this.#n=[]}enqueue(...t){return this.#t.push(...t),this.#t.length+this.#n.length}dequeue(){if(this.#n.length===0)for(;this.#t.length>0;){const t=this.#t.pop();this.#n.push(t)}return this.#n.pop()}toArray(){return this.#n.slice().reverse().concat(this.#t)}toJSON(){return this.toArray()}toString(){return this.toArray().toString()}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});class N extends Error{name;static name="NamedError";constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const s=this.cause;return typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:typeof s=="bigint"?s.toString():typeof s=="object"&&s!==null?s instanceof Set||s instanceof Map?Object.fromEntries(s):s:void 0})(),{name:e,message:r,stack:i}=this;return{name:e,message:r,stack:i,cause:t}}}Object.defineProperty(N.prototype,Symbol.toStringTag,{value:N.name});const C=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},F=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class A{#t;static name="FloatRng";constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const h=this.#t.getU64Rand()&0xffffffffn;return Number(h)}}})(),i=r&255;let s=126;if(i===0){s-=8;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const L=BigInt.asUintN(32,this.#t.getU64Rand());return Number(L)}}})();if(g===0){if(s-=32,s<0){s=0;break t}}else{s-=C(g);break t}++d}}else s-=C(i);const o=r>>>8&8388607;o===0&&r>>>31&&++s;const{buffer:a,byteOffset:l,length:u}=Uint32Array.from([s<<23|o]);return new Float32Array(a,l,u)[0]}getF32Rand(){for(let e=0;e<1e5;++e){const r=this.#n();if(r<1)return r}throw Error("exceeded loop limit")}#e(){const t=0n,e=1023n,r=(()=>{switch(this.#t.bits){case 32:{const h=BigInt(this.#t.getU32Rand()>>>0),d=BigInt(this.#t.getU32Rand()>>>0);return h<<32n|d}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),i=r&0x7ffn;let s=e-1n;if(i===0n){s-=11n;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:{const L=BigInt(this.#t.getU32Rand()>>>0),dt=BigInt(this.#t.getU32Rand()>>>0);return L<<32n|dt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(s-=64n,s<t){s=t;break t}}else{s-=F(g);break t}++d}}else s-=F(i);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++s;const{buffer:a,byteOffset:l,length:u}=BigUint64Array.from([s<<52n|o]);return new Float64Array(a,l,u)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}Object.defineProperty(A.prototype,Symbol.toStringTag,{value:A.name});const ut=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],ft=0x5851f42d4c957f2dn;class v{#t;static name="PCGMinimal";bits=32;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(ut)}#n(){this.#t[0]=this.#t[0]*ft+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return _(r,e)}getU32Rand(){return this.#n(),this.#e}getBoundedU32Rand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,i=1e5;for(let s=0;s<i;++s){const o=this.getU32Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedU32Rand(e):this.getU32Rand()}}Object.defineProperty(v.prototype,Symbol.toStringTag,{value:v.name});const ht=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class M{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(ht)}#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]=S(this.#t[3],45n)}get value(){return S(this.#t[0]+this.#t[3],23n)+this.#t[0]}getU64Rand(){const t=this.value;return this.#n(),t}getU32Rand(){const t=BigInt.asUintN(32,this.getU64Rand());return Number(t)}getBoundedU64Rand(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,i=1e5;for(let s=0;s<i;++s){const o=this.getU64Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}getBoundedU32Rand(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedU64Rand(BigInt(t));return Number(r)}*genU64Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU64Rand():this.getBoundedU64Rand(e)}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU32Rand():this.getBoundedU32Rand(e)}}Object.defineProperty(M.prototype,Symbol.toStringTag,{value:M.name}),c.FloatRng=A,c.NamedError=N,c.PCGMinimal=v,c.Queue=R,c.Rational=f,c.XoshiroMinimal=M,c.bailliePSW=E,c.compress=W,c.decodeLEB128=lt,c.decodeRFC3986URIComponent=z,c.decompress=G,c.encodeLEB128=at,c.encodeRFC3986URIComponent=K,c.exEuclidean=j,c.factorial=H,c.fromString=st,c.getHash=D,c.getRandBIByBitLength=w,c.getRandBIByRange=T,c.getRandPrimeByBitLength=et,c.getRandPrimeByRange=nt,c.getRndInt=J,c.isDeepStrictEqual=m,c.isNode=q,c.isSquare=P,c.jacobiSymbol=B,c.lazify=$,c.modPow=b,c.parseCSV=k,c.promiseWithResolvers=x,c.residue=p,c.rot32=_,c.rot64=S,c.sameValueZero=O,c.sleep=V,c.toString=ot,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
1
+ var UtilFns=(function(c){"use strict";const F=new TextEncoder,V=(n,t)=>[n].includes(t),m=(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 i=0;i<n.length;i++)if(!m(n[i],t[i]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const i=[...n.values()],s=[...t.values()];return!!m(i,s)}if(n instanceof Map&&t instanceof Map){const i=[...n.keys()],s=[...t.keys()];if(!m(i,s))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const i=n,s=t,o=Object.keys(i),a=Object.keys(s);for(const l of o){const f=a.find(g=>g===l);if(f===void 0)return!1;const[h,d]=[i[l],s[f]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},k=()=>{let n,t;return{promise:new Promise((r,i)=>{n=r,t=i}),resolve:n,reject:t}},$=n=>new Promise(t=>{setTimeout(()=>t(),n)}),D=n=>Object.prototype.toString.call(n).match(/^\[Object\s(.+)\]$/)?.at(1),q=n=>(...t)=>()=>n(...t),K=n=>{const t=[];let e=[],r="",i=!1;for(let s=0;s<n.length;s++){const o=n[s];o==='"'&&(s===0||n[s-1]!=="\\")?i=!i:o===","&&!i?(e.push(r.trim()),r=""):o===`
2
+ `&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},G=async(n,t)=>{const e=F.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},z=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",W=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),X=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)=>Math.floor(Math.random()*(t-n)+n),y=(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 i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^\d/,"1")),BigInt("0b"+i)},T=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const a=I(r);if(a>=p(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+i},p=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=y(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},A=(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,i]=[1n,0n,n],[s,o,a]=[0n,-1n,t];for(;;){const l=i/a,f=i-l*a;if(f===0n)break;[e,s]=[s,e-l*s],[r,o]=[o,r-l*o],[i,a]=[a,f]}return a<0n&&(s*=-1n,o*=-1n,a*=-1n),{x:s,y:o,gcd:a}},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 a=n;for(let l=n+2n;l<t;l+=2n)a*=l;return a}const i=n+r|1n,s=w(n,i),o=w(i,t);return s*o},Z=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=w(t,o),t=o,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 Z(n)<<t},v=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,b=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),B=(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},P=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**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},Q=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,i]=[t,e];let o=p(2n,r,n);if(o===1n)return!0;for(let a=0n;a<i;a++){if(o===n-1n)return!0;o=o*o%n}return!1},tt=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?y(n+t>>1n,t):y(n>>1n,t),nt=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const a of o)[i,s]=[y(i*s,t),U(s*s+r*i*i,t)],a==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},et=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,a]=nt(i,n,e,t);let l=a;if(o===0n)return!0;r=p(r,i,n);for(let f=0n;f<s;f++){if(l===0n)return!0;l=y(l*l-2n*r,n),r=p(r,2n,n)}return!1},E=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 s of t)if(n%s===0n)return n===s;if(!Q(n))return!1;const[e,r]=tt(n);if(r===0n)return!1;const i=(1n-e)/4n;return et(n,e,1n,i)},rt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=T(n,t);if(E(i))return i}throw Error("noPrimesFound")},st=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=I(n,t);if(E(i))return i}throw Error("noPrimesFound")};class u{#t;#n;static name="Rational";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 i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new u(r?-i:i,1n);t=1/s;let[o,a]=[1n,i],[l,f]=[0n,1n];for(;`${f}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,f]=[f,h*f+l],d===0)return new u(r?-a:a,f);t=1/d}return new u(r?-o:o,l)}#e(){const{gcd:t}=A(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 i=r.at(1),s=r.at(2);if(!i||!s)throw Error("cannot parse");return new u(BigInt(i),BigInt(s))}}Object.defineProperty(u.prototype,Symbol.toStringTag,{value:u.name});const j=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},C=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},it=n=>j(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),ot=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return C(e)},ct=n=>{let t=Array.from(n,s=>s.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,s=>Number.parseInt(s[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},at=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),i=Array.from(e,s=>{const o=s[0];return Number.parseInt(o,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(i,s=>Number.parseInt(s[0],16))},lt=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,i=Math.floor(e/7)+1;return r?i-1:i},ft=n=>{const t=lt(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let i=0;i<t-1;++i){const s=Number(n&127n)|128;e[i]=s,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},ut=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const i=BigInt(n[r]&127);e+=i<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class S extends Error{name;static name="NamedError";constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const s=this.cause;return typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:typeof s=="bigint"?s.toString():typeof s=="object"&&s!==null?s instanceof Set||s instanceof Map?Object.fromEntries(s):s:void 0})(),{name:e,message:r,stack:i}=this;return{name:e,message:r,stack:i,cause:t}}}Object.defineProperty(S.prototype,Symbol.toStringTag,{value:S.name});const O=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},_=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class R{#t;static name="FloatRng";constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const h=this.#t.getU64Rand()&0xffffffffn;return Number(h)}}})(),i=r&255;let s=126;if(i===0){s-=8;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const M=BigInt.asUintN(32,this.#t.getU64Rand());return Number(M)}}})();if(g===0){if(s-=32,s<0){s=0;break t}}else{s-=O(g);break t}++d}}else s-=O(i);const o=r>>>8&8388607;o===0&&r>>>31&&++s;const{buffer:a,byteOffset:l,length:f}=Uint32Array.from([s<<23|o]);return new Float32Array(a,l,f)[0]}getF32Rand(){for(let e=0;e<1e5;++e){const r=this.#n();if(r<1)return r}throw Error("exceeded loop limit")}#e(){const t=0n,e=1023n,r=(()=>{switch(this.#t.bits){case 32:{const h=BigInt(this.#t.getU32Rand()>>>0),d=BigInt(this.#t.getU32Rand()>>>0);return h<<32n|d}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),i=r&0x7ffn;let s=e-1n;if(i===0n){s-=11n;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:{const M=BigInt(this.#t.getU32Rand()>>>0),mt=BigInt(this.#t.getU32Rand()>>>0);return M<<32n|mt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(s-=64n,s<t){s=t;break t}}else{s-=_(g);break t}++d}}else s-=_(i);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++s;const{buffer:a,byteOffset:l,length:f}=BigUint64Array.from([s<<52n|o]);return new Float64Array(a,l,f)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});const ht=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],dt=0x5851f42d4c957f2dn;class N{#t;static name="PCGMinimal";bits=32;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(ht)}#n(){this.#t[0]=this.#t[0]*dt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return v(r,e)}getU32Rand(){return this.#n(),this.#e}getBoundedU32Rand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,i=1e5;for(let s=0;s<i;++s){const o=this.getU32Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedU32Rand(e):this.getU32Rand()}}Object.defineProperty(N.prototype,Symbol.toStringTag,{value:N.name});const gt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class L{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(gt)}#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)}getU64Rand(){const t=this.value;return this.#n(),t}getU32Rand(){const t=BigInt.asUintN(32,this.getU64Rand());return Number(t)}getBoundedU64Rand(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,i=1e5;for(let s=0;s<i;++s){const o=this.getU64Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}getBoundedU32Rand(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedU64Rand(BigInt(t));return Number(r)}*genU64Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU64Rand():this.getBoundedU64Rand(e)}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU32Rand():this.getBoundedU32Rand(e)}}return Object.defineProperty(L.prototype,Symbol.toStringTag,{value:L.name}),c.FloatRng=R,c.NamedError=S,c.PCGMinimal=N,c.Rational=u,c.XoshiroMinimal=L,c.bailliePSW=E,c.compress=H,c.decodeLEB128=ut,c.decodeRFC3986URIComponent=X,c.decompress=J,c.encodeLEB128=ft,c.encodeRFC3986URIComponent=W,c.exEuclidean=A,c.factorial=x,c.fromBase64=C,c.fromBase64Url=ot,c.fromOct=at,c.getHash=G,c.getRandBIByBitLength=I,c.getRandBIByRange=T,c.getRandPrimeByBitLength=st,c.getRandPrimeByRange=rt,c.getRndInt=Y,c.getStringTag=D,c.isDeepStrictEqual=m,c.isNode=z,c.isSquare=P,c.jacobiSymbol=B,c.lazify=q,c.modPow=p,c.parseCSV=K,c.promiseWithResolvers=k,c.residue=y,c.rot32=v,c.rot64=b,c.sameValueZero=V,c.sleep=$,c.toBase64=j,c.toBase64Url=it,c.toOct=ct,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
package/dist/main.d.ts CHANGED
@@ -3,7 +3,6 @@ export * from './math';
3
3
  export * from './baillie-psw';
4
4
  export * from './fraction';
5
5
  export * from './u8arr-ext';
6
- export * from './queue';
7
6
  export * from './named-error';
8
7
  export * from './random';
9
8
  export * from './pcg-minimal';
@@ -1,5 +1,8 @@
1
- export type Encoding = 'utf-8' | 'base64' | 'base64url' | 'hex' | 'oct' | 'bin';
2
- export declare const fromString: (str: string, encoding: Encoding) => Uint8Array<ArrayBuffer>;
3
- export declare const toString: (u8Arr: Uint8Array, encoding: Encoding) => string;
1
+ export declare const toBase64: (bin: Uint8Array) => string;
2
+ export declare const fromBase64: (base64: string) => Uint8Array<ArrayBuffer>;
3
+ export declare const toBase64Url: (bin: Uint8Array) => string;
4
+ export declare const fromBase64Url: (base64Url: string) => Uint8Array<ArrayBuffer>;
5
+ export declare const toOct: (bin: Uint8Array) => string;
6
+ export declare const fromOct: (oct: string) => Uint8Array<ArrayBuffer>;
4
7
  export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
5
8
  export declare const decodeLEB128: (leb128: Uint8Array<ArrayBuffer>) => bigint;
package/dist/util.d.ts CHANGED
@@ -25,6 +25,12 @@ export declare const promiseWithResolvers: <T>() => {
25
25
  * @returns
26
26
  */
27
27
  export declare const sleep: (delay: number) => Promise<void>;
28
+ /**
29
+ * get a value of `Symbol.toStringTag`
30
+ * @param obj
31
+ * @returns
32
+ */
33
+ export declare const getStringTag: (obj: unknown) => string | undefined;
28
34
  /**
29
35
  * makes a function lazy
30
36
  * @param func function
@@ -19,7 +19,7 @@ export declare class XoshiroMinimal implements RandomGenerator64 {
19
19
  *
20
20
  * // you should construct with random seeds.
21
21
  * const seed = crypto.getRandomValues(new BigUint64Array(4));
22
- * const betterRng = new PCGMinimal(seed);
22
+ * const betterRng = new XoshiroMinimal(seed);
23
23
  */
24
24
  constructor(seed?: BigUint64Array<ArrayBuffer>);
25
25
  get value(): bigint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.9.3",
3
+ "version": "0.10.0",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
package/dist/queue.d.ts DELETED
@@ -1,23 +0,0 @@
1
- export declare class Queue<T> {
2
- #private;
3
- static readonly name = "Queue";
4
- /**
5
- * Queue
6
- * @param data
7
- */
8
- constructor(...data: T[]);
9
- /**
10
- * enqueue data
11
- * @param data
12
- * @returns current queue length
13
- */
14
- enqueue(...data: T[]): number;
15
- /**
16
- * dequeue data
17
- * @returns data in the head
18
- */
19
- dequeue(): T | undefined;
20
- toArray(): T[];
21
- toJSON(): T[];
22
- toString(): string;
23
- }