@stackone/transport 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentHash as r,isFunction as i,isFutureUnixTimestamp as a,isMissing as o,isNumber as s,isObject as c,isString as l,notMissing as u,z as d,zStrictObject as f}from"@stackone/utils";import*as p from"redis";import m,{isAxiosError as h}from"axios";import g from"node:https";import{randomUUID as _}from"crypto";import{clearTimeout as v}from"node:timers";import y from"jsonpath";import{redactUrl as b}from"@stackone/redaction";import x from"qs";import{safeEvaluate as S}from"@stackone/expressions";var C=Object.create,w=Object.defineProperty,T=Object.getOwnPropertyDescriptor,E=Object.getOwnPropertyNames,D=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,O=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),te=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=E(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ee.call(e,s)&&s!==n&&w(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=T(t,s))||r.enumerable});return e},k=(e,t,n)=>(n=e==null?{}:C(D(e)),te(t||!e||!e.__esModule?w(n,`default`,{value:e,enumerable:!0}):n,e));const A=e=>{switch(e.type){case`none`:return{};case`basic`:return ne(e);case`bearer`:return re(e);case`oauth2`:return re(e);default:throw Error(`Invalid authentication type`)}},ne=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n,i=Buffer.from(`${e}:${t}`).toString(r);return{authorization:`Basic ${i}`}},re=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var ie=class{locks;constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);if(r&&i){i.push({lock:n,unlock:t});let e=i.length-2;await i[e].lock}else this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const ae=1e3,oe=100,se=60,ce=6e4,le=se,ue=ce,de=ce*10,fe=oe,pe=10;let me=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var he=class{config;instantiator;dataStore;lockManager;expiryMap;evictionFrequency;staleDataThreshold;truncateThreshold;truncationPercentage;logger;typeGuard;dispose;evictionInterval;lastAccessedAt=Date.now();constructor(e={}){this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new ie,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??ue,this.staleDataThreshold=e?.staleDataThreshold??de,this.truncateThreshold=e?.truncateThreshold??fe,this.truncationPercentage=e?.truncationPercentage??pe,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async setData({key:e,value:t,cacheTTL:n=le}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),u(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*ae,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{(u(this.typeGuard)&&this.typeGuard(t)||o(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/oe;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n);let i=this.dataStore.size;return{dataStoreSize:e,prunedDataStoreSize:i}}startEvictionTask(){if(u(this.evictionInterval))return;let e=async()=>{let t;try{let n=this.lastAccessedAt+this.staleDataThreshold,r=Date.now();if(n<r){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:me.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if(u(t?.dataStoreSize)&&u(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&(clearTimeout(this.evictionInterval),this.evictionInterval=void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return u(this.evictionInterval)&&u(this.dataStore)&&u(this.expiryMap)&&u(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()),i=r.filter(t=>t.includes(e)),a=[],o=t?parseInt(t,10):0;for(let e=o;e<n+o;e++){let t=i[e];if(!t)break;let r=await this.getData(t);if(r&&a.push(r),a.length>=n)break}return{items:a,cursor:a.length<n?void 0:(o+n).toString()}}};const ge=1e3,_e=6e4;let ve=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var ye=class{executorMethodStore=null;promiseStore=null;logger;eventClientConfig=null;executorMethodStoreConfig=null;pendingPromiseStoreConfig=null;constructor(e,t,n){this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new he(i),this.promiseStore=new he(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/ge;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return u(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);o(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??_e),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:ve.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){u(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):u(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return c(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},be=class{instance=null;initPromise=null;retryTimeout=null;status=`uninitialized`;initOptions=null;initArgs=[];getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:(o(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,o(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let j=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const xe=async(e,t,n)=>{try{let r=await Se.build(e,t,n);return r??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:j.RedisClientError,category:n??`buildRedisClientInstance`});return}};var Se=class e{#redisClient;#logger;static async build({getRedisClient:t=p.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s,c){let l=new e;l.#logger=s;try{l.#redisClient=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let e=we(c??`RedisClient`,l.#logger);return Ce(l.#redisClient,e),await l.#redisClient.connect(),l}catch(e){let t=e;return l.#logger?.error({message:`Error building Cache Manager.`,error:t,code:j.RedisClientError,category:c??`RedisClient`}),null}}#parseData(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#isRedisClientAvailable())return null;try{let e=await this.#redisClient.get(t);if(!e)return null;let n=this.#parseData(e);return l(n)?e:n}catch(t){let n=t;return this.#logger?.error({message:`Error getting data`,error:n,code:j.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#isRedisClientAvailable())return!1;try{let e=l(n)?n:JSON.stringify(n);return await this.#redisClient.set(t,e,{EX:r}),u(i)&&await this.#redisClient.sAdd(i,[t]),!0}catch(t){let n=t;return this.#logger?.error({message:`Error setting data`,error:n,code:j.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#logger?.error({message:`Error executing script`,error:n,code:j.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.scriptLoad(t)}catch(t){let n=t;return this.#logger?.error({message:`Error loading script`,error:n,code:j.RedisClientScriptLoadError,category:e.name}),null}}async#executeCounterCommand(t,n,r){if(!this.#isRedisClientAvailable())return null;if(!Number.isFinite(r)||r<=0)return this.#logger?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:j.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=await this.#redisClient.multiExecutor(e),a=i?.[0];return typeof a==`number`?a:null}catch(n){let r=n;return this.#logger?.error({message:`Error executing ${t} operation`,error:r,code:j.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#executeCounterCommand(`incr`,e,t)}async decrement(e,t){return this.#executeCounterCommand(`decr`,e,t)}async subscribe(t,n){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pSubscribe(t,n),!0}catch(n){let r=n;return this.#logger?.error({message:`Error subscribing to ${t}`,error:r,code:j.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pUnsubscribe(t),!0}catch(n){let r=n;return this.#logger?.error({message:`Error unsubscribing from ${t}`,error:r,code:j.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#isRedisClientAvailable())return null;try{let r=await this.#redisClient.publish(t,n);return r===0&&this.#logger?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#logger?.error({message:`Error publishing to ${t}`,error:r,code:j.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#isRedisClientAvailable()?this.#redisClient:null}#isRedisClientAvailable(){let t=this.#redisClient.isReady&&this.#redisClient.isOpen;return t||this.#logger?.error({message:`Redis Client is not ready.`,category:e.name,code:j.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#redisClient.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);u(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#logger?.error({message:`Error listing data`,error:n,code:j.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#isRedisClientAvailable())return!1;let n=await this.#redisClient.del(t);return n===0&&this.#logger?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#logger?.error({message:`Error deleting data`,error:n,code:j.RedisClientDeleteError,category:e.name}),!1}}};const Ce=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},we=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:j.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let Te=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});var Ee=class extends be{redisClientConfig;scripts;scriptMap;cacheClient;logger;additionalArgs;isInitialConnection=!0;async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let s=t??await xe(e,i,this.name);if(o(s))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=s,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();u(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){o(this.scripts)||Object.keys(this.scripts).length===0||(this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts))}async loadScripts(e,t){if(u(t))for(let[e,n]of t)this.scriptMap.set(e,n);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);u(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.name,code:Te.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{if(!this.isRedisReady())throw Error(`Redis client is not ready`);let r=this.scriptMap?.get(e);if(o(r))throw Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),o(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i}}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.name,context:{keys:t,args:n},error:r,code:Te.ScriptManagerExecutionError}),r}}isRedisReady(){return this.isReady()&&u(this.cacheClient)}},De=class{options={getCacheClient:xe};subscriptionMap=null;subscriptionClient=null;logger;name=`SubscriptionManager`;constructor(e){this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new he({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),u(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),i=r(t.toString());return await this.subscriptionMap?.setData({key:e,value:i}),n===i?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return u(this.subscriptionClient)&&u(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const Oe=6e4,ke=15e3,Ae=!1,je=6e4,Me=15e3,Ne=1e4,Pe=1;let Fe=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),Ie=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var Le=class extends Ee{subscriptionManager=null;eventClient=null;name=`QueueManager`;async additionalInitialization(){if(o(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new De({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:je,truncateThreshold:Ne,truncationPercentage:Pe}),await this.subscriptionManager?.initialize(),this.eventClient=new ye({instantiator:this.name,timeoutResolveValue:Ae},{instantiator:this.name,evictionFrequency:Me,truncateThreshold:Ne,truncationPercentage:Pe},{instantiator:this.name,evictionFrequency:Me,truncateThreshold:Ne,truncationPercentage:Pe}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?Ie.lPush:Ie.rPush,[e],[t,Oe.toString()]),s=o===1,c=i?!s:!0;return c&&await this.eventClient?.waitForEvent(a,ke),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:Fe.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(Ie.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:Fe.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(Ie.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:Fe.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return u(this.subscriptionManager)&&u(this.cacheClient)&&u(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const Re=5,ze=12e4,Be=1e4,Ve=1,He=60,Ue=90,We=`__keyevent@0__:`,Ge=`${We}set`,Ke=`${We}expire`,qe=`${We}expired`,Je=`${We}srem`,Ye=`config_check_test_key`,Xe=[Ge,Ke,qe],Ze=1,Qe=1e4,$e={mainMaxConcurrency:30};let et=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e}({}),tt=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const nt={[tt.tryConcurrency]:`
1
+ import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentHash as r,isFunction as i,isFutureUnixTimestamp as a,isMissing as o,isNumber as s,isObject as c,isString as l,notMissing as u,z as d,zStrictObject as f}from"@stackone/utils";import*as p from"redis";import m,{isAxiosError as h}from"axios";import g from"node:https";import{randomUUID as _}from"crypto";import{clearTimeout as v}from"node:timers";import y from"jsonpath";import{redactUrl as b}from"@stackone/redaction";import x from"qs";import{safeEvaluate as S}from"@stackone/expressions";var ee=Object.create,C=Object.defineProperty,w=Object.getOwnPropertyDescriptor,T=Object.getOwnPropertyNames,E=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty,D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ne=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=T(t),a=0,o=i.length,s;a<o;a++)s=i[a],!te.call(e,s)&&s!==n&&C(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=w(t,s))||r.enumerable});return e},O=(e,t,n)=>(n=e==null?{}:ee(E(e)),ne(t||!e||!e.__esModule?C(n,`default`,{value:e,enumerable:!0}):n,e));const k=e=>{switch(e.type){case`none`:return{};case`basic`:return re(e);case`bearer`:return ie(e);case`oauth2`:return ie(e);default:throw Error(`Invalid authentication type`)}},re=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n,i=Buffer.from(`${e}:${t}`).toString(r);return{authorization:`Basic ${i}`}},ie=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var ae=class{locks;constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);if(r&&i){i.push({lock:n,unlock:t});let e=i.length-2;await i[e].lock}else this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const oe=1e3,se=100,ce=60,le=6e4,ue=ce,de=le,fe=le*10,pe=se,me=10;let he=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var ge=class{config;instantiator;dataStore;lockManager;expiryMap;evictionFrequency;staleDataThreshold;truncateThreshold;truncationPercentage;logger;typeGuard;dispose;evictionInterval;lastAccessedAt=Date.now();constructor(e={}){this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new ae,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??de,this.staleDataThreshold=e?.staleDataThreshold??fe,this.truncateThreshold=e?.truncateThreshold??pe,this.truncationPercentage=e?.truncationPercentage??me,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async setData({key:e,value:t,cacheTTL:n=ue}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),u(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*oe,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{(u(this.typeGuard)&&this.typeGuard(t)||o(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/se;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n);let i=this.dataStore.size;return{dataStoreSize:e,prunedDataStoreSize:i}}startEvictionTask(){if(u(this.evictionInterval))return;let e=async()=>{let t;try{let n=this.lastAccessedAt+this.staleDataThreshold,r=Date.now();if(n<r){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:he.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if(u(t?.dataStoreSize)&&u(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&(clearTimeout(this.evictionInterval),this.evictionInterval=void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return u(this.evictionInterval)&&u(this.dataStore)&&u(this.expiryMap)&&u(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()),i=r.filter(t=>t.includes(e)),a=[],o=t?parseInt(t,10):0;for(let e=o;e<n+o;e++){let t=i[e];if(!t)break;let r=await this.getData(t);if(r&&a.push(r),a.length>=n)break}return{items:a,cursor:a.length<n?void 0:(o+n).toString()}}};const _e=1e3,ve=6e4;let ye=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var be=class{executorMethodStore=null;promiseStore=null;logger;eventClientConfig=null;executorMethodStoreConfig=null;pendingPromiseStoreConfig=null;constructor(e,t,n){this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new ge(i),this.promiseStore=new ge(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/_e;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return u(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);o(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??ve),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:ye.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){u(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):u(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return c(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},xe=class{instance=null;initPromise=null;retryTimeout=null;status=`uninitialized`;initOptions=null;initArgs=[];getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:(o(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,o(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let A=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const Se=async(e,t,n)=>{try{let r=await Ce.build(e,t,n);return r??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:A.RedisClientError,category:n??`buildRedisClientInstance`});return}};var Ce=class e{#redisClient;#logger;static async build({getRedisClient:t=p.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s,c){let l=new e;l.#logger=s;try{l.#redisClient=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let e=Te(c??`RedisClient`,l.#logger);return we(l.#redisClient,e),await l.#redisClient.connect(),l}catch(e){let t=e;return l.#logger?.error({message:`Error building Cache Manager.`,error:t,code:A.RedisClientError,category:c??`RedisClient`}),null}}#parseData(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#isRedisClientAvailable())return null;try{let e=await this.#redisClient.get(t);if(!e)return null;let n=this.#parseData(e);return l(n)?e:n}catch(t){let n=t;return this.#logger?.error({message:`Error getting data`,error:n,code:A.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#isRedisClientAvailable())return!1;try{let e=l(n)?n:JSON.stringify(n);return await this.#redisClient.set(t,e,{EX:r}),u(i)&&await this.#redisClient.sAdd(i,[t]),!0}catch(t){let n=t;return this.#logger?.error({message:`Error setting data`,error:n,code:A.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#logger?.error({message:`Error executing script`,error:n,code:A.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.scriptLoad(t)}catch(t){let n=t;return this.#logger?.error({message:`Error loading script`,error:n,code:A.RedisClientScriptLoadError,category:e.name}),null}}async#executeCounterCommand(t,n,r){if(!this.#isRedisClientAvailable())return null;if(!Number.isFinite(r)||r<=0)return this.#logger?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:A.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=await this.#redisClient.multiExecutor(e),a=i?.[0];return typeof a==`number`?a:null}catch(n){let r=n;return this.#logger?.error({message:`Error executing ${t} operation`,error:r,code:A.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#executeCounterCommand(`incr`,e,t)}async decrement(e,t){return this.#executeCounterCommand(`decr`,e,t)}async subscribe(t,n){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pSubscribe(t,n),!0}catch(n){let r=n;return this.#logger?.error({message:`Error subscribing to ${t}`,error:r,code:A.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pUnsubscribe(t),!0}catch(n){let r=n;return this.#logger?.error({message:`Error unsubscribing from ${t}`,error:r,code:A.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#isRedisClientAvailable())return null;try{let r=await this.#redisClient.publish(t,n);return r===0&&this.#logger?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#logger?.error({message:`Error publishing to ${t}`,error:r,code:A.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#isRedisClientAvailable()?this.#redisClient:null}#isRedisClientAvailable(){let t=this.#redisClient.isReady&&this.#redisClient.isOpen;return t||this.#logger?.error({message:`Redis Client is not ready.`,category:e.name,code:A.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#redisClient.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);u(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#logger?.error({message:`Error listing data`,error:n,code:A.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#isRedisClientAvailable())return!1;let n=await this.#redisClient.del(t);return n===0&&this.#logger?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#logger?.error({message:`Error deleting data`,error:n,code:A.RedisClientDeleteError,category:e.name}),!1}}};const we=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},Te=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:A.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let Ee=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});var De=class extends xe{redisClientConfig;scripts;scriptMap;cacheClient;logger;additionalArgs;isInitialConnection=!0;async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let s=t??await Se(e,i,this.name);if(o(s))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=s,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();u(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){o(this.scripts)||Object.keys(this.scripts).length===0||(this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts))}async loadScripts(e,t){if(u(t))for(let[e,n]of t)this.scriptMap.set(e,n);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);u(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.name,code:Ee.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{if(!this.isRedisReady())throw Error(`Redis client is not ready`);let r=this.scriptMap?.get(e);if(o(r))throw Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),o(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i}}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.name,context:{keys:t,args:n},error:r,code:Ee.ScriptManagerExecutionError}),r}}isRedisReady(){return this.isReady()&&u(this.cacheClient)}},Oe=class{options={getCacheClient:Se};subscriptionMap=null;subscriptionClient=null;logger;name=`SubscriptionManager`;constructor(e){this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new ge({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),u(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),i=r(t.toString());return await this.subscriptionMap?.setData({key:e,value:i}),n===i?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return u(this.subscriptionClient)&&u(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const ke=6e4,Ae=15e3,je=!1,Me=6e4,Ne=15e3,Pe=1e4,Fe=1;let Ie=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),Le=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var Re=class extends De{subscriptionManager=null;eventClient=null;name=`QueueManager`;async additionalInitialization(){if(o(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new Oe({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:Me,truncateThreshold:Pe,truncationPercentage:Fe}),await this.subscriptionManager?.initialize(),this.eventClient=new be({instantiator:this.name,timeoutResolveValue:je},{instantiator:this.name,evictionFrequency:Ne,truncateThreshold:Pe,truncationPercentage:Fe},{instantiator:this.name,evictionFrequency:Ne,truncateThreshold:Pe,truncationPercentage:Fe}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?Le.lPush:Le.rPush,[e],[t,ke.toString()]),s=o===1,c=i?!s:!0;return c&&await this.eventClient?.waitForEvent(a,Ae),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:Ie.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(Le.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:Ie.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(Le.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:Ie.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return u(this.subscriptionManager)&&u(this.cacheClient)&&u(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const ze=5,Be=12e4,Ve=1e4,He=1,Ue=60,We=90,Ge=`__keyevent@0__:`,Ke=`${Ge}set`,qe=`${Ge}expire`,Je=`${Ge}expired`,Ye=`${Ge}srem`,Xe=`config_check_test_key`,Ze=[Ke,qe,Je],Qe=1,$e=15e3,et={mainMaxConcurrency:30};let tt=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e}({}),nt=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const rt={[nt.tryConcurrency]:`
2
2
  local requestId = KEYS[1]
3
3
  local targetKey = KEYS[2]
4
4
  local queueKey = KEYS[3]
@@ -79,7 +79,7 @@ import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentH
79
79
  end
80
80
 
81
81
  return {success, failureReason}
82
- `,[tt.removeFromSet]:`
82
+ `,[nt.removeFromSet]:`
83
83
  local requestId = ARGV[1]
84
84
  local targetKey = KEYS[1]
85
85
 
@@ -88,7 +88,7 @@ import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentH
88
88
 
89
89
  -- Remove the requestId from the targetKey set
90
90
  return redis.call('SREM', targetKey, requestId)
91
- `,[tt.publishNextItem]:`
91
+ `,[nt.publishNextItem]:`
92
92
  local queueKey = KEYS[1]
93
93
 
94
94
  local nextItem = redis.call('lindex', queueKey, 0)
@@ -98,14 +98,14 @@ import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentH
98
98
 
99
99
  redis.call('publish', nextItemKey, nextItem)
100
100
  end
101
- `};var rt=class r extends Ee{hasValidRedisConfig=!1;subscriptionManager=null;queueManager=null;generateUUID;name=`ConcurrencyManager`;async additionalInitialization(e){if(this.generateUUID=e??n,this.subscriptionManager=new De({config:this.redisClientConfig,logger:this.logger,instantiator:this.name,subscriptionTTL:ze,truncateThreshold:Be,truncationPercentage:Ve}),await this.subscriptionManager?.initialize(),this.hasValidRedisConfig=await this.checkRedisEventsEmit(),!this.hasValidRedisConfig)throw Error(`Failed to validate Redis configuration for ConcurrencyManager`);if(o(this.getSingleton))throw Error(`getSingleton method not available`);this.queueManager=this.getSingleton?.(Le)}async addTestSubscription(e,t,n,r){return o(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(e,async(i,a)=>{a===e&&i.includes(t)&&(n.push(a),n.includes(Ge)&&n.includes(Ke)&&n.includes(qe)&&(r(),n.length=0))})}async checkRedisEventsEmit(){let e=[],t=Date.now(),n=async(n,i)=>{let a=()=>{let i=Date.now()-t;this.logger?.info({category:r.name,message:`All Redis events received successfully.`,context:{receivedEventCount:e.length,elapsedTimeMs:i}}),n(!0)},o=this.generateUUID(),s=`${Ye}:${o}`,c=(await Promise.all(Xe.map(async t=>this.addTestSubscription(t,s,e,a)))).every(Boolean);if(!c)return i(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:s,value:`test`,cacheTTL:Ze}),setTimeout(()=>{let e=Date.now()-t;i(Error(`Timeout waiting for Redis events to emit after ${e}ms.`))},Qe)};try{return await new Promise(n)}catch(n){let i=Date.now()-t;return this.logger?.error({category:r.name,message:`Redis events failed to emit.`,context:{receivedEventCount:e.length,elapsedTimeMs:i,reason:n?.message},error:n,code:et.ConcurrencyManagerRedisEventsEmitError}),!1}}isRedisConfigured(){return this.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){let n=await this.subscriptionManager?.subscribe(qe,async(n,r)=>{r===qe&&n.includes(t)&&n.includes(e)&&await this.releaseRequest(e,t)});return n??!1}async subscribeToSetRemoval(e,t){let n=await this.subscriptionManager?.subscribe(Je,async(n,r)=>{r===Je&&n.includes(e)&&await this.executeScript(tt.publishNextItem,[t],[])});return n??!1}async registerRequest(n,i,a,o){let s=`concurrency:${n}`,c=`queue:${n}`,l=i.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(o??``):o?.includes(e.urlPattern))?.subPoolKey,d=u(l)?`${s}-${l}`:s,{mainMaxConcurrency:f,subPools:p}=i,m=[{key:s,maxConcurrency:f},...p?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${s}-${t}`,maxConcurrency:n}})??[]],h=m.map(e=>e.key),g=m.map(e=>e.maxConcurrency),[_,v]=await Promise.all([this.subscribeToLeaseExpiry(a,d),this.subscribeToSetRemoval(d,c)]),y={requestId:a,targetConcurrencyKey:d,leaseSubscription:_,setRemovalSubscription:v,queueKey:c},[b,x]=await this.executeScript(tt.tryConcurrency,[a,d,c,...h],[He.toString(),f.toString(),Ue.toString(),...g.map(String)])??[];if(b)return{...y,joinCondition:`optimistic`,failureReason:x};let S=0,C=[];for(;S<Re;){let n=S>1,[i,o]=await this.queueManager?.joinAndWaitTurn(c,a,n,async(e,t)=>await this.executeScript(tt.tryConcurrency,[a,d,c,...h],[He.toString(),f.toString(),Ue.toString(),...g.map(String)]),!1)??[!1,``];if(u(o)&&o!==``&&C.push(o),S++,i)return S>1&&this.logger?.warning({category:r.name,message:`Register request succeeded after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`attempts`,failureMessages:C}}),{...y,joinCondition:`attempts`};let s=t(S,100);await e(s)}return this.logger?.error({category:r.name,message:`Failed to register request after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`failed`,failureMessages:C},code:et.ConcurrencyManagerRegistrationFailed}),{...y,joinCondition:`failed`}}async releaseRequest(e,t){return l(t)&&l(e)?!!await this.executeScript(tt.removeFromSet,[t],[e]):!1}isReady(){return this.subscriptionManager!==null&&this.cacheClient!==null&&this.scriptMap!==null&&this.scriptMap.size>0&&this.hasValidRedisConfig}close(){this.subscriptionManager?.close(),this.queueManager?.close(),this.scriptMap?.clear(),this.hasValidRedisConfig=!1}};const it=f({receivedStatus:d.number(),targetStatus:d.number(),message:d.string().optional(),condition:d.string().optional()}),at={100:`Continue`,101:`Switching Protocols`,102:`Processing`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,499:`Client Closed Request`,500:`Internal server error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,510:`Not Extended`,511:`Network Authentication Required`};var ot=class e extends Error{response;constructor(t,n){super(n),this.name=`HttpResponseError`,this.response=t,this.message=n??`HTTP error: ${t.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}};const st=e=>e instanceof Error&&e.name===`HttpResponseError`&&`response`in e&&typeof e.response==`object`&&e.response!==null,ct=(e,t=new WeakSet)=>{if(typeof e!=`object`||!e)return typeof e==`bigint`?e.toString():e;if(t.has(e))return`[Circular Reference]`;if(e instanceof Date)return e.toISOString();if(Array.isArray(e)){t.add(e);let n=e.map(e=>ct(e,t));return t.delete(e),n}let n=e,r={};t.add(n);for(let[e,i]of Object.entries(n))r[e]=ct(i,t);return t.delete(n),r},lt=e=>{if(st(e)){let t=e.response;return{name:e.name,message:e.message,stack:e.stack,response:ct(t)}}return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:{error:String(e)}};var ut=class{static createInstance({interceptors:e,instanceConfig:t,httpsAgentConfig:n,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s}){let c=new g.Agent(n),l=m.create({...t,httpsAgent:c});if(e){let t={axiosInstance:l,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s};this.applyInterceptors(l,e,t)}return l}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t,a=[{type:`request`,configs:r},{type:`response`,configs:i}];a.forEach(t=>{let{configs:r,type:i}=t;r.forEach(t=>{let{onFulfilled:r,onRejected:a,options:o}=t;if(i===`request`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n),o];e.interceptors.request.use(...t)}if(i===`response`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n)];e.interceptors.response.use(...t)}})})}static resolveInterceptorInstance(e,t){return u(e)&&i(e)&&typeof e(t)==`function`?e(t):e??null}};const dt=300;var ft=class e{static instance=null;static logger=null;dataStore=null;constructor(e){this.initialize(e)}static getInstance(t){return o(e.instance)&&(e.instance=new e(t)),e.instance}initialize(t){this.dataStore=new he({instantiator:e.name,logger:t,typeGuard:e=>u(e)}),e.logger=t??null,e.logger?.info({category:e.name,message:`InstanceManager initialized.`})}async get(t){return this.ensureReady(),await e.getInstance().dataStore?.getData(t)??null}async set(t,n,r){return this.ensureReady(),await e.getInstance().dataStore?.setData({key:t,value:n,cacheTTL:u(r)?r:dt})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return u(this?.dataStore)}close(){e.instance=null,this.dataStore=null}};const pt=ft.getInstance(),mt=()=>{let e=e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)};return e},ht=7.5,gt={mainRatelimit:25};let _t=function(e){return e.incr=`incr`,e}({}),vt=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e.RateLimitOrConcurrencyManagerNotInitialized=`RateLimitOrConcurrencyManagerNotInitialized`,e.InterceptorContextNotPresent=`InterceptorContextNotPresent`,e.InterceptorMaxWaitTimeExceeded=`InterceptorMaxWaitTimeExceeded`,e}({});const yt=(e,t,n,r)=>{let i=Error(e);return i.config={...t,headers:{}},i.code=n,i.response=r,i.isAxiosError=!0,i},bt=(e,t,n)=>{let r=t.signal;return r?r.aborted?Promise.reject(yt(`Request aborted`,t,`ERR_CANCELED`,n)):new Promise((i,a)=>{let o=!1,s,c=yt(`Request aborted`,t,`ERR_CANCELED`,n),l=()=>{if(!o){o=!0,s&&v(s);try{r.removeEventListener?.(`abort`,u)}catch{}}},u=()=>{l(),a(c)},d=()=>{l(),i()};try{r.addEventListener?.(`abort`,u,{once:!0})}catch{s=setTimeout(()=>{i()},e);return}if(r.aborted){l(),a(c);return}s=setTimeout(d,e)}):new Promise(t=>setTimeout(t,e))},xt=`checkConcurrencyInterceptor`,St=({logger:e,context:t,requestConfig:n,concurrencyManager:r,rateLimitManager:i})=>{let a=async a=>{if(a.signal?.aborted)return Promise.reject(yt(`Request aborted`,a,`ERR_CANCELED`));if(o(t))e?.warning({category:`HttpClient`,message:`No context for this request - that doesn't seem right.`,context:{interceptor:xt,...a,headers:void 0,hasContext:u(t),hasConfig:u(a)},code:vt.InterceptorContextNotPresent});else if(o(i)||o(r))e?.error({category:`HttpClient`,message:`RateLimitManager or ConcurrencyManager is not initialized`,context:{interceptor:xt,...a,headers:void 0,rateLimitManagerInitialized:u(i),concurrencyManagerInitialized:u(r)},code:vt.RateLimitOrConcurrencyManagerNotInitialized});else if(u(t.provider)&&u(t.accountSecureId)){let o=_(),{provider:s,accountSecureId:c}=t,l=n?.rateLimits??gt,u=n?.concurrency??$e,d=await i.getDynamicMaxWaitTime(l,u,a.url),f=async()=>r.registerRequest(`${c}-${s}`,u,o,a.url),p,m=0;for(;m<=d;){let n=Math.floor(Date.now()/1e3),r=await i.getWaitTime(`${c}-${s}`,l,a.url)??0,o=Math.max(r-n,0);if(r===0){p=await f();break}if(await bt(o*1e3,a),m+=o,m>=d){p=await f(),e?.warning({category:`HttpClient`,message:`Max Wait Time Exceeded for ${s} - Account: ${c}`,context:{...t,interceptor:xt,...a,headers:void 0,dynamicMaxWaitTime:d},code:vt.InterceptorMaxWaitTimeExceeded});break}}return{...a,requestMetadata:p}}return a};return a},Ct=1,wt=10,Tt=5,Et=3250368e4,Dt=1e3,Ot=/^\d+(\.\d+)?$/,kt=1e3,At=e=>e<Et?e*Dt:e;var jt=O(((exports,t)=>{function n(){return t.exports=n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,n.apply(null,arguments)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports})),Mt={epsilon:1e-12,matrix:`Matrix`,number:`number`,precision:64,predictable:!1,randomSeed:null};function M(e){return typeof e==`number`}function N(e){return!e||typeof e!=`object`||typeof e.constructor!=`function`?!1:e.isBigNumber===!0&&typeof e.constructor.prototype==`object`&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal==`function`&&e.constructor.isDecimal(e)===!0}function Nt(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Pt(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Ft(e){return e&&e.constructor.prototype.isUnit===!0||!1}function It(e){return typeof e==`string`}var P=Array.isArray;function Lt(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Rt(e){return Array.isArray(e)||Lt(e)}function zt(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Bt(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Vt(e){return e&&e.constructor.prototype.isRange===!0||!1}function Ht(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Ut(e){return typeof e==`boolean`}function Wt(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Gt(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Kt(e){return typeof e==`function`}function qt(e){return e instanceof Date}function Jt(e){return e instanceof RegExp}function Yt(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Nt(e)&&!Pt(e))}function Xt(e){return e===null}function Zt(e){return e===void 0}function Qt(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function $t(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function en(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function tn(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function nn(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function rn(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function an(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function on(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function sn(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function cn(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function ln(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function un(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function dn(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function fn(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function pn(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function mn(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function hn(e){return e&&e.constructor.prototype.isChain===!0||!1}function gn(e){var t=typeof e;return t===`object`?e===null?`null`:N(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function _n(e){var t=typeof e;if(t===`number`||t===`string`||t===`boolean`||e==null)return e;if(typeof e.clone==`function`)return e.clone();if(Array.isArray(e))return e.map(function(e){return _n(e)});if(e instanceof Date)return new Date(e.valueOf());if(N(e))return e;if(Yt(e))return vn(e,_n);throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function vn(e,t){var n={};for(var r in e)bn(e,r)&&(n[r]=t(e[r]));return n}function yn(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!yn(e[r],t[r]))return!1;return!0}else if(typeof e==`function`)return e===t;else if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!yn(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function bn(e,t){return e&&Object.hasOwnProperty.call(e,t)}function xn(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],a=e[i];a!==void 0&&(n[i]=a)}return n}var Sn=[`Matrix`,`Array`],Cn=[`number`,`BigNumber`,`Fraction`],wn=k(jt(),1),Tn=function(e){if(e)throw Error(`The global config is readonly.
101
+ `};var it=class extends De{hasValidRedisConfig=!1;subscriptionManager=null;queueManager=null;generateUUID;name=`ConcurrencyManager`;async additionalInitialization(e){if(this.generateUUID=e??n,this.subscriptionManager=new Oe({config:this.redisClientConfig,logger:this.logger,instantiator:this.name,subscriptionTTL:Be,truncateThreshold:Ve,truncationPercentage:He}),await this.subscriptionManager?.initialize(),this.hasValidRedisConfig=await this.checkRedisEventsEmit(),!this.hasValidRedisConfig)throw Error(`Failed to validate Redis configuration for ConcurrencyManager`);if(o(this.getSingleton))throw Error(`getSingleton method not available`);this.queueManager=this.getSingleton?.(Re)}async addTestSubscription(e,t,n,r){return o(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(e,async(i,a)=>{a===e&&i.includes(t)&&(n.push(a),n.includes(Ke)&&n.includes(qe)&&n.includes(Je)&&(r(),n.length=0))})}async checkRedisEventsEmit(){let e=[],t=Date.now(),n=async(n,r)=>{let i=()=>{let r=Date.now()-t;this.logger?.info({category:this.name,message:`All Redis events received successfully.`,context:{receivedEventCount:e.length,elapsedTimeMs:r}}),n(!0)},a=this.generateUUID(),o=`${Xe}:${a}`,s=(await Promise.all(Ze.map(async t=>this.addTestSubscription(t,o,e,i)))).every(Boolean);if(!s)return r(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:o,value:`test`,cacheTTL:Qe}),setTimeout(()=>{let e=Date.now()-t;r(Error(`Timeout waiting for Redis events to emit after ${e}ms.`))},$e)};try{return await new Promise(n)}catch(n){let r=Date.now()-t;return this.logger?.error({category:this.name,message:`Redis events failed to emit.`,context:{receivedEventCount:e.length,elapsedTimeMs:r,reason:n?.message},error:n,code:tt.ConcurrencyManagerRedisEventsEmitError}),!1}}isRedisConfigured(){return this.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){let n=await this.subscriptionManager?.subscribe(Je,async(n,r)=>{r===Je&&n.includes(t)&&n.includes(e)&&await this.releaseRequest(e,t)});return n??!1}async subscribeToSetRemoval(e,t){let n=await this.subscriptionManager?.subscribe(Ye,async(n,r)=>{r===Ye&&n.includes(e)&&await this.executeScript(nt.publishNextItem,[t],[])});return n??!1}async registerRequest(n,r,i,a){let o=`concurrency:${n}`,s=`queue:${n}`,c=r.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(a??``):a?.includes(e.urlPattern))?.subPoolKey,l=u(c)?`${o}-${c}`:o,{mainMaxConcurrency:d,subPools:f}=r,p=[{key:o,maxConcurrency:d},...f?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${o}-${t}`,maxConcurrency:n}})??[]],m=p.map(e=>e.key),h=p.map(e=>e.maxConcurrency),[g,_]=await Promise.all([this.subscribeToLeaseExpiry(i,l),this.subscribeToSetRemoval(l,s)]),v={requestId:i,targetConcurrencyKey:l,leaseSubscription:g,setRemovalSubscription:_,queueKey:s},[y,b]=await this.executeScript(nt.tryConcurrency,[i,l,s,...m],[Ue.toString(),d.toString(),We.toString(),...h.map(String)])??[];if(y)return{...v,joinCondition:`optimistic`,failureReason:b};let x=0,S=[];for(;x<ze;){let n=x>1,[r,a]=await this.queueManager?.joinAndWaitTurn(s,i,n,async(e,t)=>await this.executeScript(nt.tryConcurrency,[i,l,s,...m],[Ue.toString(),d.toString(),We.toString(),...h.map(String)]),!1)??[!1,``];if(u(a)&&a!==``&&S.push(a),x++,r)return x>1&&this.logger?.warning({category:this.name,message:`Register request succeeded after ${x} attempts.`,context:{...v,registerAttempts:x,joinCondition:`attempts`,failureMessages:S}}),{...v,joinCondition:`attempts`};let o=t(x,100);await e(o)}return this.logger?.error({category:this.name,message:`Failed to register request after ${x} attempts.`,context:{...v,registerAttempts:x,joinCondition:`failed`,failureMessages:S},code:tt.ConcurrencyManagerRegistrationFailed}),{...v,joinCondition:`failed`}}async releaseRequest(e,t){return l(t)&&l(e)?!!await this.executeScript(nt.removeFromSet,[t],[e]):!1}isReady(){return this.subscriptionManager!==null&&this.cacheClient!==null&&this.scriptMap!==null&&this.scriptMap.size>0&&this.hasValidRedisConfig}close(){this.subscriptionManager?.close(),this.queueManager?.close(),this.scriptMap?.clear(),this.hasValidRedisConfig=!1}};const at=f({receivedStatus:d.number(),targetStatus:d.number(),message:d.string().optional(),condition:d.string().optional()}),ot={100:`Continue`,101:`Switching Protocols`,102:`Processing`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,499:`Client Closed Request`,500:`Internal server error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,510:`Not Extended`,511:`Network Authentication Required`};var st=class e extends Error{response;constructor(t,n){super(n),this.name=`HttpResponseError`,this.response=t,this.message=n??`HTTP error: ${t.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}};const ct=e=>e instanceof Error&&e.name===`HttpResponseError`&&`response`in e&&typeof e.response==`object`&&e.response!==null,lt=(e,t=new WeakSet)=>{if(typeof e!=`object`||!e)return typeof e==`bigint`?e.toString():e;if(t.has(e))return`[Circular Reference]`;if(e instanceof Date)return e.toISOString();if(Array.isArray(e)){t.add(e);let n=e.map(e=>lt(e,t));return t.delete(e),n}let n=e,r={};t.add(n);for(let[e,i]of Object.entries(n))r[e]=lt(i,t);return t.delete(n),r},ut=e=>{if(ct(e)){let t=e.response;return{name:e.name,message:e.message,stack:e.stack,response:lt(t)}}return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:{error:String(e)}};var dt=class{static createInstance({interceptors:e,instanceConfig:t,httpsAgentConfig:n,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s}){let c=new g.Agent(n),l=m.create({...t,httpsAgent:c});if(e){let t={axiosInstance:l,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s};this.applyInterceptors(l,e,t)}return l}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t,a=[{type:`request`,configs:r},{type:`response`,configs:i}];a.forEach(t=>{let{configs:r,type:i}=t;r.forEach(t=>{let{onFulfilled:r,onRejected:a,options:o}=t;if(i===`request`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n),o];e.interceptors.request.use(...t)}if(i===`response`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n)];e.interceptors.response.use(...t)}})})}static resolveInterceptorInstance(e,t){return u(e)&&i(e)&&typeof e(t)==`function`?e(t):e??null}};const ft=300;var pt=class e{static instance=null;static logger=null;dataStore=null;constructor(e){this.initialize(e)}static getInstance(t){return o(e.instance)&&(e.instance=new e(t)),e.instance}initialize(t){this.dataStore=new ge({instantiator:e.name,logger:t,typeGuard:e=>u(e)}),e.logger=t??null,e.logger?.info({category:e.name,message:`InstanceManager initialized.`})}async get(t){return this.ensureReady(),await e.getInstance().dataStore?.getData(t)??null}async set(t,n,r){return this.ensureReady(),await e.getInstance().dataStore?.setData({key:t,value:n,cacheTTL:u(r)?r:ft})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return u(this?.dataStore)}close(){e.instance=null,this.dataStore=null}};const mt=pt.getInstance(),ht=()=>{let e=e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)};return e},gt=7.5,_t={mainRatelimit:25};let vt=function(e){return e.incr=`incr`,e}({}),yt=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e.RateLimitOrConcurrencyManagerNotInitialized=`RateLimitOrConcurrencyManagerNotInitialized`,e.InterceptorContextNotPresent=`InterceptorContextNotPresent`,e.InterceptorMaxWaitTimeExceeded=`InterceptorMaxWaitTimeExceeded`,e}({});const bt=(e,t,n,r)=>{let i=Error(e);return i.config={...t,headers:{}},i.code=n,i.response=r,i.isAxiosError=!0,i},xt=(e,t,n)=>{let r=t.signal;return r?r.aborted?Promise.reject(bt(`Request aborted`,t,`ERR_CANCELED`,n)):new Promise((i,a)=>{let o=!1,s,c=bt(`Request aborted`,t,`ERR_CANCELED`,n),l=()=>{if(!o){o=!0,s&&v(s);try{r.removeEventListener?.(`abort`,u)}catch{}}},u=()=>{l(),a(c)},d=()=>{l(),i()};try{r.addEventListener?.(`abort`,u,{once:!0})}catch{s=setTimeout(()=>{i()},e);return}if(r.aborted){l(),a(c);return}s=setTimeout(d,e)}):new Promise(t=>setTimeout(t,e))},St=`checkConcurrencyInterceptor`,Ct=({logger:e,context:t,requestConfig:n,concurrencyManager:r,rateLimitManager:i})=>{let a=async a=>{if(a.signal?.aborted)return Promise.reject(bt(`Request aborted`,a,`ERR_CANCELED`));if(o(t))e?.warning({category:`HttpClient`,message:`No context for this request - that doesn't seem right.`,context:{interceptor:St,...a,headers:void 0,hasContext:u(t),hasConfig:u(a)},code:yt.InterceptorContextNotPresent});else if(o(i)||o(r))e?.error({category:`HttpClient`,message:`RateLimitManager or ConcurrencyManager is not initialized`,context:{interceptor:St,...a,headers:void 0,rateLimitManagerInitialized:u(i),concurrencyManagerInitialized:u(r)},code:yt.RateLimitOrConcurrencyManagerNotInitialized});else if(u(t.provider)&&u(t.accountSecureId)){let o=_(),{provider:s,accountSecureId:c}=t,l=n?.rateLimits??_t,u=n?.concurrency??et,d=await i.getDynamicMaxWaitTime(l,u,a.url),f=async()=>r.registerRequest(`${c}-${s}`,u,o,a.url),p,m=0;for(;m<=d;){let n=Math.floor(Date.now()/1e3),r=await i.getWaitTime(`${c}-${s}`,l,a.url)??0,o=Math.max(r-n,0);if(r===0){p=await f();break}if(await xt(o*1e3,a),m+=o,m>=d){p=await f(),e?.warning({category:`HttpClient`,message:`Max Wait Time Exceeded for ${s} - Account: ${c}`,context:{...t,interceptor:St,...a,headers:void 0,dynamicMaxWaitTime:d},code:yt.InterceptorMaxWaitTimeExceeded});break}}return{...a,requestMetadata:p}}return a};return a},wt=1,Tt=10,Et=5,Dt=3250368e4,Ot=1e3,kt=/^\d+(\.\d+)?$/,At=1e3,jt=e=>e<Dt?e*Ot:e;var Mt=D(((exports,t)=>{function n(){return t.exports=n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,n.apply(null,arguments)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports})),Nt={epsilon:1e-12,matrix:`Matrix`,number:`number`,precision:64,predictable:!1,randomSeed:null};function j(e){return typeof e==`number`}function M(e){return!e||typeof e!=`object`||typeof e.constructor!=`function`?!1:e.isBigNumber===!0&&typeof e.constructor.prototype==`object`&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal==`function`&&e.constructor.isDecimal(e)===!0}function Pt(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Ft(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function It(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Lt(e){return typeof e==`string`}var N=Array.isArray;function Rt(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function zt(e){return Array.isArray(e)||Rt(e)}function Bt(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Vt(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Ht(e){return e&&e.constructor.prototype.isRange===!0||!1}function Ut(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Wt(e){return typeof e==`boolean`}function Gt(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Kt(e){return e&&e.constructor.prototype.isHelp===!0||!1}function qt(e){return typeof e==`function`}function Jt(e){return e instanceof Date}function Yt(e){return e instanceof RegExp}function Xt(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Pt(e)&&!Ft(e))}function Zt(e){return e===null}function Qt(e){return e===void 0}function $t(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function en(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function tn(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function nn(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function rn(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function an(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function on(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function sn(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function cn(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function ln(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function un(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function dn(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function fn(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function pn(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function mn(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function hn(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function gn(e){return e&&e.constructor.prototype.isChain===!0||!1}function _n(e){var t=typeof e;return t===`object`?e===null?`null`:M(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function vn(e){var t=typeof e;if(t===`number`||t===`string`||t===`boolean`||e==null)return e;if(typeof e.clone==`function`)return e.clone();if(Array.isArray(e))return e.map(function(e){return vn(e)});if(e instanceof Date)return new Date(e.valueOf());if(M(e))return e;if(Xt(e))return yn(e,vn);throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function yn(e,t){var n={};for(var r in e)xn(e,r)&&(n[r]=t(e[r]));return n}function bn(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!bn(e[r],t[r]))return!1;return!0}else if(typeof e==`function`)return e===t;else if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!bn(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function xn(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Sn(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],a=e[i];a!==void 0&&(n[i]=a)}return n}var Cn=[`Matrix`,`Array`],wn=[`number`,`BigNumber`,`Fraction`],Tn=O(Mt(),1),En=function(e){if(e)throw Error(`The global config is readonly.
102
102
  Please create a mathjs instance if you want to change the default configuration.
103
103
  Example:
104
104
 
105
105
  import { create, all } from 'mathjs';
106
106
  const mathjs = create(all);
107
107
  mathjs.config({ number: 'BigNumber' });
108
- `);return Object.freeze(Mt)};(0,wn.default)(Tn,Mt,{MATRIX_OPTIONS:Sn,NUMBER_OPTIONS:Cn});var En=O(((exports,t)=>{(function(n,r){typeof exports==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n[`'typed'`]=r())})(exports,(function(){"use strict";function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=Array.isArray(t)?t.join(`,`):t,o=T(a),s=x(o);if(!i||s in e.signatures){let t=e._typedFunctionData.signatureMap.get(s);if(t)return t}let c=o.length,l;if(i){l=[];let t;for(t in e.signatures)l.push(e._typedFunctionData.signatureMap.get(t))}else l=e._typedFunctionData.signatures;for(let e=0;e<c;++e){let t=o[e],n=[],r;for(r of l){let i=O(r.params,e);if(!i||t.restParam&&!i.restParam)continue;if(!i.hasAny){let e=w(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}if(l=n,l.length===0)break}let u;for(u of l)if(u.params.length<=c)return u;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(o,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++){let n=f(r[t].from);if(n.test(e))return r[t].convert(e)}throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=t?e.length>3?e.slice(3):`any`:e,r=n.split(`|`).map(e=>f(e.trim())),i=!1,a=t?`...`:``,o=r.map(function(e){return i=e.isAny||i,a+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}});return{types:o,name:a.slice(0,-1),hasAny:i,hasConversion:!1,restParam:t}}function C(e){let t=e.types.map(e=>e.name),n=se(t),r=e.hasAny,i=e.name,a=n.map(function(e){let t=f(e.from);return r=t.isAny||r,i+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(a),name:i,hasAny:r,hasConversion:a.length>0,restParam:e.restParam}}function w(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function T(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=S(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function E(e){let t=ye(e);return t?t.restParam:!1}function D(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function ee(e){let t,n,r;if(E(e)){t=ve(e).map(D);let n=t.length,r=D(ye(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=D(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=D(e[0]),r=D(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(D),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function O(e,t){return t<e.length?e[t]:E(e)?ye(e):null}function te(e,t){let n=O(e,t);return n?w(n):new Set}function k(e){return e.conversion===null||e.conversion===void 0}function A(e,t){let n=new Set;return e.forEach(e=>{let r=te(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function ne(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=O(n.params,s),i=D(r);(s<n.params.length||E(n.params))&&i(t[s])&&e.push(n)}),e.length===0){if(i=A(o,s),i.length>0){let e=g(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return E(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=A(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(g(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function re(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)k(e.types[n])&&(t=Math.min(t,e.types[n].typeIndex));return t}function ie(e){let t=u+1;for(let n=0;n<e.types.length;n++)k(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function ae(e,t){if(e.hasAny){if(!t.hasAny)return 1}else if(t.hasAny)return-1;if(e.restParam){if(!t.restParam)return 1}else if(t.restParam)return-1;if(e.hasConversion){if(!t.hasConversion)return 1}else if(t.hasConversion)return-1;let n=re(e)-re(t);if(n<0)return-1;if(n>0)return 1;let r=ie(e)-ie(t);return r<0?-1:r>0?1:0}function oe(e,t){let n=e.params,r=t.params,i=ye(n),a=ye(r),o=E(n),s=E(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1}else if(s&&a.hasAny)return-1;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return c-d;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1}else if(s&&a.hasConversion)return-1;if(l!==f)return l-f;if(o){if(!s)return 1}else if(s)return-1;let p=(n.length-r.length)*(o?-1:1);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=ae(n[e],r[e]);m.push(t),h+=t}if(h!==0)return h;let g;for(g of m)if(g!==0)return g;return 0}function se(e){if(e.length===0)return[];let t=e.map(f);e.length>1&&t.sort((e,t)=>e.index-t.index);let n=t[0].conversionsTo;if(e.length===1)return n;n=n.concat([]);let r=new Set(e);for(let e=1;e<t.length;++e){let i;for(i of t[e].conversionsTo)r.has(i.from)||(n.push(i),r.add(i.from))}return n}function ce(e,t){let n=t;if(e.some(e=>e.hasConversion)){let r=E(e),i=e.map(le);n=function(){let e=[],n=r?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=i[t](arguments[t]);return r&&(e[n]=arguments[n].map(i[n])),t.apply(this,e)}}let r=n;if(E(e)){let t=e.length-1;r=function(){return n.apply(this,be(arguments,0,t).concat([be(arguments,t)]))}}return r}function le(e){let t,n,r,i,a=[],o=[];switch(e.types.forEach(function(e){e.conversion&&(a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),o.length){case 0:return function(e){return e};case 1:return t=a[0],r=o[0],function(e){return t(e)?r(e):e};case 2:return t=a[0],n=a[1],r=o[0],i=o[1],function(e){return t(e)?r(e):n(e)?i(e):e};default:return function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}}function ue(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(k);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return xe(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function de(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=te(e,r),i=te(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=E(e),o=E(t);return a?o?r===i:i>=r:o?r>=i:r===i}function fe(e){return e.map(e=>Ee(e)?we(e.referToSelf.callback):Te(e)?Ce(e.referTo.references,e.referTo.callback):e)}function pe(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function me(e,t,n){let r=fe(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(Ee(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(Te(s)){let n=pe(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function he(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function ge(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&he(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=T(c);if(!e)continue;i.forEach(function(t){if(de(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of ue(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(oe);let l=me(a,o,Ae),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!E(f[0].params),h=f[1]&&f[1].params.length<=2&&!E(f[1].params),g=f[2]&&f[2].params.length<=2&&!E(f[2].params),_=f[3]&&f[3].params.length<=2&&!E(f[3].params),v=f[4]&&f[4].params.length<=2&&!E(f[4].params),y=f[5]&&f[5].params.length<=2&&!E(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=ee(f[e].params);let S=m?D(f[0].params[0]):t,w=h?D(f[1].params[0]):t,O=g?D(f[2].params[0]):t,te=_?D(f[3].params[0]):t,k=v?D(f[4].params[0]):t,A=y?D(f[5].params[0]):t,ne=m?D(f[0].params[1]):t,re=h?D(f[1].params[1]):t,ie=g?D(f[2].params[1]):t,ae=_?D(f[3].params[1]):t,se=v?D(f[4].params[1]):t,le=y?D(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=ce(f[e].params,f[e].fn);let fe=m?f[0].implementation:n,pe=h?f[1].implementation:n,ge=g?f[2].implementation:n,_e=_?f[3].implementation:n,ve=v?f[4].implementation:n,ye=y?f[5].implementation:n,be=m?f[0].params.length:-1,j=h?f[1].params.length:-1,xe=g?f[2].params.length:-1,Se=_?f[3].params.length:-1,Ce=v?f[4].params.length:-1,we=y?f[5].params.length:-1,Te=b?6:0,Ee=f.length,De=f.map(e=>e.test),Oe=f.map(e=>e.implementation),ke=function(){for(let e=Te;e<Ee;e++)if(De[e](arguments))return Oe[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function Ae(e,t){return arguments.length===be&&S(e)&&ne(t)?fe.apply(this,arguments):arguments.length===j&&w(e)&&re(t)?pe.apply(this,arguments):arguments.length===xe&&O(e)&&ie(t)?ge.apply(this,arguments):arguments.length===Se&&te(e)&&ae(t)?_e.apply(this,arguments):arguments.length===Ce&&k(e)&&se(t)?ve.apply(this,arguments):arguments.length===we&&A(e)&&le(t)?ye.apply(this,arguments):ke.apply(this,arguments)}try{Object.defineProperty(Ae,`name`,{value:e})}catch{}return Ae.signatures=o,Ae._typedFunctionData={signatures:f,signatureMap:p},Ae}function _e(e,t,n){throw ne(e,t,n)}function ve(e){return be(e,0,e.length-1)}function ye(e){return e[e.length-1]}function be(e,t,n){return Array.prototype.slice.call(e,t,n)}function j(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function xe(e,t){return Array.prototype.concat.apply([],e.map(t))}function Se(){let e=ve(arguments).map(e=>x(T(e))),t=ye(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return Ce(e,t)}function Ce(e,t){return{referTo:{references:e,callback:t}}}function we(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function Te(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function Ee(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function De(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function Oe(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=De(t,e[n].name));return t}function ke(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let Ae=d;d=function(e){let t=typeof e==`string`,n=t?1:0,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=Oe(n))),Object.keys(o).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=De(r,s)),ke(i,o)}return ge(r||``,i)},d.create=i,d.createCount=Ae.createCount,d.onMismatch=_e,d.throwMismatchError=_e,d.createError=ne,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=Se,d.referToSelf=we,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function je(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};je(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){je(e);let t=f(e.to),n=j(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}var a=i();return a}))}));function F(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function Dn(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`},i=r[t],a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!F(n))throw Error(`size must be an integer`);if(e>2**(n-1)-1||e<-(2**(n-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!F(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),a=`i${n}`}var o=``;return e<0&&(e=-e,o=`-`),`${o}${i}${e.toString(t)}${a}`}function On(e,t){if(typeof t==`function`)return t(e);if(e===1/0)return`Infinity`;if(e===-1/0)return`-Infinity`;if(isNaN(e))return`NaN`;var n=`auto`,r,i;if(t&&(t.notation&&(n=t.notation),M(t)?r=t:M(t.precision)&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return jn(e,r);case`exponential`:return Mn(e,r);case`engineering`:return An(e,r);case`bin`:return Dn(e,2,i);case`oct`:return Dn(e,8,i);case`hex`:return Dn(e,16,i);case`auto`:return Nn(e,r,t&&t).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function kn(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw SyntaxError(`Invalid number `+e);var n=t[1],r=t[2],i=parseFloat(t[4]||`0`),a=r.indexOf(`.`);i+=a===-1?r.length-1:a-1;var o=r.replace(`.`,``).replace(/^0*/,function(e){return i-=e.length,``}).replace(/0*$/,``).split(``).map(function(e){return parseInt(e)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function An(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=kn(e),r=Pn(n,t),i=r.exponent,a=r.coefficients,o=i%3==0?i:i<0?i-3-i%3:i-i%3;if(M(t))for(;t>a.length||i-o+1>a.length;)a.push(0);else for(var s=Math.abs(i-o)-(a.length-1),c=0;c<s;c++)a.push(0);for(var l=Math.abs(i-o),u=1;l>0;)u++,l--;var d=a.slice(u).join(``),f=M(t)&&d.length||d.match(/[1-9]/)?`.`+d:``,p=a.slice(0,u).join(``)+f+`e`+(i>=0?`+`:``)+o.toString();return r.sign+p}function jn(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=kn(e),r=typeof t==`number`?Pn(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(Fn(o-i.length))),a<0&&(i=Fn(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Mn(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=kn(e),r=t?Pn(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(Fn(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Nn(e,t,n){if(isNaN(e)||!isFinite(e))return String(e);var r=n&&n.lowerExp!==void 0?n.lowerExp:-3,i=n&&n.upperExp!==void 0?n.upperExp:5,a=kn(e),o=t?Pn(a,t):a;if(o.exponent<r||o.exponent>=i)return Mn(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(Fn(t-s.length))),s=s.concat(Fn(c-s.length+1+(s.length<t?t-s.length:0))),s=Fn(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function Pn(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t){var i=r.splice(t,r.length-t);if(i[0]>=5){var a=t-1;for(r[a]++;r[a]===10;)r.pop(),a===0&&(r.unshift(0),n.exponent++,a++),a--,r[a]++}}return n}function Fn(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function In(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function Ln(e,t,n){var r=e.constructor,i=new r(2),a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!F(n))throw Error(`size must be an integer`);if(e.greaterThan(i.pow(n-1).sub(1))||e.lessThan(i.pow(n-1).mul(-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!e.isInteger())throw Error(`Value must be an integer`);e.lessThan(0)&&(e=e.add(i.pow(n))),a=`i${n}`}switch(t){case 2:return`${e.toBinary()}${a}`;case 8:return`${e.toOctal()}${a}`;case 16:return`${e.toHexadecimal()}${a}`;default:throw Error(`Base ${t} not supported `)}}function Rn(e,t){if(typeof t==`function`)return t(e);if(!e.isFinite())return e.isNaN()?`NaN`:e.gt(0)?`Infinity`:`-Infinity`;var n=`auto`,r,i;if(t!==void 0&&(t.notation&&(n=t.notation),typeof t==`number`?r=t:t.precision!==void 0&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return Vn(e,r);case`exponential`:return Bn(e,r);case`engineering`:return zn(e,r);case`bin`:return Ln(e,2,i);case`oct`:return Ln(e,8,i);case`hex`:return Ln(e,16,i);case`auto`:var a=t&&t.lowerExp!==void 0?t.lowerExp:-3,o=t&&t.upperExp!==void 0?t.upperExp:5;if(e.isZero())return`0`;var s,c=e.toSignificantDigits(r),l=c.e;return s=l>=a&&l<o?c.toFixed():Bn(e,r),s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function zn(e,t){var n=e.e,r=n%3==0?n:n<0?n-3-n%3:n-n%3,i=e.mul(10**-r),a=i.toPrecision(t);if(a.indexOf(`e`)!==-1){var o=e.constructor;a=new o(a).toFixed()}return a+`e`+(n>=0?`+`:``)+r.toString()}function Bn(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function Vn(e,t){return e.toFixed(t)}function Hn(e,t){var n=Un(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function Un(e,t){if(typeof e==`number`)return On(e,t);if(N(e))return Rn(e,t);if(qn(e))return!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString();if(Array.isArray(e))return Kn(e,t);if(It(e))return Wn(e);if(typeof e==`function`)return e.syntax?String(e.syntax):`function`;if(e&&typeof e==`object`){if(typeof e.format==`function`)return e.format(t);if(e&&e.toString(t)!=={}.toString())return e.toString(t);var n=Object.keys(e).map(n=>Wn(n)+`: `+Hn(e[n],t));return`{`+n.join(`, `)+`}`}return String(e)}function Wn(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Gn?Gn[i]:i,r++}return`"`+n+`"`}var Gn={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function Kn(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=Kn(e[i],t);return n+=`]`,n}else return Hn(e,t)}function qn(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function I(e,t,n){if(!(this instanceof I))throw SyntaxError(`Constructor must be called with the new operator`);this.actual=e,this.expected=t,this.relation=n,this.message=`Dimension mismatch (`+(Array.isArray(e)?`[`+e.join(`, `)+`]`:e)+` `+(this.relation||`!=`)+` `+(Array.isArray(t)?`[`+t.join(`, `)+`]`:t)+`)`,this.stack=Error().stack}I.prototype=RangeError(),I.prototype.constructor=RangeError,I.prototype.name=`DimensionError`,I.prototype.isDimensionError=!0;function Jn(e,t,n){if(!(this instanceof Jn))throw SyntaxError(`Constructor must be called with the new operator`);this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.min!==void 0&&this.index<this.min?this.message=`Index out of range (`+this.index+` < `+this.min+`)`:this.max!==void 0&&this.index>=this.max?this.message=`Index out of range (`+this.index+` > `+(this.max-1)+`)`:this.message=`Index out of range (`+this.index+`)`,this.stack=Error().stack}Jn.prototype=RangeError(),Jn.prototype.constructor=RangeError,Jn.prototype.name=`IndexError`,Jn.prototype.isIndexError=!0;var Yn=k(jt(),1);function Xn(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function Zn(e,t,n){var r,i=e.length;if(i!==t[n])throw new I(i,t[n]);if(n<t.length-1){var a=n+1;for(r=0;r<i;r++){var o=e[r];if(!Array.isArray(o))throw new I(t.length-1,t.length,`<`);Zn(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new I(t.length+1,t.length,`>`)}function Qn(e,t){var n=t.length===0;if(n){if(Array.isArray(e))throw new I(e.length,0)}else Zn(e,t,0)}function L(e,t){if(e!==void 0){if(!M(e)||!F(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new Jn(e,t)}}function $n(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);t.forEach(function(e){if(!M(e)||!F(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Hn(t)+`)`)}),(M(e)||N(e))&&(e=[e]);var r=n===void 0?0:n;return er(e,t,0,r),e}function er(e,t,n,r){var i,a,o=e.length,s=t[n],c=Math.min(o,s);if(e.length=s,n<t.length-1){var l=n+1;for(i=0;i<c;i++)a=e[i],Array.isArray(a)||(a=[a],e[i]=a),er(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,er(a,t,l,r)}else{for(i=0;i<c;i++)for(;Array.isArray(e[i]);)e[i]=e[i][0];for(i=c;i<s;i++)e[i]=r}}function tr(e,t){var n=sr(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new I(0,r,`!=`);t=nr(t,r);var i=rr(t);if(r!==i)throw new I(i,r,`!=`);try{return ir(n,t)}catch(e){throw e instanceof I?new I(i,r,`!=`):e}}function nr(e,t){var n=rr(e),r=e.slice(),i=-1,a=e.indexOf(i),o=e.indexOf(i,a+1)>=0;if(o)throw Error(`More than one wildcard in sizes`);var s=a>=0,c=t%n===0;if(s)if(c)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function rr(e){return e.reduce((e,t)=>e*t,1)}function ir(e,t){for(var n=e,r,i=t.length-1;i>0;i--){var a=t[i];r=[];for(var o=n.length/a,s=0;s<o;s++)r.push(n.slice(s*a,(s+1)*a));n=r}return n}function ar(e,t,n,r){var i=r||Xn(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=or(e,t,0);i.length<t;)i.push(1);return e}function or(e,t,n){var r,i;if(Array.isArray(e)){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=or(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function sr(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function e(n){Array.isArray(n)?n.forEach(e):t.push(n)}),t}function cr(e,t){for(var n,r=0,i=0;i<e.length;i++){var a=e[i],o=Array.isArray(a);if(i===0&&o&&(r=a.length),o&&a.length!==r)return;var s=o?cr(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function lr(e,t,n,r){if(r<n){if(e.length!==t.length)throw new I(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=lr(e[a],t[a],n,r+1);return i}else return e.concat(t)}function ur(){var e=Array.prototype.slice.call(arguments,0,-1),t=Array.prototype.slice.call(arguments,-1);if(e.length===1)return e[0];if(e.length>1)return e.slice(1).reduce(function(e,n){return lr(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function dr(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t.map(e=>e.length),i=Math.max(...r),a=Array(i).fill(null),o=0;o<t.length;o++)for(var s=t[o],c=r[o],l=0;l<c;l++){var u=i-c+l;s[l]>a[u]&&(a[u]=s[l])}for(var d=0;d<t.length;d++)fr(t[d],a);return a}function fr(e,t){for(var n=t.length,r=e.length,i=0;i<r;i++){var a=n-r+i;if(e[i]<t[a]&&e[i]>1||e[i]>t[a])throw Error(`shape missmatch: missmatch is found in arg with shape (${e}) not possible to broadcast dimension ${r} with size ${e[i]} to size ${t[a]}`)}}function pr(e,t){var n=Xn(e);if(yn(n,t))return e;fr(n,t);var r=dr(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=hr(e);n.length<i&&(o=tr(o,a),n=Xn(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=mr(o,r[s],s),n=Xn(o));return o}function mr(e,t,n){return ur(...Array(t).fill(e),n)}function hr(e){return(0,Yn.default)([],e)}function gr(e,t,n,r){function i(r){var i=xn(r,t.map(yr));return _r(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function _r(e,t,n){var r=t.filter(e=>!vr(e)).every(e=>n[e]!==void 0);if(!r){var i=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${i.map(e=>`"${e}"`).join(`, `)}.`)}}function vr(e){return e&&e[0]===`?`}function yr(e){return e&&e[0]===`?`?e.slice(1):e}function br(e,t){if(Tr(e)&&Cr(e,t))return e[t];throw typeof e[t]==`function`&&wr(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function xr(e,t,n){if(Tr(e)&&Cr(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function Sr(e,t){return t in e}function Cr(e,t){return!e||typeof e!=`object`?!1:bn(Er,t)?!0:!(t in Object.prototype||t in Function.prototype)}function wr(e,t){return e==null||typeof e[t]!=`function`||bn(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:bn(Dr,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Tr(e){return typeof e==`object`&&e&&e.constructor===Object}var Er={length:!0,name:!0},Dr={toString:!0,valueOf:!0,toLocaleString:!0},Or=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return br(this.wrappedObject,e)}set(e,t){return xr(this.wrappedObject,e,t),this}has(e){return Sr(this.wrappedObject,e)}};function kr(e){return e?e instanceof Map||e instanceof Or||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var Ar=k(En(),1),jr=function(){return jr=Ar.default.create,Ar.default},Mr=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],Nr=gr(`typed`,Mr,function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=jr();return a.clear(),a.addTypes([{name:`number`,test:M},{name:`Complex`,test:Nt},{name:`BigNumber`,test:N},{name:`Fraction`,test:Pt},{name:`Unit`,test:Ft},{name:`identifier`,test:e=>It&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])*$/.test(e)},{name:`string`,test:It},{name:`Chain`,test:hn},{name:`Array`,test:P},{name:`Matrix`,test:Lt},{name:`DenseMatrix`,test:zt},{name:`SparseMatrix`,test:Bt},{name:`Range`,test:Vt},{name:`Index`,test:Ht},{name:`boolean`,test:Ut},{name:`ResultSet`,test:Wt},{name:`Help`,test:Gt},{name:`function`,test:Kt},{name:`Date`,test:qt},{name:`RegExp`,test:Jt},{name:`null`,test:Xt},{name:`undefined`,test:Zt},{name:`AccessorNode`,test:Qt},{name:`ArrayNode`,test:$t},{name:`AssignmentNode`,test:en},{name:`BlockNode`,test:tn},{name:`ConditionalNode`,test:nn},{name:`ConstantNode`,test:rn},{name:`FunctionNode`,test:on},{name:`FunctionAssignmentNode`,test:an},{name:`IndexNode`,test:sn},{name:`Node`,test:cn},{name:`ObjectNode`,test:ln},{name:`OperatorNode`,test:un},{name:`ParenthesisNode`,test:dn},{name:`RangeNode`,test:fn},{name:`RelationalNode`,test:pn},{name:`SymbolNode`,test:mn},{name:`Map`,test:kr},{name:`Object`,test:Yt}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Pr(e),In(e)>15)throw TypeError(`Cannot implicitly convert a number with >15 significant digits to BigNumber (value: `+e+`). Use function bignumber(x) to convert to BigNumber.`);return new t(e)}},{from:`number`,to:`Complex`,convert:function(e){return n||Fr(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||Fr(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function(e){throw TypeError(`Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.`)}},{from:`Fraction`,to:`Complex`,convert:function(e){return n||Fr(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||Lr(e);var t=new i(e);if(t.valueOf()!==e)throw TypeError(`Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: `+e+`). Use function fraction(x) to convert to Fraction.`);return t}},{from:`string`,to:`number`,convert:function(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function(e){t||Pr(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function(e){i||Lr(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||Fr(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function(e){return t||Pr(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||Lr(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||Ir(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function(e){return e.valueOf()}}]),a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&Rt(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&Rt(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a});function Pr(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function Fr(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function Ir(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function Lr(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}
108
+ `);return Object.freeze(Nt)};(0,Tn.default)(En,Nt,{MATRIX_OPTIONS:Cn,NUMBER_OPTIONS:wn});var Dn=D(((exports,t)=>{(function(n,r){typeof exports==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n[`'typed'`]=r())})(exports,(function(){"use strict";function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=Array.isArray(t)?t.join(`,`):t,o=w(a),s=x(o);if(!i||s in e.signatures){let t=e._typedFunctionData.signatureMap.get(s);if(t)return t}let c=o.length,l;if(i){l=[];let t;for(t in e.signatures)l.push(e._typedFunctionData.signatureMap.get(t))}else l=e._typedFunctionData.signatures;for(let e=0;e<c;++e){let t=o[e],n=[],r;for(r of l){let i=D(r.params,e);if(!i||t.restParam&&!i.restParam)continue;if(!i.hasAny){let e=C(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}if(l=n,l.length===0)break}let u;for(u of l)if(u.params.length<=c)return u;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(o,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++){let n=f(r[t].from);if(n.test(e))return r[t].convert(e)}throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=t?e.length>3?e.slice(3):`any`:e,r=n.split(`|`).map(e=>f(e.trim())),i=!1,a=t?`...`:``,o=r.map(function(e){return i=e.isAny||i,a+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}});return{types:o,name:a.slice(0,-1),hasAny:i,hasConversion:!1,restParam:t}}function ee(e){let t=e.types.map(e=>e.name),n=ce(t),r=e.hasAny,i=e.name,a=n.map(function(e){let t=f(e.from);return r=t.isAny||r,i+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(a),name:i,hasAny:r,hasConversion:a.length>0,restParam:e.restParam}}function C(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function w(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=S(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function T(e){let t=be(e);return t?t.restParam:!1}function E(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function te(e){let t,n,r;if(T(e)){t=ye(e).map(E);let n=t.length,r=E(be(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=E(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=E(e[0]),r=E(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(E),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function D(e,t){return t<e.length?e[t]:T(e)?be(e):null}function ne(e,t){let n=D(e,t);return n?C(n):new Set}function O(e){return e.conversion===null||e.conversion===void 0}function k(e,t){let n=new Set;return e.forEach(e=>{let r=ne(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function re(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=D(n.params,s),i=E(r);(s<n.params.length||T(n.params))&&i(t[s])&&e.push(n)}),e.length===0){if(i=k(o,s),i.length>0){let e=g(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return T(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=k(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(g(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function ie(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)O(e.types[n])&&(t=Math.min(t,e.types[n].typeIndex));return t}function ae(e){let t=u+1;for(let n=0;n<e.types.length;n++)O(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function oe(e,t){if(e.hasAny){if(!t.hasAny)return 1}else if(t.hasAny)return-1;if(e.restParam){if(!t.restParam)return 1}else if(t.restParam)return-1;if(e.hasConversion){if(!t.hasConversion)return 1}else if(t.hasConversion)return-1;let n=ie(e)-ie(t);if(n<0)return-1;if(n>0)return 1;let r=ae(e)-ae(t);return r<0?-1:r>0?1:0}function se(e,t){let n=e.params,r=t.params,i=be(n),a=be(r),o=T(n),s=T(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1}else if(s&&a.hasAny)return-1;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return c-d;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1}else if(s&&a.hasConversion)return-1;if(l!==f)return l-f;if(o){if(!s)return 1}else if(s)return-1;let p=(n.length-r.length)*(o?-1:1);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=oe(n[e],r[e]);m.push(t),h+=t}if(h!==0)return h;let g;for(g of m)if(g!==0)return g;return 0}function ce(e){if(e.length===0)return[];let t=e.map(f);e.length>1&&t.sort((e,t)=>e.index-t.index);let n=t[0].conversionsTo;if(e.length===1)return n;n=n.concat([]);let r=new Set(e);for(let e=1;e<t.length;++e){let i;for(i of t[e].conversionsTo)r.has(i.from)||(n.push(i),r.add(i.from))}return n}function le(e,t){let n=t;if(e.some(e=>e.hasConversion)){let r=T(e),i=e.map(ue);n=function(){let e=[],n=r?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=i[t](arguments[t]);return r&&(e[n]=arguments[n].map(i[n])),t.apply(this,e)}}let r=n;if(T(e)){let t=e.length-1;r=function(){return n.apply(this,xe(arguments,0,t).concat([xe(arguments,t)]))}}return r}function ue(e){let t,n,r,i,a=[],o=[];switch(e.types.forEach(function(e){e.conversion&&(a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),o.length){case 0:return function(e){return e};case 1:return t=a[0],r=o[0],function(e){return t(e)?r(e):e};case 2:return t=a[0],n=a[1],r=o[0],i=o[1],function(e){return t(e)?r(e):n(e)?i(e):e};default:return function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}}function de(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(O);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return Se(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function fe(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=ne(e,r),i=ne(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=T(e),o=T(t);return a?o?r===i:i>=r:o?r>=i:r===i}function pe(e){return e.map(e=>De(e)?Te(e.referToSelf.callback):Ee(e)?we(e.referTo.references,e.referTo.callback):e)}function me(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function he(e,t,n){let r=pe(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(De(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(Ee(s)){let n=me(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function ge(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function _e(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&ge(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=w(c);if(!e)continue;i.forEach(function(t){if(fe(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(ee),l;for(l of de(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(se);let l=he(a,o,je),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!T(f[0].params),h=f[1]&&f[1].params.length<=2&&!T(f[1].params),g=f[2]&&f[2].params.length<=2&&!T(f[2].params),_=f[3]&&f[3].params.length<=2&&!T(f[3].params),v=f[4]&&f[4].params.length<=2&&!T(f[4].params),y=f[5]&&f[5].params.length<=2&&!T(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=te(f[e].params);let S=m?E(f[0].params[0]):t,C=h?E(f[1].params[0]):t,D=g?E(f[2].params[0]):t,ne=_?E(f[3].params[0]):t,O=v?E(f[4].params[0]):t,k=y?E(f[5].params[0]):t,re=m?E(f[0].params[1]):t,ie=h?E(f[1].params[1]):t,ae=g?E(f[2].params[1]):t,oe=_?E(f[3].params[1]):t,ce=v?E(f[4].params[1]):t,ue=y?E(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=le(f[e].params,f[e].fn);let pe=m?f[0].implementation:n,me=h?f[1].implementation:n,_e=g?f[2].implementation:n,ve=_?f[3].implementation:n,ye=v?f[4].implementation:n,be=y?f[5].implementation:n,xe=m?f[0].params.length:-1,A=h?f[1].params.length:-1,Se=g?f[2].params.length:-1,Ce=_?f[3].params.length:-1,we=v?f[4].params.length:-1,Te=y?f[5].params.length:-1,Ee=b?6:0,De=f.length,Oe=f.map(e=>e.test),ke=f.map(e=>e.implementation),Ae=function(){for(let e=Ee;e<De;e++)if(Oe[e](arguments))return ke[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function je(e,t){return arguments.length===xe&&S(e)&&re(t)?pe.apply(this,arguments):arguments.length===A&&C(e)&&ie(t)?me.apply(this,arguments):arguments.length===Se&&D(e)&&ae(t)?_e.apply(this,arguments):arguments.length===Ce&&ne(e)&&oe(t)?ve.apply(this,arguments):arguments.length===we&&O(e)&&ce(t)?ye.apply(this,arguments):arguments.length===Te&&k(e)&&ue(t)?be.apply(this,arguments):Ae.apply(this,arguments)}try{Object.defineProperty(je,`name`,{value:e})}catch{}return je.signatures=o,je._typedFunctionData={signatures:f,signatureMap:p},je}function ve(e,t,n){throw re(e,t,n)}function ye(e){return xe(e,0,e.length-1)}function be(e){return e[e.length-1]}function xe(e,t,n){return Array.prototype.slice.call(e,t,n)}function A(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function Se(e,t){return Array.prototype.concat.apply([],e.map(t))}function Ce(){let e=ye(arguments).map(e=>x(w(e))),t=be(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return we(e,t)}function we(e,t){return{referTo:{references:e,callback:t}}}function Te(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function Ee(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function De(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function Oe(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function ke(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=Oe(t,e[n].name));return t}function Ae(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let je=d;d=function(e){let t=typeof e==`string`,n=t?1:0,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=ke(n))),Object.keys(o).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=Oe(r,s)),Ae(i,o)}return _e(r||``,i)},d.create=i,d.createCount=je.createCount,d.onMismatch=ve,d.throwMismatchError=ve,d.createError=re,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=Ce,d.referToSelf=Te,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function Me(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};Me(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){Me(e);let t=f(e.to),n=A(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}var a=i();return a}))}));function P(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function On(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`},i=r[t],a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!P(n))throw Error(`size must be an integer`);if(e>2**(n-1)-1||e<-(2**(n-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!P(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),a=`i${n}`}var o=``;return e<0&&(e=-e,o=`-`),`${o}${i}${e.toString(t)}${a}`}function kn(e,t){if(typeof t==`function`)return t(e);if(e===1/0)return`Infinity`;if(e===-1/0)return`-Infinity`;if(isNaN(e))return`NaN`;var n=`auto`,r,i;if(t&&(t.notation&&(n=t.notation),j(t)?r=t:j(t.precision)&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return Mn(e,r);case`exponential`:return Nn(e,r);case`engineering`:return jn(e,r);case`bin`:return On(e,2,i);case`oct`:return On(e,8,i);case`hex`:return On(e,16,i);case`auto`:return Pn(e,r,t&&t).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function An(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw SyntaxError(`Invalid number `+e);var n=t[1],r=t[2],i=parseFloat(t[4]||`0`),a=r.indexOf(`.`);i+=a===-1?r.length-1:a-1;var o=r.replace(`.`,``).replace(/^0*/,function(e){return i-=e.length,``}).replace(/0*$/,``).split(``).map(function(e){return parseInt(e)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function jn(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=An(e),r=Fn(n,t),i=r.exponent,a=r.coefficients,o=i%3==0?i:i<0?i-3-i%3:i-i%3;if(j(t))for(;t>a.length||i-o+1>a.length;)a.push(0);else for(var s=Math.abs(i-o)-(a.length-1),c=0;c<s;c++)a.push(0);for(var l=Math.abs(i-o),u=1;l>0;)u++,l--;var d=a.slice(u).join(``),f=j(t)&&d.length||d.match(/[1-9]/)?`.`+d:``,p=a.slice(0,u).join(``)+f+`e`+(i>=0?`+`:``)+o.toString();return r.sign+p}function Mn(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=An(e),r=typeof t==`number`?Fn(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(In(o-i.length))),a<0&&(i=In(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Nn(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=An(e),r=t?Fn(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(In(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Pn(e,t,n){if(isNaN(e)||!isFinite(e))return String(e);var r=n&&n.lowerExp!==void 0?n.lowerExp:-3,i=n&&n.upperExp!==void 0?n.upperExp:5,a=An(e),o=t?Fn(a,t):a;if(o.exponent<r||o.exponent>=i)return Nn(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(In(t-s.length))),s=s.concat(In(c-s.length+1+(s.length<t?t-s.length:0))),s=In(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function Fn(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t){var i=r.splice(t,r.length-t);if(i[0]>=5){var a=t-1;for(r[a]++;r[a]===10;)r.pop(),a===0&&(r.unshift(0),n.exponent++,a++),a--,r[a]++}}return n}function In(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function Ln(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function Rn(e,t,n){var r=e.constructor,i=new r(2),a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!P(n))throw Error(`size must be an integer`);if(e.greaterThan(i.pow(n-1).sub(1))||e.lessThan(i.pow(n-1).mul(-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!e.isInteger())throw Error(`Value must be an integer`);e.lessThan(0)&&(e=e.add(i.pow(n))),a=`i${n}`}switch(t){case 2:return`${e.toBinary()}${a}`;case 8:return`${e.toOctal()}${a}`;case 16:return`${e.toHexadecimal()}${a}`;default:throw Error(`Base ${t} not supported `)}}function zn(e,t){if(typeof t==`function`)return t(e);if(!e.isFinite())return e.isNaN()?`NaN`:e.gt(0)?`Infinity`:`-Infinity`;var n=`auto`,r,i;if(t!==void 0&&(t.notation&&(n=t.notation),typeof t==`number`?r=t:t.precision!==void 0&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return Hn(e,r);case`exponential`:return Vn(e,r);case`engineering`:return Bn(e,r);case`bin`:return Rn(e,2,i);case`oct`:return Rn(e,8,i);case`hex`:return Rn(e,16,i);case`auto`:var a=t&&t.lowerExp!==void 0?t.lowerExp:-3,o=t&&t.upperExp!==void 0?t.upperExp:5;if(e.isZero())return`0`;var s,c=e.toSignificantDigits(r),l=c.e;return s=l>=a&&l<o?c.toFixed():Vn(e,r),s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function Bn(e,t){var n=e.e,r=n%3==0?n:n<0?n-3-n%3:n-n%3,i=e.mul(10**-r),a=i.toPrecision(t);if(a.indexOf(`e`)!==-1){var o=e.constructor;a=new o(a).toFixed()}return a+`e`+(n>=0?`+`:``)+r.toString()}function Vn(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function Hn(e,t){return e.toFixed(t)}function Un(e,t){var n=Wn(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function Wn(e,t){if(typeof e==`number`)return kn(e,t);if(M(e))return zn(e,t);if(Jn(e))return!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString();if(Array.isArray(e))return qn(e,t);if(Lt(e))return Gn(e);if(typeof e==`function`)return e.syntax?String(e.syntax):`function`;if(e&&typeof e==`object`){if(typeof e.format==`function`)return e.format(t);if(e&&e.toString(t)!=={}.toString())return e.toString(t);var n=Object.keys(e).map(n=>Gn(n)+`: `+Un(e[n],t));return`{`+n.join(`, `)+`}`}return String(e)}function Gn(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Kn?Kn[i]:i,r++}return`"`+n+`"`}var Kn={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function qn(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=qn(e[i],t);return n+=`]`,n}else return Un(e,t)}function Jn(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function F(e,t,n){if(!(this instanceof F))throw SyntaxError(`Constructor must be called with the new operator`);this.actual=e,this.expected=t,this.relation=n,this.message=`Dimension mismatch (`+(Array.isArray(e)?`[`+e.join(`, `)+`]`:e)+` `+(this.relation||`!=`)+` `+(Array.isArray(t)?`[`+t.join(`, `)+`]`:t)+`)`,this.stack=Error().stack}F.prototype=RangeError(),F.prototype.constructor=RangeError,F.prototype.name=`DimensionError`,F.prototype.isDimensionError=!0;function Yn(e,t,n){if(!(this instanceof Yn))throw SyntaxError(`Constructor must be called with the new operator`);this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.min!==void 0&&this.index<this.min?this.message=`Index out of range (`+this.index+` < `+this.min+`)`:this.max!==void 0&&this.index>=this.max?this.message=`Index out of range (`+this.index+` > `+(this.max-1)+`)`:this.message=`Index out of range (`+this.index+`)`,this.stack=Error().stack}Yn.prototype=RangeError(),Yn.prototype.constructor=RangeError,Yn.prototype.name=`IndexError`,Yn.prototype.isIndexError=!0;var Xn=O(Mt(),1);function Zn(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function Qn(e,t,n){var r,i=e.length;if(i!==t[n])throw new F(i,t[n]);if(n<t.length-1){var a=n+1;for(r=0;r<i;r++){var o=e[r];if(!Array.isArray(o))throw new F(t.length-1,t.length,`<`);Qn(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new F(t.length+1,t.length,`>`)}function $n(e,t){var n=t.length===0;if(n){if(Array.isArray(e))throw new F(e.length,0)}else Qn(e,t,0)}function I(e,t){if(e!==void 0){if(!j(e)||!P(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new Yn(e,t)}}function er(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);t.forEach(function(e){if(!j(e)||!P(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Un(t)+`)`)}),(j(e)||M(e))&&(e=[e]);var r=n===void 0?0:n;return tr(e,t,0,r),e}function tr(e,t,n,r){var i,a,o=e.length,s=t[n],c=Math.min(o,s);if(e.length=s,n<t.length-1){var l=n+1;for(i=0;i<c;i++)a=e[i],Array.isArray(a)||(a=[a],e[i]=a),tr(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,tr(a,t,l,r)}else{for(i=0;i<c;i++)for(;Array.isArray(e[i]);)e[i]=e[i][0];for(i=c;i<s;i++)e[i]=r}}function nr(e,t){var n=cr(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new F(0,r,`!=`);t=rr(t,r);var i=ir(t);if(r!==i)throw new F(i,r,`!=`);try{return ar(n,t)}catch(e){throw e instanceof F?new F(i,r,`!=`):e}}function rr(e,t){var n=ir(e),r=e.slice(),i=-1,a=e.indexOf(i),o=e.indexOf(i,a+1)>=0;if(o)throw Error(`More than one wildcard in sizes`);var s=a>=0,c=t%n===0;if(s)if(c)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function ir(e){return e.reduce((e,t)=>e*t,1)}function ar(e,t){for(var n=e,r,i=t.length-1;i>0;i--){var a=t[i];r=[];for(var o=n.length/a,s=0;s<o;s++)r.push(n.slice(s*a,(s+1)*a));n=r}return n}function or(e,t,n,r){var i=r||Zn(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=sr(e,t,0);i.length<t;)i.push(1);return e}function sr(e,t,n){var r,i;if(Array.isArray(e)){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=sr(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function cr(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function e(n){Array.isArray(n)?n.forEach(e):t.push(n)}),t}function lr(e,t){for(var n,r=0,i=0;i<e.length;i++){var a=e[i],o=Array.isArray(a);if(i===0&&o&&(r=a.length),o&&a.length!==r)return;var s=o?lr(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function ur(e,t,n,r){if(r<n){if(e.length!==t.length)throw new F(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=ur(e[a],t[a],n,r+1);return i}else return e.concat(t)}function dr(){var e=Array.prototype.slice.call(arguments,0,-1),t=Array.prototype.slice.call(arguments,-1);if(e.length===1)return e[0];if(e.length>1)return e.slice(1).reduce(function(e,n){return ur(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function fr(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t.map(e=>e.length),i=Math.max(...r),a=Array(i).fill(null),o=0;o<t.length;o++)for(var s=t[o],c=r[o],l=0;l<c;l++){var u=i-c+l;s[l]>a[u]&&(a[u]=s[l])}for(var d=0;d<t.length;d++)pr(t[d],a);return a}function pr(e,t){for(var n=t.length,r=e.length,i=0;i<r;i++){var a=n-r+i;if(e[i]<t[a]&&e[i]>1||e[i]>t[a])throw Error(`shape missmatch: missmatch is found in arg with shape (${e}) not possible to broadcast dimension ${r} with size ${e[i]} to size ${t[a]}`)}}function mr(e,t){var n=Zn(e);if(bn(n,t))return e;pr(n,t);var r=fr(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=gr(e);n.length<i&&(o=nr(o,a),n=Zn(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=hr(o,r[s],s),n=Zn(o));return o}function hr(e,t,n){return dr(...Array(t).fill(e),n)}function gr(e){return(0,Xn.default)([],e)}function _r(e,t,n,r){function i(r){var i=Sn(r,t.map(br));return vr(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function vr(e,t,n){var r=t.filter(e=>!yr(e)).every(e=>n[e]!==void 0);if(!r){var i=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${i.map(e=>`"${e}"`).join(`, `)}.`)}}function yr(e){return e&&e[0]===`?`}function br(e){return e&&e[0]===`?`?e.slice(1):e}function xr(e,t){if(Er(e)&&wr(e,t))return e[t];throw typeof e[t]==`function`&&Tr(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function Sr(e,t,n){if(Er(e)&&wr(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function Cr(e,t){return t in e}function wr(e,t){return!e||typeof e!=`object`?!1:xn(Dr,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Tr(e,t){return e==null||typeof e[t]!=`function`||xn(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:xn(Or,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Er(e){return typeof e==`object`&&e&&e.constructor===Object}var Dr={length:!0,name:!0},Or={toString:!0,valueOf:!0,toLocaleString:!0},kr=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return xr(this.wrappedObject,e)}set(e,t){return Sr(this.wrappedObject,e,t),this}has(e){return Cr(this.wrappedObject,e)}};function Ar(e){return e?e instanceof Map||e instanceof kr||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var jr=O(Dn(),1),Mr=function(){return Mr=jr.default.create,jr.default},Nr=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],Pr=_r(`typed`,Nr,function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=Mr();return a.clear(),a.addTypes([{name:`number`,test:j},{name:`Complex`,test:Pt},{name:`BigNumber`,test:M},{name:`Fraction`,test:Ft},{name:`Unit`,test:It},{name:`identifier`,test:e=>Lt&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])*$/.test(e)},{name:`string`,test:Lt},{name:`Chain`,test:gn},{name:`Array`,test:N},{name:`Matrix`,test:Rt},{name:`DenseMatrix`,test:Bt},{name:`SparseMatrix`,test:Vt},{name:`Range`,test:Ht},{name:`Index`,test:Ut},{name:`boolean`,test:Wt},{name:`ResultSet`,test:Gt},{name:`Help`,test:Kt},{name:`function`,test:qt},{name:`Date`,test:Jt},{name:`RegExp`,test:Yt},{name:`null`,test:Zt},{name:`undefined`,test:Qt},{name:`AccessorNode`,test:$t},{name:`ArrayNode`,test:en},{name:`AssignmentNode`,test:tn},{name:`BlockNode`,test:nn},{name:`ConditionalNode`,test:rn},{name:`ConstantNode`,test:an},{name:`FunctionNode`,test:sn},{name:`FunctionAssignmentNode`,test:on},{name:`IndexNode`,test:cn},{name:`Node`,test:ln},{name:`ObjectNode`,test:un},{name:`OperatorNode`,test:dn},{name:`ParenthesisNode`,test:fn},{name:`RangeNode`,test:pn},{name:`RelationalNode`,test:mn},{name:`SymbolNode`,test:hn},{name:`Map`,test:Ar},{name:`Object`,test:Xt}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Fr(e),Ln(e)>15)throw TypeError(`Cannot implicitly convert a number with >15 significant digits to BigNumber (value: `+e+`). Use function bignumber(x) to convert to BigNumber.`);return new t(e)}},{from:`number`,to:`Complex`,convert:function(e){return n||Ir(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||Ir(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function(e){throw TypeError(`Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.`)}},{from:`Fraction`,to:`Complex`,convert:function(e){return n||Ir(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||Rr(e);var t=new i(e);if(t.valueOf()!==e)throw TypeError(`Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: `+e+`). Use function fraction(x) to convert to Fraction.`);return t}},{from:`string`,to:`number`,convert:function(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function(e){t||Fr(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function(e){i||Rr(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||Ir(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function(e){return t||Fr(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||Rr(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||Lr(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function(e){return e.valueOf()}}]),a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&zt(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&zt(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a});function Fr(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function Ir(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function Lr(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function Rr(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}
109
109
  /*!
110
110
 
111
111
  * decimal.js v10.6.0
@@ -119,8 +119,8 @@ Example:
119
119
  * MIT Licence
120
120
 
121
121
  */
122
- var Rr=9e15,zr=1e9,Br=`0123456789abcdef`,Vr=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Hr=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ur={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Rr,maxE:Rr,crypto:!1},Wr,Gr,R=!0,Kr=`[DecimalError] `,qr=Kr+`Invalid argument: `,Jr=Kr+`Precision limit exceeded`,Yr=Kr+`crypto unavailable`,Xr=`[object Decimal]`,z=Math.floor,B=Math.pow,Zr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Qr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,$r=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ei=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,V=1e7,H=7,ti=9007199254740991,ni=Vr.length-1,ri=Hr.length-1,U={toStringTag:Xr};U.absoluteValue=U.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),q(e)},U.ceil=function(){return q(new this.constructor(this),this.e+1,2)},U.clampedTo=U.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(qr+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},U.comparedTo=U.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},U.cosine=U.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+H,r.rounding=1,n=oi(r,Si(r,n)),r.precision=e,r.rounding=t,q(Gr==2||Gr==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},U.cubeRoot=U.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(R=!1,a=u.s*B(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=W(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=B(n,1/3),e=z((e+1)/3)-(e%3==(e<0?-1:2)),a==1/0?n=`5e`+e:(n=a.toExponential(),n=n.slice(0,n.indexOf(`e`)+1)+e),r=new d(n),r.s=u.s):r=new d(a.toString()),o=(e=d.precision)+3;;)if(s=r,c=s.times(s).times(s),l=c.plus(u),r=K(l.plus(u).times(s),l.plus(c),o+2,1),W(s.d).slice(0,o)===(n=W(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(q(s,e+1,0),s.times(s).times(s).eq(u))){r=s;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)==`5`)&&(q(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return R=!0,q(r,e,d.rounding,t)},U.decimalPlaces=U.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-z(this.e/H))*H,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},U.dividedBy=U.div=function(e){return K(this,new this.constructor(e))},U.dividedToIntegerBy=U.divToInt=function(e){var t=this,n=t.constructor;return q(K(t,new n(e),0,1,1),n.precision,n.rounding)},U.equals=U.eq=function(e){return this.cmp(e)===0},U.floor=function(){return q(new this.constructor(this),this.e+1,3)},U.greaterThan=U.gt=function(e){return this.cmp(e)>0},U.greaterThanOrEqualTo=U.gte=function(e){var t=this.cmp(e);return t==1||t===0},U.hyperbolicCosine=U.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/xi(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=bi(o,1,a.times(t),new o(1),!0);for(var c,l=e,u=new o(8);l--;)c=a.times(a),a=s.minus(c.times(u.minus(c.times(u))));return q(a,o.precision=n,o.rounding=r,!0)},U.hyperbolicSine=U.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=bi(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/xi(5,e)),i=bi(a,2,i,i,!0);for(var o,s=new a(5),c=new a(16),l=new a(20);e--;)o=i.times(i),i=i.times(s.plus(o.times(c.times(o).plus(l))))}return a.precision=t,a.rounding=n,q(i,t,n,!0)},U.hyperbolicTangent=U.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,K(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},U.inverseCosine=U.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?Y(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2)):n===0?e.isNeg()?Y(t,r,i):new t(0):new t(NaN)},U.inverseHyperbolicCosine=U.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,R=!1,n=n.times(n).minus(1).sqrt().plus(n),R=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},U.inverseHyperbolicSine=U.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,R=!1,n=n.times(n).plus(1).sqrt().plus(n),R=!0,r.precision=e,r.rounding=t,n.ln())},U.inverseHyperbolicTangent=U.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?q(new a(i),e,t,!0):(a.precision=n=r-i.e,i=K(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},U.inverseSine=U.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=Y(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},U.inverseTangent=U.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(l.isFinite()){if(l.isZero())return new u(l);if(l.abs().eq(1)&&d+4<=ri)return o=Y(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=ri)return o=Y(u,d+4,f).times(.5),o.s=l.s,o}for(u.precision=s=d+10,u.rounding=1,n=Math.min(28,s/H+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(s/H),r=1,c=l.times(l),o=new u(l),i=l;e!==-1;)if(i=i.times(c),a=o.minus(i.div(r+=2)),i=i.times(c),o=a.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===a.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),R=!0,q(o,u.precision=d,u.rounding=f,!0)},U.isFinite=function(){return!!this.d},U.isInteger=U.isInt=function(){return!!this.d&&z(this.e/H)>this.d.length-2},U.isNaN=function(){return!this.s},U.isNegative=U.isNeg=function(){return this.s<0},U.isPositive=U.isPos=function(){return this.s>0},U.isZero=function(){return!!this.d&&this.d[0]===0},U.lessThan=U.lt=function(e){return this.cmp(e)<0},U.lessThanOrEqualTo=U.lte=function(e){return this.cmp(e)<1},U.logarithm=U.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(R=!1,s=d+p,o=hi(l,s),r=t?ci(u,s+10):hi(e,s),c=K(o,r,s,1),ii(c.d,i=d,f))do if(s+=10,o=hi(l,s),r=t?ci(u,s+10):hi(e,s),c=K(o,r,s,1),!a){+W(c.d).slice(i+1,i+15)+1==1e14&&(c=q(c,d+1,0));break}while(ii(c.d,i+=10,f));return R=!0,q(c,d,f)},U.minus=U.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return R?q(e,s,c):e}if(n=z(e.e/H),u=z(p.e/H),l=l.slice(),a=u-n,a){for(d=a<0,d?(t=l,a=-a,o=f.length):(t=f,n=u,o=l.length),r=Math.max(Math.ceil(s/H),o)+2,a>r&&(a=r,t.length=1),t.reverse(),r=a;r--;)t.push(0);t.reverse()}else{for(r=l.length,o=f.length,d=r<o,d&&(o=r),r=0;r<o;r++)if(l[r]!=f[r]){d=l[r]<f[r];break}a=0}for(d&&(t=l,l=f,f=t,e.s=-e.s),o=l.length,r=f.length-o;r>0;--r)l[o++]=0;for(r=f.length;r>a;){if(l[--r]<f[r]){for(i=r;i&&l[--i]===0;)l[i]=V-1;--l[i],l[r]+=V}l[r]-=f[r]}for(;l[--o]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=si(l,n),R?q(e,s,c):e):new m(c===3?-0:0)},U.modulo=U.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?q(new r(n),r.precision,r.rounding):(R=!1,r.modulo==9?(t=K(n,e.abs(),0,3,1),t.s*=e.s):t=K(n,e,0,r.modulo,1),t=t.times(e),R=!0,n.minus(t))},U.naturalExponential=U.exp=function(){return mi(this)},U.naturalLogarithm=U.ln=function(){return hi(this)},U.negated=U.neg=function(){var e=new this.constructor(this);return e.s=-e.s,q(e)},U.plus=U.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),R?q(e,s,c):e;if(a=z(d.e/H),r=z(e.e/H),l=l.slice(),i=a-r,i){for(i<0?(n=l,i=-i,o=u.length):(n=u,r=a,o=l.length),a=Math.ceil(s/H),o=a>o?a+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=l.length,i=u.length,o-i<0&&(i=o,n=u,u=l,l=n),t=0;i;)t=(l[--i]=l[i]+u[i]+t)/V|0,l[i]%=V;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=si(l,r),R?q(e,s,c):e},U.precision=U.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(qr+e);return n.d?(t=li(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},U.round=function(){var e=this,t=e.constructor;return q(new t(e),e.e+1,t.rounding)},U.sine=U.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+H,r.rounding=1,n=yi(r,Si(r,n)),r.precision=e,r.rounding=t,q(Gr>2?n.neg():n,e,t,!0)):new r(NaN)},U.squareRoot=U.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(R=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=W(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=z((c+1)/2)-(c<0||c%2),l==1/0?t=`5e`+c:(t=l.toExponential(),t=t.slice(0,t.indexOf(`e`)+1)+c),r=new u(t)):r=new u(l.toString()),n=(c=u.precision)+3;;)if(a=r,r=a.plus(K(o,a,n+2,1)).times(.5),W(a.d).slice(0,n)===(t=W(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(q(a,c+1,0),a.times(a).eq(o))){r=a;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)==`5`)&&(q(r,c+1,1),e=!r.times(r).eq(o));break}return R=!0,q(r,c,u.rounding,e)},U.tangent=U.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=K(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,q(Gr==2||Gr==4?n.neg():n,e,t,!0)):new r(NaN)},U.times=U.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=z(u.e/H)+z(e.e/H),c=f.length,l=p.length,c<l&&(a=f,f=p,p=a,o=c,c=l,l=o),a=[],o=c+l,r=o;r--;)a.push(0);for(r=l;--r>=0;){for(t=0,i=c+r;i>r;)s=a[i]+p[r]*f[i-r-1]+t,a[i--]=s%V|0,t=s/V|0;a[i]=(a[i]+t)%V|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=si(a,n),R?q(e,d.precision,d.rounding):e},U.toBinary=function(e,t){return Ci(this,2,e,t)},U.toDecimalPlaces=U.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(G(e,0,zr),t===void 0?t=r.rounding:G(t,0,8),q(n,e+n.e+1,t))},U.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=J(r,!0):(G(e,0,zr),t===void 0?t=i.rounding:G(t,0,8),r=q(new i(r),e+1,t),n=J(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},U.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=J(i):(G(e,0,zr),t===void 0?t=a.rounding:G(t,0,8),r=q(new a(i),e+i.e+1,t),n=J(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},U.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=li(m)-p.e-1,o=a%H,t.d[0]=B(10,o<0?H+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(qr+s);e=s.gt(t)?a>0?t:l:s}for(R=!1,s=new h(W(m)),u=h.precision,h.precision=a=m.length*H*2;d=K(s,t,0,1,1),i=n.plus(d.times(r)),i.cmp(e)!=1;)n=r,r=i,i=l,l=c.plus(d.times(i)),c=i,i=t,t=s.minus(d.times(i)),s=i;return i=K(e.minus(n),r,0,1,1),c=c.plus(i.times(l)),n=n.plus(i.times(r)),c.s=l.s=p.s,f=K(l,r,a,1).minus(p).abs().cmp(K(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,R=!0,f},U.toHexadecimal=U.toHex=function(e,t){return Ci(this,16,e,t)},U.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:G(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(R=!1,n=K(n,e,0,t,1).times(e),R=!0,q(n)):(e.s=n.s,n=e),n},U.toNumber=function(){return+this},U.toOctal=function(e,t){return Ci(this,8,e,t)},U.toPower=U.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(B(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return q(s,r,a);if(t=z(e.e/H),t>=e.d.length-1&&(n=l<0?-l:l)<=ti)return i=di(c,s,n,r),e.s<0?new c(1).div(i):q(i,r,a);if(o=s.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),s.e==0&&s.d[0]==1&&s.d.length==1)return s.s=o,s}return n=B(+s,l),t=n==0||!isFinite(n)?z(l*(Math.log(`0.`+W(s.d))/Math.LN10+s.e+1)):new c(n+``).e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(R=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=mi(e.times(hi(s,r+n)),r),i.d&&(i=q(i,r+5,1),ii(i.d,r,a)&&(t=r+10,i=q(mi(e.times(hi(s,t+n)),t),t+5,1),+W(i.d).slice(r+1,r+15)+1==1e14&&(i=q(i,r+1,0)))),i.s=o,R=!0,c.rounding=a,q(i,r,a))},U.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=J(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(G(e,1,zr),t===void 0?t=i.rounding:G(t,0,8),r=q(new i(r),e,t),n=J(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},U.toSignificantDigits=U.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(G(e,1,zr),t===void 0?t=r.rounding:G(t,0,8)),q(new r(n),e,t)},U.toString=function(){var e=this,t=e.constructor,n=J(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},U.truncated=U.trunc=function(){return q(new this.constructor(this),this.e+1,1)},U.valueOf=U.toJSON=function(){var e=this,t=e.constructor,n=J(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function W(e){var t,n,r,i=e.length-1,a=``,o=e[0];if(i>0){for(a+=o,t=1;t<i;t++)r=e[t]+``,n=H-r.length,n&&(a+=ui(n)),a+=r;o=e[t],r=o+``,n=H-r.length,n&&(a+=ui(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function G(e,t,n){if(e!==~~e||e<t||e>n)throw Error(qr+e)}function ii(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=H,i=0):(i=Math.ceil((t+1)/H),t%=H),a=B(10,H-t),s=e[i]%a|0,r==null?t<3?(t==0?s=s/100|0:t==1&&(s=s/10|0),o=n<4&&s==99999||n>3&&s==49999||s==5e4||s==0):o=(n<4&&s+1==a||n>3&&s+1==a/2)&&(e[i+1]/a/100|0)==B(10,t-2)-1||(s==a/2||s==0)&&(e[i+1]/a/100|0)==0:t<4?(t==0?s=s/1e3|0:t==1?s=s/100|0:t==2&&(s=s/10|0),o=(r||n<4)&&s==9999||!r&&n>3&&s==4999):o=((r||n<4)&&s+1==a||!r&&n>3&&s+1==a/2)&&(e[i+1]/a/1e3|0)==B(10,t-3)-1,o}function ai(e,t,n){for(var r,i=[0],a,o=0,s=e.length;o<s;){for(a=i.length;a--;)i[a]*=t;for(i[0]+=Br.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function oi(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/xi(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=bi(e,1,t.times(i),new e(1));for(var a=n;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var K=(function(){function e(e,t,n){var r,i=0,a=e.length;for(e=e.slice();a--;)r=e[a]*t+i,e[a]=r%n|0,i=r/n|0;return i&&e.unshift(i),e}function t(e,t,n,r){var i,a;if(n!=r)a=n>r?1:-1;else for(i=a=0;i<n;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;)e.shift()}return function(r,i,a,o,s,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,ee,O=r.constructor,te=r.s==i.s?1:-1,k=r.d,A=i.d;if(!k||!k[0]||!A||!A[0])return new O(!r.s||!i.s||(k?A&&k[0]==A[0]:!A)?NaN:k&&k[0]==0||!A?te*0:te/0);for(c?(p=1,u=r.e-i.e):(c=V,p=H,u=z(r.e/p)-z(i.e/p)),D=A.length,T=k.length,_=new O(te),v=_.d=[],d=0;A[d]==(k[d]||0);d++);if(A[d]>(k[d]||0)&&u--,a==null?(S=a=O.precision,o=O.rounding):S=s?a+(r.e-i.e)+1:a,S<0)v.push(1),m=!0;else{if(S=S/p+2|0,d=0,D==1){for(f=0,A=A[0],S++;(d<T||f)&&S--;d++)C=f*c+(k[d]||0),v[d]=C/A|0,f=C%A|0;m=f||d<T}else{for(f=c/(A[0]+1)|0,f>1&&(A=e(A,f,c),k=e(k,f,c),D=A.length,T=k.length),w=D,y=k.slice(0,D),b=y.length;b<D;)y[b++]=0;ee=A.slice(),ee.unshift(0),E=A[0],A[1]>=c/2&&++E;do f=0,l=t(A,y,D,b),l<0?(x=y[0],D!=b&&(x=x*c+(y[1]||0)),f=x/E|0,f>1?(f>=c&&(f=c-1),h=e(A,f,c),g=h.length,b=y.length,l=t(h,y,g,b),l==1&&(f--,n(h,D<g?ee:A,g,c))):(f==0&&(l=f=1),h=A.slice()),g=h.length,g<b&&h.unshift(0),n(y,h,b,c),l==-1&&(b=y.length,l=t(A,y,D,b),l<1&&(f++,n(y,D<b?ee:A,b,c))),b=y.length):l===0&&(f++,y=[0]),v[d++]=f,l&&y[0]?y[b++]=k[w]||0:(y=[k[w]],b=1);while((w++<T||y[0]!==void 0)&&S--);m=y[0]!==void 0}v[0]||v.shift()}if(p==1)_.e=u,Wr=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,q(_,s?a+_.e+1:a,o,m)}return _}})();function q(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor;out:if(t!=null){if(d=e.d,!d)return e;for(i=1,s=d[0];s>=10;s/=10)i++;if(a=t-i,a<0)a+=H,o=t,u=d[f=0],c=u/B(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/H),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=H,o=a-H+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=H,o=a-H+i,c=o<0?0:u/B(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%B(10,i-o-1)),l=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(a>0?o>0?u/B(10,i-o):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,l?(t-=e.e+1,d[0]=B(10,(H-t%H)%H),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=B(10,H-a),d[f]=o>0?(u/B(10,i-o)%B(10,o)|0)*s:0),l)for(;;)if(f==0){for(a=1,o=d[0];o>=10;o/=10)a++;for(o=d[0]+=s,s=1;o>=10;o/=10)s++;a!=s&&(e.e++,d[0]==V&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=V)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return R&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function J(e,t,n){if(!e.isFinite())return gi(e);var r,i=e.e,a=W(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+ui(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+ui(-i-1)+a,n&&(r=n-o)>0&&(a+=ui(r))):i>=o?(a+=ui(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+ui(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=ui(r))),a}function si(e,t){var n=e[0];for(t*=H;n>=10;n/=10)t++;return t}function ci(e,t,n){if(t>ni)throw R=!0,n&&(e.precision=n),Error(Jr);return q(new e(Vr),t,1,!0)}function Y(e,t,n){if(t>ri)throw Error(Jr);return q(new e(Hr),t,n,!0)}function li(e){var t=e.length-1,n=t*H+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function ui(e){for(var t=``;e--;)t+=`0`;return t}function di(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/H+4);for(R=!1;;){if(n%2&&(a=a.times(t),wi(a.d,o)&&(i=!0)),n=z(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),wi(t.d,o)}return R=!0,a}function fi(e){return e.d[e.d.length-1]&1}function pi(e,t,n){for(var r,i,a=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){a=i;break}r=a.cmp(i),(r===n||r===0&&a.s===n)&&(a=i)}return a}function mi(e,t){var n,r,i,a,o,s,c,l=0,u=0,d=0,f=e.constructor,p=f.rounding,m=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(R=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(B(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=q(a.times(e),c,1),n=n.times(++u),s=o.plus(K(a,n,c,1)),W(s.d).slice(0,c)===W(o.d).slice(0,c)){for(i=d;i--;)o=q(o.times(o),c,1);if(t==null)if(l<3&&ii(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return q(o,f.precision=m,p,R=!0);else return f.precision=m,o}o=s}}function hi(e,t){var n,r,i,a,o,s,c,l,u,d,f,p=1,m=10,h=e,g=h.d,_=h.constructor,v=_.rounding,y=_.precision;if(h.s<0||!g||!g[0]||!h.e&&g[0]==1&&g.length==1)return new _(g&&!g[0]?-1/0:h.s==1?g?0:h:NaN);if(t==null?(R=!1,u=y):u=t,_.precision=u+=m,n=W(g),r=n.charAt(0),Math.abs(a=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=W(h.d),r=n.charAt(0),p++;a=h.e,r>1?(h=new _(`0.`+n),a++):h=new _(r+`.`+n.slice(1))}else return l=ci(_,u+2,y).times(a+``),h=hi(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?q(h,y,v,R=!0):h;for(d=h,c=o=h=K(h.minus(1),h.plus(1),u,1),f=q(h.times(h),u,1),i=3;;){if(o=q(o.times(f),u,1),l=c.plus(K(o,new _(i),u,1)),W(l.d).slice(0,u)===W(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(ci(_,u+2,y).times(a+``))),c=K(c,new _(p),u,1),t==null)if(ii(c.d,u-m,v,s))_.precision=u+=m,l=o=h=K(d.minus(1),d.plus(1),u,1),f=q(h.times(h),u,1),i=s=1;else return q(c,_.precision=y,v,R=!0);else return _.precision=y,c;c=l,i+=2}}function gi(e){return String(e.s*e.s/0)}function _i(e,t){var n,r,i;for((n=t.indexOf(`.`))>-1&&(t=t.replace(`.`,``)),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%H,n<0&&(r+=H),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=H;r<i;)e.d.push(+t.slice(r,r+=H));t=t.slice(r),r=H-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),R&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function vi(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),ei.test(t))return _i(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Qr.test(t))n=16,t=t.toLowerCase();else if(Zr.test(t))n=2;else if($r.test(t))n=8;else throw Error(qr+t);for(a=t.search(/p/i),a>0?(c=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf(`.`),o=a>=0,r=e.constructor,o&&(t=t.replace(`.`,``),s=t.length,a=s-a,i=di(r,new r(n),a,a*2)),l=ai(t,n,V),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=si(l,u),e.d=l,R=!1,o&&(e=K(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?B(2,c):fa.pow(2,c))),R=!0,e)}function yi(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:bi(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/xi(5,n)),t=bi(e,2,t,t);for(var i,a=new e(5),o=new e(16),s=new e(20);n--;)i=t.times(t),t=t.times(a.plus(i.times(o.times(i).minus(s))));return t}function bi(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/H);for(R=!1,c=n.times(n),s=new e(r);;){if(o=K(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=K(o.times(c),new e(t++*t++),u,1),o=s.plus(r),o.d[d]!==void 0){for(a=d;o.d[a]===s.d[a]&&a--;);if(a==-1)break}a=s,s=r,r=o,o=a,l++}return R=!0,o.d.length=d+1,o}function xi(e,t){for(var n=e;--t;)n*=e;return n}function Si(e,t){var n,r=t.s<0,i=Y(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return Gr=r?4:1,t;if(n=t.divToInt(i),n.isZero())Gr=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return Gr=fi(n)?r?2:3:r?4:1,t;Gr=fi(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Ci(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(G(n,1,zr),r===void 0?r=p.rounding:G(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=gi(e);else{for(u=J(e),o=u.indexOf(`.`),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(u=u.replace(`.`,``),f=new p(1),f.e=u.length-o,f.d=ai(J(f),10,i),f.e=f.d.length),d=ai(u,10,i),a=c=d.length;d[--c]==0;)d.pop();if(!d[0])u=m?`0p+0`:`0`;else{if(o<0?a--:(e=new p(e),e.d=d,e.e=a,e=K(e,f,n,r,0,i),d=e.d,a=e.e,l=Wr),o=d[n],s=i/2,l||=d[n+1]!==void 0,l=r<4?(o!==void 0||l)&&(r===0||r===(e.s<0?3:2)):o>s||o===s&&(r===4||l||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,l)for(;++d[--n]>i-1;)d[n]=0,n||(++a,d.unshift(1));for(c=d.length;!d[c-1];--c);for(o=0,u=``;o<c;o++)u+=Br.charAt(d[o]);if(m){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)u+=`0`;for(d=ai(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Br.charAt(d[o])}else u=u.charAt(0)+`.`+u.slice(1);u=u+(a<0?`p`:`p+`)+a}else if(a<0){for(;++a;)u=`0`+u;u=`0.`+u}else if(++a>c)for(a-=c;a--;)u+=`0`;else a<c&&(u=u.slice(0,a)+`.`+u.slice(a))}u=(t==16?`0x`:t==2?`0b`:t==8?`0o`:``)+u}return e.s<0?`-`+u:u}function wi(e,t){if(e.length>t)return e.length=t,!0}function Ti(e){return new this(e).abs()}function Ei(e){return new this(e).acos()}function Di(e){return new this(e).acosh()}function Oi(e,t){return new this(e).plus(t)}function ki(e){return new this(e).asin()}function Ai(e){return new this(e).asinh()}function ji(e){return new this(e).atan()}function Mi(e){return new this(e).atanh()}function Ni(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,a=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Y(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Y(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Y(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(K(e,t,a,1)),t=Y(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(K(e,t,a,1)),n}function Pi(e){return new this(e).cbrt()}function Fi(e){return q(e=new this(e),e.e+1,2)}function Ii(e,t,n){return new this(e).clamp(t,n)}function Li(e){if(!e||typeof e!=`object`)throw Error(Kr+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,zr,`rounding`,0,8,`toExpNeg`,-Rr,0,`toExpPos`,0,Rr,`maxE`,0,Rr,`minE`,-Rr,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Ur[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(qr+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ur[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<`u`&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Yr);else this[n]=!1;else throw Error(qr+n+`: `+r);return this}function Ri(e){return new this(e).cos()}function zi(e){return new this(e).cosh()}function Bi(e){var t,n,r;function i(e){var t,n,r,a=this;if(!(a instanceof i))return new i(e);if(a.constructor=i,Gi(e)){a.s=e.s,R?!e.d||e.e>i.maxE?(a.e=NaN,a.d=null):e.e<i.minE?(a.e=0,a.d=[0]):(a.e=e.e,a.d=e.d.slice()):(a.e=e.e,a.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){a.s=1/e<0?-1:1,a.e=0,a.d=[0];return}if(e<0?(e=-e,a.s=-1):a.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;R?t>i.maxE?(a.e=NaN,a.d=null):t<i.minE?(a.e=0,a.d=[0]):(a.e=t,a.d=[e]):(a.e=t,a.d=[e]);return}if(e*0!=0){e||(a.s=NaN),a.e=NaN,a.d=null;return}return _i(a,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),a.s=-1):(n===43&&(e=e.slice(1)),a.s=1),ei.test(e)?_i(a,e):vi(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,_i(a,e.toString());throw Error(qr+e)}if(i.prototype=U,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Li,i.clone=Bi,i.isDecimal=Gi,i.abs=Ti,i.acos=Ei,i.acosh=Di,i.add=Oi,i.asin=ki,i.asinh=Ai,i.atan=ji,i.atanh=Mi,i.atan2=Ni,i.cbrt=Pi,i.ceil=Fi,i.clamp=Ii,i.cos=Ri,i.cosh=zi,i.div=Vi,i.exp=Hi,i.floor=Ui,i.hypot=Wi,i.ln=Ki,i.log=qi,i.log10=Yi,i.log2=Ji,i.max=Xi,i.min=Zi,i.mod=Qi,i.mul=$i,i.pow=ea,i.random=ta,i.round=na,i.sign=ra,i.sin=ia,i.sinh=aa,i.sqrt=oa,i.sub=sa,i.sum=ca,i.tan=la,i.tanh=ua,i.trunc=da,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=[`precision`,`rounding`,`toExpNeg`,`toExpPos`,`maxE`,`minE`,`modulo`,`crypto`],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function Vi(e,t){return new this(e).div(t)}function Hi(e){return new this(e).exp()}function Ui(e){return q(e=new this(e),e.e+1,3)}function Wi(){var e,t,n=new this(0);for(R=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);n=t}return R=!0,n.sqrt()}function Gi(e){return e instanceof fa||e&&e.toStringTag===Xr||!1}function Ki(e){return new this(e).ln()}function qi(e,t){return new this(e).log(t)}function Ji(e){return new this(e).log(2)}function Yi(e){return new this(e).log(10)}function Xi(){return pi(this,arguments,-1)}function Zi(){return pi(this,arguments,1)}function Qi(e,t){return new this(e).mod(t)}function $i(e,t){return new this(e).mul(t)}function ea(e,t){return new this(e).pow(t)}function ta(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:G(e,1,zr),r=Math.ceil(e/H),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));a<r;)i=t[a],i>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:s[a++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);a<r;)i=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,a):(s.push(i%1e7),a+=4);a=r/4}else throw Error(Yr);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=H,r&&e&&(i=B(10,H-e),s[a]=(r/i|0)*i);s[a]===0;a--)s.pop();if(a<0)n=0,s=[0];else{for(n=-1;s[0]===0;n-=H)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<H&&(n-=H-r)}return o.e=n,o.d=s,o}function na(e){return q(e=new this(e),e.e+1,this.rounding)}function ra(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function ia(e){return new this(e).sin()}function aa(e){return new this(e).sinh()}function oa(e){return new this(e).sqrt()}function sa(e,t){return new this(e).sub(t)}function ca(){var e=0,t=arguments,n=new this(t[e]);for(R=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return R=!0,q(n,this.precision,this.rounding)}function la(e){return new this(e).tan()}function ua(e){return new this(e).tanh()}function da(e){return q(e=new this(e),e.e+1,1)}U[Symbol.for(`nodejs.util.inspect.custom`)]=U.toString,U[Symbol.toStringTag]=`Decimal`;var fa=U.constructor=Bi(Ur);Vr=new fa(Vr),Hr=new fa(Hr);var pa=fa,ma=`BigNumber`,ha=[`?on`,`config`],ga=gr(ma,ha,e=>{var{on:t,config:n}=e,r=pa.clone({precision:n.precision,modulo:pa.EUCLID});return r.prototype=Object.create(r.prototype),r.prototype.type=`BigNumber`,r.prototype.isBigNumber=!0,r.prototype.toJSON=function(){return{mathjs:`BigNumber`,value:this.toString()}},r.fromJSON=function(e){return new r(e.value)},t&&t(`config`,function(e,t){e.precision!==t.precision&&r.config({precision:e.precision})}),r},{isClass:!0});const X=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Z=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},_a=function(e){let t=Math.PI/4;if(-t>e||e>t)return Math.cos(e)-1;let n=e*e;return n*(n*(n*(n*(n*(n*(n*(n/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},va=function(e,t){return e=Math.abs(e),t=Math.abs(t),e<t&&([e,t]=[t,e]),e<1e8?Math.sqrt(e*e+t*t):(t/=e,e*Math.sqrt(1+t*t))},ya=function(){throw SyntaxError(`Invalid Param`)};function ba(e,t){let n=Math.abs(e),r=Math.abs(t);return e===0?Math.log(r):t===0?Math.log(n):n<3e3&&r<3e3?Math.log(e*e+t*t)*.5:(e*=.5,t*=.5,.5*Math.log(e*e+t*t)+Math.LN2)}const xa={re:0,im:0},Sa=function(e,t){let n=xa;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return Q.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return Q.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):ya();break;case`string`:n.im=n.re=0;let t=e.replace(/_/g,``).match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,i=0;t===null&&ya();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
123
- `||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&ya(),t[e+1]!==` `&&!isNaN(t[e+1])?(n.im+=parseFloat((i%2?`-`:``)+t[e+1]),e++):n.im+=parseFloat((i%2?`-`:``)+`1`),r=i=0):((r+i===0||isNaN(a))&&ya(),t[e+1]===`i`||t[e+1]===`I`?(n.im+=parseFloat((i%2?`-`:``)+a),e++):n.re+=parseFloat((i%2?`-`:``)+a),r=i=0))}r+i>0&&ya();break;case`number`:n.im=0,n.re=e;break;default:ya()}return isNaN(n.re)||isNaN(n.im),n};function Q(e,t){if(!(this instanceof Q))return new Q(e,t);let n=Sa(e,t);this.re=n.re,this.im=n.im}Q.prototype={re:0,im:0,sign:function(){let e=va(this.re,this.im);return new Q(this.re/e,this.im/e)},add:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Q.NAN:Q.INFINITY:new Q(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Q.NAN:Q.INFINITY:new Q(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;return r&&o||i&&a?Q.NAN:r||i?Q.INFINITY:n.im===0&&this.im===0?new Q(this.re*n.re,0):new Q(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;if(a&&o||r&&i)return Q.NAN;if(o||r)return Q.INFINITY;if(a||i)return Q.ZERO;if(n.im===0)return new Q(this.re/n.re,this.im/n.re);if(Math.abs(n.re)<Math.abs(n.im)){let e=n.re/n.im,t=n.re*e+n.im;return new Q((this.re*e+this.im)/t,(this.im*e-this.re)/t)}else{let e=n.im/n.re,t=n.im*e+n.re;return new Q((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=Sa(e,t),r=this.re===0&&this.im===0,i=n.re===0&&n.im===0;if(i)return Q.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new Q(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new Q(this.im**+n.re,0);case 1:return new Q(0,this.im**+n.re);case 2:return new Q(-(this.im**+n.re),0);case 3:return new Q(0,-(this.im**+n.re))}}if(r&&n.re>0)return Q.ZERO;let a=Math.atan2(this.im,this.re),o=ba(this.re,this.im),s=Math.exp(n.re*o-n.im*a),c=n.im*o+n.re*a;return new Q(s*Math.cos(c),s*Math.sin(c))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new Q(Math.sqrt(e),0):new Q(0,Math.sqrt(-e));let n=va(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new Q(r,t<0?-i:i):new Q(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new Q(e,0):new Q(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new Q(Math.expm1(e)*Math.cos(t)+_a(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new Q(Math.log(e),0):new Q(ba(e,t),Math.atan2(t,e))},abs:function(){return va(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new Q(Math.sin(e)*X(t),Math.cos(e)*Z(t))},cos:function(){let e=this.re,t=this.im;return new Q(Math.cos(e)*X(t),-Math.sin(e)*Z(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+X(t);return new Q(Math.sin(e)/n,Z(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-X(t);return new Q(-Math.sin(e)/n,Z(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*X(2*t)+.5*Math.cos(2*e);return new Q(Math.cos(e)*X(t)/n,Math.sin(e)*Z(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*X(2*t)-.5*Math.cos(2*e);return new Q(Math.sin(e)*X(t)/n,-Math.cos(e)*Z(t)/n)},asin:function(){let e=this.re,t=this.im,n=new Q(t*t-e*e+1,-2*e*t).sqrt(),r=new Q(n.re-t,n.im+e).log();return new Q(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new Q(t*t-e*e+1,-2*e*t).sqrt(),r=new Q(n.re-t,n.im+e).log();return new Q(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new Q(0,1/0);if(t===-1)return new Q(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new Q((1-t*t-e*e)/n,-2*e/n).log();return new Q(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new Q(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).atan():new Q(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(0,1/0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).acos():new Q(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).asin():new Q(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new Q(Z(e)*Math.cos(t),X(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new Q(X(e)*Math.cos(t),Z(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=X(e)+Math.cos(t);return new Q(Z(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=X(e)-Math.cos(t);return new Q(Z(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-X(2*e);return new Q(-2*Z(e)*Math.cos(t)/n,2*X(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+X(2*e);return new Q(2*X(e)*Math.cos(t)/n,-2*Z(e)*Math.sin(t)/n)},asinh:function(){let e=this.im;this.im=-this.re,this.re=e;let t=this.asin();return this.re=-this.im,this.im=e,e=t.re,t.re=-t.im,t.im=e,t},acosh:function(){let e=this.acos();if(e.im<=0){let t=e.re;e.re=-e.im,e.im=t}else{let t=e.im;e.im=-e.re,e.re=t}return e},atanh:function(){let e=this.re,t=this.im,n=e>1&&t===0,r=1-e,i=1+e,a=r*r+t*t,o=a===0?new Q(e===-1?0:e/0,t===0?0:t/0):new Q((i*r-t*t)/a,(t*r+i*t)/a),s=o.re;return o.re=ba(o.re,o.im)/2,o.im=Math.atan2(o.im,s)/2,n&&(o.im=-o.im),o},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(0,Math.PI/2);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).atanh():new Q(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0)return new Q(e===0?1/0:Math.log(e+Math.sqrt(e*e+1)),0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).asinh():new Q(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return Q.INFINITY;let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).acosh():new Q(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return Q.INFINITY;if(this.isInfinite())return Q.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new Q(e/n,-t/n)},conjugate:function(){return new Q(this.re,-this.im)},neg:function(){return new Q(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new Q(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new Q(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new Q(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=Sa(e,t);return Math.abs(n.re-this.re)<=Q.EPSILON&&Math.abs(n.im-this.im)<=Q.EPSILON},clone:function(){return new Q(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<Q.EPSILON&&(e=0),Math.abs(t)<Q.EPSILON&&(t=0),t===0?n+e:(e===0?t<0&&(t=-t,n+=`-`):(n+=e,n+=` `,t<0?(t=-t,n+=`-`):n+=`+`,n+=` `),t!==1&&(n+=t),n+`i`))},toVector:function(){return[this.re,this.im]},valueOf:function(){return this.im===0?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return this.im===0&&this.re===0},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!this.isFinite()}},Q.ZERO=new Q(0,0),Q.ONE=new Q(1,0),Q.I=new Q(0,1),Q.PI=new Q(Math.PI,0),Q.E=new Q(Math.E,0),Q.INFINITY=new Q(1/0,1/0),Q.NAN=new Q(NaN,NaN),Q.EPSILON=1e-15;var Ca=`Complex`,wa=[],Ta=gr(Ca,wa,()=>(Object.defineProperty(Q,`name`,{value:`Complex`}),Q.prototype.constructor=Q,Q.prototype.type=`Complex`,Q.prototype.isComplex=!0,Q.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},Q.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},Q.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=On(this.re,e),a=On(this.im,e),o=M(e)?e:e?e.precision:null;if(o!==null){var s=10**-o;Math.abs(r/n)<s&&(r=0),Math.abs(n/r)<s&&(n=0)}return t=n===0?i:r===0?n===1?`i`:n===-1?`-i`:a+`i`:n<0?n===-1?i+` - i`:i+` - `+a.substring(1)+`i`:n===1?i+` + i`:i+` + `+a+`i`,t},Q.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return Q(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(M(n)){if(Ft(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),M(r))return new Q({r:n,phi:r});throw TypeError(`Phi is not a number nor an angle unit.`)}else throw TypeError(`Radius r is not a number.`);default:throw SyntaxError(`Wrong number of arguments in function fromPolar`)}},Q.prototype.valueOf=Q.prototype.toString,Q.fromJSON=function(e){return new Q(e)},Q.compare=function(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0},Q),{isClass:!0}),Ea=O(((exports,t)=>{
122
+ var zr=9e15,Br=1e9,Vr=`0123456789abcdef`,Hr=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Ur=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Wr={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-zr,maxE:zr,crypto:!1},Gr,L,R=!0,Kr=`[DecimalError] `,qr=Kr+`Invalid argument: `,Jr=Kr+`Precision limit exceeded`,Yr=Kr+`crypto unavailable`,Xr=`[object Decimal]`,z=Math.floor,B=Math.pow,Zr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Qr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,$r=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ei=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,V=1e7,H=7,ti=9007199254740991,ni=Hr.length-1,ri=Ur.length-1,U={toStringTag:Xr};U.absoluteValue=U.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),q(e)},U.ceil=function(){return q(new this.constructor(this),this.e+1,2)},U.clampedTo=U.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(qr+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},U.comparedTo=U.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},U.cosine=U.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+H,r.rounding=1,n=oi(r,Si(r,n)),r.precision=e,r.rounding=t,q(L==2||L==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},U.cubeRoot=U.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(R=!1,a=u.s*B(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=W(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=B(n,1/3),e=z((e+1)/3)-(e%3==(e<0?-1:2)),a==1/0?n=`5e`+e:(n=a.toExponential(),n=n.slice(0,n.indexOf(`e`)+1)+e),r=new d(n),r.s=u.s):r=new d(a.toString()),o=(e=d.precision)+3;;)if(s=r,c=s.times(s).times(s),l=c.plus(u),r=K(l.plus(u).times(s),l.plus(c),o+2,1),W(s.d).slice(0,o)===(n=W(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(q(s,e+1,0),s.times(s).times(s).eq(u))){r=s;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)==`5`)&&(q(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return R=!0,q(r,e,d.rounding,t)},U.decimalPlaces=U.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-z(this.e/H))*H,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},U.dividedBy=U.div=function(e){return K(this,new this.constructor(e))},U.dividedToIntegerBy=U.divToInt=function(e){var t=this,n=t.constructor;return q(K(t,new n(e),0,1,1),n.precision,n.rounding)},U.equals=U.eq=function(e){return this.cmp(e)===0},U.floor=function(){return q(new this.constructor(this),this.e+1,3)},U.greaterThan=U.gt=function(e){return this.cmp(e)>0},U.greaterThanOrEqualTo=U.gte=function(e){var t=this.cmp(e);return t==1||t===0},U.hyperbolicCosine=U.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/xi(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=bi(o,1,a.times(t),new o(1),!0);for(var c,l=e,u=new o(8);l--;)c=a.times(a),a=s.minus(c.times(u.minus(c.times(u))));return q(a,o.precision=n,o.rounding=r,!0)},U.hyperbolicSine=U.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=bi(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/xi(5,e)),i=bi(a,2,i,i,!0);for(var o,s=new a(5),c=new a(16),l=new a(20);e--;)o=i.times(i),i=i.times(s.plus(o.times(c.times(o).plus(l))))}return a.precision=t,a.rounding=n,q(i,t,n,!0)},U.hyperbolicTangent=U.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,K(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},U.inverseCosine=U.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?Y(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2)):n===0?e.isNeg()?Y(t,r,i):new t(0):new t(NaN)},U.inverseHyperbolicCosine=U.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,R=!1,n=n.times(n).minus(1).sqrt().plus(n),R=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},U.inverseHyperbolicSine=U.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,R=!1,n=n.times(n).plus(1).sqrt().plus(n),R=!0,r.precision=e,r.rounding=t,n.ln())},U.inverseHyperbolicTangent=U.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?q(new a(i),e,t,!0):(a.precision=n=r-i.e,i=K(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},U.inverseSine=U.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=Y(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},U.inverseTangent=U.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(l.isFinite()){if(l.isZero())return new u(l);if(l.abs().eq(1)&&d+4<=ri)return o=Y(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=ri)return o=Y(u,d+4,f).times(.5),o.s=l.s,o}for(u.precision=s=d+10,u.rounding=1,n=Math.min(28,s/H+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(s/H),r=1,c=l.times(l),o=new u(l),i=l;e!==-1;)if(i=i.times(c),a=o.minus(i.div(r+=2)),i=i.times(c),o=a.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===a.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),R=!0,q(o,u.precision=d,u.rounding=f,!0)},U.isFinite=function(){return!!this.d},U.isInteger=U.isInt=function(){return!!this.d&&z(this.e/H)>this.d.length-2},U.isNaN=function(){return!this.s},U.isNegative=U.isNeg=function(){return this.s<0},U.isPositive=U.isPos=function(){return this.s>0},U.isZero=function(){return!!this.d&&this.d[0]===0},U.lessThan=U.lt=function(e){return this.cmp(e)<0},U.lessThanOrEqualTo=U.lte=function(e){return this.cmp(e)<1},U.logarithm=U.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(R=!1,s=d+p,o=hi(l,s),r=t?ci(u,s+10):hi(e,s),c=K(o,r,s,1),ii(c.d,i=d,f))do if(s+=10,o=hi(l,s),r=t?ci(u,s+10):hi(e,s),c=K(o,r,s,1),!a){+W(c.d).slice(i+1,i+15)+1==1e14&&(c=q(c,d+1,0));break}while(ii(c.d,i+=10,f));return R=!0,q(c,d,f)},U.minus=U.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return R?q(e,s,c):e}if(n=z(e.e/H),u=z(p.e/H),l=l.slice(),a=u-n,a){for(d=a<0,d?(t=l,a=-a,o=f.length):(t=f,n=u,o=l.length),r=Math.max(Math.ceil(s/H),o)+2,a>r&&(a=r,t.length=1),t.reverse(),r=a;r--;)t.push(0);t.reverse()}else{for(r=l.length,o=f.length,d=r<o,d&&(o=r),r=0;r<o;r++)if(l[r]!=f[r]){d=l[r]<f[r];break}a=0}for(d&&(t=l,l=f,f=t,e.s=-e.s),o=l.length,r=f.length-o;r>0;--r)l[o++]=0;for(r=f.length;r>a;){if(l[--r]<f[r]){for(i=r;i&&l[--i]===0;)l[i]=V-1;--l[i],l[r]+=V}l[r]-=f[r]}for(;l[--o]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=si(l,n),R?q(e,s,c):e):new m(c===3?-0:0)},U.modulo=U.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?q(new r(n),r.precision,r.rounding):(R=!1,r.modulo==9?(t=K(n,e.abs(),0,3,1),t.s*=e.s):t=K(n,e,0,r.modulo,1),t=t.times(e),R=!0,n.minus(t))},U.naturalExponential=U.exp=function(){return mi(this)},U.naturalLogarithm=U.ln=function(){return hi(this)},U.negated=U.neg=function(){var e=new this.constructor(this);return e.s=-e.s,q(e)},U.plus=U.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),R?q(e,s,c):e;if(a=z(d.e/H),r=z(e.e/H),l=l.slice(),i=a-r,i){for(i<0?(n=l,i=-i,o=u.length):(n=u,r=a,o=l.length),a=Math.ceil(s/H),o=a>o?a+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=l.length,i=u.length,o-i<0&&(i=o,n=u,u=l,l=n),t=0;i;)t=(l[--i]=l[i]+u[i]+t)/V|0,l[i]%=V;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=si(l,r),R?q(e,s,c):e},U.precision=U.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(qr+e);return n.d?(t=li(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},U.round=function(){var e=this,t=e.constructor;return q(new t(e),e.e+1,t.rounding)},U.sine=U.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+H,r.rounding=1,n=yi(r,Si(r,n)),r.precision=e,r.rounding=t,q(L>2?n.neg():n,e,t,!0)):new r(NaN)},U.squareRoot=U.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(R=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=W(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=z((c+1)/2)-(c<0||c%2),l==1/0?t=`5e`+c:(t=l.toExponential(),t=t.slice(0,t.indexOf(`e`)+1)+c),r=new u(t)):r=new u(l.toString()),n=(c=u.precision)+3;;)if(a=r,r=a.plus(K(o,a,n+2,1)).times(.5),W(a.d).slice(0,n)===(t=W(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(q(a,c+1,0),a.times(a).eq(o))){r=a;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)==`5`)&&(q(r,c+1,1),e=!r.times(r).eq(o));break}return R=!0,q(r,c,u.rounding,e)},U.tangent=U.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=K(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,q(L==2||L==4?n.neg():n,e,t,!0)):new r(NaN)},U.times=U.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=z(u.e/H)+z(e.e/H),c=f.length,l=p.length,c<l&&(a=f,f=p,p=a,o=c,c=l,l=o),a=[],o=c+l,r=o;r--;)a.push(0);for(r=l;--r>=0;){for(t=0,i=c+r;i>r;)s=a[i]+p[r]*f[i-r-1]+t,a[i--]=s%V|0,t=s/V|0;a[i]=(a[i]+t)%V|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=si(a,n),R?q(e,d.precision,d.rounding):e},U.toBinary=function(e,t){return Ci(this,2,e,t)},U.toDecimalPlaces=U.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(G(e,0,Br),t===void 0?t=r.rounding:G(t,0,8),q(n,e+n.e+1,t))},U.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=J(r,!0):(G(e,0,Br),t===void 0?t=i.rounding:G(t,0,8),r=q(new i(r),e+1,t),n=J(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},U.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=J(i):(G(e,0,Br),t===void 0?t=a.rounding:G(t,0,8),r=q(new a(i),e+i.e+1,t),n=J(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},U.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=li(m)-p.e-1,o=a%H,t.d[0]=B(10,o<0?H+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(qr+s);e=s.gt(t)?a>0?t:l:s}for(R=!1,s=new h(W(m)),u=h.precision,h.precision=a=m.length*H*2;d=K(s,t,0,1,1),i=n.plus(d.times(r)),i.cmp(e)!=1;)n=r,r=i,i=l,l=c.plus(d.times(i)),c=i,i=t,t=s.minus(d.times(i)),s=i;return i=K(e.minus(n),r,0,1,1),c=c.plus(i.times(l)),n=n.plus(i.times(r)),c.s=l.s=p.s,f=K(l,r,a,1).minus(p).abs().cmp(K(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,R=!0,f},U.toHexadecimal=U.toHex=function(e,t){return Ci(this,16,e,t)},U.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:G(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(R=!1,n=K(n,e,0,t,1).times(e),R=!0,q(n)):(e.s=n.s,n=e),n},U.toNumber=function(){return+this},U.toOctal=function(e,t){return Ci(this,8,e,t)},U.toPower=U.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(B(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return q(s,r,a);if(t=z(e.e/H),t>=e.d.length-1&&(n=l<0?-l:l)<=ti)return i=di(c,s,n,r),e.s<0?new c(1).div(i):q(i,r,a);if(o=s.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),s.e==0&&s.d[0]==1&&s.d.length==1)return s.s=o,s}return n=B(+s,l),t=n==0||!isFinite(n)?z(l*(Math.log(`0.`+W(s.d))/Math.LN10+s.e+1)):new c(n+``).e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(R=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=mi(e.times(hi(s,r+n)),r),i.d&&(i=q(i,r+5,1),ii(i.d,r,a)&&(t=r+10,i=q(mi(e.times(hi(s,t+n)),t),t+5,1),+W(i.d).slice(r+1,r+15)+1==1e14&&(i=q(i,r+1,0)))),i.s=o,R=!0,c.rounding=a,q(i,r,a))},U.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=J(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(G(e,1,Br),t===void 0?t=i.rounding:G(t,0,8),r=q(new i(r),e,t),n=J(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},U.toSignificantDigits=U.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(G(e,1,Br),t===void 0?t=r.rounding:G(t,0,8)),q(new r(n),e,t)},U.toString=function(){var e=this,t=e.constructor,n=J(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},U.truncated=U.trunc=function(){return q(new this.constructor(this),this.e+1,1)},U.valueOf=U.toJSON=function(){var e=this,t=e.constructor,n=J(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function W(e){var t,n,r,i=e.length-1,a=``,o=e[0];if(i>0){for(a+=o,t=1;t<i;t++)r=e[t]+``,n=H-r.length,n&&(a+=ui(n)),a+=r;o=e[t],r=o+``,n=H-r.length,n&&(a+=ui(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function G(e,t,n){if(e!==~~e||e<t||e>n)throw Error(qr+e)}function ii(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=H,i=0):(i=Math.ceil((t+1)/H),t%=H),a=B(10,H-t),s=e[i]%a|0,r==null?t<3?(t==0?s=s/100|0:t==1&&(s=s/10|0),o=n<4&&s==99999||n>3&&s==49999||s==5e4||s==0):o=(n<4&&s+1==a||n>3&&s+1==a/2)&&(e[i+1]/a/100|0)==B(10,t-2)-1||(s==a/2||s==0)&&(e[i+1]/a/100|0)==0:t<4?(t==0?s=s/1e3|0:t==1?s=s/100|0:t==2&&(s=s/10|0),o=(r||n<4)&&s==9999||!r&&n>3&&s==4999):o=((r||n<4)&&s+1==a||!r&&n>3&&s+1==a/2)&&(e[i+1]/a/1e3|0)==B(10,t-3)-1,o}function ai(e,t,n){for(var r,i=[0],a,o=0,s=e.length;o<s;){for(a=i.length;a--;)i[a]*=t;for(i[0]+=Vr.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function oi(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/xi(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=bi(e,1,t.times(i),new e(1));for(var a=n;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var K=(function(){function e(e,t,n){var r,i=0,a=e.length;for(e=e.slice();a--;)r=e[a]*t+i,e[a]=r%n|0,i=r/n|0;return i&&e.unshift(i),e}function t(e,t,n,r){var i,a;if(n!=r)a=n>r?1:-1;else for(i=a=0;i<n;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;)e.shift()}return function(r,i,a,o,s,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,ee,C,w,T,E,te,D=r.constructor,ne=r.s==i.s?1:-1,O=r.d,k=i.d;if(!O||!O[0]||!k||!k[0])return new D(!r.s||!i.s||(O?k&&O[0]==k[0]:!k)?NaN:O&&O[0]==0||!k?ne*0:ne/0);for(c?(p=1,u=r.e-i.e):(c=V,p=H,u=z(r.e/p)-z(i.e/p)),E=k.length,w=O.length,_=new D(ne),v=_.d=[],d=0;k[d]==(O[d]||0);d++);if(k[d]>(O[d]||0)&&u--,a==null?(S=a=D.precision,o=D.rounding):S=s?a+(r.e-i.e)+1:a,S<0)v.push(1),m=!0;else{if(S=S/p+2|0,d=0,E==1){for(f=0,k=k[0],S++;(d<w||f)&&S--;d++)ee=f*c+(O[d]||0),v[d]=ee/k|0,f=ee%k|0;m=f||d<w}else{for(f=c/(k[0]+1)|0,f>1&&(k=e(k,f,c),O=e(O,f,c),E=k.length,w=O.length),C=E,y=O.slice(0,E),b=y.length;b<E;)y[b++]=0;te=k.slice(),te.unshift(0),T=k[0],k[1]>=c/2&&++T;do f=0,l=t(k,y,E,b),l<0?(x=y[0],E!=b&&(x=x*c+(y[1]||0)),f=x/T|0,f>1?(f>=c&&(f=c-1),h=e(k,f,c),g=h.length,b=y.length,l=t(h,y,g,b),l==1&&(f--,n(h,E<g?te:k,g,c))):(f==0&&(l=f=1),h=k.slice()),g=h.length,g<b&&h.unshift(0),n(y,h,b,c),l==-1&&(b=y.length,l=t(k,y,E,b),l<1&&(f++,n(y,E<b?te:k,b,c))),b=y.length):l===0&&(f++,y=[0]),v[d++]=f,l&&y[0]?y[b++]=O[C]||0:(y=[O[C]],b=1);while((C++<w||y[0]!==void 0)&&S--);m=y[0]!==void 0}v[0]||v.shift()}if(p==1)_.e=u,Gr=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,q(_,s?a+_.e+1:a,o,m)}return _}})();function q(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor;out:if(t!=null){if(d=e.d,!d)return e;for(i=1,s=d[0];s>=10;s/=10)i++;if(a=t-i,a<0)a+=H,o=t,u=d[f=0],c=u/B(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/H),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=H,o=a-H+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=H,o=a-H+i,c=o<0?0:u/B(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%B(10,i-o-1)),l=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(a>0?o>0?u/B(10,i-o):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,l?(t-=e.e+1,d[0]=B(10,(H-t%H)%H),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=B(10,H-a),d[f]=o>0?(u/B(10,i-o)%B(10,o)|0)*s:0),l)for(;;)if(f==0){for(a=1,o=d[0];o>=10;o/=10)a++;for(o=d[0]+=s,s=1;o>=10;o/=10)s++;a!=s&&(e.e++,d[0]==V&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=V)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return R&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function J(e,t,n){if(!e.isFinite())return gi(e);var r,i=e.e,a=W(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+ui(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+ui(-i-1)+a,n&&(r=n-o)>0&&(a+=ui(r))):i>=o?(a+=ui(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+ui(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=ui(r))),a}function si(e,t){var n=e[0];for(t*=H;n>=10;n/=10)t++;return t}function ci(e,t,n){if(t>ni)throw R=!0,n&&(e.precision=n),Error(Jr);return q(new e(Hr),t,1,!0)}function Y(e,t,n){if(t>ri)throw Error(Jr);return q(new e(Ur),t,n,!0)}function li(e){var t=e.length-1,n=t*H+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function ui(e){for(var t=``;e--;)t+=`0`;return t}function di(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/H+4);for(R=!1;;){if(n%2&&(a=a.times(t),wi(a.d,o)&&(i=!0)),n=z(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),wi(t.d,o)}return R=!0,a}function fi(e){return e.d[e.d.length-1]&1}function pi(e,t,n){for(var r,i,a=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){a=i;break}r=a.cmp(i),(r===n||r===0&&a.s===n)&&(a=i)}return a}function mi(e,t){var n,r,i,a,o,s,c,l=0,u=0,d=0,f=e.constructor,p=f.rounding,m=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(R=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(B(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=q(a.times(e),c,1),n=n.times(++u),s=o.plus(K(a,n,c,1)),W(s.d).slice(0,c)===W(o.d).slice(0,c)){for(i=d;i--;)o=q(o.times(o),c,1);if(t==null)if(l<3&&ii(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return q(o,f.precision=m,p,R=!0);else return f.precision=m,o}o=s}}function hi(e,t){var n,r,i,a,o,s,c,l,u,d,f,p=1,m=10,h=e,g=h.d,_=h.constructor,v=_.rounding,y=_.precision;if(h.s<0||!g||!g[0]||!h.e&&g[0]==1&&g.length==1)return new _(g&&!g[0]?-1/0:h.s==1?g?0:h:NaN);if(t==null?(R=!1,u=y):u=t,_.precision=u+=m,n=W(g),r=n.charAt(0),Math.abs(a=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=W(h.d),r=n.charAt(0),p++;a=h.e,r>1?(h=new _(`0.`+n),a++):h=new _(r+`.`+n.slice(1))}else return l=ci(_,u+2,y).times(a+``),h=hi(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?q(h,y,v,R=!0):h;for(d=h,c=o=h=K(h.minus(1),h.plus(1),u,1),f=q(h.times(h),u,1),i=3;;){if(o=q(o.times(f),u,1),l=c.plus(K(o,new _(i),u,1)),W(l.d).slice(0,u)===W(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(ci(_,u+2,y).times(a+``))),c=K(c,new _(p),u,1),t==null)if(ii(c.d,u-m,v,s))_.precision=u+=m,l=o=h=K(d.minus(1),d.plus(1),u,1),f=q(h.times(h),u,1),i=s=1;else return q(c,_.precision=y,v,R=!0);else return _.precision=y,c;c=l,i+=2}}function gi(e){return String(e.s*e.s/0)}function _i(e,t){var n,r,i;for((n=t.indexOf(`.`))>-1&&(t=t.replace(`.`,``)),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%H,n<0&&(r+=H),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=H;r<i;)e.d.push(+t.slice(r,r+=H));t=t.slice(r),r=H-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),R&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function vi(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),ei.test(t))return _i(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Qr.test(t))n=16,t=t.toLowerCase();else if(Zr.test(t))n=2;else if($r.test(t))n=8;else throw Error(qr+t);for(a=t.search(/p/i),a>0?(c=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf(`.`),o=a>=0,r=e.constructor,o&&(t=t.replace(`.`,``),s=t.length,a=s-a,i=di(r,new r(n),a,a*2)),l=ai(t,n,V),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=si(l,u),e.d=l,R=!1,o&&(e=K(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?B(2,c):fa.pow(2,c))),R=!0,e)}function yi(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:bi(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/xi(5,n)),t=bi(e,2,t,t);for(var i,a=new e(5),o=new e(16),s=new e(20);n--;)i=t.times(t),t=t.times(a.plus(i.times(o.times(i).minus(s))));return t}function bi(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/H);for(R=!1,c=n.times(n),s=new e(r);;){if(o=K(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=K(o.times(c),new e(t++*t++),u,1),o=s.plus(r),o.d[d]!==void 0){for(a=d;o.d[a]===s.d[a]&&a--;);if(a==-1)break}a=s,s=r,r=o,o=a,l++}return R=!0,o.d.length=d+1,o}function xi(e,t){for(var n=e;--t;)n*=e;return n}function Si(e,t){var n,r=t.s<0,i=Y(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return L=r?4:1,t;if(n=t.divToInt(i),n.isZero())L=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return L=fi(n)?r?2:3:r?4:1,t;L=fi(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Ci(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(G(n,1,Br),r===void 0?r=p.rounding:G(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=gi(e);else{for(u=J(e),o=u.indexOf(`.`),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(u=u.replace(`.`,``),f=new p(1),f.e=u.length-o,f.d=ai(J(f),10,i),f.e=f.d.length),d=ai(u,10,i),a=c=d.length;d[--c]==0;)d.pop();if(!d[0])u=m?`0p+0`:`0`;else{if(o<0?a--:(e=new p(e),e.d=d,e.e=a,e=K(e,f,n,r,0,i),d=e.d,a=e.e,l=Gr),o=d[n],s=i/2,l||=d[n+1]!==void 0,l=r<4?(o!==void 0||l)&&(r===0||r===(e.s<0?3:2)):o>s||o===s&&(r===4||l||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,l)for(;++d[--n]>i-1;)d[n]=0,n||(++a,d.unshift(1));for(c=d.length;!d[c-1];--c);for(o=0,u=``;o<c;o++)u+=Vr.charAt(d[o]);if(m){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)u+=`0`;for(d=ai(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Vr.charAt(d[o])}else u=u.charAt(0)+`.`+u.slice(1);u=u+(a<0?`p`:`p+`)+a}else if(a<0){for(;++a;)u=`0`+u;u=`0.`+u}else if(++a>c)for(a-=c;a--;)u+=`0`;else a<c&&(u=u.slice(0,a)+`.`+u.slice(a))}u=(t==16?`0x`:t==2?`0b`:t==8?`0o`:``)+u}return e.s<0?`-`+u:u}function wi(e,t){if(e.length>t)return e.length=t,!0}function Ti(e){return new this(e).abs()}function Ei(e){return new this(e).acos()}function Di(e){return new this(e).acosh()}function Oi(e,t){return new this(e).plus(t)}function ki(e){return new this(e).asin()}function Ai(e){return new this(e).asinh()}function ji(e){return new this(e).atan()}function Mi(e){return new this(e).atanh()}function Ni(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,a=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Y(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Y(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Y(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(K(e,t,a,1)),t=Y(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(K(e,t,a,1)),n}function Pi(e){return new this(e).cbrt()}function Fi(e){return q(e=new this(e),e.e+1,2)}function Ii(e,t,n){return new this(e).clamp(t,n)}function Li(e){if(!e||typeof e!=`object`)throw Error(Kr+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,Br,`rounding`,0,8,`toExpNeg`,-zr,0,`toExpPos`,0,zr,`maxE`,0,zr,`minE`,-zr,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Wr[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(qr+n+`: `+r);if(n=`crypto`,i&&(this[n]=Wr[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<`u`&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Yr);else this[n]=!1;else throw Error(qr+n+`: `+r);return this}function Ri(e){return new this(e).cos()}function zi(e){return new this(e).cosh()}function Bi(e){var t,n,r;function i(e){var t,n,r,a=this;if(!(a instanceof i))return new i(e);if(a.constructor=i,Gi(e)){a.s=e.s,R?!e.d||e.e>i.maxE?(a.e=NaN,a.d=null):e.e<i.minE?(a.e=0,a.d=[0]):(a.e=e.e,a.d=e.d.slice()):(a.e=e.e,a.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){a.s=1/e<0?-1:1,a.e=0,a.d=[0];return}if(e<0?(e=-e,a.s=-1):a.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;R?t>i.maxE?(a.e=NaN,a.d=null):t<i.minE?(a.e=0,a.d=[0]):(a.e=t,a.d=[e]):(a.e=t,a.d=[e]);return}if(e*0!=0){e||(a.s=NaN),a.e=NaN,a.d=null;return}return _i(a,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),a.s=-1):(n===43&&(e=e.slice(1)),a.s=1),ei.test(e)?_i(a,e):vi(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,_i(a,e.toString());throw Error(qr+e)}if(i.prototype=U,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Li,i.clone=Bi,i.isDecimal=Gi,i.abs=Ti,i.acos=Ei,i.acosh=Di,i.add=Oi,i.asin=ki,i.asinh=Ai,i.atan=ji,i.atanh=Mi,i.atan2=Ni,i.cbrt=Pi,i.ceil=Fi,i.clamp=Ii,i.cos=Ri,i.cosh=zi,i.div=Vi,i.exp=Hi,i.floor=Ui,i.hypot=Wi,i.ln=Ki,i.log=qi,i.log10=Yi,i.log2=Ji,i.max=Xi,i.min=Zi,i.mod=Qi,i.mul=$i,i.pow=ea,i.random=ta,i.round=na,i.sign=ra,i.sin=ia,i.sinh=aa,i.sqrt=oa,i.sub=sa,i.sum=ca,i.tan=la,i.tanh=ua,i.trunc=da,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=[`precision`,`rounding`,`toExpNeg`,`toExpPos`,`maxE`,`minE`,`modulo`,`crypto`],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function Vi(e,t){return new this(e).div(t)}function Hi(e){return new this(e).exp()}function Ui(e){return q(e=new this(e),e.e+1,3)}function Wi(){var e,t,n=new this(0);for(R=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);n=t}return R=!0,n.sqrt()}function Gi(e){return e instanceof fa||e&&e.toStringTag===Xr||!1}function Ki(e){return new this(e).ln()}function qi(e,t){return new this(e).log(t)}function Ji(e){return new this(e).log(2)}function Yi(e){return new this(e).log(10)}function Xi(){return pi(this,arguments,-1)}function Zi(){return pi(this,arguments,1)}function Qi(e,t){return new this(e).mod(t)}function $i(e,t){return new this(e).mul(t)}function ea(e,t){return new this(e).pow(t)}function ta(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:G(e,1,Br),r=Math.ceil(e/H),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));a<r;)i=t[a],i>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:s[a++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);a<r;)i=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,a):(s.push(i%1e7),a+=4);a=r/4}else throw Error(Yr);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=H,r&&e&&(i=B(10,H-e),s[a]=(r/i|0)*i);s[a]===0;a--)s.pop();if(a<0)n=0,s=[0];else{for(n=-1;s[0]===0;n-=H)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<H&&(n-=H-r)}return o.e=n,o.d=s,o}function na(e){return q(e=new this(e),e.e+1,this.rounding)}function ra(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function ia(e){return new this(e).sin()}function aa(e){return new this(e).sinh()}function oa(e){return new this(e).sqrt()}function sa(e,t){return new this(e).sub(t)}function ca(){var e=0,t=arguments,n=new this(t[e]);for(R=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return R=!0,q(n,this.precision,this.rounding)}function la(e){return new this(e).tan()}function ua(e){return new this(e).tanh()}function da(e){return q(e=new this(e),e.e+1,1)}U[Symbol.for(`nodejs.util.inspect.custom`)]=U.toString,U[Symbol.toStringTag]=`Decimal`;var fa=U.constructor=Bi(Wr);Hr=new fa(Hr),Ur=new fa(Ur);var pa=fa,ma=`BigNumber`,ha=[`?on`,`config`],ga=_r(ma,ha,e=>{var{on:t,config:n}=e,r=pa.clone({precision:n.precision,modulo:pa.EUCLID});return r.prototype=Object.create(r.prototype),r.prototype.type=`BigNumber`,r.prototype.isBigNumber=!0,r.prototype.toJSON=function(){return{mathjs:`BigNumber`,value:this.toString()}},r.fromJSON=function(e){return new r(e.value)},t&&t(`config`,function(e,t){e.precision!==t.precision&&r.config({precision:e.precision})}),r},{isClass:!0});const X=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Z=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},_a=function(e){let t=Math.PI/4;if(-t>e||e>t)return Math.cos(e)-1;let n=e*e;return n*(n*(n*(n*(n*(n*(n*(n/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},va=function(e,t){return e=Math.abs(e),t=Math.abs(t),e<t&&([e,t]=[t,e]),e<1e8?Math.sqrt(e*e+t*t):(t/=e,e*Math.sqrt(1+t*t))},ya=function(){throw SyntaxError(`Invalid Param`)};function ba(e,t){let n=Math.abs(e),r=Math.abs(t);return e===0?Math.log(r):t===0?Math.log(n):n<3e3&&r<3e3?Math.log(e*e+t*t)*.5:(e*=.5,t*=.5,.5*Math.log(e*e+t*t)+Math.LN2)}const xa={re:0,im:0},Sa=function(e,t){let n=xa;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return Q.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return Q.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):ya();break;case`string`:n.im=n.re=0;let t=e.replace(/_/g,``).match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,i=0;t===null&&ya();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
123
+ `||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&ya(),t[e+1]!==` `&&!isNaN(t[e+1])?(n.im+=parseFloat((i%2?`-`:``)+t[e+1]),e++):n.im+=parseFloat((i%2?`-`:``)+`1`),r=i=0):((r+i===0||isNaN(a))&&ya(),t[e+1]===`i`||t[e+1]===`I`?(n.im+=parseFloat((i%2?`-`:``)+a),e++):n.re+=parseFloat((i%2?`-`:``)+a),r=i=0))}r+i>0&&ya();break;case`number`:n.im=0,n.re=e;break;default:ya()}return isNaN(n.re)||isNaN(n.im),n};function Q(e,t){if(!(this instanceof Q))return new Q(e,t);let n=Sa(e,t);this.re=n.re,this.im=n.im}Q.prototype={re:0,im:0,sign:function(){let e=va(this.re,this.im);return new Q(this.re/e,this.im/e)},add:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Q.NAN:Q.INFINITY:new Q(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Q.NAN:Q.INFINITY:new Q(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;return r&&o||i&&a?Q.NAN:r||i?Q.INFINITY:n.im===0&&this.im===0?new Q(this.re*n.re,0):new Q(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=Sa(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;if(a&&o||r&&i)return Q.NAN;if(o||r)return Q.INFINITY;if(a||i)return Q.ZERO;if(n.im===0)return new Q(this.re/n.re,this.im/n.re);if(Math.abs(n.re)<Math.abs(n.im)){let e=n.re/n.im,t=n.re*e+n.im;return new Q((this.re*e+this.im)/t,(this.im*e-this.re)/t)}else{let e=n.im/n.re,t=n.im*e+n.re;return new Q((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=Sa(e,t),r=this.re===0&&this.im===0,i=n.re===0&&n.im===0;if(i)return Q.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new Q(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new Q(this.im**+n.re,0);case 1:return new Q(0,this.im**+n.re);case 2:return new Q(-(this.im**+n.re),0);case 3:return new Q(0,-(this.im**+n.re))}}if(r&&n.re>0)return Q.ZERO;let a=Math.atan2(this.im,this.re),o=ba(this.re,this.im),s=Math.exp(n.re*o-n.im*a),c=n.im*o+n.re*a;return new Q(s*Math.cos(c),s*Math.sin(c))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new Q(Math.sqrt(e),0):new Q(0,Math.sqrt(-e));let n=va(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new Q(r,t<0?-i:i):new Q(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new Q(e,0):new Q(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new Q(Math.expm1(e)*Math.cos(t)+_a(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new Q(Math.log(e),0):new Q(ba(e,t),Math.atan2(t,e))},abs:function(){return va(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new Q(Math.sin(e)*X(t),Math.cos(e)*Z(t))},cos:function(){let e=this.re,t=this.im;return new Q(Math.cos(e)*X(t),-Math.sin(e)*Z(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+X(t);return new Q(Math.sin(e)/n,Z(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-X(t);return new Q(-Math.sin(e)/n,Z(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*X(2*t)+.5*Math.cos(2*e);return new Q(Math.cos(e)*X(t)/n,Math.sin(e)*Z(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*X(2*t)-.5*Math.cos(2*e);return new Q(Math.sin(e)*X(t)/n,-Math.cos(e)*Z(t)/n)},asin:function(){let e=this.re,t=this.im,n=new Q(t*t-e*e+1,-2*e*t).sqrt(),r=new Q(n.re-t,n.im+e).log();return new Q(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new Q(t*t-e*e+1,-2*e*t).sqrt(),r=new Q(n.re-t,n.im+e).log();return new Q(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new Q(0,1/0);if(t===-1)return new Q(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new Q((1-t*t-e*e)/n,-2*e/n).log();return new Q(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new Q(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).atan():new Q(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(0,1/0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).acos():new Q(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).asin():new Q(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new Q(Z(e)*Math.cos(t),X(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new Q(X(e)*Math.cos(t),Z(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=X(e)+Math.cos(t);return new Q(Z(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=X(e)-Math.cos(t);return new Q(Z(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-X(2*e);return new Q(-2*Z(e)*Math.cos(t)/n,2*X(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+X(2*e);return new Q(2*X(e)*Math.cos(t)/n,-2*Z(e)*Math.sin(t)/n)},asinh:function(){let e=this.im;this.im=-this.re,this.re=e;let t=this.asin();return this.re=-this.im,this.im=e,e=t.re,t.re=-t.im,t.im=e,t},acosh:function(){let e=this.acos();if(e.im<=0){let t=e.re;e.re=-e.im,e.im=t}else{let t=e.im;e.im=-e.re,e.re=t}return e},atanh:function(){let e=this.re,t=this.im,n=e>1&&t===0,r=1-e,i=1+e,a=r*r+t*t,o=a===0?new Q(e===-1?0:e/0,t===0?0:t/0):new Q((i*r-t*t)/a,(t*r+i*t)/a),s=o.re;return o.re=ba(o.re,o.im)/2,o.im=Math.atan2(o.im,s)/2,n&&(o.im=-o.im),o},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Q(0,Math.PI/2);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).atanh():new Q(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0)return new Q(e===0?1/0:Math.log(e+Math.sqrt(e*e+1)),0);let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).asinh():new Q(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return Q.INFINITY;let n=e*e+t*t;return n===0?new Q(e===0?0:e/0,t===0?0:-t/0).acosh():new Q(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return Q.INFINITY;if(this.isInfinite())return Q.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new Q(e/n,-t/n)},conjugate:function(){return new Q(this.re,-this.im)},neg:function(){return new Q(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new Q(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new Q(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new Q(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=Sa(e,t);return Math.abs(n.re-this.re)<=Q.EPSILON&&Math.abs(n.im-this.im)<=Q.EPSILON},clone:function(){return new Q(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<Q.EPSILON&&(e=0),Math.abs(t)<Q.EPSILON&&(t=0),t===0?n+e:(e===0?t<0&&(t=-t,n+=`-`):(n+=e,n+=` `,t<0?(t=-t,n+=`-`):n+=`+`,n+=` `),t!==1&&(n+=t),n+`i`))},toVector:function(){return[this.re,this.im]},valueOf:function(){return this.im===0?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return this.im===0&&this.re===0},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!this.isFinite()}},Q.ZERO=new Q(0,0),Q.ONE=new Q(1,0),Q.I=new Q(0,1),Q.PI=new Q(Math.PI,0),Q.E=new Q(Math.E,0),Q.INFINITY=new Q(1/0,1/0),Q.NAN=new Q(NaN,NaN),Q.EPSILON=1e-15;var Ca=`Complex`,wa=[],Ta=_r(Ca,wa,()=>(Object.defineProperty(Q,`name`,{value:`Complex`}),Q.prototype.constructor=Q,Q.prototype.type=`Complex`,Q.prototype.isComplex=!0,Q.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},Q.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},Q.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=kn(this.re,e),a=kn(this.im,e),o=j(e)?e:e?e.precision:null;if(o!==null){var s=10**-o;Math.abs(r/n)<s&&(r=0),Math.abs(n/r)<s&&(n=0)}return t=n===0?i:r===0?n===1?`i`:n===-1?`-i`:a+`i`:n<0?n===-1?i+` - i`:i+` - `+a.substring(1)+`i`:n===1?i+` + i`:i+` + `+a+`i`,t},Q.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return Q(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(j(n)){if(It(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),j(r))return new Q({r:n,phi:r});throw TypeError(`Phi is not a number nor an angle unit.`)}else throw TypeError(`Radius r is not a number.`);default:throw SyntaxError(`Wrong number of arguments in function fromPolar`)}},Q.prototype.valueOf=Q.prototype.toString,Q.fromJSON=function(e){return new Q(e)},Q.compare=function(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0},Q),{isClass:!0}),Ea=D(((exports,t)=>{
124
124
  /**
125
125
  * @license Fraction.js v4.3.0 20/08/2023
126
126
  * https://www.xarg.org/2014/03/rational-numbers-in-javascript/
@@ -128,23 +128,23 @@ var Rr=9e15,zr=1e9,Br=`0123456789abcdef`,Vr=`2.302585092994045684017991454684364
128
128
  * Copyright (c) 2023, Robert Eisele (robert@raw.org)
129
129
  * Dual licensed under the MIT or GPL Version 2 licenses.
130
130
  **/
131
- (function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n){if(u===`1`)continue;if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r){if(u===`1`)continue;if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof exports==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(exports)})),Da=k(Ea(),1),Oa=`Fraction`,ka=[],Aa=gr(Oa,ka,()=>(Object.defineProperty(Da.default,`name`,{value:`Fraction`}),Da.default.prototype.constructor=Da.default,Da.default.prototype.type=`Fraction`,Da.default.prototype.isFraction=!0,Da.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},Da.default.fromJSON=function(e){return new Da.default(e)},Da.default),{isClass:!0}),ja=`Matrix`,Ma=[],Na=gr(ja,Ma,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Pa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Fa=`DenseMatrix`,Ia=[`Matrix`],La=gr(Fa,Ia,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!It(t))throw Error(`Invalid datatype: `+t);if(Lt(e))e.type===`DenseMatrix`?(this._data=_n(e._data),this._size=_n(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&P(e.data)&&P(e.size))this._data=e.data,this._size=e.size,Qn(this._data,this._size),this._datatype=t||e.datatype;else if(P(e))this._data=l(e),this._size=Xn(this._data),Qn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+gn(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return cr(this._data,gn)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!P(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new I(e.length,this._size.length);for(var t=0;t<e.length;t++)L(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];L(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!P(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new I(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],L(a,s.length),s=s[a];return a=e[e.length-1],L(a,s.length),s[a]=t,this};function r(e,t){if(!Ht(t))throw TypeError(`Invalid index`);var r=t.isScalar();if(r)return e.get(t.min());var a=t.size();if(a.length!==e._size.length)throw new I(a.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)L(o[c],e._size[c]),L(s[c],e._size[c]);return new n(i(e._data,t,a.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return L(t,e.length),e[t]}).valueOf():o.map(function(a){L(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Lt(n)?(s=n.size(),n=n.valueOf()):s=Xn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!yn(s,i))try{n=s.length===0?pr([n],i):pr(n,i),s=Xn(n)}catch{}if(i.length<e._size.length)throw new I(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=ar(n,i.length,u,s)}if(!yn(i,s))throw new I(i,s,`>`);var d=t.max().map(function(e){return e+1});c(e,d,r);var f=i.length,p=0;o(e._data,t,n,f,p)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){L(t),e[t]=n[r[0]]}):s.forEach(function(a,s){L(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!Rt(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e),i=n?this.clone():this;return s(i,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;P(r);)r=r[0];return r}return e._size=t.slice(0),e._data=$n(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;n._data=tr(n._data,e);var r=n._size.reduce((e,t)=>e*t);return n._size=nr(e,r),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){var e=new n({data:_n(this._data),size:_n(this._size),datatype:this._datatype});return e},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=Pa(e),i=function n(i,a){return P(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)},a=i(this._data,[]),o=this._datatype===void 0?void 0:cr(a,gn);return new n(a,o)},n.prototype.forEach=function(e){var t=this,n=function n(r,i){P(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)};n(this._data,[])},n.prototype[Symbol.iterator]=function*(){var e=function*e(t,n){if(P(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}};yield*e(this._data,[])},n.prototype.rows=function(){var e=[],t=this.size();if(t.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);var r=this._data;for(var i of r)e.push(new n([i],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return _n(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Hn(this._data,e)},n.prototype.toString=function(){return Hn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(N(e)&&(e=e.toNumber()),!M(e)||!F(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!P(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(N(e)&&(e=e.toNumber()),!M(e)||!F(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(N(r)&&(r=r.toNumber()),!M(r)||!F(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(P(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Lt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=N(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=$n(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!M(e)||!F(e)||!M(t)||!F(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return L(e,this._size[0]),L(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Lt(e)?l(e.valueOf()):P(e)?e.map(l):e}return n},{isClass:!0});function Ra(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Ra(e,t,n)}):t(e)}var za=`isNumeric`,Ba=[`typed`],Va=gr(za,Ba,e=>{var{typed:t}=e;return t(za,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Ra(t,e))})}),Ha=`hasNumericValue`,Ua=[`typed`,`isNumeric`],Wa=gr(Ha,Ua,e=>{var{typed:t,isNumeric:n}=e;return t(Ha,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Ga=ga({config:Tn}),Ka=Ta({}),qa=Aa({}),Ja=Na({}),Ya=La({Matrix:Ja}),Xa=Nr({BigNumber:Ga,Complex:Ka,DenseMatrix:Ya,Fraction:qa}),Za=Va({typed:Xa}),Qa=Wa({isNumeric:Za,typed:Xa});const $a=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},eo=e=>{let t=Number(e),n=Date.now();if(Number.isNaN(t))return n+kt;if(!$a(t)&&a(t))return At(t);if($a(t))return n+t;{let e=t*Dt;return n+e}},to=`ratelimitlimit`,no=`ratelimitremaining`,ro=`ratelimitreset`,io=`ratelimitconcurrencylimit`,ao=`ratelimitconcurrencyremaining`,oo=`ratelimitconcurrencyreset`,so=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``),i=Qa(r)?Number(r):null;t[e]=i}return t},co=e=>{let t=so(e);return{rateLimitLimit:t[to],rateLimitRemaining:t[no],rateLimitReset:eo(t[ro]),concurrencyLimit:t[io],concurrencyRemaining:t[ao],concurrencyReset:eo(t[oo])}},lo=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:s,behaviours:c}=e??{};return[t,n,r,s].some(o)?null:[t,n,r,i,a,s,...c??[]].filter(Boolean).join(`-`)},uo=(e,t=wt,n=Ct)=>{let r=Date.now();return a(e)||s(e)?fo(Number(e),r,t,n):It(e)&&e!==``?po(e,r,t,n):n},fo=(e,t,n=wt,r=Ct)=>{if(e<n)return e;let i=At(e);if(i>t){let e=Math.floor((i-t)/Dt);return e>0&&e<n?e:r}return r},po=(e,t,n=wt,r=Ct)=>{if(Ot.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/Dt);return e>0&&e<n?e:r}return r},mo=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>{let a=async a=>{let{response:o,config:s}=a,c=s?.signal;if(c?.aborted)return Promise.reject(yt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:l,retryAfter:d}=ho(o,i,r,n);if(l===429&&u(s)){let r=uo(d);if(s._retryCount>=Tt)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:d,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,l={...s,_retryCount:c+1},u=d?r*Dt:t(l._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:d,calculatedRetryAfter:u}}),await bt(u*1e3,s,o),e?.request(l)}return Promise.reject(a)};return a},ho=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:s,data:l}=e??{},{retryafter:d}=so(s??{});if(o(i)||o(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:o(e),providerIsMissing:o(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:d??`undefined`}}),{status:a,retryAfter:d};let f=n?.rateLimits?.mappedRateLimitErrors;if(u(f)&&u(l))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:o,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=c(l)?y.query(l,f)[0]:l,m=go(p,r);if(t===a&&m){let e=u??_o(s,i),t=vo(e,o);return{status:429,retryAfter:d??t}}}return{status:a,retryAfter:d}},go=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,_o=(e,t)=>u(t)&&u(e)?y.query(e,t)[0]:null,vo=(e,t=`seconds`)=>u(e)?yo(e,t):null,yo=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`){let t=typeof e==`string`?parseFloat(e):e;return t/Dt}if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},bo=`rateLimitErrorInterceptor`,xo=({axiosInstance:e,logger:n,requestConfig:r,context:i,concurrencyManager:a})=>{let s=async s=>{let{response:c,config:l}=s,d=l?.signal;if(o(i)||o(l))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:bo,...l,headers:void 0,hasContext:u(i),hasConfig:u(l)},code:vt.InterceptorContextNotPresent}),Promise.reject(s);if(o(a))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:bo,...l,headers:void 0,concurrencyManagerInitialized:u(a)},code:vt.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(s);let{requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h}=l?.requestMetadata??{},g=u(f)&&u(p)?await a.releaseRequest(f,p):!1;if(!g&&u(l?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:bo,requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h},code:vt.RateLimiterReleaseRequestFailed}),d?.aborted)return Promise.reject(yt(`Request aborted`,l,`ERR_CANCELED`,c));let{status:_,retryAfter:v}=ho(c,i,r,n);if(_===429&&u(l)){let r=uo(v);if(l._retryCount>=Tt)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${l.url}. Aborting.`,context:{...i??{},...l.requestMetadata??{},retryAfterHeader:v,retryAfterAsNumber:r}}),Promise.reject(s);let a=l?._retryCount??0,o={...l,_retryCount:a+1},u=v?r*Dt:t(o._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${l.url}`,context:{...i,retryAfterHeader:v,calculatedRetryAfter:u}}),await bt(u*1e3,l,c),e?.request(o)}return Promise.reject(s)};return s},So=`rateLimitResponseInterceptor`,Co=({logger:e,context:t,concurrencyManager:n})=>{let r=async r=>{let i=r?.config,a=i?.signal;if(o(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{...i,interceptor:So,headers:void 0}});else if(o(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:So,...i,headers:void 0,concurrencyManagerInitialized:u(n)},code:vt.RateLimitOrConcurrencyManagerNotInitialized}),r;else if(u(t.provider)&&u(t.accountSecureId)){let t=r?.headers;if(u(t)){let n=co(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:So,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{},d=await n.releaseRequest(o,s);if(d||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:So,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:vt.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(yt(`Request aborted`,i,`ERR_CANCELED`,r))}return r};return r},wo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),To=[{onFulfilled:wo,onRejected:null,options:void 0}],Eo=[{onFulfilled:null,onRejected:mo},{onFulfilled:null,onRejected:mt}],Do=[{onFulfilled:wo,onRejected:null,options:void 0},{onFulfilled:St,onRejected:null,options:void 0}],Oo=[{onFulfilled:Co,onRejected:xo},{onFulfilled:null,onRejected:mt}],ko=1,Ao=1e3,jo=0,Mo=59,No=.8,Po=500;var Fo=class extends Ee{name=`RateLimitManager`;async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=Mo,i=No,a=Po){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=jo)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=jo)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=Math.min(o,s/(a/Ao)),u=ko/l,d=Math.max(ht,c*u);return Math.min(c,d)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=u(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],l=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(_t.incr,[a,...l],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},$=class{static instances=new Map;static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if(o(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(u(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){let t=this.instances.get(e);return t?.getInstanceIfReady?.()??null}static reset(e){let t=this.instances.get(e);t?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Io=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Lo=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:s}=process.env,c=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=c.includes(`RETRY`)?zo(e,n):Ro(e,n),o(n?.service)||o(n?.organizationId)||s===`test`||o(t)||o(e))return a;let l=$.getIfReady(Fo)??void 0,d=$.getIfReady(rt)??void 0,f=l?.isReady(),p=d?.isRedisConfigured(),m=[],h=[];if(c.includes(`CONCURRENCY`)){if(!p)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!f)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);m.push(...Do),h.push(...Oo)}let g=lo(n);if(o(g))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:u(a)}}),a;let _=await pt.get(g);if(u(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:d,rateLimitManager:l},y=ut.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await pt.set(g,y),y}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:u(a)},error:t,code:Io.HttpTransportInstanceCreateError}),u(a)?a:Bo()}},Ro=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return ut.createInstance(n)??Bo()},zo=(e,t)=>{let n={interceptors:{requestConfigs:To,responseConfigs:Eo},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return ut.createInstance(n)??Bo()},Bo=()=>{let e=m.create({maxBodyLength:1/0});return e};var Vo=class e{#transportFactory;#getRedisClient;#logger;#redisClientConfig;#errorMappingFn;#redisClient;constructor({transportFactory:e=Lo,getRedisClient:t=xe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.#transportFactory=e,this.#getRedisClient=t,this.#logger=n,this.#redisClientConfig=r,this.#errorMappingFn=i}#generateCacheKey({url:e,payload:t,method:n,context:i}){let a=20;if(!i?.accountSecureId||i.accountSecureId.length<a||!e||!n)return null;let o=t?r(t):``;return`${i.accountSecureId}-${n.toUpperCase()}${o}-${e}`}async#getCachedResponse({url:t,payload:n,method:r,cacheTTL:i,context:a}){if(!this.#redisClient||!i||i<=0)return null;let o=this.#generateCacheKey({url:t,payload:n,method:r,context:a});if(!o)return null;let s=await this.#redisClient.getData(o);return s?(this.#logger?.debug({category:e.name,message:`Cache hit for key [${o}].`}),s):(this.#logger?.debug({category:e.name,message:`Cache miss for key [${o}].`}),null)}async#cacheResponse({url:t,payload:n,method:r,cacheTTL:i,context:a,response:o}){if(!this.#redisClient||!i||i<=0)return!1;let s=this.#generateCacheKey({url:t,payload:n,method:r,context:a});return s?(this.#logger?.debug({category:e.name,message:`Caching result for key [${s}].`}),this.#redisClient.setData({key:s,value:o,cacheTTL:i*60})):!1}async request({headers:t={},url:n,method:r=`get`,queryParams:i,maxRedirects:a=0,responseType:s,cacheTTL:c,context:l,traceId:d,payload:f,httpsAgent:p,httpAgent:m,requestConfig:h,httpsAgentConfig:g}){try{u(this.#redisClientConfig)&&o(this.#redisClient)&&(this.#redisClient=await this.#getRedisClient(this.#redisClientConfig,this.#logger,`HttpClient`));let e=this.#buildUrlWithQueryParams(n,i),_=this.#normalizeHeaders(t),v=this.#getSafePayload(f,t),y=await this.#getCachedResponse({url:e,payload:v,method:r,cacheTTL:c,context:l});if(y)return{...y,responseTime:new Date};let b=ft.getInstance(),x=u(d)?await b.get(d):null,S=x?.signal,C=await this.#transportFactory({redisClientConfig:this.#redisClientConfig,logger:this.#logger,context:l,requestConfig:h,httpsAgentConfig:g}),w=await C.request({headers:_,url:e,method:r,maxRedirects:a,responseType:s,data:v,httpsAgent:p,httpAgent:m,signal:S}),T={data:w.data,status:w.status,body:v,method:r,headers:this.#extractAxiosHeaders(w.headers),requestUrl:n,responseType:w?.config?.responseType,responseTime:new Date};return await this.#cacheResponse({url:e,payload:v,method:r,cacheTTL:c,context:l,response:T}),T}catch(t){let i=t;i.url=b(n),this.#logger?.warning({category:e.name,message:`Request error [${r?.toUpperCase()} ${i.url}]: ${i.message}.`,error:i});let a=this.#mapErrorToHttpException(i);throw u(a)?a:t}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#normalizeHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#extractAxiosHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#isFormUrlEncoded(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#getSafePayload(e,t){if(!(o(e)||c(e)&&Object.keys(e).length===0))return this.#isFormUrlEncoded(t)?x.stringify(e):e}#mapErrorToHttpException(e){if(h(e)&&this.#errorMappingFn)return this.#errorMappingFn(e)}#buildUrlWithQueryParams(e,t){if(o(t)||Object.keys(t).length===0)return e;let n=x.stringify(t);return`${e}?${n}`}};const Ho=(e,t,n)=>new Vo({redisClientConfig:e,logger:t,errorMappingFn:n});var Uo=class{static httpClientInstance=null;static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Ho}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Wo=[`get`,`post`,`put`,`delete`,`patch`],Go={[Ie.rPush]:`
131
+ (function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n){if(u===`1`)continue;if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r){if(u===`1`)continue;if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof exports==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(exports)})),Da=O(Ea(),1),Oa=`Fraction`,ka=[],Aa=_r(Oa,ka,()=>(Object.defineProperty(Da.default,`name`,{value:`Fraction`}),Da.default.prototype.constructor=Da.default,Da.default.prototype.type=`Fraction`,Da.default.prototype.isFraction=!0,Da.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},Da.default.fromJSON=function(e){return new Da.default(e)},Da.default),{isClass:!0}),ja=`Matrix`,Ma=[],Na=_r(ja,Ma,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Pa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Fa=`DenseMatrix`,Ia=[`Matrix`],La=_r(Fa,Ia,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Lt(t))throw Error(`Invalid datatype: `+t);if(Rt(e))e.type===`DenseMatrix`?(this._data=vn(e._data),this._size=vn(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&N(e.data)&&N(e.size))this._data=e.data,this._size=e.size,$n(this._data,this._size),this._datatype=t||e.datatype;else if(N(e))this._data=l(e),this._size=Zn(this._data),$n(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+_n(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return lr(this._data,_n)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!N(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new F(e.length,this._size.length);for(var t=0;t<e.length;t++)I(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];I(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!N(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new F(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],I(a,s.length),s=s[a];return a=e[e.length-1],I(a,s.length),s[a]=t,this};function r(e,t){if(!Ut(t))throw TypeError(`Invalid index`);var r=t.isScalar();if(r)return e.get(t.min());var a=t.size();if(a.length!==e._size.length)throw new F(a.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)I(o[c],e._size[c]),I(s[c],e._size[c]);return new n(i(e._data,t,a.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return I(t,e.length),e[t]}).valueOf():o.map(function(a){I(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Rt(n)?(s=n.size(),n=n.valueOf()):s=Zn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!bn(s,i))try{n=s.length===0?mr([n],i):mr(n,i),s=Zn(n)}catch{}if(i.length<e._size.length)throw new F(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=or(n,i.length,u,s)}if(!bn(i,s))throw new F(i,s,`>`);var d=t.max().map(function(e){return e+1});c(e,d,r);var f=i.length,p=0;o(e._data,t,n,f,p)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){I(t),e[t]=n[r[0]]}):s.forEach(function(a,s){I(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!zt(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e),i=n?this.clone():this;return s(i,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;N(r);)r=r[0];return r}return e._size=t.slice(0),e._data=er(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;n._data=nr(n._data,e);var r=n._size.reduce((e,t)=>e*t);return n._size=rr(e,r),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){var e=new n({data:vn(this._data),size:vn(this._size),datatype:this._datatype});return e},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=Pa(e),i=function n(i,a){return N(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)},a=i(this._data,[]),o=this._datatype===void 0?void 0:lr(a,_n);return new n(a,o)},n.prototype.forEach=function(e){var t=this,n=function n(r,i){N(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)};n(this._data,[])},n.prototype[Symbol.iterator]=function*(){var e=function*e(t,n){if(N(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}};yield*e(this._data,[])},n.prototype.rows=function(){var e=[],t=this.size();if(t.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);var r=this._data;for(var i of r)e.push(new n([i],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return vn(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Un(this._data,e)},n.prototype.toString=function(){return Un(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(M(e)&&(e=e.toNumber()),!j(e)||!P(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!N(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(M(e)&&(e=e.toNumber()),!j(e)||!P(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(M(r)&&(r=r.toNumber()),!j(r)||!P(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(N(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Rt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=M(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=er(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!j(e)||!P(e)||!j(t)||!P(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return I(e,this._size[0]),I(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Rt(e)?l(e.valueOf()):N(e)?e.map(l):e}return n},{isClass:!0});function Ra(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Ra(e,t,n)}):t(e)}var za=`isNumeric`,Ba=[`typed`],Va=_r(za,Ba,e=>{var{typed:t}=e;return t(za,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Ra(t,e))})}),Ha=`hasNumericValue`,Ua=[`typed`,`isNumeric`],Wa=_r(Ha,Ua,e=>{var{typed:t,isNumeric:n}=e;return t(Ha,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Ga=ga({config:En}),Ka=Ta({}),qa=Aa({}),Ja=Na({}),Ya=La({Matrix:Ja}),Xa=Pr({BigNumber:Ga,Complex:Ka,DenseMatrix:Ya,Fraction:qa}),Za=Va({typed:Xa}),Qa=Wa({isNumeric:Za,typed:Xa});const $a=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},eo=e=>{let t=Number(e),n=Date.now();if(Number.isNaN(t))return n+At;if(!$a(t)&&a(t))return jt(t);if($a(t))return n+t;{let e=t*Ot;return n+e}},to=`ratelimitlimit`,no=`ratelimitremaining`,ro=`ratelimitreset`,io=`ratelimitconcurrencylimit`,ao=`ratelimitconcurrencyremaining`,oo=`ratelimitconcurrencyreset`,so=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``),i=Qa(r)?Number(r):null;t[e]=i}return t},co=e=>{let t=so(e);return{rateLimitLimit:t[to],rateLimitRemaining:t[no],rateLimitReset:eo(t[ro]),concurrencyLimit:t[io],concurrencyRemaining:t[ao],concurrencyReset:eo(t[oo])}},lo=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:s,behaviours:c}=e??{};return[t,n,r,s].some(o)?null:[t,n,r,i,a,s,...c??[]].filter(Boolean).join(`-`)},uo=(e,t=Tt,n=wt)=>{let r=Date.now();return a(e)||s(e)?fo(Number(e),r,t,n):Lt(e)&&e!==``?po(e,r,t,n):n},fo=(e,t,n=Tt,r=wt)=>{if(e<n)return e;let i=jt(e);if(i>t){let e=Math.floor((i-t)/Ot);return e>0&&e<n?e:r}return r},po=(e,t,n=Tt,r=wt)=>{if(kt.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/Ot);return e>0&&e<n?e:r}return r},mo=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>{let a=async a=>{let{response:o,config:s}=a,c=s?.signal;if(c?.aborted)return Promise.reject(bt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:l,retryAfter:d}=ho(o,i,r,n);if(l===429&&u(s)){let r=uo(d);if(s._retryCount>=Et)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:d,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,l={...s,_retryCount:c+1},u=d?r*Ot:t(l._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:d,calculatedRetryAfter:u}}),await xt(u*1e3,s,o),e?.request(l)}return Promise.reject(a)};return a},ho=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:s,data:l}=e??{},{retryafter:d}=so(s??{});if(o(i)||o(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:o(e),providerIsMissing:o(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:d??`undefined`}}),{status:a,retryAfter:d};let f=n?.rateLimits?.mappedRateLimitErrors;if(u(f)&&u(l))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:o,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=c(l)?y.query(l,f)[0]:l,m=go(p,r);if(t===a&&m){let e=u??_o(s,i),t=vo(e,o);return{status:429,retryAfter:d??t}}}return{status:a,retryAfter:d}},go=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,_o=(e,t)=>u(t)&&u(e)?y.query(e,t)[0]:null,vo=(e,t=`seconds`)=>u(e)?yo(e,t):null,yo=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`){let t=typeof e==`string`?parseFloat(e):e;return t/Ot}if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},bo=`rateLimitErrorInterceptor`,xo=({axiosInstance:e,logger:n,requestConfig:r,context:i,concurrencyManager:a})=>{let s=async s=>{let{response:c,config:l}=s,d=l?.signal;if(o(i)||o(l))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:bo,...l,headers:void 0,hasContext:u(i),hasConfig:u(l)},code:yt.InterceptorContextNotPresent}),Promise.reject(s);if(o(a))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:bo,...l,headers:void 0,concurrencyManagerInitialized:u(a)},code:yt.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(s);let{requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h}=l?.requestMetadata??{},g=u(f)&&u(p)?await a.releaseRequest(f,p):!1;if(!g&&u(l?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:bo,requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h},code:yt.RateLimiterReleaseRequestFailed}),d?.aborted)return Promise.reject(bt(`Request aborted`,l,`ERR_CANCELED`,c));let{status:_,retryAfter:v}=ho(c,i,r,n);if(_===429&&u(l)){let r=uo(v);if(l._retryCount>=Et)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${l.url}. Aborting.`,context:{...i??{},...l.requestMetadata??{},retryAfterHeader:v,retryAfterAsNumber:r}}),Promise.reject(s);let a=l?._retryCount??0,o={...l,_retryCount:a+1},u=v?r*Ot:t(o._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${l.url}`,context:{...i,retryAfterHeader:v,calculatedRetryAfter:u}}),await xt(u*1e3,l,c),e?.request(o)}return Promise.reject(s)};return s},So=`rateLimitResponseInterceptor`,Co=({logger:e,context:t,concurrencyManager:n})=>{let r=async r=>{let i=r?.config,a=i?.signal;if(o(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{...i,interceptor:So,headers:void 0}});else if(o(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:So,...i,headers:void 0,concurrencyManagerInitialized:u(n)},code:yt.RateLimitOrConcurrencyManagerNotInitialized}),r;else if(u(t.provider)&&u(t.accountSecureId)){let t=r?.headers;if(u(t)){let n=co(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:So,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{},d=await n.releaseRequest(o,s);if(d||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:So,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:yt.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(bt(`Request aborted`,i,`ERR_CANCELED`,r))}return r};return r},wo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),To=[{onFulfilled:wo,onRejected:null,options:void 0}],Eo=[{onFulfilled:null,onRejected:mo},{onFulfilled:null,onRejected:ht}],Do=[{onFulfilled:wo,onRejected:null,options:void 0},{onFulfilled:Ct,onRejected:null,options:void 0}],Oo=[{onFulfilled:Co,onRejected:xo},{onFulfilled:null,onRejected:ht}],ko=1,Ao=1e3,jo=0,Mo=59,No=.8,Po=500;var Fo=class extends De{name=`RateLimitManager`;async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=Mo,i=No,a=Po){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=jo)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=jo)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=Math.min(o,s/(a/Ao)),u=ko/l,d=Math.max(gt,c*u);return Math.min(c,d)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=u(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],l=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(vt.incr,[a,...l],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},$=class{static instances=new Map;static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if(o(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(u(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){let t=this.instances.get(e);return t?.getInstanceIfReady?.()??null}static reset(e){let t=this.instances.get(e);t?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Io=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Lo=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:s}=process.env,c=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=c.includes(`RETRY`)?zo(e,n):Ro(e,n),o(n?.service)||o(n?.organizationId)||s===`test`||o(t)||o(e))return a;let l=$.getIfReady(Fo)??void 0,d=$.getIfReady(it)??void 0,f=l?.isReady(),p=d?.isRedisConfigured(),m=[],h=[];if(c.includes(`CONCURRENCY`)){if(!p)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!f)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);m.push(...Do),h.push(...Oo)}let g=lo(n);if(o(g))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:u(a)}}),a;let _=await mt.get(g);if(u(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:d,rateLimitManager:l},y=dt.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await mt.set(g,y),y}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:u(a)},error:t,code:Io.HttpTransportInstanceCreateError}),u(a)?a:Bo()}},Ro=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return dt.createInstance(n)??Bo()},zo=(e,t)=>{let n={interceptors:{requestConfigs:To,responseConfigs:Eo},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return dt.createInstance(n)??Bo()},Bo=()=>{let e=m.create({maxBodyLength:1/0});return e};var Vo=class{#transportFactory;#getRedisClient;#logger;#redisClientConfig;#errorMappingFn;#redisClient;name=`HttpClient`;constructor({transportFactory:e=Lo,getRedisClient:t=Se,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.#transportFactory=e,this.#getRedisClient=t,this.#logger=n,this.#redisClientConfig=r,this.#errorMappingFn=i}#generateCacheKey({url:e,payload:t,method:n,context:i}){let a=20;if(!i?.accountSecureId||i.accountSecureId.length<a||!e||!n)return null;let o=t?r(t):``;return`${i.accountSecureId}-${n.toUpperCase()}${o}-${e}`}async#getCachedResponse({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#redisClient||!r||r<=0)return null;let a=this.#generateCacheKey({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#redisClient.getData(a);return o?(this.#logger?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#logger?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#cacheResponse({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#redisClient||!r||r<=0)return!1;let o=this.#generateCacheKey({url:e,payload:t,method:n,context:i});return o?(this.#logger?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#redisClient.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:s,context:c,traceId:l,payload:d,httpsAgent:f,httpAgent:p,requestConfig:m,httpsAgentConfig:h}){try{u(this.#redisClientConfig)&&o(this.#redisClient)&&(this.#redisClient=await this.#getRedisClient(this.#redisClientConfig,this.#logger,`HttpClient`));let g=this.#buildUrlWithQueryParams(t,r),_=this.#normalizeHeaders(e),v=this.#getSafePayload(d,e),y=await this.#getCachedResponse({url:g,payload:v,method:n,cacheTTL:s,context:c});if(y)return{...y,responseTime:new Date};let b=pt.getInstance(),x=u(l)?await b.get(l):null,S=x?.signal,ee=await this.#transportFactory({redisClientConfig:this.#redisClientConfig,logger:this.#logger,context:c,requestConfig:m,httpsAgentConfig:h}),C=await ee.request({headers:_,url:g,method:n,maxRedirects:i,responseType:a,data:v,httpsAgent:f,httpAgent:p,signal:S}),w={data:C.data,status:C.status,body:v,method:n,headers:this.#extractAxiosHeaders(C.headers),requestUrl:t,responseType:C?.config?.responseType,responseTime:new Date};return await this.#cacheResponse({url:g,payload:v,method:n,cacheTTL:s,context:c,response:w}),w}catch(e){let r=e;r.url=b(t),this.#logger?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#mapErrorToHttpException(r);throw u(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#normalizeHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#extractAxiosHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#isFormUrlEncoded(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#getSafePayload(e,t){if(!(o(e)||c(e)&&Object.keys(e).length===0))return this.#isFormUrlEncoded(t)?x.stringify(e):e}#mapErrorToHttpException(e){if(h(e)&&this.#errorMappingFn)return this.#errorMappingFn(e)}#buildUrlWithQueryParams(e,t){if(o(t)||Object.keys(t).length===0)return e;let n=x.stringify(t);return`${e}?${n}`}};const Ho=(e,t,n)=>new Vo({redisClientConfig:e,logger:t,errorMappingFn:n});var Uo=class{static httpClientInstance=null;static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Ho}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Wo=[`get`,`post`,`put`,`delete`,`patch`],Go={[Le.rPush]:`
132
132
  local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
133
133
 
134
134
  redis.call('PEXPIRE', KEYS[1], ARGV[2])
135
135
 
136
136
  return queueLength
137
- `,[Ie.lPush]:`
137
+ `,[Le.lPush]:`
138
138
  local queueLength = redis.call('LPUSH', KEYS[1], ARGV[1])
139
139
 
140
140
  redis.call('PEXPIRE', KEYS[1], ARGV[2])
141
141
 
142
142
  return queueLength
143
- `,[Ie.lPop]:`
143
+ `,[Le.lPop]:`
144
144
  local queueKey = KEYS[1]
145
145
 
146
146
  return redis.call("lpop", queueKey)
147
- `,[Ie.llen]:`return redis.call("llen", KEYS[1])`},Ko={[_t.incr]:`
147
+ `,[Le.llen]:`return redis.call("llen", KEYS[1])`},Ko={[vt.incr]:`
148
148
  local targetKey = KEYS[1]
149
149
  local totalLimit = tonumber(ARGV[1])
150
150
 
@@ -186,4 +186,4 @@ var Rr=9e15,zr=1e9,Br=`0123456789abcdef`,Vr=`2.302585092994045684017991454684364
186
186
  end
187
187
 
188
188
  return nil
189
- `},qo=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let[e,i,a]=await Promise.all([$.prepare(rt,{redisClientConfig:t,scripts:nt,logger:n,additionalArgs:r?[r]:void 0}),$.prepare(Le,{redisClientConfig:t,scripts:Go,logger:n}),$.prepare(Fo,{redisClientConfig:t,scripts:Ko,logger:n})]),o=[{name:`ConcurrencyManager`,ready:e.isReady()},{name:`QueueManager`,ready:i.isReady()},{name:`RateLimitManager`,ready:a.isReady()}],s=o.filter(e=>!e.ready);if(s.length>0){let e=s.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:o.map(e=>e.name)}}),{concurrencyManager:e,queueManager:i,rateLimitManager:a}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=$.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},Jo=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=$.getIfReady(rt),n=$.getIfReady(Le),r=$.getIfReady(Fo);t?.close(),n?.close(),r?.close(),$.reset(rt),$.reset(Le),$.reset(Fo),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},Yo=()=>{let e=$.getIfReady(rt),t=$.getIfReady(Le),n=$.getIfReady(Fo);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},Xo=()=>{let e=$.getIfReady(rt),t=$.getIfReady(Le),n=$.getIfReady(Fo);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},Zo=e=>e.reduce((e,t)=>(Array.isArray(e[t.in][t.name])?e[t.in][t.name]=e[t.in][t.name].concat(t.value):typeof e[t.in][t.name]==`object`&&typeof t.value==`object`?e[t.in][t.name]={...e[t.in][t.name],...t.value}:e[t.in][t.name]=t.in===`body`?t.value:String(t.value),e),{query:{},body:{},headers:{}}),Qo=[`query`,`body`,`headers`],$o=(e,t)=>{if(o(t)||t?.length===0||o(e))return{data:e.data,status:e.status,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,message:e.message};let n=t?.filter(t=>t.receivedStatus===e.status);if(n?.length)for(let t of n){let n=t.condition,r=S(n,e)===!0;if(o(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??at[t.targetStatus]??`Unknown error`}}return e},es=e=>u(e)&&e>=200&&e<=299,ts=e=>u(e)&&e>=400&&e<=599,ns=e=>u(e)&&e>=100&&e<=199;var rs=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;try{l=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:a,requestConfig:c})}catch(e){if(o(e?.response))throw e;l=e.response}let u=$o(l,s);if(ts(u?.status))throw new ot(u,u.message);return u}},os=class{static build(e=`rest`){if(e===`rest`)return new rs;throw Error(`Unknown request client type: ${e}`)}};export{it as CUSTOM_ERROR_CONFIG_SCHEMA,rt as ConcurrencyManager,ye as EventClient,Vo as HttpClient,Uo as HttpClientManager,at as HttpErrorMessages,Wo as HttpMethods,ot as HttpResponseError,ut as HttpTransportFactory,ft as InstanceManager,ie as LockManager,he as MemoryStore,Le as QueueManager,Fo as RateLimitManager,Se as RedisClient,os as RequestClientFactory,Qo as RequestParameterLocations,Ee as ScriptManager,De as SubscriptionManager,Ho as buildHttpClientInstance,A as createAuthorizationHeaders,Lo as getTransportInstance,Xo as getTransportManagers,qo as initializeTransportSystem,ts as isFailedStatusCode,ns as isInfoStatusCode,es as isSuccessStatusCode,Yo as isTransportSystemReady,Zo as parseRequestParameters,lt as serializeHttpResponseError,Jo as shutdownTransportSystem};
189
+ `},qo=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let[e,i,a]=await Promise.all([$.prepare(it,{redisClientConfig:t,scripts:rt,logger:n,additionalArgs:r?[r]:void 0}),$.prepare(Re,{redisClientConfig:t,scripts:Go,logger:n}),$.prepare(Fo,{redisClientConfig:t,scripts:Ko,logger:n})]),o=[{name:`ConcurrencyManager`,ready:e.isReady()},{name:`QueueManager`,ready:i.isReady()},{name:`RateLimitManager`,ready:a.isReady()}],s=o.filter(e=>!e.ready);if(s.length>0){let e=s.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:o.map(e=>e.name)}}),{concurrencyManager:e,queueManager:i,rateLimitManager:a}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=$.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},Jo=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=$.getIfReady(it),n=$.getIfReady(Re),r=$.getIfReady(Fo);t?.close(),n?.close(),r?.close(),$.reset(it),$.reset(Re),$.reset(Fo),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},Yo=()=>{let e=$.getIfReady(it),t=$.getIfReady(Re),n=$.getIfReady(Fo);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},Xo=()=>{let e=$.getIfReady(it),t=$.getIfReady(Re),n=$.getIfReady(Fo);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},Zo=e=>e.reduce((e,t)=>(Array.isArray(e[t.in][t.name])?e[t.in][t.name]=e[t.in][t.name].concat(t.value):typeof e[t.in][t.name]==`object`&&typeof t.value==`object`?e[t.in][t.name]={...e[t.in][t.name],...t.value}:e[t.in][t.name]=t.in===`body`?t.value:String(t.value),e),{query:{},body:{},headers:{}}),Qo=[`query`,`body`,`headers`],$o=(e,t)=>{if(o(t)||t?.length===0||o(e))return{data:e.data,status:e.status,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,message:e.message};let n=t?.filter(t=>t.receivedStatus===e.status);if(n?.length)for(let t of n){let n=t.condition,r=S(n,e)===!0;if(o(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??ot[t.targetStatus]??`Unknown error`}}return e},es=e=>u(e)&&e>=200&&e<=299,ts=e=>u(e)&&e>=400&&e<=599,ns=e=>u(e)&&e>=100&&e<=199;var rs=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;try{l=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:a,requestConfig:c})}catch(e){if(o(e?.response))throw e;l=e.response}let u=$o(l,s);if(ts(u?.status))throw new st(u,u.message);return u}},os=class{static build(e=`rest`){if(e===`rest`)return new rs;throw Error(`Unknown request client type: ${e}`)}};export{at as CUSTOM_ERROR_CONFIG_SCHEMA,it as ConcurrencyManager,be as EventClient,Vo as HttpClient,Uo as HttpClientManager,ot as HttpErrorMessages,Wo as HttpMethods,st as HttpResponseError,dt as HttpTransportFactory,pt as InstanceManager,ae as LockManager,ge as MemoryStore,Re as QueueManager,Fo as RateLimitManager,Ce as RedisClient,os as RequestClientFactory,Qo as RequestParameterLocations,De as ScriptManager,Oe as SubscriptionManager,Ho as buildHttpClientInstance,k as createAuthorizationHeaders,Lo as getTransportInstance,Xo as getTransportManagers,qo as initializeTransportSystem,ts as isFailedStatusCode,ns as isInfoStatusCode,es as isSuccessStatusCode,Yo as isTransportSystemReady,Zo as parseRequestParameters,ut as serializeHttpResponseError,Jo as shutdownTransportSystem};