@tktb-tess/util-fns 0.10.1 → 0.11.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/dist/bundle.js +450 -406
- package/dist/bundle.min.js +2 -2
- package/dist/icon.svg +23 -0
- package/dist/main.d.ts +5 -4
- package/dist/{named-error.d.ts → named_error.d.ts} +1 -1
- package/dist/util.d.ts +8 -1
- package/dist/worker_stream.d.ts +7 -0
- package/package.json +1 -1
- /package/dist/{baillie-psw.d.ts → baillie_psw.d.ts} +0 -0
- /package/dist/{pcg-minimal.d.ts → pcg_minimal.d.ts} +0 -0
- /package/dist/{u8arr-ext.d.ts → u8arr_ext.d.ts} +0 -0
package/dist/bundle.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var UtilFns=(function(c){"use strict";const
|
|
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{constructor(t,e,r){super(e,{cause:r}),this.errName=t}static name="NamedError";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})(),{errName:e,message:r,stack:i}=this;return{errName: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})({});
|
|
1
|
+
var UtilFns=(function(c){"use strict";const $=new TextEncoder,D=(n,t)=>[n].includes(t),g=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;s++)if(!g(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],i=[...t.values()];return!!g(s,i)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],i=[...t.keys()];if(!g(s,i))return!1;const o=[...n.values()],a=[...t.values()];return!!g(o,a)}if(e==="[object Object]"){const s=n,i=t,o=Object.keys(s),a=Object.keys(i);for(const l of o){const u=a.find(v=>v===l);if(u===void 0)return!1;const[h,d]=[s[l],i[u]];if(!g(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},q=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},k=n=>new Promise(t=>{setTimeout(()=>t(),n)}),K=n=>Object.prototype.toString.call(n).match(/^\[Object\s(.+)\]$/)?.at(1),W=n=>(...t)=>()=>n(...t),G=n=>{const t=[];let e=[],r="",s=!1;for(let i=0;i<n.length;i++){const o=n[i];o==='"'&&(i===0||n[i-1]!=="\\")?s=!s:o===","&&!s?(e.push(r.trim()),r=""):o===`
|
|
2
|
+
`&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},z=async(n,t)=>{const e=$.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},X=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",H=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),J=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},Y=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},Z=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},x=(n,t)=>new Promise((e,r)=>{setTimeout(async()=>{try{const s=await n();e(s)}catch(s){r(s)}},t)});class y extends Error{constructor(t,e,r){super(e,r),this.errName=t}static name="NamedError";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})(),{errName:e,message:r,stack:s}=this;return{errName:e,message:r,stack:s,cause:t}}}Object.defineProperty(y.prototype,Symbol.toStringTag,{value:y.name});const Q=(n,t)=>Math.floor(Math.random()*(t-n)+n),m=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},I=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let s=Array.from(r,i=>i.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},N=(n,t)=>{if(n>=t)throw new y("RangeError","min is larger than max");const e=t-n,r=e.toString(2).length,s=(()=>{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+s},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=m(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},L=(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}},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 s=n+r|1n,i=w(n,s),o=w(s,t);return i*o},tt=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*=w(t,o),t=o,e*=r}return e},nt=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 tt(n)<<t},M=(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},T=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r*r<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},et=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=p(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},rt=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&T(n))return[0n,0n];e=B(t,n)}return[t,e]},E=(n,t)=>(n&1n)===1n?m(n+t>>1n,t):m(n>>1n,t),st=(n,t,e,r)=>{let s=1n,i=e;const o=n.toString(2).slice(1);for(const a of o)[s,i]=[m(s*i,t),E(i*i+r*s*s,t)],a==="1"&&([s,i]=[E(e*s+i,t),E(r*s+e*i,t)]);return[s,i]},it=(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]=st(s,n,e,t);let l=a;if(o===0n)return!0;r=p(r,s,n);for(let u=0n;u<i;u++){if(l===0n)return!0;l=m(l*l-2n*r,n),r=p(r,2n,n)}return!1},S=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const i of t)if(n%i===0n)return n===i;if(!et(n))return!1;const[e,r]=rt(n);if(r===0n)return!1;const s=(1n-e)/4n;return it(n,e,1n,s)},ot=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=N(n,t);if(S(s))return s}throw Error("noPrimesFound")},ct=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=I(n,t);if(S(s))return s}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const 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}=L(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))}}Object.defineProperty(f.prototype,Symbol.toStringTag,{value:f.name});const A=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},P=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},at=n=>A(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),lt=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return P(e)},ut=n=>{let t=Array.from(n,i=>i.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,i=>Number.parseInt(i[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},ft=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),s=Array.from(e,i=>{const o=i[0];return Number.parseInt(o,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,i=>Number.parseInt(i[0],16))},ht=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},dt=n=>{const t=ht(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},gt=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)},j=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},C="FloatRng",_=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class O{#t;static name=C;constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const l=this.#t.getU64Rand()&0xffffffffn;return Number(l)}}})(),s=r&255;let i=126;if(s===0){i-=8;const l=1e5;let u=0;t:for(;;){if(u>l)throw Error("loop exceeded limit");const h=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const d=BigInt.asUintN(32,this.#t.getU64Rand());return Number(d)}}})();if(h===0){if(i-=32,i<0){i=0;break t}}else{i-=j(h);break t}++u}}else i-=j(s);const o=r>>>8&8388607;o===0&&r>>>31&&++i;const a=Uint32Array.from([i<<23|o]);return new Float32Array(a.buffer)[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 l=BigInt(this.#t.getU32Rand()>>>0),u=BigInt(this.#t.getU32Rand()>>>0);return l<<32n|u}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),s=r&0x7ffn;let i=e-1n;if(s===0n){i-=11n;const l=1e5;let u=0;t:for(;;){if(u>l)throw Error("loop exceeded limit");const h=(()=>{switch(this.#t.bits){case 32:{const d=BigInt(this.#t.getU32Rand()>>>0),v=BigInt(this.#t.getU32Rand()>>>0);return d<<32n|v}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(h===0n){if(i-=64n,i<t){i=t;break t}}else{i-=_(h);break t}++u}}else i-=_(s);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++i;const a=BigUint64Array.from([i<<52n|o]);return new Float64Array(a.buffer)[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(O.prototype,Symbol.toStringTag,{value:C});const mt=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],yt=0x5851f42d4c957f2dn;class U{#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(mt)}#n(){this.#t[0]=this.#t[0]*yt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return M(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()}}Object.defineProperty(U.prototype,Symbol.toStringTag,{value:U.name});const pt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class R{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(pt)}#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,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)}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});const F="WorkerStream";class V extends ReadableStream{close;#t;static name=F;constructor(t,e){let r,s,i;super({start:o=>{r=a=>{o.enqueue(a.data)},s=a=>{t.removeEventListener("message",r),t.removeEventListener("error",s);const l=new y("WorkerStreamError",a.message,{cause:a.error});o.error(l)},i=()=>{t.removeEventListener("message",r),t.removeEventListener("error",s),o.close()},t.addEventListener("message",r),t.addEventListener("error",s)},cancel:o=>{console.log("Canceled reason:",o),t.removeEventListener("message",r),t.removeEventListener("error",s)}},e),this.close=i,this.#t=t}postMessage(t,e){this.#t.postMessage(t,e)}}return Object.defineProperty(V.prototype,Symbol.toStringTag,{value:F}),c.FloatRng=O,c.NamedError=y,c.PCGMinimal=U,c.Rational=f,c.WorkerStream=V,c.XoshiroMinimal=R,c.bailliePSW=S,c.compress=Y,c.decodeLEB128=gt,c.decodeRFC3986URIComponent=J,c.decompress=Z,c.encodeLEB128=dt,c.encodeRFC3986URIComponent=H,c.exEuclidean=L,c.factorial=nt,c.fromBase64=P,c.fromBase64Url=lt,c.fromOct=ft,c.getHash=z,c.getRandBIByBitLength=I,c.getRandBIByRange=N,c.getRandPrimeByBitLength=ct,c.getRandPrimeByRange=ot,c.getRndInt=Q,c.getStringTag=K,c.isDeepStrictEqual=g,c.isNode=X,c.isSquare=T,c.jacobiSymbol=B,c.lazify=W,c.modPow=p,c.parseCSV=G,c.residue=m,c.rot32=M,c.rot64=b,c.sameValueZero=D,c.setTimeoutPromise=x,c.sleep=k,c.toBase64=A,c.toBase64Url=at,c.toOct=ut,c.withResolvers=q,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
|
package/dist/icon.svg
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
3
|
+
|
|
4
|
+
<svg viewBox="0 0 1080 1080" version="1.1" id="svg1"
|
|
5
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
+
xmlns:svg="http://www.w3.org/2000/svg"
|
|
7
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
8
|
+
xmlns:cc="http://creativecommons.org/ns#">
|
|
9
|
+
<defs id="defs1" />
|
|
10
|
+
<metadata id="metadata1">
|
|
11
|
+
<rdf:RDF>
|
|
12
|
+
<cc:Work rdf:about="">
|
|
13
|
+
<cc:license rdf:resource="http://creativecommons.org/publicdomain/zero/1.0/" />
|
|
14
|
+
</cc:Work>
|
|
15
|
+
<cc:License rdf:about="http://creativecommons.org/publicdomain/zero/1.0/">
|
|
16
|
+
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction" />
|
|
17
|
+
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution" />
|
|
18
|
+
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
|
|
19
|
+
</cc:License>
|
|
20
|
+
</rdf:RDF>
|
|
21
|
+
</metadata>
|
|
22
|
+
<path id="path1" d="M 1080,540 A 540,540 0 0 1 540,1080 540,540 0 0 1 0,540 540,540 0 0 1 540,0 540,540 0 0 1 1080,540 Z" />
|
|
23
|
+
</svg>
|
package/dist/main.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from './util';
|
|
2
2
|
export * from './math';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './baillie_psw';
|
|
4
4
|
export * from './fraction';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './u8arr_ext';
|
|
6
|
+
export * from './named_error';
|
|
7
7
|
export * from './random';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './pcg_minimal';
|
|
9
9
|
export * from './xoshiro-minimal';
|
|
10
|
+
export * from './worker_stream';
|
|
@@ -6,7 +6,7 @@ interface NamedError<EName extends string> {
|
|
|
6
6
|
declare class NamedError<EName extends string> extends Error {
|
|
7
7
|
readonly errName: EName;
|
|
8
8
|
static readonly name = "NamedError";
|
|
9
|
-
constructor(errName: EName, message: string,
|
|
9
|
+
constructor(errName: EName, message: string, options?: ErrorOptions);
|
|
10
10
|
toJSON(): {
|
|
11
11
|
errName: EName;
|
|
12
12
|
message: string;
|
package/dist/util.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const isDeepStrictEqual: (a: unknown, b: unknown) => boolean;
|
|
|
14
14
|
/**
|
|
15
15
|
* a polyfill for `Promise.withResolvers()`
|
|
16
16
|
*/
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const withResolvers: <T>() => {
|
|
18
18
|
promise: Promise<T>;
|
|
19
19
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
20
20
|
reject: (reason?: unknown) => void;
|
|
@@ -71,3 +71,10 @@ export declare const encodeRFC3986URIComponent: (URIComponent: string | number |
|
|
|
71
71
|
export declare const decodeRFC3986URIComponent: (encodedURIComponent: string) => string;
|
|
72
72
|
export declare const compress: (raw: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
|
|
73
73
|
export declare const decompress: (compressed: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param handler
|
|
77
|
+
* @param timeout timeout
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
export declare const setTimeoutPromise: <T>(handler: () => T, timeout?: number) => Promise<T>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class WorkerStream<TPost, TRecv> extends ReadableStream<TRecv> {
|
|
2
|
+
#private;
|
|
3
|
+
readonly close: () => void;
|
|
4
|
+
static readonly name = "WorkerStream";
|
|
5
|
+
constructor(worker: Worker, strategy?: CountQueuingStrategy);
|
|
6
|
+
postMessage(message: TPost, options?: StructuredSerializeOptions): void;
|
|
7
|
+
}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|