@tktb-tess/util-fns 0.13.3 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import { ID } from './async_worker_type';
2
- export declare const postSuccess: <TRecv>(value: TRecv, id: ID) => void;
3
- export declare const postFailed: (error: unknown, id: ID) => void;
2
+ export declare function postSuccess<TRecv>(value: TRecv, id: ID): void;
3
+ export declare function postFailed(error: unknown, id: ID): void;
@@ -1,5 +1,6 @@
1
1
  //#region lib/async_worker_post.ts
2
- var e = () => typeof window > "u" && typeof self < "u" && "importScripts" in self, t = (t, n) => {
2
+ var e = () => typeof window > "u" && typeof self < "u" && "importScripts" in self;
3
+ function t(t, n) {
3
4
  if (!e()) throw Error("this function must be used in Worker");
4
5
  let r = {
5
6
  success: !0,
@@ -7,7 +8,8 @@ var e = () => typeof window > "u" && typeof self < "u" && "importScripts" in sel
7
8
  id: n
8
9
  };
9
10
  self.postMessage(r);
10
- }, n = (t, n) => {
11
+ }
12
+ function n(t, n) {
11
13
  if (!e()) throw Error("this function must be used in Worker");
12
14
  let r = {
13
15
  success: !1,
@@ -15,6 +17,6 @@ var e = () => typeof window > "u" && typeof self < "u" && "importScripts" in sel
15
17
  id: n
16
18
  };
17
19
  self.postMessage(r);
18
- };
20
+ }
19
21
  //#endregion
20
22
  export { n as postFailed, t as postSuccess };
@@ -3,24 +3,24 @@
3
3
  * @param n tested integer
4
4
  * @returns whether `n` is a prime
5
5
  */
6
- export declare const bailliePSW: (n: bigint) => boolean;
6
+ export declare function bailliePSW(n: bigint): boolean;
7
7
  /**
8
8
  * returns probable prime of `min` or more and less than `max`
9
9
  * @param min minimum
10
10
  * @param max upper limit
11
11
  * @returns
12
12
  */
13
- export declare const getRandPrimeByRange: (min: bigint, max: bigint) => bigint;
13
+ export declare function getRandPrimeByRange(min: bigint, max: bigint): bigint;
14
14
  /**
15
15
  * returns probable prime of `bitLength` bit
16
16
  * @param bitLength bit length of probable prime
17
17
  * @param fixed `true`: fixed to `bitLength`, `false` (default): variable bit length of `bitLength` or under
18
18
  * @returns
19
19
  */
20
- export declare const getRandPrimeByBitLength: (bitLength: number, fixed?: boolean) => bigint;
20
+ export declare function getRandPrimeByBitLength(bitLength: number, fixed?: boolean): bigint;
21
21
  /**
22
22
  * worker async version of `bailliePSW()` \
23
23
  * only available in esm context
24
24
  * @param n
25
25
  */
26
- export declare const bailliePSWAsync: (n: bigint) => Promise<boolean>;
26
+ export declare function bailliePSWAsync(n: bigint): Promise<boolean>;
@@ -1,104 +1,8 @@
1
- import { n as e, t } from "./mod_pow-S-7GJ74l.js";
1
+ import { n as e, t } from "./mod_pow--lOK7jfy.js";
2
2
  import { isSquare as n, jacobiSymbol as r } from "./math.js";
3
3
  import { getRandBIByBitLength as i, getRandBIByRange as a } from "./random.js";
4
4
  //#region lib/baillie_psw.ts
5
- var o = [
6
- 2n,
7
- 3n,
8
- 5n,
9
- 7n,
10
- 11n,
11
- 13n,
12
- 17n,
13
- 19n,
14
- 23n,
15
- 29n,
16
- 31n,
17
- 37n,
18
- 41n,
19
- 43n,
20
- 47n,
21
- 53n,
22
- 59n,
23
- 61n,
24
- 67n,
25
- 71n,
26
- 73n,
27
- 79n,
28
- 83n,
29
- 89n,
30
- 97n,
31
- 101n,
32
- 103n,
33
- 107n,
34
- 109n,
35
- 113n,
36
- 127n,
37
- 131n,
38
- 137n,
39
- 139n,
40
- 149n,
41
- 151n,
42
- 157n,
43
- 163n,
44
- 167n,
45
- 173n,
46
- 179n,
47
- 181n,
48
- 191n,
49
- 193n,
50
- 197n,
51
- 199n,
52
- 211n,
53
- 223n,
54
- 227n,
55
- 229n,
56
- 233n,
57
- 239n,
58
- 241n,
59
- 251n,
60
- 257n,
61
- 263n,
62
- 269n,
63
- 271n,
64
- 277n,
65
- 281n,
66
- 283n,
67
- 293n,
68
- 307n,
69
- 311n,
70
- 313n,
71
- 317n,
72
- 331n,
73
- 337n,
74
- 347n,
75
- 349n,
76
- 353n,
77
- 359n,
78
- 367n,
79
- 373n,
80
- 379n,
81
- 383n,
82
- 389n,
83
- 397n,
84
- 401n,
85
- 409n,
86
- 419n,
87
- 421n,
88
- 431n,
89
- 433n,
90
- 439n,
91
- 443n,
92
- 449n,
93
- 457n,
94
- 461n,
95
- 463n,
96
- 467n,
97
- 479n,
98
- 487n,
99
- 491n,
100
- 499n
101
- ], s = (e) => {
5
+ function o(e) {
102
6
  if (e <= 1n) return !1;
103
7
  if (e % 2n == 0n) return e === 2n;
104
8
  let n = e - 1n, r = 0n;
@@ -110,25 +14,29 @@ var o = [
110
14
  o = o * o % e;
111
15
  }
112
16
  return !1;
113
- }, c = (e) => {
17
+ }
18
+ function s(e) {
114
19
  let t = 5n;
115
20
  for (;;) {
116
21
  let i = r(t, e);
117
22
  if (i === -1n) return t;
118
23
  if (i === 0n || (t = t > 0n ? -(t + 2n) : -(t - 2n), t === -15n && n(e))) return null;
119
24
  }
120
- }, l = (t, n) => {
25
+ }
26
+ function c(t, n) {
121
27
  if ((n & 1n) == 0n) throw Error("`n` is not odd");
122
28
  return (t & 1n) == 1n ? e(t + n >> 1n, n) : e(t >> 1n, n);
123
- }, u = (t, n, r, i) => {
29
+ }
30
+ function l(t, n, r, i) {
124
31
  let a = 1n, o = r, s = t.toString(2).slice(1);
125
- for (let t of s) [a, o] = [e(a * o, n), l(o * o + i * a * a, n)], t === "1" && ([a, o] = [l(r * a + o, n), l(i * a + r * o, n)]);
32
+ for (let t of s) [a, o] = [e(a * o, n), c(o * o + i * a * a, n)], t === "1" && ([a, o] = [c(r * a + o, n), c(i * a + r * o, n)]);
126
33
  return [a, o];
127
- }, d = (n, r, i, a) => {
34
+ }
35
+ function u(n, r, i, a) {
128
36
  if (n % 2n != 1n) throw RangeError("`n` must be odd");
129
37
  let o = n + 1n, s = 0n;
130
38
  for (; o % 2n == 0n;) o >>= 1n, s += 1n;
131
- let [c, l] = u(o, n, i, r), d = l;
39
+ let [c, u] = l(o, n, i, r), d = u;
132
40
  if (c === 0n) return !0;
133
41
  a = t(a, o, n);
134
42
  for (let r = 0n; r < s; r++) {
@@ -136,30 +44,89 @@ var o = [
136
44
  d = e(d * d - 2n * a, n), a = t(a, 2n, n);
137
45
  }
138
46
  return !1;
139
- }, f = (e) => {
47
+ }
48
+ function d(e) {
140
49
  if (e <= 1n) return !1;
141
50
  if (e % 2n == 0n) return e === 2n;
142
- for (let t of o) if (e % t === 0n) return e === t;
143
- if (!s(e)) return !1;
144
- let t = c(e);
145
- return t == null ? !1 : d(e, t, 1n, (1n - t) / 4n);
146
- }, p = (e, t) => {
51
+ for (let t of [
52
+ 2n,
53
+ 3n,
54
+ 5n,
55
+ 7n,
56
+ 11n,
57
+ 13n,
58
+ 17n,
59
+ 19n,
60
+ 23n,
61
+ 29n,
62
+ 31n,
63
+ 37n,
64
+ 41n,
65
+ 43n,
66
+ 47n,
67
+ 53n,
68
+ 59n,
69
+ 61n,
70
+ 67n,
71
+ 71n,
72
+ 73n,
73
+ 79n,
74
+ 83n,
75
+ 89n,
76
+ 97n,
77
+ 101n,
78
+ 103n,
79
+ 107n,
80
+ 109n,
81
+ 113n,
82
+ 127n,
83
+ 131n,
84
+ 137n,
85
+ 139n,
86
+ 149n,
87
+ 151n,
88
+ 157n,
89
+ 163n,
90
+ 167n,
91
+ 173n,
92
+ 179n,
93
+ 181n,
94
+ 191n,
95
+ 193n,
96
+ 197n,
97
+ 199n,
98
+ 211n,
99
+ 223n,
100
+ 227n,
101
+ 229n,
102
+ 233n,
103
+ 239n,
104
+ 241n,
105
+ 251n
106
+ ]) if (e % t === 0n) return e === t;
107
+ if (!o(e)) return !1;
108
+ let t = s(e);
109
+ return t == null ? !1 : u(e, t, 1n, (1n - t) / 4n);
110
+ }
111
+ function f(e, t) {
147
112
  if (t < 2n) throw RangeError("`max` must be 2 or larger");
148
113
  for (let n = 0; n < 1e5; n++) {
149
114
  let n = a(e, t);
150
- if (f(n)) return n;
115
+ if (d(n)) return n;
151
116
  }
152
117
  throw Error("no primes were found");
153
- }, m = (e, t = !1) => {
118
+ }
119
+ function p(e, t = !1) {
154
120
  if (e < 2) throw RangeError("`bitLength` must be 2 or larger");
155
121
  for (let n = 0; n < 1e5; n++) {
156
122
  let n = i(e, t);
157
- if (f(n)) return n;
123
+ if (d(n)) return n;
158
124
  }
159
125
  throw Error("no primes were found");
160
- }, h = async (e) => {
161
- let { getWorker: t } = await import("./bpsw_worker_wrap-Ex4MZHGr.js");
162
- return (await t()).postMessage(e);
163
- };
126
+ }
127
+ async function m(e) {
128
+ let { getWorker: t } = await import("./bpsw_worker_wrap-BtWQ4Gha.js");
129
+ return t().postMessage(e);
130
+ }
164
131
  //#endregion
165
- export { f as bailliePSW, h as bailliePSWAsync, m as getRandPrimeByBitLength, p as getRandPrimeByRange };
132
+ export { d as bailliePSW, m as bailliePSWAsync, p as getRandPrimeByBitLength, f as getRandPrimeByRange };
@@ -1,4 +1,4 @@
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>;
1
+ export declare function toBase64(bin: Uint8Array): string;
2
+ export declare function fromBase64(base64: string): Uint8Array<ArrayBuffer>;
3
+ export declare function toBase64URL(bin: Uint8Array): string;
4
+ export declare function fromBase64URL(base64URL: string): Uint8Array<ArrayBuffer>;
@@ -1,13 +1,16 @@
1
1
  //#region lib/base64.ts
2
- var e = (e) => {
3
- let t = Array.from(e, (e) => String.fromCharCode(e));
4
- return btoa(t.join(""));
5
- }, t = (e) => {
6
- let t = atob(e);
7
- return Uint8Array.from(t, (e) => e.charCodeAt(0));
8
- }, n = (t) => e(t).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), r = (e) => {
9
- let n = 4 - (e.length & 3) & 3;
10
- return t(e.concat("=".repeat(n)).replaceAll("-", "+").replaceAll("_", "/"));
11
- };
2
+ function e(e) {
3
+ return btoa(e.reduce((e, t) => e + String.fromCharCode(t), ""));
4
+ }
5
+ function t(e) {
6
+ return Uint8Array.from(atob(e), (e) => e.charCodeAt(0));
7
+ }
8
+ function n(t) {
9
+ return e(t).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
10
+ }
11
+ function r(e) {
12
+ for (; e.length & 3;) e += "=";
13
+ return t(e.replaceAll("-", "+").replaceAll("_", "/"));
14
+ }
12
15
  //#endregion
13
16
  export { t as fromBase64, r as fromBase64URL, e as toBase64, n as toBase64URL };
@@ -0,0 +1,23 @@
1
+ import { AsyncWorker as e } from "./async_worker.js";
2
+ //#region lib/bpsw_worker.ts?worker&inline
3
+ var t = "(function(){function e(e,t){t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n}function t(t,n,r){if(r<1n)throw RangeError(\"`mod` must be positive\");if(n<0n)throw RangeError(\"`power` must not be negative\");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i}function n(e,t){if(t<1n||t%2n==0n)throw RangeError(\"`n` is out of range\");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n}function r(e){if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n}function i(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1}function a(e){let t=5n;for(;;){let i=n(t,e);if(i===-1n)return t;if(i===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&r(e)))return null}}function o(t,n){if((n&1n)==0n)throw Error(\"`n` is not odd\");return(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n)}function s(t,n,r,i){let a=1n,s=r,c=t.toString(2).slice(1);for(let t of c)[a,s]=[e(a*s,n),o(s*s+i*a*a,n)],t===`1`&&([a,s]=[o(r*a+s,n),o(i*a+r*s,n)]);return[a,s]}function c(n,r,i,a){if(n%2n!=1n)throw RangeError(\"`n` must be odd\");let o=n+1n,c=0n;for(;o%2n==0n;)o>>=1n,c+=1n;let[l,u]=s(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<c;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1}function l(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n])if(e%t===0n)return e===t;if(!i(e))return!1;let t=a(e);return t==null?!1:c(e,t,1n,(1n-t)/4n)}let u=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self;function d(e,t){if(!u())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)}function f(e,t){if(!u())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)}let p=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{d(l(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;f({name:t,message:r,stack:i,cause:p(a)},n)}else f({name:`BPSWError`,message:`unidentified error`,cause:p(e)},n)}}})();", n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", t], { type: "text/javascript;charset=utf-8" });
4
+ function r(e) {
5
+ let r;
6
+ try {
7
+ if (r = n && (self.URL || self.webkitURL).createObjectURL(n), !r) throw "";
8
+ let t = new Worker(r, { name: e?.name });
9
+ return t.addEventListener("error", () => {
10
+ (self.URL || self.webkitURL).revokeObjectURL(r);
11
+ }), t;
12
+ } catch {
13
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(t), { name: e?.name });
14
+ }
15
+ }
16
+ //#endregion
17
+ //#region lib/bpsw_worker_wrap.ts
18
+ var i = null;
19
+ function a() {
20
+ return i ||= new e(new r({ name: "bpsw_worker" })), i;
21
+ }
22
+ //#endregion
23
+ export { a as getWorker };
@@ -1,2 +1,2 @@
1
1
  import { AsyncWorker } from './async_worker';
2
- export declare const getWorker: () => Promise<AsyncWorker<bigint, boolean>>;
2
+ export declare function getWorker(): AsyncWorker<bigint, boolean>;
@@ -4,14 +4,14 @@
4
4
  * @param format
5
5
  * @returns
6
6
  */
7
- export declare const compress: (raw: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
7
+ export declare function compress(raw: Uint8Array<ArrayBuffer>, format: CompressionFormat): Promise<Uint8Array<ArrayBuffer>>;
8
8
  /**
9
9
  * Decompress binary data
10
10
  * @param compressed
11
11
  * @param format
12
12
  * @returns
13
13
  */
14
- export declare const decompress: (compressed: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
14
+ export declare function decompress(compressed: Uint8Array<ArrayBuffer>, format: CompressionFormat): Promise<Uint8Array<ArrayBuffer>>;
15
15
  /**
16
16
  * Compress string into Base64(URL)-encoded string
17
17
  * @param str
@@ -19,7 +19,7 @@ export declare const decompress: (compressed: Uint8Array<ArrayBuffer>, format: C
19
19
  * @param encoding default: `base64url`
20
20
  * @returns
21
21
  */
22
- export declare const compressString: (str: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
22
+ export declare function compressString(str: string, format?: CompressionFormat, encoding?: 'base64' | 'base64url'): Promise<string>;
23
23
  /**
24
24
  * Decompress Base64(URL)-encoded data
25
25
  * @param compressedString
@@ -27,4 +27,4 @@ export declare const compressString: (str: string, format: CompressionFormat, en
27
27
  * @param encoding default: `base64url`
28
28
  * @returns
29
29
  */
30
- export declare const decompressString: (compressedString: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
30
+ export declare function decompressString(compressedString: string, format?: CompressionFormat, encoding?: 'base64' | 'base64url'): Promise<string>;
@@ -1,19 +1,20 @@
1
1
  import { fromBase64 as e, fromBase64URL as t, toBase64 as n, toBase64URL as r } from "./base64.js";
2
2
  //#region lib/compression.ts
3
- var i = (e, t) => {
3
+ function i(e, t) {
4
4
  let n = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
5
5
  return new Response(n).bytes();
6
- }, a = (e, t) => {
6
+ }
7
+ function a(e, t) {
7
8
  let n = new Blob([e]).stream().pipeThrough(new DecompressionStream(t));
8
9
  return new Response(n).bytes();
9
- }, o = async (e, t, i = "base64url") => {
10
+ }
11
+ async function o(e, t = "deflate-raw", i = "base64url") {
10
12
  let a = new Blob([e]).stream().pipeThrough(new CompressionStream(t)), o = await new Response(a).bytes();
11
13
  return i === "base64" ? n(o) : r(o);
12
- }, s = (n, r, i = "base64url") => {
13
- let a;
14
- a = i === "base64" ? e(n) : t(n);
15
- let o = new Blob([a]).stream().pipeThrough(new DecompressionStream(r));
14
+ }
15
+ function s(n, r = "deflate-raw", i = "base64url") {
16
+ let a = i === "base64" ? e(n) : t(n), o = new Blob([a]).stream().pipeThrough(new DecompressionStream(r));
16
17
  return new Response(o).text();
17
- };
18
+ }
18
19
  //#endregion
19
20
  export { i as compress, o as compressString, a as decompress, s as decompressString };
@@ -0,0 +1 @@
1
+ export declare function getTextEncoder(): TextEncoder;
@@ -4,10 +4,10 @@
4
4
  * @param b
5
5
  * @returns
6
6
  */
7
- export declare const sameValueZero: (a: unknown, b: unknown) => boolean;
7
+ export declare function sameValueZero(a: unknown, b: unknown): boolean;
8
8
  /**
9
9
  * Judges whether two objects has the same (nested) properties \
10
10
  * Compares with SameValueZero, ignores symbol keys in an object
11
11
  * @returns
12
12
  */
13
- export declare const isDeepStrictEqual: (a: unknown, b: unknown) => boolean;
13
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
@@ -1,5 +1,8 @@
1
1
  //#region lib/equality.ts
2
- var e = (e, t) => [e].includes(t), t = (e, n) => {
2
+ function e(e, t) {
3
+ return [e].includes(t);
4
+ }
5
+ function t(e, n) {
3
6
  if (typeof e != typeof n) return !1;
4
7
  let r = Object.prototype.toString.call(e);
5
8
  if (r !== Object.prototype.toString.call(n)) return !1;
@@ -24,6 +27,6 @@ var e = (e, t) => [e].includes(t), t = (e, n) => {
24
27
  return !0;
25
28
  }
26
29
  throw TypeError(`comparing these objects is unavailable: ${e}, ${n}`, { cause: [e, n] });
27
- };
30
+ }
28
31
  //#endregion
29
32
  export { t as isDeepStrictEqual, e as sameValueZero };
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncWorker as e } from "./async_worker.js";
2
2
  import { postFailed as t, postSuccess as n } from "./async_worker_post.js";
3
- import { n as r, t as i } from "./mod_pow-S-7GJ74l.js";
3
+ import { n as r, t as i } from "./mod_pow--lOK7jfy.js";
4
4
  import { exEuclidean as a, factorial as o, isSquare as s, jacobiSymbol as c, rot32 as l, rot64 as u } from "./math.js";
5
5
  import { floatRng as d, getRandBIByBitLength as f, getRandBIByRange as p, getRndInt as m } from "./random.js";
6
6
  import { bailliePSW as h, bailliePSWAsync as g, getRandPrimeByBitLength as _, getRandPrimeByRange as v } from "./baillie_psw.js";
@@ -13,6 +13,6 @@ import { decodeLEB128 as j, encodeLEB128 as M } from "./leb128.js";
13
13
  import { NamedError as N } from "./named_error.js";
14
14
  import { fromOct as P, toOct as F } from "./oct.js";
15
15
  import { PCGMinimal as I } from "./pcg_minimal.js";
16
- import { createWorker as L, decodeRFC3986URIComponent as R, encodeRFC3986URIComponent as z, getHash as B, getStringTag as V, lazify as H, nullableStrictAt as U, setTimeoutPromise as W, sleepSort as G, strictAt as K, withResolvers as q } from "./util.js";
16
+ import { a as L, c as R, d as z, i as B, l as V, n as H, o as U, r as W, s as G, t as K, u as q } from "./util-f4z6xA0b.js";
17
17
  import { XoshiroMinimal as J } from "./xoshiro_minimal.js";
18
- export { e as AsyncWorker, A as FixedUint8Array, N as NamedError, I as PCGMinimal, k as Rational, J as XoshiroMinimal, h as bailliePSW, g as bailliePSWAsync, C as compress, w as compressString, L as createWorker, j as decodeLEB128, R as decodeRFC3986URIComponent, T as decompress, E as decompressString, M as encodeLEB128, z as encodeRFC3986URIComponent, a as exEuclidean, o as factorial, d as floatRng, y as fromBase64, b as fromBase64URL, P as fromOct, B as getHash, f as getRandBIByBitLength, p as getRandBIByRange, _ as getRandPrimeByBitLength, v as getRandPrimeByRange, m as getRndInt, V as getStringTag, D as isDeepStrictEqual, s as isSquare, c as jacobiSymbol, H as lazify, i as modPow, U as nullableStrictAt, t as postFailed, n as postSuccess, r as residue, l as rot32, u as rot64, O as sameValueZero, W as setTimeoutPromise, G as sleepSort, K as strictAt, x as toBase64, S as toBase64URL, F as toOct, q as withResolvers };
18
+ export { e as AsyncWorker, A as FixedUint8Array, N as NamedError, I as PCGMinimal, k as Rational, J as XoshiroMinimal, h as bailliePSW, g as bailliePSWAsync, C as compress, w as compressString, K as createWorker, j as decodeLEB128, H as decodeRFC3986URIComponent, T as decompress, E as decompressString, M as encodeLEB128, W as encodeRFC3986URIComponent, a as exEuclidean, o as factorial, d as floatRng, y as fromBase64, b as fromBase64URL, P as fromOct, B as getHash, f as getRandBIByBitLength, p as getRandBIByRange, _ as getRandPrimeByBitLength, v as getRandPrimeByRange, m as getRndInt, L as getStringTag, D as isDeepStrictEqual, s as isSquare, c as jacobiSymbol, U as lazify, i as modPow, G as nullableStrictAt, t as postFailed, n as postSuccess, r as residue, l as rot32, u as rot64, O as sameValueZero, R as setTimeoutPromise, V as sleepSort, q as strictAt, x as toBase64, S as toBase64URL, F as toOct, z as withResolvers };
@@ -3,10 +3,10 @@
3
3
  * @param bigint
4
4
  * @returns
5
5
  */
6
- export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
6
+ export declare function encodeLEB128(bigint: bigint): Uint8Array<ArrayBuffer>;
7
7
  /**
8
8
  * Decode LEB128 into bigint
9
9
  * @param LEB128
10
10
  * @returns
11
11
  */
12
- export declare const decodeLEB128: (LEB128: Uint8Array<ArrayBuffer>) => bigint;
12
+ export declare function decodeLEB128(LEB128: Uint8Array<ArrayBuffer>): bigint;
@@ -1,23 +1,18 @@
1
1
  //#region lib/leb128.ts
2
- var e = (e) => {
3
- let t = e < 0n;
4
- t && (e *= -1n);
5
- let n = e.toString(2).length, r = e === 1n << BigInt(n - 1) && !(n % 7) && t, i = Math.floor(n / 7) + 1;
6
- return r ? i - 1 : i;
7
- }, t = (t) => {
8
- let n = e(t);
9
- t = BigInt.asUintN(n * 7, t);
10
- let r = new Uint8Array(n);
11
- for (let e = 0; e < n - 1; ++e) r[e] = Number(t & 127n) | 128, t >>= 7n;
12
- let i = Number(t & 127n);
13
- return r[n - 1] = i, t >>= 7n, r;
14
- }, n = (e) => {
15
- let t = e.length, n = 0n;
16
- for (let [t, r] of e.entries()) {
17
- let e = BigInt(r & 127);
18
- n += e << BigInt(7 * t);
2
+ function e(e) {
3
+ let t = [];
4
+ for (;;) {
5
+ let n = Number(e & 127n);
6
+ e >>= 7n;
7
+ let r = n & 64;
8
+ if (e === 0n && r === 0 || e === -1n && r !== 0) return t.push(n), Uint8Array.from(t);
9
+ t.push(n | 128);
19
10
  }
20
- return BigInt.asIntN(7 * t, n);
21
- };
11
+ }
12
+ function t(e) {
13
+ let t = 0n, n = 0;
14
+ for (let r of e) if (t |= BigInt(r & 127) << BigInt(n), n += 7, !(r & 128)) return BigInt.asIntN(n, t);
15
+ return n += 7, BigInt.asIntN(n, t);
16
+ }
22
17
  //#endregion
23
- export { n as decodeLEB128, t as encodeLEB128 };
18
+ export { t as decodeLEB128, e as encodeLEB128 };
@@ -8,7 +8,7 @@ export { residue, modPow } from './mod_pow';
8
8
  * @param b
9
9
  * @returns
10
10
  */
11
- export declare const exEuclidean: (a: bigint, b: bigint) => {
11
+ export declare function exEuclidean(a: bigint, b: bigint): {
12
12
  x: bigint;
13
13
  y: bigint;
14
14
  gcd: bigint;
@@ -19,30 +19,30 @@ export declare const exEuclidean: (a: bigint, b: bigint) => {
19
19
  * @param n integer
20
20
  * @returns factorial of `n`
21
21
  */
22
- export declare const factorial: (n: bigint) => bigint;
22
+ export declare function factorial(n: bigint): bigint;
23
23
  /**
24
24
  * 32-bit rorate (number)
25
25
  * @param value
26
26
  * @param rot
27
27
  * @returns
28
28
  */
29
- export declare const rot32: (value: number, rot: number) => number;
29
+ export declare function rot32(value: number, rot: number): number;
30
30
  /**
31
31
  * 64-bit rorate (bigint)
32
32
  * @param value
33
33
  * @param rot
34
34
  * @returns
35
35
  */
36
- export declare const rot64: (value: bigint, rot: bigint) => bigint;
36
+ export declare function rot64(value: bigint, rot: bigint): bigint;
37
37
  /**
38
38
  * Jacobi symbol `(a/n)`
39
39
  * @param a positive integer
40
40
  * @param n positive odd integer
41
41
  */
42
- export declare const jacobiSymbol: (a: bigint, n: bigint) => bigint;
42
+ export declare function jacobiSymbol(a: bigint, n: bigint): bigint;
43
43
  /**
44
44
  * Whether an input number is square
45
45
  * @param n
46
46
  * @returns
47
47
  */
48
- export declare const isSquare: (n: bigint) => boolean;
48
+ export declare function isSquare(n: bigint): boolean;
package/dist/esm/math.js CHANGED
@@ -1,6 +1,6 @@
1
- import { n as e, t } from "./mod_pow-S-7GJ74l.js";
1
+ import { n as e, t } from "./mod_pow--lOK7jfy.js";
2
2
  //#region lib/math.ts
3
- var n = (e, t) => {
3
+ function n(e, t) {
4
4
  if (e === 0n && t === 0n) return {
5
5
  x: 0n,
6
6
  y: 0n,
@@ -43,7 +43,8 @@ var n = (e, t) => {
43
43
  y: o,
44
44
  gcd: s
45
45
  };
46
- }, r = (e, t) => {
46
+ }
47
+ function r(e, t) {
47
48
  if (e >= t) return 1n;
48
49
  let n = BigInt((t - 2n).toString(2).length), i = (t - e) / 2n;
49
50
  if (n * i < 63n) {
@@ -53,19 +54,28 @@ var n = (e, t) => {
53
54
  }
54
55
  let a = e + i | 1n;
55
56
  return r(e, a) * r(a, t);
56
- }, i = (e) => {
57
+ }
58
+ function i(e) {
57
59
  let t = 3n, n = 1n, i = 1n, a = BigInt(e.toString(2).length) - 1n;
58
60
  for (let o = a - 1n; o > -1n; --o) {
59
61
  let a = (e >> o) + 1n | 1n;
60
62
  i *= r(t, a), t = a, n *= i;
61
63
  }
62
64
  return n;
63
- }, a = (e) => {
65
+ }
66
+ function a(e) {
64
67
  if (e < 0n) throw RangeError("'n' must be non-negative");
65
68
  if (e === 0n) return 1n;
66
69
  let t = e - BigInt(e.toString(2).match(/1/g)?.length ?? 0);
67
70
  return i(e) << t;
68
- }, o = (e, t) => (e >>> (t & 31) | e << (-t & 31)) >>> 0, s = (e, t) => BigInt.asUintN(64, e >> (t & 63n) | e << (-t & 63n)), c = (e, t) => {
71
+ }
72
+ function o(e, t) {
73
+ return (e >>> (t & 31) | e << (-t & 31)) >>> 0;
74
+ }
75
+ function s(e, t) {
76
+ return BigInt.asUintN(64, e >> (t & 63n) | e << (-t & 63n));
77
+ }
78
+ function c(e, t) {
69
79
  if (t < 1n || t % 2n == 0n) throw RangeError("`n` is out of range");
70
80
  for (; e < 0n;) e += t;
71
81
  e %= t;
@@ -79,7 +89,8 @@ var n = (e, t) => {
79
89
  [e, t] = [t, e], e % 4n == 3n && t % 4n == 3n && (n *= -1n), e %= t;
80
90
  }
81
91
  return t === 1n ? n : 0n;
82
- }, l = (e) => {
92
+ }
93
+ function l(e) {
83
94
  if (e < 0n) return !1;
84
95
  if (e === 0n) return !0;
85
96
  let t = 1n, n = e;
@@ -88,6 +99,6 @@ var n = (e, t) => {
88
99
  r * r < e ? t = r : n = r;
89
100
  }
90
101
  return e === t ** 2n || e === (t + 1n) ** 2n;
91
- };
102
+ }
92
103
  //#endregion
93
104
  export { n as exEuclidean, a as factorial, l as isSquare, c as jacobiSymbol, t as modPow, e as residue, o as rot32, s as rot64 };
@@ -1,9 +1,10 @@
1
1
  //#region lib/mod_pow.ts
2
- var e = (e, t) => {
2
+ function e(e, t) {
3
3
  t < 0n && (t *= -1n);
4
4
  let n = e % t;
5
5
  return n < 0n ? n + t : n;
6
- }, t = (t, n, r) => {
6
+ }
7
+ function t(t, n, r) {
7
8
  if (r < 1n) throw RangeError("`mod` must be positive");
8
9
  if (n < 0n) throw RangeError("`power` must not be negative");
9
10
  if (t = e(t, r), r === 1n) return 0n;
@@ -12,6 +13,6 @@ var e = (e, t) => {
12
13
  let i = 1n;
13
14
  for (; n > 0n;) n & 1n && (i = i * t % r), t = t * t % r, n >>= 1n;
14
15
  return i;
15
- };
16
+ }
16
17
  //#endregion
17
18
  export { e as n, t };
@@ -4,7 +4,7 @@
4
4
  * @param modulo
5
5
  * @returns
6
6
  */
7
- export declare const residue: (n: bigint, modulo: bigint) => bigint;
7
+ export declare function residue(n: bigint, modulo: bigint): bigint;
8
8
  /**
9
9
  * Calculates modpow
10
10
  * @param base
@@ -12,4 +12,4 @@ export declare const residue: (n: bigint, modulo: bigint) => bigint;
12
12
  * @param mod
13
13
  *
14
14
  */
15
- export declare const modPow: (base: bigint, power: bigint, mod: bigint) => bigint;
15
+ export declare function modPow(base: bigint, power: bigint, mod: bigint): bigint;
package/dist/esm/oct.d.ts CHANGED
@@ -4,10 +4,10 @@
4
4
  * @param bin a binary array
5
5
  * @returns
6
6
  */
7
- export declare const toOct: (bin: Uint8Array) => string;
7
+ export declare function toOct(bin: Uint8Array): string;
8
8
  /**
9
9
  * Constructs `Uint8Array` from octal string \
10
10
  * A string length must be multiples of 8
11
11
  * @param oct octal string
12
12
  */
13
- export declare const fromOct: (oct: string) => Uint8Array<ArrayBuffer>;
13
+ export declare function fromOct(oct: string): Uint8Array<ArrayBuffer>;
package/dist/esm/oct.js CHANGED
@@ -1,24 +1,25 @@
1
1
  //#region lib/oct.ts
2
- var e = (e) => {
2
+ function e(e) {
3
3
  if (e.length % 3 != 0) throw Error("The array length of input must be multiples of 3");
4
- let t = e.length / 3, n = Array.from({ length: t }, (t, n) => [
4
+ let t = e.length / 3;
5
+ return Array.from({ length: t }, (t, n) => [
5
6
  0,
6
7
  1,
7
8
  2
8
- ].reduce((t, r) => t | (e[3 * n + r] ?? 0) << 16 - 8 * r, 0)), r = 8 * t;
9
- return n.map((e) => e.toString(8).padStart(8, "0")).slice(0, r).join("");
10
- }, t = (e) => {
9
+ ].reduce((t, r) => t | (e[3 * n + r] ?? 0) << 16 - 8 * r, 0)).reduce((e, t) => e + t.toString(8).padStart(8, "0"), "");
10
+ }
11
+ function t(e) {
11
12
  if (e.length & 7) throw Error("A string length must be multiples of 8");
12
13
  let t = e.matchAll(/.{8}/g), n = Array.from(t, (e) => {
13
14
  let t = Number.parseInt(e[0], 8);
14
15
  if (Number.isNaN(t)) throw TypeError("Invalid input");
15
- return t;
16
- }).map((e) => [
17
- 0,
18
- 1,
19
- 2
20
- ].map((t) => e >>> 16 - 8 * t & 255)).flat();
16
+ return [
17
+ 0,
18
+ 1,
19
+ 2
20
+ ].map((e) => t >>> 16 - 8 * e & 255);
21
+ }).flat();
21
22
  return Uint8Array.from(n);
22
- };
23
+ }
23
24
  //#endregion
24
25
  export { t as fromOct, e as toOct };
@@ -8,14 +8,14 @@ export declare class PCGMinimal {
8
8
  static readonly name = "PCGMinimal";
9
9
  /**
10
10
  * @param seeds
11
- * `BigUint64Array` with length 2. \
11
+ * `BigUint64Array` with length 2 or longer. \
12
12
  * if it is not given, initialized by default value
13
13
  * @example
14
- * // the following example is always initialized by the same seeds.
14
+ * // The following example is always initialized by the same seeds.
15
15
  * // not recommended
16
16
  * const rng = new PCGMinimal();
17
17
  *
18
- * // you should construct with random seeds.
18
+ * // You should construct with random seeds.
19
19
  * const seed = crypto.getRandomValues(new BigUint64Array(2));
20
20
  * const betterRng = new PCGMinimal(seed);
21
21
  */
@@ -31,11 +31,12 @@ export declare class PCGMinimal {
31
31
  readonly getBoundedRandU32: (bound: number) => number;
32
32
  /**
33
33
  *
34
- * @param step the number of needed random integers
34
+ * @param iterNum the number of needed random integers
35
35
  * @param bound upper limit
36
36
  * @returns
37
37
  * the iterator that generates random 32-bit unsigned integers `step` times \
38
38
  * if `bound` is given, random integers are less than `bound`
39
39
  */
40
- genRandU32s(step: number, bound?: number): Generator<number, void, unknown>;
40
+ genRandU32s(iterNum: number, bound?: number): Generator<number, void, unknown>;
41
+ readonly stream: (byteLen: number) => ReadableStream<Uint8Array<ArrayBuffer>>;
41
42
  }
@@ -5,8 +5,8 @@ var t = [9600629759793949339n, 15726070495360670683n], n = 6364136223846793005n,
5
5
  static name = r;
6
6
  constructor(e) {
7
7
  if (e && e[0] != null && e[1] != null) {
8
- if (this.#e = new BigUint64Array(2), this.#e[0] == null || this.#e[1] == null) throw TypeError("unexpected");
9
- this.#e[1] = e[1] << 1n | 1n, this.#t(), this.#e[0] += e[0], this.#t();
8
+ let t = e[1] << 1n | 1n;
9
+ this.#e = BigUint64Array.from([e[0] + t, t]), this.#t();
10
10
  } else this.#e = BigUint64Array.from(t);
11
11
  }
12
12
  #t() {
@@ -34,6 +34,25 @@ var t = [9600629759793949339n, 15726070495360670683n], n = 6364136223846793005n,
34
34
  if (e <= 0) throw RangeError("'step' must be positive");
35
35
  for (let n = 0; n < e; n++) yield typeof t == "number" ? this.getBoundedRandU32(t) : this.getRandU32();
36
36
  }
37
+ stream = (e) => {
38
+ let t, n = e;
39
+ return new ReadableStream({
40
+ start: (e) => {
41
+ let r = () => {
42
+ if (n <= 0) {
43
+ e.close();
44
+ return;
45
+ }
46
+ let i = Uint32Array.from([this.getRandU32()]), a = Math.min(n, 4);
47
+ e.enqueue(new Uint8Array(i.buffer, 0, a)), n -= a, t = setTimeout(r, 20);
48
+ };
49
+ t = setTimeout(r, 10);
50
+ },
51
+ cancel: (e) => {
52
+ clearTimeout(t), console.log("stream is cancelled: ", e);
53
+ }
54
+ });
55
+ };
37
56
  };
38
57
  Object.defineProperty(i.prototype, Symbol.toStringTag, { value: r });
39
58
  //#endregion
@@ -3,7 +3,7 @@
3
3
  * @param getRandU64 function that returns a random 64-bit unsigned int
4
4
  * @returns function that returns a random 64-bit float
5
5
  */
6
- export declare const floatRng: (getRandU64: () => bigint) => () => number;
6
+ export declare function floatRng(getRandU64: () => bigint): () => number;
7
7
  /**
8
8
  * Returns random numbers with `length` bits or shorter, or just `length` bits
9
9
  * @param length bit length
@@ -11,18 +11,18 @@ export declare const floatRng: (getRandU64: () => bigint) => () => number;
11
11
  * false (default): variable length with `length` bits or shorter
12
12
  *
13
13
  */
14
- export declare const getRandBIByBitLength: (length: number, fixed?: boolean) => bigint;
14
+ export declare function getRandBIByBitLength(length: number, fixed?: boolean): bigint;
15
15
  /**
16
16
  * Returns a random integer of `min` or more and less than `max`
17
17
  * @param min minimum
18
18
  * @param max upper limit
19
19
  * @returns
20
20
  */
21
- export declare const getRandBIByRange: (min: bigint, max: bigint) => bigint;
21
+ export declare function getRandBIByRange(min: bigint, max: bigint): bigint;
22
22
  /**
23
23
  * Returns an integer of `min` or more and less than `max`
24
24
  * @param min
25
25
  * @param max
26
26
  *
27
27
  */
28
- export declare const getRndInt: (min: number, max: number) => number;
28
+ export declare function getRndInt(min: number, max: number): number;
@@ -1,11 +1,12 @@
1
- import { t as e } from "./mod_pow-S-7GJ74l.js";
1
+ import { t as e } from "./mod_pow--lOK7jfy.js";
2
2
  //#region lib/random.ts
3
- var t = (e) => {
3
+ function t(e) {
4
4
  if (e === 0n) return 64n;
5
5
  let t = 0n;
6
6
  for (; e > 0n && !(e & 1n);) ++t, e >>= 1n;
7
7
  return BigInt.asUintN(64, t);
8
- }, n = (e, n) => {
8
+ }
9
+ function n(e, n) {
9
10
  let r = 0n, i = e & 2047n, a = 1023n - 1n;
10
11
  if (i > 0n) return a -= t(i), a;
11
12
  a -= 11n;
@@ -15,7 +16,8 @@ var t = (e) => {
15
16
  if (a -= 64n, a < r) return r;
16
17
  }
17
18
  throw Error("loop exceeded limit");
18
- }, r = (e) => {
19
+ }
20
+ function r(e) {
19
21
  let t = () => BigInt.asUintN(64, e()), r = () => {
20
22
  let e = t(), r = BigInt.asUintN(52, e >> 11n), i = r === 0n && e >> 63n == 1n ? n(e, t) + 1n : n(e, t), { buffer: a } = BigUint64Array.from([i << 52n | r]), o = new Float64Array(a)[0];
21
23
  if (o == null) throw Error("unexpected");
@@ -28,12 +30,14 @@ var t = (e) => {
28
30
  }
29
31
  throw Error("Loop limit exceeded");
30
32
  };
31
- }, i = (e, t = !1) => {
33
+ }
34
+ function i(e, t = !1) {
32
35
  if (!Number.isFinite(e)) throw RangeError("`length` is not a valid number");
33
36
  if (e <= 0) throw RangeError("`length` must be positive");
34
- let n = Math.ceil(e / 8), r = crypto.getRandomValues(new Uint8Array(n)), i = Array.from(r, (e) => e.toString(2).padStart(8, "0")).join("").slice(0, e);
35
- return t && (i = i.replace(/^\d/, "1")), BigInt("0b" + i);
36
- }, a = (t, n) => {
37
+ let n = Math.ceil(e / 8), r = crypto.getRandomValues(new Uint8Array(n)).reduce((e, t) => e + t.toString(2).padStart(8, "0"), "").slice(0, e);
38
+ return t && (r = r.replace(/^\d/, "1")), BigInt("0b" + r);
39
+ }
40
+ function a(t, n) {
37
41
  if (t >= n) throw RangeError("`min` must be smaller than `max`");
38
42
  let r = n - t, a = r.toString(2).length;
39
43
  return t + (() => {
@@ -43,6 +47,9 @@ var t = (e) => {
43
47
  }
44
48
  throw Error("Failed to generate a random bigint");
45
49
  })();
46
- }, o = (e, t) => Math.floor(Math.random() * (t - e) + e);
50
+ }
51
+ function o(e, t) {
52
+ return Math.floor(Math.random() * (t - e) + e);
53
+ }
47
54
  //#endregion
48
55
  export { r as floatRng, i as getRandBIByBitLength, a as getRandBIByRange, o as getRndInt };
@@ -0,0 +1,73 @@
1
+ //#region lib/encoder.ts
2
+ var e = null, t = null, n = 1e3 * 30;
3
+ function r() {
4
+ return e ||= new TextEncoder(), t != null && clearTimeout(t), t = setTimeout(() => {
5
+ e = null, t = null;
6
+ }, n), e;
7
+ }
8
+ //#endregion
9
+ //#region lib/util.ts
10
+ function i() {
11
+ let e, t;
12
+ return {
13
+ promise: new Promise((n, r) => {
14
+ e = n, t = r;
15
+ }),
16
+ resolve: e,
17
+ reject: t
18
+ };
19
+ }
20
+ function a(e) {
21
+ return Object.prototype.toString.call(e).slice(8, -1);
22
+ }
23
+ function o(e) {
24
+ return (...t) => () => e(...t);
25
+ }
26
+ async function s(e, t) {
27
+ let n = r().encode(e), i = await crypto.subtle.digest(t, n);
28
+ return new Uint8Array(i);
29
+ }
30
+ function c(e) {
31
+ return encodeURIComponent(e).replace(/[!'()*]/g, (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`);
32
+ }
33
+ function l(e) {
34
+ if (e.includes("+")) throw URIError("an input string must not include `+`");
35
+ return decodeURIComponent(e);
36
+ }
37
+ function u(e, t) {
38
+ return new Promise((n, r) => {
39
+ setTimeout(async () => {
40
+ try {
41
+ n(await e());
42
+ } catch (e) {
43
+ r(e);
44
+ }
45
+ }, t);
46
+ });
47
+ }
48
+ function d(e, t) {
49
+ if (t < -e.length || t >= e.length) throw RangeError("`index` is out of range");
50
+ return e.at(t);
51
+ }
52
+ function f(e, t) {
53
+ let n = d(e, t);
54
+ if (n == null) throw TypeError("value is nullable");
55
+ return n;
56
+ }
57
+ async function p(e) {
58
+ let t = [], n = [];
59
+ return e.forEach((e) => {
60
+ let r = new Promise((n) => {
61
+ setTimeout(() => {
62
+ t.push(e), n();
63
+ }, e);
64
+ });
65
+ n.push(r);
66
+ }), await Promise.all(n), t;
67
+ }
68
+ function m(e, t) {
69
+ let n = `(()=>{${`self.onmessage=${e};`}${t ? `self.onerror=${t};` : ""}})();`.replace(/\s+/g, " "), r = new Blob([n], { type: "text/javascript;charset=UTF-8" }), i = URL.createObjectURL(r);
70
+ return setTimeout(() => URL.revokeObjectURL(i), 1e3 * 60), new Worker(i);
71
+ }
72
+ //#endregion
73
+ export { a, u as c, i as d, s as i, p as l, l as n, o, c as r, d as s, m as t, f as u };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A polyfill for `Promise.withResolvers()`
3
3
  */
4
- export declare const withResolvers: <T>() => {
4
+ export declare function withResolvers<T>(): {
5
5
  promise: Promise<T>;
6
6
  resolve: (value: T | PromiseLike<T>) => void;
7
7
  reject: (reason?: unknown) => void;
@@ -11,59 +11,58 @@ export declare const withResolvers: <T>() => {
11
11
  * @param obj
12
12
  * @returns
13
13
  */
14
- export declare const getStringTag: (obj: unknown) => string;
14
+ export declare function getStringTag(obj: unknown): string;
15
15
  /**
16
16
  * Makes a function lazy
17
17
  * @param func function
18
18
  * @returns lazified function
19
19
  */
20
- export declare const lazify: <TArgs extends unknown[], TRet>(func: (...args: TArgs) => TRet) => (...args: TArgs) => () => TRet;
20
+ export declare function lazify<TArgs extends unknown[], TRet>(func: (...args: TArgs) => TRet): (...args: TArgs) => () => TRet;
21
21
  /**
22
22
  * Returns hash of a string
23
23
  * @param str string
24
24
  * @param algorithm hash algorithm
25
- * @param encoder text encoder, if not given, construct it internally
26
25
  * @returns hash
27
26
  */
28
- export declare const getHash: (str: string, algorithm: AlgorithmIdentifier, encoder?: TextEncoder) => Promise<Uint8Array<ArrayBuffer>>;
27
+ export declare function getHash(str: string, algorithm: AlgorithmIdentifier): Promise<Uint8Array<ArrayBuffer>>;
29
28
  /**
30
29
  * Encodes a text string as a valid component of a URI and compatible with RFC3986.
31
30
  * @param URIComponent
32
31
  * @returns
33
32
  */
34
- export declare const encodeRFC3986URIComponent: (URIComponent: string | number | boolean) => string;
33
+ export declare function encodeRFC3986URIComponent(URIComponent: string | number | boolean): string;
35
34
  /**
36
35
  * Gets the unencoded version of an RFC3986-compatible encoded component of a URI.
37
36
  * @param encodedURIComponent
38
37
  * @throws An input string has '+'
39
38
  * @returns
40
39
  */
41
- export declare const decodeRFC3986URIComponent: (encodedURIComponent: string) => string;
40
+ export declare function decodeRFC3986URIComponent(encodedURIComponent: string): string;
42
41
  /**
43
42
  * Schedules execution of a one-time `callback` after `delay` milliseconds, and returns promise resolved by a return value of `callback`.
44
43
  * @param callback
45
44
  * @param delay
46
45
  * @returns
47
46
  */
48
- export declare const setTimeoutPromise: <TRtrn>(callback: () => TRtrn, delay?: number) => Promise<TRtrn>;
47
+ export declare function setTimeoutPromise<T>(callback: () => T, delay?: number): Promise<T>;
49
48
  /**
50
49
  * `Array.prototype.at()` with boundary check, nullable value is acceptable
51
50
  * @param array
52
51
  * @param index
53
52
  * @returns
54
53
  */
55
- export declare const nullableStrictAt: <T>(array: T[], index: number) => T | undefined;
54
+ export declare function nullableStrictAt<T>(array: T[], index: number): T | undefined;
56
55
  /**
57
56
  * `Array.prototype.at()` with boundary check and non-nullable check
58
57
  * @param array
59
58
  * @param index
60
59
  * @returns
61
60
  */
62
- export declare const strictAt: <T extends {}>(array: T[], index: number) => T;
61
+ export declare function strictAt<T extends {}>(array: T[], index: number): T;
63
62
  /**
64
63
  * The best sorting alorithm you've ever seen
65
64
  * @param array
66
65
  * @returns
67
66
  */
68
- export declare const sleepSort: (array: number[]) => Promise<number[]>;
69
- export declare const createWorker: (onmessage: (ev: MessageEvent<unknown>) => void, onerror?: (ev: ErrorEvent) => void) => Worker;
67
+ export declare function sleepSort(array: number[]): Promise<number[]>;
68
+ export declare function createWorker(onmessage: (ev: MessageEvent<unknown>) => void, onerror?: (ev: ErrorEvent) => void): Worker;
package/dist/esm/util.js CHANGED
@@ -1,47 +1,2 @@
1
- //#region lib/util.ts
2
- var e = () => {
3
- let e, t;
4
- return {
5
- promise: new Promise((n, r) => {
6
- e = n, t = r;
7
- }),
8
- resolve: e,
9
- reject: t
10
- };
11
- }, t = (e) => Object.prototype.toString.call(e).slice(8, -1), n = (e) => (...t) => () => e(...t), r = async (e, t, n) => {
12
- let r = (n ?? new TextEncoder()).encode(e), i = await crypto.subtle.digest(t, r);
13
- return new Uint8Array(i);
14
- }, i = (e) => encodeURIComponent(e).replace(/[!'()*]/g, (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`), a = (e) => {
15
- if (e.includes("+")) throw URIError("an input string must not include `+`");
16
- return decodeURIComponent(e);
17
- }, o = (e, t) => new Promise((n, r) => {
18
- setTimeout(async () => {
19
- try {
20
- n(await e());
21
- } catch (e) {
22
- r(e);
23
- }
24
- }, t);
25
- }), s = (e, t) => {
26
- if (t < -e.length || t >= e.length) throw RangeError("`index` is out of range");
27
- return e.at(t);
28
- }, c = (e, t) => {
29
- let n = s(e, t);
30
- if (n == null) throw TypeError("value is nullable");
31
- return n;
32
- }, l = async (e) => {
33
- let t = [], n = [];
34
- return e.forEach((e) => {
35
- let r = new Promise((n) => {
36
- setTimeout(() => {
37
- t.push(e), n();
38
- }, e);
39
- });
40
- n.push(r);
41
- }), await Promise.all(n), t;
42
- }, u = (e, t) => {
43
- let n = `data:text/javascript;charset=UTF-8,${i(`(()=>{${`self.onmessage=${e};`}${t ? `self.onerror=${t};` : ""}})();`.replace(/\s+/g, " "))}`;
44
- return new Worker(n);
45
- };
46
- //#endregion
47
- export { u as createWorker, a as decodeRFC3986URIComponent, i as encodeRFC3986URIComponent, r as getHash, t as getStringTag, n as lazify, s as nullableStrictAt, o as setTimeoutPromise, l as sleepSort, c as strictAt, e as withResolvers };
1
+ import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./util-f4z6xA0b.js";
2
+ export { l as createWorker, a as decodeRFC3986URIComponent, s as encodeRFC3986URIComponent, r as getHash, e as getStringTag, o as lazify, c as nullableStrictAt, t as setTimeoutPromise, i as sleepSort, u as strictAt, n as withResolvers };
@@ -1 +1 @@
1
- var UtilFns=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t)=>()=>(e&&(t=e(e=0)),t),r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},i=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},a=e=>Object.prototype.toString.call(e).slice(8,-1),o=e=>(...t)=>()=>e(...t),s=async(e,t,n)=>{let r=(n??new TextEncoder).encode(e),i=await crypto.subtle.digest(t,r);return new Uint8Array(i)},c=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),l=e=>{if(e.includes(`+`))throw URIError("an input string must not include `+`");return decodeURIComponent(e)},ee=(e,t)=>new Promise((n,r)=>{setTimeout(async()=>{try{n(await e())}catch(e){r(e)}},t)}),u=(e,t)=>{if(t<-e.length||t>=e.length)throw RangeError("`index` is out of range");return e.at(t)},te=(e,t)=>{let n=u(e,t);if(n==null)throw TypeError(`value is nullable`);return n},ne=async e=>{let t=[],n=[];return e.forEach(e=>{let r=new Promise(n=>{setTimeout(()=>{t.push(e),n()},e)});n.push(r)}),await Promise.all(n),t},re=(e,t)=>{let n=`data:text/javascript;charset=UTF-8,${c(`(()=>{${`self.onmessage=${e};`}${t?`self.onerror=${t};`:``}})();`.replace(/\s+/g,` `))}`;return new Worker(n)},d=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},f=(e,t,n)=>{if(n<1n)throw RangeError("`mod` must be positive");if(t<0n)throw RangeError("`power` must not be negative");if(e=d(e,n),n===1n)return 0n;if(e%n===1n||e%n===0n)return e;if(e===n-1n)return t&1n?n-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),e=e*e%n,t>>=1n;return r},p=(e,t)=>{if(e===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(e===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return e>0n?{x:1n,y:0n,gcd:e}:{x:-1n,y:0n,gcd:-e};let[n,r,i]=[1n,0n,e],[a,o,s]=[0n,-1n,t];for(;;){let e=i/s,t=i-e*s;if(t===0n)break;[n,a]=[a,n-e*a],[r,o]=[o,r-e*o],[i,s]=[s,t]}return s<0n&&(a*=-1n,o*=-1n,s*=-1n),{x:a,y:o,gcd:s}},m=(e,t)=>{if(e>=t)return 1n;let n=BigInt((t-2n).toString(2).length),r=(t-e)/2n;if(n*r<63n){let n=e;for(let r=e+2n;r<t;r+=2n)n*=r;return n}let i=e+r|1n;return m(e,i)*m(i,t)},ie=e=>{let t=3n,n=1n,r=1n,i=BigInt(e.toString(2).length)-1n;for(let a=i-1n;a>-1n;--a){let i=(e>>a)+1n|1n;r*=m(t,i),t=i,n*=r}return n},ae=e=>{if(e<0n)throw RangeError(`'n' must be non-negative`);if(e===0n)return 1n;let t=e-BigInt(e.toString(2).match(/1/g)?.length??0);return ie(e)<<t},h=(e,t)=>(e>>>(t&31)|e<<(-t&31))>>>0,g=(e,t)=>BigInt.asUintN(64,e>>(t&63n)|e<<(-t&63n)),_=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},v=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},y=e=>{if(e===0n)return 64n;let t=0n;for(;e>0n&&!(e&1n);)++t,e>>=1n;return BigInt.asUintN(64,t)},b=(e,t)=>{let n=0n,r=e&2047n,i=1023n-1n;if(r>0n)return i-=y(r),i;i-=11n;for(let e=0;e<1e5;++e){let e=t();if(e>0n)return i-=y(e),i;if(i-=64n,i<n)return n}throw Error(`loop exceeded limit`)},oe=e=>{let t=()=>BigInt.asUintN(64,e()),n=()=>{let e=t(),n=BigInt.asUintN(52,e>>11n),r=n===0n&&e>>63n==1n?b(e,t)+1n:b(e,t),{buffer:i}=BigUint64Array.from([r<<52n|n]),a=new Float64Array(i)[0];if(a==null)throw Error(`unexpected`);return a};return()=>{for(let e=0;e<1e5;++e){let e=n();if(e<1)return e}throw Error(`Loop limit exceeded`)}},x=(e,t=!1)=>{if(!Number.isFinite(e))throw RangeError("`length` is not a valid number");if(e<=0)throw RangeError("`length` must be positive");let n=Math.ceil(e/8),r=crypto.getRandomValues(new Uint8Array(n)),i=Array.from(r,e=>e.toString(2).padStart(8,`0`)).join(``).slice(0,e);return t&&(i=i.replace(/^\d/,`1`)),BigInt(`0b`+i)},S=(e,t)=>{if(e>=t)throw RangeError("`min` must be smaller than `max`");let n=t-e,r=n.toString(2).length;return e+(()=>{for(let e=0;e<1e5;e++){let e=x(r);if(e>=f(2n,BigInt(r),n))return e%n}throw Error(`Failed to generate a random bigint`)})()},C=(e,t)=>Math.floor(Math.random()*(t-e)+e),w,T,E,D,O,k=n((()=>{w=`AsyncWorker`,T=1n<<128n,E=0n,D=()=>{let e=`${E++}`;return E===T&&(E=0n),e},O=class{static name=w;#e;constructor(e){this.#e=e}postMessage=(e,t)=>new Promise((n,r)=>{let i=D(),a=new AbortController,{signal:o}=a;this.#e.addEventListener(`message`,e=>{let t=e.data;t.id===i&&(a.abort(),t.success?n(t.value):r(t.error))},{signal:o}),this.#e.addEventListener(`error`,e=>{a.abort(),r(e.error)},{signal:o});let s={value:e,id:i};this.#e.postMessage(s,t)})},Object.defineProperty(O.prototype,Symbol.toStringTag,{value:w,enumerable:!0})}));function se(e){let t;try{if(t=j&&(self.URL||self.webkitURL).createObjectURL(j),!t)throw``;let n=new Worker(t,{name:e?.name});return n.addEventListener(`error`,()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker(`data:text/javascript;charset=utf-8,`+encodeURIComponent(A),{name:e?.name})}}var A,j,ce=n((()=>{A='(function(){let e=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},t=(t,n,r)=>{if(r<1n)throw RangeError("`mod` must be positive");if(n<0n)throw RangeError("`power` must not be negative");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i},n=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},r=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},i=[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],a=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},o=e=>{let t=5n;for(;;){let i=n(t,e);if(i===-1n)return t;if(i===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&r(e)))return null}},s=(t,n)=>{if((n&1n)==0n)throw Error("`n` is not odd");return(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n)},c=(t,n,r,i)=>{let a=1n,o=r,c=t.toString(2).slice(1);for(let t of c)[a,o]=[e(a*o,n),s(o*o+i*a*a,n)],t===`1`&&([a,o]=[s(r*a+o,n),s(i*a+r*o,n)]);return[a,o]},l=(n,r,i,a)=>{if(n%2n!=1n)throw RangeError("`n` must be odd");let o=n+1n,s=0n;for(;o%2n==0n;)o>>=1n,s+=1n;let[l,u]=c(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<s;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1},u=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of i)if(e%t===0n)return e===t;if(!a(e))return!1;let t=o(e);return t==null?!1:l(e,t,1n,(1n-t)/4n)},d=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,f=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},p=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},m=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{f(u(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;p({name:t,message:r,stack:i,cause:m(a)},n)}else p({name:`BPSWError`,message:`unidentified error`,cause:m(e)},n)}}})();',j=typeof self<`u`&&self.Blob&&new Blob([`(self.URL || self.webkitURL).revokeObjectURL(self.location.href);`,A],{type:`text/javascript;charset=utf-8`})})),M=r({getWorker:()=>P}),N,P,le=n((()=>{k(),ce(),P=async()=>(N||=new O(new se({name:`bpsw_worker`})),N)})),ue=[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],de=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let t=e-1n,n=0n;for(;t%2n==0n;)t>>=1n,n+=1n;let[r,i]=[t,n],a=f(2n,r,e);if(a===1n)return!0;for(let t=0n;t<i;t++){if(a===e-1n)return!0;a=a*a%e}return!1},fe=e=>{let t=5n;for(;;){let n=_(t,e);if(n===-1n)return t;if(n===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&v(e)))return null}},F=(e,t)=>{if((t&1n)==0n)throw Error("`n` is not odd");return(e&1n)==1n?d(e+t>>1n,t):d(e>>1n,t)},pe=(e,t,n,r)=>{let i=1n,a=n,o=e.toString(2).slice(1);for(let e of o)[i,a]=[d(i*a,t),F(a*a+r*i*i,t)],e===`1`&&([i,a]=[F(n*i+a,t),F(r*i+n*a,t)]);return[i,a]},me=(e,t,n,r)=>{if(e%2n!=1n)throw RangeError("`n` must be odd");let i=e+1n,a=0n;for(;i%2n==0n;)i>>=1n,a+=1n;let[o,s]=pe(i,e,n,t),c=s;if(o===0n)return!0;r=f(r,i,e);for(let t=0n;t<a;t++){if(c===0n)return!0;c=d(c*c-2n*r,e),r=f(r,2n,e)}return!1},I=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of ue)if(e%t===0n)return e===t;if(!de(e))return!1;let t=fe(e);return t==null?!1:me(e,t,1n,(1n-t)/4n)},L=(e,t)=>{if(t<2n)throw RangeError("`max` must be 2 or larger");for(let n=0;n<1e5;n++){let n=S(e,t);if(I(n))return n}throw Error(`no primes were found`)},R=(e,t=!1)=>{if(e<2)throw RangeError("`bitLength` must be 2 or larger");for(let n=0;n<1e5;n++){let n=x(e,t);if(I(n))return n}throw Error(`no primes were found`)},z=async e=>{let{getWorker:t}=await Promise.resolve().then(()=>(le(),M));return(await t()).postMessage(e)},B=e=>{let t=Array.from(e,e=>String.fromCharCode(e));return btoa(t.join(``))},V=e=>{let t=atob(e);return Uint8Array.from(t,e=>e.charCodeAt(0))},H=e=>B(e).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``),U=e=>{let t=4-(e.length&3)&3;return V(e.concat(`=`.repeat(t)).replaceAll(`-`,`+`).replaceAll(`_`,`/`))},he=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return new Response(n).bytes()},ge=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(t));return new Response(n).bytes()},_e=async(e,t,n=`base64url`)=>{let r=new Blob([e]).stream().pipeThrough(new CompressionStream(t)),i=await new Response(r).bytes();return n===`base64`?B(i):H(i)},ve=(e,t,n=`base64url`)=>{let r;r=n===`base64`?V(e):U(e);let i=new Blob([r]).stream().pipeThrough(new DecompressionStream(t));return new Response(i).text()},ye=(e,t)=>[e].includes(t),W=(e,t)=>{if(typeof e!=typeof t)return!1;let n=Object.prototype.toString.call(e);if(n!==Object.prototype.toString.call(t))return!1;if(typeof e==`string`||typeof e==`bigint`||typeof e==`boolean`||typeof e==`symbol`||e==null)return e===t;if(typeof e==`number`)return e===t||e!==e&&t!==t;if(typeof e==`function`)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!W(e[n],t[n]))return!1;return!0}if(e instanceof Set&&t instanceof Set)return!!W([...e.values()],[...t.values()]);if(e instanceof Map&&t instanceof Map)return!(!W([...e.keys()],[...t.keys()])||!W([...e.values()],[...t.values()]));if(n===`[object Object]`){let n=e,r=t,i=Object.keys(n),a=Object.keys(r);for(let e of i){let t=a.find(t=>t===e);if(t==null)return!1;let[i,o]=[n[e],r[t]];if(!W(i,o))return!1}return!0}throw TypeError(`comparing these objects is unavailable: ${e}, ${t}`,{cause:[e,t]})},G=`Rational`,K=class e{#e;#t;static name=G;constructor(e,t){t===0n?(this.#t=0n,this.#e=e===0n?0n:e>0n?1n:-1n):t>0n?(this.#e=e,this.#t=t):(this.#e=-e,this.#t=-t),this.#n()}static fromDecimal(t,n=5){if(Number.isNaN(t))return new e(0n,0n);if(Math.abs(t)===1/0)return new e(t>0?1n:-1n,0n);let r=t<0;r&&(t*=-1);let i=BigInt(Math.floor(t)),a=t-Number(i);if(a===0)return new e(r?-i:i,1n);t=1/a;let[o,s]=[1n,i],[c,l]=[0n,1n];for(;`${l}`.length<=n;){let n=BigInt(Math.floor(t)),i=t-Number(n);if([o,s]=[s,n*s+o],[c,l]=[l,n*l+c],i===0)return new e(r?-s:s,l);t=1/i}return new e(r?-o:o,c)}#n=()=>{let{gcd:e}=p(this.#e,this.#t);e!==0n&&(this.#e/=e,this.#t/=e)};minus=()=>new e(-this.#e,this.#t);inverse=()=>new e(this.#t,this.#e);add=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#t+t.#e*this.#t,n)};substr=e=>this.add(e.minus());multiply=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#e,n)};divide=e=>this.multiply(e.inverse());mediant=t=>{let n=this.#t+t.#t;return new e(this.#e+t.#e,n)};toDecimal=()=>Number(this.#e)/Number(this.#t);toString=()=>this.#e===0n&&this.#t===0n?`NaN`:this.#e===0n?`0`:this.#t===0n?this.#e<0n?`-Infinity`:`Infinity`:this.#t===1n?`${this.#e}`:`${this.#e}/${this.#t}`;valueOf=()=>this.toDecimal();toJSON=()=>({type:`Rational`,value:[`0x`+this.#e.toString(16),`0x`+this.#t.toString(16)]});static fromData(t){return new e(BigInt(t.value[0]),BigInt(t.value[1]))}static parse(t){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!n)throw Error(`cannot parse`);let r=n.at(1),i=n.at(2);if(!r||!i)throw Error(`cannot parse`);return new e(BigInt(r),BigInt(i))}};Object.defineProperty(K.prototype,Symbol.toStringTag,{value:G});var be={new:e=>new Uint8Array(e),fromBuffer:(e,t,n)=>new Uint8Array(e,t,n)},q=`NamedError`,J=class extends Error{static name=q;errName;name;constructor(e,t,n){super(t,n),this.errName=e,this.name=e}toJSON=()=>{let e=(()=>{let e=this.cause;if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t})(),{errName:t,message:n,stack:r}=this;return{name:t,message:n,stack:r,cause:e}}};Object.defineProperty(J.prototype,Symbol.toStringTag,{value:q});var xe=e=>{if(e.length%3!=0)throw Error(`The array length of input must be multiples of 3`);let t=e.length/3,n=Array.from({length:t},(t,n)=>[0,1,2].reduce((t,r)=>t|(e[3*n+r]??0)<<16-8*r,0)),r=8*t;return n.map(e=>e.toString(8).padStart(8,`0`)).slice(0,r).join(``)},Se=e=>{if(e.length&7)throw Error(`A string length must be multiples of 8`);let t=e.matchAll(/.{8}/g),n=Array.from(t,e=>{let t=Number.parseInt(e[0],8);if(Number.isNaN(t))throw TypeError(`Invalid input`);return t}).map(e=>[0,1,2].map(t=>e>>>16-8*t&255)).flat();return Uint8Array.from(n)},Ce=[9600629759793949339n,15726070495360670683n],we=6364136223846793005n,Y=`PCGMinimal`,X=class{#e;static name=Y;constructor(e){if(e&&e[0]!=null&&e[1]!=null){if(this.#e=new BigUint64Array(2),this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[1]=e[1]<<1n|1n,this.#t(),this.#e[0]+=e[0],this.#t()}else this.#e=BigUint64Array.from(Ce)}#t(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[0]=this.#e[0]*we+this.#e[1]}get#n(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);let e=this.#e[0],t=Number(e>>59n);return h(Number(BigInt.asUintN(32,(e^e>>18n)>>27n)),t)}getRandU32=()=>(this.#t(),this.#n);getBoundedRandU32=e=>{let t=4294967296;if(e>t)throw RangeError("`bound` exceeded limit (2^32)");if(e<=0)throw RangeError(`'bound' must be positive`);let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU32();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};*genRandU32s(e,t){if(e<=0)throw RangeError(`'step' must be positive`);for(let n=0;n<e;n++)yield typeof t==`number`?this.getBoundedRandU32(t):this.getRandU32()}};Object.defineProperty(X.prototype,Symbol.toStringTag,{value:Y});var Te=[13715198867125970446n,3333371893450545919n,5627726498316411518n,8467276975966080893n],Z=`XoshiroMinimal`,Q=class{bits=64;#e;static name=Z;constructor(e){if(e&&e[0]!=null&&e[1]!=null&&e[2]!=null&&e[3]!=null){if(this.#e=new BigUint64Array(4),this.#e[0]=e[0],this.#e[1]=e[1],this.#t(),this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);this.#e[2]+=e[2],this.#e[3]+=e[3]}else this.#e=BigUint64Array.from(Te)}#t(){if(this.#e[0]==null||this.#e[1]==null||this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=this.#e[1]<<17n;this.#e[2]^=this.#e[0],this.#e[3]^=this.#e[1],this.#e[1]^=this.#e[2],this.#e[0]^=this.#e[3],this.#e[2]^=e,this.#e[3]=g(this.#e[3],45n)}get value(){if(this.#e[0]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=g(this.#e[0]+this.#e[3],23n)+this.#e[0];return BigInt.asUintN(64,e)}getRandU64=()=>{let e=this.value;return this.#t(),e};getRandU32=()=>{let e=BigInt.asUintN(32,this.getRandU64());return Number(e)};getBoundedRandU64=e=>{let t=1n<<64n;if(e>t)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU64();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};getBoundedRandU32=e=>{if(e>2**32)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let t=this.getBoundedRandU64(BigInt(e));return Number(t)};*genRandU64s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU64():this.getBoundedRandU64(t)}*genRandU32s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU32():this.getBoundedRandU32(t)}};Object.defineProperty(Q.prototype,Symbol.toStringTag,{value:Z});var $=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,Ee=(e,t)=>{if(!$())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},De=(e,t)=>{if(!$())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},Oe=e=>{let t=e<0n;t&&(e*=-1n);let n=e.toString(2).length,r=e===1n<<BigInt(n-1)&&!(n%7)&&t,i=Math.floor(n/7)+1;return r?i-1:i};return k(),e.AsyncWorker=O,e.FixedUint8Array=be,e.NamedError=J,e.PCGMinimal=X,e.Rational=K,e.XoshiroMinimal=Q,e.bailliePSW=I,e.bailliePSWAsync=z,e.compress=he,e.compressString=_e,e.createWorker=re,e.decodeLEB128=e=>{let t=e.length,n=0n;for(let[t,r]of e.entries()){let e=BigInt(r&127);n+=e<<BigInt(7*t)}return BigInt.asIntN(7*t,n)},e.decodeRFC3986URIComponent=l,e.decompress=ge,e.decompressString=ve,e.encodeLEB128=e=>{let t=Oe(e);e=BigInt.asUintN(t*7,e);let n=new Uint8Array(t);for(let r=0;r<t-1;++r)n[r]=Number(e&127n)|128,e>>=7n;let r=Number(e&127n);return n[t-1]=r,e>>=7n,n},e.encodeRFC3986URIComponent=c,e.exEuclidean=p,e.factorial=ae,e.floatRng=oe,e.fromBase64=V,e.fromBase64URL=U,e.fromOct=Se,e.getHash=s,e.getRandBIByBitLength=x,e.getRandBIByRange=S,e.getRandPrimeByBitLength=R,e.getRandPrimeByRange=L,e.getRndInt=C,e.getStringTag=a,e.isDeepStrictEqual=W,e.isSquare=v,e.jacobiSymbol=_,e.lazify=o,e.modPow=f,e.nullableStrictAt=u,e.postFailed=De,e.postSuccess=Ee,e.residue=d,e.rot32=h,e.rot64=g,e.sameValueZero=ye,e.setTimeoutPromise=ee,e.sleepSort=ne,e.strictAt=te,e.toBase64=B,e.toBase64URL=H,e.toOct=xe,e.withResolvers=i,e})({});
1
+ var UtilFns=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t)=>()=>(e&&(t=e(e=0)),t),r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},i=null,a=null,o=1e3*30;function s(){return i||=new TextEncoder,a!=null&&clearTimeout(a),a=setTimeout(()=>{i=null,a=null},o),i}function c(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function l(e){return Object.prototype.toString.call(e).slice(8,-1)}function ee(e){return(...t)=>()=>e(...t)}async function te(e,t){let n=s().encode(e),r=await crypto.subtle.digest(t,n);return new Uint8Array(r)}function u(e){return encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)}function ne(e){if(e.includes(`+`))throw URIError("an input string must not include `+`");return decodeURIComponent(e)}function re(e,t){return new Promise((n,r)=>{setTimeout(async()=>{try{n(await e())}catch(e){r(e)}},t)})}function d(e,t){if(t<-e.length||t>=e.length)throw RangeError("`index` is out of range");return e.at(t)}function ie(e,t){let n=d(e,t);if(n==null)throw TypeError(`value is nullable`);return n}async function ae(e){let t=[],n=[];return e.forEach(e=>{let r=new Promise(n=>{setTimeout(()=>{t.push(e),n()},e)});n.push(r)}),await Promise.all(n),t}function oe(e,t){let n=`(()=>{${`self.onmessage=${e};`}${t?`self.onerror=${t};`:``}})();`.replace(/\s+/g,` `),r=new Blob([n],{type:`text/javascript;charset=UTF-8`}),i=URL.createObjectURL(r);return setTimeout(()=>URL.revokeObjectURL(i),1e3*60),new Worker(i)}function f(e,t){t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n}function p(e,t,n){if(n<1n)throw RangeError("`mod` must be positive");if(t<0n)throw RangeError("`power` must not be negative");if(e=f(e,n),n===1n)return 0n;if(e%n===1n||e%n===0n)return e;if(e===n-1n)return t&1n?n-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),e=e*e%n,t>>=1n;return r}function m(e,t){if(e===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(e===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return e>0n?{x:1n,y:0n,gcd:e}:{x:-1n,y:0n,gcd:-e};let[n,r,i]=[1n,0n,e],[a,o,s]=[0n,-1n,t];for(;;){let e=i/s,t=i-e*s;if(t===0n)break;[n,a]=[a,n-e*a],[r,o]=[o,r-e*o],[i,s]=[s,t]}return s<0n&&(a*=-1n,o*=-1n,s*=-1n),{x:a,y:o,gcd:s}}function h(e,t){if(e>=t)return 1n;let n=BigInt((t-2n).toString(2).length),r=(t-e)/2n;if(n*r<63n){let n=e;for(let r=e+2n;r<t;r+=2n)n*=r;return n}let i=e+r|1n;return h(e,i)*h(i,t)}function g(e){let t=3n,n=1n,r=1n,i=BigInt(e.toString(2).length)-1n;for(let a=i-1n;a>-1n;--a){let i=(e>>a)+1n|1n;r*=h(t,i),t=i,n*=r}return n}function se(e){if(e<0n)throw RangeError(`'n' must be non-negative`);if(e===0n)return 1n;let t=e-BigInt(e.toString(2).match(/1/g)?.length??0);return g(e)<<t}function _(e,t){return(e>>>(t&31)|e<<(-t&31))>>>0}function v(e,t){return BigInt.asUintN(64,e>>(t&63n)|e<<(-t&63n))}function y(e,t){if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n}function b(e){if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n}function x(e){if(e===0n)return 64n;let t=0n;for(;e>0n&&!(e&1n);)++t,e>>=1n;return BigInt.asUintN(64,t)}function S(e,t){let n=0n,r=e&2047n,i=1023n-1n;if(r>0n)return i-=x(r),i;i-=11n;for(let e=0;e<1e5;++e){let e=t();if(e>0n)return i-=x(e),i;if(i-=64n,i<n)return n}throw Error(`loop exceeded limit`)}function ce(e){let t=()=>BigInt.asUintN(64,e()),n=()=>{let e=t(),n=BigInt.asUintN(52,e>>11n),r=n===0n&&e>>63n==1n?S(e,t)+1n:S(e,t),{buffer:i}=BigUint64Array.from([r<<52n|n]),a=new Float64Array(i)[0];if(a==null)throw Error(`unexpected`);return a};return()=>{for(let e=0;e<1e5;++e){let e=n();if(e<1)return e}throw Error(`Loop limit exceeded`)}}function C(e,t=!1){if(!Number.isFinite(e))throw RangeError("`length` is not a valid number");if(e<=0)throw RangeError("`length` must be positive");let n=Math.ceil(e/8),r=crypto.getRandomValues(new Uint8Array(n)).reduce((e,t)=>e+t.toString(2).padStart(8,`0`),``).slice(0,e);return t&&(r=r.replace(/^\d/,`1`)),BigInt(`0b`+r)}function w(e,t){if(e>=t)throw RangeError("`min` must be smaller than `max`");let n=t-e,r=n.toString(2).length;return e+(()=>{for(let e=0;e<1e5;e++){let e=C(r);if(e>=p(2n,BigInt(r),n))return e%n}throw Error(`Failed to generate a random bigint`)})()}function le(e,t){return Math.floor(Math.random()*(t-e)+e)}var T,E,D,O,k,A=n((()=>{T=`AsyncWorker`,E=1n<<128n,D=0n,O=()=>{let e=`${D++}`;return D===E&&(D=0n),e},k=class{static name=T;#e;constructor(e){this.#e=e}postMessage=(e,t)=>new Promise((n,r)=>{let i=O(),a=new AbortController,{signal:o}=a;this.#e.addEventListener(`message`,e=>{let t=e.data;t.id===i&&(a.abort(),t.success?n(t.value):r(t.error))},{signal:o}),this.#e.addEventListener(`error`,e=>{a.abort(),r(e.error)},{signal:o});let s={value:e,id:i};this.#e.postMessage(s,t)})},Object.defineProperty(k.prototype,Symbol.toStringTag,{value:T,enumerable:!0})}));function ue(e){let t;try{if(t=M&&(self.URL||self.webkitURL).createObjectURL(M),!t)throw``;let n=new Worker(t,{name:e?.name});return n.addEventListener(`error`,()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker(`data:text/javascript;charset=utf-8,`+encodeURIComponent(j),{name:e?.name})}}var j,M,de=n((()=>{j='(function(){function e(e,t){t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n}function t(t,n,r){if(r<1n)throw RangeError("`mod` must be positive");if(n<0n)throw RangeError("`power` must not be negative");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i}function n(e,t){if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n}function r(e){if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n}function i(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1}function a(e){let t=5n;for(;;){let i=n(t,e);if(i===-1n)return t;if(i===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&r(e)))return null}}function o(t,n){if((n&1n)==0n)throw Error("`n` is not odd");return(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n)}function s(t,n,r,i){let a=1n,s=r,c=t.toString(2).slice(1);for(let t of c)[a,s]=[e(a*s,n),o(s*s+i*a*a,n)],t===`1`&&([a,s]=[o(r*a+s,n),o(i*a+r*s,n)]);return[a,s]}function c(n,r,i,a){if(n%2n!=1n)throw RangeError("`n` must be odd");let o=n+1n,c=0n;for(;o%2n==0n;)o>>=1n,c+=1n;let[l,u]=s(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<c;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1}function l(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n])if(e%t===0n)return e===t;if(!i(e))return!1;let t=a(e);return t==null?!1:c(e,t,1n,(1n-t)/4n)}let u=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self;function d(e,t){if(!u())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)}function f(e,t){if(!u())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)}let p=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{d(l(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;f({name:t,message:r,stack:i,cause:p(a)},n)}else f({name:`BPSWError`,message:`unidentified error`,cause:p(e)},n)}}})();',M=typeof self<`u`&&self.Blob&&new Blob([`(self.URL || self.webkitURL).revokeObjectURL(self.location.href);`,j],{type:`text/javascript;charset=utf-8`})})),fe=r({getWorker:()=>pe});function pe(){return N||=new k(new ue({name:`bpsw_worker`})),N}var N,me=n((()=>{A(),de(),N=null}));function he(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;let t=e-1n,n=0n;for(;t%2n==0n;)t>>=1n,n+=1n;let[r,i]=[t,n],a=p(2n,r,e);if(a===1n)return!0;for(let t=0n;t<i;t++){if(a===e-1n)return!0;a=a*a%e}return!1}function P(e){let t=5n;for(;;){let n=y(t,e);if(n===-1n)return t;if(n===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&b(e)))return null}}function F(e,t){if((t&1n)==0n)throw Error("`n` is not odd");return(e&1n)==1n?f(e+t>>1n,t):f(e>>1n,t)}function I(e,t,n,r){let i=1n,a=n,o=e.toString(2).slice(1);for(let e of o)[i,a]=[f(i*a,t),F(a*a+r*i*i,t)],e===`1`&&([i,a]=[F(n*i+a,t),F(r*i+n*a,t)]);return[i,a]}function L(e,t,n,r){if(e%2n!=1n)throw RangeError("`n` must be odd");let i=e+1n,a=0n;for(;i%2n==0n;)i>>=1n,a+=1n;let[o,s]=I(i,e,n,t),c=s;if(o===0n)return!0;r=p(r,i,e);for(let t=0n;t<a;t++){if(c===0n)return!0;c=f(c*c-2n*r,e),r=p(r,2n,e)}return!1}function R(e){if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n])if(e%t===0n)return e===t;if(!he(e))return!1;let t=P(e);return t==null?!1:L(e,t,1n,(1n-t)/4n)}function ge(e,t){if(t<2n)throw RangeError("`max` must be 2 or larger");for(let n=0;n<1e5;n++){let n=w(e,t);if(R(n))return n}throw Error(`no primes were found`)}function _e(e,t=!1){if(e<2)throw RangeError("`bitLength` must be 2 or larger");for(let n=0;n<1e5;n++){let n=C(e,t);if(R(n))return n}throw Error(`no primes were found`)}async function ve(e){let{getWorker:t}=await Promise.resolve().then(()=>(me(),fe));return t().postMessage(e)}function z(e){return btoa(e.reduce((e,t)=>e+String.fromCharCode(t),``))}function B(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0))}function V(e){return z(e).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``)}function H(e){for(;e.length&3;)e+=`=`;return B(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`))}function ye(e,t){let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return new Response(n).bytes()}function be(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(t));return new Response(n).bytes()}async function xe(e,t=`deflate-raw`,n=`base64url`){let r=new Blob([e]).stream().pipeThrough(new CompressionStream(t)),i=await new Response(r).bytes();return n===`base64`?z(i):V(i)}function Se(e,t=`deflate-raw`,n=`base64url`){let r=n===`base64`?B(e):H(e),i=new Blob([r]).stream().pipeThrough(new DecompressionStream(t));return new Response(i).text()}function Ce(e,t){return[e].includes(t)}function U(e,t){if(typeof e!=typeof t)return!1;let n=Object.prototype.toString.call(e);if(n!==Object.prototype.toString.call(t))return!1;if(typeof e==`string`||typeof e==`bigint`||typeof e==`boolean`||typeof e==`symbol`||e==null)return e===t;if(typeof e==`number`)return e===t||e!==e&&t!==t;if(typeof e==`function`)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!U(e[n],t[n]))return!1;return!0}if(e instanceof Set&&t instanceof Set)return!!U([...e.values()],[...t.values()]);if(e instanceof Map&&t instanceof Map)return!(!U([...e.keys()],[...t.keys()])||!U([...e.values()],[...t.values()]));if(n===`[object Object]`){let n=e,r=t,i=Object.keys(n),a=Object.keys(r);for(let e of i){let t=a.find(t=>t===e);if(t==null)return!1;let[i,o]=[n[e],r[t]];if(!U(i,o))return!1}return!0}throw TypeError(`comparing these objects is unavailable: ${e}, ${t}`,{cause:[e,t]})}var W=`Rational`,G=class e{#e;#t;static name=W;constructor(e,t){t===0n?(this.#t=0n,this.#e=e===0n?0n:e>0n?1n:-1n):t>0n?(this.#e=e,this.#t=t):(this.#e=-e,this.#t=-t),this.#n()}static fromDecimal(t,n=5){if(Number.isNaN(t))return new e(0n,0n);if(Math.abs(t)===1/0)return new e(t>0?1n:-1n,0n);let r=t<0;r&&(t*=-1);let i=BigInt(Math.floor(t)),a=t-Number(i);if(a===0)return new e(r?-i:i,1n);t=1/a;let[o,s]=[1n,i],[c,l]=[0n,1n];for(;`${l}`.length<=n;){let n=BigInt(Math.floor(t)),i=t-Number(n);if([o,s]=[s,n*s+o],[c,l]=[l,n*l+c],i===0)return new e(r?-s:s,l);t=1/i}return new e(r?-o:o,c)}#n=()=>{let{gcd:e}=m(this.#e,this.#t);e!==0n&&(this.#e/=e,this.#t/=e)};minus=()=>new e(-this.#e,this.#t);inverse=()=>new e(this.#t,this.#e);add=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#t+t.#e*this.#t,n)};substr=e=>this.add(e.minus());multiply=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#e,n)};divide=e=>this.multiply(e.inverse());mediant=t=>{let n=this.#t+t.#t;return new e(this.#e+t.#e,n)};toDecimal=()=>Number(this.#e)/Number(this.#t);toString=()=>this.#e===0n&&this.#t===0n?`NaN`:this.#e===0n?`0`:this.#t===0n?this.#e<0n?`-Infinity`:`Infinity`:this.#t===1n?`${this.#e}`:`${this.#e}/${this.#t}`;valueOf=()=>this.toDecimal();toJSON=()=>({type:`Rational`,value:[`0x`+this.#e.toString(16),`0x`+this.#t.toString(16)]});static fromData(t){return new e(BigInt(t.value[0]),BigInt(t.value[1]))}static parse(t){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!n)throw Error(`cannot parse`);let r=n.at(1),i=n.at(2);if(!r||!i)throw Error(`cannot parse`);return new e(BigInt(r),BigInt(i))}};Object.defineProperty(G.prototype,Symbol.toStringTag,{value:W});var we={new:e=>new Uint8Array(e),fromBuffer:(e,t,n)=>new Uint8Array(e,t,n)},K=`NamedError`,q=class extends Error{static name=K;errName;name;constructor(e,t,n){super(t,n),this.errName=e,this.name=e}toJSON=()=>{let e=(()=>{let e=this.cause;if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t})(),{errName:t,message:n,stack:r}=this;return{name:t,message:n,stack:r,cause:e}}};Object.defineProperty(q.prototype,Symbol.toStringTag,{value:K});function Te(e){if(e.length%3!=0)throw Error(`The array length of input must be multiples of 3`);let t=e.length/3;return Array.from({length:t},(t,n)=>[0,1,2].reduce((t,r)=>t|(e[3*n+r]??0)<<16-8*r,0)).reduce((e,t)=>e+t.toString(8).padStart(8,`0`),``)}function Ee(e){if(e.length&7)throw Error(`A string length must be multiples of 8`);let t=e.matchAll(/.{8}/g),n=Array.from(t,e=>{let t=Number.parseInt(e[0],8);if(Number.isNaN(t))throw TypeError(`Invalid input`);return[0,1,2].map(e=>t>>>16-8*e&255)}).flat();return Uint8Array.from(n)}var De=[9600629759793949339n,15726070495360670683n],J=6364136223846793005n,Y=`PCGMinimal`,X=class{#e;static name=Y;constructor(e){if(e&&e[0]!=null&&e[1]!=null){let t=e[1]<<1n|1n;this.#e=BigUint64Array.from([e[0]+t,t]),this.#t()}else this.#e=BigUint64Array.from(De)}#t(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[0]=this.#e[0]*J+this.#e[1]}get#n(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);let e=this.#e[0],t=Number(e>>59n);return _(Number(BigInt.asUintN(32,(e^e>>18n)>>27n)),t)}getRandU32=()=>(this.#t(),this.#n);getBoundedRandU32=e=>{let t=4294967296;if(e>t)throw RangeError("`bound` exceeded limit (2^32)");if(e<=0)throw RangeError(`'bound' must be positive`);let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU32();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};*genRandU32s(e,t){if(e<=0)throw RangeError(`'step' must be positive`);for(let n=0;n<e;n++)yield typeof t==`number`?this.getBoundedRandU32(t):this.getRandU32()}stream=e=>{let t,n=e;return new ReadableStream({start:e=>{let r=()=>{if(n<=0){e.close();return}let i=Uint32Array.from([this.getRandU32()]),a=Math.min(n,4);e.enqueue(new Uint8Array(i.buffer,0,a)),n-=a,t=setTimeout(r,20)};t=setTimeout(r,10)},cancel:e=>{clearTimeout(t),console.log(`stream is cancelled: `,e)}})}};Object.defineProperty(X.prototype,Symbol.toStringTag,{value:Y});var Oe=[13715198867125970446n,3333371893450545919n,5627726498316411518n,8467276975966080893n],Z=`XoshiroMinimal`,Q=class{bits=64;#e;static name=Z;constructor(e){if(e&&e[0]!=null&&e[1]!=null&&e[2]!=null&&e[3]!=null){if(this.#e=new BigUint64Array(4),this.#e[0]=e[0],this.#e[1]=e[1],this.#t(),this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);this.#e[2]+=e[2],this.#e[3]+=e[3]}else this.#e=BigUint64Array.from(Oe)}#t(){if(this.#e[0]==null||this.#e[1]==null||this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=this.#e[1]<<17n;this.#e[2]^=this.#e[0],this.#e[3]^=this.#e[1],this.#e[1]^=this.#e[2],this.#e[0]^=this.#e[3],this.#e[2]^=e,this.#e[3]=v(this.#e[3],45n)}get value(){if(this.#e[0]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=v(this.#e[0]+this.#e[3],23n)+this.#e[0];return BigInt.asUintN(64,e)}getRandU64=()=>{let e=this.value;return this.#t(),e};getRandU32=()=>{let e=BigInt.asUintN(32,this.getRandU64());return Number(e)};getBoundedRandU64=e=>{let t=1n<<64n;if(e>t)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU64();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};getBoundedRandU32=e=>{if(e>2**32)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let t=this.getBoundedRandU64(BigInt(e));return Number(t)};*genRandU64s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU64():this.getBoundedRandU64(t)}*genRandU32s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU32():this.getBoundedRandU32(t)}};Object.defineProperty(Q.prototype,Symbol.toStringTag,{value:Z});var $=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self;function ke(e,t){if(!$())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)}function Ae(e,t){if(!$())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)}function je(e){let t=[];for(;;){let n=Number(e&127n);e>>=7n;let r=n&64;if(e===0n&&r===0||e===-1n&&r!==0)return t.push(n),Uint8Array.from(t);t.push(n|128)}}function Me(e){let t=0n,n=0;for(let r of e)if(t|=BigInt(r&127)<<BigInt(n),n+=7,!(r&128))return BigInt.asIntN(n,t);return n+=7,BigInt.asIntN(n,t)}return A(),e.AsyncWorker=k,e.FixedUint8Array=we,e.NamedError=q,e.PCGMinimal=X,e.Rational=G,e.XoshiroMinimal=Q,e.bailliePSW=R,e.bailliePSWAsync=ve,e.compress=ye,e.compressString=xe,e.createWorker=oe,e.decodeLEB128=Me,e.decodeRFC3986URIComponent=ne,e.decompress=be,e.decompressString=Se,e.encodeLEB128=je,e.encodeRFC3986URIComponent=u,e.exEuclidean=m,e.factorial=se,e.floatRng=ce,e.fromBase64=B,e.fromBase64URL=H,e.fromOct=Ee,e.getHash=te,e.getRandBIByBitLength=C,e.getRandBIByRange=w,e.getRandPrimeByBitLength=_e,e.getRandPrimeByRange=ge,e.getRndInt=le,e.getStringTag=l,e.isDeepStrictEqual=U,e.isSquare=b,e.jacobiSymbol=y,e.lazify=ee,e.modPow=p,e.nullableStrictAt=d,e.postFailed=Ae,e.postSuccess=ke,e.residue=f,e.rot32=_,e.rot64=v,e.sameValueZero=Ce,e.setTimeoutPromise=re,e.sleepSort=ae,e.strictAt=ie,e.toBase64=z,e.toBase64URL=V,e.toOct=Te,e.withResolvers=c,e})({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
@@ -89,11 +89,11 @@
89
89
  },
90
90
  "homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
91
91
  "devDependencies": {
92
- "@types/node": "^24.12.2",
92
+ "@types/node": "^24.12.4",
93
93
  "typescript": "^6.0.3",
94
94
  "unplugin-dts": "1.0.0-beta.6",
95
- "vite": "^8.0.10",
96
- "vitest": "^4.1.5"
95
+ "vite": "^8.0.13",
96
+ "vitest": "^4.1.6"
97
97
  },
98
98
  "scripts": {
99
99
  "dev": "vite",
@@ -1,20 +0,0 @@
1
- import { AsyncWorker as e } from "./async_worker.js";
2
- //#region lib/bpsw_worker.ts?worker&inline
3
- var t = "(function(){let e=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},t=(t,n,r)=>{if(r<1n)throw RangeError(\"`mod` must be positive\");if(n<0n)throw RangeError(\"`power` must not be negative\");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i},n=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError(\"`n` is out of range\");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},r=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},i=[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],a=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},o=e=>{let t=5n;for(;;){let i=n(t,e);if(i===-1n)return t;if(i===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&r(e)))return null}},s=(t,n)=>{if((n&1n)==0n)throw Error(\"`n` is not odd\");return(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n)},c=(t,n,r,i)=>{let a=1n,o=r,c=t.toString(2).slice(1);for(let t of c)[a,o]=[e(a*o,n),s(o*o+i*a*a,n)],t===`1`&&([a,o]=[s(r*a+o,n),s(i*a+r*o,n)]);return[a,o]},l=(n,r,i,a)=>{if(n%2n!=1n)throw RangeError(\"`n` must be odd\");let o=n+1n,s=0n;for(;o%2n==0n;)o>>=1n,s+=1n;let[l,u]=c(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<s;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1},u=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of i)if(e%t===0n)return e===t;if(!a(e))return!1;let t=o(e);return t==null?!1:l(e,t,1n,(1n-t)/4n)},d=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,f=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},p=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},m=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{f(u(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;p({name:t,message:r,stack:i,cause:m(a)},n)}else p({name:`BPSWError`,message:`unidentified error`,cause:m(e)},n)}}})();", n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", t], { type: "text/javascript;charset=utf-8" });
4
- function r(e) {
5
- let r;
6
- try {
7
- if (r = n && (self.URL || self.webkitURL).createObjectURL(n), !r) throw "";
8
- let t = new Worker(r, { name: e?.name });
9
- return t.addEventListener("error", () => {
10
- (self.URL || self.webkitURL).revokeObjectURL(r);
11
- }), t;
12
- } catch {
13
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(t), { name: e?.name });
14
- }
15
- }
16
- //#endregion
17
- //#region lib/bpsw_worker_wrap.ts
18
- var i, a = async () => (i ||= new e(new r({ name: "bpsw_worker" })), i);
19
- //#endregion
20
- export { a as getWorker };