diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index 1ed8456..f707663 100644 --- a/dist/game/eMath.game.min.js +++ b/dist/game/eMath.game.min.js @@ -1,4 +1,4 @@ -"use strict";(function(Ot,at){var Ft=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],at);else if(typeof module=="object"&&module.exports)module.exports=at();else{var ft=at(),xt=Ft?exports:Ot;for(var Tt in ft)xt[Tt]=ft[Tt]}})(typeof self<"u"?self:exports,()=>{var Ot={},at={exports:Ot},Ft=Object.create,ft=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Tt=Object.getOwnPropertyNames,He=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty,wt=(t,e)=>function(){return e||(0,t[Tt(t)[0]])((e={exports:{}}).exports,e),e.exports},Ut=(t,e)=>{for(var r in e)ft(t,r,{get:e[r],enumerable:!0})},ne=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Tt(e))!We.call(t,n)&&n!==r&&ft(t,n,{get:()=>e[n],enumerable:!(i=xt(e,n))||i.enumerable});return t},st=(t,e,r)=>(r=t!=null?Ft(He(t)):{},ne(e||!t||!t.__esModule?ft(r,"default",{value:t,enumerable:!0}):r,t)),Xe=t=>ne(ft({},"__esModule",{value:!0}),t),nt=(t,e,r,i)=>{for(var n=i>1?void 0:i?xt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&ft(e,r,n),n},lt=wt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(u,v){return function(f,l){Object.defineProperty(u,f,{configurable:!0,writable:!0,value:l}),v&&v(f,l)}}function c(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return c()||g()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",c=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",u={__proto__:[]}instanceof Array,v=!m&&!u,f={create:m?function(){return re(Object.create(null))}:u?function(){return re({__proto__:null})}:function(){return re({})},has:v?function(N,w){return n.call(N,w)}:function(N,w){return w in N},get:v?function(N,w){return n.call(N,w)?N[w]:void 0}:function(N,w){return N[w]}},l=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:$r(),p=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Yr(),d=typeof WeakMap=="function"?WeakMap:zr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,E=jr(),P=Gr(E);function a(N,w,A,C){if(R(A)){if(!ke(N))throw new TypeError;if(!qe(w))throw new TypeError;return K(N,w)}else{if(!ke(N))throw new TypeError;if(!X(w))throw new TypeError;if(!X(C)&&!R(C)&&!It(C))throw new TypeError;return It(C)&&(C=void 0),A=ut(A),it(N,w,A,C)}}r("decorate",a);function S(N,w){function A(C,U){if(!X(C))throw new TypeError;if(!R(U)&&!Ur(U))throw new TypeError;qt(N,w,C,U)}return A}r("metadata",S);function y(N,w,A,C){if(!X(A))throw new TypeError;return R(C)||(C=ut(C)),qt(N,w,A,C)}r("defineMetadata",y);function I(N,w,A){if(!X(w))throw new TypeError;return R(A)||(A=ut(A)),H(N,w,A)}r("hasMetadata",I);function _(N,w,A){if(!X(w))throw new TypeError;return R(A)||(A=ut(A)),Y(N,w,A)}r("hasOwnMetadata",_);function M(N,w,A){if(!X(w))throw new TypeError;return R(A)||(A=ut(A)),W(N,w,A)}r("getMetadata",M);function F(N,w,A){if(!X(w))throw new TypeError;return R(A)||(A=ut(A)),gt(N,w,A)}r("getOwnMetadata",F);function x(N,w){if(!X(N))throw new TypeError;return R(w)||(w=ut(w)),Bt(N,w)}r("getMetadataKeys",x);function j(N,w){if(!X(N))throw new TypeError;return R(w)||(w=ut(w)),Dt(N,w)}r("getOwnMetadataKeys",j);function z(N,w,A){if(!X(w))throw new TypeError;if(R(A)||(A=ut(A)),!X(w))throw new TypeError;R(A)||(A=ut(A));var C=Ct(w,A,!1);return R(C)?!1:C.OrdinaryDeleteMetadata(N,w,A)}r("deleteMetadata",z);function K(N,w){for(var A=N.length-1;A>=0;--A){var C=N[A],U=C(w);if(!R(U)&&!It(U)){if(!qe(U))throw new TypeError;w=U}}return w}function it(N,w,A,C){for(var U=N.length-1;U>=0;--U){var J=N[U],tt=J(w,A,C);if(!R(tt)&&!It(tt)){if(!X(tt))throw new TypeError;C=tt}}return C}function H(N,w,A){var C=Y(N,w,A);if(C)return!0;var U=ee(w);return It(U)?!1:H(N,U,A)}function Y(N,w,A){var C=Ct(w,A,!1);return R(C)?!1:Le(C.OrdinaryHasOwnMetadata(N,w,A))}function W(N,w,A){var C=Y(N,w,A);if(C)return gt(N,w,A);var U=ee(w);if(!It(U))return W(N,U,A)}function gt(N,w,A){var C=Ct(w,A,!1);if(!R(C))return C.OrdinaryGetOwnMetadata(N,w,A)}function qt(N,w,A,C){var U=Ct(A,C,!0);U.OrdinaryDefineOwnMetadata(N,w,A,C)}function Bt(N,w){var A=Dt(N,w),C=ee(N);if(C===null)return A;var U=Bt(C,w);if(U.length<=0)return A;if(A.length<=0)return U;for(var J=new p,tt=[],Z=0,L=A;Z=0&&L=this._keys.length?(this._index=-1,this._keys=w,this._values=w):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},Z.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=w,this._values=w),L},Z.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=w,this._values=w),{value:L,done:!0}},Z}(),C=function(){function Z(){this._keys=[],this._values=[],this._cacheKey=N,this._cacheIndex=-2}return Object.defineProperty(Z.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Z.prototype.has=function(L){return this._find(L,!1)>=0},Z.prototype.get=function(L){var k=this._find(L,!1);return k>=0?this._values[k]:void 0},Z.prototype.set=function(L,k){var q=this._find(L,!0);return this._values[q]=k,this},Z.prototype.delete=function(L){var k=this._find(L,!1);if(k>=0){for(var q=this._keys.length,B=k+1;B>>8,f[l*2+1]=p%256}return f},decompressFromUint8Array:function(u){if(u==null)return m.decompress(u);for(var v=new Array(u.length/2),f=0,l=v.length;f>1}else{for(h=1,l=0;l>1}a--,a==0&&(a=Math.pow(2,y),y++),delete d[P]}else for(h=p[P],l=0;l>1;a--,a==0&&(a=Math.pow(2,y),y++),p[E]=S++,P=String(O)}if(P!==""){if(Object.prototype.hasOwnProperty.call(d,P)){if(P.charCodeAt(0)<256){for(l=0;l>1}else{for(h=1,l=0;l>1}a--,a==0&&(a=Math.pow(2,y),y++),delete d[P]}else for(h=p[P],l=0;l>1;a--,a==0&&(a=Math.pow(2,y),y++)}for(h=2,l=0;l>1;for(;;)if(_=_<<1,M==v-1){I.push(f(_));break}else M++;return I.join("")},decompress:function(u){return u==null?"":u==""?null:m._decompress(u.length,32768,function(v){return u.charCodeAt(v)})},_decompress:function(u,v,f){var l=[],h,p=4,d=4,O=3,E="",P=[],a,S,y,I,_,M,F,x={val:f(0),position:v,index:1};for(a=0;a<3;a+=1)l[a]=a;for(y=0,_=Math.pow(2,2),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;switch(h=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 2:return""}for(l[3]=F,S=F,P.push(F);;){if(x.index>u)return"";for(y=0,_=Math.pow(2,O),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;switch(F=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;l[d++]=i(y),F=d-1,p--;break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=x.val&x.position,x.position>>=1,x.position==0&&(x.position=v,x.val=f(x.index++)),y|=(I>0?1:0)*M,M<<=1;l[d++]=i(y),F=d-1,p--;break;case 2:return P.join("")}if(p==0&&(p=Math.pow(2,O),O++),l[F])E=l[F];else if(F===d)E=S+S.charAt(0);else return null;P.push(E),l[d++]=S+E.charAt(0),p--,S=E,p==0&&(p=Math.pow(2,O),O++)}}};return m}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),Qe=wt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],c=0,g=0;c>>5]|=n[c]<<24-g%32;return o},wordsToBytes:function(n){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(n){for(var o=[],c=0;c>>4).toString(16)),o.push((n[c]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],c=0;c>>6*(3-m)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,g=0;c>>6-g*2);return o}};e.exports=i})()}}),se=wt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],o=0;o>>24)&16711935|(u[d]<<24|u[d]>>>8)&4278255360;u[v>>>5]|=128<>>9<<4)+14]=v;for(var O=c._ff,E=c._gg,P=c._hh,a=c._ii,d=0;d>>0,l=l+y>>>0,h=h+I>>>0,p=p+_>>>0}return r.endian([f,l,h,p])};c._ff=function(g,m,u,v,f,l,h){var p=g+(m&u|~m&v)+(f>>>0)+h;return(p<>>32-l)+m},c._gg=function(g,m,u,v,f,l,h){var p=g+(m&v|u&~v)+(f>>>0)+h;return(p<>>32-l)+m},c._hh=function(g,m,u,v,f,l,h){var p=g+(m^u^v)+(f>>>0)+h;return(p<>>32-l)+m},c._ii=function(g,m,u,v,f,l,h){var p=g+(u^(m|~v))+(f>>>0)+h;return(p<>>32-l)+m},c._blocksize=16,c._digestsize=16,e.exports=function(g,m){if(g==null)throw new Error("Illegal argument "+g);var u=r.wordsToBytes(c(g,m));return m&&m.asBytes?u:m&&m.asString?o.bytesToString(u):r.bytesToHex(u)}})()}}),oe={};Ut(oe,{default:()=>Pr}),at.exports=Xe(oe);var Wr=st(lt()),Xr=st(lt()),ae={};Ut(ae,{Attribute:()=>Lt,AttributeStatic:()=>be,Boost:()=>zt,BoostObject:()=>St,Currency:()=>mt,CurrencyStatic:()=>we,DEFAULT_ITERATIONS:()=>Pt,Decimal:()=>s,E:()=>Ar,FORMATS:()=>Mr,FormatTypeList:()=>ar,Grid:()=>_e,GridCell:()=>Me,GridCellCollection:()=>vt,Item:()=>ve,ItemData:()=>yt,LRUCache:()=>Rt,ListNode:()=>ue,ST_NAMES:()=>ct,UpgradeData:()=>Nt,UpgradeStatic:()=>Jt,calculateItem:()=>ye,calculateSum:()=>Xt,calculateSumApprox:()=>ge,calculateSumLoop:()=>me,calculateUpgrade:()=>pe,decimalToJSONString:()=>Ne,equalsTolerance:()=>Ht,formats:()=>dt,inverseFunctionApprox:()=>Wt,roundingBase:()=>Sr,upgradeToCacheNameEL:()=>Ir});var Jr=st(lt()),Rt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new ue(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},ue=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},G;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(G||(G={}));var er=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===G.CLASS_TO_CLASS||i===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===G.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(f){return f.propertyName!==void 0}));for(var o=[],c=0,g=this.getAncestors(r);c0&&(c=c.filter(function(f){return!u.includes(f)})),this.options.version!==void 0&&(c=c.filter(function(f){var l=et.findExposeMetadata(e,f);return!l||!l.options?!0:n.checkVersion(l.options.since,l.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(f){var l=et.findExposeMetadata(e,f);return!l||!l.options?!0:n.checkGroups(l.options.groups)}):c=c.filter(function(f){var l=et.findExposeMetadata(e,f);return!l||!l.options||!l.options.groups||!l.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(c=c.filter(function(v){return n.options.excludePrefixes.every(function(f){return v.substr(0,f.length)!==f})})),c=c.filter(function(v,f,l){return l.indexOf(v)===f}),c},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(3)){let j=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(2)){let j=[];for(let z=0;z118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][I]},beyondOg(a){let S=Math.floor(Math.log10(a)),y=["n","u","b","t","q","p","h","s","o","e"],I="";for(let _=S;_>=0;_--){let M=Math.floor(a/Math.pow(10,_))%10;I==""?I=y[M].toUpperCase():I+=y[M]}return I},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let S=a.log(118).toNumber(),y=Math.floor(S)+1,I=e.elemental.abbreviationLength(y),_=S-y+1,M=Math.floor(_*I),F=e.elemental.getAbbreviation(y,_),x=new t(118).pow(y+M/I-1);return[F,x]},formatElementalPart(a,S){return S.eq(1)?a:`${S.toString()} ${a}`},format(a,S=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),S);let y=a.log(118),_=y.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),F=[];for(;y.gte(1)&&F.length=M)return F.map(j=>e.elemental.formatElementalPart(j[0],j[1])).join(" + ");let x=new t(118).pow(y).toFixed(F.length===1?3:S);return F.length===0?x:F.length===1?`${x} \xD7 ${e.elemental.formatElementalPart(F[0][0],F[0][1])}`:`${x} \xD7 (${F.map(j=>e.elemental.formatElementalPart(j[0],j[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(t.dTen.pow(y));return(y.log10().gte(9)?"":I.toFixed(4))+"e"+e.old_sc.format(y,0)}}},eng:{format(a,S=2){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let I=a.div(new t(1e3).pow(y.div(3).floor()));return(y.log10().gte(9)?"":I.toFixed(new t(4).sub(y.sub(y.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(y.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,y=9){a=new t(a);let I=a.log10().floor();return I.lt(303)&&I.gte(y)?m(a,S,y,"st"):m(a,S,y,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,y){a=new t(a);let I=a.max(1).log10().max(1).log(r.log10()).floor();if(I.lte(0))return m(a,S,y,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return m(a,Math.max(4,S),y,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+m(_,0,y,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ct[0][0][a%10]+ct[0][1][Math.floor(a/10)%10]+ct[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,y=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ct[1][0][a]:(y==1&&S==0?_+="Vec":_+=ct[1][1][S]+ct[1][2][y],_+=ct[1][3][I],_)}},inf:{format(a,S,y){a=new t(a);let I=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],F=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?m(a,S,y,"sc"):a.gte(3)?F[I]+M[I]+"\u03C9^"+m(a.sub(1),S,y,"sc"):a.gte(2)?F[I]+"\u03C9"+M[I]+"-"+m(_.pow(a.sub(2)),S,y,"sc"):F[I]+M[I]+"-"+m(_.pow(a.sub(1)),S,y,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),y=!1,I=9){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,M=_.length,F=a.log(1e3).sub(S.log(1e3)).floor(),x=F.add(1).log(M+1).ceil(),j="",z=(K,it)=>{let H=K,Y="";for(let W=0;W=M)return"\u03C9";Y=_[gt]+Y,H=H.sub(1).div(M).floor()}return Y};if(x.lt(I))j=z(F,x);else{let K=x.sub(I).add(1),it=F.div(t.pow(M+1,K.sub(1))).floor();j=`${z(it,new t(I))}(${K.gt("1e9")?K.format():K.format(0)})`}return j},format(a,S=2,y=9,I="mixed_sc",_=new t(1e15),M=!1,F){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return m(a,S,y,I);let x=e.alphabet.getAbbreviation(a,_,M,F),j=a.div(t.pow(1e3,a.log(1e3).floor()));return`${x.length>(F??9)+2?"":j.toFixed(S)+" "}${x}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function g(a,S=2,y=9,I="st"){return m(a,S,y,I)}function m(a,S=2,y=9,I="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(S);let M=a.log10().floor();switch(I){case"sc":case"scientific":if(a.log10().lt(Math.min(-S,0))&&S>1){let F=a.log10().ceil(),x=a.div(F.eq(-1)?new t(.1):t.dTen.pow(F)),j=F.mul(-1).max(1).log10().gte(9);return _+(j?"":x.toFixed(2))+"e"+m(F,0,y,"mixed_sc")}else if(M.lt(y)){let F=Math.max(Math.min(S-M.toNumber(),S),0);return _+(F>0?a.toFixed(F):a.toFixed(F).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let j=a.slog();return(j.gte(1e9)?"":t.dTen.pow(j.sub(j.floor())).toFixed(2))+"F"+m(j.floor(),0)}let F=a.div(t.dTen.pow(M)),x=M.log10().gte(9);return _+(x?"":F.toFixed(2))+"e"+m(M,0,y,"mixed_sc")}case"st":case"standard":{let F=a.log(1e3).floor();if(F.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let x=F.mul(3),j=F.log10().floor();if(j.gte(3e3))return"e"+m(M,S,y,"st");let z="";if(F.lt(4))z=["","K","M","B"][Math.round(F.toNumber())];else{let H=Math.floor(F.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),F=F.sub(1).div(t.dTen.pow(H*3));F.gt(0);){let Y=F.div(1e3).floor(),W=F.sub(Y.mul(1e3)).floor().toNumber();W>0&&(W==1&&!H&&(z="U"),H&&(z=e.standard.tier2(H)+(z?"-"+z:"")),W>1&&(z=e.standard.tier1(W)+z)),F=Y,H++}}let K=a.div(t.dTen.pow(x)),it=S===2?t.dTwo.sub(M.sub(x)).add(1).toNumber():S;return _+(j.gte(10)?"":K.toFixed(it)+" ")+z}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,y)}}function u(a,S,y="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),F,x=M.div(a);return x.gte(10)&&a.gte(1e100)?(x=x.log10().mul(20),F="(+"+m(x,I,_,y)+" OoMs/sec)"):F="(+"+m(S,I,_,y)+"/sec)",F}function v(a,S=2,y="s"){return a=new t(a),a.gte(86400)?m(a.div(86400).floor(),0,12,"sc")+":"+v(a.mod(86400),S,"d"):a.gte(3600)||y=="d"?(a.div(3600).gte(10)||y!="d"?"":"0")+m(a.div(3600).floor(),0,12,"sc")+":"+v(a.mod(3600),S,"h"):a.gte(60)||y=="h"?(a.div(60).gte(10)||y!="h"?"":"0")+m(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||y!="m"?"":"0")+m(a,S,12,"sc")}function f(a,S=!1,y=0,I=9,_="mixed_sc"){let M=Dt=>m(Dt,y,I,_);a=new t(a);let F=a.mul(1e3).mod(1e3).floor(),x=a.mod(60).floor(),j=a.div(60).mod(60).floor(),z=a.div(3600).mod(24).floor(),K=a.div(86400).mod(365.2425).floor(),it=a.div(31556952).floor(),H=it.eq(1)?" year":" years",Y=K.eq(1)?" day":" days",W=z.eq(1)?" hour":" hours",gt=j.eq(1)?" minute":" minutes",qt=x.eq(1)?" second":" seconds",Bt=F.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?M(it)+H+", ":""}${K.gt(0)?M(K)+Y+", ":""}${z.gt(0)?M(z)+W+", ":""}${j.gt(0)?M(j)+gt+", ":""}${x.gt(0)?M(x)+qt+",":""}${S&&F.gt(0)?" "+M(F)+Bt:""}`.replace(/,([^,]*)$/,"$1").trim()}function l(a){return a=new t(a),m(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),m(a.mul(100))+"%"}function p(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function d(a,S,y=10){return t.gte(a,10)?t.pow(y,t.log(a,y).pow(S)):new t(a)}function O(a,S=0){a=new t(a);let y=(F=>F.map((x,j)=>({name:x.name,altName:x.altName,value:t.pow(1e3,new t(j).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),I="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),y.length-1).floor().toNumber(),M=y[_];if(_===0)switch(S){case 1:I="";break;case 2:case 0:default:I=a.format();break}switch(S){case 1:I=M.name;break;case 2:I=a.divide(M.value).format();break;case 3:I=M.altName;break;case 0:default:I=`${a.divide(M.value).format()} ${M.name}`;break}return I}function E(a,S=!1){return`${O(a,2)} ${O(a,1)}eV${S?"/c^2":""}`}let P={...e,toSubscript:o,toSuperscript:c,formatST:g,format:m,formatGain:u,formatTime:v,formatTimeLong:f,formatReduction:l,formatPercent:h,formatMult:p,expMult:d,metric:O,ev:E};return{FORMATS:e,formats:P}}var Zt=17,lr=9e15,fr=Math.log10(9e15),cr=1/9e15,hr=308,dr=-324,ce=5,mr=1023,gr=!0,pr=!1,Nr=function(){let t=[];for(let r=dr+1;r<=hr;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),pt=[2,Math.E,3,4,5,6,7,8,9,10],yr=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],vr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],b=function(e){return s.fromValue_noAlloc(e)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},ht=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},$t=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},wr=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r-1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r-1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r-691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r-3617/(122400*n),Math.exp(r)/e},br=.36787944117144233,he=.5671432904097838,Yt=function(t,e=1e-10,r=!0){let i,n;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return he;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),D(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),c=o.pow(2);return o.neg().add(c.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=lr)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);gr?t=t.replace(",",""):pr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let d=parseFloat(n[0]),O=parseFloat(n[1]),E=n[1].split(";"),P=1;if(E.length===2&&(P=parseFloat(E[1]),isFinite(P)||(P=1)),isFinite(d)&&isFinite(O)){let a=s.pentate(d,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let d=parseFloat(o[0]),O=parseFloat(o[1]),E=o[1].split(";"),P=1;if(E.length===2&&(P=parseFloat(E[1]),isFinite(P)||(P=1)),isFinite(d)&&isFinite(O)){let a=s.tetrate(d,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let d=parseFloat(c[0]),O=parseFloat(c[1]);if(isFinite(d)&&isFinite(O)){let E=s.pow(d,O);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,m,u=t.split("pt");if(u.length===2){g=10;let d=!1;u[0].startsWith("-")&&(d=!0,u[0]=u[0].slice(1)),m=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(g)&&isFinite(m)){let E=s.tetrate(g,m,O,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(u=t.split("p"),u.length===2){g=10;let d=!1;u[0].startsWith("-")&&(d=!0,u[0]=u[0].slice(1)),m=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(g)&&isFinite(m)){let E=s.tetrate(g,m,O,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(u=t.split("f"),u.length===2){g=10;let d=!1;u[0].startsWith("-")&&(d=!0,u[0]=u[0].slice(1)),u[0]=u[0].replace("(",""),u[0]=u[0].replace(")","");let O=parseFloat(u[0]);if(u[1]=u[1].replace("(",""),u[1]=u[1].replace(")",""),m=parseFloat(u[1]),isFinite(O)||(O=1),isFinite(g)&&isFinite(m)){let E=s.tetrate(g,m,O,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}let v=t.split("e"),f=v.length-1;if(f===0){let d=parseFloat(t);if(isFinite(d))return this.fromNumber(d),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(f===1){let d=parseFloat(t);if(isFinite(d)&&d!==0)return this.fromNumber(d),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let l=t.split("e^");if(l.length===2){this.sign=1,l[0].startsWith("-")&&(this.sign=-1);let d="";for(let O=0;O=43&&E<=57||E===101)d+=l[1].charAt(O);else return this.layer=parseFloat(d),this.mag=parseFloat(l[1].substr(O+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(v[0]);if(h===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let p=parseFloat(v[v.length-1]);if(f>=2){let d=parseFloat(v[v.length-2]);isFinite(d)&&(p*=Math.sign(d),p+=$t(d))}if(!isFinite(h))this.sign=v[0]==="-"?-1:1,this.layer=f,this.mag=p;else if(f===1)this.sign=Math.sign(h),this.layer=1,this.mag=p+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=f,f===2){let d=s.mul(D(1,2,p),b(h));return this.sign=d.sign,this.layer=d.layer,this.mag=d.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=p;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ht(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ht(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ce?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ht(this.m,t)+"e"+ht(this.e,t):this.layer===1?ht(this.m,t)+"e"+ht(this.e,t):this.layer<=ce?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return T(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Zt)return r;{let c=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*c;return D(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>Zt)return r;{let c=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*c;return D(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>Zt)return r;{let c=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*c;return D(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(b(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return T(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return T(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return D(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return D(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return D(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=b(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?T(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?T(0,0,0):this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=b(t).abs();if(e.eq(s.dZero))return T(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?T(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=b(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=b(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=b(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=$t(n)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=b(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=b(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?T(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return T(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:T(Number.NaN,Number.NaN,Number.NaN):n}pow10(){if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return T(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return T(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return b(t).pow(this)}root(t){let e=b(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(T(1,0,24)))return s.fromNumber(wr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,c=e+o;if(c===e||(e=c,i=i*r,n=360*i,o=1/n,c=e-o,c===e))return s.exp(e);e=c,i=i*r,n=1260*i;let g=1/n;return e=e+g,i=i*r,n=1680*i,g=1/n,e=e-g,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?T(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?D(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?D(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):D(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return D(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(T(this.sign,this.layer-1,this.mag),T(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=T(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return T(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let c=s.ln(this).neg(),g=c.lambertw().div(c);if(o<1)return g;let m=c.lambertw(!1).div(c);return o>1.444667861009099&&(g=m=s.fromNumber(Math.E)),e=b(e),e.eq(m)?m:e.lt(m)?g:T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let c=0;c1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=b(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let c=Math.min(e,i.layer-t.layer-3);e-=c,i.layer-=c}for(let c=0;c1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let g=1;g1&&o!=u&&(n=!0),o=u,n?i/=2:i*=2,i=Math.abs(i)*(u?-1:1),c+=i,i===0)break}return s.fromNumber(c)}slog_internal(t=10,e=!1){if(t=b(t),t.lte(s.dZero)||t.eq(s.dOne))return T(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?T(0,0,0):this.eq(s.dZero)?T(-1,0,1):T(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return T(-1,0,1);if(t.lt(1.444667861009766)){let n=s.ln(t).neg(),o=n.lambertw().div(n);if(this.eq(o))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return T(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,vr)}static tetrate_critical(t,e){return s.critical_section(t,e,yr)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let g=0;gt){let m=(t-pt[g])/(pt[g+1]-pt[g]);n=r[g][Math.floor(e)]*(1-m)+r[g+1][Math.floor(e)]*m,o=r[g][Math.ceil(e)]*(1-m)+r[g+1][Math.ceil(e)]*m;break}let c=e-Math.floor(e);return n<=0||o<=0?n*(1-c)+o*c:Math.pow(t,Math.log(n)/Math.log(t)*(1-c)+Math.log(o)/Math.log(t)*c)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=b(e);if(i.gt(1)&&i.lte(1.444667861009766)){let c=s.excess_slog(this,e,r),g=c[0].toNumber(),m=c[1],u=g+t,v=s.ln(e).neg(),f=v.lambertw().div(v),l=v.lambertw(!1).div(v),h=s.dOne;m==1?h=f.mul(l).sqrt():m==2&&(h=l.mul(2));let p=i.pow(h),d=Math.floor(u),O=u-d,E=h.pow(1-O).mul(p.pow(O));return s.tetrate(i,d,E,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):T(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=b(t),e=b(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[T(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let n=s.ln(e).neg(),o=n.lambertw().div(n),c=s.dInf;if(e>1&&(c=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=c=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(c))return[T(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(c)){let g=c.mul(2),m=i.pow(g),u=0;if(t.gte(g)&&t.lt(m))u=0;else if(t.gte(m)){let d=m;for(u=1;d.lt(t);)if(d=i.pow(d),u=u+1,d.layer>3){let O=Math.floor(t.layer-d.layer+1);d=i.iteratedexp(O,d,r),u=u+O}d.gt(t)&&(d=d.log(e),u=u-1)}else if(t.lt(g)){let d=g;for(u=0;d.gt(t);)d=d.log(e),u=u-1}let v=0,f=0,l=.5,h=g,p=s.dZero;for(;l>1e-16;){if(f=v+l,h=g.pow(1-f).mul(m.pow(f)),p=s.iteratedexp(e,u,h),p.eq(t))return[new s(u+f),2];p.lt(t)&&(v+=l),l/=2}return p.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(u+v),2]}if(t.lt(c)&&t.gt(o)){let g=o.mul(c).sqrt(),m=i.pow(g),u=0;if(t.lte(g)&&t.gt(m))u=0;else if(t.lte(m)){let d=m;for(u=1;d.gt(t);)d=i.pow(d),u=u+1;d.lt(t)&&(d=d.log(e),u=u-1)}else if(t.gt(g)){let d=g;for(u=0;d.lt(t);)d=d.log(e),u=u-1}let v=0,f=0,l=.5,h=g,p=s.dZero;for(;l>1e-16;){if(f=v+l,h=g.pow(1-f).mul(m.pow(f)),p=s.iteratedexp(e,u,h),p.eq(t))return[new s(u+f),1];p.gt(t)&&(v+=l),l/=2}return p.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(u+v),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?T(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(Yt(this.toNumber())):this.layer===0?s.fromNumber(Yt(this.sign*this.mag)):this.lt("eee15")?de(this):this.ln():this.sign===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Yt(this.sign*this.mag,1e-10,!1)):this.layer==1?de(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return T(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return T(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return ebr?this.pow(this.recip()):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return T(1,0,1);if(this.lt(0))return T(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):T(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,c=n.div(2),g=!0;for(;g;)c=r.add(n).div(2),s.iteratedexp(10,i,c,!0).tetrate(t,1,!0).gt(this)?n=c:r=c,c.eq(o)?g=!1:o=c;return s.iteratedexp(10,i,c,!0)}else{let e=1,r=D(1,10,1),i=D(1,10,1),n=D(1,10,1),o=D(1,1,-16),c=s.dZero,g=D(1,10,1),m=o.pow10().recip(),u=s.dZero,v=m,f=m,l=Math.ceil(t)%2==0,h=0,p=D(1,10,1),d=!1,O=s.dZero,E=!1;for(;e<4;){if(e==2){if(l)break;n=D(1,10,1),o=r,e=3,g=D(1,10,1),p=D(1,10,1)}for(d=!1;o.neq(n);){if(O=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))m=o.pow10().recip(),v=o.pow10().recip(),f=o.pow10().recip(),u=s.dZero,h=-1,e==3&&(p=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!l&&o.pow10().recip().lt(.4))m=o.pow10().recip(),v=o.pow10().recip(),f=o.pow10().recip(),u=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))m=o.pow10().recip(),v=s.dZero,f=m.mul(2),u=m,l?h=-1:h=0;else{for(c=o.mul(12e-17),m=o.pow10().recip(),v=o.add(c).pow10().recip(),u=m.sub(v),f=m.add(u);v.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||f.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||v.gte(m)||f.lte(m);)c=c.mul(2),v=o.add(c).pow10().recip(),u=m.sub(v),f=m.add(u);if((e==1&&f.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(p=o),f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))h=-1;else if(l)h=1;else if(e==3&&o.gt_tolerance(r,1e-8))h=0;else{for(;v.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||f.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||v.gte(m)||f.lte(m);)c=c.mul(2),v=o.add(c).pow10().recip(),u=m.sub(v),f=m.add(u);f.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(v.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(E=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(D(1,10,1)))o=o.mul(2);else{let y=!1;if(d&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),o=o.add(n).div(2),y)break}else if(n.eq(D(1,10,1)))n=o,o=o.div(2);else{let y=!1;if(d&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),n=n.sub(g),o=o.sub(g),y)break}if(n.sub(o).div(2).abs().gt(g.mul(1.5))&&(d=!0),g=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(O))break}if(o.gt("1e18")||!E||p==D(1,10,1))break;e==1?r=p:e==3&&(i=p),e++}n=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(i.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(n=D(1,10,1),o=i,P=o,a=s.dZero,S=!0;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=T(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):T(0,0,0)}cos(){return this.mag<0?T(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):T(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):T(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?T(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return dt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return dt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return dt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return dt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return dt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return dt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let c=Math.floor(r/i[o]);r-=c*i[o],n+=o.repeat(c)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=T(0,0,0),s.dOne=T(1,0,1),s.dNegOne=T(-1,0,1),s.dTwo=T(1,0,2),s.dTen=T(1,0,10),s.dNaN=T(Number.NaN,Number.NaN,Number.NaN),s.dInf=T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=D(1,0,Number.MAX_VALUE),s.dNumberMin=D(1,0,Number.MIN_VALUE),s.fromStringCache=new Rt(mr),nt([Et()],s.prototype,"sign",2),nt([Et()],s.prototype,"mag",2),nt([Et()],s.prototype,"layer",2),s=nt([or()],s);var{formats:dt,FORMATS:Mr}=ur(s);s.formats=dt;var St=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},zt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new s(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new St(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nf),u=n,v=this.getBoosts(o,!0);v[0][0]?this.boostArray[v[1][0]]=new St({id:o,name:c,description:g,value:m,order:u}):this.boostArray.push(new St({id:o,name:c,description:g,value:m,order:u}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let c=this.getBoosts(o.id,!0);c[0][0]?this.boostArray[c[1][0]]=new St(o):this.boostArray.push(new St(o))}}}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},Qr=st(lt()),Pt=30,Vt=.001;function _r(t,e,r="geometric"){switch(t=new s(t),e=new s(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return s.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Ht(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new s(t),e=new s(e),r=new s(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function Wt(t,e,r="geometric",i=Pt,n=Vt){let o=s.dOne,c=new s(e);if(t(c).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(c).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:c,lowerBound:c,upperBound:c};for(let m=0;m=0;g--){let m=r.add(c.mul(g)),u=r.add(c.mul(g+1)),v=o;if(o=o.add(t(m).add(t(u)).div(2).mul(c)),Ht(v,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Xt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(Pt)?me(t,e,r,i):ge(t,e,r,n)}function Sr(t,e=10,r=0,i=1e3){if(t=new s(t),t.gte(s.pow(e,i)))return t;let n=s.floor(s.log(t,e)),o=t.div(s.pow(e,n));return o=o.mul(s.pow(e,r)).round(),o=o.div(s.pow(e,r)),o=o.mul(s.pow(e,n)),o}function pe(t,e,r,i=s.dInf,n,o,c=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[s.dZero,s.dZero];if(c=(typeof e.el=="function"?e.el():e.el)??c,g.eq(1)){let f=e.cost(e.level),l=t.gte(f),h=[s.dZero,s.dZero];return c?(h[0]=l?s.dOne:s.dZero,h):(h=[l?s.dOne:s.dZero,l?f:s.dZero],h)}if(e.costBulk){let[f,l]=e.costBulk(t,e.level,g),h=t.gte(l);return[h?f:s.dZero,h&&!c?l:s.dZero]}if(c){let f=p=>e.cost(p.add(r)),l=s.min(i,Wt(f,t,n,o).value.floor()),h=s.dZero;return[l,h]}let m=Wt(f=>Xt(e.cost,f,r),t,n,o).value.floor().min(r.add(g).sub(1)),u=Xt(e.cost,m,r);return[m.sub(r).add(1).max(0),u]}function Ne(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Ir(t){return`el/${Ne(t)}`}var Nt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};nt([Et()],Nt.prototype,"id",2),nt([_t(()=>s)],Nt.prototype,"level",2);var Jt=class Ze{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:s.dOne}}).data??{level:s.dOne}).level}set level(e){this.data.level=new s(e)}constructor(e,r,i,n){let o=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>o,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new Rt(n??Ze.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??s.dOne}},Kr=st(lt());function ye(t,e,r=s.dInf){if(t=new s(t),r=new s(r),r.lt(0))return console.warn("calculateItem: Invalid target: ",r),[s.dZero,s.dZero];if(r.eq(1)){let o=e.cost();return[t.gte(o)?s.dOne:s.dZero,t.gte(o)?o:s.dZero]}let i=t.div(e.cost()).floor().min(r),n=e.cost().mul(i);return[i,n]}var ve=class{constructor(t,e,r){this.defaultAmount=s.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??s.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:s.dOne}}).data??{amount:s.dOne}).amount}set amount(t){this.data.amount=new s(t)}},yt=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??s.dZero}};nt([Et()],yt.prototype,"id",2),nt([_t(()=>s)],yt.prototype,"amount",2);var ti=st(lt()),mt=class{constructor(){this.value=s.dZero,this.upgrades={},this.items={}}};nt([_t(()=>s)],mt.prototype,"value",2),nt([_t(()=>Nt)],mt.prototype,"upgrades",2),nt([_t(()=>yt)],mt.prototype,"items",2);var we=class{constructor(t=new mt,e,r={defaultVal:s.dZero,defaultBoost:s.dOne}){this.items={},this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new zt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(n);if(i.resetItemAmounts)for(let n of Object.values(this.items))n.amount=new s(n.defaultAmount),i.runUpgradeEffect&&this.runUpgradeEffect(n)}gain(t=1e3){let e=this.boost.calculate().mul(new s(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Nt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(o=>i.test(o)).map(o=>this.upgrades[o])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let n=new Jt(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(n),this.upgrades[i.id]=n,r.push(n)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t instanceof Jt?t.effect?.(t.level,t,this):t.effect?.(t.amount,t,this)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[s.dZero,s.dZero]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=s.min(e,n.maxLevel)),pe(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),n.level=n.level.add(o),this.runUpgradeEffect(n),!0)}pointerAddItem(t){let e=new yt(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new ve(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runUpgradeEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e=1/0){let r=this.getItem(t);return r===null?(console.warn(`Item "${t}" not found.`),[s.dZero,s.dZero]):ye(this.value,r,e)}buyItem(t,e){let r=this.getItem(t);if(r===null)return console.warn(`Item "${t}" not found.`),!1;let[i,n]=this.calculateItem(t,e);return i.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(n),r.amount=r.amount.add(i),this.runUpgradeEffect(r),!0)}},ei=st(lt()),Lt=class{constructor(t=0){this.value=new s(t)}};nt([_t(()=>s)],Lt.prototype,"value",2);var be=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new Lt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new zt(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},Me=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=r,this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}direction(t,e=1){let r=_e.getInstance(this.gridSymbol);switch(t){case"up":return r.getCell(this.x,this.y-e);case"right":return r.getCell(this.x+e,this.y);case"down":return r.getCell(this.x,this.y+e);case"left":return r.getCell(this.x-e,this.y);default:throw new Error("Invalid direction")}}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}},vt=class extends Array{constructor(t){t=Array.isArray(t)?t:[t],super(...t)}},_e=class ie{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),ie.instances[this.gridSymbol]=this,this.xSize=e,this.ySize=r??e;for(let n=0;n{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),Or=ae,Se={};Ut(Se,{ConfigManager:()=>kt,DataManager:()=>Ee,EventManager:()=>Oe,EventTypes:()=>Ae,Game:()=>Fr,GameAttribute:()=>Fe,GameCurrency:()=>Ce,GameReset:()=>Kt,KeyManager:()=>Ie,gameDefaultConfig:()=>xe,keys:()=>Er});var ri=st(lt()),kt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Tr={autoAddInterval:!0,fps:30},Er="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),Ie=class $e{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=$e.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new kt(Tr)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:i}]:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let o=this.getBind(n.id);if(o){Object.assign(o,n);continue}this.binds.push(n)}}},Ae=(t=>(t.interval="interval",t.timeout="timeout",t))(Ae||{}),Cr={autoAddInterval:!0,fps:30},Oe=class Ye{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=Ye.configManager.parse(e),this.events={},this.config.autoAddInterval){let r=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/r)}}static{this.configManager=new kt(Cr)}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callbackFn(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},ii=st(lt()),Te=st(Je()),Qt=st(tr()),Ee=class{constructor(t){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return typeof this.static[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=jt(this.data)}compileDataRaw(t=this.data){let e=jt(t),r=(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.1.0"}catch{i="8.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,Te.compressToBase64)(e)}decompileData(t=window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)){if(!t)return null;let e;try{return e=JSON.parse((0,Te.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!window.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");window.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t)}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(f){return typeof f=="object"&&f?.constructor===Object}let n=(f,l)=>Object.prototype.hasOwnProperty.call(f,l);function o(f,l,h){if(!f||!l||!h)throw new Error("dataManager.deepMerge(): Missing arguments.");let p=h;for(let d in f)if(n(f,d)&&!n(h,d)&&(p[d]=f[d]),l[d]instanceof mt){let O=f[d],E=h[d];if(Array.isArray(E.upgrades)){let P=E.upgrades;E.upgrades={};for(let a of P)E.upgrades[a.id]=a}E.upgrades={...O.upgrades,...E.upgrades},p[d]=E,E.items={...O.items,...E.items}}else i(f[d])&&i(h[d])&&(p[d]=o(f[d],l[d],h[d]));return p}let c=e?o(this.normalDataPlain,this.normalData,r):r,g=Object.getOwnPropertyNames(new Nt({id:"",level:s.dZero})),m=Object.getOwnPropertyNames(new yt({id:"",amount:s.dZero}));function u(f,l){let h=Gt(f,l);if(h instanceof mt){for(let p in h.upgrades){let d=h.upgrades[p];if(!d||!g.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.upgrades[p];continue}h.upgrades[p]=Gt(Nt,d)}for(let p in h.items){let d=h.items[p];if(!d||!m.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.items[p];continue}h.items[p]=Gt(yt,d)}}if(!h)throw new Error(`Failed to convert ${f.name} to class instance.`);return h}function v(f,l){if(!f||!l)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let h=l;for(let p in f){if(l[p]===void 0){console.warn(`Missing property "${p}" in loaded data.`);continue}if(!i(l[p]))continue;let d=f[p].constructor;if(d===Object){h[p]=v(f[p],l[p]);continue}h[p]=u(d,l[p])}return h}return c=v(this.normalData,c),c}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],jt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Ce=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,i){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=i,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Fe=class{constructor(t,e,r){this.data=typeof t=="function"?t():t,this.static=typeof e=="function"?e():e,this.game=r}get value(){return this.static.value}set value(t){this.data.value=t}},Kt=class ze{static fromObject(e){return new ze(e.currenciesToReset,e.extender,e.onReset,e.condition)}constructor(e,r,i,n){this.currenciesToReset=Array.isArray(e)?e:[e],this.extender=Array.isArray(r)?r:r?[r]:[],this.onReset=i,this.condition=n,this.id=Symbol()}reset(e=!1,r=!0,i=new Set){if(e||(typeof this.condition=="function"?!this.condition(this):!this.condition)&&typeof this.condition<"u")return;let n=()=>{this.onReset?.(this),this.currenciesToReset.forEach(o=>{o.static.reset()})};if(this.extender.length===0){n();return}this.extender.forEach(o=>{i.has(o.id)||(i.add(o.id),o.reset(r||e,r,i))}),n()}},xe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Fr=class Ve{static{this.configManager=new kt(xe)}constructor(e){this.config=Ve.configManager.parse(e),this.dataManager=new Ee(this),this.keyManager=new Ie({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new Oe({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[]){return this.dataManager.setData(e,{currency:new mt}),this.dataManager.setStatic(e,{currency:new we(()=>this.dataManager.getData(e).currency,r)}),new Ce(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new Lt(i)),this.dataManager.setStatic(e,new be(this.dataManager.getData(e),r,i)),new Fe(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new Kt(...e)}addResetFromObject(e){return Kt.fromObject(e)}},xr={...Or,...Se},Pr=xr;if(typeof at.exports=="object"&&typeof Ot=="object"){var Lr=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};at.exports=Lr(at.exports,Ot)}return at.exports}); +"use strict";(function(Ot,ut){var Ft=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],ut);else if(typeof module=="object"&&module.exports)module.exports=ut();else{var ct=ut(),Pt=Ft?exports:Ot;for(var Tt in ct)Pt[Tt]=ct[Tt]}})(typeof self<"u"?self:exports,()=>{var Ot={},ut={exports:Ot},Ft=Object.create,ct=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Tt=Object.getOwnPropertyNames,We=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty,wt=(t,e)=>function(){return e||(0,t[Tt(t)[0]])((e={exports:{}}).exports,e),e.exports},Ut=(t,e)=>{for(var r in e)ct(t,r,{get:e[r],enumerable:!0})},se=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Tt(e))!Xe.call(t,n)&&n!==r&&ct(t,n,{get:()=>e[n],enumerable:!(i=Pt(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ft(We(t)):{},se(e||!t||!t.__esModule?ct(r,"default",{value:t,enumerable:!0}):r,t)),Je=t=>se(ct({},"__esModule",{value:!0}),t),st=(t,e,r,i)=>{for(var n=i>1?void 0:i?Pt(e,r):e,o=t.length-1,f;o>=0;o--)(f=t[o])&&(n=(i?f(e,r,n):f(n))||n);return i&&n&&ct(e,r,n),n},ft=wt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:d(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(u,v){return function(c,l){Object.defineProperty(u,c,{configurable:!0,writable:!0,value:l}),v&&v(c,l)}}function f(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function d(){return f()||g()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",f=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",d=typeof Object.create=="function",u={__proto__:[]}instanceof Array,v=!d&&!u,c={create:d?function(){return re(Object.create(null))}:u?function(){return re({__proto__:null})}:function(){return re({})},has:v?function(N,w){return n.call(N,w)}:function(N,w){return w in N},get:v?function(N,w){return n.call(N,w)?N[w]:void 0}:function(N,w){return N[w]}},l=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Yr(),p=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:zr(),m=typeof WeakMap=="function"?WeakMap:Vr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,C=Gr(),x=Zr(C);function a(N,w,A,E){if(j(A)){if(!qe(N))throw new TypeError;if(!De(w))throw new TypeError;return K(N,w)}else{if(!qe(N))throw new TypeError;if(!X(w))throw new TypeError;if(!X(E)&&!j(E)&&!It(E))throw new TypeError;return It(E)&&(E=void 0),A=lt(A),it(N,w,A,E)}}r("decorate",a);function S(N,w){function A(E,U){if(!X(E))throw new TypeError;if(!j(U)&&!jr(U))throw new TypeError;qt(N,w,E,U)}return A}r("metadata",S);function y(N,w,A,E){if(!X(A))throw new TypeError;return j(E)||(E=lt(E)),qt(N,w,A,E)}r("defineMetadata",y);function I(N,w,A){if(!X(w))throw new TypeError;return j(A)||(A=lt(A)),H(N,w,A)}r("hasMetadata",I);function _(N,w,A){if(!X(w))throw new TypeError;return j(A)||(A=lt(A)),Y(N,w,A)}r("hasOwnMetadata",_);function M(N,w,A){if(!X(w))throw new TypeError;return j(A)||(A=lt(A)),W(N,w,A)}r("getMetadata",M);function F(N,w,A){if(!X(w))throw new TypeError;return j(A)||(A=lt(A)),pt(N,w,A)}r("getOwnMetadata",F);function P(N,w){if(!X(N))throw new TypeError;return j(w)||(w=lt(w)),Dt(N,w)}r("getMetadataKeys",P);function R(N,w){if(!X(N))throw new TypeError;return j(w)||(w=lt(w)),Bt(N,w)}r("getOwnMetadataKeys",R);function z(N,w,A){if(!X(w))throw new TypeError;if(j(A)||(A=lt(A)),!X(w))throw new TypeError;j(A)||(A=lt(A));var E=Et(w,A,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(N,w,A)}r("deleteMetadata",z);function K(N,w){for(var A=N.length-1;A>=0;--A){var E=N[A],U=E(w);if(!j(U)&&!It(U)){if(!De(U))throw new TypeError;w=U}}return w}function it(N,w,A,E){for(var U=N.length-1;U>=0;--U){var J=N[U],tt=J(w,A,E);if(!j(tt)&&!It(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(N,w,A){var E=Y(N,w,A);if(E)return!0;var U=ee(w);return It(U)?!1:H(N,U,A)}function Y(N,w,A){var E=Et(w,A,!1);return j(E)?!1:ke(E.OrdinaryHasOwnMetadata(N,w,A))}function W(N,w,A){var E=Y(N,w,A);if(E)return pt(N,w,A);var U=ee(w);if(!It(U))return W(N,U,A)}function pt(N,w,A){var E=Et(w,A,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(N,w,A)}function qt(N,w,A,E){var U=Et(A,E,!0);U.OrdinaryDefineOwnMetadata(N,w,A,E)}function Dt(N,w){var A=Bt(N,w),E=ee(N);if(E===null)return A;var U=Dt(E,w);if(U.length<=0)return A;if(A.length<=0)return U;for(var J=new p,tt=[],Z=0,L=A;Z=0&&L=this._keys.length?(this._index=-1,this._keys=w,this._values=w):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},Z.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=w,this._values=w),L},Z.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=w,this._values=w),{value:L,done:!0}},Z}(),E=function(){function Z(){this._keys=[],this._values=[],this._cacheKey=N,this._cacheIndex=-2}return Object.defineProperty(Z.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Z.prototype.has=function(L){return this._find(L,!1)>=0},Z.prototype.get=function(L){var k=this._find(L,!1);return k>=0?this._values[k]:void 0},Z.prototype.set=function(L,k){var q=this._find(L,!0);return this._values[q]=k,this},Z.prototype.delete=function(L){var k=this._find(L,!1);if(k>=0){for(var q=this._keys.length,D=k+1;D>>8,c[l*2+1]=p%256}return c},decompressFromUint8Array:function(u){if(u==null)return d.decompress(u);for(var v=new Array(u.length/2),c=0,l=v.length;c>1}else{for(h=1,l=0;l>1}a--,a==0&&(a=Math.pow(2,y),y++),delete m[x]}else for(h=p[x],l=0;l>1;a--,a==0&&(a=Math.pow(2,y),y++),p[C]=S++,x=String(O)}if(x!==""){if(Object.prototype.hasOwnProperty.call(m,x)){if(x.charCodeAt(0)<256){for(l=0;l>1}else{for(h=1,l=0;l>1}a--,a==0&&(a=Math.pow(2,y),y++),delete m[x]}else for(h=p[x],l=0;l>1;a--,a==0&&(a=Math.pow(2,y),y++)}for(h=2,l=0;l>1;for(;;)if(_=_<<1,M==v-1){I.push(c(_));break}else M++;return I.join("")},decompress:function(u){return u==null?"":u==""?null:d._decompress(u.length,32768,function(v){return u.charCodeAt(v)})},_decompress:function(u,v,c){var l=[],h,p=4,m=4,O=3,C="",x=[],a,S,y,I,_,M,F,P={val:c(0),position:v,index:1};for(a=0;a<3;a+=1)l[a]=a;for(y=0,_=Math.pow(2,2),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;switch(h=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 2:return""}for(l[3]=F,S=F,x.push(F);;){if(P.index>u)return"";for(y=0,_=Math.pow(2,O),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;switch(F=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;l[m++]=i(y),F=m-1,p--;break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;l[m++]=i(y),F=m-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,O),O++),l[F])C=l[F];else if(F===m)C=S+S.charAt(0);else return null;x.push(C),l[m++]=S+C.charAt(0),p--,S=C,p==0&&(p=Math.pow(2,O),O++)}}};return d}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),Ke=wt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],f=0,g=0;f>>5]|=n[f]<<24-g%32;return o},wordsToBytes:function(n){for(var o=[],f=0;f>>5]>>>24-f%32&255);return o},bytesToHex:function(n){for(var o=[],f=0;f>>4).toString(16)),o.push((n[f]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],f=0;f>>6*(3-d)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],f=0,g=0;f>>6-g*2);return o}};e.exports=i})()}}),oe=wt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],o=0;o>>24)&16711935|(u[m]<<24|u[m]>>>8)&4278255360;u[v>>>5]|=128<>>9<<4)+14]=v;for(var O=f._ff,C=f._gg,x=f._hh,a=f._ii,m=0;m>>0,l=l+y>>>0,h=h+I>>>0,p=p+_>>>0}return r.endian([c,l,h,p])};f._ff=function(g,d,u,v,c,l,h){var p=g+(d&u|~d&v)+(c>>>0)+h;return(p<>>32-l)+d},f._gg=function(g,d,u,v,c,l,h){var p=g+(d&v|u&~v)+(c>>>0)+h;return(p<>>32-l)+d},f._hh=function(g,d,u,v,c,l,h){var p=g+(d^u^v)+(c>>>0)+h;return(p<>>32-l)+d},f._ii=function(g,d,u,v,c,l,h){var p=g+(u^(d|~v))+(c>>>0)+h;return(p<>>32-l)+d},f._blocksize=16,f._digestsize=16,e.exports=function(g,d){if(g==null)throw new Error("Illegal argument "+g);var u=r.wordsToBytes(f(g,d));return d&&d.asBytes?u:d&&d.asString?o.bytesToString(u):r.bytesToHex(u)}})()}}),ae={};Ut(ae,{default:()=>Lr}),ut.exports=Je(ae);var Xr=ot(ft()),Jr=ot(ft()),ue={};Ut(ue,{Attribute:()=>Lt,AttributeStatic:()=>Me,Boost:()=>zt,BoostObject:()=>St,Currency:()=>gt,CurrencyStatic:()=>be,DEFAULT_ITERATIONS:()=>xt,Decimal:()=>s,E:()=>Or,FORMATS:()=>_r,FormatTypeList:()=>ur,Grid:()=>Se,GridCell:()=>_e,GridCellCollection:()=>nt,Item:()=>we,ItemData:()=>vt,LRUCache:()=>jt,ListNode:()=>le,ST_NAMES:()=>ht,UpgradeData:()=>yt,UpgradeStatic:()=>Jt,calculateItem:()=>ve,calculateSum:()=>Xt,calculateSumApprox:()=>pe,calculateSumLoop:()=>ge,calculateUpgrade:()=>Ne,decimalToJSONString:()=>ye,equalsTolerance:()=>Ht,formats:()=>dt,inverseFunctionApprox:()=>Wt,roundingBase:()=>Ir,upgradeToCacheNameEL:()=>Ar});var Qr=ot(ft()),jt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new le(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},le=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},G;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(G||(G={}));var rr=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===G.CLASS_TO_CLASS||i===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===G.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(c){return c.propertyName!==void 0}));for(var o=[],f=0,g=this.getAncestors(r);f0&&(f=f.filter(function(c){return!u.includes(c)})),this.options.version!==void 0&&(f=f.filter(function(c){var l=et.findExposeMetadata(e,c);return!l||!l.options?!0:n.checkVersion(l.options.since,l.options.until)})),this.options.groups&&this.options.groups.length?f=f.filter(function(c){var l=et.findExposeMetadata(e,c);return!l||!l.options?!0:n.checkGroups(l.options.groups)}):f=f.filter(function(c){var l=et.findExposeMetadata(e,c);return!l||!l.options||!l.options.groups||!l.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(f=f.filter(function(v){return n.options.excludePrefixes.every(function(c){return v.substr(0,c.length)!==c})})),f=f.filter(function(v,c,l){return l.indexOf(v)===c}),f},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(3)){let R=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(2)){let R=[];for(let z=0;z118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][I]},beyondOg(a){let S=Math.floor(Math.log10(a)),y=["n","u","b","t","q","p","h","s","o","e"],I="";for(let _=S;_>=0;_--){let M=Math.floor(a/Math.pow(10,_))%10;I==""?I=y[M].toUpperCase():I+=y[M]}return I},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let S=a.log(118).toNumber(),y=Math.floor(S)+1,I=e.elemental.abbreviationLength(y),_=S-y+1,M=Math.floor(_*I),F=e.elemental.getAbbreviation(y,_),P=new t(118).pow(y+M/I-1);return[F,P]},formatElementalPart(a,S){return S.eq(1)?a:`${S.toString()} ${a}`},format(a,S=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),S);let y=a.log(118),_=y.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),F=[];for(;y.gte(1)&&F.length=M)return F.map(R=>e.elemental.formatElementalPart(R[0],R[1])).join(" + ");let P=new t(118).pow(y).toFixed(F.length===1?3:S);return F.length===0?P:F.length===1?`${P} \xD7 ${e.elemental.formatElementalPart(F[0][0],F[0][1])}`:`${P} \xD7 (${F.map(R=>e.elemental.formatElementalPart(R[0],R[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(t.dTen.pow(y));return(y.log10().gte(9)?"":I.toFixed(4))+"e"+e.old_sc.format(y,0)}}},eng:{format(a,S=2){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let I=a.div(new t(1e3).pow(y.div(3).floor()));return(y.log10().gte(9)?"":I.toFixed(new t(4).sub(y.sub(y.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(y.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,y=9){a=new t(a);let I=a.log10().floor();return I.lt(303)&&I.gte(y)?d(a,S,y,"st"):d(a,S,y,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,y){a=new t(a);let I=a.max(1).log10().max(1).log(r.log10()).floor();if(I.lte(0))return d(a,S,y,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return d(a,Math.max(4,S),y,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+d(_,0,y,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ht[0][0][a%10]+ht[0][1][Math.floor(a/10)%10]+ht[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,y=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ht[1][0][a]:(y==1&&S==0?_+="Vec":_+=ht[1][1][S]+ht[1][2][y],_+=ht[1][3][I],_)}},inf:{format(a,S,y){a=new t(a);let I=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],F=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?d(a,S,y,"sc"):a.gte(3)?F[I]+M[I]+"\u03C9^"+d(a.sub(1),S,y,"sc"):a.gte(2)?F[I]+"\u03C9"+M[I]+"-"+d(_.pow(a.sub(2)),S,y,"sc"):F[I]+M[I]+"-"+d(_.pow(a.sub(1)),S,y,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),y=!1,I=9){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,M=_.length,F=a.log(1e3).sub(S.log(1e3)).floor(),P=F.add(1).log(M+1).ceil(),R="",z=(K,it)=>{let H=K,Y="";for(let W=0;W=M)return"\u03C9";Y=_[pt]+Y,H=H.sub(1).div(M).floor()}return Y};if(P.lt(I))R=z(F,P);else{let K=P.sub(I).add(1),it=F.div(t.pow(M+1,K.sub(1))).floor();R=`${z(it,new t(I))}(${K.gt("1e9")?K.format():K.format(0)})`}return R},format(a,S=2,y=9,I="mixed_sc",_=new t(1e15),M=!1,F){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return d(a,S,y,I);let P=e.alphabet.getAbbreviation(a,_,M,F),R=a.div(t.pow(1e3,a.log(1e3).floor()));return`${P.length>(F??9)+2?"":R.toFixed(S)+" "}${P}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function f(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function g(a,S=2,y=9,I="st"){return d(a,S,y,I)}function d(a,S=2,y=9,I="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(S);let M=a.log10().floor();switch(I){case"sc":case"scientific":if(a.log10().lt(Math.min(-S,0))&&S>1){let F=a.log10().ceil(),P=a.div(F.eq(-1)?new t(.1):t.dTen.pow(F)),R=F.mul(-1).max(1).log10().gte(9);return _+(R?"":P.toFixed(2))+"e"+d(F,0,y,"mixed_sc")}else if(M.lt(y)){let F=Math.max(Math.min(S-M.toNumber(),S),0);return _+(F>0?a.toFixed(F):a.toFixed(F).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let R=a.slog();return(R.gte(1e9)?"":t.dTen.pow(R.sub(R.floor())).toFixed(2))+"F"+d(R.floor(),0)}let F=a.div(t.dTen.pow(M)),P=M.log10().gte(9);return _+(P?"":F.toFixed(2))+"e"+d(M,0,y,"mixed_sc")}case"st":case"standard":{let F=a.log(1e3).floor();if(F.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let P=F.mul(3),R=F.log10().floor();if(R.gte(3e3))return"e"+d(M,S,y,"st");let z="";if(F.lt(4))z=["","K","M","B"][Math.round(F.toNumber())];else{let H=Math.floor(F.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),F=F.sub(1).div(t.dTen.pow(H*3));F.gt(0);){let Y=F.div(1e3).floor(),W=F.sub(Y.mul(1e3)).floor().toNumber();W>0&&(W==1&&!H&&(z="U"),H&&(z=e.standard.tier2(H)+(z?"-"+z:"")),W>1&&(z=e.standard.tier1(W)+z)),F=Y,H++}}let K=a.div(t.dTen.pow(P)),it=S===2?t.dTwo.sub(M.sub(P)).add(1).toNumber():S;return _+(R.gte(10)?"":K.toFixed(it)+" ")+z}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,y)}}function u(a,S,y="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),F,P=M.div(a);return P.gte(10)&&a.gte(1e100)?(P=P.log10().mul(20),F="(+"+d(P,I,_,y)+" OoMs/sec)"):F="(+"+d(S,I,_,y)+"/sec)",F}function v(a,S=2,y="s"){return a=new t(a),a.gte(86400)?d(a.div(86400).floor(),0,12,"sc")+":"+v(a.mod(86400),S,"d"):a.gte(3600)||y=="d"?(a.div(3600).gte(10)||y!="d"?"":"0")+d(a.div(3600).floor(),0,12,"sc")+":"+v(a.mod(3600),S,"h"):a.gte(60)||y=="h"?(a.div(60).gte(10)||y!="h"?"":"0")+d(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||y!="m"?"":"0")+d(a,S,12,"sc")}function c(a,S=!1,y=0,I=9,_="mixed_sc"){let M=Bt=>d(Bt,y,I,_);a=new t(a);let F=a.mul(1e3).mod(1e3).floor(),P=a.mod(60).floor(),R=a.div(60).mod(60).floor(),z=a.div(3600).mod(24).floor(),K=a.div(86400).mod(365.2425).floor(),it=a.div(31556952).floor(),H=it.eq(1)?" year":" years",Y=K.eq(1)?" day":" days",W=z.eq(1)?" hour":" hours",pt=R.eq(1)?" minute":" minutes",qt=P.eq(1)?" second":" seconds",Dt=F.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?M(it)+H+", ":""}${K.gt(0)?M(K)+Y+", ":""}${z.gt(0)?M(z)+W+", ":""}${R.gt(0)?M(R)+pt+", ":""}${P.gt(0)?M(P)+qt+",":""}${S&&F.gt(0)?" "+M(F)+Dt:""}`.replace(/,([^,]*)$/,"$1").trim()}function l(a){return a=new t(a),d(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),d(a.mul(100))+"%"}function p(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function m(a,S,y=10){return t.gte(a,10)?t.pow(y,t.log(a,y).pow(S)):new t(a)}function O(a,S=0){a=new t(a);let y=(F=>F.map((P,R)=>({name:P.name,altName:P.altName,value:t.pow(1e3,new t(R).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),I="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),y.length-1).floor().toNumber(),M=y[_];if(_===0)switch(S){case 1:I="";break;case 2:case 0:default:I=a.format();break}switch(S){case 1:I=M.name;break;case 2:I=a.divide(M.value).format();break;case 3:I=M.altName;break;case 0:default:I=`${a.divide(M.value).format()} ${M.name}`;break}return I}function C(a,S=!1){return`${O(a,2)} ${O(a,1)}eV${S?"/c^2":""}`}let x={...e,toSubscript:o,toSuperscript:f,formatST:g,format:d,formatGain:u,formatTime:v,formatTimeLong:c,formatReduction:l,formatPercent:h,formatMult:p,expMult:m,metric:O,ev:C};return{FORMATS:e,formats:x}}var Zt=17,fr=9e15,cr=Math.log10(9e15),hr=1/9e15,mr=308,dr=-324,he=5,gr=1023,pr=!0,Nr=!1,yr=function(){let t=[];for(let r=dr+1;r<=mr;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),Nt=[2,Math.E,3,4,5,6,7,8,9,10],vr=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],wr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],b=function(e){return s.fromValue_noAlloc(e)},B=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},mt=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},$t=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},br=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r-1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r-1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r-691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r-3617/(122400*n),Math.exp(r)/e},Mr=.36787944117144233,me=.5671432904097838,Yt=function(t,e=1e-10,r=!0){let i,n;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return me;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),B(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),f=o.pow(2);return o.neg().add(f.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=fr)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);pr?t=t.replace(",",""):Nr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let m=parseFloat(n[0]),O=parseFloat(n[1]),C=n[1].split(";"),x=1;if(C.length===2&&(x=parseFloat(C[1]),isFinite(x)||(x=1)),isFinite(m)&&isFinite(O)){let a=s.pentate(m,O,x,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let m=parseFloat(o[0]),O=parseFloat(o[1]),C=o[1].split(";"),x=1;if(C.length===2&&(x=parseFloat(C[1]),isFinite(x)||(x=1)),isFinite(m)&&isFinite(O)){let a=s.tetrate(m,O,x,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let f=t.split("^");if(f.length===2){let m=parseFloat(f[0]),O=parseFloat(f[1]);if(isFinite(m)&&isFinite(O)){let C=s.pow(m,O);return this.sign=C.sign,this.layer=C.layer,this.mag=C.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,d,u=t.split("pt");if(u.length===2){g=10;let m=!1;u[0].startsWith("-")&&(m=!0,u[0]=u[0].slice(1)),d=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(g)&&isFinite(d)){let C=s.tetrate(g,d,O,e);return this.sign=C.sign,this.layer=C.layer,this.mag=C.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),m&&(this.sign*=-1),this}}if(u=t.split("p"),u.length===2){g=10;let m=!1;u[0].startsWith("-")&&(m=!0,u[0]=u[0].slice(1)),d=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(g)&&isFinite(d)){let C=s.tetrate(g,d,O,e);return this.sign=C.sign,this.layer=C.layer,this.mag=C.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),m&&(this.sign*=-1),this}}if(u=t.split("f"),u.length===2){g=10;let m=!1;u[0].startsWith("-")&&(m=!0,u[0]=u[0].slice(1)),u[0]=u[0].replace("(",""),u[0]=u[0].replace(")","");let O=parseFloat(u[0]);if(u[1]=u[1].replace("(",""),u[1]=u[1].replace(")",""),d=parseFloat(u[1]),isFinite(O)||(O=1),isFinite(g)&&isFinite(d)){let C=s.tetrate(g,d,O,e);return this.sign=C.sign,this.layer=C.layer,this.mag=C.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),m&&(this.sign*=-1),this}}let v=t.split("e"),c=v.length-1;if(c===0){let m=parseFloat(t);if(isFinite(m))return this.fromNumber(m),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(c===1){let m=parseFloat(t);if(isFinite(m)&&m!==0)return this.fromNumber(m),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let l=t.split("e^");if(l.length===2){this.sign=1,l[0].startsWith("-")&&(this.sign=-1);let m="";for(let O=0;O=43&&C<=57||C===101)m+=l[1].charAt(O);else return this.layer=parseFloat(m),this.mag=parseFloat(l[1].substr(O+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(c<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(v[0]);if(h===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let p=parseFloat(v[v.length-1]);if(c>=2){let m=parseFloat(v[v.length-2]);isFinite(m)&&(p*=Math.sign(m),p+=$t(m))}if(!isFinite(h))this.sign=v[0]==="-"?-1:1,this.layer=c,this.mag=p;else if(c===1)this.sign=Math.sign(h),this.layer=1,this.mag=p+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=c,c===2){let m=s.mul(B(1,2,p),b(h));return this.sign=m.sign,this.layer=m.layer,this.mag=m.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=p;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:mt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:mt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=he?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):mt(this.m,t)+"e"+mt(this.e,t):this.layer===1?mt(this.m,t)+"e"+mt(this.e,t):this.layer<=he?(this.sign===-1?"-":"")+"e".repeat(this.layer)+mt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+mt(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?B(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?B(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?B(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?B(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return T(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Zt)return r;{let f=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*f;return B(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>Zt)return r;{let f=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*f;return B(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>Zt)return r;{let f=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*f;return B(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(b(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return T(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return T(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return B(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return B(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return B(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=B(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(B(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return B(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=B(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(B(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return B(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=b(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?T(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?T(0,0,0):this.layer===0?B(this.sign,0,1/this.mag):B(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=b(t).abs();if(e.eq(s.dZero))return T(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?T(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=b(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=b(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=b(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=$t(n)),this.layer0?B(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):B(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?B(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):B(this.sign,0,Math.log10(this.mag))}log(t){return t=b(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?B(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?B(this.sign,0,Math.log2(this.mag)):this.layer===1?B(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?B(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):B(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?B(this.sign,0,Math.log(this.mag)):this.layer===1?B(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?B(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):B(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=b(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?T(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return T(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:T(Number.NaN,Number.NaN,Number.NaN):n}pow10(){if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return T(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return T(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return B(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?B(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?B(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return b(t).pow(this)}root(t){let e=b(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(T(1,0,24)))return s.fromNumber(br(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,f=e+o;if(f===e||(e=f,i=i*r,n=360*i,o=1/n,f=e-o,f===e))return s.exp(e);e=f,i=i*r,n=1260*i;let g=1/n;return e=e+g,i=i*r,n=1680*i,g=1/n,e=e-g,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?T(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?B(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?B(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):B(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return B(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(T(this.sign,this.layer-1,this.mag),T(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=T(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return T(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let f=s.ln(this).neg(),g=f.lambertw().div(f);if(o<1)return g;let d=f.lambertw(!1).div(f);return o>1.444667861009099&&(g=d=s.fromNumber(Math.E)),e=b(e),e.eq(d)?d:e.lt(d)?g:T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let f=0;f1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=b(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let f=Math.min(e,i.layer-t.layer-3);e-=f,i.layer-=f}for(let f=0;f1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,f=this.slog_internal(t,r).toNumber();for(let g=1;g1&&o!=u&&(n=!0),o=u,n?i/=2:i*=2,i=Math.abs(i)*(u?-1:1),f+=i,i===0)break}return s.fromNumber(f)}slog_internal(t=10,e=!1){if(t=b(t),t.lte(s.dZero)||t.eq(s.dOne))return T(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?T(0,0,0):this.eq(s.dZero)?T(-1,0,1):T(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return T(-1,0,1);if(t.lt(1.444667861009766)){let n=s.ln(t).neg(),o=n.lambertw().div(n);if(this.eq(o))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return T(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,wr)}static tetrate_critical(t,e){return s.critical_section(t,e,vr)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let g=0;gt){let d=(t-Nt[g])/(Nt[g+1]-Nt[g]);n=r[g][Math.floor(e)]*(1-d)+r[g+1][Math.floor(e)]*d,o=r[g][Math.ceil(e)]*(1-d)+r[g+1][Math.ceil(e)]*d;break}let f=e-Math.floor(e);return n<=0||o<=0?n*(1-f)+o*f:Math.pow(t,Math.log(n)/Math.log(t)*(1-f)+Math.log(o)/Math.log(t)*f)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=b(e);if(i.gt(1)&&i.lte(1.444667861009766)){let f=s.excess_slog(this,e,r),g=f[0].toNumber(),d=f[1],u=g+t,v=s.ln(e).neg(),c=v.lambertw().div(v),l=v.lambertw(!1).div(v),h=s.dOne;d==1?h=c.mul(l).sqrt():d==2&&(h=l.mul(2));let p=i.pow(h),m=Math.floor(u),O=u-m,C=h.pow(1-O).mul(p.pow(O));return s.tetrate(i,m,C,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):T(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=b(t),e=b(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[T(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let n=s.ln(e).neg(),o=n.lambertw().div(n),f=s.dInf;if(e>1&&(f=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=f=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(f))return[T(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(f)){let g=f.mul(2),d=i.pow(g),u=0;if(t.gte(g)&&t.lt(d))u=0;else if(t.gte(d)){let m=d;for(u=1;m.lt(t);)if(m=i.pow(m),u=u+1,m.layer>3){let O=Math.floor(t.layer-m.layer+1);m=i.iteratedexp(O,m,r),u=u+O}m.gt(t)&&(m=m.log(e),u=u-1)}else if(t.lt(g)){let m=g;for(u=0;m.gt(t);)m=m.log(e),u=u-1}let v=0,c=0,l=.5,h=g,p=s.dZero;for(;l>1e-16;){if(c=v+l,h=g.pow(1-c).mul(d.pow(c)),p=s.iteratedexp(e,u,h),p.eq(t))return[new s(u+c),2];p.lt(t)&&(v+=l),l/=2}return p.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(u+v),2]}if(t.lt(f)&&t.gt(o)){let g=o.mul(f).sqrt(),d=i.pow(g),u=0;if(t.lte(g)&&t.gt(d))u=0;else if(t.lte(d)){let m=d;for(u=1;m.gt(t);)m=i.pow(m),u=u+1;m.lt(t)&&(m=m.log(e),u=u-1)}else if(t.gt(g)){let m=g;for(u=0;m.lt(t);)m=m.log(e),u=u-1}let v=0,c=0,l=.5,h=g,p=s.dZero;for(;l>1e-16;){if(c=v+l,h=g.pow(1-c).mul(d.pow(c)),p=s.iteratedexp(e,u,h),p.eq(t))return[new s(u+c),1];p.gt(t)&&(v+=l),l/=2}return p.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(u+v),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?T(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(Yt(this.toNumber())):this.layer===0?s.fromNumber(Yt(this.sign*this.mag)):this.lt("eee15")?de(this):this.ln():this.sign===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Yt(this.sign*this.mag,1e-10,!1)):this.layer==1?de(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return T(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return T(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eMr?this.pow(this.recip()):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return T(1,0,1);if(this.lt(0))return T(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):T(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,f=n.div(2),g=!0;for(;g;)f=r.add(n).div(2),s.iteratedexp(10,i,f,!0).tetrate(t,1,!0).gt(this)?n=f:r=f,f.eq(o)?g=!1:o=f;return s.iteratedexp(10,i,f,!0)}else{let e=1,r=B(1,10,1),i=B(1,10,1),n=B(1,10,1),o=B(1,1,-16),f=s.dZero,g=B(1,10,1),d=o.pow10().recip(),u=s.dZero,v=d,c=d,l=Math.ceil(t)%2==0,h=0,p=B(1,10,1),m=!1,O=s.dZero,C=!1;for(;e<4;){if(e==2){if(l)break;n=B(1,10,1),o=r,e=3,g=B(1,10,1),p=B(1,10,1)}for(m=!1;o.neq(n);){if(O=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))d=o.pow10().recip(),v=o.pow10().recip(),c=o.pow10().recip(),u=s.dZero,h=-1,e==3&&(p=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!l&&o.pow10().recip().lt(.4))d=o.pow10().recip(),v=o.pow10().recip(),c=o.pow10().recip(),u=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))d=o.pow10().recip(),v=s.dZero,c=d.mul(2),u=d,l?h=-1:h=0;else{for(f=o.mul(12e-17),d=o.pow10().recip(),v=o.add(f).pow10().recip(),u=d.sub(v),c=d.add(u);v.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||c.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||v.gte(d)||c.lte(d);)f=f.mul(2),v=o.add(f).pow10().recip(),u=d.sub(v),c=d.add(u);if((e==1&&c.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))||e==3&&c.tetrate(t,1,!0).lt(d.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))&&(p=o),c.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))h=-1;else if(l)h=1;else if(e==3&&o.gt_tolerance(r,1e-8))h=0;else{for(;v.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||c.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||v.gte(d)||c.lte(d);)f=f.mul(2),v=o.add(f).pow10().recip(),u=d.sub(v),c=d.add(u);c.tetrate(t,1,!0).sub(d.tetrate(t,1,!0)).lt(d.tetrate(t,1,!0).sub(v.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(C=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(B(1,10,1)))o=o.mul(2);else{let y=!1;if(m&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),o=o.add(n).div(2),y)break}else if(n.eq(B(1,10,1)))n=o,o=o.div(2);else{let y=!1;if(m&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),n=n.sub(g),o=o.sub(g),y)break}if(n.sub(o).div(2).abs().gt(g.mul(1.5))&&(m=!0),g=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(O))break}if(o.gt("1e18")||!C||p==B(1,10,1))break;e==1?r=p:e==3&&(i=p),e++}n=r,o=B(1,1,-18);let x=o,a=s.dZero,S=!0;for(;S;)if(n.eq(B(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(x)?S=!1:x=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(i.eq(B(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(n=B(1,10,1),o=i,x=o,a=s.dZero,S=!0;S;)if(n.eq(B(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(x)?S=!1:x=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=T(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):T(0,0,0)}cos(){return this.mag<0?T(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):T(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):T(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?T(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return dt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return dt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return dt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return dt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return dt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return dt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let f=Math.floor(r/i[o]);r-=f*i[o],n+=o.repeat(f)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=T(0,0,0),s.dOne=T(1,0,1),s.dNegOne=T(-1,0,1),s.dTwo=T(1,0,2),s.dTen=T(1,0,10),s.dNaN=T(Number.NaN,Number.NaN,Number.NaN),s.dInf=T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=B(1,0,Number.MAX_VALUE),s.dNumberMin=B(1,0,Number.MIN_VALUE),s.fromStringCache=new jt(gr),st([Ct()],s.prototype,"sign",2),st([Ct()],s.prototype,"mag",2),st([Ct()],s.prototype,"layer",2),s=st([ar()],s);var{formats:dt,FORMATS:_r}=lr(s);s.formats=dt;var St=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},zt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new s(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new St(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nc),u=n,v=this.getBoosts(o,!0);v[0][0]?this.boostArray[v[1][0]]=new St({id:o,name:f,description:g,value:d,order:u}):this.boostArray.push(new St({id:o,name:f,description:g,value:d,order:u}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let f=this.getBoosts(o.id,!0);f[0][0]?this.boostArray[f[1][0]]=new St(o):this.boostArray.push(new St(o))}}}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},Kr=ot(ft()),xt=30,Vt=.001;function Sr(t,e,r="geometric"){switch(t=new s(t),e=new s(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return s.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Ht(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new s(t),e=new s(e),r=new s(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function Wt(t,e,r="geometric",i=xt,n=Vt){let o=s.dOne,f=new s(e);if(t(f).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(f).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:f,lowerBound:f,upperBound:f};for(let d=0;d=0;g--){let d=r.add(f.mul(g)),u=r.add(f.mul(g+1)),v=o;if(o=o.add(t(d).add(t(u)).div(2).mul(f)),Ht(v,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Xt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(xt)?ge(t,e,r,i):pe(t,e,r,n)}function Ir(t,e=10,r=0,i=1e3){if(t=new s(t),t.gte(s.pow(e,i)))return t;let n=s.floor(s.log(t,e)),o=t.div(s.pow(e,n));return o=o.mul(s.pow(e,r)).round(),o=o.div(s.pow(e,r)),o=o.mul(s.pow(e,n)),o}function Ne(t,e,r,i=s.dInf,n,o,f=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[s.dZero,s.dZero];if(f=(typeof e.el=="function"?e.el():e.el)??f,g.eq(1)){let c=e.cost(e.level),l=t.gte(c),h=[s.dZero,s.dZero];return f?(h[0]=l?s.dOne:s.dZero,h):(h=[l?s.dOne:s.dZero,l?c:s.dZero],h)}if(e.costBulk){let[c,l]=e.costBulk(t,e.level,g),h=t.gte(l);return[h?c:s.dZero,h&&!f?l:s.dZero]}if(f){let c=p=>e.cost(p.add(r)),l=s.min(i,Wt(c,t,n,o).value.floor()),h=s.dZero;return[l,h]}let d=Wt(c=>Xt(e.cost,c,r),t,n,o).value.floor().min(r.add(g).sub(1)),u=Xt(e.cost,d,r);return[d.sub(r).add(1).max(0),u]}function ye(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Ar(t){return`el/${ye(t)}`}var yt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};st([Ct()],yt.prototype,"id",2),st([_t(()=>s)],yt.prototype,"level",2);var Jt=class $e{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:s.dOne}}).data??{level:s.dOne}).level}set level(e){this.data.level=new s(e)}constructor(e,r,i,n){let o=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>o,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new jt(n??$e.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??s.dOne}},ti=ot(ft());function ve(t,e,r=s.dInf){if(t=new s(t),r=new s(r),r.lt(0))return console.warn("calculateItem: Invalid target: ",r),[s.dZero,s.dZero];if(r.eq(1)){let o=e.cost();return[t.gte(o)?s.dOne:s.dZero,t.gte(o)?o:s.dZero]}let i=t.div(e.cost()).floor().min(r),n=e.cost().mul(i);return[i,n]}var we=class{constructor(t,e,r){this.defaultAmount=s.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??s.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:s.dOne}}).data??{amount:s.dOne}).amount}set amount(t){this.data.amount=new s(t)}},vt=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??s.dZero}};st([Ct()],vt.prototype,"id",2),st([_t(()=>s)],vt.prototype,"amount",2);var ei=ot(ft()),gt=class{constructor(){this.value=s.dZero,this.upgrades={},this.items={}}};st([_t(()=>s)],gt.prototype,"value",2),st([_t(()=>yt)],gt.prototype,"upgrades",2),st([_t(()=>vt)],gt.prototype,"items",2);var be=class{constructor(t=new gt,e,r={defaultVal:s.dZero,defaultBoost:s.dOne}){this.items={},this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new zt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(n);if(i.resetItemAmounts)for(let n of Object.values(this.items))n.amount=new s(n.defaultAmount),i.runUpgradeEffect&&this.runUpgradeEffect(n)}gain(t=1e3){let e=this.boost.calculate().mul(new s(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new yt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(o=>i.test(o)).map(o=>this.upgrades[o])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let n=new Jt(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(n),this.upgrades[i.id]=n,r.push(n)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t instanceof Jt?t.effect?.(t.level,t,this):t.effect?.(t.amount,t,this)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[s.dZero,s.dZero]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=s.min(e,n.maxLevel)),Ne(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,f]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(f),n.level=n.level.add(o),this.runUpgradeEffect(n),!0)}pointerAddItem(t){let e=new vt(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new we(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runUpgradeEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e=1/0){let r=this.getItem(t);return r===null?(console.warn(`Item "${t}" not found.`),[s.dZero,s.dZero]):ve(this.value,r,e)}buyItem(t,e){let r=this.getItem(t);if(r===null)return console.warn(`Item "${t}" not found.`),!1;let[i,n]=this.calculateItem(t,e);return i.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(n),r.amount=r.amount.add(i),this.runUpgradeEffect(r),!0)}},ri=ot(ft()),Lt=class{constructor(t=0){this.value=new s(t)}};st([_t(()=>s)],Lt.prototype,"value",2);var Me=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new Lt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new zt(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},_e=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=r,this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}direction(t,e=1,r){let i=Se.getInstance(this.gridSymbol);return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}},nt=class ie extends Array{constructor(e){e=Array.isArray(e)?e:[e],super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}direction(e,r,i){if(["up","right","down","left"].includes(e))return new ie(this.map(o=>o.direction(e,r,i)));let n=[];for(let o of this)n.push(...o.direction(e,r,i));return new ie(n)}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},Se=class ne{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),ne.instances[this.gridSymbol]=this,this.xSize=e,this.ySize=r??e;for(let n=0;n{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),Tr=ue,Ie={};Ut(Ie,{ConfigManager:()=>kt,DataManager:()=>Ee,EventManager:()=>Te,EventTypes:()=>Oe,Game:()=>Pr,GameAttribute:()=>Pe,GameCurrency:()=>Fe,GameReset:()=>Kt,KeyManager:()=>Ae,gameDefaultConfig:()=>xe,keys:()=>Er});var ii=ot(ft()),kt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Cr={autoAddInterval:!0,fps:30},Er="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),Ae=class Ye{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=Ye.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new kt(Cr)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:i}]:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let o=this.getBind(n.id);if(o){Object.assign(o,n);continue}this.binds.push(n)}}},Oe=(t=>(t.interval="interval",t.timeout="timeout",t))(Oe||{}),Fr={autoAddInterval:!0,fps:30},Te=class ze{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=ze.configManager.parse(e),this.events={},this.config.autoAddInterval){let r=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/r)}}static{this.configManager=new kt(Fr)}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callbackFn(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},ni=ot(ft()),Ce=ot(Qe()),Qt=ot(er()),Ee=class{constructor(t){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return typeof this.static[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=Rt(this.data)}compileDataRaw(t=this.data){let e=Rt(t),r=(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.1.0"}catch{i="8.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,Ce.compressToBase64)(e)}decompileData(t=window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)){if(!t)return null;let e;try{return e=JSON.parse((0,Ce.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Qt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!window.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");window.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t)}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(c){return typeof c=="object"&&c?.constructor===Object}let n=(c,l)=>Object.prototype.hasOwnProperty.call(c,l);function o(c,l,h){if(!c||!l||!h)throw new Error("dataManager.deepMerge(): Missing arguments.");let p=h;for(let m in c)if(n(c,m)&&!n(h,m)&&(p[m]=c[m]),l[m]instanceof gt){let O=c[m],C=h[m];if(Array.isArray(C.upgrades)){let x=C.upgrades;C.upgrades={};for(let a of x)C.upgrades[a.id]=a}C.upgrades={...O.upgrades,...C.upgrades},p[m]=C,C.items={...O.items,...C.items}}else i(c[m])&&i(h[m])&&(p[m]=o(c[m],l[m],h[m]));return p}let f=e?o(this.normalDataPlain,this.normalData,r):r,g=Object.getOwnPropertyNames(new yt({id:"",level:s.dZero})),d=Object.getOwnPropertyNames(new vt({id:"",amount:s.dZero}));function u(c,l){let h=Gt(c,l);if(h instanceof gt){for(let p in h.upgrades){let m=h.upgrades[p];if(!m||!g.every(O=>Object.getOwnPropertyNames(m).includes(O))){delete h.upgrades[p];continue}h.upgrades[p]=Gt(yt,m)}for(let p in h.items){let m=h.items[p];if(!m||!d.every(O=>Object.getOwnPropertyNames(m).includes(O))){delete h.items[p];continue}h.items[p]=Gt(vt,m)}}if(!h)throw new Error(`Failed to convert ${c.name} to class instance.`);return h}function v(c,l){if(!c||!l)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let h=l;for(let p in c){if(l[p]===void 0){console.warn(`Missing property "${p}" in loaded data.`);continue}if(!i(l[p]))continue;let m=c[p].constructor;if(m===Object){h[p]=v(c[p],l[p]);continue}h[p]=u(m,l[p])}return h}return f=v(this.normalData,f),f}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],Rt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Fe=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,i){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=i,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Pe=class{constructor(t,e,r){this.data=typeof t=="function"?t():t,this.static=typeof e=="function"?e():e,this.game=r}get value(){return this.static.value}set value(t){this.data.value=t}},Kt=class Ve{static fromObject(e){return new Ve(e.currenciesToReset,e.extender,e.onReset,e.condition)}constructor(e,r,i,n){this.currenciesToReset=Array.isArray(e)?e:[e],this.extender=Array.isArray(r)?r:r?[r]:[],this.onReset=i,this.condition=n,this.id=Symbol()}reset(e=!1,r=!0,i=new Set){if(e||(typeof this.condition=="function"?!this.condition(this):!this.condition)&&typeof this.condition<"u")return;let n=()=>{this.onReset?.(this),this.currenciesToReset.forEach(o=>{o.static.reset()})};if(this.extender.length===0){n();return}this.extender.forEach(o=>{i.has(o.id)||(i.add(o.id),o.reset(r||e,r,i))}),n()}},xe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Pr=class He{static{this.configManager=new kt(xe)}constructor(e){this.config=He.configManager.parse(e),this.dataManager=new Ee(this),this.keyManager=new Ae({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new Te({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[]){return this.dataManager.setData(e,{currency:new gt}),this.dataManager.setStatic(e,{currency:new be(()=>this.dataManager.getData(e).currency,r)}),new Fe(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new Lt(i)),this.dataManager.setStatic(e,new Me(this.dataManager.getData(e),r,i)),new Pe(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new Kt(...e)}addResetFromObject(e){return Kt.fromObject(e)}},xr={...Tr,...Ie},Lr=xr;if(typeof ut.exports=="object"&&typeof Ot=="object"){var kr=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};ut.exports=kr(ut.exports,Ot)}return ut.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.js b/dist/main/eMath.js index 5d3045d..3e41b97 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -5906,22 +5906,32 @@ var GridCell = class { * Gets the cell in a specific direction from the current cell. * @param direction - The direction to move. * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - direction(direction, distance = 1) { + direction(direction, distance = 1, fill) { const grid = Grid.getInstance(this.gridSymbol); - switch (direction) { - case "up": - return grid.getCell(this.x, this.y - distance); - case "right": - return grid.getCell(this.x + distance, this.y); - case "down": - return grid.getCell(this.x, this.y + distance); - case "left": - return grid.getCell(this.x - distance, this.y); - default: - throw new Error("Invalid direction"); - } + const out = (() => { + switch (direction) { + case "up": + return grid.getCell(this.x, this.y - distance); + case "right": + return grid.getCell(this.x + distance, this.y); + case "down": + return grid.getCell(this.x, this.y + distance); + case "left": + return grid.getCell(this.x - distance, this.y); + case "adjacent": + return grid.getAdjacent(this.x, this.y, distance, fill); + case "diagonal": + return grid.getDiagonal(this.x, this.y, distance, fill); + case "encircling": + return grid.getEncircling(this.x, this.y, distance, fill); + default: + throw new Error("Invalid direction"); + } + })(); + return out; } /** * Gets the cell to the right of the current cell. Can be chained. @@ -5956,7 +5966,7 @@ var GridCell = class { return this.direction("left", distance); } }; -var GridCellCollection = class extends Array { +var GridCellCollection = class _GridCellCollection extends Array { /** * Initializes a new instance of the grid cell collection. * @param cells - The cells to initialize with. @@ -5964,6 +5974,99 @@ var GridCellCollection = class extends Array { constructor(cells) { cells = Array.isArray(cells) ? cells : [cells]; super(...cells); + this.removeDuplicates(); + } + /** + * Removes duplicate cells from the collection. + * Modifies the array in place. + */ + removeDuplicates() { + const duplicatedIndexes = []; + this.forEach((cell, index) => { + if (this.indexOf(cell) !== index) duplicatedIndexes.push(index); + }); + duplicatedIndexes.forEach((index) => this.splice(index, 1)); + } + // Directions + /** + * Gets the cells in a specific direction from the current cells. + * @param direction - The direction to move. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells in the specified direction. + */ + direction(direction, distance, fill) { + if (["up", "right", "down", "left"].includes(direction)) { + return new _GridCellCollection(this.map((cell) => cell.direction(direction, distance, fill))); + } + const output = []; + for (const cell of this) { + output.push(...cell.direction(direction, distance, fill)); + } + return new _GridCellCollection(output); + } + /** + * Gets the cells above the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells above. + */ + up(distance) { + return this.direction("up", distance); + } + /** + * Gets the cells to the right of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the right. + */ + right(distance) { + return this.direction("right", distance); + } + /** + * Gets the cells below the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells below. + */ + down(distance) { + return this.direction("down", distance); + } + /** + * Gets the cells to the left of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the left. + */ + left(distance) { + return this.direction("left", distance); + } + // Other direction + /** + * Gets the cells adjacent to the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells adjacent. + */ + adjacent(distance, fill) { + return this.direction("adjacent", distance, fill); + } + /** + * Gets the cells diagonally from the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells diagonally. + */ + diagonal(distance, fill) { + return this.direction("diagonal", distance, fill); + } + /** + * Gets the cells encircling the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells encircling. + */ + encircling(distance, fill) { + return this.direction("encircling", distance, fill); } }; var Grid = class _Grid { @@ -6061,40 +6164,116 @@ var Grid = class _Grid { * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. - */ - getAdjacent(x, y) { - return new GridCellCollection([ - this.getCell(x, y + 1), - this.getCell(x + 1, y), - this.getCell(x, y - 1), - this.getCell(x - 1, y) - ]); + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + */ + getAdjacent(x, y, distance = 1, fill = false) { + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x, y + 1), + this.getCell(x + 1, y), + this.getCell(x, y - 1), + this.getCell(x - 1, y) + ]); + } + if (!fill) { + return new GridCellCollection([ + this.getCell(x, y + distance), + this.getCell(x + distance, y), + this.getCell(x, y - distance), + this.getCell(x - distance, y) + ]); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x, y + i)); + output.push(this.getCell(x + i, y)); + output.push(this.getCell(x, y - i)); + output.push(this.getCell(x - i, y)); + } + return new GridCellCollection(output); } /** * Gets an array containing all cells diagonally adjacent from a specific cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the diagonal. Defaults to `false`. + */ + getDiagonal(x, y, distance = 1, fill = false) { + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x - 1, y + 1), + this.getCell(x + 1, y + 1), + this.getCell(x + 1, y - 1), + this.getCell(x - 1, y - 1) + ]); + } + if (!fill) { + return new GridCellCollection([ + this.getCell(x - distance, y + distance), + this.getCell(x + distance, y + distance), + this.getCell(x + distance, y - distance), + this.getCell(x - distance, y - distance) + ]); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x - i, y + i)); + output.push(this.getCell(x + i, y + i)); + output.push(this.getCell(x + i, y - i)); + output.push(this.getCell(x - i, y - i)); + } + return new GridCellCollection(output); + } + /** + * Gets an array containing all cells that surround a cell at a specific distance. + * @param x - The x coordinate to check. + * @param y - The y coordinate to check. + * @param distance - The distance to check. + * @returns - An array of all cells. */ - getDiagonal(x, y) { - return new GridCellCollection([ - this.getCell(x - 1, y + 1), - this.getCell(x + 1, y + 1), - this.getCell(x + 1, y - 1), - this.getCell(x - 1, y - 1) - ]); + getEncirclingAtDistance(x, y, distance) { + if (distance <= 1) { + return new GridCellCollection([ + ...this.getAdjacent(x, y), + ...this.getDiagonal(x, y) + ]); + } + const output = []; + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance + i, y - distance)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance, y - distance + i)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance - i, y + distance)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance, y + distance - i)); + } + output.push(...this.getDiagonal(x, y, distance, false)); + return new GridCellCollection(output); } /** * Gets an array containing all cells that surround a cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the surrounding cells. Defaults to `false`. */ - getEncircling(x, y) { - return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y) - ]); + getEncircling(x, y, distance = 1, fill = false) { + if (distance === 1 || !fill) { + return this.getEncirclingAtDistance(x, y, distance); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(...this.getEncirclingAtDistance(x, y, i)); + } + return new GridCellCollection(output); } /** * Calculates the distance between two points on the grid. diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index fc9bf3f..ff40e81 100644 --- a/dist/main/eMath.min.js +++ b/dist/main/eMath.min.js @@ -1,4 +1,4 @@ -"use strict";(function(yt,nt){var Ot=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],nt);else if(typeof module=="object"&&module.exports)module.exports=nt();else{var at=nt(),Tt=Ot?exports:yt;for(var wt in at)Tt[wt]=at[wt]}})(typeof self<"u"?self:exports,()=>{var yt={},nt={exports:yt},Ot=Object.create,at=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyNames,ve=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty,_e=(t,e)=>function(){return e||(0,t[wt(t)[0]])((e={exports:{}}).exports,e),e.exports},Dt=(t,e)=>{for(var r in e)at(t,r,{get:e[r],enumerable:!0})},Wt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(e))!Me.call(t,s)&&s!==r&&at(t,s,{get:()=>e[s],enumerable:!(i=Tt(e,s))||i.enumerable});return t},mt=(t,e,r)=>(r=t!=null?Ot(ve(t)):{},Wt(e||!t||!t.__esModule?at(r,"default",{value:t,enumerable:!0}):r,t)),Ie=t=>Wt(at({},"__esModule",{value:!0}),t),J=(t,e,r,i)=>{for(var s=i>1?void 0:i?Tt(e,r):e,a=t.length-1,h;a>=0;a--)(h=t[a])&&(s=(i?h(e,r,s):h(s))||s);return i&&s&&at(e,r,s),s},gt=_e({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),s=a(e);typeof i.Reflect<"u"&&(s=a(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function a(d,I){return function(F,L){Object.defineProperty(d,F,{configurable:!0,writable:!0,value:L}),I&&I(F,L)}}function h(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return h()||g()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",h=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!m&&!d,F={create:m?function(){return zt(Object.create(null))}:d?function(){return zt({__proto__:null})}:function(){return zt({})},has:I?function(u,l){return s.call(u,l)}:function(u,l){return l in u},get:I?function(u,l){return s.call(u,l)?u[l]:void 0}:function(u,l){return u[l]}},L=Object.getPrototypeOf(Function),P=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:ar(),R=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:or(),w=typeof WeakMap=="function"?WeakMap:ur(),x=a?Symbol.for("@reflect-metadata:registry"):void 0,U=ir(),D=nr(U);function o(u,l,c,y){if(k(c)){if(!ce(u))throw new TypeError;if(!me(l))throw new TypeError;return Q(u,l)}else{if(!ce(u))throw new TypeError;if(!$(l))throw new TypeError;if(!$(y)&&!k(y)&&!Nt(y))throw new TypeError;return Nt(y)&&(y=void 0),c=st(c),rt(u,l,c,y)}}r("decorate",o);function N(u,l){function c(y,q){if(!$(y))throw new TypeError;if(!k(q)&&!er(q))throw new TypeError;Et(u,l,y,q)}return c}r("metadata",N);function p(u,l,c,y){if(!$(c))throw new TypeError;return k(y)||(y=st(y)),Et(u,l,c,y)}r("defineMetadata",p);function v(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=st(c)),X(u,l,c)}r("hasMetadata",v);function S(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=st(c)),K(u,l,c)}r("hasOwnMetadata",S);function E(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=st(c)),tt(u,l,c)}r("getMetadata",E);function O(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=st(c)),ft(u,l,c)}r("getOwnMetadata",O);function j(u,l){if(!$(u))throw new TypeError;return k(l)||(l=st(l)),At(u,l)}r("getMetadataKeys",j);function V(u,l){if(!$(u))throw new TypeError;return k(l)||(l=st(l)),Ct(u,l)}r("getOwnMetadataKeys",V);function Z(u,l,c){if(!$(l))throw new TypeError;if(k(c)||(c=st(c)),!$(l))throw new TypeError;k(c)||(c=st(c));var y=St(l,c,!1);return k(y)?!1:y.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",Z);function Q(u,l){for(var c=u.length-1;c>=0;--c){var y=u[c],q=y(l);if(!k(q)&&!Nt(q)){if(!me(q))throw new TypeError;l=q}}return l}function rt(u,l,c,y){for(var q=u.length-1;q>=0;--q){var z=u[q],W=z(l,c,y);if(!k(W)&&!Nt(W)){if(!$(W))throw new TypeError;y=W}}return y}function X(u,l,c){var y=K(u,l,c);if(y)return!0;var q=$t(l);return Nt(q)?!1:X(u,q,c)}function K(u,l,c){var y=St(l,c,!1);return k(y)?!1:he(y.OrdinaryHasOwnMetadata(u,l,c))}function tt(u,l,c){var y=K(u,l,c);if(y)return ft(u,l,c);var q=$t(l);if(!Nt(q))return tt(u,q,c)}function ft(u,l,c){var y=St(l,c,!1);if(!k(y))return y.OrdinaryGetOwnMetadata(u,l,c)}function Et(u,l,c,y){var q=St(c,y,!0);q.OrdinaryDefineOwnMetadata(u,l,c,y)}function At(u,l){var c=Ct(u,l),y=$t(u);if(y===null)return c;var q=At(y,l);if(q.length<=0)return c;if(c.length<=0)return q;for(var z=new R,W=[],B=0,M=c;B=0&&M=this._keys.length?(this._index=-1,this._keys=l,this._values=l):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},B.prototype.throw=function(M){throw this._index>=0&&(this._index=-1,this._keys=l,this._values=l),M},B.prototype.return=function(M){return this._index>=0&&(this._index=-1,this._keys=l,this._values=l),{value:M,done:!0}},B}(),y=function(){function B(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(B.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),B.prototype.has=function(M){return this._find(M,!1)>=0},B.prototype.get=function(M){var _=this._find(M,!1);return _>=0?this._values[_]:void 0},B.prototype.set=function(M,_){var T=this._find(M,!0);return this._values[T]=_,this},B.prototype.delete=function(M){var _=this._find(M,!1);if(_>=0){for(var T=this._keys.length,A=_+1;AWe}),nt.exports=Ie(Xt);var hr=mt(gt()),Qt={};Dt(Qt,{Attribute:()=>Zt,AttributeStatic:()=>He,Boost:()=>Ut,BoostObject:()=>pt,Currency:()=>It,CurrencyStatic:()=>ze,DEFAULT_ITERATIONS:()=>Ft,Decimal:()=>n,E:()=>De,FORMATS:()=>Re,FormatTypeList:()=>Te,Grid:()=>le,GridCell:()=>ue,GridCellCollection:()=>ct,Item:()=>oe,ItemData:()=>_t,LRUCache:()=>qt,ListNode:()=>Jt,ST_NAMES:()=>ot,UpgradeData:()=>Mt,UpgradeStatic:()=>Rt,calculateItem:()=>ae,calculateSum:()=>jt,calculateSumApprox:()=>ie,calculateSumLoop:()=>re,calculateUpgrade:()=>ne,decimalToJSONString:()=>se,equalsTolerance:()=>Bt,formats:()=>lt,inverseFunctionApprox:()=>Gt,roundingBase:()=>Ye,upgradeToCacheNameEL:()=>$e});var cr=mt(gt()),qt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new Jt(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},Jt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},et;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(et||(et={}));var Se=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?i===et.CLASS_TO_CLASS||i===et.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===et.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),s=this._exposeMetadatas.get(e),a=s&&s.get(void 0);return i&&a||!i&&!a?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(F){return F.propertyName!==void 0}));for(var a=[],h=0,g=this.getAncestors(r);hNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(3)){let V=[];for(let Z=0;ZNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(2)){let V=[];for(let Z=0;Z118?e.elemental.beyondOg(S):e.elemental.config.element_lists[o-1][v]},beyondOg(o){let N=Math.floor(Math.log10(o)),p=["n","u","b","t","q","p","h","s","o","e"],v="";for(let S=N;S>=0;S--){let E=Math.floor(o/Math.pow(10,S))%10;v==""?v=p[E].toUpperCase():v+=p[E]}return v},abbreviationLength(o){return o==1?1:Math.pow(Math.floor(o/2)+1,2)*2},getAbbreviationAndValue(o){let N=o.log(118).toNumber(),p=Math.floor(N)+1,v=e.elemental.abbreviationLength(p),S=N-p+1,E=Math.floor(S*v),O=e.elemental.getAbbreviation(p,S),j=new t(118).pow(p+E/v-1);return[O,j]},formatElementalPart(o,N){return N.eq(1)?o:`${N.toString()} ${o}`},format(o,N=2){if(o.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(o.log10(),N);let p=o.log(118),S=p.log(118).log(118).toNumber(),E=Math.max(4-S*2,1),O=[];for(;p.gte(1)&&O.length=E)return O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ");let j=new t(118).pow(p).toFixed(O.length===1?3:N);return O.length===0?j:O.length===1?`${j} \xD7 ${e.elemental.formatElementalPart(O[0][0],O[0][1])}`:`${j} \xD7 (${O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ")})`}},old_sc:{format(o,N){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(t.dTen.pow(p));return(p.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(o,N=2){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.eng.format(S.floor(),0)}let v=o.div(new t(1e3).pow(p.div(3).floor()));return(p.log10().gte(9)?"":v.toFixed(new t(4).sub(p.sub(p.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(p.div(3).floor().mul(3),0)}}},mixed_sc:{format(o,N,p=9){o=new t(o);let v=o.log10().floor();return v.lt(303)&&v.gte(p)?m(o,N,p,"st"):m(o,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(o,N=2,p){o=new t(o);let v=o.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return m(o,N,p,"sc");o=t.dTen.pow(o.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let S=v.div(10).floor(),E=v.toNumber()%10-1;return m(o,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+m(S,0,p,"sc"):"")+"-":"")+(isNaN(E)?"nanity":e.layer.layers[E])}},standard:{tier1(o){return ot[0][0][o%10]+ot[0][1][Math.floor(o/10)%10]+ot[0][2][Math.floor(o/100)]},tier2(o){let N=o%10,p=Math.floor(o/10)%10,v=Math.floor(o/100)%10,S="";return o<10?ot[1][0][o]:(p==1&&N==0?S+="Vec":S+=ot[1][1][N]+ot[1][2][p],S+=ot[1][3][v],S)}},inf:{format(o,N,p){o=new t(o);let v=0,S=new t(Number.MAX_VALUE),E=["","\u221E","\u03A9","\u03A8","\u028A"],O=["","","m","mm","mmm"];for(;o.gte(S);)o=o.log(S),v++;return v==0?m(o,N,p,"sc"):o.gte(3)?O[v]+E[v]+"\u03C9^"+m(o.sub(1),N,p,"sc"):o.gte(2)?O[v]+"\u03C9"+E[v]+"-"+m(S.pow(o.sub(2)),N,p,"sc"):O[v]+E[v]+"-"+m(S.pow(o.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(o,N=new t(1e15),p=!1,v=9){if(o=new t(o),N=new t(N).div(1e3),o.lt(N.mul(1e3)))return"";let{alphabet:S}=e.alphabet.config,E=S.length,O=o.log(1e3).sub(N.log(1e3)).floor(),j=O.add(1).log(E+1).ceil(),V="",Z=(Q,rt)=>{let X=Q,K="";for(let tt=0;tt=E)return"\u03C9";K=S[ft]+K,X=X.sub(1).div(E).floor()}return K};if(j.lt(v))V=Z(O,j);else{let Q=j.sub(v).add(1),rt=O.div(t.pow(E+1,Q.sub(1))).floor();V=`${Z(rt,new t(v))}(${Q.gt("1e9")?Q.format():Q.format(0)})`}return V},format(o,N=2,p=9,v="mixed_sc",S=new t(1e15),E=!1,O){if(o=new t(o),S=new t(S).div(1e3),o.lt(S.mul(1e3)))return m(o,N,p,v);let j=e.alphabet.getAbbreviation(o,S,E,O),V=o.div(t.pow(1e3,o.log(1e3).floor()));return`${j.length>(O??9)+2?"":V.toFixed(N)+" "}${j}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",s="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function a(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":i[parseInt(N,10)]).join("")}function h(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function g(o,N=2,p=9,v="st"){return m(o,N,p,v)}function m(o,N=2,p=9,v="mixed_sc"){o=new t(o);let S=o.lt(0)?"-":"";if(o.mag==1/0)return S+"Infinity";if(Number.isNaN(o.mag))return S+"NaN";if(o.lt(0)&&(o=o.mul(-1)),o.eq(0))return o.toFixed(N);let E=o.log10().floor();switch(v){case"sc":case"scientific":if(o.log10().lt(Math.min(-N,0))&&N>1){let O=o.log10().ceil(),j=o.div(O.eq(-1)?new t(.1):t.dTen.pow(O)),V=O.mul(-1).max(1).log10().gte(9);return S+(V?"":j.toFixed(2))+"e"+m(O,0,p,"mixed_sc")}else if(E.lt(p)){let O=Math.max(Math.min(N-E.toNumber(),N),0);return S+(O>0?o.toFixed(O):o.toFixed(O).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(o.gte("eeee10")){let V=o.slog();return(V.gte(1e9)?"":t.dTen.pow(V.sub(V.floor())).toFixed(2))+"F"+m(V.floor(),0)}let O=o.div(t.dTen.pow(E)),j=E.log10().gte(9);return S+(j?"":O.toFixed(2))+"e"+m(E,0,p,"mixed_sc")}case"st":case"standard":{let O=o.log(1e3).floor();if(O.lt(1))return S+o.toFixed(Math.max(Math.min(N-E.toNumber(),N),0));let j=O.mul(3),V=O.log10().floor();if(V.gte(3e3))return"e"+m(E,N,p,"st");let Z="";if(O.lt(4))Z=["","K","M","B"][Math.round(O.toNumber())];else{let X=Math.floor(O.log(1e3).toNumber());for(X<100&&(X=Math.max(X-1,0)),O=O.sub(1).div(t.dTen.pow(X*3));O.gt(0);){let K=O.div(1e3).floor(),tt=O.sub(K.mul(1e3)).floor().toNumber();tt>0&&(tt==1&&!X&&(Z="U"),X&&(Z=e.standard.tier2(X)+(Z?"-"+Z:"")),tt>1&&(Z=e.standard.tier1(tt)+Z)),O=K,X++}}let Q=o.div(t.dTen.pow(j)),rt=N===2?t.dTwo.sub(E.sub(j)).add(1).toNumber():N;return S+(V.gte(10)?"":Q.toFixed(rt)+" ")+Z}default:return e[v]||console.error('Invalid format type "',v,'"'),S+e[v].format(o,N,p)}}function d(o,N,p="mixed_sc",v,S){o=new t(o),N=new t(N);let E=o.add(N),O,j=E.div(o);return j.gte(10)&&o.gte(1e100)?(j=j.log10().mul(20),O="(+"+m(j,v,S,p)+" OoMs/sec)"):O="(+"+m(N,v,S,p)+"/sec)",O}function I(o,N=2,p="s"){return o=new t(o),o.gte(86400)?m(o.div(86400).floor(),0,12,"sc")+":"+I(o.mod(86400),N,"d"):o.gte(3600)||p=="d"?(o.div(3600).gte(10)||p!="d"?"":"0")+m(o.div(3600).floor(),0,12,"sc")+":"+I(o.mod(3600),N,"h"):o.gte(60)||p=="h"?(o.div(60).gte(10)||p!="h"?"":"0")+m(o.div(60).floor(),0,12,"sc")+":"+I(o.mod(60),N,"m"):(o.gte(10)||p!="m"?"":"0")+m(o,N,12,"sc")}function F(o,N=!1,p=0,v=9,S="mixed_sc"){let E=Ct=>m(Ct,p,v,S);o=new t(o);let O=o.mul(1e3).mod(1e3).floor(),j=o.mod(60).floor(),V=o.div(60).mod(60).floor(),Z=o.div(3600).mod(24).floor(),Q=o.div(86400).mod(365.2425).floor(),rt=o.div(31556952).floor(),X=rt.eq(1)?" year":" years",K=Q.eq(1)?" day":" days",tt=Z.eq(1)?" hour":" hours",ft=V.eq(1)?" minute":" minutes",Et=j.eq(1)?" second":" seconds",At=O.eq(1)?" millisecond":" milliseconds";return`${rt.gt(0)?E(rt)+X+", ":""}${Q.gt(0)?E(Q)+K+", ":""}${Z.gt(0)?E(Z)+tt+", ":""}${V.gt(0)?E(V)+ft+", ":""}${j.gt(0)?E(j)+Et+",":""}${N&&O.gt(0)?" "+E(O)+At:""}`.replace(/,([^,]*)$/,"$1").trim()}function L(o){return o=new t(o),m(t.dOne.sub(o).mul(100))+"%"}function P(o){return o=new t(o),m(o.mul(100))+"%"}function R(o,N=2){return o=new t(o),o.gte(1)?"\xD7"+o.format(N):"/"+o.pow(-1).format(N)}function w(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function x(o,N=0){o=new t(o);let p=(O=>O.map((j,V)=>({name:j.name,altName:j.altName,value:t.pow(1e3,new t(V).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),v="",S=o.lte(0)?0:t.min(t.log(o,1e3).sub(1),p.length-1).floor().toNumber(),E=p[S];if(S===0)switch(N){case 1:v="";break;case 2:case 0:default:v=o.format();break}switch(N){case 1:v=E.name;break;case 2:v=o.divide(E.value).format();break;case 3:v=E.altName;break;case 0:default:v=`${o.divide(E.value).format()} ${E.name}`;break}return v}function U(o,N=!1){return`${x(o,2)} ${x(o,1)}eV${N?"/c^2":""}`}let D={...e,toSubscript:a,toSuperscript:h,formatST:g,format:m,formatGain:d,formatTime:I,formatTimeLong:F,formatReduction:L,formatPercent:P,formatMult:R,expMult:w,metric:x,ev:U};return{FORMATS:e,formats:D}}var xt=17,Ee=9e15,Ae=Math.log10(9e15),Ce=1/9e15,qe=308,Pe=-324,Kt=5,xe=1023,ke=!0,Le=!1,Ue=function(){let t=[];for(let r=Pe+1;r<=qe;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ht=[2,Math.E,3,4,5,6,7,8,9,10],Ve=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],Be=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return n.fromValue_noAlloc(e)},C=function(t,e,r){return n.fromComponents(t,e,r)},b=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},ut=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),a=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(a.toFixed(Math.max(i-s,0)))},kt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Ge=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,s=t;return r=r+1/(12*s),s=s*i,r=r-1/(360*s),s=s*i,r=r+1/(1260*s),s=s*i,r=r-1/(1680*s),s=s*i,r=r+1/(1188*s),s=s*i,r=r-691/(360360*s),s=s*i,r=r+7/(1092*s),s=s*i,r=r-3617/(122400*s),Math.exp(r)/e},je=.36787944117144233,te=.5671432904097838,Lt=function(t,e=1e-10,r=!0){let i,s;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return te;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let a=0;a<100;++a){if(s=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(s-i).5?1:-1;if(Math.random()*20<1)return b(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let s=Math.pow(10,i);return Math.random()>.9&&(s=Math.trunc(s)),C(e,r,s)}static affordGeometricSeries_core(t,e,r,i){let s=e.mul(r.pow(i));return n.floor(t.div(s).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(n.sub(1,r.pow(t))).div(n.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r)).sub(r.div(2)),h=a.pow(2);return a.neg().add(h.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=Ee)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=n.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);ke?t=t.replace(",",""):Le&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let w=parseFloat(s[0]),x=parseFloat(s[1]),U=s[1].split(";"),D=1;if(U.length===2&&(D=parseFloat(U[1]),isFinite(D)||(D=1)),isFinite(w)&&isFinite(x)){let o=n.pentate(w,x,D,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let a=t.split("^^");if(a.length===2){let w=parseFloat(a[0]),x=parseFloat(a[1]),U=a[1].split(";"),D=1;if(U.length===2&&(D=parseFloat(U[1]),isFinite(D)||(D=1)),isFinite(w)&&isFinite(x)){let o=n.tetrate(w,x,D,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let h=t.split("^");if(h.length===2){let w=parseFloat(h[0]),x=parseFloat(h[1]);if(isFinite(w)&&isFinite(x)){let U=n.pow(w,x);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,m,d=t.split("pt");if(d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}let I=t.split("e"),F=I.length-1;if(F===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(F===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let L=t.split("e^");if(L.length===2){this.sign=1,L[0].startsWith("-")&&(this.sign=-1);let w="";for(let x=0;x=43&&U<=57||U===101)w+=L[1].charAt(x);else return this.layer=parseFloat(w),this.mag=parseFloat(L[1].substr(x+1)),this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}if(F<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let P=parseFloat(I[0]);if(P===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let R=parseFloat(I[I.length-1]);if(F>=2){let w=parseFloat(I[I.length-2]);isFinite(w)&&(R*=Math.sign(w),R+=kt(w))}if(!isFinite(P))this.sign=I[0]==="-"?-1:1,this.layer=F,this.mag=R;else if(F===1)this.sign=Math.sign(P),this.layer=1,this.mag=R+Math.log10(Math.abs(P));else if(this.sign=Math.sign(P),this.layer=F,F===2){let w=n.mul(C(1,2,R),f(P));return this.sign=w.sign,this.layer=w.layer,this.mag=w.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=R;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ut(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ut(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=Kt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ut(this.m,t)+"e"+ut(this.e,t):this.layer===1?ut(this.m,t)+"e"+ut(this.e,t):this.layer<=Kt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ut(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ut(this.mag,t)}abs(){return b(this.sign===0?0:1,this.layer,this.mag)}neg(){return b(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?b(-1,0,1):b(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?C(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?b(1,0,1):b(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?C(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return b(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),a=i.layer*Math.sign(i.mag);if(s-a>=2)return r;if(s===0&&a===-1){if(Math.abs(i.mag-Math.log10(r.mag))>xt)return r;{let h=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>xt)return r;{let h=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*h;return C(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>xt)return r;{let h=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return b(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return b(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return C(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return C(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return C(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?b(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?b(0,0,0):this.layer===0?C(this.sign,0,1/this.mag):C(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(n.dZero))return b(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new n(r%i):this.sub(e).eq(this)?b(0,0,0):e.sub(this).eq(e)?new n(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=kt(s)),this.layer0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer>0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?C(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log2(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?b(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return b(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:b(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return b(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return b(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return C(1,0,e);if(t.sign===0)return b(1,0,1);t=b(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?C(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?C(-t.sign,t.layer+1,-t.mag):b(1,0,1)}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(b(1,0,24)))return n.fromNumber(Ge(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,s=12*i,a=1/s,h=e+a;if(h===e||(e=h,i=i*r,s=360*i,a=1/s,h=e-a,h===e))return n.exp(e);e=h,i=i*r,s=1260*i;let g=1/s;return e=e+g,i=i*r,s=1680*i,g=1/s,e=e-g,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?b(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?C(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?C(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):C(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return C(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(b(this.sign,this.layer-1,this.mag),b(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=b(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return b(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let a=this.toNumber();if(a<=1.444667861009766&&a>=.06598803584531254){let h=n.ln(this).neg(),g=h.lambertw().div(h);if(a<1)return g;let m=h.lambertw(!1).div(h);return a>1.444667861009099&&(g=m=n.fromNumber(Math.E)),e=f(e),e.eq(m)?m:e.lt(m)?g:b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return a>1.444667861009766?b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let a=Math.abs((t+1)%2);return a>1&&(a=2-a),n.fromNumber(a)}if(t<0)return n.iteratedlog(e,this,-t,r);e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;if(this.gt(n.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(n.ln(this).neg().lambertw(!1).div(n.ln(this).neg())))&&(i>1e4||!r)){let a=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let h=0;h1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let a=0;a3)return b(e.sign,e.layer+(t-a-1),e.mag);if(a>1e4)return e}return e}iteratedexp(t=2,e=b(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=f(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let a=s-e;if(i.layer-t.layer>3){let h=Math.min(e,i.layer-t.layer-3);e-=h,i.layer-=h}for(let h=0;h1e4)return i}return a>0&&a<1&&(t.eq(10)?i=i.layeradd10(-a,r):i=i.layeradd(-a,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,s=!1,a=!1,h=this.slog_internal(t,r).toNumber();for(let g=1;g1&&a!=d&&(s=!0),a=d,s?i/=2:i*=2,i=Math.abs(i)*(d?-1:1),h+=i,i===0)break}return n.fromNumber(h)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(n.dZero)||t.eq(n.dOne))return b(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?b(0,0,0):this.eq(n.dZero)?b(-1,0,1):b(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return b(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),a=s.lambertw().div(s);if(this.eq(a))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(a))return b(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=n.fromDecimal(this);if(i.layer-t.layer>3){let s=i.layer-t.layer-3;r+=s,i.layer-=s}for(let s=0;s<100;++s)if(i.lt(n.dZero))i=n.pow(t,i),r-=1;else{if(i.lte(n.dOne))return e?n.fromNumber(r+i.toNumber()-1):n.fromNumber(r+n.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=n.log(i,t)}return n.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:n.critical_section(t,e,Be)}static tetrate_critical(t,e){return n.critical_section(t,e,Ve)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let s=0,a=0;for(let g=0;gt){let m=(t-ht[g])/(ht[g+1]-ht[g]);s=r[g][Math.floor(e)]*(1-m)+r[g+1][Math.floor(e)]*m,a=r[g][Math.ceil(e)]*(1-m)+r[g+1][Math.ceil(e)]*m;break}let h=e-Math.floor(e);return s<=0||a<=0?s*(1-h)+a*h:Math.pow(t,Math.log(s)/Math.log(t)*(1-h)+Math.log(a)/Math.log(t)*h)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=f(e);if(i.gt(1)&&i.lte(1.444667861009766)){let h=n.excess_slog(this,e,r),g=h[0].toNumber(),m=h[1],d=g+t,I=n.ln(e).neg(),F=I.lambertw().div(I),L=I.lambertw(!1).div(I),P=n.dOne;m==1?P=F.mul(L).sqrt():m==2&&(P=L.mul(2));let R=i.pow(P),w=Math.floor(d),x=d-w,U=P.pow(1-x).mul(R.pow(x));return n.tetrate(i,w,U,r)}let a=this.slog(e,100,r).toNumber()+t;return a>=0?n.tetrate(e,a,n.dOne,r):Number.isFinite(a)?a>=-1?n.log(n.tetrate(e,a+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,a+2,n.dOne,r),e),e):b(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=f(t),e=f(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[b(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),a=s.lambertw().div(s),h=n.dInf;if(e>1&&(h=s.lambertw(!1).div(s)),e>1.444667861009099&&(a=h=n.fromNumber(Math.E)),t.lt(a))return[t.slog(e,100,r),0];if(t.eq(a))return[b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(h))return[b(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(h)){let g=h.mul(2),m=i.pow(g),d=0;if(t.gte(g)&&t.lt(m))d=0;else if(t.gte(m)){let w=m;for(d=1;w.lt(t);)if(w=i.pow(w),d=d+1,w.layer>3){let x=Math.floor(t.layer-w.layer+1);w=i.iteratedexp(x,w,r),d=d+x}w.gt(t)&&(w=w.log(e),d=d-1)}else if(t.lt(g)){let w=g;for(d=0;w.gt(t);)w=w.log(e),d=d-1}let I=0,F=0,L=.5,P=g,R=n.dZero;for(;L>1e-16;){if(F=I+L,P=g.pow(1-F).mul(m.pow(F)),R=n.iteratedexp(e,d,P),R.eq(t))return[new n(d+F),2];R.lt(t)&&(I+=L),L/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),2]}if(t.lt(h)&&t.gt(a)){let g=a.mul(h).sqrt(),m=i.pow(g),d=0;if(t.lte(g)&&t.gt(m))d=0;else if(t.lte(m)){let w=m;for(d=1;w.gt(t);)w=i.pow(w),d=d+1;w.lt(t)&&(w=w.log(e),d=d-1)}else if(t.gt(g)){let w=g;for(d=0;w.lt(t);)w=w.log(e),d=d-1}let I=0,F=0,L=.5,P=g,R=n.dZero;for(;L>1e-16;){if(F=I+L,P=g.pow(1-F).mul(m.pow(F)),R=n.iteratedexp(e,d,P),R.eq(t))return[new n(d+F),1];R.gt(t)&&(I+=L),L/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?b(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new n(this):this.mag<0?n.fromNumber(Lt(this.toNumber())):this.layer===0?n.fromNumber(Lt(this.sign*this.mag)):this.lt("eee15")?ee(this):this.ln():this.sign===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?n.fromNumber(Lt(this.sign*this.mag,1e-10,!1)):this.layer==1?ee(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return b(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return n.fromNumber(t).add(2).pow(this.recip());if(t<=0)return b(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eje?this.pow(this.recip()):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return b(1,0,1);if(this.lt(0))return b(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new n(this):b(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=n.dTen;this.gte(n.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=n.dZero,i=e.layer,s=e.iteratedlog(10,i,!0),a=s,h=s.div(2),g=!0;for(;g;)h=r.add(s).div(2),n.iteratedexp(10,i,h,!0).tetrate(t,1,!0).gt(this)?s=h:r=h,h.eq(a)?g=!1:a=h;return n.iteratedexp(10,i,h,!0)}else{let e=1,r=C(1,10,1),i=C(1,10,1),s=C(1,10,1),a=C(1,1,-16),h=n.dZero,g=C(1,10,1),m=a.pow10().recip(),d=n.dZero,I=m,F=m,L=Math.ceil(t)%2==0,P=0,R=C(1,10,1),w=!1,x=n.dZero,U=!1;for(;e<4;){if(e==2){if(L)break;s=C(1,10,1),a=r,e=3,g=C(1,10,1),R=C(1,10,1)}for(w=!1;a.neq(s);){if(x=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),F=a.pow10().recip(),d=n.dZero,P=-1,e==3&&(R=a);else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip())&&!L&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),F=a.pow10().recip(),d=n.dZero,P=0;else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip().mul(2).tetrate(t,1,!0)))m=a.pow10().recip(),I=n.dZero,F=m.mul(2),d=m,L?P=-1:P=0;else{for(h=a.mul(12e-17),m=a.pow10().recip(),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);I.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||F.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||I.gte(m)||F.lte(m);)h=h.mul(2),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);if((e==1&&F.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(R=a),F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))P=-1;else if(L)P=1;else if(e==3&&a.gt_tolerance(r,1e-8))P=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||F.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||I.gte(m)||F.lte(m);)h=h.mul(2),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);F.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?P=0:P=1}}if(P==-1&&(U=!0),e==1&&P==1||e==3&&P!=0)if(s.eq(C(1,10,1)))a=a.mul(2);else{let p=!1;if(w&&(P==1&&e==1||P==-1&&e==3)&&(p=!0),a=a.add(s).div(2),p)break}else if(s.eq(C(1,10,1)))s=a,a=a.div(2);else{let p=!1;if(w&&(P==1&&e==1||P==-1&&e==3)&&(p=!0),s=s.sub(g),a=a.sub(g),p)break}if(s.sub(a).div(2).abs().gt(g.mul(1.5))&&(w=!0),g=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(x))break}if(a.gt("1e18")||!U||R==C(1,10,1))break;e==1?r=R:e==3&&(i=R),e++}s=r,a=C(1,1,-18);let D=a,o=n.dZero,N=!0;for(;N;)if(s.eq(C(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(D)?N=!1:D=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);if(o.eq_tolerance(r,1e-15)){if(i.eq(C(1,10,1)))return b(Number.NaN,Number.NaN,Number.NaN);for(s=C(1,10,1),a=i,D=a,o=n.dZero,N=!0;N;)if(s.eq(C(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(D)?N=!1:D=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);return o.pow10().recip()}else return o.pow10().recip()}}pentate(t=2,e=b(1,0,1),r=!1){e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;s!==0&&(e.eq(n.dOne)?(++t,e=n.fromNumber(s)):this.eq(10)?e=e.layeradd10(s,r):e=e.layeradd(s,this,r));for(let a=0;a10)return e}return e}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):b(0,0,0)}cos(){return this.mag<0?b(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):b(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):b(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?b(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return lt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return lt.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return lt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return lt.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return lt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return lt.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let a of Object.keys(i)){let h=Math.floor(r/i[a]);r-=h*i[a],s+=a.repeat(h)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=b(0,0,0),n.dOne=b(1,0,1),n.dNegOne=b(-1,0,1),n.dTwo=b(1,0,2),n.dTen=b(1,0,10),n.dNaN=b(Number.NaN,Number.NaN,Number.NaN),n.dInf=b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=C(1,0,Number.MAX_VALUE),n.dNumberMin=C(1,0,Number.MIN_VALUE),n.fromStringCache=new qt(xe),J([vt()],n.prototype,"sign",2),J([vt()],n.prototype,"mag",2),J([vt()],n.prototype,"layer",2),n=J([Oe()],n);var{formats:lt,FORMATS:Re}=Fe(n);n.formats=lt;var pt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Ut=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new n(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new pt(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sF),d=s,I=this.getBoosts(a,!0);I[0][0]?this.boostArray[I[1][0]]=new pt({id:a,name:h,description:g,value:m,order:d}):this.boostArray.push(new pt({id:a,name:h,description:g,value:m,order:d}))}else{t=Array.isArray(t)?t:[t];for(let a of t){let h=this.getBoosts(a.id,!0);h[0][0]?this.boostArray[h[1][0]]=new pt(a):this.boostArray.push(new pt(a))}}}calculate(t=this.baseEffect){let e=new n(t),r=this.boostArray;r=r.sort((i,s)=>i.order-s.order);for(let i of r)e=i.value(e);return e}},mr=mt(gt()),Ft=30,Vt=.001;function Ze(t,e,r="geometric"){switch(t=new n(t),e=new n(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return n.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Bt(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new n(t),e=new n(e),r=new n(r);let s,a;return i.mode==="geometric"?(s=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),a=s.lte(r)):(s=t.sub(e).abs(),a=s.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!a)&&console.log({a:t,b:e,tolerance:r,config:i,diff:s,result:a}),a}function Gt(t,e,r="geometric",i=Ft,s=Vt){let a=n.dOne,h=new n(e);if(t(h).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(h).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:h,lowerBound:h,upperBound:h};for(let m=0;m=0;g--){let m=r.add(h.mul(g)),d=r.add(h.mul(g+1)),I=a;if(a=a.add(t(m).add(t(d)).div(2).mul(h)),Bt(I,a,s,{verbose:!1,mode:"geometric"}))break}return a}function jt(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(Ft)?re(t,e,r,i):ie(t,e,r,s)}function Ye(t,e=10,r=0,i=1e3){if(t=new n(t),t.gte(n.pow(e,i)))return t;let s=n.floor(n.log(t,e)),a=t.div(n.pow(e,s));return a=a.mul(n.pow(e,r)).round(),a=a.div(n.pow(e,r)),a=a.mul(n.pow(e,s)),a}function ne(t,e,r,i=n.dInf,s,a,h=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[n.dZero,n.dZero];if(h=(typeof e.el=="function"?e.el():e.el)??h,g.eq(1)){let F=e.cost(e.level),L=t.gte(F),P=[n.dZero,n.dZero];return h?(P[0]=L?n.dOne:n.dZero,P):(P=[L?n.dOne:n.dZero,L?F:n.dZero],P)}if(e.costBulk){let[F,L]=e.costBulk(t,e.level,g),P=t.gte(L);return[P?F:n.dZero,P&&!h?L:n.dZero]}if(h){let F=R=>e.cost(R.add(r)),L=n.min(i,Gt(F,t,s,a).value.floor()),P=n.dZero;return[L,P]}let m=Gt(F=>jt(e.cost,F,r),t,s,a).value.floor().min(r.add(g).sub(1)),d=jt(e.cost,m,r);return[m.sub(r).add(1).max(0),d]}function se(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function $e(t){return`el/${se(t)}`}var Mt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};J([vt()],Mt.prototype,"id",2),J([dt(()=>n)],Mt.prototype,"level",2);var Rt=class we{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:n.dOne}}).data??{level:n.dOne}).level}set level(e){this.data.level=new n(e)}constructor(e,r,i,s){let a=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>a,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new qt(s??we.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??n.dOne}},gr=mt(gt());function ae(t,e,r=n.dInf){if(t=new n(t),r=new n(r),r.lt(0))return console.warn("calculateItem: Invalid target: ",r),[n.dZero,n.dZero];if(r.eq(1)){let a=e.cost();return[t.gte(a)?n.dOne:n.dZero,t.gte(a)?a:n.dZero]}let i=t.div(e.cost()).floor().min(r),s=e.cost().mul(i);return[i,s]}var oe=class{constructor(t,e,r){this.defaultAmount=n.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??n.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:n.dOne}}).data??{amount:n.dOne}).amount}set amount(t){this.data.amount=new n(t)}},_t=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??n.dZero}};J([vt()],_t.prototype,"id",2),J([dt(()=>n)],_t.prototype,"amount",2);var dr=mt(gt()),It=class{constructor(){this.value=n.dZero,this.upgrades={},this.items={}}};J([dt(()=>n)],It.prototype,"value",2),J([dt(()=>Mt)],It.prototype,"upgrades",2),J([dt(()=>_t)],It.prototype,"items",2);var ze=class{constructor(t=new It,e,r={defaultVal:n.dZero,defaultBoost:n.dOne}){this.items={},this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Ut(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let s of Object.values(this.upgrades))s.level=new n(s.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(s);if(i.resetItemAmounts)for(let s of Object.values(this.items))s.amount=new n(s.defaultAmount),i.runUpgradeEffect&&this.runUpgradeEffect(s)}gain(t=1e3){let e=this.boost.calculate().mul(new n(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Mt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(a=>i.test(a)).map(a=>this.upgrades[a])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let s=new Rt(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(s),this.upgrades[i.id]=s,r.push(s)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t instanceof Rt?t.effect?.(t.level,t,this):t.effect?.(t.amount,t,this)}calculateUpgrade(t,e=1/0,r,i){let s=this.getUpgrade(t);return s===null?(console.warn(`Upgrade "${t}" not found.`),[n.dZero,n.dZero]):(e=s.level.add(e),s.maxLevel!==void 0&&(e=n.min(e,s.maxLevel)),ne(this.value,s,s.level,e,r,i))}getNextCost(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(a))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(a[0])).add(a[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[a,h]=this.calculateUpgrade(t,e,r,i);return a.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(h),s.level=s.level.add(a),this.runUpgradeEffect(s),!0)}pointerAddItem(t){let e=new _t(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new oe(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runUpgradeEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e=1/0){let r=this.getItem(t);return r===null?(console.warn(`Item "${t}" not found.`),[n.dZero,n.dZero]):ae(this.value,r,e)}buyItem(t,e){let r=this.getItem(t);if(r===null)return console.warn(`Item "${t}" not found.`),!1;let[i,s]=this.calculateItem(t,e);return i.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(s),r.amount=r.amount.add(i),this.runUpgradeEffect(r),!0)}},pr=mt(gt()),Zt=class{constructor(t=0){this.value=new n(t)}};J([dt(()=>n)],Zt.prototype,"value",2);var He=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new Zt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Ut(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},ue=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=r,this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}direction(t,e=1){let r=le.getInstance(this.gridSymbol);switch(t){case"up":return r.getCell(this.x,this.y-e);case"right":return r.getCell(this.x+e,this.y);case"down":return r.getCell(this.x,this.y+e);case"left":return r.getCell(this.x-e,this.y);default:throw new Error("Invalid direction")}}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}},ct=class extends Array{constructor(t){t=Array.isArray(t)?t:[t],super(...t)}},le=class Ht{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),Ht.instances[this.gridSymbol]=this,this.xSize=e,this.ySize=r??e;for(let s=0;s{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new n(r));return Object.getOwnPropertyNames(n).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=n[r]}),e})(),We=Qt;if(typeof nt.exports=="object"&&typeof yt=="object"){var Xe=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,s)&&s!==r&&Object.defineProperty(t,s,{get:()=>e[s],enumerable:!(i=Object.getOwnPropertyDescriptor(e,s))||i.enumerable});return t};nt.exports=Xe(nt.exports,yt)}return nt.exports}); +"use strict";(function(wt,st){var Ot=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],st);else if(typeof module=="object"&&module.exports)module.exports=st();else{var ot=st(),Tt=Ot?exports:wt;for(var yt in ot)Tt[yt]=ot[yt]}})(typeof self<"u"?self:exports,()=>{var wt={},st={exports:wt},Ot=Object.create,ot=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyNames,Me=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty,Ie=(t,e)=>function(){return e||(0,t[yt(t)[0]])((e={exports:{}}).exports,e),e.exports},Wt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},Xt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of yt(e))!_e.call(t,s)&&s!==r&&ot(t,s,{get:()=>e[s],enumerable:!(i=Tt(e,s))||i.enumerable});return t},mt=(t,e,r)=>(r=t!=null?Ot(Me(t)):{},Xt(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),Se=t=>Xt(ot({},"__esModule",{value:!0}),t),K=(t,e,r,i)=>{for(var s=i>1?void 0:i?Tt(e,r):e,a=t.length-1,l;a>=0;a--)(l=t[a])&&(s=(i?l(e,r,s):l(s))||s);return i&&s&&ot(e,r,s),s},gt=Ie({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),s=a(e);typeof i.Reflect<"u"&&(s=a(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function a(d,I){return function(E,L){Object.defineProperty(d,E,{configurable:!0,writable:!0,value:L}),I&&I(E,L)}}function l(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return l()||g()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",l=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!m&&!d,E={create:m?function(){return zt(Object.create(null))}:d?function(){return zt({__proto__:null})}:function(){return zt({})},has:I?function(u,f){return s.call(u,f)}:function(u,f){return f in u},get:I?function(u,f){return s.call(u,f)?u[f]:void 0}:function(u,f){return u[f]}},L=Object.getPrototypeOf(Function),P=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:or(),R=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:ur(),y=typeof WeakMap=="function"?WeakMap:lr(),x=a?Symbol.for("@reflect-metadata:registry"):void 0,U=nr(),H=sr(U);function o(u,f,c,w){if(k(c)){if(!me(u))throw new TypeError;if(!ge(f))throw new TypeError;return Q(u,f)}else{if(!me(u))throw new TypeError;if(!$(f))throw new TypeError;if(!$(w)&&!k(w)&&!Nt(w))throw new TypeError;return Nt(w)&&(w=void 0),c=at(c),it(u,f,c,w)}}r("decorate",o);function N(u,f){function c(w,q){if(!$(w))throw new TypeError;if(!k(q)&&!rr(q))throw new TypeError;Ft(u,f,w,q)}return c}r("metadata",N);function p(u,f,c,w){if(!$(c))throw new TypeError;return k(w)||(w=at(w)),Ft(u,f,c,w)}r("defineMetadata",p);function v(u,f,c){if(!$(f))throw new TypeError;return k(c)||(c=at(c)),X(u,f,c)}r("hasMetadata",v);function S(u,f,c){if(!$(f))throw new TypeError;return k(c)||(c=at(c)),tt(u,f,c)}r("hasOwnMetadata",S);function F(u,f,c){if(!$(f))throw new TypeError;return k(c)||(c=at(c)),et(u,f,c)}r("getMetadata",F);function O(u,f,c){if(!$(f))throw new TypeError;return k(c)||(c=at(c)),ht(u,f,c)}r("getOwnMetadata",O);function j(u,f){if(!$(u))throw new TypeError;return k(f)||(f=at(f)),At(u,f)}r("getMetadataKeys",j);function V(u,f){if(!$(u))throw new TypeError;return k(f)||(f=at(f)),Ct(u,f)}r("getOwnMetadataKeys",V);function Z(u,f,c){if(!$(f))throw new TypeError;if(k(c)||(c=at(c)),!$(f))throw new TypeError;k(c)||(c=at(c));var w=St(f,c,!1);return k(w)?!1:w.OrdinaryDeleteMetadata(u,f,c)}r("deleteMetadata",Z);function Q(u,f){for(var c=u.length-1;c>=0;--c){var w=u[c],q=w(f);if(!k(q)&&!Nt(q)){if(!ge(q))throw new TypeError;f=q}}return f}function it(u,f,c,w){for(var q=u.length-1;q>=0;--q){var z=u[q],W=z(f,c,w);if(!k(W)&&!Nt(W)){if(!$(W))throw new TypeError;w=W}}return w}function X(u,f,c){var w=tt(u,f,c);if(w)return!0;var q=$t(f);return Nt(q)?!1:X(u,q,c)}function tt(u,f,c){var w=St(f,c,!1);return k(w)?!1:ce(w.OrdinaryHasOwnMetadata(u,f,c))}function et(u,f,c){var w=tt(u,f,c);if(w)return ht(u,f,c);var q=$t(f);if(!Nt(q))return et(u,q,c)}function ht(u,f,c){var w=St(f,c,!1);if(!k(w))return w.OrdinaryGetOwnMetadata(u,f,c)}function Ft(u,f,c,w){var q=St(c,w,!0);q.OrdinaryDefineOwnMetadata(u,f,c,w)}function At(u,f){var c=Ct(u,f),w=$t(u);if(w===null)return c;var q=At(w,f);if(q.length<=0)return c;if(c.length<=0)return q;for(var z=new R,W=[],B=0,M=c;B=0&&M=this._keys.length?(this._index=-1,this._keys=f,this._values=f):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},B.prototype.throw=function(M){throw this._index>=0&&(this._index=-1,this._keys=f,this._values=f),M},B.prototype.return=function(M){return this._index>=0&&(this._index=-1,this._keys=f,this._values=f),{value:M,done:!0}},B}(),w=function(){function B(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(B.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),B.prototype.has=function(M){return this._find(M,!1)>=0},B.prototype.get=function(M){var _=this._find(M,!1);return _>=0?this._values[_]:void 0},B.prototype.set=function(M,_){var T=this._find(M,!0);return this._values[T]=_,this},B.prototype.delete=function(M){var _=this._find(M,!1);if(_>=0){for(var T=this._keys.length,A=_+1;AXe}),st.exports=Se(Qt);var cr=mt(gt()),Jt={};Wt(Jt,{Attribute:()=>Zt,AttributeStatic:()=>He,Boost:()=>Ut,BoostObject:()=>pt,Currency:()=>It,CurrencyStatic:()=>De,DEFAULT_ITERATIONS:()=>Et,Decimal:()=>n,E:()=>We,FORMATS:()=>Ze,FormatTypeList:()=>Ee,Grid:()=>fe,GridCell:()=>le,GridCellCollection:()=>J,Item:()=>ue,ItemData:()=>_t,LRUCache:()=>qt,ListNode:()=>Kt,ST_NAMES:()=>ut,UpgradeData:()=>Mt,UpgradeStatic:()=>Rt,calculateItem:()=>oe,calculateSum:()=>jt,calculateSumApprox:()=>ne,calculateSumLoop:()=>ie,calculateUpgrade:()=>se,decimalToJSONString:()=>ae,equalsTolerance:()=>Bt,formats:()=>ft,inverseFunctionApprox:()=>Gt,roundingBase:()=>$e,upgradeToCacheNameEL:()=>ze});var mr=mt(gt()),qt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new Kt(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},Kt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},rt;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(rt||(rt={}));var Oe=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?i===rt.CLASS_TO_CLASS||i===rt.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===rt.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),s=this._exposeMetadatas.get(e),a=s&&s.get(void 0);return i&&a||!i&&!a?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===rt.CLASS_TO_CLASS||r===rt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===rt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===rt.CLASS_TO_CLASS||r===rt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===rt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(E){return E.propertyName!==void 0}));for(var a=[],l=0,g=this.getAncestors(r);lNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let F=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(3)){let V=[];for(let Z=0;ZNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let F=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(2)){let V=[];for(let Z=0;Z118?e.elemental.beyondOg(S):e.elemental.config.element_lists[o-1][v]},beyondOg(o){let N=Math.floor(Math.log10(o)),p=["n","u","b","t","q","p","h","s","o","e"],v="";for(let S=N;S>=0;S--){let F=Math.floor(o/Math.pow(10,S))%10;v==""?v=p[F].toUpperCase():v+=p[F]}return v},abbreviationLength(o){return o==1?1:Math.pow(Math.floor(o/2)+1,2)*2},getAbbreviationAndValue(o){let N=o.log(118).toNumber(),p=Math.floor(N)+1,v=e.elemental.abbreviationLength(p),S=N-p+1,F=Math.floor(S*v),O=e.elemental.getAbbreviation(p,S),j=new t(118).pow(p+F/v-1);return[O,j]},formatElementalPart(o,N){return N.eq(1)?o:`${N.toString()} ${o}`},format(o,N=2){if(o.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(o.log10(),N);let p=o.log(118),S=p.log(118).log(118).toNumber(),F=Math.max(4-S*2,1),O=[];for(;p.gte(1)&&O.length=F)return O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ");let j=new t(118).pow(p).toFixed(O.length===1?3:N);return O.length===0?j:O.length===1?`${j} \xD7 ${e.elemental.formatElementalPart(O[0][0],O[0][1])}`:`${j} \xD7 (${O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ")})`}},old_sc:{format(o,N){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(t.dTen.pow(p));return(p.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(o,N=2){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.eng.format(S.floor(),0)}let v=o.div(new t(1e3).pow(p.div(3).floor()));return(p.log10().gte(9)?"":v.toFixed(new t(4).sub(p.sub(p.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(p.div(3).floor().mul(3),0)}}},mixed_sc:{format(o,N,p=9){o=new t(o);let v=o.log10().floor();return v.lt(303)&&v.gte(p)?m(o,N,p,"st"):m(o,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(o,N=2,p){o=new t(o);let v=o.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return m(o,N,p,"sc");o=t.dTen.pow(o.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let S=v.div(10).floor(),F=v.toNumber()%10-1;return m(o,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+m(S,0,p,"sc"):"")+"-":"")+(isNaN(F)?"nanity":e.layer.layers[F])}},standard:{tier1(o){return ut[0][0][o%10]+ut[0][1][Math.floor(o/10)%10]+ut[0][2][Math.floor(o/100)]},tier2(o){let N=o%10,p=Math.floor(o/10)%10,v=Math.floor(o/100)%10,S="";return o<10?ut[1][0][o]:(p==1&&N==0?S+="Vec":S+=ut[1][1][N]+ut[1][2][p],S+=ut[1][3][v],S)}},inf:{format(o,N,p){o=new t(o);let v=0,S=new t(Number.MAX_VALUE),F=["","\u221E","\u03A9","\u03A8","\u028A"],O=["","","m","mm","mmm"];for(;o.gte(S);)o=o.log(S),v++;return v==0?m(o,N,p,"sc"):o.gte(3)?O[v]+F[v]+"\u03C9^"+m(o.sub(1),N,p,"sc"):o.gte(2)?O[v]+"\u03C9"+F[v]+"-"+m(S.pow(o.sub(2)),N,p,"sc"):O[v]+F[v]+"-"+m(S.pow(o.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(o,N=new t(1e15),p=!1,v=9){if(o=new t(o),N=new t(N).div(1e3),o.lt(N.mul(1e3)))return"";let{alphabet:S}=e.alphabet.config,F=S.length,O=o.log(1e3).sub(N.log(1e3)).floor(),j=O.add(1).log(F+1).ceil(),V="",Z=(Q,it)=>{let X=Q,tt="";for(let et=0;et=F)return"\u03C9";tt=S[ht]+tt,X=X.sub(1).div(F).floor()}return tt};if(j.lt(v))V=Z(O,j);else{let Q=j.sub(v).add(1),it=O.div(t.pow(F+1,Q.sub(1))).floor();V=`${Z(it,new t(v))}(${Q.gt("1e9")?Q.format():Q.format(0)})`}return V},format(o,N=2,p=9,v="mixed_sc",S=new t(1e15),F=!1,O){if(o=new t(o),S=new t(S).div(1e3),o.lt(S.mul(1e3)))return m(o,N,p,v);let j=e.alphabet.getAbbreviation(o,S,F,O),V=o.div(t.pow(1e3,o.log(1e3).floor()));return`${j.length>(O??9)+2?"":V.toFixed(N)+" "}${j}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",s="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function a(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":i[parseInt(N,10)]).join("")}function l(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function g(o,N=2,p=9,v="st"){return m(o,N,p,v)}function m(o,N=2,p=9,v="mixed_sc"){o=new t(o);let S=o.lt(0)?"-":"";if(o.mag==1/0)return S+"Infinity";if(Number.isNaN(o.mag))return S+"NaN";if(o.lt(0)&&(o=o.mul(-1)),o.eq(0))return o.toFixed(N);let F=o.log10().floor();switch(v){case"sc":case"scientific":if(o.log10().lt(Math.min(-N,0))&&N>1){let O=o.log10().ceil(),j=o.div(O.eq(-1)?new t(.1):t.dTen.pow(O)),V=O.mul(-1).max(1).log10().gte(9);return S+(V?"":j.toFixed(2))+"e"+m(O,0,p,"mixed_sc")}else if(F.lt(p)){let O=Math.max(Math.min(N-F.toNumber(),N),0);return S+(O>0?o.toFixed(O):o.toFixed(O).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(o.gte("eeee10")){let V=o.slog();return(V.gte(1e9)?"":t.dTen.pow(V.sub(V.floor())).toFixed(2))+"F"+m(V.floor(),0)}let O=o.div(t.dTen.pow(F)),j=F.log10().gte(9);return S+(j?"":O.toFixed(2))+"e"+m(F,0,p,"mixed_sc")}case"st":case"standard":{let O=o.log(1e3).floor();if(O.lt(1))return S+o.toFixed(Math.max(Math.min(N-F.toNumber(),N),0));let j=O.mul(3),V=O.log10().floor();if(V.gte(3e3))return"e"+m(F,N,p,"st");let Z="";if(O.lt(4))Z=["","K","M","B"][Math.round(O.toNumber())];else{let X=Math.floor(O.log(1e3).toNumber());for(X<100&&(X=Math.max(X-1,0)),O=O.sub(1).div(t.dTen.pow(X*3));O.gt(0);){let tt=O.div(1e3).floor(),et=O.sub(tt.mul(1e3)).floor().toNumber();et>0&&(et==1&&!X&&(Z="U"),X&&(Z=e.standard.tier2(X)+(Z?"-"+Z:"")),et>1&&(Z=e.standard.tier1(et)+Z)),O=tt,X++}}let Q=o.div(t.dTen.pow(j)),it=N===2?t.dTwo.sub(F.sub(j)).add(1).toNumber():N;return S+(V.gte(10)?"":Q.toFixed(it)+" ")+Z}default:return e[v]||console.error('Invalid format type "',v,'"'),S+e[v].format(o,N,p)}}function d(o,N,p="mixed_sc",v,S){o=new t(o),N=new t(N);let F=o.add(N),O,j=F.div(o);return j.gte(10)&&o.gte(1e100)?(j=j.log10().mul(20),O="(+"+m(j,v,S,p)+" OoMs/sec)"):O="(+"+m(N,v,S,p)+"/sec)",O}function I(o,N=2,p="s"){return o=new t(o),o.gte(86400)?m(o.div(86400).floor(),0,12,"sc")+":"+I(o.mod(86400),N,"d"):o.gte(3600)||p=="d"?(o.div(3600).gte(10)||p!="d"?"":"0")+m(o.div(3600).floor(),0,12,"sc")+":"+I(o.mod(3600),N,"h"):o.gte(60)||p=="h"?(o.div(60).gte(10)||p!="h"?"":"0")+m(o.div(60).floor(),0,12,"sc")+":"+I(o.mod(60),N,"m"):(o.gte(10)||p!="m"?"":"0")+m(o,N,12,"sc")}function E(o,N=!1,p=0,v=9,S="mixed_sc"){let F=Ct=>m(Ct,p,v,S);o=new t(o);let O=o.mul(1e3).mod(1e3).floor(),j=o.mod(60).floor(),V=o.div(60).mod(60).floor(),Z=o.div(3600).mod(24).floor(),Q=o.div(86400).mod(365.2425).floor(),it=o.div(31556952).floor(),X=it.eq(1)?" year":" years",tt=Q.eq(1)?" day":" days",et=Z.eq(1)?" hour":" hours",ht=V.eq(1)?" minute":" minutes",Ft=j.eq(1)?" second":" seconds",At=O.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?F(it)+X+", ":""}${Q.gt(0)?F(Q)+tt+", ":""}${Z.gt(0)?F(Z)+et+", ":""}${V.gt(0)?F(V)+ht+", ":""}${j.gt(0)?F(j)+Ft+",":""}${N&&O.gt(0)?" "+F(O)+At:""}`.replace(/,([^,]*)$/,"$1").trim()}function L(o){return o=new t(o),m(t.dOne.sub(o).mul(100))+"%"}function P(o){return o=new t(o),m(o.mul(100))+"%"}function R(o,N=2){return o=new t(o),o.gte(1)?"\xD7"+o.format(N):"/"+o.pow(-1).format(N)}function y(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function x(o,N=0){o=new t(o);let p=(O=>O.map((j,V)=>({name:j.name,altName:j.altName,value:t.pow(1e3,new t(V).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),v="",S=o.lte(0)?0:t.min(t.log(o,1e3).sub(1),p.length-1).floor().toNumber(),F=p[S];if(S===0)switch(N){case 1:v="";break;case 2:case 0:default:v=o.format();break}switch(N){case 1:v=F.name;break;case 2:v=o.divide(F.value).format();break;case 3:v=F.altName;break;case 0:default:v=`${o.divide(F.value).format()} ${F.name}`;break}return v}function U(o,N=!1){return`${x(o,2)} ${x(o,1)}eV${N?"/c^2":""}`}let H={...e,toSubscript:a,toSuperscript:l,formatST:g,format:m,formatGain:d,formatTime:I,formatTimeLong:E,formatReduction:L,formatPercent:P,formatMult:R,expMult:y,metric:x,ev:U};return{FORMATS:e,formats:H}}var xt=17,Ae=9e15,Ce=Math.log10(9e15),qe=1/9e15,Pe=308,xe=-324,te=5,ke=1023,Le=!0,Ue=!1,Ve=function(){let t=[];for(let r=xe+1;r<=Pe;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ct=[2,Math.E,3,4,5,6,7,8,9,10],Be=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],Ge=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],h=function(e){return n.fromValue_noAlloc(e)},C=function(t,e,r){return n.fromComponents(t,e,r)},b=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},lt=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),a=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(a.toFixed(Math.max(i-s,0)))},kt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},je=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,s=t;return r=r+1/(12*s),s=s*i,r=r-1/(360*s),s=s*i,r=r+1/(1260*s),s=s*i,r=r-1/(1680*s),s=s*i,r=r+1/(1188*s),s=s*i,r=r-691/(360360*s),s=s*i,r=r+7/(1092*s),s=s*i,r=r-3617/(122400*s),Math.exp(r)/e},Re=.36787944117144233,ee=.5671432904097838,Lt=function(t,e=1e-10,r=!0){let i,s;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ee;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let a=0;a<100;++a){if(s=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(s-i).5?1:-1;if(Math.random()*20<1)return b(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let s=Math.pow(10,i);return Math.random()>.9&&(s=Math.trunc(s)),C(e,r,s)}static affordGeometricSeries_core(t,e,r,i){let s=e.mul(r.pow(i));return n.floor(t.div(s).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(n.sub(1,r.pow(t))).div(n.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r)).sub(r.div(2)),l=a.pow(2);return a.neg().add(l.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=Ae)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=n.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Le?t=t.replace(",",""):Ue&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let y=parseFloat(s[0]),x=parseFloat(s[1]),U=s[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(y)&&isFinite(x)){let o=n.pentate(y,x,H,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let a=t.split("^^");if(a.length===2){let y=parseFloat(a[0]),x=parseFloat(a[1]),U=a[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(y)&&isFinite(x)){let o=n.tetrate(y,x,H,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let l=t.split("^");if(l.length===2){let y=parseFloat(l[0]),x=parseFloat(l[1]);if(isFinite(y)&&isFinite(x)){let U=n.pow(y,x);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,m,d=t.split("pt");if(d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),y&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),y&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,x,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),y&&(this.sign*=-1),this}}let I=t.split("e"),E=I.length-1;if(E===0){let y=parseFloat(t);if(isFinite(y))return this.fromNumber(y),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(E===1){let y=parseFloat(t);if(isFinite(y)&&y!==0)return this.fromNumber(y),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let L=t.split("e^");if(L.length===2){this.sign=1,L[0].startsWith("-")&&(this.sign=-1);let y="";for(let x=0;x=43&&U<=57||U===101)y+=L[1].charAt(x);else return this.layer=parseFloat(y),this.mag=parseFloat(L[1].substr(x+1)),this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}if(E<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let P=parseFloat(I[0]);if(P===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let R=parseFloat(I[I.length-1]);if(E>=2){let y=parseFloat(I[I.length-2]);isFinite(y)&&(R*=Math.sign(y),R+=kt(y))}if(!isFinite(P))this.sign=I[0]==="-"?-1:1,this.layer=E,this.mag=R;else if(E===1)this.sign=Math.sign(P),this.layer=1,this.mag=R+Math.log10(Math.abs(P));else if(this.sign=Math.sign(P),this.layer=E,E===2){let y=n.mul(C(1,2,R),h(P));return this.sign=y.sign,this.layer=y.layer,this.mag=y.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=R;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:lt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:lt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=te?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):lt(this.m,t)+"e"+lt(this.e,t):this.layer===1?lt(this.m,t)+"e"+lt(this.e,t):this.layer<=te?(this.sign===-1?"-":"")+"e".repeat(this.layer)+lt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+lt(this.mag,t)}abs(){return b(this.sign===0?0:1,this.layer,this.mag)}neg(){return b(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?b(-1,0,1):b(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?C(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?b(1,0,1):b(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?C(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=h(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return b(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),a=i.layer*Math.sign(i.mag);if(s-a>=2)return r;if(s===0&&a===-1){if(Math.abs(i.mag-Math.log10(r.mag))>xt)return r;{let l=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*l;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>xt)return r;{let l=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*l;return C(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>xt)return r;{let l=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*l;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(h(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=h(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return b(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return b(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return C(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return C(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return C(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=h(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?b(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?b(0,0,0):this.layer===0?C(this.sign,0,1/this.mag):C(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=h(t).abs();if(e.eq(n.dZero))return b(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new n(r%i):this.sub(e).eq(this)?b(0,0,0):e.sub(this).eq(e)?new n(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=h(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=h(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=h(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=kt(s)),this.layer0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer>0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(this.sign,0,Math.log10(this.mag))}log(t){return t=h(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?C(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log2(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=h(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?b(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return b(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:b(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return b(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return b(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return C(1,0,e);if(t.sign===0)return b(1,0,1);t=b(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?C(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?C(-t.sign,t.layer+1,-t.mag):b(1,0,1)}pow_base(t){return h(t).pow(this)}root(t){let e=h(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(b(1,0,24)))return n.fromNumber(je(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,s=12*i,a=1/s,l=e+a;if(l===e||(e=l,i=i*r,s=360*i,a=1/s,l=e-a,l===e))return n.exp(e);e=l,i=i*r,s=1260*i;let g=1/s;return e=e+g,i=i*r,s=1680*i,g=1/s,e=e-g,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?b(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?C(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?C(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):C(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return C(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(b(this.sign,this.layer-1,this.mag),b(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=b(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return b(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let a=this.toNumber();if(a<=1.444667861009766&&a>=.06598803584531254){let l=n.ln(this).neg(),g=l.lambertw().div(l);if(a<1)return g;let m=l.lambertw(!1).div(l);return a>1.444667861009099&&(g=m=n.fromNumber(Math.E)),e=h(e),e.eq(m)?m:e.lt(m)?g:b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return a>1.444667861009766?b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let a=Math.abs((t+1)%2);return a>1&&(a=2-a),n.fromNumber(a)}if(t<0)return n.iteratedlog(e,this,-t,r);e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;if(this.gt(n.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(n.ln(this).neg().lambertw(!1).div(n.ln(this).neg())))&&(i>1e4||!r)){let a=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let l=0;l1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let a=0;a3)return b(e.sign,e.layer+(t-a-1),e.mag);if(a>1e4)return e}return e}iteratedexp(t=2,e=b(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=h(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let a=s-e;if(i.layer-t.layer>3){let l=Math.min(e,i.layer-t.layer-3);e-=l,i.layer-=l}for(let l=0;l1e4)return i}return a>0&&a<1&&(t.eq(10)?i=i.layeradd10(-a,r):i=i.layeradd(-a,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,s=!1,a=!1,l=this.slog_internal(t,r).toNumber();for(let g=1;g1&&a!=d&&(s=!0),a=d,s?i/=2:i*=2,i=Math.abs(i)*(d?-1:1),l+=i,i===0)break}return n.fromNumber(l)}slog_internal(t=10,e=!1){if(t=h(t),t.lte(n.dZero)||t.eq(n.dOne))return b(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?b(0,0,0):this.eq(n.dZero)?b(-1,0,1):b(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return b(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),a=s.lambertw().div(s);if(this.eq(a))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(a))return b(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=n.fromDecimal(this);if(i.layer-t.layer>3){let s=i.layer-t.layer-3;r+=s,i.layer-=s}for(let s=0;s<100;++s)if(i.lt(n.dZero))i=n.pow(t,i),r-=1;else{if(i.lte(n.dOne))return e?n.fromNumber(r+i.toNumber()-1):n.fromNumber(r+n.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=n.log(i,t)}return n.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:n.critical_section(t,e,Ge)}static tetrate_critical(t,e){return n.critical_section(t,e,Be)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let s=0,a=0;for(let g=0;gt){let m=(t-ct[g])/(ct[g+1]-ct[g]);s=r[g][Math.floor(e)]*(1-m)+r[g+1][Math.floor(e)]*m,a=r[g][Math.ceil(e)]*(1-m)+r[g+1][Math.ceil(e)]*m;break}let l=e-Math.floor(e);return s<=0||a<=0?s*(1-l)+a*l:Math.pow(t,Math.log(s)/Math.log(t)*(1-l)+Math.log(a)/Math.log(t)*l)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=h(e);if(i.gt(1)&&i.lte(1.444667861009766)){let l=n.excess_slog(this,e,r),g=l[0].toNumber(),m=l[1],d=g+t,I=n.ln(e).neg(),E=I.lambertw().div(I),L=I.lambertw(!1).div(I),P=n.dOne;m==1?P=E.mul(L).sqrt():m==2&&(P=L.mul(2));let R=i.pow(P),y=Math.floor(d),x=d-y,U=P.pow(1-x).mul(R.pow(x));return n.tetrate(i,y,U,r)}let a=this.slog(e,100,r).toNumber()+t;return a>=0?n.tetrate(e,a,n.dOne,r):Number.isFinite(a)?a>=-1?n.log(n.tetrate(e,a+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,a+2,n.dOne,r),e),e):b(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=h(t),e=h(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[b(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),a=s.lambertw().div(s),l=n.dInf;if(e>1&&(l=s.lambertw(!1).div(s)),e>1.444667861009099&&(a=l=n.fromNumber(Math.E)),t.lt(a))return[t.slog(e,100,r),0];if(t.eq(a))return[b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(l))return[b(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(l)){let g=l.mul(2),m=i.pow(g),d=0;if(t.gte(g)&&t.lt(m))d=0;else if(t.gte(m)){let y=m;for(d=1;y.lt(t);)if(y=i.pow(y),d=d+1,y.layer>3){let x=Math.floor(t.layer-y.layer+1);y=i.iteratedexp(x,y,r),d=d+x}y.gt(t)&&(y=y.log(e),d=d-1)}else if(t.lt(g)){let y=g;for(d=0;y.gt(t);)y=y.log(e),d=d-1}let I=0,E=0,L=.5,P=g,R=n.dZero;for(;L>1e-16;){if(E=I+L,P=g.pow(1-E).mul(m.pow(E)),R=n.iteratedexp(e,d,P),R.eq(t))return[new n(d+E),2];R.lt(t)&&(I+=L),L/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),2]}if(t.lt(l)&&t.gt(a)){let g=a.mul(l).sqrt(),m=i.pow(g),d=0;if(t.lte(g)&&t.gt(m))d=0;else if(t.lte(m)){let y=m;for(d=1;y.gt(t);)y=i.pow(y),d=d+1;y.lt(t)&&(y=y.log(e),d=d-1)}else if(t.gt(g)){let y=g;for(d=0;y.lt(t);)y=y.log(e),d=d-1}let I=0,E=0,L=.5,P=g,R=n.dZero;for(;L>1e-16;){if(E=I+L,P=g.pow(1-E).mul(m.pow(E)),R=n.iteratedexp(e,d,P),R.eq(t))return[new n(d+E),1];R.gt(t)&&(I+=L),L/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?b(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new n(this):this.mag<0?n.fromNumber(Lt(this.toNumber())):this.layer===0?n.fromNumber(Lt(this.sign*this.mag)):this.lt("eee15")?re(this):this.ln():this.sign===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?n.fromNumber(Lt(this.sign*this.mag,1e-10,!1)):this.layer==1?re(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return b(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return n.fromNumber(t).add(2).pow(this.recip());if(t<=0)return b(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eRe?this.pow(this.recip()):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return b(1,0,1);if(this.lt(0))return b(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new n(this):b(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=n.dTen;this.gte(n.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=n.dZero,i=e.layer,s=e.iteratedlog(10,i,!0),a=s,l=s.div(2),g=!0;for(;g;)l=r.add(s).div(2),n.iteratedexp(10,i,l,!0).tetrate(t,1,!0).gt(this)?s=l:r=l,l.eq(a)?g=!1:a=l;return n.iteratedexp(10,i,l,!0)}else{let e=1,r=C(1,10,1),i=C(1,10,1),s=C(1,10,1),a=C(1,1,-16),l=n.dZero,g=C(1,10,1),m=a.pow10().recip(),d=n.dZero,I=m,E=m,L=Math.ceil(t)%2==0,P=0,R=C(1,10,1),y=!1,x=n.dZero,U=!1;for(;e<4;){if(e==2){if(L)break;s=C(1,10,1),a=r,e=3,g=C(1,10,1),R=C(1,10,1)}for(y=!1;a.neq(s);){if(x=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),E=a.pow10().recip(),d=n.dZero,P=-1,e==3&&(R=a);else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip())&&!L&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),E=a.pow10().recip(),d=n.dZero,P=0;else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip().mul(2).tetrate(t,1,!0)))m=a.pow10().recip(),I=n.dZero,E=m.mul(2),d=m,L?P=-1:P=0;else{for(l=a.mul(12e-17),m=a.pow10().recip(),I=a.add(l).pow10().recip(),d=m.sub(I),E=m.add(d);I.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||E.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||I.gte(m)||E.lte(m);)l=l.mul(2),I=a.add(l).pow10().recip(),d=m.sub(I),E=m.add(d);if((e==1&&E.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&E.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(R=a),E.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))P=-1;else if(L)P=1;else if(e==3&&a.gt_tolerance(r,1e-8))P=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||E.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||I.gte(m)||E.lte(m);)l=l.mul(2),I=a.add(l).pow10().recip(),d=m.sub(I),E=m.add(d);E.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?P=0:P=1}}if(P==-1&&(U=!0),e==1&&P==1||e==3&&P!=0)if(s.eq(C(1,10,1)))a=a.mul(2);else{let p=!1;if(y&&(P==1&&e==1||P==-1&&e==3)&&(p=!0),a=a.add(s).div(2),p)break}else if(s.eq(C(1,10,1)))s=a,a=a.div(2);else{let p=!1;if(y&&(P==1&&e==1||P==-1&&e==3)&&(p=!0),s=s.sub(g),a=a.sub(g),p)break}if(s.sub(a).div(2).abs().gt(g.mul(1.5))&&(y=!0),g=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(x))break}if(a.gt("1e18")||!U||R==C(1,10,1))break;e==1?r=R:e==3&&(i=R),e++}s=r,a=C(1,1,-18);let H=a,o=n.dZero,N=!0;for(;N;)if(s.eq(C(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(H)?N=!1:H=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);if(o.eq_tolerance(r,1e-15)){if(i.eq(C(1,10,1)))return b(Number.NaN,Number.NaN,Number.NaN);for(s=C(1,10,1),a=i,H=a,o=n.dZero,N=!0;N;)if(s.eq(C(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(H)?N=!1:H=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);return o.pow10().recip()}else return o.pow10().recip()}}pentate(t=2,e=b(1,0,1),r=!1){e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;s!==0&&(e.eq(n.dOne)?(++t,e=n.fromNumber(s)):this.eq(10)?e=e.layeradd10(s,r):e=e.layeradd(s,this,r));for(let a=0;a10)return e}return e}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):b(0,0,0)}cos(){return this.mag<0?b(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):b(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):b(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?b(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return ft.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return ft.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return ft.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return ft.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return ft.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return ft.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let a of Object.keys(i)){let l=Math.floor(r/i[a]);r-=l*i[a],s+=a.repeat(l)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=b(0,0,0),n.dOne=b(1,0,1),n.dNegOne=b(-1,0,1),n.dTwo=b(1,0,2),n.dTen=b(1,0,10),n.dNaN=b(Number.NaN,Number.NaN,Number.NaN),n.dInf=b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=C(1,0,Number.MAX_VALUE),n.dNumberMin=C(1,0,Number.MIN_VALUE),n.fromStringCache=new qt(ke),K([vt()],n.prototype,"sign",2),K([vt()],n.prototype,"mag",2),K([vt()],n.prototype,"layer",2),n=K([Te()],n);var{formats:ft,FORMATS:Ze}=Fe(n);n.formats=ft;var pt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Ut=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new n(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new pt(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sE),d=s,I=this.getBoosts(a,!0);I[0][0]?this.boostArray[I[1][0]]=new pt({id:a,name:l,description:g,value:m,order:d}):this.boostArray.push(new pt({id:a,name:l,description:g,value:m,order:d}))}else{t=Array.isArray(t)?t:[t];for(let a of t){let l=this.getBoosts(a.id,!0);l[0][0]?this.boostArray[l[1][0]]=new pt(a):this.boostArray.push(new pt(a))}}}calculate(t=this.baseEffect){let e=new n(t),r=this.boostArray;r=r.sort((i,s)=>i.order-s.order);for(let i of r)e=i.value(e);return e}},gr=mt(gt()),Et=30,Vt=.001;function Ye(t,e,r="geometric"){switch(t=new n(t),e=new n(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return n.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Bt(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new n(t),e=new n(e),r=new n(r);let s,a;return i.mode==="geometric"?(s=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),a=s.lte(r)):(s=t.sub(e).abs(),a=s.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!a)&&console.log({a:t,b:e,tolerance:r,config:i,diff:s,result:a}),a}function Gt(t,e,r="geometric",i=Et,s=Vt){let a=n.dOne,l=new n(e);if(t(l).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(l).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:l,lowerBound:l,upperBound:l};for(let m=0;m=0;g--){let m=r.add(l.mul(g)),d=r.add(l.mul(g+1)),I=a;if(a=a.add(t(m).add(t(d)).div(2).mul(l)),Bt(I,a,s,{verbose:!1,mode:"geometric"}))break}return a}function jt(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(Et)?ie(t,e,r,i):ne(t,e,r,s)}function $e(t,e=10,r=0,i=1e3){if(t=new n(t),t.gte(n.pow(e,i)))return t;let s=n.floor(n.log(t,e)),a=t.div(n.pow(e,s));return a=a.mul(n.pow(e,r)).round(),a=a.div(n.pow(e,r)),a=a.mul(n.pow(e,s)),a}function se(t,e,r,i=n.dInf,s,a,l=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[n.dZero,n.dZero];if(l=(typeof e.el=="function"?e.el():e.el)??l,g.eq(1)){let E=e.cost(e.level),L=t.gte(E),P=[n.dZero,n.dZero];return l?(P[0]=L?n.dOne:n.dZero,P):(P=[L?n.dOne:n.dZero,L?E:n.dZero],P)}if(e.costBulk){let[E,L]=e.costBulk(t,e.level,g),P=t.gte(L);return[P?E:n.dZero,P&&!l?L:n.dZero]}if(l){let E=R=>e.cost(R.add(r)),L=n.min(i,Gt(E,t,s,a).value.floor()),P=n.dZero;return[L,P]}let m=Gt(E=>jt(e.cost,E,r),t,s,a).value.floor().min(r.add(g).sub(1)),d=jt(e.cost,m,r);return[m.sub(r).add(1).max(0),d]}function ae(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function ze(t){return`el/${ae(t)}`}var Mt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};K([vt()],Mt.prototype,"id",2),K([dt(()=>n)],Mt.prototype,"level",2);var Rt=class ve{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:n.dOne}}).data??{level:n.dOne}).level}set level(e){this.data.level=new n(e)}constructor(e,r,i,s){let a=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>a,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new qt(s??ve.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??n.dOne}},dr=mt(gt());function oe(t,e,r=n.dInf){if(t=new n(t),r=new n(r),r.lt(0))return console.warn("calculateItem: Invalid target: ",r),[n.dZero,n.dZero];if(r.eq(1)){let a=e.cost();return[t.gte(a)?n.dOne:n.dZero,t.gte(a)?a:n.dZero]}let i=t.div(e.cost()).floor().min(r),s=e.cost().mul(i);return[i,s]}var ue=class{constructor(t,e,r){this.defaultAmount=n.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??n.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:n.dOne}}).data??{amount:n.dOne}).amount}set amount(t){this.data.amount=new n(t)}},_t=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??n.dZero}};K([vt()],_t.prototype,"id",2),K([dt(()=>n)],_t.prototype,"amount",2);var pr=mt(gt()),It=class{constructor(){this.value=n.dZero,this.upgrades={},this.items={}}};K([dt(()=>n)],It.prototype,"value",2),K([dt(()=>Mt)],It.prototype,"upgrades",2),K([dt(()=>_t)],It.prototype,"items",2);var De=class{constructor(t=new It,e,r={defaultVal:n.dZero,defaultBoost:n.dOne}){this.items={},this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Ut(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let s of Object.values(this.upgrades))s.level=new n(s.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(s);if(i.resetItemAmounts)for(let s of Object.values(this.items))s.amount=new n(s.defaultAmount),i.runUpgradeEffect&&this.runUpgradeEffect(s)}gain(t=1e3){let e=this.boost.calculate().mul(new n(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Mt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(a=>i.test(a)).map(a=>this.upgrades[a])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let s=new Rt(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(s),this.upgrades[i.id]=s,r.push(s)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t instanceof Rt?t.effect?.(t.level,t,this):t.effect?.(t.amount,t,this)}calculateUpgrade(t,e=1/0,r,i){let s=this.getUpgrade(t);return s===null?(console.warn(`Upgrade "${t}" not found.`),[n.dZero,n.dZero]):(e=s.level.add(e),s.maxLevel!==void 0&&(e=n.min(e,s.maxLevel)),se(this.value,s,s.level,e,r,i))}getNextCost(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(a))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(a[0])).add(a[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[a,l]=this.calculateUpgrade(t,e,r,i);return a.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(l),s.level=s.level.add(a),this.runUpgradeEffect(s),!0)}pointerAddItem(t){let e=new _t(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new ue(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runUpgradeEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e=1/0){let r=this.getItem(t);return r===null?(console.warn(`Item "${t}" not found.`),[n.dZero,n.dZero]):oe(this.value,r,e)}buyItem(t,e){let r=this.getItem(t);if(r===null)return console.warn(`Item "${t}" not found.`),!1;let[i,s]=this.calculateItem(t,e);return i.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(s),r.amount=r.amount.add(i),this.runUpgradeEffect(r),!0)}},Nr=mt(gt()),Zt=class{constructor(t=0){this.value=new n(t)}};K([dt(()=>n)],Zt.prototype,"value",2);var He=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new Zt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Ut(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},le=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=r,this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}direction(t,e=1,r){let i=fe.getInstance(this.gridSymbol);return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}},J=class Dt extends Array{constructor(e){e=Array.isArray(e)?e:[e],super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}direction(e,r,i){if(["up","right","down","left"].includes(e))return new Dt(this.map(a=>a.direction(e,r,i)));let s=[];for(let a of this)s.push(...a.direction(e,r,i));return new Dt(s)}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},fe=class Ht{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),Ht.instances[this.gridSymbol]=this,this.xSize=e,this.ySize=r??e;for(let s=0;s{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new n(r));return Object.getOwnPropertyNames(n).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=n[r]}),e})(),Xe=Jt;if(typeof st.exports=="object"&&typeof wt=="object"){var Qe=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,s)&&s!==r&&Object.defineProperty(t,s,{get:()=>e[s],enumerable:!(i=Object.getOwnPropertyDescriptor(e,s))||i.enumerable});return t};st.exports=Qe(st.exports,wt)}return st.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.mjs b/dist/main/eMath.mjs index b4105b4..f108ebd 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -5841,22 +5841,32 @@ var GridCell = class { * Gets the cell in a specific direction from the current cell. * @param direction - The direction to move. * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - direction(direction, distance = 1) { + direction(direction, distance = 1, fill) { const grid = Grid.getInstance(this.gridSymbol); - switch (direction) { - case "up": - return grid.getCell(this.x, this.y - distance); - case "right": - return grid.getCell(this.x + distance, this.y); - case "down": - return grid.getCell(this.x, this.y + distance); - case "left": - return grid.getCell(this.x - distance, this.y); - default: - throw new Error("Invalid direction"); - } + const out = (() => { + switch (direction) { + case "up": + return grid.getCell(this.x, this.y - distance); + case "right": + return grid.getCell(this.x + distance, this.y); + case "down": + return grid.getCell(this.x, this.y + distance); + case "left": + return grid.getCell(this.x - distance, this.y); + case "adjacent": + return grid.getAdjacent(this.x, this.y, distance, fill); + case "diagonal": + return grid.getDiagonal(this.x, this.y, distance, fill); + case "encircling": + return grid.getEncircling(this.x, this.y, distance, fill); + default: + throw new Error("Invalid direction"); + } + })(); + return out; } /** * Gets the cell to the right of the current cell. Can be chained. @@ -5891,7 +5901,7 @@ var GridCell = class { return this.direction("left", distance); } }; -var GridCellCollection = class extends Array { +var GridCellCollection = class _GridCellCollection extends Array { /** * Initializes a new instance of the grid cell collection. * @param cells - The cells to initialize with. @@ -5899,6 +5909,99 @@ var GridCellCollection = class extends Array { constructor(cells) { cells = Array.isArray(cells) ? cells : [cells]; super(...cells); + this.removeDuplicates(); + } + /** + * Removes duplicate cells from the collection. + * Modifies the array in place. + */ + removeDuplicates() { + const duplicatedIndexes = []; + this.forEach((cell, index) => { + if (this.indexOf(cell) !== index) duplicatedIndexes.push(index); + }); + duplicatedIndexes.forEach((index) => this.splice(index, 1)); + } + // Directions + /** + * Gets the cells in a specific direction from the current cells. + * @param direction - The direction to move. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells in the specified direction. + */ + direction(direction, distance, fill) { + if (["up", "right", "down", "left"].includes(direction)) { + return new _GridCellCollection(this.map((cell) => cell.direction(direction, distance, fill))); + } + const output = []; + for (const cell of this) { + output.push(...cell.direction(direction, distance, fill)); + } + return new _GridCellCollection(output); + } + /** + * Gets the cells above the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells above. + */ + up(distance) { + return this.direction("up", distance); + } + /** + * Gets the cells to the right of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the right. + */ + right(distance) { + return this.direction("right", distance); + } + /** + * Gets the cells below the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells below. + */ + down(distance) { + return this.direction("down", distance); + } + /** + * Gets the cells to the left of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the left. + */ + left(distance) { + return this.direction("left", distance); + } + // Other direction + /** + * Gets the cells adjacent to the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells adjacent. + */ + adjacent(distance, fill) { + return this.direction("adjacent", distance, fill); + } + /** + * Gets the cells diagonally from the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells diagonally. + */ + diagonal(distance, fill) { + return this.direction("diagonal", distance, fill); + } + /** + * Gets the cells encircling the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells encircling. + */ + encircling(distance, fill) { + return this.direction("encircling", distance, fill); } }; var Grid = class _Grid { @@ -5996,40 +6099,116 @@ var Grid = class _Grid { * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. - */ - getAdjacent(x, y) { - return new GridCellCollection([ - this.getCell(x, y + 1), - this.getCell(x + 1, y), - this.getCell(x, y - 1), - this.getCell(x - 1, y) - ]); + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + */ + getAdjacent(x, y, distance = 1, fill = false) { + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x, y + 1), + this.getCell(x + 1, y), + this.getCell(x, y - 1), + this.getCell(x - 1, y) + ]); + } + if (!fill) { + return new GridCellCollection([ + this.getCell(x, y + distance), + this.getCell(x + distance, y), + this.getCell(x, y - distance), + this.getCell(x - distance, y) + ]); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x, y + i)); + output.push(this.getCell(x + i, y)); + output.push(this.getCell(x, y - i)); + output.push(this.getCell(x - i, y)); + } + return new GridCellCollection(output); } /** * Gets an array containing all cells diagonally adjacent from a specific cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the diagonal. Defaults to `false`. + */ + getDiagonal(x, y, distance = 1, fill = false) { + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x - 1, y + 1), + this.getCell(x + 1, y + 1), + this.getCell(x + 1, y - 1), + this.getCell(x - 1, y - 1) + ]); + } + if (!fill) { + return new GridCellCollection([ + this.getCell(x - distance, y + distance), + this.getCell(x + distance, y + distance), + this.getCell(x + distance, y - distance), + this.getCell(x - distance, y - distance) + ]); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x - i, y + i)); + output.push(this.getCell(x + i, y + i)); + output.push(this.getCell(x + i, y - i)); + output.push(this.getCell(x - i, y - i)); + } + return new GridCellCollection(output); + } + /** + * Gets an array containing all cells that surround a cell at a specific distance. + * @param x - The x coordinate to check. + * @param y - The y coordinate to check. + * @param distance - The distance to check. + * @returns - An array of all cells. */ - getDiagonal(x, y) { - return new GridCellCollection([ - this.getCell(x - 1, y + 1), - this.getCell(x + 1, y + 1), - this.getCell(x + 1, y - 1), - this.getCell(x - 1, y - 1) - ]); + getEncirclingAtDistance(x, y, distance) { + if (distance <= 1) { + return new GridCellCollection([ + ...this.getAdjacent(x, y), + ...this.getDiagonal(x, y) + ]); + } + const output = []; + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance + i, y - distance)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance, y - distance + i)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance - i, y + distance)); + } + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance, y + distance - i)); + } + output.push(...this.getDiagonal(x, y, distance, false)); + return new GridCellCollection(output); } /** * Gets an array containing all cells that surround a cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the surrounding cells. Defaults to `false`. */ - getEncircling(x, y) { - return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y) - ]); + getEncircling(x, y, distance = 1, fill = false) { + if (distance === 1 || !fill) { + return this.getEncirclingAtDistance(x, y, distance); + } + const output = []; + for (let i = 1; i <= distance; i++) { + output.push(...this.getEncirclingAtDistance(x, y, i)); + } + return new GridCellCollection(output); } /** * Calculates the distance between two points on the grid. diff --git a/dist/types/classes/Grid.d.ts b/dist/types/classes/Grid.d.ts index 679a7d0..2c17a5a 100644 --- a/dist/types/classes/Grid.d.ts +++ b/dist/types/classes/Grid.d.ts @@ -2,7 +2,8 @@ * @file Declares the gridCell and grid classes. */ import type { UnknownObject } from "../common/types"; -type Directions = "up" | "right" | "down" | "left"; +type DirectionCollection = "adjacent" | "diagonal" | "encircling"; +type Directions = "up" | "right" | "down" | "left" | DirectionCollection; /** * Represents a grid cell with coordinates and properties. * @template P - The type of the properties of the grid cell. @@ -45,9 +46,10 @@ declare class GridCell

{ * Gets the cell in a specific direction from the current cell. * @param direction - The direction to move. * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - direction(direction: Directions, distance?: number): GridCell

; + direction(direction: D, distance?: number, fill?: boolean): D extends DirectionCollection ? GridCellCollection

: GridCell

; /** * Gets the cell to the right of the current cell. Can be chained. * @param distance - The distance to move. Defaults to 1. @@ -83,6 +85,67 @@ declare class GridCellCollection

extends Array * @param cells - The cells to initialize with. */ constructor(cells: GridCell

| GridCell

[]); + /** + * Removes duplicate cells from the collection. + * Modifies the array in place. + */ + removeDuplicates(): void; + /** + * Gets the cells in a specific direction from the current cells. + * @param direction - The direction to move. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells in the specified direction. + */ + direction(direction: Directions, distance?: number, fill?: boolean): GridCellCollection

; + /** + * Gets the cells above the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells above. + */ + up(distance?: number): GridCellCollection

; + /** + * Gets the cells to the right of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the right. + */ + right(distance?: number): GridCellCollection

; + /** + * Gets the cells below the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells below. + */ + down(distance?: number): GridCellCollection

; + /** + * Gets the cells to the left of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the left. + */ + left(distance?: number): GridCellCollection

; + /** + * Gets the cells adjacent to the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells adjacent. + */ + adjacent(distance?: number, fill?: boolean): GridCellCollection

; + /** + * Gets the cells diagonally from the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells diagonally. + */ + diagonal(distance?: number, fill?: boolean): GridCellCollection

; + /** + * Gets the cells encircling the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells encircling. + */ + encircling(distance?: number, fill?: boolean): GridCellCollection

; } /** * Represents a grid with cells. @@ -154,22 +217,36 @@ declare class Grid

{ * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the adjacent cells. Defaults to `false`. */ - getAdjacent(x: number, y: number): GridCellCollection

; + getAdjacent(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

; /** * Gets an array containing all cells diagonally adjacent from a specific cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the diagonal. Defaults to `false`. + */ + getDiagonal(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

; + /** + * Gets an array containing all cells that surround a cell at a specific distance. + * @param x - The x coordinate to check. + * @param y - The y coordinate to check. + * @param distance - The distance to check. + * @returns - An array of all cells. */ - getDiagonal(x: number, y: number): GridCellCollection

; + private getEncirclingAtDistance; /** * Gets an array containing all cells that surround a cell. * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the surrounding cells. Defaults to `false`. */ - getEncircling(x: number, y: number): GridCellCollection

; + getEncircling(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

; /** * Calculates the distance between two points on the grid. * @deprecated Use your own distance function instead. diff --git a/examples/src/index.ts b/examples/src/index.ts index eb974b0..129e4f2 100644 --- a/examples/src/index.ts +++ b/examples/src/index.ts @@ -5,11 +5,18 @@ // import { E } from "emath.js"; // console.log(E(69420).format()); -import * as lzstring from "lz-string"; -import * as eMath from "emath.js"; -(window as any).eMath = eMath; -(window as any).lzstring = lzstring; import "./nguformat"; // import "./latexToE"; -import "./coinGame/index"; \ No newline at end of file +import "./coinGame/index"; + +void (async (): Promise => { + const keysToLoad = { + eMath: await import("emath.js"), + eMathGame: await import("emath.js/game"), + eMathPresets: await import("emath.js/presets"), + lzstring: await import("lz-string"), + }; + + Object.assign(window, keysToLoad); +})(); diff --git a/src/classes/Grid.ts b/src/classes/Grid.ts index 7c0c0d6..7253f6d 100644 --- a/src/classes/Grid.ts +++ b/src/classes/Grid.ts @@ -3,7 +3,8 @@ */ import type { UnknownObject } from "../common/types"; -type Directions = "up" | "right" | "down" | "left"; +type DirectionCollection = "adjacent" | "diagonal" | "encircling"; +type Directions = "up" | "right" | "down" | "left" | DirectionCollection; /** * Represents a grid cell with coordinates and properties. @@ -66,23 +67,34 @@ class GridCell

{ * Gets the cell in a specific direction from the current cell. * @param direction - The direction to move. * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - public direction (direction: Directions, distance = 1): GridCell

{ + public direction (direction: D, distance = 1, fill?: boolean): D extends DirectionCollection ? GridCellCollection

: GridCell

{ const grid = Grid.getInstance(this.gridSymbol); - switch (direction) { - case "up": - return grid.getCell(this.x, this.y - distance) as GridCell

; - case "right": - return grid.getCell(this.x + distance, this.y) as GridCell

; - case "down": - return grid.getCell(this.x, this.y + distance) as GridCell

; - case "left": - return grid.getCell(this.x - distance, this.y) as GridCell

; - default: - throw new Error("Invalid direction"); - } + const out: GridCell | GridCellCollection = ((): typeof out => { + switch (direction) { + case "up": + return grid.getCell(this.x, this.y - distance); + case "right": + return grid.getCell(this.x + distance, this.y); + case "down": + return grid.getCell(this.x, this.y + distance); + case "left": + return grid.getCell(this.x - distance, this.y); + case "adjacent": + return grid.getAdjacent(this.x, this.y, distance, fill); + case "diagonal": + return grid.getDiagonal(this.x, this.y, distance, fill); + case "encircling": + return grid.getEncircling(this.x, this.y, distance, fill); + default: + throw new Error("Invalid direction"); + } + })(); + + return out as D extends DirectionCollection ? GridCellCollection

: GridCell

; } /** @@ -91,7 +103,6 @@ class GridCell

{ * @returns - The cell to the right. */ public up (distance = 1): GridCell

{ - // Return the cell return this.direction("up", distance); } @@ -101,7 +112,6 @@ class GridCell

{ * @returns - The cell to the right. */ public right (distance = 1): GridCell

{ - // Return the cell return this.direction("right", distance); } @@ -111,7 +121,6 @@ class GridCell

{ * @returns - The cell below. */ public down (distance = 1): GridCell

{ - // Return the cell return this.direction("down", distance); } @@ -121,7 +130,6 @@ class GridCell

{ * @returns - The cell to the left. */ public left (distance = 1): GridCell

{ - // Return the cell return this.direction("left", distance); } } @@ -141,6 +149,122 @@ class GridCellCollection

extends Array { + // Check if the cell is duplicated + if (this.indexOf(cell) !== index) duplicatedIndexes.push(index); + }); + + // Remove the duplicates + duplicatedIndexes.forEach(index => this.splice(index, 1)); + } + + // Directions + + /** + * Gets the cells in a specific direction from the current cells. + * @param direction - The direction to move. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells in the specified direction. + */ + public direction (direction: Directions, distance?: number, fill?: boolean): GridCellCollection

{ + if ([ "up", "right", "down", "left" ].includes(direction)) { + return new GridCellCollection(this.map(cell => cell.direction(direction as Exclude, distance, fill))); + } + + const output: GridCell

[] = []; + + // Iterate through each cell + for (const cell of this) { + output.push(...cell.direction(direction as DirectionCollection, distance, fill)); + } + + return new GridCellCollection(output); + } + + /** + * Gets the cells above the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells above. + */ + public up (distance?: number): GridCellCollection

{ + return this.direction("up", distance); + } + + /** + * Gets the cells to the right of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the right. + */ + public right (distance?: number): GridCellCollection

{ + return this.direction("right", distance); + } + + /** + * Gets the cells below the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells below. + */ + public down (distance?: number): GridCellCollection

{ + return this.direction("down", distance); + } + + /** + * Gets the cells to the left of the current cells. Can be chained. + * @param distance - The distance to move. Defaults to 1. + * @returns - The cells to the left. + */ + public left (distance?: number): GridCellCollection

{ + return this.direction("left", distance); + } + + // Other direction + + /** + * Gets the cells adjacent to the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells adjacent. + */ + public adjacent (distance?: number, fill?: boolean): GridCellCollection

{ + return this.direction("adjacent", distance, fill); + } + + /** + * Gets the cells diagonally from the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells diagonally. + */ + public diagonal (distance?: number, fill?: boolean): GridCellCollection

{ + return this.direction("diagonal", distance, fill); + } + + /** + * Gets the cells encircling the current cells. Can be chained. + * Note: Can be slow with large collections. + * @param distance - The distance to move. Defaults to 1. + * @param fill - Whether to fill the cells. Defaults to `false`. + * @returns - The cells encircling. + */ + public encircling (distance?: number, fill?: boolean): GridCellCollection

{ + return this.direction("encircling", distance, fill); } } @@ -263,14 +387,41 @@ class Grid

{ * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the adjacent cells. Defaults to `false`. */ - public getAdjacent (x: number, y: number): GridCellCollection

{ - return new GridCellCollection([ - this.getCell(x, y + 1), - this.getCell(x + 1, y), - this.getCell(x, y - 1), - this.getCell(x - 1, y), - ]); + public getAdjacent (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + // If the distance is 1, return the adjacent cells + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x, y + 1), + this.getCell(x + 1, y), + this.getCell(x, y - 1), + this.getCell(x - 1, y), + ]); + } + + // If the fill is false, return the adjacent cells at the distance + if (!fill) { + return new GridCellCollection([ + this.getCell(x, y + distance), + this.getCell(x + distance, y), + this.getCell(x, y - distance), + this.getCell(x - distance, y), + ]); + } + + const output: GridCell

[] = []; + + // Iterate through the distance + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x, y + i)); + output.push(this.getCell(x + i, y)); + output.push(this.getCell(x, y - i)); + output.push(this.getCell(x - i, y)); + } + + return new GridCellCollection(output); } /** @@ -278,14 +429,87 @@ class Grid

{ * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the diagonal. Defaults to `false`. + */ + public getDiagonal (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + // If the distance is 1, return the diagonal cells + if (distance === 1) { + return new GridCellCollection([ + this.getCell(x - 1, y + 1), + this.getCell(x + 1, y + 1), + this.getCell(x + 1, y - 1), + this.getCell(x - 1, y - 1), + ]); + } + + // If the fill is false, return the diagonal cells at the distance + if (!fill) { + return new GridCellCollection([ + this.getCell(x - distance, y + distance), + this.getCell(x + distance, y + distance), + this.getCell(x + distance, y - distance), + this.getCell(x - distance, y - distance), + ]); + } + + const output: GridCell

[] = []; + + // Iterate through the distance + for (let i = 1; i <= distance; i++) { + output.push(this.getCell(x - i, y + i)); + output.push(this.getCell(x + i, y + i)); + output.push(this.getCell(x + i, y - i)); + output.push(this.getCell(x - i, y - i)); + } + + return new GridCellCollection(output); + } + + /** + * Gets an array containing all cells that surround a cell at a specific distance. + * @param x - The x coordinate to check. + * @param y - The y coordinate to check. + * @param distance - The distance to check. + * @returns - An array of all cells. */ - public getDiagonal (x: number, y: number): GridCellCollection

{ - return new GridCellCollection([ - this.getCell(x - 1, y + 1), - this.getCell(x + 1, y + 1), - this.getCell(x + 1, y - 1), - this.getCell(x - 1, y - 1), - ]); + private getEncirclingAtDistance (x: number, y: number, distance: number): GridCellCollection

{ + // If the distance is 1, return the encircling cells + if (distance <= 1) { + return new GridCellCollection([ + ...this.getAdjacent(x, y), + ...this.getDiagonal(x, y), + ]); + } + + // An encircling is basically the cells coordinates + + const output: GridCell

[] = []; + + // Get the top row + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance + i, y - distance)); + } + + // Get the right column + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance, y - distance + i)); + } + + // Get the bottom row + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x + distance - i, y + distance)); + } + + // Get the left column + for (let i = 1; i < distance; i++) { + output.push(this.getCell(x - distance, y + distance - i)); + } + + // Get diagonal cells + output.push(...this.getDiagonal(x, y, distance, false)); + + return new GridCellCollection(output); } /** @@ -293,12 +517,22 @@ class Grid

{ * @returns - An array of all cells. * @param x - The x coordinate to check. * @param y - The y coordinate to check. + * @param distance - The distance to check. Defaults to 1. + * @param fill - Whether to fill the surrounding cells. Defaults to `false`. */ - public getEncircling (x: number, y: number): GridCellCollection

{ - return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y), - ]); + public getEncircling (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + // If the distance is 1, or fill is false return the encircling cells + if (distance === 1 || !fill) { + return this.getEncirclingAtDistance(x, y, distance); + } + + const output: GridCell

[] = []; + // Return all the distances + for (let i = 1; i <= distance; i++) { + output.push(...this.getEncirclingAtDistance(x, y, i)); + } + + return new GridCellCollection(output); } /** @@ -318,9 +552,12 @@ class Grid

{ export { GridCell, GridCellCollection, Grid }; // test -// const grid = new Grid(5); -// const cell = grid.get(2, 2); +// const grid = new Grid(10); -// const newCell = cell.up(3); +// const newCell = grid.getAdjacent(5, 5, 2).adjacent(3, true); -// console.log(cell, newCell); +// console.log(newCell.map(cell => ({ +// x: cell.x, +// y: cell.y, +// })) +// .sort((a, b) => a.x - b.x || a.y - b.y));