diff --git a/dist/game/eMath.game.js b/dist/game/eMath.game.js index 21fc798..6335ca7 100644 --- a/dist/game/eMath.game.js +++ b/dist/game/eMath.game.js @@ -6999,7 +6999,7 @@ var DataManager = class { const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); let version; try { - version = "9.1.0"; + version = "9.2.0"; } catch (error) { version = "8.3.0"; } diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index bba7467..608aa16 100644 --- a/dist/game/eMath.game.min.js +++ b/dist/game/eMath.game.min.js @@ -1,4 +1,4 @@ -"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})},oe=(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)):{},oe(e||!t||!t.__esModule?ct(r,"default",{value:t,enumerable:!0}):r,t)),Je=t=>oe(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 ie(Object.create(null))}:u?function(){return ie({__proto__:null})}:function(){return ie({})},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=re(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=re(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=re(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})()}}),ae=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)}})()}}),ue={};Ut(ue,{default:()=>Lr}),ut.exports=Je(ue);var Xr=ot(ft()),Jr=ot(ft()),le={};Ut(le,{Attribute:()=>Lt,AttributeStatic:()=>_e,Boost:()=>zt,BoostObject:()=>St,Currency:()=>gt,CurrencyStatic:()=>Me,DEFAULT_ITERATIONS:()=>xt,Decimal:()=>s,E:()=>Or,FORMATS:()=>_r,FormatTypeList:()=>ur,Grid:()=>Qt,GridCell:()=>Se,GridCellCollection:()=>nt,Item:()=>be,ItemData:()=>vt,LRUCache:()=>jt,ListNode:()=>fe,ST_NAMES:()=>ht,UpgradeData:()=>yt,UpgradeStatic:()=>Jt,calculateItem:()=>we,calculateSum:()=>Xt,calculateSumApprox:()=>Ne,calculateSumLoop:()=>pe,calculateUpgrade:()=>ye,decimalToJSONString:()=>ve,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 fe(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}}},fe=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,me=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,de=.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 de;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<=me?(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<=me?(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")?ge(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?ge(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)?pe(t,e,r,i):Ne(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 ye(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 ve(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Ar(t){return`el/${ve(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 we(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 be=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 Me=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)),ye(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 be(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]):we(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 _e=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}},Se=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=typeof r=="function"?{...r(this)}:{...r},this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Qt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=Qt.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 ne 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))}translate(e=0,r=0){return new ne(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new ne(this.flatMap(n=>n.direction(e,r,i)))}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)}},Qt=class se{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),se.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=le,Ie={};Ut(Ie,{ConfigManager:()=>kt,DataManager:()=>Ee,EventManager:()=>Te,EventTypes:()=>Oe,Game:()=>Pr,GameAttribute:()=>Pe,GameCurrency:()=>Fe,GameReset:()=>te,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()),Kt=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,Kt.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,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Kt.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}},te=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 Me(()=>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 _e(this.dataManager.getData(e),r,i)),new Pe(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new te(...e)}addResetFromObject(e){return te.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}); +"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,bt=(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})},oe=(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)):{},oe(e||!t||!t.__esModule?ct(r,"default",{value:t,enumerable:!0}):r,t)),Je=t=>oe(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=bt({"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:g(),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 m(){try{return(0,eval)("(function() { return this; })()")}catch{}}function g(){return f()||m()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",f=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",m=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",g=typeof Object.create=="function",u={__proto__:[]}instanceof Array,v=!g&&!u,c={create:g?function(){return ie(Object.create(null))}:u?function(){return ie({__proto__:null})}:function(){return ie({})},has:v?function(N,b){return n.call(N,b)}:function(N,b){return b in N},get:v?function(N,b){return n.call(N,b)?N[b]:void 0}:function(N,b){return N[b]}},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(),d=typeof WeakMap=="function"?WeakMap:Vr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,C=Gr(),x=Zr(C);function a(N,b,A,E){if(j(A)){if(!qe(N))throw new TypeError;if(!De(b))throw new TypeError;return K(N,b)}else{if(!qe(N))throw new TypeError;if(!X(b))throw new TypeError;if(!X(E)&&!j(E)&&!It(E))throw new TypeError;return It(E)&&(E=void 0),A=lt(A),nt(N,b,A,E)}}r("decorate",a);function S(N,b){function A(E,U){if(!X(E))throw new TypeError;if(!j(U)&&!jr(U))throw new TypeError;qt(N,b,E,U)}return A}r("metadata",S);function y(N,b,A,E){if(!X(A))throw new TypeError;return j(E)||(E=lt(E)),qt(N,b,A,E)}r("defineMetadata",y);function I(N,b,A){if(!X(b))throw new TypeError;return j(A)||(A=lt(A)),H(N,b,A)}r("hasMetadata",I);function _(N,b,A){if(!X(b))throw new TypeError;return j(A)||(A=lt(A)),Y(N,b,A)}r("hasOwnMetadata",_);function M(N,b,A){if(!X(b))throw new TypeError;return j(A)||(A=lt(A)),W(N,b,A)}r("getMetadata",M);function F(N,b,A){if(!X(b))throw new TypeError;return j(A)||(A=lt(A)),pt(N,b,A)}r("getOwnMetadata",F);function P(N,b){if(!X(N))throw new TypeError;return j(b)||(b=lt(b)),Dt(N,b)}r("getMetadataKeys",P);function R(N,b){if(!X(N))throw new TypeError;return j(b)||(b=lt(b)),Bt(N,b)}r("getOwnMetadataKeys",R);function z(N,b,A){if(!X(b))throw new TypeError;if(j(A)||(A=lt(A)),!X(b))throw new TypeError;j(A)||(A=lt(A));var E=Et(b,A,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(N,b,A)}r("deleteMetadata",z);function K(N,b){for(var A=N.length-1;A>=0;--A){var E=N[A],U=E(b);if(!j(U)&&!It(U)){if(!De(U))throw new TypeError;b=U}}return b}function nt(N,b,A,E){for(var U=N.length-1;U>=0;--U){var J=N[U],tt=J(b,A,E);if(!j(tt)&&!It(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(N,b,A){var E=Y(N,b,A);if(E)return!0;var U=re(b);return It(U)?!1:H(N,U,A)}function Y(N,b,A){var E=Et(b,A,!1);return j(E)?!1:ke(E.OrdinaryHasOwnMetadata(N,b,A))}function W(N,b,A){var E=Y(N,b,A);if(E)return pt(N,b,A);var U=re(b);if(!It(U))return W(N,U,A)}function pt(N,b,A){var E=Et(b,A,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(N,b,A)}function qt(N,b,A,E){var U=Et(A,E,!0);U.OrdinaryDefineOwnMetadata(N,b,A,E)}function Dt(N,b){var A=Bt(N,b),E=re(N);if(E===null)return A;var U=Dt(E,b);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=b,this._values=b):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=b,this._values=b),L},Z.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{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 g.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 d[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(d,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 d[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:g._decompress(u.length,32768,function(v){return u.charCodeAt(v)})},_decompress:function(u,v,c){var l=[],h,p=4,d=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[d++]=i(y),F=d-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[d++]=i(y),F=d-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===d)C=S+S.charAt(0);else return null;x.push(C),l[d++]=S+C.charAt(0),p--,S=C,p==0&&(p=Math.pow(2,O),O++)}}};return g}();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=bt({"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,m=0;f>>5]|=n[f]<<24-m%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-g)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],f=0,m=0;f>>6-m*2);return o}};e.exports=i})()}}),ae=bt({"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=f._ff,C=f._gg,x=f._hh,a=f._ii,d=0;d>>0,l=l+y>>>0,h=h+I>>>0,p=p+_>>>0}return r.endian([c,l,h,p])};f._ff=function(m,g,u,v,c,l,h){var p=m+(g&u|~g&v)+(c>>>0)+h;return(p<>>32-l)+g},f._gg=function(m,g,u,v,c,l,h){var p=m+(g&v|u&~v)+(c>>>0)+h;return(p<>>32-l)+g},f._hh=function(m,g,u,v,c,l,h){var p=m+(g^u^v)+(c>>>0)+h;return(p<>>32-l)+g},f._ii=function(m,g,u,v,c,l,h){var p=m+(u^(g|~v))+(c>>>0)+h;return(p<>>32-l)+g},f._blocksize=16,f._digestsize=16,e.exports=function(m,g){if(m==null)throw new Error("Illegal argument "+m);var u=r.wordsToBytes(f(m,g));return g&&g.asBytes?u:g&&g.asString?o.bytesToString(u):r.bytesToHex(u)}})()}}),ue={};Ut(ue,{default:()=>Lr}),ut.exports=Je(ue);var Xr=ot(ft()),Jr=ot(ft()),le={};Ut(le,{Attribute:()=>Lt,AttributeStatic:()=>_e,Boost:()=>zt,BoostObject:()=>St,Currency:()=>gt,CurrencyStatic:()=>Me,DEFAULT_ITERATIONS:()=>xt,Decimal:()=>s,E:()=>Or,FORMATS:()=>_r,FormatTypeList:()=>ur,Grid:()=>Qt,GridCell:()=>Se,GridCellCollection:()=>rt,Item:()=>we,ItemData:()=>vt,LRUCache:()=>jt,ListNode:()=>fe,ST_NAMES:()=>ht,UpgradeData:()=>yt,UpgradeStatic:()=>Jt,calculateItem:()=>be,calculateSum:()=>Xt,calculateSumApprox:()=>Ne,calculateSumLoop:()=>pe,calculateUpgrade:()=>ye,decimalToJSONString:()=>ve,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 fe(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}}},fe=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,m=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)?g(a,S,y,"st"):g(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 g(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 g(a,Math.max(4,S),y,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+g(_,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?g(a,S,y,"sc"):a.gte(3)?F[I]+M[I]+"\u03C9^"+g(a.sub(1),S,y,"sc"):a.gte(2)?F[I]+"\u03C9"+M[I]+"-"+g(_.pow(a.sub(2)),S,y,"sc"):F[I]+M[I]+"-"+g(_.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,nt)=>{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),nt=F.div(t.pow(M+1,K.sub(1))).floor();R=`${z(nt,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 g(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 m(a,S=2,y=9,I="st"){return g(a,S,y,I)}function g(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"+g(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"+g(R.floor(),0)}let F=a.div(t.dTen.pow(M)),P=M.log10().gte(9);return _+(P?"":F.toFixed(2))+"e"+g(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"+g(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)),nt=S===2?t.dTwo.sub(M.sub(P)).add(1).toNumber():S;return _+(R.gte(10)?"":K.toFixed(nt)+" ")+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="(+"+g(P,I,_,y)+" OoMs/sec)"):F="(+"+g(S,I,_,y)+"/sec)",F}function v(a,S=2,y="s"){return a=new t(a),a.gte(86400)?g(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")+g(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")+g(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||y!="m"?"":"0")+g(a,S,12,"sc")}function c(a,S=!1,y=0,I=9,_="mixed_sc"){let M=Bt=>g(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(),nt=a.div(31556952).floor(),H=nt.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`${nt.gt(0)?M(nt)+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),g(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),g(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((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:m,format:g,formatGain:u,formatTime:v,formatTimeLong:c,formatReduction:l,formatPercent:h,formatMult:p,expMult:d,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,me=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]],br=[[-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]],w=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))},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},Mr=.36787944117144233,de=.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 de;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 d=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(d)&&isFinite(O)){let a=s.pentate(d,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 d=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(d)&&isFinite(O)){let a=s.tetrate(d,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 d=parseFloat(f[0]),O=parseFloat(f[1]);if(isFinite(d)&&isFinite(O)){let C=s.pow(d,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 m,g,u=t.split("pt");if(u.length===2){m=10;let d=!1;u[0].startsWith("-")&&(d=!0,u[0]=u[0].slice(1)),g=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let C=s.tetrate(m,g,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)),d&&(this.sign*=-1),this}}if(u=t.split("p"),u.length===2){m=10;let d=!1;u[0].startsWith("-")&&(d=!0,u[0]=u[0].slice(1)),g=parseFloat(u[0]),u[1]=u[1].replace("(",""),u[1]=u[1].replace(")","");let O=parseFloat(u[1]);if(isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let C=s.tetrate(m,g,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)),d&&(this.sign*=-1),this}}if(u=t.split("f"),u.length===2){m=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(")",""),g=parseFloat(u[1]),isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let C=s.tetrate(m,g,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)),d&&(this.sign*=-1),this}}let v=t.split("e"),c=v.length-1;if(c===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(c===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&&C<=57||C===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(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 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=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 d=s.mul(B(1,2,p),w(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: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<=me?(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<=me?(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=w(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),m=i.sign+r.sign*f;return B(Math.sign(m),1,i.mag+Math.log10(Math.abs(m)))}}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)),m=i.sign+r.sign*f;return B(Math.sign(m),1,Math.log10(i.mag)+Math.log10(Math.abs(m)))}}if(Math.abs(r.mag-i.mag)>Zt)return r;{let f=Math.pow(10,r.mag-i.mag),m=i.sign+r.sign*f;return B(Math.sign(m),1,i.mag+Math.log10(Math.abs(m)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(w(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=w(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=w(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=w(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=w(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=w(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=w(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=w(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=w(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 w(t).pow(this)}root(t){let e=w(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,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 m=1/n;return e=e+m,i=i*r,n=1680*i,m=1/n,e=e-m,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(),m=f.lambertw().div(f);if(o<1)return m;let g=f.lambertw(!1).div(f);return o>1.444667861009099&&(m=g=s.fromNumber(Math.E)),e=w(e),e.eq(g)?g:e.lt(g)?m: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=w(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 m=1;m1&&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=w(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,br)}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 m=0;mt){let g=(t-Nt[m])/(Nt[m+1]-Nt[m]);n=r[m][Math.floor(e)]*(1-g)+r[m+1][Math.floor(e)]*g,o=r[m][Math.ceil(e)]*(1-g)+r[m+1][Math.ceil(e)]*g;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=w(e);if(i.gt(1)&&i.lte(1.444667861009766)){let f=s.excess_slog(this,e,r),m=f[0].toNumber(),g=f[1],u=m+t,v=s.ln(e).neg(),c=v.lambertw().div(v),l=v.lambertw(!1).div(v),h=s.dOne;g==1?h=c.mul(l).sqrt():g==2&&(h=l.mul(2));let p=i.pow(h),d=Math.floor(u),O=u-d,C=h.pow(1-O).mul(p.pow(O));return s.tetrate(i,d,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=w(t),e=w(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 m=f.mul(2),g=i.pow(m),u=0;if(t.gte(m)&&t.lt(g))u=0;else if(t.gte(g)){let d=g;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(m)){let d=m;for(u=0;d.gt(t);)d=d.log(e),u=u-1}let v=0,c=0,l=.5,h=m,p=s.dZero;for(;l>1e-16;){if(c=v+l,h=m.pow(1-c).mul(g.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 m=o.mul(f).sqrt(),g=i.pow(m),u=0;if(t.lte(m)&&t.gt(g))u=0;else if(t.lte(g)){let d=g;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(m)){let d=m;for(u=0;d.lt(t);)d=d.log(e),u=u-1}let v=0,c=0,l=.5,h=m,p=s.dZero;for(;l>1e-16;){if(c=v+l,h=m.pow(1-c).mul(g.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")?ge(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?ge(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),m=!0;for(;m;)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)?m=!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,m=B(1,10,1),g=o.pow10().recip(),u=s.dZero,v=g,c=g,l=Math.ceil(t)%2==0,h=0,p=B(1,10,1),d=!1,O=s.dZero,C=!1;for(;e<4;){if(e==2){if(l)break;n=B(1,10,1),o=r,e=3,m=B(1,10,1),p=B(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))g=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))g=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)))g=o.pow10().recip(),v=s.dZero,c=g.mul(2),u=g,l?h=-1:h=0;else{for(f=o.mul(12e-17),g=o.pow10().recip(),v=o.add(f).pow10().recip(),u=g.sub(v),c=g.add(u);v.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||c.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||v.gte(g)||c.lte(g);)f=f.mul(2),v=o.add(f).pow10().recip(),u=g.sub(v),c=g.add(u);if((e==1&&c.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&c.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(p=o),c.tetrate(t,1,!0).lt(g.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(g.tetrate(t,1,!0),1e-8)||c.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||v.gte(g)||c.lte(g);)f=f.mul(2),v=o.add(f).pow10().recip(),u=g.sub(v),c=g.add(u);c.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.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(d&&(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(d&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),n=n.sub(m),o=o.sub(m),y)break}if(n.sub(o).div(2).abs().gt(m.mul(1.5))&&(d=!0),m=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:m,value:g,order:u}):this.boostArray.push(new St({id:o,name:f,description:m,value:g,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 g=0;g=0;m--){let g=r.add(f.mul(m)),u=r.add(f.mul(m+1)),v=o;if(o=o.add(t(g).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)?pe(t,e,r,i):Ne(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 ye(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 m=i.sub(r);if(m.lt(0))return console.warn("calculateUpgrade: Invalid target: ",m),[s.dZero,s.dZero];if(f=(typeof e.el=="function"?e.el():e.el)??f,m.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,m),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 g=Wt(c=>Xt(e.cost,c,r),t,n,o).value.floor().min(r.add(m).sub(1)),u=Xt(e.cost,g,r);return[g.sub(r).add(1).max(0),u]}function ve(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Ar(t){return`el/${ve(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 be(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 Me=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)),ye(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]):be(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 _e=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}},Se=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=typeof r=="function"?{...r(this)}:{...r},this.gridSymbol=i}get grid(){return Qt.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Qt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;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)}},rt=class ne extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),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))}translate(e=0,r=0){return new ne(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new ne(this.flatMap(n=>n.direction(e,r,i)))}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)}},Qt=class se{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),se.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=le,Ie={};Ut(Ie,{ConfigManager:()=>kt,DataManager:()=>Ee,EventManager:()=>Te,EventTypes:()=>Oe,Game:()=>Pr,GameAttribute:()=>Pe,GameCurrency:()=>Fe,GameReset:()=>te,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()),Kt=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,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.2.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,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Kt.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 d in c)if(n(c,d)&&!n(h,d)&&(p[d]=c[d]),l[d]instanceof gt){let O=c[d],C=h[d];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[d]=C,C.items={...O.items,...C.items}}else i(c[d])&&i(h[d])&&(p[d]=o(c[d],l[d],h[d]));return p}let f=e?o(this.normalDataPlain,this.normalData,r):r,m=Object.getOwnPropertyNames(new yt({id:"",level:s.dZero})),g=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 d=h.upgrades[p];if(!d||!m.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.upgrades[p];continue}h.upgrades[p]=Gt(yt,d)}for(let p in h.items){let d=h.items[p];if(!d||!g.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.items[p];continue}h.items[p]=Gt(vt,d)}}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 d=c[p].constructor;if(d===Object){h[p]=v(c[p],l[p]);continue}h[p]=u(d,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}},te=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 Me(()=>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 _e(this.dataManager.getData(e),r,i)),new Pe(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new te(...e)}addResetFromObject(e){return te.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/game/eMath.game.mjs b/dist/game/eMath.game.mjs index 2bfa5cc..30bb0e6 100644 --- a/dist/game/eMath.game.mjs +++ b/dist/game/eMath.game.mjs @@ -6965,7 +6965,7 @@ var DataManager = class { const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); let version; try { - version = "9.1.0"; + version = "9.2.0"; } catch (error) { version = "8.3.0"; } diff --git a/dist/main/eMath.js b/dist/main/eMath.js index 74da091..baa0220 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -5883,6 +5883,10 @@ var GridCell = class { this.properties = typeof props === "function" ? { ...props(this) } : { ...props }; this.gridSymbol = gridSymbol; } + /** @returns The grid instance the cell belongs to. */ + get grid() { + return Grid.getInstance(this.gridSymbol); + } /** * Sets the value of a property on the cell. * @param name - The name of the property. @@ -5919,7 +5923,7 @@ var GridCell = class { * @returns - The cell in the specified direction. */ direction(direction, distance = 1, fill) { - const grid = Grid.getInstance(this.gridSymbol); + const grid = this.grid; const out = (() => { switch (direction) { case "up": @@ -5982,6 +5986,7 @@ var GridCellCollection = class _GridCellCollection extends Array { */ constructor(cells) { cells = Array.isArray(cells) ? cells : [cells]; + cells = cells.filter((cell) => cell !== void 0); super(...cells); this.removeDuplicates(); } @@ -6154,16 +6159,22 @@ var Grid = class _Grid { } /** * Gets a cell. - * @returns - The cell. + * @template O - Whether to allow overflow. Defaults to `true`. If `false`, the cell can exist or be `undefined`. * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - The cell. */ getCell(x, y, overflow = true) { x = overflow ? (x + this.xSize) % this.xSize : x; y = overflow ? (y + this.ySize) % this.ySize : y; - const out = this.cells[y][x]; - if (!out) throw new Error(`Grid: Invalid cell coordinates: (${x}, ${y})`); + let out; + try { + out = this.cells[y][x]; + } catch (e) { + return void 0; + } + if (!out) return void 0; return out; } /** @@ -6177,69 +6188,75 @@ var Grid = class _Grid { } /** * Gets an array containing all cells orthagonally adjacent to 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getAdjacent(x, y, distance = 1, fill = false) { + getAdjacent(x, y, distance = 1, fill = false, overflow = true) { 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) + this.getCell(x, y + 1, overflow), + this.getCell(x + 1, y, overflow), + this.getCell(x, y - 1, overflow), + this.getCell(x - 1, y, overflow) ]); } 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) + this.getCell(x, y + distance, overflow), + this.getCell(x + distance, y, overflow), + this.getCell(x, y - distance, overflow), + this.getCell(x - distance, y, overflow) ]); } const output = [this.getCell(x, y)]; 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)); + output.push(...new GridCellCollection([ + this.getCell(x, y + i, overflow), + this.getCell(x + i, y, overflow), + this.getCell(x, y - i, overflow), + this.getCell(x - i, y, overflow) + ])); } 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the diagonal. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getDiagonal(x, y, distance = 1, fill = false) { + getDiagonal(x, y, distance = 1, fill = false, overflow = true) { 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) + this.getCell(x - 1, y + 1, overflow), + this.getCell(x + 1, y + 1, overflow), + this.getCell(x + 1, y - 1, overflow), + this.getCell(x - 1, y - 1, overflow) ]); } 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) + this.getCell(x - distance, y + distance, overflow), + this.getCell(x + distance, y + distance, overflow), + this.getCell(x + distance, y - distance, overflow), + this.getCell(x - distance, y - distance, overflow) ]); } const output = [this.getCell(x, y)]; 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)); + output.push(...new GridCellCollection([ + this.getCell(x - i, y + i, overflow), + this.getCell(x + i, y + i, overflow), + this.getCell(x + i, y - i, overflow), + this.getCell(x - i, y - i, overflow) + ])); } return new GridCellCollection(output); } @@ -6248,46 +6265,48 @@ var Grid = class _Grid { * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param distance - The distance to check. + * @param overflow - Whether to allow overflow. Defaults to `true`. * @returns - An array of all cells. */ - getEncirclingAtDistance(x, y, distance) { + getEncirclingAtDistance(x, y, distance, overflow = true) { if (distance <= 1) { return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y) + ...this.getAdjacent(x, y, 1, false, overflow), + ...this.getDiagonal(x, y, 1, false, overflow) ]); } const output = []; for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance + i, y - distance)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance, y - distance + i)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance - i, y + distance)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance, y + distance - i)); - } - output.push(...this.getDiagonal(x, y, distance, false)); + output.push(...new GridCellCollection([ + // Get the top row + this.getCell(x - distance + i, y - distance, overflow), + // Get the right column + this.getCell(x + distance, y - distance + i, overflow), + // Get the bottom row + this.getCell(x + distance - i, y + distance, overflow), + // Get the left column + this.getCell(x - distance, y + distance - i, overflow) + ])); + } + output.push(...this.getDiagonal(x, y, distance, false, overflow)); 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the surrounding cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getEncircling(x, y, distance = 1, fill = false) { + getEncircling(x, y, distance = 1, fill = false, overflow = true) { if (distance === 1 || !fill) { - return this.getEncirclingAtDistance(x, y, distance); + return this.getEncirclingAtDistance(x, y, distance, overflow); } const output = [this.getCell(x, y)]; for (let i = 1; i <= distance; i++) { - output.push(...this.getEncirclingAtDistance(x, y, i)); + output.push(...this.getEncirclingAtDistance(x, y, i, overflow)); } return new GridCellCollection(output); } diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index 1b3d16b..fcdd995 100644 --- a/dist/main/eMath.min.js +++ b/dist/main/eMath.min.js @@ -1,4 +1,4 @@ -"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},Xt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},Qt=(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)):{},Qt(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),Se=t=>Qt(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,x){Object.defineProperty(d,E,{configurable:!0,writable:!0,value:x}),I&&I(E,x)}}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 Dt(Object.create(null))}:d?function(){return Dt({__proto__:null})}:function(){return Dt({})},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]}},x=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(),k=a?Symbol.for("@reflect-metadata:registry"):void 0,U=nr(),H=sr(U);function o(u,f,c,w){if(L(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)&&!L(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(!L(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 L(w)||(w=at(w)),Ft(u,f,c,w)}r("defineMetadata",p);function v(u,f,c){if(!$(f))throw new TypeError;return L(c)||(c=at(c)),X(u,f,c)}r("hasMetadata",v);function S(u,f,c){if(!$(f))throw new TypeError;return L(c)||(c=at(c)),tt(u,f,c)}r("hasOwnMetadata",S);function F(u,f,c){if(!$(f))throw new TypeError;return L(c)||(c=at(c)),et(u,f,c)}r("getMetadata",F);function O(u,f,c){if(!$(f))throw new TypeError;return L(c)||(c=at(c)),ht(u,f,c)}r("getOwnMetadata",O);function j(u,f){if(!$(u))throw new TypeError;return L(f)||(f=at(f)),At(u,f)}r("getMetadataKeys",j);function V(u,f){if(!$(u))throw new TypeError;return L(f)||(f=at(f)),Ct(u,f)}r("getOwnMetadataKeys",V);function Z(u,f,c){if(!$(f))throw new TypeError;if(L(c)||(c=at(c)),!$(f))throw new TypeError;L(c)||(c=at(c));var w=St(f,c,!1);return L(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(!L(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(!L(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=zt(f);return Nt(q)?!1:X(u,q,c)}function tt(u,f,c){var w=St(f,c,!1);return L(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=zt(f);if(!Nt(q))return et(u,q,c)}function ht(u,f,c){var w=St(f,c,!1);if(!L(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=zt(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(Jt);var cr=mt(gt()),Kt={};Xt(Kt,{Attribute:()=>Zt,AttributeStatic:()=>He,Boost:()=>Ut,BoostObject:()=>pt,Currency:()=>It,CurrencyStatic:()=>De,DEFAULT_ITERATIONS:()=>Et,Decimal:()=>n,E:()=>We,FORMATS:()=>Ze,FormatTypeList:()=>Ee,Grid:()=>Yt,GridCell:()=>fe,GridCellCollection:()=>J,Item:()=>le,ItemData:()=>_t,LRUCache:()=>qt,ListNode:()=>te,ST_NAMES:()=>ut,UpgradeData:()=>Mt,UpgradeStatic:()=>Rt,calculateItem:()=>ue,calculateSum:()=>jt,calculateSumApprox:()=>se,calculateSumLoop:()=>ne,calculateUpgrade:()=>ae,decimalToJSONString:()=>oe,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 te(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}}},te=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 x(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 k(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`${k(o,2)} ${k(o,1)}eV${N?"/c^2":""}`}let H={...e,toSubscript:a,toSuperscript:l,formatST:g,format:m,formatGain:d,formatTime:I,formatTimeLong:E,formatReduction:x,formatPercent:P,formatMult:R,expMult:y,metric:k,ev:U};return{FORMATS:e,formats:H}}var kt=17,Ae=9e15,Ce=Math.log10(9e15),qe=1/9e15,Pe=308,ke=-324,ee=5,Le=1023,xe=!0,Ue=!1,Ve=function(){let t=[];for(let r=ke+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)))},Lt=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,re=.5671432904097838,xt=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 re;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);xe?t=t.replace(",",""):Ue&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let y=parseFloat(s[0]),k=parseFloat(s[1]),U=s[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(y)&&isFinite(k)){let o=n.pentate(y,k,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]),k=parseFloat(a[1]),U=a[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(y)&&isFinite(k)){let o=n.tetrate(y,k,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]),k=parseFloat(l[1]);if(isFinite(y)&&isFinite(k)){let U=n.pow(y,k);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 k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,k,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 k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,k,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 k=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(k)||(k=1),isFinite(g)&&isFinite(m)){let U=n.tetrate(g,m,k,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 x=t.split("e^");if(x.length===2){this.sign=1,x[0].startsWith("-")&&(this.sign=-1);let y="";for(let k=0;k=43&&U<=57||U===101)y+=x[1].charAt(k);else return this.layer=parseFloat(y),this.mag=parseFloat(x[1].substr(k+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+=Lt(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<=ee?(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<=ee?(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))>kt)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))>kt)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)>kt)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=Lt(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),x=I.lambertw(!1).div(I),P=n.dOne;m==1?P=E.mul(x).sqrt():m==2&&(P=x.mul(2));let R=i.pow(P),y=Math.floor(d),k=d-y,U=P.pow(1-k).mul(R.pow(k));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 k=Math.floor(t.layer-y.layer+1);y=i.iteratedexp(k,y,r),d=d+k}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,x=.5,P=g,R=n.dZero;for(;x>1e-16;){if(E=I+x,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+=x),x/=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,x=.5,P=g,R=n.dZero;for(;x>1e-16;){if(E=I+x,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+=x),x/=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(xt(this.toNumber())):this.layer===0?n.fromNumber(xt(this.sign*this.mag)):this.lt("eee15")?ie(this):this.ln():this.sign===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?n.fromNumber(xt(this.sign*this.mag,1e-10,!1)):this.layer==1?ie(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,x=Math.ceil(t)%2==0,P=0,R=C(1,10,1),y=!1,k=n.dZero,U=!1;for(;e<4;){if(e==2){if(x)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(k=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())&&!x&&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,x?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(x)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(k))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(Le),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)?ne(t,e,r,i):se(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 ae(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),x=t.gte(E),P=[n.dZero,n.dZero];return l?(P[0]=x?n.dOne:n.dZero,P):(P=[x?n.dOne:n.dZero,x?E:n.dZero],P)}if(e.costBulk){let[E,x]=e.costBulk(t,e.level,g),P=t.gte(x);return[P?E:n.dZero,P&&!l?x:n.dZero]}if(l){let E=R=>e.cost(R.add(r)),x=n.min(i,Gt(E,t,s,a).value.floor()),P=n.dZero;return[x,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 oe(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function ze(t){return`el/${oe(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 ue(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 le=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)),ae(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 le(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]):ue(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}},fe=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=typeof r=="function"?{...r(this)}:{...r},this.gridSymbol=i}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Yt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=Yt.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 Ht 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))}translate(e=0,r=0){return new Ht(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new Ht(this.flatMap(s=>s.direction(e,r,i)))}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)}},Yt=class Wt{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),Wt.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=Kt;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}); +"use strict";(function(yt,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:yt;for(var wt in ot)Tt[wt]=ot[wt]}})(typeof self<"u"?self:exports,()=>{var yt={},st={exports:yt},Ot=Object.create,ot=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyNames,Me=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty,Ie=(t,e)=>function(){return e||(0,t[wt(t)[0]])((e={exports:{}}).exports,e),e.exports},Xt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},Qt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(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)):{},Qt(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),Se=t=>Qt(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:g(),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 c(){try{return(0,eval)("(function() { return this; })()")}catch{}}function g(){return l()||c()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",l=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",c=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",g=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!g&&!d,E={create:g?function(){return Dt(Object.create(null))}:d?function(){return Dt({__proto__:null})}:function(){return Dt({})},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(),w=typeof WeakMap=="function"?WeakMap:lr(),k=a?Symbol.for("@reflect-metadata:registry"):void 0,U=nr(),H=sr(U);function o(u,f,m,y){if(x(m)){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(!$(y)&&!x(y)&&!Nt(y))throw new TypeError;return Nt(y)&&(y=void 0),m=at(m),it(u,f,m,y)}}r("decorate",o);function N(u,f){function m(y,q){if(!$(y))throw new TypeError;if(!x(q)&&!rr(q))throw new TypeError;Ft(u,f,y,q)}return m}r("metadata",N);function p(u,f,m,y){if(!$(m))throw new TypeError;return x(y)||(y=at(y)),Ft(u,f,m,y)}r("defineMetadata",p);function v(u,f,m){if(!$(f))throw new TypeError;return x(m)||(m=at(m)),X(u,f,m)}r("hasMetadata",v);function S(u,f,m){if(!$(f))throw new TypeError;return x(m)||(m=at(m)),tt(u,f,m)}r("hasOwnMetadata",S);function F(u,f,m){if(!$(f))throw new TypeError;return x(m)||(m=at(m)),et(u,f,m)}r("getMetadata",F);function O(u,f,m){if(!$(f))throw new TypeError;return x(m)||(m=at(m)),ht(u,f,m)}r("getOwnMetadata",O);function j(u,f){if(!$(u))throw new TypeError;return x(f)||(f=at(f)),At(u,f)}r("getMetadataKeys",j);function V(u,f){if(!$(u))throw new TypeError;return x(f)||(f=at(f)),Ct(u,f)}r("getOwnMetadataKeys",V);function Z(u,f,m){if(!$(f))throw new TypeError;if(x(m)||(m=at(m)),!$(f))throw new TypeError;x(m)||(m=at(m));var y=St(f,m,!1);return x(y)?!1:y.OrdinaryDeleteMetadata(u,f,m)}r("deleteMetadata",Z);function Q(u,f){for(var m=u.length-1;m>=0;--m){var y=u[m],q=y(f);if(!x(q)&&!Nt(q)){if(!ge(q))throw new TypeError;f=q}}return f}function it(u,f,m,y){for(var q=u.length-1;q>=0;--q){var z=u[q],W=z(f,m,y);if(!x(W)&&!Nt(W)){if(!$(W))throw new TypeError;y=W}}return y}function X(u,f,m){var y=tt(u,f,m);if(y)return!0;var q=zt(f);return Nt(q)?!1:X(u,q,m)}function tt(u,f,m){var y=St(f,m,!1);return x(y)?!1:ce(y.OrdinaryHasOwnMetadata(u,f,m))}function et(u,f,m){var y=tt(u,f,m);if(y)return ht(u,f,m);var q=zt(f);if(!Nt(q))return et(u,q,m)}function ht(u,f,m){var y=St(f,m,!1);if(!x(y))return y.OrdinaryGetOwnMetadata(u,f,m)}function Ft(u,f,m,y){var q=St(m,y,!0);q.OrdinaryDefineOwnMetadata(u,f,m,y)}function At(u,f){var m=Ct(u,f),y=zt(u);if(y===null)return m;var q=At(y,f);if(q.length<=0)return m;if(m.length<=0)return q;for(var z=new R,W=[],B=0,M=m;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}(),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;AXe}),st.exports=Se(Jt);var cr=mt(gt()),Kt={};Xt(Kt,{Attribute:()=>Zt,AttributeStatic:()=>He,Boost:()=>Ut,BoostObject:()=>pt,Currency:()=>It,CurrencyStatic:()=>De,DEFAULT_ITERATIONS:()=>Et,Decimal:()=>n,E:()=>We,FORMATS:()=>Ze,FormatTypeList:()=>Ee,Grid:()=>Yt,GridCell:()=>fe,GridCellCollection:()=>J,Item:()=>le,ItemData:()=>_t,LRUCache:()=>qt,ListNode:()=>te,ST_NAMES:()=>ut,UpgradeData:()=>Mt,UpgradeStatic:()=>Rt,calculateItem:()=>ue,calculateSum:()=>jt,calculateSumApprox:()=>se,calculateSumLoop:()=>ne,calculateUpgrade:()=>ae,decimalToJSONString:()=>oe,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 te(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}}},te=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,c=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)?g(o,N,p,"st"):g(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 g(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 g(o,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+g(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?g(o,N,p,"sc"):o.gte(3)?O[v]+F[v]+"\u03C9^"+g(o.sub(1),N,p,"sc"):o.gte(2)?O[v]+"\u03C9"+F[v]+"-"+g(S.pow(o.sub(2)),N,p,"sc"):O[v]+F[v]+"-"+g(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 g(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 c(o,N=2,p=9,v="st"){return g(o,N,p,v)}function g(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"+g(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"+g(V.floor(),0)}let O=o.div(t.dTen.pow(F)),j=F.log10().gte(9);return S+(j?"":O.toFixed(2))+"e"+g(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"+g(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="(+"+g(j,v,S,p)+" OoMs/sec)"):O="(+"+g(N,v,S,p)+"/sec)",O}function I(o,N=2,p="s"){return o=new t(o),o.gte(86400)?g(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")+g(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")+g(o.div(60).floor(),0,12,"sc")+":"+I(o.mod(60),N,"m"):(o.gte(10)||p!="m"?"":"0")+g(o,N,12,"sc")}function E(o,N=!1,p=0,v=9,S="mixed_sc"){let F=Ct=>g(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),g(t.dOne.sub(o).mul(100))+"%"}function P(o){return o=new t(o),g(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 k(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`${k(o,2)} ${k(o,1)}eV${N?"/c^2":""}`}let H={...e,toSubscript:a,toSuperscript:l,formatST:c,format:g,formatGain:d,formatTime:I,formatTimeLong:E,formatReduction:L,formatPercent:P,formatMult:R,expMult:w,metric:k,ev:U};return{FORMATS:e,formats:H}}var kt=17,Ae=9e15,Ce=Math.log10(9e15),qe=1/9e15,Pe=308,ke=-324,ee=5,xe=1023,Le=!0,Ue=!1,Ve=function(){let t=[];for(let r=ke+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)))},xt=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,re=.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 re;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 w=parseFloat(s[0]),k=parseFloat(s[1]),U=s[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(w)&&isFinite(k)){let o=n.pentate(w,k,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 w=parseFloat(a[0]),k=parseFloat(a[1]),U=a[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(w)&&isFinite(k)){let o=n.tetrate(w,k,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 w=parseFloat(l[0]),k=parseFloat(l[1]);if(isFinite(w)&&isFinite(k)){let U=n.pow(w,k);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 c,g,d=t.split("pt");if(d.length===2){c=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),g=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,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){c=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),g=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,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){c=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 k=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),g=parseFloat(d[1]),isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,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"),E=I.length-1;if(E===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(E===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 k=0;k=43&&U<=57||U===101)w+=L[1].charAt(k);else return this.layer=parseFloat(w),this.mag=parseFloat(L[1].substr(k+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 w=parseFloat(I[I.length-2]);isFinite(w)&&(R*=Math.sign(w),R+=xt(w))}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 w=n.mul(C(1,2,R),h(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: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<=ee?(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<=ee?(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))>kt)return r;{let l=Math.pow(10,Math.log10(r.mag)-i.mag),c=i.sign+r.sign*l;return C(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>kt)return r;{let l=Math.pow(10,r.mag-Math.log10(i.mag)),c=i.sign+r.sign*l;return C(Math.sign(c),1,Math.log10(i.mag)+Math.log10(Math.abs(c)))}}if(Math.abs(r.mag-i.mag)>kt)return r;{let l=Math.pow(10,r.mag-i.mag),c=i.sign+r.sign*l;return C(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}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=xt(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 c=1/s;return e=e+c,i=i*r,s=1680*i,c=1/s,e=e-c,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(),c=l.lambertw().div(l);if(a<1)return c;let g=l.lambertw(!1).div(l);return a>1.444667861009099&&(c=g=n.fromNumber(Math.E)),e=h(e),e.eq(g)?g:e.lt(g)?c: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 c=1;c1&&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 c=0;ct){let g=(t-ct[c])/(ct[c+1]-ct[c]);s=r[c][Math.floor(e)]*(1-g)+r[c+1][Math.floor(e)]*g,a=r[c][Math.ceil(e)]*(1-g)+r[c+1][Math.ceil(e)]*g;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),c=l[0].toNumber(),g=l[1],d=c+t,I=n.ln(e).neg(),E=I.lambertw().div(I),L=I.lambertw(!1).div(I),P=n.dOne;g==1?P=E.mul(L).sqrt():g==2&&(P=L.mul(2));let R=i.pow(P),w=Math.floor(d),k=d-w,U=P.pow(1-k).mul(R.pow(k));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=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 c=l.mul(2),g=i.pow(c),d=0;if(t.gte(c)&&t.lt(g))d=0;else if(t.gte(g)){let w=g;for(d=1;w.lt(t);)if(w=i.pow(w),d=d+1,w.layer>3){let k=Math.floor(t.layer-w.layer+1);w=i.iteratedexp(k,w,r),d=d+k}w.gt(t)&&(w=w.log(e),d=d-1)}else if(t.lt(c)){let w=c;for(d=0;w.gt(t);)w=w.log(e),d=d-1}let I=0,E=0,L=.5,P=c,R=n.dZero;for(;L>1e-16;){if(E=I+L,P=c.pow(1-E).mul(g.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 c=a.mul(l).sqrt(),g=i.pow(c),d=0;if(t.lte(c)&&t.gt(g))d=0;else if(t.lte(g)){let w=g;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(c)){let w=c;for(d=0;w.lt(t);)w=w.log(e),d=d-1}let I=0,E=0,L=.5,P=c,R=n.dZero;for(;L>1e-16;){if(E=I+L,P=c.pow(1-E).mul(g.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")?ie(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?ie(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),c=!0;for(;c;)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)?c=!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,c=C(1,10,1),g=a.pow10().recip(),d=n.dZero,I=g,E=g,L=Math.ceil(t)%2==0,P=0,R=C(1,10,1),w=!1,k=n.dZero,U=!1;for(;e<4;){if(e==2){if(L)break;s=C(1,10,1),a=r,e=3,c=C(1,10,1),R=C(1,10,1)}for(w=!1;a.neq(s);){if(k=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))g=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))g=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)))g=a.pow10().recip(),I=n.dZero,E=g.mul(2),d=g,L?P=-1:P=0;else{for(l=a.mul(12e-17),g=a.pow10().recip(),I=a.add(l).pow10().recip(),d=g.sub(I),E=g.add(d);I.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||E.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||I.gte(g)||E.lte(g);)l=l.mul(2),I=a.add(l).pow10().recip(),d=g.sub(I),E=g.add(d);if((e==1&&E.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&E.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(R=a),E.tetrate(t,1,!0).lt(g.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(g.tetrate(t,1,!0),1e-8)||E.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||I.gte(g)||E.lte(g);)l=l.mul(2),I=a.add(l).pow10().recip(),d=g.sub(I),E=g.add(d);E.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.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(c),a=a.sub(c),p)break}if(s.sub(a).div(2).abs().gt(c.mul(1.5))&&(w=!0),c=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(k))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(xe),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:c,value:g,order:d}):this.boostArray.push(new pt({id:a,name:l,description:c,value:g,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 g=0;g=0;c--){let g=r.add(l.mul(c)),d=r.add(l.mul(c+1)),I=a;if(a=a.add(t(g).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)?ne(t,e,r,i):se(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 ae(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 c=i.sub(r);if(c.lt(0))return console.warn("calculateUpgrade: Invalid target: ",c),[n.dZero,n.dZero];if(l=(typeof e.el=="function"?e.el():e.el)??l,c.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,c),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 g=Gt(E=>jt(e.cost,E,r),t,s,a).value.floor().min(r.add(c).sub(1)),d=jt(e.cost,g,r);return[g.sub(r).add(1).max(0),d]}function oe(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function ze(t){return`el/${oe(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 ue(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 le=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)),ae(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 le(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]):ue(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}},fe=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=typeof r=="function"?{...r(this)}:{...r},this.gridSymbol=i}get grid(){return Yt.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Yt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;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 Ht extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),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))}translate(e=0,r=0){return new Ht(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new Ht(this.flatMap(s=>s.direction(e,r,i)))}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)}},Yt=class Wt{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),Wt.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=Kt;if(typeof st.exports=="object"&&typeof yt=="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,yt)}return st.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.mjs b/dist/main/eMath.mjs index 9ed7809..e838552 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -5818,6 +5818,10 @@ var GridCell = class { this.properties = typeof props === "function" ? { ...props(this) } : { ...props }; this.gridSymbol = gridSymbol; } + /** @returns The grid instance the cell belongs to. */ + get grid() { + return Grid.getInstance(this.gridSymbol); + } /** * Sets the value of a property on the cell. * @param name - The name of the property. @@ -5854,7 +5858,7 @@ var GridCell = class { * @returns - The cell in the specified direction. */ direction(direction, distance = 1, fill) { - const grid = Grid.getInstance(this.gridSymbol); + const grid = this.grid; const out = (() => { switch (direction) { case "up": @@ -5917,6 +5921,7 @@ var GridCellCollection = class _GridCellCollection extends Array { */ constructor(cells) { cells = Array.isArray(cells) ? cells : [cells]; + cells = cells.filter((cell) => cell !== void 0); super(...cells); this.removeDuplicates(); } @@ -6089,16 +6094,22 @@ var Grid = class _Grid { } /** * Gets a cell. - * @returns - The cell. + * @template O - Whether to allow overflow. Defaults to `true`. If `false`, the cell can exist or be `undefined`. * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - The cell. */ getCell(x, y, overflow = true) { x = overflow ? (x + this.xSize) % this.xSize : x; y = overflow ? (y + this.ySize) % this.ySize : y; - const out = this.cells[y][x]; - if (!out) throw new Error(`Grid: Invalid cell coordinates: (${x}, ${y})`); + let out; + try { + out = this.cells[y][x]; + } catch (e) { + return void 0; + } + if (!out) return void 0; return out; } /** @@ -6112,69 +6123,75 @@ var Grid = class _Grid { } /** * Gets an array containing all cells orthagonally adjacent to 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getAdjacent(x, y, distance = 1, fill = false) { + getAdjacent(x, y, distance = 1, fill = false, overflow = true) { 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) + this.getCell(x, y + 1, overflow), + this.getCell(x + 1, y, overflow), + this.getCell(x, y - 1, overflow), + this.getCell(x - 1, y, overflow) ]); } 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) + this.getCell(x, y + distance, overflow), + this.getCell(x + distance, y, overflow), + this.getCell(x, y - distance, overflow), + this.getCell(x - distance, y, overflow) ]); } const output = [this.getCell(x, y)]; 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)); + output.push(...new GridCellCollection([ + this.getCell(x, y + i, overflow), + this.getCell(x + i, y, overflow), + this.getCell(x, y - i, overflow), + this.getCell(x - i, y, overflow) + ])); } 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the diagonal. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getDiagonal(x, y, distance = 1, fill = false) { + getDiagonal(x, y, distance = 1, fill = false, overflow = true) { 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) + this.getCell(x - 1, y + 1, overflow), + this.getCell(x + 1, y + 1, overflow), + this.getCell(x + 1, y - 1, overflow), + this.getCell(x - 1, y - 1, overflow) ]); } 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) + this.getCell(x - distance, y + distance, overflow), + this.getCell(x + distance, y + distance, overflow), + this.getCell(x + distance, y - distance, overflow), + this.getCell(x - distance, y - distance, overflow) ]); } const output = [this.getCell(x, y)]; 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)); + output.push(...new GridCellCollection([ + this.getCell(x - i, y + i, overflow), + this.getCell(x + i, y + i, overflow), + this.getCell(x + i, y - i, overflow), + this.getCell(x - i, y - i, overflow) + ])); } return new GridCellCollection(output); } @@ -6183,46 +6200,48 @@ var Grid = class _Grid { * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param distance - The distance to check. + * @param overflow - Whether to allow overflow. Defaults to `true`. * @returns - An array of all cells. */ - getEncirclingAtDistance(x, y, distance) { + getEncirclingAtDistance(x, y, distance, overflow = true) { if (distance <= 1) { return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y) + ...this.getAdjacent(x, y, 1, false, overflow), + ...this.getDiagonal(x, y, 1, false, overflow) ]); } const output = []; for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance + i, y - distance)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance, y - distance + i)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance - i, y + distance)); - } - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance, y + distance - i)); - } - output.push(...this.getDiagonal(x, y, distance, false)); + output.push(...new GridCellCollection([ + // Get the top row + this.getCell(x - distance + i, y - distance, overflow), + // Get the right column + this.getCell(x + distance, y - distance + i, overflow), + // Get the bottom row + this.getCell(x + distance - i, y + distance, overflow), + // Get the left column + this.getCell(x - distance, y + distance - i, overflow) + ])); + } + output.push(...this.getDiagonal(x, y, distance, false, overflow)); 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the surrounding cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getEncircling(x, y, distance = 1, fill = false) { + getEncircling(x, y, distance = 1, fill = false, overflow = true) { if (distance === 1 || !fill) { - return this.getEncirclingAtDistance(x, y, distance); + return this.getEncirclingAtDistance(x, y, distance, overflow); } const output = [this.getCell(x, y)]; for (let i = 1; i <= distance; i++) { - output.push(...this.getEncirclingAtDistance(x, y, i)); + output.push(...this.getEncirclingAtDistance(x, y, i, overflow)); } return new GridCellCollection(output); } diff --git a/dist/types/E/e.d.ts b/dist/types/E/e.d.ts index 3cf6853..712a32e 100644 --- a/dist/types/E/e.d.ts +++ b/dist/types/E/e.d.ts @@ -1310,9 +1310,15 @@ declare class Decimal { declare const formats: { toSubscript: (value: number) => string; toSuperscript: (value: number) => string; - formatST: (ex: DecimalSource, acc?: number, max?: number, type?: "sc" | "st" | FormatType) => string; - format: (ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string; - formatGain: (amt: DecimalSource, gain: DecimalSource, type?: FormatType, acc?: number, max?: number) => string; + formatST: (ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string; + format: (ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string; /** + * Returns true if 'value' is greater than or equal to 'other'. + * However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. + * Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. + * For example, if you put in 1e-9, then any number closer to the + * larger number than (larger number)*1e-9 will be considered equal. + */ + formatGain: (amt: DecimalSource, gain: DecimalSource, type?: FormatType, acc?: number | undefined, max?: number | undefined) => string; formatTime: (ex: DecimalSource, acc?: number, type?: string) => string; formatTimeLong: (ex: DecimalSource, ms?: boolean, acc?: number, max?: number, type?: FormatType) => string; formatReduction: (ex: DecimalSource) => string; @@ -1354,25 +1360,25 @@ declare const formats: { format(ex: DecimalSource, acc?: number): string; }; mixed_sc: { - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number | undefined, max?: number): string; }; layer: { layers: string[]; - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number, max?: number | undefined): string; }; standard: { tier1(x: number): string; tier2(x: number): string; }; inf: { - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number | undefined, max?: number | undefined): string; }; alphabet: { config: { alphabet: string; }; getAbbreviation(ex: DecimalSource, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string; - format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string; + format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number | undefined): string; }; }, FORMATS: { omega: { @@ -1408,25 +1414,25 @@ declare const formats: { format(ex: DecimalSource, acc?: number): string; }; mixed_sc: { - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number | undefined, max?: number): string; }; layer: { layers: string[]; - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number, max?: number | undefined): string; }; standard: { tier1(x: number): string; tier2(x: number): string; }; inf: { - format(ex: DecimalSource, acc?: number, max?: number): string; + format(ex: DecimalSource, acc?: number | undefined, max?: number | undefined): string; }; alphabet: { config: { alphabet: string; }; getAbbreviation(ex: DecimalSource, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string; - format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string; + format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number | undefined): string; }; }; export { formats, FORMATS }; diff --git a/dist/types/classes/Grid.d.ts b/dist/types/classes/Grid.d.ts index 73e5d73..65d53cc 100644 --- a/dist/types/classes/Grid.d.ts +++ b/dist/types/classes/Grid.d.ts @@ -2,8 +2,18 @@ * @file Declares the gridCell and grid classes. */ import type { UnknownObject } from "../common/types"; -type DirectionCollection = "adjacent" | "diagonal" | "encircling"; -type Directions = "up" | "right" | "down" | "left" | DirectionCollection; +/** + * Grid directions that result in {@link GridCell} + */ +type GridDirectionCell = "up" | "right" | "down" | "left"; +/** + * Grid directions that result in {@link GridCellCollection} + */ +type GridDirectionCollection = "adjacent" | "diagonal" | "encircling"; +/** + * Grid directions + */ +type GridDirection = GridDirectionCell | GridDirectionCollection; /** * Represents a grid cell with coordinates and properties. * @template P - The type of the properties of the grid cell. @@ -15,6 +25,8 @@ declare class GridCell

{ y: number; /** The grid instance the cell belongs to. */ private gridSymbol; + /** @returns The grid instance the cell belongs to. */ + get grid(): Grid

; /** The properties of the cell. */ properties: P; /** @@ -24,7 +36,7 @@ declare class GridCell

{ * @param props - The properties to initialize with. * @param gridSymbol - The symbol of the grid the cell belongs to. */ - constructor(x: number, y: number, props: (P | ((grid: GridCell

) => P)) | undefined, gridSymbol: symbol); + constructor(x: number, y: number, props: P | ((grid: GridCell

) => P) | undefined, gridSymbol: symbol); /** * Sets the value of a property on the cell. * @param name - The name of the property. @@ -56,7 +68,7 @@ declare class GridCell

{ * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - direction(direction: D, distance?: number, fill?: boolean): D extends DirectionCollection ? GridCellCollection

: GridCell

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

: GridCell

; /** * Gets the cell to the right of the current cell. Can be chained. * @param distance - The distance to move. Defaults to 1. @@ -91,7 +103,7 @@ declare class GridCellCollection

extends Array * Initializes a new instance of the grid cell collection. * @param cells - The cells to initialize with. */ - constructor(cells: GridCell

| GridCell

[]); + constructor(cells: GridCell

| (GridCell

| undefined)[]); /** * Removes duplicate cells from the collection. * Modifies the array in place. @@ -111,7 +123,7 @@ declare class GridCellCollection

extends Array * @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

; + direction(direction: GridDirection, distance?: number, fill?: boolean): GridCellCollection

; /** * Gets the cells above the current cells. Can be chained. * @param distance - The distance to move. Defaults to 1. @@ -214,14 +226,15 @@ declare class Grid

{ allY: (y: number) => GridCellCollection

; /** * Gets a cell. - * @returns - The cell. + * @template O - Whether to allow overflow. Defaults to `true`. If `false`, the cell can exist or be `undefined`. * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - The cell. */ - getCell(x: number, y: number, overflow?: boolean): GridCell

; + getCell(x: number, y: number, overflow?: O): O extends true ? GridCell

: GridCell

| undefined; /** @deprecated Use {@link getCell} instead. */ - get: (x: number, y: number, overflow?: boolean) => GridCell

; + get: (x: number, y: number, overflow?: O) => O extends true ? GridCell

: GridCell

| undefined; /** * Sets the value of a cell in the grid. * @param x The x-coordinate of the cell. @@ -233,39 +246,43 @@ declare class Grid

{ set: (x: number, y: number, value: GridCell

) => void; /** * Gets an array containing all cells orthagonally adjacent to 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getAdjacent(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

; + getAdjacent(x: number, y: number, distance?: number, fill?: boolean, overflow?: 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the diagonal. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getDiagonal(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

; + getDiagonal(x: number, y: number, distance?: number, fill?: boolean, overflow?: 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. + * @param overflow - Whether to allow overflow. Defaults to `true`. * @returns - An array of all cells. */ 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the surrounding cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - getEncircling(x: number, y: number, distance?: number, fill?: boolean): GridCellCollection

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

; /** * Calculates the distance between two points on the grid. * @deprecated Use your own distance function instead. @@ -278,3 +295,4 @@ declare class Grid

{ static getDistance(x1: number, y1: number, x2: number, y2: number): number; } export { GridCell, GridCellCollection, Grid }; +export type { GridDirection, GridDirectionCell, GridDirectionCollection }; diff --git a/dist/types/classes/Item.d.ts b/dist/types/classes/Item.d.ts index 9e20a59..f92670a 100644 --- a/dist/types/classes/Item.d.ts +++ b/dist/types/classes/Item.d.ts @@ -76,7 +76,7 @@ declare class Item implements ItemInit { id: string; name: string; cost: () => Decimal; - effect: ((amount: Decimal, itemContext: Item, currencyContext: CurrencyStatic) => void) | undefined; + effect: ((amount: Decimal, itemContext: Item, currencyContext: CurrencyStatic<[], string>) => void) | undefined; defaultAmount: Decimal; /** @returns The data of the item. */ private dataPointerFn; diff --git a/dist/types/classes/Upgrade.d.ts b/dist/types/classes/Upgrade.d.ts index 5e1bfd0..df9a17b 100644 --- a/dist/types/classes/Upgrade.d.ts +++ b/dist/types/classes/Upgrade.d.ts @@ -207,7 +207,7 @@ declare class UpgradeStatic implements IUpgradeStatic { cost: (level: Decimal) => Decimal; costBulk: ((currencyValue: Decimal, level: Decimal, target: Decimal) => [amount: Decimal, cost: Decimal]) | undefined; maxLevel: Decimal | undefined; - effect: ((level: Decimal, upgradeContext: UpgradeStatic, currencyContext: CurrencyStatic) => void) | undefined; + effect: ((level: Decimal, upgradeContext: UpgradeStatic, currencyContext: CurrencyStatic<[], string>) => void) | undefined; el?: boolean | (() => boolean) | undefined; defaultLevel: Decimal; /** The default size of the cache. Should be one less than a power of 2. */ diff --git a/dist/types/game/hookGame.d.ts b/dist/types/game/hookGame.d.ts index 228b157..b461ee9 100644 --- a/dist/types/game/hookGame.d.ts +++ b/dist/types/game/hookGame.d.ts @@ -21,9 +21,9 @@ declare const eMath: { formats: { toSubscript: (value: number) => string; toSuperscript: (value: number) => string; - formatST: (ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: "sc" | "st" | eMathMain.FormatType) => string; + formatST: (ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType) => string; format: (ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType) => string; - formatGain: (amt: eMathMain.DecimalSource, gain: eMathMain.DecimalSource, type?: eMathMain.FormatType, acc?: number, max?: number) => string; + formatGain: (amt: eMathMain.DecimalSource, gain: eMathMain.DecimalSource, type?: eMathMain.FormatType, acc?: number | undefined, max?: number | undefined) => string; formatTime: (ex: eMathMain.DecimalSource, acc?: number, type?: string) => string; formatTimeLong: (ex: eMathMain.DecimalSource, ms?: boolean, acc?: number, max?: number, type?: eMathMain.FormatType) => string; formatReduction: (ex: eMathMain.DecimalSource) => string; @@ -65,25 +65,25 @@ declare const eMath: { format(ex: eMathMain.DecimalSource, acc?: number): string; }; mixed_sc: { - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number | undefined, max?: number): string; }; layer: { layers: string[]; - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number, max?: number | undefined): string; }; standard: { tier1(x: number): string; tier2(x: number): string; }; inf: { - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number | undefined, max?: number | undefined): string; }; alphabet: { config: { alphabet: string; }; getAbbreviation(ex: eMathMain.DecimalSource, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number): string; - format(ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number | undefined): string; }; }; FORMATS: { @@ -120,25 +120,25 @@ declare const eMath: { format(ex: eMathMain.DecimalSource, acc?: number): string; }; mixed_sc: { - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number | undefined, max?: number): string; }; layer: { layers: string[]; - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number, max?: number | undefined): string; }; standard: { tier1(x: number): string; tier2(x: number): string; }; inf: { - format(ex: eMathMain.DecimalSource, acc?: number, max?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number | undefined, max?: number | undefined): string; }; alphabet: { config: { alphabet: string; }; getAbbreviation(ex: eMathMain.DecimalSource, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number): string; - format(ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number): string; + format(ex: eMathMain.DecimalSource, acc?: number, max?: number, type?: eMathMain.FormatType, start?: eMathMain.DecimalSource, startDouble?: boolean, abbStart?: number | undefined): string; }; }; ST_NAMES: string[][][]; @@ -168,6 +168,6 @@ declare const eMath: { calculateSum: typeof eMathMain.calculateSum; roundingBase: typeof eMathMain.roundingBase; DEFAULT_ITERATIONS: 30; - E: ((x?: eMathMain.DecimalSource) => eMathMain.Decimal) & typeof eMathMain.Decimal; + E: ((x?: eMathMain.DecimalSource | undefined) => eMathMain.Decimal) & typeof eMathMain.Decimal; }; export default eMath; diff --git a/src/classes/Grid.ts b/src/classes/Grid.ts index 61147d4..e2803d8 100644 --- a/src/classes/Grid.ts +++ b/src/classes/Grid.ts @@ -3,8 +3,20 @@ */ import type { UnknownObject } from "../common/types"; -type DirectionCollection = "adjacent" | "diagonal" | "encircling"; -type Directions = "up" | "right" | "down" | "left" | DirectionCollection; +/** + * Grid directions that result in {@link GridCell} + */ +type GridDirectionCell = "up" | "right" | "down" | "left"; + +/** + * Grid directions that result in {@link GridCellCollection} + */ +type GridDirectionCollection = "adjacent" | "diagonal" | "encircling"; + +/** + * Grid directions + */ +type GridDirection = GridDirectionCell | GridDirectionCollection; /** * Represents a grid cell with coordinates and properties. @@ -20,6 +32,11 @@ class GridCell

{ /** The grid instance the cell belongs to. */ private gridSymbol: symbol; + /** @returns The grid instance the cell belongs to. */ + public get grid (): Grid

{ + return Grid.getInstance(this.gridSymbol); + } + /** The properties of the cell. */ public properties: P; @@ -82,8 +99,8 @@ class GridCell

{ * @param fill - Whether to fill the cells. Defaults to `false`. * @returns - The cell in the specified direction. */ - public direction (direction: D, distance = 1, fill?: boolean): D extends DirectionCollection ? GridCellCollection

: GridCell

{ - const grid = Grid.getInstance(this.gridSymbol); + public direction (direction: D, distance = 1, fill?: boolean): D extends GridDirectionCollection ? GridCellCollection

: GridCell

{ + const grid = this.grid as Grid; const out: GridCell | GridCellCollection = ((): typeof out => { switch (direction) { @@ -106,7 +123,7 @@ class GridCell

{ } })(); - return out as D extends DirectionCollection ? GridCellCollection

: GridCell

; + return out as D extends GridDirectionCollection ? GridCellCollection

: GridCell

; } /** @@ -155,12 +172,15 @@ class GridCellCollection

extends Array | GridCell

[]) { + constructor (cells: GridCell

| (GridCell

| undefined)[]) { // Normalize the input to an array of cells cells = Array.isArray(cells) ? cells : [cells]; + // Filter out undefined cells + cells = cells.filter((cell): cell is GridCell

=> cell !== undefined); + // Call the parent constructor with the cells - super(...cells); + super(...cells as GridCell

[]); // Remove duplicates this.removeDuplicates(); @@ -203,7 +223,7 @@ class GridCellCollection

extends Array { + public direction (direction: GridDirection, distance?: number, fill?: boolean): GridCellCollection

{ return new GridCellCollection(this.flatMap(cell => cell.direction(direction, distance, fill))); } @@ -369,18 +389,29 @@ class Grid

{ /** * Gets a cell. - * @returns - The cell. + * @template O - Whether to allow overflow. Defaults to `true`. If `false`, the cell can exist or be `undefined`. * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - The cell. */ - public getCell (x: number, y: number, overflow = true): GridCell

{ + public getCell (x: number, y: number, overflow: O = true as O): O extends true ? GridCell

: GridCell

| undefined { + // Normalize the coordinates based on overflow x = overflow ? (x + this.xSize) % this.xSize : x; y = overflow ? (y + this.ySize) % this.ySize : y; - const out = this.cells[y][x]; + let out: GridCell

| undefined; + + try { + out = this.cells[y][x]; + } catch (e) { + return undefined as never; + } + + // If the cell is undefined, return undefined // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (!out) throw new Error(`Grid: Invalid cell coordinates: (${x}, ${y})`); + if (!out) return undefined as never; + return out; } /** @deprecated Use {@link getCell} instead. */ @@ -400,30 +431,31 @@ class Grid

{ /** * Gets an array containing all cells orthagonally adjacent to 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the adjacent cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - public getAdjacent (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + public getAdjacent (x: number, y: number, distance = 1, fill = false, overflow = true): 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), + this.getCell(x, y + 1, overflow), + this.getCell(x + 1, y, overflow), + this.getCell(x, y - 1, overflow), + this.getCell(x - 1, y, overflow), ]); } // 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), + this.getCell(x, y + distance, overflow), + this.getCell(x + distance, y, overflow), + this.getCell(x, y - distance, overflow), + this.getCell(x - distance, y, overflow), ]); } @@ -431,10 +463,12 @@ class Grid

{ // 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)); + output.push(...new GridCellCollection([ + this.getCell(x, y + i, overflow), + this.getCell(x + i, y, overflow), + this.getCell(x, y - i, overflow), + this.getCell(x - i, y, overflow), + ])); } return new GridCellCollection(output); @@ -442,30 +476,31 @@ class Grid

{ /** * 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the diagonal. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - public getDiagonal (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + public getDiagonal (x: number, y: number, distance = 1, fill = false, overflow = true): 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), + this.getCell(x - 1, y + 1, overflow), + this.getCell(x + 1, y + 1, overflow), + this.getCell(x + 1, y - 1, overflow), + this.getCell(x - 1, y - 1, overflow), ]); } // 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), + this.getCell(x - distance, y + distance, overflow), + this.getCell(x + distance, y + distance, overflow), + this.getCell(x + distance, y - distance, overflow), + this.getCell(x - distance, y - distance, overflow), ]); } @@ -473,10 +508,12 @@ class Grid

{ // 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)); + output.push(...new GridCellCollection([ + this.getCell(x - i, y + i, overflow), + this.getCell(x + i, y + i, overflow), + this.getCell(x + i, y - i, overflow), + this.getCell(x - i, y - i, overflow), + ])); } return new GridCellCollection(output); @@ -487,14 +524,15 @@ class Grid

{ * @param x - The x coordinate to check. * @param y - The y coordinate to check. * @param distance - The distance to check. + * @param overflow - Whether to allow overflow. Defaults to `true`. * @returns - An array of all cells. */ - private getEncirclingAtDistance (x: number, y: number, distance: number): GridCellCollection

{ + private getEncirclingAtDistance (x: number, y: number, distance: number, overflow = true): GridCellCollection

{ // If the distance is 1, return the encircling cells if (distance <= 1) { return new GridCellCollection([ - ...this.getAdjacent(x, y), - ...this.getDiagonal(x, y), + ...this.getAdjacent(x, y, 1, false, overflow), + ...this.getDiagonal(x, y, 1, false, overflow), ]); } @@ -502,50 +540,48 @@ class Grid

{ const output: GridCell

[] = []; - // Get the top row for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance + i, y - distance)); - } + output.push(...new GridCellCollection([ + // Get the top row + this.getCell(x - distance + i, y - distance, overflow), - // Get the right column - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance, y - distance + i)); - } + // Get the right column + this.getCell(x + distance, y - distance + i, overflow), - // Get the bottom row - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x + distance - i, y + distance)); - } + // Get the bottom row + this.getCell(x + distance - i, y + distance, overflow), - // Get the left column - for (let i = 1; i < distance * 2; i++) { - output.push(this.getCell(x - distance, y + distance - i)); + // Get the left column + this.getCell(x - distance, y + distance - i, overflow), + ])); } // Get diagonal cells - output.push(...this.getDiagonal(x, y, distance, false)); + output.push(...this.getDiagonal(x, y, distance, false, overflow)); 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 distance - The distance to check. Defaults to `1`. * @param fill - Whether to fill the surrounding cells. Defaults to `false`. + * @param overflow - Whether to allow overflow. Defaults to `true`. + * @returns - An array of all cells. */ - public getEncircling (x: number, y: number, distance = 1, fill = false): GridCellCollection

{ + public getEncircling (x: number, y: number, distance = 1, fill = false, overflow = true): GridCellCollection

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

[] = [this.getCell(x, y)]; + // Return all the distances for (let i = 1; i <= distance; i++) { - output.push(...this.getEncirclingAtDistance(x, y, i)); + output.push(...this.getEncirclingAtDistance(x, y, i, overflow)); } return new GridCellCollection(output); @@ -566,6 +602,7 @@ class Grid

{ } export { GridCell, GridCellCollection, Grid }; +export type { GridDirection, GridDirectionCell, GridDirectionCollection }; // test // const grid = new Grid(100);