diff --git a/dist/game/eMath.game.js b/dist/game/eMath.game.js index f5790a0..5e655b3 100644 --- a/dist/game/eMath.game.js +++ b/dist/game/eMath.game.js @@ -5588,20 +5588,26 @@ var import_class_transformer3 = require("class-transformer"); // src/classes/Boost.ts var BoostObject = class { - // eslint-disable-next-line jsdoc/require-returns - /** @deprecated Use {@link description} instead */ + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ get desc() { return this.description; } get description() { return this.descriptionFn(); } + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ constructor(init) { this.id = init.id; this.name = init.name ?? ""; - this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; this.value = init.value; this.order = init.order ?? 99; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; } }; var Boost = class { @@ -5976,10 +5982,6 @@ var UpgradeStatic = class _UpgradeStatic { // src/classes/Currency.ts var Currency = class { - // public upgrades: UpgradeData[]; - // /** A boost object that affects the currency gain. */ - // @Expose() - // public boost: boost; /** * Constructs a new currency object with an initial value of 0. */ @@ -6034,13 +6036,7 @@ var CurrencyStatic = class { this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; this.boost = new Boost(this.defaultBoost); this.pointer.value = this.defaultVal; - this.upgrades = { - // *[Symbol.iterator] () { - // for (const upgrade of Object.values(this)) { - // yield upgrade; - // } - // }, - }; + this.upgrades = {}; if (upgrades) this.addUpgrade(upgrades); } /** @@ -6113,6 +6109,39 @@ var CurrencyStatic = class { getUpgrade(id) { return this.upgrades[id] ?? null; } + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + queryUpgrade(id) { + const allUpgradeIds = Object.keys(this.upgrades); + if (id instanceof RegExp) { + const regex = id; + const matchedIds = allUpgradeIds.filter((upgrade) => regex.test(upgrade)); + return matchedIds.map((matchedId) => this.upgrades[matchedId]); + } + if (typeof id === "string") { + id = [id]; + } + const matchedUpgrades = allUpgradeIds.filter((upgrade) => id.includes(upgrade)); + return matchedUpgrades.map((matchedId) => this.upgrades[matchedId]); + } /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -6141,20 +6170,20 @@ var CurrencyStatic = class { */ addUpgrade(upgrades, runEffectInstantly = true) { if (!Array.isArray(upgrades)) upgrades = [upgrades]; - const addedUpgradeList = {}; + const addedUpgradeList = []; for (const upgrade of upgrades) { - const addedUpgradeData = this.pointerAddUpgrade(upgrade); + this.pointerAddUpgrade(upgrade); const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id)); if (addedUpgradeStatic.effect && runEffectInstantly) addedUpgradeStatic.effect(addedUpgradeStatic.level, addedUpgradeStatic, this); - addedUpgradeList[upgrade.id] = addedUpgradeStatic; this.upgrades[upgrade.id] = addedUpgradeStatic; + addedUpgradeList.push(addedUpgradeStatic); } - return Object.values(addedUpgradeList); + return addedUpgradeList; } /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -6165,13 +6194,10 @@ var CurrencyStatic = class { * } * }); */ - updateUpgrade(id, upgrade) { - const upgrade1 = this.getUpgrade(id); - if (upgrade1 === null) return; - upgrade1.name = upgrade.name ?? upgrade1.name; - upgrade1.cost = upgrade.cost ?? upgrade1.cost; - upgrade1.maxLevel = upgrade.maxLevel ?? upgrade1.maxLevel; - upgrade1.effect = upgrade.effect ?? upgrade1.effect; + updateUpgrade(id, newUpgrade) { + const oldUpgrade = this.getUpgrade(id); + if (oldUpgrade === null) return; + Object.assign(oldUpgrade, newUpgrade); } /** * Calculates the cost and how many upgrades you can buy. @@ -6185,7 +6211,6 @@ var CurrencyStatic = class { * // Calculate how many healthBoost upgrades you can buy and the cost of the upgrades * const [amount, cost] = currency.calculateUpgrade("healthBoost", 10); */ - // public calculateUpgrade (id: string, target: DecimalSource = 1, el: boolean = false): [amount: Decimal, cost: Decimal] { calculateUpgrade(id, target = Infinity, mode, iterations) { const upgrade = this.getUpgrade(id); if (upgrade === null) { diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index e01ffc0..dfb9e40 100644 --- a/dist/game/eMath.game.min.js +++ b/dist/game/eMath.game.min.js @@ -1,4 +1,4 @@ -"use strict";(function(St,st){var At=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],st);else if(typeof module=="object"&&module.exports)module.exports=st();else{var lt=st(),Tt=At?exports:St;for(var It in lt)Tt[It]=lt[It]}})(typeof self<"u"?self:exports,()=>{var St={},st={exports:St},At=Object.create,lt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,It=Object.getOwnPropertyNames,Ge=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,yt=(t,e)=>function(){return e||(0,t[It(t)[0]])((e={exports:{}}).exports,e),e.exports},Bt=(t,e)=>{for(var r in e)lt(t,r,{get:e[r],enumerable:!0})},Kt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of It(e))!$e.call(t,n)&&n!==r&<(t,n,{get:()=>e[n],enumerable:!(i=Tt(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?At(Ge(t)):{},Kt(e||!t||!t.__esModule?lt(r,"default",{value:t,enumerable:!0}):r,t)),Ye=t=>Kt(lt({},"__esModule",{value:!0}),t),ut=(t,e,r,i)=>{for(var n=i>1?void 0:i?Tt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&<(e,r,n),n},ft=yt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(l,p){return function(f,u){Object.defineProperty(l,f,{configurable:!0,writable:!0,value:u}),p&&p(f,u)}}function c(){try{return Function("return this;")()}catch{}}function d(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return c()||d()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",c=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",d=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",l={__proto__:[]}instanceof Array,p=!m&&!l,f={create:m?function(){return Qt(Object.create(null))}:l?function(){return Qt({__proto__:null})}:function(){return Qt({})},has:p?function(y,b){return n.call(y,b)}:function(y,b){return b in y},get:p?function(y,b){return n.call(y,b)?y[b]:void 0}:function(y,b){return y[b]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Rr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:jr(),N=typeof WeakMap=="function"?WeakMap:Ur(),A=o?Symbol.for("@reflect-metadata:registry"):void 0,x=qr(),P=Br(x);function a(y,b,O,E){if(j(O)){if(!Ee(y))throw new TypeError;if(!Ce(b))throw new TypeError;return K(y,b)}else{if(!Ee(y))throw new TypeError;if(!X(b))throw new TypeError;if(!X(E)&&!j(E)&&!Mt(E))throw new TypeError;return Mt(E)&&(E=void 0),O=at(O),it(y,b,O,E)}}r("decorate",a);function S(y,b){function O(E,R){if(!X(E))throw new TypeError;if(!j(R)&&!Lr(R))throw new TypeError;Lt(y,b,E,R)}return O}r("metadata",S);function v(y,b,O,E){if(!X(O))throw new TypeError;return j(E)||(E=at(E)),Lt(y,b,O,E)}r("defineMetadata",v);function I(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),H(y,b,O)}r("hasMetadata",I);function _(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),Z(y,b,O)}r("hasOwnMetadata",_);function M(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),W(y,b,O)}r("getMetadata",M);function C(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),dt(y,b,O)}r("getOwnMetadata",C);function F(y,b){if(!X(y))throw new TypeError;return j(b)||(b=at(b)),kt(y,b)}r("getMetadataKeys",F);function U(y,b){if(!X(y))throw new TypeError;return j(b)||(b=at(b)),qt(y,b)}r("getOwnMetadataKeys",U);function z(y,b,O){if(!X(b))throw new TypeError;if(j(O)||(O=at(O)),!X(b))throw new TypeError;j(O)||(O=at(O));var E=Ot(b,O,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(y,b,O)}r("deleteMetadata",z);function K(y,b){for(var O=y.length-1;O>=0;--O){var E=y[O],R=E(b);if(!j(R)&&!Mt(R)){if(!Ce(R))throw new TypeError;b=R}}return b}function it(y,b,O,E){for(var R=y.length-1;R>=0;--R){var J=y[R],tt=J(b,O,E);if(!j(tt)&&!Mt(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(y,b,O){var E=Z(y,b,O);if(E)return!0;var R=Jt(b);return Mt(R)?!1:H(y,R,O)}function Z(y,b,O){var E=Ot(b,O,!1);return j(E)?!1:Te(E.OrdinaryHasOwnMetadata(y,b,O))}function W(y,b,O){var E=Z(y,b,O);if(E)return dt(y,b,O);var R=Jt(b);if(!Mt(R))return W(y,R,O)}function dt(y,b,O){var E=Ot(b,O,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(y,b,O)}function Lt(y,b,O,E){var R=Ot(O,E,!0);R.OrdinaryDefineOwnMetadata(y,b,O,E)}function kt(y,b){var O=qt(y,b),E=Jt(y);if(E===null)return O;var R=kt(E,b);if(R.length<=0)return O;if(O.length<=0)return R;for(var J=new g,tt=[],$=0,L=O;$=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}},$.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),L},$.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:L,done:!0}},$}(),E=function(){function $(){this._keys=[],this._values=[],this._cacheKey=y,this._cacheIndex=-2}return Object.defineProperty($.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),$.prototype.has=function(L){return this._find(L,!1)>=0},$.prototype.get=function(L){var k=this._find(L,!1);return k>=0?this._values[k]:void 0},$.prototype.set=function(L,k){var q=this._find(L,!0);return this._values[q]=k,this},$.prototype.delete=function(L){var k=this._find(L,!1);if(k>=0){for(var q=this._keys.length,B=k+1;B>>8,f[u*2+1]=g%256}return f},decompressFromUint8Array:function(l){if(l==null)return m.decompress(l);for(var p=new Array(l.length/2),f=0,u=p.length;f>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,v),v++),delete N[P]}else for(h=g[P],u=0;u>1;a--,a==0&&(a=Math.pow(2,v),v++),g[x]=S++,P=String(A)}if(P!==""){if(Object.prototype.hasOwnProperty.call(N,P)){if(P.charCodeAt(0)<256){for(u=0;u>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,v),v++),delete N[P]}else for(h=g[P],u=0;u>1;a--,a==0&&(a=Math.pow(2,v),v++)}for(h=2,u=0;u>1;for(;;)if(_=_<<1,M==p-1){I.push(f(_));break}else M++;return I.join("")},decompress:function(l){return l==null?"":l==""?null:m._decompress(l.length,32768,function(p){return l.charCodeAt(p)})},_decompress:function(l,p,f){var u=[],h,g=4,N=4,A=3,x="",P=[],a,S,v,I,_,M,C,F={val:f(0),position:p,index:1};for(a=0;a<3;a+=1)u[a]=a;for(v=0,_=Math.pow(2,2),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;switch(h=v){case 0:for(v=0,_=Math.pow(2,8),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;C=i(v);break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;C=i(v);break;case 2:return""}for(u[3]=C,S=C,P.push(C);;){if(F.index>l)return"";for(v=0,_=Math.pow(2,A),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;switch(C=v){case 0:for(v=0,_=Math.pow(2,8),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=i(v),C=N-1,g--;break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=i(v),C=N-1,g--;break;case 2:return P.join("")}if(g==0&&(g=Math.pow(2,A),A++),u[C])x=u[C];else if(C===N)x=S+S.charAt(0);else return null;P.push(x),u[N++]=S+x.charAt(0),g--,S=x,g==0&&(g=Math.pow(2,A),A++)}}};return m}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),ze=yt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],c=0,d=0;c>>5]|=n[c]<<24-d%32;return o},wordsToBytes:function(n){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(n){for(var o=[],c=0;c>>4).toString(16)),o.push((n[c]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],c=0;c>>6*(3-m)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,d=0;c>>6-d*2);return o}};e.exports=i})()}}),te=yt({"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|(l[N]<<24|l[N]>>>8)&4278255360;l[p>>>5]|=128<>>9<<4)+14]=p;for(var A=c._ff,x=c._gg,P=c._hh,a=c._ii,N=0;N>>0,u=u+v>>>0,h=h+I>>>0,g=g+_>>>0}return r.endian([f,u,h,g])};c._ff=function(d,m,l,p,f,u,h){var g=d+(m&l|~m&p)+(f>>>0)+h;return(g<>>32-u)+m},c._gg=function(d,m,l,p,f,u,h){var g=d+(m&p|l&~p)+(f>>>0)+h;return(g<>>32-u)+m},c._hh=function(d,m,l,p,f,u,h){var g=d+(m^l^p)+(f>>>0)+h;return(g<>>32-u)+m},c._ii=function(d,m,l,p,f,u,h){var g=d+(l^(m|~p))+(f>>>0)+h;return(g<>>32-u)+m},c._blocksize=16,c._digestsize=16,e.exports=function(d,m){if(d==null)throw new Error("Illegal argument "+d);var l=r.wordsToBytes(c(d,m));return m&&m.asBytes?l:m&&m.asString?o.bytesToString(l):r.bytesToHex(l)}})()}}),ee={};Bt(ee,{default:()=>Tr}),st.exports=Ye(ee);var Yr=ot(ft()),Zr=ot(ft()),re={};Bt(re,{Attribute:()=>xt,AttributeStatic:()=>pe,Boost:()=>$t,BoostObject:()=>wt,Currency:()=>Nt,CurrencyStatic:()=>ge,DEFAULT_ITERATIONS:()=>Ft,Decimal:()=>s,E:()=>wr,FORMATS:()=>pr,FormatTypeList:()=>er,Grid:()=>br,GridCell:()=>Ne,LRUCache:()=>Dt,ListNode:()=>ie,ST_NAMES:()=>ct,UpgradeData:()=>pt,UpgradeStatic:()=>de,calculateSum:()=>Vt,calculateSumApprox:()=>ce,calculateSumLoop:()=>fe,calculateUpgrade:()=>he,decimalToJSONString:()=>me,equalsTolerance:()=>Zt,formats:()=>mt,inverseFunctionApprox:()=>zt,roundingBase:()=>yr,upgradeToCacheNameEL:()=>vr});var zr=ot(ft()),Dt=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 ie(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}}},ie=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 We=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===G.CLASS_TO_CLASS||i===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===G.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(f){return f.propertyName!==void 0}));for(var o=[],c=0,d=this.getAncestors(r);c0&&(c=c.filter(function(f){return!l.includes(f)})),this.options.version!==void 0&&(c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkVersion(u.options.since,u.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkGroups(u.options.groups)}):c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options||!u.options.groups||!u.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(c=c.filter(function(p){return n.options.excludePrefixes.every(function(f){return p.substr(0,f.length)!==f})})),c=c.filter(function(p,f,u){return u.indexOf(p)===f}),c},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(v.equals(0))return I;if(v.gt(0)&&v.lte(3)){let U=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(v.equals(0))return I;if(v.gt(0)&&v.lte(2)){let U=[];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)),v=["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=v[M].toUpperCase():I+=v[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(),v=Math.floor(S)+1,I=e.elemental.abbreviationLength(v),_=S-v+1,M=Math.floor(_*I),C=e.elemental.getAbbreviation(v,_),F=new t(118).pow(v+M/I-1);return[C,F]},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 v=a.log(118),_=v.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),C=[];for(;v.gte(1)&&C.length=M)return C.map(U=>e.elemental.formatElementalPart(U[0],U[1])).join(" + ");let F=new t(118).pow(v).toFixed(C.length===1?3:S);return C.length===0?F:C.length===1?`${F} \xD7 ${e.elemental.formatElementalPart(C[0][0],C[0][1])}`:`${F} \xD7 (${C.map(U=>e.elemental.formatElementalPart(U[0],U[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let v=a.log10().floor();if(v.lt(9))return v.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(v));return(v.log10().gte(9)?"":I.toFixed(4))+"e"+e.old_sc.format(v,0)}}},eng:{format(a,S=2){a=new t(a);let v=a.log10().floor();if(v.lt(9))return v.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(v.div(3).floor()));return(v.log10().gte(9)?"":I.toFixed(new t(4).sub(v.sub(v.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(v.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,v=9){a=new t(a);let I=a.log10().floor();return I.lt(303)&&I.gte(v)?m(a,S,v,"st"):m(a,S,v,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,v){a=new t(a);let I=a.max(1).log10().max(1).log(r.log10()).floor();if(I.lte(0))return m(a,S,v,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return m(a,Math.max(4,S),v,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+m(_,0,v,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ct[0][0][a%10]+ct[0][1][Math.floor(a/10)%10]+ct[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,v=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ct[1][0][a]:(v==1&&S==0?_+="Vec":_+=ct[1][1][S]+ct[1][2][v],_+=ct[1][3][I],_)}},inf:{format(a,S,v){a=new t(a);let I=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],C=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?m(a,S,v,"sc"):a.gte(3)?C[I]+M[I]+"\u03C9^"+m(a.sub(1),S,v,"sc"):a.gte(2)?C[I]+"\u03C9"+M[I]+"-"+m(_.pow(a.sub(2)),S,v,"sc"):C[I]+M[I]+"-"+m(_.pow(a.sub(1)),S,v,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),v=!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,C=a.log(1e3).sub(S.log(1e3)).floor(),F=C.add(1).log(M+1).ceil(),U="",z=(K,it)=>{let H=K,Z="";for(let W=0;W=M)return"\u03C9";Z=_[dt]+Z,H=H.sub(1).div(M).floor()}return Z};if(F.lt(I))U=z(C,F);else{let K=F.sub(I).add(1),it=C.div(t.pow(M+1,K.sub(1))).floor();U=`${z(it,new t(I))}(${K.gt("1e9")?K.format():K.format(0)})`}return U},format(a,S=2,v=9,I="mixed_sc",_=new t(1e15),M=!1,C){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return m(a,S,v,I);let F=e.alphabet.getAbbreviation(a,_,M,C),U=a.div(t.pow(1e3,a.log(1e3).floor()));return`${F.length>(C??9)+2?"":U.toFixed(S)+" "}${F}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function d(a,S=2,v=9,I="st"){return m(a,S,v,I)}function m(a,S=2,v=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 C=a.log10().ceil(),F=a.div(C.eq(-1)?new t(.1):t.dTen.pow(C)),U=C.mul(-1).max(1).log10().gte(9);return _+(U?"":F.toFixed(2))+"e"+m(C,0,v,"mixed_sc")}else if(M.lt(v)){let C=Math.max(Math.min(S-M.toNumber(),S),0);return _+(C>0?a.toFixed(C):a.toFixed(C).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let U=a.slog();return(U.gte(1e9)?"":t.dTen.pow(U.sub(U.floor())).toFixed(2))+"F"+m(U.floor(),0)}let C=a.div(t.dTen.pow(M)),F=M.log10().gte(9);return _+(F?"":C.toFixed(2))+"e"+m(M,0,v,"mixed_sc")}case"st":case"standard":{let C=a.log(1e3).floor();if(C.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let F=C.mul(3),U=C.log10().floor();if(U.gte(3e3))return"e"+m(M,S,v,"st");let z="";if(C.lt(4))z=["","K","M","B"][Math.round(C.toNumber())];else{let H=Math.floor(C.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),C=C.sub(1).div(t.dTen.pow(H*3));C.gt(0);){let Z=C.div(1e3).floor(),W=C.sub(Z.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)),C=Z,H++}}let K=a.div(t.dTen.pow(F)),it=S===2?t.dTwo.sub(M.sub(F)).add(1).toNumber():S;return _+(U.gte(10)?"":K.toFixed(it)+" ")+z}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,v)}}function l(a,S,v="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),C,F=M.div(a);return F.gte(10)&&a.gte(1e100)?(F=F.log10().mul(20),C="(+"+m(F,I,_,v)+" OoMs/sec)"):C="(+"+m(S,I,_,v)+"/sec)",C}function p(a,S=2,v="s"){return a=new t(a),a.gte(86400)?m(a.div(86400).floor(),0,12,"sc")+":"+p(a.mod(86400),S,"d"):a.gte(3600)||v=="d"?(a.div(3600).gte(10)||v!="d"?"":"0")+m(a.div(3600).floor(),0,12,"sc")+":"+p(a.mod(3600),S,"h"):a.gte(60)||v=="h"?(a.div(60).gte(10)||v!="h"?"":"0")+m(a.div(60).floor(),0,12,"sc")+":"+p(a.mod(60),S,"m"):(a.gte(10)||v!="m"?"":"0")+m(a,S,12,"sc")}function f(a,S=!1,v=0,I=9,_="mixed_sc"){let M=qt=>m(qt,v,I,_);a=new t(a);let C=a.mul(1e3).mod(1e3).floor(),F=a.mod(60).floor(),U=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",Z=K.eq(1)?" day":" days",W=z.eq(1)?" hour":" hours",dt=U.eq(1)?" minute":" minutes",Lt=F.eq(1)?" second":" seconds",kt=C.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?M(it)+H+", ":""}${K.gt(0)?M(K)+Z+", ":""}${z.gt(0)?M(z)+W+", ":""}${U.gt(0)?M(U)+dt+", ":""}${F.gt(0)?M(F)+Lt+",":""}${S&&C.gt(0)?" "+M(C)+kt:""}`.replace(/,([^,]*)$/,"$1").trim()}function u(a){return a=new t(a),m(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),m(a.mul(100))+"%"}function g(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function N(a,S,v=10){return t.gte(a,10)?t.pow(v,t.log(a,v).pow(S)):new t(a)}function A(a,S=0){a=new t(a);let v=(C=>C.map((F,U)=>({name:F.name,altName:F.altName,value:t.pow(1e3,new t(U).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),v.length-1).floor().toNumber(),M=v[_];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 x(a,S=!1){return`${A(a,2)} ${A(a,1)}eV${S?"/c^2":""}`}let P={...e,toSubscript:o,toSuperscript:c,formatST:d,format:m,formatGain:l,formatTime:p,formatTimeLong:f,formatReduction:u,formatPercent:h,formatMult:g,expMult:N,metric:A,ev:x};return{FORMATS:e,formats:P}}var jt=17,ir=9e15,nr=Math.log10(9e15),sr=1/9e15,or=308,ar=-324,ae=5,ur=1023,lr=!0,fr=!1,cr=function(){let t=[];for(let r=ar+1;r<=or;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),gt=[2,Math.E,3,4,5,6,7,8,9,10],hr=[[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]],mr=[[-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)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},ht=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},dr=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},gr=.36787944117144233,ue=.5671432904097838,Gt=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 ue;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),D(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),c=o.pow(2);return o.neg().add(c.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=ir)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);lr?t=t.replace(",",""):fr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let N=parseFloat(n[0]),A=parseFloat(n[1]),x=n[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(A)){let a=s.pentate(N,A,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let N=parseFloat(o[0]),A=parseFloat(o[1]),x=o[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(A)){let a=s.tetrate(N,A,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let N=parseFloat(c[0]),A=parseFloat(c[1]);if(isFinite(N)&&isFinite(A)){let x=s.pow(N,A);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let d,m,l=t.split("pt");if(l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),m=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let A=parseFloat(l[1]);if(isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}if(l=t.split("p"),l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),m=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let A=parseFloat(l[1]);if(isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}if(l=t.split("f"),l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let A=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),m=parseFloat(l[1]),isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}let p=t.split("e"),f=p.length-1;if(f===0){let N=parseFloat(t);if(isFinite(N))return this.fromNumber(N),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(f===1){let N=parseFloat(t);if(isFinite(N)&&N!==0)return this.fromNumber(N),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let u=t.split("e^");if(u.length===2){this.sign=1,u[0].startsWith("-")&&(this.sign=-1);let N="";for(let A=0;A=43&&x<=57||x===101)N+=u[1].charAt(A);else return this.layer=parseFloat(N),this.mag=parseFloat(u[1].substr(A+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(p[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 g=parseFloat(p[p.length-1]);if(f>=2){let N=parseFloat(p[p.length-2]);isFinite(N)&&(g*=Math.sign(N),g+=Ut(N))}if(!isFinite(h))this.sign=p[0]==="-"?-1:1,this.layer=f,this.mag=g;else if(f===1)this.sign=Math.sign(h),this.layer=1,this.mag=g+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=f,f===2){let N=s.mul(D(1,2,g),w(h));return this.sign=N.sign,this.layer=N.layer,this.mag=N.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=g;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ht(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ht(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ht(this.m,t)+"e"+ht(this.e,t):this.layer===1?ht(this.m,t)+"e"+ht(this.e,t):this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=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))>jt)return r;{let c=Math.pow(10,Math.log10(r.mag)-i.mag),d=i.sign+r.sign*c;return D(Math.sign(d),1,i.mag+Math.log10(Math.abs(d)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>jt)return r;{let c=Math.pow(10,r.mag-Math.log10(i.mag)),d=i.sign+r.sign*c;return D(Math.sign(d),1,Math.log10(i.mag)+Math.log10(Math.abs(d)))}}if(Math.abs(r.mag-i.mag)>jt)return r;{let c=Math.pow(10,r.mag-i.mag),d=i.sign+r.sign*c;return D(Math.sign(d),1,i.mag+Math.log10(Math.abs(d)))}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 D(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return D(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return D(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=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?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=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=Ut(n)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=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?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=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 D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return 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(dr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,c=e+o;if(c===e||(e=c,i=i*r,n=360*i,o=1/n,c=e-o,c===e))return s.exp(e);e=c,i=i*r,n=1260*i;let d=1/n;return e=e+d,i=i*r,n=1680*i,d=1/n,e=e-d,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?T(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?D(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?D(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):D(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return D(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(T(this.sign,this.layer-1,this.mag),T(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=T(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return T(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let c=s.ln(this).neg(),d=c.lambertw().div(c);if(o<1)return d;let m=c.lambertw(!1).div(c);return o>1.444667861009099&&(d=m=s.fromNumber(Math.E)),e=w(e),e.eq(m)?m:e.lt(m)?d:T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let c=0;c1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=w(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let c=Math.min(e,i.layer-t.layer-3);e-=c,i.layer-=c}for(let c=0;c1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let d=1;d1&&o!=l&&(n=!0),o=l,n?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),c+=i,i===0)break}return s.fromNumber(c)}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,mr)}static tetrate_critical(t,e){return s.critical_section(t,e,hr)}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 d=0;dt){let m=(t-gt[d])/(gt[d+1]-gt[d]);n=r[d][Math.floor(e)]*(1-m)+r[d+1][Math.floor(e)]*m,o=r[d][Math.ceil(e)]*(1-m)+r[d+1][Math.ceil(e)]*m;break}let c=e-Math.floor(e);return n<=0||o<=0?n*(1-c)+o*c:Math.pow(t,Math.log(n)/Math.log(t)*(1-c)+Math.log(o)/Math.log(t)*c)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=w(e);if(i.gt(1)&&i.lte(1.444667861009766)){let c=s.excess_slog(this,e,r),d=c[0].toNumber(),m=c[1],l=d+t,p=s.ln(e).neg(),f=p.lambertw().div(p),u=p.lambertw(!1).div(p),h=s.dOne;m==1?h=f.mul(u).sqrt():m==2&&(h=u.mul(2));let g=i.pow(h),N=Math.floor(l),A=l-N,x=h.pow(1-A).mul(g.pow(A));return s.tetrate(i,N,x,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),c=s.dInf;if(e>1&&(c=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=c=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(c))return[T(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(c)){let d=c.mul(2),m=i.pow(d),l=0;if(t.gte(d)&&t.lt(m))l=0;else if(t.gte(m)){let N=m;for(l=1;N.lt(t);)if(N=i.pow(N),l=l+1,N.layer>3){let A=Math.floor(t.layer-N.layer+1);N=i.iteratedexp(A,N,r),l=l+A}N.gt(t)&&(N=N.log(e),l=l-1)}else if(t.lt(d)){let N=d;for(l=0;N.gt(t);)N=N.log(e),l=l-1}let p=0,f=0,u=.5,h=d,g=s.dZero;for(;u>1e-16;){if(f=p+u,h=d.pow(1-f).mul(m.pow(f)),g=s.iteratedexp(e,l,h),g.eq(t))return[new s(l+f),2];g.lt(t)&&(p+=u),u/=2}return g.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+p),2]}if(t.lt(c)&&t.gt(o)){let d=o.mul(c).sqrt(),m=i.pow(d),l=0;if(t.lte(d)&&t.gt(m))l=0;else if(t.lte(m)){let N=m;for(l=1;N.gt(t);)N=i.pow(N),l=l+1;N.lt(t)&&(N=N.log(e),l=l-1)}else if(t.gt(d)){let N=d;for(l=0;N.lt(t);)N=N.log(e),l=l-1}let p=0,f=0,u=.5,h=d,g=s.dZero;for(;u>1e-16;){if(f=p+u,h=d.pow(1-f).mul(m.pow(f)),g=s.iteratedexp(e,l,h),g.eq(t))return[new s(l+f),1];g.gt(t)&&(p+=u),u/=2}return g.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+p),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(Gt(this.toNumber())):this.layer===0?s.fromNumber(Gt(this.sign*this.mag)):this.lt("eee15")?le(this):this.ln():this.sign===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Gt(this.sign*this.mag,1e-10,!1)):this.layer==1?le(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 egr?this.pow(this.recip()):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return T(1,0,1);if(this.lt(0))return T(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):T(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,c=n.div(2),d=!0;for(;d;)c=r.add(n).div(2),s.iteratedexp(10,i,c,!0).tetrate(t,1,!0).gt(this)?n=c:r=c,c.eq(o)?d=!1:o=c;return s.iteratedexp(10,i,c,!0)}else{let e=1,r=D(1,10,1),i=D(1,10,1),n=D(1,10,1),o=D(1,1,-16),c=s.dZero,d=D(1,10,1),m=o.pow10().recip(),l=s.dZero,p=m,f=m,u=Math.ceil(t)%2==0,h=0,g=D(1,10,1),N=!1,A=s.dZero,x=!1;for(;e<4;){if(e==2){if(u)break;n=D(1,10,1),o=r,e=3,d=D(1,10,1),g=D(1,10,1)}for(N=!1;o.neq(n);){if(A=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))m=o.pow10().recip(),p=o.pow10().recip(),f=o.pow10().recip(),l=s.dZero,h=-1,e==3&&(g=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!u&&o.pow10().recip().lt(.4))m=o.pow10().recip(),p=o.pow10().recip(),f=o.pow10().recip(),l=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))m=o.pow10().recip(),p=s.dZero,f=m.mul(2),l=m,u?h=-1:h=0;else{for(c=o.mul(12e-17),m=o.pow10().recip(),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);p.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||f.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||p.gte(m)||f.lte(m);)c=c.mul(2),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);if((e==1&&f.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&p.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&p.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(g=o),f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))h=-1;else if(u)h=1;else if(e==3&&o.gt_tolerance(r,1e-8))h=0;else{for(;p.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||f.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||p.gte(m)||f.lte(m);)c=c.mul(2),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);f.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(p.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(x=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(D(1,10,1)))o=o.mul(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),o=o.add(n).div(2),v)break}else if(n.eq(D(1,10,1)))n=o,o=o.div(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),n=n.sub(d),o=o.sub(d),v)break}if(n.sub(o).div(2).abs().gt(d.mul(1.5))&&(N=!0),d=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(A))break}if(o.gt("1e18")||!x||g==D(1,10,1))break;e==1?r=g:e==3&&(i=g),e++}n=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(i.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(n=D(1,10,1),o=i,P=o,a=s.dZero,S=!0;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=T(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):T(0,0,0)}cos(){return this.mag<0?T(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):T(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):T(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?T(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return mt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return mt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return mt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return mt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return mt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return mt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let c=Math.floor(r/i[o]);r-=c*i[o],n+=o.repeat(c)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=T(0,0,0),s.dOne=T(1,0,1),s.dNegOne=T(-1,0,1),s.dTwo=T(1,0,2),s.dTen=T(1,0,10),s.dNaN=T(Number.NaN,Number.NaN,Number.NaN),s.dInf=T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=D(1,0,Number.MAX_VALUE),s.dNumberMin=D(1,0,Number.MIN_VALUE),s.fromStringCache=new Dt(ur),ut([Et()],s.prototype,"sign",2),ut([Et()],s.prototype,"mag",2),ut([Et()],s.prototype,"layer",2),s=ut([tr()],s);var{formats:mt,FORMATS:pr}=rr(s);s.formats=mt;var wt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},$t=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 wt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nf),l=n,p=this.getBoosts(o,!0);p[0][0]?this.boostArray[p[1][0]]=new wt({id:o,name:c,description:d,value:m,order:l}):this.boostArray.push(new wt({id:o,name:c,description:d,value:m,order:l}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let c=this.getBoosts(o.id,!0);c[0][0]?this.boostArray[c[1][0]]=new wt(o):this.boostArray.push(new wt(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}},Vr=ot(ft()),Ft=30,Yt=.001;function Nr(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 Zt(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 zt(t,e,r="geometric",i=Ft,n=Yt){let o=s.dOne,c=new s(e);if(t(c).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(c).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:c,lowerBound:c,upperBound:c};for(let m=0;m=0;d--){let m=r.add(c.mul(d)),l=r.add(c.mul(d+1)),p=o;if(o=o.add(t(m).add(t(l)).div(2).mul(c)),Zt(p,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Vt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(Ft)?fe(t,e,r,i):ce(t,e,r,n)}function yr(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 he(t,e,r,i=1/0,n,o,c=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let d=i.sub(r);if(d.lt(0))return console.warn("calculateUpgrade: Invalid target: ",d),[s.dZero,s.dZero];if(c=(typeof e.el=="function"?e.el():e.el)??c,d.eq(1)){let f=e.cost(e.level),u=t.gte(f),h=[s.dZero,s.dZero];return c?(h[0]=u?s.dOne:s.dZero,h):(h=[u?s.dOne:s.dZero,u?f:s.dZero],h)}if(e.costBulk){let[f,u]=e.costBulk(t,e.level,d),h=t.gte(u);return[h?f:s.dZero,h&&!c?u:s.dZero]}if(c){let f=g=>e.cost(g.add(r)),u=s.min(i,zt(f,t,n,o).value.floor()),h=s.dZero;return[u,h]}let m=zt(f=>Vt(e.cost,f,r),t,n,o).value.floor().min(r.add(d).sub(1)),l=Vt(e.cost,m,r);return[m.sub(r).add(1).max(0),l]}function me(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function vr(t){return`el/${me(t)}`}var pt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};ut([Et()],pt.prototype,"id",2),ut([Ct(()=>s)],pt.prototype,"level",2);var de=class Be{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}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){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new Dt(i??Be.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}},Hr=ot(ft()),Nt=class{constructor(){this.value=s.dZero,this.upgrades={}}};ut([Ct(()=>s)],Nt.prototype,"value",2),ut([Ct(()=>pt)],Nt.prototype,"upgrades",2);var ge=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Nt,e,r={defaultVal:s.dZero,defaultBoost:s.dOne}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new $t(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=new s(i.defaultLevel),r&&i.effect?.(i.level,i,this)}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 pt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let n=this.pointerAddUpgrade(i),o=new de(i,()=>this.pointerGetUpgrade(i.id));o.effect&&e&&o.effect(o.level,o,this),r[i.id]=o,this.upgrades[i.id]=o}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}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)),he(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),n.level=n.level.add(o),n.effect?.(n.level,n,this),!0)}},Wr=ot(ft()),xt=class{constructor(t=0){this.value=new s(t)}};ut([Ct(()=>s)],xt.prototype,"value",2);var pe=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new xt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new $t(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}},Ne=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},br=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{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})(),Mr=re,ye={};Bt(ye,{ConfigManager:()=>Pt,DataManager:()=>_e,EventManager:()=>we,EventTypes:()=>be,Game:()=>Or,GameAttribute:()=>Ie,GameCurrency:()=>Se,GameReset:()=>Wt,KeyManager:()=>ve,gameDefaultConfig:()=>Oe,keys:()=>Sr});var Xr=ot(ft()),Pt=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}},_r={autoAddInterval:!0,fps:30},Sr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),ve=class De{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=De.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 Pt(_r)}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)}}},be=(t=>(t.interval="interval",t.timeout="timeout",t))(be||{}),Ir={autoAddInterval:!0,fps:30},we=class Re{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=Re.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 Pt(Ir)}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]}},Jr=ot(ft()),Me=ot(Ze()),Ht=ot(He()),_e=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,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.0.1"}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,Me.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,Me.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,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Ht.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(p){return typeof p=="object"&&p?.constructor===Object}let n=(p,f)=>Object.prototype.hasOwnProperty.call(p,f);function o(p,f,u){if(!p||!f||!u)throw new Error("dataManager.deepMerge(): Missing arguments.");let h=u;for(let g in p)if(n(p,g)&&!n(u,g)&&(h[g]=p[g]),f[g]instanceof Nt){let N=p[g],A=u[g];if(Array.isArray(A.upgrades)){let x=A.upgrades;A.upgrades={};for(let P of x)A.upgrades[P.id]=P}A.upgrades={...N.upgrades,...A.upgrades},h[g]=A}else i(p[g])&&i(u[g])&&(h[g]=o(p[g],f[g],u[g]));return h}let c=e?o(this.normalDataPlain,this.normalData,r):r,d=Object.getOwnPropertyNames(new pt({id:"",level:s.dZero}));function m(p,f){let u=oe(p,f);if(u instanceof Nt)for(let h in u.upgrades){let g=u.upgrades[h];if(!g||!d.every(N=>Object.getOwnPropertyNames(g).includes(N))){delete u.upgrades[h];continue}u.upgrades[h]=oe(pt,g)}if(!u)throw new Error(`Failed to convert ${p.name} to class instance.`);return u}function l(p,f){if(!p||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let u=f;for(let h in p){if(f[h]===void 0){console.warn(`Missing property "${h}" in loaded data.`);continue}if(!i(f[h]))continue;let g=p[h].constructor;if(g===Object){u[h]=l(p[h],f[h]);continue}u[h]=m(g,f[h])}return u}return c=l(this.normalData,c),c}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],Rt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Se=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}},Ie=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}},Wt=class je{static fromObject(e){return new je(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()}},Oe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Or=class Ue{static{this.configManager=new Pt(Oe)}constructor(e){this.config=Ue.configManager.parse(e),this.dataManager=new _e(this),this.keyManager=new ve({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new we({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 Nt}),this.dataManager.setStatic(e,{currency:new ge(()=>this.dataManager.getData(e).currency,r)}),new Se(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new xt(i)),this.dataManager.setStatic(e,new pe(this.dataManager.getData(e),r,i)),new Ie(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new Wt(...e)}addResetFromObject(e){return Wt.fromObject(e)}},Ar={...Mr,...ye},Tr=Ar;if(typeof st.exports=="object"&&typeof St=="object"){var Er=(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};st.exports=Er(st.exports,St)}return st.exports}); +"use strict";(function(St,st){var At=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],st);else if(typeof module=="object"&&module.exports)module.exports=st();else{var lt=st(),Tt=At?exports:St;for(var It in lt)Tt[It]=lt[It]}})(typeof self<"u"?self:exports,()=>{var St={},st={exports:St},At=Object.create,lt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,It=Object.getOwnPropertyNames,Ge=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,yt=(t,e)=>function(){return e||(0,t[It(t)[0]])((e={exports:{}}).exports,e),e.exports},Bt=(t,e)=>{for(var r in e)lt(t,r,{get:e[r],enumerable:!0})},Kt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of It(e))!$e.call(t,n)&&n!==r&<(t,n,{get:()=>e[n],enumerable:!(i=Tt(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?At(Ge(t)):{},Kt(e||!t||!t.__esModule?lt(r,"default",{value:t,enumerable:!0}):r,t)),Ye=t=>Kt(lt({},"__esModule",{value:!0}),t),ut=(t,e,r,i)=>{for(var n=i>1?void 0:i?Tt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&<(e,r,n),n},ft=yt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(l,p){return function(f,u){Object.defineProperty(l,f,{configurable:!0,writable:!0,value:u}),p&&p(f,u)}}function c(){try{return Function("return this;")()}catch{}}function d(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return c()||d()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",c=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",d=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",l={__proto__:[]}instanceof Array,p=!m&&!l,f={create:m?function(){return Qt(Object.create(null))}:l?function(){return Qt({__proto__:null})}:function(){return Qt({})},has:p?function(y,b){return n.call(y,b)}:function(y,b){return b in y},get:p?function(y,b){return n.call(y,b)?y[b]:void 0}:function(y,b){return y[b]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Rr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:jr(),N=typeof WeakMap=="function"?WeakMap:Ur(),A=o?Symbol.for("@reflect-metadata:registry"):void 0,x=qr(),P=Br(x);function a(y,b,O,E){if(j(O)){if(!Ee(y))throw new TypeError;if(!Ce(b))throw new TypeError;return K(y,b)}else{if(!Ee(y))throw new TypeError;if(!X(b))throw new TypeError;if(!X(E)&&!j(E)&&!Mt(E))throw new TypeError;return Mt(E)&&(E=void 0),O=at(O),it(y,b,O,E)}}r("decorate",a);function S(y,b){function O(E,R){if(!X(E))throw new TypeError;if(!j(R)&&!kr(R))throw new TypeError;kt(y,b,E,R)}return O}r("metadata",S);function v(y,b,O,E){if(!X(O))throw new TypeError;return j(E)||(E=at(E)),kt(y,b,O,E)}r("defineMetadata",v);function I(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),H(y,b,O)}r("hasMetadata",I);function _(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),Z(y,b,O)}r("hasOwnMetadata",_);function M(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),W(y,b,O)}r("getMetadata",M);function C(y,b,O){if(!X(b))throw new TypeError;return j(O)||(O=at(O)),dt(y,b,O)}r("getOwnMetadata",C);function F(y,b){if(!X(y))throw new TypeError;return j(b)||(b=at(b)),Lt(y,b)}r("getMetadataKeys",F);function U(y,b){if(!X(y))throw new TypeError;return j(b)||(b=at(b)),qt(y,b)}r("getOwnMetadataKeys",U);function z(y,b,O){if(!X(b))throw new TypeError;if(j(O)||(O=at(O)),!X(b))throw new TypeError;j(O)||(O=at(O));var E=Ot(b,O,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(y,b,O)}r("deleteMetadata",z);function K(y,b){for(var O=y.length-1;O>=0;--O){var E=y[O],R=E(b);if(!j(R)&&!Mt(R)){if(!Ce(R))throw new TypeError;b=R}}return b}function it(y,b,O,E){for(var R=y.length-1;R>=0;--R){var J=y[R],tt=J(b,O,E);if(!j(tt)&&!Mt(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(y,b,O){var E=Z(y,b,O);if(E)return!0;var R=Jt(b);return Mt(R)?!1:H(y,R,O)}function Z(y,b,O){var E=Ot(b,O,!1);return j(E)?!1:Te(E.OrdinaryHasOwnMetadata(y,b,O))}function W(y,b,O){var E=Z(y,b,O);if(E)return dt(y,b,O);var R=Jt(b);if(!Mt(R))return W(y,R,O)}function dt(y,b,O){var E=Ot(b,O,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(y,b,O)}function kt(y,b,O,E){var R=Ot(O,E,!0);R.OrdinaryDefineOwnMetadata(y,b,O,E)}function Lt(y,b){var O=qt(y,b),E=Jt(y);if(E===null)return O;var R=Lt(E,b);if(R.length<=0)return O;if(O.length<=0)return R;for(var J=new g,tt=[],$=0,k=O;$=0&&k=this._keys.length?(this._index=-1,this._keys=b,this._values=b):this._index++,{value:L,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(k){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),k},$.prototype.return=function(k){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:k,done:!0}},$}(),E=function(){function $(){this._keys=[],this._values=[],this._cacheKey=y,this._cacheIndex=-2}return Object.defineProperty($.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),$.prototype.has=function(k){return this._find(k,!1)>=0},$.prototype.get=function(k){var L=this._find(k,!1);return L>=0?this._values[L]:void 0},$.prototype.set=function(k,L){var q=this._find(k,!0);return this._values[q]=L,this},$.prototype.delete=function(k){var L=this._find(k,!1);if(L>=0){for(var q=this._keys.length,B=L+1;B>>8,f[u*2+1]=g%256}return f},decompressFromUint8Array:function(l){if(l==null)return m.decompress(l);for(var p=new Array(l.length/2),f=0,u=p.length;f>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,v),v++),delete N[P]}else for(h=g[P],u=0;u>1;a--,a==0&&(a=Math.pow(2,v),v++),g[x]=S++,P=String(A)}if(P!==""){if(Object.prototype.hasOwnProperty.call(N,P)){if(P.charCodeAt(0)<256){for(u=0;u>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,v),v++),delete N[P]}else for(h=g[P],u=0;u>1;a--,a==0&&(a=Math.pow(2,v),v++)}for(h=2,u=0;u>1;for(;;)if(_=_<<1,M==p-1){I.push(f(_));break}else M++;return I.join("")},decompress:function(l){return l==null?"":l==""?null:m._decompress(l.length,32768,function(p){return l.charCodeAt(p)})},_decompress:function(l,p,f){var u=[],h,g=4,N=4,A=3,x="",P=[],a,S,v,I,_,M,C,F={val:f(0),position:p,index:1};for(a=0;a<3;a+=1)u[a]=a;for(v=0,_=Math.pow(2,2),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;switch(h=v){case 0:for(v=0,_=Math.pow(2,8),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;C=i(v);break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;C=i(v);break;case 2:return""}for(u[3]=C,S=C,P.push(C);;){if(F.index>l)return"";for(v=0,_=Math.pow(2,A),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;switch(C=v){case 0:for(v=0,_=Math.pow(2,8),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=i(v),C=N-1,g--;break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=F.val&F.position,F.position>>=1,F.position==0&&(F.position=p,F.val=f(F.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=i(v),C=N-1,g--;break;case 2:return P.join("")}if(g==0&&(g=Math.pow(2,A),A++),u[C])x=u[C];else if(C===N)x=S+S.charAt(0);else return null;P.push(x),u[N++]=S+x.charAt(0),g--,S=x,g==0&&(g=Math.pow(2,A),A++)}}};return m}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),ze=yt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],c=0,d=0;c>>5]|=n[c]<<24-d%32;return o},wordsToBytes:function(n){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(n){for(var o=[],c=0;c>>4).toString(16)),o.push((n[c]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],c=0;c>>6*(3-m)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,d=0;c>>6-d*2);return o}};e.exports=i})()}}),te=yt({"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|(l[N]<<24|l[N]>>>8)&4278255360;l[p>>>5]|=128<>>9<<4)+14]=p;for(var A=c._ff,x=c._gg,P=c._hh,a=c._ii,N=0;N>>0,u=u+v>>>0,h=h+I>>>0,g=g+_>>>0}return r.endian([f,u,h,g])};c._ff=function(d,m,l,p,f,u,h){var g=d+(m&l|~m&p)+(f>>>0)+h;return(g<>>32-u)+m},c._gg=function(d,m,l,p,f,u,h){var g=d+(m&p|l&~p)+(f>>>0)+h;return(g<>>32-u)+m},c._hh=function(d,m,l,p,f,u,h){var g=d+(m^l^p)+(f>>>0)+h;return(g<>>32-u)+m},c._ii=function(d,m,l,p,f,u,h){var g=d+(l^(m|~p))+(f>>>0)+h;return(g<>>32-u)+m},c._blocksize=16,c._digestsize=16,e.exports=function(d,m){if(d==null)throw new Error("Illegal argument "+d);var l=r.wordsToBytes(c(d,m));return m&&m.asBytes?l:m&&m.asString?o.bytesToString(l):r.bytesToHex(l)}})()}}),ee={};Bt(ee,{default:()=>Tr}),st.exports=Ye(ee);var Yr=ot(ft()),Zr=ot(ft()),re={};Bt(re,{Attribute:()=>xt,AttributeStatic:()=>pe,Boost:()=>$t,BoostObject:()=>wt,Currency:()=>Nt,CurrencyStatic:()=>ge,DEFAULT_ITERATIONS:()=>Ft,Decimal:()=>s,E:()=>wr,FORMATS:()=>pr,FormatTypeList:()=>er,Grid:()=>br,GridCell:()=>Ne,LRUCache:()=>Dt,ListNode:()=>ie,ST_NAMES:()=>ct,UpgradeData:()=>pt,UpgradeStatic:()=>de,calculateSum:()=>Vt,calculateSumApprox:()=>ce,calculateSumLoop:()=>fe,calculateUpgrade:()=>he,decimalToJSONString:()=>me,equalsTolerance:()=>Zt,formats:()=>mt,inverseFunctionApprox:()=>zt,roundingBase:()=>yr,upgradeToCacheNameEL:()=>vr});var zr=ot(ft()),Dt=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 ie(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}}},ie=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 We=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===G.CLASS_TO_CLASS||i===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===G.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(f){return f.propertyName!==void 0}));for(var o=[],c=0,d=this.getAncestors(r);c0&&(c=c.filter(function(f){return!l.includes(f)})),this.options.version!==void 0&&(c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkVersion(u.options.since,u.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkGroups(u.options.groups)}):c=c.filter(function(f){var u=et.findExposeMetadata(e,f);return!u||!u.options||!u.options.groups||!u.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(c=c.filter(function(p){return n.options.excludePrefixes.every(function(f){return p.substr(0,f.length)!==f})})),c=c.filter(function(p,f,u){return u.indexOf(p)===f}),c},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(v.equals(0))return I;if(v.gt(0)&&v.lte(3)){let U=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(v.equals(0))return I;if(v.gt(0)&&v.lte(2)){let U=[];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)),v=["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=v[M].toUpperCase():I+=v[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(),v=Math.floor(S)+1,I=e.elemental.abbreviationLength(v),_=S-v+1,M=Math.floor(_*I),C=e.elemental.getAbbreviation(v,_),F=new t(118).pow(v+M/I-1);return[C,F]},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 v=a.log(118),_=v.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),C=[];for(;v.gte(1)&&C.length=M)return C.map(U=>e.elemental.formatElementalPart(U[0],U[1])).join(" + ");let F=new t(118).pow(v).toFixed(C.length===1?3:S);return C.length===0?F:C.length===1?`${F} \xD7 ${e.elemental.formatElementalPart(C[0][0],C[0][1])}`:`${F} \xD7 (${C.map(U=>e.elemental.formatElementalPart(U[0],U[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let v=a.log10().floor();if(v.lt(9))return v.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(v));return(v.log10().gte(9)?"":I.toFixed(4))+"e"+e.old_sc.format(v,0)}}},eng:{format(a,S=2){a=new t(a);let v=a.log10().floor();if(v.lt(9))return v.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(v.div(3).floor()));return(v.log10().gte(9)?"":I.toFixed(new t(4).sub(v.sub(v.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(v.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,v=9){a=new t(a);let I=a.log10().floor();return I.lt(303)&&I.gte(v)?m(a,S,v,"st"):m(a,S,v,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,v){a=new t(a);let I=a.max(1).log10().max(1).log(r.log10()).floor();if(I.lte(0))return m(a,S,v,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return m(a,Math.max(4,S),v,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+m(_,0,v,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ct[0][0][a%10]+ct[0][1][Math.floor(a/10)%10]+ct[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,v=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ct[1][0][a]:(v==1&&S==0?_+="Vec":_+=ct[1][1][S]+ct[1][2][v],_+=ct[1][3][I],_)}},inf:{format(a,S,v){a=new t(a);let I=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],C=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?m(a,S,v,"sc"):a.gte(3)?C[I]+M[I]+"\u03C9^"+m(a.sub(1),S,v,"sc"):a.gte(2)?C[I]+"\u03C9"+M[I]+"-"+m(_.pow(a.sub(2)),S,v,"sc"):C[I]+M[I]+"-"+m(_.pow(a.sub(1)),S,v,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),v=!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,C=a.log(1e3).sub(S.log(1e3)).floor(),F=C.add(1).log(M+1).ceil(),U="",z=(K,it)=>{let H=K,Z="";for(let W=0;W=M)return"\u03C9";Z=_[dt]+Z,H=H.sub(1).div(M).floor()}return Z};if(F.lt(I))U=z(C,F);else{let K=F.sub(I).add(1),it=C.div(t.pow(M+1,K.sub(1))).floor();U=`${z(it,new t(I))}(${K.gt("1e9")?K.format():K.format(0)})`}return U},format(a,S=2,v=9,I="mixed_sc",_=new t(1e15),M=!1,C){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return m(a,S,v,I);let F=e.alphabet.getAbbreviation(a,_,M,C),U=a.div(t.pow(1e3,a.log(1e3).floor()));return`${F.length>(C??9)+2?"":U.toFixed(S)+" "}${F}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function d(a,S=2,v=9,I="st"){return m(a,S,v,I)}function m(a,S=2,v=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 C=a.log10().ceil(),F=a.div(C.eq(-1)?new t(.1):t.dTen.pow(C)),U=C.mul(-1).max(1).log10().gte(9);return _+(U?"":F.toFixed(2))+"e"+m(C,0,v,"mixed_sc")}else if(M.lt(v)){let C=Math.max(Math.min(S-M.toNumber(),S),0);return _+(C>0?a.toFixed(C):a.toFixed(C).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let U=a.slog();return(U.gte(1e9)?"":t.dTen.pow(U.sub(U.floor())).toFixed(2))+"F"+m(U.floor(),0)}let C=a.div(t.dTen.pow(M)),F=M.log10().gte(9);return _+(F?"":C.toFixed(2))+"e"+m(M,0,v,"mixed_sc")}case"st":case"standard":{let C=a.log(1e3).floor();if(C.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let F=C.mul(3),U=C.log10().floor();if(U.gte(3e3))return"e"+m(M,S,v,"st");let z="";if(C.lt(4))z=["","K","M","B"][Math.round(C.toNumber())];else{let H=Math.floor(C.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),C=C.sub(1).div(t.dTen.pow(H*3));C.gt(0);){let Z=C.div(1e3).floor(),W=C.sub(Z.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)),C=Z,H++}}let K=a.div(t.dTen.pow(F)),it=S===2?t.dTwo.sub(M.sub(F)).add(1).toNumber():S;return _+(U.gte(10)?"":K.toFixed(it)+" ")+z}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,v)}}function l(a,S,v="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),C,F=M.div(a);return F.gte(10)&&a.gte(1e100)?(F=F.log10().mul(20),C="(+"+m(F,I,_,v)+" OoMs/sec)"):C="(+"+m(S,I,_,v)+"/sec)",C}function p(a,S=2,v="s"){return a=new t(a),a.gte(86400)?m(a.div(86400).floor(),0,12,"sc")+":"+p(a.mod(86400),S,"d"):a.gte(3600)||v=="d"?(a.div(3600).gte(10)||v!="d"?"":"0")+m(a.div(3600).floor(),0,12,"sc")+":"+p(a.mod(3600),S,"h"):a.gte(60)||v=="h"?(a.div(60).gte(10)||v!="h"?"":"0")+m(a.div(60).floor(),0,12,"sc")+":"+p(a.mod(60),S,"m"):(a.gte(10)||v!="m"?"":"0")+m(a,S,12,"sc")}function f(a,S=!1,v=0,I=9,_="mixed_sc"){let M=qt=>m(qt,v,I,_);a=new t(a);let C=a.mul(1e3).mod(1e3).floor(),F=a.mod(60).floor(),U=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",Z=K.eq(1)?" day":" days",W=z.eq(1)?" hour":" hours",dt=U.eq(1)?" minute":" minutes",kt=F.eq(1)?" second":" seconds",Lt=C.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?M(it)+H+", ":""}${K.gt(0)?M(K)+Z+", ":""}${z.gt(0)?M(z)+W+", ":""}${U.gt(0)?M(U)+dt+", ":""}${F.gt(0)?M(F)+kt+",":""}${S&&C.gt(0)?" "+M(C)+Lt:""}`.replace(/,([^,]*)$/,"$1").trim()}function u(a){return a=new t(a),m(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),m(a.mul(100))+"%"}function g(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function N(a,S,v=10){return t.gte(a,10)?t.pow(v,t.log(a,v).pow(S)):new t(a)}function A(a,S=0){a=new t(a);let v=(C=>C.map((F,U)=>({name:F.name,altName:F.altName,value:t.pow(1e3,new t(U).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),v.length-1).floor().toNumber(),M=v[_];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 x(a,S=!1){return`${A(a,2)} ${A(a,1)}eV${S?"/c^2":""}`}let P={...e,toSubscript:o,toSuperscript:c,formatST:d,format:m,formatGain:l,formatTime:p,formatTimeLong:f,formatReduction:u,formatPercent:h,formatMult:g,expMult:N,metric:A,ev:x};return{FORMATS:e,formats:P}}var jt=17,ir=9e15,nr=Math.log10(9e15),sr=1/9e15,or=308,ar=-324,ae=5,ur=1023,lr=!0,fr=!1,cr=function(){let t=[];for(let r=ar+1;r<=or;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),gt=[2,Math.E,3,4,5,6,7,8,9,10],hr=[[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]],mr=[[-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)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},ht=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},dr=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},gr=.36787944117144233,ue=.5671432904097838,Gt=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 ue;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),D(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),c=o.pow(2);return o.neg().add(c.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=ir)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);lr?t=t.replace(",",""):fr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let N=parseFloat(n[0]),A=parseFloat(n[1]),x=n[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(A)){let a=s.pentate(N,A,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let N=parseFloat(o[0]),A=parseFloat(o[1]),x=o[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(A)){let a=s.tetrate(N,A,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let N=parseFloat(c[0]),A=parseFloat(c[1]);if(isFinite(N)&&isFinite(A)){let x=s.pow(N,A);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let d,m,l=t.split("pt");if(l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),m=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let A=parseFloat(l[1]);if(isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}if(l=t.split("p"),l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),m=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let A=parseFloat(l[1]);if(isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}if(l=t.split("f"),l.length===2){d=10;let N=!1;l[0].startsWith("-")&&(N=!0,l[0]=l[0].slice(1)),l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let A=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),m=parseFloat(l[1]),isFinite(A)||(A=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,A,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),N&&(this.sign*=-1),this}}let p=t.split("e"),f=p.length-1;if(f===0){let N=parseFloat(t);if(isFinite(N))return this.fromNumber(N),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(f===1){let N=parseFloat(t);if(isFinite(N)&&N!==0)return this.fromNumber(N),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let u=t.split("e^");if(u.length===2){this.sign=1,u[0].startsWith("-")&&(this.sign=-1);let N="";for(let A=0;A=43&&x<=57||x===101)N+=u[1].charAt(A);else return this.layer=parseFloat(N),this.mag=parseFloat(u[1].substr(A+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(p[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 g=parseFloat(p[p.length-1]);if(f>=2){let N=parseFloat(p[p.length-2]);isFinite(N)&&(g*=Math.sign(N),g+=Ut(N))}if(!isFinite(h))this.sign=p[0]==="-"?-1:1,this.layer=f,this.mag=g;else if(f===1)this.sign=Math.sign(h),this.layer=1,this.mag=g+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=f,f===2){let N=s.mul(D(1,2,g),w(h));return this.sign=N.sign,this.layer=N.layer,this.mag=N.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=g;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ht(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ht(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ht(this.m,t)+"e"+ht(this.e,t):this.layer===1?ht(this.m,t)+"e"+ht(this.e,t):this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=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))>jt)return r;{let c=Math.pow(10,Math.log10(r.mag)-i.mag),d=i.sign+r.sign*c;return D(Math.sign(d),1,i.mag+Math.log10(Math.abs(d)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>jt)return r;{let c=Math.pow(10,r.mag-Math.log10(i.mag)),d=i.sign+r.sign*c;return D(Math.sign(d),1,Math.log10(i.mag)+Math.log10(Math.abs(d)))}}if(Math.abs(r.mag-i.mag)>jt)return r;{let c=Math.pow(10,r.mag-i.mag),d=i.sign+r.sign*c;return D(Math.sign(d),1,i.mag+Math.log10(Math.abs(d)))}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 D(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return D(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return D(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=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?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=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=Ut(n)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=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?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=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 D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return 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(dr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,c=e+o;if(c===e||(e=c,i=i*r,n=360*i,o=1/n,c=e-o,c===e))return s.exp(e);e=c,i=i*r,n=1260*i;let d=1/n;return e=e+d,i=i*r,n=1680*i,d=1/n,e=e-d,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?T(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?D(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?D(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):D(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return D(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(T(this.sign,this.layer-1,this.mag),T(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=T(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return T(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let c=s.ln(this).neg(),d=c.lambertw().div(c);if(o<1)return d;let m=c.lambertw(!1).div(c);return o>1.444667861009099&&(d=m=s.fromNumber(Math.E)),e=w(e),e.eq(m)?m:e.lt(m)?d:T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let c=0;c1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=w(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let c=Math.min(e,i.layer-t.layer-3);e-=c,i.layer-=c}for(let c=0;c1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let d=1;d1&&o!=l&&(n=!0),o=l,n?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),c+=i,i===0)break}return s.fromNumber(c)}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,mr)}static tetrate_critical(t,e){return s.critical_section(t,e,hr)}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 d=0;dt){let m=(t-gt[d])/(gt[d+1]-gt[d]);n=r[d][Math.floor(e)]*(1-m)+r[d+1][Math.floor(e)]*m,o=r[d][Math.ceil(e)]*(1-m)+r[d+1][Math.ceil(e)]*m;break}let c=e-Math.floor(e);return n<=0||o<=0?n*(1-c)+o*c:Math.pow(t,Math.log(n)/Math.log(t)*(1-c)+Math.log(o)/Math.log(t)*c)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=w(e);if(i.gt(1)&&i.lte(1.444667861009766)){let c=s.excess_slog(this,e,r),d=c[0].toNumber(),m=c[1],l=d+t,p=s.ln(e).neg(),f=p.lambertw().div(p),u=p.lambertw(!1).div(p),h=s.dOne;m==1?h=f.mul(u).sqrt():m==2&&(h=u.mul(2));let g=i.pow(h),N=Math.floor(l),A=l-N,x=h.pow(1-A).mul(g.pow(A));return s.tetrate(i,N,x,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),c=s.dInf;if(e>1&&(c=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=c=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(c))return[T(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(c)){let d=c.mul(2),m=i.pow(d),l=0;if(t.gte(d)&&t.lt(m))l=0;else if(t.gte(m)){let N=m;for(l=1;N.lt(t);)if(N=i.pow(N),l=l+1,N.layer>3){let A=Math.floor(t.layer-N.layer+1);N=i.iteratedexp(A,N,r),l=l+A}N.gt(t)&&(N=N.log(e),l=l-1)}else if(t.lt(d)){let N=d;for(l=0;N.gt(t);)N=N.log(e),l=l-1}let p=0,f=0,u=.5,h=d,g=s.dZero;for(;u>1e-16;){if(f=p+u,h=d.pow(1-f).mul(m.pow(f)),g=s.iteratedexp(e,l,h),g.eq(t))return[new s(l+f),2];g.lt(t)&&(p+=u),u/=2}return g.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+p),2]}if(t.lt(c)&&t.gt(o)){let d=o.mul(c).sqrt(),m=i.pow(d),l=0;if(t.lte(d)&&t.gt(m))l=0;else if(t.lte(m)){let N=m;for(l=1;N.gt(t);)N=i.pow(N),l=l+1;N.lt(t)&&(N=N.log(e),l=l-1)}else if(t.gt(d)){let N=d;for(l=0;N.lt(t);)N=N.log(e),l=l-1}let p=0,f=0,u=.5,h=d,g=s.dZero;for(;u>1e-16;){if(f=p+u,h=d.pow(1-f).mul(m.pow(f)),g=s.iteratedexp(e,l,h),g.eq(t))return[new s(l+f),1];g.gt(t)&&(p+=u),u/=2}return g.neq_tolerance(t,1e-7)?[T(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+p),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(Gt(this.toNumber())):this.layer===0?s.fromNumber(Gt(this.sign*this.mag)):this.lt("eee15")?le(this):this.ln():this.sign===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Gt(this.sign*this.mag,1e-10,!1)):this.layer==1?le(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 egr?this.pow(this.recip()):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return T(1,0,1);if(this.lt(0))return T(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):T(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,c=n.div(2),d=!0;for(;d;)c=r.add(n).div(2),s.iteratedexp(10,i,c,!0).tetrate(t,1,!0).gt(this)?n=c:r=c,c.eq(o)?d=!1:o=c;return s.iteratedexp(10,i,c,!0)}else{let e=1,r=D(1,10,1),i=D(1,10,1),n=D(1,10,1),o=D(1,1,-16),c=s.dZero,d=D(1,10,1),m=o.pow10().recip(),l=s.dZero,p=m,f=m,u=Math.ceil(t)%2==0,h=0,g=D(1,10,1),N=!1,A=s.dZero,x=!1;for(;e<4;){if(e==2){if(u)break;n=D(1,10,1),o=r,e=3,d=D(1,10,1),g=D(1,10,1)}for(N=!1;o.neq(n);){if(A=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))m=o.pow10().recip(),p=o.pow10().recip(),f=o.pow10().recip(),l=s.dZero,h=-1,e==3&&(g=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!u&&o.pow10().recip().lt(.4))m=o.pow10().recip(),p=o.pow10().recip(),f=o.pow10().recip(),l=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))m=o.pow10().recip(),p=s.dZero,f=m.mul(2),l=m,u?h=-1:h=0;else{for(c=o.mul(12e-17),m=o.pow10().recip(),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);p.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||f.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||p.gte(m)||f.lte(m);)c=c.mul(2),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);if((e==1&&f.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&p.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&p.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(g=o),f.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))h=-1;else if(u)h=1;else if(e==3&&o.gt_tolerance(r,1e-8))h=0;else{for(;p.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||f.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||p.gte(m)||f.lte(m);)c=c.mul(2),p=o.add(c).pow10().recip(),l=m.sub(p),f=m.add(l);f.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(p.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(x=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(D(1,10,1)))o=o.mul(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),o=o.add(n).div(2),v)break}else if(n.eq(D(1,10,1)))n=o,o=o.div(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),n=n.sub(d),o=o.sub(d),v)break}if(n.sub(o).div(2).abs().gt(d.mul(1.5))&&(N=!0),d=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(A))break}if(o.gt("1e18")||!x||g==D(1,10,1))break;e==1?r=g:e==3&&(i=g),e++}n=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(i.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(n=D(1,10,1),o=i,P=o,a=s.dZero,S=!0;S;)if(n.eq(D(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(P)?S=!1:P=a,o.gt("1e18"))return T(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=T(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):T(0,0,0)}cos(){return this.mag<0?T(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):T(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):T(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):T(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?T(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return mt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return mt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return mt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return mt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return mt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return mt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let c=Math.floor(r/i[o]);r-=c*i[o],n+=o.repeat(c)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=T(0,0,0),s.dOne=T(1,0,1),s.dNegOne=T(-1,0,1),s.dTwo=T(1,0,2),s.dTen=T(1,0,10),s.dNaN=T(Number.NaN,Number.NaN,Number.NaN),s.dInf=T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=D(1,0,Number.MAX_VALUE),s.dNumberMin=D(1,0,Number.MIN_VALUE),s.fromStringCache=new Dt(ur),ut([Et()],s.prototype,"sign",2),ut([Et()],s.prototype,"mag",2),ut([Et()],s.prototype,"layer",2),s=ut([tr()],s);var{formats:mt,FORMATS:pr}=rr(s);s.formats=mt;var wt=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:()=>""}},$t=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 wt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nf),l=n,p=this.getBoosts(o,!0);p[0][0]?this.boostArray[p[1][0]]=new wt({id:o,name:c,description:d,value:m,order:l}):this.boostArray.push(new wt({id:o,name:c,description:d,value:m,order:l}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let c=this.getBoosts(o.id,!0);c[0][0]?this.boostArray[c[1][0]]=new wt(o):this.boostArray.push(new wt(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}},Vr=ot(ft()),Ft=30,Yt=.001;function Nr(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 Zt(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 zt(t,e,r="geometric",i=Ft,n=Yt){let o=s.dOne,c=new s(e);if(t(c).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(c).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:c,lowerBound:c,upperBound:c};for(let m=0;m=0;d--){let m=r.add(c.mul(d)),l=r.add(c.mul(d+1)),p=o;if(o=o.add(t(m).add(t(l)).div(2).mul(c)),Zt(p,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Vt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(Ft)?fe(t,e,r,i):ce(t,e,r,n)}function yr(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 he(t,e,r,i=1/0,n,o,c=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let d=i.sub(r);if(d.lt(0))return console.warn("calculateUpgrade: Invalid target: ",d),[s.dZero,s.dZero];if(c=(typeof e.el=="function"?e.el():e.el)??c,d.eq(1)){let f=e.cost(e.level),u=t.gte(f),h=[s.dZero,s.dZero];return c?(h[0]=u?s.dOne:s.dZero,h):(h=[u?s.dOne:s.dZero,u?f:s.dZero],h)}if(e.costBulk){let[f,u]=e.costBulk(t,e.level,d),h=t.gte(u);return[h?f:s.dZero,h&&!c?u:s.dZero]}if(c){let f=g=>e.cost(g.add(r)),u=s.min(i,zt(f,t,n,o).value.floor()),h=s.dZero;return[u,h]}let m=zt(f=>Vt(e.cost,f,r),t,n,o).value.floor().min(r.add(d).sub(1)),l=Vt(e.cost,m,r);return[m.sub(r).add(1).max(0),l]}function me(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function vr(t){return`el/${me(t)}`}var pt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};ut([Et()],pt.prototype,"id",2),ut([Ct(()=>s)],pt.prototype,"level",2);var de=class Be{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}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){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new Dt(i??Be.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}},Hr=ot(ft()),Nt=class{constructor(){this.value=s.dZero,this.upgrades={}}};ut([Ct(()=>s)],Nt.prototype,"value",2),ut([Ct(()=>pt)],Nt.prototype,"upgrades",2);var ge=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Nt,e,r={defaultVal:s.dZero,defaultBoost:s.dOne}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new $t(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=new s(i.defaultLevel),r&&i.effect?.(i.level,i,this)}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 pt(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 de(i,()=>this.pointerGetUpgrade(i.id));n.effect&&e&&n.effect(n.level,n,this),this.upgrades[i.id]=n,r.push(n)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}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)),he(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),n.level=n.level.add(o),n.effect?.(n.level,n,this),!0)}},Wr=ot(ft()),xt=class{constructor(t=0){this.value=new s(t)}};ut([Ct(()=>s)],xt.prototype,"value",2);var pe=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new xt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new $t(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}},Ne=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},br=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{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})(),Mr=re,ye={};Bt(ye,{ConfigManager:()=>Pt,DataManager:()=>_e,EventManager:()=>we,EventTypes:()=>be,Game:()=>Or,GameAttribute:()=>Ie,GameCurrency:()=>Se,GameReset:()=>Wt,KeyManager:()=>ve,gameDefaultConfig:()=>Oe,keys:()=>Sr});var Xr=ot(ft()),Pt=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}},_r={autoAddInterval:!0,fps:30},Sr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),ve=class De{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=De.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 Pt(_r)}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)}}},be=(t=>(t.interval="interval",t.timeout="timeout",t))(be||{}),Ir={autoAddInterval:!0,fps:30},we=class Re{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=Re.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 Pt(Ir)}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]}},Jr=ot(ft()),Me=ot(Ze()),Ht=ot(He()),_e=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,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.0.1"}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,Me.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,Me.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,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Ht.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(p){return typeof p=="object"&&p?.constructor===Object}let n=(p,f)=>Object.prototype.hasOwnProperty.call(p,f);function o(p,f,u){if(!p||!f||!u)throw new Error("dataManager.deepMerge(): Missing arguments.");let h=u;for(let g in p)if(n(p,g)&&!n(u,g)&&(h[g]=p[g]),f[g]instanceof Nt){let N=p[g],A=u[g];if(Array.isArray(A.upgrades)){let x=A.upgrades;A.upgrades={};for(let P of x)A.upgrades[P.id]=P}A.upgrades={...N.upgrades,...A.upgrades},h[g]=A}else i(p[g])&&i(u[g])&&(h[g]=o(p[g],f[g],u[g]));return h}let c=e?o(this.normalDataPlain,this.normalData,r):r,d=Object.getOwnPropertyNames(new pt({id:"",level:s.dZero}));function m(p,f){let u=oe(p,f);if(u instanceof Nt)for(let h in u.upgrades){let g=u.upgrades[h];if(!g||!d.every(N=>Object.getOwnPropertyNames(g).includes(N))){delete u.upgrades[h];continue}u.upgrades[h]=oe(pt,g)}if(!u)throw new Error(`Failed to convert ${p.name} to class instance.`);return u}function l(p,f){if(!p||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let u=f;for(let h in p){if(f[h]===void 0){console.warn(`Missing property "${h}" in loaded data.`);continue}if(!i(f[h]))continue;let g=p[h].constructor;if(g===Object){u[h]=l(p[h],f[h]);continue}u[h]=m(g,f[h])}return u}return c=l(this.normalData,c),c}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],Rt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Se=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}},Ie=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}},Wt=class je{static fromObject(e){return new je(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()}},Oe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Or=class Ue{static{this.configManager=new Pt(Oe)}constructor(e){this.config=Ue.configManager.parse(e),this.dataManager=new _e(this),this.keyManager=new ve({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new we({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 Nt}),this.dataManager.setStatic(e,{currency:new ge(()=>this.dataManager.getData(e).currency,r)}),new Se(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new xt(i)),this.dataManager.setStatic(e,new pe(this.dataManager.getData(e),r,i)),new Ie(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(...e){return new Wt(...e)}addResetFromObject(e){return Wt.fromObject(e)}},Ar={...Mr,...ye},Tr=Ar;if(typeof st.exports=="object"&&typeof St=="object"){var Er=(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};st.exports=Er(st.exports,St)}return st.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/game/eMath.game.mjs b/dist/game/eMath.game.mjs index 31c8d1d..b3aa825 100644 --- a/dist/game/eMath.game.mjs +++ b/dist/game/eMath.game.mjs @@ -5554,20 +5554,26 @@ import { Type as Type2 } from "class-transformer"; // src/classes/Boost.ts var BoostObject = class { - // eslint-disable-next-line jsdoc/require-returns - /** @deprecated Use {@link description} instead */ + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ get desc() { return this.description; } get description() { return this.descriptionFn(); } + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ constructor(init) { this.id = init.id; this.name = init.name ?? ""; - this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; this.value = init.value; this.order = init.order ?? 99; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; } }; var Boost = class { @@ -5942,10 +5948,6 @@ var UpgradeStatic = class _UpgradeStatic { // src/classes/Currency.ts var Currency = class { - // public upgrades: UpgradeData[]; - // /** A boost object that affects the currency gain. */ - // @Expose() - // public boost: boost; /** * Constructs a new currency object with an initial value of 0. */ @@ -6000,13 +6002,7 @@ var CurrencyStatic = class { this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; this.boost = new Boost(this.defaultBoost); this.pointer.value = this.defaultVal; - this.upgrades = { - // *[Symbol.iterator] () { - // for (const upgrade of Object.values(this)) { - // yield upgrade; - // } - // }, - }; + this.upgrades = {}; if (upgrades) this.addUpgrade(upgrades); } /** @@ -6079,6 +6075,39 @@ var CurrencyStatic = class { getUpgrade(id) { return this.upgrades[id] ?? null; } + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + queryUpgrade(id) { + const allUpgradeIds = Object.keys(this.upgrades); + if (id instanceof RegExp) { + const regex = id; + const matchedIds = allUpgradeIds.filter((upgrade) => regex.test(upgrade)); + return matchedIds.map((matchedId) => this.upgrades[matchedId]); + } + if (typeof id === "string") { + id = [id]; + } + const matchedUpgrades = allUpgradeIds.filter((upgrade) => id.includes(upgrade)); + return matchedUpgrades.map((matchedId) => this.upgrades[matchedId]); + } /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -6107,20 +6136,20 @@ var CurrencyStatic = class { */ addUpgrade(upgrades, runEffectInstantly = true) { if (!Array.isArray(upgrades)) upgrades = [upgrades]; - const addedUpgradeList = {}; + const addedUpgradeList = []; for (const upgrade of upgrades) { - const addedUpgradeData = this.pointerAddUpgrade(upgrade); + this.pointerAddUpgrade(upgrade); const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id)); if (addedUpgradeStatic.effect && runEffectInstantly) addedUpgradeStatic.effect(addedUpgradeStatic.level, addedUpgradeStatic, this); - addedUpgradeList[upgrade.id] = addedUpgradeStatic; this.upgrades[upgrade.id] = addedUpgradeStatic; + addedUpgradeList.push(addedUpgradeStatic); } - return Object.values(addedUpgradeList); + return addedUpgradeList; } /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -6131,13 +6160,10 @@ var CurrencyStatic = class { * } * }); */ - updateUpgrade(id, upgrade) { - const upgrade1 = this.getUpgrade(id); - if (upgrade1 === null) return; - upgrade1.name = upgrade.name ?? upgrade1.name; - upgrade1.cost = upgrade.cost ?? upgrade1.cost; - upgrade1.maxLevel = upgrade.maxLevel ?? upgrade1.maxLevel; - upgrade1.effect = upgrade.effect ?? upgrade1.effect; + updateUpgrade(id, newUpgrade) { + const oldUpgrade = this.getUpgrade(id); + if (oldUpgrade === null) return; + Object.assign(oldUpgrade, newUpgrade); } /** * Calculates the cost and how many upgrades you can buy. @@ -6151,7 +6177,6 @@ var CurrencyStatic = class { * // Calculate how many healthBoost upgrades you can buy and the cost of the upgrades * const [amount, cost] = currency.calculateUpgrade("healthBoost", 10); */ - // public calculateUpgrade (id: string, target: DecimalSource = 1, el: boolean = false): [amount: Decimal, cost: Decimal] { calculateUpgrade(id, target = Infinity, mode, iterations) { const upgrade = this.getUpgrade(id); if (upgrade === null) { diff --git a/dist/main/eMath.js b/dist/main/eMath.js index d5c141f..f36cae2 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -4882,20 +4882,26 @@ Decimal.formats = formats; // src/classes/Boost.ts var BoostObject = class { - // eslint-disable-next-line jsdoc/require-returns - /** @deprecated Use {@link description} instead */ + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ get desc() { return this.description; } get description() { return this.descriptionFn(); } + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ constructor(init) { this.id = init.id; this.name = init.name ?? ""; - this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; this.value = init.value; this.order = init.order ?? 99; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; } }; var Boost = class { @@ -5289,10 +5295,6 @@ var UpgradeStatic = class _UpgradeStatic { var import_reflect_metadata2 = require("reflect-metadata"); var import_class_transformer3 = require("class-transformer"); var Currency = class { - // public upgrades: UpgradeData[]; - // /** A boost object that affects the currency gain. */ - // @Expose() - // public boost: boost; /** * Constructs a new currency object with an initial value of 0. */ @@ -5347,13 +5349,7 @@ var CurrencyStatic = class { this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; this.boost = new Boost(this.defaultBoost); this.pointer.value = this.defaultVal; - this.upgrades = { - // *[Symbol.iterator] () { - // for (const upgrade of Object.values(this)) { - // yield upgrade; - // } - // }, - }; + this.upgrades = {}; if (upgrades) this.addUpgrade(upgrades); } /** @@ -5426,6 +5422,39 @@ var CurrencyStatic = class { getUpgrade(id) { return this.upgrades[id] ?? null; } + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + queryUpgrade(id) { + const allUpgradeIds = Object.keys(this.upgrades); + if (id instanceof RegExp) { + const regex = id; + const matchedIds = allUpgradeIds.filter((upgrade) => regex.test(upgrade)); + return matchedIds.map((matchedId) => this.upgrades[matchedId]); + } + if (typeof id === "string") { + id = [id]; + } + const matchedUpgrades = allUpgradeIds.filter((upgrade) => id.includes(upgrade)); + return matchedUpgrades.map((matchedId) => this.upgrades[matchedId]); + } /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -5454,20 +5483,20 @@ var CurrencyStatic = class { */ addUpgrade(upgrades, runEffectInstantly = true) { if (!Array.isArray(upgrades)) upgrades = [upgrades]; - const addedUpgradeList = {}; + const addedUpgradeList = []; for (const upgrade of upgrades) { - const addedUpgradeData = this.pointerAddUpgrade(upgrade); + this.pointerAddUpgrade(upgrade); const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id)); if (addedUpgradeStatic.effect && runEffectInstantly) addedUpgradeStatic.effect(addedUpgradeStatic.level, addedUpgradeStatic, this); - addedUpgradeList[upgrade.id] = addedUpgradeStatic; this.upgrades[upgrade.id] = addedUpgradeStatic; + addedUpgradeList.push(addedUpgradeStatic); } - return Object.values(addedUpgradeList); + return addedUpgradeList; } /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -5478,13 +5507,10 @@ var CurrencyStatic = class { * } * }); */ - updateUpgrade(id, upgrade) { - const upgrade1 = this.getUpgrade(id); - if (upgrade1 === null) return; - upgrade1.name = upgrade.name ?? upgrade1.name; - upgrade1.cost = upgrade.cost ?? upgrade1.cost; - upgrade1.maxLevel = upgrade.maxLevel ?? upgrade1.maxLevel; - upgrade1.effect = upgrade.effect ?? upgrade1.effect; + updateUpgrade(id, newUpgrade) { + const oldUpgrade = this.getUpgrade(id); + if (oldUpgrade === null) return; + Object.assign(oldUpgrade, newUpgrade); } /** * Calculates the cost and how many upgrades you can buy. @@ -5498,7 +5524,6 @@ var CurrencyStatic = class { * // Calculate how many healthBoost upgrades you can buy and the cost of the upgrades * const [amount, cost] = currency.calculateUpgrade("healthBoost", 10); */ - // public calculateUpgrade (id: string, target: DecimalSource = 1, el: boolean = false): [amount: Decimal, cost: Decimal] { calculateUpgrade(id, target = Infinity, mode, iterations) { const upgrade = this.getUpgrade(id); if (upgrade === null) { diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index 4b0bb3a..83d00ea 100644 --- a/dist/main/eMath.min.js +++ b/dist/main/eMath.min.js @@ -1,4 +1,4 @@ -"use strict";(function(dt,it){var vt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],it);else if(typeof module=="object"&&module.exports)module.exports=it();else{var at=it(),Mt=vt?exports:dt;for(var pt in at)Mt[pt]=at[pt]}})(typeof self<"u"?self:exports,()=>{var dt={},it={exports:dt},vt=Object.create,at=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,pt=Object.getOwnPropertyNames,de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty,Ne=(t,e)=>function(){return e||(0,t[pt(t)[0]])((e={exports:{}}).exports,e),e.exports},Zt=(t,e)=>{for(var r in e)at(t,r,{get:e[r],enumerable:!0})},$t=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pt(e))!pe.call(t,s)&&s!==r&&at(t,s,{get:()=>e[s],enumerable:!(i=Mt(e,s))||i.enumerable});return t},Nt=(t,e,r)=>(r=t!=null?vt(de(t)):{},$t(e||!t||!t.__esModule?at(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>$t(at({},"__esModule",{value:!0}),t),st=(t,e,r,i)=>{for(var s=i>1?void 0:i?Mt(e,r):e,a=t.length-1,h;a>=0;a--)(h=t[a])&&(s=(i?h(e,r,s):h(s))||s);return i&&s&&at(e,r,s),s},bt=Ne({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),s=a(e);typeof i.Reflect<"u"&&(s=a(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function a(d,I){return function(F,k){Object.defineProperty(d,F,{configurable:!0,writable:!0,value:k}),I&&I(F,k)}}function h(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return h()||g()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",h=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!m&&!d,F={create:m?function(){return Yt(Object.create(null))}:d?function(){return Yt({__proto__:null})}:function(){return Yt({})},has:I?function(u,l){return s.call(u,l)}:function(u,l){return l in u},get:I?function(u,l){return s.call(u,l)?u[l]:void 0}:function(u,l){return u[l]}},k=Object.getPrototypeOf(Function),q=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:er(),j=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:rr(),w=typeof WeakMap=="function"?WeakMap:ir(),x=a?Symbol.for("@reflect-metadata:registry"):void 0,V=Je(),W=Ke(V);function o(u,l,c,y){if(L(c)){if(!ae(u))throw new TypeError;if(!oe(l))throw new TypeError;return Q(u,l)}else{if(!ae(u))throw new TypeError;if(!$(l))throw new TypeError;if(!$(y)&&!L(y)&&!mt(y))throw new TypeError;return mt(y)&&(y=void 0),c=nt(c),et(u,l,c,y)}}r("decorate",o);function N(u,l){function c(y,P){if(!$(y))throw new TypeError;if(!L(P)&&!Xe(P))throw new TypeError;Tt(u,l,y,P)}return c}r("metadata",N);function p(u,l,c,y){if(!$(c))throw new TypeError;return L(y)||(y=nt(y)),Tt(u,l,c,y)}r("defineMetadata",p);function v(u,l,c){if(!$(l))throw new TypeError;return L(c)||(c=nt(c)),X(u,l,c)}r("hasMetadata",v);function S(u,l,c){if(!$(l))throw new TypeError;return L(c)||(c=nt(c)),J(u,l,c)}r("hasOwnMetadata",S);function E(u,l,c){if(!$(l))throw new TypeError;return L(c)||(c=nt(c)),K(u,l,c)}r("getMetadata",E);function O(u,l,c){if(!$(l))throw new TypeError;return L(c)||(c=nt(c)),ft(u,l,c)}r("getOwnMetadata",O);function G(u,l){if(!$(u))throw new TypeError;return L(l)||(l=nt(l)),Ft(u,l)}r("getMetadataKeys",G);function B(u,l){if(!$(u))throw new TypeError;return L(l)||(l=nt(l)),Et(u,l)}r("getOwnMetadataKeys",B);function Y(u,l,c){if(!$(l))throw new TypeError;if(L(c)||(c=nt(c)),!$(l))throw new TypeError;L(c)||(c=nt(c));var y=wt(l,c,!1);return L(y)?!1:y.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",Y);function Q(u,l){for(var c=u.length-1;c>=0;--c){var y=u[c],P=y(l);if(!L(P)&&!mt(P)){if(!oe(P))throw new TypeError;l=P}}return l}function et(u,l,c,y){for(var P=u.length-1;P>=0;--P){var z=u[P],D=z(l,c,y);if(!L(D)&&!mt(D)){if(!$(D))throw new TypeError;y=D}}return y}function X(u,l,c){var y=J(u,l,c);if(y)return!0;var P=jt(l);return mt(P)?!1:X(u,P,c)}function J(u,l,c){var y=wt(l,c,!1);return L(y)?!1:se(y.OrdinaryHasOwnMetadata(u,l,c))}function K(u,l,c){var y=J(u,l,c);if(y)return ft(u,l,c);var P=jt(l);if(!mt(P))return K(u,P,c)}function ft(u,l,c){var y=wt(l,c,!1);if(!L(y))return y.OrdinaryGetOwnMetadata(u,l,c)}function Tt(u,l,c,y){var P=wt(c,y,!0);P.OrdinaryDefineOwnMetadata(u,l,c,y)}function Ft(u,l){var c=Et(u,l),y=jt(u);if(y===null)return c;var P=Ft(y,l);if(P.length<=0)return c;if(c.length<=0)return P;for(var z=new j,D=[],U=0,M=c;U=0&&M=this._keys.length?(this._index=-1,this._keys=l,this._values=l):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},U.prototype.throw=function(M){throw this._index>=0&&(this._index=-1,this._keys=l,this._values=l),M},U.prototype.return=function(M){return this._index>=0&&(this._index=-1,this._keys=l,this._values=l),{value:M,done:!0}},U}(),y=function(){function U(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(U.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),U.prototype.has=function(M){return this._find(M,!1)>=0},U.prototype.get=function(M){var _=this._find(M,!1);return _>=0?this._values[_]:void 0},U.prototype.set=function(M,_){var T=this._find(M,!0);return this._values[T]=_,this},U.prototype.delete=function(M){var _=this._find(M,!1);if(_>=0){for(var T=this._keys.length,A=_+1;AZe}),it.exports=be(zt);var ar=Nt(bt()),Ht={};Zt(Ht,{Attribute:()=>Rt,AttributeStatic:()=>Ge,Boost:()=>Lt,BoostObject:()=>ct,Currency:()=>Ot,CurrencyStatic:()=>Re,DEFAULT_ITERATIONS:()=>St,Decimal:()=>n,E:()=>Ye,FORMATS:()=>ke,FormatTypeList:()=>ve,Grid:()=>je,GridCell:()=>ie,LRUCache:()=>At,ListNode:()=>Wt,ST_NAMES:()=>ot,UpgradeData:()=>yt,UpgradeStatic:()=>re,calculateSum:()=>Ut,calculateSumApprox:()=>Kt,calculateSumLoop:()=>Jt,calculateUpgrade:()=>te,decimalToJSONString:()=>ee,equalsTolerance:()=>Vt,formats:()=>lt,inverseFunctionApprox:()=>Bt,roundingBase:()=>Be,upgradeToCacheNameEL:()=>Ue});var or=Nt(bt()),At=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 Wt(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}}},Wt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},tt;(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"})(tt||(tt={}));var ye=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===tt.CLASS_TO_CLASS||i===tt.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===tt.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===tt.CLASS_TO_CLASS||r===tt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===tt.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===tt.CLASS_TO_CLASS||r===tt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===tt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(F){return F.propertyName!==void 0}));for(var a=[],h=0,g=this.getAncestors(r);hNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(3)){let B=[];for(let Y=0;YNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(2)){let B=[];for(let Y=0;Y118?e.elemental.beyondOg(S):e.elemental.config.element_lists[o-1][v]},beyondOg(o){let N=Math.floor(Math.log10(o)),p=["n","u","b","t","q","p","h","s","o","e"],v="";for(let S=N;S>=0;S--){let E=Math.floor(o/Math.pow(10,S))%10;v==""?v=p[E].toUpperCase():v+=p[E]}return v},abbreviationLength(o){return o==1?1:Math.pow(Math.floor(o/2)+1,2)*2},getAbbreviationAndValue(o){let N=o.log(118).toNumber(),p=Math.floor(N)+1,v=e.elemental.abbreviationLength(p),S=N-p+1,E=Math.floor(S*v),O=e.elemental.getAbbreviation(p,S),G=new t(118).pow(p+E/v-1);return[O,G]},formatElementalPart(o,N){return N.eq(1)?o:`${N.toString()} ${o}`},format(o,N=2){if(o.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(o.log10(),N);let p=o.log(118),S=p.log(118).log(118).toNumber(),E=Math.max(4-S*2,1),O=[];for(;p.gte(1)&&O.length=E)return O.map(B=>e.elemental.formatElementalPart(B[0],B[1])).join(" + ");let G=new t(118).pow(p).toFixed(O.length===1?3:N);return O.length===0?G:O.length===1?`${G} \xD7 ${e.elemental.formatElementalPart(O[0][0],O[0][1])}`:`${G} \xD7 (${O.map(B=>e.elemental.formatElementalPart(B[0],B[1])).join(" + ")})`}},old_sc:{format(o,N){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(t.dTen.pow(p));return(p.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(o,N=2){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.eng.format(S.floor(),0)}let v=o.div(new t(1e3).pow(p.div(3).floor()));return(p.log10().gte(9)?"":v.toFixed(new t(4).sub(p.sub(p.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(p.div(3).floor().mul(3),0)}}},mixed_sc:{format(o,N,p=9){o=new t(o);let v=o.log10().floor();return v.lt(303)&&v.gte(p)?m(o,N,p,"st"):m(o,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(o,N=2,p){o=new t(o);let v=o.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return m(o,N,p,"sc");o=t.dTen.pow(o.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let S=v.div(10).floor(),E=v.toNumber()%10-1;return m(o,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+m(S,0,p,"sc"):"")+"-":"")+(isNaN(E)?"nanity":e.layer.layers[E])}},standard:{tier1(o){return ot[0][0][o%10]+ot[0][1][Math.floor(o/10)%10]+ot[0][2][Math.floor(o/100)]},tier2(o){let N=o%10,p=Math.floor(o/10)%10,v=Math.floor(o/100)%10,S="";return o<10?ot[1][0][o]:(p==1&&N==0?S+="Vec":S+=ot[1][1][N]+ot[1][2][p],S+=ot[1][3][v],S)}},inf:{format(o,N,p){o=new t(o);let v=0,S=new t(Number.MAX_VALUE),E=["","\u221E","\u03A9","\u03A8","\u028A"],O=["","","m","mm","mmm"];for(;o.gte(S);)o=o.log(S),v++;return v==0?m(o,N,p,"sc"):o.gte(3)?O[v]+E[v]+"\u03C9^"+m(o.sub(1),N,p,"sc"):o.gte(2)?O[v]+"\u03C9"+E[v]+"-"+m(S.pow(o.sub(2)),N,p,"sc"):O[v]+E[v]+"-"+m(S.pow(o.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(o,N=new t(1e15),p=!1,v=9){if(o=new t(o),N=new t(N).div(1e3),o.lt(N.mul(1e3)))return"";let{alphabet:S}=e.alphabet.config,E=S.length,O=o.log(1e3).sub(N.log(1e3)).floor(),G=O.add(1).log(E+1).ceil(),B="",Y=(Q,et)=>{let X=Q,J="";for(let K=0;K=E)return"\u03C9";J=S[ft]+J,X=X.sub(1).div(E).floor()}return J};if(G.lt(v))B=Y(O,G);else{let Q=G.sub(v).add(1),et=O.div(t.pow(E+1,Q.sub(1))).floor();B=`${Y(et,new t(v))}(${Q.gt("1e9")?Q.format():Q.format(0)})`}return B},format(o,N=2,p=9,v="mixed_sc",S=new t(1e15),E=!1,O){if(o=new t(o),S=new t(S).div(1e3),o.lt(S.mul(1e3)))return m(o,N,p,v);let G=e.alphabet.getAbbreviation(o,S,E,O),B=o.div(t.pow(1e3,o.log(1e3).floor()));return`${G.length>(O??9)+2?"":B.toFixed(N)+" "}${G}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",s="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function a(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":i[parseInt(N,10)]).join("")}function h(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function g(o,N=2,p=9,v="st"){return m(o,N,p,v)}function m(o,N=2,p=9,v="mixed_sc"){o=new t(o);let S=o.lt(0)?"-":"";if(o.mag==1/0)return S+"Infinity";if(Number.isNaN(o.mag))return S+"NaN";if(o.lt(0)&&(o=o.mul(-1)),o.eq(0))return o.toFixed(N);let E=o.log10().floor();switch(v){case"sc":case"scientific":if(o.log10().lt(Math.min(-N,0))&&N>1){let O=o.log10().ceil(),G=o.div(O.eq(-1)?new t(.1):t.dTen.pow(O)),B=O.mul(-1).max(1).log10().gte(9);return S+(B?"":G.toFixed(2))+"e"+m(O,0,p,"mixed_sc")}else if(E.lt(p)){let O=Math.max(Math.min(N-E.toNumber(),N),0);return S+(O>0?o.toFixed(O):o.toFixed(O).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(o.gte("eeee10")){let B=o.slog();return(B.gte(1e9)?"":t.dTen.pow(B.sub(B.floor())).toFixed(2))+"F"+m(B.floor(),0)}let O=o.div(t.dTen.pow(E)),G=E.log10().gte(9);return S+(G?"":O.toFixed(2))+"e"+m(E,0,p,"mixed_sc")}case"st":case"standard":{let O=o.log(1e3).floor();if(O.lt(1))return S+o.toFixed(Math.max(Math.min(N-E.toNumber(),N),0));let G=O.mul(3),B=O.log10().floor();if(B.gte(3e3))return"e"+m(E,N,p,"st");let Y="";if(O.lt(4))Y=["","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 J=O.div(1e3).floor(),K=O.sub(J.mul(1e3)).floor().toNumber();K>0&&(K==1&&!X&&(Y="U"),X&&(Y=e.standard.tier2(X)+(Y?"-"+Y:"")),K>1&&(Y=e.standard.tier1(K)+Y)),O=J,X++}}let Q=o.div(t.dTen.pow(G)),et=N===2?t.dTwo.sub(E.sub(G)).add(1).toNumber():N;return S+(B.gte(10)?"":Q.toFixed(et)+" ")+Y}default:return e[v]||console.error('Invalid format type "',v,'"'),S+e[v].format(o,N,p)}}function d(o,N,p="mixed_sc",v,S){o=new t(o),N=new t(N);let E=o.add(N),O,G=E.div(o);return G.gte(10)&&o.gte(1e100)?(G=G.log10().mul(20),O="(+"+m(G,v,S,p)+" OoMs/sec)"):O="(+"+m(N,v,S,p)+"/sec)",O}function I(o,N=2,p="s"){return o=new t(o),o.gte(86400)?m(o.div(86400).floor(),0,12,"sc")+":"+I(o.mod(86400),N,"d"):o.gte(3600)||p=="d"?(o.div(3600).gte(10)||p!="d"?"":"0")+m(o.div(3600).floor(),0,12,"sc")+":"+I(o.mod(3600),N,"h"):o.gte(60)||p=="h"?(o.div(60).gte(10)||p!="h"?"":"0")+m(o.div(60).floor(),0,12,"sc")+":"+I(o.mod(60),N,"m"):(o.gte(10)||p!="m"?"":"0")+m(o,N,12,"sc")}function F(o,N=!1,p=0,v=9,S="mixed_sc"){let E=Et=>m(Et,p,v,S);o=new t(o);let O=o.mul(1e3).mod(1e3).floor(),G=o.mod(60).floor(),B=o.div(60).mod(60).floor(),Y=o.div(3600).mod(24).floor(),Q=o.div(86400).mod(365.2425).floor(),et=o.div(31556952).floor(),X=et.eq(1)?" year":" years",J=Q.eq(1)?" day":" days",K=Y.eq(1)?" hour":" hours",ft=B.eq(1)?" minute":" minutes",Tt=G.eq(1)?" second":" seconds",Ft=O.eq(1)?" millisecond":" milliseconds";return`${et.gt(0)?E(et)+X+", ":""}${Q.gt(0)?E(Q)+J+", ":""}${Y.gt(0)?E(Y)+K+", ":""}${B.gt(0)?E(B)+ft+", ":""}${G.gt(0)?E(G)+Tt+",":""}${N&&O.gt(0)?" "+E(O)+Ft:""}`.replace(/,([^,]*)$/,"$1").trim()}function k(o){return o=new t(o),m(t.dOne.sub(o).mul(100))+"%"}function q(o){return o=new t(o),m(o.mul(100))+"%"}function j(o,N=2){return o=new t(o),o.gte(1)?"\xD7"+o.format(N):"/"+o.pow(-1).format(N)}function w(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function x(o,N=0){o=new t(o);let p=(O=>O.map((G,B)=>({name:G.name,altName:G.altName,value:t.pow(1e3,new t(B).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),v="",S=o.lte(0)?0:t.min(t.log(o,1e3).sub(1),p.length-1).floor().toNumber(),E=p[S];if(S===0)switch(N){case 1:v="";break;case 2:case 0:default:v=o.format();break}switch(N){case 1:v=E.name;break;case 2:v=o.divide(E.value).format();break;case 3:v=E.altName;break;case 0:default:v=`${o.divide(E.value).format()} ${E.name}`;break}return v}function V(o,N=!1){return`${x(o,2)} ${x(o,1)}eV${N?"/c^2":""}`}let W={...e,toSubscript:a,toSuperscript:h,formatST:g,format:m,formatGain:d,formatTime:I,formatTimeLong:F,formatReduction:k,formatPercent:q,formatMult:j,expMult:w,metric:x,ev:V};return{FORMATS:e,formats:W}}var Pt=17,_e=9e15,Ie=Math.log10(9e15),Se=1/9e15,Oe=308,Te=-324,Dt=5,Fe=1023,Ee=!0,Ae=!1,Ce=function(){let t=[];for(let r=Te+1;r<=Oe;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ht=[2,Math.E,3,4,5,6,7,8,9,10],Pe=[[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]],qe=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return n.fromValue_noAlloc(e)},C=function(t,e,r){return n.fromComponents(t,e,r)},b=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},ut=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),a=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(a.toFixed(Math.max(i-s,0)))},qt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},xe=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},Le=.36787944117144233,Xt=.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 Xt;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let a=0;a<100;++a){if(s=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(s-i).5?1:-1;if(Math.random()*20<1)return b(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let s=Math.pow(10,i);return Math.random()>.9&&(s=Math.trunc(s)),C(e,r,s)}static affordGeometricSeries_core(t,e,r,i){let s=e.mul(r.pow(i));return n.floor(t.div(s).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(n.sub(1,r.pow(t))).div(n.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r)).sub(r.div(2)),h=a.pow(2);return a.neg().add(h.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=_e)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);Ee?t=t.replace(",",""):Ae&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let w=parseFloat(s[0]),x=parseFloat(s[1]),V=s[1].split(";"),W=1;if(V.length===2&&(W=parseFloat(V[1]),isFinite(W)||(W=1)),isFinite(w)&&isFinite(x)){let o=n.pentate(w,x,W,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let a=t.split("^^");if(a.length===2){let w=parseFloat(a[0]),x=parseFloat(a[1]),V=a[1].split(";"),W=1;if(V.length===2&&(W=parseFloat(V[1]),isFinite(W)||(W=1)),isFinite(w)&&isFinite(x)){let o=n.tetrate(w,x,W,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let h=t.split("^");if(h.length===2){let w=parseFloat(h[0]),x=parseFloat(h[1]);if(isFinite(w)&&isFinite(x)){let V=n.pow(w,x);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,m,d=t.split("pt");if(d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}let I=t.split("e"),F=I.length-1;if(F===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(F===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let k=t.split("e^");if(k.length===2){this.sign=1,k[0].startsWith("-")&&(this.sign=-1);let w="";for(let x=0;x=43&&V<=57||V===101)w+=k[1].charAt(x);else return this.layer=parseFloat(w),this.mag=parseFloat(k[1].substr(x+1)),this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}if(F<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let q=parseFloat(I[0]);if(q===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let j=parseFloat(I[I.length-1]);if(F>=2){let w=parseFloat(I[I.length-2]);isFinite(w)&&(j*=Math.sign(w),j+=qt(w))}if(!isFinite(q))this.sign=I[0]==="-"?-1:1,this.layer=F,this.mag=j;else if(F===1)this.sign=Math.sign(q),this.layer=1,this.mag=j+Math.log10(Math.abs(q));else if(this.sign=Math.sign(q),this.layer=F,F===2){let w=n.mul(C(1,2,j),f(q));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=j;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ut(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ut(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=Dt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ut(this.m,t)+"e"+ut(this.e,t):this.layer===1?ut(this.m,t)+"e"+ut(this.e,t):this.layer<=Dt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ut(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ut(this.mag,t)}abs(){return b(this.sign===0?0:1,this.layer,this.mag)}neg(){return b(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?b(-1,0,1):b(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?C(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?b(1,0,1):b(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?C(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return b(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),a=i.layer*Math.sign(i.mag);if(s-a>=2)return r;if(s===0&&a===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Pt)return r;{let h=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>Pt)return r;{let h=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*h;return C(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>Pt)return r;{let h=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return b(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return b(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return C(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return C(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return C(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?b(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?b(0,0,0):this.layer===0?C(this.sign,0,1/this.mag):C(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(n.dZero))return b(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new n(r%i):this.sub(e).eq(this)?b(0,0,0):e.sub(this).eq(e)?new n(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=qt(s)),this.layer0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer>0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?C(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log2(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?b(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return b(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:b(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return b(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return b(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return C(1,0,e);if(t.sign===0)return b(1,0,1);t=b(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?C(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?C(-t.sign,t.layer+1,-t.mag):b(1,0,1)}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(b(1,0,24)))return n.fromNumber(xe(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,s=12*i,a=1/s,h=e+a;if(h===e||(e=h,i=i*r,s=360*i,a=1/s,h=e-a,h===e))return n.exp(e);e=h,i=i*r,s=1260*i;let g=1/s;return e=e+g,i=i*r,s=1680*i,g=1/s,e=e-g,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?b(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?C(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?C(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):C(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return C(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(b(this.sign,this.layer-1,this.mag),b(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=b(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return b(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let a=this.toNumber();if(a<=1.444667861009766&&a>=.06598803584531254){let h=n.ln(this).neg(),g=h.lambertw().div(h);if(a<1)return g;let m=h.lambertw(!1).div(h);return a>1.444667861009099&&(g=m=n.fromNumber(Math.E)),e=f(e),e.eq(m)?m:e.lt(m)?g:b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return a>1.444667861009766?b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let a=Math.abs((t+1)%2);return a>1&&(a=2-a),n.fromNumber(a)}if(t<0)return n.iteratedlog(e,this,-t,r);e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;if(this.gt(n.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(n.ln(this).neg().lambertw(!1).div(n.ln(this).neg())))&&(i>1e4||!r)){let a=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let h=0;h1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let a=0;a3)return b(e.sign,e.layer+(t-a-1),e.mag);if(a>1e4)return e}return e}iteratedexp(t=2,e=b(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=f(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let a=s-e;if(i.layer-t.layer>3){let h=Math.min(e,i.layer-t.layer-3);e-=h,i.layer-=h}for(let h=0;h1e4)return i}return a>0&&a<1&&(t.eq(10)?i=i.layeradd10(-a,r):i=i.layeradd(-a,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,s=!1,a=!1,h=this.slog_internal(t,r).toNumber();for(let g=1;g1&&a!=d&&(s=!0),a=d,s?i/=2:i*=2,i=Math.abs(i)*(d?-1:1),h+=i,i===0)break}return n.fromNumber(h)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(n.dZero)||t.eq(n.dOne))return b(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?b(0,0,0):this.eq(n.dZero)?b(-1,0,1):b(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return b(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),a=s.lambertw().div(s);if(this.eq(a))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(a))return b(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=n.fromDecimal(this);if(i.layer-t.layer>3){let s=i.layer-t.layer-3;r+=s,i.layer-=s}for(let s=0;s<100;++s)if(i.lt(n.dZero))i=n.pow(t,i),r-=1;else{if(i.lte(n.dOne))return e?n.fromNumber(r+i.toNumber()-1):n.fromNumber(r+n.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=n.log(i,t)}return n.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:n.critical_section(t,e,qe)}static tetrate_critical(t,e){return n.critical_section(t,e,Pe)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let s=0,a=0;for(let g=0;gt){let m=(t-ht[g])/(ht[g+1]-ht[g]);s=r[g][Math.floor(e)]*(1-m)+r[g+1][Math.floor(e)]*m,a=r[g][Math.ceil(e)]*(1-m)+r[g+1][Math.ceil(e)]*m;break}let h=e-Math.floor(e);return s<=0||a<=0?s*(1-h)+a*h:Math.pow(t,Math.log(s)/Math.log(t)*(1-h)+Math.log(a)/Math.log(t)*h)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=f(e);if(i.gt(1)&&i.lte(1.444667861009766)){let h=n.excess_slog(this,e,r),g=h[0].toNumber(),m=h[1],d=g+t,I=n.ln(e).neg(),F=I.lambertw().div(I),k=I.lambertw(!1).div(I),q=n.dOne;m==1?q=F.mul(k).sqrt():m==2&&(q=k.mul(2));let j=i.pow(q),w=Math.floor(d),x=d-w,V=q.pow(1-x).mul(j.pow(x));return n.tetrate(i,w,V,r)}let a=this.slog(e,100,r).toNumber()+t;return a>=0?n.tetrate(e,a,n.dOne,r):Number.isFinite(a)?a>=-1?n.log(n.tetrate(e,a+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,a+2,n.dOne,r),e),e):b(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=f(t),e=f(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[b(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),a=s.lambertw().div(s),h=n.dInf;if(e>1&&(h=s.lambertw(!1).div(s)),e>1.444667861009099&&(a=h=n.fromNumber(Math.E)),t.lt(a))return[t.slog(e,100,r),0];if(t.eq(a))return[b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(h))return[b(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(h)){let g=h.mul(2),m=i.pow(g),d=0;if(t.gte(g)&&t.lt(m))d=0;else if(t.gte(m)){let w=m;for(d=1;w.lt(t);)if(w=i.pow(w),d=d+1,w.layer>3){let x=Math.floor(t.layer-w.layer+1);w=i.iteratedexp(x,w,r),d=d+x}w.gt(t)&&(w=w.log(e),d=d-1)}else if(t.lt(g)){let w=g;for(d=0;w.gt(t);)w=w.log(e),d=d-1}let I=0,F=0,k=.5,q=g,j=n.dZero;for(;k>1e-16;){if(F=I+k,q=g.pow(1-F).mul(m.pow(F)),j=n.iteratedexp(e,d,q),j.eq(t))return[new n(d+F),2];j.lt(t)&&(I+=k),k/=2}return j.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),2]}if(t.lt(h)&&t.gt(a)){let g=a.mul(h).sqrt(),m=i.pow(g),d=0;if(t.lte(g)&&t.gt(m))d=0;else if(t.lte(m)){let w=m;for(d=1;w.gt(t);)w=i.pow(w),d=d+1;w.lt(t)&&(w=w.log(e),d=d-1)}else if(t.gt(g)){let w=g;for(d=0;w.lt(t);)w=w.log(e),d=d-1}let I=0,F=0,k=.5,q=g,j=n.dZero;for(;k>1e-16;){if(F=I+k,q=g.pow(1-F).mul(m.pow(F)),j=n.iteratedexp(e,d,q),j.eq(t))return[new n(d+F),1];j.gt(t)&&(I+=k),k/=2}return j.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")?Qt(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?Qt(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 eLe?this.pow(this.recip()):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return b(1,0,1);if(this.lt(0))return b(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new n(this):b(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=n.dTen;this.gte(n.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=n.dZero,i=e.layer,s=e.iteratedlog(10,i,!0),a=s,h=s.div(2),g=!0;for(;g;)h=r.add(s).div(2),n.iteratedexp(10,i,h,!0).tetrate(t,1,!0).gt(this)?s=h:r=h,h.eq(a)?g=!1:a=h;return n.iteratedexp(10,i,h,!0)}else{let e=1,r=C(1,10,1),i=C(1,10,1),s=C(1,10,1),a=C(1,1,-16),h=n.dZero,g=C(1,10,1),m=a.pow10().recip(),d=n.dZero,I=m,F=m,k=Math.ceil(t)%2==0,q=0,j=C(1,10,1),w=!1,x=n.dZero,V=!1;for(;e<4;){if(e==2){if(k)break;s=C(1,10,1),a=r,e=3,g=C(1,10,1),j=C(1,10,1)}for(w=!1;a.neq(s);){if(x=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),F=a.pow10().recip(),d=n.dZero,q=-1,e==3&&(j=a);else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip())&&!k&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),F=a.pow10().recip(),d=n.dZero,q=0;else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip().mul(2).tetrate(t,1,!0)))m=a.pow10().recip(),I=n.dZero,F=m.mul(2),d=m,k?q=-1:q=0;else{for(h=a.mul(12e-17),m=a.pow10().recip(),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);I.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||F.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||I.gte(m)||F.lte(m);)h=h.mul(2),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);if((e==1&&F.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(j=a),F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))q=-1;else if(k)q=1;else if(e==3&&a.gt_tolerance(r,1e-8))q=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||F.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||I.gte(m)||F.lte(m);)h=h.mul(2),I=a.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);F.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?q=0:q=1}}if(q==-1&&(V=!0),e==1&&q==1||e==3&&q!=0)if(s.eq(C(1,10,1)))a=a.mul(2);else{let p=!1;if(w&&(q==1&&e==1||q==-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&&(q==1&&e==1||q==-1&&e==3)&&(p=!0),s=s.sub(g),a=a.sub(g),p)break}if(s.sub(a).div(2).abs().gt(g.mul(1.5))&&(w=!0),g=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(x))break}if(a.gt("1e18")||!V||j==C(1,10,1))break;e==1?r=j:e==3&&(i=j),e++}s=r,a=C(1,1,-18);let W=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(W)?N=!1:W=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,W=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(W)?N=!1:W=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);return o.pow10().recip()}else return o.pow10().recip()}}pentate(t=2,e=b(1,0,1),r=!1){e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;s!==0&&(e.eq(n.dOne)?(++t,e=n.fromNumber(s)):this.eq(10)?e=e.layeradd10(s,r):e=e.layeradd(s,this,r));for(let a=0;a10)return e}return e}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):b(0,0,0)}cos(){return this.mag<0?b(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):b(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):b(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?b(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return lt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return lt.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return lt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return lt.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return lt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return lt.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let a of Object.keys(i)){let h=Math.floor(r/i[a]);r-=h*i[a],s+=a.repeat(h)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=b(0,0,0),n.dOne=b(1,0,1),n.dNegOne=b(-1,0,1),n.dTwo=b(1,0,2),n.dTen=b(1,0,10),n.dNaN=b(Number.NaN,Number.NaN,Number.NaN),n.dInf=b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=C(1,0,Number.MAX_VALUE),n.dNumberMin=C(1,0,Number.MIN_VALUE),n.fromStringCache=new At(Fe),st([_t()],n.prototype,"sign",2),st([_t()],n.prototype,"mag",2),st([_t()],n.prototype,"layer",2),n=st([we()],n);var{formats:lt,FORMATS:ke}=Me(n);n.formats=lt;var ct=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},Lt=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 ct(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sF),d=s,I=this.getBoosts(a,!0);I[0][0]?this.boostArray[I[1][0]]=new ct({id:a,name:h,description:g,value:m,order:d}):this.boostArray.push(new ct({id:a,name:h,description:g,value:m,order:d}))}else{t=Array.isArray(t)?t:[t];for(let a of t){let h=this.getBoosts(a.id,!0);h[0][0]?this.boostArray[h[1][0]]=new ct(a):this.boostArray.push(new ct(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}},ur=Nt(bt()),St=30,kt=.001;function Ve(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 Vt(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 Bt(t,e,r="geometric",i=St,s=kt){let a=n.dOne,h=new n(e);if(t(h).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(h).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:h,lowerBound:h,upperBound:h};for(let m=0;m=0;g--){let m=r.add(h.mul(g)),d=r.add(h.mul(g+1)),I=a;if(a=a.add(t(m).add(t(d)).div(2).mul(h)),Vt(I,a,s,{verbose:!1,mode:"geometric"}))break}return a}function Ut(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(St)?Jt(t,e,r,i):Kt(t,e,r,s)}function Be(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 te(t,e,r,i=1/0,s,a,h=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[n.dZero,n.dZero];if(h=(typeof e.el=="function"?e.el():e.el)??h,g.eq(1)){let F=e.cost(e.level),k=t.gte(F),q=[n.dZero,n.dZero];return h?(q[0]=k?n.dOne:n.dZero,q):(q=[k?n.dOne:n.dZero,k?F:n.dZero],q)}if(e.costBulk){let[F,k]=e.costBulk(t,e.level,g),q=t.gte(k);return[q?F:n.dZero,q&&!h?k:n.dZero]}if(h){let F=j=>e.cost(j.add(r)),k=n.min(i,Bt(F,t,s,a).value.floor()),q=n.dZero;return[k,q]}let m=Bt(F=>Ut(e.cost,F,r),t,s,a).value.floor().min(r.add(g).sub(1)),d=Ut(e.cost,m,r);return[m.sub(r).add(1).max(0),d]}function ee(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function Ue(t){return`el/${ee(t)}`}var yt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};st([_t()],yt.prototype,"id",2),st([It(()=>n)],yt.prototype,"level",2);var re=class ge{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}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){let s=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>s,this.cache=new At(i??ge.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}},lr=Nt(bt()),Ot=class{constructor(){this.value=n.dZero,this.upgrades={}}};st([It(()=>n)],Ot.prototype,"value",2),st([It(()=>yt)],Ot.prototype,"upgrades",2);var Re=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Ot,e,r={defaultVal:n.dZero,defaultBoost:n.dOne}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Lt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=new n(i.defaultLevel),r&&i.effect?.(i.level,i,this)}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 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}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let s=this.pointerAddUpgrade(i),a=new re(i,()=>this.pointerGetUpgrade(i.id));a.effect&&e&&a.effect(a.level,a,this),r[i.id]=a,this.upgrades[i.id]=a}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}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)),te(this.value,s,s.level,e,r,i))}getNextCost(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(a))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(a[0])).add(a[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[a,h]=this.calculateUpgrade(t,e,r,i);return a.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(h),s.level=s.level.add(a),s.effect?.(s.level,s,this),!0)}},fr=Nt(bt()),Rt=class{constructor(t=0){this.value=new n(t)}};st([It(()=>n)],Rt.prototype,"value",2);var Ge=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new Rt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Lt(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}},ie=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},je=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{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})(),Ze=Ht;if(typeof it.exports=="object"&&typeof dt=="object"){var $e=(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};it.exports=$e(it.exports,dt)}return it.exports}); +"use strict";(function(dt,it){var vt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],it);else if(typeof module=="object"&&module.exports)module.exports=it();else{var at=it(),Mt=vt?exports:dt;for(var pt in at)Mt[pt]=at[pt]}})(typeof self<"u"?self:exports,()=>{var dt={},it={exports:dt},vt=Object.create,at=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,pt=Object.getOwnPropertyNames,de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty,Ne=(t,e)=>function(){return e||(0,t[pt(t)[0]])((e={exports:{}}).exports,e),e.exports},Zt=(t,e)=>{for(var r in e)at(t,r,{get:e[r],enumerable:!0})},$t=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pt(e))!pe.call(t,s)&&s!==r&&at(t,s,{get:()=>e[s],enumerable:!(i=Mt(e,s))||i.enumerable});return t},Nt=(t,e,r)=>(r=t!=null?vt(de(t)):{},$t(e||!t||!t.__esModule?at(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>$t(at({},"__esModule",{value:!0}),t),st=(t,e,r,i)=>{for(var s=i>1?void 0:i?Mt(e,r):e,o=t.length-1,h;o>=0;o--)(h=t[o])&&(s=(i?h(e,r,s):h(s))||s);return i&&s&&at(e,r,s),s},bt=Ne({"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=o(e);typeof i.Reflect<"u"&&(s=o(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(d,I){return function(F,L){Object.defineProperty(d,F,{configurable:!0,writable:!0,value:L}),I&&I(F,L)}}function h(){try{return Function("return this;")()}catch{}}function g(){try{return(0,eval)("(function() { return this; })()")}catch{}}function m(){return h()||g()}})(function(r,i){var s=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",h=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",g=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",m=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!m&&!d,F={create:m?function(){return Yt(Object.create(null))}:d?function(){return Yt({__proto__:null})}:function(){return Yt({})},has:I?function(u,l){return s.call(u,l)}:function(u,l){return l in u},get:I?function(u,l){return s.call(u,l)?u[l]:void 0}:function(u,l){return u[l]}},L=Object.getPrototypeOf(Function),q=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:er(),j=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:rr(),w=typeof WeakMap=="function"?WeakMap:ir(),x=o?Symbol.for("@reflect-metadata:registry"):void 0,V=Je(),W=Ke(V);function a(u,l,c,y){if(k(c)){if(!ae(u))throw new TypeError;if(!oe(l))throw new TypeError;return Q(u,l)}else{if(!ae(u))throw new TypeError;if(!$(l))throw new TypeError;if(!$(y)&&!k(y)&&!mt(y))throw new TypeError;return mt(y)&&(y=void 0),c=nt(c),et(u,l,c,y)}}r("decorate",a);function N(u,l){function c(y,P){if(!$(y))throw new TypeError;if(!k(P)&&!Xe(P))throw new TypeError;Tt(u,l,y,P)}return c}r("metadata",N);function p(u,l,c,y){if(!$(c))throw new TypeError;return k(y)||(y=nt(y)),Tt(u,l,c,y)}r("defineMetadata",p);function v(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=nt(c)),X(u,l,c)}r("hasMetadata",v);function S(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=nt(c)),J(u,l,c)}r("hasOwnMetadata",S);function E(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=nt(c)),K(u,l,c)}r("getMetadata",E);function O(u,l,c){if(!$(l))throw new TypeError;return k(c)||(c=nt(c)),ft(u,l,c)}r("getOwnMetadata",O);function G(u,l){if(!$(u))throw new TypeError;return k(l)||(l=nt(l)),Ft(u,l)}r("getMetadataKeys",G);function B(u,l){if(!$(u))throw new TypeError;return k(l)||(l=nt(l)),Et(u,l)}r("getOwnMetadataKeys",B);function Y(u,l,c){if(!$(l))throw new TypeError;if(k(c)||(c=nt(c)),!$(l))throw new TypeError;k(c)||(c=nt(c));var y=wt(l,c,!1);return k(y)?!1:y.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",Y);function Q(u,l){for(var c=u.length-1;c>=0;--c){var y=u[c],P=y(l);if(!k(P)&&!mt(P)){if(!oe(P))throw new TypeError;l=P}}return l}function et(u,l,c,y){for(var P=u.length-1;P>=0;--P){var z=u[P],D=z(l,c,y);if(!k(D)&&!mt(D)){if(!$(D))throw new TypeError;y=D}}return y}function X(u,l,c){var y=J(u,l,c);if(y)return!0;var P=jt(l);return mt(P)?!1:X(u,P,c)}function J(u,l,c){var y=wt(l,c,!1);return k(y)?!1:se(y.OrdinaryHasOwnMetadata(u,l,c))}function K(u,l,c){var y=J(u,l,c);if(y)return ft(u,l,c);var P=jt(l);if(!mt(P))return K(u,P,c)}function ft(u,l,c){var y=wt(l,c,!1);if(!k(y))return y.OrdinaryGetOwnMetadata(u,l,c)}function Tt(u,l,c,y){var P=wt(c,y,!0);P.OrdinaryDefineOwnMetadata(u,l,c,y)}function Ft(u,l){var c=Et(u,l),y=jt(u);if(y===null)return c;var P=Ft(y,l);if(P.length<=0)return c;if(c.length<=0)return P;for(var z=new j,D=[],U=0,M=c;U=0&&M=this._keys.length?(this._index=-1,this._keys=l,this._values=l):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},U.prototype.throw=function(M){throw this._index>=0&&(this._index=-1,this._keys=l,this._values=l),M},U.prototype.return=function(M){return this._index>=0&&(this._index=-1,this._keys=l,this._values=l),{value:M,done:!0}},U}(),y=function(){function U(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(U.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),U.prototype.has=function(M){return this._find(M,!1)>=0},U.prototype.get=function(M){var _=this._find(M,!1);return _>=0?this._values[_]:void 0},U.prototype.set=function(M,_){var T=this._find(M,!0);return this._values[T]=_,this},U.prototype.delete=function(M){var _=this._find(M,!1);if(_>=0){for(var T=this._keys.length,A=_+1;AZe}),it.exports=be(zt);var ar=Nt(bt()),Ht={};Zt(Ht,{Attribute:()=>Rt,AttributeStatic:()=>Ge,Boost:()=>kt,BoostObject:()=>ct,Currency:()=>Ot,CurrencyStatic:()=>Re,DEFAULT_ITERATIONS:()=>St,Decimal:()=>n,E:()=>Ye,FORMATS:()=>Le,FormatTypeList:()=>ve,Grid:()=>je,GridCell:()=>ie,LRUCache:()=>At,ListNode:()=>Wt,ST_NAMES:()=>ot,UpgradeData:()=>yt,UpgradeStatic:()=>re,calculateSum:()=>Ut,calculateSumApprox:()=>Kt,calculateSumLoop:()=>Jt,calculateUpgrade:()=>te,decimalToJSONString:()=>ee,equalsTolerance:()=>Vt,formats:()=>lt,inverseFunctionApprox:()=>Bt,roundingBase:()=>Be,upgradeToCacheNameEL:()=>Ue});var or=Nt(bt()),At=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 Wt(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}}},Wt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},tt;(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"})(tt||(tt={}));var ye=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===tt.CLASS_TO_CLASS||i===tt.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===tt.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),o=s&&s.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===tt.CLASS_TO_CLASS||r===tt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===tt.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===tt.CLASS_TO_CLASS||r===tt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===tt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(F){return F.propertyName!==void 0}));for(var o=[],h=0,g=this.getAncestors(r);hNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(a,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(3)){let B=[];for(let Y=0;YNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let E=t.log(a,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(2)){let B=[];for(let Y=0;Y118?e.elemental.beyondOg(S):e.elemental.config.element_lists[a-1][v]},beyondOg(a){let N=Math.floor(Math.log10(a)),p=["n","u","b","t","q","p","h","s","o","e"],v="";for(let S=N;S>=0;S--){let E=Math.floor(a/Math.pow(10,S))%10;v==""?v=p[E].toUpperCase():v+=p[E]}return v},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let N=a.log(118).toNumber(),p=Math.floor(N)+1,v=e.elemental.abbreviationLength(p),S=N-p+1,E=Math.floor(S*v),O=e.elemental.getAbbreviation(p,S),G=new t(118).pow(p+E/v-1);return[O,G]},formatElementalPart(a,N){return N.eq(1)?a:`${N.toString()} ${a}`},format(a,N=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),N);let p=a.log(118),S=p.log(118).log(118).toNumber(),E=Math.max(4-S*2,1),O=[];for(;p.gte(1)&&O.length=E)return O.map(B=>e.elemental.formatElementalPart(B[0],B[1])).join(" + ");let G=new t(118).pow(p).toFixed(O.length===1?3:N);return O.length===0?G:O.length===1?`${G} \xD7 ${e.elemental.formatElementalPart(O[0][0],O[0][1])}`:`${G} \xD7 (${O.map(B=>e.elemental.formatElementalPart(B[0],B[1])).join(" + ")})`}},old_sc:{format(a,N){a=new t(a);let p=a.log10().floor();if(p.lt(9))return p.lt(3)?a.toFixed(N):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let S=a.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=a.div(t.dTen.pow(p));return(p.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(a,N=2){a=new t(a);let p=a.log10().floor();if(p.lt(9))return p.lt(3)?a.toFixed(N):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let S=a.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.eng.format(S.floor(),0)}let v=a.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(a,N,p=9){a=new t(a);let v=a.log10().floor();return v.lt(303)&&v.gte(p)?m(a,N,p,"st"):m(a,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,N=2,p){a=new t(a);let v=a.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return m(a,N,p,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let S=v.div(10).floor(),E=v.toNumber()%10-1;return m(a,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+m(S,0,p,"sc"):"")+"-":"")+(isNaN(E)?"nanity":e.layer.layers[E])}},standard:{tier1(a){return ot[0][0][a%10]+ot[0][1][Math.floor(a/10)%10]+ot[0][2][Math.floor(a/100)]},tier2(a){let N=a%10,p=Math.floor(a/10)%10,v=Math.floor(a/100)%10,S="";return a<10?ot[1][0][a]:(p==1&&N==0?S+="Vec":S+=ot[1][1][N]+ot[1][2][p],S+=ot[1][3][v],S)}},inf:{format(a,N,p){a=new t(a);let v=0,S=new t(Number.MAX_VALUE),E=["","\u221E","\u03A9","\u03A8","\u028A"],O=["","","m","mm","mmm"];for(;a.gte(S);)a=a.log(S),v++;return v==0?m(a,N,p,"sc"):a.gte(3)?O[v]+E[v]+"\u03C9^"+m(a.sub(1),N,p,"sc"):a.gte(2)?O[v]+"\u03C9"+E[v]+"-"+m(S.pow(a.sub(2)),N,p,"sc"):O[v]+E[v]+"-"+m(S.pow(a.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,N=new t(1e15),p=!1,v=9){if(a=new t(a),N=new t(N).div(1e3),a.lt(N.mul(1e3)))return"";let{alphabet:S}=e.alphabet.config,E=S.length,O=a.log(1e3).sub(N.log(1e3)).floor(),G=O.add(1).log(E+1).ceil(),B="",Y=(Q,et)=>{let X=Q,J="";for(let K=0;K=E)return"\u03C9";J=S[ft]+J,X=X.sub(1).div(E).floor()}return J};if(G.lt(v))B=Y(O,G);else{let Q=G.sub(v).add(1),et=O.div(t.pow(E+1,Q.sub(1))).floor();B=`${Y(et,new t(v))}(${Q.gt("1e9")?Q.format():Q.format(0)})`}return B},format(a,N=2,p=9,v="mixed_sc",S=new t(1e15),E=!1,O){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return m(a,N,p,v);let G=e.alphabet.getAbbreviation(a,S,E,O),B=a.div(t.pow(1e3,a.log(1e3).floor()));return`${G.length>(O??9)+2?"":B.toFixed(N)+" "}${G}`}}},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 o(a){return a.toFixed(0).split("").map(N=>N==="-"?"\u208B":i[parseInt(N,10)]).join("")}function h(a){return a.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function g(a,N=2,p=9,v="st"){return m(a,N,p,v)}function m(a,N=2,p=9,v="mixed_sc"){a=new t(a);let S=a.lt(0)?"-":"";if(a.mag==1/0)return S+"Infinity";if(Number.isNaN(a.mag))return S+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(N);let E=a.log10().floor();switch(v){case"sc":case"scientific":if(a.log10().lt(Math.min(-N,0))&&N>1){let O=a.log10().ceil(),G=a.div(O.eq(-1)?new t(.1):t.dTen.pow(O)),B=O.mul(-1).max(1).log10().gte(9);return S+(B?"":G.toFixed(2))+"e"+m(O,0,p,"mixed_sc")}else if(E.lt(p)){let O=Math.max(Math.min(N-E.toNumber(),N),0);return S+(O>0?a.toFixed(O):a.toFixed(O).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let B=a.slog();return(B.gte(1e9)?"":t.dTen.pow(B.sub(B.floor())).toFixed(2))+"F"+m(B.floor(),0)}let O=a.div(t.dTen.pow(E)),G=E.log10().gte(9);return S+(G?"":O.toFixed(2))+"e"+m(E,0,p,"mixed_sc")}case"st":case"standard":{let O=a.log(1e3).floor();if(O.lt(1))return S+a.toFixed(Math.max(Math.min(N-E.toNumber(),N),0));let G=O.mul(3),B=O.log10().floor();if(B.gte(3e3))return"e"+m(E,N,p,"st");let Y="";if(O.lt(4))Y=["","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 J=O.div(1e3).floor(),K=O.sub(J.mul(1e3)).floor().toNumber();K>0&&(K==1&&!X&&(Y="U"),X&&(Y=e.standard.tier2(X)+(Y?"-"+Y:"")),K>1&&(Y=e.standard.tier1(K)+Y)),O=J,X++}}let Q=a.div(t.dTen.pow(G)),et=N===2?t.dTwo.sub(E.sub(G)).add(1).toNumber():N;return S+(B.gte(10)?"":Q.toFixed(et)+" ")+Y}default:return e[v]||console.error('Invalid format type "',v,'"'),S+e[v].format(a,N,p)}}function d(a,N,p="mixed_sc",v,S){a=new t(a),N=new t(N);let E=a.add(N),O,G=E.div(a);return G.gte(10)&&a.gte(1e100)?(G=G.log10().mul(20),O="(+"+m(G,v,S,p)+" OoMs/sec)"):O="(+"+m(N,v,S,p)+"/sec)",O}function I(a,N=2,p="s"){return a=new t(a),a.gte(86400)?m(a.div(86400).floor(),0,12,"sc")+":"+I(a.mod(86400),N,"d"):a.gte(3600)||p=="d"?(a.div(3600).gte(10)||p!="d"?"":"0")+m(a.div(3600).floor(),0,12,"sc")+":"+I(a.mod(3600),N,"h"):a.gte(60)||p=="h"?(a.div(60).gte(10)||p!="h"?"":"0")+m(a.div(60).floor(),0,12,"sc")+":"+I(a.mod(60),N,"m"):(a.gte(10)||p!="m"?"":"0")+m(a,N,12,"sc")}function F(a,N=!1,p=0,v=9,S="mixed_sc"){let E=Et=>m(Et,p,v,S);a=new t(a);let O=a.mul(1e3).mod(1e3).floor(),G=a.mod(60).floor(),B=a.div(60).mod(60).floor(),Y=a.div(3600).mod(24).floor(),Q=a.div(86400).mod(365.2425).floor(),et=a.div(31556952).floor(),X=et.eq(1)?" year":" years",J=Q.eq(1)?" day":" days",K=Y.eq(1)?" hour":" hours",ft=B.eq(1)?" minute":" minutes",Tt=G.eq(1)?" second":" seconds",Ft=O.eq(1)?" millisecond":" milliseconds";return`${et.gt(0)?E(et)+X+", ":""}${Q.gt(0)?E(Q)+J+", ":""}${Y.gt(0)?E(Y)+K+", ":""}${B.gt(0)?E(B)+ft+", ":""}${G.gt(0)?E(G)+Tt+",":""}${N&&O.gt(0)?" "+E(O)+Ft:""}`.replace(/,([^,]*)$/,"$1").trim()}function L(a){return a=new t(a),m(t.dOne.sub(a).mul(100))+"%"}function q(a){return a=new t(a),m(a.mul(100))+"%"}function j(a,N=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(N):"/"+a.pow(-1).format(N)}function w(a,N,p=10){return t.gte(a,10)?t.pow(p,t.log(a,p).pow(N)):new t(a)}function x(a,N=0){a=new t(a);let p=(O=>O.map((G,B)=>({name:G.name,altName:G.altName,value:t.pow(1e3,new t(B).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=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),p.length-1).floor().toNumber(),E=p[S];if(S===0)switch(N){case 1:v="";break;case 2:case 0:default:v=a.format();break}switch(N){case 1:v=E.name;break;case 2:v=a.divide(E.value).format();break;case 3:v=E.altName;break;case 0:default:v=`${a.divide(E.value).format()} ${E.name}`;break}return v}function V(a,N=!1){return`${x(a,2)} ${x(a,1)}eV${N?"/c^2":""}`}let W={...e,toSubscript:o,toSuperscript:h,formatST:g,format:m,formatGain:d,formatTime:I,formatTimeLong:F,formatReduction:L,formatPercent:q,formatMult:j,expMult:w,metric:x,ev:V};return{FORMATS:e,formats:W}}var Pt=17,_e=9e15,Ie=Math.log10(9e15),Se=1/9e15,Oe=308,Te=-324,Dt=5,Fe=1023,Ee=!0,Ae=!1,Ce=function(){let t=[];for(let r=Te+1;r<=Oe;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ht=[2,Math.E,3,4,5,6,7,8,9,10],Pe=[[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]],qe=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return n.fromValue_noAlloc(e)},C=function(t,e,r){return n.fromComponents(t,e,r)},b=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},ut=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(o.toFixed(Math.max(i-s,0)))},qt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},xe=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},ke=.36787944117144233,Xt=.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 Xt;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(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 o=e.add(i.mul(r)).sub(r.div(2)),h=o.pow(2);return o.neg().add(h.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=_e)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);Ee?t=t.replace(",",""):Ae&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let w=parseFloat(s[0]),x=parseFloat(s[1]),V=s[1].split(";"),W=1;if(V.length===2&&(W=parseFloat(V[1]),isFinite(W)||(W=1)),isFinite(w)&&isFinite(x)){let a=n.pentate(w,x,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let w=parseFloat(o[0]),x=parseFloat(o[1]),V=o[1].split(";"),W=1;if(V.length===2&&(W=parseFloat(V[1]),isFinite(W)||(W=1)),isFinite(w)&&isFinite(x)){let a=n.tetrate(w,x,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let h=t.split("^");if(h.length===2){let w=parseFloat(h[0]),x=parseFloat(h[1]);if(isFinite(w)&&isFinite(x)){let V=n.pow(w,x);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let g,m,d=t.split("pt");if(d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let V=n.tetrate(g,m,x,e);return this.sign=V.sign,this.layer=V.layer,this.mag=V.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}let I=t.split("e"),F=I.length-1;if(F===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(F===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let L=t.split("e^");if(L.length===2){this.sign=1,L[0].startsWith("-")&&(this.sign=-1);let w="";for(let x=0;x=43&&V<=57||V===101)w+=L[1].charAt(x);else return this.layer=parseFloat(w),this.mag=parseFloat(L[1].substr(x+1)),this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}if(F<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let q=parseFloat(I[0]);if(q===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let j=parseFloat(I[I.length-1]);if(F>=2){let w=parseFloat(I[I.length-2]);isFinite(w)&&(j*=Math.sign(w),j+=qt(w))}if(!isFinite(q))this.sign=I[0]==="-"?-1:1,this.layer=F,this.mag=j;else if(F===1)this.sign=Math.sign(q),this.layer=1,this.mag=j+Math.log10(Math.abs(q));else if(this.sign=Math.sign(q),this.layer=F,F===2){let w=n.mul(C(1,2,j),f(q));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=j;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ut(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ut(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=Dt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ut(this.m,t)+"e"+ut(this.e,t):this.layer===1?ut(this.m,t)+"e"+ut(this.e,t):this.layer<=Dt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ut(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ut(this.mag,t)}abs(){return b(this.sign===0?0:1,this.layer,this.mag)}neg(){return b(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?b(-1,0,1):b(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?C(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?b(1,0,1):b(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?C(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?b(0,0,0):this.layer===0?C(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return b(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(s-o>=2)return r;if(s===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Pt)return r;{let h=Math.pow(10,Math.log10(r.mag)-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}}if(s===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>Pt)return r;{let h=Math.pow(10,r.mag-Math.log10(i.mag)),g=i.sign+r.sign*h;return C(Math.sign(g),1,Math.log10(i.mag)+Math.log10(Math.abs(g)))}}if(Math.abs(r.mag-i.mag)>Pt)return r;{let h=Math.pow(10,r.mag-i.mag),g=i.sign+r.sign*h;return C(Math.sign(g),1,i.mag+Math.log10(Math.abs(g)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return b(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return b(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return C(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return C(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return C(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=C(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(C(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return C(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?b(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?b(0,0,0):this.layer===0?C(this.sign,0,1/this.mag):C(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(n.dZero))return b(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new n(r%i):this.sub(e).eq(this)?b(0,0,0):e.sub(this).eq(e)?new n(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=qt(s)),this.layer0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer>0?C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):C(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?C(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log2(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?C(this.sign,0,Math.log(this.mag)):this.layer===1?C(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?C(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):C(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?b(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return b(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:b(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return b(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return b(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return C(1,0,e);if(t.sign===0)return b(1,0,1);t=b(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?C(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?C(-t.sign,t.layer+1,-t.mag):b(1,0,1)}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(b(1,0,24)))return n.fromNumber(xe(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,o=1/s,h=e+o;if(h===e||(e=h,i=i*r,s=360*i,o=1/s,h=e-o,h===e))return n.exp(e);e=h,i=i*r,s=1260*i;let g=1/s;return e=e+g,i=i*r,s=1680*i,g=1/s,e=e-g,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?b(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?C(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?C(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):C(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return C(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(b(this.sign,this.layer-1,this.mag),b(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=b(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return b(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let h=n.ln(this).neg(),g=h.lambertw().div(h);if(o<1)return g;let m=h.lambertw(!1).div(h);return o>1.444667861009099&&(g=m=n.fromNumber(Math.E)),e=f(e),e.eq(m)?m:e.lt(m)?g:b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),n.fromNumber(o)}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 o=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let h=0;h1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let o=0;o3)return b(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=b(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=f(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let o=s-e;if(i.layer-t.layer>3){let h=Math.min(e,i.layer-t.layer-3);e-=h,i.layer-=h}for(let h=0;h1e4)return i}return 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,s=!1,o=!1,h=this.slog_internal(t,r).toNumber();for(let g=1;g1&&o!=d&&(s=!0),o=d,s?i/=2:i*=2,i=Math.abs(i)*(d?-1:1),h+=i,i===0)break}return n.fromNumber(h)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(n.dZero)||t.eq(n.dOne))return b(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?b(0,0,0):this.eq(n.dZero)?b(-1,0,1):b(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return b(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),o=s.lambertw().div(s);if(this.eq(o))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))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,qe)}static tetrate_critical(t,e){return n.critical_section(t,e,Pe)}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,o=0;for(let g=0;gt){let m=(t-ht[g])/(ht[g+1]-ht[g]);s=r[g][Math.floor(e)]*(1-m)+r[g+1][Math.floor(e)]*m,o=r[g][Math.ceil(e)]*(1-m)+r[g+1][Math.ceil(e)]*m;break}let h=e-Math.floor(e);return s<=0||o<=0?s*(1-h)+o*h:Math.pow(t,Math.log(s)/Math.log(t)*(1-h)+Math.log(o)/Math.log(t)*h)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=f(e);if(i.gt(1)&&i.lte(1.444667861009766)){let h=n.excess_slog(this,e,r),g=h[0].toNumber(),m=h[1],d=g+t,I=n.ln(e).neg(),F=I.lambertw().div(I),L=I.lambertw(!1).div(I),q=n.dOne;m==1?q=F.mul(L).sqrt():m==2&&(q=L.mul(2));let j=i.pow(q),w=Math.floor(d),x=d-w,V=q.pow(1-x).mul(j.pow(x));return n.tetrate(i,w,V,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?n.tetrate(e,o,n.dOne,r):Number.isFinite(o)?o>=-1?n.log(n.tetrate(e,o+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,o+2,n.dOne,r),e),e):b(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=f(t),e=f(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[b(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),o=s.lambertw().div(s),h=n.dInf;if(e>1&&(h=s.lambertw(!1).div(s)),e>1.444667861009099&&(o=h=n.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(h))return[b(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(h)){let g=h.mul(2),m=i.pow(g),d=0;if(t.gte(g)&&t.lt(m))d=0;else if(t.gte(m)){let w=m;for(d=1;w.lt(t);)if(w=i.pow(w),d=d+1,w.layer>3){let x=Math.floor(t.layer-w.layer+1);w=i.iteratedexp(x,w,r),d=d+x}w.gt(t)&&(w=w.log(e),d=d-1)}else if(t.lt(g)){let w=g;for(d=0;w.gt(t);)w=w.log(e),d=d-1}let I=0,F=0,L=.5,q=g,j=n.dZero;for(;L>1e-16;){if(F=I+L,q=g.pow(1-F).mul(m.pow(F)),j=n.iteratedexp(e,d,q),j.eq(t))return[new n(d+F),2];j.lt(t)&&(I+=L),L/=2}return j.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),2]}if(t.lt(h)&&t.gt(o)){let g=o.mul(h).sqrt(),m=i.pow(g),d=0;if(t.lte(g)&&t.gt(m))d=0;else if(t.lte(m)){let w=m;for(d=1;w.gt(t);)w=i.pow(w),d=d+1;w.lt(t)&&(w=w.log(e),d=d-1)}else if(t.gt(g)){let w=g;for(d=0;w.lt(t);)w=w.log(e),d=d-1}let I=0,F=0,L=.5,q=g,j=n.dZero;for(;L>1e-16;){if(F=I+L,q=g.pow(1-F).mul(m.pow(F)),j=n.iteratedexp(e,d,q),j.eq(t))return[new n(d+F),1];j.gt(t)&&(I+=L),L/=2}return j.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")?Qt(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?Qt(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 eke?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),o=s,h=s.div(2),g=!0;for(;g;)h=r.add(s).div(2),n.iteratedexp(10,i,h,!0).tetrate(t,1,!0).gt(this)?s=h:r=h,h.eq(o)?g=!1:o=h;return n.iteratedexp(10,i,h,!0)}else{let e=1,r=C(1,10,1),i=C(1,10,1),s=C(1,10,1),o=C(1,1,-16),h=n.dZero,g=C(1,10,1),m=o.pow10().recip(),d=n.dZero,I=m,F=m,L=Math.ceil(t)%2==0,q=0,j=C(1,10,1),w=!1,x=n.dZero,V=!1;for(;e<4;){if(e==2){if(L)break;s=C(1,10,1),o=r,e=3,g=C(1,10,1),j=C(1,10,1)}for(w=!1;o.neq(s);){if(x=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))m=o.pow10().recip(),I=o.pow10().recip(),F=o.pow10().recip(),d=n.dZero,q=-1,e==3&&(j=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!L&&o.pow10().recip().lt(.4))m=o.pow10().recip(),I=o.pow10().recip(),F=o.pow10().recip(),d=n.dZero,q=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))m=o.pow10().recip(),I=n.dZero,F=m.mul(2),d=m,L?q=-1:q=0;else{for(h=o.mul(12e-17),m=o.pow10().recip(),I=o.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);I.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||F.tetrate(t,1,!0).eq(m.tetrate(t,1,!0))||I.gte(m)||F.lte(m);)h=h.mul(2),I=o.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);if((e==1&&F.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(m.tetrate(t,1,!0))||e==3&&F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))&&(j=o),F.tetrate(t,1,!0).lt(m.tetrate(t,1,!0)))q=-1;else if(L)q=1;else if(e==3&&o.gt_tolerance(r,1e-8))q=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||F.tetrate(t,1,!0).eq_tolerance(m.tetrate(t,1,!0),1e-8)||I.gte(m)||F.lte(m);)h=h.mul(2),I=o.add(h).pow10().recip(),d=m.sub(I),F=m.add(d);F.tetrate(t,1,!0).sub(m.tetrate(t,1,!0)).lt(m.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?q=0:q=1}}if(q==-1&&(V=!0),e==1&&q==1||e==3&&q!=0)if(s.eq(C(1,10,1)))o=o.mul(2);else{let p=!1;if(w&&(q==1&&e==1||q==-1&&e==3)&&(p=!0),o=o.add(s).div(2),p)break}else if(s.eq(C(1,10,1)))s=o,o=o.div(2);else{let p=!1;if(w&&(q==1&&e==1||q==-1&&e==3)&&(p=!0),s=s.sub(g),o=o.sub(g),p)break}if(s.sub(o).div(2).abs().gt(g.mul(1.5))&&(w=!0),g=s.sub(o).div(2).abs(),o.gt("1e18")||o.eq(x))break}if(o.gt("1e18")||!V||j==C(1,10,1))break;e==1?r=j:e==3&&(i=j),e++}s=r,o=C(1,1,-18);let W=o,a=n.dZero,N=!0;for(;N;)if(s.eq(C(1,10,1))?a=o.mul(2):a=s.add(o).div(2),n.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:s=a,a.eq(W)?N=!1:W=a,o.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);if(a.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),o=i,W=o,a=n.dZero,N=!0;N;)if(s.eq(C(1,10,1))?a=o.mul(2):a=s.add(o).div(2),n.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:s=a,a.eq(W)?N=!1:W=a,o.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.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 o=0;o10)return e}return e}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):b(0,0,0)}cos(){return this.mag<0?b(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):b(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):b(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?b(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return lt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return lt.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return lt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return lt.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return lt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return lt.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let o of Object.keys(i)){let h=Math.floor(r/i[o]);r-=h*i[o],s+=o.repeat(h)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=b(0,0,0),n.dOne=b(1,0,1),n.dNegOne=b(-1,0,1),n.dTwo=b(1,0,2),n.dTen=b(1,0,10),n.dNaN=b(Number.NaN,Number.NaN,Number.NaN),n.dInf=b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=C(1,0,Number.MAX_VALUE),n.dNumberMin=C(1,0,Number.MIN_VALUE),n.fromStringCache=new At(Fe),st([_t()],n.prototype,"sign",2),st([_t()],n.prototype,"mag",2),st([_t()],n.prototype,"layer",2),n=st([we()],n);var{formats:lt,FORMATS:Le}=Me(n);n.formats=lt;var ct=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:()=>""}},kt=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 ct(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sF),d=s,I=this.getBoosts(o,!0);I[0][0]?this.boostArray[I[1][0]]=new ct({id:o,name:h,description:g,value:m,order:d}):this.boostArray.push(new ct({id:o,name:h,description:g,value:m,order:d}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let h=this.getBoosts(o.id,!0);h[0][0]?this.boostArray[h[1][0]]=new ct(o):this.boostArray.push(new ct(o))}}}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}},ur=Nt(bt()),St=30,Lt=.001;function Ve(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 Vt(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,o;return i.mode==="geometric"?(s=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=s.lte(r)):(s=t.sub(e).abs(),o=s.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:s,result:o}),o}function Bt(t,e,r="geometric",i=St,s=Lt){let o=n.dOne,h=new n(e);if(t(h).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(h).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:h,lowerBound:h,upperBound:h};for(let m=0;m=0;g--){let m=r.add(h.mul(g)),d=r.add(h.mul(g+1)),I=o;if(o=o.add(t(m).add(t(d)).div(2).mul(h)),Vt(I,o,s,{verbose:!1,mode:"geometric"}))break}return o}function Ut(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(St)?Jt(t,e,r,i):Kt(t,e,r,s)}function Be(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)),o=t.div(n.pow(e,s));return o=o.mul(n.pow(e,r)).round(),o=o.div(n.pow(e,r)),o=o.mul(n.pow(e,s)),o}function te(t,e,r,i=1/0,s,o,h=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let g=i.sub(r);if(g.lt(0))return console.warn("calculateUpgrade: Invalid target: ",g),[n.dZero,n.dZero];if(h=(typeof e.el=="function"?e.el():e.el)??h,g.eq(1)){let F=e.cost(e.level),L=t.gte(F),q=[n.dZero,n.dZero];return h?(q[0]=L?n.dOne:n.dZero,q):(q=[L?n.dOne:n.dZero,L?F:n.dZero],q)}if(e.costBulk){let[F,L]=e.costBulk(t,e.level,g),q=t.gte(L);return[q?F:n.dZero,q&&!h?L:n.dZero]}if(h){let F=j=>e.cost(j.add(r)),L=n.min(i,Bt(F,t,s,o).value.floor()),q=n.dZero;return[L,q]}let m=Bt(F=>Ut(e.cost,F,r),t,s,o).value.floor().min(r.add(g).sub(1)),d=Ut(e.cost,m,r);return[m.sub(r).add(1).max(0),d]}function ee(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function Ue(t){return`el/${ee(t)}`}var yt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};st([_t()],yt.prototype,"id",2),st([It(()=>n)],yt.prototype,"level",2);var re=class ge{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}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){let s=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>s,this.cache=new At(i??ge.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}},lr=Nt(bt()),Ot=class{constructor(){this.value=n.dZero,this.upgrades={}}};st([It(()=>n)],Ot.prototype,"value",2),st([It(()=>yt)],Ot.prototype,"upgrades",2);var Re=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Ot,e,r={defaultVal:n.dZero,defaultBoost:n.dOne}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new kt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=new n(i.defaultLevel),r&&i.effect?.(i.level,i,this)}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 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 s=new re(i,()=>this.pointerGetUpgrade(i.id));s.effect&&e&&s.effect(s.level,s,this),this.upgrades[i.id]=s,r.push(s)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}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)),te(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 o=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(o))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),n.dZero;let o=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,h]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(h),s.level=s.level.add(o),s.effect?.(s.level,s,this),!0)}},fr=Nt(bt()),Rt=class{constructor(t=0){this.value=new n(t)}};st([It(()=>n)],Rt.prototype,"value",2);var Ge=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new Rt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new kt(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}},ie=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},je=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{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})(),Ze=Ht;if(typeof it.exports=="object"&&typeof dt=="object"){var $e=(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};it.exports=$e(it.exports,dt)}return it.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.mjs b/dist/main/eMath.mjs index d37fe49..76d7e27 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -4821,20 +4821,26 @@ Decimal.formats = formats; // src/classes/Boost.ts var BoostObject = class { - // eslint-disable-next-line jsdoc/require-returns - /** @deprecated Use {@link description} instead */ + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ get desc() { return this.description; } get description() { return this.descriptionFn(); } + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ constructor(init) { this.id = init.id; this.name = init.name ?? ""; - this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; this.value = init.value; this.order = init.order ?? 99; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; } }; var Boost = class { @@ -5228,10 +5234,6 @@ var UpgradeStatic = class _UpgradeStatic { import "reflect-metadata"; import { Type as Type2 } from "class-transformer"; var Currency = class { - // public upgrades: UpgradeData[]; - // /** A boost object that affects the currency gain. */ - // @Expose() - // public boost: boost; /** * Constructs a new currency object with an initial value of 0. */ @@ -5286,13 +5288,7 @@ var CurrencyStatic = class { this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; this.boost = new Boost(this.defaultBoost); this.pointer.value = this.defaultVal; - this.upgrades = { - // *[Symbol.iterator] () { - // for (const upgrade of Object.values(this)) { - // yield upgrade; - // } - // }, - }; + this.upgrades = {}; if (upgrades) this.addUpgrade(upgrades); } /** @@ -5365,6 +5361,39 @@ var CurrencyStatic = class { getUpgrade(id) { return this.upgrades[id] ?? null; } + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + queryUpgrade(id) { + const allUpgradeIds = Object.keys(this.upgrades); + if (id instanceof RegExp) { + const regex = id; + const matchedIds = allUpgradeIds.filter((upgrade) => regex.test(upgrade)); + return matchedIds.map((matchedId) => this.upgrades[matchedId]); + } + if (typeof id === "string") { + id = [id]; + } + const matchedUpgrades = allUpgradeIds.filter((upgrade) => id.includes(upgrade)); + return matchedUpgrades.map((matchedId) => this.upgrades[matchedId]); + } /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -5393,20 +5422,20 @@ var CurrencyStatic = class { */ addUpgrade(upgrades, runEffectInstantly = true) { if (!Array.isArray(upgrades)) upgrades = [upgrades]; - const addedUpgradeList = {}; + const addedUpgradeList = []; for (const upgrade of upgrades) { - const addedUpgradeData = this.pointerAddUpgrade(upgrade); + this.pointerAddUpgrade(upgrade); const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id)); if (addedUpgradeStatic.effect && runEffectInstantly) addedUpgradeStatic.effect(addedUpgradeStatic.level, addedUpgradeStatic, this); - addedUpgradeList[upgrade.id] = addedUpgradeStatic; this.upgrades[upgrade.id] = addedUpgradeStatic; + addedUpgradeList.push(addedUpgradeStatic); } - return Object.values(addedUpgradeList); + return addedUpgradeList; } /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -5417,13 +5446,10 @@ var CurrencyStatic = class { * } * }); */ - updateUpgrade(id, upgrade) { - const upgrade1 = this.getUpgrade(id); - if (upgrade1 === null) return; - upgrade1.name = upgrade.name ?? upgrade1.name; - upgrade1.cost = upgrade.cost ?? upgrade1.cost; - upgrade1.maxLevel = upgrade.maxLevel ?? upgrade1.maxLevel; - upgrade1.effect = upgrade.effect ?? upgrade1.effect; + updateUpgrade(id, newUpgrade) { + const oldUpgrade = this.getUpgrade(id); + if (oldUpgrade === null) return; + Object.assign(oldUpgrade, newUpgrade); } /** * Calculates the cost and how many upgrades you can buy. @@ -5437,7 +5463,6 @@ var CurrencyStatic = class { * // Calculate how many healthBoost upgrades you can buy and the cost of the upgrades * const [amount, cost] = currency.calculateUpgrade("healthBoost", 10); */ - // public calculateUpgrade (id: string, target: DecimalSource = 1, el: boolean = false): [amount: Decimal, cost: Decimal] { calculateUpgrade(id, target = Infinity, mode, iterations) { const upgrade = this.getUpgrade(id); if (upgrade === null) { diff --git a/dist/types/classes/Boost.d.ts b/dist/types/classes/Boost.d.ts index 73c1fb7..434ac5a 100644 --- a/dist/types/classes/Boost.d.ts +++ b/dist/types/classes/Boost.d.ts @@ -4,7 +4,9 @@ import { Decimal } from "../E/e"; import type { DecimalSource } from "../E/e"; import type { Pointer } from "../common/types"; -/** An object representing a boost. */ +/** + * An object representing a boost. + */ interface BoostsObjectInit { /** The ID of the boost. */ id: string; @@ -44,17 +46,26 @@ interface BoostsObjectInit { /** The order at which the boost is applied. Lower orders are applied first. */ order?: number; } -/** Represents an indiviual boost object. */ +/** + * Represents an indiviual boost object. + */ declare class BoostObject implements BoostsObjectInit { id: string; name: string; + value: (input: Decimal) => Decimal; + order: number; descriptionFn: (...args: any[]) => string; - /** @deprecated Use {@link description} instead */ + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ get desc(): string; get description(): string; - value: (input: Decimal) => Decimal; - order: number; - constructor(init: BoostObject | BoostsObjectInit); + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ + constructor(init: BoostsObjectInit); } /** * Represents a boost manager that applies various effects to a base value. @@ -105,11 +116,12 @@ declare class Boost { removeBoost(id: string): void; /** * Sets or updates a boost with the given parameters. + * @deprecated Use the other overload instead. * @param id - The ID of the boost. * @param name - The name of the boost. * @param description - The description of the boost. * @param value - The value of the boost (function). - * @param order - The order of the boost (higher order go first) + * @param order - The order of the boost (lower order go first) * @example * // Set a boost that multiplies the input value by 2 * boost.setBoost("doubleBoost", "Double Boost", "Doubles the input value", (input) => input.mul(2)); diff --git a/dist/types/classes/Currency.d.ts b/dist/types/classes/Currency.d.ts index f8176ed..60d5144 100644 --- a/dist/types/classes/Currency.d.ts +++ b/dist/types/classes/Currency.d.ts @@ -3,11 +3,11 @@ */ import "reflect-metadata"; import { Decimal, DecimalSource } from "../E/e"; -import type { Pointer } from "../common/types"; import { Boost } from "./Boost"; import { MeanMode } from "./numericalAnalysis"; -import { UpgradeData, UpgradeStatic, UpgradeInit, UpgradeInitArrayType } from "./Upgrade"; -import type { IsPrimitiveString } from "../common/types"; +import { UpgradeData, UpgradeStatic } from "./Upgrade"; +import type { UpgradeInitArrayType, UpgradeInit } from "./Upgrade"; +import type { Pointer, IsPrimitiveString } from "../common/types"; /** * Represents the frontend READONLY for a currency. Useful for saving / data management. * Note: This class is created by default when creating a {@link CurrencyStatic} class. Use that instead as there are no methods here. @@ -119,6 +119,27 @@ declare class CurrencyStatic[] = [], S extends s * console.log(upgrade); // upgrade object */ getUpgrade(id: T): IsPrimitiveString extends false ? UpgradeStatic : UpgradeStatic | null; + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + queryUpgrade(id: S | S[] | RegExp): UpgradeStatic[]; /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -149,7 +170,7 @@ declare class CurrencyStatic[] = [], S extends s /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -160,7 +181,7 @@ declare class CurrencyStatic[] = [], S extends s * } * }); */ - updateUpgrade(id: S, upgrade: Partial): void; + updateUpgrade(id: S, newUpgrade: Partial): void; /** * Calculates the cost and how many upgrades you can buy. * See {@link calculateUpgrade} for more information. diff --git a/src/classes/Boost.ts b/src/classes/Boost.ts index cb08b03..02a0768 100644 --- a/src/classes/Boost.ts +++ b/src/classes/Boost.ts @@ -3,10 +3,11 @@ */ import { Decimal } from "../E/e"; import type { DecimalSource } from "../E/e"; -// import { Type, Expose } from "class-transformer"; import type { Pointer } from "../common/types"; -/** An object representing a boost. */ +/** + * An object representing a boost. + */ interface BoostsObjectInit { /** The ID of the boost. */ id: string; @@ -53,36 +54,36 @@ interface BoostsObjectInit { order?: number; } -/** Represents an indiviual boost object. */ +/** + * Represents an indiviual boost object. + */ class BoostObject implements BoostsObjectInit { - // public id; name; desc; value; order; - public id: string; - public name: string; - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // Assign the properties from the BoostsObjectInit interface + public id; name; value; order; + + // TODO: Change the args of descriptionFn to be more specific public descriptionFn: (...args: any[]) => string; - // eslint-disable-next-line jsdoc/require-returns - /** @deprecated Use {@link description} instead */ + + /** + * @returns The description of the boost. + * @deprecated Use {@link description} instead + */ public get desc (): string { return this.description; } - public get description (): string { - return this.descriptionFn(); - } - public value: (input: Decimal) => Decimal; - public order: number; + public get description (): string { return this.descriptionFn(); } - constructor (init: BoostObject | BoostsObjectInit) { - // if (init instanceof boostObject) { - // init = init as boostObject; - // } + /** + * Constructs a new boost object. + * @param init - The initialization object. + */ + constructor (init: BoostsObjectInit) { + // Assign the properties from the BoostsObjectInit interface this.id = init.id; this.name = init.name ?? ""; - // this.desc = init.desc ?? ""; - this.descriptionFn = init.description ? (typeof init.description === "function" ? init.description : (): string => init.description as string) : (): string => ""; - // this.descriptionFn = init.description || init.desc ? - // (init.description ? (typeof init.description === "function" ? init.description : () => init.description as string) : ( - // init.desc ? (typeof init.desc === "function" ? init.desc : () => init.desc as string) : () => "" - // )) this.value = init.value; this.order = init.order ?? 99; + + // Assign the description function + this.descriptionFn = init.description ? (typeof init.description === "function" ? init.description : (): string => init.description as string) : (): string => ""; } } @@ -92,11 +93,9 @@ class BoostObject implements BoostsObjectInit { */ class Boost { /** An array of boost objects. */ - // @Type(() => boostObject) public readonly boostArray: BoostObject[]; /** The base effect value. */ - // @Expose() public readonly baseEffect: Decimal; /** @@ -136,7 +135,6 @@ class Boost { const boostList: BoostObject[] = []; const indexList: number[] = []; for (let i = 0; i < this.boostArray.length; i++) { - // if (i === this.boostArray.length) break; if ( (typeof id === "string" && id === this.boostArray[i].id) || (id instanceof RegExp && id.test(this.boostArray[i].id)) @@ -176,11 +174,12 @@ class Boost { /** * Sets or updates a boost with the given parameters. + * @deprecated Use the other overload instead. * @param id - The ID of the boost. * @param name - The name of the boost. * @param description - The description of the boost. * @param value - The value of the boost (function). - * @param order - The order of the boost (higher order go first) + * @param order - The order of the boost (lower order go first) * @example * // Set a boost that multiplies the input value by 2 * boost.setBoost("doubleBoost", "Double Boost", "Doubles the input value", (input) => input.mul(2)); @@ -200,9 +199,13 @@ class Boost { */ public setBoost (boostObj: BoostsObjectInit | BoostsObjectInit[]): void; public setBoost (arg1: string | (BoostsObjectInit | BoostsObjectInit[]), arg2?: string, arg3?: string, arg4?: (input: Decimal) => Decimal, arg5?: number): void { - if (!arg1) return; // class-transformer bug + // class-transformer bug where it doesn't recognize the overload + if (!arg1) return; + if (typeof arg1 === "string") { // Basic set using parameters + + // Assign the parameters to the variables const id = arg1; const name = arg2 ?? ""; const description = arg3 ?? ""; @@ -245,6 +248,7 @@ class Boost { public calculate (base: DecimalSource = this.baseEffect): Decimal { let output: Decimal = new Decimal(base); let boosts = this.boostArray; + // Sort boosts by order from lowest to highest boosts = boosts.sort((a: BoostObject, b: BoostObject) => a.order - b.order); for (const boost of boosts) { diff --git a/src/classes/Currency.ts b/src/classes/Currency.ts index 0e1308e..ac46eb1 100644 --- a/src/classes/Currency.ts +++ b/src/classes/Currency.ts @@ -3,15 +3,14 @@ */ import "reflect-metadata"; // Required for class-transformer import { Type } from "class-transformer"; -import { Decimal, DecimalSource } from "../E/e"; -// import { Decimal } from "../E/e"; -import type { Pointer } from "../common/types"; +import { Decimal, DecimalSource } from "../E/e"; import { Boost } from "./Boost"; import { MeanMode } from "./numericalAnalysis"; -import { UpgradeData, UpgradeStatic, UpgradeInit, UpgradeInitArrayType, calculateUpgrade } from "./Upgrade"; +import { UpgradeData, UpgradeStatic, calculateUpgrade } from "./Upgrade"; -import type { IsPrimitiveString, Mutable } from "../common/types"; +import type { UpgradeInitArrayType, UpgradeInit } from "./Upgrade"; +import type { Pointer, IsPrimitiveString, Mutable } from "../common/types"; /** * Represents the frontend READONLY for a currency. Useful for saving / data management. @@ -25,20 +24,13 @@ class Currency { /** An array that represents upgrades and their levels. */ @Type(() => UpgradeData) public upgrades: Record; - // public upgrades: UpgradeData[]; - - // /** A boost object that affects the currency gain. */ - // @Expose() - // public boost: boost; /** * Constructs a new currency object with an initial value of 0. */ constructor () { this.value = Decimal.dZero; - // this.upgrades = []; this.upgrades = {}; - // this.boost = new boost(); } } @@ -54,12 +46,7 @@ class Currency { */ class CurrencyStatic[] = [], S extends string = UpgradeInitArrayType> { /** An array that represents upgrades, their costs, and their effects. */ - // public upgrades: upgradeStatic[]; public readonly upgrades: Record; - // public upgrades: { - // [id: string]: UpgradeStatic; - // [Symbol.iterator]: IterableIterator; - // }; /** A function that returns the pointer of the data */ protected readonly pointerFn: (() => Currency); @@ -109,36 +96,31 @@ class CurrencyStatic[] = [], S extends string = * // CurrencyStatic<["upgId1", "upgId2"]> */ constructor (pointer: Pointer = new Currency(), upgrades?: U, defaults = { defaultVal: Decimal.dZero, defaultBoost: Decimal.dOne }) { - // this.defaultVal = new Decimal(defaultVal); - // this.defaultBoost = new Decimal(defaultBoost); + // Assign the default values this.defaultVal = defaults.defaultVal; this.defaultBoost = defaults.defaultBoost; + // Assign the pointer function this.pointerFn = typeof pointer === "function" ? pointer : (): Currency => pointer; + + // Set the boost object this.boost = new Boost(this.defaultBoost); - // this.upgradeCache = new LRUCache(CurrencyStatic.cacheSize); + // Set the pointer value to the default value this.pointer.value = this.defaultVal; - // this.upgrades = []; // @ts-expect-error - Properties are added in the next line - this.upgrades = { - // *[Symbol.iterator] () { - // for (const upgrade of Object.values(this)) { - // yield upgrade; - // } - // }, - }; + this.upgrades = {}; + // Add upgrades if (upgrades) this.addUpgrade(upgrades); - - // this.upgrades = this.upgrades; } /** * Updates / applies effects to the currency on load. */ public onLoadData (): void { + // Call the effect function for each upgrade for (const upgrade of Object.values(this.upgrades)) { (upgrade as UpgradeStatic).effect?.((upgrade as UpgradeStatic).level, (upgrade as UpgradeStatic), this as CurrencyStatic); } @@ -154,13 +136,16 @@ class CurrencyStatic[] = [], S extends string = * console.log(currency.value); // Decimal.dZero, or the default value */ public reset (resetCurrency = true, resetUpgradeLevels = true, runUpgradeEffect = true): void { + // Reset the value if (resetCurrency) this.value = this.defaultVal; + + // Reset the upgrades if (resetUpgradeLevels) { - // this.upgrades.forEach((upgrade) => { - // upgrade.level = Decimal.dZero; - // }); for (const upgrade of Object.values(this.upgrades)) { + // Reset the level to the default level (upgrade as UpgradeStatic).level = new Decimal((upgrade as UpgradeStatic).defaultLevel); + + // Call the effect function for each upgrade if (runUpgradeEffect) (upgrade as UpgradeStatic).effect?.((upgrade as UpgradeStatic).level, (upgrade as UpgradeStatic), this as CurrencyStatic); } }; @@ -187,8 +172,6 @@ class CurrencyStatic[] = [], S extends string = */ private pointerAddUpgrade (upgrades: UpgradeInit): UpgradeData { const upgradesToAdd = new UpgradeData(upgrades); - // this.pointer.upgrades.push(upgradesToAdd); - // console.log("pointerAdd", { upgradesToAdd }); this.pointer.upgrades[upgradesToAdd.id] = upgradesToAdd; return upgradesToAdd; }; @@ -199,7 +182,6 @@ class CurrencyStatic[] = [], S extends string = * @returns The upgrade object if found, otherwise null. */ private pointerGetUpgrade (id: string): UpgradeData | null { - // console.log("pointerGet", { id, upgrades: this.pointer }); return this.pointer.upgrades[id] ?? null; } @@ -212,17 +194,52 @@ class CurrencyStatic[] = [], S extends string = * const upgrade = currency.getUpgrade("healthBoost"); * console.log(upgrade); // upgrade object */ - public getUpgrade (id: T): IsPrimitiveString extends false ? - // { - // [K in keyof U]: U[K]["id"] extends T ? ConvertInitToStatic : never; - // }[number] - UpgradeStatic - : UpgradeStatic | null { + public getUpgrade (id: T): IsPrimitiveString extends false ? UpgradeStatic : UpgradeStatic | null { // // @ts-expect-error - This is a hack to get the type to work // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition return this.upgrades[id] ?? null; } + /** + * Queries upgrades based on the provided id. Returns an array of upgrades that match the id. + * @param id - The id of the upgrade to query. + * @returns An array of upgrades that match the id. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { id: "healthBoostSmall", cost: (level) => level.mul(10) }, + * { id: "healthBoostLarge", cost: (level) => level.mul(20) }, + * { id: "damageBoostSmall", cost: (level) => level.mul(10) }, + * { id: "damageBoostLarge", cost: (level) => level.mul(20) }, + * ] as const satisfies UpgradeInit[]); + * + * // Get all health upgrades + * const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }] + * + * // Get all small upgrades + * const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]); + * // or + * const smallUpgrades2 = currency.queryUpgrade(/.*Small/); + */ + public queryUpgrade (id: S | S[] | RegExp): UpgradeStatic[] { + const allUpgradeIds = Object.keys(this.upgrades) as S[]; + + // If the id is a regular expression search for all upgrades that match the regex + if (id instanceof RegExp) { + const regex = id; + const matchedIds = allUpgradeIds.filter((upgrade) => regex.test(upgrade)); + return matchedIds.map((matchedId) => this.upgrades[matchedId]); + } + + // Convert to array if not already + if (typeof id === "string") { + id = [id]; + } + + // If the id is an array, return all upgrades that match the ids + const matchedUpgrades = allUpgradeIds.filter((upgrade) => id.includes(upgrade)); + return matchedUpgrades.map((matchedId) => this.upgrades[matchedId]); + } + /** * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. * @param upgrades - An array of upgrade objects. @@ -250,35 +267,37 @@ class CurrencyStatic[] = [], S extends string = * }); */ public addUpgrade (upgrades: UpgradeInit | UpgradeInit[], runEffectInstantly = true): UpgradeStatic[] { + // Convert to array if not already if (!Array.isArray(upgrades)) upgrades = [upgrades]; - // console.log({ upgrades }); + // Create an array to store the added upgrades + const addedUpgradeList: UpgradeStatic[] = []; - // Adds standard (object instead of array) - const addedUpgradeList: Record = {}; for (const upgrade of upgrades) { - // console.log(upgrade.id); + // Add the upgrade to the data + this.pointerAddUpgrade(upgrade); - const addedUpgradeData = this.pointerAddUpgrade(upgrade); - // const addedUpgradeStatic = new UpgradeStatic(upgrade, () => addedUpgradeData); - // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style - const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id) as UpgradeData); + // Create the upgrade object + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const addedUpgradeStatic = new UpgradeStatic(upgrade, () => this.pointerGetUpgrade(upgrade.id)!); + // Run the effect instantly if needed if (addedUpgradeStatic.effect && runEffectInstantly) addedUpgradeStatic.effect(addedUpgradeStatic.level, addedUpgradeStatic, this as CurrencyStatic); - addedUpgradeList[upgrade.id] = addedUpgradeStatic; + + // Add the upgrade to this.upgrades (this.upgrades as Record)[upgrade.id] = addedUpgradeStatic; - } - // console.log({ addedUpgradeList }); + // Add the upgrade to the list + addedUpgradeList.push(addedUpgradeStatic); + } - // return addedUpgradeList; - return Object.values(addedUpgradeList); + return addedUpgradeList; } /** * Updates an upgrade. To create an upgrade, use {@link addUpgrade} instead. * @param id - The id of the upgrade to update. - * @param upgrade - The upgrade object to update. + * @param newUpgrade - The new upgrade object. * @example * currency.updateUpgrade("healthBoost", { * name: "New Health Boost". @@ -289,15 +308,15 @@ class CurrencyStatic[] = [], S extends string = * } * }); */ - public updateUpgrade (id: S, upgrade: Partial): void { - // const upgrade1 = this.getUpgrade(id); - const upgrade1 = (this.getUpgrade(id) as Mutable | null); - if (upgrade1 === null) return; - - upgrade1.name = upgrade.name ?? upgrade1.name; - upgrade1.cost = upgrade.cost ?? upgrade1.cost; - upgrade1.maxLevel = upgrade.maxLevel ?? upgrade1.maxLevel; - upgrade1.effect = upgrade.effect ?? upgrade1.effect; + public updateUpgrade (id: S, newUpgrade: Partial): void { + // Get the upgrade + const oldUpgrade = (this.getUpgrade(id) as Mutable | null); + + // If the upgrade doesn't exist, return + if (oldUpgrade === null) return; + + // Update the upgrade + Object.assign(oldUpgrade, newUpgrade); } /** @@ -312,10 +331,11 @@ class CurrencyStatic[] = [], S extends string = * // Calculate how many healthBoost upgrades you can buy and the cost of the upgrades * const [amount, cost] = currency.calculateUpgrade("healthBoost", 10); */ - // public calculateUpgrade (id: string, target: DecimalSource = 1, el: boolean = false): [amount: Decimal, cost: Decimal] { public calculateUpgrade (id: S, target: DecimalSource = Infinity, mode?: MeanMode, iterations?: number): [amount: Decimal, cost: Decimal] { - // const [id] = args; + // Get the upgrade const upgrade = this.getUpgrade(id); + + // If the upgrade doesn't exist, return [0, 0] if (upgrade === null) { console.warn(`Upgrade "${id}" not found.`); return [Decimal.dZero, Decimal.dZero]; @@ -324,10 +344,8 @@ class CurrencyStatic[] = [], S extends string = // Calculate the target based on the maxLevel target = upgrade.level.add(target); + // Cap the target to the max level if it exists if (upgrade.maxLevel !== undefined) { - // target = Decimal.min(target, upgrade.maxLevel.sub(upgrade.level)); - // console.log({ target, maxLevel: upgrade.maxLevel, level: upgrade.level }); - target = Decimal.min(target, upgrade.maxLevel); } @@ -347,14 +365,19 @@ class CurrencyStatic[] = [], S extends string = * const nextCost = currency.getNextCost("healthBoost"); */ public getNextCost (id: S, target: DecimalSource = 1, mode?: MeanMode, iterations?: number): Decimal { - // throw new Error("This function is broken and may throw a RangeError. Use calculateUpgrade instead."); + // Get the upgrade const upgrade = this.getUpgrade(id); + + // If the upgrade doesn't exist, return 0 if (upgrade === null) { console.warn(`Upgrade "${id}" not found.`); return Decimal.dZero; } + + // Calculate the amount of upgrades you can buy const amount = this.calculateUpgrade(id, target, mode, iterations)[0]; + // Calculate the cost of the next upgrade const nextCost = upgrade.cost(upgrade.level.add(amount)); return nextCost; } @@ -373,12 +396,19 @@ class CurrencyStatic[] = [], S extends string = * console.log(currency.getNextCostMax("healthBoost")); // The cost of the next upgrade after the maximum affordable quantity. (The cost of the 101st upgrade) */ public getNextCostMax (id: S, target: DecimalSource = 1, mode?: MeanMode, iterations?: number): Decimal { + // Get the upgrade const upgrade = this.getUpgrade(id); + + // If the upgrade doesn't exist, return 0 if (upgrade === null) { console.warn(`Upgrade "${id}" not found.`); return Decimal.dZero; } + + // Calculate the amount of upgrades you can buy const upgCalc = this.calculateUpgrade(id, target, mode, iterations); + + // Calculate the cost of the next upgrade after the maximum affordable quantity const nextCost = upgrade.cost(upgrade.level.add(upgCalc[0])) .add(upgCalc[1]); return nextCost; @@ -396,12 +426,16 @@ class CurrencyStatic[] = [], S extends string = * currency.buyUpgrade("healthBoost", 10); */ public buyUpgrade (id: S, target?: DecimalSource, mode?: MeanMode, iterations?: number): boolean { + // Get the upgrade const upgrade = this.getUpgrade(id); + + // If the upgrade doesn't exist, return false if (upgrade === null) { console.warn(`Upgrade "${id}" not found.`); return false; } + // Calculate the amount of upgrades you can buy const [amount, cost] = this.calculateUpgrade(id, target, mode, iterations); // Check if affordable @@ -415,8 +449,6 @@ class CurrencyStatic[] = [], S extends string = // Set the upgrade level upgrade.level = upgrade.level.add(amount); - // console.log("upgrade.level", upgrade.level); - // Call the effect function if it exists upgrade.effect?.(upgrade.level, upgrade, this as CurrencyStatic);