From a8e8179170e55e3237ef80186d6115dfda6331f8 Mon Sep 17 00:00:00 2001 From: xShadowBlade Date: Fri, 7 Jun 2024 17:35:04 +0700 Subject: [PATCH] Update README.md, format.ts --- README.md | 42 +- dist/game/eMath.game.js | 2 +- dist/game/eMath.game.min.js | 2 +- dist/game/eMath.game.mjs | 2 +- dist/main/eMath.js | 2 +- dist/main/eMath.min.js | 2 +- dist/main/eMath.mjs | 2 +- dist/presets/eMath.presets.js | 2363 +++++++++++++++++++++++++++- dist/presets/eMath.presets.min.js | 28 +- dist/presets/eMath.presets.mjs | 2373 ++++++++++++++++++++++++++++- dist/types/E/e.d.ts | 4 +- dist/types/E/format.d.ts | 24 +- dist/types/common/types.d.ts | 5 + dist/types/game/hookGame.d.ts | 4 +- dist/types/presets/index.d.ts | 2 + src/E/format.ts | 177 ++- src/presets/index.ts | 5 +- 17 files changed, 4927 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 64bdb313..cdacaf43 100644 --- a/README.md +++ b/README.md @@ -18,22 +18,26 @@ eMath.js is a JavaScript library designed to provide tools for incremental game This project started when I was trying to create my first incremental game. I found it difficult to implement certain systems like upgrades and saving. When I eventually made those systems, I wanted to make a package so I could streamline those tools. After a few months of development, I have finally developed it into a presentable state (I should have started it with v0.1.0 instead of v1.0.0 . . .). -Note: This package uses break_eternity.js by exporting a function `E` which is used both to construct and use methods on numbers. For example, +Note: This package uses break_eternity.js by exporting the class `Decimal` directly. You should import the `Decimal` class from `emath.js` instead of `break_eternity.js`. For example, ```js -import { E } from "emath.js"; +import { Decimal } from "emath.js"; -const num1 = E(10); // Equivalent to new Decimal(10) -const num2 = num1.add(5); // Equivalent to num.add(5) +const num1 = new Decimal(10); +const num2 = num1.add(5); -const num3 = E(20); -const num4 = E.pow(num1, num3); // Equivalent to num1.pow(num3), or Decimal.pow(num1, num3) - -// Also has built-in formatting -console.log(num4.format()); // 100 Qt +const num3 = new Decimal(20); +const num4 = Decimal.pow(num1, num3); ``` -This feature was originally provided to make the package more concise and easier to use. However, it ended up being a bit confusing. It will be removed in the future. +This was done in order to implement the saving/loading system using [`class-transformer`](https://github.com/typestack/class-transformer) and [`reflect-metadata`](https://github.com/rbuckton/reflect-metadata) (which are the only dependencies of this package). + +You cannot import directly from `break_eternity.js` as the package [targets a version of javascript (es5)](https://github.com/Patashu/break_eternity.js/issues/114) that is not supported by `class-transformer` and `reflect-metadata`. + + ## Example Usage @@ -42,11 +46,11 @@ This is a simple example of how to use the package. It creates a game with a cur > Note: This example uses javascript. It is recommended to use typescript for better type checking. ```js -import { E } from "emath.js"; +import { Decimal } from "emath.js"; import { Game } from "emath.js/game"; // For CDN usage: -// const { E, Game } = eMath; +// const { Decimal, Game } = eMath; // Initialize game const coinGame = new Game(); @@ -56,8 +60,10 @@ const coins = coinGame.addCurrency("coins", [ { id: "upg1Coins", // Unique ID cost: level => level.mul(10), // Cost of 10 times the level - maxLevel: E(1000), + maxLevel: new Decimal(1000), effect: (level, upgradeContext, currencyContext) => { + // `level` is the level of the upgrade + // `upgradeContext` is the context of the upgrade (this upgrade) // `currencyContext` is the context of the currency (coins in this case) // Access the `boost` object to add a boost @@ -128,10 +134,20 @@ npm install emath.js #### emath.js/game +Also includes `"emath.js"` so you only need to include this script. + ```html ``` +#### emath.js/presets + +Also includes `"emath.js"` and `"emath.js/game"` so you only need to include this script. + +```html + +``` + --- Check out the [documentation](https://xshadowblade.github.io/emath.js/)! diff --git a/dist/game/eMath.game.js b/dist/game/eMath.game.js index aded8bc4..86598818 100644 --- a/dist/game/eMath.game.js +++ b/dist/game/eMath.game.js @@ -1137,7 +1137,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index 88584c9e..6e9fa7af 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 Ot=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=Ot?exports:St;for(var It in lt)Tt[It]=lt[It]}})(typeof self<"u"?self:exports,()=>{var St={},st={exports:St},Ot=Object.create,lt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,It=Object.getOwnPropertyNames,Ue=Object.getPrototypeOf,Ge=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})},Qt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of It(e))!Ge.call(t,i)&&i!==r&<(t,i,{get:()=>e[i],enumerable:!(n=Tt(e,i))||n.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ot(Ue(t)):{},Qt(e||!t||!t.__esModule?lt(r,"default",{value:t,enumerable:!0}):r,t)),$e=t=>Qt(lt({},"__esModule",{value:!0}),t),ut=(t,e,r,n)=>{for(var i=n>1?void 0:n?Tt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(i=(n?c(e,r,i):c(i))||i);return n&&i&<(e,r,i),i},ft=yt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var n=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),i=o(e);typeof n.Reflect<"u"&&(i=o(n.Reflect,i)),r(i,n),typeof n.Reflect>"u"&&(n.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,n){var i=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 Jt(Object.create(null))}:l?function(){return Jt({__proto__:null})}:function(){return Jt({})},has:p?function(y,w){return i.call(y,w)}:function(y,w){return w in y},get:p?function(y,w){return i.call(y,w)?y[w]:void 0}:function(y,w){return y[w]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Dr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Rr(),N=typeof WeakMap=="function"?WeakMap:jr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,x=kr(),P=qr(x);function a(y,w,A,E){if(j(A)){if(!Ee(y))throw new TypeError;if(!Ce(w))throw new TypeError;return K(y,w)}else{if(!Ee(y))throw new TypeError;if(!X(w))throw new TypeError;if(!X(E)&&!j(E)&&!Mt(E))throw new TypeError;return Mt(E)&&(E=void 0),A=at(A),nt(y,w,A,E)}}r("decorate",a);function S(y,w){function A(E,R){if(!X(E))throw new TypeError;if(!j(R)&&!Pr(R))throw new TypeError;Lt(y,w,E,R)}return A}r("metadata",S);function v(y,w,A,E){if(!X(A))throw new TypeError;return j(E)||(E=at(E)),Lt(y,w,A,E)}r("defineMetadata",v);function I(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),H(y,w,A)}r("hasMetadata",I);function _(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),z(y,w,A)}r("hasOwnMetadata",_);function M(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),W(y,w,A)}r("getMetadata",M);function C(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),dt(y,w,A)}r("getOwnMetadata",C);function F(y,w){if(!X(y))throw new TypeError;return j(w)||(w=at(w)),kt(y,w)}r("getMetadataKeys",F);function U(y,w){if(!X(y))throw new TypeError;return j(w)||(w=at(w)),qt(y,w)}r("getOwnMetadataKeys",U);function V(y,w,A){if(!X(w))throw new TypeError;if(j(A)||(A=at(A)),!X(w))throw new TypeError;j(A)||(A=at(A));var E=At(w,A,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(y,w,A)}r("deleteMetadata",V);function K(y,w){for(var A=y.length-1;A>=0;--A){var E=y[A],R=E(w);if(!j(R)&&!Mt(R)){if(!Ce(R))throw new TypeError;w=R}}return w}function nt(y,w,A,E){for(var R=y.length-1;R>=0;--R){var J=y[R],tt=J(w,A,E);if(!j(tt)&&!Mt(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(y,w,A){var E=z(y,w,A);if(E)return!0;var R=Xt(w);return Mt(R)?!1:H(y,R,A)}function z(y,w,A){var E=At(w,A,!1);return j(E)?!1:Te(E.OrdinaryHasOwnMetadata(y,w,A))}function W(y,w,A){var E=z(y,w,A);if(E)return dt(y,w,A);var R=Xt(w);if(!Mt(R))return W(y,R,A)}function dt(y,w,A){var E=At(w,A,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(y,w,A)}function Lt(y,w,A,E){var R=At(A,E,!0);R.OrdinaryDefineOwnMetadata(y,w,A,E)}function kt(y,w){var A=qt(y,w),E=Xt(y);if(E===null)return A;var R=kt(E,w);if(R.length<=0)return A;if(A.length<=0)return R;for(var J=new g,tt=[],$=0,L=A;$=0&&L=this._keys.length?(this._index=-1,this._keys=w,this._values=w):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=w,this._values=w),L},$.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=w,this._values=w),{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(O)}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,O=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=n(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=n(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,O),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++]=n(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++]=n(v),C=N-1,g--;break;case 2:return P.join("")}if(g==0&&(g=Math.pow(2,O),O++),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,O),O++)}}};return m}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),ze=yt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={rotl:function(i,o){return i<>>32-o},rotr:function(i,o){return i<<32-o|i>>>o},endian:function(i){if(i.constructor==Number)return n.rotl(i,8)&16711935|n.rotl(i,24)&4278255360;for(var o=0;o0;i--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(i){for(var o=[],c=0,d=0;c>>5]|=i[c]<<24-d%32;return o},wordsToBytes:function(i){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(i){for(var o=[],c=0;c>>4).toString(16)),o.push((i[c]&15).toString(16));return o.join("")},hexToBytes:function(i){for(var o=[],c=0;c>>6*(3-m)&63)):o.push("=");return o.join("")},base64ToBytes:function(i){i=i.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,d=0;c>>6-d*2);return o}};e.exports=n})()}}),Kt=yt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(n){return r.bin.stringToBytes(unescape(encodeURIComponent(n)))},bytesToString:function(n){return decodeURIComponent(escape(r.bin.bytesToString(n)))}},bin:{stringToBytes:function(n){for(var i=[],o=0;o>>24)&16711935|(l[N]<<24|l[N]>>>8)&4278255360;l[p>>>5]|=128<>>9<<4)+14]=p;for(var O=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)}})()}}),te={};Bt(te,{default:()=>Or}),st.exports=$e(te);var $r=ot(ft()),Yr=ot(ft()),ee={};Bt(ee,{Attribute:()=>xt,AttributeStatic:()=>ge,Boost:()=>$t,BoostObject:()=>bt,Currency:()=>Nt,CurrencyStatic:()=>de,DEFAULT_ITERATIONS:()=>Ft,Decimal:()=>s,E:()=>wr,FORMATS:()=>gr,FormatTypeList:()=>tr,Grid:()=>vr,GridCell:()=>pe,LRUCache:()=>Dt,ListNode:()=>re,ST_NAMES:()=>ct,UpgradeData:()=>pt,UpgradeStatic:()=>me,calculateSum:()=>Zt,calculateSumApprox:()=>fe,calculateSumLoop:()=>le,calculateUpgrade:()=>ce,decimalToJSONString:()=>he,equalsTolerance:()=>zt,formats:()=>mt,inverseFunctionApprox:()=>Vt,roundingBase:()=>Nr,upgradeToCacheNameEL:()=>yr});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 re(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 n=this.last;this.map.delete(n.key),this.last=n.prev,this.last.next=void 0}}},re=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 He=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,n){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?n===G.CLASS_TO_CLASS||n===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?n===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(n){return n.options&&n.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),n=r&&r.get(void 0),i=this._exposeMetadatas.get(e),o=i&&i.get(void 0);return n&&o||!n&&!o?"none":n?"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(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var n=e.get(r),i;n&&(i=Array.from(n.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:i.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:i.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 i.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 n=!0;return n&&e&&(n=this.options.version>=e),n&&r&&(n=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 V=0;VNumber.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 V=0;V118?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} ${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)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(new t(10).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)?"":new t(10).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=new t(10).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="",V=(K,nt)=>{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=V(C,F);else{let K=F.sub(I).add(1),nt=C.div(t.pow(M+1,K.sub(1))).floor();U=`${V(nt,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=new t(2).pow(1024),n="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",i="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[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):new t(10).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)?"":new t(10).pow(U.sub(U.floor())).toFixed(2))+"F"+m(U.floor(),0)}let C=a.div(new t(10).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 V="";if(C.lt(4))V=["","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(new t(10).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&&(V="U"),H&&(V=e.standard.tier2(H)+(V?"-"+V:"")),W>1&&(V=e.standard.tier1(W)+V)),C=z,H++}}let K=a.div(new t(10).pow(F)),nt=S===2?new t(2).sub(M.sub(F)).add(1).toNumber():S;return _+(U.gte(10)?"":K.toFixed(nt)+" ")+V}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(),V=a.div(3600).mod(24).floor(),K=a.div(86400).mod(365.2425).floor(),nt=a.div(31556952).floor(),H=nt.eq(1)?" year":" years",z=K.eq(1)?" day":" days",W=V.eq(1)?" hour":" hours",dt=U.eq(1)?" minute":" minutes",Lt=F.eq(1)?" second":" seconds",kt=C.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+H+", ":""}${K.gt(0)?M(K)+z+", ":""}${V.gt(0)?M(V)+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(new t(1).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 O(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`${O(a,2)} ${O(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:O,ev:x};return{FORMATS:e,formats:P}}var jt=17,rr=9e15,nr=Math.log10(9e15),ir=1/9e15,sr=308,or=-324,oe=5,ar=1023,ur=!0,lr=!1,fr=function(){let t=[];for(let r=or+1;r<=sr;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],cr=[[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]],hr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],b=function(e){return s.fromValue_noAlloc(e)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,n){return s.fromComponents_noNormalize(e,r,n)},ht=function(e,r){let n=r+1,i=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,n-i))*Math.pow(10,i-n);return parseFloat(o.toFixed(Math.max(n-i,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},mr=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 n=t*t,i=t;return r=r+1/(12*i),i=i*n,r=r-1/(360*i),i=i*n,r=r+1/(1260*i),i=i*n,r=r-1/(1680*i),i=i*n,r=r+1/(1188*i),i=i*n,r=r-691/(360360*i),i=i*n,r=r+7/(1092*i),i=i*n,r=r-3617/(122400*i),Math.exp(r)/e},dr=.36787944117144233,ae=.5671432904097838,Gt=function(t,e=1e-10,r=!0){let n,i;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ae;t<10?n=0:n=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?n=-2:n=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(i=(t*Math.exp(-n)+n*n)/(n+1),Math.abs(i-n).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),n=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(n=Math.trunc(n));let i=Math.pow(10,n);return Math.random()>.9&&(i=Math.trunc(i)),D(e,r,i)}static affordGeometricSeries_core(t,e,r,n){let i=e.mul(r.pow(n));return s.floor(t.div(i).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,n){return e.mul(r.pow(n)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,n){let o=e.add(n.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,n){let i=e.add(n.mul(r));return t.div(2).mul(i.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=rr)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,n=s.fromStringCache.get(r);if(n!==void 0)return this.fromDecimal(n);ur?t=t.replace(",",""):lr&&(t=t.replace(",","."));let i=t.split("^^^");if(i.length===2){let N=parseFloat(i[0]),O=parseFloat(i[1]),x=i[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(O)){let a=s.pentate(N,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let N=parseFloat(o[0]),O=parseFloat(o[1]),x=o[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(O)){let a=s.tetrate(N,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let N=parseFloat(c[0]),O=parseFloat(c[1]);if(isFinite(N)&&isFinite(O)){let x=s.pow(N,O);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 O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),m=parseFloat(l[1]),isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=0;O=43&&x<=57||x===101)N+=u[1].charAt(O);else return this.layer=parseFloat(N),this.mag=parseFloat(u[1].substr(O+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(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),b(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<=oe?(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<=oe?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return T(0,0,0);let r,n;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*r.mag+n.sign*n.mag);let i=r.layer*Math.sign(r.mag),o=n.layer*Math.sign(n.mag);if(i-o>=2)return r;if(i===0&&o===-1){if(Math.abs(n.mag-Math.log10(r.mag))>jt)return r;{let c=Math.pow(10,Math.log10(r.mag)-n.mag),d=n.sign+r.sign*c;return D(Math.sign(d),1,n.mag+Math.log10(Math.abs(d)))}}if(i===1&&o===0){if(Math.abs(r.mag-Math.log10(n.mag))>jt)return r;{let c=Math.pow(10,r.mag-Math.log10(n.mag)),d=n.sign+r.sign*c;return D(Math.sign(d),1,Math.log10(n.mag)+Math.log10(Math.abs(d)))}}if(Math.abs(r.mag-n.mag)>jt)return r;{let c=Math.pow(10,r.mag-n.mag),d=n.sign+r.sign*c;return D(Math.sign(d),1,n.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(b(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return T(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return T(this.sign*e.sign,0,1);let r,n;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*n.sign*r.mag*n.mag);if(r.layer>=3||r.layer-n.layer>=2)return D(r.sign*n.sign,r.layer,r.mag);if(r.layer===1&&n.layer===0)return D(r.sign*n.sign,1,r.mag+Math.log10(n.mag));if(r.layer===1&&n.layer===1)return D(r.sign*n.sign,1,r.mag+n.mag);if(r.layer===2&&n.layer===1){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}if(r.layer===2&&n.layer===2){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=b(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?T(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?T(0,0,0):this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=b(t).abs();if(e.eq(s.dZero))return T(0,0,0);let r=this.toNumber(),n=e.toNumber();return isFinite(r)&&isFinite(n)&&r!=0&&n!=0?new s(r%n):this.sub(e).eq(this)?T(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=b(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,n=e.mag>0?e.layer:-e.layer;return r>n?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=b(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=b(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let n=this.mag,i=r.mag;return this.layer>r.layer&&(i=Ut(i)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=b(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=b(t),r=new s(this),n=new s(e);if(r.sign===0)return n.eq(0)?T(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(n.sign===0)return T(1,0,1);if(n.sign===1&&n.layer===0&&n.mag===1)return r;let i=r.absLog10().mul(n).pow10();return this.sign===-1?Math.abs(n.toNumber()%2)%2===1?i.neg():Math.abs(n.toNumber()%2)%2===0?i:T(Number.NaN,Number.NaN,Number.NaN):i}pow10(){if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return T(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return T(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return b(t).pow(this)}root(t){let e=b(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(T(1,0,24)))return s.fromNumber(mr(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,n=t,i=12*n,o=1/i,c=e+o;if(c===e||(e=c,n=n*r,i=360*n,o=1/i,c=e-o,c===e))return s.exp(e);e=c,n=n*r,i=1260*n;let d=1/i;return e=e+d,n=n*r,i=1680*n,d=1/i,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=b(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 n=t;t=Math.trunc(t);let i=n-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())))&&(n>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(i):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this);for(let c=0;c1e4&&Math.ceil(n)%2==1?this.pow(e):e}i!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(i):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),i)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(i,r):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=b(t);let n=s.fromDecimal(this),i=e;e=Math.trunc(e);let o=i-e;if(n.layer-t.layer>3){let c=Math.min(e,n.layer-t.layer-3);e-=c,n.layer-=c}for(let c=0;c1e4)return n}return o>0&&o<1&&(t.eq(10)?n=n.layeradd10(-o,r):n=n.layeradd(-o,t,r)),n}slog(t=10,e=100,r=!1){let n=.001,i=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let d=1;d1&&o!=l&&(i=!0),o=l,i?n/=2:n*=2,n=Math.abs(n)*(l?-1:1),c+=n,n===0)break}return s.fromNumber(c)}slog_internal(t=10,e=!1){if(t=b(t),t.lte(s.dZero)||t.eq(s.dOne))return T(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?T(0,0,0):this.eq(s.dZero)?T(-1,0,1):T(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return T(-1,0,1);if(t.lt(1.444667861009766)){let i=s.ln(t).neg(),o=i.lambertw().div(i);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,n=s.fromDecimal(this);if(n.layer-t.layer>3){let i=n.layer-t.layer-3;r+=i,n.layer-=i}for(let i=0;i<100;++i)if(n.lt(s.dZero))n=s.pow(t,n),r-=1;else{if(n.lte(s.dOne))return e?s.fromNumber(r+n.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),n.toNumber()));r+=1,n=s.log(n,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,hr)}static tetrate_critical(t,e){return s.critical_section(t,e,cr)}static critical_section(t,e,r,n=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let i=0,o=0;for(let d=0;dt){let m=(t-gt[d])/(gt[d+1]-gt[d]);i=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 i<=0||o<=0?i*(1-c)+o*c:Math.pow(t,Math.log(i)/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 n=Math.trunc(t);t-=n,r.layer+=n}if(t<=-1){let n=Math.trunc(t);if(t-=n,r.layer+=n,r.layer<0)for(let i=0;i<100;++i){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 n=b(e);if(n.gt(1)&&n.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=n.pow(h),N=Math.floor(l),O=l-N,x=h.pow(1-O).mul(g.pow(O));return s.tetrate(n,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=b(t),e=b(e);let n=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 i=s.ln(e).neg(),o=i.lambertw().div(i),c=s.dInf;if(e>1&&(c=i.lambertw(!1).div(i)),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=n.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=n.pow(N),l=l+1,N.layer>3){let O=Math.floor(t.layer-N.layer+1);N=n.iteratedexp(O,N,r),l=l+O}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=n.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=n.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")?ue(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?ue(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 edr?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,n=e.layer,i=e.iteratedlog(10,n,!0),o=i,c=i.div(2),d=!0;for(;d;)c=r.add(i).div(2),s.iteratedexp(10,n,c,!0).tetrate(t,1,!0).gt(this)?i=c:r=c,c.eq(o)?d=!1:o=c;return s.iteratedexp(10,n,c,!0)}else{let e=1,r=D(1,10,1),n=D(1,10,1),i=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,O=s.dZero,x=!1;for(;e<4;){if(e==2){if(u)break;i=D(1,10,1),o=r,e=3,d=D(1,10,1),g=D(1,10,1)}for(N=!1;o.neq(i);){if(O=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(i.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(i).div(2),v)break}else if(i.eq(D(1,10,1)))i=o,o=o.div(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),i=i.sub(d),o=o.sub(d),v)break}if(i.sub(o).div(2).abs().gt(d.mul(1.5))&&(N=!0),d=i.sub(o).div(2).abs(),o.gt("1e18")||o.eq(O))break}if(o.gt("1e18")||!x||g==D(1,10,1))break;e==1?r=g:e==3&&(n=g),e++}i=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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(n.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(i=D(1,10,1),o=n,P=o,a=s.dZero,S=!0;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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 n=t;t=Math.trunc(t);let i=n-t;i!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(i)):this.eq(10)?e=e.layeradd10(i,r):e=e.layeradd(i,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,n){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(n)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=n.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(n=n.sub(t).div(e).add(t))),n}static softcap(t,e,r,n){return new s(t).softcap(e,r,n)}scale(t,e,r,n=!1){t=new s(t),e=new s(e);let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=n?i.mul(t.pow(e.sub(1))).root(e):i.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(i=n?i.div(t).max(1).log(e).add(t):s.pow(e,i.sub(t)).mul(t))),i}static scale(t,e,r,n,i=!1){return new s(t).scale(e,r,n,i)}format(t=2,e=9,r="mixed_sc"){return mt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,n="mixed_sc"){return mt.format(new s(t),e,r,n)}formatST(t=2,e=9,r="st"){return mt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,n="st"){return mt.format(new s(t),e,r,n)}formatGain(t,e="mixed_sc",r,n){return mt.formatGain(this.clone(),t,e,r,n)}static formatGain(t,e,r="mixed_sc",n,i){return mt.formatGain(new s(t),e,r,n,i)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),n={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},i="";for(let o of Object.keys(n)){let c=Math.floor(r/n[o]);r-=c*n[o],i+=o.repeat(c)}return i}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(ar),ut([Et()],s.prototype,"sign",2),ut([Et()],s.prototype,"mag",2),ut([Et()],s.prototype,"layer",2),s=ut([Ke()],s);var{formats:mt,FORMATS:gr}=er(s);s.formats=mt;var bt=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 bt(r))})}getBoosts(t,e){let r=[],n=[];for(let i=0;if),l=i,p=this.getBoosts(o,!0);p[0][0]?this.boostArray[p[1][0]]=new bt({id:o,name:c,description:d,value:m,order:l}):this.boostArray.push(new bt({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 bt(o):this.boostArray.push(new bt(o))}}}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((n,i)=>n.order-i.order);for(let n of r)e=n.value(e);return e}},Vr=ot(ft()),Ft=30,Yt=.001;function pr(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 new s(2).div(t.reciprocal().add(e.reciprocal()))}}function zt(t,e,r,n){n=Object.assign({},{verbose:!1,mode:"geometric"},n),t=new s(t),e=new s(e),r=new s(r);let i,o;return n.mode==="geometric"?(i=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=i.lte(r)):(i=t.sub(e).abs(),o=i.lte(r)),(n.verbose===!0||n.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:n,diff:i,result:o}),o}function Vt(t,e,r="geometric",n=Ft,i=Yt){let o=new s(1),c=new s(e);if(t(c).eq(0))return{value:new s(0),lowerBound:new s(0),upperBound:new s(0)};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,i,{verbose:!1,mode:"geometric"}))break}return o}function Zt(t,e,r=0,n,i){return r=new s(r),e=new s(e),e.sub(r).lte(Ft)?le(t,e,r,n):fe(t,e,r,i)}function Nr(t,e=10,r=0,n=1e3){if(t=new s(t),t.gte(s.pow(e,n)))return t;let i=s.floor(s.log(t,e)),o=t.div(s.pow(e,i));return o=o.mul(s.pow(e,r)).round(),o=o.div(s.pow(e,r)),o=o.mul(s.pow(e,i)),o}function ce(t,e,r,n=1/0,i,o,c=!1){t=new s(t),r=new s(r??e.level),n=new s(n);let d=n.sub(r);if(d.lt(0))return console.warn("calculateUpgrade: Invalid target: ",d),[new s(0),new s(0)];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=[new s(0),new s(0)];return c?(h[0]=u?new s(1):new s(0),h):(h=[u?new s(1):new s(0),u?f:new s(0)],h)}if(e.costBulk){let[f,u]=e.costBulk(t,e.level,d),h=t.gte(u);return[h?f:new s(0),h&&!c?u:new s(0)]}if(c){let f=g=>e.cost(g.add(r)),u=s.min(n,Vt(f,t,i,o).value.floor()),h=new s(0);return[u,h]}let m=Vt(f=>Zt(e.cost,f,r),t,i,o).value.floor().min(r.add(d).sub(1)),l=Zt(e.cost,m,r);return[m.sub(r).add(1).max(0),l]}function he(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function yr(t){return`el/${he(t)}`}var pt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):new s(1)}};ut([Et()],pt.prototype,"id",2),ut([Ct(()=>s)],pt.prototype,"level",2);var me=class Be{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:new s(1)}}).data??{level:new s(1)}).level}set level(e){this.data.level=new s(e)}constructor(e,r,n){let i=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>i,this.cache=new Dt(n??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??new s(1)}},Zr=ot(ft()),Nt=class{constructor(){this.value=new s(0),this.upgrades={}}};ut([Ct(()=>s)],Nt.prototype,"value",2),ut([Ct(()=>pt)],Nt.prototype,"upgrades",2);var de=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:new s(0),defaultBoost:new s(1)}){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 n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),r&&n.effect?.(n.level,n,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 n of t){let i=this.pointerAddUpgrade(n),o=new me(n,()=>this.pointerGetUpgrade(n.id));o.effect&&e&&o.effect(o.level,o,this),r[n.id]=o,this.upgrades[n.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,n){let i=this.getUpgrade(t);return i===null?(console.warn(`Upgrade "${t}" not found.`),[new s(0),new s(0)]):(e=i.level.add(e),i.maxLevel!==void 0&&(e=s.min(e,i.maxLevel)),ce(this.value,i,i.level,e,r,n))}getNextCost(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n)[0];return i.cost(i.level.add(o))}getNextCostMax(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n);return i.cost(i.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,n);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),i.level=i.level.add(o),i.effect?.(i.level,i,this),!0)}},Hr=ot(ft()),xt=class{constructor(t=0){this.value=new s(t)}};ut([Ct(()=>s)],xt.prototype,"value",2);var ge=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}},pe=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]}},vr=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let n=0;n{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),br=ee,Ne={};Bt(Ne,{ConfigManager:()=>Pt,DataManager:()=>Me,EventManager:()=>we,EventTypes:()=>ve,Game:()=>Ir,GameAttribute:()=>Se,GameCurrency:()=>_e,GameReset:()=>Ie,KeyManager:()=>ye,gameDefaultConfig:()=>Ae,keys:()=>_r});var Wr=ot(ft()),Pt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,n){for(let i in n)typeof r[i]>"u"?r[i]=n[i]:typeof r[i]=="object"&&typeof n[i]=="object"&&!Array.isArray(r[i])&&!Array.isArray(n[i])&&(r[i]=e(r[i],n[i]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Mr={autoAddInterval:!0,fps:30},_r="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),ye=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 n of this.tickers)n(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let n of this.binds)(typeof n.onDownContinuous<"u"||typeof n.fn<"u")&&this.isPressing(n.id)&&(n.onDownContinuous?.(r),n.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(Mr)}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 n=e.key;r&&!this.keysPressed.includes(n)?this.keysPressed.push(n):!r&&this.keysPressed.includes(n)&&this.keysPressed.splice(this.keysPressed.indexOf(n),1)}onAll(e,r){for(let n of this.binds)if(n.key===r)switch(e){case"down":n.onDown?.();break;case"press":default:n.onPress?.();break;case"up":n.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,n){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:n}]:e,e=Array.isArray(e)?e:[e];for(let i of e){i.id=i.id??i.name;let o=this.getBind(i.id);if(o){Object.assign(o,i);continue}this.binds.push(i)}}},ve=(t=>(t.interval="interval",t.timeout="timeout",t))(ve||{}),Sr={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(Sr)}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 n=e-r.intervalLast;r.callbackFn(n),r.intervalLast=e}break;case"timeout":{let n=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(n),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,n,i){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},Xr=ot(ft()),be=ot(Ye()),Ht=ot(Ze()),Me=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(n){r()[t]=n},setValue(n){r()[t]=n}}}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)}`),n;try{n="9.0.0"}catch{n="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:n}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,be.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,be.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 n=e.hash,i=(0,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return n===i}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 n(p){return typeof p=="object"&&p?.constructor===Object}let i=(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(i(p,g)&&!i(u,g)&&(h[g]=p[g]),f[g]instanceof Nt){let N=p[g],O=u[g];if(Array.isArray(O.upgrades)){let x=O.upgrades;O.upgrades={};for(let P of x)O.upgrades[P.id]=P}O.upgrades={...N.upgrades,...O.upgrades},h[g]=O}else n(p[g])&&n(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:new s(0)}));function m(p,f){let u=se(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]=se(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(!n(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 n of this.eventsOnLoad)n();return e}},_e=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,n){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=n,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Se=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}},Ie=class{constructor(t,e){this.currenciesToReset=Array.isArray(t)?t:[t],this.extender=Array.isArray(e)?e:e?[e]:[],this.id=Symbol()}reset(){this.onReset?.(this),this.currenciesToReset.forEach(t=>{t.static.reset()}),this.extender.forEach(t=>{t.id!==this.id&&t.reset()})}},Ae={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Ir=class je{static{this.configManager=new Pt(Ae)}constructor(e){this.config=je.configManager.parse(e),this.dataManager=new Me(this),this.keyManager=new ye({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 de(()=>this.dataManager.getData(e).currency,r)}),new _e(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,n=0){return this.dataManager.setData(e,new xt(n)),this.dataManager.setStatic(e,new ge(this.dataManager.getData(e),r,n)),new Se(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(e,r){return new Ie(e,r)}},Ar={...br,...Ne},Or=Ar;if(typeof st.exports=="object"&&typeof St=="object"){var Tr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,i)&&i!==r&&Object.defineProperty(t,i,{get:()=>e[i],enumerable:!(n=Object.getOwnPropertyDescriptor(e,i))||n.enumerable});return t};st.exports=Tr(st.exports,St)}return st.exports}); +"use strict";(function(St,st){var Ot=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],st);else if(typeof module=="object"&&module.exports)module.exports=st();else{var lt=st(),Tt=Ot?exports:St;for(var It in lt)Tt[It]=lt[It]}})(typeof self<"u"?self:exports,()=>{var St={},st={exports:St},Ot=Object.create,lt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,It=Object.getOwnPropertyNames,Ue=Object.getPrototypeOf,Ge=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})},Qt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of It(e))!Ge.call(t,i)&&i!==r&<(t,i,{get:()=>e[i],enumerable:!(n=Tt(e,i))||n.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ot(Ue(t)):{},Qt(e||!t||!t.__esModule?lt(r,"default",{value:t,enumerable:!0}):r,t)),$e=t=>Qt(lt({},"__esModule",{value:!0}),t),ut=(t,e,r,n)=>{for(var i=n>1?void 0:n?Tt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(i=(n?c(e,r,i):c(i))||i);return n&&i&<(e,r,i),i},ft=yt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var n=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:m(),i=o(e);typeof n.Reflect<"u"&&(i=o(n.Reflect,i)),r(i,n),typeof n.Reflect>"u"&&(n.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,n){var i=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 Jt(Object.create(null))}:l?function(){return Jt({__proto__:null})}:function(){return Jt({})},has:p?function(y,w){return i.call(y,w)}:function(y,w){return w in y},get:p?function(y,w){return i.call(y,w)?y[w]:void 0}:function(y,w){return y[w]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Dr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Rr(),N=typeof WeakMap=="function"?WeakMap:jr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,x=kr(),P=qr(x);function a(y,w,A,E){if(j(A)){if(!Ee(y))throw new TypeError;if(!Ce(w))throw new TypeError;return K(y,w)}else{if(!Ee(y))throw new TypeError;if(!X(w))throw new TypeError;if(!X(E)&&!j(E)&&!Mt(E))throw new TypeError;return Mt(E)&&(E=void 0),A=at(A),nt(y,w,A,E)}}r("decorate",a);function S(y,w){function A(E,R){if(!X(E))throw new TypeError;if(!j(R)&&!Pr(R))throw new TypeError;Lt(y,w,E,R)}return A}r("metadata",S);function v(y,w,A,E){if(!X(A))throw new TypeError;return j(E)||(E=at(E)),Lt(y,w,A,E)}r("defineMetadata",v);function I(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),H(y,w,A)}r("hasMetadata",I);function _(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),z(y,w,A)}r("hasOwnMetadata",_);function M(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),W(y,w,A)}r("getMetadata",M);function C(y,w,A){if(!X(w))throw new TypeError;return j(A)||(A=at(A)),dt(y,w,A)}r("getOwnMetadata",C);function F(y,w){if(!X(y))throw new TypeError;return j(w)||(w=at(w)),kt(y,w)}r("getMetadataKeys",F);function U(y,w){if(!X(y))throw new TypeError;return j(w)||(w=at(w)),qt(y,w)}r("getOwnMetadataKeys",U);function V(y,w,A){if(!X(w))throw new TypeError;if(j(A)||(A=at(A)),!X(w))throw new TypeError;j(A)||(A=at(A));var E=At(w,A,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(y,w,A)}r("deleteMetadata",V);function K(y,w){for(var A=y.length-1;A>=0;--A){var E=y[A],R=E(w);if(!j(R)&&!Mt(R)){if(!Ce(R))throw new TypeError;w=R}}return w}function nt(y,w,A,E){for(var R=y.length-1;R>=0;--R){var J=y[R],tt=J(w,A,E);if(!j(tt)&&!Mt(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(y,w,A){var E=z(y,w,A);if(E)return!0;var R=Xt(w);return Mt(R)?!1:H(y,R,A)}function z(y,w,A){var E=At(w,A,!1);return j(E)?!1:Te(E.OrdinaryHasOwnMetadata(y,w,A))}function W(y,w,A){var E=z(y,w,A);if(E)return dt(y,w,A);var R=Xt(w);if(!Mt(R))return W(y,R,A)}function dt(y,w,A){var E=At(w,A,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(y,w,A)}function Lt(y,w,A,E){var R=At(A,E,!0);R.OrdinaryDefineOwnMetadata(y,w,A,E)}function kt(y,w){var A=qt(y,w),E=Xt(y);if(E===null)return A;var R=kt(E,w);if(R.length<=0)return A;if(A.length<=0)return R;for(var J=new g,tt=[],$=0,L=A;$=0&&L=this._keys.length?(this._index=-1,this._keys=w,this._values=w):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=w,this._values=w),L},$.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=w,this._values=w),{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(O)}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,O=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=n(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=n(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,O),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++]=n(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++]=n(v),C=N-1,g--;break;case 2:return P.join("")}if(g==0&&(g=Math.pow(2,O),O++),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,O),O++)}}};return m}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),ze=yt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={rotl:function(i,o){return i<>>32-o},rotr:function(i,o){return i<<32-o|i>>>o},endian:function(i){if(i.constructor==Number)return n.rotl(i,8)&16711935|n.rotl(i,24)&4278255360;for(var o=0;o0;i--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(i){for(var o=[],c=0,d=0;c>>5]|=i[c]<<24-d%32;return o},wordsToBytes:function(i){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(i){for(var o=[],c=0;c>>4).toString(16)),o.push((i[c]&15).toString(16));return o.join("")},hexToBytes:function(i){for(var o=[],c=0;c>>6*(3-m)&63)):o.push("=");return o.join("")},base64ToBytes:function(i){i=i.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,d=0;c>>6-d*2);return o}};e.exports=n})()}}),Kt=yt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(n){return r.bin.stringToBytes(unescape(encodeURIComponent(n)))},bytesToString:function(n){return decodeURIComponent(escape(r.bin.bytesToString(n)))}},bin:{stringToBytes:function(n){for(var i=[],o=0;o>>24)&16711935|(l[N]<<24|l[N]>>>8)&4278255360;l[p>>>5]|=128<>>9<<4)+14]=p;for(var O=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)}})()}}),te={};Bt(te,{default:()=>Or}),st.exports=$e(te);var $r=ot(ft()),Yr=ot(ft()),ee={};Bt(ee,{Attribute:()=>xt,AttributeStatic:()=>ge,Boost:()=>$t,BoostObject:()=>bt,Currency:()=>Nt,CurrencyStatic:()=>de,DEFAULT_ITERATIONS:()=>Ft,Decimal:()=>s,E:()=>wr,FORMATS:()=>gr,FormatTypeList:()=>tr,Grid:()=>vr,GridCell:()=>pe,LRUCache:()=>Dt,ListNode:()=>re,ST_NAMES:()=>ct,UpgradeData:()=>pt,UpgradeStatic:()=>me,calculateSum:()=>Zt,calculateSumApprox:()=>fe,calculateSumLoop:()=>le,calculateUpgrade:()=>ce,decimalToJSONString:()=>he,equalsTolerance:()=>zt,formats:()=>mt,inverseFunctionApprox:()=>Vt,roundingBase:()=>Nr,upgradeToCacheNameEL:()=>yr});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 re(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 n=this.last;this.map.delete(n.key),this.last=n.prev,this.last.next=void 0}}},re=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 He=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,n){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?n===G.CLASS_TO_CLASS||n===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?n===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(n){return n.options&&n.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),n=r&&r.get(void 0),i=this._exposeMetadatas.get(e),o=i&&i.get(void 0);return n&&o||!n&&!o?"none":n?"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(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var n=e.get(r),i;n&&(i=Array.from(n.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:i.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:i.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 i.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 n=!0;return n&&e&&(n=this.options.version>=e),n&&r&&(n=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 V=0;VNumber.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 V=0;V118?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)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(new t(10).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)?"":new t(10).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=new t(10).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="",V=(K,nt)=>{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=V(C,F);else{let K=F.sub(I).add(1),nt=C.div(t.pow(M+1,K.sub(1))).floor();U=`${V(nt,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=new t(2).pow(1024),n="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",i="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[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):new t(10).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)?"":new t(10).pow(U.sub(U.floor())).toFixed(2))+"F"+m(U.floor(),0)}let C=a.div(new t(10).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 V="";if(C.lt(4))V=["","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(new t(10).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&&(V="U"),H&&(V=e.standard.tier2(H)+(V?"-"+V:"")),W>1&&(V=e.standard.tier1(W)+V)),C=z,H++}}let K=a.div(new t(10).pow(F)),nt=S===2?new t(2).sub(M.sub(F)).add(1).toNumber():S;return _+(U.gte(10)?"":K.toFixed(nt)+" ")+V}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(),V=a.div(3600).mod(24).floor(),K=a.div(86400).mod(365.2425).floor(),nt=a.div(31556952).floor(),H=nt.eq(1)?" year":" years",z=K.eq(1)?" day":" days",W=V.eq(1)?" hour":" hours",dt=U.eq(1)?" minute":" minutes",Lt=F.eq(1)?" second":" seconds",kt=C.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+H+", ":""}${K.gt(0)?M(K)+z+", ":""}${V.gt(0)?M(V)+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(new t(1).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 O(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`${O(a,2)} ${O(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:O,ev:x};return{FORMATS:e,formats:P}}var jt=17,rr=9e15,nr=Math.log10(9e15),ir=1/9e15,sr=308,or=-324,oe=5,ar=1023,ur=!0,lr=!1,fr=function(){let t=[];for(let r=or+1;r<=sr;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],cr=[[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]],hr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],b=function(e){return s.fromValue_noAlloc(e)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,n){return s.fromComponents_noNormalize(e,r,n)},ht=function(e,r){let n=r+1,i=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,n-i))*Math.pow(10,i-n);return parseFloat(o.toFixed(Math.max(n-i,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},mr=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 n=t*t,i=t;return r=r+1/(12*i),i=i*n,r=r-1/(360*i),i=i*n,r=r+1/(1260*i),i=i*n,r=r-1/(1680*i),i=i*n,r=r+1/(1188*i),i=i*n,r=r-691/(360360*i),i=i*n,r=r+7/(1092*i),i=i*n,r=r-3617/(122400*i),Math.exp(r)/e},dr=.36787944117144233,ae=.5671432904097838,Gt=function(t,e=1e-10,r=!0){let n,i;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ae;t<10?n=0:n=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?n=-2:n=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(i=(t*Math.exp(-n)+n*n)/(n+1),Math.abs(i-n).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),n=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(n=Math.trunc(n));let i=Math.pow(10,n);return Math.random()>.9&&(i=Math.trunc(i)),D(e,r,i)}static affordGeometricSeries_core(t,e,r,n){let i=e.mul(r.pow(n));return s.floor(t.div(i).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,n){return e.mul(r.pow(n)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,n){let o=e.add(n.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,n){let i=e.add(n.mul(r));return t.div(2).mul(i.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=rr)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,n=s.fromStringCache.get(r);if(n!==void 0)return this.fromDecimal(n);ur?t=t.replace(",",""):lr&&(t=t.replace(",","."));let i=t.split("^^^");if(i.length===2){let N=parseFloat(i[0]),O=parseFloat(i[1]),x=i[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(O)){let a=s.pentate(N,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let N=parseFloat(o[0]),O=parseFloat(o[1]),x=o[1].split(";"),P=1;if(x.length===2&&(P=parseFloat(x[1]),isFinite(P)||(P=1)),isFinite(N)&&isFinite(O)){let a=s.tetrate(N,O,P,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let N=parseFloat(c[0]),O=parseFloat(c[1]);if(isFinite(N)&&isFinite(O)){let x=s.pow(N,O);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 O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),m=parseFloat(l[1]),isFinite(O)||(O=1),isFinite(d)&&isFinite(m)){let x=s.tetrate(d,m,O,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 O=0;O=43&&x<=57||x===101)N+=u[1].charAt(O);else return this.layer=parseFloat(N),this.mag=parseFloat(u[1].substr(O+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(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),b(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<=oe?(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<=oe?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return T(0,0,0);let r,n;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*r.mag+n.sign*n.mag);let i=r.layer*Math.sign(r.mag),o=n.layer*Math.sign(n.mag);if(i-o>=2)return r;if(i===0&&o===-1){if(Math.abs(n.mag-Math.log10(r.mag))>jt)return r;{let c=Math.pow(10,Math.log10(r.mag)-n.mag),d=n.sign+r.sign*c;return D(Math.sign(d),1,n.mag+Math.log10(Math.abs(d)))}}if(i===1&&o===0){if(Math.abs(r.mag-Math.log10(n.mag))>jt)return r;{let c=Math.pow(10,r.mag-Math.log10(n.mag)),d=n.sign+r.sign*c;return D(Math.sign(d),1,Math.log10(n.mag)+Math.log10(Math.abs(d)))}}if(Math.abs(r.mag-n.mag)>jt)return r;{let c=Math.pow(10,r.mag-n.mag),d=n.sign+r.sign*c;return D(Math.sign(d),1,n.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(b(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return T(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return T(this.sign*e.sign,0,1);let r,n;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*n.sign*r.mag*n.mag);if(r.layer>=3||r.layer-n.layer>=2)return D(r.sign*n.sign,r.layer,r.mag);if(r.layer===1&&n.layer===0)return D(r.sign*n.sign,1,r.mag+Math.log10(n.mag));if(r.layer===1&&n.layer===1)return D(r.sign*n.sign,1,r.mag+n.mag);if(r.layer===2&&n.layer===1){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}if(r.layer===2&&n.layer===2){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=b(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?T(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?T(0,0,0):this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=b(t).abs();if(e.eq(s.dZero))return T(0,0,0);let r=this.toNumber(),n=e.toNumber();return isFinite(r)&&isFinite(n)&&r!=0&&n!=0?new s(r%n):this.sub(e).eq(this)?T(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=b(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,n=e.mag>0?e.layer:-e.layer;return r>n?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=b(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=b(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let n=this.mag,i=r.mag;return this.layer>r.layer&&(i=Ut(i)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=b(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=b(t),r=new s(this),n=new s(e);if(r.sign===0)return n.eq(0)?T(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(n.sign===0)return T(1,0,1);if(n.sign===1&&n.layer===0&&n.mag===1)return r;let i=r.absLog10().mul(n).pow10();return this.sign===-1?Math.abs(n.toNumber()%2)%2===1?i.neg():Math.abs(n.toNumber()%2)%2===0?i:T(Number.NaN,Number.NaN,Number.NaN):i}pow10(){if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return T(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return T(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return b(t).pow(this)}root(t){let e=b(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(T(1,0,24)))return s.fromNumber(mr(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,n=t,i=12*n,o=1/i,c=e+o;if(c===e||(e=c,n=n*r,i=360*n,o=1/i,c=e-o,c===e))return s.exp(e);e=c,n=n*r,i=1260*n;let d=1/i;return e=e+d,n=n*r,i=1680*n,d=1/i,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=b(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 n=t;t=Math.trunc(t);let i=n-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())))&&(n>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(i):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this);for(let c=0;c1e4&&Math.ceil(n)%2==1?this.pow(e):e}i!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(i):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),i)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(i,r):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=b(t);let n=s.fromDecimal(this),i=e;e=Math.trunc(e);let o=i-e;if(n.layer-t.layer>3){let c=Math.min(e,n.layer-t.layer-3);e-=c,n.layer-=c}for(let c=0;c1e4)return n}return o>0&&o<1&&(t.eq(10)?n=n.layeradd10(-o,r):n=n.layeradd(-o,t,r)),n}slog(t=10,e=100,r=!1){let n=.001,i=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let d=1;d1&&o!=l&&(i=!0),o=l,i?n/=2:n*=2,n=Math.abs(n)*(l?-1:1),c+=n,n===0)break}return s.fromNumber(c)}slog_internal(t=10,e=!1){if(t=b(t),t.lte(s.dZero)||t.eq(s.dOne))return T(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?T(0,0,0):this.eq(s.dZero)?T(-1,0,1):T(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return T(-1,0,1);if(t.lt(1.444667861009766)){let i=s.ln(t).neg(),o=i.lambertw().div(i);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,n=s.fromDecimal(this);if(n.layer-t.layer>3){let i=n.layer-t.layer-3;r+=i,n.layer-=i}for(let i=0;i<100;++i)if(n.lt(s.dZero))n=s.pow(t,n),r-=1;else{if(n.lte(s.dOne))return e?s.fromNumber(r+n.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),n.toNumber()));r+=1,n=s.log(n,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,hr)}static tetrate_critical(t,e){return s.critical_section(t,e,cr)}static critical_section(t,e,r,n=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let i=0,o=0;for(let d=0;dt){let m=(t-gt[d])/(gt[d+1]-gt[d]);i=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 i<=0||o<=0?i*(1-c)+o*c:Math.pow(t,Math.log(i)/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 n=Math.trunc(t);t-=n,r.layer+=n}if(t<=-1){let n=Math.trunc(t);if(t-=n,r.layer+=n,r.layer<0)for(let i=0;i<100;++i){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 n=b(e);if(n.gt(1)&&n.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=n.pow(h),N=Math.floor(l),O=l-N,x=h.pow(1-O).mul(g.pow(O));return s.tetrate(n,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=b(t),e=b(e);let n=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 i=s.ln(e).neg(),o=i.lambertw().div(i),c=s.dInf;if(e>1&&(c=i.lambertw(!1).div(i)),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=n.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=n.pow(N),l=l+1,N.layer>3){let O=Math.floor(t.layer-N.layer+1);N=n.iteratedexp(O,N,r),l=l+O}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=n.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=n.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")?ue(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?ue(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 edr?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,n=e.layer,i=e.iteratedlog(10,n,!0),o=i,c=i.div(2),d=!0;for(;d;)c=r.add(i).div(2),s.iteratedexp(10,n,c,!0).tetrate(t,1,!0).gt(this)?i=c:r=c,c.eq(o)?d=!1:o=c;return s.iteratedexp(10,n,c,!0)}else{let e=1,r=D(1,10,1),n=D(1,10,1),i=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,O=s.dZero,x=!1;for(;e<4;){if(e==2){if(u)break;i=D(1,10,1),o=r,e=3,d=D(1,10,1),g=D(1,10,1)}for(N=!1;o.neq(i);){if(O=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(i.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(i).div(2),v)break}else if(i.eq(D(1,10,1)))i=o,o=o.div(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),i=i.sub(d),o=o.sub(d),v)break}if(i.sub(o).div(2).abs().gt(d.mul(1.5))&&(N=!0),d=i.sub(o).div(2).abs(),o.gt("1e18")||o.eq(O))break}if(o.gt("1e18")||!x||g==D(1,10,1))break;e==1?r=g:e==3&&(n=g),e++}i=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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(n.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(i=D(1,10,1),o=n,P=o,a=s.dZero,S=!0;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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 n=t;t=Math.trunc(t);let i=n-t;i!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(i)):this.eq(10)?e=e.layeradd10(i,r):e=e.layeradd(i,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,n){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(n)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=n.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(n=n.sub(t).div(e).add(t))),n}static softcap(t,e,r,n){return new s(t).softcap(e,r,n)}scale(t,e,r,n=!1){t=new s(t),e=new s(e);let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=n?i.mul(t.pow(e.sub(1))).root(e):i.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(i=n?i.div(t).max(1).log(e).add(t):s.pow(e,i.sub(t)).mul(t))),i}static scale(t,e,r,n,i=!1){return new s(t).scale(e,r,n,i)}format(t=2,e=9,r="mixed_sc"){return mt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,n="mixed_sc"){return mt.format(new s(t),e,r,n)}formatST(t=2,e=9,r="st"){return mt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,n="st"){return mt.format(new s(t),e,r,n)}formatGain(t,e="mixed_sc",r,n){return mt.formatGain(this.clone(),t,e,r,n)}static formatGain(t,e,r="mixed_sc",n,i){return mt.formatGain(new s(t),e,r,n,i)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),n={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},i="";for(let o of Object.keys(n)){let c=Math.floor(r/n[o]);r-=c*n[o],i+=o.repeat(c)}return i}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(ar),ut([Et()],s.prototype,"sign",2),ut([Et()],s.prototype,"mag",2),ut([Et()],s.prototype,"layer",2),s=ut([Ke()],s);var{formats:mt,FORMATS:gr}=er(s);s.formats=mt;var bt=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 bt(r))})}getBoosts(t,e){let r=[],n=[];for(let i=0;if),l=i,p=this.getBoosts(o,!0);p[0][0]?this.boostArray[p[1][0]]=new bt({id:o,name:c,description:d,value:m,order:l}):this.boostArray.push(new bt({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 bt(o):this.boostArray.push(new bt(o))}}}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((n,i)=>n.order-i.order);for(let n of r)e=n.value(e);return e}},Vr=ot(ft()),Ft=30,Yt=.001;function pr(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 new s(2).div(t.reciprocal().add(e.reciprocal()))}}function zt(t,e,r,n){n=Object.assign({},{verbose:!1,mode:"geometric"},n),t=new s(t),e=new s(e),r=new s(r);let i,o;return n.mode==="geometric"?(i=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=i.lte(r)):(i=t.sub(e).abs(),o=i.lte(r)),(n.verbose===!0||n.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:n,diff:i,result:o}),o}function Vt(t,e,r="geometric",n=Ft,i=Yt){let o=new s(1),c=new s(e);if(t(c).eq(0))return{value:new s(0),lowerBound:new s(0),upperBound:new s(0)};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,i,{verbose:!1,mode:"geometric"}))break}return o}function Zt(t,e,r=0,n,i){return r=new s(r),e=new s(e),e.sub(r).lte(Ft)?le(t,e,r,n):fe(t,e,r,i)}function Nr(t,e=10,r=0,n=1e3){if(t=new s(t),t.gte(s.pow(e,n)))return t;let i=s.floor(s.log(t,e)),o=t.div(s.pow(e,i));return o=o.mul(s.pow(e,r)).round(),o=o.div(s.pow(e,r)),o=o.mul(s.pow(e,i)),o}function ce(t,e,r,n=1/0,i,o,c=!1){t=new s(t),r=new s(r??e.level),n=new s(n);let d=n.sub(r);if(d.lt(0))return console.warn("calculateUpgrade: Invalid target: ",d),[new s(0),new s(0)];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=[new s(0),new s(0)];return c?(h[0]=u?new s(1):new s(0),h):(h=[u?new s(1):new s(0),u?f:new s(0)],h)}if(e.costBulk){let[f,u]=e.costBulk(t,e.level,d),h=t.gte(u);return[h?f:new s(0),h&&!c?u:new s(0)]}if(c){let f=g=>e.cost(g.add(r)),u=s.min(n,Vt(f,t,i,o).value.floor()),h=new s(0);return[u,h]}let m=Vt(f=>Zt(e.cost,f,r),t,i,o).value.floor().min(r.add(d).sub(1)),l=Zt(e.cost,m,r);return[m.sub(r).add(1).max(0),l]}function he(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function yr(t){return`el/${he(t)}`}var pt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):new s(1)}};ut([Et()],pt.prototype,"id",2),ut([Ct(()=>s)],pt.prototype,"level",2);var me=class Be{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:new s(1)}}).data??{level:new s(1)}).level}set level(e){this.data.level=new s(e)}constructor(e,r,n){let i=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>i,this.cache=new Dt(n??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??new s(1)}},Zr=ot(ft()),Nt=class{constructor(){this.value=new s(0),this.upgrades={}}};ut([Ct(()=>s)],Nt.prototype,"value",2),ut([Ct(()=>pt)],Nt.prototype,"upgrades",2);var de=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:new s(0),defaultBoost:new s(1)}){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 n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),r&&n.effect?.(n.level,n,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 n of t){let i=this.pointerAddUpgrade(n),o=new me(n,()=>this.pointerGetUpgrade(n.id));o.effect&&e&&o.effect(o.level,o,this),r[n.id]=o,this.upgrades[n.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,n){let i=this.getUpgrade(t);return i===null?(console.warn(`Upgrade "${t}" not found.`),[new s(0),new s(0)]):(e=i.level.add(e),i.maxLevel!==void 0&&(e=s.min(e,i.maxLevel)),ce(this.value,i,i.level,e,r,n))}getNextCost(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n)[0];return i.cost(i.level.add(o))}getNextCostMax(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n);return i.cost(i.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,n);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),i.level=i.level.add(o),i.effect?.(i.level,i,this),!0)}},Hr=ot(ft()),xt=class{constructor(t=0){this.value=new s(t)}};ut([Ct(()=>s)],xt.prototype,"value",2);var ge=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}},pe=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]}},vr=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let n=0;n{let t=!1,e=r=>(t||(console.warn("The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),br=ee,Ne={};Bt(Ne,{ConfigManager:()=>Pt,DataManager:()=>Me,EventManager:()=>we,EventTypes:()=>ve,Game:()=>Ir,GameAttribute:()=>Se,GameCurrency:()=>_e,GameReset:()=>Ie,KeyManager:()=>ye,gameDefaultConfig:()=>Ae,keys:()=>_r});var Wr=ot(ft()),Pt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,n){for(let i in n)typeof r[i]>"u"?r[i]=n[i]:typeof r[i]=="object"&&typeof n[i]=="object"&&!Array.isArray(r[i])&&!Array.isArray(n[i])&&(r[i]=e(r[i],n[i]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Mr={autoAddInterval:!0,fps:30},_r="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),ye=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 n of this.tickers)n(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let n of this.binds)(typeof n.onDownContinuous<"u"||typeof n.fn<"u")&&this.isPressing(n.id)&&(n.onDownContinuous?.(r),n.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(Mr)}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 n=e.key;r&&!this.keysPressed.includes(n)?this.keysPressed.push(n):!r&&this.keysPressed.includes(n)&&this.keysPressed.splice(this.keysPressed.indexOf(n),1)}onAll(e,r){for(let n of this.binds)if(n.key===r)switch(e){case"down":n.onDown?.();break;case"press":default:n.onPress?.();break;case"up":n.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,n){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:n}]:e,e=Array.isArray(e)?e:[e];for(let i of e){i.id=i.id??i.name;let o=this.getBind(i.id);if(o){Object.assign(o,i);continue}this.binds.push(i)}}},ve=(t=>(t.interval="interval",t.timeout="timeout",t))(ve||{}),Sr={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(Sr)}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 n=e-r.intervalLast;r.callbackFn(n),r.intervalLast=e}break;case"timeout":{let n=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(n),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,n,i){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},Xr=ot(ft()),be=ot(Ye()),Ht=ot(Ze()),Me=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(n){r()[t]=n},setValue(n){r()[t]=n}}}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)}`),n;try{n="9.0.0"}catch{n="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:n}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,be.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,be.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 n=e.hash,i=(0,Ht.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return n===i}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 n(p){return typeof p=="object"&&p?.constructor===Object}let i=(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(i(p,g)&&!i(u,g)&&(h[g]=p[g]),f[g]instanceof Nt){let N=p[g],O=u[g];if(Array.isArray(O.upgrades)){let x=O.upgrades;O.upgrades={};for(let P of x)O.upgrades[P.id]=P}O.upgrades={...N.upgrades,...O.upgrades},h[g]=O}else n(p[g])&&n(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:new s(0)}));function m(p,f){let u=se(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]=se(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(!n(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 n of this.eventsOnLoad)n();return e}},_e=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,n){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=n,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Se=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}},Ie=class{constructor(t,e){this.currenciesToReset=Array.isArray(t)?t:[t],this.extender=Array.isArray(e)?e:e?[e]:[],this.id=Symbol()}reset(){this.onReset?.(this),this.currenciesToReset.forEach(t=>{t.static.reset()}),this.extender.forEach(t=>{t.id!==this.id&&t.reset()})}},Ae={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Ir=class je{static{this.configManager=new Pt(Ae)}constructor(e){this.config=je.configManager.parse(e),this.dataManager=new Me(this),this.keyManager=new ye({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 de(()=>this.dataManager.getData(e).currency,r)}),new _e(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,n=0){return this.dataManager.setData(e,new xt(n)),this.dataManager.setStatic(e,new ge(this.dataManager.getData(e),r,n)),new Se(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(e,r){return new Ie(e,r)}},Ar={...br,...Ne},Or=Ar;if(typeof st.exports=="object"&&typeof St=="object"){var Tr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,i)&&i!==r&&Object.defineProperty(t,i,{get:()=>e[i],enumerable:!(n=Object.getOwnPropertyDescriptor(e,i))||n.enumerable});return t};st.exports=Tr(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 e6ec3657..714b03db 100644 --- a/dist/game/eMath.game.mjs +++ b/dist/game/eMath.game.mjs @@ -1103,7 +1103,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); diff --git a/dist/main/eMath.js b/dist/main/eMath.js index c6ade73b..b43e4180 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -435,7 +435,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index 5c89424e..f246a8ee 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},$t=(t,e)=>{for(var r in e)at(t,r,{get:e[r],enumerable:!0})},zt=(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)):{},zt(e||!t||!t.__esModule?at(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>zt(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(),y=typeof WeakMap=="function"?WeakMap:ir(),x=a?Symbol.for("@reflect-metadata:registry"):void 0,V=Je(),W=Ke(V);function o(u,l,c,w){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(!z(l))throw new TypeError;if(!z(w)&&!L(w)&&!mt(w))throw new TypeError;return mt(w)&&(w=void 0),c=nt(c),et(u,l,c,w)}}r("decorate",o);function N(u,l){function c(w,P){if(!z(w))throw new TypeError;if(!L(P)&&!Xe(P))throw new TypeError;Tt(u,l,w,P)}return c}r("metadata",N);function p(u,l,c,w){if(!z(c))throw new TypeError;return L(w)||(w=nt(w)),Tt(u,l,c,w)}r("defineMetadata",p);function v(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),X(u,l,c)}r("hasMetadata",v);function S(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),J(u,l,c)}r("hasOwnMetadata",S);function E(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),K(u,l,c)}r("getMetadata",E);function O(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),ft(u,l,c)}r("getOwnMetadata",O);function G(u,l){if(!z(u))throw new TypeError;return L(l)||(l=nt(l)),Ft(u,l)}r("getMetadataKeys",G);function B(u,l){if(!z(u))throw new TypeError;return L(l)||(l=nt(l)),Et(u,l)}r("getOwnMetadataKeys",B);function Y(u,l,c){if(!z(l))throw new TypeError;if(L(c)||(c=nt(c)),!z(l))throw new TypeError;L(c)||(c=nt(c));var w=yt(l,c,!1);return L(w)?!1:w.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",Y);function Q(u,l){for(var c=u.length-1;c>=0;--c){var w=u[c],P=w(l);if(!L(P)&&!mt(P)){if(!oe(P))throw new TypeError;l=P}}return l}function et(u,l,c,w){for(var P=u.length-1;P>=0;--P){var Z=u[P],D=Z(l,c,w);if(!L(D)&&!mt(D)){if(!z(D))throw new TypeError;w=D}}return w}function X(u,l,c){var w=J(u,l,c);if(w)return!0;var P=jt(l);return mt(P)?!1:X(u,P,c)}function J(u,l,c){var w=yt(l,c,!1);return L(w)?!1:se(w.OrdinaryHasOwnMetadata(u,l,c))}function K(u,l,c){var w=J(u,l,c);if(w)return ft(u,l,c);var P=jt(l);if(!mt(P))return K(u,P,c)}function ft(u,l,c){var w=yt(l,c,!1);if(!L(w))return w.OrdinaryGetOwnMetadata(u,l,c)}function Tt(u,l,c,w){var P=yt(c,w,!0);P.OrdinaryDefineOwnMetadata(u,l,c,w)}function Ft(u,l){var c=Et(u,l),w=jt(u);if(w===null)return c;var P=Ft(w,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}(),w=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;A$e}),it.exports=be(Zt);var ar=Nt(bt()),Ht={};$t(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:()=>wt,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 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(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} ${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)?"":new t(10).pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(new t(10).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)?"":new t(10).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=new t(10).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=new t(2).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):new t(10).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)?"":new t(10).pow(B.sub(B.floor())).toFixed(2))+"F"+m(B.floor(),0)}let O=o.div(new t(10).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(new t(10).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(new t(10).pow(G)),et=N===2?new t(2).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(new t(1).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 y(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function x(o,N=0){o=new t(o);let p=(O=>O.map((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:y,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 y=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(y)&&isFinite(x)){let o=n.pentate(y,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 y=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(y)&&isFinite(x)){let o=n.tetrate(y,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 y=parseFloat(h[0]),x=parseFloat(h[1]);if(isFinite(y)&&isFinite(x)){let V=n.pow(y,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 y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}let I=t.split("e"),F=I.length-1;if(F===0){let y=parseFloat(t);if(isFinite(y))return this.fromNumber(y),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(F===1){let y=parseFloat(t);if(isFinite(y)&&y!==0)return this.fromNumber(y),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let k=t.split("e^");if(k.length===2){this.sign=1,k[0].startsWith("-")&&(this.sign=-1);let y="";for(let x=0;x=43&&V<=57||V===101)y+=k[1].charAt(x);else return this.layer=parseFloat(y),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 y=parseFloat(I[I.length-2]);isFinite(y)&&(j*=Math.sign(y),j+=qt(y))}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 y=n.mul(C(1,2,j),f(q));return this.sign=y.sign,this.layer=y.layer,this.mag=y.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=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),y=Math.floor(d),x=d-y,V=q.pow(1-x).mul(j.pow(x));return n.tetrate(i,y,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 y=m;for(d=1;y.lt(t);)if(y=i.pow(y),d=d+1,y.layer>3){let x=Math.floor(t.layer-y.layer+1);y=i.iteratedexp(x,y,r),d=d+x}y.gt(t)&&(y=y.log(e),d=d-1)}else if(t.lt(g)){let y=g;for(d=0;y.gt(t);)y=y.log(e),d=d-1}let I=0,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 y=m;for(d=1;y.gt(t);)y=i.pow(y),d=d+1;y.lt(t)&&(y=y.log(e),d=d-1)}else if(t.gt(g)){let y=g;for(d=0;y.lt(t);)y=y.log(e),d=d-1}let I=0,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),y=!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(y=!1;a.neq(s);){if(x=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),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(y&&(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(y&&(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))&&(y=!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([ye()],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 new n(2).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=new n(1),h=new n(e);if(t(h).eq(0))return{value:new n(0),lowerBound:new n(0),upperBound:new n(0)};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),[new n(0),new n(0)];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=[new n(0),new n(0)];return h?(q[0]=k?new n(1):new n(0),q):(q=[k?new n(1):new n(0),k?F:new n(0)],q)}if(e.costBulk){let[F,k]=e.costBulk(t,e.level,g),q=t.gte(k);return[q?F:new n(0),q&&!h?k:new n(0)]}if(h){let F=j=>e.cost(j.add(r)),k=n.min(i,Bt(F,t,s,a).value.floor()),q=new n(0);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 wt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):new n(1)}};st([_t()],wt.prototype,"id",2),st([It(()=>n)],wt.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:new n(1)}}).data??{level:new n(1)}).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??new n(1)}},lr=Nt(bt()),Ot=class{constructor(){this.value=new n(0),this.upgrades={}}};st([It(()=>n)],Ot.prototype,"value",2),st([It(()=>wt)],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:new n(0),defaultBoost:new n(1)}){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 wt(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.`),[new n(0),new n(0)]):(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.`),new n(0);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.`),new n(0);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})(),$e=Ht;if(typeof it.exports=="object"&&typeof dt=="object"){var ze=(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=ze(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},$t=(t,e)=>{for(var r in e)at(t,r,{get:e[r],enumerable:!0})},zt=(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)):{},zt(e||!t||!t.__esModule?at(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>zt(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(),y=typeof WeakMap=="function"?WeakMap:ir(),x=a?Symbol.for("@reflect-metadata:registry"):void 0,V=Je(),W=Ke(V);function o(u,l,c,w){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(!z(l))throw new TypeError;if(!z(w)&&!L(w)&&!mt(w))throw new TypeError;return mt(w)&&(w=void 0),c=nt(c),et(u,l,c,w)}}r("decorate",o);function N(u,l){function c(w,P){if(!z(w))throw new TypeError;if(!L(P)&&!Xe(P))throw new TypeError;Tt(u,l,w,P)}return c}r("metadata",N);function p(u,l,c,w){if(!z(c))throw new TypeError;return L(w)||(w=nt(w)),Tt(u,l,c,w)}r("defineMetadata",p);function v(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),X(u,l,c)}r("hasMetadata",v);function S(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),J(u,l,c)}r("hasOwnMetadata",S);function E(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),K(u,l,c)}r("getMetadata",E);function O(u,l,c){if(!z(l))throw new TypeError;return L(c)||(c=nt(c)),ft(u,l,c)}r("getOwnMetadata",O);function G(u,l){if(!z(u))throw new TypeError;return L(l)||(l=nt(l)),Ft(u,l)}r("getMetadataKeys",G);function B(u,l){if(!z(u))throw new TypeError;return L(l)||(l=nt(l)),Et(u,l)}r("getOwnMetadataKeys",B);function Y(u,l,c){if(!z(l))throw new TypeError;if(L(c)||(c=nt(c)),!z(l))throw new TypeError;L(c)||(c=nt(c));var w=yt(l,c,!1);return L(w)?!1:w.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",Y);function Q(u,l){for(var c=u.length-1;c>=0;--c){var w=u[c],P=w(l);if(!L(P)&&!mt(P)){if(!oe(P))throw new TypeError;l=P}}return l}function et(u,l,c,w){for(var P=u.length-1;P>=0;--P){var Z=u[P],D=Z(l,c,w);if(!L(D)&&!mt(D)){if(!z(D))throw new TypeError;w=D}}return w}function X(u,l,c){var w=J(u,l,c);if(w)return!0;var P=jt(l);return mt(P)?!1:X(u,P,c)}function J(u,l,c){var w=yt(l,c,!1);return L(w)?!1:se(w.OrdinaryHasOwnMetadata(u,l,c))}function K(u,l,c){var w=J(u,l,c);if(w)return ft(u,l,c);var P=jt(l);if(!mt(P))return K(u,P,c)}function ft(u,l,c){var w=yt(l,c,!1);if(!L(w))return w.OrdinaryGetOwnMetadata(u,l,c)}function Tt(u,l,c,w){var P=yt(c,w,!0);P.OrdinaryDefineOwnMetadata(u,l,c,w)}function Ft(u,l){var c=Et(u,l),w=jt(u);if(w===null)return c;var P=Ft(w,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}(),w=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;A$e}),it.exports=be(Zt);var ar=Nt(bt()),Ht={};$t(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:()=>wt,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 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(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)?"":new t(10).pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(new t(10).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)?"":new t(10).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=new t(10).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=new t(2).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):new t(10).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)?"":new t(10).pow(B.sub(B.floor())).toFixed(2))+"F"+m(B.floor(),0)}let O=o.div(new t(10).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(new t(10).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(new t(10).pow(G)),et=N===2?new t(2).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(new t(1).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 y(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function x(o,N=0){o=new t(o);let p=(O=>O.map((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:y,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 y=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(y)&&isFinite(x)){let o=n.pentate(y,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 y=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(y)&&isFinite(x)){let o=n.tetrate(y,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 y=parseFloat(h[0]),x=parseFloat(h[1]);if(isFinite(y)&&isFinite(x)){let V=n.pow(y,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 y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),m=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let x=parseFloat(d[1]);if(isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){g=10;let y=!1;d[0].startsWith("-")&&(y=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let x=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),m=parseFloat(d[1]),isFinite(x)||(x=1),isFinite(g)&&isFinite(m)){let 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)),y&&(this.sign*=-1),this}}let I=t.split("e"),F=I.length-1;if(F===0){let y=parseFloat(t);if(isFinite(y))return this.fromNumber(y),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(F===1){let y=parseFloat(t);if(isFinite(y)&&y!==0)return this.fromNumber(y),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let k=t.split("e^");if(k.length===2){this.sign=1,k[0].startsWith("-")&&(this.sign=-1);let y="";for(let x=0;x=43&&V<=57||V===101)y+=k[1].charAt(x);else return this.layer=parseFloat(y),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 y=parseFloat(I[I.length-2]);isFinite(y)&&(j*=Math.sign(y),j+=qt(y))}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 y=n.mul(C(1,2,j),f(q));return this.sign=y.sign,this.layer=y.layer,this.mag=y.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=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),y=Math.floor(d),x=d-y,V=q.pow(1-x).mul(j.pow(x));return n.tetrate(i,y,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 y=m;for(d=1;y.lt(t);)if(y=i.pow(y),d=d+1,y.layer>3){let x=Math.floor(t.layer-y.layer+1);y=i.iteratedexp(x,y,r),d=d+x}y.gt(t)&&(y=y.log(e),d=d-1)}else if(t.lt(g)){let y=g;for(d=0;y.gt(t);)y=y.log(e),d=d-1}let I=0,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 y=m;for(d=1;y.gt(t);)y=i.pow(y),d=d+1;y.lt(t)&&(y=y.log(e),d=d-1)}else if(t.gt(g)){let y=g;for(d=0;y.lt(t);)y=y.log(e),d=d-1}let I=0,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),y=!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(y=!1;a.neq(s);){if(x=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))m=a.pow10().recip(),I=a.pow10().recip(),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(y&&(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(y&&(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))&&(y=!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([ye()],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 new n(2).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=new n(1),h=new n(e);if(t(h).eq(0))return{value:new n(0),lowerBound:new n(0),upperBound:new n(0)};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),[new n(0),new n(0)];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=[new n(0),new n(0)];return h?(q[0]=k?new n(1):new n(0),q):(q=[k?new n(1):new n(0),k?F:new n(0)],q)}if(e.costBulk){let[F,k]=e.costBulk(t,e.level,g),q=t.gte(k);return[q?F:new n(0),q&&!h?k:new n(0)]}if(h){let F=j=>e.cost(j.add(r)),k=n.min(i,Bt(F,t,s,a).value.floor()),q=new n(0);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 wt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):new n(1)}};st([_t()],wt.prototype,"id",2),st([It(()=>n)],wt.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:new n(1)}}).data??{level:new n(1)}).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??new n(1)}},lr=Nt(bt()),Ot=class{constructor(){this.value=new n(0),this.upgrades={}}};st([It(()=>n)],Ot.prototype,"value",2),st([It(()=>wt)],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:new n(0),defaultBoost:new n(1)}){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 wt(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.`),[new n(0),new n(0)]):(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.`),new n(0);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.`),new n(0);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})(),$e=Ht;if(typeof it.exports=="object"&&typeof dt=="object"){var ze=(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=ze(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 7e28ec69..42c5e91e 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -374,7 +374,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); diff --git a/dist/presets/eMath.presets.js b/dist/presets/eMath.presets.js index 95d54c54..83439cf4 100644 --- a/dist/presets/eMath.presets.js +++ b/dist/presets/eMath.presets.js @@ -12,10 +12,15 @@ var exports = {}; var module = { exports }; "use strict"; +var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; +var __commonJS = (cb, mod) => function __require() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); @@ -28,6 +33,14 @@ var __copyProps = (to, from, except, desc) => { } return to; }; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; @@ -38,6 +51,713 @@ var __decorateClass = (decorators, target, key, kind) => { return result; }; +// node_modules/lz-string/libs/lz-string.js +var require_lz_string = __commonJS({ + "node_modules/lz-string/libs/lz-string.js"(exports, module2) { + var LZString = function() { + var f = String.fromCharCode; + var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$"; + var baseReverseDic = {}; + function getBaseValue(alphabet, character) { + if (!baseReverseDic[alphabet]) { + baseReverseDic[alphabet] = {}; + for (var i = 0; i < alphabet.length; i++) { + baseReverseDic[alphabet][alphabet.charAt(i)] = i; + } + } + return baseReverseDic[alphabet][character]; + } + var LZString2 = { + compressToBase64: function(input) { + if (input == null) return ""; + var res = LZString2._compress(input, 6, function(a) { + return keyStrBase64.charAt(a); + }); + switch (res.length % 4) { + default: + case 0: + return res; + case 1: + return res + "==="; + case 2: + return res + "=="; + case 3: + return res + "="; + } + }, + decompressFromBase64: function(input) { + if (input == null) return ""; + if (input == "") return null; + return LZString2._decompress(input.length, 32, function(index) { + return getBaseValue(keyStrBase64, input.charAt(index)); + }); + }, + compressToUTF16: function(input) { + if (input == null) return ""; + return LZString2._compress(input, 15, function(a) { + return f(a + 32); + }) + " "; + }, + decompressFromUTF16: function(compressed) { + if (compressed == null) return ""; + if (compressed == "") return null; + return LZString2._decompress(compressed.length, 16384, function(index) { + return compressed.charCodeAt(index) - 32; + }); + }, + //compress into uint8array (UCS-2 big endian format) + compressToUint8Array: function(uncompressed) { + var compressed = LZString2.compress(uncompressed); + var buf = new Uint8Array(compressed.length * 2); + for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) { + var current_value = compressed.charCodeAt(i); + buf[i * 2] = current_value >>> 8; + buf[i * 2 + 1] = current_value % 256; + } + return buf; + }, + //decompress from uint8array (UCS-2 big endian format) + decompressFromUint8Array: function(compressed) { + if (compressed === null || compressed === void 0) { + return LZString2.decompress(compressed); + } else { + var buf = new Array(compressed.length / 2); + for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) { + buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1]; + } + var result = []; + buf.forEach(function(c) { + result.push(f(c)); + }); + return LZString2.decompress(result.join("")); + } + }, + //compress into a string that is already URI encoded + compressToEncodedURIComponent: function(input) { + if (input == null) return ""; + return LZString2._compress(input, 6, function(a) { + return keyStrUriSafe.charAt(a); + }); + }, + //decompress from an output of compressToEncodedURIComponent + decompressFromEncodedURIComponent: function(input) { + if (input == null) return ""; + if (input == "") return null; + input = input.replace(/ /g, "+"); + return LZString2._decompress(input.length, 32, function(index) { + return getBaseValue(keyStrUriSafe, input.charAt(index)); + }); + }, + compress: function(uncompressed) { + return LZString2._compress(uncompressed, 16, function(a) { + return f(a); + }); + }, + _compress: function(uncompressed, bitsPerChar, getCharFromInt) { + if (uncompressed == null) return ""; + var i, value, context_dictionary = {}, context_dictionaryToCreate = {}, context_c = "", context_wc = "", context_w = "", context_enlargeIn = 2, context_dictSize = 3, context_numBits = 2, context_data = [], context_data_val = 0, context_data_position = 0, ii; + for (ii = 0; ii < uncompressed.length; ii += 1) { + context_c = uncompressed.charAt(ii); + if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) { + context_dictionary[context_c] = context_dictSize++; + context_dictionaryToCreate[context_c] = true; + } + context_wc = context_w + context_c; + if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) { + context_w = context_wc; + } else { + if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) { + if (context_w.charCodeAt(0) < 256) { + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + } + value = context_w.charCodeAt(0); + for (i = 0; i < 8; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } else { + value = 1; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = 0; + } + value = context_w.charCodeAt(0); + for (i = 0; i < 16; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + delete context_dictionaryToCreate[context_w]; + } else { + value = context_dictionary[context_w]; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + context_dictionary[context_wc] = context_dictSize++; + context_w = String(context_c); + } + } + if (context_w !== "") { + if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) { + if (context_w.charCodeAt(0) < 256) { + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + } + value = context_w.charCodeAt(0); + for (i = 0; i < 8; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } else { + value = 1; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = 0; + } + value = context_w.charCodeAt(0); + for (i = 0; i < 16; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + delete context_dictionaryToCreate[context_w]; + } else { + value = context_dictionary[context_w]; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + } + value = 2; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + while (true) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data.push(getCharFromInt(context_data_val)); + break; + } else context_data_position++; + } + return context_data.join(""); + }, + decompress: function(compressed) { + if (compressed == null) return ""; + if (compressed == "") return null; + return LZString2._decompress(compressed.length, 32768, function(index) { + return compressed.charCodeAt(index); + }); + }, + _decompress: function(length, resetValue, getNextValue) { + var dictionary = [], next, enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = { val: getNextValue(0), position: resetValue, index: 1 }; + for (i = 0; i < 3; i += 1) { + dictionary[i] = i; + } + bits = 0; + maxpower = Math.pow(2, 2); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + switch (next = bits) { + case 0: + bits = 0; + maxpower = Math.pow(2, 8); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + c = f(bits); + break; + case 1: + bits = 0; + maxpower = Math.pow(2, 16); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + c = f(bits); + break; + case 2: + return ""; + } + dictionary[3] = c; + w = c; + result.push(c); + while (true) { + if (data.index > length) { + return ""; + } + bits = 0; + maxpower = Math.pow(2, numBits); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + switch (c = bits) { + case 0: + bits = 0; + maxpower = Math.pow(2, 8); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + dictionary[dictSize++] = f(bits); + c = dictSize - 1; + enlargeIn--; + break; + case 1: + bits = 0; + maxpower = Math.pow(2, 16); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + dictionary[dictSize++] = f(bits); + c = dictSize - 1; + enlargeIn--; + break; + case 2: + return result.join(""); + } + if (enlargeIn == 0) { + enlargeIn = Math.pow(2, numBits); + numBits++; + } + if (dictionary[c]) { + entry = dictionary[c]; + } else { + if (c === dictSize) { + entry = w + w.charAt(0); + } else { + return null; + } + } + result.push(entry); + dictionary[dictSize++] = w + entry.charAt(0); + enlargeIn--; + w = entry; + if (enlargeIn == 0) { + enlargeIn = Math.pow(2, numBits); + numBits++; + } + } + } + }; + return LZString2; + }(); + if (typeof define === "function" && define.amd) { + define(function() { + return LZString; + }); + } else if (typeof module2 !== "undefined" && module2 != null) { + module2.exports = LZString; + } else if (typeof angular !== "undefined" && angular != null) { + angular.module("LZString", []).factory("LZString", function() { + return LZString; + }); + } + } +}); + +// node_modules/crypt/crypt.js +var require_crypt = __commonJS({ + "node_modules/crypt/crypt.js"(exports, module2) { + (function() { + var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt = { + // Bit-wise rotation left + rotl: function(n, b) { + return n << b | n >>> 32 - b; + }, + // Bit-wise rotation right + rotr: function(n, b) { + return n << 32 - b | n >>> b; + }, + // Swap big-endian to little-endian and vice versa + endian: function(n) { + if (n.constructor == Number) { + return crypt.rotl(n, 8) & 16711935 | crypt.rotl(n, 24) & 4278255360; + } + for (var i = 0; i < n.length; i++) + n[i] = crypt.endian(n[i]); + return n; + }, + // Generate an array of any length of random bytes + randomBytes: function(n) { + for (var bytes = []; n > 0; n--) + bytes.push(Math.floor(Math.random() * 256)); + return bytes; + }, + // Convert a byte array to big-endian 32-bit words + bytesToWords: function(bytes) { + for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8) + words[b >>> 5] |= bytes[i] << 24 - b % 32; + return words; + }, + // Convert big-endian 32-bit words to a byte array + wordsToBytes: function(words) { + for (var bytes = [], b = 0; b < words.length * 32; b += 8) + bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255); + return bytes; + }, + // Convert a byte array to a hex string + bytesToHex: function(bytes) { + for (var hex = [], i = 0; i < bytes.length; i++) { + hex.push((bytes[i] >>> 4).toString(16)); + hex.push((bytes[i] & 15).toString(16)); + } + return hex.join(""); + }, + // Convert a hex string to a byte array + hexToBytes: function(hex) { + for (var bytes = [], c = 0; c < hex.length; c += 2) + bytes.push(parseInt(hex.substr(c, 2), 16)); + return bytes; + }, + // Convert a byte array to a base-64 string + bytesToBase64: function(bytes) { + for (var base64 = [], i = 0; i < bytes.length; i += 3) { + var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2]; + for (var j = 0; j < 4; j++) + if (i * 8 + j * 6 <= bytes.length * 8) + base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63)); + else + base64.push("="); + } + return base64.join(""); + }, + // Convert a base-64 string to a byte array + base64ToBytes: function(base64) { + base64 = base64.replace(/[^A-Z0-9+\/]/ig, ""); + for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) { + if (imod4 == 0) continue; + bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2); + } + return bytes; + } + }; + module2.exports = crypt; + })(); + } +}); + +// node_modules/charenc/charenc.js +var require_charenc = __commonJS({ + "node_modules/charenc/charenc.js"(exports, module2) { + var charenc = { + // UTF-8 encoding + utf8: { + // Convert a string to a byte array + stringToBytes: function(str) { + return charenc.bin.stringToBytes(unescape(encodeURIComponent(str))); + }, + // Convert a byte array to a string + bytesToString: function(bytes) { + return decodeURIComponent(escape(charenc.bin.bytesToString(bytes))); + } + }, + // Binary encoding + bin: { + // Convert a string to a byte array + stringToBytes: function(str) { + for (var bytes = [], i = 0; i < str.length; i++) + bytes.push(str.charCodeAt(i) & 255); + return bytes; + }, + // Convert a byte array to a string + bytesToString: function(bytes) { + for (var str = [], i = 0; i < bytes.length; i++) + str.push(String.fromCharCode(bytes[i])); + return str.join(""); + } + } + }; + module2.exports = charenc; + } +}); + +// node_modules/is-buffer/index.js +var require_is_buffer = __commonJS({ + "node_modules/is-buffer/index.js"(exports, module2) { + module2.exports = function(obj) { + return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer); + }; + function isBuffer(obj) { + return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj); + } + function isSlowBuffer(obj) { + return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0)); + } + } +}); + +// node_modules/md5/md5.js +var require_md5 = __commonJS({ + "node_modules/md5/md5.js"(exports, module2) { + (function() { + var crypt = require_crypt(), utf8 = require_charenc().utf8, isBuffer = require_is_buffer(), bin = require_charenc().bin, md52 = function(message, options) { + if (message.constructor == String) + if (options && options.encoding === "binary") + message = bin.stringToBytes(message); + else + message = utf8.stringToBytes(message); + else if (isBuffer(message)) + message = Array.prototype.slice.call(message, 0); + else if (!Array.isArray(message) && message.constructor !== Uint8Array) + message = message.toString(); + var m = crypt.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878; + for (var i = 0; i < m.length; i++) { + m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360; + } + m[l >>> 5] |= 128 << l % 32; + m[(l + 64 >>> 9 << 4) + 14] = l; + var FF = md52._ff, GG = md52._gg, HH = md52._hh, II = md52._ii; + for (var i = 0; i < m.length; i += 16) { + var aa = a, bb = b, cc = c, dd = d; + a = FF(a, b, c, d, m[i + 0], 7, -680876936); + d = FF(d, a, b, c, m[i + 1], 12, -389564586); + c = FF(c, d, a, b, m[i + 2], 17, 606105819); + b = FF(b, c, d, a, m[i + 3], 22, -1044525330); + a = FF(a, b, c, d, m[i + 4], 7, -176418897); + d = FF(d, a, b, c, m[i + 5], 12, 1200080426); + c = FF(c, d, a, b, m[i + 6], 17, -1473231341); + b = FF(b, c, d, a, m[i + 7], 22, -45705983); + a = FF(a, b, c, d, m[i + 8], 7, 1770035416); + d = FF(d, a, b, c, m[i + 9], 12, -1958414417); + c = FF(c, d, a, b, m[i + 10], 17, -42063); + b = FF(b, c, d, a, m[i + 11], 22, -1990404162); + a = FF(a, b, c, d, m[i + 12], 7, 1804603682); + d = FF(d, a, b, c, m[i + 13], 12, -40341101); + c = FF(c, d, a, b, m[i + 14], 17, -1502002290); + b = FF(b, c, d, a, m[i + 15], 22, 1236535329); + a = GG(a, b, c, d, m[i + 1], 5, -165796510); + d = GG(d, a, b, c, m[i + 6], 9, -1069501632); + c = GG(c, d, a, b, m[i + 11], 14, 643717713); + b = GG(b, c, d, a, m[i + 0], 20, -373897302); + a = GG(a, b, c, d, m[i + 5], 5, -701558691); + d = GG(d, a, b, c, m[i + 10], 9, 38016083); + c = GG(c, d, a, b, m[i + 15], 14, -660478335); + b = GG(b, c, d, a, m[i + 4], 20, -405537848); + a = GG(a, b, c, d, m[i + 9], 5, 568446438); + d = GG(d, a, b, c, m[i + 14], 9, -1019803690); + c = GG(c, d, a, b, m[i + 3], 14, -187363961); + b = GG(b, c, d, a, m[i + 8], 20, 1163531501); + a = GG(a, b, c, d, m[i + 13], 5, -1444681467); + d = GG(d, a, b, c, m[i + 2], 9, -51403784); + c = GG(c, d, a, b, m[i + 7], 14, 1735328473); + b = GG(b, c, d, a, m[i + 12], 20, -1926607734); + a = HH(a, b, c, d, m[i + 5], 4, -378558); + d = HH(d, a, b, c, m[i + 8], 11, -2022574463); + c = HH(c, d, a, b, m[i + 11], 16, 1839030562); + b = HH(b, c, d, a, m[i + 14], 23, -35309556); + a = HH(a, b, c, d, m[i + 1], 4, -1530992060); + d = HH(d, a, b, c, m[i + 4], 11, 1272893353); + c = HH(c, d, a, b, m[i + 7], 16, -155497632); + b = HH(b, c, d, a, m[i + 10], 23, -1094730640); + a = HH(a, b, c, d, m[i + 13], 4, 681279174); + d = HH(d, a, b, c, m[i + 0], 11, -358537222); + c = HH(c, d, a, b, m[i + 3], 16, -722521979); + b = HH(b, c, d, a, m[i + 6], 23, 76029189); + a = HH(a, b, c, d, m[i + 9], 4, -640364487); + d = HH(d, a, b, c, m[i + 12], 11, -421815835); + c = HH(c, d, a, b, m[i + 15], 16, 530742520); + b = HH(b, c, d, a, m[i + 2], 23, -995338651); + a = II(a, b, c, d, m[i + 0], 6, -198630844); + d = II(d, a, b, c, m[i + 7], 10, 1126891415); + c = II(c, d, a, b, m[i + 14], 15, -1416354905); + b = II(b, c, d, a, m[i + 5], 21, -57434055); + a = II(a, b, c, d, m[i + 12], 6, 1700485571); + d = II(d, a, b, c, m[i + 3], 10, -1894986606); + c = II(c, d, a, b, m[i + 10], 15, -1051523); + b = II(b, c, d, a, m[i + 1], 21, -2054922799); + a = II(a, b, c, d, m[i + 8], 6, 1873313359); + d = II(d, a, b, c, m[i + 15], 10, -30611744); + c = II(c, d, a, b, m[i + 6], 15, -1560198380); + b = II(b, c, d, a, m[i + 13], 21, 1309151649); + a = II(a, b, c, d, m[i + 4], 6, -145523070); + d = II(d, a, b, c, m[i + 11], 10, -1120210379); + c = II(c, d, a, b, m[i + 2], 15, 718787259); + b = II(b, c, d, a, m[i + 9], 21, -343485551); + a = a + aa >>> 0; + b = b + bb >>> 0; + c = c + cc >>> 0; + d = d + dd >>> 0; + } + return crypt.endian([a, b, c, d]); + }; + md52._ff = function(a, b, c, d, x, s, t) { + var n = a + (b & c | ~b & d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._gg = function(a, b, c, d, x, s, t) { + var n = a + (b & d | c & ~d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._hh = function(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._ii = function(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._blocksize = 16; + md52._digestsize = 16; + module2.exports = function(message, options) { + if (message === void 0 || message === null) + throw new Error("Illegal argument " + message); + var digestbytes = crypt.wordsToBytes(md52(message, options)); + return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt.bytesToHex(digestbytes); + }; + })(); + } +}); + // src/presets/index.ts var presets_exports = {}; __export(presets_exports, { @@ -49,8 +769,8 @@ __export(presets_exports, { }); module.exports = __toCommonJS(presets_exports); -// src/E/e.ts -var import_class_transformer = require("class-transformer"); +// src/index.ts +var import_reflect_metadata4 = require("reflect-metadata"); // src/E/lru-cache.ts var LRUCache = class { @@ -155,6 +875,9 @@ var ListNode = class { } }; +// src/E/e.ts +var import_class_transformer = require("class-transformer"); + // src/E/format.ts var ST_NAMES = [ [ @@ -410,7 +1133,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); @@ -4855,6 +5578,1630 @@ Decimal = __decorateClass([ var { formats, FORMATS } = decimalFormatGenerator(Decimal); Decimal.formats = formats; +// src/classes/Boost.ts +var BoostObject = class { + // eslint-disable-next-line jsdoc/require-returns + /** @deprecated Use {@link description} instead */ + get desc() { + return this.description; + } + get description() { + return this.descriptionFn(); + } + 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; + } +}; +var Boost = class { + /** + * Constructs a new boost manager. + * @param baseEffect - The base effect value to which boosts are applied. + * @param boosts - An array of boost objects to initialize with. + */ + constructor(baseEffect = 1, boosts) { + /** + * @alias setBoost + * @deprecated Use {@link setBoost} instead. + */ + this.addBoost = this.setBoost.bind(this); + boosts = boosts ? Array.isArray(boosts) ? boosts : [boosts] : void 0; + this.baseEffect = new Decimal(baseEffect); + this.boostArray = []; + if (boosts) { + boosts.forEach((boostObj) => { + this.boostArray.push(new BoostObject(boostObj)); + }); + } + } + getBoosts(id, index) { + const boostList = []; + const indexList = []; + for (let i = 0; i < this.boostArray.length; i++) { + if (typeof id === "string" && id === this.boostArray[i].id || id instanceof RegExp && id.test(this.boostArray[i].id)) { + boostList.push(this.boostArray[i]); + indexList.push(i); + } + } + return index ? [boostList, indexList] : boostList; + } + /** + * Gets a boost object by its ID. + * @deprecated Use {@link getBoosts} instead. + * @param id - The ID of the boost to retrieve. + * @returns The boost object if found, or null if not found. + */ + getBoost(id) { + return this.getBoosts(id)[0] ?? null; + } + /** + * Removes a boost by its ID. Only removes the first instance of the id. + * @param id - The ID of the boost to remove. + * @example + * // Remove the boost with the ID "healthBoost" + * boost.removeBoost("healthBoost"); + */ + removeBoost(id) { + for (let i = 0; i < this.boostArray.length; i++) { + if (id === this.boostArray[i].id) { + this.boostArray.splice(i, 1); + break; + } + } + } + setBoost(arg1, arg2, arg3, arg4, arg5) { + if (!arg1) return; + if (typeof arg1 === "string") { + const id = arg1; + const name = arg2 ?? ""; + const description = arg3 ?? ""; + const value = arg4 ?? ((e) => e); + const order = arg5; + const bCheck = this.getBoosts(id, true); + if (!bCheck[0][0]) { + this.boostArray.push(new BoostObject({ id, name, description, value, order })); + } else { + this.boostArray[bCheck[1][0]] = new BoostObject({ id, name, description, value, order }); + } + } else { + arg1 = Array.isArray(arg1) ? arg1 : [arg1]; + for (const boost of arg1) { + const bCheck = this.getBoosts(boost.id, true); + if (!bCheck[0][0]) { + this.boostArray.push(new BoostObject(boost)); + } else { + this.boostArray[bCheck[1][0]] = new BoostObject(boost); + } + } + } + } + /** + * Calculates the cumulative effect of all boosts on the base effect. + * @param base - The base effect value to calculate with. Defaults to the base effect of the boost manager. + * @returns The calculated effect after applying boosts. + * @example + * // Calculate the effect of all boosts + * const finalEffect = boost.calculate(); + */ + calculate(base = this.baseEffect) { + let output = new Decimal(base); + let boosts = this.boostArray; + boosts = boosts.sort((a, b) => a.order - b.order); + for (const boost of boosts) { + output = boost.value(output); + } + return output; + } +}; + +// src/classes/Upgrade.ts +var import_reflect_metadata = require("reflect-metadata"); +var import_class_transformer2 = require("class-transformer"); + +// src/classes/numericalAnalysis.ts +var DEFAULT_ITERATIONS = 30; +var DEFAULT_TOLERANCE = 1e-3; +function mean(a, b, mode = "geometric") { + a = new Decimal(a); + b = new Decimal(b); + switch (mode) { + case "arithmetic": + case 1: + return a.add(b).div(2); + case "geometric": + case 2: + default: + return a.mul(b).sqrt(); + case "harmonic": + case 3: + return new Decimal(2).div(a.reciprocal().add(b.reciprocal())); + } +} +function equalsTolerance(a, b, tolerance, config) { + config = Object.assign({}, { + verbose: false, + mode: "geometric" + }, config); + a = new Decimal(a); + b = new Decimal(b); + tolerance = new Decimal(tolerance); + let diff; + let result; + if (config.mode === "geometric") { + diff = a.sub(b).abs().div(a.abs().add(b.abs()).div(2)); + result = diff.lte(tolerance); + } else { + diff = a.sub(b).abs(); + result = diff.lte(tolerance); + } + if (config.verbose === true || config.verbose === "onlyOnFail" && !result) console.log({ a, b, tolerance, config, diff, result }); + return result; +} +function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_ITERATIONS, tolerance = DEFAULT_TOLERANCE) { + let lowerBound = new Decimal(1); + let upperBound = new Decimal(n); + if (f(upperBound).eq(0)) { + return { + value: new Decimal(0), + lowerBound: new Decimal(0), + upperBound: new Decimal(0) + }; + } + if (f(upperBound).lt(n)) { + console.warn("The function is not monotonically increasing. (f(n) < n)"); + return { + value: upperBound, + lowerBound: upperBound, + upperBound + }; + } + for (let i = 0; i < iterations; i++) { + const mid = mean(lowerBound, upperBound, mode); + const midValue = f(mid); + if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { + break; + } + if (midValue.lt(n)) { + lowerBound = mid; + } else { + upperBound = mid; + } + } + const out = { + value: lowerBound, + lowerBound, + upperBound + }; + return out; +} +function calculateSumLoop(f, b, a = 0, epsilon = DEFAULT_TOLERANCE) { + let sum = new Decimal(); + let n = new Decimal(b); + for (; n.gte(a); n = n.sub(1)) { + const initSum = sum; + const value = f(n); + sum = sum.add(value); + const diff = initSum.div(sum); + if (diff.lte(1) && diff.gt(new Decimal(1).sub(epsilon))) break; + } + return sum; +} +function calculateSumApprox(f, b, a = 0, iterations = DEFAULT_ITERATIONS, tolerance = DEFAULT_TOLERANCE * 2) { + a = new Decimal(a); + b = new Decimal(b); + let sum = new Decimal(0); + const intervalWidth = b.sub(a).div(iterations); + for (let i = iterations - 1; i >= 0; i--) { + const x0 = a.add(intervalWidth.mul(i)); + const x1 = a.add(intervalWidth.mul(i + 1)); + const oldSum = sum; + sum = sum.add(f(x0).add(f(x1)).div(2).mul(intervalWidth)); + if (equalsTolerance(oldSum, sum, tolerance, { verbose: false, mode: "geometric" })) { + break; + } + } + return sum; +} +function calculateSum(f, b, a = 0, epsilon, iterations) { + a = new Decimal(a); + b = new Decimal(b); + if (b.sub(a).lte(DEFAULT_ITERATIONS)) { + return calculateSumLoop(f, b, a, epsilon); + } else { + return calculateSumApprox(f, b, a, iterations); + } +} + +// src/classes/Upgrade.ts +function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iterations, el = false) { + value = new Decimal(value); + start = new Decimal(start ?? upgrade.level); + end = new Decimal(end); + const target = end.sub(start); + if (target.lt(0)) { + console.warn("calculateUpgrade: Invalid target: ", target); + return [new Decimal(0), new Decimal(0)]; + } + el = (typeof upgrade.el === "function" ? upgrade.el() : upgrade.el) ?? el; + if (target.eq(1)) { + const cost2 = upgrade.cost(upgrade.level); + const canAfford = value.gte(cost2); + let out = [new Decimal(0), new Decimal(0)]; + if (el) { + out[0] = canAfford ? new Decimal(1) : new Decimal(0); + return out; + } else { + out = [canAfford ? new Decimal(1) : new Decimal(0), canAfford ? cost2 : new Decimal(0)]; + return out; + } + } + if (upgrade.costBulk) { + const [amount, cost2] = upgrade.costBulk(value, upgrade.level, target); + const canAfford = value.gte(cost2); + const out = [canAfford ? amount : new Decimal(0), canAfford && !el ? cost2 : new Decimal(0)]; + return out; + } + if (el) { + const costTargetFn = (level) => upgrade.cost(level.add(start)); + const maxLevelAffordable2 = Decimal.min(end, inverseFunctionApprox(costTargetFn, value, mode, iterations).value.floor()); + const cost2 = new Decimal(0); + return [maxLevelAffordable2, cost2]; + } + const maxLevelAffordable = inverseFunctionApprox( + (x) => calculateSum(upgrade.cost, x, start), + value, + mode, + iterations + ).value.floor().min(start.add(target).sub(1)); + const cost = calculateSum(upgrade.cost, maxLevelAffordable, start); + const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0); + return [maxLevelAffordableActual, cost]; +} +var UpgradeData = class { + /** + * Constructs a new upgrade object with an initial level of 1 (or the provided level) + * @param init - The upgrade object to initialize. + */ + constructor(init) { + init = init ?? {}; + this.id = init.id; + this.level = init.level ? new Decimal(init.level) : new Decimal(1); + } +}; +__decorateClass([ + (0, import_class_transformer2.Expose)() +], UpgradeData.prototype, "id", 2); +__decorateClass([ + (0, import_class_transformer2.Type)(() => Decimal) +], UpgradeData.prototype, "level", 2); +var UpgradeStatic = class _UpgradeStatic { + static { + /** The default size of the cache. Should be one less than a power of 2. */ + this.cacheSize = 15; + } + /** @returns The data of the upgrade. */ + get data() { + return this.dataPointerFn(); + } + get description() { + return this.descriptionFn(); + } + /** + * The current level of the upgrade. + * @returns The current level of the upgrade. + */ + get level() { + return ((this ?? { data: { level: new Decimal(1) } }).data ?? { level: new Decimal(1) }).level; + } + set level(n) { + this.data.level = new Decimal(n); + } + /** + * Constructs a new static upgrade object. + * @param init - The upgrade object to initialize. + * @param dataPointer - A function or reference that returns the pointer of the data / frontend. + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. + */ + constructor(init, dataPointer, cacheSize) { + const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; + this.dataPointerFn = typeof dataPointer === "function" ? dataPointer : () => data; + this.cache = new LRUCache(cacheSize ?? _UpgradeStatic.cacheSize); + this.id = init.id; + this.name = init.name ?? init.id; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; + this.cost = init.cost; + this.costBulk = init.costBulk; + this.maxLevel = init.maxLevel; + this.effect = init.effect; + this.el = init.el; + this.defaultLevel = init.level ?? new Decimal(1); + } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: DecimalSource, end: DecimalSource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: DecimalSource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: DecimalSource, end?: DecimalSource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? new Decimal(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: DecimalSource, end: DecimalSource, cost: DecimalSource): UpgradeCachedSum; + // public setCached(type: "el", level: DecimalSource, cost: DecimalSource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: DecimalSource, endOrStart: DecimalSource, costSum?: DecimalSource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: new Decimal(start), + // end: new Decimal(endOrStart), + // cost: new Decimal(costSum), + // } : { + // id: this.id, + // el: true, + // level: new Decimal(start), + // cost: new Decimal(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } +}; + +// src/classes/Currency.ts +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. + */ + constructor() { + this.value = new Decimal(0); + this.upgrades = {}; + } +}; +__decorateClass([ + (0, import_class_transformer3.Type)(() => Decimal) +], Currency.prototype, "value", 2); +__decorateClass([ + (0, import_class_transformer3.Type)(() => UpgradeData) +], Currency.prototype, "upgrades", 2); +var CurrencyStatic = class { + /** @returns The pointer of the data. */ + get pointer() { + return this.pointerFn(); + } + /** + * The current value of the currency. + * Note: If you want to change the value, use {@link gain} instead. + * @returns The current value of the currency. + */ + get value() { + return this.pointer.value; + } + set value(value) { + this.pointer.value = value; + } + /** + * Constructs a new currnecy + * @param pointer - A function or reference that returns the pointer of the data / frontend. + * @param upgrades - An array of upgrade objects. + * @param defaults - The default value and boost of the currency. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { + * id: "upgId1", + * cost: (level: Decimal): Decimal => level.mul(10), + * }, + * { + * id: "upgId2", + * cost: (level: Decimal): Decimal => level.mul(20), + * } + * ] as const satisfies UpgradeInit[]); + * // CurrencyStatic<["upgId1", "upgId2"]> + */ + constructor(pointer = new Currency(), upgrades, defaults = { defaultVal: new Decimal(0), defaultBoost: new Decimal(1) }) { + this.defaultVal = defaults.defaultVal; + this.defaultBoost = defaults.defaultBoost; + 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; + // } + // }, + }; + if (upgrades) this.addUpgrade(upgrades); + } + /** + * Updates / applies effects to the currency on load. + */ + onLoadData() { + for (const upgrade of Object.values(this.upgrades)) { + upgrade.effect?.(upgrade.level, upgrade, this); + } + } + /** + * Resets the currency and upgrade levels. + * @param resetCurrency - Whether to reset the currency value. Default is true. + * @param resetUpgradeLevels - Whether to reset the upgrade levels. Default is true. + * @param runUpgradeEffect - Whether to run the upgrade effect. Default is true. + * @example + * currency.reset(); + * console.log(currency.value); // new Decimal(0), or the default value + */ + reset(resetCurrency = true, resetUpgradeLevels = true, runUpgradeEffect = true) { + if (resetCurrency) this.value = this.defaultVal; + if (resetUpgradeLevels) { + for (const upgrade of Object.values(this.upgrades)) { + upgrade.level = new Decimal(upgrade.defaultLevel); + if (runUpgradeEffect) upgrade.effect?.(upgrade.level, upgrade, this); + } + } + ; + } + /** + * The new currency value after applying the boost. + * @param dt - Deltatime / multipler in milliseconds, assuming you gain once every second. Ex. 500 = 0.5 seconds = half gain. + * @returns What was gained, NOT the new value. + * @example + * // Gain a random number between 1 and 10, and return the amount gained. + * currency.gain(Math.random() * 10000); + */ + gain(dt = 1e3) { + const toAdd = this.boost.calculate().mul(new Decimal(dt).div(1e3)); + this.pointer.value = this.pointer.value.add(toAdd); + return toAdd; + } + /** + * Adds an upgrade to the data class. + * @param upgrades - Upgrade to add + * @returns The upgrade object. + */ + pointerAddUpgrade(upgrades) { + const upgradesToAdd = new UpgradeData(upgrades); + this.pointer.upgrades[upgradesToAdd.id] = upgradesToAdd; + return upgradesToAdd; + } + /** + * Retrieves an upgrade object from the data pointer based on the provided id. + * @param id - The id of the upgrade to retrieve. + * @returns The upgrade object if found, otherwise null. + */ + pointerGetUpgrade(id) { + return this.pointer.upgrades[id] ?? null; + } + /** + * Retrieves an upgrade object based on the provided id. + * @template T - The type of the upgrade ID. + * @param id - The id of the upgrade to retrieve. + * @returns The upgrade object if found, otherwise null. + * @example + * const upgrade = currency.getUpgrade("healthBoost"); + * console.log(upgrade); // upgrade object + */ + getUpgrade(id) { + return this.upgrades[id] ?? null; + } + /** + * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. + * @param upgrades - An array of upgrade objects. + * @param runEffectInstantly - Whether to run the effect immediately. Defaults to `true`. + * @returns The added upgrades. + * @example + * currency.addUpgrade({ + * id: "healthBoost", // The ID of the upgrade, used to retrieve it later + * name: "Health Boost", // The name of the upgrade, for display purposes (optional, defaults to the ID) + * description: "Increases health by 10.", // The description of the upgrade, for display purposes (optional, defaults to "") + * cost: (level) => level.mul(10), // Cost of the upgrade, 10 times the level + * maxLevel: 10, // Maximum level of the upgrade (optional, defaults to 1) + * // Effect of the upgrade (runs when the upgrade is bought, and instantly if runEffectInstantly is true) + * effect: (level, context) => { + * // Set / update the boost + * // health: currencyStatic + * health.boost.setBoost( + * "healthBoost", + * "Health Boost", + * "Boosts health by 2x per level.", + * n => n.mul(Decimal.pow(2, level.sub(1))), + * 2, + * ); + * } + * }); + */ + addUpgrade(upgrades, runEffectInstantly = true) { + if (!Array.isArray(upgrades)) upgrades = [upgrades]; + const addedUpgradeList = {}; + for (const upgrade of upgrades) { + const addedUpgradeData = 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; + } + return Object.values(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. + * @example + * currency.updateUpgrade("healthBoost", { + * name: "New Health Boost". + * cost: (level) => level.mul(20), + * maxLevel: 20, + * effect: (level, context) => { + * console.log("Health Boost effect"); + * } + * }); + */ + 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; + } + /** + * Calculates the cost and how many upgrades you can buy. + * See {@link calculateUpgrade} for more information. + * @param id - The ID or position of the upgrade to calculate. + * @param target - The target level or quantity to reach for the upgrade. If omitted, it calculates the maximum affordable quantity. + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The amount of upgrades you can buy and the cost of the upgrades. If you can't afford any, it returns [new Decimal(0), new Decimal(0)]. + * @example + * // 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) { + console.warn(`Upgrade "${id}" not found.`); + return [new Decimal(0), new Decimal(0)]; + } + target = upgrade.level.add(target); + if (upgrade.maxLevel !== void 0) { + target = Decimal.min(target, upgrade.maxLevel); + } + return calculateUpgrade(this.value, upgrade, upgrade.level, target, mode, iterations); + } + /** + * Calculates how much is needed for the next upgrade. + * @deprecated Use {@link getNextCostMax} instead as it is more versatile. + * @param id - Index or ID of the upgrade + * @param target - How many before the next upgrade + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The cost of the next upgrade. + * @example + * // Calculate the cost of the next healthBoost upgrade + * const nextCost = currency.getNextCost("healthBoost"); + */ + getNextCost(id, target = 1, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return new Decimal(0); + } + const amount = this.calculateUpgrade(id, target, mode, iterations)[0]; + const nextCost = upgrade.cost(upgrade.level.add(amount)); + return nextCost; + } + /** + * Calculates the cost of the next upgrade after the maximum affordable quantity. + * @param id - Index or ID of the upgrade + * @param target - How many before the next upgrade + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The cost of the next upgrade. + * @example + * // Calculate the cost of the next healthBoost upgrade + * currency.gain(1e6); // Gain 1 thousand currency + * console.log(currency.calculateUpgrade("healthBoost")); // The maximum affordable quantity and the cost of the upgrades. Ex. [new Decimal(100), new Decimal(1000)] + * console.log(currency.getNextCostMax("healthBoost")); // The cost of the next upgrade after the maximum affordable quantity. (The cost of the 101st upgrade) + */ + getNextCostMax(id, target = 1, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return new Decimal(0); + } + const upgCalc = this.calculateUpgrade(id, target, mode, iterations); + const nextCost = upgrade.cost(upgrade.level.add(upgCalc[0])).add(upgCalc[1]); + return nextCost; + } + /** + * Buys an upgrade based on its ID or array position if enough currency is available. + * @param id - The ID or position of the upgrade to buy or upgrade. + * @param target - The target level or quantity to reach for the upgrade. See the argument in {@link calculateUpgrade}. + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns Returns true if the purchase or upgrade is successful, or false if there is not enough currency or the upgrade does not exist. + * @example + * // Attempt to buy up to 10 healthBoost upgrades at once + * currency.buyUpgrade("healthBoost", 10); + */ + buyUpgrade(id, target, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return false; + } + const [amount, cost] = this.calculateUpgrade(id, target, mode, iterations); + if (amount.lte(0)) { + return false; + } + this.pointer.value = this.pointer.value.sub(cost); + upgrade.level = upgrade.level.add(amount); + upgrade.effect?.(upgrade.level, upgrade, this); + return true; + } +}; + +// src/classes/Attribute.ts +var import_reflect_metadata3 = require("reflect-metadata"); +var import_class_transformer4 = require("class-transformer"); +var Attribute = class { + /** + * Constructs a static attribute with an initial effect. + * @param initial - The inital value of the attribute. + */ + constructor(initial = 0) { + this.value = new Decimal(initial); + } +}; +__decorateClass([ + (0, import_class_transformer4.Type)(() => Decimal) +], Attribute.prototype, "value", 2); +var AttributeStatic = class { + /** @returns The data for the attribute. */ + get pointer() { + return this.pointerFn(); + } + /** + * Constructs a new instance of the Attribute class. + * @param pointer - A function or an instance of the attribute class. Defaults to a new instance of the attribute class. + * @param useBoost - Indicates whether to use boost for the attribute. Defaults to true. (hint: if you don't use boost, don't use this class and use Decimal directly) + * @param initial - The initial value of the attribute. Defaults to 0. + */ + constructor(pointer, useBoost = true, initial = 0) { + this.initial = new Decimal(initial); + pointer ??= new Attribute(this.initial); + this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; + this.boost = useBoost ? new Boost(this.initial) : null; + } + /** + * Updates the value of the attribute. + * NOTE: This method must be called every time the boost is updated, else the value stored will not be updated. + * @deprecated This is automatically called when the value is accessed. It will be removed in the future. + */ + update() { + console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."); + if (this.boost) { + this.pointer.value = this.boost.calculate(); + } + } + /** + * Gets the value of the attribute, and also updates the value stored. + * NOTE: This getter must be called every time the boost is updated, else the value stored will not be updated. + * @returns The calculated value of the attribute. + */ + get value() { + if (this.boost) { + this.pointer.value = this.boost.calculate(); + } + return this.pointer.value; + } + /** + * Sets the value of the attribute. + * NOTE: This setter should not be used when boost is enabled. + * @param value - The value to set the attribute to. + */ + set value(value) { + if (this.boost) { + throw new Error("Cannot set value of attributeStatic when boost is enabled."); + } + this.pointer.value = value; + } +}; + +// src/E/eMain.ts +var E = (() => { + let shownWarning = false; + const out = (x) => { + if (!shownWarning) { + console.warn("The E function is deprecated. Use the Decimal class directly."); + shownWarning = true; + } + return new Decimal(x); + }; + Object.getOwnPropertyNames(Decimal).filter((b) => !Object.getOwnPropertyNames(class { + }).includes(b)).forEach((prop) => { + out[prop] = Decimal[prop]; + }); + return out; +})(); + +// src/game/index.ts +var import_reflect_metadata6 = require("reflect-metadata"); + +// src/game/managers/ConfigManager.ts +var ConfigManager = class { + /** + * Constructs a new configuration manager. + * @param configOptionTemplate - The template to use for default values. + */ + constructor(configOptionTemplate) { + this.configOptionTemplate = configOptionTemplate; + } + /** + * Parses the given configuration object and returns a new object with default values for any missing options. + * @param config - The configuration object to parse. + * @returns A new object with default values for any missing options. + */ + parse(config) { + if (typeof config === "undefined") { + return this.configOptionTemplate; + } + function parseObject(obj, template) { + for (const key in template) { + if (typeof obj[key] === "undefined") { + obj[key] = template[key]; + } else if (typeof obj[key] === "object" && typeof template[key] === "object" && !Array.isArray(obj[key]) && !Array.isArray(template[key])) { + obj[key] = parseObject(obj[key], template[key]); + } + } + return obj; + } + return parseObject(config, this.configOptionTemplate); + } + /** + * @returns The template to use for default values. + */ + get options() { + return this.configOptionTemplate; + } +}; + +// src/game/managers/KeyManager.ts +var keyManagerDefaultConfig = { + autoAddInterval: true, + fps: 30 + // pixiApp: undefined, +}; +var keys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]); +var KeyManager = class _KeyManager { + /** + * Creates a new key manager. + * @param config - The configuration for the key manager. + */ + constructor(config) { + /** @deprecated Use {@link addKey} instead. */ + this.addKeys = this.addKey.bind(this); + this.keysPressed = []; + this.binds = []; + this.tickers = []; + this.config = _KeyManager.configManager.parse(config); + if (this.config.autoAddInterval) { + const fps = this.config.fps ? this.config.fps : 30; + this.tickerInterval = setInterval(() => { + for (const ticker of this.tickers) { + ticker(1e3 / fps); + } + }, 1e3 / fps); + } + if (typeof document === "undefined") { + return; + } + this.tickers.push((dt) => { + for (const bind of this.binds) { + if ((typeof bind.onDownContinuous !== "undefined" || typeof bind.fn !== "undefined") && this.isPressing(bind.id)) { + bind.onDownContinuous?.(dt); + bind.fn?.(dt); + } + } + }); + document.addEventListener("keydown", (e) => { + this.logKey(e, true); + this.onAll("down", e.key); + }); + document.addEventListener("keyup", (e) => { + this.logKey(e, false); + this.onAll("up", e.key); + }); + document.addEventListener("keypress", (e) => { + this.onAll("press", e.key); + }); + } + static { + /** The configuration manager for the key manager */ + this.configManager = new ConfigManager(keyManagerDefaultConfig); + } + /** + * Changes the framerate of the key manager. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.config.fps = fps; + if (this.tickerInterval) { + clearInterval(this.tickerInterval); + this.tickerInterval = setInterval(() => { + for (const ticker of this.tickers) { + ticker(1e3 / fps); + } + }, 1e3 / fps); + } + } + /** + * Adds keys to the list of keys pressed. + * @param event - The event to add the key from. + * @param type - Whether to add or remove the key. `true` to add, `false` to remove. + */ + logKey(event, type) { + const key = event.key; + if (type && !this.keysPressed.includes(key)) { + this.keysPressed.push(key); + } else if (!type && this.keysPressed.includes(key)) { + this.keysPressed.splice(this.keysPressed.indexOf(key), 1); + } + } + /** + * Manages onDown, onPress, and onUp events for all key bindings. + * @param eventType - The type of event to call for. + * @param keypress - The key that was pressed. + */ + onAll(eventType, keypress) { + for (const bind of this.binds) { + if (bind.key !== keypress) continue; + switch (eventType) { + case "down": + bind.onDown?.(); + break; + case "press": + default: + bind.onPress?.(); + break; + case "up": + bind.onUp?.(); + break; + } + } + } + /** + * Checks if a specific key binding is currently being pressed. + * @param id - The name of the key binding to check. + * @returns True if the key binding is being pressed, otherwise false. + */ + isPressing(id) { + for (const current of this.binds) { + if (current.id === id) { + return this.keysPressed.includes(current.key); + } + } + return false; + } + /** + * Gets a key binding by its id. + * @param id - The id of the key binding to get. + * @returns The key binding, if found. + */ + getBind(id) { + return this.binds.find((current) => current.id === id); + } + addKey(nameOrKeysToAdd, key, fn) { + nameOrKeysToAdd = typeof nameOrKeysToAdd === "string" ? [{ id: nameOrKeysToAdd, name: nameOrKeysToAdd, key: key ?? "", fn }] : nameOrKeysToAdd; + nameOrKeysToAdd = Array.isArray(nameOrKeysToAdd) ? nameOrKeysToAdd : [nameOrKeysToAdd]; + for (const keyBinding of nameOrKeysToAdd) { + keyBinding.id = keyBinding.id ?? keyBinding.name; + const existing = this.getBind(keyBinding.id); + if (existing) { + Object.assign(existing, keyBinding); + continue; + } + this.binds.push(keyBinding); + } + } +}; + +// src/game/managers/EventManager.ts +var eventManagerDefaultConfig = { + autoAddInterval: true, + fps: 30 + // pixiApp: undefined, +}; +var EventManager = class _EventManager { + /** + * Creates a new event manager. + * @param config - The config to use for this event manager. + */ + constructor(config) { + /** + * Adds a new event + * @deprecated Use {@link EventManager.setEvent} instead. + * @alias eventManager.setEvent + */ + this.addEvent = this.setEvent.bind(this); + this.config = _EventManager.configManager.parse(config); + this.events = {}; + if (this.config.autoAddInterval) { + const fps = this.config.fps ?? 30; + this.tickerInterval = setInterval(() => { + this.tickerFunction(); + }, 1e3 / fps); + } + } + static { + /** The static config manager for the event manager */ + this.configManager = new ConfigManager(eventManagerDefaultConfig); + } + /** + * The function that is called every frame, executes all events. + */ + tickerFunction() { + const currentTime = Date.now(); + for (const event of Object.values(this.events)) { + switch (event.type) { + case "interval" /* interval */: + { + if (currentTime - event.intervalLast >= event.delay) { + const dt = currentTime - event.intervalLast; + event.callbackFn(dt); + event.intervalLast = currentTime; + } + } + ; + break; + case "timeout" /* timeout */: + { + const dt = currentTime - event.timeCreated; + if (currentTime - event.timeCreated >= event.delay) { + event.callbackFn(dt); + delete this.events[event.name]; + } + } + ; + break; + } + } + } + /** + * Changes the framerate of the event manager. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.config.fps = fps; + if (this.tickerInterval) { + clearInterval(this.tickerInterval); + this.tickerInterval = setInterval(() => { + this.tickerFunction(); + }, 1e3 / fps); + } + } + /** + * Warps time by a certain amount. Note: This will affect the stored creation time of timeout events. + * @param dt - The time to warp by. + */ + timeWarp(dt) { + for (const event of Object.values(this.events)) { + switch (event.type) { + case "interval" /* interval */: + { + event.intervalLast -= dt; + } + ; + break; + case "timeout" /* timeout */: + { + event.timeCreated -= dt; + } + ; + break; + } + } + } + /** + * Adds a new event or changes an existing event to the event system. + * @param name - The name of the event. If an event with this name already exists, it will be overwritten. + * @param type - The type of the event, either "interval" or "timeout". + * @param delay - The delay in milliseconds before the event triggers. (NOTE: If delay is less than the framerate, it will at trigger at max, once every frame.) + * @param callbackFn - The callback function to execute when the event triggers. + * @example + * const myEventManger = new eventManager(); + * // Add an interval event that executes every 2 seconds. + * myEventManger.addEvent("IntervalEvent", "interval", 2000, () => { + * console.log("Interval event executed."); + * }); + * + * // Add a timeout event that executes after 5 seconds. + * myEventManger.addEvent("TimeoutEvent", "timeout", 5000, () => { + * console.log("Timeout event executed."); + * }); + */ + setEvent(name, type, delay, callbackFn) { + this.events[name] = (() => { + switch (type) { + case "interval": + { + const event = { + name, + type, + delay: typeof delay === "number" ? delay : delay.toNumber(), + callbackFn, + timeCreated: Date.now(), + intervalLast: Date.now() + }; + return event; + } + ; + break; + case "timeout": + default: { + const event = { + name, + type, + delay: typeof delay === "number" ? delay : delay.toNumber(), + callbackFn, + timeCreated: Date.now() + }; + return event; + } + } + })(); + } + /** + * Removes an event from the event system. + * @param name - The name of the event to remove. + * @example + * myEventManger.removeEvent("IntervalEvent"); // Removes the interval event with the name "IntervalEvent". + */ + removeEvent(name) { + delete this.events[name]; + } +}; + +// src/game/managers/DataManager.ts +var import_reflect_metadata5 = require("reflect-metadata"); +var import_class_transformer5 = require("class-transformer"); +var import_lz_string = __toESM(require_lz_string()); +var import_md5 = __toESM(require_md5()); +var DataManager = class { + /** + * Creates a new instance of the game class. + * @param gameRef - A function that returns the game instance. + */ + constructor(gameRef) { + /** The current game data. */ + this.data = {}; + /** The static game data. */ + this.static = {}; + /** A queue of functions to call when the game data is loaded. */ + this.eventsOnLoad = []; + this.gameRef = typeof gameRef === "function" ? gameRef() : gameRef; + } + /** + * Adds an event to call when the game data is loaded. + * @param event - The event to call when the game data is loaded. + * @example dataManager.addEventOnLoad(() => console.log("Data loaded!")); + */ + addEventOnLoad(event) { + this.eventsOnLoad.push(event); + } + /** + * Sets the data for the given key. + * The getter is a work in progress. + * @template S - The key to set the data for. + * @template T - The value to set the data to. + * @param key - The key to set the data for. + * @param value - The value to set the data to. + * @returns An object with a single entry of the name of the key and the value of the data. This is a getter and setter. + * @example + * // ! WARNING: Do not destruct the `value` property, as it will remove the getter and setter. + * const testData = dataManager.setData("test", 5); + * console.log(testData.value); // 5 + * testData.value = 10; // Also sets the data + * console.log(testData.value); // 10 + */ + setData(key, value) { + if (typeof this.data[key] === "undefined" && this.normalData) { + console.warn("After initializing data, you should not add new properties to data."); + } + this.data[key] = value; + const thisData = () => this.data; + return { + get value() { + return thisData()[key]; + }, + set value(valueToSet) { + thisData()[key] = valueToSet; + }, + setValue(valueToSet) { + thisData()[key] = valueToSet; + } + }; + } + /** + * Gets the data for the given key. + * @deprecated Set the return value of {@link setData} to a variable instead, as that is a getter and provides type checking. + * @param key - The key to get the data for. + * @returns The data for the given key. + */ + getData(key) { + return this.data[key]; + } + /** + * Sets the static data for the given key. + * This data is not affected by data loading and saving, and is mainly used internally. + * @param key - The key to set the static data for. + * @param value - The value to set the static data to. + * @returns A getter for the static data. + */ + setStatic(key, value) { + if (typeof this.static[key] === "undefined" && this.normalData) { + console.warn("After initializing data, you should not add new properties to staticData."); + } + this.static[key] = value; + return this.static[key]; + } + /** + * Gets the static data for the given key. + * @deprecated Set the return value of {@link setStatic} to a variable instead, as that is a getter and provides type checking. + * @param key - The key to get the static data for. + * @returns The static data for the given key. + */ + getStatic(key) { + return this.static[key]; + } + /** + * Initializes / sets data that is unmodified by the player. + * This is used to merge the loaded data with the default data. + * It should be called before you load data. + * Note: This should only be called once, and after it is called, you should not add new properties to data. + * @example dataManager.init(); // Call this after setting the initial data. + */ + init() { + this.normalData = this.data; + this.normalDataPlain = (0, import_class_transformer5.instanceToPlain)(this.data); + } + /** + * Compiles the given game data to a tuple containing the compressed game data and a hash. + * @param data The game data to be compressed. Defaults to the current game data. + * @returns [hash, data] - The compressed game data and a hash as a base64-encoded string to use for saving. + */ + compileDataRaw(data = this.data) { + const gameDataString = (0, import_class_transformer5.instanceToPlain)(data); + const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); + let version; + try { + version = "9.0.0"; + } catch (error) { + version = "8.3.0"; + } + const saveMetadata = { + hash: hasedData, + game: { + title: this.gameRef.config.name.title, + id: this.gameRef.config.name.id, + version: this.gameRef.config.name.version + }, + emath: { + version + } + }; + return [saveMetadata, gameDataString]; + } + /** + * Compresses the given game data to a base64-encoded using lz-string. + * @param data The game data to be compressed. Defaults to the current game data. + * @returns The compressed game data and a hash as a base64-encoded string to use for saving. + */ + compileData(data = this.data) { + const dataRawString = JSON.stringify(this.compileDataRaw(data)); + return (0, import_lz_string.compressToBase64)(dataRawString); + } + /** + * Decompiles the data stored in localStorage and returns the corresponding object. + * @param data - The data to decompile. If not provided, it will be fetched from localStorage using the key `${game.config.name.id}-data`. + * @returns The decompiled object, or null if the data is empty or invalid. + */ + decompileData(data = window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)) { + if (!data) return null; + let parsedData; + try { + parsedData = JSON.parse((0, import_lz_string.decompressFromBase64)(data)); + return parsedData; + } catch (error) { + if (error instanceof SyntaxError) { + console.error(`Failed to decompile data (corrupted) "${data}":`, error); + } else { + throw error; + } + return null; + } + } + /** + * Validates the given data using a hashing algorithm (md5) + * @param data - [hash, data] The data to validate. + * @returns Whether the data is valid / unchanged. False means that the data has been tampered with / save edited. + */ + validateData(data) { + const [saveMetadata, gameDataToValidate] = data; + if (typeof saveMetadata === "string") { + return (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataToValidate)}`) === saveMetadata; + } + const hashSave = saveMetadata.hash; + const hashCheck = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataToValidate)}`); + return hashSave === hashCheck; + } + /** + * Resets the game data to its initial state and saves it. + * @param reload - Whether to reload the page after resetting the data. Defaults to `false`. + */ + resetData(reload = false) { + if (!this.normalData) throw new Error("dataManager.resetData(): You must call init() before writing to data."); + this.data = this.normalData; + this.saveData(); + if (reload) window.location.reload(); + } + /** + * Saves the game data to local storage under the key `${game.config.name.id}-data`. + * If you dont want to save to local storage, use {@link compileData} instead. + * @param dataToSave - The data to save. If not provided, it will be fetched from localStorage using {@link compileData}. + */ + saveData(dataToSave = this.compileData()) { + if (!dataToSave) 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`, dataToSave); + } + /** + * Compiles the game data and prompts the user to download it as a text file using {@link window.prompt}. + * If you want to implement a custom data export, use {@link compileData} instead. + */ + exportData() { + const content = this.compileData(); + if (prompt("Download save data?:", content) != null) { + const blob = new Blob([content], { type: "text/plain" }); + const downloadLink = document.createElement("a"); + downloadLink.href = URL.createObjectURL(blob); + downloadLink.download = `${this.gameRef.config.name.id}-data.txt`; + downloadLink.textContent = `Download ${this.gameRef.config.name.id}-data.txt file`; + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); + } + } + /** + * Loads game data and processes it. + * @param dataToParse - The data to load. If not provided, it will be fetched from localStorage using {@link decompileData}. + * @param mergeData - Whether to merge the loaded data with the normal data. Defaults to `true`. + * Warning: If set to `false`, the loaded data may have missing properties and may cause errors. + * @returns The loaded data. + */ + parseData(dataToParse = this.decompileData(), mergeData = true) { + if ((!this.normalData || !this.normalDataPlain) && mergeData) throw new Error("dataManager.parseData(): You must call init() before writing to data."); + if (!dataToParse) return null; + const [, loadedData] = dataToParse; + function isPlainObject(obj) { + return typeof obj === "object" && obj?.constructor === Object; + } + const objectHasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key); + function deepMerge(sourcePlain, source, target) { + if (!sourcePlain || !source || !target) throw new Error("dataManager.deepMerge(): Missing arguments."); + const out = target; + for (const key in sourcePlain) { + if (objectHasOwnProperty(sourcePlain, key) && !objectHasOwnProperty(target, key)) { + out[key] = sourcePlain[key]; + } + if (source[key] instanceof Currency) { + const sourceCurrency = sourcePlain[key]; + const targetCurrency = target[key]; + if (Array.isArray(targetCurrency.upgrades)) { + const upgrades = targetCurrency.upgrades; + targetCurrency.upgrades = {}; + for (const upgrade of upgrades) { + targetCurrency.upgrades[upgrade.id] = upgrade; + } + } + targetCurrency.upgrades = { ...sourceCurrency.upgrades, ...targetCurrency.upgrades }; + out[key] = targetCurrency; + } else if (isPlainObject(sourcePlain[key]) && isPlainObject(target[key])) { + out[key] = deepMerge(sourcePlain[key], source[key], target[key]); + } + } + return out; + } + let loadedDataProcessed = !mergeData ? loadedData : deepMerge(this.normalDataPlain, this.normalData, loadedData); + const upgradeDataProperties = Object.getOwnPropertyNames(new UpgradeData({ id: "", level: new Decimal(0) })); + function convertTemplateClass(templateClassToConvert, plain) { + const out = (0, import_class_transformer5.plainToInstance)(templateClassToConvert, plain); + if (out instanceof Currency) { + for (const upgradeName in out.upgrades) { + const upgrade = out.upgrades[upgradeName]; + if (!upgrade || !upgradeDataProperties.every((prop) => Object.getOwnPropertyNames(upgrade).includes(prop))) { + delete out.upgrades[upgradeName]; + continue; + } + out.upgrades[upgradeName] = (0, import_class_transformer5.plainToInstance)(UpgradeData, upgrade); + } + } + if (!out) throw new Error(`Failed to convert ${templateClassToConvert.name} to class instance.`); + return out; + } + function plainToInstanceRecursive(normal, plain) { + if (!normal || !plain) throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments."); + const out = plain; + for (const key in normal) { + if (plain[key] === void 0) { + console.warn(`Missing property "${key}" in loaded data.`); + continue; + } + if (!isPlainObject(plain[key])) continue; + const normalDataClass = normal[key].constructor; + if (normalDataClass === Object) { + out[key] = plainToInstanceRecursive(normal[key], plain[key]); + continue; + } + out[key] = convertTemplateClass(normalDataClass, plain[key]); + } + return out; + } + loadedDataProcessed = plainToInstanceRecursive(this.normalData, loadedDataProcessed); + return loadedDataProcessed; + } + /** + * Loads game data and processes it. + * @param dataToLoad - The data to load. If not provided, it will be fetched from localStorage using {@link decompileData}. + * @returns Returns null if the data is empty or invalid, or false if the data is tampered with. Otherwise, returns true. + */ + loadData(dataToLoad = this.decompileData()) { + dataToLoad = typeof dataToLoad === "string" ? this.decompileData(dataToLoad) : dataToLoad; + if (!dataToLoad) return null; + const isDataValid = this.validateData([dataToLoad[0], (0, import_class_transformer5.instanceToPlain)(dataToLoad[1])]); + const parsedData = this.parseData(dataToLoad); + if (!parsedData) return null; + this.data = parsedData; + for (const obj of this.eventsOnLoad) { + obj(); + } + return isDataValid; + } +}; + +// src/game/GameCurrency.ts +var GameCurrency = class { + /** @returns The data for the currency. */ + get data() { + return this.dataPointer(); + } + /** @returns The static data for the currency. */ + get static() { + return this.staticPointer(); + } + /** + * Creates a new instance of the game class. + * @param currencyPointer - A function that returns the current currency value. + * @param staticPointer - A function that returns the static data for the game. + * @param gamePointer A pointer to the game instance. + * @param name - The name of the currency. This is optional, and you can use it for display purposes. + */ + constructor(currencyPointer, staticPointer, gamePointer, name) { + this.dataPointer = typeof currencyPointer === "function" ? currencyPointer : () => currencyPointer; + this.staticPointer = typeof staticPointer === "function" ? staticPointer : () => staticPointer; + this.game = gamePointer; + this.name = name; + this.game.dataManager.addEventOnLoad(() => { + this.static.onLoadData(); + }); + } + /** + * Gets the value of the game currency. + * Note: There is no setter for this property. To change the value of the currency, use the corresponding methods in the static class. + * @returns The value of the game currency. + */ + get value() { + return this.data.value; + } +}; + +// src/game/GameAttribute.ts +var GameAttribute = class { + /** + * Creates a new instance of the attribute class. + * @param attributePointer - A function that returns the current attribute value. + * @param staticPointer - A function that returns the static data for the attribute. + * @param gamePointer A pointer to the game instance. + */ + constructor(attributePointer, staticPointer, gamePointer) { + this.data = typeof attributePointer === "function" ? attributePointer() : attributePointer; + this.static = typeof staticPointer === "function" ? staticPointer() : staticPointer; + this.game = gamePointer; + } + /** + * Gets the value of the attribute. + * NOTE: This getter is sometimes inaccurate. + * @returns The value of the attribute. + */ + get value() { + return this.static.value; + } + /** + * Sets the value of the attribute. + * NOTE: This setter should not be used when boost is enabled. + * @param value - The value to set the attribute to. + */ + set value(value) { + this.data.value = value; + } +}; + +// src/game/ResetLayer.ts +var GameReset = class { + /** + * Creates a new instance of the game reset. + * @param currenciesToReset The currencies to reset. + * @param extender The extender for the game reset. WARNING: Do not set this to the same object, as it will cause an infinite loop. + */ + constructor(currenciesToReset, extender) { + this.currenciesToReset = Array.isArray(currenciesToReset) ? currenciesToReset : [currenciesToReset]; + this.extender = Array.isArray(extender) ? extender : extender ? [extender] : []; + this.id = Symbol(); + } + /** + * Resets a currency to its default value, and runs the extender's reset function if it exists (recursively). + */ + reset() { + this.onReset?.(this); + this.currenciesToReset.forEach((currency) => { + currency.static.reset(); + }); + this.extender.forEach((extender) => { + if (extender.id !== this.id) { + extender.reset(); + } + }); + } +}; + +// src/game/Game.ts +var gameDefaultConfig = { + mode: "production", + name: { + title: "", + id: "", + version: "0.0.0" + }, + settings: { + framerate: 30 + }, + initIntervalBasedManagers: true +}; +var Game = class _Game { + static { + /** The static config manager for the game. */ + this.configManager = new ConfigManager(gameDefaultConfig); + } + /** + * Creates a new instance of the game class. + * @param config - The configuration object for the game. + * @example + * const myGame = new game({ + * name: { + * title: "My Game", + * id: "my-game", + * }, + * // Additional options here + * }); + */ + constructor(config) { + this.config = _Game.configManager.parse(config); + this.dataManager = new DataManager(this); + this.keyManager = new KeyManager({ + autoAddInterval: this.config.initIntervalBasedManagers, + fps: this.config.settings.framerate + }); + this.eventManager = new EventManager({ + autoAddInterval: this.config.initIntervalBasedManagers, + fps: this.config.settings.framerate + }); + this.tickers = []; + } + /** + * Initializes the game. Also initializes the data manager. + * See {@link DataManager.init} for more information. + */ + init() { + this.dataManager.init(); + } + /** + * Changes the framerate of the game. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.keyManager.changeFps(fps); + this.eventManager.changeFps(fps); + } + /** + * Adds a new currency section to the game. {@link GameCurrency} is the class. + * It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading. + * @template N - The name + * @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information. + * @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique. + * @param upgrades - The upgrades for the currency. + * @returns A new instance of the gameCurrency class. + * @example + * const currency = game.addCurrency("currency"); + * currency.static.gain(); + * console.log(currency.value); // new Decimal(1) + */ + addCurrency(name, upgrades = []) { + this.dataManager.setData(name, { + currency: new Currency() + }); + this.dataManager.setStatic(name, { + currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades) + }); + const classInstance = new GameCurrency( + () => this.dataManager.getData(name).currency, + () => this.dataManager.getStatic(name).currency, + this, + name + ); + return classInstance; + } + /** + * Adds a new attribute to the game. {@link GameAttribute} is the class. + * It automatically adds the attribute and attributeStatic objects to the data and static objects for saving and loading. + * @param name - The name of the attribute. + * @param useBoost - Indicates whether to use boost for the attribute. + * @param initial - The initial value of the attribute. + * @returns The newly created attribute. + * @example + * const myAttribute = game.addAttribute("myAttribute"); + */ + addAttribute(name, useBoost = true, initial = 0) { + this.dataManager.setData(name, new Attribute(initial)); + this.dataManager.setStatic(name, new AttributeStatic(this.dataManager.getData(name), useBoost, initial)); + const classInstance = new GameAttribute(this.dataManager.getData(name), this.dataManager.getStatic(name), this); + return classInstance; + } + /** + * Creates a new game reset object with the specified currencies to reset. + * @param currenciesToReset - The currencies to reset. + * @param extender - An optional object to extend the game reset object with. + * @returns The newly created game reset object. + */ + addReset(currenciesToReset, extender) { + const reset = new GameReset(currenciesToReset, extender); + return reset; + } +}; + // src/presets/GameFormats.ts function gameFormat(value, settings) { settings = Object.assign({ @@ -4968,6 +7315,16 @@ var formatTimeOptions = [ value: "long" } ].sort((a, b) => a.name.localeCompare(b.name)); +/*! Bundled license information: + +is-buffer/index.js: + (*! + * Determine if an object is a Buffer + * + * @author Feross Aboukhadijeh + * @license MIT + *) +*/ if (typeof module.exports == "object" && typeof exports == "object") { var __cp = (to, from, except, desc) => { if ((from && typeof from === "object") || typeof from === "function") { diff --git a/dist/presets/eMath.presets.min.js b/dist/presets/eMath.presets.min.js index cee7c172..b315105f 100644 --- a/dist/presets/eMath.presets.min.js +++ b/dist/presets/eMath.presets.min.js @@ -1 +1,27 @@ -"use strict";(function(j,V){var k=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],V);else if(typeof module=="object"&&module.exports)module.exports=V();else{var H=V(),K=k?exports:j;for(var X in H)K[X]=H[X]}})(typeof self<"u"?self:exports,()=>{var j={},V={exports:j},k=Object.defineProperty,H=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyNames,X=Object.prototype.hasOwnProperty,rt=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:!0})},ht=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of K(e))!X.call(t,a)&&a!==r&&k(t,a,{get:()=>e[a],enumerable:!(i=H(e,a))||i.enumerable});return t},mt=t=>ht(k({},"__esModule",{value:!0}),t),W=(t,e,r,i)=>{for(var a=i>1?void 0:i?H(e,r):e,o=t.length-1,m;o>=0;o--)(m=t[o])&&(a=(i?m(e,r,a):m(a))||a);return i&&a&&k(e,r,a),a},it={};rt(it,{emathPresets:()=>st}),V.exports=mt(it);var st={};rt(st,{GameFormatClass:()=>qt,formatOptions:()=>Ct,formatTimeOptions:()=>At,gameFormat:()=>Q,gameFormatGain:()=>lt});var L;(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"})(L||(L={}));var ft=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(a){return!a.options||a.options.toClassOnly===!0&&a.options.toPlainOnly===!0?!0:a.options.toClassOnly===!0?i===L.CLASS_TO_CLASS||i===L.PLAIN_TO_CLASS:a.options.toPlainOnly===!0?i===L.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),a=this._exposeMetadatas.get(e),o=a&&a.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===L.CLASS_TO_CLASS||r===L.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===L.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===L.CLASS_TO_CLASS||r===L.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===L.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),a;i&&(a=Array.from(i.values()).filter(function(I){return I.propertyName!==void 0}));for(var o=[],m=0,N=this.getAncestors(r);mthis.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},Nt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},R=[[["","U","D","T","Qa","Qt","Sx","Sp","Oc","No"],["","Dc","Vg","Tg","Qag","Qtg","Sxg","Spg","Ocg","Nog"],["","Ce","De","Te","Qae","Qte","Sxe","Spe","Oce","Noe"]],[["","Mi","Mc","Na","Pc","Fm","At","Zp","Yc","Xn"],["","Me","Du","Tr","Te","Pe","He","Hp","Ot","En"],["","c","Ic","TCn","TeC","PCn","HCn","HpC","OCn","ECn"],["","Hc","DHe","THt","TeH","PHc","HHe","HpH","OHt","EHc"]]];function pt(t){let e={omega:{config:{greek:"\u03B2\u03B6\u03BB\u03C8\u03A3\u0398\u03A8\u03C9",infinity:"\u03A9"},format(n){n=new t(n);let h=t.floor(n.div(1e3)),l=t.floor(h.div(e.omega.config.greek.length)),p=e.omega.config.greek[h.toNumber()%e.omega.config.greek.length]+o(n.toNumber()%1e3);(e.omega.config.greek[h.toNumber()%e.omega.config.greek.length]===void 0||h.toNumber()>Number.MAX_SAFE_INTEGER)&&(p="\u03C9");let y=t.log(n,8e3).toNumber();if(l.equals(0))return p;if(l.gt(0)&&l.lte(3)){let v=[];for(let C=0;CNumber.MAX_SAFE_INTEGER)&&(p="\u03C9");let y=t.log(n,8e3).toNumber();if(l.equals(0))return p;if(l.gt(0)&&l.lte(2)){let v=[];for(let C=0;C118?e.elemental.beyondOg(b):e.elemental.config.element_lists[n-1][p]},beyondOg(n){let h=Math.floor(Math.log10(n)),l=["n","u","b","t","q","p","h","s","o","e"],p="";for(let b=h;b>=0;b--){let y=Math.floor(n/Math.pow(10,b))%10;p==""?p=l[y].toUpperCase():p+=l[y]}return p},abbreviationLength(n){return n==1?1:Math.pow(Math.floor(n/2)+1,2)*2},getAbbreviationAndValue(n){let h=n.log(118).toNumber(),l=Math.floor(h)+1,p=e.elemental.abbreviationLength(l),b=h-l+1,y=Math.floor(b*p),M=e.elemental.getAbbreviation(l,b),T=new t(118).pow(l+y/p-1);return[M,T]},formatElementalPart(n,h){return h.eq(1)?n:`${h} ${n}`},format(n,h=2){if(n.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(n.log10(),h);let l=n.log(118),b=l.log(118).log(118).toNumber(),y=Math.max(4-b*2,1),M=[];for(;l.gte(1)&&M.length=y)return M.map(v=>e.elemental.formatElementalPart(v[0],v[1])).join(" + ");let T=new t(118).pow(l).toFixed(M.length===1?3:h);return M.length===0?T:M.length===1?`${T} \xD7 ${e.elemental.formatElementalPart(M[0][0],M[0][1])}`:`${T} \xD7 (${M.map(v=>e.elemental.formatElementalPart(v[0],v[1])).join(" + ")})`}},old_sc:{format(n,h){n=new t(n);let l=n.log10().floor();if(l.lt(9))return l.lt(3)?n.toFixed(h):n.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(n.gte("eeee10")){let b=n.slog();return(b.gte(1e9)?"":new t(10).pow(b.sub(b.floor())).toFixed(4))+"F"+e.old_sc.format(b.floor(),0)}let p=n.div(new t(10).pow(l));return(l.log10().gte(9)?"":p.toFixed(4))+"e"+e.old_sc.format(l,0)}}},eng:{format(n,h=2){n=new t(n);let l=n.log10().floor();if(l.lt(9))return l.lt(3)?n.toFixed(h):n.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(n.gte("eeee10")){let b=n.slog();return(b.gte(1e9)?"":new t(10).pow(b.sub(b.floor())).toFixed(4))+"F"+e.eng.format(b.floor(),0)}let p=n.div(new t(1e3).pow(l.div(3).floor()));return(l.log10().gte(9)?"":p.toFixed(new t(4).sub(l.sub(l.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(l.div(3).floor().mul(3),0)}}},mixed_sc:{format(n,h,l=9){n=new t(n);let p=n.log10().floor();return p.lt(303)&&p.gte(l)?g(n,h,l,"st"):g(n,h,l,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(n,h=2,l){n=new t(n);let p=n.max(1).log10().max(1).log(r.log10()).floor();if(p.lte(0))return g(n,h,l,"sc");n=new t(10).pow(n.max(1).log10().div(r.log10().pow(p)).sub(p.gte(1)?1:0));let b=p.div(10).floor(),y=p.toNumber()%10-1;return g(n,Math.max(4,h),l,"sc")+" "+(b.gte(1)?"meta"+(b.gte(2)?"^"+g(b,0,l,"sc"):"")+"-":"")+(isNaN(y)?"nanity":e.layer.layers[y])}},standard:{tier1(n){return R[0][0][n%10]+R[0][1][Math.floor(n/10)%10]+R[0][2][Math.floor(n/100)]},tier2(n){let h=n%10,l=Math.floor(n/10)%10,p=Math.floor(n/100)%10,b="";return n<10?R[1][0][n]:(l==1&&h==0?b+="Vec":b+=R[1][1][h]+R[1][2][l],b+=R[1][3][p],b)}},inf:{format(n,h,l){n=new t(n);let p=0,b=new t(Number.MAX_VALUE),y=["","\u221E","\u03A9","\u03A8","\u028A"],M=["","","m","mm","mmm"];for(;n.gte(b);)n=n.log(b),p++;return p==0?g(n,h,l,"sc"):n.gte(3)?M[p]+y[p]+"\u03C9^"+g(n.sub(1),h,l,"sc"):n.gte(2)?M[p]+"\u03C9"+y[p]+"-"+g(b.pow(n.sub(2)),h,l,"sc"):M[p]+y[p]+"-"+g(b.pow(n.sub(1)),h,l,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(n,h=new t(1e15),l=!1,p=9){if(n=new t(n),h=new t(h).div(1e3),n.lt(h.mul(1e3)))return"";let{alphabet:b}=e.alphabet.config,y=b.length,M=n.log(1e3).sub(h.log(1e3)).floor(),T=M.add(1).log(y+1).ceil(),v="",C=(P,Y)=>{let x=P,B="";for(let G=0;G=y)return"\u03C9";B=b[U]+B,x=x.sub(1).div(y).floor()}return B};if(T.lt(p))v=C(M,T);else{let P=T.sub(p).add(1),Y=M.div(t.pow(y+1,P.sub(1))).floor();v=`${C(Y,new t(p))}(${P.gt("1e9")?P.format():P.format(0)})`}return v},format(n,h=2,l=9,p="mixed_sc",b=new t(1e15),y=!1,M){if(n=new t(n),b=new t(b).div(1e3),n.lt(b.mul(1e3)))return g(n,h,l,p);let T=e.alphabet.getAbbreviation(n,b,y,M),v=n.div(t.pow(1e3,n.log(1e3).floor()));return`${T.length>(M??9)+2?"":v.toFixed(h)+" "}${T}`}}},r=new t(2).pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",a="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(n){return n.toFixed(0).split("").map(h=>h==="-"?"\u208B":i[parseInt(h,10)]).join("")}function m(n){return n.toFixed(0).split("").map(h=>h==="-"?"\u208B":a[parseInt(h,10)]).join("")}function N(n,h=2,l=9,p="st"){return g(n,h,l,p)}function g(n,h=2,l=9,p="mixed_sc"){n=new t(n);let b=n.lt(0)?"-":"";if(n.mag==1/0)return b+"Infinity";if(Number.isNaN(n.mag))return b+"NaN";if(n.lt(0)&&(n=n.mul(-1)),n.eq(0))return n.toFixed(h);let y=n.log10().floor();switch(p){case"sc":case"scientific":if(n.log10().lt(Math.min(-h,0))&&h>1){let M=n.log10().ceil(),T=n.div(M.eq(-1)?new t(.1):new t(10).pow(M)),v=M.mul(-1).max(1).log10().gte(9);return b+(v?"":T.toFixed(2))+"e"+g(M,0,l,"mixed_sc")}else if(y.lt(l)){let M=Math.max(Math.min(h-y.toNumber(),h),0);return b+(M>0?n.toFixed(M):n.toFixed(M).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(n.gte("eeee10")){let v=n.slog();return(v.gte(1e9)?"":new t(10).pow(v.sub(v.floor())).toFixed(2))+"F"+g(v.floor(),0)}let M=n.div(new t(10).pow(y)),T=y.log10().gte(9);return b+(T?"":M.toFixed(2))+"e"+g(y,0,l,"mixed_sc")}case"st":case"standard":{let M=n.log(1e3).floor();if(M.lt(1))return b+n.toFixed(Math.max(Math.min(h-y.toNumber(),h),0));let T=M.mul(3),v=M.log10().floor();if(v.gte(3e3))return"e"+g(y,h,l,"st");let C="";if(M.lt(4))C=["","K","M","B"][Math.round(M.toNumber())];else{let x=Math.floor(M.log(1e3).toNumber());for(x<100&&(x=Math.max(x-1,0)),M=M.sub(1).div(new t(10).pow(x*3));M.gt(0);){let B=M.div(1e3).floor(),G=M.sub(B.mul(1e3)).floor().toNumber();G>0&&(G==1&&!x&&(C="U"),x&&(C=e.standard.tier2(x)+(C?"-"+C:"")),G>1&&(C=e.standard.tier1(G)+C)),M=B,x++}}let P=n.div(new t(10).pow(T)),Y=h===2?new t(2).sub(y.sub(T)).add(1).toNumber():h;return b+(v.gte(10)?"":P.toFixed(Y)+" ")+C}default:return e[p]||console.error('Invalid format type "',p,'"'),b+e[p].format(n,h,l)}}function c(n,h,l="mixed_sc",p,b){n=new t(n),h=new t(h);let y=n.add(h),M,T=y.div(n);return T.gte(10)&&n.gte(1e100)?(T=T.log10().mul(20),M="(+"+g(T,p,b,l)+" OoMs/sec)"):M="(+"+g(h,p,b,l)+"/sec)",M}function _(n,h=2,l="s"){return n=new t(n),n.gte(86400)?g(n.div(86400).floor(),0,12,"sc")+":"+_(n.mod(86400),h,"d"):n.gte(3600)||l=="d"?(n.div(3600).gte(10)||l!="d"?"":"0")+g(n.div(3600).floor(),0,12,"sc")+":"+_(n.mod(3600),h,"h"):n.gte(60)||l=="h"?(n.div(60).gte(10)||l!="h"?"":"0")+g(n.div(60).floor(),0,12,"sc")+":"+_(n.mod(60),h,"m"):(n.gte(10)||l!="m"?"":"0")+g(n,h,12,"sc")}function I(n,h=!1,l=0,p=9,b="mixed_sc"){let y=Vt=>g(Vt,l,p,b);n=new t(n);let M=n.mul(1e3).mod(1e3).floor(),T=n.mod(60).floor(),v=n.div(60).mod(60).floor(),C=n.div(3600).mod(24).floor(),P=n.div(86400).mod(365.2425).floor(),Y=n.div(31556952).floor(),x=Y.eq(1)?" year":" years",B=P.eq(1)?" day":" days",G=C.eq(1)?" hour":" hours",U=v.eq(1)?" minute":" minutes",xt=T.eq(1)?" second":" seconds",Lt=M.eq(1)?" millisecond":" milliseconds";return`${Y.gt(0)?y(Y)+x+", ":""}${P.gt(0)?y(P)+B+", ":""}${C.gt(0)?y(C)+G+", ":""}${v.gt(0)?y(v)+U+", ":""}${T.gt(0)?y(T)+xt+",":""}${h&&M.gt(0)?" "+y(M)+Lt:""}`.replace(/,([^,]*)$/,"$1").trim()}function q(n){return n=new t(n),g(new t(1).sub(n).mul(100))+"%"}function F(n){return n=new t(n),g(n.mul(100))+"%"}function O(n,h=2){return n=new t(n),n.gte(1)?"\xD7"+n.format(h):"/"+n.pow(-1).format(h)}function d(n,h,l=10){return t.gte(n,10)?t.pow(l,t.log(n,l).pow(h)):new t(n)}function S(n,h=0){n=new t(n);let l=(M=>M.map((T,v)=>({name:T.name,altName:T.altName,value:t.pow(1e3,new t(v).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),p="",b=n.lte(0)?0:t.min(t.log(n,1e3).sub(1),l.length-1).floor().toNumber(),y=l[b];if(b===0)switch(h){case 1:p="";break;case 2:case 0:default:p=n.format();break}switch(h){case 1:p=y.name;break;case 2:p=n.divide(y.value).format();break;case 3:p=y.altName;break;case 0:default:p=`${n.divide(y.value).format()} ${y.name}`;break}return p}function E(n,h=!1){return`${S(n,2)} ${S(n,1)}eV${h?"/c^2":""}`}let A={...e,toSubscript:o,toSuperscript:m,formatST:N,format:g,formatGain:c,formatTime:_,formatTimeLong:I,formatReduction:q,formatPercent:F,formatMult:O,expMult:d,metric:S,ev:E};return{FORMATS:e,formats:A}}var D=17,dt=9e15,bt=Math.log10(9e15),Mt=1/9e15,wt=308,yt=-324,at=5,_t=1023,It=!0,St=!1,Ft=function(){let t=[];for(let r=yt+1;r<=wt;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),Z=[2,Math.E,3,4,5,6,7,8,9,10],vt=[[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]],Tt=[[-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]],u=function(e){return s.fromValue_noAlloc(e)},w=function(t,e,r){return s.fromComponents(t,e,r)},f=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},$=function(e,r){let i=r+1,a=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-a))*Math.pow(10,a-i);return parseFloat(o.toFixed(Math.max(i-a,0)))},tt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Et=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,a=t;return r=r+1/(12*a),a=a*i,r=r-1/(360*a),a=a*i,r=r+1/(1260*a),a=a*i,r=r-1/(1680*a),a=a*i,r=r+1/(1188*a),a=a*i,r=r-691/(360360*a),a=a*i,r=r+7/(1092*a),a=a*i,r=r-3617/(122400*a),Math.exp(r)/e},Ot=.36787944117144233,ot=.5671432904097838,et=function(t,e=1e-10,r=!0){let i,a;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ot;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(a=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(a-i).5?1:-1;if(Math.random()*20<1)return f(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 a=Math.pow(10,i);return Math.random()>.9&&(a=Math.trunc(a)),w(e,r,a)}static affordGeometricSeries_core(t,e,r,i){let a=e.mul(r.pow(i));return s.floor(t.div(a).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)),m=o.pow(2);return o.neg().add(m.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r));return t.div(2).mul(a.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=dt)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);It?t=t.replace(",",""):St&&(t=t.replace(",","."));let a=t.split("^^^");if(a.length===2){let d=parseFloat(a[0]),S=parseFloat(a[1]),E=a[1].split(";"),A=1;if(E.length===2&&(A=parseFloat(E[1]),isFinite(A)||(A=1)),isFinite(d)&&isFinite(S)){let n=s.pentate(d,S,A,e);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}}let o=t.split("^^");if(o.length===2){let d=parseFloat(o[0]),S=parseFloat(o[1]),E=o[1].split(";"),A=1;if(E.length===2&&(A=parseFloat(E[1]),isFinite(A)||(A=1)),isFinite(d)&&isFinite(S)){let n=s.tetrate(d,S,A,e);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}}let m=t.split("^");if(m.length===2){let d=parseFloat(m[0]),S=parseFloat(m[1]);if(isFinite(d)&&isFinite(S)){let E=s.pow(d,S);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let N,g,c=t.split("pt");if(c.length===2){N=10;let d=!1;c[0].startsWith("-")&&(d=!0,c[0]=c[0].slice(1)),g=parseFloat(c[0]),c[1]=c[1].replace("(",""),c[1]=c[1].replace(")","");let S=parseFloat(c[1]);if(isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(c=t.split("p"),c.length===2){N=10;let d=!1;c[0].startsWith("-")&&(d=!0,c[0]=c[0].slice(1)),g=parseFloat(c[0]),c[1]=c[1].replace("(",""),c[1]=c[1].replace(")","");let S=parseFloat(c[1]);if(isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(c=t.split("f"),c.length===2){N=10;let d=!1;c[0].startsWith("-")&&(d=!0,c[0]=c[0].slice(1)),c[0]=c[0].replace("(",""),c[0]=c[0].replace(")","");let S=parseFloat(c[0]);if(c[1]=c[1].replace("(",""),c[1]=c[1].replace(")",""),g=parseFloat(c[1]),isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}let _=t.split("e"),I=_.length-1;if(I===0){let d=parseFloat(t);if(isFinite(d))return this.fromNumber(d),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(I===1){let d=parseFloat(t);if(isFinite(d)&&d!==0)return this.fromNumber(d),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let q=t.split("e^");if(q.length===2){this.sign=1,q[0].startsWith("-")&&(this.sign=-1);let d="";for(let S=0;S=43&&E<=57||E===101)d+=q[1].charAt(S);else return this.layer=parseFloat(d),this.mag=parseFloat(q[1].substr(S+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(I<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let F=parseFloat(_[0]);if(F===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let O=parseFloat(_[_.length-1]);if(I>=2){let d=parseFloat(_[_.length-2]);isFinite(d)&&(O*=Math.sign(d),O+=tt(d))}if(!isFinite(F))this.sign=_[0]==="-"?-1:1,this.layer=I,this.mag=O;else if(I===1)this.sign=Math.sign(F),this.layer=1,this.mag=O+Math.log10(Math.abs(F));else if(this.sign=Math.sign(F),this.layer=I,I===2){let d=s.mul(w(1,2,O),u(F));return this.sign=d.sign,this.layer=d.layer,this.mag=d.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=O;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:$(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:$(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<=at?(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):$(this.m,t)+"e"+$(this.e,t):this.layer===1?$(this.m,t)+"e"+$(this.e,t):this.layer<=at?(this.sign===-1?"-":"")+"e".repeat(this.layer)+$(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+$(this.mag,t)}abs(){return f(this.sign===0?0:1,this.layer,this.mag)}neg(){return f(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?f(0,0,0):this.layer===0?w(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?f(-1,0,1):f(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?w(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?f(1,0,1):f(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?w(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?f(0,0,0):this.layer===0?w(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=u(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return f(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 f(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 a=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(a-o>=2)return r;if(a===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>D)return r;{let m=Math.pow(10,Math.log10(r.mag)-i.mag),N=i.sign+r.sign*m;return w(Math.sign(N),1,i.mag+Math.log10(Math.abs(N)))}}if(a===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>D)return r;{let m=Math.pow(10,r.mag-Math.log10(i.mag)),N=i.sign+r.sign*m;return w(Math.sign(N),1,Math.log10(i.mag)+Math.log10(Math.abs(N)))}}if(Math.abs(r.mag-i.mag)>D)return r;{let m=Math.pow(10,r.mag-i.mag),N=i.sign+r.sign*m;return w(Math.sign(N),1,i.mag+Math.log10(Math.abs(N)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(u(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=u(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return f(-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 f(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 f(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return f(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 w(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return w(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return w(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let a=w(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(w(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return w(r.sign*i.sign,a.layer+1,a.sign*a.mag)}if(r.layer===2&&i.layer===2){let a=w(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(w(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return w(r.sign*i.sign,a.layer+1,a.sign*a.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=u(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?f(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?f(0,0,0):this.layer===0?w(this.sign,0,1/this.mag):w(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=u(t).abs();if(e.eq(s.dZero))return f(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)?f(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=u(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=u(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=u(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,a=r.mag;return this.layer>r.layer&&(a=tt(a)),this.layer0?w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):w(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer>0?w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):w(this.sign,0,Math.log10(this.mag))}log(t){return t=u(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?w(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?w(this.sign,0,Math.log2(this.mag)):this.layer===1?w(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?w(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?w(this.sign,0,Math.log(this.mag)):this.layer===1?w(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?w(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=u(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?f(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return f(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let a=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?a.neg():Math.abs(i.toNumber()%2)%2===0?a:f(Number.NaN,Number.NaN,Number.NaN):a}pow10(){if(this.eq(s.dInf))return f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return f(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return f(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 w(1,0,e);if(t.sign===0)return f(1,0,1);t=f(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?w(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?w(-t.sign,t.layer+1,-t.mag):f(1,0,1)}pow_base(t){return u(t).pow(this)}root(t){let e=u(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(f(1,0,24)))return s.fromNumber(Et(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,a=12*i,o=1/a,m=e+o;if(m===e||(e=m,i=i*r,a=360*i,o=1/a,m=e-o,m===e))return s.exp(e);e=m,i=i*r,a=1260*i;let N=1/a;return e=e+N,i=i*r,a=1680*i,N=1/a,e=e-N,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?f(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?w(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?w(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):w(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 w(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(f(this.sign,this.layer-1,this.mag),f(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=f(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 f(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 m=s.ln(this).neg(),N=m.lambertw().div(m);if(o<1)return N;let g=m.lambertw(!1).div(m);return o>1.444667861009099&&(N=g=s.fromNumber(Math.E)),e=u(e),e.eq(g)?g:e.lt(g)?N:f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):f(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 a=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(a):this.lt(1)?e=e.pow(1-a).mul(this.pow(e).pow(a)):e=e.layeradd(a,this);for(let m=0;m1e4&&Math.ceil(i)%2==1?this.pow(e):e}a!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(a):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),a)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(a,r):this.lt(1)?e=e.pow(1-a).mul(this.pow(e).pow(a)):e=e.layeradd(a,this,r));for(let o=0;o3)return f(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=f(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=u(t);let i=s.fromDecimal(this),a=e;e=Math.trunc(e);let o=a-e;if(i.layer-t.layer>3){let m=Math.min(e,i.layer-t.layer-3);e-=m,i.layer-=m}for(let m=0;m1e4)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,a=!1,o=!1,m=this.slog_internal(t,r).toNumber();for(let N=1;N1&&o!=c&&(a=!0),o=c,a?i/=2:i*=2,i=Math.abs(i)*(c?-1:1),m+=i,i===0)break}return s.fromNumber(m)}slog_internal(t=10,e=!1){if(t=u(t),t.lte(s.dZero)||t.eq(s.dOne))return f(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?f(0,0,0):this.eq(s.dZero)?f(-1,0,1):f(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return f(-1,0,1);if(t.lt(1.444667861009766)){let a=s.ln(t).neg(),o=a.lambertw().div(a);if(this.eq(o))return f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return f(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let a=i.layer-t.layer-3;r+=a,i.layer-=a}for(let a=0;a<100;++a)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,Tt)}static tetrate_critical(t,e){return s.critical_section(t,e,vt)}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 a=0,o=0;for(let N=0;Nt){let g=(t-Z[N])/(Z[N+1]-Z[N]);a=r[N][Math.floor(e)]*(1-g)+r[N+1][Math.floor(e)]*g,o=r[N][Math.ceil(e)]*(1-g)+r[N+1][Math.ceil(e)]*g;break}let m=e-Math.floor(e);return a<=0||o<=0?a*(1-m)+o*m:Math.pow(t,Math.log(a)/Math.log(t)*(1-m)+Math.log(o)/Math.log(t)*m)}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 a=0;a<100;++a){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=u(e);if(i.gt(1)&&i.lte(1.444667861009766)){let m=s.excess_slog(this,e,r),N=m[0].toNumber(),g=m[1],c=N+t,_=s.ln(e).neg(),I=_.lambertw().div(_),q=_.lambertw(!1).div(_),F=s.dOne;g==1?F=I.mul(q).sqrt():g==2&&(F=q.mul(2));let O=i.pow(F),d=Math.floor(c),S=c-d,E=F.pow(1-S).mul(O.pow(S));return s.tetrate(i,d,E,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):f(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=u(t),e=u(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[f(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let a=s.ln(e).neg(),o=a.lambertw().div(a),m=s.dInf;if(e>1&&(m=a.lambertw(!1).div(a)),e>1.444667861009099&&(o=m=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(m))return[f(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(m)){let N=m.mul(2),g=i.pow(N),c=0;if(t.gte(N)&&t.lt(g))c=0;else if(t.gte(g)){let d=g;for(c=1;d.lt(t);)if(d=i.pow(d),c=c+1,d.layer>3){let S=Math.floor(t.layer-d.layer+1);d=i.iteratedexp(S,d,r),c=c+S}d.gt(t)&&(d=d.log(e),c=c-1)}else if(t.lt(N)){let d=N;for(c=0;d.gt(t);)d=d.log(e),c=c-1}let _=0,I=0,q=.5,F=N,O=s.dZero;for(;q>1e-16;){if(I=_+q,F=N.pow(1-I).mul(g.pow(I)),O=s.iteratedexp(e,c,F),O.eq(t))return[new s(c+I),2];O.lt(t)&&(_+=q),q/=2}return O.neq_tolerance(t,1e-7)?[f(Number.NaN,Number.NaN,Number.NaN),0]:[new s(c+_),2]}if(t.lt(m)&&t.gt(o)){let N=o.mul(m).sqrt(),g=i.pow(N),c=0;if(t.lte(N)&&t.gt(g))c=0;else if(t.lte(g)){let d=g;for(c=1;d.gt(t);)d=i.pow(d),c=c+1;d.lt(t)&&(d=d.log(e),c=c-1)}else if(t.gt(N)){let d=N;for(c=0;d.lt(t);)d=d.log(e),c=c-1}let _=0,I=0,q=.5,F=N,O=s.dZero;for(;q>1e-16;){if(I=_+q,F=N.pow(1-I).mul(g.pow(I)),O=s.iteratedexp(e,c,F),O.eq(t))return[new s(c+I),1];O.gt(t)&&(_+=q),q/=2}return O.neq_tolerance(t,1e-7)?[f(Number.NaN,Number.NaN,Number.NaN),0]:[new s(c+_),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?f(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(et(this.toNumber())):this.layer===0?s.fromNumber(et(this.sign*this.mag)):this.lt("eee15")?ut(this):this.ln():this.sign===1?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(et(this.sign*this.mag,1e-10,!1)):this.layer==1?ut(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 f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return f(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 f(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eOt?this.pow(this.recip()):f(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return f(1,0,1);if(this.lt(0))return f(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):f(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,a=e.iteratedlog(10,i,!0),o=a,m=a.div(2),N=!0;for(;N;)m=r.add(a).div(2),s.iteratedexp(10,i,m,!0).tetrate(t,1,!0).gt(this)?a=m:r=m,m.eq(o)?N=!1:o=m;return s.iteratedexp(10,i,m,!0)}else{let e=1,r=w(1,10,1),i=w(1,10,1),a=w(1,10,1),o=w(1,1,-16),m=s.dZero,N=w(1,10,1),g=o.pow10().recip(),c=s.dZero,_=g,I=g,q=Math.ceil(t)%2==0,F=0,O=w(1,10,1),d=!1,S=s.dZero,E=!1;for(;e<4;){if(e==2){if(q)break;a=w(1,10,1),o=r,e=3,N=w(1,10,1),O=w(1,10,1)}for(d=!1;o.neq(a);){if(S=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))g=o.pow10().recip(),_=o.pow10().recip(),I=o.pow10().recip(),c=s.dZero,F=-1,e==3&&(O=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!q&&o.pow10().recip().lt(.4))g=o.pow10().recip(),_=o.pow10().recip(),I=o.pow10().recip(),c=s.dZero,F=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))g=o.pow10().recip(),_=s.dZero,I=g.mul(2),c=g,q?F=-1:F=0;else{for(m=o.mul(12e-17),g=o.pow10().recip(),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);_.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||I.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||_.gte(g)||I.lte(g);)m=m.mul(2),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);if((e==1&&I.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&_.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&_.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(O=o),I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))F=-1;else if(q)F=1;else if(e==3&&o.gt_tolerance(r,1e-8))F=0;else{for(;_.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||I.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||_.gte(g)||I.lte(g);)m=m.mul(2),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);I.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.tetrate(t,1,!0).sub(_.tetrate(t,1,!0)))?F=0:F=1}}if(F==-1&&(E=!0),e==1&&F==1||e==3&&F!=0)if(a.eq(w(1,10,1)))o=o.mul(2);else{let l=!1;if(d&&(F==1&&e==1||F==-1&&e==3)&&(l=!0),o=o.add(a).div(2),l)break}else if(a.eq(w(1,10,1)))a=o,o=o.div(2);else{let l=!1;if(d&&(F==1&&e==1||F==-1&&e==3)&&(l=!0),a=a.sub(N),o=o.sub(N),l)break}if(a.sub(o).div(2).abs().gt(N.mul(1.5))&&(d=!0),N=a.sub(o).div(2).abs(),o.gt("1e18")||o.eq(S))break}if(o.gt("1e18")||!E||O==w(1,10,1))break;e==1?r=O:e==3&&(i=O),e++}a=r,o=w(1,1,-18);let A=o,n=s.dZero,h=!0;for(;h;)if(a.eq(w(1,10,1))?n=o.mul(2):n=a.add(o).div(2),s.pow(10,n).recip().tetrate(t,1,!0).gt(this)?o=n:a=n,n.eq(A)?h=!1:A=n,o.gt("1e18"))return f(Number.NaN,Number.NaN,Number.NaN);if(n.eq_tolerance(r,1e-15)){if(i.eq(w(1,10,1)))return f(Number.NaN,Number.NaN,Number.NaN);for(a=w(1,10,1),o=i,A=o,n=s.dZero,h=!0;h;)if(a.eq(w(1,10,1))?n=o.mul(2):n=a.add(o).div(2),s.pow(10,n).recip().tetrate(t,1,!0).gt(this)?o=n:a=n,n.eq(A)?h=!1:A=n,o.gt("1e18"))return f(Number.NaN,Number.NaN,Number.NaN);return n.pow10().recip()}else return n.pow10().recip()}}pentate(t=2,e=f(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let a=i-t;a!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(a)):this.eq(10)?e=e.layeradd10(a,r):e=e.layeradd(a,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)):f(0,0,0)}cos(){return this.mag<0?f(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):f(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):f(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):f(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)):f(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)?f(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 a=this.clone();return a.gte(t)&&([0,"pow"].includes(r)&&(a=i?a.mul(t.pow(e.sub(1))).root(e):a.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(a=i?a.div(t).max(1).log(e).add(t):s.pow(e,a.sub(t)).mul(t))),a}static scale(t,e,r,i,a=!1){return new s(t).scale(e,r,i,a)}format(t=2,e=9,r="mixed_sc"){return z.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return z.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return z.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return z.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return z.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,a){return z.formatGain(new s(t),e,r,i,a)}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},a="";for(let o of Object.keys(i)){let m=Math.floor(r/i[o]);r-=m*i[o],a+=o.repeat(m)}return a}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=f(0,0,0),s.dOne=f(1,0,1),s.dNegOne=f(-1,0,1),s.dTwo=f(1,0,2),s.dTen=f(1,0,10),s.dNaN=f(Number.NaN,Number.NaN,Number.NaN),s.dInf=f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=f(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=w(1,0,Number.MAX_VALUE),s.dNumberMin=w(1,0,Number.MIN_VALUE),s.fromStringCache=new ct(_t),W([J()],s.prototype,"sign",2),W([J()],s.prototype,"mag",2),W([J()],s.prototype,"layer",2),s=W([gt()],s);var{formats:z,FORMATS:Yt}=pt(s);s.formats=z;function Q(t,e){e=Object.assign({formatType:"mixed_sc",acc:2,max:9},e);let{formatType:r,acc:i,max:a,time:o,multi:m,formatTimeType:N}=e;if(o)switch(N){case"short":return s.formats.formatTime(t,i,r);case"long":return s.formats.formatTimeLong(t,!0,0,a,r)}return m?s.formats.formatMult(t,i):s.format(t,i,a,r)}function lt(t,e,r){let{formatType:i,acc:a,max:o}=r;return s.formatGain(t,e,i,a,o)}var qt=class{constructor(t){this.format=e=>Q(e,this.settings),this.gain=(e,r)=>lt(e,r,this.settings),this.time=e=>Q(e,{...this.settings,time:!0}),this.multi=e=>Q(e,{...this.settings,multi:!0}),this.settingsFn=typeof t=="function"?t:()=>t}get settings(){return this.settingsFn()}},Ct=[{name:"Standard",value:"standard"},{name:"Scientific",value:"scientific"},{name:"Mixed Scientific (default)",value:"mixed_sc"},{name:"Old Scientific",value:"old_sc"},{name:"Engineering",value:"eng"},{name:"Infinity",value:"inf"},{name:"Omega",value:"omega"},{name:"Omega Short",value:"omega_short"},{name:"Elemental",value:"elemental"},{name:"Layer",value:"layer"}].sort((t,e)=>t.name.localeCompare(e.name)),At=[{name:"Short (default)",value:"short"},{name:"Long",value:"long"}].sort((t,e)=>t.name.localeCompare(e.name));if(typeof V.exports=="object"&&typeof j=="object"){var Pt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,a)&&a!==r&&Object.defineProperty(t,a,{get:()=>e[a],enumerable:!(i=Object.getOwnPropertyDescriptor(e,a))||i.enumerable});return t};V.exports=Pt(V.exports,j)}return V.exports}); +"use strict";(function(_t,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 ut=st(),Tt=At?exports:_t;for(var St in ut)Tt[St]=ut[St]}})(typeof self<"u"?self:exports,()=>{var _t={},st={exports:_t},At=Object.create,ut=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,St=Object.getOwnPropertyNames,Ie=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty,gt=(t,e)=>function(){return e||(0,t[St(t)[0]])((e={exports:{}}).exports,e),e.exports},Vt=(t,e)=>{for(var r in e)ut(t,r,{get:e[r],enumerable:!0})},Ht=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of St(e))!Oe.call(t,i)&&i!==r&&ut(t,i,{get:()=>e[i],enumerable:!(n=Tt(e,i))||n.enumerable});return t},ft=(t,e,r)=>(r=t!=null?At(Ie(t)):{},Ht(e||!t||!t.__esModule?ut(r,"default",{value:t,enumerable:!0}):r,t)),Ae=t=>Ht(ut({},"__esModule",{value:!0}),t),at=(t,e,r,n)=>{for(var i=n>1?void 0:n?Tt(e,r):e,o=t.length-1,c;o>=0;o--)(c=t[o])&&(i=(n?c(e,r,i):c(i))||i);return n&&i&&ut(e,r,i),i},pt=gt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var n=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:d(),i=o(e);typeof n.Reflect<"u"&&(i=o(n.Reflect,i)),r(i,n),typeof n.Reflect>"u"&&(n.Reflect=e);function o(f,p){return function(l,u){Object.defineProperty(f,l,{configurable:!0,writable:!0,value:u}),p&&p(l,u)}}function c(){try{return Function("return this;")()}catch{}}function m(){try{return(0,eval)("(function() { return this; })()")}catch{}}function d(){return c()||m()}})(function(r,n){var i=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",c=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",m=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",d=typeof Object.create=="function",f={__proto__:[]}instanceof Array,p=!d&&!f,l={create:d?function(){return Zt(Object.create(null))}:f?function(){return Zt({__proto__:null})}:function(){return Zt({})},has:p?function(y,w){return i.call(y,w)}:function(y,w){return w in y},get:p?function(y,w){return i.call(y,w)?y[w]:void 0}:function(y,w){return y[w]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Tr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Er(),N=typeof WeakMap=="function"?WeakMap:Fr(),A=o?Symbol.for("@reflect-metadata:registry"):void 0,x=Ir(),P=Or(x);function a(y,w,O,E){if(j(O)){if(!me(y))throw new TypeError;if(!de(w))throw new TypeError;return K(y,w)}else{if(!me(y))throw new TypeError;if(!X(w))throw new TypeError;if(!X(E)&&!j(E)&&!bt(E))throw new TypeError;return bt(E)&&(E=void 0),O=ot(O),nt(y,w,O,E)}}r("decorate",a);function S(y,w){function O(E,R){if(!X(E))throw new TypeError;if(!j(R)&&!_r(R))throw new TypeError;xt(y,w,E,R)}return O}r("metadata",S);function v(y,w,O,E){if(!X(O))throw new TypeError;return j(E)||(E=ot(E)),xt(y,w,O,E)}r("defineMetadata",v);function I(y,w,O){if(!X(w))throw new TypeError;return j(O)||(O=ot(O)),H(y,w,O)}r("hasMetadata",I);function _(y,w,O){if(!X(w))throw new TypeError;return j(O)||(O=ot(O)),z(y,w,O)}r("hasOwnMetadata",_);function M(y,w,O){if(!X(w))throw new TypeError;return j(O)||(O=ot(O)),W(y,w,O)}r("getMetadata",M);function F(y,w,O){if(!X(w))throw new TypeError;return j(O)||(O=ot(O)),ct(y,w,O)}r("getOwnMetadata",F);function C(y,w){if(!X(y))throw new TypeError;return j(w)||(w=ot(w)),Pt(y,w)}r("getMetadataKeys",C);function U(y,w){if(!X(y))throw new TypeError;return j(w)||(w=ot(w)),Lt(y,w)}r("getOwnMetadataKeys",U);function Z(y,w,O){if(!X(w))throw new TypeError;if(j(O)||(O=ot(O)),!X(w))throw new TypeError;j(O)||(O=ot(O));var E=Ot(w,O,!1);return j(E)?!1:E.OrdinaryDeleteMetadata(y,w,O)}r("deleteMetadata",Z);function K(y,w){for(var O=y.length-1;O>=0;--O){var E=y[O],R=E(w);if(!j(R)&&!bt(R)){if(!de(R))throw new TypeError;w=R}}return w}function nt(y,w,O,E){for(var R=y.length-1;R>=0;--R){var J=y[R],tt=J(w,O,E);if(!j(tt)&&!bt(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(y,w,O){var E=z(y,w,O);if(E)return!0;var R=zt(w);return bt(R)?!1:H(y,R,O)}function z(y,w,O){var E=Ot(w,O,!1);return j(E)?!1:he(E.OrdinaryHasOwnMetadata(y,w,O))}function W(y,w,O){var E=z(y,w,O);if(E)return ct(y,w,O);var R=zt(w);if(!bt(R))return W(y,R,O)}function ct(y,w,O){var E=Ot(w,O,!1);if(!j(E))return E.OrdinaryGetOwnMetadata(y,w,O)}function xt(y,w,O,E){var R=Ot(O,E,!0);R.OrdinaryDefineOwnMetadata(y,w,O,E)}function Pt(y,w){var O=Lt(y,w),E=zt(y);if(E===null)return O;var R=Pt(E,w);if(R.length<=0)return O;if(O.length<=0)return R;for(var J=new g,tt=[],Y=0,L=O;Y=0&&L=this._keys.length?(this._index=-1,this._keys=w,this._values=w):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},Y.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=w,this._values=w),L},Y.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=w,this._values=w),{value:L,done:!0}},Y}(),E=function(){function Y(){this._keys=[],this._values=[],this._cacheKey=y,this._cacheIndex=-2}return Object.defineProperty(Y.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),Y.prototype.has=function(L){return this._find(L,!1)>=0},Y.prototype.get=function(L){var k=this._find(L,!1);return k>=0?this._values[k]:void 0},Y.prototype.set=function(L,k){var q=this._find(L,!0);return this._values[q]=k,this},Y.prototype.delete=function(L){var k=this._find(L,!1);if(k>=0){for(var q=this._keys.length,B=k+1;B>>8,l[u*2+1]=g%256}return l},decompressFromUint8Array:function(f){if(f==null)return d.decompress(f);for(var p=new Array(f.length/2),l=0,u=p.length;l>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(l(_));break}else M++;return I.join("")},decompress:function(f){return f==null?"":f==""?null:d._decompress(f.length,32768,function(p){return f.charCodeAt(p)})},_decompress:function(f,p,l){var u=[],h,g=4,N=4,A=3,x="",P=[],a,S,v,I,_,M,F,C={val:l(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=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.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=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.index++)),v|=(I>0?1:0)*M,M<<=1;F=n(v);break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.index++)),v|=(I>0?1:0)*M,M<<=1;F=n(v);break;case 2:return""}for(u[3]=F,S=F,P.push(F);;){if(C.index>f)return"";for(v=0,_=Math.pow(2,A),M=1;M!=_;)I=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.index++)),v|=(I>0?1:0)*M,M<<=1;switch(F=v){case 0:for(v=0,_=Math.pow(2,8),M=1;M!=_;)I=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=n(v),F=N-1,g--;break;case 1:for(v=0,_=Math.pow(2,16),M=1;M!=_;)I=C.val&C.position,C.position>>=1,C.position==0&&(C.position=p,C.val=l(C.index++)),v|=(I>0?1:0)*M,M<<=1;u[N++]=n(v),F=N-1,g--;break;case 2:return P.join("")}if(g==0&&(g=Math.pow(2,A),A++),u[F])x=u[F];else if(F===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 d}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),Ee=gt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={rotl:function(i,o){return i<>>32-o},rotr:function(i,o){return i<<32-o|i>>>o},endian:function(i){if(i.constructor==Number)return n.rotl(i,8)&16711935|n.rotl(i,24)&4278255360;for(var o=0;o0;i--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(i){for(var o=[],c=0,m=0;c>>5]|=i[c]<<24-m%32;return o},wordsToBytes:function(i){for(var o=[],c=0;c>>5]>>>24-c%32&255);return o},bytesToHex:function(i){for(var o=[],c=0;c>>4).toString(16)),o.push((i[c]&15).toString(16));return o.join("")},hexToBytes:function(i){for(var o=[],c=0;c>>6*(3-d)&63)):o.push("=");return o.join("")},base64ToBytes:function(i){i=i.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],c=0,m=0;c>>6-m*2);return o}};e.exports=n})()}}),Wt=gt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(n){return r.bin.stringToBytes(unescape(encodeURIComponent(n)))},bytesToString:function(n){return decodeURIComponent(escape(r.bin.bytesToString(n)))}},bin:{stringToBytes:function(n){for(var i=[],o=0;o>>24)&16711935|(f[N]<<24|f[N]>>>8)&4278255360;f[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([l,u,h,g])};c._ff=function(m,d,f,p,l,u,h){var g=m+(d&f|~d&p)+(l>>>0)+h;return(g<>>32-u)+d},c._gg=function(m,d,f,p,l,u,h){var g=m+(d&p|f&~p)+(l>>>0)+h;return(g<>>32-u)+d},c._hh=function(m,d,f,p,l,u,h){var g=m+(d^f^p)+(l>>>0)+h;return(g<>>32-u)+d},c._ii=function(m,d,f,p,l,u,h){var g=m+(f^(d|~p))+(l>>>0)+h;return(g<>>32-u)+d},c._blocksize=16,c._digestsize=16,e.exports=function(m,d){if(m==null)throw new Error("Illegal argument "+m);var f=r.wordsToBytes(c(m,d));return d&&d.asBytes?f:d&&d.asString?o.bytesToString(f):r.bytesToHex(f)}})()}}),Xt={};Vt(Xt,{emathPresets:()=>Jt}),st.exports=Ae(Xt);var Jt={};Vt(Jt,{GameFormatClass:()=>gr,formatOptions:()=>pr,formatTimeOptions:()=>Nr,gameFormat:()=>Ct,gameFormatGain:()=>le});var Pr=ft(pt()),Qt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new xe(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 n=this.last;this.map.delete(n.key),this.last=n.prev,this.last.next=void 0}}},xe=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 Pe=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,n){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?n===G.CLASS_TO_CLASS||n===G.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?n===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(n){return n.options&&n.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),n=r&&r.get(void 0),i=this._exposeMetadatas.get(e),o=i&&i.get(void 0);return n&&o||!n&&!o?"none":n?"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(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?r===G.CLASS_TO_CLASS||r===G.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?r===G.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var n=e.get(r),i;n&&(i=Array.from(n.values()).filter(function(l){return l.propertyName!==void 0}));for(var o=[],c=0,m=this.getAncestors(r);c0&&(c=c.filter(function(l){return!f.includes(l)})),this.options.version!==void 0&&(c=c.filter(function(l){var u=et.findExposeMetadata(e,l);return!u||!u.options?!0:i.checkVersion(u.options.since,u.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(l){var u=et.findExposeMetadata(e,l);return!u||!u.options?!0:i.checkGroups(u.options.groups)}):c=c.filter(function(l){var u=et.findExposeMetadata(e,l);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 i.options.excludePrefixes.every(function(l){return p.substr(0,l.length)!==l})})),c=c.filter(function(p,l,u){return u.indexOf(p)===l}),c},t.prototype.checkVersion=function(e,r){var n=!0;return n&&e&&(n=this.options.version>=e),n&&r&&(n=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),F=e.elemental.getAbbreviation(v,_),C=new t(118).pow(v+M/I-1);return[F,C]},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),F=[];for(;v.gte(1)&&F.length=M)return F.map(U=>e.elemental.formatElementalPart(U[0],U[1])).join(" + ");let C=new t(118).pow(v).toFixed(F.length===1?3:S);return F.length===0?C:F.length===1?`${C} \xD7 ${e.elemental.formatElementalPart(F[0][0],F[0][1])}`:`${C} \xD7 (${F.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)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(new t(10).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)?"":new t(10).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)?d(a,S,v,"st"):d(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 d(a,S,v,"sc");a=new t(10).pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return d(a,Math.max(4,S),v,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+d(_,0,v,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ht[0][0][a%10]+ht[0][1][Math.floor(a/10)%10]+ht[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,v=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ht[1][0][a]:(v==1&&S==0?_+="Vec":_+=ht[1][1][S]+ht[1][2][v],_+=ht[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"],F=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?d(a,S,v,"sc"):a.gte(3)?F[I]+M[I]+"\u03C9^"+d(a.sub(1),S,v,"sc"):a.gte(2)?F[I]+"\u03C9"+M[I]+"-"+d(_.pow(a.sub(2)),S,v,"sc"):F[I]+M[I]+"-"+d(_.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,F=a.log(1e3).sub(S.log(1e3)).floor(),C=F.add(1).log(M+1).ceil(),U="",Z=(K,nt)=>{let H=K,z="";for(let W=0;W=M)return"\u03C9";z=_[ct]+z,H=H.sub(1).div(M).floor()}return z};if(C.lt(I))U=Z(F,C);else{let K=C.sub(I).add(1),nt=F.div(t.pow(M+1,K.sub(1))).floor();U=`${Z(nt,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,F){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return d(a,S,v,I);let C=e.alphabet.getAbbreviation(a,_,M,F),U=a.div(t.pow(1e3,a.log(1e3).floor()));return`${C.length>(F??9)+2?"":U.toFixed(S)+" "}${C}`}}},r=new t(2).pow(1024),n="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",i="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function m(a,S=2,v=9,I="st"){return d(a,S,v,I)}function d(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 F=a.log10().ceil(),C=a.div(F.eq(-1)?new t(.1):new t(10).pow(F)),U=F.mul(-1).max(1).log10().gte(9);return _+(U?"":C.toFixed(2))+"e"+d(F,0,v,"mixed_sc")}else if(M.lt(v)){let F=Math.max(Math.min(S-M.toNumber(),S),0);return _+(F>0?a.toFixed(F):a.toFixed(F).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let U=a.slog();return(U.gte(1e9)?"":new t(10).pow(U.sub(U.floor())).toFixed(2))+"F"+d(U.floor(),0)}let F=a.div(new t(10).pow(M)),C=M.log10().gte(9);return _+(C?"":F.toFixed(2))+"e"+d(M,0,v,"mixed_sc")}case"st":case"standard":{let F=a.log(1e3).floor();if(F.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let C=F.mul(3),U=F.log10().floor();if(U.gte(3e3))return"e"+d(M,S,v,"st");let Z="";if(F.lt(4))Z=["","K","M","B"][Math.round(F.toNumber())];else{let H=Math.floor(F.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),F=F.sub(1).div(new t(10).pow(H*3));F.gt(0);){let z=F.div(1e3).floor(),W=F.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)),F=z,H++}}let K=a.div(new t(10).pow(C)),nt=S===2?new t(2).sub(M.sub(C)).add(1).toNumber():S;return _+(U.gte(10)?"":K.toFixed(nt)+" ")+Z}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,v)}}function f(a,S,v="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),F,C=M.div(a);return C.gte(10)&&a.gte(1e100)?(C=C.log10().mul(20),F="(+"+d(C,I,_,v)+" OoMs/sec)"):F="(+"+d(S,I,_,v)+"/sec)",F}function p(a,S=2,v="s"){return a=new t(a),a.gte(86400)?d(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")+d(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")+d(a.div(60).floor(),0,12,"sc")+":"+p(a.mod(60),S,"m"):(a.gte(10)||v!="m"?"":"0")+d(a,S,12,"sc")}function l(a,S=!1,v=0,I=9,_="mixed_sc"){let M=Lt=>d(Lt,v,I,_);a=new t(a);let F=a.mul(1e3).mod(1e3).floor(),C=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(),nt=a.div(31556952).floor(),H=nt.eq(1)?" year":" years",z=K.eq(1)?" day":" days",W=Z.eq(1)?" hour":" hours",ct=U.eq(1)?" minute":" minutes",xt=C.eq(1)?" second":" seconds",Pt=F.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+H+", ":""}${K.gt(0)?M(K)+z+", ":""}${Z.gt(0)?M(Z)+W+", ":""}${U.gt(0)?M(U)+ct+", ":""}${C.gt(0)?M(C)+xt+",":""}${S&&F.gt(0)?" "+M(F)+Pt:""}`.replace(/,([^,]*)$/,"$1").trim()}function u(a){return a=new t(a),d(new t(1).sub(a).mul(100))+"%"}function h(a){return a=new t(a),d(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=(F=>F.map((C,U)=>({name:C.name,altName:C.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:m,format:d,formatGain:f,formatTime:p,formatTimeLong:l,formatReduction:u,formatPercent:h,formatMult:g,expMult:N,metric:A,ev:x};return{FORMATS:e,formats:P}}var qt=17,je=9e15,Ue=Math.log10(9e15),Ge=1/9e15,Ye=308,$e=-324,re=5,ze=1023,Ze=!0,Ve=!1,He=function(){let t=[];for(let r=$e+1;r<=Ye;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),mt=[2,Math.E,3,4,5,6,7,8,9,10],We=[[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]],Xe=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],b=function(e){return s.fromValue_noAlloc(e)},D=function(t,e,r){return s.fromComponents(t,e,r)},T=function(e,r,n){return s.fromComponents_noNormalize(e,r,n)},lt=function(e,r){let n=r+1,i=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,n-i))*Math.pow(10,i-n);return parseFloat(o.toFixed(Math.max(n-i,0)))},Bt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Je=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let n=t*t,i=t;return r=r+1/(12*i),i=i*n,r=r-1/(360*i),i=i*n,r=r+1/(1260*i),i=i*n,r=r-1/(1680*i),i=i*n,r=r+1/(1188*i),i=i*n,r=r-691/(360360*i),i=i*n,r=r+7/(1092*i),i=i*n,r=r-3617/(122400*i),Math.exp(r)/e},Qe=.36787944117144233,ne=.5671432904097838,Dt=function(t,e=1e-10,r=!0){let n,i;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ne;t<10?n=0:n=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?n=-2:n=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(i=(t*Math.exp(-n)+n*n)/(n+1),Math.abs(i-n).5?1:-1;if(Math.random()*20<1)return T(e,0,1);let r=Math.floor(Math.random()*(t+1)),n=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(n=Math.trunc(n));let i=Math.pow(10,n);return Math.random()>.9&&(i=Math.trunc(i)),D(e,r,i)}static affordGeometricSeries_core(t,e,r,n){let i=e.mul(r.pow(n));return s.floor(t.div(i).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,n){return e.mul(r.pow(n)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,n){let o=e.add(n.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,n){let i=e.add(n.mul(r));return t.div(2).mul(i.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=je)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,n=s.fromStringCache.get(r);if(n!==void 0)return this.fromDecimal(n);Ze?t=t.replace(",",""):Ve&&(t=t.replace(",","."));let i=t.split("^^^");if(i.length===2){let N=parseFloat(i[0]),A=parseFloat(i[1]),x=i[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 m,d,f=t.split("pt");if(f.length===2){m=10;let N=!1;f[0].startsWith("-")&&(N=!0,f[0]=f[0].slice(1)),d=parseFloat(f[0]),f[1]=f[1].replace("(",""),f[1]=f[1].replace(")","");let A=parseFloat(f[1]);if(isFinite(A)||(A=1),isFinite(m)&&isFinite(d)){let x=s.tetrate(m,d,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(f=t.split("p"),f.length===2){m=10;let N=!1;f[0].startsWith("-")&&(N=!0,f[0]=f[0].slice(1)),d=parseFloat(f[0]),f[1]=f[1].replace("(",""),f[1]=f[1].replace(")","");let A=parseFloat(f[1]);if(isFinite(A)||(A=1),isFinite(m)&&isFinite(d)){let x=s.tetrate(m,d,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(f=t.split("f"),f.length===2){m=10;let N=!1;f[0].startsWith("-")&&(N=!0,f[0]=f[0].slice(1)),f[0]=f[0].replace("(",""),f[0]=f[0].replace(")","");let A=parseFloat(f[0]);if(f[1]=f[1].replace("(",""),f[1]=f[1].replace(")",""),d=parseFloat(f[1]),isFinite(A)||(A=1),isFinite(m)&&isFinite(d)){let x=s.tetrate(m,d,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"),l=p.length-1;if(l===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(l===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(l<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(l>=2){let N=parseFloat(p[p.length-2]);isFinite(N)&&(g*=Math.sign(N),g+=Bt(N))}if(!isFinite(h))this.sign=p[0]==="-"?-1:1,this.layer=l,this.mag=g;else if(l===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=l,l===2){let N=s.mul(D(1,2,g),b(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:lt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:lt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=re?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):lt(this.m,t)+"e"+lt(this.e,t):this.layer===1?lt(this.m,t)+"e"+lt(this.e,t):this.layer<=re?(this.sign===-1?"-":"")+"e".repeat(this.layer)+lt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+lt(this.mag,t)}abs(){return T(this.sign===0?0:1,this.layer,this.mag)}neg(){return T(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?T(-1,0,1):T(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?T(1,0,1):T(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?T(0,0,0):this.layer===0?D(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return T(0,0,0);let r,n;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*r.mag+n.sign*n.mag);let i=r.layer*Math.sign(r.mag),o=n.layer*Math.sign(n.mag);if(i-o>=2)return r;if(i===0&&o===-1){if(Math.abs(n.mag-Math.log10(r.mag))>qt)return r;{let c=Math.pow(10,Math.log10(r.mag)-n.mag),m=n.sign+r.sign*c;return D(Math.sign(m),1,n.mag+Math.log10(Math.abs(m)))}}if(i===1&&o===0){if(Math.abs(r.mag-Math.log10(n.mag))>qt)return r;{let c=Math.pow(10,r.mag-Math.log10(n.mag)),m=n.sign+r.sign*c;return D(Math.sign(m),1,Math.log10(n.mag)+Math.log10(Math.abs(m)))}}if(Math.abs(r.mag-n.mag)>qt)return r;{let c=Math.pow(10,r.mag-n.mag),m=n.sign+r.sign*c;return D(Math.sign(m),1,n.mag+Math.log10(Math.abs(m)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(b(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=b(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return T(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return T(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return T(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return T(this.sign*e.sign,0,1);let r,n;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),n=new s(e)):(r=new s(e),n=new s(this)),r.layer===0&&n.layer===0)return s.fromNumber(r.sign*n.sign*r.mag*n.mag);if(r.layer>=3||r.layer-n.layer>=2)return D(r.sign*n.sign,r.layer,r.mag);if(r.layer===1&&n.layer===0)return D(r.sign*n.sign,1,r.mag+Math.log10(n.mag));if(r.layer===1&&n.layer===1)return D(r.sign*n.sign,1,r.mag+n.mag);if(r.layer===2&&n.layer===1){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}if(r.layer===2&&n.layer===2){let i=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(n.mag),n.layer-1,Math.abs(n.mag)));return D(r.sign*n.sign,i.layer+1,i.sign*i.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=b(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?T(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?T(0,0,0):this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=b(t).abs();if(e.eq(s.dZero))return T(0,0,0);let r=this.toNumber(),n=e.toNumber();return isFinite(r)&&isFinite(n)&&r!=0&&n!=0?new s(r%n):this.sub(e).eq(this)?T(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=b(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,n=e.mag>0?e.layer:-e.layer;return r>n?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=b(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=b(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let n=this.mag,i=r.mag;return this.layer>r.layer&&(i=Bt(i)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=b(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=b(t),r=new s(this),n=new s(e);if(r.sign===0)return n.eq(0)?T(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(n.sign===0)return T(1,0,1);if(n.sign===1&&n.layer===0&&n.mag===1)return r;let i=r.absLog10().mul(n).pow10();return this.sign===-1?Math.abs(n.toNumber()%2)%2===1?i.neg():Math.abs(n.toNumber()%2)%2===0?i:T(Number.NaN,Number.NaN,Number.NaN):i}pow10(){if(this.eq(s.dInf))return T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return T(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return T(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return T(1,0,1);t=T(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):T(1,0,1)}pow_base(t){return b(t).pow(this)}root(t){let e=b(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(T(1,0,24)))return s.fromNumber(Je(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,n=t,i=12*n,o=1/i,c=e+o;if(c===e||(e=c,n=n*r,i=360*n,o=1/i,c=e-o,c===e))return s.exp(e);e=c,n=n*r,i=1260*n;let m=1/i;return e=e+m,n=n*r,i=1680*n,m=1/i,e=e-m,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?T(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?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(),m=c.lambertw().div(c);if(o<1)return m;let d=c.lambertw(!1).div(c);return o>1.444667861009099&&(m=d=s.fromNumber(Math.E)),e=b(e),e.eq(d)?d:e.lt(d)?m:T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?T(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):T(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let n=t;t=Math.trunc(t);let i=n-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())))&&(n>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(i):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this);for(let c=0;c1e4&&Math.ceil(n)%2==1?this.pow(e):e}i!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(i):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),i)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(i,r):this.lt(1)?e=e.pow(1-i).mul(this.pow(e).pow(i)):e=e.layeradd(i,this,r));for(let o=0;o3)return T(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=T(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=b(t);let n=s.fromDecimal(this),i=e;e=Math.trunc(e);let o=i-e;if(n.layer-t.layer>3){let c=Math.min(e,n.layer-t.layer-3);e-=c,n.layer-=c}for(let c=0;c1e4)return n}return o>0&&o<1&&(t.eq(10)?n=n.layeradd10(-o,r):n=n.layeradd(-o,t,r)),n}slog(t=10,e=100,r=!1){let n=.001,i=!1,o=!1,c=this.slog_internal(t,r).toNumber();for(let m=1;m1&&o!=f&&(i=!0),o=f,i?n/=2:n*=2,n=Math.abs(n)*(f?-1:1),c+=n,n===0)break}return s.fromNumber(c)}slog_internal(t=10,e=!1){if(t=b(t),t.lte(s.dZero)||t.eq(s.dOne))return T(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?T(0,0,0):this.eq(s.dZero)?T(-1,0,1):T(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return T(-1,0,1);if(t.lt(1.444667861009766)){let i=s.ln(t).neg(),o=i.lambertw().div(i);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,n=s.fromDecimal(this);if(n.layer-t.layer>3){let i=n.layer-t.layer-3;r+=i,n.layer-=i}for(let i=0;i<100;++i)if(n.lt(s.dZero))n=s.pow(t,n),r-=1;else{if(n.lte(s.dOne))return e?s.fromNumber(r+n.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),n.toNumber()));r+=1,n=s.log(n,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,Xe)}static tetrate_critical(t,e){return s.critical_section(t,e,We)}static critical_section(t,e,r,n=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let i=0,o=0;for(let m=0;mt){let d=(t-mt[m])/(mt[m+1]-mt[m]);i=r[m][Math.floor(e)]*(1-d)+r[m+1][Math.floor(e)]*d,o=r[m][Math.ceil(e)]*(1-d)+r[m+1][Math.ceil(e)]*d;break}let c=e-Math.floor(e);return i<=0||o<=0?i*(1-c)+o*c:Math.pow(t,Math.log(i)/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 n=Math.trunc(t);t-=n,r.layer+=n}if(t<=-1){let n=Math.trunc(t);if(t-=n,r.layer+=n,r.layer<0)for(let i=0;i<100;++i){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 n=b(e);if(n.gt(1)&&n.lte(1.444667861009766)){let c=s.excess_slog(this,e,r),m=c[0].toNumber(),d=c[1],f=m+t,p=s.ln(e).neg(),l=p.lambertw().div(p),u=p.lambertw(!1).div(p),h=s.dOne;d==1?h=l.mul(u).sqrt():d==2&&(h=u.mul(2));let g=n.pow(h),N=Math.floor(f),A=f-N,x=h.pow(1-A).mul(g.pow(A));return s.tetrate(n,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=b(t),e=b(e);let n=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 i=s.ln(e).neg(),o=i.lambertw().div(i),c=s.dInf;if(e>1&&(c=i.lambertw(!1).div(i)),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 m=c.mul(2),d=n.pow(m),f=0;if(t.gte(m)&&t.lt(d))f=0;else if(t.gte(d)){let N=d;for(f=1;N.lt(t);)if(N=n.pow(N),f=f+1,N.layer>3){let A=Math.floor(t.layer-N.layer+1);N=n.iteratedexp(A,N,r),f=f+A}N.gt(t)&&(N=N.log(e),f=f-1)}else if(t.lt(m)){let N=m;for(f=0;N.gt(t);)N=N.log(e),f=f-1}let p=0,l=0,u=.5,h=m,g=s.dZero;for(;u>1e-16;){if(l=p+u,h=m.pow(1-l).mul(d.pow(l)),g=s.iteratedexp(e,f,h),g.eq(t))return[new s(f+l),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(f+p),2]}if(t.lt(c)&&t.gt(o)){let m=o.mul(c).sqrt(),d=n.pow(m),f=0;if(t.lte(m)&&t.gt(d))f=0;else if(t.lte(d)){let N=d;for(f=1;N.gt(t);)N=n.pow(N),f=f+1;N.lt(t)&&(N=N.log(e),f=f-1)}else if(t.gt(m)){let N=m;for(f=0;N.lt(t);)N=N.log(e),f=f-1}let p=0,l=0,u=.5,h=m,g=s.dZero;for(;u>1e-16;){if(l=p+u,h=m.pow(1-l).mul(d.pow(l)),g=s.iteratedexp(e,f,h),g.eq(t))return[new s(f+l),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(f+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(Dt(this.toNumber())):this.layer===0?s.fromNumber(Dt(this.sign*this.mag)):this.lt("eee15")?ie(this):this.ln():this.sign===1?T(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Dt(this.sign*this.mag,1e-10,!1)):this.layer==1?ie(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(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 eQe?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,n=e.layer,i=e.iteratedlog(10,n,!0),o=i,c=i.div(2),m=!0;for(;m;)c=r.add(i).div(2),s.iteratedexp(10,n,c,!0).tetrate(t,1,!0).gt(this)?i=c:r=c,c.eq(o)?m=!1:o=c;return s.iteratedexp(10,n,c,!0)}else{let e=1,r=D(1,10,1),n=D(1,10,1),i=D(1,10,1),o=D(1,1,-16),c=s.dZero,m=D(1,10,1),d=o.pow10().recip(),f=s.dZero,p=d,l=d,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;i=D(1,10,1),o=r,e=3,m=D(1,10,1),g=D(1,10,1)}for(N=!1;o.neq(i);){if(A=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))d=o.pow10().recip(),p=o.pow10().recip(),l=o.pow10().recip(),f=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))d=o.pow10().recip(),p=o.pow10().recip(),l=o.pow10().recip(),f=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))d=o.pow10().recip(),p=s.dZero,l=d.mul(2),f=d,u?h=-1:h=0;else{for(c=o.mul(12e-17),d=o.pow10().recip(),p=o.add(c).pow10().recip(),f=d.sub(p),l=d.add(f);p.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||l.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||p.gte(d)||l.lte(d);)c=c.mul(2),p=o.add(c).pow10().recip(),f=d.sub(p),l=d.add(f);if((e==1&&l.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))&&p.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))||e==3&&l.tetrate(t,1,!0).lt(d.tetrate(t,1,!0))&&p.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))&&(g=o),l.tetrate(t,1,!0).lt(d.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(d.tetrate(t,1,!0),1e-8)||l.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||p.gte(d)||l.lte(d);)c=c.mul(2),p=o.add(c).pow10().recip(),f=d.sub(p),l=d.add(f);l.tetrate(t,1,!0).sub(d.tetrate(t,1,!0)).lt(d.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(i.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(i).div(2),v)break}else if(i.eq(D(1,10,1)))i=o,o=o.div(2);else{let v=!1;if(N&&(h==1&&e==1||h==-1&&e==3)&&(v=!0),i=i.sub(m),o=o.sub(m),v)break}if(i.sub(o).div(2).abs().gt(m.mul(1.5))&&(N=!0),m=i.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&&(n=g),e++}i=r,o=D(1,1,-18);let P=o,a=s.dZero,S=!0;for(;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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(n.eq(D(1,10,1)))return T(Number.NaN,Number.NaN,Number.NaN);for(i=D(1,10,1),o=n,P=o,a=s.dZero,S=!0;S;)if(i.eq(D(1,10,1))?a=o.mul(2):a=i.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:i=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 n=t;t=Math.trunc(t);let i=n-t;i!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(i)):this.eq(10)?e=e.layeradd10(i,r):e=e.layeradd(i,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,n){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(n)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=n.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(n=n.sub(t).div(e).add(t))),n}static softcap(t,e,r,n){return new s(t).softcap(e,r,n)}scale(t,e,r,n=!1){t=new s(t),e=new s(e);let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=n?i.mul(t.pow(e.sub(1))).root(e):i.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(i=n?i.div(t).max(1).log(e).add(t):s.pow(e,i.sub(t)).mul(t))),i}static scale(t,e,r,n,i=!1){return new s(t).scale(e,r,n,i)}format(t=2,e=9,r="mixed_sc"){return dt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,n="mixed_sc"){return dt.format(new s(t),e,r,n)}formatST(t=2,e=9,r="st"){return dt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,n="st"){return dt.format(new s(t),e,r,n)}formatGain(t,e="mixed_sc",r,n){return dt.formatGain(this.clone(),t,e,r,n)}static formatGain(t,e,r="mixed_sc",n,i){return dt.formatGain(new s(t),e,r,n,i)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),n={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},i="";for(let o of Object.keys(n)){let c=Math.floor(r/n[o]);r-=c*n[o],i+=o.repeat(c)}return i}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 Qt(ze),at([Et()],s.prototype,"sign",2),at([Et()],s.prototype,"mag",2),at([Et()],s.prototype,"layer",2),s=at([De()],s);var{formats:dt,FORMATS:Lr}=Re(s);s.formats=dt;var It=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}},se=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 It(r))})}getBoosts(t,e){let r=[],n=[];for(let i=0;il),f=i,p=this.getBoosts(o,!0);p[0][0]?this.boostArray[p[1][0]]=new It({id:o,name:c,description:m,value:d,order:f}):this.boostArray.push(new It({id:o,name:c,description:m,value:d,order:f}))}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 It(o):this.boostArray.push(new It(o))}}}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((n,i)=>n.order-i.order);for(let n of r)e=n.value(e);return e}},kr=ft(pt()),Rt=30,jt=.001;function Ke(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 new s(2).div(t.reciprocal().add(e.reciprocal()))}}function oe(t,e,r,n){n=Object.assign({},{verbose:!1,mode:"geometric"},n),t=new s(t),e=new s(e),r=new s(r);let i,o;return n.mode==="geometric"?(i=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=i.lte(r)):(i=t.sub(e).abs(),o=i.lte(r)),(n.verbose===!0||n.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:n,diff:i,result:o}),o}function ae(t,e,r="geometric",n=Rt,i=jt){let o=new s(1),c=new s(e);if(t(c).eq(0))return{value:new s(0),lowerBound:new s(0),upperBound:new s(0)};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 d=0;d=0;m--){let d=r.add(c.mul(m)),f=r.add(c.mul(m+1)),p=o;if(o=o.add(t(d).add(t(f)).div(2).mul(c)),oe(p,o,i,{verbose:!1,mode:"geometric"}))break}return o}function ue(t,e,r=0,n,i){return r=new s(r),e=new s(e),e.sub(r).lte(Rt)?tr(t,e,r,n):er(t,e,r,i)}function rr(t,e,r,n=1/0,i,o,c=!1){t=new s(t),r=new s(r??e.level),n=new s(n);let m=n.sub(r);if(m.lt(0))return console.warn("calculateUpgrade: Invalid target: ",m),[new s(0),new s(0)];if(c=(typeof e.el=="function"?e.el():e.el)??c,m.eq(1)){let l=e.cost(e.level),u=t.gte(l),h=[new s(0),new s(0)];return c?(h[0]=u?new s(1):new s(0),h):(h=[u?new s(1):new s(0),u?l:new s(0)],h)}if(e.costBulk){let[l,u]=e.costBulk(t,e.level,m),h=t.gte(u);return[h?l:new s(0),h&&!c?u:new s(0)]}if(c){let l=g=>e.cost(g.add(r)),u=s.min(n,ae(l,t,i,o).value.floor()),h=new s(0);return[u,h]}let d=ae(l=>ue(e.cost,l,r),t,i,o).value.floor().min(r.add(m).sub(1)),f=ue(e.cost,d,r);return[d.sub(r).add(1).max(0),f]}var vt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):new s(1)}};at([Et()],vt.prototype,"id",2),at([Ft(()=>s)],vt.prototype,"level",2);var nr=class be{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:new s(1)}}).data??{level:new s(1)}).level}set level(e){this.data.level=new s(e)}constructor(e,r,n){let i=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>i,this.cache=new Qt(n??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??new s(1)}},qr=ft(pt()),wt=class{constructor(){this.value=new s(0),this.upgrades={}}};at([Ft(()=>s)],wt.prototype,"value",2),at([Ft(()=>vt)],wt.prototype,"upgrades",2);var ir=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new wt,e,r={defaultVal:new s(0),defaultBoost:new s(1)}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new se(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 n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),r&&n.effect?.(n.level,n,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 vt(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 n of t){let i=this.pointerAddUpgrade(n),o=new nr(n,()=>this.pointerGetUpgrade(n.id));o.effect&&e&&o.effect(o.level,o,this),r[n.id]=o,this.upgrades[n.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,n){let i=this.getUpgrade(t);return i===null?(console.warn(`Upgrade "${t}" not found.`),[new s(0),new s(0)]):(e=i.level.add(e),i.maxLevel!==void 0&&(e=s.min(e,i.maxLevel)),rr(this.value,i,i.level,e,r,n))}getNextCost(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n)[0];return i.cost(i.level.add(o))}getNextCostMax(t,e=1,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),new s(0);let o=this.calculateUpgrade(t,e,r,n);return i.cost(i.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,n){let i=this.getUpgrade(t);if(i===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,c]=this.calculateUpgrade(t,e,r,n);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),i.level=i.level.add(o),i.effect?.(i.level,i,this),!0)}},Br=ft(pt()),Ut=class{constructor(t=0){this.value=new s(t)}};at([Ft(()=>s)],Ut.prototype,"value",2);var sr=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new Ut(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new se(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}},Dr=(()=>{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})(),Rr=ft(pt()),Gt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,n){for(let i in n)typeof r[i]>"u"?r[i]=n[i]:typeof r[i]=="object"&&typeof n[i]=="object"&&!Array.isArray(r[i])&&!Array.isArray(n[i])&&(r[i]=e(r[i],n[i]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},or={autoAddInterval:!0,fps:30},jr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),ar=class Me{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=Me.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let n of this.tickers)n(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let n of this.binds)(typeof n.onDownContinuous<"u"||typeof n.fn<"u")&&this.isPressing(n.id)&&(n.onDownContinuous?.(r),n.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 Gt(or)}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 n=e.key;r&&!this.keysPressed.includes(n)?this.keysPressed.push(n):!r&&this.keysPressed.includes(n)&&this.keysPressed.splice(this.keysPressed.indexOf(n),1)}onAll(e,r){for(let n of this.binds)if(n.key===r)switch(e){case"down":n.onDown?.();break;case"press":default:n.onPress?.();break;case"up":n.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,n){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:n}]:e,e=Array.isArray(e)?e:[e];for(let i of e){i.id=i.id??i.name;let o=this.getBind(i.id);if(o){Object.assign(o,i);continue}this.binds.push(i)}}},ur={autoAddInterval:!0,fps:30},fr=class _e{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=_e.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 Gt(ur)}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 n=e-r.intervalLast;r.callbackFn(n),r.intervalLast=e}break;case"timeout":{let n=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(n),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,n,i){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof n=="number"?n:n.toNumber(),callbackFn:i,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},Ur=ft(pt()),fe=ft(Te()),Yt=ft(Ce()),lr=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(n){r()[t]=n},setValue(n){r()[t]=n}}}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=kt(this.data)}compileDataRaw(t=this.data){let e=kt(t),r=(0,Yt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),n;try{n="9.0.0"}catch{n="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:n}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,fe.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,fe.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,Yt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let n=e.hash,i=(0,Yt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return n===i}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 n(p){return typeof p=="object"&&p?.constructor===Object}let i=(p,l)=>Object.prototype.hasOwnProperty.call(p,l);function o(p,l,u){if(!p||!l||!u)throw new Error("dataManager.deepMerge(): Missing arguments.");let h=u;for(let g in p)if(i(p,g)&&!i(u,g)&&(h[g]=p[g]),l[g]instanceof wt){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 n(p[g])&&n(u[g])&&(h[g]=o(p[g],l[g],u[g]));return h}let c=e?o(this.normalDataPlain,this.normalData,r):r,m=Object.getOwnPropertyNames(new vt({id:"",level:new s(0)}));function d(p,l){let u=ee(p,l);if(u instanceof wt)for(let h in u.upgrades){let g=u.upgrades[h];if(!g||!m.every(N=>Object.getOwnPropertyNames(g).includes(N))){delete u.upgrades[h];continue}u.upgrades[h]=ee(vt,g)}if(!u)throw new Error(`Failed to convert ${p.name} to class instance.`);return u}function f(p,l){if(!p||!l)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let u=l;for(let h in p){if(l[h]===void 0){console.warn(`Missing property "${h}" in loaded data.`);continue}if(!n(l[h]))continue;let g=p[h].constructor;if(g===Object){u[h]=f(p[h],l[h]);continue}u[h]=d(g,l[h])}return u}return c=f(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],kt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let n of this.eventsOnLoad)n();return e}},cr=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,n){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=n,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},hr=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}},mr=class{constructor(t,e){this.currenciesToReset=Array.isArray(t)?t:[t],this.extender=Array.isArray(e)?e:e?[e]:[],this.id=Symbol()}reset(){this.onReset?.(this),this.currenciesToReset.forEach(t=>{t.static.reset()}),this.extender.forEach(t=>{t.id!==this.id&&t.reset()})}},dr={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Gr=class Se{static{this.configManager=new Gt(dr)}constructor(e){this.config=Se.configManager.parse(e),this.dataManager=new lr(this),this.keyManager=new ar({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new fr({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 wt}),this.dataManager.setStatic(e,{currency:new ir(()=>this.dataManager.getData(e).currency,r)}),new cr(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,n=0){return this.dataManager.setData(e,new Ut(n)),this.dataManager.setStatic(e,new sr(this.dataManager.getData(e),r,n)),new hr(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(e,r){return new mr(e,r)}};function Ct(t,e){e=Object.assign({formatType:"mixed_sc",acc:2,max:9},e);let{formatType:r,acc:n,max:i,time:o,multi:c,formatTimeType:m}=e;if(o)switch(m){case"short":return s.formats.formatTime(t,n,r);case"long":return s.formats.formatTimeLong(t,!0,0,i,r)}return c?s.formats.formatMult(t,n):s.format(t,n,i,r)}function le(t,e,r){let{formatType:n,acc:i,max:o}=r;return s.formatGain(t,e,n,i,o)}var gr=class{constructor(t){this.format=e=>Ct(e,this.settings),this.gain=(e,r)=>le(e,r,this.settings),this.time=e=>Ct(e,{...this.settings,time:!0}),this.multi=e=>Ct(e,{...this.settings,multi:!0}),this.settingsFn=typeof t=="function"?t:()=>t}get settings(){return this.settingsFn()}},pr=[{name:"Standard",value:"standard"},{name:"Scientific",value:"scientific"},{name:"Mixed Scientific (default)",value:"mixed_sc"},{name:"Old Scientific",value:"old_sc"},{name:"Engineering",value:"eng"},{name:"Infinity",value:"inf"},{name:"Omega",value:"omega"},{name:"Omega Short",value:"omega_short"},{name:"Elemental",value:"elemental"},{name:"Layer",value:"layer"}].sort((t,e)=>t.name.localeCompare(e.name)),Nr=[{name:"Short (default)",value:"short"},{name:"Long",value:"long"}].sort((t,e)=>t.name.localeCompare(e.name));if(typeof st.exports=="object"&&typeof _t=="object"){var yr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,i)&&i!==r&&Object.defineProperty(t,i,{get:()=>e[i],enumerable:!(n=Object.getOwnPropertyDescriptor(e,i))||n.enumerable});return t};st.exports=yr(st.exports,_t)}return st.exports}); +/*! Bundled license information: + +reflect-metadata/Reflect.js: + (*! ***************************************************************************** + Copyright (C) Microsoft. All rights reserved. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of the + License at http://www.apache.org/licenses/LICENSE-2.0 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** *) + +is-buffer/index.js: + (*! + * Determine if an object is a Buffer + * + * @author Feross Aboukhadijeh + * @license MIT + *) +*/ diff --git a/dist/presets/eMath.presets.mjs b/dist/presets/eMath.presets.mjs index 5964bd11..5bcd1e0d 100644 --- a/dist/presets/eMath.presets.mjs +++ b/dist/presets/eMath.presets.mjs @@ -1,5 +1,28 @@ +var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __commonJS = (cb, mod) => function __require() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i = decorators.length - 1, decorator; i >= 0; i--) @@ -9,8 +32,715 @@ var __decorateClass = (decorators, target, key, kind) => { return result; }; -// src/E/e.ts -import { Exclude, Expose } from "class-transformer"; +// node_modules/lz-string/libs/lz-string.js +var require_lz_string = __commonJS({ + "node_modules/lz-string/libs/lz-string.js"(exports, module) { + var LZString = function() { + var f = String.fromCharCode; + var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$"; + var baseReverseDic = {}; + function getBaseValue(alphabet, character) { + if (!baseReverseDic[alphabet]) { + baseReverseDic[alphabet] = {}; + for (var i = 0; i < alphabet.length; i++) { + baseReverseDic[alphabet][alphabet.charAt(i)] = i; + } + } + return baseReverseDic[alphabet][character]; + } + var LZString2 = { + compressToBase64: function(input) { + if (input == null) return ""; + var res = LZString2._compress(input, 6, function(a) { + return keyStrBase64.charAt(a); + }); + switch (res.length % 4) { + default: + case 0: + return res; + case 1: + return res + "==="; + case 2: + return res + "=="; + case 3: + return res + "="; + } + }, + decompressFromBase64: function(input) { + if (input == null) return ""; + if (input == "") return null; + return LZString2._decompress(input.length, 32, function(index) { + return getBaseValue(keyStrBase64, input.charAt(index)); + }); + }, + compressToUTF16: function(input) { + if (input == null) return ""; + return LZString2._compress(input, 15, function(a) { + return f(a + 32); + }) + " "; + }, + decompressFromUTF16: function(compressed) { + if (compressed == null) return ""; + if (compressed == "") return null; + return LZString2._decompress(compressed.length, 16384, function(index) { + return compressed.charCodeAt(index) - 32; + }); + }, + //compress into uint8array (UCS-2 big endian format) + compressToUint8Array: function(uncompressed) { + var compressed = LZString2.compress(uncompressed); + var buf = new Uint8Array(compressed.length * 2); + for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) { + var current_value = compressed.charCodeAt(i); + buf[i * 2] = current_value >>> 8; + buf[i * 2 + 1] = current_value % 256; + } + return buf; + }, + //decompress from uint8array (UCS-2 big endian format) + decompressFromUint8Array: function(compressed) { + if (compressed === null || compressed === void 0) { + return LZString2.decompress(compressed); + } else { + var buf = new Array(compressed.length / 2); + for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) { + buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1]; + } + var result = []; + buf.forEach(function(c) { + result.push(f(c)); + }); + return LZString2.decompress(result.join("")); + } + }, + //compress into a string that is already URI encoded + compressToEncodedURIComponent: function(input) { + if (input == null) return ""; + return LZString2._compress(input, 6, function(a) { + return keyStrUriSafe.charAt(a); + }); + }, + //decompress from an output of compressToEncodedURIComponent + decompressFromEncodedURIComponent: function(input) { + if (input == null) return ""; + if (input == "") return null; + input = input.replace(/ /g, "+"); + return LZString2._decompress(input.length, 32, function(index) { + return getBaseValue(keyStrUriSafe, input.charAt(index)); + }); + }, + compress: function(uncompressed) { + return LZString2._compress(uncompressed, 16, function(a) { + return f(a); + }); + }, + _compress: function(uncompressed, bitsPerChar, getCharFromInt) { + if (uncompressed == null) return ""; + var i, value, context_dictionary = {}, context_dictionaryToCreate = {}, context_c = "", context_wc = "", context_w = "", context_enlargeIn = 2, context_dictSize = 3, context_numBits = 2, context_data = [], context_data_val = 0, context_data_position = 0, ii; + for (ii = 0; ii < uncompressed.length; ii += 1) { + context_c = uncompressed.charAt(ii); + if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) { + context_dictionary[context_c] = context_dictSize++; + context_dictionaryToCreate[context_c] = true; + } + context_wc = context_w + context_c; + if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) { + context_w = context_wc; + } else { + if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) { + if (context_w.charCodeAt(0) < 256) { + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + } + value = context_w.charCodeAt(0); + for (i = 0; i < 8; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } else { + value = 1; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = 0; + } + value = context_w.charCodeAt(0); + for (i = 0; i < 16; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + delete context_dictionaryToCreate[context_w]; + } else { + value = context_dictionary[context_w]; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + context_dictionary[context_wc] = context_dictSize++; + context_w = String(context_c); + } + } + if (context_w !== "") { + if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) { + if (context_w.charCodeAt(0) < 256) { + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + } + value = context_w.charCodeAt(0); + for (i = 0; i < 8; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } else { + value = 1; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = 0; + } + value = context_w.charCodeAt(0); + for (i = 0; i < 16; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + delete context_dictionaryToCreate[context_w]; + } else { + value = context_dictionary[context_w]; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + } + context_enlargeIn--; + if (context_enlargeIn == 0) { + context_enlargeIn = Math.pow(2, context_numBits); + context_numBits++; + } + } + value = 2; + for (i = 0; i < context_numBits; i++) { + context_data_val = context_data_val << 1 | value & 1; + if (context_data_position == bitsPerChar - 1) { + context_data_position = 0; + context_data.push(getCharFromInt(context_data_val)); + context_data_val = 0; + } else { + context_data_position++; + } + value = value >> 1; + } + while (true) { + context_data_val = context_data_val << 1; + if (context_data_position == bitsPerChar - 1) { + context_data.push(getCharFromInt(context_data_val)); + break; + } else context_data_position++; + } + return context_data.join(""); + }, + decompress: function(compressed) { + if (compressed == null) return ""; + if (compressed == "") return null; + return LZString2._decompress(compressed.length, 32768, function(index) { + return compressed.charCodeAt(index); + }); + }, + _decompress: function(length, resetValue, getNextValue) { + var dictionary = [], next, enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = { val: getNextValue(0), position: resetValue, index: 1 }; + for (i = 0; i < 3; i += 1) { + dictionary[i] = i; + } + bits = 0; + maxpower = Math.pow(2, 2); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + switch (next = bits) { + case 0: + bits = 0; + maxpower = Math.pow(2, 8); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + c = f(bits); + break; + case 1: + bits = 0; + maxpower = Math.pow(2, 16); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + c = f(bits); + break; + case 2: + return ""; + } + dictionary[3] = c; + w = c; + result.push(c); + while (true) { + if (data.index > length) { + return ""; + } + bits = 0; + maxpower = Math.pow(2, numBits); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + switch (c = bits) { + case 0: + bits = 0; + maxpower = Math.pow(2, 8); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + dictionary[dictSize++] = f(bits); + c = dictSize - 1; + enlargeIn--; + break; + case 1: + bits = 0; + maxpower = Math.pow(2, 16); + power = 1; + while (power != maxpower) { + resb = data.val & data.position; + data.position >>= 1; + if (data.position == 0) { + data.position = resetValue; + data.val = getNextValue(data.index++); + } + bits |= (resb > 0 ? 1 : 0) * power; + power <<= 1; + } + dictionary[dictSize++] = f(bits); + c = dictSize - 1; + enlargeIn--; + break; + case 2: + return result.join(""); + } + if (enlargeIn == 0) { + enlargeIn = Math.pow(2, numBits); + numBits++; + } + if (dictionary[c]) { + entry = dictionary[c]; + } else { + if (c === dictSize) { + entry = w + w.charAt(0); + } else { + return null; + } + } + result.push(entry); + dictionary[dictSize++] = w + entry.charAt(0); + enlargeIn--; + w = entry; + if (enlargeIn == 0) { + enlargeIn = Math.pow(2, numBits); + numBits++; + } + } + } + }; + return LZString2; + }(); + if (typeof define === "function" && define.amd) { + define(function() { + return LZString; + }); + } else if (typeof module !== "undefined" && module != null) { + module.exports = LZString; + } else if (typeof angular !== "undefined" && angular != null) { + angular.module("LZString", []).factory("LZString", function() { + return LZString; + }); + } + } +}); + +// node_modules/crypt/crypt.js +var require_crypt = __commonJS({ + "node_modules/crypt/crypt.js"(exports, module) { + (function() { + var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt = { + // Bit-wise rotation left + rotl: function(n, b) { + return n << b | n >>> 32 - b; + }, + // Bit-wise rotation right + rotr: function(n, b) { + return n << 32 - b | n >>> b; + }, + // Swap big-endian to little-endian and vice versa + endian: function(n) { + if (n.constructor == Number) { + return crypt.rotl(n, 8) & 16711935 | crypt.rotl(n, 24) & 4278255360; + } + for (var i = 0; i < n.length; i++) + n[i] = crypt.endian(n[i]); + return n; + }, + // Generate an array of any length of random bytes + randomBytes: function(n) { + for (var bytes = []; n > 0; n--) + bytes.push(Math.floor(Math.random() * 256)); + return bytes; + }, + // Convert a byte array to big-endian 32-bit words + bytesToWords: function(bytes) { + for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8) + words[b >>> 5] |= bytes[i] << 24 - b % 32; + return words; + }, + // Convert big-endian 32-bit words to a byte array + wordsToBytes: function(words) { + for (var bytes = [], b = 0; b < words.length * 32; b += 8) + bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255); + return bytes; + }, + // Convert a byte array to a hex string + bytesToHex: function(bytes) { + for (var hex = [], i = 0; i < bytes.length; i++) { + hex.push((bytes[i] >>> 4).toString(16)); + hex.push((bytes[i] & 15).toString(16)); + } + return hex.join(""); + }, + // Convert a hex string to a byte array + hexToBytes: function(hex) { + for (var bytes = [], c = 0; c < hex.length; c += 2) + bytes.push(parseInt(hex.substr(c, 2), 16)); + return bytes; + }, + // Convert a byte array to a base-64 string + bytesToBase64: function(bytes) { + for (var base64 = [], i = 0; i < bytes.length; i += 3) { + var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2]; + for (var j = 0; j < 4; j++) + if (i * 8 + j * 6 <= bytes.length * 8) + base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63)); + else + base64.push("="); + } + return base64.join(""); + }, + // Convert a base-64 string to a byte array + base64ToBytes: function(base64) { + base64 = base64.replace(/[^A-Z0-9+\/]/ig, ""); + for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) { + if (imod4 == 0) continue; + bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2); + } + return bytes; + } + }; + module.exports = crypt; + })(); + } +}); + +// node_modules/charenc/charenc.js +var require_charenc = __commonJS({ + "node_modules/charenc/charenc.js"(exports, module) { + var charenc = { + // UTF-8 encoding + utf8: { + // Convert a string to a byte array + stringToBytes: function(str) { + return charenc.bin.stringToBytes(unescape(encodeURIComponent(str))); + }, + // Convert a byte array to a string + bytesToString: function(bytes) { + return decodeURIComponent(escape(charenc.bin.bytesToString(bytes))); + } + }, + // Binary encoding + bin: { + // Convert a string to a byte array + stringToBytes: function(str) { + for (var bytes = [], i = 0; i < str.length; i++) + bytes.push(str.charCodeAt(i) & 255); + return bytes; + }, + // Convert a byte array to a string + bytesToString: function(bytes) { + for (var str = [], i = 0; i < bytes.length; i++) + str.push(String.fromCharCode(bytes[i])); + return str.join(""); + } + } + }; + module.exports = charenc; + } +}); + +// node_modules/is-buffer/index.js +var require_is_buffer = __commonJS({ + "node_modules/is-buffer/index.js"(exports, module) { + module.exports = function(obj) { + return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer); + }; + function isBuffer(obj) { + return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj); + } + function isSlowBuffer(obj) { + return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0)); + } + } +}); + +// node_modules/md5/md5.js +var require_md5 = __commonJS({ + "node_modules/md5/md5.js"(exports, module) { + (function() { + var crypt = require_crypt(), utf8 = require_charenc().utf8, isBuffer = require_is_buffer(), bin = require_charenc().bin, md52 = function(message, options) { + if (message.constructor == String) + if (options && options.encoding === "binary") + message = bin.stringToBytes(message); + else + message = utf8.stringToBytes(message); + else if (isBuffer(message)) + message = Array.prototype.slice.call(message, 0); + else if (!Array.isArray(message) && message.constructor !== Uint8Array) + message = message.toString(); + var m = crypt.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878; + for (var i = 0; i < m.length; i++) { + m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360; + } + m[l >>> 5] |= 128 << l % 32; + m[(l + 64 >>> 9 << 4) + 14] = l; + var FF = md52._ff, GG = md52._gg, HH = md52._hh, II = md52._ii; + for (var i = 0; i < m.length; i += 16) { + var aa = a, bb = b, cc = c, dd = d; + a = FF(a, b, c, d, m[i + 0], 7, -680876936); + d = FF(d, a, b, c, m[i + 1], 12, -389564586); + c = FF(c, d, a, b, m[i + 2], 17, 606105819); + b = FF(b, c, d, a, m[i + 3], 22, -1044525330); + a = FF(a, b, c, d, m[i + 4], 7, -176418897); + d = FF(d, a, b, c, m[i + 5], 12, 1200080426); + c = FF(c, d, a, b, m[i + 6], 17, -1473231341); + b = FF(b, c, d, a, m[i + 7], 22, -45705983); + a = FF(a, b, c, d, m[i + 8], 7, 1770035416); + d = FF(d, a, b, c, m[i + 9], 12, -1958414417); + c = FF(c, d, a, b, m[i + 10], 17, -42063); + b = FF(b, c, d, a, m[i + 11], 22, -1990404162); + a = FF(a, b, c, d, m[i + 12], 7, 1804603682); + d = FF(d, a, b, c, m[i + 13], 12, -40341101); + c = FF(c, d, a, b, m[i + 14], 17, -1502002290); + b = FF(b, c, d, a, m[i + 15], 22, 1236535329); + a = GG(a, b, c, d, m[i + 1], 5, -165796510); + d = GG(d, a, b, c, m[i + 6], 9, -1069501632); + c = GG(c, d, a, b, m[i + 11], 14, 643717713); + b = GG(b, c, d, a, m[i + 0], 20, -373897302); + a = GG(a, b, c, d, m[i + 5], 5, -701558691); + d = GG(d, a, b, c, m[i + 10], 9, 38016083); + c = GG(c, d, a, b, m[i + 15], 14, -660478335); + b = GG(b, c, d, a, m[i + 4], 20, -405537848); + a = GG(a, b, c, d, m[i + 9], 5, 568446438); + d = GG(d, a, b, c, m[i + 14], 9, -1019803690); + c = GG(c, d, a, b, m[i + 3], 14, -187363961); + b = GG(b, c, d, a, m[i + 8], 20, 1163531501); + a = GG(a, b, c, d, m[i + 13], 5, -1444681467); + d = GG(d, a, b, c, m[i + 2], 9, -51403784); + c = GG(c, d, a, b, m[i + 7], 14, 1735328473); + b = GG(b, c, d, a, m[i + 12], 20, -1926607734); + a = HH(a, b, c, d, m[i + 5], 4, -378558); + d = HH(d, a, b, c, m[i + 8], 11, -2022574463); + c = HH(c, d, a, b, m[i + 11], 16, 1839030562); + b = HH(b, c, d, a, m[i + 14], 23, -35309556); + a = HH(a, b, c, d, m[i + 1], 4, -1530992060); + d = HH(d, a, b, c, m[i + 4], 11, 1272893353); + c = HH(c, d, a, b, m[i + 7], 16, -155497632); + b = HH(b, c, d, a, m[i + 10], 23, -1094730640); + a = HH(a, b, c, d, m[i + 13], 4, 681279174); + d = HH(d, a, b, c, m[i + 0], 11, -358537222); + c = HH(c, d, a, b, m[i + 3], 16, -722521979); + b = HH(b, c, d, a, m[i + 6], 23, 76029189); + a = HH(a, b, c, d, m[i + 9], 4, -640364487); + d = HH(d, a, b, c, m[i + 12], 11, -421815835); + c = HH(c, d, a, b, m[i + 15], 16, 530742520); + b = HH(b, c, d, a, m[i + 2], 23, -995338651); + a = II(a, b, c, d, m[i + 0], 6, -198630844); + d = II(d, a, b, c, m[i + 7], 10, 1126891415); + c = II(c, d, a, b, m[i + 14], 15, -1416354905); + b = II(b, c, d, a, m[i + 5], 21, -57434055); + a = II(a, b, c, d, m[i + 12], 6, 1700485571); + d = II(d, a, b, c, m[i + 3], 10, -1894986606); + c = II(c, d, a, b, m[i + 10], 15, -1051523); + b = II(b, c, d, a, m[i + 1], 21, -2054922799); + a = II(a, b, c, d, m[i + 8], 6, 1873313359); + d = II(d, a, b, c, m[i + 15], 10, -30611744); + c = II(c, d, a, b, m[i + 6], 15, -1560198380); + b = II(b, c, d, a, m[i + 13], 21, 1309151649); + a = II(a, b, c, d, m[i + 4], 6, -145523070); + d = II(d, a, b, c, m[i + 11], 10, -1120210379); + c = II(c, d, a, b, m[i + 2], 15, 718787259); + b = II(b, c, d, a, m[i + 9], 21, -343485551); + a = a + aa >>> 0; + b = b + bb >>> 0; + c = c + cc >>> 0; + d = d + dd >>> 0; + } + return crypt.endian([a, b, c, d]); + }; + md52._ff = function(a, b, c, d, x, s, t) { + var n = a + (b & c | ~b & d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._gg = function(a, b, c, d, x, s, t) { + var n = a + (b & d | c & ~d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._hh = function(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._ii = function(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + (x >>> 0) + t; + return (n << s | n >>> 32 - s) + b; + }; + md52._blocksize = 16; + md52._digestsize = 16; + module.exports = function(message, options) { + if (message === void 0 || message === null) + throw new Error("Illegal argument " + message); + var digestbytes = crypt.wordsToBytes(md52(message, options)); + return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt.bytesToHex(digestbytes); + }; + })(); + } +}); + +// src/index.ts +import "reflect-metadata"; // src/E/lru-cache.ts var LRUCache = class { @@ -115,6 +845,9 @@ var ListNode = class { } }; +// src/E/e.ts +import { Exclude, Expose } from "class-transformer"; + // src/E/format.ts var ST_NAMES = [ [ @@ -370,7 +1103,7 @@ function decimalFormatGenerator(Decimal2) { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format(value, acc = 2) { if (value.gt(new Decimal2(118).pow(new Decimal2(118).pow(new Decimal2(118).pow(4))))) return "e" + FORMATS2.elemental.format(value.log10(), acc); @@ -4815,6 +5548,1630 @@ Decimal = __decorateClass([ var { formats, FORMATS } = decimalFormatGenerator(Decimal); Decimal.formats = formats; +// src/classes/Boost.ts +var BoostObject = class { + // eslint-disable-next-line jsdoc/require-returns + /** @deprecated Use {@link description} instead */ + get desc() { + return this.description; + } + get description() { + return this.descriptionFn(); + } + 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; + } +}; +var Boost = class { + /** + * Constructs a new boost manager. + * @param baseEffect - The base effect value to which boosts are applied. + * @param boosts - An array of boost objects to initialize with. + */ + constructor(baseEffect = 1, boosts) { + /** + * @alias setBoost + * @deprecated Use {@link setBoost} instead. + */ + this.addBoost = this.setBoost.bind(this); + boosts = boosts ? Array.isArray(boosts) ? boosts : [boosts] : void 0; + this.baseEffect = new Decimal(baseEffect); + this.boostArray = []; + if (boosts) { + boosts.forEach((boostObj) => { + this.boostArray.push(new BoostObject(boostObj)); + }); + } + } + getBoosts(id, index) { + const boostList = []; + const indexList = []; + for (let i = 0; i < this.boostArray.length; i++) { + if (typeof id === "string" && id === this.boostArray[i].id || id instanceof RegExp && id.test(this.boostArray[i].id)) { + boostList.push(this.boostArray[i]); + indexList.push(i); + } + } + return index ? [boostList, indexList] : boostList; + } + /** + * Gets a boost object by its ID. + * @deprecated Use {@link getBoosts} instead. + * @param id - The ID of the boost to retrieve. + * @returns The boost object if found, or null if not found. + */ + getBoost(id) { + return this.getBoosts(id)[0] ?? null; + } + /** + * Removes a boost by its ID. Only removes the first instance of the id. + * @param id - The ID of the boost to remove. + * @example + * // Remove the boost with the ID "healthBoost" + * boost.removeBoost("healthBoost"); + */ + removeBoost(id) { + for (let i = 0; i < this.boostArray.length; i++) { + if (id === this.boostArray[i].id) { + this.boostArray.splice(i, 1); + break; + } + } + } + setBoost(arg1, arg2, arg3, arg4, arg5) { + if (!arg1) return; + if (typeof arg1 === "string") { + const id = arg1; + const name = arg2 ?? ""; + const description = arg3 ?? ""; + const value = arg4 ?? ((e) => e); + const order = arg5; + const bCheck = this.getBoosts(id, true); + if (!bCheck[0][0]) { + this.boostArray.push(new BoostObject({ id, name, description, value, order })); + } else { + this.boostArray[bCheck[1][0]] = new BoostObject({ id, name, description, value, order }); + } + } else { + arg1 = Array.isArray(arg1) ? arg1 : [arg1]; + for (const boost of arg1) { + const bCheck = this.getBoosts(boost.id, true); + if (!bCheck[0][0]) { + this.boostArray.push(new BoostObject(boost)); + } else { + this.boostArray[bCheck[1][0]] = new BoostObject(boost); + } + } + } + } + /** + * Calculates the cumulative effect of all boosts on the base effect. + * @param base - The base effect value to calculate with. Defaults to the base effect of the boost manager. + * @returns The calculated effect after applying boosts. + * @example + * // Calculate the effect of all boosts + * const finalEffect = boost.calculate(); + */ + calculate(base = this.baseEffect) { + let output = new Decimal(base); + let boosts = this.boostArray; + boosts = boosts.sort((a, b) => a.order - b.order); + for (const boost of boosts) { + output = boost.value(output); + } + return output; + } +}; + +// src/classes/Upgrade.ts +import "reflect-metadata"; +import { Type, Expose as Expose2 } from "class-transformer"; + +// src/classes/numericalAnalysis.ts +var DEFAULT_ITERATIONS = 30; +var DEFAULT_TOLERANCE = 1e-3; +function mean(a, b, mode = "geometric") { + a = new Decimal(a); + b = new Decimal(b); + switch (mode) { + case "arithmetic": + case 1: + return a.add(b).div(2); + case "geometric": + case 2: + default: + return a.mul(b).sqrt(); + case "harmonic": + case 3: + return new Decimal(2).div(a.reciprocal().add(b.reciprocal())); + } +} +function equalsTolerance(a, b, tolerance, config) { + config = Object.assign({}, { + verbose: false, + mode: "geometric" + }, config); + a = new Decimal(a); + b = new Decimal(b); + tolerance = new Decimal(tolerance); + let diff; + let result; + if (config.mode === "geometric") { + diff = a.sub(b).abs().div(a.abs().add(b.abs()).div(2)); + result = diff.lte(tolerance); + } else { + diff = a.sub(b).abs(); + result = diff.lte(tolerance); + } + if (config.verbose === true || config.verbose === "onlyOnFail" && !result) console.log({ a, b, tolerance, config, diff, result }); + return result; +} +function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_ITERATIONS, tolerance = DEFAULT_TOLERANCE) { + let lowerBound = new Decimal(1); + let upperBound = new Decimal(n); + if (f(upperBound).eq(0)) { + return { + value: new Decimal(0), + lowerBound: new Decimal(0), + upperBound: new Decimal(0) + }; + } + if (f(upperBound).lt(n)) { + console.warn("The function is not monotonically increasing. (f(n) < n)"); + return { + value: upperBound, + lowerBound: upperBound, + upperBound + }; + } + for (let i = 0; i < iterations; i++) { + const mid = mean(lowerBound, upperBound, mode); + const midValue = f(mid); + if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { + break; + } + if (midValue.lt(n)) { + lowerBound = mid; + } else { + upperBound = mid; + } + } + const out = { + value: lowerBound, + lowerBound, + upperBound + }; + return out; +} +function calculateSumLoop(f, b, a = 0, epsilon = DEFAULT_TOLERANCE) { + let sum = new Decimal(); + let n = new Decimal(b); + for (; n.gte(a); n = n.sub(1)) { + const initSum = sum; + const value = f(n); + sum = sum.add(value); + const diff = initSum.div(sum); + if (diff.lte(1) && diff.gt(new Decimal(1).sub(epsilon))) break; + } + return sum; +} +function calculateSumApprox(f, b, a = 0, iterations = DEFAULT_ITERATIONS, tolerance = DEFAULT_TOLERANCE * 2) { + a = new Decimal(a); + b = new Decimal(b); + let sum = new Decimal(0); + const intervalWidth = b.sub(a).div(iterations); + for (let i = iterations - 1; i >= 0; i--) { + const x0 = a.add(intervalWidth.mul(i)); + const x1 = a.add(intervalWidth.mul(i + 1)); + const oldSum = sum; + sum = sum.add(f(x0).add(f(x1)).div(2).mul(intervalWidth)); + if (equalsTolerance(oldSum, sum, tolerance, { verbose: false, mode: "geometric" })) { + break; + } + } + return sum; +} +function calculateSum(f, b, a = 0, epsilon, iterations) { + a = new Decimal(a); + b = new Decimal(b); + if (b.sub(a).lte(DEFAULT_ITERATIONS)) { + return calculateSumLoop(f, b, a, epsilon); + } else { + return calculateSumApprox(f, b, a, iterations); + } +} + +// src/classes/Upgrade.ts +function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iterations, el = false) { + value = new Decimal(value); + start = new Decimal(start ?? upgrade.level); + end = new Decimal(end); + const target = end.sub(start); + if (target.lt(0)) { + console.warn("calculateUpgrade: Invalid target: ", target); + return [new Decimal(0), new Decimal(0)]; + } + el = (typeof upgrade.el === "function" ? upgrade.el() : upgrade.el) ?? el; + if (target.eq(1)) { + const cost2 = upgrade.cost(upgrade.level); + const canAfford = value.gte(cost2); + let out = [new Decimal(0), new Decimal(0)]; + if (el) { + out[0] = canAfford ? new Decimal(1) : new Decimal(0); + return out; + } else { + out = [canAfford ? new Decimal(1) : new Decimal(0), canAfford ? cost2 : new Decimal(0)]; + return out; + } + } + if (upgrade.costBulk) { + const [amount, cost2] = upgrade.costBulk(value, upgrade.level, target); + const canAfford = value.gte(cost2); + const out = [canAfford ? amount : new Decimal(0), canAfford && !el ? cost2 : new Decimal(0)]; + return out; + } + if (el) { + const costTargetFn = (level) => upgrade.cost(level.add(start)); + const maxLevelAffordable2 = Decimal.min(end, inverseFunctionApprox(costTargetFn, value, mode, iterations).value.floor()); + const cost2 = new Decimal(0); + return [maxLevelAffordable2, cost2]; + } + const maxLevelAffordable = inverseFunctionApprox( + (x) => calculateSum(upgrade.cost, x, start), + value, + mode, + iterations + ).value.floor().min(start.add(target).sub(1)); + const cost = calculateSum(upgrade.cost, maxLevelAffordable, start); + const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0); + return [maxLevelAffordableActual, cost]; +} +var UpgradeData = class { + /** + * Constructs a new upgrade object with an initial level of 1 (or the provided level) + * @param init - The upgrade object to initialize. + */ + constructor(init) { + init = init ?? {}; + this.id = init.id; + this.level = init.level ? new Decimal(init.level) : new Decimal(1); + } +}; +__decorateClass([ + Expose2() +], UpgradeData.prototype, "id", 2); +__decorateClass([ + Type(() => Decimal) +], UpgradeData.prototype, "level", 2); +var UpgradeStatic = class _UpgradeStatic { + static { + /** The default size of the cache. Should be one less than a power of 2. */ + this.cacheSize = 15; + } + /** @returns The data of the upgrade. */ + get data() { + return this.dataPointerFn(); + } + get description() { + return this.descriptionFn(); + } + /** + * The current level of the upgrade. + * @returns The current level of the upgrade. + */ + get level() { + return ((this ?? { data: { level: new Decimal(1) } }).data ?? { level: new Decimal(1) }).level; + } + set level(n) { + this.data.level = new Decimal(n); + } + /** + * Constructs a new static upgrade object. + * @param init - The upgrade object to initialize. + * @param dataPointer - A function or reference that returns the pointer of the data / frontend. + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. + */ + constructor(init, dataPointer, cacheSize) { + const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; + this.dataPointerFn = typeof dataPointer === "function" ? dataPointer : () => data; + this.cache = new LRUCache(cacheSize ?? _UpgradeStatic.cacheSize); + this.id = init.id; + this.name = init.name ?? init.id; + this.descriptionFn = init.description ? typeof init.description === "function" ? init.description : () => init.description : () => ""; + this.cost = init.cost; + this.costBulk = init.costBulk; + this.maxLevel = init.maxLevel; + this.effect = init.effect; + this.el = init.el; + this.defaultLevel = init.level ?? new Decimal(1); + } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: DecimalSource, end: DecimalSource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: DecimalSource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: DecimalSource, end?: DecimalSource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? new Decimal(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: DecimalSource, end: DecimalSource, cost: DecimalSource): UpgradeCachedSum; + // public setCached(type: "el", level: DecimalSource, cost: DecimalSource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: DecimalSource, endOrStart: DecimalSource, costSum?: DecimalSource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: new Decimal(start), + // end: new Decimal(endOrStart), + // cost: new Decimal(costSum), + // } : { + // id: this.id, + // el: true, + // level: new Decimal(start), + // cost: new Decimal(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } +}; + +// src/classes/Currency.ts +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. + */ + constructor() { + this.value = new Decimal(0); + this.upgrades = {}; + } +}; +__decorateClass([ + Type2(() => Decimal) +], Currency.prototype, "value", 2); +__decorateClass([ + Type2(() => UpgradeData) +], Currency.prototype, "upgrades", 2); +var CurrencyStatic = class { + /** @returns The pointer of the data. */ + get pointer() { + return this.pointerFn(); + } + /** + * The current value of the currency. + * Note: If you want to change the value, use {@link gain} instead. + * @returns The current value of the currency. + */ + get value() { + return this.pointer.value; + } + set value(value) { + this.pointer.value = value; + } + /** + * Constructs a new currnecy + * @param pointer - A function or reference that returns the pointer of the data / frontend. + * @param upgrades - An array of upgrade objects. + * @param defaults - The default value and boost of the currency. + * @example + * const currency = new CurrencyStatic(undefined, [ + * { + * id: "upgId1", + * cost: (level: Decimal): Decimal => level.mul(10), + * }, + * { + * id: "upgId2", + * cost: (level: Decimal): Decimal => level.mul(20), + * } + * ] as const satisfies UpgradeInit[]); + * // CurrencyStatic<["upgId1", "upgId2"]> + */ + constructor(pointer = new Currency(), upgrades, defaults = { defaultVal: new Decimal(0), defaultBoost: new Decimal(1) }) { + this.defaultVal = defaults.defaultVal; + this.defaultBoost = defaults.defaultBoost; + 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; + // } + // }, + }; + if (upgrades) this.addUpgrade(upgrades); + } + /** + * Updates / applies effects to the currency on load. + */ + onLoadData() { + for (const upgrade of Object.values(this.upgrades)) { + upgrade.effect?.(upgrade.level, upgrade, this); + } + } + /** + * Resets the currency and upgrade levels. + * @param resetCurrency - Whether to reset the currency value. Default is true. + * @param resetUpgradeLevels - Whether to reset the upgrade levels. Default is true. + * @param runUpgradeEffect - Whether to run the upgrade effect. Default is true. + * @example + * currency.reset(); + * console.log(currency.value); // new Decimal(0), or the default value + */ + reset(resetCurrency = true, resetUpgradeLevels = true, runUpgradeEffect = true) { + if (resetCurrency) this.value = this.defaultVal; + if (resetUpgradeLevels) { + for (const upgrade of Object.values(this.upgrades)) { + upgrade.level = new Decimal(upgrade.defaultLevel); + if (runUpgradeEffect) upgrade.effect?.(upgrade.level, upgrade, this); + } + } + ; + } + /** + * The new currency value after applying the boost. + * @param dt - Deltatime / multipler in milliseconds, assuming you gain once every second. Ex. 500 = 0.5 seconds = half gain. + * @returns What was gained, NOT the new value. + * @example + * // Gain a random number between 1 and 10, and return the amount gained. + * currency.gain(Math.random() * 10000); + */ + gain(dt = 1e3) { + const toAdd = this.boost.calculate().mul(new Decimal(dt).div(1e3)); + this.pointer.value = this.pointer.value.add(toAdd); + return toAdd; + } + /** + * Adds an upgrade to the data class. + * @param upgrades - Upgrade to add + * @returns The upgrade object. + */ + pointerAddUpgrade(upgrades) { + const upgradesToAdd = new UpgradeData(upgrades); + this.pointer.upgrades[upgradesToAdd.id] = upgradesToAdd; + return upgradesToAdd; + } + /** + * Retrieves an upgrade object from the data pointer based on the provided id. + * @param id - The id of the upgrade to retrieve. + * @returns The upgrade object if found, otherwise null. + */ + pointerGetUpgrade(id) { + return this.pointer.upgrades[id] ?? null; + } + /** + * Retrieves an upgrade object based on the provided id. + * @template T - The type of the upgrade ID. + * @param id - The id of the upgrade to retrieve. + * @returns The upgrade object if found, otherwise null. + * @example + * const upgrade = currency.getUpgrade("healthBoost"); + * console.log(upgrade); // upgrade object + */ + getUpgrade(id) { + return this.upgrades[id] ?? null; + } + /** + * Creates upgrades. To update an upgrade, use {@link updateUpgrade} instead. + * @param upgrades - An array of upgrade objects. + * @param runEffectInstantly - Whether to run the effect immediately. Defaults to `true`. + * @returns The added upgrades. + * @example + * currency.addUpgrade({ + * id: "healthBoost", // The ID of the upgrade, used to retrieve it later + * name: "Health Boost", // The name of the upgrade, for display purposes (optional, defaults to the ID) + * description: "Increases health by 10.", // The description of the upgrade, for display purposes (optional, defaults to "") + * cost: (level) => level.mul(10), // Cost of the upgrade, 10 times the level + * maxLevel: 10, // Maximum level of the upgrade (optional, defaults to 1) + * // Effect of the upgrade (runs when the upgrade is bought, and instantly if runEffectInstantly is true) + * effect: (level, context) => { + * // Set / update the boost + * // health: currencyStatic + * health.boost.setBoost( + * "healthBoost", + * "Health Boost", + * "Boosts health by 2x per level.", + * n => n.mul(Decimal.pow(2, level.sub(1))), + * 2, + * ); + * } + * }); + */ + addUpgrade(upgrades, runEffectInstantly = true) { + if (!Array.isArray(upgrades)) upgrades = [upgrades]; + const addedUpgradeList = {}; + for (const upgrade of upgrades) { + const addedUpgradeData = 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; + } + return Object.values(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. + * @example + * currency.updateUpgrade("healthBoost", { + * name: "New Health Boost". + * cost: (level) => level.mul(20), + * maxLevel: 20, + * effect: (level, context) => { + * console.log("Health Boost effect"); + * } + * }); + */ + 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; + } + /** + * Calculates the cost and how many upgrades you can buy. + * See {@link calculateUpgrade} for more information. + * @param id - The ID or position of the upgrade to calculate. + * @param target - The target level or quantity to reach for the upgrade. If omitted, it calculates the maximum affordable quantity. + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The amount of upgrades you can buy and the cost of the upgrades. If you can't afford any, it returns [new Decimal(0), new Decimal(0)]. + * @example + * // 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) { + console.warn(`Upgrade "${id}" not found.`); + return [new Decimal(0), new Decimal(0)]; + } + target = upgrade.level.add(target); + if (upgrade.maxLevel !== void 0) { + target = Decimal.min(target, upgrade.maxLevel); + } + return calculateUpgrade(this.value, upgrade, upgrade.level, target, mode, iterations); + } + /** + * Calculates how much is needed for the next upgrade. + * @deprecated Use {@link getNextCostMax} instead as it is more versatile. + * @param id - Index or ID of the upgrade + * @param target - How many before the next upgrade + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The cost of the next upgrade. + * @example + * // Calculate the cost of the next healthBoost upgrade + * const nextCost = currency.getNextCost("healthBoost"); + */ + getNextCost(id, target = 1, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return new Decimal(0); + } + const amount = this.calculateUpgrade(id, target, mode, iterations)[0]; + const nextCost = upgrade.cost(upgrade.level.add(amount)); + return nextCost; + } + /** + * Calculates the cost of the next upgrade after the maximum affordable quantity. + * @param id - Index or ID of the upgrade + * @param target - How many before the next upgrade + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns The cost of the next upgrade. + * @example + * // Calculate the cost of the next healthBoost upgrade + * currency.gain(1e6); // Gain 1 thousand currency + * console.log(currency.calculateUpgrade("healthBoost")); // The maximum affordable quantity and the cost of the upgrades. Ex. [new Decimal(100), new Decimal(1000)] + * console.log(currency.getNextCostMax("healthBoost")); // The cost of the next upgrade after the maximum affordable quantity. (The cost of the 101st upgrade) + */ + getNextCostMax(id, target = 1, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return new Decimal(0); + } + const upgCalc = this.calculateUpgrade(id, target, mode, iterations); + const nextCost = upgrade.cost(upgrade.level.add(upgCalc[0])).add(upgCalc[1]); + return nextCost; + } + /** + * Buys an upgrade based on its ID or array position if enough currency is available. + * @param id - The ID or position of the upgrade to buy or upgrade. + * @param target - The target level or quantity to reach for the upgrade. See the argument in {@link calculateUpgrade}. + * @param mode - See the argument in {@link calculateUpgrade}. + * @param iterations - See the argument in {@link calculateUpgrade}. + * @returns Returns true if the purchase or upgrade is successful, or false if there is not enough currency or the upgrade does not exist. + * @example + * // Attempt to buy up to 10 healthBoost upgrades at once + * currency.buyUpgrade("healthBoost", 10); + */ + buyUpgrade(id, target, mode, iterations) { + const upgrade = this.getUpgrade(id); + if (upgrade === null) { + console.warn(`Upgrade "${id}" not found.`); + return false; + } + const [amount, cost] = this.calculateUpgrade(id, target, mode, iterations); + if (amount.lte(0)) { + return false; + } + this.pointer.value = this.pointer.value.sub(cost); + upgrade.level = upgrade.level.add(amount); + upgrade.effect?.(upgrade.level, upgrade, this); + return true; + } +}; + +// src/classes/Attribute.ts +import "reflect-metadata"; +import { Type as Type3 } from "class-transformer"; +var Attribute = class { + /** + * Constructs a static attribute with an initial effect. + * @param initial - The inital value of the attribute. + */ + constructor(initial = 0) { + this.value = new Decimal(initial); + } +}; +__decorateClass([ + Type3(() => Decimal) +], Attribute.prototype, "value", 2); +var AttributeStatic = class { + /** @returns The data for the attribute. */ + get pointer() { + return this.pointerFn(); + } + /** + * Constructs a new instance of the Attribute class. + * @param pointer - A function or an instance of the attribute class. Defaults to a new instance of the attribute class. + * @param useBoost - Indicates whether to use boost for the attribute. Defaults to true. (hint: if you don't use boost, don't use this class and use Decimal directly) + * @param initial - The initial value of the attribute. Defaults to 0. + */ + constructor(pointer, useBoost = true, initial = 0) { + this.initial = new Decimal(initial); + pointer ??= new Attribute(this.initial); + this.pointerFn = typeof pointer === "function" ? pointer : () => pointer; + this.boost = useBoost ? new Boost(this.initial) : null; + } + /** + * Updates the value of the attribute. + * NOTE: This method must be called every time the boost is updated, else the value stored will not be updated. + * @deprecated This is automatically called when the value is accessed. It will be removed in the future. + */ + update() { + console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."); + if (this.boost) { + this.pointer.value = this.boost.calculate(); + } + } + /** + * Gets the value of the attribute, and also updates the value stored. + * NOTE: This getter must be called every time the boost is updated, else the value stored will not be updated. + * @returns The calculated value of the attribute. + */ + get value() { + if (this.boost) { + this.pointer.value = this.boost.calculate(); + } + return this.pointer.value; + } + /** + * Sets the value of the attribute. + * NOTE: This setter should not be used when boost is enabled. + * @param value - The value to set the attribute to. + */ + set value(value) { + if (this.boost) { + throw new Error("Cannot set value of attributeStatic when boost is enabled."); + } + this.pointer.value = value; + } +}; + +// src/E/eMain.ts +var E = (() => { + let shownWarning = false; + const out = (x) => { + if (!shownWarning) { + console.warn("The E function is deprecated. Use the Decimal class directly."); + shownWarning = true; + } + return new Decimal(x); + }; + Object.getOwnPropertyNames(Decimal).filter((b) => !Object.getOwnPropertyNames(class { + }).includes(b)).forEach((prop) => { + out[prop] = Decimal[prop]; + }); + return out; +})(); + +// src/game/index.ts +import "reflect-metadata"; + +// src/game/managers/ConfigManager.ts +var ConfigManager = class { + /** + * Constructs a new configuration manager. + * @param configOptionTemplate - The template to use for default values. + */ + constructor(configOptionTemplate) { + this.configOptionTemplate = configOptionTemplate; + } + /** + * Parses the given configuration object and returns a new object with default values for any missing options. + * @param config - The configuration object to parse. + * @returns A new object with default values for any missing options. + */ + parse(config) { + if (typeof config === "undefined") { + return this.configOptionTemplate; + } + function parseObject(obj, template) { + for (const key in template) { + if (typeof obj[key] === "undefined") { + obj[key] = template[key]; + } else if (typeof obj[key] === "object" && typeof template[key] === "object" && !Array.isArray(obj[key]) && !Array.isArray(template[key])) { + obj[key] = parseObject(obj[key], template[key]); + } + } + return obj; + } + return parseObject(config, this.configOptionTemplate); + } + /** + * @returns The template to use for default values. + */ + get options() { + return this.configOptionTemplate; + } +}; + +// src/game/managers/KeyManager.ts +var keyManagerDefaultConfig = { + autoAddInterval: true, + fps: 30 + // pixiApp: undefined, +}; +var keys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]); +var KeyManager = class _KeyManager { + /** + * Creates a new key manager. + * @param config - The configuration for the key manager. + */ + constructor(config) { + /** @deprecated Use {@link addKey} instead. */ + this.addKeys = this.addKey.bind(this); + this.keysPressed = []; + this.binds = []; + this.tickers = []; + this.config = _KeyManager.configManager.parse(config); + if (this.config.autoAddInterval) { + const fps = this.config.fps ? this.config.fps : 30; + this.tickerInterval = setInterval(() => { + for (const ticker of this.tickers) { + ticker(1e3 / fps); + } + }, 1e3 / fps); + } + if (typeof document === "undefined") { + return; + } + this.tickers.push((dt) => { + for (const bind of this.binds) { + if ((typeof bind.onDownContinuous !== "undefined" || typeof bind.fn !== "undefined") && this.isPressing(bind.id)) { + bind.onDownContinuous?.(dt); + bind.fn?.(dt); + } + } + }); + document.addEventListener("keydown", (e) => { + this.logKey(e, true); + this.onAll("down", e.key); + }); + document.addEventListener("keyup", (e) => { + this.logKey(e, false); + this.onAll("up", e.key); + }); + document.addEventListener("keypress", (e) => { + this.onAll("press", e.key); + }); + } + static { + /** The configuration manager for the key manager */ + this.configManager = new ConfigManager(keyManagerDefaultConfig); + } + /** + * Changes the framerate of the key manager. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.config.fps = fps; + if (this.tickerInterval) { + clearInterval(this.tickerInterval); + this.tickerInterval = setInterval(() => { + for (const ticker of this.tickers) { + ticker(1e3 / fps); + } + }, 1e3 / fps); + } + } + /** + * Adds keys to the list of keys pressed. + * @param event - The event to add the key from. + * @param type - Whether to add or remove the key. `true` to add, `false` to remove. + */ + logKey(event, type) { + const key = event.key; + if (type && !this.keysPressed.includes(key)) { + this.keysPressed.push(key); + } else if (!type && this.keysPressed.includes(key)) { + this.keysPressed.splice(this.keysPressed.indexOf(key), 1); + } + } + /** + * Manages onDown, onPress, and onUp events for all key bindings. + * @param eventType - The type of event to call for. + * @param keypress - The key that was pressed. + */ + onAll(eventType, keypress) { + for (const bind of this.binds) { + if (bind.key !== keypress) continue; + switch (eventType) { + case "down": + bind.onDown?.(); + break; + case "press": + default: + bind.onPress?.(); + break; + case "up": + bind.onUp?.(); + break; + } + } + } + /** + * Checks if a specific key binding is currently being pressed. + * @param id - The name of the key binding to check. + * @returns True if the key binding is being pressed, otherwise false. + */ + isPressing(id) { + for (const current of this.binds) { + if (current.id === id) { + return this.keysPressed.includes(current.key); + } + } + return false; + } + /** + * Gets a key binding by its id. + * @param id - The id of the key binding to get. + * @returns The key binding, if found. + */ + getBind(id) { + return this.binds.find((current) => current.id === id); + } + addKey(nameOrKeysToAdd, key, fn) { + nameOrKeysToAdd = typeof nameOrKeysToAdd === "string" ? [{ id: nameOrKeysToAdd, name: nameOrKeysToAdd, key: key ?? "", fn }] : nameOrKeysToAdd; + nameOrKeysToAdd = Array.isArray(nameOrKeysToAdd) ? nameOrKeysToAdd : [nameOrKeysToAdd]; + for (const keyBinding of nameOrKeysToAdd) { + keyBinding.id = keyBinding.id ?? keyBinding.name; + const existing = this.getBind(keyBinding.id); + if (existing) { + Object.assign(existing, keyBinding); + continue; + } + this.binds.push(keyBinding); + } + } +}; + +// src/game/managers/EventManager.ts +var eventManagerDefaultConfig = { + autoAddInterval: true, + fps: 30 + // pixiApp: undefined, +}; +var EventManager = class _EventManager { + /** + * Creates a new event manager. + * @param config - The config to use for this event manager. + */ + constructor(config) { + /** + * Adds a new event + * @deprecated Use {@link EventManager.setEvent} instead. + * @alias eventManager.setEvent + */ + this.addEvent = this.setEvent.bind(this); + this.config = _EventManager.configManager.parse(config); + this.events = {}; + if (this.config.autoAddInterval) { + const fps = this.config.fps ?? 30; + this.tickerInterval = setInterval(() => { + this.tickerFunction(); + }, 1e3 / fps); + } + } + static { + /** The static config manager for the event manager */ + this.configManager = new ConfigManager(eventManagerDefaultConfig); + } + /** + * The function that is called every frame, executes all events. + */ + tickerFunction() { + const currentTime = Date.now(); + for (const event of Object.values(this.events)) { + switch (event.type) { + case "interval" /* interval */: + { + if (currentTime - event.intervalLast >= event.delay) { + const dt = currentTime - event.intervalLast; + event.callbackFn(dt); + event.intervalLast = currentTime; + } + } + ; + break; + case "timeout" /* timeout */: + { + const dt = currentTime - event.timeCreated; + if (currentTime - event.timeCreated >= event.delay) { + event.callbackFn(dt); + delete this.events[event.name]; + } + } + ; + break; + } + } + } + /** + * Changes the framerate of the event manager. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.config.fps = fps; + if (this.tickerInterval) { + clearInterval(this.tickerInterval); + this.tickerInterval = setInterval(() => { + this.tickerFunction(); + }, 1e3 / fps); + } + } + /** + * Warps time by a certain amount. Note: This will affect the stored creation time of timeout events. + * @param dt - The time to warp by. + */ + timeWarp(dt) { + for (const event of Object.values(this.events)) { + switch (event.type) { + case "interval" /* interval */: + { + event.intervalLast -= dt; + } + ; + break; + case "timeout" /* timeout */: + { + event.timeCreated -= dt; + } + ; + break; + } + } + } + /** + * Adds a new event or changes an existing event to the event system. + * @param name - The name of the event. If an event with this name already exists, it will be overwritten. + * @param type - The type of the event, either "interval" or "timeout". + * @param delay - The delay in milliseconds before the event triggers. (NOTE: If delay is less than the framerate, it will at trigger at max, once every frame.) + * @param callbackFn - The callback function to execute when the event triggers. + * @example + * const myEventManger = new eventManager(); + * // Add an interval event that executes every 2 seconds. + * myEventManger.addEvent("IntervalEvent", "interval", 2000, () => { + * console.log("Interval event executed."); + * }); + * + * // Add a timeout event that executes after 5 seconds. + * myEventManger.addEvent("TimeoutEvent", "timeout", 5000, () => { + * console.log("Timeout event executed."); + * }); + */ + setEvent(name, type, delay, callbackFn) { + this.events[name] = (() => { + switch (type) { + case "interval": + { + const event = { + name, + type, + delay: typeof delay === "number" ? delay : delay.toNumber(), + callbackFn, + timeCreated: Date.now(), + intervalLast: Date.now() + }; + return event; + } + ; + break; + case "timeout": + default: { + const event = { + name, + type, + delay: typeof delay === "number" ? delay : delay.toNumber(), + callbackFn, + timeCreated: Date.now() + }; + return event; + } + } + })(); + } + /** + * Removes an event from the event system. + * @param name - The name of the event to remove. + * @example + * myEventManger.removeEvent("IntervalEvent"); // Removes the interval event with the name "IntervalEvent". + */ + removeEvent(name) { + delete this.events[name]; + } +}; + +// src/game/managers/DataManager.ts +var import_lz_string = __toESM(require_lz_string()); +import "reflect-metadata"; +import { instanceToPlain, plainToInstance } from "class-transformer"; +var import_md5 = __toESM(require_md5()); +var DataManager = class { + /** + * Creates a new instance of the game class. + * @param gameRef - A function that returns the game instance. + */ + constructor(gameRef) { + /** The current game data. */ + this.data = {}; + /** The static game data. */ + this.static = {}; + /** A queue of functions to call when the game data is loaded. */ + this.eventsOnLoad = []; + this.gameRef = typeof gameRef === "function" ? gameRef() : gameRef; + } + /** + * Adds an event to call when the game data is loaded. + * @param event - The event to call when the game data is loaded. + * @example dataManager.addEventOnLoad(() => console.log("Data loaded!")); + */ + addEventOnLoad(event) { + this.eventsOnLoad.push(event); + } + /** + * Sets the data for the given key. + * The getter is a work in progress. + * @template S - The key to set the data for. + * @template T - The value to set the data to. + * @param key - The key to set the data for. + * @param value - The value to set the data to. + * @returns An object with a single entry of the name of the key and the value of the data. This is a getter and setter. + * @example + * // ! WARNING: Do not destruct the `value` property, as it will remove the getter and setter. + * const testData = dataManager.setData("test", 5); + * console.log(testData.value); // 5 + * testData.value = 10; // Also sets the data + * console.log(testData.value); // 10 + */ + setData(key, value) { + if (typeof this.data[key] === "undefined" && this.normalData) { + console.warn("After initializing data, you should not add new properties to data."); + } + this.data[key] = value; + const thisData = () => this.data; + return { + get value() { + return thisData()[key]; + }, + set value(valueToSet) { + thisData()[key] = valueToSet; + }, + setValue(valueToSet) { + thisData()[key] = valueToSet; + } + }; + } + /** + * Gets the data for the given key. + * @deprecated Set the return value of {@link setData} to a variable instead, as that is a getter and provides type checking. + * @param key - The key to get the data for. + * @returns The data for the given key. + */ + getData(key) { + return this.data[key]; + } + /** + * Sets the static data for the given key. + * This data is not affected by data loading and saving, and is mainly used internally. + * @param key - The key to set the static data for. + * @param value - The value to set the static data to. + * @returns A getter for the static data. + */ + setStatic(key, value) { + if (typeof this.static[key] === "undefined" && this.normalData) { + console.warn("After initializing data, you should not add new properties to staticData."); + } + this.static[key] = value; + return this.static[key]; + } + /** + * Gets the static data for the given key. + * @deprecated Set the return value of {@link setStatic} to a variable instead, as that is a getter and provides type checking. + * @param key - The key to get the static data for. + * @returns The static data for the given key. + */ + getStatic(key) { + return this.static[key]; + } + /** + * Initializes / sets data that is unmodified by the player. + * This is used to merge the loaded data with the default data. + * It should be called before you load data. + * Note: This should only be called once, and after it is called, you should not add new properties to data. + * @example dataManager.init(); // Call this after setting the initial data. + */ + init() { + this.normalData = this.data; + this.normalDataPlain = instanceToPlain(this.data); + } + /** + * Compiles the given game data to a tuple containing the compressed game data and a hash. + * @param data The game data to be compressed. Defaults to the current game data. + * @returns [hash, data] - The compressed game data and a hash as a base64-encoded string to use for saving. + */ + compileDataRaw(data = this.data) { + const gameDataString = instanceToPlain(data); + const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); + let version; + try { + version = "9.0.0"; + } catch (error) { + version = "8.3.0"; + } + const saveMetadata = { + hash: hasedData, + game: { + title: this.gameRef.config.name.title, + id: this.gameRef.config.name.id, + version: this.gameRef.config.name.version + }, + emath: { + version + } + }; + return [saveMetadata, gameDataString]; + } + /** + * Compresses the given game data to a base64-encoded using lz-string. + * @param data The game data to be compressed. Defaults to the current game data. + * @returns The compressed game data and a hash as a base64-encoded string to use for saving. + */ + compileData(data = this.data) { + const dataRawString = JSON.stringify(this.compileDataRaw(data)); + return (0, import_lz_string.compressToBase64)(dataRawString); + } + /** + * Decompiles the data stored in localStorage and returns the corresponding object. + * @param data - The data to decompile. If not provided, it will be fetched from localStorage using the key `${game.config.name.id}-data`. + * @returns The decompiled object, or null if the data is empty or invalid. + */ + decompileData(data = window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)) { + if (!data) return null; + let parsedData; + try { + parsedData = JSON.parse((0, import_lz_string.decompressFromBase64)(data)); + return parsedData; + } catch (error) { + if (error instanceof SyntaxError) { + console.error(`Failed to decompile data (corrupted) "${data}":`, error); + } else { + throw error; + } + return null; + } + } + /** + * Validates the given data using a hashing algorithm (md5) + * @param data - [hash, data] The data to validate. + * @returns Whether the data is valid / unchanged. False means that the data has been tampered with / save edited. + */ + validateData(data) { + const [saveMetadata, gameDataToValidate] = data; + if (typeof saveMetadata === "string") { + return (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataToValidate)}`) === saveMetadata; + } + const hashSave = saveMetadata.hash; + const hashCheck = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataToValidate)}`); + return hashSave === hashCheck; + } + /** + * Resets the game data to its initial state and saves it. + * @param reload - Whether to reload the page after resetting the data. Defaults to `false`. + */ + resetData(reload = false) { + if (!this.normalData) throw new Error("dataManager.resetData(): You must call init() before writing to data."); + this.data = this.normalData; + this.saveData(); + if (reload) window.location.reload(); + } + /** + * Saves the game data to local storage under the key `${game.config.name.id}-data`. + * If you dont want to save to local storage, use {@link compileData} instead. + * @param dataToSave - The data to save. If not provided, it will be fetched from localStorage using {@link compileData}. + */ + saveData(dataToSave = this.compileData()) { + if (!dataToSave) 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`, dataToSave); + } + /** + * Compiles the game data and prompts the user to download it as a text file using {@link window.prompt}. + * If you want to implement a custom data export, use {@link compileData} instead. + */ + exportData() { + const content = this.compileData(); + if (prompt("Download save data?:", content) != null) { + const blob = new Blob([content], { type: "text/plain" }); + const downloadLink = document.createElement("a"); + downloadLink.href = URL.createObjectURL(blob); + downloadLink.download = `${this.gameRef.config.name.id}-data.txt`; + downloadLink.textContent = `Download ${this.gameRef.config.name.id}-data.txt file`; + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); + } + } + /** + * Loads game data and processes it. + * @param dataToParse - The data to load. If not provided, it will be fetched from localStorage using {@link decompileData}. + * @param mergeData - Whether to merge the loaded data with the normal data. Defaults to `true`. + * Warning: If set to `false`, the loaded data may have missing properties and may cause errors. + * @returns The loaded data. + */ + parseData(dataToParse = this.decompileData(), mergeData = true) { + if ((!this.normalData || !this.normalDataPlain) && mergeData) throw new Error("dataManager.parseData(): You must call init() before writing to data."); + if (!dataToParse) return null; + const [, loadedData] = dataToParse; + function isPlainObject(obj) { + return typeof obj === "object" && obj?.constructor === Object; + } + const objectHasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key); + function deepMerge(sourcePlain, source, target) { + if (!sourcePlain || !source || !target) throw new Error("dataManager.deepMerge(): Missing arguments."); + const out = target; + for (const key in sourcePlain) { + if (objectHasOwnProperty(sourcePlain, key) && !objectHasOwnProperty(target, key)) { + out[key] = sourcePlain[key]; + } + if (source[key] instanceof Currency) { + const sourceCurrency = sourcePlain[key]; + const targetCurrency = target[key]; + if (Array.isArray(targetCurrency.upgrades)) { + const upgrades = targetCurrency.upgrades; + targetCurrency.upgrades = {}; + for (const upgrade of upgrades) { + targetCurrency.upgrades[upgrade.id] = upgrade; + } + } + targetCurrency.upgrades = { ...sourceCurrency.upgrades, ...targetCurrency.upgrades }; + out[key] = targetCurrency; + } else if (isPlainObject(sourcePlain[key]) && isPlainObject(target[key])) { + out[key] = deepMerge(sourcePlain[key], source[key], target[key]); + } + } + return out; + } + let loadedDataProcessed = !mergeData ? loadedData : deepMerge(this.normalDataPlain, this.normalData, loadedData); + const upgradeDataProperties = Object.getOwnPropertyNames(new UpgradeData({ id: "", level: new Decimal(0) })); + function convertTemplateClass(templateClassToConvert, plain) { + const out = plainToInstance(templateClassToConvert, plain); + if (out instanceof Currency) { + for (const upgradeName in out.upgrades) { + const upgrade = out.upgrades[upgradeName]; + if (!upgrade || !upgradeDataProperties.every((prop) => Object.getOwnPropertyNames(upgrade).includes(prop))) { + delete out.upgrades[upgradeName]; + continue; + } + out.upgrades[upgradeName] = plainToInstance(UpgradeData, upgrade); + } + } + if (!out) throw new Error(`Failed to convert ${templateClassToConvert.name} to class instance.`); + return out; + } + function plainToInstanceRecursive(normal, plain) { + if (!normal || !plain) throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments."); + const out = plain; + for (const key in normal) { + if (plain[key] === void 0) { + console.warn(`Missing property "${key}" in loaded data.`); + continue; + } + if (!isPlainObject(plain[key])) continue; + const normalDataClass = normal[key].constructor; + if (normalDataClass === Object) { + out[key] = plainToInstanceRecursive(normal[key], plain[key]); + continue; + } + out[key] = convertTemplateClass(normalDataClass, plain[key]); + } + return out; + } + loadedDataProcessed = plainToInstanceRecursive(this.normalData, loadedDataProcessed); + return loadedDataProcessed; + } + /** + * Loads game data and processes it. + * @param dataToLoad - The data to load. If not provided, it will be fetched from localStorage using {@link decompileData}. + * @returns Returns null if the data is empty or invalid, or false if the data is tampered with. Otherwise, returns true. + */ + loadData(dataToLoad = this.decompileData()) { + dataToLoad = typeof dataToLoad === "string" ? this.decompileData(dataToLoad) : dataToLoad; + if (!dataToLoad) return null; + const isDataValid = this.validateData([dataToLoad[0], instanceToPlain(dataToLoad[1])]); + const parsedData = this.parseData(dataToLoad); + if (!parsedData) return null; + this.data = parsedData; + for (const obj of this.eventsOnLoad) { + obj(); + } + return isDataValid; + } +}; + +// src/game/GameCurrency.ts +var GameCurrency = class { + /** @returns The data for the currency. */ + get data() { + return this.dataPointer(); + } + /** @returns The static data for the currency. */ + get static() { + return this.staticPointer(); + } + /** + * Creates a new instance of the game class. + * @param currencyPointer - A function that returns the current currency value. + * @param staticPointer - A function that returns the static data for the game. + * @param gamePointer A pointer to the game instance. + * @param name - The name of the currency. This is optional, and you can use it for display purposes. + */ + constructor(currencyPointer, staticPointer, gamePointer, name) { + this.dataPointer = typeof currencyPointer === "function" ? currencyPointer : () => currencyPointer; + this.staticPointer = typeof staticPointer === "function" ? staticPointer : () => staticPointer; + this.game = gamePointer; + this.name = name; + this.game.dataManager.addEventOnLoad(() => { + this.static.onLoadData(); + }); + } + /** + * Gets the value of the game currency. + * Note: There is no setter for this property. To change the value of the currency, use the corresponding methods in the static class. + * @returns The value of the game currency. + */ + get value() { + return this.data.value; + } +}; + +// src/game/GameAttribute.ts +var GameAttribute = class { + /** + * Creates a new instance of the attribute class. + * @param attributePointer - A function that returns the current attribute value. + * @param staticPointer - A function that returns the static data for the attribute. + * @param gamePointer A pointer to the game instance. + */ + constructor(attributePointer, staticPointer, gamePointer) { + this.data = typeof attributePointer === "function" ? attributePointer() : attributePointer; + this.static = typeof staticPointer === "function" ? staticPointer() : staticPointer; + this.game = gamePointer; + } + /** + * Gets the value of the attribute. + * NOTE: This getter is sometimes inaccurate. + * @returns The value of the attribute. + */ + get value() { + return this.static.value; + } + /** + * Sets the value of the attribute. + * NOTE: This setter should not be used when boost is enabled. + * @param value - The value to set the attribute to. + */ + set value(value) { + this.data.value = value; + } +}; + +// src/game/ResetLayer.ts +var GameReset = class { + /** + * Creates a new instance of the game reset. + * @param currenciesToReset The currencies to reset. + * @param extender The extender for the game reset. WARNING: Do not set this to the same object, as it will cause an infinite loop. + */ + constructor(currenciesToReset, extender) { + this.currenciesToReset = Array.isArray(currenciesToReset) ? currenciesToReset : [currenciesToReset]; + this.extender = Array.isArray(extender) ? extender : extender ? [extender] : []; + this.id = Symbol(); + } + /** + * Resets a currency to its default value, and runs the extender's reset function if it exists (recursively). + */ + reset() { + this.onReset?.(this); + this.currenciesToReset.forEach((currency) => { + currency.static.reset(); + }); + this.extender.forEach((extender) => { + if (extender.id !== this.id) { + extender.reset(); + } + }); + } +}; + +// src/game/Game.ts +var gameDefaultConfig = { + mode: "production", + name: { + title: "", + id: "", + version: "0.0.0" + }, + settings: { + framerate: 30 + }, + initIntervalBasedManagers: true +}; +var Game = class _Game { + static { + /** The static config manager for the game. */ + this.configManager = new ConfigManager(gameDefaultConfig); + } + /** + * Creates a new instance of the game class. + * @param config - The configuration object for the game. + * @example + * const myGame = new game({ + * name: { + * title: "My Game", + * id: "my-game", + * }, + * // Additional options here + * }); + */ + constructor(config) { + this.config = _Game.configManager.parse(config); + this.dataManager = new DataManager(this); + this.keyManager = new KeyManager({ + autoAddInterval: this.config.initIntervalBasedManagers, + fps: this.config.settings.framerate + }); + this.eventManager = new EventManager({ + autoAddInterval: this.config.initIntervalBasedManagers, + fps: this.config.settings.framerate + }); + this.tickers = []; + } + /** + * Initializes the game. Also initializes the data manager. + * See {@link DataManager.init} for more information. + */ + init() { + this.dataManager.init(); + } + /** + * Changes the framerate of the game. + * @param fps - The new framerate to use. + */ + changeFps(fps) { + this.keyManager.changeFps(fps); + this.eventManager.changeFps(fps); + } + /** + * Adds a new currency section to the game. {@link GameCurrency} is the class. + * It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading. + * @template N - The name + * @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information. + * @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique. + * @param upgrades - The upgrades for the currency. + * @returns A new instance of the gameCurrency class. + * @example + * const currency = game.addCurrency("currency"); + * currency.static.gain(); + * console.log(currency.value); // new Decimal(1) + */ + addCurrency(name, upgrades = []) { + this.dataManager.setData(name, { + currency: new Currency() + }); + this.dataManager.setStatic(name, { + currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades) + }); + const classInstance = new GameCurrency( + () => this.dataManager.getData(name).currency, + () => this.dataManager.getStatic(name).currency, + this, + name + ); + return classInstance; + } + /** + * Adds a new attribute to the game. {@link GameAttribute} is the class. + * It automatically adds the attribute and attributeStatic objects to the data and static objects for saving and loading. + * @param name - The name of the attribute. + * @param useBoost - Indicates whether to use boost for the attribute. + * @param initial - The initial value of the attribute. + * @returns The newly created attribute. + * @example + * const myAttribute = game.addAttribute("myAttribute"); + */ + addAttribute(name, useBoost = true, initial = 0) { + this.dataManager.setData(name, new Attribute(initial)); + this.dataManager.setStatic(name, new AttributeStatic(this.dataManager.getData(name), useBoost, initial)); + const classInstance = new GameAttribute(this.dataManager.getData(name), this.dataManager.getStatic(name), this); + return classInstance; + } + /** + * Creates a new game reset object with the specified currencies to reset. + * @param currenciesToReset - The currencies to reset. + * @param extender - An optional object to extend the game reset object with. + * @returns The newly created game reset object. + */ + addReset(currenciesToReset, extender) { + const reset = new GameReset(currenciesToReset, extender); + return reset; + } +}; + // src/presets/GameFormats.ts function gameFormat(value, settings) { settings = Object.assign({ @@ -4935,3 +7292,13 @@ export { gameFormat, gameFormatGain }; +/*! Bundled license information: + +is-buffer/index.js: + (*! + * Determine if an object is a Buffer + * + * @author Feross Aboukhadijeh + * @license MIT + *) +*/ diff --git a/dist/types/E/e.d.ts b/dist/types/E/e.d.ts index 67324605..9c88498e 100644 --- a/dist/types/E/e.d.ts +++ b/dist/types/E/e.d.ts @@ -1343,7 +1343,7 @@ declare const formats: { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: Decimal): (string | Decimal)[]; + getAbbreviationAndValue(x: Decimal): [string, Decimal]; formatElementalPart(abbreviation: string, n: Decimal): string; format(value: Decimal, acc?: number): string; }; @@ -1397,7 +1397,7 @@ declare const formats: { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: Decimal): (string | Decimal)[]; + getAbbreviationAndValue(x: Decimal): [string, Decimal]; formatElementalPart(abbreviation: string, n: Decimal): string; format(value: Decimal, acc?: number): string; }; diff --git a/dist/types/E/format.d.ts b/dist/types/E/format.d.ts index ac3c14b0..dcb045b7 100644 --- a/dist/types/E/format.d.ts +++ b/dist/types/E/format.d.ts @@ -1,5 +1,22 @@ /** * @file Declares a generator function for formats for the Decimal library. + * Adapted from MrRedShark77's Incremental Mass Rewritten (https://github.com/MrRedShark77/incremental-mass-rewritten) + * Modified to be written in typescript and adds JSDoc comments. + */ +/** + * MIT License + * + * Copyright (c) 2021 MrRedShark77 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. */ import type { Decimal as DecimalType, DecimalSource } from "./e"; type Decimal = DecimalType; @@ -49,7 +66,7 @@ declare function decimalFormatGenerator(Decimal: typeof DecimalType): { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: Decimal): (string | DecimalType)[]; + getAbbreviationAndValue(x: Decimal): [string, Decimal]; formatElementalPart(abbreviation: string, n: Decimal): string; format(value: Decimal, acc?: number): string; }; @@ -192,7 +209,7 @@ declare function decimalFormatGenerator(Decimal: typeof DecimalType): { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: Decimal): (string | DecimalType)[]; + getAbbreviationAndValue(x: Decimal): [string, Decimal]; formatElementalPart(abbreviation: string, n: Decimal): string; format(value: Decimal, acc?: number): string; }; @@ -287,4 +304,5 @@ declare function decimalFormatGenerator(Decimal: typeof DecimalType): { }; }; }; -export { decimalFormatGenerator, FormatType, ST_NAMES, FormatTypeList }; +export type { FormatType }; +export { decimalFormatGenerator, ST_NAMES, FormatTypeList }; diff --git a/dist/types/common/types.d.ts b/dist/types/common/types.d.ts index a2e8e772..dd7148d7 100644 --- a/dist/types/common/types.d.ts +++ b/dist/types/common/types.d.ts @@ -3,6 +3,10 @@ */ /** * Determines if a type is a primitive string. + * + * Works by checking the intersection of `T` with a random string. + * - If `T` is a primitive string, the intersection will be the first random string, which does not extend `""`. + * - If `T` is is any other type, the intersection will be `never`. For some reason, `never` extends any type. * @template T - The type to check. * @example * type Test1 = IsPrimitiveString; // true @@ -21,6 +25,7 @@ type Mutable = { type ClassType = new (...args: any[]) => any; /** A plain object with unknown properties. */ type UnknownObject = Record; +/** An object that can be constructed with the `new` keyword. */ type ConstructableObject = object & { constructor: ClassType; }; diff --git a/dist/types/game/hookGame.d.ts b/dist/types/game/hookGame.d.ts index 435f8221..54be62e6 100644 --- a/dist/types/game/hookGame.d.ts +++ b/dist/types/game/hookGame.d.ts @@ -54,7 +54,7 @@ declare const eMath: { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: eMathMain.Decimal): (string | eMathMain.Decimal)[]; + getAbbreviationAndValue(x: eMathMain.Decimal): [string, eMathMain.Decimal]; formatElementalPart(abbreviation: string, n: eMathMain.Decimal): string; format(value: eMathMain.Decimal, acc?: number): string; }; @@ -109,7 +109,7 @@ declare const eMath: { getAbbreviation(group: number, progress: number): string; beyondOg(x: number): string; abbreviationLength(group: number): number; - getAbbreviationAndValue(x: eMathMain.Decimal): (string | eMathMain.Decimal)[]; + getAbbreviationAndValue(x: eMathMain.Decimal): [string, eMathMain.Decimal]; formatElementalPart(abbreviation: string, n: eMathMain.Decimal): string; format(value: eMathMain.Decimal, acc?: number): string; }; diff --git a/dist/types/presets/index.d.ts b/dist/types/presets/index.d.ts index 3c975efe..7644636c 100644 --- a/dist/types/presets/index.d.ts +++ b/dist/types/presets/index.d.ts @@ -2,4 +2,6 @@ * @file index.ts * @description This package exports useful presets for the library. */ +import "../index"; +import "../game/index"; export * from "./GameFormats"; diff --git a/src/E/format.ts b/src/E/format.ts index 5395decb..f9e75967 100644 --- a/src/E/format.ts +++ b/src/E/format.ts @@ -1,6 +1,26 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-condition */ /** * @file Declares a generator function for formats for the Decimal library. + * Adapted from MrRedShark77's Incremental Mass Rewritten (https://github.com/MrRedShark77/incremental-mass-rewritten) + * Modified to be written in typescript and adds JSDoc comments. */ + +/** + * MIT License + * + * Copyright (c) 2021 MrRedShark77 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + import type { Decimal as DecimalType, DecimalSource } from "./e"; type Decimal = DecimalType; @@ -31,7 +51,7 @@ const FormatTypeList: FormatType[] = ["st", "sc", "scientific", "omega", "omega_ * @param Decimal - The Decimal constructor to use. * @returns - The format function. */ -// eslint-disable-next-line no-shadow +// eslint-disable-next-line no-shadow, @typescript-eslint/explicit-function-return-type function decimalFormatGenerator (Decimal: typeof DecimalType) { /** A list of formats */ const FORMATS = { @@ -152,7 +172,7 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { if (group % 2 == 1) r += 2 * Math.pow(n + 1, 2); return r; }, - getAbbreviation (group: number, progress: number) { + getAbbreviation (group: number, progress: number): string { const length = FORMATS.elemental.abbreviationLength(group); const elemRel = Math.floor(length * progress); @@ -174,7 +194,7 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { abbreviationLength (group: number): number { return group == 1 ? 1 : Math.pow(Math.floor(group / 2) + 1, 2) * 2; }, - getAbbreviationAndValue (x: Decimal) { + getAbbreviationAndValue (x: Decimal): [string, Decimal] { const abbreviationListUnfloored = x.log(118).toNumber(); const abbreviationListIndex = Math.floor(abbreviationListUnfloored) + 1; const abbreviationLength = FORMATS.elemental.abbreviationLength(abbreviationListIndex); @@ -184,11 +204,11 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { const value = new Decimal(118).pow(abbreviationListIndex + abbreviationIndex / abbreviationLength - 1); return [abbreviation, value]; }, - formatElementalPart (abbreviation: string, n: Decimal) { + formatElementalPart (abbreviation: string, n: Decimal): string { if (n.eq(1)) { return abbreviation; } - return `${n} ${abbreviation}`; + return `${n.toString()} ${abbreviation}`; }, format (value: Decimal, acc = 2): string { if (value.gt(new Decimal(118).pow(new Decimal(118).pow(new Decimal(118).pow(4))))) return "e" + FORMATS.elemental.format(value.log10(), acc); @@ -511,64 +531,64 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { if (ex.eq(0)) return ex.toFixed(acc); const e = ex.log10().floor(); switch (type) { - case "sc": - case "scientific": { - if (ex.log10().lt(Math.min(-acc, 0)) && acc > 1) { - const e2 = ex.log10().ceil(); - const m = ex.div(e2.eq(-1) ? new Decimal(0.1) : new Decimal(10).pow(e2)); - const be = e2.mul(-1).max(1).log10().gte(9); - return neg + (be ? "" : m.toFixed(2)) + "e" + format(e2, 0, max, "mixed_sc"); - } else if (e.lt(max)) { - const a = Math.max(Math.min(acc - e.toNumber(), acc), 0); - return neg + (a > 0 ? ex.toFixed(a) : ex.toFixed(a).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")); - } else { - if (ex.gte("eeee10")) { - const slog = ex.slog(); - return (slog.gte(1e9) ? "" : new Decimal(10).pow(slog.sub(slog.floor())).toFixed(2)) + "F" + format(slog.floor(), 0); + case "sc": + case "scientific": { + if (ex.log10().lt(Math.min(-acc, 0)) && acc > 1) { + const e2 = ex.log10().ceil(); + const m = ex.div(e2.eq(-1) ? new Decimal(0.1) : new Decimal(10).pow(e2)); + const be = e2.mul(-1).max(1).log10().gte(9); + return neg + (be ? "" : m.toFixed(2)) + "e" + format(e2, 0, max, "mixed_sc"); + } else if (e.lt(max)) { + const a = Math.max(Math.min(acc - e.toNumber(), acc), 0); + return neg + (a > 0 ? ex.toFixed(a) : ex.toFixed(a).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")); + } else { + if (ex.gte("eeee10")) { + const slog = ex.slog(); + return (slog.gte(1e9) ? "" : new Decimal(10).pow(slog.sub(slog.floor())).toFixed(2)) + "F" + format(slog.floor(), 0); + } + const m = ex.div(new Decimal(10).pow(e)); + const be = e.log10().gte(9); + return neg + (be ? "" : m.toFixed(2)) + "e" + format(e, 0, max, "mixed_sc"); } - const m = ex.div(new Decimal(10).pow(e)); - const be = e.log10().gte(9); - return neg + (be ? "" : m.toFixed(2)) + "e" + format(e, 0, max, "mixed_sc"); - } - } - case "st": - case "standard": { - let e3 = ex.log(1e3).floor(); - if (e3.lt(1)) { - return neg + ex.toFixed(Math.max(Math.min(acc - e.toNumber(), acc), 0)); } + case "st": + case "standard": { + let e3 = ex.log(1e3).floor(); + if (e3.lt(1)) { + return neg + ex.toFixed(Math.max(Math.min(acc - e.toNumber(), acc), 0)); + } - const e3_mul = e3.mul(3); - const ee = e3.log10().floor(); - if (ee.gte(3000)) return "e" + format(e, acc, max, "st"); - - let final = ""; - if (e3.lt(4)) final = ["", "K", "M", "B"][Math.round(e3.toNumber())]; - else { - let ee3 = Math.floor(e3.log(1e3).toNumber()); - if (ee3 < 100) ee3 = Math.max(ee3 - 1, 0); - e3 = e3.sub(1).div(new Decimal(10).pow(ee3 * 3)); - while (e3.gt(0)) { - const div1000 = e3.div(1e3).floor(); - const mod1000 = e3.sub(div1000.mul(1e3)).floor().toNumber(); - if (mod1000 > 0) { - if (mod1000 == 1 && !ee3) final = "U"; - if (ee3) final = FORMATS.standard.tier2(ee3) + (final ? "-" + final : ""); - if (mod1000 > 1) final = FORMATS.standard.tier1(mod1000) + final; + const e3_mul = e3.mul(3); + const ee = e3.log10().floor(); + if (ee.gte(3000)) return "e" + format(e, acc, max, "st"); + + let final = ""; + if (e3.lt(4)) final = ["", "K", "M", "B"][Math.round(e3.toNumber())]; + else { + let ee3 = Math.floor(e3.log(1e3).toNumber()); + if (ee3 < 100) ee3 = Math.max(ee3 - 1, 0); + e3 = e3.sub(1).div(new Decimal(10).pow(ee3 * 3)); + while (e3.gt(0)) { + const div1000 = e3.div(1e3).floor(); + const mod1000 = e3.sub(div1000.mul(1e3)).floor().toNumber(); + if (mod1000 > 0) { + if (mod1000 == 1 && !ee3) final = "U"; + if (ee3) final = FORMATS.standard.tier2(ee3) + (final ? "-" + final : ""); + if (mod1000 > 1) final = FORMATS.standard.tier1(mod1000) + final; + } + e3 = div1000; + ee3++; } - e3 = div1000; - ee3++; } - } - const m = ex.div(new Decimal(10).pow(e3_mul)); - const fixedAmt = acc === 2 ? new Decimal(2).sub(e.sub(e3_mul)).add(1).toNumber() : acc; - return neg + (ee.gte(10) ? "" : (m.toFixed(fixedAmt)) + " ") + final; - } - default: + const m = ex.div(new Decimal(10).pow(e3_mul)); + const fixedAmt = acc === 2 ? new Decimal(2).sub(e.sub(e3_mul)).add(1).toNumber() : acc; + return neg + (ee.gte(10) ? "" : (m.toFixed(fixedAmt)) + " ") + final; + } + default: // Other formats - if (!FORMATS[type]) console.error(`Invalid format type "`, type, `"`); - return neg + FORMATS[type].format(ex, acc, max); + if (!FORMATS[type]) console.error(`Invalid format type "`, type, `"`); + return neg + FORMATS[type].format(ex, acc, max); } } @@ -623,7 +643,7 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { * @returns - The formatted time */ function formatTimeLong (ex: DecimalSource, ms = false, acc = 0, max = 9, type: FormatType = "mixed_sc"): string { - const formatFn = (exf: DecimalSource) => format(exf, acc, max, type); + const formatFn = (exf: DecimalSource): string => format(exf, acc, max, type); ex = new Decimal(ex); const mls = ex.mul(1000).mod(1000).floor(); const sec = ex.mod(60).floor(); @@ -678,7 +698,7 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { * @param base - The base * @returns - The value after being exponentiated */ - function expMult (a: DecimalSource, b: DecimalSource, base = 10) { + function expMult (a: DecimalSource, b: DecimalSource, base = 10): DecimalType { return Decimal.gte(a, 10) ? Decimal.pow(base, Decimal.log(a, base).pow(b)) : new Decimal(a); } @@ -760,30 +780,30 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { const abbMax = abb[abbNum]; if (abbNum === 0) { switch (type) { + case 1: + output = ""; + break; + case 2: + case 0: + default: + output = num.format(); + break; + } + } + switch (type) { case 1: - output = ""; + output = abbMax.name; break; case 2: + output = num.divide(abbMax.value).format(); + break; + case 3: + output = abbMax.altName; + break; case 0: default: - output = num.format(); + output = `${num.divide(abbMax.value).format()} ${abbMax.name}`; break; - } - } - switch (type) { - case 1: - output = abbMax.name; - break; - case 2: - output = num.divide(abbMax.value).format(); - break; - case 3: - output = abbMax.altName; - break; - case 0: - default: - output = `${num.divide(abbMax.value).format()} ${abbMax.name}`; - break; } return output; } @@ -794,7 +814,7 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { * @param c2 - Whether to include /c^2 * @returns The formatted value */ - function ev (num: DecimalSource, c2 = false) { + function ev (num: DecimalSource, c2 = false): string { return `${metric(num, 2)} ${metric(num, 1)}eV${c2 ? "/c^2" : ""}`; } @@ -820,4 +840,5 @@ function decimalFormatGenerator (Decimal: typeof DecimalType) { }; } -export { decimalFormatGenerator, FormatType, ST_NAMES, FormatTypeList }; +export type { FormatType }; +export { decimalFormatGenerator, ST_NAMES, FormatTypeList }; diff --git a/src/presets/index.ts b/src/presets/index.ts index b9429e5b..6d30faff 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -4,4 +4,7 @@ */ // import "reflect-metadata"; -export * from "./GameFormats"; \ No newline at end of file +import "../index"; +import "../game/index"; + +export * from "./GameFormats";