UNPKG

min-bounding-rectangle

Version:

Minimum bounding rectangle implementation in JavaScript. Uses `concaveman` and `mathjs` as dependencies.

1 lines 173 kB
(function(Ft,wt){typeof exports=="object"&&typeof module<"u"?wt(exports):typeof define=="function"&&define.amd?define(["exports"],wt):(Ft=typeof globalThis<"u"?globalThis:Ft||self,wt(Ft["min-bounding-rectangle"]={}))})(this,(function(Ft){"use strict";function wt(e,t,n=0,r=e.length-1,i=Qi){for(;r>n;){if(r-n>600){const f=r-n+1,l=t-n+1,a=Math.log(f),c=.5*Math.exp(2*a/3),D=.5*Math.sqrt(a*c*(f-c)/f)*(l-f/2<0?-1:1),w=Math.max(n,Math.floor(t-l*c/f+D)),M=Math.min(r,Math.floor(t+(f-l)*c/f+D));wt(e,t,w,M,i)}const u=e[t];let o=n,s=r;for(Xt(e,n,t),i(e[r],u)>0&&Xt(e,n,r);o<s;){for(Xt(e,o,s),o++,s--;i(e[o],u)<0;)o++;for(;i(e[s],u)>0;)s--}i(e[n],u)===0?Xt(e,n,s):(s++,Xt(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function Xt(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function Qi(e,t){return e<t?-1:e>t?1:0}class jn{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const r=[];if(!en(t,n))return r;const i=this.toBBox,u=[];for(;n;){for(let o=0;o<n.children.length;o++){const s=n.children[o],f=n.leaf?i(s):s;en(t,f)&&(n.leaf?r.push(s):Sn(t,f)?this._all(s,r):u.push(s))}n=u.pop()}return r}collides(t){let n=this.data;if(!en(t,n))return!1;const r=[];for(;n;){for(let i=0;i<n.children.length;i++){const u=n.children[i],o=n.leaf?this.toBBox(u):u;if(en(t,o)){if(n.leaf||Sn(t,o))return!0;r.push(u)}}n=r.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let r=0;r<t.length;r++)this.insert(t[r]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=At([]),this}remove(t,n){if(!t)return this;let r=this.data;const i=this.toBBox(t),u=[],o=[];let s,f,l;for(;r||u.length;){if(r||(r=u.pop(),f=u[u.length-1],s=o.pop(),l=!0),r.leaf){const a=Ki(t,r.children,n);if(a!==-1)return r.children.splice(a,1),u.push(r),this._condense(u),this}!l&&!r.leaf&&Sn(r,i)?(u.push(r),o.push(s),s=0,f=r,r=r.children[0]):f?(s++,r=f.children[s],l=!1):r=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const r=[];for(;t;)t.leaf?n.push(...t.children):r.push(...t.children),t=r.pop();return n}_build(t,n,r,i){const u=r-n+1;let o=this._maxEntries,s;if(u<=o)return s=At(t.slice(n,r+1)),Et(s,this.toBBox),s;i||(i=Math.ceil(Math.log(u)/Math.log(o)),o=Math.ceil(u/Math.pow(o,i-1))),s=At([]),s.leaf=!1,s.height=i;const f=Math.ceil(u/o),l=f*Math.ceil(Math.sqrt(o));er(t,n,r,l,this.compareMinX);for(let a=n;a<=r;a+=l){const c=Math.min(a+l-1,r);er(t,a,c,f,this.compareMinY);for(let D=a;D<=c;D+=f){const w=Math.min(D+f-1,c);s.children.push(this._build(t,D,w,i-1))}}return Et(s,this.toBBox),s}_chooseSubtree(t,n,r,i){for(;i.push(n),!(n.leaf||i.length-1===r);){let u=1/0,o=1/0,s;for(let f=0;f<n.children.length;f++){const l=n.children[f],a=xn(l),c=tu(t,l)-a;c<o?(o=c,u=a<u?a:u,s=l):c===o&&a<u&&(u=a,s=l)}n=s||n.children[0]}return n}_insert(t,n,r){const i=r?t:this.toBBox(t),u=[],o=this._chooseSubtree(i,this.data,n,u);for(o.children.push(t),Lt(o,i);n>=0&&u[n].children.length>this._maxEntries;)this._split(u,n),n--;this._adjustParentBBoxes(i,u,n)}_split(t,n){const r=t[n],i=r.children.length,u=this._minEntries;this._chooseSplitAxis(r,u,i);const o=this._chooseSplitIndex(r,u,i),s=At(r.children.splice(o,r.children.length-o));s.height=r.height,s.leaf=r.leaf,Et(r,this.toBBox),Et(s,this.toBBox),n?t[n-1].children.push(s):this._splitRoot(r,s)}_splitRoot(t,n){this.data=At([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Et(this.data,this.toBBox)}_chooseSplitIndex(t,n,r){let i,u=1/0,o=1/0;for(let s=n;s<=r-n;s++){const f=$t(t,0,s,this.toBBox),l=$t(t,s,r,this.toBBox),a=nu(f,l),c=xn(f)+xn(l);a<u?(u=a,i=s,o=c<o?c:o):a===u&&c<o&&(o=c,i=s)}return i||r-n}_chooseSplitAxis(t,n,r){const i=t.leaf?this.compareMinX:ji,u=t.leaf?this.compareMinY:eu,o=this._allDistMargin(t,n,r,i),s=this._allDistMargin(t,n,r,u);o<s&&t.children.sort(i)}_allDistMargin(t,n,r,i){t.children.sort(i);const u=this.toBBox,o=$t(t,0,n,u),s=$t(t,r-n,r,u);let f=jt(o)+jt(s);for(let l=n;l<r-n;l++){const a=t.children[l];Lt(o,t.leaf?u(a):a),f+=jt(o)}for(let l=r-n-1;l>=n;l--){const a=t.children[l];Lt(s,t.leaf?u(a):a),f+=jt(s)}return f}_adjustParentBBoxes(t,n,r){for(let i=r;i>=0;i--)Lt(n[i],t)}_condense(t){for(let n=t.length-1,r;n>=0;n--)t[n].children.length===0?n>0?(r=t[n-1].children,r.splice(r.indexOf(t[n]),1)):this.clear():Et(t[n],this.toBBox)}}function Ki(e,t,n){if(!n)return t.indexOf(e);for(let r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function Et(e,t){$t(e,0,e.children.length,t,e)}function $t(e,t,n,r,i){i||(i=At(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let u=t;u<n;u++){const o=e.children[u];Lt(i,e.leaf?r(o):o)}return i}function Lt(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function ji(e,t){return e.minX-t.minX}function eu(e,t){return e.minY-t.minY}function xn(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function jt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function tu(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function nu(e,t){const n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),u=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,u-r)}function Sn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function en(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function At(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function er(e,t,n,r,i){const u=[t,n];for(;u.length;){if(n=u.pop(),t=u.pop(),n-t<=r)continue;const o=t+Math.ceil((n-t)/r/2)*r;wt(e,o,t,n,i),u.push(t,o,o,n)}}class ru{constructor(t=[],n=(r,i)=>r<i?-1:r>i?1:0){if(this.data=t,this.length=this.data.length,this.compare=n,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(this.length===0)return;const t=this.data[0],n=this.data.pop();return--this.length>0&&(this.data[0]=n,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:n,compare:r}=this,i=n[t];for(;t>0;){const u=t-1>>1,o=n[u];if(r(i,o)>=0)break;n[t]=o,t=u}n[t]=i}_down(t){const{data:n,compare:r}=this,i=this.length>>1,u=n[t];for(;t<i;){let o=(t<<1)+1;const s=o+1;if(s<this.length&&r(n[s],n[o])<0&&(o=s),r(n[o],u)>=0)break;n[t]=n[o],t=o}n[t]=u}}function tr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Zt={exports:{}},Tn,nr;function iu(){return nr||(nr=1,Tn=function(t,n,r,i){var u=t[0],o=t[1],s=!1;r===void 0&&(r=0),i===void 0&&(i=n.length);for(var f=(i-r)/2,l=0,a=f-1;l<f;a=l++){var c=n[r+l*2+0],D=n[r+l*2+1],w=n[r+a*2+0],M=n[r+a*2+1],h=D>o!=M>o&&u<(w-c)*(o-D)/(M-D)+c;h&&(s=!s)}return s}),Tn}var bn,rr;function uu(){return rr||(rr=1,bn=function(t,n,r,i){var u=t[0],o=t[1],s=!1;r===void 0&&(r=0),i===void 0&&(i=n.length);for(var f=i-r,l=0,a=f-1;l<f;a=l++){var c=n[l+r][0],D=n[l+r][1],w=n[a+r][0],M=n[a+r][1],h=D>o!=M>o&&u<(w-c)*(o-D)/(M-D)+c;h&&(s=!s)}return s}),bn}var ir;function ou(){if(ir)return Zt.exports;ir=1;var e=iu(),t=uu();return Zt.exports=function(r,i,u,o){return i.length>0&&Array.isArray(i[0])?t(r,i,u,o):e(r,i,u,o)},Zt.exports.nested=t,Zt.exports.flat=e,Zt.exports}var su=ou();const au=tr(su),it=11102230246251565e-32,be=134217729,fu=(3+8*it)*it;function In(e,t,n,r,i){let u,o,s,f,l=t[0],a=r[0],c=0,D=0;a>l==a>-l?(u=l,l=t[++c]):(u=a,a=r[++D]);let w=0;if(c<e&&D<n)for(a>l==a>-l?(o=l+u,s=u-(o-l),l=t[++c]):(o=a+u,s=u-(o-a),a=r[++D]),u=o,s!==0&&(i[w++]=s);c<e&&D<n;)a>l==a>-l?(o=u+l,f=o-u,s=u-(o-f)+(l-f),l=t[++c]):(o=u+a,f=o-u,s=u-(o-f)+(a-f),a=r[++D]),u=o,s!==0&&(i[w++]=s);for(;c<e;)o=u+l,f=o-u,s=u-(o-f)+(l-f),l=t[++c],u=o,s!==0&&(i[w++]=s);for(;D<n;)o=u+a,f=o-u,s=u-(o-f)+(a-f),a=r[++D],u=o,s!==0&&(i[w++]=s);return(u!==0||w===0)&&(i[w++]=u),w}function cu(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function Wt(e){return new Float64Array(e)}const lu=(3+16*it)*it,hu=(2+12*it)*it,Du=(9+64*it)*it*it,Ct=Wt(4),ur=Wt(8),or=Wt(12),sr=Wt(16),ze=Wt(4);function pu(e,t,n,r,i,u,o){let s,f,l,a,c,D,w,M,h,g,p,E,F,A,d,m,C,y;const B=e-i,x=n-i,T=t-u,q=r-u;A=B*q,D=be*B,w=D-(D-B),M=B-w,D=be*q,h=D-(D-q),g=q-h,d=M*g-(A-w*h-M*h-w*g),m=T*x,D=be*T,w=D-(D-T),M=T-w,D=be*x,h=D-(D-x),g=x-h,C=M*g-(m-w*h-M*h-w*g),p=d-C,c=d-p,Ct[0]=d-(p+c)+(c-C),E=A+p,c=E-A,F=A-(E-c)+(p-c),p=F-m,c=F-p,Ct[1]=F-(p+c)+(c-m),y=E+p,c=y-E,Ct[2]=E-(y-c)+(p-c),Ct[3]=y;let Z=cu(4,Ct),W=hu*o;if(Z>=W||-Z>=W||(c=e-B,s=e-(B+c)+(c-i),c=n-x,l=n-(x+c)+(c-i),c=t-T,f=t-(T+c)+(c-u),c=r-q,a=r-(q+c)+(c-u),s===0&&f===0&&l===0&&a===0)||(W=Du*o+fu*Math.abs(Z),Z+=B*a+q*s-(T*l+x*f),Z>=W||-Z>=W))return Z;A=s*q,D=be*s,w=D-(D-s),M=s-w,D=be*q,h=D-(D-q),g=q-h,d=M*g-(A-w*h-M*h-w*g),m=f*x,D=be*f,w=D-(D-f),M=f-w,D=be*x,h=D-(D-x),g=x-h,C=M*g-(m-w*h-M*h-w*g),p=d-C,c=d-p,ze[0]=d-(p+c)+(c-C),E=A+p,c=E-A,F=A-(E-c)+(p-c),p=F-m,c=F-p,ze[1]=F-(p+c)+(c-m),y=E+p,c=y-E,ze[2]=E-(y-c)+(p-c),ze[3]=y;const L=In(4,Ct,4,ze,ur);A=B*a,D=be*B,w=D-(D-B),M=B-w,D=be*a,h=D-(D-a),g=a-h,d=M*g-(A-w*h-M*h-w*g),m=T*l,D=be*T,w=D-(D-T),M=T-w,D=be*l,h=D-(D-l),g=l-h,C=M*g-(m-w*h-M*h-w*g),p=d-C,c=d-p,ze[0]=d-(p+c)+(c-C),E=A+p,c=E-A,F=A-(E-c)+(p-c),p=F-m,c=F-p,ze[1]=F-(p+c)+(c-m),y=E+p,c=y-E,ze[2]=E-(y-c)+(p-c),ze[3]=y;const z=In(L,ur,4,ze,or);A=s*a,D=be*s,w=D-(D-s),M=s-w,D=be*a,h=D-(D-a),g=a-h,d=M*g-(A-w*h-M*h-w*g),m=f*l,D=be*f,w=D-(D-f),M=f-w,D=be*l,h=D-(D-l),g=l-h,C=M*g-(m-w*h-M*h-w*g),p=d-C,c=d-p,ze[0]=d-(p+c)+(c-C),E=A+p,c=E-A,F=A-(E-c)+(p-c),p=F-m,c=F-p,ze[1]=F-(p+c)+(c-m),y=E+p,c=y-E,ze[2]=E-(y-c)+(p-c),ze[3]=y;const k=In(z,or,4,ze,sr);return sr[k-1]}function du(e,t,n,r,i,u){const o=(t-u)*(n-i),s=(e-i)*(r-u),f=o-s,l=Math.abs(o+s);return Math.abs(f)>=lu*l?f:-pu(e,t,n,r,i,u,l)}function mu(e,t,n){t=Math.max(0,t===void 0?2:t),n=n||0;const r=Eu(e),i=new jn(16);i.toBBox=function(D){return{minX:D[0],minY:D[1],maxX:D[0],maxY:D[1]}},i.compareMinX=function(D,w){return D[0]-w[0]},i.compareMinY=function(D,w){return D[1]-w[1]},i.load(e);const u=[];let o;for(let D=0;D<r.length;D++){const w=r[D];i.remove(w),o=cr(w,o),u.push(o)}const s=new jn(16);for(let D=0;D<u.length;D++)s.insert(On(u[D]));const f=t*t,l=n*n;for(;u.length;){const D=u.shift(),w=D.p,M=D.next.p,h=Pn(w,M);if(h<l)continue;const g=h/f,p=gu(i,D.prev.p,w,M,D.next.next.p,g,s);p&&Math.min(Pn(p,w),Pn(p,M))<=g&&(u.push(D),u.push(cr(p,D)),i.remove(p),s.remove(D),s.insert(On(D)),s.insert(On(D.next)))}let a=o;const c=[];do c.push(a.p),a=a.next;while(a!==o);return c.push(a.p),c}function gu(e,t,n,r,i,u,o){const s=new ru([],vu);let f=e.data;for(;f;){for(let l=0;l<f.children.length;l++){const a=f.children[l],c=f.leaf?zn(a,n,r):Fu(n,r,a);c>u||s.push({node:a,dist:c})}for(;s.length&&!s.peek().node.children;){const l=s.pop(),a=l.node,c=zn(a,t,n),D=zn(a,r,i);if(l.dist<c&&l.dist<D&&fr(n,a,o)&&fr(r,a,o))return a}f=s.pop(),f&&(f=f.node)}return null}function vu(e,t){return e.dist-t.dist}function Fu(e,t,n){if(ar(e,n)||ar(t,n))return 0;const r=tn(e[0],e[1],t[0],t[1],n.minX,n.minY,n.maxX,n.minY);if(r===0)return 0;const i=tn(e[0],e[1],t[0],t[1],n.minX,n.minY,n.minX,n.maxY);if(i===0)return 0;const u=tn(e[0],e[1],t[0],t[1],n.maxX,n.minY,n.maxX,n.maxY);if(u===0)return 0;const o=tn(e[0],e[1],t[0],t[1],n.minX,n.maxY,n.maxX,n.maxY);return o===0?0:Math.min(r,i,u,o)}function ar(e,t){return e[0]>=t.minX&&e[0]<=t.maxX&&e[1]>=t.minY&&e[1]<=t.maxY}function fr(e,t,n){const r=Math.min(e[0],t[0]),i=Math.min(e[1],t[1]),u=Math.max(e[0],t[0]),o=Math.max(e[1],t[1]),s=n.search({minX:r,minY:i,maxX:u,maxY:o});for(let f=0;f<s.length;f++)if(wu(s[f].p,s[f].next.p,e,t))return!1;return!0}function yt(e,t,n){return du(e[0],e[1],t[0],t[1],n[0],n[1])}function wu(e,t,n,r){return e!==r&&t!==n&&yt(e,t,n)>0!=yt(e,t,r)>0&&yt(n,r,e)>0!=yt(n,r,t)>0}function On(e){const t=e.p,n=e.next.p;return e.minX=Math.min(t[0],n[0]),e.minY=Math.min(t[1],n[1]),e.maxX=Math.max(t[0],n[0]),e.maxY=Math.max(t[1],n[1]),e}function Eu(e){let t=e[0],n=e[0],r=e[0],i=e[0];for(let s=0;s<e.length;s++){const f=e[s];f[0]<t[0]&&(t=f),f[0]>r[0]&&(r=f),f[1]<n[1]&&(n=f),f[1]>i[1]&&(i=f)}const u=[t,n,r,i],o=u.slice();for(let s=0;s<e.length;s++)au(e[s],u)||o.push(e[s]);return Cu(o)}function cr(e,t){const n={p:e,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return t?(n.next=t.next,n.prev=t,t.next.prev=n,t.next=n):(n.prev=n,n.next=n),n}function Pn(e,t){const n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function zn(e,t,n){let r=t[0],i=t[1],u=n[0]-r,o=n[1]-i;if(u!==0||o!==0){const s=((e[0]-r)*u+(e[1]-i)*o)/(u*u+o*o);s>1?(r=n[0],i=n[1]):s>0&&(r+=u*s,i+=o*s)}return u=e[0]-r,o=e[1]-i,u*u+o*o}function tn(e,t,n,r,i,u,o,s){const f=n-e,l=r-t,a=o-i,c=s-u,D=e-i,w=t-u,M=f*f+l*l,h=f*a+l*c,g=a*a+c*c,p=f*D+l*w,E=a*D+c*w,F=M*g-h*h;let A,d,m=F,C=F;F===0?(A=0,m=1,d=E,C=g):(A=h*E-g*p,d=M*E-h*p,A<0?(A=0,d=E,C=g):A>m&&(A=m,d=E+h,C=g)),d<0?(d=0,-p<0?A=0:-p>M?A=m:(A=-p,m=M)):d>C&&(d=C,-p+h<0?A=0:-p+h>M?A=m:(A=-p+h,m=M));const y=A===0?0:A/m,B=d===0?0:d/C,x=(1-y)*e+y*n,T=(1-y)*t+y*r,q=(1-B)*i+B*o,Z=(1-B)*u+B*s,W=q-x,L=Z-T;return W*W+L*L}function Au(e,t){return e[0]===t[0]?e[1]-t[1]:e[0]-t[0]}function Cu(e){e.sort(Au);const t=[];for(let r=0;r<e.length;r++){for(;t.length>=2&&yt(t[t.length-2],t[t.length-1],e[r])<=0;)t.pop();t.push(e[r])}const n=[];for(let r=e.length-1;r>=0;r--){for(;n.length>=2&&yt(n[n.length-2],n[n.length-1],e[r])<=0;)n.pop();n.push(e[r])}return n.pop(),t.pop(),t.concat(n)}function nn(){return nn=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},nn.apply(null,arguments)}var lr={relTol:1e-12,absTol:1e-15,matrix:"Matrix",number:"number",numberFallback:"number",precision:64,predictable:!1,randomSeed:null};function yu(e,t){if(rn(e,t))return e[t];throw typeof e[t]=="function"&&_u(e,t)?new Error('Cannot access method "'+t+'" as a property'):new Error('No access to property "'+t+'"')}function Bu(e,t,n){if(rn(e,t))return e[t]=n,n;throw new Error('No access to property "'+t+'"')}function rn(e,t){return!Mu(e)&&!Array.isArray(e)?!1:Ze(Nu,t)?!0:!(t in Object.prototype||t in Function.prototype)}function _u(e,t){return e==null||typeof e[t]!="function"||Ze(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:Ze(xu,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Mu(e){return typeof e=="object"&&e&&e.constructor===Object}var Nu={length:!0,name:!0},xu={toString:!0,valueOf:!0,toLocaleString:!0};class Su{constructor(t){this.wrappedObject=t,this[Symbol.iterator]=this.entries}keys(){return Object.keys(this.wrappedObject).filter(t=>this.has(t)).values()}get(t){return yu(this.wrappedObject,t)}set(t,n){return Bu(this.wrappedObject,t,n),this}has(t){return rn(this.wrappedObject,t)&&t in this.wrappedObject}entries(){return Tu(this.keys(),t=>[t,this.get(t)])}forEach(t){for(var n of this.keys())t(this.get(n),n,this)}delete(t){rn(this.wrappedObject,t)&&delete this.wrappedObject[t]}clear(){for(var t of this.keys())this.delete(t)}get size(){return Object.keys(this.wrappedObject).length}}function Tu(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function ce(e){return typeof e=="number"}function ye(e){return!e||typeof e!="object"||typeof e.constructor!="function"?!1:e.isBigNumber===!0&&typeof e.constructor.prototype=="object"&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal=="function"&&e.constructor.isDecimal(e)===!0}function hr(e){return typeof e=="bigint"}function un(e){return e&&typeof e=="object"&&Object.getPrototypeOf(e).isComplex===!0||!1}function on(e){return e&&typeof e=="object"&&Object.getPrototypeOf(e).isFraction===!0||!1}function sn(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Ge(e){return typeof e=="string"}var we=Array.isArray;function Be(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Vt(e){return Array.isArray(e)||Be(e)}function Dr(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function pr(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function dr(e){return e&&e.constructor.prototype.isRange===!0||!1}function an(e){return e&&e.constructor.prototype.isIndex===!0||!1}function mr(e){return typeof e=="boolean"}function gr(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function vr(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Fr(e){return typeof e=="function"}function wr(e){return e instanceof Date}function Er(e){return e instanceof RegExp}function Bt(e){return!!(e&&typeof e=="object"&&e.constructor===Object&&!un(e)&&!on(e))}function _t(e){return e?e instanceof Map||e instanceof Su||typeof e.set=="function"&&typeof e.get=="function"&&typeof e.keys=="function"&&typeof e.has=="function":!1}function bu(e){return _t(e)&&_t(e.a)&&_t(e.b)}function Iu(e){return _t(e)&&Bt(e.wrappedObject)}function Ar(e){return e===null}function Cr(e){return e===void 0}function yr(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function Br(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function _r(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Mr(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function Nr(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function xr(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function Sr(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Tr(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function br(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ir(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function Or(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function Pr(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function zr(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function Rr(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function qr(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Yr(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ur(e){return e&&e.constructor.prototype.isChain===!0||!1}function pt(e){var t=typeof e;return t==="object"?e===null?"null":ye(e)?"BigNumber":e.constructor&&e.constructor.name?e.constructor.name:"Object":t}function he(e){var t=typeof e;if(t==="number"||t==="bigint"||t==="string"||t==="boolean"||e===null||e===void 0)return e;if(typeof e.clone=="function")return e.clone();if(Array.isArray(e))return e.map(function(n){return he(n)});if(e instanceof Date)return new Date(e.valueOf());if(ye(e))return e;if(Bt(e))return Ou(e,he);if(t==="function")return e;throw new TypeError("Cannot clone: unknown type of value (value: ".concat(e,")"))}function Ou(e,t){var n={};for(var r in e)Ze(e,r)&&(n[r]=t(e[r]));return n}function Xr(e,t){if(Array.isArray(t))throw new TypeError("Arrays are not supported by deepExtend");for(var n in t)if(Ze(t,n)&&!(n in Object.prototype)&&!(n in Function.prototype))if(t[n]&&t[n].constructor===Object)e[n]===void 0&&(e[n]={}),e[n]&&e[n].constructor===Object?Xr(e[n],t[n]):e[n]=t[n];else{if(Array.isArray(t[n]))throw new TypeError("Arrays are not supported by deepExtend");e[n]=t[n]}return e}function Mt(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!Mt(e[r],t[r]))return!1;return!0}else{if(typeof e=="function")return e===t;if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!Mt(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}}function Pu(e){var t={};return $r(e,t),t}function $r(e,t){for(var n in e)if(Ze(e,n)){var r=e[n];typeof r=="object"&&r!==null?$r(r,t):t[n]=r}}function Nt(e,t,n){var r=!0,i;Object.defineProperty(e,t,{get:function(){return r&&(i=n(),r=!1),i},set:function(o){i=o,r=!1},configurable:!0,enumerable:!0})}function Ze(e,t){return e&&Object.hasOwnProperty.call(e,t)}function zu(e){return e&&typeof e.factory=="function"}function Ru(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],u=e[i];u!==void 0&&(n[i]=u)}return n}var Lr=["Matrix","Array"],Zr=["number","BigNumber","Fraction"];function qu(e,t){function n(r){if(r){if(r.epsilon!==void 0){console.warn('Warning: The configuration option "epsilon" is deprecated. Use "relTol" and "absTol" instead.');var i=he(r);return i.relTol=r.epsilon,i.absTol=r.epsilon*.001,delete i.epsilon,n(i)}var u=he(e);Wr(r,"matrix",Lr),Wr(r,"number",Zr),Xr(e,r);var o=he(e),s=he(r);return t("config",o,u,s),o}else return he(e)}return n.MATRIX_OPTIONS=Lr,n.NUMBER_OPTIONS=Zr,Object.keys(lr).forEach(r=>{Object.defineProperty(n,r,{get:()=>e[r],enumerable:!0,configurable:!0})}),n}function Wr(e,t,n){e[t]!==void 0&&!n.includes(e[t])&&console.warn('Warning: Unknown value "'+e[t]+'" for configuration option "'+t+'". Available options: '+n.map(r=>JSON.stringify(r)).join(", ")+".")}function Vr(){return!0}function We(){return!1}function xt(){}const Hr="Argument is not a typed-function.";function Jr(){function e(v){return typeof v=="object"&&v!==null&&v.constructor===Object}const t=[{name:"number",test:function(v){return typeof v=="number"}},{name:"string",test:function(v){return typeof v=="string"}},{name:"boolean",test:function(v){return typeof v=="boolean"}},{name:"Function",test:function(v){return typeof v=="function"}},{name:"Array",test:Array.isArray},{name:"Date",test:function(v){return v instanceof Date}},{name:"RegExp",test:function(v){return v instanceof RegExp}},{name:"Object",test:e},{name:"null",test:function(v){return v===null}},{name:"undefined",test:function(v){return v===void 0}}],n={name:"any",test:Vr,isAny:!0};let r,i,u=0,o={createCount:0};function s(v){const _=r.get(v);if(_)return _;let N='Unknown type "'+v+'"';const b=v.toLowerCase();let P;for(P of i)if(P.toLowerCase()===b){N+='. Did you mean "'+P+'" ?';break}throw new TypeError(N)}function f(v){let _=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"any";const N=_?s(_).index:i.length,b=[];for(let O=0;O<v.length;++O){if(!v[O]||typeof v[O].name!="string"||typeof v[O].test!="function")throw new TypeError("Object with properties {name: string, test: function} expected");const X=v[O].name;if(r.has(X))throw new TypeError('Duplicate type name "'+X+'"');b.push(X),r.set(X,{name:X,test:v[O].test,isAny:v[O].isAny,index:N+O,conversionsTo:[]})}const P=i.slice(N);i=i.slice(0,N).concat(b).concat(P);for(let O=N+b.length;O<i.length;++O)r.get(i[O]).index=O}function l(){r=new Map,i=[],u=0,f([n],!1)}l(),f(t);function a(){let v;for(v of i)r.get(v).conversionsTo=[];u=0}function c(v){const _=i.filter(N=>{const b=r.get(N);return!b.isAny&&b.test(v)});return _.length?_:["any"]}function D(v){return v&&typeof v=="function"&&"_typedFunctionData"in v}function w(v,_,N){if(!D(v))throw new TypeError(Hr);const b=N&&N.exact,P=Array.isArray(_)?_.join(","):_,O=A(P),X=g(O);if(!b||X in v.signatures){const ue=v._typedFunctionData.signatureMap.get(X);if(ue)return ue}const Y=O.length;let $;if(b){$=[];let ue;for(ue in v.signatures)$.push(v._typedFunctionData.signatureMap.get(ue))}else $=v._typedFunctionData.signatures;for(let ue=0;ue<Y;++ue){const le=O[ue],Ae=[];let Xe;for(Xe of $){const qe=y(Xe.params,ue);if(!(!qe||le.restParam&&!qe.restParam)){if(!qe.hasAny){const je=F(qe);if(le.types.some(et=>!je.has(et.name)))continue}Ae.push(Xe)}}if($=Ae,$.length===0)break}let R;for(R of $)if(R.params.length<=Y)return R;throw new TypeError("Signature not found (signature: "+(v.name||"unnamed")+"("+g(O,", ")+"))")}function M(v,_,N){return w(v,_,N).implementation}function h(v,_){const N=s(_);if(N.test(v))return v;const b=N.conversionsTo;if(b.length===0)throw new Error("There are no conversions to "+_+" defined.");for(let P=0;P<b.length;P++)if(s(b[P].from).test(v))return b[P].convert(v);throw new Error("Cannot convert "+v+" to "+_)}function g(v){let _=arguments.length>1&&arguments[1]!==void 0?arguments[1]:",";return v.map(N=>N.name).join(_)}function p(v){const _=v.indexOf("...")===0,b=(_?v.length>3?v.slice(3):"any":v).split("|").map(Y=>s(Y.trim()));let P=!1,O=_?"...":"";return{types:b.map(function(Y){return P=Y.isAny||P,O+=Y.name+"|",{name:Y.name,typeIndex:Y.index,test:Y.test,isAny:Y.isAny,conversion:null,conversionIndex:-1}}),name:O.slice(0,-1),hasAny:P,hasConversion:!1,restParam:_}}function E(v){const _=v.types.map(X=>X.name),N=k(_);let b=v.hasAny,P=v.name;const O=N.map(function(X){const Y=s(X.from);return b=Y.isAny||b,P+="|"+X.from,{name:X.from,typeIndex:Y.index,test:Y.test,isAny:Y.isAny,conversion:X,conversionIndex:X.index}});return{types:v.types.concat(O),name:P,hasAny:b,hasConversion:O.length>0,restParam:v.restParam}}function F(v){return v.typeSet||(v.typeSet=new Set,v.types.forEach(_=>v.typeSet.add(_.name))),v.typeSet}function A(v){const _=[];if(typeof v!="string")throw new TypeError("Signatures must be strings");const N=v.trim();if(N==="")return _;const b=N.split(",");for(let P=0;P<b.length;++P){const O=p(b[P].trim());if(O.restParam&&P!==b.length-1)throw new SyntaxError('Unexpected rest parameter "'+b[P]+'": only allowed for the last parameter');if(O.types.length===0)return null;_.push(O)}return _}function d(v){const _=ae(v);return _?_.restParam:!1}function m(v){if(!v||v.types.length===0)return Vr;if(v.types.length===1)return s(v.types[0].name).test;if(v.types.length===2){const _=s(v.types[0].name).test,N=s(v.types[1].name).test;return function(P){return _(P)||N(P)}}else{const _=v.types.map(function(N){return s(N.name).test});return function(b){for(let P=0;P<_.length;P++)if(_[P](b))return!0;return!1}}}function C(v){let _,N,b;if(d(v)){_=Re(v).map(m);const P=_.length,O=m(ae(v)),X=function(Y){for(let $=P;$<Y.length;$++)if(!O(Y[$]))return!1;return!0};return function($){for(let R=0;R<_.length;R++)if(!_[R]($[R]))return!1;return X($)&&$.length>=P+1}}else return v.length===0?function(O){return O.length===0}:v.length===1?(N=m(v[0]),function(O){return N(O[0])&&O.length===1}):v.length===2?(N=m(v[0]),b=m(v[1]),function(O){return N(O[0])&&b(O[1])&&O.length===2}):(_=v.map(m),function(O){for(let X=0;X<_.length;X++)if(!_[X](O[X]))return!1;return O.length===_.length})}function y(v,_){return _<v.length?v[_]:d(v)?ae(v):null}function B(v,_){const N=y(v,_);return N?F(N):new Set}function x(v){return v.conversion===null||v.conversion===void 0}function T(v,_){const N=new Set;return v.forEach(b=>{const P=B(b.params,_);let O;for(O of P)N.add(O)}),N.has("any")?["any"]:Array.from(N)}function q(v,_,N){let b,P;const O=v||"unnamed";let X=N,Y;for(Y=0;Y<_.length;Y++){const le=[];if(X.forEach(Ae=>{const Xe=y(Ae.params,Y),qe=m(Xe);(Y<Ae.params.length||d(Ae.params))&&qe(_[Y])&&le.push(Ae)}),le.length===0){if(P=T(X,Y),P.length>0){const Ae=c(_[Y]);return b=new TypeError("Unexpected type of argument in function "+O+" (expected: "+P.join(" or ")+", actual: "+Ae.join(" | ")+", index: "+Y+")"),b.data={category:"wrongType",fn:O,index:Y,actual:Ae,expected:P},b}}else X=le}const $=X.map(function(le){return d(le.params)?1/0:le.params.length});if(_.length<Math.min.apply(null,$))return P=T(X,Y),b=new TypeError("Too few arguments in function "+O+" (expected: "+P.join(" or ")+", index: "+_.length+")"),b.data={category:"tooFewArgs",fn:O,index:_.length,expected:P},b;const R=Math.max.apply(null,$);if(_.length>R)return b=new TypeError("Too many arguments in function "+O+" (expected: "+R+", actual: "+_.length+")"),b.data={category:"tooManyArgs",fn:O,index:_.length,expectedLength:R},b;const ue=[];for(let le=0;le<_.length;++le)ue.push(c(_[le]).join("|"));return b=new TypeError('Arguments of type "'+ue.join(", ")+'" do not match any of the defined signatures of function '+O+"."),b.data={category:"mismatch",actual:ue},b}function Z(v){let _=i.length+1;for(let N=0;N<v.types.length;N++)x(v.types[N])&&(_=Math.min(_,v.types[N].typeIndex));return _}function W(v){let _=u+1;for(let N=0;N<v.types.length;N++)x(v.types[N])||(_=Math.min(_,v.types[N].conversionIndex));return _}function L(v,_){if(v.hasAny){if(!_.hasAny)return 1}else if(_.hasAny)return-1;if(v.restParam){if(!_.restParam)return 1}else if(_.restParam)return-1;if(v.hasConversion){if(!_.hasConversion)return 1}else if(_.hasConversion)return-1;const N=Z(v)-Z(_);if(N<0)return-1;if(N>0)return 1;const b=W(v)-W(_);return b<0?-1:b>0?1:0}function z(v,_){const N=v.params,b=_.params,P=ae(N),O=ae(b),X=d(N),Y=d(b);if(X&&P.hasAny){if(!Y||!O.hasAny)return 1}else if(Y&&O.hasAny)return-1;let $=0,R=0,ue;for(ue of N)ue.hasAny&&++$,ue.hasConversion&&++R;let le=0,Ae=0;for(ue of b)ue.hasAny&&++le,ue.hasConversion&&++Ae;if($!==le)return $-le;if(X&&P.hasConversion){if(!Y||!O.hasConversion)return 1}else if(Y&&O.hasConversion)return-1;if(R!==Ae)return R-Ae;if(X){if(!Y)return 1}else if(Y)return-1;const Xe=(N.length-b.length)*(X?-1:1);if(Xe!==0)return Xe;const qe=[];let je=0;for(let Ut=0;Ut<N.length;++Ut){const Mn=L(N[Ut],b[Ut]);qe.push(Mn),je+=Mn}if(je!==0)return je;let et;for(et of qe)if(et!==0)return et;return 0}function k(v){if(v.length===0)return[];const _=v.map(s);v.length>1&&_.sort((P,O)=>P.index-O.index);let N=_[0].conversionsTo;if(v.length===1)return N;N=N.concat([]);const b=new Set(v);for(let P=1;P<_.length;++P){let O;for(O of _[P].conversionsTo)b.has(O.from)||(N.push(O),b.add(O.from))}return N}function G(v,_){let N=_;if(v.some(P=>P.hasConversion)){const P=d(v),O=v.map(Q);N=function(){const Y=[],$=P?arguments.length-1:arguments.length;for(let R=0;R<$;R++)Y[R]=O[R](arguments[R]);return P&&(Y[$]=arguments[$].map(O[$])),_.apply(this,Y)}}let b=N;if(d(v)){const P=v.length-1;b=function(){return N.apply(this,ie(arguments,0,P).concat([ie(arguments,P)]))}}return b}function Q(v){let _,N,b,P;const O=[],X=[];switch(v.types.forEach(function(Y){Y.conversion&&(O.push(s(Y.conversion.from).test),X.push(Y.conversion.convert))}),X.length){case 0:return function($){return $};case 1:return _=O[0],b=X[0],function($){return _($)?b($):$};case 2:return _=O[0],N=O[1],b=X[0],P=X[1],function($){return _($)?b($):N($)?P($):$};default:return function($){for(let R=0;R<X.length;R++)if(O[R]($))return X[R]($);return $}}}function j(v){function _(N,b,P){if(b<N.length){const O=N[b];let X=[];if(O.restParam){const Y=O.types.filter(x);Y.length<O.types.length&&X.push({types:Y,name:"..."+Y.map($=>$.name).join("|"),hasAny:Y.some($=>$.isAny),hasConversion:!1,restParam:!0}),X.push(O)}else X=O.types.map(function(Y){return{types:[Y],name:Y.name,hasAny:Y.isAny,hasConversion:Y.conversion,restParam:!1}});return Te(X,function(Y){return _(N,b+1,P.concat([Y]))})}else return[P]}return _(v,0,[])}function re(v,_){const N=Math.max(v.length,_.length);for(let Y=0;Y<N;Y++){const $=B(v,Y),R=B(_,Y);let ue=!1,le;for(le of R)if($.has(le)){ue=!0;break}if(!ue)return!1}const b=v.length,P=_.length,O=d(v),X=d(_);return O?X?b===P:P>=b:X?b>=P:b===P}function te(v){return v.map(_=>at(_)?ke(_.referToSelf.callback):st(_)?Ne(_.referTo.references,_.referTo.callback):_)}function se(v,_,N){const b=[];let P;for(P of v){let O=N[P];if(typeof O!="number")throw new TypeError('No definition for referenced signature "'+P+'"');if(O=_[O],typeof O!="function")return!1;b.push(O)}return b}function Ee(v,_,N){const b=te(v),P=new Array(b.length).fill(!1);let O=!0;for(;O;){O=!1;let X=!0;for(let Y=0;Y<b.length;++Y){if(P[Y])continue;const $=b[Y];if(at($))b[Y]=$.referToSelf.callback(N),b[Y].referToSelf=$.referToSelf,P[Y]=!0,X=!1;else if(st($)){const R=se($.referTo.references,b,_);R?(b[Y]=$.referTo.callback.apply(this,R),b[Y].referTo=$.referTo,P[Y]=!0,X=!1):O=!0}}if(X&&O)throw new SyntaxError("Circular reference detected in resolving typed.referTo")}return b}function Fe(v){const _=/\bthis(\(|\.signatures\b)/;Object.keys(v).forEach(N=>{const b=v[N];if(_.test(b.toString()))throw new SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function ge(v,_){if(o.createCount++,Object.keys(_).length===0)throw new SyntaxError("No signatures provided");o.warnAgainstDeprecatedThis&&Fe(_);const N=[],b=[],P={},O=[];let X;for(X in _){if(!Object.prototype.hasOwnProperty.call(_,X))continue;const ne=A(X);if(!ne)continue;N.forEach(function(Kt){if(re(Kt,ne))throw new TypeError('Conflicting signatures "'+g(Kt)+'" and "'+g(ne)+'".')}),N.push(ne);const $e=b.length;b.push(_[X]);const Qa=ne.map(E);let Nn;for(Nn of j(Qa)){const Kt=g(Nn);O.push({params:Nn,name:Kt,fn:$e}),Nn.every(Ka=>!Ka.hasConversion)&&(P[Kt]=$e)}}O.sort(z);const Y=Ee(b,P,Qt);let $;for($ in P)Object.prototype.hasOwnProperty.call(P,$)&&(P[$]=Y[P[$]]);const R=[],ue=new Map;for($ of O)ue.has($.name)||($.fn=Y[$.fn],R.push($),ue.set($.name,$));const le=R[0]&&R[0].params.length<=2&&!d(R[0].params),Ae=R[1]&&R[1].params.length<=2&&!d(R[1].params),Xe=R[2]&&R[2].params.length<=2&&!d(R[2].params),qe=R[3]&&R[3].params.length<=2&&!d(R[3].params),je=R[4]&&R[4].params.length<=2&&!d(R[4].params),et=R[5]&&R[5].params.length<=2&&!d(R[5].params),Ut=le&&Ae&&Xe&&qe&&je&&et;for(let ne=0;ne<R.length;++ne)R[ne].test=C(R[ne].params);const Mn=le?m(R[0].params[0]):We,Ca=Ae?m(R[1].params[0]):We,ya=Xe?m(R[2].params[0]):We,Ba=qe?m(R[3].params[0]):We,_a=je?m(R[4].params[0]):We,Ma=et?m(R[5].params[0]):We,Na=le?m(R[0].params[1]):We,xa=Ae?m(R[1].params[1]):We,Sa=Xe?m(R[2].params[1]):We,Ta=qe?m(R[3].params[1]):We,ba=je?m(R[4].params[1]):We,Ia=et?m(R[5].params[1]):We;for(let ne=0;ne<R.length;++ne)R[ne].implementation=G(R[ne].params,R[ne].fn);const Oa=le?R[0].implementation:xt,Pa=Ae?R[1].implementation:xt,za=Xe?R[2].implementation:xt,Ra=qe?R[3].implementation:xt,qa=je?R[4].implementation:xt,Ya=et?R[5].implementation:xt,Ua=le?R[0].params.length:-1,Xa=Ae?R[1].params.length:-1,$a=Xe?R[2].params.length:-1,La=qe?R[3].params.length:-1,Za=je?R[4].params.length:-1,Wa=et?R[5].params.length:-1,Va=Ut?6:0,Ha=R.length,Ja=R.map(ne=>ne.test),ka=R.map(ne=>ne.implementation),Ga=function(){for(let $e=Va;$e<Ha;$e++)if(Ja[$e](arguments))return ka[$e].apply(this,arguments);return o.onMismatch(v,arguments,R)};function Qt(ne,$e){return arguments.length===Ua&&Mn(ne)&&Na($e)?Oa.apply(this,arguments):arguments.length===Xa&&Ca(ne)&&xa($e)?Pa.apply(this,arguments):arguments.length===$a&&ya(ne)&&Sa($e)?za.apply(this,arguments):arguments.length===La&&Ba(ne)&&Ta($e)?Ra.apply(this,arguments):arguments.length===Za&&_a(ne)&&ba($e)?qa.apply(this,arguments):arguments.length===Wa&&Ma(ne)&&Ia($e)?Ya.apply(this,arguments):Ga.apply(this,arguments)}try{Object.defineProperty(Qt,"name",{value:v})}catch{}return Qt.signatures=P,Qt._typedFunctionData={signatures:R,signatureMap:ue},Qt}function pe(v,_,N){throw q(v,_,N)}function Re(v){return ie(v,0,v.length-1)}function ae(v){return v[v.length-1]}function ie(v,_,N){return Array.prototype.slice.call(v,_,N)}function Je(v,_){for(let N=0;N<v.length;N++)if(_(v[N]))return v[N]}function Te(v,_){return Array.prototype.concat.apply([],v.map(_))}function fe(){const v=Re(arguments).map(N=>g(A(N))),_=ae(arguments);if(typeof _!="function")throw new TypeError("Callback function expected as last argument");return Ne(v,_)}function Ne(v,_){return{referTo:{references:v,callback:_}}}function ke(v){if(typeof v!="function")throw new TypeError("Callback function expected as first argument");return{referToSelf:{callback:v}}}function st(v){return v&&typeof v.referTo=="object"&&Array.isArray(v.referTo.references)&&typeof v.referTo.callback=="function"}function at(v){return v&&typeof v.referToSelf=="object"&&typeof v.referToSelf.callback=="function"}function qt(v,_){if(!v)return _;if(_&&_!==v){const N=new Error("Function names do not match (expected: "+v+", actual: "+_+")");throw N.data={actual:_,expected:v},N}return v}function Yt(v){let _;for(const N in v)Object.prototype.hasOwnProperty.call(v,N)&&(D(v[N])||typeof v[N].signature=="string")&&(_=qt(_,v[N].name));return _}function Kn(v,_){let N;for(N in _)if(Object.prototype.hasOwnProperty.call(_,N)){if(N in v&&_[N]!==v[N]){const b=new Error('Signature "'+N+'" is defined twice');throw b.data={signature:N,sourceFunction:_[N],destFunction:v[N]},b}v[N]=_[N]}}const Aa=o;o=function(v){const _=typeof v=="string",N=_?1:0;let b=_?v:"";const P={};for(let O=N;O<arguments.length;++O){const X=arguments[O];let Y={},$;if(typeof X=="function"?($=X.name,typeof X.signature=="string"?Y[X.signature]=X:D(X)&&(Y=X.signatures)):e(X)&&(Y=X,_||($=Yt(X))),Object.keys(Y).length===0){const R=new TypeError("Argument to 'typed' at index "+O+" is not a (typed) function, nor an object with signatures as keys and functions as values.");throw R.data={index:O,argument:X},R}_||(b=qt(b,$)),Kn(P,Y)}return ge(b||"",P)},o.create=Jr,o.createCount=Aa.createCount,o.onMismatch=pe,o.throwMismatchError=pe,o.createError=q,o.clear=l,o.clearConversions=a,o.addTypes=f,o._findType=s,o.referTo=fe,o.referToSelf=ke,o.convert=h,o.findSignature=w,o.find=M,o.isTypedFunction=D,o.warnAgainstDeprecatedThis=!0,o.addType=function(v,_){let N="any";_!==!1&&r.has("Object")&&(N="Object"),o.addTypes([v],N)};function Gi(v){if(!v||typeof v.from!="string"||typeof v.to!="string"||typeof v.convert!="function")throw new TypeError("Object with properties {from: string, to: string, convert: function} expected");if(v.to===v.from)throw new SyntaxError('Illegal to define conversion from "'+v.from+'" to itself.')}return o.addConversion=function(v){let _=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};Gi(v);const N=s(v.to),b=N.conversionsTo.find(P=>P.from===v.from);if(b)if(_&&_.override)o.removeConversion({from:b.from,to:v.to,convert:b.convert});else throw new Error('There is already a conversion from "'+v.from+'" to "'+N.name+'"');N.conversionsTo.push({from:v.from,convert:v.convert,index:u++})},o.addConversions=function(v,_){v.forEach(N=>o.addConversion(N,_))},o.removeConversion=function(v){Gi(v);const _=s(v.to),N=Je(_.conversionsTo,P=>P.from===v.from);if(!N)throw new Error("Attempt to remove nonexistent conversion from "+v.from+" to "+v.to);if(N.convert!==v.convert)throw new Error("Conversion to remove does not match existing conversion");const b=_.conversionsTo.indexOf(N);_.conversionsTo.splice(b,1)},o.resolve=function(v,_){if(!D(v))throw new TypeError(Hr);const N=v._typedFunctionData.signatures;for(let b=0;b<N.length;++b)if(N[b].test(_))return N[b];return null},o}const Ht=Jr();function ve(e,t,n,r){function i(u){var o=Ru(u,t.map(kr));return Yu(e,t,u),n(o)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Jt(e){return typeof e=="function"&&typeof e.fn=="string"&&Array.isArray(e.dependencies)}function Yu(e,t,n){var r=t.filter(u=>!Uu(u)).every(u=>n[u]!==void 0);if(!r){var i=t.filter(u=>n[u]===void 0);throw new Error('Cannot create function "'.concat(e,'", ')+"some dependencies are missing: ".concat(i.map(u=>'"'.concat(u,'"')).join(", "),"."))}}function Uu(e){return e&&e[0]==="?"}function kr(e){return e&&e[0]==="?"?e.slice(1):e}function xe(e){return typeof e=="boolean"?!0:isFinite(e)?e===Math.round(e):!1}function Rn(e,t,n){var r={2:"0b",8:"0o",16:"0x"},i=r[t],u="";if(n){if(n<1)throw new Error("size must be in greater than 0");if(!xe(n))throw new Error("size must be an integer");if(e>2**(n-1)-1||e<-(2**(n-1)))throw new Error("Value must be in range [-2^".concat(n-1,", 2^").concat(n-1,"-1]"));if(!xe(e))throw new Error("Value must be an integer");e<0&&(e=e+2**n),u="i".concat(n)}var o="";return e<0&&(e=-e,o="-"),"".concat(o).concat(i).concat(e.toString(t)).concat(u)}function qn(e,t){if(typeof t=="function")return t(e);if(e===1/0)return"Infinity";if(e===-1/0)return"-Infinity";if(isNaN(e))return"NaN";var{notation:n,precision:r,wordSize:i}=Gr(t);switch(n){case"fixed":return $u(e,r);case"exponential":return Qr(e,r);case"engineering":return Xu(e,r);case"bin":return Rn(e,2,i);case"oct":return Rn(e,8,i);case"hex":return Rn(e,16,i);case"auto":return Lu(e,r,t).replace(/((\.\d*?)(0+))($|e)/,function(){var u=arguments[2],o=arguments[4];return u!=="."?u+o:o});default:throw new Error('Unknown notation "'+n+'". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.')}}function Gr(e){var t="auto",n,r;if(e!==void 0)if(ce(e))n=e;else if(ye(e))n=e.toNumber();else if(Bt(e))e.precision!==void 0&&(n=Kr(e.precision,()=>{throw new Error('Option "precision" must be a number or BigNumber')})),e.wordSize!==void 0&&(r=Kr(e.wordSize,()=>{throw new Error('Option "wordSize" must be a number or BigNumber')})),e.notation&&(t=e.notation);else throw new Error("Unsupported type of options, number, BigNumber, or object expected");return{notation:t,precision:n,wordSize:r}}function fn(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw new SyntaxError("Invalid number "+e);var n=t[1],r=t[2],i=parseFloat(t[4]||"0"),u=r.indexOf(".");i+=u!==-1?u-1:r.length-1;var o=r.replace(".","").replace(/^0*/,function(s){return i-=s.length,""}).replace(/0*$/,"").split("").map(function(s){return parseInt(s)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function Xu(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=fn(e),r=cn(n,t),i=r.exponent,u=r.coefficients,o=i%3===0?i:i<0?i-3-i%3:i-i%3;if(ce(t))for(;t>u.length||i-o+1>u.length;)u.push(0);else for(var s=Math.abs(i-o)-(u.length-1),f=0;f<s;f++)u.push(0);for(var l=Math.abs(i-o),a=1;l>0;)a++,l--;var c=u.slice(a).join(""),D=ce(t)&&c.length||c.match(/[1-9]/)?"."+c:"",w=u.slice(0,a).join("")+D+"e"+(i>=0?"+":"")+o.toString();return r.sign+w}function $u(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=fn(e),r=typeof t=="number"?cn(n,n.exponent+1+t):n,i=r.coefficients,u=r.exponent+1,o=u+(t||0);return i.length<o&&(i=i.concat(St(o-i.length))),u<0&&(i=St(-u+1).concat(i),u=1),u<i.length&&i.splice(u,0,u===0?"0.":"."),r.sign+i.join("")}function Qr(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=fn(e),r=t?cn(n,t):n,i=r.coefficients,u=r.exponent;i.length<t&&(i=i.concat(St(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?"."+i.join(""):"")+"e"+(u>=0?"+":"")+u}function Lu(e,t,n){if(isNaN(e)||!isFinite(e))return String(e);var r=jr(n?.lowerExp,-3),i=jr(n?.upperExp,5),u=fn(e),o=t?cn(u,t):u;if(o.exponent<r||o.exponent>=i)return Qr(e,t);var s=o.coefficients,f=o.exponent;s.length<t&&(s=s.concat(St(t-s.length))),s=s.concat(St(f-s.length+1+(s.length<t?t-s.length:0))),s=St(-f).concat(s);var l=f>0?f:0;return l<s.length-1&&s.splice(l+1,0,"."),o.sign+s.join("")}function cn(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t){var i=r.splice(t,r.length-t);if(i[0]>=5){var u=t-1;for(r[u]++;r[u]===10;)r.pop(),u===0&&(r.unshift(0),n.exponent++,u++),u--,r[u]++}}return n}function St(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function Zu(e){return e.toExponential().replace(/e.*$/,"").replace(/^0\.?0*|\./,"").length}function ln(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1e-8,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;if(n<=0)throw new Error("Relative tolerance must be greater than 0");if(r<0)throw new Error("Absolute tolerance must be at least 0");return isNaN(e)||isNaN(t)?!1:!isFinite(e)||!isFinite(t)?e===t:e===t?!0:Math.abs(e-t)<=Math.max(n*Math.max(Math.abs(e),Math.abs(t)),r)}function Kr(e,t){if(ce(e))return e;if(ye(e))return e.toNumber();t()}function jr(e,t){return ce(e)?e:ye(e)?e.toNumber():t}var ei=function(){return ei=Ht.create,Ht},Wu=["?BigNumber","?Complex","?DenseMatrix","?Fraction"],Vu=ve("typed",Wu,function(t){var{BigNumber:n,Complex:r,DenseMatrix:i,Fraction:u}=t,o=ei();return o.clear(),o.addTypes([{name:"number",test:ce},{name:"Complex",test:un},{name:"BigNumber",test:ye},{name:"bigint",test:hr},{name:"Fraction",test:on},{name:"Unit",test:sn},{name:"identifier",test:s=>Ge&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDDC0-\uDDF3\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDD4A-\uDD65\uDD6F-\uDD85\uDE80-\uDEA9\uDEB0\uDEB1\uDEC2-\uDEC4\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61\uDF80-\uDF89\uDF8B\uDF8E\uDF90-\uDFB5\uDFB7\uDFD1\uDFD3]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDC