@tktb-tess/util-fns 0.9.2 → 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 +13 -2
- package/dist/bundle.js +243 -306
- package/dist/bundle.min.js +2 -2
- package/dist/fraction.d.ts +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/named-error.d.ts +0 -1
- package/dist/pcg-minimal.d.ts +0 -1
- package/dist/random.d.ts +1 -2
- package/dist/u8arr-ext.d.ts +6 -3
- package/dist/util.d.ts +6 -0
- package/dist/xoshiro-minimal.d.ts +1 -2
- package/package.json +3 -4
- package/dist/queue.d.ts +0 -24
package/README.md
CHANGED
|
@@ -26,10 +26,21 @@ console.log(bailliePSW(4n)): // false
|
|
|
26
26
|
|
|
27
27
|
### CDN
|
|
28
28
|
|
|
29
|
-
You can also use CDN such as jsDelivr.
|
|
29
|
+
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.10.0/dist/bundle.min.js"></script>
|
|
34
|
+
<script type="module">
|
|
35
|
+
const { modPow } = UtilFns;
|
|
36
|
+
// ...
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<!-- or as an ES Module -->
|
|
40
|
+
<script type="module">
|
|
41
|
+
import { modPow } from 'https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.10.0/+esm';
|
|
42
|
+
// ...
|
|
43
|
+
</script>
|
|
33
44
|
```
|
|
34
45
|
|
|
35
46
|
|
package/dist/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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 v = new TextEncoder(), Y = (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
|
|
14
|
-
if (!g(n[
|
|
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
|
|
19
|
-
return !!g(
|
|
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
|
|
23
|
-
if (!g(
|
|
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
|
|
29
|
-
for (const
|
|
30
|
-
const l = c.find((d) => d ===
|
|
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 [
|
|
33
|
-
if (!g(
|
|
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
|
-
},
|
|
40
|
+
}, H = () => {
|
|
41
41
|
let n, t;
|
|
42
42
|
return {
|
|
43
|
-
promise: new Promise((r,
|
|
44
|
-
n = r, t =
|
|
43
|
+
promise: new Promise((r, o) => {
|
|
44
|
+
n = r, t = o;
|
|
45
45
|
}),
|
|
46
46
|
resolve: n,
|
|
47
47
|
reject: t
|
|
48
48
|
};
|
|
49
|
-
},
|
|
49
|
+
}, J = (n) => new Promise((t) => {
|
|
50
50
|
setTimeout(() => t(), n);
|
|
51
|
-
}),
|
|
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 = "",
|
|
54
|
-
for (let
|
|
55
|
-
const i = n[
|
|
56
|
-
i === '"' && (
|
|
57
|
-
` && !
|
|
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 =
|
|
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,
|
|
@@ -77,23 +77,23 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
|
|
|
77
77
|
t < 0n && (t *= -1n);
|
|
78
78
|
const e = n % t;
|
|
79
79
|
return e < 0n ? e + t : e;
|
|
80
|
-
},
|
|
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
|
|
85
|
-
return t && (
|
|
86
|
-
},
|
|
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,
|
|
88
|
+
const e = t - n, r = e.toString(2).length, o = (() => {
|
|
89
89
|
for (let i = 0; i < 1e5; i++) {
|
|
90
|
-
const c =
|
|
90
|
+
const c = A(r);
|
|
91
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 +
|
|
96
|
+
return n + o;
|
|
97
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");
|
|
@@ -104,44 +104,44 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
|
|
|
104
104
|
for (; t > 0n; )
|
|
105
105
|
t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
|
|
106
106
|
return r;
|
|
107
|
-
},
|
|
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,
|
|
113
|
+
let [e, r, o] = [1n, 0n, n], [s, i, c] = [0n, -1n, t];
|
|
114
114
|
for (; ; ) {
|
|
115
|
-
const
|
|
115
|
+
const f = o / c, l = o - f * c;
|
|
116
116
|
if (l === 0n) break;
|
|
117
|
-
[e,
|
|
117
|
+
[e, s] = [s, e - f * s], [r, i] = [i, r - f * i], [o, c] = [c, l];
|
|
118
118
|
}
|
|
119
|
-
return c < 0n && (
|
|
120
|
-
},
|
|
119
|
+
return c < 0n && (s *= -1n, i *= -1n, c *= -1n), { x: s, y: i, gcd: c };
|
|
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
|
|
126
|
-
c *=
|
|
125
|
+
for (let f = n + 2n; f < t; f += 2n)
|
|
126
|
+
c *= f;
|
|
127
127
|
return c;
|
|
128
128
|
}
|
|
129
|
-
const
|
|
130
|
-
return
|
|
131
|
-
},
|
|
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
|
|
134
|
-
for (let
|
|
135
|
-
const i = (n >>
|
|
136
|
-
r *=
|
|
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
|
+
r *= w(t, i), t = i, e *= r;
|
|
137
137
|
}
|
|
138
138
|
return e;
|
|
139
139
|
}, it = (n) => {
|
|
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
|
|
144
|
-
},
|
|
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; )
|
|
@@ -157,7 +157,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
|
|
|
157
157
|
[n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
|
|
158
158
|
}
|
|
159
159
|
return t === 1n ? e : 0n;
|
|
160
|
-
},
|
|
160
|
+
}, O = (n) => {
|
|
161
161
|
if (n < 0n) return !1;
|
|
162
162
|
if (n === 0n) return !0;
|
|
163
163
|
let t = 1n, e = n;
|
|
@@ -166,49 +166,49 @@ const v = new TextEncoder(), Y = (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
|
-
},
|
|
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,
|
|
175
|
+
const [r, o] = [t, e];
|
|
176
176
|
let i = p(2n, r, n);
|
|
177
177
|
if (i === 1n) return !0;
|
|
178
|
-
for (let c = 0n; 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
|
-
},
|
|
184
|
-
let t = 5n, e =
|
|
183
|
+
}, F = (n) => {
|
|
184
|
+
let t = 5n, e = B(t, n);
|
|
185
185
|
for (; e > 0n; ) {
|
|
186
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
186
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && O(n))
|
|
187
187
|
return [0n, 0n];
|
|
188
|
-
e =
|
|
188
|
+
e = B(t, n);
|
|
189
189
|
}
|
|
190
190
|
return [t, e];
|
|
191
|
-
},
|
|
192
|
-
let
|
|
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
|
-
[
|
|
196
|
-
return [
|
|
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
|
|
200
|
-
for (;
|
|
201
|
-
|
|
202
|
-
const [i, c] =
|
|
203
|
-
let
|
|
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 = p(r,
|
|
206
|
-
for (let l = 0n; l <
|
|
207
|
-
if (
|
|
208
|
-
|
|
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
|
-
},
|
|
211
|
+
}, T = (n) => {
|
|
212
212
|
if (n <= 1n) return !1;
|
|
213
213
|
if (n % 2n === 0n) return n === 2n;
|
|
214
214
|
const t = [
|
|
@@ -239,37 +239,36 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
|
|
|
239
239
|
97n,
|
|
240
240
|
101n
|
|
241
241
|
];
|
|
242
|
-
for (const
|
|
243
|
-
if (n %
|
|
244
|
-
return n ===
|
|
245
|
-
if (!
|
|
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] =
|
|
247
|
+
const [e, r] = F(n);
|
|
248
248
|
if (r === 0n) return !1;
|
|
249
|
-
const
|
|
250
|
-
return k(n, e, 1n,
|
|
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
|
|
256
|
-
if (
|
|
255
|
+
const o = v(n, t);
|
|
256
|
+
if (T(o)) return o;
|
|
257
257
|
}
|
|
258
258
|
throw Error("noPrimesFound");
|
|
259
|
-
},
|
|
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
|
|
264
|
-
if (
|
|
263
|
+
const o = A(n, t);
|
|
264
|
+
if (T(o)) return o;
|
|
265
265
|
}
|
|
266
266
|
throw Error("noPrimesFound");
|
|
267
267
|
};
|
|
268
|
-
class
|
|
268
|
+
class a {
|
|
269
269
|
#t;
|
|
270
270
|
#n;
|
|
271
271
|
static name = "Rational";
|
|
272
|
-
[Symbol.toStringTag] = u.name;
|
|
273
272
|
/**
|
|
274
273
|
* fraction (rational) class
|
|
275
274
|
* @param numerator
|
|
@@ -285,29 +284,29 @@ class u {
|
|
|
285
284
|
*/
|
|
286
285
|
static fromDecimal(t, e = 5) {
|
|
287
286
|
if (Number.isNaN(t))
|
|
288
|
-
return new
|
|
287
|
+
return new a(0n, 0n);
|
|
289
288
|
if (Math.abs(t) === 1 / 0)
|
|
290
|
-
return new
|
|
289
|
+
return new a(t > 0 ? 1n : -1n, 0n);
|
|
291
290
|
const r = t < 0;
|
|
292
291
|
r && (t *= -1);
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
return new
|
|
296
|
-
t = 1 /
|
|
297
|
-
let [i, c] = [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];
|
|
298
297
|
for (; `${l}`.length < e + 1; ) {
|
|
299
|
-
const
|
|
300
|
-
if ([i, c] = [c,
|
|
301
|
-
return new
|
|
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);
|
|
302
301
|
t = 1 / h;
|
|
303
302
|
}
|
|
304
|
-
return new
|
|
303
|
+
return new a(r ? -i : i, f);
|
|
305
304
|
}
|
|
306
305
|
/**
|
|
307
306
|
* reduction
|
|
308
307
|
*/
|
|
309
308
|
#e() {
|
|
310
|
-
const { gcd: t } =
|
|
309
|
+
const { gcd: t } = _(this.#t, this.#n);
|
|
311
310
|
t !== 0n && (this.#t /= t, this.#n /= t);
|
|
312
311
|
}
|
|
313
312
|
/**
|
|
@@ -315,14 +314,14 @@ class u {
|
|
|
315
314
|
* @returns
|
|
316
315
|
*/
|
|
317
316
|
minus() {
|
|
318
|
-
return new
|
|
317
|
+
return new a(-this.#t, this.#n);
|
|
319
318
|
}
|
|
320
319
|
/**
|
|
321
320
|
* returns inverse of this fraction
|
|
322
321
|
* @returns
|
|
323
322
|
*/
|
|
324
323
|
inverse() {
|
|
325
|
-
return new
|
|
324
|
+
return new a(this.#n, this.#t);
|
|
326
325
|
}
|
|
327
326
|
/**
|
|
328
327
|
* returns `this + right`
|
|
@@ -331,7 +330,7 @@ class u {
|
|
|
331
330
|
*/
|
|
332
331
|
add(t) {
|
|
333
332
|
const e = this.#n * t.#n, r = this.#t * t.#n + t.#t * this.#n;
|
|
334
|
-
return new
|
|
333
|
+
return new a(r, e);
|
|
335
334
|
}
|
|
336
335
|
/**
|
|
337
336
|
* returns `this - right`
|
|
@@ -348,7 +347,7 @@ class u {
|
|
|
348
347
|
*/
|
|
349
348
|
multiply(t) {
|
|
350
349
|
const e = this.#n * t.#n, r = this.#t * t.#t;
|
|
351
|
-
return new
|
|
350
|
+
return new a(r, e);
|
|
352
351
|
}
|
|
353
352
|
/**
|
|
354
353
|
* returns `this / right`
|
|
@@ -366,7 +365,7 @@ class u {
|
|
|
366
365
|
*/
|
|
367
366
|
mediant(t) {
|
|
368
367
|
const e = this.#n + t.#n, r = this.#t + t.#t;
|
|
369
|
-
return new
|
|
368
|
+
return new a(r, e);
|
|
370
369
|
}
|
|
371
370
|
/**
|
|
372
371
|
* returns `number` type decimal
|
|
@@ -398,7 +397,7 @@ class u {
|
|
|
398
397
|
*/
|
|
399
398
|
static fromData(t) {
|
|
400
399
|
const e = BigInt(t.value[0]), r = BigInt(t.value[1]);
|
|
401
|
-
return new
|
|
400
|
+
return new a(e, r);
|
|
402
401
|
}
|
|
403
402
|
/**
|
|
404
403
|
* pases string whose form is `'numerator/denominator'`
|
|
@@ -409,183 +408,105 @@ class u {
|
|
|
409
408
|
const r = /^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);
|
|
410
409
|
if (!r)
|
|
411
410
|
throw Error("cannot parse");
|
|
412
|
-
const
|
|
413
|
-
if (!
|
|
411
|
+
const o = r.at(1), s = r.at(2);
|
|
412
|
+
if (!o || !s)
|
|
414
413
|
throw Error("cannot parse");
|
|
415
|
-
return new
|
|
414
|
+
return new a(BigInt(o), BigInt(s));
|
|
416
415
|
}
|
|
417
416
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return Uint8Array.from(s);
|
|
450
|
-
}
|
|
451
|
-
default:
|
|
452
|
-
throw Error(`Invalid encoding: ${t}`, { cause: t });
|
|
453
|
-
}
|
|
454
|
-
}, ut = (n, t) => {
|
|
455
|
-
switch (t) {
|
|
456
|
-
case "utf-8":
|
|
457
|
-
return q.decode(n);
|
|
458
|
-
case "base64": {
|
|
459
|
-
const e = Array.from(n, (r) => String.fromCharCode(r)).join("");
|
|
460
|
-
return btoa(e);
|
|
461
|
-
}
|
|
462
|
-
case "base64url": {
|
|
463
|
-
const e = Array.from(n, (s) => String.fromCharCode(s)).join("");
|
|
464
|
-
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
465
|
-
}
|
|
466
|
-
case "hex":
|
|
467
|
-
return Array.from(n, (r) => r.toString(16).padStart(2, "0")).join("").replace(/^0+/, "");
|
|
468
|
-
case "oct": {
|
|
469
|
-
let e = Array.from(
|
|
470
|
-
n,
|
|
471
|
-
(i) => i.toString(16).padStart(2, "0")
|
|
472
|
-
).join("");
|
|
473
|
-
const r = e.length % 6;
|
|
474
|
-
r && (e = "0".repeat(6 - r) + e);
|
|
475
|
-
const s = e.matchAll(/.{6}/g);
|
|
476
|
-
return Array.from(
|
|
477
|
-
s,
|
|
478
|
-
(i) => Number.parseInt(i[0], 16).toString(8).padStart(8, "0")
|
|
479
|
-
).join("").replace(/^0+/, "");
|
|
480
|
-
}
|
|
481
|
-
case "bin":
|
|
482
|
-
return Array.from(n, (r) => r.toString(2).padStart(8, "0")).join("").replace(/^0+/, "");
|
|
483
|
-
default:
|
|
484
|
-
throw Error(`Invalid encoding: ${t}`, { cause: t });
|
|
485
|
-
}
|
|
417
|
+
Object.defineProperty(a.prototype, Symbol.toStringTag, {
|
|
418
|
+
value: a.name
|
|
419
|
+
});
|
|
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));
|
|
486
448
|
}, K = (n) => {
|
|
487
449
|
const t = n < 0n;
|
|
488
450
|
t && (n *= -1n);
|
|
489
|
-
const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t,
|
|
490
|
-
return r ?
|
|
491
|
-
},
|
|
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) => {
|
|
492
454
|
const t = K(n);
|
|
493
455
|
n = BigInt.asUintN(t * 7, n);
|
|
494
456
|
const e = new Uint8Array(t);
|
|
495
|
-
for (let
|
|
496
|
-
const
|
|
497
|
-
e[
|
|
457
|
+
for (let o = 0; o < t - 1; ++o) {
|
|
458
|
+
const s = Number(n & 127n) | 128;
|
|
459
|
+
e[o] = s, n >>= 7n;
|
|
498
460
|
}
|
|
499
461
|
const r = Number(n & 127n);
|
|
500
462
|
return e[t - 1] = r, n >>= 7n, e;
|
|
501
|
-
},
|
|
463
|
+
}, gt = (n) => {
|
|
502
464
|
const t = n.length;
|
|
503
465
|
let e = 0n;
|
|
504
466
|
for (let r = 0; r < t; ++r) {
|
|
505
|
-
const
|
|
506
|
-
e +=
|
|
467
|
+
const o = BigInt(n[r] & 127);
|
|
468
|
+
e += o << BigInt(7 * r);
|
|
507
469
|
}
|
|
508
470
|
return BigInt.asIntN(7 * t, e);
|
|
509
471
|
};
|
|
510
|
-
class
|
|
511
|
-
#t;
|
|
512
|
-
#n;
|
|
513
|
-
static name = "Queue";
|
|
514
|
-
[Symbol.toStringTag] = N.name;
|
|
515
|
-
/**
|
|
516
|
-
* Queue
|
|
517
|
-
* @param data
|
|
518
|
-
*/
|
|
519
|
-
constructor(...t) {
|
|
520
|
-
this.#t = t, this.#n = [];
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* enqueue data
|
|
524
|
-
* @param data
|
|
525
|
-
* @returns current queue length
|
|
526
|
-
*/
|
|
527
|
-
enqueue(...t) {
|
|
528
|
-
return this.#t.push(...t), this.#t.length + this.#n.length;
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* dequeue data
|
|
532
|
-
* @returns data in the head
|
|
533
|
-
*/
|
|
534
|
-
dequeue() {
|
|
535
|
-
if (this.#n.length === 0)
|
|
536
|
-
for (; this.#t.length > 0; ) {
|
|
537
|
-
const t = this.#t.pop();
|
|
538
|
-
this.#n.push(t);
|
|
539
|
-
}
|
|
540
|
-
return this.#n.pop();
|
|
541
|
-
}
|
|
542
|
-
toArray() {
|
|
543
|
-
return this.#n.slice().reverse().concat(this.#t);
|
|
544
|
-
}
|
|
545
|
-
toJSON() {
|
|
546
|
-
return this.toArray();
|
|
547
|
-
}
|
|
548
|
-
toString() {
|
|
549
|
-
return this.toArray().toString();
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
class R extends Error {
|
|
472
|
+
class U extends Error {
|
|
553
473
|
name;
|
|
554
474
|
static name = "NamedError";
|
|
555
|
-
[Symbol.toStringTag] = R.name;
|
|
556
475
|
constructor(t, e, r) {
|
|
557
476
|
super(e, { cause: r }), this.name = t;
|
|
558
477
|
}
|
|
559
478
|
toJSON() {
|
|
560
479
|
const t = (() => {
|
|
561
|
-
const
|
|
562
|
-
return typeof
|
|
563
|
-
})(), { name: e, message: r, stack:
|
|
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;
|
|
564
483
|
return {
|
|
565
484
|
name: e,
|
|
566
485
|
message: r,
|
|
567
|
-
stack:
|
|
486
|
+
stack: o,
|
|
568
487
|
cause: t
|
|
569
488
|
};
|
|
570
489
|
}
|
|
571
490
|
}
|
|
572
|
-
|
|
491
|
+
Object.defineProperty(U.prototype, Symbol.toStringTag, {
|
|
492
|
+
value: U.name
|
|
493
|
+
});
|
|
494
|
+
const E = (n) => {
|
|
573
495
|
if (n === 0) return 32;
|
|
574
496
|
let t = 0;
|
|
575
497
|
for (; n > 0 && !(n & 1); )
|
|
576
498
|
++t, n >>>= 1;
|
|
577
499
|
return t;
|
|
578
|
-
},
|
|
500
|
+
}, S = (n) => {
|
|
579
501
|
if (n === 0n) return 64n;
|
|
580
502
|
let t = 0n;
|
|
581
503
|
for (; n > 0n && !(n & 1n); )
|
|
582
504
|
++t, n >>= 1n;
|
|
583
505
|
return BigInt.asUintN(64, t);
|
|
584
506
|
};
|
|
585
|
-
class
|
|
507
|
+
class R {
|
|
586
508
|
#t;
|
|
587
|
-
static name = "
|
|
588
|
-
[Symbol.toStringTag] = A.name;
|
|
509
|
+
static name = "FloatRng";
|
|
589
510
|
constructor(t) {
|
|
590
511
|
this.#t = t;
|
|
591
512
|
}
|
|
@@ -595,18 +516,18 @@ class A {
|
|
|
595
516
|
case 32:
|
|
596
517
|
return this.#t.getU32Rand() >>> 0;
|
|
597
518
|
case 64: {
|
|
598
|
-
const
|
|
599
|
-
return Number(
|
|
519
|
+
const u = this.#t.getU64Rand() & 0xffffffffn;
|
|
520
|
+
return Number(u);
|
|
600
521
|
}
|
|
601
522
|
}
|
|
602
|
-
})(),
|
|
603
|
-
let
|
|
604
|
-
if (
|
|
605
|
-
|
|
606
|
-
const
|
|
523
|
+
})(), o = r & 255;
|
|
524
|
+
let s = 126;
|
|
525
|
+
if (o === 0) {
|
|
526
|
+
s -= 8;
|
|
527
|
+
const u = 1e5;
|
|
607
528
|
let h = 0;
|
|
608
529
|
t: for (; ; ) {
|
|
609
|
-
if (h >
|
|
530
|
+
if (h > u)
|
|
610
531
|
throw Error("loop exceeded limit");
|
|
611
532
|
const d = (() => {
|
|
612
533
|
switch (this.#t.bits) {
|
|
@@ -619,22 +540,24 @@ class A {
|
|
|
619
540
|
}
|
|
620
541
|
})();
|
|
621
542
|
if (d === 0) {
|
|
622
|
-
if (
|
|
623
|
-
|
|
543
|
+
if (s -= 32, s < 0) {
|
|
544
|
+
s = 0;
|
|
624
545
|
break t;
|
|
625
546
|
}
|
|
626
547
|
} else {
|
|
627
|
-
|
|
548
|
+
s -= E(d);
|
|
628
549
|
break t;
|
|
629
550
|
}
|
|
630
551
|
++h;
|
|
631
552
|
}
|
|
632
553
|
} else
|
|
633
|
-
|
|
554
|
+
s -= E(o);
|
|
634
555
|
const i = r >>> 8 & 8388607;
|
|
635
|
-
i === 0 && r >>> 31 && ++
|
|
636
|
-
const { buffer: c, byteOffset:
|
|
637
|
-
|
|
556
|
+
i === 0 && r >>> 31 && ++s;
|
|
557
|
+
const { buffer: c, byteOffset: f, length: l } = Uint32Array.from([
|
|
558
|
+
s << 23 | i
|
|
559
|
+
]);
|
|
560
|
+
return new Float32Array(c, f, l)[0];
|
|
638
561
|
}
|
|
639
562
|
/**
|
|
640
563
|
* returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
|
|
@@ -652,48 +575,50 @@ class A {
|
|
|
652
575
|
const t = 0n, e = 1023n, r = (() => {
|
|
653
576
|
switch (this.#t.bits) {
|
|
654
577
|
case 32: {
|
|
655
|
-
const
|
|
656
|
-
return
|
|
578
|
+
const u = BigInt(this.#t.getU32Rand() >>> 0), h = BigInt(this.#t.getU32Rand() >>> 0);
|
|
579
|
+
return u << 32n | h;
|
|
657
580
|
}
|
|
658
581
|
case 64:
|
|
659
582
|
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
660
583
|
}
|
|
661
|
-
})(),
|
|
662
|
-
let
|
|
663
|
-
if (
|
|
664
|
-
|
|
665
|
-
const
|
|
584
|
+
})(), o = r & 0x7ffn;
|
|
585
|
+
let s = e - 1n;
|
|
586
|
+
if (o === 0n) {
|
|
587
|
+
s -= 11n;
|
|
588
|
+
const u = 1e5;
|
|
666
589
|
let h = 0;
|
|
667
590
|
t: for (; ; ) {
|
|
668
|
-
if (h >
|
|
591
|
+
if (h > u)
|
|
669
592
|
throw Error("loop exceeded limit");
|
|
670
593
|
const d = (() => {
|
|
671
594
|
switch (this.#t.bits) {
|
|
672
595
|
case 32: {
|
|
673
|
-
const y = BigInt(this.#t.getU32Rand() >>> 0),
|
|
674
|
-
return y << 32n |
|
|
596
|
+
const y = BigInt(this.#t.getU32Rand() >>> 0), M = BigInt(this.#t.getU32Rand() >>> 0);
|
|
597
|
+
return y << 32n | M;
|
|
675
598
|
}
|
|
676
599
|
case 64:
|
|
677
600
|
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
678
601
|
}
|
|
679
602
|
})();
|
|
680
603
|
if (d === 0n) {
|
|
681
|
-
if (
|
|
682
|
-
|
|
604
|
+
if (s -= 64n, s < t) {
|
|
605
|
+
s = t;
|
|
683
606
|
break t;
|
|
684
607
|
}
|
|
685
608
|
} else {
|
|
686
|
-
|
|
609
|
+
s -= S(d);
|
|
687
610
|
break t;
|
|
688
611
|
}
|
|
689
612
|
++h;
|
|
690
613
|
}
|
|
691
614
|
} else
|
|
692
|
-
|
|
615
|
+
s -= S(o);
|
|
693
616
|
const i = BigInt.asUintN(52, r >> 11n);
|
|
694
|
-
i === 0n && r >> 63n && ++
|
|
695
|
-
const { buffer: c, byteOffset:
|
|
696
|
-
|
|
617
|
+
i === 0n && r >> 63n && ++s;
|
|
618
|
+
const { buffer: c, byteOffset: f, length: l } = BigUint64Array.from([
|
|
619
|
+
s << 52n | i
|
|
620
|
+
]);
|
|
621
|
+
return new Float64Array(c, f, l)[0];
|
|
697
622
|
}
|
|
698
623
|
/**
|
|
699
624
|
* returns a random double-precision floating-point number (float64) in the range of [0.0, 1.0)
|
|
@@ -708,14 +633,16 @@ class A {
|
|
|
708
633
|
throw Error("exceeded loop limit");
|
|
709
634
|
}
|
|
710
635
|
}
|
|
711
|
-
|
|
712
|
-
|
|
636
|
+
Object.defineProperty(R.prototype, Symbol.toStringTag, {
|
|
637
|
+
value: R.name
|
|
638
|
+
});
|
|
639
|
+
const q = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], G = 0x5851f42d4c957f2dn;
|
|
640
|
+
class N {
|
|
713
641
|
/**
|
|
714
642
|
* length = 2, `[state, increment]`
|
|
715
643
|
*/
|
|
716
644
|
#t;
|
|
717
645
|
static name = "PCGMinimal";
|
|
718
|
-
[Symbol.toStringTag] = M.name;
|
|
719
646
|
bits = 32;
|
|
720
647
|
/**
|
|
721
648
|
* @param seeds
|
|
@@ -731,16 +658,16 @@ class M {
|
|
|
731
658
|
* const betterRng = new PCGMinimal(seed);
|
|
732
659
|
*/
|
|
733
660
|
constructor(t) {
|
|
734
|
-
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(
|
|
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);
|
|
735
662
|
}
|
|
736
663
|
/** step inner state */
|
|
737
664
|
#n() {
|
|
738
|
-
this.#t[0] = this.#t[0] *
|
|
665
|
+
this.#t[0] = this.#t[0] * G + this.#t[1];
|
|
739
666
|
}
|
|
740
667
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
741
668
|
get #e() {
|
|
742
669
|
const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
|
|
743
|
-
return
|
|
670
|
+
return P(r, e);
|
|
744
671
|
}
|
|
745
672
|
/**
|
|
746
673
|
*
|
|
@@ -756,8 +683,8 @@ class M {
|
|
|
756
683
|
if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
|
|
757
684
|
if (t <= 0)
|
|
758
685
|
throw Error("'bound' must be positive");
|
|
759
|
-
const r = 4294967296 % t,
|
|
760
|
-
for (let
|
|
686
|
+
const r = 4294967296 % t, o = 1e5;
|
|
687
|
+
for (let s = 0; s < o; ++s) {
|
|
761
688
|
const i = this.getU32Rand();
|
|
762
689
|
if (i >= r)
|
|
763
690
|
return i % t;
|
|
@@ -779,17 +706,19 @@ class M {
|
|
|
779
706
|
yield typeof e == "number" ? this.getBoundedU32Rand(e) : this.getU32Rand();
|
|
780
707
|
}
|
|
781
708
|
}
|
|
782
|
-
|
|
709
|
+
Object.defineProperty(N.prototype, Symbol.toStringTag, {
|
|
710
|
+
value: N.name
|
|
711
|
+
});
|
|
712
|
+
const z = [
|
|
783
713
|
0xbe562cb412e2260en,
|
|
784
714
|
0x2e4284137d641affn,
|
|
785
715
|
0x4e19b36ee933e27en,
|
|
786
716
|
0x7581cf8c4f4d4f7dn
|
|
787
717
|
];
|
|
788
|
-
class
|
|
718
|
+
class x {
|
|
789
719
|
bits = 64;
|
|
790
720
|
#t;
|
|
791
721
|
static name = "XoshiroMinimal";
|
|
792
|
-
[Symbol.toStringTag] = T.name;
|
|
793
722
|
/**
|
|
794
723
|
* @param seeds
|
|
795
724
|
* `BigUint64Array` with length 4. \
|
|
@@ -801,17 +730,18 @@ class T {
|
|
|
801
730
|
*
|
|
802
731
|
* // you should construct with random seeds.
|
|
803
732
|
* const seed = crypto.getRandomValues(new BigUint64Array(4));
|
|
804
|
-
* const betterRng = new
|
|
733
|
+
* const betterRng = new XoshiroMinimal(seed);
|
|
805
734
|
*/
|
|
806
735
|
constructor(t) {
|
|
807
|
-
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(
|
|
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);
|
|
808
737
|
}
|
|
809
738
|
#n() {
|
|
810
739
|
const t = this.#t[1] << 17n;
|
|
811
|
-
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] =
|
|
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);
|
|
812
741
|
}
|
|
813
742
|
get value() {
|
|
814
|
-
|
|
743
|
+
const t = b(this.#t[0] + this.#t[3], 23n) + this.#t[0];
|
|
744
|
+
return BigInt.asUintN(64, t);
|
|
815
745
|
}
|
|
816
746
|
getU64Rand() {
|
|
817
747
|
const t = this.value;
|
|
@@ -827,8 +757,8 @@ class T {
|
|
|
827
757
|
throw Error("'bound' exceeded limit");
|
|
828
758
|
if (t <= 0n)
|
|
829
759
|
throw Error("'bound' must be positive");
|
|
830
|
-
const r = e % t,
|
|
831
|
-
for (let
|
|
760
|
+
const r = e % t, o = 1e5;
|
|
761
|
+
for (let s = 0; s < o; ++s) {
|
|
832
762
|
const i = this.getU64Rand();
|
|
833
763
|
if (i >= r)
|
|
834
764
|
return i % t;
|
|
@@ -856,41 +786,48 @@ class T {
|
|
|
856
786
|
yield e === void 0 ? this.getU32Rand() : this.getBoundedU32Rand(e);
|
|
857
787
|
}
|
|
858
788
|
}
|
|
789
|
+
Object.defineProperty(x.prototype, Symbol.toStringTag, {
|
|
790
|
+
value: x.name
|
|
791
|
+
});
|
|
859
792
|
export {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
T as
|
|
866
|
-
x 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,
|
|
867
799
|
rt as compress,
|
|
868
|
-
|
|
800
|
+
gt as decodeLEB128,
|
|
869
801
|
et as decodeRFC3986URIComponent,
|
|
870
802
|
st as decompress,
|
|
871
|
-
|
|
803
|
+
dt as encodeLEB128,
|
|
872
804
|
nt as encodeRFC3986URIComponent,
|
|
873
|
-
|
|
805
|
+
_ as exEuclidean,
|
|
874
806
|
it as factorial,
|
|
875
|
-
|
|
807
|
+
D as fromBase64,
|
|
808
|
+
at as fromBase64Url,
|
|
809
|
+
ht as fromOct,
|
|
876
810
|
Q as getHash,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
811
|
+
A as getRandBIByBitLength,
|
|
812
|
+
v as getRandBIByRange,
|
|
813
|
+
ft as getRandPrimeByBitLength,
|
|
880
814
|
ct as getRandPrimeByRange,
|
|
881
815
|
ot as getRndInt,
|
|
816
|
+
W as getStringTag,
|
|
882
817
|
g as isDeepStrictEqual,
|
|
883
818
|
tt as isNode,
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
819
|
+
O as isSquare,
|
|
820
|
+
B as jacobiSymbol,
|
|
821
|
+
Y as lazify,
|
|
887
822
|
p as modPow,
|
|
888
823
|
Z as parseCSV,
|
|
889
|
-
|
|
824
|
+
H as promiseWithResolvers,
|
|
890
825
|
m as residue,
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
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
|
|
896
833
|
};
|
package/dist/bundle.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
`&&!s?(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=p.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()},J=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},G=(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},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 s=Array.from(r,i=>i.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 Error("rangeError");const e=t-n,r=e.toString(2).length,s=(()=>{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+s},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=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},C=(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],[i,o,a]=[0n,-1n,t];for(;;){const l=s/a,u=s-l*a;if(u===0n)break;[e,i]=[i,e-l*i],[r,o]=[o,r-l*o],[s,a]=[a,u]}return a<0n&&(i*=-1n,o*=-1n,a*=-1n),{x:i,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 s=n+r|1n,i=I(n,s),o=I(s,t);return i*o},H=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let i=s-1n;i>-1n;--i){const o=(n>>i)+1n|1n;r*=I(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 H(n)<<t},j=(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},_=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,s]=[t,e];let o=b(2n,r,n);if(o===1n)return!0;for(let a=0n;a<s;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&&_(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),Q=(n,t,e,r)=>{let s=1n,i=e;const o=n.toString(2).slice(1);for(const a of o)[s,i]=[y(s*i,t),U(i*i+r*s*s,t)],a==="1"&&([s,i]=[U(e*s+i,t),U(r*s+e*i,t)]);return[s,i]},tt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,i=0n;for(;s%2n===0n;)s>>=1n,i+=1n;const[o,a]=Q(s,n,e,t);let l=a;if(o===0n)return!0;r=b(r,s,n);for(let u=0n;u<i;u++){if(l===0n)return!0;l=y(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 i of t)if(n%i===0n)return n===i;if(!Y(n))return!1;const[e,r]=Z(n);if(r===0n)return!1;const s=(1n-e)/4n;return tt(n,e,1n,s)},nt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=v(n,t);if(E(s))return s}throw Error("noPrimesFound")},et=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=w(n,t);if(E(s))return s}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";[Symbol.toStringTag]=f.name;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)),i=t-Number(s);if(i===0)return new f(r?-s:s,1n);t=1/i;let[o,a]=[1n,s],[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}=C(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),i=r.at(2);if(!s||!i)throw Error("cannot parse");return new f(BigInt(s),BigInt(i))}}const rt=new TextEncoder,st=new TextDecoder,it=(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,s=>Number.parseInt(s[0],16))}case"oct":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),i=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(i,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),s=Array.from(r,i=>Number.parseInt(i[0],2));return Uint8Array.from(s)}default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ot=(n,t)=>{switch(t){case"utf-8":return st.decode(n);case"base64":{const e=Array.from(n,r=>String.fromCharCode(r)).join("");return btoa(e)}case"base64url":{const e=Array.from(n,s=>String.fromCharCode(s)).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 s=e.matchAll(/.{6}/g);return Array.from(s,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,s=Math.floor(e/7)+1;return r?s-1:s},at=n=>{const t=ct(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const i=Number(n&127n)|128;e[s]=i,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 s=BigInt(n[r]&127);e+=s<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class R{#t;#n;static name="Queue";[Symbol.toStringTag]=R.name;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()}}class N extends Error{name;static name="NamedError";[Symbol.toStringTag]=N.name;constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const i=this.cause;return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?i:typeof i=="bigint"?i.toString():typeof i=="object"&&i!==null?i instanceof Set||i instanceof Map?Object.fromEntries(i):i:void 0})(),{name:e,message:r,stack:s}=this;return{name:e,message:r,stack:s,cause:t}}}const P=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="FloatRand";[Symbol.toStringTag]=A.name;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)}}})(),s=r&255;let i=126;if(s===0){i-=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(i-=32,i<0){i=0;break t}}else{i-=P(g);break t}++d}}else i-=P(s);const o=r>>>8&8388607;o===0&&r>>>31&&++i;const{buffer:a,byteOffset:l,length:u}=Uint32Array.from([i<<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())}})(),s=r&0x7ffn;let i=e-1n;if(s===0n){i-=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(i-=64n,i<t){i=t;break t}}else{i-=F(g);break t}++d}}else i-=F(s);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++i;const{buffer:a,byteOffset:l,length:u}=BigUint64Array.from([i<<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")}}const ut=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],ft=0x5851f42d4c957f2dn;class T{#t;static name="PCGMinimal";[Symbol.toStringTag]=T.name;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 j(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,s=1e5;for(let i=0;i<s;++i){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()}}const ht=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class M{bits=64;#t;static name="XoshiroMinimal";[Symbol.toStringTag]=M.name;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,s=1e5;for(let i=0;i<s;++i){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)}}c.FloatRng=A,c.NamedError=N,c.PCGMinimal=T,c.Queue=R,c.Rational=f,c.XoshiroMinimal=M,c.bailliePSW=E,c.compress=W,c.decodeLEB128=lt,c.decodeRFC3986URIComponent=z,c.decompress=J,c.encodeLEB128=at,c.encodeRFC3986URIComponent=K,c.exEuclidean=C,c.factorial=X,c.fromString=it,c.getHash=D,c.getRandBIByBitLength=w,c.getRandBIByRange=v,c.getRandPrimeByBitLength=et,c.getRandPrimeByRange=nt,c.getRndInt=G,c.isDeepStrictEqual=m,c.isNode=q,c.isSquare=_,c.jacobiSymbol=B,c.lazify=$,c.modPow=b,c.parseCSV=k,c.promiseWithResolvers=V,c.residue=y,c.rot32=j,c.rot64=S,c.sameValueZero=x,c.sleep=O,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/fraction.d.ts
CHANGED
package/dist/main.d.ts
CHANGED
package/dist/named-error.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ interface NamedError<EName extends string> {
|
|
|
6
6
|
declare class NamedError<EName extends string> extends Error {
|
|
7
7
|
readonly name: EName;
|
|
8
8
|
static readonly name = "NamedError";
|
|
9
|
-
readonly [Symbol.toStringTag] = "NamedError";
|
|
10
9
|
constructor(name: EName, message: string, cause?: unknown);
|
|
11
10
|
toJSON(): {
|
|
12
11
|
name: EName;
|
package/dist/pcg-minimal.d.ts
CHANGED
package/dist/random.d.ts
CHANGED
|
@@ -8,8 +8,7 @@ export interface RandomGenerator64 {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class FloatRng<TRng extends RandomGenerator32 | RandomGenerator64> {
|
|
10
10
|
#private;
|
|
11
|
-
static readonly name = "
|
|
12
|
-
readonly [Symbol.toStringTag] = "FloatRand";
|
|
11
|
+
static readonly name = "FloatRng";
|
|
13
12
|
constructor(rng: TRng);
|
|
14
13
|
/**
|
|
15
14
|
* returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
|
package/dist/u8arr-ext.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
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
|
|
@@ -8,7 +8,6 @@ export declare class XoshiroMinimal implements RandomGenerator64 {
|
|
|
8
8
|
#private;
|
|
9
9
|
readonly bits = 64;
|
|
10
10
|
static readonly name = "XoshiroMinimal";
|
|
11
|
-
readonly [Symbol.toStringTag] = "XoshiroMinimal";
|
|
12
11
|
/**
|
|
13
12
|
* @param seeds
|
|
14
13
|
* `BigUint64Array` with length 4. \
|
|
@@ -20,7 +19,7 @@ export declare class XoshiroMinimal implements RandomGenerator64 {
|
|
|
20
19
|
*
|
|
21
20
|
* // you should construct with random seeds.
|
|
22
21
|
* const seed = crypto.getRandomValues(new BigUint64Array(4));
|
|
23
|
-
* const betterRng = new
|
|
22
|
+
* const betterRng = new XoshiroMinimal(seed);
|
|
24
23
|
*/
|
|
25
24
|
constructor(seed?: BigUint64Array<ArrayBuffer>);
|
|
26
25
|
get value(): bigint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"types": "./dist/main.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
"types": "./dist/main.d.ts",
|
|
17
|
-
"import": "./dist/bundle.js"
|
|
18
|
-
"require": null
|
|
17
|
+
"import": "./dist/bundle.js"
|
|
19
18
|
},
|
|
20
19
|
"engines": {
|
|
21
20
|
"node": "^22",
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
"vitest": "^3.2.4"
|
|
36
35
|
},
|
|
37
36
|
"volta": {
|
|
38
|
-
"node": "22.
|
|
37
|
+
"node": "22.21.0"
|
|
39
38
|
},
|
|
40
39
|
"scripts": {
|
|
41
40
|
"dev": "vite",
|
package/dist/queue.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare class Queue<T> {
|
|
2
|
-
#private;
|
|
3
|
-
static readonly name = "Queue";
|
|
4
|
-
readonly [Symbol.toStringTag] = "Queue";
|
|
5
|
-
/**
|
|
6
|
-
* Queue
|
|
7
|
-
* @param data
|
|
8
|
-
*/
|
|
9
|
-
constructor(...data: T[]);
|
|
10
|
-
/**
|
|
11
|
-
* enqueue data
|
|
12
|
-
* @param data
|
|
13
|
-
* @returns current queue length
|
|
14
|
-
*/
|
|
15
|
-
enqueue(...data: T[]): number;
|
|
16
|
-
/**
|
|
17
|
-
* dequeue data
|
|
18
|
-
* @returns data in the head
|
|
19
|
-
*/
|
|
20
|
-
dequeue(): T | undefined;
|
|
21
|
-
toArray(): T[];
|
|
22
|
-
toJSON(): T[];
|
|
23
|
-
toString(): string;
|
|
24
|
-
}
|