@guihz/trading-vue-editor-tes 0.0.105 → 0.0.107

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,7 @@ Example:
51
51
  * Dual licensed under the MIT or GPL Version 2 licenses.
52
52
  **/(function(s,e){(function(t){var r=2e3,n={s:1,n:0,d:1};function i(m,w){if(isNaN(m=parseInt(m,10)))throw _();return m*w}function a(m,w){if(w===0)throw x();var D=Object.create(v.prototype);D.s=m<0?-1:1,m=m<0?-m:m;var C=p(m,w);return D.n=m/C,D.d=w/C,D}function u(m){for(var w={},D=m,C=2,b=4;b<=D;){for(;D%C===0;)D/=C,w[C]=(w[C]||0)+1;b+=1+2*C++}return D!==m?D>1&&(w[D]=(w[D]||0)+1):w[m]=(w[m]||0)+1,w}var f=function(m,w){var D=0,C=1,b=1,F=0,B=0,M=0,O=1,A=1,N=0,T=1,R=1,k=1,z=1e7,L;if(m!=null)if(w!==void 0){if(D=m,C=w,b=D*C,D%1!==0||C%1!==0)throw y()}else switch(typeof m){case"object":{if("d"in m&&"n"in m)D=m.n,C=m.d,"s"in m&&(D*=m.s);else if(0 in m)D=m[0],1 in m&&(C=m[1]);else throw _();b=D*C;break}case"number":{if(m<0&&(b=m,m=-m),m%1===0)D=m;else if(m>0){for(m>=1&&(A=Math.pow(10,Math.floor(1+Math.log(m)/Math.LN10)),m/=A);T<=z&&k<=z;)if(L=(N+R)/(T+k),m===L){T+k<=z?(D=N+R,C=T+k):k>T?(D=R,C=k):(D=N,C=T);break}else m>L?(N+=R,T+=k):(R+=N,k+=T),T>z?(D=R,C=k):(D=N,C=T);D*=A}else(isNaN(m)||isNaN(w))&&(C=D=NaN);break}case"string":{if(T=m.match(/\d+|./g),T===null)throw _();if(T[N]==="-"?(b=-1,N++):T[N]==="+"&&N++,T.length===N+1?B=i(T[N++],b):T[N+1]==="."||T[N]==="."?(T[N]!=="."&&(F=i(T[N++],b)),N++,(N+1===T.length||T[N+1]==="("&&T[N+3]===")"||T[N+1]==="'"&&T[N+3]==="'")&&(B=i(T[N],b),O=Math.pow(10,T[N].length),N++),(T[N]==="("&&T[N+2]===")"||T[N]==="'"&&T[N+2]==="'")&&(M=i(T[N+1],b),A=Math.pow(10,T[N+1].length)-1,N+=3)):T[N+1]==="/"||T[N+1]===":"?(B=i(T[N],b),O=i(T[N+2],1),N+=3):T[N+3]==="/"&&T[N+1]===" "&&(F=i(T[N],b),B=i(T[N+2],b),O=i(T[N+4],1),N+=5),T.length<=N){C=O*A,b=D=M+C*F+A*B;break}}default:throw _()}if(C===0)throw x();n.s=b<0?-1:1,n.n=Math.abs(D),n.d=Math.abs(C)};function c(m,w,D){for(var C=1;w>0;m=m*m%D,w>>=1)w&1&&(C=C*m%D);return C}function h(m,w){for(;w%2===0;w/=2);for(;w%5===0;w/=5);if(w===1)return 0;for(var D=10%w,C=1;D!==1;C++)if(D=D*10%w,C>r)return 0;return C}function d(m,w,D){for(var C=1,b=c(10,D,w),F=0;F<300;F++){if(C===b)return F;C=C*10%w,b=b*10%w}return 0}function p(m,w){if(!m)return w;if(!w)return m;for(;;){if(m%=w,!m)return w;if(w%=m,!w)return m}}function v(m,w){if(f(m,w),this instanceof v)m=p(n.d,n.n),this.s=n.s,this.n=n.n/m,this.d=n.d/m;else return a(n.s*n.n,n.d)}var x=function(){return new Error("Division by Zero")},_=function(){return new Error("Invalid argument")},y=function(){return new Error("Parameters must be integer")};v.prototype={s:1,n:0,d:1,abs:function(){return a(this.n,this.d)},neg:function(){return a(-this.s*this.n,this.d)},add:function(m,w){return f(m,w),a(this.s*this.n*n.d+n.s*this.d*n.n,this.d*n.d)},sub:function(m,w){return f(m,w),a(this.s*this.n*n.d-n.s*this.d*n.n,this.d*n.d)},mul:function(m,w){return f(m,w),a(this.s*n.s*this.n*n.n,this.d*n.d)},div:function(m,w){return f(m,w),a(this.s*n.s*this.n*n.d,this.d*n.n)},clone:function(){return a(this.s*this.n,this.d)},mod:function(m,w){if(isNaN(this.n)||isNaN(this.d))return new v(NaN);if(m===void 0)return a(this.s*this.n%this.d,1);if(f(m,w),n.n===0&&this.d===0)throw x();return a(this.s*(n.d*this.n)%(n.n*this.d),n.d*this.d)},gcd:function(m,w){return f(m,w),a(p(n.n,this.n)*p(n.d,this.d),n.d*this.d)},lcm:function(m,w){return f(m,w),n.n===0&&this.n===0?a(0,1):a(n.n*this.n,p(n.n,this.n)*p(n.d,this.d))},ceil:function(m){return m=Math.pow(10,m||0),isNaN(this.n)||isNaN(this.d)?new v(NaN):a(Math.ceil(m*this.s*this.n/this.d),m)},floor:function(m){return m=Math.pow(10,m||0),isNaN(this.n)||isNaN(this.d)?new v(NaN):a(Math.floor(m*this.s*this.n/this.d),m)},round:function(m){return m=Math.pow(10,m||0),isNaN(this.n)||isNaN(this.d)?new v(NaN):a(Math.round(m*this.s*this.n/this.d),m)},inverse:function(){return a(this.s*this.d,this.n)},pow:function(m,w){if(f(m,w),n.d===1)return n.s<0?a(Math.pow(this.s*this.d,n.n),Math.pow(this.n,n.n)):a(Math.pow(this.s*this.n,n.n),Math.pow(this.d,n.n));if(this.s<0)return null;var D=u(this.n),C=u(this.d),b=1,F=1;for(var B in D)if(B!=="1"){if(B==="0"){b=0;break}if(D[B]*=n.n,D[B]%n.d===0)D[B]/=n.d;else return null;b*=Math.pow(B,D[B])}for(var B in C)if(B!=="1"){if(C[B]*=n.n,C[B]%n.d===0)C[B]/=n.d;else return null;F*=Math.pow(B,C[B])}return n.s<0?a(F,b):a(b,F)},equals:function(m,w){return f(m,w),this.s*this.n*n.d===n.s*n.n*this.d},compare:function(m,w){f(m,w);var D=this.s*this.n*n.d-n.s*n.n*this.d;return(0<D)-(D<0)},simplify:function(m){if(isNaN(this.n)||isNaN(this.d))return this;m=m||.001;for(var w=this.abs(),D=w.toContinued(),C=1;C<D.length;C++){for(var b=a(D[C-1],1),F=C-2;F>=0;F--)b=b.inverse().add(D[F]);if(Math.abs(b.sub(w).valueOf())<m)return b.mul(this.s)}return this},divisible:function(m,w){return f(m,w),!(!(n.n*this.d)||this.n*n.d%(n.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(m){var w,D="",C=this.n,b=this.d;return this.s<0&&(D+="-"),b===1?D+=C:(m&&(w=Math.floor(C/b))>0&&(D+=w,D+=" ",C%=b),D+=C,D+="/",D+=b),D},toLatex:function(m){var w,D="",C=this.n,b=this.d;return this.s<0&&(D+="-"),b===1?D+=C:(m&&(w=Math.floor(C/b))>0&&(D+=w,C%=b),D+="\\frac{",D+=C,D+="}{",D+=b,D+="}"),D},toContinued:function(){var m,w=this.n,D=this.d,C=[];if(isNaN(w)||isNaN(D))return C;do C.push(Math.floor(w/D)),m=w%D,w=D,D=m;while(w!==1);return C},toString:function(m){var w=this.n,D=this.d;if(isNaN(w)||isNaN(D))return"NaN";m=m||15;var C=h(w,D),b=d(w,D,C),F=this.s<0?"-":"";if(F+=w/D|0,w%=D,w*=10,w&&(F+="."),C){for(var B=b;B--;)F+=w/D|0,w%=D,w*=10;F+="(";for(var B=C;B--;)F+=w/D|0,w%=D,w*=10;F+=")"}else for(var B=m;w&&B--;)F+=w/D|0,w%=D,w*=10;return F}},Object.defineProperty(v,"__esModule",{value:!0}),v.default=v,v.Fraction=v,s.exports=v})()})(dc);var Cv=dc.exports,mn=tt(Cv),Fv="Fraction",Bv=[],Mv=xe(Fv,Bv,()=>(Object.defineProperty(mn,"name",{value:"Fraction"}),mn.prototype.constructor=mn,mn.prototype.type="Fraction",mn.prototype.isFraction=!0,mn.prototype.toJSON=function(){return{mathjs:"Fraction",n:this.s*this.n,d:this.d}},mn.fromJSON=function(s){return new mn(s)},mn),{isClass:!0}),Nv="Matrix",Sv=[],Ov=xe(Nv,Sv,()=>{function s(){if(!(this instanceof s))throw new SyntaxError("Constructor must be called with the new operator")}return s.prototype.type="Matrix",s.prototype.isMatrix=!0,s.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},s.prototype.datatype=function(){throw new Error("Cannot invoke datatype on a Matrix interface")},s.prototype.create=function(e,t){throw new Error("Cannot invoke create on a Matrix interface")},s.prototype.subset=function(e,t,r){throw new Error("Cannot invoke subset on a Matrix interface")},s.prototype.get=function(e){throw new Error("Cannot invoke get on a Matrix interface")},s.prototype.set=function(e,t,r){throw new Error("Cannot invoke set on a Matrix interface")},s.prototype.resize=function(e,t){throw new Error("Cannot invoke resize on a Matrix interface")},s.prototype.reshape=function(e,t){throw new Error("Cannot invoke reshape on a Matrix interface")},s.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},s.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},s.prototype.map=function(e,t){throw new Error("Cannot invoke map on a Matrix interface")},s.prototype.forEach=function(e){throw new Error("Cannot invoke forEach on a Matrix interface")},s.prototype[Symbol.iterator]=function(){throw new Error("Cannot iterate a Matrix interface")},s.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},s.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},s.prototype.format=function(e){throw new Error("Cannot invoke format on a Matrix interface")},s.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},s},{isClass:!0});function pc(s){return Object.keys(s.signatures||{}).reduce(function(e,t){var r=(t.match(/,/g)||[]).length+1;return Math.max(e,r)},-1)}var Tv="DenseMatrix",Iv=["Matrix"],$v=xe(Tv,Iv,s=>{var{Matrix:e}=s;function t(h,d){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(d&&!un(d))throw new Error("Invalid datatype: "+d);if(mt(h))h.type==="DenseMatrix"?(this._data=ut(h._data),this._size=ut(h._size),this._datatype=d||h._datatype):(this._data=h.toArray(),this._size=h.size(),this._datatype=d||h._datatype);else if(h&&Ct(h.data)&&Ct(h.size))this._data=h.data,this._size=h.size,Ul(this._data,this._size),this._datatype=d||h.datatype;else if(Ct(h))this._data=c(h),this._size=Lt(this._data),Ul(this._data,this._size),this._datatype=d;else{if(h)throw new TypeError("Unsupported type of data ("+Sn(h)+")");this._data=[],this._size=[0],this._datatype=d}}t.prototype=new e,t.prototype.createDenseMatrix=function(h,d){return new t(h,d)},Object.defineProperty(t,"name",{value:"DenseMatrix"}),t.prototype.constructor=t,t.prototype.type="DenseMatrix",t.prototype.isDenseMatrix=!0,t.prototype.getDataType=function(){return Ys(this._data,Sn)},t.prototype.storage=function(){return"dense"},t.prototype.datatype=function(){return this._datatype},t.prototype.create=function(h,d){return new t(h,d)},t.prototype.subset=function(h,d,p){switch(arguments.length){case 1:return r(this,h);case 2:case 3:return i(this,h,d,p);default:throw new SyntaxError("Wrong number of arguments")}},t.prototype.get=function(h){if(!Ct(h))throw new TypeError("Array expected");if(h.length!==this._size.length)throw new rt(h.length,this._size.length);for(var d=0;d<h.length;d++)Ft(h[d],this._size[d]);for(var p=this._data,v=0,x=h.length;v<x;v++){var _=h[v];Ft(_,p.length),p=p[_]}return p},t.prototype.set=function(h,d,p){if(!Ct(h))throw new TypeError("Array expected");if(h.length<this._size.length)throw new rt(h.length,this._size.length,"<");var v,x,_,y=h.map(function(w){return w+1});f(this,y,p);var m=this._data;for(v=0,x=h.length-1;v<x;v++)_=h[v],Ft(_,m.length),m=m[_];return _=h[h.length-1],Ft(_,m.length),m[_]=d,this};function r(h,d){if(!Aa(d))throw new TypeError("Invalid index");var p=d.isScalar();if(p)return h.get(d.min());var v=d.size();if(v.length!==h._size.length)throw new rt(v.length,h._size.length);for(var x=d.min(),_=d.max(),y=0,m=h._size.length;y<m;y++)Ft(x[y],h._size[y]),Ft(_[y],h._size[y]);return new t(n(h._data,d,v.length,0),h._datatype)}function n(h,d,p,v){var x=v===p-1,_=d.dimension(v);return x?_.map(function(y){return Ft(y,h.length),h[y]}).valueOf():_.map(function(y){Ft(y,h.length);var m=h[y];return n(m,d,p,v+1)}).valueOf()}function i(h,d,p,v){if(!d||d.isIndex!==!0)throw new TypeError("Invalid index");var x=d.size(),_=d.isScalar(),y;if(mt(p)?(y=p.size(),p=p.valueOf()):y=Lt(p),_){if(y.length!==0)throw new TypeError("Scalar expected");h.set(d.min(),p,v)}else{if(!yi(y,x))try{y.length===0?p=Vl([p],x):p=Vl(p,x),y=Lt(p)}catch{}if(x.length<h._size.length)throw new rt(x.length,h._size.length,"<");if(y.length<x.length){for(var m=0,w=0;x[m]===1&&y[m]===1;)m++;for(;x[m]===1;)w++,m++;p=Hl(p,x.length,w,y)}if(!yi(x,y))throw new rt(x,y,">");var D=d.max().map(function(F){return F+1});f(h,D,v);var C=x.length,b=0;a(h._data,d,p,C,b)}return h}function a(h,d,p,v,x){var _=x===v-1,y=d.dimension(x);_?y.forEach(function(m,w){Ft(m),h[m]=p[w[0]]}):y.forEach(function(m,w){Ft(m),a(h[m],d,p[w[0]],v,x+1)})}t.prototype.resize=function(h,d,p){if(!is(h))throw new TypeError("Array or Matrix expected");var v=h.valueOf().map(_=>Array.isArray(_)&&_.length===1?_[0]:_),x=p?this.clone():this;return u(x,v,d)};function u(h,d,p){if(d.length===0){for(var v=h._data;Ct(v);)v=v[0];return v}return h._size=d.slice(0),h._data=Na(h._data,h._size,p),h}t.prototype.reshape=function(h,d){var p=d?this.clone():this;p._data=Oa(p._data,h);var v=p._size.reduce((x,_)=>x*_);return p._size=Ta(h,v),p};function f(h,d,p){for(var v=h._size.slice(0),x=!1;v.length<d.length;)v.push(0),x=!0;for(var _=0,y=d.length;_<y;_++)d[_]>v[_]&&(v[_]=d[_],x=!0);x&&u(h,v,p)}t.prototype.clone=function(){var h=new t({data:ut(this._data),size:ut(this._size),datatype:this._datatype});return h},t.prototype.size=function(){return this._size.slice(0)},t.prototype.map=function(h){var d=this,p=pc(h),v=function y(m,w){return Ct(m)?m.map(function(D,C){return y(D,w.concat(C))}):p===1?h(m):p===2?h(m,w):h(m,w,d)},x=v(this._data,[]),_=this._datatype!==void 0?Ys(x,Sn):void 0;return new t(x,_)},t.prototype.forEach=function(h){var d=this,p=function v(x,_){Ct(x)?x.forEach(function(y,m){v(y,_.concat(m))}):h(x,_,d)};p(this._data,[])},t.prototype[Symbol.iterator]=function*(){var h=function*d(p,v){if(Ct(p))for(var x=0;x<p.length;x++)yield*d(p[x],v.concat(x));else yield{value:p,index:v}};yield*h(this._data,[])},t.prototype.rows=function(){var h=[],d=this.size();if(d.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");var p=this._data;for(var v of p)h.push(new t([v],this._datatype));return h},t.prototype.columns=function(){var h=this,d=[],p=this.size();if(p.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");for(var v=this._data,x=function(m){var w=v.map(D=>[D[m]]);d.push(new t(w,h._datatype))},_=0;_<p[1];_++)x(_);return d},t.prototype.toArray=function(){return ut(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.format=function(h){return ct(this._data,h)},t.prototype.toString=function(){return ct(this._data)},t.prototype.toJSON=function(){return{mathjs:"DenseMatrix",data:this._data,size:this._size,datatype:this._datatype}},t.prototype.diagonal=function(h){if(h){if(St(h)&&(h=h.toNumber()),!pt(h)||!bt(h))throw new TypeError("The parameter k must be an integer number")}else h=0;for(var d=h>0?h:0,p=h<0?-h:0,v=this._size[0],x=this._size[1],_=Math.min(v-p,x-d),y=[],m=0;m<_;m++)y[m]=this._data[m+p][m+d];return new t({data:y,size:[_],datatype:this._datatype})},t.diagonal=function(h,d,p,v){if(!Ct(h))throw new TypeError("Array expected, size parameter");if(h.length!==2)throw new Error("Only two dimensions matrix are supported");if(h=h.map(function(B){if(St(B)&&(B=B.toNumber()),!pt(B)||!bt(B)||B<1)throw new Error("Size values must be positive integers");return B}),p){if(St(p)&&(p=p.toNumber()),!pt(p)||!bt(p))throw new TypeError("The parameter k must be an integer number")}else p=0;var x=p>0?p:0,_=p<0?-p:0,y=h[0],m=h[1],w=Math.min(y-_,m-x),D;if(Ct(d)){if(d.length!==w)throw new Error("Invalid value array length");D=function(M){return d[M]}}else if(mt(d)){var C=d.size();if(C.length!==1||C[0]!==w)throw new Error("Invalid matrix length");D=function(M){return d.get([M])}}else D=function(){return d};v||(v=St(D(0))?D(0).mul(0):0);var b=[];if(h.length>0){b=Na(b,h,v);for(var F=0;F<w;F++)b[F+_][F+x]=D(F)}return new t({data:b,size:[y,m]})},t.fromJSON=function(h){return new t(h)},t.prototype.swapRows=function(h,d){if(!pt(h)||!bt(h)||!pt(d)||!bt(d))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Ft(h,this._size[0]),Ft(d,this._size[0]),t._swapRows(h,d,this._data),this},t._swapRows=function(h,d,p){var v=p[h];p[h]=p[d],p[d]=v};function c(h){return mt(h)?c(h.valueOf()):Ct(h)?h.map(c):h}return t},{isClass:!0});function Rv(s){var e=s.length,t=s[0].length,r,n,i=[];for(n=0;n<t;n++){var a=[];for(r=0;r<e;r++)a.push(s[r][n]);i.push(a)}return i}function ro(s){for(var e=0;e<s.length;e++)if(is(s[e]))return!0;return!1}function as(s,e){mt(s)&&(s=s.valueOf());for(var t=0,r=s.length;t<r;t++){var n=s[t];Array.isArray(n)?as(n,e):e(n)}}function Jr(s,e,t){return s&&typeof s.map=="function"?s.map(function(r){return Jr(r,e)}):e(s)}function Wa(s,e,t){var r=Array.isArray(s)?Lt(s):s.size();if(e<0||e>=r.length)throw new On(e,r.length);return mt(s)?s.create(no(s.valueOf(),e,t)):no(s,e,t)}function no(s,e,t){var r,n,i,a;if(e<=0)if(Array.isArray(s[0])){for(a=Rv(s),n=[],r=0;r<a.length;r++)n[r]=no(a[r],e-1,t);return n}else{for(i=s[0],r=1;r<s.length;r++)i=t(i,s[r]);return i}else{for(n=[],r=0;r<s.length;r++)n[r]=no(s[r],e-1,t);return n}}var _c="isInteger",Lv=["typed"],Pv=xe(_c,Lv,s=>{var{typed:e}=s;return e(_c,{number:bt,BigNumber:function(r){return r.isInt()},Fraction:function(r){return r.d===1&&isFinite(r.n)},"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),vc="number",io="number, number";function gc(s){return Math.abs(s)}gc.signature=vc;function mc(s,e){return s+e}mc.signature=io;function xc(s,e){return s-e}xc.signature=io;function yc(s,e){return s*e}yc.signature=io;function Dc(s){return-s}Dc.signature=vc;function wc(s,e){return s*s<1&&e===1/0||s*s>1&&e===-1/0?0:Math.pow(s,e)}wc.signature=io;var bc="number";function Ec(s){return s===0}Ec.signature=bc;function Ac(s){return Number.isNaN(s)}Ac.signature=bc;var Cc="isNumeric",kv=["typed"],zv=xe(Cc,kv,s=>{var{typed:e}=s;return e(Cc,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Fc="isZero",qv=["typed"],Uv=xe(Fc,qv,s=>{var{typed:e}=s;return e(Fc,{number:Ec,BigNumber:function(r){return r.isZero()},Complex:function(r){return r.re===0&&r.im===0},Fraction:function(r){return r.d===1&&r.n===0},Unit:e.referToSelf(t=>r=>e.find(t,r.valueType())(r.value)),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Bc="isNaN",Wv=["typed"],Hv=xe(Bc,Wv,s=>{var{typed:e}=s;return e(Bc,{number:Ac,BigNumber:function(r){return r.isNaN()},Fraction:function(r){return!1},Complex:function(r){return r.isNaN()},Unit:function(r){return Number.isNaN(r.value)},"Array | Matrix":function(r){return Jr(r,Number.isNaN)}})});function so(s,e,t){if(t==null)return s.eq(e);if(s.eq(e))return!0;if(s.isNaN()||e.isNaN())return!1;if(s.isFinite()&&e.isFinite()){var r=s.minus(e).abs();if(r.isZero())return!0;var n=s.constructor.max(s.abs(),e.abs());return r.lte(n.times(t))}return!1}function jv(s,e,t){return ti(s.re,e.re,t)&&ti(s.im,e.im,t)}var oo=xe("compareUnits",["typed"],s=>{var{typed:e}=s;return{"Unit, Unit":e.referToSelf(t=>(r,n)=>{if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return e.find(t,[r.valueType(),n.valueType()])(r.value,n.value)})}}),ao="equalScalar",Yv=["typed","config"],Zv=xe(ao,Yv,s=>{var{typed:e,config:t}=s,r=oo({typed:e});return e(ao,{"boolean, boolean":function(i,a){return i===a},"number, number":function(i,a){return ti(i,a,t.epsilon)},"BigNumber, BigNumber":function(i,a){return i.eq(a)||so(i,a,t.epsilon)},"Fraction, Fraction":function(i,a){return i.equals(a)},"Complex, Complex":function(i,a){return jv(i,a,t.epsilon)}},r)});xe(ao,["typed","config"],s=>{var{typed:e,config:t}=s;return e(ao,{"number, number":function(n,i){return ti(n,i,t.epsilon)}})});var Vv="SparseMatrix",Gv=["typed","equalScalar","Matrix"],Kv=xe(Vv,Gv,s=>{var{typed:e,equalScalar:t,Matrix:r}=s;function n(_,y){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(y&&!un(y))throw new Error("Invalid datatype: "+y);if(mt(_))i(this,_,y);else if(_&&Ct(_.index)&&Ct(_.ptr)&&Ct(_.size))this._values=_.values,this._index=_.index,this._ptr=_.ptr,this._size=_.size,this._datatype=y||_.datatype;else if(Ct(_))a(this,_,y);else{if(_)throw new TypeError("Unsupported type of data ("+Sn(_)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=y}}function i(_,y,m){y.type==="SparseMatrix"?(_._values=y._values?ut(y._values):void 0,_._index=ut(y._index),_._ptr=ut(y._ptr),_._size=ut(y._size),_._datatype=m||y._datatype):a(_,y.valueOf(),m||y._datatype)}function a(_,y,m){_._values=[],_._index=[],_._ptr=[],_._datatype=m;var w=y.length,D=0,C=t,b=0;if(un(m)&&(C=e.find(t,[m,m])||t,b=e.convert(0,m)),w>0){var F=0;do{_._ptr.push(_._index.length);for(var B=0;B<w;B++){var M=y[B];if(Ct(M)){if(F===0&&D<M.length&&(D=M.length),F<M.length){var O=M[F];C(O,b)||(_._values.push(O),_._index.push(B))}}else F===0&&D<1&&(D=1),C(M,b)||(_._values.push(M),_._index.push(B))}F++}while(F<D)}_._ptr.push(_._index.length),_._size=[w,D]}n.prototype=new r,n.prototype.createSparseMatrix=function(_,y){return new n(_,y)},Object.defineProperty(n,"name",{value:"SparseMatrix"}),n.prototype.constructor=n,n.prototype.type="SparseMatrix",n.prototype.isSparseMatrix=!0,n.prototype.getDataType=function(){return Ys(this._values,Sn)},n.prototype.storage=function(){return"sparse"},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(_,y){return new n(_,y)},n.prototype.density=function(){var _=this._size[0],y=this._size[1];return _!==0&&y!==0?this._index.length/(_*y):0},n.prototype.subset=function(_,y,m){if(!this._values)throw new Error("Cannot invoke subset on a Pattern only matrix");switch(arguments.length){case 1:return u(this,_);case 2:case 3:return f(this,_,y,m);default:throw new SyntaxError("Wrong number of arguments")}};function u(_,y){if(!Aa(y))throw new TypeError("Invalid index");var m=y.isScalar();if(m)return _.get(y.min());var w=y.size();if(w.length!==_._size.length)throw new rt(w.length,_._size.length);var D,C,b,F,B=y.min(),M=y.max();for(D=0,C=_._size.length;D<C;D++)Ft(B[D],_._size[D]),Ft(M[D],_._size[D]);var O=_._values,A=_._index,N=_._ptr,T=y.dimension(0),R=y.dimension(1),k=[],z=[];T.forEach(function(ee,te){z[ee]=te[0],k[ee]=!0});var L=O?[]:void 0,G=[],H=[];return R.forEach(function(ee){for(H.push(G.length),b=N[ee],F=N[ee+1];b<F;b++)D=A[b],k[D]===!0&&(G.push(z[D]),L&&L.push(O[b]))}),H.push(G.length),new n({values:L,index:G,ptr:H,size:w,datatype:_._datatype})}function f(_,y,m,w){if(!y||y.isIndex!==!0)throw new TypeError("Invalid index");var D=y.size(),C=y.isScalar(),b;if(mt(m)?(b=m.size(),m=m.toArray()):b=Lt(m),C){if(b.length!==0)throw new TypeError("Scalar expected");_.set(y.min(),m,w)}else{if(D.length!==1&&D.length!==2)throw new rt(D.length,_._size.length,"<");if(b.length<D.length){for(var F=0,B=0;D[F]===1&&b[F]===1;)F++;for(;D[F]===1;)B++,F++;m=Hl(m,D.length,B,b)}if(!yi(D,b))throw new rt(D,b,">");if(D.length===1){var M=y.dimension(0);M.forEach(function(N,T){Ft(N),_.set([N,0],m[T[0]],w)})}else{var O=y.dimension(0),A=y.dimension(1);O.forEach(function(N,T){Ft(N),A.forEach(function(R,k){Ft(R),_.set([N,R],m[T[0]][k[0]],w)})})}}return _}n.prototype.get=function(_){if(!Ct(_))throw new TypeError("Array expected");if(_.length!==this._size.length)throw new rt(_.length,this._size.length);if(!this._values)throw new Error("Cannot invoke get on a Pattern only matrix");var y=_[0],m=_[1];Ft(y,this._size[0]),Ft(m,this._size[1]);var w=c(y,this._ptr[m],this._ptr[m+1],this._index);return w<this._ptr[m+1]&&this._index[w]===y?this._values[w]:0},n.prototype.set=function(_,y,m){if(!Ct(_))throw new TypeError("Array expected");if(_.length!==this._size.length)throw new rt(_.length,this._size.length);if(!this._values)throw new Error("Cannot invoke set on a Pattern only matrix");var w=_[0],D=_[1],C=this._size[0],b=this._size[1],F=t,B=0;un(this._datatype)&&(F=e.find(t,[this._datatype,this._datatype])||t,B=e.convert(0,this._datatype)),(w>C-1||D>b-1)&&(p(this,Math.max(w+1,C),Math.max(D+1,b),m),C=this._size[0],b=this._size[1]),Ft(w,C),Ft(D,b);var M=c(w,this._ptr[D],this._ptr[D+1],this._index);return M<this._ptr[D+1]&&this._index[M]===w?F(y,B)?h(M,D,this._values,this._index,this._ptr):this._values[M]=y:F(y,B)||d(M,w,D,y,this._values,this._index,this._ptr),this};function c(_,y,m,w){if(m-y===0)return m;for(var D=y;D<m;D++)if(w[D]===_)return D;return y}function h(_,y,m,w,D){m.splice(_,1),w.splice(_,1);for(var C=y+1;C<D.length;C++)D[C]--}function d(_,y,m,w,D,C,b){D.splice(_,0,w),C.splice(_,0,y);for(var F=m+1;F<b.length;F++)b[F]++}n.prototype.resize=function(_,y,m){if(!is(_))throw new TypeError("Array or Matrix expected");var w=_.valueOf().map(C=>Array.isArray(C)&&C.length===1?C[0]:C);if(w.length!==2)throw new Error("Only two dimensions matrix are supported");w.forEach(function(C){if(!pt(C)||!bt(C)||C<0)throw new TypeError("Invalid size, must contain positive integers (size: "+ct(w)+")")});var D=m?this.clone():this;return p(D,w[0],w[1],y)};function p(_,y,m,w){var D=w||0,C=t,b=0;un(_._datatype)&&(C=e.find(t,[_._datatype,_._datatype])||t,b=e.convert(0,_._datatype),D=e.convert(D,_._datatype));var F=!C(D,b),B=_._size[0],M=_._size[1],O,A,N;if(m>M){for(A=M;A<m;A++)if(_._ptr[A]=_._values.length,F)for(O=0;O<B;O++)_._values.push(D),_._index.push(O);_._ptr[m]=_._values.length}else m<M&&(_._ptr.splice(m+1,M-m),_._values.splice(_._ptr[m],_._values.length),_._index.splice(_._ptr[m],_._index.length));if(M=m,y>B){if(F){var T=0;for(A=0;A<M;A++){_._ptr[A]=_._ptr[A]+T,N=_._ptr[A+1]+T;var R=0;for(O=B;O<y;O++,R++)_._values.splice(N+R,0,D),_._index.splice(N+R,0,O),T++}_._ptr[M]=_._values.length}}else if(y<B){var k=0;for(A=0;A<M;A++){_._ptr[A]=_._ptr[A]-k;var z=_._ptr[A],L=_._ptr[A+1]-k;for(N=z;N<L;N++)O=_._index[N],O>y-1&&(_._values.splice(N,1),_._index.splice(N,1),k++)}_._ptr[A]=_._values.length}return _._size[0]=y,_._size[1]=m,_}n.prototype.reshape=function(_,y){if(!Ct(_))throw new TypeError("Array expected");if(_.length!==2)throw new Error("Sparse matrices can only be reshaped in two dimensions");_.forEach(function(ee){if(!pt(ee)||!bt(ee)||ee<=-2||ee===0)throw new TypeError("Invalid size, must contain positive integers or -1 (size: "+ct(_)+")")});var m=this._size[0]*this._size[1];_=Ta(_,m);var w=_[0]*_[1];if(m!==w)throw new Error("Reshaping sparse matrix will result in the wrong number of elements");var D=y?this.clone():this;if(this._size[0]===_[0]&&this._size[1]===_[1])return D;for(var C=[],b=0;b<D._ptr.length;b++)for(var F=0;F<D._ptr[b+1]-D._ptr[b];F++)C.push(b);for(var B=D._values.slice(),M=D._index.slice(),O=0;O<D._index.length;O++){var A=M[O],N=C[O],T=A*D._size[1]+N;C[O]=T%_[1],M[O]=Math.floor(T/_[1])}D._values.length=0,D._index.length=0,D._ptr.length=_[1]+1,D._size=_.slice();for(var R=0;R<D._ptr.length;R++)D._ptr[R]=0;for(var k=0;k<B.length;k++){var z=M[k],L=C[k],G=B[k],H=c(z,D._ptr[L],D._ptr[L+1],D._index);d(H,z,L,G,D._values,D._index,D._ptr)}return D},n.prototype.clone=function(){var _=new n({values:this._values?ut(this._values):void 0,index:ut(this._index),ptr:ut(this._ptr),size:ut(this._size),datatype:this._datatype});return _},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(_,y){if(!this._values)throw new Error("Cannot invoke map on a Pattern only matrix");var m=this,w=this._size[0],D=this._size[1],C=pc(_),b=function(B,M,O){return C===1?_(B):C===2?_(B,[M,O]):_(B,[M,O],m)};return v(this,0,w-1,0,D-1,b,y)};function v(_,y,m,w,D,C,b){var F=[],B=[],M=[],O=t,A=0;un(_._datatype)&&(O=e.find(t,[_._datatype,_._datatype])||t,A=e.convert(0,_._datatype));for(var N=function(Y,Q,pe){Y=C(Y,Q,pe),O(Y,A)||(F.push(Y),B.push(Q))},T=w;T<=D;T++){M.push(F.length);var R=_._ptr[T],k=_._ptr[T+1];if(b)for(var z=R;z<k;z++){var L=_._index[z];L>=y&&L<=m&&N(_._values[z],L-y,T-w)}else{for(var G={},H=R;H<k;H++){var ee=_._index[H];G[ee]=_._values[H]}for(var te=y;te<=m;te++){var j=te in G?G[te]:0;N(j,te-y,T-w)}}}return M.push(F.length),new n({values:F,index:B,ptr:M,size:[m-y+1,D-w+1]})}n.prototype.forEach=function(_,y){if(!this._values)throw new Error("Cannot invoke forEach on a Pattern only matrix");for(var m=this,w=this._size[0],D=this._size[1],C=0;C<D;C++){var b=this._ptr[C],F=this._ptr[C+1];if(y)for(var B=b;B<F;B++){var M=this._index[B];_(this._values[B],[M,C],m)}else{for(var O={},A=b;A<F;A++){var N=this._index[A];O[N]=this._values[A]}for(var T=0;T<w;T++){var R=T in O?O[T]:0;_(R,[T,C],m)}}}},n.prototype[Symbol.iterator]=function*(){if(!this._values)throw new Error("Cannot iterate a Pattern only matrix");for(var _=this._size[1],y=0;y<_;y++)for(var m=this._ptr[y],w=this._ptr[y+1],D=m;D<w;D++){var C=this._index[D];yield{value:this._values[D],index:[C,y]}}},n.prototype.toArray=function(){return x(this._values,this._index,this._ptr,this._size,!0)},n.prototype.valueOf=function(){return x(this._values,this._index,this._ptr,this._size,!1)};function x(_,y,m,w,D){var C=w[0],b=w[1],F=[],B,M;for(B=0;B<C;B++)for(F[B]=[],M=0;M<b;M++)F[B][M]=0;for(M=0;M<b;M++)for(var O=m[M],A=m[M+1],N=O;N<A;N++)B=y[N],F[B][M]=_?D?ut(_[N]):_[N]:1;return F}return n.prototype.format=function(_){for(var y=this._size[0],m=this._size[1],w=this.density(),D="Sparse Matrix ["+ct(y,_)+" x "+ct(m,_)+"] density: "+ct(w,_)+`
53
53
  `,C=0;C<m;C++)for(var b=this._ptr[C],F=this._ptr[C+1],B=b;B<F;B++){var M=this._index[B];D+=`
54
- (`+ct(M,_)+", "+ct(C,_)+") ==> "+(this._values?ct(this._values[B],_):"X")}return D},n.prototype.toString=function(){return ct(this.toArray())},n.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(_){if(_){if(St(_)&&(_=_.toNumber()),!pt(_)||!bt(_))throw new TypeError("The parameter k must be an integer number")}else _=0;var y=_>0?_:0,m=_<0?-_:0,w=this._size[0],D=this._size[1],C=Math.min(w-m,D-y),b=[],F=[],B=[];B[0]=0;for(var M=y;M<D&&b.length<C;M++)for(var O=this._ptr[M],A=this._ptr[M+1],N=O;N<A;N++){var T=this._index[N];if(T===M-y+m){b.push(this._values[N]),F[b.length-1]=T-m;break}}return B.push(b.length),new n({values:b,index:F,ptr:B,size:[C,1]})},n.fromJSON=function(_){return new n(_)},n.diagonal=function(_,y,m,w,D){if(!Ct(_))throw new TypeError("Array expected, size parameter");if(_.length!==2)throw new Error("Only two dimensions matrix are supported");if(_=_.map(function(ee){if(St(ee)&&(ee=ee.toNumber()),!pt(ee)||!bt(ee)||ee<1)throw new Error("Size values must be positive integers");return ee}),m){if(St(m)&&(m=m.toNumber()),!pt(m)||!bt(m))throw new TypeError("The parameter k must be an integer number")}else m=0;var C=t,b=0;un(D)&&(C=e.find(t,[D,D])||t,b=e.convert(0,D));var F=m>0?m:0,B=m<0?-m:0,M=_[0],O=_[1],A=Math.min(M-B,O-F),N;if(Ct(y)){if(y.length!==A)throw new Error("Invalid value array length");N=function(te){return y[te]}}else if(mt(y)){var T=y.size();if(T.length!==1||T[0]!==A)throw new Error("Invalid matrix length");N=function(te){return y.get([te])}}else N=function(){return y};for(var R=[],k=[],z=[],L=0;L<O;L++){z.push(R.length);var G=L-F;if(G>=0&&G<A){var H=N(G);C(H,b)||(k.push(G+B),R.push(H))}}return z.push(R.length),new n({values:R,index:k,ptr:z,size:[M,O]})},n.prototype.swapRows=function(_,y){if(!pt(_)||!bt(_)||!pt(y)||!bt(y))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Ft(_,this._size[0]),Ft(y,this._size[0]),n._swapRows(_,y,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(_,y,m,w,D){for(var C=w[_],b=w[_+1],F=C;F<b;F++)D(m[F],y[F])},n._swapRows=function(_,y,m,w,D,C){for(var b=0;b<m;b++){var F=C[b],B=C[b+1],M=c(_,F,B,D),O=c(y,F,B,D);if(M<B&&O<B&&D[M]===_&&D[O]===y){if(w){var A=w[M];w[M]=w[O],w[O]=A}continue}if(M<B&&D[M]===_&&(O>=B||D[O]!==y)){var N=w?w[M]:void 0;D.splice(O,0,y),w&&w.splice(O,0,N),D.splice(O<=M?M+1:M,1),w&&w.splice(O<=M?M+1:M,1);continue}if(O<B&&D[O]===y&&(M>=B||D[M]!==_)){var T=w?w[O]:void 0;D.splice(M,0,_),w&&w.splice(M,0,T),D.splice(M<=O?O+1:O,1),w&&w.splice(M<=O?O+1:O,1)}}},n},{isClass:!0}),Xv="number",Qv=["typed"];function Jv(s){var e=s.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(e){var t={"0b":2,"0o":8,"0x":16}[e[1]],r=e[2],n=e[3];return{input:s,radix:t,integerPart:r,fractionalPart:n}}else return null}function eg(s){for(var e=parseInt(s.integerPart,s.radix),t=0,r=0;r<s.fractionalPart.length;r++){var n=parseInt(s.fractionalPart[r],s.radix);t+=n/Math.pow(s.radix,r+1)}var i=e+t;if(isNaN(i))throw new SyntaxError('String "'+s.input+'" is not a valid number');return i}var tg=xe(Xv,Qv,s=>{var{typed:e}=s,t=e("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var i=Jv(n);if(i)return eg(i);var a=0,u=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);u&&(a=Number(u[2]),n=u[1]);var f=Number(n);if(isNaN(f))throw new SyntaxError('String "'+n+'" is not a valid number');if(u){if(f>2**a-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));f>=2**(a-1)&&(f=f-2**a)}return f},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),null:function(n){return 0},"Unit, string | Unit":function(n,i){return n.toNumber(i)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),rg="bignumber",ng=["typed","BigNumber"],ig=xe(rg,ng,s=>{var{typed:e,BigNumber:t}=s;return e("bignumber",{"":function(){return new t(0)},number:function(n){return new t(n+"")},string:function(n){var i=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(i){var a=i[2],u=t(i[1]),f=new t(2).pow(Number(a));if(u.gt(f.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var c=new t(2).pow(Number(a)-1);return u.gte(c)?u.sub(f):u}return new t(n)},BigNumber:function(n){return n},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),Fraction:function(n){return new t(n.n).div(n.d).times(n.s)},null:function(n){return new t(0)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))})}),sg="fraction",og=["typed","Fraction"],ag=xe(sg,og,s=>{var{typed:e,Fraction:t}=s;return e("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new t(n)},string:function(n){return new t(n)},"number, number":function(n,i){return new t(n,i)},null:function(n){return new t(0)},BigNumber:function(n){return new t(n.toString())},Fraction:function(n){return n},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),Object:function(n){return new t(n)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))})}),Mc="matrix",ug=["typed","Matrix","DenseMatrix","SparseMatrix"],lg=xe(Mc,ug,s=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:n}=s;return e(Mc,{"":function(){return i([])},string:function(u){return i([],u)},"string, string":function(u,f){return i([],u,f)},Array:function(u){return i(u)},Matrix:function(u){return i(u,u.storage())},"Array | Matrix, string":i,"Array | Matrix, string, string":i});function i(a,u,f){if(u==="dense"||u==="default"||u===void 0)return new r(a,f);if(u==="sparse")return new n(a,f);throw new TypeError("Unknown matrix type "+JSON.stringify(u)+".")}}),Nc="unaryMinus",cg=["typed"],fg=xe(Nc,cg,s=>{var{typed:e}=s;return e(Nc,{number:Dc,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var n=r.clone();return n.value=e.find(t,n.valueType())(r.value),n}),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Sc="abs",hg=["typed"],dg=xe(Sc,hg,s=>{var{typed:e}=s;return e(Sc,{number:gc,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Oc="addScalar",pg=["typed"],_g=xe(Oc,pg,s=>{var{typed:e}=s;return e(Oc,{"number, number":mc,"Complex, Complex":function(r,n){return r.add(n)},"BigNumber, BigNumber":function(r,n){return r.plus(n)},"Fraction, Fraction":function(r,n){return r.add(n)},"Unit, Unit":e.referToSelf(t=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var i=r.clone();return i.value=e.find(t,[i.valueType(),n.valueType()])(i.value,n.value),i.fixPrefix=!1,i})})}),Tc="subtractScalar",vg=["typed"],gg=xe(Tc,vg,s=>{var{typed:e}=s;return e(Tc,{"number, number":xc,"Complex, Complex":function(r,n){return r.sub(n)},"BigNumber, BigNumber":function(r,n){return r.minus(n)},"Fraction, Fraction":function(r,n){return r.sub(n)},"Unit, Unit":e.referToSelf(t=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var i=r.clone();return i.value=e.find(t,[i.valueType(),n.valueType()])(i.value,n.value),i.fixPrefix=!1,i})})}),mg="matAlgo11xS0s",xg=["typed","equalScalar"],Ha=xe(mg,xg,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=t,m=0,w=a;typeof p=="string"&&(_=p,y=e.find(t,[_,_]),m=e.convert(0,_),i=e.convert(i,_),w=e.find(a,[_,_]));for(var D=[],C=[],b=[],F=0;F<x;F++){b[F]=C.length;for(var B=h[F],M=h[F+1],O=B;O<M;O++){var A=c[O],N=u?w(i,f[O]):w(f[O],i);y(N,m)||(C.push(A),D.push(N))}}return b[x]=C.length,n.createSparseMatrix({values:D,index:C,ptr:b,size:[v,x],datatype:_})}}),yg="matAlgo12xSfs",Dg=["typed","DenseMatrix"],Ci=xe(yg,Dg,s=>{var{typed:e,DenseMatrix:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=a;typeof p=="string"&&(_=p,i=e.convert(i,_),y=e.find(a,[_,_]));for(var m=[],w=[],D=[],C=0;C<x;C++){for(var b=C+1,F=h[C],B=h[C+1],M=F;M<B;M++){var O=c[M];w[O]=f[M],D[O]=b}for(var A=0;A<v;A++)C===0&&(m[A]=[]),D[A]===b?m[A][C]=u?y(i,w[A]):y(w[A],i):m[A][C]=u?y(i,0):y(0,i)}return new t({data:m,size:[v,x],datatype:_})}}),wg="matAlgo14xDs",bg=["typed"],ja=xe(wg,bg,s=>{var{typed:e}=s;return function(n,i,a,u){var f=n._data,c=n._size,h=n._datatype,d,p=a;typeof h=="string"&&(d=h,i=e.convert(i,d),p=e.find(a,[d,d]));var v=c.length>0?t(p,0,c,c[0],f,i,u):[];return n.createDenseMatrix({data:v,size:ut(c),datatype:d})};function t(r,n,i,a,u,f,c){var h=[];if(n===i.length-1)for(var d=0;d<a;d++)h[d]=c?r(f,u[d]):r(u[d],f);else for(var p=0;p<a;p++)h[p]=t(r,n+1,i,i[n+1],u[p],f,c);return h}}),Eg="matAlgo02xDS0",Ag=["typed","equalScalar"],Cg=xe(Eg,Ag,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a,u){var f=n._data,c=n._size,h=n._datatype||n.getDataType(),d=i._values,p=i._index,v=i._ptr,x=i._size,_=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(c.length!==x.length)throw new rt(c.length,x.length);if(c[0]!==x[0]||c[1]!==x[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+x+")");if(!d)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var y=c[0],m=c[1],w,D=t,C=0,b=a;typeof h=="string"&&h===_&&h!=="mixed"&&(w=h,D=e.find(t,[w,w]),C=e.convert(0,w),b=e.find(a,[w,w]));for(var F=[],B=[],M=[],O=0;O<m;O++){M[O]=B.length;for(var A=v[O],N=v[O+1],T=A;T<N;T++){var R=p[T],k=u?b(d[T],f[R][O]):b(f[R][O],d[T]);D(k,C)||(B.push(R),F.push(k))}}return M[m]=B.length,i.createSparseMatrix({values:F,index:B,ptr:M,size:[y,m],datatype:h===n._datatype&&_===i._datatype?w:void 0})}}),Fg="matAlgo03xDSf",Bg=["typed"],Fi=xe(Fg,Bg,s=>{var{typed:e}=s;return function(r,n,i,a){var u=r._data,f=r._size,c=r._datatype||r.getDataType(),h=n._values,d=n._index,p=n._ptr,v=n._size,x=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==v.length)throw new rt(f.length,v.length);if(f[0]!==v[0]||f[1]!==v[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+v+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var _=f[0],y=f[1],m,w=0,D=i;typeof c=="string"&&c===x&&c!=="mixed"&&(m=c,w=e.convert(0,m),D=e.find(i,[m,m]));for(var C=[],b=0;b<_;b++)C[b]=[];for(var F=[],B=[],M=0;M<y;M++){for(var O=M+1,A=p[M],N=p[M+1],T=A;T<N;T++){var R=d[T];F[R]=a?D(h[T],u[R][M]):D(u[R][M],h[T]),B[R]=O}for(var k=0;k<_;k++)B[k]===O?C[k][M]=F[k]:C[k][M]=a?D(w,u[k][M]):D(u[k][M],w)}return r.createDenseMatrix({data:C,size:[_,y],datatype:c===r._datatype&&x===n._datatype?m:void 0})}}),Mg="matAlgo05xSfSf",Ng=["typed","equalScalar"],Ic=xe(Mg,Ng,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a){var u=n._values,f=n._index,c=n._ptr,h=n._size,d=n._datatype||n._data===void 0?n._datatype:n.getDataType(),p=i._values,v=i._index,x=i._ptr,_=i._size,y=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(h.length!==_.length)throw new rt(h.length,_.length);if(h[0]!==_[0]||h[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+_+")");var m=h[0],w=h[1],D,C=t,b=0,F=a;typeof d=="string"&&d===y&&d!=="mixed"&&(D=d,C=e.find(t,[D,D]),b=e.convert(0,D),F=e.find(a,[D,D]));var B=u&&p?[]:void 0,M=[],O=[],A=B?[]:void 0,N=B?[]:void 0,T=[],R=[],k,z,L,G;for(z=0;z<w;z++){O[z]=M.length;var H=z+1;for(L=c[z],G=c[z+1];L<G;L++)k=f[L],M.push(k),T[k]=H,A&&(A[k]=u[L]);for(L=x[z],G=x[z+1];L<G;L++)k=v[L],T[k]!==H&&M.push(k),R[k]=H,N&&(N[k]=p[L]);if(B)for(L=O[z];L<M.length;){k=M[L];var ee=T[k],te=R[k];if(ee===H||te===H){var j=ee===H?A[k]:b,X=te===H?N[k]:b,Y=F(j,X);C(Y,b)?M.splice(L,1):(B.push(Y),L++)}}}return O[w]=M.length,n.createSparseMatrix({values:B,index:M,ptr:O,size:[m,w],datatype:d===n._datatype&&y===i._datatype?D:void 0})}}),Sg="matAlgo13xDD",Og=["typed"],Tg=xe(Sg,Og,s=>{var{typed:e}=s;return function(n,i,a){var u=n._data,f=n._size,c=n._datatype,h=i._data,d=i._size,p=i._datatype,v=[];if(f.length!==d.length)throw new rt(f.length,d.length);for(var x=0;x<f.length;x++){if(f[x]!==d[x])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+d+")");v[x]=f[x]}var _,y=a;typeof c=="string"&&c===p&&(_=c,y=e.find(a,[_,_]));var m=v.length>0?t(y,0,v,v[0],u,h):[];return n.createDenseMatrix({data:m,size:v,datatype:_})};function t(r,n,i,a,u,f){var c=[];if(n===i.length-1)for(var h=0;h<a;h++)c[h]=r(u[h],f[h]);else for(var d=0;d<a;d++)c[d]=t(r,n+1,i,i[n+1],u[d],f[d]);return c}}),Ig="broadcast",$g=["concat"],Rg=xe(Ig,$g,s=>{var{concat:e}=s;return function(n,i){var a=Math.max(n._size.length,i._size.length);if(n._size.length===i._size.length&&n._size.every((x,_)=>x===i._size[_]))return[n,i];for(var u=t(n._size,a,0),f=t(i._size,a,0),c=[],h=0;h<a;h++)c[h]=Math.max(u[h],f[h]);Zs(u,c),Zs(f,c);var d=n.clone(),p=i.clone();d._size.length<a?d.reshape(t(d._size,a,1)):p._size.length<a&&p.reshape(t(p._size,a,1));for(var v=0;v<a;v++)d._size[v]<c[v]&&(d=r(d,c[v],v)),p._size[v]<c[v]&&(p=r(p,c[v],v));return[d,p]};function t(n,i,a){return[...Array(i-n.length).fill(a),...n]}function r(n,i,a){return e(...Array(i).fill(n),a)}}),Lg="matrixAlgorithmSuite",Pg=["typed","matrix","concat"],ri=xe(Lg,Pg,s=>{var{typed:e,matrix:t,concat:r}=s,n=Tg({typed:e}),i=ja({typed:e}),a=Rg({concat:r});return function(f){var c=f.elop,h=f.SD||f.DS,d;c?(d={"DenseMatrix, DenseMatrix":(_,y)=>n(...a(_,y),c),"Array, Array":(_,y)=>n(...a(t(_),t(y)),c).valueOf(),"Array, DenseMatrix":(_,y)=>n(...a(t(_),y),c),"DenseMatrix, Array":(_,y)=>n(...a(_,t(y)),c)},f.SS&&(d["SparseMatrix, SparseMatrix"]=(_,y)=>f.SS(...a(_,y),c,!1)),f.DS&&(d["DenseMatrix, SparseMatrix"]=(_,y)=>f.DS(...a(_,y),c,!1),d["Array, SparseMatrix"]=(_,y)=>f.DS(...a(t(_),y),c,!1)),h&&(d["SparseMatrix, DenseMatrix"]=(_,y)=>h(...a(y,_),c,!0),d["SparseMatrix, Array"]=(_,y)=>h(...a(t(y),_),c,!0))):(d={"DenseMatrix, DenseMatrix":e.referToSelf(_=>(y,m)=>n(...a(y,m),_)),"Array, Array":e.referToSelf(_=>(y,m)=>n(...a(t(y),t(m)),_).valueOf()),"Array, DenseMatrix":e.referToSelf(_=>(y,m)=>n(...a(t(y),m),_)),"DenseMatrix, Array":e.referToSelf(_=>(y,m)=>n(...a(y,t(m)),_))},f.SS&&(d["SparseMatrix, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.SS(...a(y,m),_,!1))),f.DS&&(d["DenseMatrix, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.DS(...a(y,m),_,!1)),d["Array, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.DS(...a(t(y),m),_,!1))),h&&(d["SparseMatrix, DenseMatrix"]=e.referToSelf(_=>(y,m)=>h(...a(m,y),_,!0)),d["SparseMatrix, Array"]=e.referToSelf(_=>(y,m)=>h(...a(t(m),y),_,!0))));var p=f.scalar||"any",v=f.Ds||f.Ss;v&&(c?(d["DenseMatrix,"+p]=(_,y)=>i(_,y,c,!1),d[p+", DenseMatrix"]=(_,y)=>i(y,_,c,!0),d["Array,"+p]=(_,y)=>i(t(_),y,c,!1).valueOf(),d[p+", Array"]=(_,y)=>i(t(y),_,c,!0).valueOf()):(d["DenseMatrix,"+p]=e.referToSelf(_=>(y,m)=>i(y,m,_,!1)),d[p+", DenseMatrix"]=e.referToSelf(_=>(y,m)=>i(m,y,_,!0)),d["Array,"+p]=e.referToSelf(_=>(y,m)=>i(t(y),m,_,!1).valueOf()),d[p+", Array"]=e.referToSelf(_=>(y,m)=>i(t(m),y,_,!0).valueOf())));var x=f.sS!==void 0?f.sS:f.Ss;return c?(f.Ss&&(d["SparseMatrix,"+p]=(_,y)=>f.Ss(_,y,c,!1)),x&&(d[p+", SparseMatrix"]=(_,y)=>x(y,_,c,!0))):(f.Ss&&(d["SparseMatrix,"+p]=e.referToSelf(_=>(y,m)=>f.Ss(y,m,_,!1))),x&&(d[p+", SparseMatrix"]=e.referToSelf(_=>(y,m)=>x(m,y,_,!0)))),c&&c.signatures&&Fl(d,c.signatures),d}}),kg="matAlgo01xDSid",zg=["typed"],$c=xe(kg,zg,s=>{var{typed:e}=s;return function(r,n,i,a){var u=r._data,f=r._size,c=r._datatype||r.getDataType(),h=n._values,d=n._index,p=n._ptr,v=n._size,x=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==v.length)throw new rt(f.length,v.length);if(f[0]!==v[0]||f[1]!==v[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+v+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var _=f[0],y=f[1],m=typeof c=="string"&&c!=="mixed"&&c===x?c:void 0,w=m?e.find(i,[m,m]):i,D,C,b=[];for(D=0;D<_;D++)b[D]=[];var F=[],B=[];for(C=0;C<y;C++){for(var M=C+1,O=p[C],A=p[C+1],N=O;N<A;N++)D=d[N],F[D]=a?w(h[N],u[D][C]):w(u[D][C],h[N]),B[D]=M;for(D=0;D<_;D++)B[D]===M?b[D][C]=F[D]:b[D][C]=u[D][C]}return r.createDenseMatrix({data:b,size:[_,y],datatype:c===r._datatype&&x===n._datatype?m:void 0})}}),qg="matAlgo04xSidSid",Ug=["typed","equalScalar"],Wg=xe(qg,Ug,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a){var u=n._values,f=n._index,c=n._ptr,h=n._size,d=n._datatype||n._data===void 0?n._datatype:n.getDataType(),p=i._values,v=i._index,x=i._ptr,_=i._size,y=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(h.length!==_.length)throw new rt(h.length,_.length);if(h[0]!==_[0]||h[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+_+")");var m=h[0],w=h[1],D,C=t,b=0,F=a;typeof d=="string"&&d===y&&d!=="mixed"&&(D=d,C=e.find(t,[D,D]),b=e.convert(0,D),F=e.find(a,[D,D]));var B=u&&p?[]:void 0,M=[],O=[],A=u&&p?[]:void 0,N=u&&p?[]:void 0,T=[],R=[],k,z,L,G,H;for(z=0;z<w;z++){O[z]=M.length;var ee=z+1;for(G=c[z],H=c[z+1],L=G;L<H;L++)k=f[L],M.push(k),T[k]=ee,A&&(A[k]=u[L]);for(G=x[z],H=x[z+1],L=G;L<H;L++)if(k=v[L],T[k]===ee){if(A){var te=F(A[k],p[L]);C(te,b)?T[k]=null:A[k]=te}}else M.push(k),R[k]=ee,N&&(N[k]=p[L]);if(A&&N)for(L=O[z];L<M.length;)k=M[L],T[k]===ee?(B[L]=A[k],L++):R[k]===ee?(B[L]=N[k],L++):M.splice(L,1)}return O[w]=M.length,n.createSparseMatrix({values:B,index:M,ptr:O,size:[m,w],datatype:d===n._datatype&&y===i._datatype?D:void 0})}}),Hg="matAlgo10xSids",jg=["typed","DenseMatrix"],Rc=xe(Hg,jg,s=>{var{typed:e,DenseMatrix:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=a;typeof p=="string"&&(_=p,i=e.convert(i,_),y=e.find(a,[_,_]));for(var m=[],w=[],D=[],C=0;C<x;C++){for(var b=C+1,F=h[C],B=h[C+1],M=F;M<B;M++){var O=c[M];w[O]=f[M],D[O]=b}for(var A=0;A<v;A++)C===0&&(m[A]=[]),D[A]===b?m[A][C]=u?y(i,w[A]):y(w[A],i):m[A][C]=i}return new t({data:m,size:[v,x],datatype:_})}}),Yg="multiplyScalar",Zg=["typed"],Vg=xe(Yg,Zg,s=>{var{typed:e}=s;return e("multiplyScalar",{"number, number":yc,"Complex, Complex":function(r,n){return r.mul(n)},"BigNumber, BigNumber":function(r,n){return r.times(n)},"Fraction, Fraction":function(r,n){return r.mul(n)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Lc="multiply",Gg=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],Kg=xe(Lc,Gg,s=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:n,equalScalar:i,dot:a}=s,u=Ha({typed:e,equalScalar:i}),f=ja({typed:e});function c(b,F){switch(b.length){case 1:switch(F.length){case 1:if(b[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(b[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+b[0]+") must match Matrix rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;case 2:switch(F.length){case 1:if(b[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+b[1]+") must match Vector length ("+F[0]+")");break;case 2:if(b[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+b[1]+") must match Matrix B rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+b.length+" dimensions)")}}function h(b,F,B){if(B===0)throw new Error("Cannot multiply two empty vectors");return a(b,F)}function d(b,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return p(b,F)}function p(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._size,T=F._datatype||F.getDataType(),R=M[0],k=N[1],z,L=r,G=n;O&&T&&O===T&&typeof O=="string"&&O!=="mixed"&&(z=O,L=e.find(r,[z,z]),G=e.find(n,[z,z]));for(var H=[],ee=0;ee<k;ee++){for(var te=G(B[0],A[0][ee]),j=1;j<R;j++)te=L(te,G(B[j],A[j][ee]));H[ee]=te}return b.createDenseMatrix({data:H,size:[k],datatype:O===b._datatype&&T===F._datatype?z:void 0})}var v=e("_multiplyMatrixVector",{"DenseMatrix, any":_,"SparseMatrix, any":w}),x=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":y,"DenseMatrix, SparseMatrix":m,"SparseMatrix, DenseMatrix":D,"SparseMatrix, SparseMatrix":C});function _(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._datatype||F.getDataType(),T=M[0],R=M[1],k,z=r,L=n;O&&N&&O===N&&typeof O=="string"&&O!=="mixed"&&(k=O,z=e.find(r,[k,k]),L=e.find(n,[k,k]));for(var G=[],H=0;H<T;H++){for(var ee=B[H],te=L(ee[0],A[0]),j=1;j<R;j++)te=z(te,L(ee[j],A[j]));G[H]=te}return b.createDenseMatrix({data:G,size:[T],datatype:O===b._datatype&&N===F._datatype?k:void 0})}function y(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._size,T=F._datatype||F.getDataType(),R=M[0],k=M[1],z=N[1],L,G=r,H=n;O&&T&&O===T&&typeof O=="string"&&O!=="mixed"&&O!=="mixed"&&(L=O,G=e.find(r,[L,L]),H=e.find(n,[L,L]));for(var ee=[],te=0;te<R;te++){var j=B[te];ee[te]=[];for(var X=0;X<z;X++){for(var Y=H(j[0],A[0][X]),Q=1;Q<k;Q++)Y=G(Y,H(j[Q],A[Q][X]));ee[te][X]=Y}}return b.createDenseMatrix({data:ee,size:[R,z],datatype:O===b._datatype&&T===F._datatype?L:void 0})}function m(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._values,N=F._index,T=F._ptr,R=F._size,k=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!A)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var z=M[0],L=R[1],G,H=r,ee=n,te=i,j=0;O&&k&&O===k&&typeof O=="string"&&O!=="mixed"&&(G=O,H=e.find(r,[G,G]),ee=e.find(n,[G,G]),te=e.find(i,[G,G]),j=e.convert(0,G));for(var X=[],Y=[],Q=[],pe=F.createSparseMatrix({values:X,index:Y,ptr:Q,size:[z,L],datatype:O===b._datatype&&k===F._datatype?G:void 0}),De=0;De<L;De++){Q[De]=Y.length;var we=T[De],be=T[De+1];if(be>we)for(var Oe=0,Fe=0;Fe<z;Fe++){for(var nt=Fe+1,Ye=void 0,Te=we;Te<be;Te++){var Re=N[Te];Oe!==nt?(Ye=ee(B[Fe][Re],A[Te]),Oe=nt):Ye=H(Ye,ee(B[Fe][Re],A[Te]))}Oe===nt&&!te(Ye,j)&&(Y.push(Fe),X.push(Ye))}}return Q[L]=Y.length,pe}function w(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(!B)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var N=F._data,T=F._datatype||F.getDataType(),R=b._size[0],k=F._size[0],z=[],L=[],G=[],H,ee=r,te=n,j=i,X=0;A&&T&&A===T&&typeof A=="string"&&A!=="mixed"&&(H=A,ee=e.find(r,[H,H]),te=e.find(n,[H,H]),j=e.find(i,[H,H]),X=e.convert(0,H));var Y=[],Q=[];G[0]=0;for(var pe=0;pe<k;pe++){var De=N[pe];if(!j(De,X))for(var we=O[pe],be=O[pe+1],Oe=we;Oe<be;Oe++){var Fe=M[Oe];Q[Fe]?Y[Fe]=ee(Y[Fe],te(De,B[Oe])):(Q[Fe]=!0,L.push(Fe),Y[Fe]=te(De,B[Oe]))}}for(var nt=L.length,Ye=0;Ye<nt;Ye++){var Te=L[Ye];z[Ye]=Y[Te]}return G[1]=L.length,b.createSparseMatrix({values:z,index:L,ptr:G,size:[R,1],datatype:A===b._datatype&&T===F._datatype?H:void 0})}function D(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(!B)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var N=F._data,T=F._datatype||F.getDataType(),R=b._size[0],k=F._size[0],z=F._size[1],L,G=r,H=n,ee=i,te=0;A&&T&&A===T&&typeof A=="string"&&A!=="mixed"&&(L=A,G=e.find(r,[L,L]),H=e.find(n,[L,L]),ee=e.find(i,[L,L]),te=e.convert(0,L));for(var j=[],X=[],Y=[],Q=b.createSparseMatrix({values:j,index:X,ptr:Y,size:[R,z],datatype:A===b._datatype&&T===F._datatype?L:void 0}),pe=[],De=[],we=0;we<z;we++){Y[we]=X.length;for(var be=we+1,Oe=0;Oe<k;Oe++){var Fe=N[Oe][we];if(!ee(Fe,te))for(var nt=O[Oe],Ye=O[Oe+1],Te=nt;Te<Ye;Te++){var Re=M[Te];De[Re]!==be?(De[Re]=be,X.push(Re),pe[Re]=H(Fe,B[Te])):pe[Re]=G(pe[Re],H(Fe,B[Te]))}}for(var xt=Y[we],Ut=X.length,Et=xt;Et<Ut;Et++){var lr=X[Et];j[Et]=pe[lr]}}return Y[z]=X.length,Q}function C(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType(),N=F._values,T=F._index,R=F._ptr,k=F._datatype||F._data===void 0?F._datatype:F.getDataType(),z=b._size[0],L=F._size[1],G=B&&N,H,ee=r,te=n;A&&k&&A===k&&typeof A=="string"&&A!=="mixed"&&(H=A,ee=e.find(r,[H,H]),te=e.find(n,[H,H]));for(var j=G?[]:void 0,X=[],Y=[],Q=b.createSparseMatrix({values:j,index:X,ptr:Y,size:[z,L],datatype:A===b._datatype&&k===F._datatype?H:void 0}),pe=G?[]:void 0,De=[],we,be,Oe,Fe,nt,Ye,Te,Re,xt=0;xt<L;xt++){Y[xt]=X.length;var Ut=xt+1;for(nt=R[xt],Ye=R[xt+1],Fe=nt;Fe<Ye;Fe++)if(Re=T[Fe],G)for(be=O[Re],Oe=O[Re+1],we=be;we<Oe;we++)Te=M[we],De[Te]!==Ut?(De[Te]=Ut,X.push(Te),pe[Te]=te(N[Fe],B[we])):pe[Te]=ee(pe[Te],te(N[Fe],B[we]));else for(be=O[Re],Oe=O[Re+1],we=be;we<Oe;we++)Te=M[we],De[Te]!==Ut&&(De[Te]=Ut,X.push(Te));if(G)for(var Et=Y[xt],lr=X.length,Lr=Et;Lr<lr;Lr++){var cr=X[Lr];j[Lr]=pe[cr]}}return Y[L]=X.length,Q}return e(Lc,n,{"Array, Array":e.referTo("Matrix, Matrix",b=>(F,B)=>{c(Lt(F),Lt(B));var M=b(t(F),t(B));return mt(M)?M.valueOf():M}),"Matrix, Matrix":function(F,B){var M=F.size(),O=B.size();return c(M,O),M.length===1?O.length===1?h(F,B,M[0]):d(F,B):O.length===1?v(F,B):x(F,B)},"Matrix, Array":e.referTo("Matrix,Matrix",b=>(F,B)=>b(F,t(B))),"Array, Matrix":e.referToSelf(b=>(F,B)=>b(t(F,B.storage()),B)),"SparseMatrix, any":function(F,B){return u(F,B,n,!1)},"DenseMatrix, any":function(F,B){return f(F,B,n,!1)},"any, SparseMatrix":function(F,B){return u(B,F,n,!0)},"any, DenseMatrix":function(F,B){return f(B,F,n,!0)},"Array, any":function(F,B){return f(t(F),B,n,!1).valueOf()},"any, Array":function(F,B){return f(t(B),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":e.referToSelf(b=>(F,B,M)=>{for(var O=b(F,B),A=0;A<M.length;A++)O=b(O,M[A]);return O})})}),Pc="subtract",Xg=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],Qg=xe(Pc,Xg,s=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:n,unaryMinus:i,DenseMatrix:a,concat:u}=s,f=$c({typed:e}),c=Fi({typed:e}),h=Ic({typed:e,equalScalar:r}),d=Rc({typed:e,DenseMatrix:a}),p=Ci({typed:e,DenseMatrix:a}),v=ri({typed:e,matrix:t,concat:u});return e(Pc,{"any, any":n},v({elop:n,SS:h,DS:f,SD:c,Ss:p,sS:d}))}),Jg="matAlgo07xSSf",em=["typed","DenseMatrix"],uo=xe(Jg,em,s=>{var{typed:e,DenseMatrix:t}=s;return function(i,a,u){var f=i._size,c=i._datatype||i._data===void 0?i._datatype:i.getDataType(),h=a._size,d=a._datatype||a._data===void 0?a._datatype:a.getDataType();if(f.length!==h.length)throw new rt(f.length,h.length);if(f[0]!==h[0]||f[1]!==h[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+h+")");var p=f[0],v=f[1],x,_=0,y=u;typeof c=="string"&&c===d&&c!=="mixed"&&(x=c,_=e.convert(0,x),y=e.find(u,[x,x]));var m,w,D=[];for(m=0;m<p;m++)D[m]=[];var C=[],b=[],F=[],B=[];for(w=0;w<v;w++){var M=w+1;for(r(i,w,F,C,M),r(a,w,B,b,M),m=0;m<p;m++){var O=F[m]===M?C[m]:_,A=B[m]===M?b[m]:_;D[m][w]=y(O,A)}}return new t({data:D,size:[p,v],datatype:c===i._datatype&&d===a._datatype?x:void 0})};function r(n,i,a,u,f){for(var c=n._values,h=n._index,d=n._ptr,p=d[i],v=d[i+1];p<v;p++){var x=h[p];a[x]=f,u[x]=c[p]}}}),kc="conj",tm=["typed"],rm=xe(kc,tm,s=>{var{typed:e}=s;return e(kc,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),zc="concat",nm=["typed","matrix","isInteger"],im=xe(zc,nm,s=>{var{typed:e,matrix:t,isInteger:r}=s;return e(zc,{"...Array | Matrix | number | BigNumber":function(i){var a,u=i.length,f=-1,c,h=!1,d=[];for(a=0;a<u;a++){var p=i[a];if(mt(p)&&(h=!0),pt(p)||St(p)){if(a!==u-1)throw new Error("Dimension must be specified as last argument");if(c=f,f=p.valueOf(),!r(f))throw new TypeError("Integer number expected for dimension");if(f<0||a>0&&f>c)throw new On(f,c+1)}else{var v=ut(p).valueOf(),x=Lt(v);if(d[a]=v,c=f,f=x.length-1,a>0&&f!==c)throw new rt(c+1,f+1)}}if(d.length===0)throw new SyntaxError("At least one matrix expected");for(var _=d.shift();d.length;)_=Zl(_,d.shift(),f);return h?t(_):_},"...string":function(i){return i.join("")}})}),qc="count",sm=["typed","size","prod"],om=xe(qc,sm,s=>{var{typed:e,size:t,prod:r}=s;return e(qc,{string:function(i){return i.length},"Matrix | Array":function(i){return r(t(i))}})}),Uc="identity",am=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],um=xe(Uc,am,s=>{var{typed:e,config:t,matrix:r,BigNumber:n,DenseMatrix:i,SparseMatrix:a}=s;return e(Uc,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(h){return r(h)},"number | BigNumber":function(h){return f(h,h,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(h,d){return f(h,h,d)},"number | BigNumber, number | BigNumber":function(h,d){return f(h,d,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(h,d,p){return f(h,d,p)},Array:function(h){return u(h)},"Array, string":function(h,d){return u(h,d)},Matrix:function(h){return u(h.valueOf(),h.storage())},"Matrix, string":function(h,d){return u(h.valueOf(),d)}});function u(c,h){switch(c.length){case 0:return h?r(h):[];case 1:return f(c[0],c[0],h);case 2:return f(c[0],c[1],h);default:throw new Error("Vector containing two values expected")}}function f(c,h,d){var p=St(c)||St(h)?n:null;if(St(c)&&(c=c.toNumber()),St(h)&&(h=h.toNumber()),!bt(c)||c<1)throw new Error("Parameters in function identity must be positive integers");if(!bt(h)||h<1)throw new Error("Parameters in function identity must be positive integers");var v=p?new n(1):1,x=p?new p(0):0,_=[c,h];if(d){if(d==="sparse")return a.diagonal(_,v,0,x);if(d==="dense")return i.diagonal(_,v,0,x);throw new TypeError('Unknown matrix type "'.concat(d,'"'))}for(var y=Na([],_,x),m=c<h?c:h,w=0;w<m;w++)y[w][w]=v;return y}}),Wc="kron",lm=["typed","matrix","multiplyScalar"],cm=xe(Wc,lm,s=>{var{typed:e,matrix:t,multiplyScalar:r}=s;return e(Wc,{"Matrix, Matrix":function(a,u){return t(n(a.toArray(),u.toArray()))},"Matrix, Array":function(a,u){return t(n(a.toArray(),u))},"Array, Matrix":function(a,u){return t(n(a,u.toArray()))},"Array, Array":n});function n(i,a){if(Lt(i).length===1&&(i=[i]),Lt(a).length===1&&(a=[a]),Lt(i).length>2||Lt(a).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(i.length)+", y = "+JSON.stringify(a.length)+")");var u=[],f=[];return i.map(function(c){return a.map(function(h){return f=[],u.push(f),c.map(function(d){return h.map(function(p){return f.push(r(d,p))})})})})&&u}});function fm(){throw new Error('No "bignumber" implementation available')}function hm(){throw new Error('No "fraction" implementation available')}function dm(){throw new Error('No "matrix" implementation available')}var Hc="reshape",pm=["typed","isInteger","matrix"],_m=xe(Hc,pm,s=>{var{typed:e,isInteger:t}=s;return e(Hc,{"Matrix, Array":function(n,i){return n.reshape(i,!0)},"Array, Array":function(n,i){return i.forEach(function(a){if(!t(a))throw new TypeError("Invalid size for dimension: "+a)}),Oa(n,i)}})}),jc="size",vm=["typed","config","?matrix"],gm=xe(jc,vm,s=>{var{typed:e,config:t,matrix:r}=s;return e(jc,{Matrix:function(i){return i.create(i.size())},Array:Lt,string:function(i){return t.matrix==="Array"?[i.length]:r([i.length])},"number | Complex | BigNumber | Unit | boolean | null":function(i){return t.matrix==="Array"?[]:r?r([]):dm()}})}),Yc="transpose",mm=["typed","matrix"],xm=xe(Yc,mm,s=>{var{typed:e,matrix:t}=s;return e(Yc,{Array:a=>r(t(a)).valueOf(),Matrix:r,any:ut});function r(a){var u=a.size(),f;switch(u.length){case 1:f=a.clone();break;case 2:{var c=u[0],h=u[1];if(h===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+ct(u)+")");switch(a.storage()){case"dense":f=n(a,c,h);break;case"sparse":f=i(a,c,h);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+ct(u)+")")}return f}function n(a,u,f){for(var c=a._data,h=[],d,p=0;p<f;p++){d=h[p]=[];for(var v=0;v<u;v++)d[v]=ut(c[v][p])}return a.createDenseMatrix({data:h,size:[f,u],datatype:a._datatype})}function i(a,u,f){for(var c=a._values,h=a._index,d=a._ptr,p=c?[]:void 0,v=[],x=[],_=[],y=0;y<u;y++)_[y]=0;var m,w,D;for(m=0,w=h.length;m<w;m++)_[h[m]]++;for(var C=0,b=0;b<u;b++)x.push(C),C+=_[b],_[b]=x[b];for(x.push(C),D=0;D<f;D++)for(var F=d[D],B=d[D+1],M=F;M<B;M++){var O=_[h[M]]++;v[O]=D,c&&(p[O]=ut(c[M]))}return a.createSparseMatrix({values:p,index:v,ptr:x,size:[f,u],datatype:a._datatype})}}),Zc="ctranspose",ym=["typed","transpose","conj"],Dm=xe(Zc,ym,s=>{var{typed:e,transpose:t,conj:r}=s;return e(Zc,{any:function(i){return r(t(i))}})}),Vc="mode",wm=["typed","isNaN","isNumeric"],bm=xe(Vc,wm,s=>{var{typed:e,isNaN:t,isNumeric:r}=s;return e(Vc,{"Array | Matrix":n,"...":function(a){return n(a)}});function n(i){i=Ia(i.valueOf());var a=i.length;if(a===0)throw new Error("Cannot calculate mode of an empty array");for(var u={},f=[],c=0,h=0;h<i.length;h++){var d=i[h];if(r(d)&&t(d))throw new Error("Cannot calculate mode of an array containing NaN values");d in u||(u[d]=0),u[d]++,u[d]===c?f.push(d):u[d]>c&&(c=u[d],f=[d])}return f}});function Ln(s,e,t){var r;return String(s).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+Sn(t)+", value: "+JSON.stringify(t)+")":" (type: "+s.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(s).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+Sn(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):s}var Gc="prod",Em=["typed","config","multiplyScalar","numeric"],Am=xe(Gc,Em,s=>{var{typed:e,config:t,multiplyScalar:r,numeric:n}=s;return e(Gc,{"Array | Matrix":i,"Array | Matrix, number | BigNumber":function(u,f){throw new Error("prod(A, dim) is not yet supported")},"...":function(u){return i(u)}});function i(a){var u;if(as(a,function(f){try{u=u===void 0?f:r(u,f)}catch(c){throw Ln(c,"prod",f)}}),typeof u=="string"&&(u=n(u,t.number)),u===void 0)throw new Error("Cannot calculate prod of an empty array");return u}}),Cm="numeric",Fm=["number","?bignumber","?fraction"],Bm=xe(Cm,Fm,s=>{var{number:e,bignumber:t,fraction:r}=s,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},i={number:a=>e(a),BigNumber:t?a=>t(a):fm,Fraction:r?a=>r(a):hm};return function(u){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",c=arguments.length>2?arguments[2]:void 0;if(c!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var h=Sn(u);if(!(h in n))throw new TypeError("Cannot convert "+u+' of type "'+h+'"; valid input types are '+Object.keys(n).join(", "));if(!(f in i))throw new TypeError("Cannot convert "+u+' to type "'+f+'"; valid output types are '+Object.keys(i).join(", "));return f===h?u:i[f](u)}}),Kc="divideScalar",Mm=["typed","numeric"],Nm=xe(Kc,Mm,s=>{var{typed:e,numeric:t}=s;return e(Kc,{"number, number":function(n,i){return n/i},"Complex, Complex":function(n,i){return n.div(i)},"BigNumber, BigNumber":function(n,i){return n.div(i)},"Fraction, Fraction":function(n,i){return n.div(i)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),Xc="pow",Sm=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Om=xe(Xc,Sm,s=>{var{typed:e,config:t,identity:r,multiply:n,matrix:i,inv:a,number:u,fraction:f,Complex:c}=s;return e(Xc,{"number, number":h,"Complex, Complex":function(x,_){return x.pow(_)},"BigNumber, BigNumber":function(x,_){return _.isInteger()||x>=0||t.predictable?x.pow(_):new c(x.toNumber(),0).pow(_.toNumber(),0)},"Fraction, Fraction":function(x,_){var y=x.pow(_);if(y!=null)return y;if(t.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return h(x.valueOf(),_.valueOf())},"Array, number":d,"Array, BigNumber":function(x,_){return d(x,_.toNumber())},"Matrix, number":p,"Matrix, BigNumber":function(x,_){return p(x,_.toNumber())},"Unit, number | BigNumber":function(x,_){return x.pow(_)}});function h(v,x){if(t.predictable&&!bt(x)&&v<0)try{var _=f(x),y=u(_);if((x===y||Math.abs((x-y)/x)<1e-14)&&_.d%2===1)return(_.n%2===0?1:-1)*Math.pow(-v,x)}catch{}return t.predictable&&(v<-1&&x===1/0||v>-1&&v<0&&x===-1/0)?NaN:bt(x)||v>=0||t.predictable?wc(v,x):v*v<1&&x===1/0||v*v>1&&x===-1/0?0:new c(v,0).pow(x,0)}function d(v,x){if(!bt(x))throw new TypeError("For A^b, b must be an integer (value is "+x+")");var _=Lt(v);if(_.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+_.length+" dimensions)");if(_[0]!==_[1])throw new Error("For A^b, A must be square (size is "+_[0]+"x"+_[1]+")");if(x<0)try{return d(a(v),-x)}catch(w){throw w.message==="Cannot calculate inverse, determinant is zero"?new TypeError("For A^b, when A is not invertible, b must be a positive integer (value is "+x+")"):w}for(var y=r(_[0]).valueOf(),m=v;x>=1;)(x&1)===1&&(y=n(m,y)),x>>=1,m=n(m,m);return y}function p(v,x){return i(d(v.valueOf(),x))}}),Qc="dotDivide",Tm=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],Im=xe(Qc,Tm,s=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:n,DenseMatrix:i,concat:a}=s,u=Cg({typed:e,equalScalar:r}),f=Fi({typed:e}),c=uo({typed:e,DenseMatrix:i}),h=Ha({typed:e,equalScalar:r}),d=Ci({typed:e,DenseMatrix:i}),p=ri({typed:e,matrix:t,concat:a});return e(Qc,p({elop:n,SS:c,DS:f,SD:u,Ss:h,sS:d}))}),lo="compare",$m=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],Rm=xe(lo,$m,s=>{var{typed:e,config:t,equalScalar:r,matrix:n,BigNumber:i,Fraction:a,DenseMatrix:u,concat:f}=s,c=Fi({typed:e}),h=Ic({typed:e,equalScalar:r}),d=Ci({typed:e,DenseMatrix:u}),p=ri({typed:e,matrix:n,concat:f}),v=oo({typed:e});return e(lo,Lm({typed:e,config:t}),{"boolean, boolean":function(_,y){return _===y?0:_>y?1:-1},"BigNumber, BigNumber":function(_,y){return so(_,y,t.epsilon)?new i(0):new i(_.cmp(y))},"Fraction, Fraction":function(_,y){return new a(_.compare(y))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},v,p({SS:h,DS:c,Ss:d}))}),Lm=xe(lo,["typed","config"],s=>{var{typed:e,config:t}=s;return e(lo,{"number, number":function(n,i){return ti(n,i,t.epsilon)?0:n>i?1:-1}})}),co="equal",Pm=["typed","matrix","equalScalar","DenseMatrix","concat"],km=xe(co,Pm,s=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:t,concat:i});return e(co,zm({typed:e,equalScalar:r}),c({elop:r,SS:u,DS:a,Ss:f}))}),zm=xe(co,["typed","equalScalar"],s=>{var{typed:e,equalScalar:t}=s;return e(co,{"any, any":function(n,i){return n===null?i===null:i===null?n===null:n===void 0?i===void 0:i===void 0?n===void 0:t(n,i)}})}),fo="smaller",qm=["typed","config","matrix","DenseMatrix","concat"],Um=xe(fo,qm,s=>{var{typed:e,config:t,matrix:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:r,concat:i}),h=oo({typed:e});return e(fo,Wm({typed:e,config:t}),{"boolean, boolean":(d,p)=>d<p,"BigNumber, BigNumber":function(p,v){return p.lt(v)&&!so(p,v,t.epsilon)},"Fraction, Fraction":(d,p)=>d.compare(p)===-1,"Complex, Complex":function(p,v){throw new TypeError("No ordering relation is defined for complex numbers")}},h,c({SS:u,DS:a,Ss:f}))}),Wm=xe(fo,["typed","config"],s=>{var{typed:e,config:t}=s;return e(fo,{"number, number":function(n,i){return n<i&&!ti(n,i,t.epsilon)}})}),ho="larger",Hm=["typed","config","matrix","DenseMatrix","concat"],jm=xe(ho,Hm,s=>{var{typed:e,config:t,matrix:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:r,concat:i}),h=oo({typed:e});return e(ho,Ym({typed:e,config:t}),{"boolean, boolean":(d,p)=>d>p,"BigNumber, BigNumber":function(p,v){return p.gt(v)&&!so(p,v,t.epsilon)},"Fraction, Fraction":(d,p)=>d.compare(p)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},h,c({SS:u,DS:a,Ss:f}))}),Ym=xe(ho,["typed","config"],s=>{var{typed:e,config:t}=s;return e(ho,{"number, number":function(n,i){return n>i&&!ti(n,i,t.epsilon)}})}),Jc="deepEqual",Zm=["typed","equal"],Vm=xe(Jc,Zm,s=>{var{typed:e,equal:t}=s;return e(Jc,{"any, any":function(i,a){return r(i.valueOf(),a.valueOf())}});function r(n,i){if(Array.isArray(n))if(Array.isArray(i)){var a=n.length;if(a!==i.length)return!1;for(var u=0;u<a;u++)if(!r(n[u],i[u]))return!1;return!0}else return!1;else return Array.isArray(i)?!1:t(n,i)}}),ef="partitionSelect",Gm=["typed","isNumeric","isNaN","compare"],Km=xe(ef,Gm,s=>{var{typed:e,isNumeric:t,isNaN:r,compare:n}=s,i=n,a=(c,h)=>-n(c,h);return e(ef,{"Array | Matrix, number":function(h,d){return u(h,d,i)},"Array | Matrix, number, string":function(h,d,p){if(p==="asc")return u(h,d,i);if(p==="desc")return u(h,d,a);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":u});function u(c,h,d){if(!bt(h)||h<0)throw new Error("k must be a non-negative integer");if(mt(c)){var p=c.size();if(p.length>1)throw new Error("Only one dimensional matrices supported");return f(c.valueOf(),h,d)}if(Array.isArray(c))return f(c,h,d)}function f(c,h,d){if(h>=c.length)throw new Error("k out of bounds");for(var p=0;p<c.length;p++)if(t(c[p])&&r(c[p]))return c[p];for(var v=0,x=c.length-1;v<x;){for(var _=v,y=x,m=c[Math.floor(Math.random()*(x-v+1))+v];_<y;)if(d(c[_],m)>=0){var w=c[y];c[y]=c[_],c[_]=w,--y}else++_;d(c[_],m)>0&&--_,h<=_?x=_:v=_+1}return c[h]}}),tf="max",Xm=["typed","config","numeric","larger"],Qm=xe(tf,Xm,s=>{var{typed:e,config:t,numeric:r,larger:n}=s;return e(tf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(f,c){return Wa(f,c.valueOf(),i)},"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function max");return a(f)}});function i(u,f){try{return n(u,f)?u:f}catch(c){throw Ln(c,"max",f)}}function a(u){var f;if(as(u,function(c){try{isNaN(c)&&typeof c=="number"?f=NaN:(f===void 0||n(c,f))&&(f=c)}catch(h){throw Ln(h,"max",c)}}),f===void 0)throw new Error("Cannot calculate max of an empty array");return typeof f=="string"&&(f=r(f,t.number)),f}}),rf="min",Jm=["typed","config","numeric","smaller"],ex=xe(rf,Jm,s=>{var{typed:e,config:t,numeric:r,smaller:n}=s;return e(rf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(f,c){return Wa(f,c.valueOf(),i)},"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function min");return a(f)}});function i(u,f){try{return n(u,f)?u:f}catch(c){throw Ln(c,"min",f)}}function a(u){var f;if(as(u,function(c){try{isNaN(c)&&typeof c=="number"?f=NaN:(f===void 0||n(c,f))&&(f=c)}catch(h){throw Ln(h,"min",c)}}),f===void 0)throw new Error("Cannot calculate min of an empty array");return typeof f=="string"&&(f=r(f,t.number)),f}}),nf="add",tx=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],rx=xe(nf,tx,s=>{var{typed:e,matrix:t,addScalar:r,equalScalar:n,DenseMatrix:i,SparseMatrix:a,concat:u}=s,f=$c({typed:e}),c=Wg({typed:e,equalScalar:n}),h=Rc({typed:e,DenseMatrix:i}),d=ri({typed:e,matrix:t,concat:u});return e(nf,{"any, any":r,"any, any, ...any":e.referToSelf(p=>(v,x,_)=>{for(var y=p(v,x),m=0;m<_.length;m++)y=p(y,_[m]);return y})},d({elop:r,DS:f,SS:c,Ss:h}))}),sf="dot",nx=["typed","addScalar","multiplyScalar","conj","size"],ix=xe(sf,nx,s=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:n,size:i}=s;return e(sf,{"Array | DenseMatrix, Array | DenseMatrix":u,"SparseMatrix, SparseMatrix":f});function a(h,d){var p=c(h),v=c(d),x,_;if(p.length===1)x=p[0];else if(p.length===2&&p[1]===1)x=p[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+p.join(", ")+")");if(v.length===1)_=v[0];else if(v.length===2&&v[1]===1)_=v[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+v.join(", ")+")");if(x!==_)throw new RangeError("Vectors must have equal length ("+x+" != "+_+")");if(x===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return x}function u(h,d){var p=a(h,d),v=mt(h)?h._data:h,x=mt(h)?h._datatype||h.getDataType():void 0,_=mt(d)?d._data:d,y=mt(d)?d._datatype||d.getDataType():void 0,m=c(h).length===2,w=c(d).length===2,D=t,C=r;if(x&&y&&x===y&&typeof x=="string"&&x!=="mixed"){var b=x;D=e.find(t,[b,b]),C=e.find(r,[b,b])}if(!m&&!w){for(var F=C(n(v[0]),_[0]),B=1;B<p;B++)F=D(F,C(n(v[B]),_[B]));return F}if(!m&&w){for(var M=C(n(v[0]),_[0][0]),O=1;O<p;O++)M=D(M,C(n(v[O]),_[O][0]));return M}if(m&&!w){for(var A=C(n(v[0][0]),_[0]),N=1;N<p;N++)A=D(A,C(n(v[N][0]),_[N]));return A}if(m&&w){for(var T=C(n(v[0][0]),_[0][0]),R=1;R<p;R++)T=D(T,C(n(v[R][0]),_[R][0]));return T}}function f(h,d){a(h,d);for(var p=h._index,v=h._values,x=d._index,_=d._values,y=0,m=t,w=r,D=0,C=0;D<p.length&&C<x.length;){var b=p[D],F=x[C];if(b<F){D++;continue}if(b>F){C++;continue}b===F&&(y=m(y,w(v[D],_[C])),D++,C++)}return y}function c(h){return mt(h)?h.size():i(h)}}),sx="trace",ox=["typed","matrix","add"],ax=xe(sx,ox,s=>{var{typed:e,matrix:t,add:r}=s;return e("trace",{Array:function(u){return n(t(u))},SparseMatrix:i,DenseMatrix:n,any:ut});function n(a){var u=a._size,f=a._data;switch(u.length){case 1:if(u[0]===1)return ut(f[0]);throw new RangeError("Matrix must be square (size: "+ct(u)+")");case 2:{var c=u[0],h=u[1];if(c===h){for(var d=0,p=0;p<c;p++)d=r(d,f[p][p]);return d}else throw new RangeError("Matrix must be square (size: "+ct(u)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(u)+")")}}function i(a){var u=a._values,f=a._index,c=a._ptr,h=a._size,d=h[0],p=h[1];if(d===p){var v=0;if(u.length>0)for(var x=0;x<p;x++)for(var _=c[x],y=c[x+1],m=_;m<y;m++){var w=f[m];if(w===x){v=r(v,u[m]);break}if(w>x)break}return v}throw new RangeError("Matrix must be square (size: "+ct(h)+")")}}),of="det",ux=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],lx=xe(of,ux,s=>{var{typed:e,matrix:t,subtractScalar:r,multiply:n,divideScalar:i,isZero:a,unaryMinus:u}=s;return e(of,{any:function(h){return ut(h)},"Array | Matrix":function(h){var d;switch(mt(h)?d=h.size():Array.isArray(h)?(h=t(h),d=h.size()):d=[],d.length){case 0:return ut(h);case 1:if(d[0]===1)return ut(h.valueOf()[0]);if(d[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+ct(d)+")");case 2:{var p=d[0],v=d[1];if(p===v)return f(h.clone().valueOf(),p);if(v===0)return 1;throw new RangeError("Matrix must be square (size: "+ct(d)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(d)+")")}}});function f(c,h,d){if(h===1)return ut(c[0][0]);if(h===2)return r(n(c[0][0],c[1][1]),n(c[1][0],c[0][1]));for(var p=!1,v=new Array(h).fill(0).map((B,M)=>M),x=0;x<h;x++){var _=v[x];if(a(c[_][x])){var y=void 0;for(y=x+1;y<h;y++)if(!a(c[v[y]][x])){_=v[y],v[y]=v[x],v[x]=_,p=!p;break}if(y===h)return c[_][x]}for(var m=c[_][x],w=x===0?1:c[v[x-1]][x-1],D=x+1;D<h;D++)for(var C=v[D],b=x+1;b<h;b++)c[C][b]=i(r(n(c[C][b],m),n(c[C][x],c[_][b])),w)}var F=c[v[h-1]][h-1];return p?u(F):F}}),af="inv",cx=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],fx=xe(af,cx,s=>{var{typed:e,matrix:t,divideScalar:r,addScalar:n,multiply:i,unaryMinus:a,det:u,identity:f,abs:c}=s;return e(af,{"Array | Matrix":function(p){var v=mt(p)?p.size():Lt(p);switch(v.length){case 1:if(v[0]===1)return mt(p)?t([r(1,p.valueOf()[0])]):[r(1,p[0])];throw new RangeError("Matrix must be square (size: "+ct(v)+")");case 2:{var x=v[0],_=v[1];if(x===_)return mt(p)?t(h(p.valueOf(),x,_),p.storage()):h(p,x,_);throw new RangeError("Matrix must be square (size: "+ct(v)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(v)+")")}},any:function(p){return r(1,p)}});function h(d,p,v){var x,_,y,m,w;if(p===1){if(m=d[0][0],m===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,m)]]}else if(p===2){var D=u(d);if(D===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(d[1][1],D),r(a(d[0][1]),D)],[r(a(d[1][0]),D),r(d[0][0],D)]]}else{var C=d.concat();for(x=0;x<p;x++)C[x]=C[x].concat();for(var b=f(p).valueOf(),F=0;F<v;F++){var B=c(C[F][F]),M=F;for(x=F+1;x<p;)c(C[x][F])>B&&(B=c(C[x][F]),M=x),x++;if(B===0)throw Error("Cannot calculate inverse, determinant is zero");x=M,x!==F&&(w=C[F],C[F]=C[x],C[x]=w,w=b[F],b[F]=b[x],b[x]=w);var O=C[F],A=b[F];for(x=0;x<p;x++){var N=C[x],T=b[x];if(x!==F){if(N[F]!==0){for(y=r(a(N[F]),O[F]),_=F;_<v;_++)N[_]=n(N[_],i(y,O[_]));for(_=0;_<v;_++)T[_]=n(T[_],i(y,A[_]))}}else{for(y=O[F],_=F;_<v;_++)N[_]=r(N[_],y);for(_=0;_<v;_++)T[_]=r(T[_],y)}}}return b}}}),uf="pinv",hx=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],dx=xe(uf,hx,s=>{var{typed:e,matrix:t,inv:r,deepEqual:n,equal:i,dotDivide:a,dot:u,ctranspose:f,divideScalar:c,multiply:h,add:d,Complex:p}=s;return e(uf,{"Array | Matrix":function(D){var C=mt(D)?D.size():Lt(D);switch(C.length){case 1:return m(D)?f(D):C[0]===1?r(D):a(f(D),u(D,D));case 2:{if(m(D))return f(D);var b=C[0],F=C[1];if(b===F)try{return r(D)}catch(B){if(!(B instanceof Error&&B.message.match(/Cannot calculate inverse, determinant is zero/)))throw B}return mt(D)?t(v(D.valueOf(),b,F),D.storage()):v(D,b,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(C)+")")}},any:function(D){return i(D,0)?ut(D):c(1,D)}});function v(w,D,C){var{C:b,F}=_(w,D,C),B=h(r(h(f(b),b)),f(b)),M=h(f(F),r(h(F,f(F))));return h(M,B)}function x(w,D,C){for(var b=ut(w),F=0,B=0;B<D;B++){if(C<=F)return b;for(var M=B;y(b[M][F]);)if(M++,D===M&&(M=B,F++,C===F))return b;[b[M],b[B]]=[b[B],b[M]];for(var O=b[B][F],A=0;A<C;A++)b[B][A]=a(b[B][A],O);for(var N=0;N<D;N++)if(N!==B){O=b[N][F];for(var T=0;T<C;T++)b[N][T]=d(b[N][T],h(-1,h(O,b[B][T])))}F++}return b}function _(w,D,C){var b=x(w,D,C),F=w.map((M,O)=>M.filter((A,N)=>N<D&&!y(u(b[N],b[N])))),B=b.filter((M,O)=>!y(u(b[O],b[O])));return{C:F,F:B}}function y(w){return i(d(w,p(1,1)),d(0,p(1,1)))}function m(w){return n(d(w,p(1,1)),d(h(w,0),p(1,1)))}}),px="divide",_x=["typed","matrix","multiply","equalScalar","divideScalar","inv"],vx=xe(px,_x,s=>{var{typed:e,matrix:t,multiply:r,equalScalar:n,divideScalar:i,inv:a}=s,u=Ha({typed:e,equalScalar:n}),f=ja({typed:e});return e("divide",Fl({"Array | Matrix, Array | Matrix":function(h,d){return r(h,a(d))},"DenseMatrix, any":function(h,d){return f(h,d,i,!1)},"SparseMatrix, any":function(h,d){return u(h,d,i,!1)},"Array, any":function(h,d){return f(t(h),d,i,!1).valueOf()},"any, Array | Matrix":function(h,d){return r(h,a(d))}},i.signatures))}),lf="sum",gx=["typed","config","add","numeric"],mx=xe(lf,gx,s=>{var{typed:e,config:t,add:r,numeric:n}=s;return e(lf,{"Array | Matrix":i,"Array | Matrix, number | BigNumber":a,"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function sum");return i(f)}});function i(u){var f;return as(u,function(c){try{f=f===void 0?c:r(f,c)}catch(h){throw Ln(h,"sum",c)}}),f===void 0&&(f=n(0,t.number)),typeof f=="string"&&(f=n(f,t.number)),f}function a(u,f){try{var c=Wa(u,f,r);return c}catch(h){throw Ln(h,"sum")}}}),cf="median",xx=["typed","add","divide","compare","partitionSelect"],yx=xe(cf,xx,s=>{var{typed:e,add:t,divide:r,compare:n,partitionSelect:i}=s;function a(c){try{c=Ia(c.valueOf());var h=c.length;if(h===0)throw new Error("Cannot calculate median of an empty array");if(h%2===0){for(var d=h/2-1,p=i(c,d+1),v=c[d],x=0;x<d;++x)n(c[x],v)>0&&(v=c[x]);return f(v,p)}else{var _=i(c,(h-1)/2);return u(_)}}catch(y){throw Ln(y,"median")}}var u=e({"number | BigNumber | Complex | Unit":function(h){return h}}),f=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(h,d){return r(t(h,d),2)}});return e(cf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(h,d){throw new Error("median(A, dim) is not yet supported")},"...":function(h){if(ro(h))throw new TypeError("Scalar values expected in function median");return a(h)}})}),Dx={},wx=Object.freeze({__proto__:null,default:Dx}),bx=Mt(wx),po=Dv({config:Er}),Ya=Av({}),Za=Mv({}),Va=Ov({}),cn=$v({Matrix:Va}),Ie=E_({BigNumber:po,Complex:Ya,DenseMatrix:cn,Fraction:Za}),Ex=dg({typed:Ie}),_o=_g({typed:Ie}),Ax=ig({BigNumber:po,typed:Ie}),ff=rm({typed:Ie}),Pn=Zv({config:Er,typed:Ie}),vo=Pv({typed:Ie}),Cx=Uv({typed:Ie}),go=Vg({typed:Ie}),hf=tg({typed:Ie}),Ga=Kv({Matrix:Va,equalScalar:Pn,typed:Ie}),df=gg({typed:Ie}),pf=Hv({typed:Ie}),Ka=fg({typed:Ie}),_f=ag({Fraction:Za,typed:Ie}),vf=zv({typed:Ie}),Pt=lg({DenseMatrix:cn,Matrix:Va,SparseMatrix:Ga,typed:Ie}),gf=bm({isNaN:pf,isNumeric:vf,typed:Ie}),us=Bm({bignumber:Ax,fraction:_f,number:hf}),Fx=Am({config:Er,multiplyScalar:go,numeric:us,typed:Ie}),Bx=_m({isInteger:vo,matrix:Pt,typed:Ie}),mf=gm({matrix:Pt,config:Er,typed:Ie}),xf=xm({matrix:Pt,typed:Ie}),ni=im({isInteger:vo,matrix:Pt,typed:Ie}),Mx=om({prod:Fx,size:mf,typed:Ie}),Nx=Dm({conj:ff,transpose:xf,typed:Ie}),ls=Nm({numeric:us,typed:Ie}),Sx=Im({DenseMatrix:cn,concat:ni,divideScalar:ls,equalScalar:Pn,matrix:Pt,typed:Ie}),yf=km({DenseMatrix:cn,concat:ni,equalScalar:Pn,matrix:Pt,typed:Ie}),Df=um({BigNumber:po,DenseMatrix:cn,SparseMatrix:Ga,config:Er,matrix:Pt,typed:Ie}),Ox=cm({matrix:Pt,multiplyScalar:go,typed:Ie}),Tx=Um({DenseMatrix:cn,concat:ni,config:Er,matrix:Pt,typed:Ie}),Ix=Qg({DenseMatrix:cn,concat:ni,equalScalar:Pn,matrix:Pt,subtractScalar:df,typed:Ie,unaryMinus:Ka}),cs=rx({DenseMatrix:cn,SparseMatrix:Ga,addScalar:_o,concat:ni,equalScalar:Pn,matrix:Pt,typed:Ie}),wf=Rm({BigNumber:po,DenseMatrix:cn,Fraction:Za,concat:ni,config:Er,equalScalar:Pn,matrix:Pt,typed:Ie}),$x=Vm({equal:yf,typed:Ie}),bf=ix({addScalar:_o,conj:ff,multiplyScalar:go,size:mf,typed:Ie}),Rx=jm({DenseMatrix:cn,concat:ni,config:Er,matrix:Pt,typed:Ie}),Xa=ex({config:Er,numeric:us,smaller:Tx,typed:Ie}),Bi=Kg({addScalar:_o,dot:bf,equalScalar:Pn,matrix:Pt,multiplyScalar:go,typed:Ie}),Lx=Km({compare:wf,isNaN:pf,isNumeric:vf,typed:Ie}),Px=mx({add:cs,config:Er,numeric:us,typed:Ie}),kx=ax({add:cs,matrix:Pt,typed:Ie}),Ef=lx({divideScalar:ls,isZero:Cx,matrix:Pt,multiply:Bi,subtractScalar:df,typed:Ie,unaryMinus:Ka}),zx=Qm({config:Er,larger:Rx,numeric:us,typed:Ie}),mo=fx({abs:Ex,addScalar:_o,det:Ef,divideScalar:ls,identity:Df,matrix:Pt,multiply:Bi,typed:Ie,unaryMinus:Ka}),qx=dx({Complex:Ya,add:cs,ctranspose:Nx,deepEqual:$x,divideScalar:ls,dot:bf,dotDivide:Sx,equal:yf,inv:mo,matrix:Pt,multiply:Bi,typed:Ie}),Ux=Om({Complex:Ya,config:Er,fraction:_f,identity:Df,inv:mo,matrix:Pt,multiply:Bi,number:hf,typed:Ie}),Wx=vx({divideScalar:ls,equalScalar:Pn,inv:mo,matrix:Pt,multiply:Bi,typed:Ie}),Af=yx({add:cs,compare:wf,divide:Wx,partitionSelect:Lx,typed:Ie});class Hx{constructor(e,t,r){U(this,"_cacheData");U(this,"_variables");U(this,"_math");U(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}alma({series:e,length:t,offset:r,sigma:n,floor:i},a){if(t===void 0||r===void 0||n===void 0)return;const u=this._cacheDataList(e,t,`alma_${a}`);if(u===void 0)return;let f=r*(t-1);i&&(f=Math.floor(f));const c=t/n;let h=0,d=0;for(let p=0;p<=t-1;p++){const v=Math.exp(-1*Math.pow(p-f,2)/(2*Math.pow(c,2)));h+=v,d+=u[u.length-1-(t-p-1)]*v}return d/h}sma({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const i=this._cacheDataList(e,t,`sma_${r}`);if(i===void 0)return;const a=i.slice(-t);return n=Px(...a)/t,n}rma({source:e,length:t},r){if(e===void 0||t===void 0||isNaN(e))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=e,this._cacheData[`sma_${r}`]=n;const{sum:i}=this._cacheData[`rma_${r}`]||{},a=1/t,u=i===void 0?this.sma({source:e,length:t},r):a*e+(1-a)*(i||0);return this._cacheDataHandle(`rma_${r}`,{sum:u}),u}atr({length:e},t){const{high:r,close:n}=this._cacheData[`atr_${t}`]||{},{high:i,close:a,low:u}=this._variables,f=r===void 0?i-u:Math.max(Math.max(i-u,Math.abs(i-n)),Math.abs(u-n));return this._cacheDataHandle(`atr_${t}`,{high:i,close:a}),this.rma({source:f,length:e},t)}barssince({condition:e},t){let{count:r}=this._cacheData[`barssince_${t}`]||{};if(e)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${t}`,{count:r}),r}stdev({source:e,length:t,biased:r=!0},n){if(e===void 0||isNaN(e)||t===void 0)return;const i=this._cacheDataList(e,t,`stdev_${n}`),a=this.sma({source:e,length:t},n);if(i===void 0)return;let u=0;for(let f=0;f<t;f++){const c=this._sum(i[i.length-1-f],-(a||0));u+=c*c}return r||t<=1?Math.sqrt(u/t):Math.sqrt(u/(t-1))}_sum(e,t){let n=e+t;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:e,length:t,mult:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const i=this.sma({source:e,length:t},n),a=this.stdev({source:e,length:t},n);if(i===void 0||a===void 0)return[];const u=r*a;return[i,i+u,i-u]}bbw({series:e,length:t,mult:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const i=this.sma({source:e,length:t},n),a=this.stdev({source:e,length:t},n);if(i===void 0||a===void 0)return;const u=r*a;return(i+u-(i-u))/i}cci({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t},r),i=this.dev({source:e,length:t},r);if(!(n===void 0||i===void 0))return(e-n)/(.015*i)}change({source:e,length:t=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=e,this._cacheData[`change_${r}`]=n;const i=n[n.length-1-t];if(!(e===void 0||isNaN(e)))return i===void 0?i:typeof e=="boolean"?i!==e:e-i}cmo({series:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.change({source:e},r);if(n===void 0)return;const i=this._math.sum({source:n>=0?n:0,length:t},`sm1_${r}`),a=this._math.sum({source:n>=0?0:-n,length:t},`sm2_${r}`);if(!(i===void 0||a===void 0))return 100*(i-a)/(i+a)}cog({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${r}`),i=this._math.sum({source:e,length:t},r);if(i===void 0||n===void 0)return;let a=0;for(let u=0;u<t;u++){const f=n[n.length-1-u];a+=f*(u+1)}return-a/i}correlation({source1:e,source2:t,length:r},n){if(e===void 0||isNaN(e)||t===void 0||isNaN(t)||r===void 0)return;const i=this._cacheDataList([e,t],r,`correlation_${n}`),a=this.sma({source:e,length:r},`sma1_${n}`),u=this.sma({source:t,length:r},`sma2_${n}`);if(a===void 0||u===void 0||i===void 0)return;let f=0,c=0,h=0;for(let p=0;p<r;p++){const[v,x]=i[i.length-1-p],_=v-a,y=x-u;f+=_*y,c+=_*_,h+=y*y}return isNaN(c)||isNaN(f)||isNaN(h)?void 0:f/Math.sqrt(c*h)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n>=i&&e<t||n<=i&&e>t}crossover({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n<=i&&e>t}crossunder({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n>=i&&e<t}cum({source:e=0},t){e=isNaN(e)?0:e;let{sum:r}=this._cacheData[`cum_${t}`]||{};return r=r||0,r+=e,this._cacheDataHandle(`cum_${t}`,{sum:r}),r}dev({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t},r);let i=0;const a=this._cacheDataList(e,t,`dev_${r}`);if(!(!a||n===void 0)){for(let u=0;u<t;u++){const f=a[a.length-1-u];i+=Math.abs(f-n)}return i/t}}dmi({diLength:e,adxSmoothing:t},r){if(e===void 0||t===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:i,high:a,close:u,PDMS:f,NDMS:c,TRS:h,ADX:d,count:p=0}=this._cacheData[n]||{},{low:v,high:x,close:_}=this._variables;if(i===void 0||a===void 0||u===void 0)return this._cacheData[n]={low:v,high:x,close:_,PDMS:f,NDMS:c,TRS:x-v,count:1},[void 0,void 0,void 0];let y=x-a,m=i-v;y=y>m&&y>0?y:0,m=m>y&&m>0?m:0,y===m&&(y=m=0);const w=Math.max(x-v,Math.abs(x-u),Math.abs(v-u));if(p<e)return this._cacheDataHandle(n,{low:v,high:x,close:_,PDMS:(f||0)+y,NDMS:(c||0)+m,TRS:(h||0)+w,count:p+1}),[void 0,void 0,void 0];{const D=f-f/e+y,C=c-c/e+m,b=h-h/e+w,F=D/b*100,B=C/b*100,M=Math.abs((F-B)/(F+B))*100;let O=M,A=[F,B,void 0];if(p+1-e<t){const N=p+1-e;O=((d||0)*(N-1)+M)/N}else O=(d*(t-1)+M)/t,A=[F,B,O];return this._cacheDataHandle(n,{low:v,high:x,close:_,PDMS:D,NDMS:C,TRS:b,ADX:O,count:p+1}),A}}ema({source:e,length:t},r){if(e===void 0||t===void 0||isNaN(e))return;let{sum:n,count:i=1}=this._cacheData[`ema_${r}`]||{};const a=this.sma({source:e,length:t},r);if(i>t){const u=2/(t+1);n=n===void 0?e:u*e+(1-u)*(n||0)}else n=a;return i+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:i}),n}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const{source:n,fallings:i=[]}=this._cacheData[`falling_${r}`]||{};i.push(n>e);const a=i.slice(-t);return this._cacheDataHandle(`falling_${r}`,{source:e,fallings:a}),a.length<t?!1:a.every(u=>u)}rising({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const{source:n,risings:i=[]}=this._cacheData[`rising_${r}`]||{};i.push(n<e);const a=i.slice(-t);return this._cacheDataHandle(`rising_${r}`,{source:e,risings:a}),a.length<t?!1:a.every(u=>u)}highest({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`highest_${r}`]=n;const u=n.filter(()=>!0);if(!(u.length<t))return Math.max(...u.slice(-t))}highestbars({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`highestbars_${r}`]=n;const u=n.filter(()=>!0);return u.length<t?void 0:u.slice(-t).reduce((c,h,d,p)=>h>=p[c]?d:c,0)-t+1}wma({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${r}`);if(!n)return;let i=0,a=0;for(let u=0;u<t;u++){const f=(t-u)*t;i+=f,a+=n[n.length-1-u]*f}return a/i}hma({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t},r),i=this.wma({source:e,length:Math.round(t/2)},r);return n===void 0||i===void 0?void 0:this.wma({source:2*i-n,length:Math.floor(Math.sqrt(t))},`hma_${r}`)}kc({series:e,length:t,mult:r,useTrueRange:n=!0},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[void 0,void 0,void 0];const a=this.ema({source:e,length:t},i),{ta:u,high:f,low:c}=this._variables,h=n?u.tr:f-c,d=this.ema({source:h,length:t},`range_${i}`);return[a,a+d*r,a-d*r]}kcw({series:e,length:t,mult:r,useTrueRange:n=!0},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const a=this.ema({source:e,length:t},i),{ta:u,high:f,low:c}=this._variables,h=n?u.tr:f-c,d=this.ema({source:h,length:t},`range_${i}`);return(a+d*r-(a-d*r))/a}linreg({source:e,length:t,offset:r},n){if(t===void 0||r===void 0)return;const i=this._cacheDataList(e,t,`dev_${n}`);if(!i)return;const a=i.slice(-t).filter(v=>v!==void 0);let u=0,f=0,c=0,h=0;for(const[v,x]of a.entries())u+=v,f+=x,c+=v*x,h+=v*v;const d=(t*c-u*f)/(t*h-u*u);return(f-d*u)/t+d*(t-1-r)}lowest({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`lowest_${r}`]=n;const u=n.filter(()=>!0);if(!(u.length<t))return Math.min(...u.slice(-t))}lowestbars({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`lowestbars_${r}`]=n;const u=n.filter(()=>!0);return u.length<t?void 0:u.slice(-t).reduce((c,h,d,p)=>h<=p[c]?d:c,0)-t+1}macd({source:e,fastlen:t,slowlen:r,siglen:n},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const a=this.ema({source:e,length:t},`ema1_${i}`),u=this.ema({source:e,length:r},`ema2_${i}`);if(a===void 0||u===void 0)return[void 0,void 0,void 0];const f=a-u,c=this.ema({source:f,length:n},`macd_${i}`);if(c===void 0)return[f,c,void 0];const h=f-c;return[f,c,h]}max({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`max_${t}`]||0;return e>r&&(r=e),this._cacheData[`max_${t}`]=r,r}min({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`min_${t}`]||1/0;return e<r&&(r=e),this._cacheData[`min_${t}`]=r,r}median({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${r}`);if(n)return Af(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:n}=this._variables,i=this.change({source:e},r),a=this._math.sum({source:n*(i>=0?0:e),length:t},`lower_${r}`),u=this._math.sum({source:n*(i<=0?0:e),length:t},`upper_${r}`);if(!(u===void 0||a===void 0))return 100-100/(1+u/a)}mode({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${r}`);if(n)return Xa(gf(n.slice(-t)))}mom({source:e,length:t},r){if(t===void 0||t<0)return;const n=`mom_${r}`,i=this._cacheData[n]||[];if(i[this._variables.bar_index]=e,this._cacheData[n]=i,i.length<=t||e===void 0||isNaN(e))return;let a=i.length-t-1,u;for(;u===void 0&&a>=0;)u=i[a],a--;return u===void 0?u:e-u}percentile_linear_interpolation({source:e,length:t,percentage:r},n){if(t===void 0||r===void 0||t<0||r<0||r>100)return;const i=this._cacheDataList(e,t+1,`percentile_linear_interpolation_${n}`);if(!i)return;const a=this._sort(i.slice(-(t+1))),u=a.length;r/=100;const f=1/(u*2);if(r<=f)return a[0];if(r>=1-1/(u*2))return a[u-1];for(const[c,h]of a.entries()){const d=a[c-1];if(r<(c+.5)/u)return d===void 0||h===void 0?void 0:d+(h-d)*(r-(c-.5)/u)/(1/u)}}percentile_nearest_rank({source:e,length:t,percentage:r},n){if(t===void 0||r===void 0||e===void 0||isNaN(e)||t<0||r<0||r>100)return;const i=this._cacheDataList(e,t,`percentile_nearest_rank_${n}`);if(!i)return;const a=this._sort(i.slice(-t)),u=r/100*a.length,f=Math.ceil(u)-1;return a[f>=a.length?a.length-1:f]}percentrank({source:e,length:t},r){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${r}`);if(!n)return;const i=n.slice(-(t+1)),a=e;if(a===void 0)return;let u=0;for(let f=0;f<i.length;f++)i[f]!==void 0&&(i[f]<a||i[f]===a&&f<t)&&u++;return u/(i.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},n){const i=new it;let{close:a,open:u,low:f,high:c}=this._variables;const h=`pivot_point_levels_${n}`,{close:d,low:p,high:v,open:x,result:_}=this._cacheData[h]||{};if(!t&&(v&&p&&(c=Math.max(v,c),f=Math.min(p,f)),this._cacheDataHandle(h,{close:a,open:u,low:f,high:c,result:_}),!r))return i._value=_||[],i;const y={close:a,open:u,low:f,high:c};t===!0&&!r&&(a=d,u=x,f=p,c=v);const m=this._getPivotPointLevels(c,f,a,u,r,e);return this._cacheDataHandle(h,{...y,result:m}),i._value=m,i}_getPivotPointLevels(e,t,r,n,i,a){if(r===void 0||n===void 0||t===void 0||e===void 0)return[];switch(a){case ei.traditional:return this._traditional(e,t,r);case ei.fibonacci:return this._fibonacci(e,t,r);case ei.woodie:return i?[]:this._woodie(e,t);case ei.classic:return this._classic(e,t,r);case ei.dm:return this._DM(e,t,r,n);case ei.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const n=(e+t+r)/3,i=n*2-t,a=n+(e-t),u=n*2+(e-2*t),f=n*3+(e-3*t),c=n*4+(e-4*t),h=n*2-e,d=n-(e-t),p=n*2-(2*e-t),v=n*3-(3*e-t),x=n*4-(4*e-t);return[n,i,h,a,d,u,p,f,v,c,x]}_fibonacci(e,t,r){const n=(e+t+r)/3,i=n+.382*(e-t),a=n-.382*(e-t),u=n+.618*(e-t),f=n-.618*(e-t),c=n+(e-t),h=n-(e-t);return[n,i,a,u,f,c,h]}_woodie(e,t){const{open:r}=this._variables,n=(e+t+2*r)/4,i=2*n-t,a=2*n-e,u=n+(e-t),f=n-(e-t),c=e+2*(n-t),h=t-2*(e-n),d=c+(e-t),p=h-(e-t);return[n,i,a,u,f,c,h,d,p]}_classic(e,t,r){const n=(e+t+r)/3,i=2*n-t,a=2*n-e,u=n+(e-t),f=n-(e-t),c=n+2*(e-t),h=n-2*(e-t),d=n+3*(e-t),p=n-3*(e-t);return[n,i,a,u,f,c,h,d,p]}_DM(e,t,r,n){let i;n===r?i=e+t+2*r:r>n?i=2*e+t+r:i=2*t+e+r;const a=i/4,u=i/2-t,f=i/2-e;return[a,u,f]}_camarilla(e,t,r){const n=(e+t+r)/3,i=r+1.1*(e-t)/12,a=r-1.1*(e-t)/12,u=r+1.1*(e-t)/6,f=r-1.1*(e-t)/6,c=r+1.1*(e-t)/4,h=r-1.1*(e-t)/4,d=r+1.1*(e-t)/2,p=r-1.1*(e-t)/2,v=e/t*r,x=r-(v-r);return[n,i,a,u,f,c,h,d,p,v,x]}pivothigh({source:e=this._variables.high,leftbars:t,rightbars:r},n){if(t===void 0||r===void 0||t<0||r<0)return;const i=this._cacheDataList(e,t+r+1,`pivothigh_${n}`);if(!i)return;const a=i.slice(-(t+r+1)),u=a[t];return Math.max(...a)===u?u:void 0}pivotlow({source:e=this._variables.low,leftbars:t,rightbars:r},n){if(t===void 0||r===void 0||t<0||r<0)return;const i=this._cacheDataList(e,t+r+1,`pivotlow_${n}`);if(!i)return;const a=i.slice(-(t+r+1)),u=a[t];return Math.min(...a)===u?u:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._cacheDataList(e,t,`range_${r}`);if(!n)return;const i=n.filter(f=>f!==void 0).slice(-t),a=Math.max(...i),u=Math.min(...i);return a-u}roc({source:e,length:t},r){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${r}`),i=this.change({source:e,length:t},r);if(n)return 100*i/n[n.length-1-t]}rsi({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},i=Math.max(e-n,0),a=Math.max(n-e,0),u=this.rma({source:i,length:t},`rma1_${r}`),f=this.rma({source:a,length:t},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:e}),!(u===void 0||f===void 0))return 100-100/(1+u/f)}sar({start:e,inc:t,max:r},n){if(e===void 0||t===void 0||r===void 0)return;const{close:i,low:a,high:u,preLow:f,preHigh:c,data:h={}}=this._cacheData[`sar_${n}`]||{};let{result:d,maxMin:p,acceleration:v,isBelow:x}=h,_=!1;const{close:y,low:m,high:w,bar_index:D}=this._variables;return D===1&&(y>i?(x=!0,p=w,d=a):(x=!1,p=m,d=u),_=!0,v=e),d=d+v*(p-d),x?d>m&&(_=!0,x=!1,d=Math.max(w,p||0),p=m,v=e):d<w&&(_=!0,x=!0,d=Math.min(m,p||0),p=w,v=e),_||(x?w>(p||0)&&(p=w,v=Math.min((v||0)+t,r)):m<(p||0)&&(p=m,v=Math.min((v||0)+t,r))),x?(d=Math.min(d,a),D>1&&(d=Math.min(d,f))):(d=Math.max(d,u),D>1&&(d=Math.max(d,c))),this._cacheDataHandle(`sar_${n}`,{high:w,close:y,low:m,preLow:a,preHigh:u,data:Object.assign(h,{result:d,maxMin:p,acceleration:v,isBelow:x})}),d}stoch({source:e,high:t,low:r,length:n},i){if(n===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||n<0)return;const a=this.lowest({source:r,length:n},i),u=this.highest({source:t,length:n},i);if(!(a===void 0||u===void 0))return 100*(this._variables.close-a)/(u-a)}supertrend({factor:e,atrPeriod:t},r){if(e===void 0||t===void 0)return[void 0,void 0];const{hl2:n,close:i}=this._variables,a=`supertrend_${r}`,{upperBand:u,lowerBand:f,superTrend:c,atr:h,close:d}=this._cacheData[a]||{},p=this.atr({length:t},r);if(p===void 0)return this._cacheDataHandle(a,{close:i}),[void 0,void 0];let v=n+e*p,x=n-e*p;const _=u||0,y=f||0;x=x>y||d<y?x:y,v=v<_||d>_?v:_;let m;h===void 0?m=1:c===_?m=i>v?-1:1:m=i<x?1:-1;const w=m===-1?x:v;return this._cacheDataHandle(a,{upperBand:v,lowerBand:x,superTrend:w,atr:p,close:i}),[w,m]}swma({source:e},t){let{list:r}=this._cacheData[`swma_${t}`]||{};if(r||(r=[]),r.push(e),r=r.slice(-4),this._cacheDataHandle(`swma_${t}`,{list:r}),!(r.filter(n=>n!==void 0).length<4))return r[3]*1/6+r[2]*2/6+r[1]*2/6+r[0]*1/6}tr({handle_na:e=!1},t){const{close:r,low:n,high:i}=this._variables,{close:a}=this._cacheData[`tr_${t}`]||{};return this._cacheDataHandle(`tr_${t}`,{close:r}),a===void 0?e?i-n:void 0:Math.max(i-n,Math.abs(i-a),Math.abs(n-a))}tsi({source:e,short_length:t,long_length:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const i=this.change({source:e},n);if(i===void 0)return;const a=this.ema({source:Math.abs(i),length:t},`absema1_${n}`),u=this.ema({source:i,length:t},`ema1_${n}`);if(u===void 0)return;const f=this.ema({source:u,length:r},`ema2_${n}`),c=this.ema({source:a,length:t},`absema2_${n}`);if(f!==void 0)return f/c}valuewhen({condition:e,source:t,occurrence:r},n){if(t===void 0||r===void 0||r<0)return;let{list:i}=this._cacheData[`valuewhen_${n}`]||{};return i||(i=[]),e&&i.push(t),this._cacheDataHandle(`valuewhen_${n}`,{list:i}),i[i.length-1-r]}variance({source:e,length:t,biased:r=!0},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const i=this.sma({source:e,length:t},n),a=this._cacheDataList(e,t,`mode_${n}`);if(!a||i===void 0)return;const u=a.filter(c=>c!==void 0&&!isNaN(c)).slice(-t);if(u.length<t)return;const f=u.reduce((c,h)=>c+Math.pow(h-i,2),0);if(f!==void 0)return r||t<=1?f/t:f/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},n){if(e===void 0)return;t=t===void 0?this._timeframe.change({timeframe:"1D"},n):t;const{volume:i}=this._variables;let{sum:a=0,sumV:u=0,count:f=0,isReset:c,sumS:h=0}=this._cacheData[`vwap_${n}`]||{};if(t&&(a=u=f=h=0,c=!0),!c)return r!==void 0?[]:void 0;const d=e*i+a,p=i+u,v=d/p;return f++,r!==void 0?(h=i*Math.pow(e,2)+h,this._cacheDataHandle(`vwap_${n}`,{sum:d,sumV:p,count:f,isReset:c,sumS:h}),this._computeBands(h,p,r,v)):(this._cacheDataHandle(`vwap_${n}`,{sum:d,sumV:p,count:f,isReset:c}),v)}_computeBands(e,t,r,n){let i=e/t-Math.pow(n,2);i=i<0?0:i;const a=Math.sqrt(i),u=a!==void 0&&!isNaN(a)?n+r*a:void 0,f=a!==void 0&&!isNaN(a)?n-r*a:void 0;return[n,u,f]}vwma({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0||t<=0)return;const{volume:n}=this._variables,i=this.sma({source:e*n,length:t},`sma1_${r}`),a=this.sma({source:n,length:t},`sma2_${r}`);if(!(i===void 0||a===void 0))return i/a}wpr({length:e},t){if(e===void 0||e<=0)return;const r=this.highest({length:e},t),n=this.lowest({length:e},t),{close:i}=this._variables;if(!(r===void 0||n===void 0))return(r-i)/(r-n)*-100}_sort(e){const t=e.length;for(let r=0;r<t;r++){let n={};for(let i=0;i<t-r;i++){const{currentVal:a,currentIndex:u}=n,f=e[i];if(f!==void 0){if(a!==void 0&&f<a){e.splice(i,1),e.splice(u,0,f),n={currentIndex:u+1,currentVal:a};continue}n={currentIndex:i,currentVal:f}}}}return e}_cacheDataList(e,t,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=e,this._cacheData[r]=n;const i=n.filter(()=>!0);if(!(i.length<t))return i}_cacheDataHandle(e,t){const{barIndex:r}=this._cacheData[e]||{};r!==this._variables.bar_index&&(this._cacheData[e]=Object.assign(t,{barIndex:this._variables.bar_index}))}}const Kt={onlyInLoop:"'$text' is only allowed inside loops",invalidType:"Invalid argument 'expr$index' in 'operator SQBR' call",typeUseError:"Cannot specify a type form '$text' without also specifying the type.",notTypeKeyword:"'$text' is not a valid type keyword in variable declaration",undeclared:"Undeclared identifier '$name'",repeatVar:"'$name' is already defined",typeRepeatErr:"$keyword '$name' is already defined.",typeMismatch:"Cannot call '$operator' with argument '$index'. An argument of '$typeE' type was used but a '$typeR' is expected.",assignTypeMismatch:"Cannot assign a value of the `$typeE` type to the '$name' variable. The variable is declared with the `$typeR` type.",voidNotVar:"Void expression cannot be assigned to a variable",declareTypeErr:"Declared type '$type' is not compatible with assigned type '$valueType'",mapKeyValErr:"Cannot put <$typeA, $typeB> pairs into a map containing `$typeC` keys and `$typeD` values. The maps passed into the `$name()` function must have the same key types and value types.",inputSourceErr:"Invalid value for the '$name' parameter of the '$funcName' function. Possible values: [open, high, low, close, hl2, hlc3, ohlc4, hlcc4, volume].",buildInUseErr:"Cannot use '$name' as the default value of a type's field. The default value cannot be a function, variable or calculation.",argsLenErr:"Too many arguments passed into the `$name()` function call. Passed $lenA arguments but expected $lenB.",requiredParamErr:"No value assigned to the `$argName` parameter in $name()",argsSyntaxErr:"Syntax error after the argument for `$argName`. Arguments without their parameter name cannot be used after arguments with parameter names.",requestArgsErr:"Type $type cannot be used in $name '$argName' argument",mapKeyErr:"Incorrect `key` type `$type` in the variable. The `key` type must be one of the following: int, float, string, bool, color.",templateErr:"Incorrect number of arguments for the template: $countA expected, $countB passed.",templateNoSupportErr:"The '$name()' function does not support templates",ifOrSwitchTypeErr:"Return type of one of the '$keyword' blocks is not compatible with return type of other block(s) ($types)",argsNameErr:"The '$name' function does not have an argument with the name '$argName'",noFiledErr:"Object has no field $name",methodNotExistErr:"Could not find method or method reference '$methodName' for '$name'",tupleVarErr:"Syntax error: The quantities of tuple elements on each side of the assignment operator do not match. The right side has $indexA but the left side has $indexB.",tupleLeftVarErr:"Invalid assignment. Cannot assign a tuple to a variable '$name'.",tupleRightVarErr:"Cannot assign a variable to a tuple. The right side must be a function call or structure ('if', 'switch', 'for', 'while') returning a tuple with the same number of elements.",tempateTypeErr:"Syntax error: Only templates for arrays and matrices consist of a single type identifier enclosed in angle brackets.",qualifierErr:"'$name' is not a valid type qualifier. Possible values: 'const', 'simple', 'series'",notFindFuncErr:"Could not find function or function reference '$name'",naVarErr:"Value with NA type cannot be assigned to a variable that was defined without type keyword",notHistoryErr:"Variable '$name' doesn't have history values",defaultValueErr:"The default value cannot be a function, variable or calculation.",defaultValueTypeErr:"Default value of type $typeE can not be assigned to an argument of type $typeR",typeFieldErr:"In a type declaration, all fields without a default value must be explicitly typified.",unaryErr:"Syntax error at input '$sign'",funcArgAssignErr:"Function arguments cannot be mutable ('$name')",declaredErr:"A variable declared with the '$prefix' keyword cannot accept values of the '$type' form. Assign a '$prefix' value to this variable or remove the '$prefix' keyword from its declaration.",globalFuncErr:"Cannot use '$name' in local scope",onlyStatementErr:"Scripts must contain one declaration statement: `indicator()`, `strategy()` or `library()`, Your script has $count.",modifyGlobalVarErr:"Cannot modify global variable '$name' in function",inputDefvalErr:"Arguments of input function must be of constant type, or 'source' builtin variables.",objectIsNaErr:"Cannot access the '$name' $type of an na object. The object is 'na'.",buidinAssignErr:"Cannot assign a new value to the built-in variable '$name'.",buidinVarErr:"Cannot shadow the built-in variable `$name` because it has already been used as a built-in.",useNaErr:"Cannot use an `na` value of an unspecified type in the `$name` function.",libraryTitleErr:"Invalid argument 'title' in 'library' call. It cannot contain spaces, special characters or begin with a digit.",exportFuncArgErr:"All exported functions args should be typified",indiRunErr:"An indicator must contain at least one of the following: any `plot*()` function, `barcolor()`, `bgcolor()`, `hline()`, `alertcondition()`, or any drawing (line, label, box, table, polyline).",libraryExportErr:"A library must contain at least one exported function, method, or type.",strategyRunErr:"A strategy must contain at least one of the following: any `strategy.*()` function that creates orders, any `plot*()` function, `barcolor()`, `bgcolor()`, `hline()`, or any drawing (line, label, box, table, polyline).",exportUseErr:"Only libraries can contain exported $type.",funcRepeatErr:"The '$name' function has overloads with the same parameters. The type of parameters must be different in overloaded versions of functions.",importMultipleErr:"Cannot import a library more than once",importNotExitErr:"The user '$username' does not have a published library titled '$libraryName'",importNameRepeatErr:"More than one import uses the same alias: $name. Previous usage at line: $line",exportFuncHasInputErr:"The exported function '$func' depends on the '$name' input variable, which is not allowed.",libraryTitleIsKeywordErr:"Invalid argument 'title' in 'library' call. Token: '$name' can't be used as library title.",exportFuncUseGlobalVarErr:"Cannot use global variables in exported functions. Function: $func",loopRuntimeErr:"Loop takes too long to execute (> 500 ms)",paramsErr:"Invalid value '$value' for '$param' parameter of the '$func' function. Possible values: $targetVal",displayErr:"Invalid argument 'display' in '$func' call. Possible values: $values",exportFuncUseReqErr:"Cannot use `request.*()` call in exported function `$name()`",requestExprErr:"Type series $type cannot be used in $name 'expression' argument",argDefaultErr:"The default value assigned to a parameter must be either a literal value (e.g., `5`) or a built-in variable (e.g., `close`)",overloadFuncErr:"Cannot use global variables or any values qualified as 'input' in the local scopes of overloaded functions or methods. Remove any global variables or inputs from the scopes of all '$name()' overloads.",againAssignErr:"Unable to determine the object for the field assignment. Try putting the object into a separate variable before assigning values to its fields.",requestUserInLoopErr:"Cannot use `request.*()` call within loops or conditional structures.",enumVarNameErr:"Invalid enum name '$name': `bool`, `int`, `float`, `string`, and `color` are not allowed.",enumVarNameBuiltinErr:"Invalid object name: $name. Namespaces of built-ins cannot be used.",typeNameErr:"Invalid user-defined type name '$name': `bool`, `int`, `float`, `string`, and `color` are not allowed.",enumUseErr:"Cannot use the '$name' as a value. Use one of the enum's fields instead.",conditionalErr:"'$name' conditional expression must be of a bool type!",fortoErr:'The value of the "for" loop must be a number.',indicatorUseStrategyFuncErr:"You cannot use strategy $type ($name) in indicator script."};an.SERIES,an.SIMPLE,an.INPUT,an.CONST,an.INT,an.FLOAT,an.BOOL,an.COLOR,an.STRING;const jx=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"],Yx=["case","catch","default","delete","do","finally","function","instanceof","new","return","this","throw","try","typeof","void","with"],Zx=["linefill","polyline","matrix","series","simple","string","array","color","const","float","label","table","bool","line","box","int","map","continue","for","varip","var","in","export","import","method","switch","break","while","else","type","and","for","not","as","by","if","in","or","to"];class Vx{constructor(e,t,r){U(this,"_cacheData");U(this,"_variables");U(this,"_errorListener");U(this,"_historyInputs");U(this,"_name");this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(e){for(const t of e){const r=t.id;this._cacheData[r]=Object.assign(this._cacheData[r]||{},{...t,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${t.index}`,{modifyDefval:t.sourceTypeName||t.defval})}}input(e,t){return this._cacheHandle(e,t)}int(e,t){return this._cacheHandle(e,t,ur.INT)}bool(e,t){return this._cacheHandle(e,t,ur.BOOL)}color(e,t){return this._cacheHandle(e,t,ur.COLOR)}time(e,t){return this._cacheHandle(e,t,ur.TIME)}float(e,t){return this._cacheHandle(e,t,ur.FLOAT)}price(e,t){return this._cacheHandle(e,t,ur.PRICE)}source(e,t){return this._cacheHandle(e,t,ur.SOURCE)}string(e,t){return this._cacheHandle(e,t,ur.STRING)}symbol(e,t){return this._cacheHandle(e,t,ur.SYMBOL)}session(e,t){return this._cacheHandle(e,t,ur.SESSION)}text_area(e,t){return this._cacheHandle(e,t,ur.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,ur.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,ur.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const n=`${r||"input"}_${t}`,i=this._cacheData[n];if(e.defval===void 0&&this._errorListener.addError(Kt.inputDefvalErr,t,Ve.Error),i)i.isModify?i.sourceTypeName&&(this._cacheData[n].defval=this._variables[i.sourceTypeName]):Object.assign(this._cacheData[n],e);else{const{defval:a,display:u}=e;this._displayVerify(t,u),e={inputType:r,...e},this._cacheData[n]=e,this._judgeHistoryInputs(e),(r||e.inputType)===ur.SOURCE?this._cacheData[n].options=jx:e.options&&!e.options.includes(a)&&this._errorListener.addError(`input's defval should be in options, but '${a}' is not in [${e.options.toString()}]`,t,Ve.Error,6+((r==null?void 0:r.length)||-1))}return this._cacheData[n].defval}_judgeHistoryInputs(e){const{defval:t,sourceTypeName:r,index:n}=e;let i=r||t;const a=`in_${n}`,u=this._historyInputs[a];if(!u)self.workerStorage.setValue(this._name,a,{defval:i});else{const{defval:f,modifyDefval:c}=u;f===i?i=c||i:self.workerStorage.setValue(this._name,a,{defval:i})}r?e.sourceTypeName=i:e.defval=i}_displayVerify(e,t){!t||!t.length||t.includes(Zt.dataWindow)||t.includes(Zt.statusLine)||this._errorListener.addError(or(Kt.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,Ve.Error)}getInputs(){const e=Object.keys(this._cacheData),t=[];for(const r of e){const n=this._cacheData[r];n.id=r,t.push(n)}return t.sort((r,n)=>(r.index||0)-(n.index||0))}}class Gx{color({x:e}){return e}new({color:e,transp:t=100}){me(t)&&(t=100);const r=(100-t)/100;if(e===void 0)return`defaultColor_${r}`;const{r:n,g:i,b:a}=this._parseColor(e);return`rgba(${Math.round(n)}, ${Math.round(i)}, ${Math.round(a)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:n=0}){return me(n)&&(n=0),me(e)&&(e=0),me(t)&&(t=0),me(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-n)/100})`}g({color:e}){return e?this._parseColor(e).g:0}r({color:e}){return e?this._parseColor(e).r:0}b({color:e}){return e?this._parseColor(e).b:0}t({color:e}){return e?Math.round(this._parseColor(e).a*100):0}from_gradient({value:e,bottom_value:t,top_value:r,bottom_color:n,top_color:i}){if(me(e)||me(t)||me(r))return"rgba(0,0,0,1)";const a=(e-t)/(r-t),u=Math.min(Math.max(a,0),1),{r:f,g:c,b:h,a:d}=this._parseColor(n||"rgba(0,0,0,0)"),{r:p,g:v,b:x,a:_}=this._parseColor(i||"rgba(0,0,0,0)"),y=f+u*(p-f),m=c+u*(v-c),w=h+u*(x-h),D=d+u*(_-d);return`rgba(${Math.round(y)}, ${Math.round(m)}, ${Math.round(w)}, ${D.toFixed(2)})`}_parseColor(e){let t,r,n,i;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);const a=e.substring(7);a?i=(255-parseInt(a,16))/255:i=1}else{const a=this._parserRgbColor(e);t=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:t,g:r,b:n,a:i}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}}var We={};const Kx=Object.prototype.toString;function fs(s){const e=Kx.call(s);return e.endsWith("Array]")&&!e.includes("Big")}var Xx=Object.freeze({__proto__:null,isAnyArray:fs}),Qx=Mt(Xx);function Jx(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!fs(s))throw new TypeError("input must be an array");if(s.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,n=e.toIndex,i=n===void 0?s.length:n;if(r<0||r>=s.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=r||i>s.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=s[r],u=r+1;u<i;u++)s[u]>a&&(a=s[u]);return a}function ey(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!fs(s))throw new TypeError("input must be an array");if(s.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,n=e.toIndex,i=n===void 0?s.length:n;if(r<0||r>=s.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=r||i>s.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=s[r],u=r+1;u<i;u++)s[u]<a&&(a=s[u]);return a}function ty(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(fs(s)){if(s.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var t;if(e.output!==void 0){if(!fs(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(s.length);var r=ey(s),n=Jx(s);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,a=i===void 0?e.autoMinMax?r:0:i,u=e.max,f=u===void 0?e.autoMinMax?n:1:u;if(a>=f)throw new RangeError("min option must be smaller than max option");for(var c=(f-a)/(n-r),h=0;h<s.length;h++)t[h]=(s[h]-r)*c+a;return t}var ry=Object.freeze({__proto__:null,default:ty}),ny=Mt(ry);Object.defineProperty(We,"__esModule",{value:!0});var gr=Qx,Cf=ny;const xo=" ".repeat(2),Ff=" ".repeat(4);function iy(){return Bf(this)}function Bf(s,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:n=8,padMinus:i="auto"}=e;return`${s.constructor.name} {
54
+ (`+ct(M,_)+", "+ct(C,_)+") ==> "+(this._values?ct(this._values[B],_):"X")}return D},n.prototype.toString=function(){return ct(this.toArray())},n.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(_){if(_){if(St(_)&&(_=_.toNumber()),!pt(_)||!bt(_))throw new TypeError("The parameter k must be an integer number")}else _=0;var y=_>0?_:0,m=_<0?-_:0,w=this._size[0],D=this._size[1],C=Math.min(w-m,D-y),b=[],F=[],B=[];B[0]=0;for(var M=y;M<D&&b.length<C;M++)for(var O=this._ptr[M],A=this._ptr[M+1],N=O;N<A;N++){var T=this._index[N];if(T===M-y+m){b.push(this._values[N]),F[b.length-1]=T-m;break}}return B.push(b.length),new n({values:b,index:F,ptr:B,size:[C,1]})},n.fromJSON=function(_){return new n(_)},n.diagonal=function(_,y,m,w,D){if(!Ct(_))throw new TypeError("Array expected, size parameter");if(_.length!==2)throw new Error("Only two dimensions matrix are supported");if(_=_.map(function(ee){if(St(ee)&&(ee=ee.toNumber()),!pt(ee)||!bt(ee)||ee<1)throw new Error("Size values must be positive integers");return ee}),m){if(St(m)&&(m=m.toNumber()),!pt(m)||!bt(m))throw new TypeError("The parameter k must be an integer number")}else m=0;var C=t,b=0;un(D)&&(C=e.find(t,[D,D])||t,b=e.convert(0,D));var F=m>0?m:0,B=m<0?-m:0,M=_[0],O=_[1],A=Math.min(M-B,O-F),N;if(Ct(y)){if(y.length!==A)throw new Error("Invalid value array length");N=function(te){return y[te]}}else if(mt(y)){var T=y.size();if(T.length!==1||T[0]!==A)throw new Error("Invalid matrix length");N=function(te){return y.get([te])}}else N=function(){return y};for(var R=[],k=[],z=[],L=0;L<O;L++){z.push(R.length);var G=L-F;if(G>=0&&G<A){var H=N(G);C(H,b)||(k.push(G+B),R.push(H))}}return z.push(R.length),new n({values:R,index:k,ptr:z,size:[M,O]})},n.prototype.swapRows=function(_,y){if(!pt(_)||!bt(_)||!pt(y)||!bt(y))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Ft(_,this._size[0]),Ft(y,this._size[0]),n._swapRows(_,y,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(_,y,m,w,D){for(var C=w[_],b=w[_+1],F=C;F<b;F++)D(m[F],y[F])},n._swapRows=function(_,y,m,w,D,C){for(var b=0;b<m;b++){var F=C[b],B=C[b+1],M=c(_,F,B,D),O=c(y,F,B,D);if(M<B&&O<B&&D[M]===_&&D[O]===y){if(w){var A=w[M];w[M]=w[O],w[O]=A}continue}if(M<B&&D[M]===_&&(O>=B||D[O]!==y)){var N=w?w[M]:void 0;D.splice(O,0,y),w&&w.splice(O,0,N),D.splice(O<=M?M+1:M,1),w&&w.splice(O<=M?M+1:M,1);continue}if(O<B&&D[O]===y&&(M>=B||D[M]!==_)){var T=w?w[O]:void 0;D.splice(M,0,_),w&&w.splice(M,0,T),D.splice(M<=O?O+1:O,1),w&&w.splice(M<=O?O+1:O,1)}}},n},{isClass:!0}),Xv="number",Qv=["typed"];function Jv(s){var e=s.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(e){var t={"0b":2,"0o":8,"0x":16}[e[1]],r=e[2],n=e[3];return{input:s,radix:t,integerPart:r,fractionalPart:n}}else return null}function eg(s){for(var e=parseInt(s.integerPart,s.radix),t=0,r=0;r<s.fractionalPart.length;r++){var n=parseInt(s.fractionalPart[r],s.radix);t+=n/Math.pow(s.radix,r+1)}var i=e+t;if(isNaN(i))throw new SyntaxError('String "'+s.input+'" is not a valid number');return i}var tg=xe(Xv,Qv,s=>{var{typed:e}=s,t=e("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var i=Jv(n);if(i)return eg(i);var a=0,u=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);u&&(a=Number(u[2]),n=u[1]);var f=Number(n);if(isNaN(f))throw new SyntaxError('String "'+n+'" is not a valid number');if(u){if(f>2**a-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));f>=2**(a-1)&&(f=f-2**a)}return f},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),null:function(n){return 0},"Unit, string | Unit":function(n,i){return n.toNumber(i)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),rg="bignumber",ng=["typed","BigNumber"],ig=xe(rg,ng,s=>{var{typed:e,BigNumber:t}=s;return e("bignumber",{"":function(){return new t(0)},number:function(n){return new t(n+"")},string:function(n){var i=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(i){var a=i[2],u=t(i[1]),f=new t(2).pow(Number(a));if(u.gt(f.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var c=new t(2).pow(Number(a)-1);return u.gte(c)?u.sub(f):u}return new t(n)},BigNumber:function(n){return n},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),Fraction:function(n){return new t(n.n).div(n.d).times(n.s)},null:function(n){return new t(0)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))})}),sg="fraction",og=["typed","Fraction"],ag=xe(sg,og,s=>{var{typed:e,Fraction:t}=s;return e("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new t(n)},string:function(n){return new t(n)},"number, number":function(n,i){return new t(n,i)},null:function(n){return new t(0)},BigNumber:function(n){return new t(n.toString())},Fraction:function(n){return n},Unit:e.referToSelf(r=>n=>{var i=n.clone();return i.value=r(n.value),i}),Object:function(n){return new t(n)},"Array | Matrix":e.referToSelf(r=>n=>Jr(n,r))})}),Mc="matrix",ug=["typed","Matrix","DenseMatrix","SparseMatrix"],lg=xe(Mc,ug,s=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:n}=s;return e(Mc,{"":function(){return i([])},string:function(u){return i([],u)},"string, string":function(u,f){return i([],u,f)},Array:function(u){return i(u)},Matrix:function(u){return i(u,u.storage())},"Array | Matrix, string":i,"Array | Matrix, string, string":i});function i(a,u,f){if(u==="dense"||u==="default"||u===void 0)return new r(a,f);if(u==="sparse")return new n(a,f);throw new TypeError("Unknown matrix type "+JSON.stringify(u)+".")}}),Nc="unaryMinus",cg=["typed"],fg=xe(Nc,cg,s=>{var{typed:e}=s;return e(Nc,{number:Dc,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var n=r.clone();return n.value=e.find(t,n.valueType())(r.value),n}),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Sc="abs",hg=["typed"],dg=xe(Sc,hg,s=>{var{typed:e}=s;return e(Sc,{number:gc,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),Oc="addScalar",pg=["typed"],_g=xe(Oc,pg,s=>{var{typed:e}=s;return e(Oc,{"number, number":mc,"Complex, Complex":function(r,n){return r.add(n)},"BigNumber, BigNumber":function(r,n){return r.plus(n)},"Fraction, Fraction":function(r,n){return r.add(n)},"Unit, Unit":e.referToSelf(t=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var i=r.clone();return i.value=e.find(t,[i.valueType(),n.valueType()])(i.value,n.value),i.fixPrefix=!1,i})})}),Tc="subtractScalar",vg=["typed"],gg=xe(Tc,vg,s=>{var{typed:e}=s;return e(Tc,{"number, number":xc,"Complex, Complex":function(r,n){return r.sub(n)},"BigNumber, BigNumber":function(r,n){return r.minus(n)},"Fraction, Fraction":function(r,n){return r.sub(n)},"Unit, Unit":e.referToSelf(t=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var i=r.clone();return i.value=e.find(t,[i.valueType(),n.valueType()])(i.value,n.value),i.fixPrefix=!1,i})})}),mg="matAlgo11xS0s",xg=["typed","equalScalar"],Ha=xe(mg,xg,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=t,m=0,w=a;typeof p=="string"&&(_=p,y=e.find(t,[_,_]),m=e.convert(0,_),i=e.convert(i,_),w=e.find(a,[_,_]));for(var D=[],C=[],b=[],F=0;F<x;F++){b[F]=C.length;for(var B=h[F],M=h[F+1],O=B;O<M;O++){var A=c[O],N=u?w(i,f[O]):w(f[O],i);y(N,m)||(C.push(A),D.push(N))}}return b[x]=C.length,n.createSparseMatrix({values:D,index:C,ptr:b,size:[v,x],datatype:_})}}),yg="matAlgo12xSfs",Dg=["typed","DenseMatrix"],Ci=xe(yg,Dg,s=>{var{typed:e,DenseMatrix:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=a;typeof p=="string"&&(_=p,i=e.convert(i,_),y=e.find(a,[_,_]));for(var m=[],w=[],D=[],C=0;C<x;C++){for(var b=C+1,F=h[C],B=h[C+1],M=F;M<B;M++){var O=c[M];w[O]=f[M],D[O]=b}for(var A=0;A<v;A++)C===0&&(m[A]=[]),D[A]===b?m[A][C]=u?y(i,w[A]):y(w[A],i):m[A][C]=u?y(i,0):y(0,i)}return new t({data:m,size:[v,x],datatype:_})}}),wg="matAlgo14xDs",bg=["typed"],ja=xe(wg,bg,s=>{var{typed:e}=s;return function(n,i,a,u){var f=n._data,c=n._size,h=n._datatype,d,p=a;typeof h=="string"&&(d=h,i=e.convert(i,d),p=e.find(a,[d,d]));var v=c.length>0?t(p,0,c,c[0],f,i,u):[];return n.createDenseMatrix({data:v,size:ut(c),datatype:d})};function t(r,n,i,a,u,f,c){var h=[];if(n===i.length-1)for(var d=0;d<a;d++)h[d]=c?r(f,u[d]):r(u[d],f);else for(var p=0;p<a;p++)h[p]=t(r,n+1,i,i[n+1],u[p],f,c);return h}}),Eg="matAlgo02xDS0",Ag=["typed","equalScalar"],Cg=xe(Eg,Ag,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a,u){var f=n._data,c=n._size,h=n._datatype||n.getDataType(),d=i._values,p=i._index,v=i._ptr,x=i._size,_=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(c.length!==x.length)throw new rt(c.length,x.length);if(c[0]!==x[0]||c[1]!==x[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+x+")");if(!d)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var y=c[0],m=c[1],w,D=t,C=0,b=a;typeof h=="string"&&h===_&&h!=="mixed"&&(w=h,D=e.find(t,[w,w]),C=e.convert(0,w),b=e.find(a,[w,w]));for(var F=[],B=[],M=[],O=0;O<m;O++){M[O]=B.length;for(var A=v[O],N=v[O+1],T=A;T<N;T++){var R=p[T],k=u?b(d[T],f[R][O]):b(f[R][O],d[T]);D(k,C)||(B.push(R),F.push(k))}}return M[m]=B.length,i.createSparseMatrix({values:F,index:B,ptr:M,size:[y,m],datatype:h===n._datatype&&_===i._datatype?w:void 0})}}),Fg="matAlgo03xDSf",Bg=["typed"],Fi=xe(Fg,Bg,s=>{var{typed:e}=s;return function(r,n,i,a){var u=r._data,f=r._size,c=r._datatype||r.getDataType(),h=n._values,d=n._index,p=n._ptr,v=n._size,x=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==v.length)throw new rt(f.length,v.length);if(f[0]!==v[0]||f[1]!==v[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+v+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var _=f[0],y=f[1],m,w=0,D=i;typeof c=="string"&&c===x&&c!=="mixed"&&(m=c,w=e.convert(0,m),D=e.find(i,[m,m]));for(var C=[],b=0;b<_;b++)C[b]=[];for(var F=[],B=[],M=0;M<y;M++){for(var O=M+1,A=p[M],N=p[M+1],T=A;T<N;T++){var R=d[T];F[R]=a?D(h[T],u[R][M]):D(u[R][M],h[T]),B[R]=O}for(var k=0;k<_;k++)B[k]===O?C[k][M]=F[k]:C[k][M]=a?D(w,u[k][M]):D(u[k][M],w)}return r.createDenseMatrix({data:C,size:[_,y],datatype:c===r._datatype&&x===n._datatype?m:void 0})}}),Mg="matAlgo05xSfSf",Ng=["typed","equalScalar"],Ic=xe(Mg,Ng,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a){var u=n._values,f=n._index,c=n._ptr,h=n._size,d=n._datatype||n._data===void 0?n._datatype:n.getDataType(),p=i._values,v=i._index,x=i._ptr,_=i._size,y=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(h.length!==_.length)throw new rt(h.length,_.length);if(h[0]!==_[0]||h[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+_+")");var m=h[0],w=h[1],D,C=t,b=0,F=a;typeof d=="string"&&d===y&&d!=="mixed"&&(D=d,C=e.find(t,[D,D]),b=e.convert(0,D),F=e.find(a,[D,D]));var B=u&&p?[]:void 0,M=[],O=[],A=B?[]:void 0,N=B?[]:void 0,T=[],R=[],k,z,L,G;for(z=0;z<w;z++){O[z]=M.length;var H=z+1;for(L=c[z],G=c[z+1];L<G;L++)k=f[L],M.push(k),T[k]=H,A&&(A[k]=u[L]);for(L=x[z],G=x[z+1];L<G;L++)k=v[L],T[k]!==H&&M.push(k),R[k]=H,N&&(N[k]=p[L]);if(B)for(L=O[z];L<M.length;){k=M[L];var ee=T[k],te=R[k];if(ee===H||te===H){var j=ee===H?A[k]:b,X=te===H?N[k]:b,Y=F(j,X);C(Y,b)?M.splice(L,1):(B.push(Y),L++)}}}return O[w]=M.length,n.createSparseMatrix({values:B,index:M,ptr:O,size:[m,w],datatype:d===n._datatype&&y===i._datatype?D:void 0})}}),Sg="matAlgo13xDD",Og=["typed"],Tg=xe(Sg,Og,s=>{var{typed:e}=s;return function(n,i,a){var u=n._data,f=n._size,c=n._datatype,h=i._data,d=i._size,p=i._datatype,v=[];if(f.length!==d.length)throw new rt(f.length,d.length);for(var x=0;x<f.length;x++){if(f[x]!==d[x])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+d+")");v[x]=f[x]}var _,y=a;typeof c=="string"&&c===p&&(_=c,y=e.find(a,[_,_]));var m=v.length>0?t(y,0,v,v[0],u,h):[];return n.createDenseMatrix({data:m,size:v,datatype:_})};function t(r,n,i,a,u,f){var c=[];if(n===i.length-1)for(var h=0;h<a;h++)c[h]=r(u[h],f[h]);else for(var d=0;d<a;d++)c[d]=t(r,n+1,i,i[n+1],u[d],f[d]);return c}}),Ig="broadcast",$g=["concat"],Rg=xe(Ig,$g,s=>{var{concat:e}=s;return function(n,i){var a=Math.max(n._size.length,i._size.length);if(n._size.length===i._size.length&&n._size.every((x,_)=>x===i._size[_]))return[n,i];for(var u=t(n._size,a,0),f=t(i._size,a,0),c=[],h=0;h<a;h++)c[h]=Math.max(u[h],f[h]);Zs(u,c),Zs(f,c);var d=n.clone(),p=i.clone();d._size.length<a?d.reshape(t(d._size,a,1)):p._size.length<a&&p.reshape(t(p._size,a,1));for(var v=0;v<a;v++)d._size[v]<c[v]&&(d=r(d,c[v],v)),p._size[v]<c[v]&&(p=r(p,c[v],v));return[d,p]};function t(n,i,a){return[...Array(i-n.length).fill(a),...n]}function r(n,i,a){return e(...Array(i).fill(n),a)}}),Lg="matrixAlgorithmSuite",Pg=["typed","matrix","concat"],ri=xe(Lg,Pg,s=>{var{typed:e,matrix:t,concat:r}=s,n=Tg({typed:e}),i=ja({typed:e}),a=Rg({concat:r});return function(f){var c=f.elop,h=f.SD||f.DS,d;c?(d={"DenseMatrix, DenseMatrix":(_,y)=>n(...a(_,y),c),"Array, Array":(_,y)=>n(...a(t(_),t(y)),c).valueOf(),"Array, DenseMatrix":(_,y)=>n(...a(t(_),y),c),"DenseMatrix, Array":(_,y)=>n(...a(_,t(y)),c)},f.SS&&(d["SparseMatrix, SparseMatrix"]=(_,y)=>f.SS(...a(_,y),c,!1)),f.DS&&(d["DenseMatrix, SparseMatrix"]=(_,y)=>f.DS(...a(_,y),c,!1),d["Array, SparseMatrix"]=(_,y)=>f.DS(...a(t(_),y),c,!1)),h&&(d["SparseMatrix, DenseMatrix"]=(_,y)=>h(...a(y,_),c,!0),d["SparseMatrix, Array"]=(_,y)=>h(...a(t(y),_),c,!0))):(d={"DenseMatrix, DenseMatrix":e.referToSelf(_=>(y,m)=>n(...a(y,m),_)),"Array, Array":e.referToSelf(_=>(y,m)=>n(...a(t(y),t(m)),_).valueOf()),"Array, DenseMatrix":e.referToSelf(_=>(y,m)=>n(...a(t(y),m),_)),"DenseMatrix, Array":e.referToSelf(_=>(y,m)=>n(...a(y,t(m)),_))},f.SS&&(d["SparseMatrix, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.SS(...a(y,m),_,!1))),f.DS&&(d["DenseMatrix, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.DS(...a(y,m),_,!1)),d["Array, SparseMatrix"]=e.referToSelf(_=>(y,m)=>f.DS(...a(t(y),m),_,!1))),h&&(d["SparseMatrix, DenseMatrix"]=e.referToSelf(_=>(y,m)=>h(...a(m,y),_,!0)),d["SparseMatrix, Array"]=e.referToSelf(_=>(y,m)=>h(...a(t(m),y),_,!0))));var p=f.scalar||"any",v=f.Ds||f.Ss;v&&(c?(d["DenseMatrix,"+p]=(_,y)=>i(_,y,c,!1),d[p+", DenseMatrix"]=(_,y)=>i(y,_,c,!0),d["Array,"+p]=(_,y)=>i(t(_),y,c,!1).valueOf(),d[p+", Array"]=(_,y)=>i(t(y),_,c,!0).valueOf()):(d["DenseMatrix,"+p]=e.referToSelf(_=>(y,m)=>i(y,m,_,!1)),d[p+", DenseMatrix"]=e.referToSelf(_=>(y,m)=>i(m,y,_,!0)),d["Array,"+p]=e.referToSelf(_=>(y,m)=>i(t(y),m,_,!1).valueOf()),d[p+", Array"]=e.referToSelf(_=>(y,m)=>i(t(m),y,_,!0).valueOf())));var x=f.sS!==void 0?f.sS:f.Ss;return c?(f.Ss&&(d["SparseMatrix,"+p]=(_,y)=>f.Ss(_,y,c,!1)),x&&(d[p+", SparseMatrix"]=(_,y)=>x(y,_,c,!0))):(f.Ss&&(d["SparseMatrix,"+p]=e.referToSelf(_=>(y,m)=>f.Ss(y,m,_,!1))),x&&(d[p+", SparseMatrix"]=e.referToSelf(_=>(y,m)=>x(m,y,_,!0)))),c&&c.signatures&&Fl(d,c.signatures),d}}),kg="matAlgo01xDSid",zg=["typed"],$c=xe(kg,zg,s=>{var{typed:e}=s;return function(r,n,i,a){var u=r._data,f=r._size,c=r._datatype||r.getDataType(),h=n._values,d=n._index,p=n._ptr,v=n._size,x=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==v.length)throw new rt(f.length,v.length);if(f[0]!==v[0]||f[1]!==v[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+v+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var _=f[0],y=f[1],m=typeof c=="string"&&c!=="mixed"&&c===x?c:void 0,w=m?e.find(i,[m,m]):i,D,C,b=[];for(D=0;D<_;D++)b[D]=[];var F=[],B=[];for(C=0;C<y;C++){for(var M=C+1,O=p[C],A=p[C+1],N=O;N<A;N++)D=d[N],F[D]=a?w(h[N],u[D][C]):w(u[D][C],h[N]),B[D]=M;for(D=0;D<_;D++)B[D]===M?b[D][C]=F[D]:b[D][C]=u[D][C]}return r.createDenseMatrix({data:b,size:[_,y],datatype:c===r._datatype&&x===n._datatype?m:void 0})}}),qg="matAlgo04xSidSid",Ug=["typed","equalScalar"],Wg=xe(qg,Ug,s=>{var{typed:e,equalScalar:t}=s;return function(n,i,a){var u=n._values,f=n._index,c=n._ptr,h=n._size,d=n._datatype||n._data===void 0?n._datatype:n.getDataType(),p=i._values,v=i._index,x=i._ptr,_=i._size,y=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(h.length!==_.length)throw new rt(h.length,_.length);if(h[0]!==_[0]||h[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+_+")");var m=h[0],w=h[1],D,C=t,b=0,F=a;typeof d=="string"&&d===y&&d!=="mixed"&&(D=d,C=e.find(t,[D,D]),b=e.convert(0,D),F=e.find(a,[D,D]));var B=u&&p?[]:void 0,M=[],O=[],A=u&&p?[]:void 0,N=u&&p?[]:void 0,T=[],R=[],k,z,L,G,H;for(z=0;z<w;z++){O[z]=M.length;var ee=z+1;for(G=c[z],H=c[z+1],L=G;L<H;L++)k=f[L],M.push(k),T[k]=ee,A&&(A[k]=u[L]);for(G=x[z],H=x[z+1],L=G;L<H;L++)if(k=v[L],T[k]===ee){if(A){var te=F(A[k],p[L]);C(te,b)?T[k]=null:A[k]=te}}else M.push(k),R[k]=ee,N&&(N[k]=p[L]);if(A&&N)for(L=O[z];L<M.length;)k=M[L],T[k]===ee?(B[L]=A[k],L++):R[k]===ee?(B[L]=N[k],L++):M.splice(L,1)}return O[w]=M.length,n.createSparseMatrix({values:B,index:M,ptr:O,size:[m,w],datatype:d===n._datatype&&y===i._datatype?D:void 0})}}),Hg="matAlgo10xSids",jg=["typed","DenseMatrix"],Rc=xe(Hg,jg,s=>{var{typed:e,DenseMatrix:t}=s;return function(n,i,a,u){var f=n._values,c=n._index,h=n._ptr,d=n._size,p=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var v=d[0],x=d[1],_,y=a;typeof p=="string"&&(_=p,i=e.convert(i,_),y=e.find(a,[_,_]));for(var m=[],w=[],D=[],C=0;C<x;C++){for(var b=C+1,F=h[C],B=h[C+1],M=F;M<B;M++){var O=c[M];w[O]=f[M],D[O]=b}for(var A=0;A<v;A++)C===0&&(m[A]=[]),D[A]===b?m[A][C]=u?y(i,w[A]):y(w[A],i):m[A][C]=i}return new t({data:m,size:[v,x],datatype:_})}}),Yg="multiplyScalar",Zg=["typed"],Vg=xe(Yg,Zg,s=>{var{typed:e}=s;return e("multiplyScalar",{"number, number":yc,"Complex, Complex":function(r,n){return r.mul(n)},"BigNumber, BigNumber":function(r,n){return r.times(n)},"Fraction, Fraction":function(r,n){return r.mul(n)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Lc="multiply",Gg=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],Kg=xe(Lc,Gg,s=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:n,equalScalar:i,dot:a}=s,u=Ha({typed:e,equalScalar:i}),f=ja({typed:e});function c(b,F){switch(b.length){case 1:switch(F.length){case 1:if(b[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(b[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+b[0]+") must match Matrix rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;case 2:switch(F.length){case 1:if(b[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+b[1]+") must match Vector length ("+F[0]+")");break;case 2:if(b[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+b[1]+") must match Matrix B rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+b.length+" dimensions)")}}function h(b,F,B){if(B===0)throw new Error("Cannot multiply two empty vectors");return a(b,F)}function d(b,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return p(b,F)}function p(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._size,T=F._datatype||F.getDataType(),R=M[0],k=N[1],z,L=r,G=n;O&&T&&O===T&&typeof O=="string"&&O!=="mixed"&&(z=O,L=e.find(r,[z,z]),G=e.find(n,[z,z]));for(var H=[],ee=0;ee<k;ee++){for(var te=G(B[0],A[0][ee]),j=1;j<R;j++)te=L(te,G(B[j],A[j][ee]));H[ee]=te}return b.createDenseMatrix({data:H,size:[k],datatype:O===b._datatype&&T===F._datatype?z:void 0})}var v=e("_multiplyMatrixVector",{"DenseMatrix, any":_,"SparseMatrix, any":w}),x=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":y,"DenseMatrix, SparseMatrix":m,"SparseMatrix, DenseMatrix":D,"SparseMatrix, SparseMatrix":C});function _(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._datatype||F.getDataType(),T=M[0],R=M[1],k,z=r,L=n;O&&N&&O===N&&typeof O=="string"&&O!=="mixed"&&(k=O,z=e.find(r,[k,k]),L=e.find(n,[k,k]));for(var G=[],H=0;H<T;H++){for(var ee=B[H],te=L(ee[0],A[0]),j=1;j<R;j++)te=z(te,L(ee[j],A[j]));G[H]=te}return b.createDenseMatrix({data:G,size:[T],datatype:O===b._datatype&&N===F._datatype?k:void 0})}function y(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._data,N=F._size,T=F._datatype||F.getDataType(),R=M[0],k=M[1],z=N[1],L,G=r,H=n;O&&T&&O===T&&typeof O=="string"&&O!=="mixed"&&O!=="mixed"&&(L=O,G=e.find(r,[L,L]),H=e.find(n,[L,L]));for(var ee=[],te=0;te<R;te++){var j=B[te];ee[te]=[];for(var X=0;X<z;X++){for(var Y=H(j[0],A[0][X]),Q=1;Q<k;Q++)Y=G(Y,H(j[Q],A[Q][X]));ee[te][X]=Y}}return b.createDenseMatrix({data:ee,size:[R,z],datatype:O===b._datatype&&T===F._datatype?L:void 0})}function m(b,F){var B=b._data,M=b._size,O=b._datatype||b.getDataType(),A=F._values,N=F._index,T=F._ptr,R=F._size,k=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!A)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var z=M[0],L=R[1],G,H=r,ee=n,te=i,j=0;O&&k&&O===k&&typeof O=="string"&&O!=="mixed"&&(G=O,H=e.find(r,[G,G]),ee=e.find(n,[G,G]),te=e.find(i,[G,G]),j=e.convert(0,G));for(var X=[],Y=[],Q=[],pe=F.createSparseMatrix({values:X,index:Y,ptr:Q,size:[z,L],datatype:O===b._datatype&&k===F._datatype?G:void 0}),De=0;De<L;De++){Q[De]=Y.length;var we=T[De],be=T[De+1];if(be>we)for(var Oe=0,Fe=0;Fe<z;Fe++){for(var nt=Fe+1,Ye=void 0,Te=we;Te<be;Te++){var Re=N[Te];Oe!==nt?(Ye=ee(B[Fe][Re],A[Te]),Oe=nt):Ye=H(Ye,ee(B[Fe][Re],A[Te]))}Oe===nt&&!te(Ye,j)&&(Y.push(Fe),X.push(Ye))}}return Q[L]=Y.length,pe}function w(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(!B)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var N=F._data,T=F._datatype||F.getDataType(),R=b._size[0],k=F._size[0],z=[],L=[],G=[],H,ee=r,te=n,j=i,X=0;A&&T&&A===T&&typeof A=="string"&&A!=="mixed"&&(H=A,ee=e.find(r,[H,H]),te=e.find(n,[H,H]),j=e.find(i,[H,H]),X=e.convert(0,H));var Y=[],Q=[];G[0]=0;for(var pe=0;pe<k;pe++){var De=N[pe];if(!j(De,X))for(var we=O[pe],be=O[pe+1],Oe=we;Oe<be;Oe++){var Fe=M[Oe];Q[Fe]?Y[Fe]=ee(Y[Fe],te(De,B[Oe])):(Q[Fe]=!0,L.push(Fe),Y[Fe]=te(De,B[Oe]))}}for(var nt=L.length,Ye=0;Ye<nt;Ye++){var Te=L[Ye];z[Ye]=Y[Te]}return G[1]=L.length,b.createSparseMatrix({values:z,index:L,ptr:G,size:[R,1],datatype:A===b._datatype&&T===F._datatype?H:void 0})}function D(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(!B)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var N=F._data,T=F._datatype||F.getDataType(),R=b._size[0],k=F._size[0],z=F._size[1],L,G=r,H=n,ee=i,te=0;A&&T&&A===T&&typeof A=="string"&&A!=="mixed"&&(L=A,G=e.find(r,[L,L]),H=e.find(n,[L,L]),ee=e.find(i,[L,L]),te=e.convert(0,L));for(var j=[],X=[],Y=[],Q=b.createSparseMatrix({values:j,index:X,ptr:Y,size:[R,z],datatype:A===b._datatype&&T===F._datatype?L:void 0}),pe=[],De=[],we=0;we<z;we++){Y[we]=X.length;for(var be=we+1,Oe=0;Oe<k;Oe++){var Fe=N[Oe][we];if(!ee(Fe,te))for(var nt=O[Oe],Ye=O[Oe+1],Te=nt;Te<Ye;Te++){var Re=M[Te];De[Re]!==be?(De[Re]=be,X.push(Re),pe[Re]=H(Fe,B[Te])):pe[Re]=G(pe[Re],H(Fe,B[Te]))}}for(var xt=Y[we],Ut=X.length,Et=xt;Et<Ut;Et++){var lr=X[Et];j[Et]=pe[lr]}}return Y[z]=X.length,Q}function C(b,F){var B=b._values,M=b._index,O=b._ptr,A=b._datatype||b._data===void 0?b._datatype:b.getDataType(),N=F._values,T=F._index,R=F._ptr,k=F._datatype||F._data===void 0?F._datatype:F.getDataType(),z=b._size[0],L=F._size[1],G=B&&N,H,ee=r,te=n;A&&k&&A===k&&typeof A=="string"&&A!=="mixed"&&(H=A,ee=e.find(r,[H,H]),te=e.find(n,[H,H]));for(var j=G?[]:void 0,X=[],Y=[],Q=b.createSparseMatrix({values:j,index:X,ptr:Y,size:[z,L],datatype:A===b._datatype&&k===F._datatype?H:void 0}),pe=G?[]:void 0,De=[],we,be,Oe,Fe,nt,Ye,Te,Re,xt=0;xt<L;xt++){Y[xt]=X.length;var Ut=xt+1;for(nt=R[xt],Ye=R[xt+1],Fe=nt;Fe<Ye;Fe++)if(Re=T[Fe],G)for(be=O[Re],Oe=O[Re+1],we=be;we<Oe;we++)Te=M[we],De[Te]!==Ut?(De[Te]=Ut,X.push(Te),pe[Te]=te(N[Fe],B[we])):pe[Te]=ee(pe[Te],te(N[Fe],B[we]));else for(be=O[Re],Oe=O[Re+1],we=be;we<Oe;we++)Te=M[we],De[Te]!==Ut&&(De[Te]=Ut,X.push(Te));if(G)for(var Et=Y[xt],lr=X.length,Lr=Et;Lr<lr;Lr++){var cr=X[Lr];j[Lr]=pe[cr]}}return Y[L]=X.length,Q}return e(Lc,n,{"Array, Array":e.referTo("Matrix, Matrix",b=>(F,B)=>{c(Lt(F),Lt(B));var M=b(t(F),t(B));return mt(M)?M.valueOf():M}),"Matrix, Matrix":function(F,B){var M=F.size(),O=B.size();return c(M,O),M.length===1?O.length===1?h(F,B,M[0]):d(F,B):O.length===1?v(F,B):x(F,B)},"Matrix, Array":e.referTo("Matrix,Matrix",b=>(F,B)=>b(F,t(B))),"Array, Matrix":e.referToSelf(b=>(F,B)=>b(t(F,B.storage()),B)),"SparseMatrix, any":function(F,B){return u(F,B,n,!1)},"DenseMatrix, any":function(F,B){return f(F,B,n,!1)},"any, SparseMatrix":function(F,B){return u(B,F,n,!0)},"any, DenseMatrix":function(F,B){return f(B,F,n,!0)},"Array, any":function(F,B){return f(t(F),B,n,!1).valueOf()},"any, Array":function(F,B){return f(t(B),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":e.referToSelf(b=>(F,B,M)=>{for(var O=b(F,B),A=0;A<M.length;A++)O=b(O,M[A]);return O})})}),Pc="subtract",Xg=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],Qg=xe(Pc,Xg,s=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:n,unaryMinus:i,DenseMatrix:a,concat:u}=s,f=$c({typed:e}),c=Fi({typed:e}),h=Ic({typed:e,equalScalar:r}),d=Rc({typed:e,DenseMatrix:a}),p=Ci({typed:e,DenseMatrix:a}),v=ri({typed:e,matrix:t,concat:u});return e(Pc,{"any, any":n},v({elop:n,SS:h,DS:f,SD:c,Ss:p,sS:d}))}),Jg="matAlgo07xSSf",em=["typed","DenseMatrix"],uo=xe(Jg,em,s=>{var{typed:e,DenseMatrix:t}=s;return function(i,a,u){var f=i._size,c=i._datatype||i._data===void 0?i._datatype:i.getDataType(),h=a._size,d=a._datatype||a._data===void 0?a._datatype:a.getDataType();if(f.length!==h.length)throw new rt(f.length,h.length);if(f[0]!==h[0]||f[1]!==h[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+h+")");var p=f[0],v=f[1],x,_=0,y=u;typeof c=="string"&&c===d&&c!=="mixed"&&(x=c,_=e.convert(0,x),y=e.find(u,[x,x]));var m,w,D=[];for(m=0;m<p;m++)D[m]=[];var C=[],b=[],F=[],B=[];for(w=0;w<v;w++){var M=w+1;for(r(i,w,F,C,M),r(a,w,B,b,M),m=0;m<p;m++){var O=F[m]===M?C[m]:_,A=B[m]===M?b[m]:_;D[m][w]=y(O,A)}}return new t({data:D,size:[p,v],datatype:c===i._datatype&&d===a._datatype?x:void 0})};function r(n,i,a,u,f){for(var c=n._values,h=n._index,d=n._ptr,p=d[i],v=d[i+1];p<v;p++){var x=h[p];a[x]=f,u[x]=c[p]}}}),kc="conj",tm=["typed"],rm=xe(kc,tm,s=>{var{typed:e}=s;return e(kc,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>Jr(r,t))})}),zc="concat",nm=["typed","matrix","isInteger"],im=xe(zc,nm,s=>{var{typed:e,matrix:t,isInteger:r}=s;return e(zc,{"...Array | Matrix | number | BigNumber":function(i){var a,u=i.length,f=-1,c,h=!1,d=[];for(a=0;a<u;a++){var p=i[a];if(mt(p)&&(h=!0),pt(p)||St(p)){if(a!==u-1)throw new Error("Dimension must be specified as last argument");if(c=f,f=p.valueOf(),!r(f))throw new TypeError("Integer number expected for dimension");if(f<0||a>0&&f>c)throw new On(f,c+1)}else{var v=ut(p).valueOf(),x=Lt(v);if(d[a]=v,c=f,f=x.length-1,a>0&&f!==c)throw new rt(c+1,f+1)}}if(d.length===0)throw new SyntaxError("At least one matrix expected");for(var _=d.shift();d.length;)_=Zl(_,d.shift(),f);return h?t(_):_},"...string":function(i){return i.join("")}})}),qc="count",sm=["typed","size","prod"],om=xe(qc,sm,s=>{var{typed:e,size:t,prod:r}=s;return e(qc,{string:function(i){return i.length},"Matrix | Array":function(i){return r(t(i))}})}),Uc="identity",am=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],um=xe(Uc,am,s=>{var{typed:e,config:t,matrix:r,BigNumber:n,DenseMatrix:i,SparseMatrix:a}=s;return e(Uc,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(h){return r(h)},"number | BigNumber":function(h){return f(h,h,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(h,d){return f(h,h,d)},"number | BigNumber, number | BigNumber":function(h,d){return f(h,d,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(h,d,p){return f(h,d,p)},Array:function(h){return u(h)},"Array, string":function(h,d){return u(h,d)},Matrix:function(h){return u(h.valueOf(),h.storage())},"Matrix, string":function(h,d){return u(h.valueOf(),d)}});function u(c,h){switch(c.length){case 0:return h?r(h):[];case 1:return f(c[0],c[0],h);case 2:return f(c[0],c[1],h);default:throw new Error("Vector containing two values expected")}}function f(c,h,d){var p=St(c)||St(h)?n:null;if(St(c)&&(c=c.toNumber()),St(h)&&(h=h.toNumber()),!bt(c)||c<1)throw new Error("Parameters in function identity must be positive integers");if(!bt(h)||h<1)throw new Error("Parameters in function identity must be positive integers");var v=p?new n(1):1,x=p?new p(0):0,_=[c,h];if(d){if(d==="sparse")return a.diagonal(_,v,0,x);if(d==="dense")return i.diagonal(_,v,0,x);throw new TypeError('Unknown matrix type "'.concat(d,'"'))}for(var y=Na([],_,x),m=c<h?c:h,w=0;w<m;w++)y[w][w]=v;return y}}),Wc="kron",lm=["typed","matrix","multiplyScalar"],cm=xe(Wc,lm,s=>{var{typed:e,matrix:t,multiplyScalar:r}=s;return e(Wc,{"Matrix, Matrix":function(a,u){return t(n(a.toArray(),u.toArray()))},"Matrix, Array":function(a,u){return t(n(a.toArray(),u))},"Array, Matrix":function(a,u){return t(n(a,u.toArray()))},"Array, Array":n});function n(i,a){if(Lt(i).length===1&&(i=[i]),Lt(a).length===1&&(a=[a]),Lt(i).length>2||Lt(a).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(i.length)+", y = "+JSON.stringify(a.length)+")");var u=[],f=[];return i.map(function(c){return a.map(function(h){return f=[],u.push(f),c.map(function(d){return h.map(function(p){return f.push(r(d,p))})})})})&&u}});function fm(){throw new Error('No "bignumber" implementation available')}function hm(){throw new Error('No "fraction" implementation available')}function dm(){throw new Error('No "matrix" implementation available')}var Hc="reshape",pm=["typed","isInteger","matrix"],_m=xe(Hc,pm,s=>{var{typed:e,isInteger:t}=s;return e(Hc,{"Matrix, Array":function(n,i){return n.reshape(i,!0)},"Array, Array":function(n,i){return i.forEach(function(a){if(!t(a))throw new TypeError("Invalid size for dimension: "+a)}),Oa(n,i)}})}),jc="size",vm=["typed","config","?matrix"],gm=xe(jc,vm,s=>{var{typed:e,config:t,matrix:r}=s;return e(jc,{Matrix:function(i){return i.create(i.size())},Array:Lt,string:function(i){return t.matrix==="Array"?[i.length]:r([i.length])},"number | Complex | BigNumber | Unit | boolean | null":function(i){return t.matrix==="Array"?[]:r?r([]):dm()}})}),Yc="transpose",mm=["typed","matrix"],xm=xe(Yc,mm,s=>{var{typed:e,matrix:t}=s;return e(Yc,{Array:a=>r(t(a)).valueOf(),Matrix:r,any:ut});function r(a){var u=a.size(),f;switch(u.length){case 1:f=a.clone();break;case 2:{var c=u[0],h=u[1];if(h===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+ct(u)+")");switch(a.storage()){case"dense":f=n(a,c,h);break;case"sparse":f=i(a,c,h);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+ct(u)+")")}return f}function n(a,u,f){for(var c=a._data,h=[],d,p=0;p<f;p++){d=h[p]=[];for(var v=0;v<u;v++)d[v]=ut(c[v][p])}return a.createDenseMatrix({data:h,size:[f,u],datatype:a._datatype})}function i(a,u,f){for(var c=a._values,h=a._index,d=a._ptr,p=c?[]:void 0,v=[],x=[],_=[],y=0;y<u;y++)_[y]=0;var m,w,D;for(m=0,w=h.length;m<w;m++)_[h[m]]++;for(var C=0,b=0;b<u;b++)x.push(C),C+=_[b],_[b]=x[b];for(x.push(C),D=0;D<f;D++)for(var F=d[D],B=d[D+1],M=F;M<B;M++){var O=_[h[M]]++;v[O]=D,c&&(p[O]=ut(c[M]))}return a.createSparseMatrix({values:p,index:v,ptr:x,size:[f,u],datatype:a._datatype})}}),Zc="ctranspose",ym=["typed","transpose","conj"],Dm=xe(Zc,ym,s=>{var{typed:e,transpose:t,conj:r}=s;return e(Zc,{any:function(i){return r(t(i))}})}),Vc="mode",wm=["typed","isNaN","isNumeric"],bm=xe(Vc,wm,s=>{var{typed:e,isNaN:t,isNumeric:r}=s;return e(Vc,{"Array | Matrix":n,"...":function(a){return n(a)}});function n(i){i=Ia(i.valueOf());var a=i.length;if(a===0)throw new Error("Cannot calculate mode of an empty array");for(var u={},f=[],c=0,h=0;h<i.length;h++){var d=i[h];if(r(d)&&t(d))throw new Error("Cannot calculate mode of an array containing NaN values");d in u||(u[d]=0),u[d]++,u[d]===c?f.push(d):u[d]>c&&(c=u[d],f=[d])}return f}});function Ln(s,e,t){var r;return String(s).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+Sn(t)+", value: "+JSON.stringify(t)+")":" (type: "+s.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(s).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+Sn(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):s}var Gc="prod",Em=["typed","config","multiplyScalar","numeric"],Am=xe(Gc,Em,s=>{var{typed:e,config:t,multiplyScalar:r,numeric:n}=s;return e(Gc,{"Array | Matrix":i,"Array | Matrix, number | BigNumber":function(u,f){throw new Error("prod(A, dim) is not yet supported")},"...":function(u){return i(u)}});function i(a){var u;if(as(a,function(f){try{u=u===void 0?f:r(u,f)}catch(c){throw Ln(c,"prod",f)}}),typeof u=="string"&&(u=n(u,t.number)),u===void 0)throw new Error("Cannot calculate prod of an empty array");return u}}),Cm="numeric",Fm=["number","?bignumber","?fraction"],Bm=xe(Cm,Fm,s=>{var{number:e,bignumber:t,fraction:r}=s,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},i={number:a=>e(a),BigNumber:t?a=>t(a):fm,Fraction:r?a=>r(a):hm};return function(u){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",c=arguments.length>2?arguments[2]:void 0;if(c!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var h=Sn(u);if(!(h in n))throw new TypeError("Cannot convert "+u+' of type "'+h+'"; valid input types are '+Object.keys(n).join(", "));if(!(f in i))throw new TypeError("Cannot convert "+u+' to type "'+f+'"; valid output types are '+Object.keys(i).join(", "));return f===h?u:i[f](u)}}),Kc="divideScalar",Mm=["typed","numeric"],Nm=xe(Kc,Mm,s=>{var{typed:e,numeric:t}=s;return e(Kc,{"number, number":function(n,i){return n/i},"Complex, Complex":function(n,i){return n.div(i)},"BigNumber, BigNumber":function(n,i){return n.div(i)},"Fraction, Fraction":function(n,i){return n.div(i)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),Xc="pow",Sm=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Om=xe(Xc,Sm,s=>{var{typed:e,config:t,identity:r,multiply:n,matrix:i,inv:a,number:u,fraction:f,Complex:c}=s;return e(Xc,{"number, number":h,"Complex, Complex":function(x,_){return x.pow(_)},"BigNumber, BigNumber":function(x,_){return _.isInteger()||x>=0||t.predictable?x.pow(_):new c(x.toNumber(),0).pow(_.toNumber(),0)},"Fraction, Fraction":function(x,_){var y=x.pow(_);if(y!=null)return y;if(t.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return h(x.valueOf(),_.valueOf())},"Array, number":d,"Array, BigNumber":function(x,_){return d(x,_.toNumber())},"Matrix, number":p,"Matrix, BigNumber":function(x,_){return p(x,_.toNumber())},"Unit, number | BigNumber":function(x,_){return x.pow(_)}});function h(v,x){if(t.predictable&&!bt(x)&&v<0)try{var _=f(x),y=u(_);if((x===y||Math.abs((x-y)/x)<1e-14)&&_.d%2===1)return(_.n%2===0?1:-1)*Math.pow(-v,x)}catch{}return t.predictable&&(v<-1&&x===1/0||v>-1&&v<0&&x===-1/0)?NaN:bt(x)||v>=0||t.predictable?wc(v,x):v*v<1&&x===1/0||v*v>1&&x===-1/0?0:new c(v,0).pow(x,0)}function d(v,x){if(!bt(x))throw new TypeError("For A^b, b must be an integer (value is "+x+")");var _=Lt(v);if(_.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+_.length+" dimensions)");if(_[0]!==_[1])throw new Error("For A^b, A must be square (size is "+_[0]+"x"+_[1]+")");if(x<0)try{return d(a(v),-x)}catch(w){throw w.message==="Cannot calculate inverse, determinant is zero"?new TypeError("For A^b, when A is not invertible, b must be a positive integer (value is "+x+")"):w}for(var y=r(_[0]).valueOf(),m=v;x>=1;)(x&1)===1&&(y=n(m,y)),x>>=1,m=n(m,m);return y}function p(v,x){return i(d(v.valueOf(),x))}}),Qc="dotDivide",Tm=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],Im=xe(Qc,Tm,s=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:n,DenseMatrix:i,concat:a}=s,u=Cg({typed:e,equalScalar:r}),f=Fi({typed:e}),c=uo({typed:e,DenseMatrix:i}),h=Ha({typed:e,equalScalar:r}),d=Ci({typed:e,DenseMatrix:i}),p=ri({typed:e,matrix:t,concat:a});return e(Qc,p({elop:n,SS:c,DS:f,SD:u,Ss:h,sS:d}))}),lo="compare",$m=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],Rm=xe(lo,$m,s=>{var{typed:e,config:t,equalScalar:r,matrix:n,BigNumber:i,Fraction:a,DenseMatrix:u,concat:f}=s,c=Fi({typed:e}),h=Ic({typed:e,equalScalar:r}),d=Ci({typed:e,DenseMatrix:u}),p=ri({typed:e,matrix:n,concat:f}),v=oo({typed:e});return e(lo,Lm({typed:e,config:t}),{"boolean, boolean":function(_,y){return _===y?0:_>y?1:-1},"BigNumber, BigNumber":function(_,y){return so(_,y,t.epsilon)?new i(0):new i(_.cmp(y))},"Fraction, Fraction":function(_,y){return new a(_.compare(y))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},v,p({SS:h,DS:c,Ss:d}))}),Lm=xe(lo,["typed","config"],s=>{var{typed:e,config:t}=s;return e(lo,{"number, number":function(n,i){return ti(n,i,t.epsilon)?0:n>i?1:-1}})}),co="equal",Pm=["typed","matrix","equalScalar","DenseMatrix","concat"],km=xe(co,Pm,s=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:t,concat:i});return e(co,zm({typed:e,equalScalar:r}),c({elop:r,SS:u,DS:a,Ss:f}))}),zm=xe(co,["typed","equalScalar"],s=>{var{typed:e,equalScalar:t}=s;return e(co,{"any, any":function(n,i){return n===null?i===null:i===null?n===null:n===void 0?i===void 0:i===void 0?n===void 0:t(n,i)}})}),fo="smaller",qm=["typed","config","matrix","DenseMatrix","concat"],Um=xe(fo,qm,s=>{var{typed:e,config:t,matrix:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:r,concat:i}),h=oo({typed:e});return e(fo,Wm({typed:e,config:t}),{"boolean, boolean":(d,p)=>d<p,"BigNumber, BigNumber":function(p,v){return p.lt(v)&&!so(p,v,t.epsilon)},"Fraction, Fraction":(d,p)=>d.compare(p)===-1,"Complex, Complex":function(p,v){throw new TypeError("No ordering relation is defined for complex numbers")}},h,c({SS:u,DS:a,Ss:f}))}),Wm=xe(fo,["typed","config"],s=>{var{typed:e,config:t}=s;return e(fo,{"number, number":function(n,i){return n<i&&!ti(n,i,t.epsilon)}})}),ho="larger",Hm=["typed","config","matrix","DenseMatrix","concat"],jm=xe(ho,Hm,s=>{var{typed:e,config:t,matrix:r,DenseMatrix:n,concat:i}=s,a=Fi({typed:e}),u=uo({typed:e,DenseMatrix:n}),f=Ci({typed:e,DenseMatrix:n}),c=ri({typed:e,matrix:r,concat:i}),h=oo({typed:e});return e(ho,Ym({typed:e,config:t}),{"boolean, boolean":(d,p)=>d>p,"BigNumber, BigNumber":function(p,v){return p.gt(v)&&!so(p,v,t.epsilon)},"Fraction, Fraction":(d,p)=>d.compare(p)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},h,c({SS:u,DS:a,Ss:f}))}),Ym=xe(ho,["typed","config"],s=>{var{typed:e,config:t}=s;return e(ho,{"number, number":function(n,i){return n>i&&!ti(n,i,t.epsilon)}})}),Jc="deepEqual",Zm=["typed","equal"],Vm=xe(Jc,Zm,s=>{var{typed:e,equal:t}=s;return e(Jc,{"any, any":function(i,a){return r(i.valueOf(),a.valueOf())}});function r(n,i){if(Array.isArray(n))if(Array.isArray(i)){var a=n.length;if(a!==i.length)return!1;for(var u=0;u<a;u++)if(!r(n[u],i[u]))return!1;return!0}else return!1;else return Array.isArray(i)?!1:t(n,i)}}),ef="partitionSelect",Gm=["typed","isNumeric","isNaN","compare"],Km=xe(ef,Gm,s=>{var{typed:e,isNumeric:t,isNaN:r,compare:n}=s,i=n,a=(c,h)=>-n(c,h);return e(ef,{"Array | Matrix, number":function(h,d){return u(h,d,i)},"Array | Matrix, number, string":function(h,d,p){if(p==="asc")return u(h,d,i);if(p==="desc")return u(h,d,a);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":u});function u(c,h,d){if(!bt(h)||h<0)throw new Error("k must be a non-negative integer");if(mt(c)){var p=c.size();if(p.length>1)throw new Error("Only one dimensional matrices supported");return f(c.valueOf(),h,d)}if(Array.isArray(c))return f(c,h,d)}function f(c,h,d){if(h>=c.length)throw new Error("k out of bounds");for(var p=0;p<c.length;p++)if(t(c[p])&&r(c[p]))return c[p];for(var v=0,x=c.length-1;v<x;){for(var _=v,y=x,m=c[Math.floor(Math.random()*(x-v+1))+v];_<y;)if(d(c[_],m)>=0){var w=c[y];c[y]=c[_],c[_]=w,--y}else++_;d(c[_],m)>0&&--_,h<=_?x=_:v=_+1}return c[h]}}),tf="max",Xm=["typed","config","numeric","larger"],Qm=xe(tf,Xm,s=>{var{typed:e,config:t,numeric:r,larger:n}=s;return e(tf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(f,c){return Wa(f,c.valueOf(),i)},"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function max");return a(f)}});function i(u,f){try{return n(u,f)?u:f}catch(c){throw Ln(c,"max",f)}}function a(u){var f;if(as(u,function(c){try{isNaN(c)&&typeof c=="number"?f=NaN:(f===void 0||n(c,f))&&(f=c)}catch(h){throw Ln(h,"max",c)}}),f===void 0)throw new Error("Cannot calculate max of an empty array");return typeof f=="string"&&(f=r(f,t.number)),f}}),rf="min",Jm=["typed","config","numeric","smaller"],ex=xe(rf,Jm,s=>{var{typed:e,config:t,numeric:r,smaller:n}=s;return e(rf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(f,c){return Wa(f,c.valueOf(),i)},"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function min");return a(f)}});function i(u,f){try{return n(u,f)?u:f}catch(c){throw Ln(c,"min",f)}}function a(u){var f;if(as(u,function(c){try{isNaN(c)&&typeof c=="number"?f=NaN:(f===void 0||n(c,f))&&(f=c)}catch(h){throw Ln(h,"min",c)}}),f===void 0)throw new Error("Cannot calculate min of an empty array");return typeof f=="string"&&(f=r(f,t.number)),f}}),nf="add",tx=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],rx=xe(nf,tx,s=>{var{typed:e,matrix:t,addScalar:r,equalScalar:n,DenseMatrix:i,SparseMatrix:a,concat:u}=s,f=$c({typed:e}),c=Wg({typed:e,equalScalar:n}),h=Rc({typed:e,DenseMatrix:i}),d=ri({typed:e,matrix:t,concat:u});return e(nf,{"any, any":r,"any, any, ...any":e.referToSelf(p=>(v,x,_)=>{for(var y=p(v,x),m=0;m<_.length;m++)y=p(y,_[m]);return y})},d({elop:r,DS:f,SS:c,Ss:h}))}),sf="dot",nx=["typed","addScalar","multiplyScalar","conj","size"],ix=xe(sf,nx,s=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:n,size:i}=s;return e(sf,{"Array | DenseMatrix, Array | DenseMatrix":u,"SparseMatrix, SparseMatrix":f});function a(h,d){var p=c(h),v=c(d),x,_;if(p.length===1)x=p[0];else if(p.length===2&&p[1]===1)x=p[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+p.join(", ")+")");if(v.length===1)_=v[0];else if(v.length===2&&v[1]===1)_=v[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+v.join(", ")+")");if(x!==_)throw new RangeError("Vectors must have equal length ("+x+" != "+_+")");if(x===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return x}function u(h,d){var p=a(h,d),v=mt(h)?h._data:h,x=mt(h)?h._datatype||h.getDataType():void 0,_=mt(d)?d._data:d,y=mt(d)?d._datatype||d.getDataType():void 0,m=c(h).length===2,w=c(d).length===2,D=t,C=r;if(x&&y&&x===y&&typeof x=="string"&&x!=="mixed"){var b=x;D=e.find(t,[b,b]),C=e.find(r,[b,b])}if(!m&&!w){for(var F=C(n(v[0]),_[0]),B=1;B<p;B++)F=D(F,C(n(v[B]),_[B]));return F}if(!m&&w){for(var M=C(n(v[0]),_[0][0]),O=1;O<p;O++)M=D(M,C(n(v[O]),_[O][0]));return M}if(m&&!w){for(var A=C(n(v[0][0]),_[0]),N=1;N<p;N++)A=D(A,C(n(v[N][0]),_[N]));return A}if(m&&w){for(var T=C(n(v[0][0]),_[0][0]),R=1;R<p;R++)T=D(T,C(n(v[R][0]),_[R][0]));return T}}function f(h,d){a(h,d);for(var p=h._index,v=h._values,x=d._index,_=d._values,y=0,m=t,w=r,D=0,C=0;D<p.length&&C<x.length;){var b=p[D],F=x[C];if(b<F){D++;continue}if(b>F){C++;continue}b===F&&(y=m(y,w(v[D],_[C])),D++,C++)}return y}function c(h){return mt(h)?h.size():i(h)}}),sx="trace",ox=["typed","matrix","add"],ax=xe(sx,ox,s=>{var{typed:e,matrix:t,add:r}=s;return e("trace",{Array:function(u){return n(t(u))},SparseMatrix:i,DenseMatrix:n,any:ut});function n(a){var u=a._size,f=a._data;switch(u.length){case 1:if(u[0]===1)return ut(f[0]);throw new RangeError("Matrix must be square (size: "+ct(u)+")");case 2:{var c=u[0],h=u[1];if(c===h){for(var d=0,p=0;p<c;p++)d=r(d,f[p][p]);return d}else throw new RangeError("Matrix must be square (size: "+ct(u)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(u)+")")}}function i(a){var u=a._values,f=a._index,c=a._ptr,h=a._size,d=h[0],p=h[1];if(d===p){var v=0;if(u.length>0)for(var x=0;x<p;x++)for(var _=c[x],y=c[x+1],m=_;m<y;m++){var w=f[m];if(w===x){v=r(v,u[m]);break}if(w>x)break}return v}throw new RangeError("Matrix must be square (size: "+ct(h)+")")}}),of="det",ux=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],lx=xe(of,ux,s=>{var{typed:e,matrix:t,subtractScalar:r,multiply:n,divideScalar:i,isZero:a,unaryMinus:u}=s;return e(of,{any:function(h){return ut(h)},"Array | Matrix":function(h){var d;switch(mt(h)?d=h.size():Array.isArray(h)?(h=t(h),d=h.size()):d=[],d.length){case 0:return ut(h);case 1:if(d[0]===1)return ut(h.valueOf()[0]);if(d[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+ct(d)+")");case 2:{var p=d[0],v=d[1];if(p===v)return f(h.clone().valueOf(),p);if(v===0)return 1;throw new RangeError("Matrix must be square (size: "+ct(d)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(d)+")")}}});function f(c,h,d){if(h===1)return ut(c[0][0]);if(h===2)return r(n(c[0][0],c[1][1]),n(c[1][0],c[0][1]));for(var p=!1,v=new Array(h).fill(0).map((B,M)=>M),x=0;x<h;x++){var _=v[x];if(a(c[_][x])){var y=void 0;for(y=x+1;y<h;y++)if(!a(c[v[y]][x])){_=v[y],v[y]=v[x],v[x]=_,p=!p;break}if(y===h)return c[_][x]}for(var m=c[_][x],w=x===0?1:c[v[x-1]][x-1],D=x+1;D<h;D++)for(var C=v[D],b=x+1;b<h;b++)c[C][b]=i(r(n(c[C][b],m),n(c[C][x],c[_][b])),w)}var F=c[v[h-1]][h-1];return p?u(F):F}}),af="inv",cx=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],fx=xe(af,cx,s=>{var{typed:e,matrix:t,divideScalar:r,addScalar:n,multiply:i,unaryMinus:a,det:u,identity:f,abs:c}=s;return e(af,{"Array | Matrix":function(p){var v=mt(p)?p.size():Lt(p);switch(v.length){case 1:if(v[0]===1)return mt(p)?t([r(1,p.valueOf()[0])]):[r(1,p[0])];throw new RangeError("Matrix must be square (size: "+ct(v)+")");case 2:{var x=v[0],_=v[1];if(x===_)return mt(p)?t(h(p.valueOf(),x,_),p.storage()):h(p,x,_);throw new RangeError("Matrix must be square (size: "+ct(v)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(v)+")")}},any:function(p){return r(1,p)}});function h(d,p,v){var x,_,y,m,w;if(p===1){if(m=d[0][0],m===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,m)]]}else if(p===2){var D=u(d);if(D===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(d[1][1],D),r(a(d[0][1]),D)],[r(a(d[1][0]),D),r(d[0][0],D)]]}else{var C=d.concat();for(x=0;x<p;x++)C[x]=C[x].concat();for(var b=f(p).valueOf(),F=0;F<v;F++){var B=c(C[F][F]),M=F;for(x=F+1;x<p;)c(C[x][F])>B&&(B=c(C[x][F]),M=x),x++;if(B===0)throw Error("Cannot calculate inverse, determinant is zero");x=M,x!==F&&(w=C[F],C[F]=C[x],C[x]=w,w=b[F],b[F]=b[x],b[x]=w);var O=C[F],A=b[F];for(x=0;x<p;x++){var N=C[x],T=b[x];if(x!==F){if(N[F]!==0){for(y=r(a(N[F]),O[F]),_=F;_<v;_++)N[_]=n(N[_],i(y,O[_]));for(_=0;_<v;_++)T[_]=n(T[_],i(y,A[_]))}}else{for(y=O[F],_=F;_<v;_++)N[_]=r(N[_],y);for(_=0;_<v;_++)T[_]=r(T[_],y)}}}return b}}}),uf="pinv",hx=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],dx=xe(uf,hx,s=>{var{typed:e,matrix:t,inv:r,deepEqual:n,equal:i,dotDivide:a,dot:u,ctranspose:f,divideScalar:c,multiply:h,add:d,Complex:p}=s;return e(uf,{"Array | Matrix":function(D){var C=mt(D)?D.size():Lt(D);switch(C.length){case 1:return m(D)?f(D):C[0]===1?r(D):a(f(D),u(D,D));case 2:{if(m(D))return f(D);var b=C[0],F=C[1];if(b===F)try{return r(D)}catch(B){if(!(B instanceof Error&&B.message.match(/Cannot calculate inverse, determinant is zero/)))throw B}return mt(D)?t(v(D.valueOf(),b,F),D.storage()):v(D,b,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+ct(C)+")")}},any:function(D){return i(D,0)?ut(D):c(1,D)}});function v(w,D,C){var{C:b,F}=_(w,D,C),B=h(r(h(f(b),b)),f(b)),M=h(f(F),r(h(F,f(F))));return h(M,B)}function x(w,D,C){for(var b=ut(w),F=0,B=0;B<D;B++){if(C<=F)return b;for(var M=B;y(b[M][F]);)if(M++,D===M&&(M=B,F++,C===F))return b;[b[M],b[B]]=[b[B],b[M]];for(var O=b[B][F],A=0;A<C;A++)b[B][A]=a(b[B][A],O);for(var N=0;N<D;N++)if(N!==B){O=b[N][F];for(var T=0;T<C;T++)b[N][T]=d(b[N][T],h(-1,h(O,b[B][T])))}F++}return b}function _(w,D,C){var b=x(w,D,C),F=w.map((M,O)=>M.filter((A,N)=>N<D&&!y(u(b[N],b[N])))),B=b.filter((M,O)=>!y(u(b[O],b[O])));return{C:F,F:B}}function y(w){return i(d(w,p(1,1)),d(0,p(1,1)))}function m(w){return n(d(w,p(1,1)),d(h(w,0),p(1,1)))}}),px="divide",_x=["typed","matrix","multiply","equalScalar","divideScalar","inv"],vx=xe(px,_x,s=>{var{typed:e,matrix:t,multiply:r,equalScalar:n,divideScalar:i,inv:a}=s,u=Ha({typed:e,equalScalar:n}),f=ja({typed:e});return e("divide",Fl({"Array | Matrix, Array | Matrix":function(h,d){return r(h,a(d))},"DenseMatrix, any":function(h,d){return f(h,d,i,!1)},"SparseMatrix, any":function(h,d){return u(h,d,i,!1)},"Array, any":function(h,d){return f(t(h),d,i,!1).valueOf()},"any, Array | Matrix":function(h,d){return r(h,a(d))}},i.signatures))}),lf="sum",gx=["typed","config","add","numeric"],mx=xe(lf,gx,s=>{var{typed:e,config:t,add:r,numeric:n}=s;return e(lf,{"Array | Matrix":i,"Array | Matrix, number | BigNumber":a,"...":function(f){if(ro(f))throw new TypeError("Scalar values expected in function sum");return i(f)}});function i(u){var f;return as(u,function(c){try{f=f===void 0?c:r(f,c)}catch(h){throw Ln(h,"sum",c)}}),f===void 0&&(f=n(0,t.number)),typeof f=="string"&&(f=n(f,t.number)),f}function a(u,f){try{var c=Wa(u,f,r);return c}catch(h){throw Ln(h,"sum")}}}),cf="median",xx=["typed","add","divide","compare","partitionSelect"],yx=xe(cf,xx,s=>{var{typed:e,add:t,divide:r,compare:n,partitionSelect:i}=s;function a(c){try{c=Ia(c.valueOf());var h=c.length;if(h===0)throw new Error("Cannot calculate median of an empty array");if(h%2===0){for(var d=h/2-1,p=i(c,d+1),v=c[d],x=0;x<d;++x)n(c[x],v)>0&&(v=c[x]);return f(v,p)}else{var _=i(c,(h-1)/2);return u(_)}}catch(y){throw Ln(y,"median")}}var u=e({"number | BigNumber | Complex | Unit":function(h){return h}}),f=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(h,d){return r(t(h,d),2)}});return e(cf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(h,d){throw new Error("median(A, dim) is not yet supported")},"...":function(h){if(ro(h))throw new TypeError("Scalar values expected in function median");return a(h)}})}),Dx={},wx=Object.freeze({__proto__:null,default:Dx}),bx=Mt(wx),po=Dv({config:Er}),Ya=Av({}),Za=Mv({}),Va=Ov({}),cn=$v({Matrix:Va}),Ie=E_({BigNumber:po,Complex:Ya,DenseMatrix:cn,Fraction:Za}),Ex=dg({typed:Ie}),_o=_g({typed:Ie}),Ax=ig({BigNumber:po,typed:Ie}),ff=rm({typed:Ie}),Pn=Zv({config:Er,typed:Ie}),vo=Pv({typed:Ie}),Cx=Uv({typed:Ie}),go=Vg({typed:Ie}),hf=tg({typed:Ie}),Ga=Kv({Matrix:Va,equalScalar:Pn,typed:Ie}),df=gg({typed:Ie}),pf=Hv({typed:Ie}),Ka=fg({typed:Ie}),_f=ag({Fraction:Za,typed:Ie}),vf=zv({typed:Ie}),Pt=lg({DenseMatrix:cn,Matrix:Va,SparseMatrix:Ga,typed:Ie}),gf=bm({isNaN:pf,isNumeric:vf,typed:Ie}),us=Bm({bignumber:Ax,fraction:_f,number:hf}),Fx=Am({config:Er,multiplyScalar:go,numeric:us,typed:Ie}),Bx=_m({isInteger:vo,matrix:Pt,typed:Ie}),mf=gm({matrix:Pt,config:Er,typed:Ie}),xf=xm({matrix:Pt,typed:Ie}),ni=im({isInteger:vo,matrix:Pt,typed:Ie}),Mx=om({prod:Fx,size:mf,typed:Ie}),Nx=Dm({conj:ff,transpose:xf,typed:Ie}),ls=Nm({numeric:us,typed:Ie}),Sx=Im({DenseMatrix:cn,concat:ni,divideScalar:ls,equalScalar:Pn,matrix:Pt,typed:Ie}),yf=km({DenseMatrix:cn,concat:ni,equalScalar:Pn,matrix:Pt,typed:Ie}),Df=um({BigNumber:po,DenseMatrix:cn,SparseMatrix:Ga,config:Er,matrix:Pt,typed:Ie}),Ox=cm({matrix:Pt,multiplyScalar:go,typed:Ie}),Tx=Um({DenseMatrix:cn,concat:ni,config:Er,matrix:Pt,typed:Ie}),Ix=Qg({DenseMatrix:cn,concat:ni,equalScalar:Pn,matrix:Pt,subtractScalar:df,typed:Ie,unaryMinus:Ka}),cs=rx({DenseMatrix:cn,SparseMatrix:Ga,addScalar:_o,concat:ni,equalScalar:Pn,matrix:Pt,typed:Ie}),wf=Rm({BigNumber:po,DenseMatrix:cn,Fraction:Za,concat:ni,config:Er,equalScalar:Pn,matrix:Pt,typed:Ie}),$x=Vm({equal:yf,typed:Ie}),bf=ix({addScalar:_o,conj:ff,multiplyScalar:go,size:mf,typed:Ie}),Rx=jm({DenseMatrix:cn,concat:ni,config:Er,matrix:Pt,typed:Ie}),Xa=ex({config:Er,numeric:us,smaller:Tx,typed:Ie}),Bi=Kg({addScalar:_o,dot:bf,equalScalar:Pn,matrix:Pt,multiplyScalar:go,typed:Ie}),Lx=Km({compare:wf,isNaN:pf,isNumeric:vf,typed:Ie}),Px=mx({add:cs,config:Er,numeric:us,typed:Ie}),kx=ax({add:cs,matrix:Pt,typed:Ie}),Ef=lx({divideScalar:ls,isZero:Cx,matrix:Pt,multiply:Bi,subtractScalar:df,typed:Ie,unaryMinus:Ka}),zx=Qm({config:Er,larger:Rx,numeric:us,typed:Ie}),mo=fx({abs:Ex,addScalar:_o,det:Ef,divideScalar:ls,identity:Df,matrix:Pt,multiply:Bi,typed:Ie,unaryMinus:Ka}),qx=dx({Complex:Ya,add:cs,ctranspose:Nx,deepEqual:$x,divideScalar:ls,dot:bf,dotDivide:Sx,equal:yf,inv:mo,matrix:Pt,multiply:Bi,typed:Ie}),Ux=Om({Complex:Ya,config:Er,fraction:_f,identity:Df,inv:mo,matrix:Pt,multiply:Bi,number:hf,typed:Ie}),Wx=vx({divideScalar:ls,equalScalar:Pn,inv:mo,matrix:Pt,multiply:Bi,typed:Ie}),Af=yx({add:cs,compare:wf,divide:Wx,partitionSelect:Lx,typed:Ie});class Hx{constructor(e,t,r){U(this,"_cacheData");U(this,"_variables");U(this,"_math");U(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}alma({series:e,length:t,offset:r,sigma:n,floor:i},a){if(t===void 0||r===void 0||n===void 0)return;const u=this._cacheDataList(e,t,`alma_${a}`);if(u===void 0)return;let f=r*(t-1);i&&(f=Math.floor(f));const c=t/n;let h=0,d=0;for(let p=0;p<=t-1;p++){const v=Math.exp(-1*Math.pow(p-f,2)/(2*Math.pow(c,2)));h+=v,d+=u[u.length-1-(t-p-1)]*v}return d/h}sma({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const i=this._cacheDataList(e,t,`sma_${r}`);if(i===void 0)return;const a=i.slice(-t);return n=Px(...a)/t,n}rma({source:e,length:t},r){if(e===void 0||t===void 0||isNaN(e))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=e,this._cacheData[`sma_${r}`]=n;const{sum:i}=this._cacheData[`rma_${r}`]||{},a=1/t,u=i===void 0?this.sma({source:e,length:t},r):a*e+(1-a)*(i||0);return this._cacheDataHandle(`rma_${r}`,{sum:u}),u}atr({length:e},t){const{high:r,close:n}=this._cacheData[`atr_${t}`]||{},{high:i,close:a,low:u}=this._variables,f=r===void 0?i-u:Math.max(Math.max(i-u,Math.abs(i-n)),Math.abs(u-n));return this._cacheDataHandle(`atr_${t}`,{high:i,close:a}),this.rma({source:f,length:e},t)}barssince({condition:e},t){let{count:r}=this._cacheData[`barssince_${t}`]||{};if(e)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${t}`,{count:r}),r}stdev({source:e,length:t,biased:r=!0},n){if(e===void 0||isNaN(e)||t===void 0)return;const i=this._cacheDataList(e,t,`stdev_${n}`),a=this.sma({source:e,length:t},n);if(i===void 0)return;let u=0;for(let f=0;f<t;f++){const c=this._sum(i[i.length-1-f],-(a||0));u+=c*c}return r||t<=1?Math.sqrt(u/t):Math.sqrt(u/(t-1))}_sum(e,t){let n=e+t;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:e,length:t,mult:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const i=this.sma({source:e,length:t},n),a=this.stdev({source:e,length:t},n);if(i===void 0||a===void 0)return[];const u=r*a;return[i,i+u,i-u]}bbw({series:e,length:t,mult:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const i=this.sma({source:e,length:t},n),a=this.stdev({source:e,length:t},n);if(i===void 0||a===void 0)return;const u=r*a;return(i+u-(i-u))/i}cci({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t},r),i=this.dev({source:e,length:t},r);if(!(n===void 0||i===void 0))return(e-n)/(.015*i)}change({source:e,length:t=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=e,this._cacheData[`change_${r}`]=n;const i=n[n.length-1-t];if(!(e===void 0||isNaN(e)))return i===void 0?i:typeof e=="boolean"?i!==e:e-i}cmo({series:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.change({source:e},r);if(n===void 0)return;const i=this._math.sum({source:n>=0?n:0,length:t},`sm1_${r}`),a=this._math.sum({source:n>=0?0:-n,length:t},`sm2_${r}`);if(!(i===void 0||a===void 0))return 100*(i-a)/(i+a)}cog({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${r}`),i=this._math.sum({source:e,length:t},r);if(i===void 0||n===void 0)return;let a=0;for(let u=0;u<t;u++){const f=n[n.length-1-u];a+=f*(u+1)}return-a/i}correlation({source1:e,source2:t,length:r},n){if(e===void 0||isNaN(e)||t===void 0||isNaN(t)||r===void 0)return;const i=this._cacheDataList([e,t],r,`correlation_${n}`),a=this.sma({source:e,length:r},`sma1_${n}`),u=this.sma({source:t,length:r},`sma2_${n}`);if(a===void 0||u===void 0||i===void 0)return;let f=0,c=0,h=0;for(let p=0;p<r;p++){const[v,x]=i[i.length-1-p],_=v-a,y=x-u;f+=_*y,c+=_*_,h+=y*y}return isNaN(c)||isNaN(f)||isNaN(h)?void 0:f/Math.sqrt(c*h)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n>=i&&e<t||n<=i&&e>t}crossover({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n<=i&&e>t}crossunder({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const{source1:n,source2:i}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:e,source2:t}),n===void 0||i===void 0?!1:n>=i&&e<t}cum({source:e=0},t){e=isNaN(e)?0:e;let{sum:r}=this._cacheData[`cum_${t}`]||{};return r=r||0,r+=e,this._cacheDataHandle(`cum_${t}`,{sum:r}),r}dev({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t},r);let i=0;const a=this._cacheDataList(e,t,`dev_${r}`);if(!(!a||n===void 0)){for(let u=0;u<t;u++){const f=a[a.length-1-u];i+=Math.abs(f-n)}return i/t}}dmi({diLength:e,adxSmoothing:t},r){if(e===void 0||t===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:i,high:a,close:u,PDMS:f,NDMS:c,TRS:h,ADX:d,count:p=0}=this._cacheData[n]||{},{low:v,high:x,close:_}=this._variables;if(i===void 0||a===void 0||u===void 0)return this._cacheData[n]={low:v,high:x,close:_,PDMS:f,NDMS:c,TRS:x-v,count:1},[void 0,void 0,void 0];let y=x-a,m=i-v;y=y>m&&y>0?y:0,m=m>y&&m>0?m:0,y===m&&(y=m=0);const w=Math.max(x-v,Math.abs(x-u),Math.abs(v-u));if(p<e)return this._cacheDataHandle(n,{low:v,high:x,close:_,PDMS:(f||0)+y,NDMS:(c||0)+m,TRS:(h||0)+w,count:p+1}),[void 0,void 0,void 0];{const D=f-f/e+y,C=c-c/e+m,b=h-h/e+w,F=D/b*100,B=C/b*100,M=Math.abs((F-B)/(F+B))*100;let O=M,A=[F,B,void 0];if(p+1-e<t){const N=p+1-e;O=((d||0)*(N-1)+M)/N}else O=(d*(t-1)+M)/t,A=[F,B,O];return this._cacheDataHandle(n,{low:v,high:x,close:_,PDMS:D,NDMS:C,TRS:b,ADX:O,count:p+1}),A}}ema({source:e,length:t},r){if(e===void 0||t===void 0||isNaN(e))return;let{sum:n,count:i=1}=this._cacheData[`ema_${r}`]||{};const a=this.sma({source:e,length:t},r);if(i>t){const u=2/(t+1);n=n===void 0?e:u*e+(1-u)*(n||0)}else n=a;return i+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:i}),n}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const{source:n,fallings:i=[]}=this._cacheData[`falling_${r}`]||{};i.push(n>e);const a=i.slice(-t);return this._cacheDataHandle(`falling_${r}`,{source:e,fallings:a}),a.length<t?!1:a.every(u=>u)}rising({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const{source:n,risings:i=[]}=this._cacheData[`rising_${r}`]||{};i.push(n<e);const a=i.slice(-t);return this._cacheDataHandle(`rising_${r}`,{source:e,risings:a}),a.length<t?!1:a.every(u=>u)}highest({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`highest_${r}`]=n;const u=n.filter(()=>!0);if(!(u.length<t))return Math.max(...u.slice(-t))}highestbars({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`highestbars_${r}`]=n;const u=n.filter(()=>!0);return u.length<t?void 0:u.slice(-t).reduce((c,h,d,p)=>h>=p[c]?d:c,0)-t+1}wma({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${r}`);if(!n)return;let i=0,a=0;for(let u=0;u<t;u++){const f=(t-u)*t;i+=f,a+=n[n.length-1-u]*f}return a/i}hma({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t},r),i=this.wma({source:e,length:Math.round(t/2)},r);return n===void 0||i===void 0?void 0:this.wma({source:2*i-n,length:Math.floor(Math.sqrt(t))},`hma_${r}`)}kc({series:e,length:t,mult:r,useTrueRange:n=!0},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[void 0,void 0,void 0];const a=this.ema({source:e,length:t},i),{ta:u,high:f,low:c}=this._variables,h=n?u.tr:f-c,d=this.ema({source:h,length:t},`range_${i}`);return[a,a+d*r,a-d*r]}kcw({series:e,length:t,mult:r,useTrueRange:n=!0},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const a=this.ema({source:e,length:t},i),{ta:u,high:f,low:c}=this._variables,h=n?u.tr:f-c,d=this.ema({source:h,length:t},`range_${i}`);return(a+d*r-(a-d*r))/a}linreg({source:e,length:t,offset:r},n){if(t===void 0||r===void 0)return;const i=this._cacheDataList(e,t,`dev_${n}`);if(!i)return;const a=i.slice(-t).filter(v=>v!==void 0);let u=0,f=0,c=0,h=0;for(const[v,x]of a.entries())u+=v,f+=x,c+=v*x,h+=v*v;const d=(t*c-u*f)/(t*h-u*u);return(f-d*u)/t+d*(t-1-r)}lowest({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`lowest_${r}`]=n;const u=n.filter(()=>!0);if(!(u.length<t))return Math.min(...u.slice(-t))}lowestbars({source:e,length:t},r){if(t===void 0||t<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:i,bar_index:a}=this._variables;typeof e!="number"?n[a]=i:n[a]=e,this._cacheData[`lowestbars_${r}`]=n;const u=n.filter(()=>!0);return u.length<t?void 0:u.slice(-t).reduce((c,h,d,p)=>h<=p[c]?d:c,0)-t+1}macd({source:e,fastlen:t,slowlen:r,siglen:n},i){if(e===void 0||isNaN(e)||t===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const a=this.ema({source:e,length:t},`ema1_${i}`),u=this.ema({source:e,length:r},`ema2_${i}`);if(a===void 0||u===void 0)return[void 0,void 0,void 0];const f=a-u,c=this.ema({source:f,length:n},`macd_${i}`);if(c===void 0)return[f,c,void 0];const h=f-c;return[f,c,h]}max({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`max_${t}`]||0;return e>r&&(r=e),this._cacheData[`max_${t}`]=r,r}min({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`min_${t}`]||1/0;return e<r&&(r=e),this._cacheData[`min_${t}`]=r,r}median({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${r}`);if(n)return Af(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:n}=this._variables,i=this.change({source:e},r),a=this._math.sum({source:n*(i>=0?0:e),length:t},`lower_${r}`),u=this._math.sum({source:n*(i<=0?0:e),length:t},`upper_${r}`);if(!(u===void 0||a===void 0))return 100-100/(1+u/a)}mode({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${r}`);if(n)return Xa(gf(n.slice(-t)))}mom({source:e,length:t},r){if(t===void 0||t<0)return;const n=`mom_${r}`,i=this._cacheData[n]||[];if(i[this._variables.bar_index]=e,this._cacheData[n]=i,i.length<=t||e===void 0||isNaN(e))return;let a=i.length-t-1,u;for(;u===void 0&&a>=0;)u=i[a],a--;return u===void 0?u:e-u}percentile_linear_interpolation({source:e,length:t,percentage:r},n){if(t===void 0||r===void 0||t<0||r<0||r>100)return;const i=this._cacheDataList(e,t+1,`percentile_linear_interpolation_${n}`);if(!i)return;const a=this._sort(i.slice(-(t+1))),u=a.length;r/=100;const f=1/(u*2);if(r<=f)return a[0];if(r>=1-1/(u*2))return a[u-1];for(const[c,h]of a.entries()){const d=a[c-1];if(r<(c+.5)/u)return d===void 0||h===void 0?void 0:d+(h-d)*(r-(c-.5)/u)/(1/u)}}percentile_nearest_rank({source:e,length:t,percentage:r},n){if(t===void 0||r===void 0||e===void 0||isNaN(e)||t<0||r<0||r>100)return;const i=this._cacheDataList(e,t,`percentile_nearest_rank_${n}`);if(!i)return;const a=this._sort(i.slice(-t)),u=r/100*a.length,f=Math.ceil(u)-1;return a[f>=a.length?a.length-1:f]}percentrank({source:e,length:t},r){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${r}`);if(!n)return;const i=n.slice(-(t+1)),a=e;if(a===void 0)return;let u=0;for(let f=0;f<i.length;f++)i[f]!==void 0&&(i[f]<a||i[f]===a&&f<t)&&u++;return u/(i.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},n){const i=new it;let{close:a,open:u,low:f,high:c}=this._variables;const h=`pivot_point_levels_${n}`,{close:d,low:p,high:v,open:x,result:_}=this._cacheData[h]||{};if(!t&&(v&&p&&(c=Math.max(v,c),f=Math.min(p,f)),this._cacheDataHandle(h,{close:a,open:u,low:f,high:c,result:_}),!r))return i._value=_||[],i;const y={close:a,open:u,low:f,high:c};t===!0&&!r&&(a=d,u=x,f=p,c=v);const m=this._getPivotPointLevels(c,f,a,u,r,e);return this._cacheDataHandle(h,{...y,result:m}),i._value=m,i}_getPivotPointLevels(e,t,r,n,i,a){if(r===void 0||n===void 0||t===void 0||e===void 0)return[];switch(a){case ei.traditional:return this._traditional(e,t,r);case ei.fibonacci:return this._fibonacci(e,t,r);case ei.woodie:return i?[]:this._woodie(e,t);case ei.classic:return this._classic(e,t,r);case ei.dm:return this._DM(e,t,r,n);case ei.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const n=(e+t+r)/3,i=n*2-t,a=n+(e-t),u=n*2+(e-2*t),f=n*3+(e-3*t),c=n*4+(e-4*t),h=n*2-e,d=n-(e-t),p=n*2-(2*e-t),v=n*3-(3*e-t),x=n*4-(4*e-t);return[n,i,h,a,d,u,p,f,v,c,x]}_fibonacci(e,t,r){const n=(e+t+r)/3,i=n+.382*(e-t),a=n-.382*(e-t),u=n+.618*(e-t),f=n-.618*(e-t),c=n+(e-t),h=n-(e-t);return[n,i,a,u,f,c,h]}_woodie(e,t){const{open:r}=this._variables,n=(e+t+2*r)/4,i=2*n-t,a=2*n-e,u=n+(e-t),f=n-(e-t),c=e+2*(n-t),h=t-2*(e-n),d=c+(e-t),p=h-(e-t);return[n,i,a,u,f,c,h,d,p]}_classic(e,t,r){const n=(e+t+r)/3,i=2*n-t,a=2*n-e,u=n+(e-t),f=n-(e-t),c=n+2*(e-t),h=n-2*(e-t),d=n+3*(e-t),p=n-3*(e-t);return[n,i,a,u,f,c,h,d,p]}_DM(e,t,r,n){let i;n===r?i=e+t+2*r:r>n?i=2*e+t+r:i=2*t+e+r;const a=i/4,u=i/2-t,f=i/2-e;return[a,u,f]}_camarilla(e,t,r){const n=(e+t+r)/3,i=r+1.1*(e-t)/12,a=r-1.1*(e-t)/12,u=r+1.1*(e-t)/6,f=r-1.1*(e-t)/6,c=r+1.1*(e-t)/4,h=r-1.1*(e-t)/4,d=r+1.1*(e-t)/2,p=r-1.1*(e-t)/2,v=e/t*r,x=r-(v-r);return[n,i,a,u,f,c,h,d,p,v,x]}pivothigh({source:e=this._variables.high,leftbars:t,rightbars:r},n){if(t===void 0||r===void 0||t<0||r<0)return;const i=this._cacheDataList(e,t+r+1,`pivothigh_${n}`);if(!i)return;const a=i.slice(-(t+r+1)),u=a[t];return Math.max(...a)===u?u:void 0}pivotlow({source:e=this._variables.low,leftbars:t,rightbars:r},n){if(t===void 0||r===void 0||t<0||r<0)return;const i=this._cacheDataList(e,t+r+1,`pivotlow_${n}`);if(!i)return;const a=i.slice(-(t+r+1)),u=a[t];return Math.min(...a)===u?u:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._cacheDataList(e,t,`range_${r}`);if(!n)return;const i=n.filter(f=>f!==void 0).slice(-t),a=Math.max(...i),u=Math.min(...i);return a-u}roc({source:e,length:t},r){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${r}`),i=this.change({source:e,length:t},r);if(n)return 100*i/n[n.length-1-t]}rsi({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},i=Math.max(e-n,0),a=Math.max(n-e,0),u=this.rma({source:i,length:t},`rma1_${r}`),f=this.rma({source:a,length:t},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:e}),!(u===void 0||f===void 0))return 100-100/(1+u/f)}sar({start:e,inc:t,max:r},n){if(e===void 0||t===void 0||r===void 0)return;const{close:i,low:a,high:u,preLow:f,preHigh:c,data:h={}}=this._cacheData[`sar_${n}`]||{};let{result:d,maxMin:p,acceleration:v,isBelow:x}=h,_=!1;const{close:y,low:m,high:w,bar_index:D}=this._variables;return D===1&&(y>i?(x=!0,p=w,d=a):(x=!1,p=m,d=u),_=!0,v=e),d=d+v*(p-d),x?d>m&&(_=!0,x=!1,d=Math.max(w,p||0),p=m,v=e):d<w&&(_=!0,x=!0,d=Math.min(m,p||0),p=w,v=e),_||(x?w>(p||0)&&(p=w,v=Math.min((v||0)+t,r)):m<(p||0)&&(p=m,v=Math.min((v||0)+t,r))),x?(d=Math.min(d,a),D>1&&(d=Math.min(d,f))):(d=Math.max(d,u),D>1&&(d=Math.max(d,c))),this._cacheDataHandle(`sar_${n}`,{high:w,close:y,low:m,preLow:a,preHigh:u,data:Object.assign(h,{result:d,maxMin:p,acceleration:v,isBelow:x})}),d}stoch({source:e,high:t,low:r,length:n},i){if(n===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||n<0)return;const a=this.lowest({source:r,length:n},i),u=this.highest({source:t,length:n},i);if(!(a===void 0||u===void 0))return 100*(this._variables.close-a)/(u-a)}supertrend({factor:e,atrPeriod:t},r){if(e===void 0||t===void 0)return[void 0,void 0];const{hl2:n,close:i}=this._variables,a=`supertrend_${r}`,{upperBand:u,lowerBand:f,superTrend:c,atr:h,close:d}=this._cacheData[a]||{},p=this.atr({length:t},r);if(p===void 0)return this._cacheDataHandle(a,{close:i}),[void 0,void 0];let v=n+e*p,x=n-e*p;const _=u||0,y=f||0;x=x>y||d<y?x:y,v=v<_||d>_?v:_;let m;h===void 0?m=1:c===_?m=i>v?-1:1:m=i<x?1:-1;const w=m===-1?x:v;return this._cacheDataHandle(a,{upperBand:v,lowerBand:x,superTrend:w,atr:p,close:i}),[w,m]}swma({source:e},t){let{list:r}=this._cacheData[`swma_${t}`]||{};if(r||(r=[]),r.push(e),r=r.slice(-4),this._cacheDataHandle(`swma_${t}`,{list:r}),!(r.filter(n=>n!==void 0).length<4))return r[3]*1/6+r[2]*2/6+r[1]*2/6+r[0]*1/6}tr({handle_na:e=!1},t){const{close:r,low:n,high:i}=this._variables,{close:a}=this._cacheData[`tr_${t}`]||{};return this._cacheDataHandle(`tr_${t}`,{close:r}),a===void 0?e?i-n:void 0:Math.max(i-n,Math.abs(i-a),Math.abs(n-a))}tsi({source:e,short_length:t,long_length:r},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const i=this.change({source:e},n);if(i===void 0)return;const a=this.ema({source:Math.abs(i),length:t},`absema1_${n}`),u=this.ema({source:i,length:t},`ema1_${n}`);if(u===void 0)return;const f=this.ema({source:u,length:r},`ema2_${n}`),c=this.ema({source:a,length:t},`absema2_${n}`);if(f!==void 0)return f/c}valuewhen({condition:e,source:t,occurrence:r},n){if(t===void 0||r===void 0||r<0)return;let{list:i}=this._cacheData[`valuewhen_${n}`]||{};return i||(i=[]),e&&i.push(t),this._cacheDataHandle(`valuewhen_${n}`,{list:i}),i[i.length-1-r]}variance({source:e,length:t,biased:r=!0},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const i=this.sma({source:e,length:t},n),a=this._cacheDataList(e,t,`mode_${n}`);if(!a||i===void 0)return;const u=a.filter(c=>c!==void 0&&!isNaN(c)).slice(-t);if(u.length<t)return;const f=u.reduce((c,h)=>c+Math.pow(h-i,2),0);if(f!==void 0)return r||t<=1?f/t:f/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},n){if(e===void 0)return;t=t===void 0?this._timeframe.change({timeframe:"1D"},n):t;const{volume:i}=this._variables;let{sum:a=0,sumV:u=0,count:f=0,isReset:c,sumS:h=0}=this._cacheData[`vwap_${n}`]||{};if(t&&(a=u=f=h=0,c=!0),!c)return r!==void 0?[]:void 0;const d=e*i+a,p=i+u,v=d/p;return f++,r!==void 0?(h=i*Math.pow(e,2)+h,this._cacheDataHandle(`vwap_${n}`,{sum:d,sumV:p,count:f,isReset:c,sumS:h}),this._computeBands(h,p,r,v)):(this._cacheDataHandle(`vwap_${n}`,{sum:d,sumV:p,count:f,isReset:c}),v)}_computeBands(e,t,r,n){let i=e/t-Math.pow(n,2);i=i<0?0:i;const a=Math.sqrt(i),u=a!==void 0&&!isNaN(a)?n+r*a:void 0,f=a!==void 0&&!isNaN(a)?n-r*a:void 0;return[n,u,f]}vwma({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0||t<=0)return;const{volume:n}=this._variables,i=this.sma({source:e*n,length:t},`sma1_${r}`),a=this.sma({source:n,length:t},`sma2_${r}`);if(!(i===void 0||a===void 0))return i/a}wpr({length:e},t){if(e===void 0||e<=0)return;const r=this.highest({length:e},t),n=this.lowest({length:e},t),{close:i}=this._variables;if(!(r===void 0||n===void 0))return(r-i)/(r-n)*-100}_sort(e){const t=e.length;for(let r=0;r<t;r++){let n={};for(let i=0;i<t-r;i++){const{currentVal:a,currentIndex:u}=n,f=e[i];if(f!==void 0){if(a!==void 0&&f<a){e.splice(i,1),e.splice(u,0,f),n={currentIndex:u+1,currentVal:a};continue}n={currentIndex:i,currentVal:f}}}}return e}_cacheDataList(e,t,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=e,this._cacheData[r]=n;const i=n.filter(()=>!0);if(!(i.length<t))return i}_cacheDataHandle(e,t){const{barIndex:r}=this._cacheData[e]||{};r!==this._variables.bar_index&&(this._cacheData[e]=Object.assign(t,{barIndex:this._variables.bar_index}))}}const Kt={onlyInLoop:"'$text' is only allowed inside loops",invalidType:"Invalid argument 'expr$index' in 'operator SQBR' call",typeUseError:"Cannot specify a type form '$text' without also specifying the type.",notTypeKeyword:"'$text' is not a valid type keyword in variable declaration",undeclared:"Undeclared identifier '$name'",repeatVar:"'$name' is already defined",typeRepeatErr:"$keyword '$name' is already defined.",typeMismatch:"Cannot call '$operator' with argument '$index'. An argument of '$typeE' type was used but a '$typeR' is expected.",assignTypeMismatch:"Cannot assign a value of the `$typeE` type to the '$name' variable. The variable is declared with the `$typeR` type.",voidNotVar:"Void expression cannot be assigned to a variable",declareTypeErr:"Declared type '$type' is not compatible with assigned type '$valueType'",mapKeyValErr:"Cannot put <$typeA, $typeB> pairs into a map containing `$typeC` keys and `$typeD` values. The maps passed into the `$name()` function must have the same key types and value types.",inputSourceErr:"Invalid value for the '$name' parameter of the '$funcName' function. Possible values: [open, high, low, close, hl2, hlc3, ohlc4, hlcc4, volume].",buildInUseErr:"Cannot use '$name' as the default value of a type's field. The default value cannot be a function, variable or calculation.",argsLenErr:"Too many arguments passed into the `$name()` function call. Passed $lenA arguments but expected $lenB.",requiredParamErr:"No value assigned to the `$argName` parameter in $name()",argsSyntaxErr:"Syntax error after the argument for `$argName`. Arguments without their parameter name cannot be used after arguments with parameter names.",requestArgsErr:"Type $type cannot be used in $name '$argName' argument",mapKeyErr:"Incorrect `key` type `$type` in the variable. The `key` type must be one of the following: int, float, string, bool, color.",templateErr:"Incorrect number of arguments for the template: $countA expected, $countB passed.",templateNoSupportErr:"The '$name()' function does not support templates",ifOrSwitchTypeErr:"Return type of one of the '$keyword' blocks is not compatible with return type of other block(s) ($types)",argsNameErr:"The '$name' function does not have an argument with the name '$argName'",noFiledErr:"Object has no field $name",methodNotExistErr:"Could not find method or method reference '$methodName' for '$name'",tupleVarErr:"Syntax error: The quantities of tuple elements on each side of the assignment operator do not match. The right side has $indexA but the left side has $indexB.",tupleLeftVarErr:"Invalid assignment. Cannot assign a tuple to a variable '$name'.",tupleRightVarErr:"Cannot assign a variable to a tuple. The right side must be a function call or structure ('if', 'switch', 'for', 'while') returning a tuple with the same number of elements.",tempateTypeErr:"Syntax error: Only templates for arrays and matrices consist of a single type identifier enclosed in angle brackets.",qualifierErr:"'$name' is not a valid type qualifier. Possible values: 'const', 'simple', 'series'",notFindFuncErr:"Could not find function or function reference '$name'",naVarErr:"Value with NA type cannot be assigned to a variable that was defined without type keyword",notHistoryErr:"Variable '$name' doesn't have history values",defaultValueErr:"The default value cannot be a function, variable or calculation.",defaultValueTypeErr:"Default value of type $typeE can not be assigned to an argument of type $typeR",typeFieldErr:"In a type declaration, all fields without a default value must be explicitly typified.",unaryErr:"Syntax error at input '$sign'",funcArgAssignErr:"Function arguments cannot be mutable ('$name')",declaredErr:"A variable declared with the '$prefix' keyword cannot accept values of the '$type' form. Assign a '$prefix' value to this variable or remove the '$prefix' keyword from its declaration.",globalFuncErr:"Cannot use '$name' in local scope",onlyStatementErr:"Scripts must contain one declaration statement: `indicator()`, `strategy()` or `library()`, Your script has $count.",modifyGlobalVarErr:"Cannot modify global variable '$name' in function",inputDefvalErr:"Arguments of input function must be of constant type, or 'source' builtin variables.",objectIsNaErr:"Cannot access the '$name' $type of an na object. The object is 'na'.",buidinAssignErr:"Cannot assign a new value to the built-in variable '$name'.",buidinVarErr:"Cannot shadow the built-in variable `$name` because it has already been used as a built-in.",useNaErr:"Cannot use an `na` value of an unspecified type in the `$name` function.",libraryTitleErr:"Invalid argument 'title' in 'library' call. It cannot contain spaces, special characters or begin with a digit.",exportFuncArgErr:"All exported functions args should be typified",indiRunErr:"An indicator must contain at least one of the following: any `plot*()` function, `barcolor()`, `bgcolor()`, `hline()`, `alertcondition()`, or any drawing (line, label, box, table, polyline).",libraryExportErr:"A library must contain at least one exported function, method, or type.",strategyRunErr:"A strategy must contain at least one of the following: any `strategy.*()` function that creates orders, any `plot*()` function, `barcolor()`, `bgcolor()`, `hline()`, or any drawing (line, label, box, table, polyline).",exportUseErr:"Only libraries can contain exported $type.",funcRepeatErr:"The '$name' function has overloads with the same parameters. The type of parameters must be different in overloaded versions of functions.",importMultipleErr:"Cannot import a library more than once",importNotExitErr:"The user '$username' does not have a published library titled '$libraryName'",importNameRepeatErr:"More than one import uses the same alias: $name. Previous usage at line: $line",exportFuncHasInputErr:"The exported function '$func' depends on the '$name' input variable, which is not allowed.",libraryTitleIsKeywordErr:"Invalid argument 'title' in 'library' call. Token: '$name' can't be used as library title.",exportFuncUseGlobalVarErr:"Cannot use global variables in exported functions. Function: $func",loopRuntimeErr:"Loop takes too long to execute (> 500 ms)",paramsErr:"Invalid value '$value' for '$param' parameter of the '$func' function. Possible values: $targetVal",displayErr:"Invalid argument 'display' in '$func' call. Possible values: $values",exportFuncUseReqErr:"Cannot use `request.*()` call in exported function `$name()`",requestExprErr:"Type series $type cannot be used in $name 'expression' argument",argDefaultErr:"The default value assigned to a parameter must be either a literal value (e.g., `5`) or a built-in variable (e.g., `close`)",overloadFuncErr:"Cannot use global variables or any values qualified as 'input' in the local scopes of overloaded functions or methods. Remove any global variables or inputs from the scopes of all '$name()' overloads.",againAssignErr:"Unable to determine the object for the field assignment. Try putting the object into a separate variable before assigning values to its fields.",requestUserInLoopErr:"Cannot use `request.*()` call within loops or conditional structures.",enumVarNameErr:"Invalid enum name '$name': `bool`, `int`, `float`, `string`, and `color` are not allowed.",enumVarNameBuiltinErr:"Invalid object name: $name. Namespaces of built-ins cannot be used.",typeNameErr:"Invalid user-defined type name '$name': `bool`, `int`, `float`, `string`, and `color` are not allowed.",enumUseErr:"Cannot use the '$name' as a value. Use one of the enum's fields instead.",conditionalErr:"'$name' conditional expression must be of a bool type!",fortoErr:'The value of the "for" loop must be a number.',indicatorUseStrategyFuncErr:"You cannot use strategy $type ($name) in indicator script."};an.SERIES,an.SIMPLE,an.INPUT,an.CONST,an.INT,an.FLOAT,an.BOOL,an.COLOR,an.STRING;const jx=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"],Yx=["case","catch","default","delete","do","finally","function","instanceof","new","return","this","throw","try","typeof","void","with"],Zx=["linefill","polyline","matrix","series","simple","string","array","color","const","float","label","table","bool","line","box","int","map","continue","for","varip","var","in","export","import","method","switch","break","while","else","type","and","for","not","as","by","if","in","or","to"];class Vx{constructor(e,t,r){U(this,"_cacheData");U(this,"_variables");U(this,"_errorListener");U(this,"_historyInputs");U(this,"_name");this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(e){for(const t of e){const r=t.id;this._cacheData[r]=Object.assign(this._cacheData[r]||{},{...t,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${t.index}`,{modifyDefval:t.sourceTypeName||t.defval})}}input(e,t){return this._cacheHandle(e,t)}int(e,t){return this._cacheHandle(e,t,ur.INT)}bool(e,t){return this._cacheHandle(e,t,ur.BOOL)}color(e,t){return this._cacheHandle(e,t,ur.COLOR)}time(e,t){return this._cacheHandle(e,t,ur.TIME)}float(e,t){return this._cacheHandle(e,t,ur.FLOAT)}price(e,t){return this._cacheHandle(e,t,ur.PRICE)}source(e,t){return this._cacheHandle(e,t,ur.SOURCE)}string(e,t){return this._cacheHandle(e,t,ur.STRING)}symbol(e,t){return this._cacheHandle(e,t,ur.SYMBOL)}session(e,t){return this._cacheHandle(e,t,ur.SESSION)}text_area(e,t){return this._cacheHandle(e,t,ur.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,ur.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,ur.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const n=`${r||"input"}_${t}`,i=this._cacheData[n];if(e.defval===void 0&&this._errorListener.addError(Kt.inputDefvalErr,t,Ve.Error),i)i.isModify?i.sourceTypeName&&(this._cacheData[n].defval=this._variables[i.sourceTypeName]):Object.assign(this._cacheData[n],e);else{const{defval:a,display:u}=e;this._displayVerify(t,u),e={inputType:r,...e},this._cacheData[n]=e,this._judgeHistoryInputs(e),(r||e.inputType)===ur.SOURCE?this._cacheData[n].options=jx:e.options&&!e.options.includes(a)&&this._errorListener.addError(`input's defval should be in options, but '${a}' is not in [${e.options.toString()}]`,t,Ve.Error,6+((r==null?void 0:r.length)||-1))}return this._cacheData[n].defval}_judgeHistoryInputs(e){const{defval:t,sourceTypeName:r,index:n}=e;let i=r||t;const a=`in_${n}`,u=this._historyInputs[a];if(!u)self.workerStorage.setValue(this._name,a,{defval:i});else{const{defval:f,modifyDefval:c}=u;f===i?i=c||i:self.workerStorage.setValue(this._name,a,{defval:i})}r?e.sourceTypeName=i:e.defval=i}_displayVerify(e,t){!t||!t.length||t.includes(Zt.dataWindow)||t.includes(Zt.statusLine)||this._errorListener.addError(or(Kt.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,Ve.Error)}getInputs(){const e=Object.keys(this._cacheData),t=[];for(const r of e){const n=this._cacheData[r];n.id=r,t.push(n)}return t.sort((r,n)=>(r.index||0)-(n.index||0))}}class Gx{color({x:e}){return e}new({color:e,transp:t=100}){me(t)&&(t=100);const r=(100-t)/100,{r:n,g:i,b:a}=this._parseColor(e||"");return`rgba(${Math.round(n)}, ${Math.round(i)}, ${Math.round(a)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:n=0}){return me(n)&&(n=0),me(e)&&(e=0),me(t)&&(t=0),me(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-n)/100})`}g({color:e}){return e?this._parseColor(e).g:0}r({color:e}){return e?this._parseColor(e).r:0}b({color:e}){return e?this._parseColor(e).b:0}t({color:e}){return e?Math.round(this._parseColor(e).a*100):0}from_gradient({value:e,bottom_value:t,top_value:r,bottom_color:n,top_color:i}){if(me(e)||me(t)||me(r))return"rgba(0,0,0,1)";const a=(e-t)/(r-t),u=Math.min(Math.max(a,0),1),{r:f,g:c,b:h,a:d}=this._parseColor(n||"rgba(0,0,0,0)"),{r:p,g:v,b:x,a:_}=this._parseColor(i||"rgba(0,0,0,0)"),y=f+u*(p-f),m=c+u*(v-c),w=h+u*(x-h),D=d+u*(_-d);return`rgba(${Math.round(y)}, ${Math.round(m)}, ${Math.round(w)}, ${D.toFixed(2)})`}_parseColor(e){let t,r,n,i;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);const a=e.substring(7);a?i=(255-parseInt(a,16))/255:i=1}else{const a=this._parserRgbColor(e);t=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:t,g:r,b:n,a:i}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}}var We={};const Kx=Object.prototype.toString;function fs(s){const e=Kx.call(s);return e.endsWith("Array]")&&!e.includes("Big")}var Xx=Object.freeze({__proto__:null,isAnyArray:fs}),Qx=Mt(Xx);function Jx(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!fs(s))throw new TypeError("input must be an array");if(s.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,n=e.toIndex,i=n===void 0?s.length:n;if(r<0||r>=s.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=r||i>s.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=s[r],u=r+1;u<i;u++)s[u]>a&&(a=s[u]);return a}function ey(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!fs(s))throw new TypeError("input must be an array");if(s.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,n=e.toIndex,i=n===void 0?s.length:n;if(r<0||r>=s.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=r||i>s.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=s[r],u=r+1;u<i;u++)s[u]<a&&(a=s[u]);return a}function ty(s){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(fs(s)){if(s.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var t;if(e.output!==void 0){if(!fs(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(s.length);var r=ey(s),n=Jx(s);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,a=i===void 0?e.autoMinMax?r:0:i,u=e.max,f=u===void 0?e.autoMinMax?n:1:u;if(a>=f)throw new RangeError("min option must be smaller than max option");for(var c=(f-a)/(n-r),h=0;h<s.length;h++)t[h]=(s[h]-r)*c+a;return t}var ry=Object.freeze({__proto__:null,default:ty}),ny=Mt(ry);Object.defineProperty(We,"__esModule",{value:!0});var gr=Qx,Cf=ny;const xo=" ".repeat(2),Ff=" ".repeat(4);function iy(){return Bf(this)}function Bf(s,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:n=8,padMinus:i="auto"}=e;return`${s.constructor.name} {
55
55
  ${xo}[
56
56
  ${Ff}${sy(s,t,r,n,i)}
57
57
  ${xo}]
@@ -59,7 +59,7 @@ ${xo}rows: ${s.rows}
59
59
  ${xo}columns: ${s.columns}
60
60
  }`}function sy(s,e,t,r,n){const{rows:i,columns:a}=s,u=Math.min(i,e),f=Math.min(a,t),c=[];if(n==="auto"){n=!1;e:for(let h=0;h<u;h++)for(let d=0;d<f;d++)if(s.get(h,d)<0){n=!0;break e}}for(let h=0;h<u;h++){let d=[];for(let p=0;p<f;p++)d.push(oy(s.get(h,p),r,n));c.push(`${d.join(" ")}`)}return f!==a&&(c[c.length-1]+=` ... ${a-t} more columns`),u!==i&&c.push(`... ${i-e} more rows`),c.join(`
61
61
  ${Ff}`)}function oy(s,e,t){return(s>=0&&t?` ${Mf(s,e-1)}`:Mf(s,e)).padEnd(e)}function Mf(s,e){let t=s.toString();if(t.length<=e)return t;let r=s.toFixed(e);if(r.length>e&&(r=s.toFixed(Math.max(0,e-(r.length-e)))),r.length<=e&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=s.toExponential(e);return n.length>e&&(n=s.toExponential(Math.max(0,e-(n.length-e)))),n.slice(0)}function ay(s,e){s.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},s.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+r);return this},s.prototype.addM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+r.get(n,i));return this},s.add=function(r,n){return new e(r).add(n)},s.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},s.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-r);return this},s.prototype.subM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-r.get(n,i));return this},s.sub=function(r,n){return new e(r).sub(n)},s.prototype.subtract=s.prototype.sub,s.prototype.subtractS=s.prototype.subS,s.prototype.subtractM=s.prototype.subM,s.subtract=s.sub,s.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},s.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*r);return this},s.prototype.mulM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*r.get(n,i));return this},s.mul=function(r,n){return new e(r).mul(n)},s.prototype.multiply=s.prototype.mul,s.prototype.multiplyS=s.prototype.mulS,s.prototype.multiplyM=s.prototype.mulM,s.multiply=s.mul,s.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},s.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/r);return this},s.prototype.divM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/r.get(n,i));return this},s.div=function(r,n){return new e(r).div(n)},s.prototype.divide=s.prototype.div,s.prototype.divideS=s.prototype.divS,s.prototype.divideM=s.prototype.divM,s.divide=s.div,s.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},s.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%r);return this},s.prototype.modM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%r.get(n,i));return this},s.mod=function(r,n){return new e(r).mod(n)},s.prototype.modulus=s.prototype.mod,s.prototype.modulusS=s.prototype.modS,s.prototype.modulusM=s.prototype.modM,s.modulus=s.mod,s.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},s.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&r);return this},s.prototype.andM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&r.get(n,i));return this},s.and=function(r,n){return new e(r).and(n)},s.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},s.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|r);return this},s.prototype.orM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|r.get(n,i));return this},s.or=function(r,n){return new e(r).or(n)},s.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},s.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^r);return this},s.prototype.xorM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^r.get(n,i));return this},s.xor=function(r,n){return new e(r).xor(n)},s.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},s.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<r);return this},s.prototype.leftShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<r.get(n,i));return this},s.leftShift=function(r,n){return new e(r).leftShift(n)},s.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},s.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>r);return this},s.prototype.signPropagatingRightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>r.get(n,i));return this},s.signPropagatingRightShift=function(r,n){return new e(r).signPropagatingRightShift(n)},s.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},s.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>r);return this},s.prototype.rightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>r.get(n,i));return this},s.rightShift=function(r,n){return new e(r).rightShift(n)},s.prototype.zeroFillRightShift=s.prototype.rightShift,s.prototype.zeroFillRightShiftS=s.prototype.rightShiftS,s.prototype.zeroFillRightShiftM=s.prototype.rightShiftM,s.zeroFillRightShift=s.rightShift,s.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},s.not=function(r){return new e(r).not()},s.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},s.abs=function(r){return new e(r).abs()},s.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},s.acos=function(r){return new e(r).acos()},s.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},s.acosh=function(r){return new e(r).acosh()},s.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},s.asin=function(r){return new e(r).asin()},s.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},s.asinh=function(r){return new e(r).asinh()},s.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},s.atan=function(r){return new e(r).atan()},s.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},s.atanh=function(r){return new e(r).atanh()},s.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},s.cbrt=function(r){return new e(r).cbrt()},s.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},s.ceil=function(r){return new e(r).ceil()},s.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},s.clz32=function(r){return new e(r).clz32()},s.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},s.cos=function(r){return new e(r).cos()},s.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},s.cosh=function(r){return new e(r).cosh()},s.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},s.exp=function(r){return new e(r).exp()},s.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},s.expm1=function(r){return new e(r).expm1()},s.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},s.floor=function(r){return new e(r).floor()},s.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},s.fround=function(r){return new e(r).fround()},s.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},s.log=function(r){return new e(r).log()},s.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},s.log1p=function(r){return new e(r).log1p()},s.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},s.log10=function(r){return new e(r).log10()},s.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},s.log2=function(r){return new e(r).log2()},s.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},s.round=function(r){return new e(r).round()},s.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},s.sign=function(r){return new e(r).sign()},s.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},s.sin=function(r){return new e(r).sin()},s.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},s.sinh=function(r){return new e(r).sinh()},s.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},s.sqrt=function(r){return new e(r).sqrt()},s.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},s.tan=function(r){return new e(r).tan()},s.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},s.tanh=function(r){return new e(r).tanh()},s.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},s.trunc=function(r){return new e(r).trunc()},s.pow=function(r,n){return new e(r).pow(n)},s.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},s.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,Math.pow(this.get(n,i),r));return this},s.prototype.powM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,Math.pow(this.get(n,i),r.get(n,i)));return this}}function $r(s,e,t){let r=t?s.rows:s.rows-1;if(e<0||e>r)throw new RangeError("Row index out of range")}function Rr(s,e,t){let r=t?s.columns:s.columns-1;if(e<0||e>r)throw new RangeError("Column index out of range")}function Mi(s,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==s.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function Ni(s,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==s.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function Qa(s,e){if(!gr.isAnyArray(e))throw new TypeError("row indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=s.rows)throw new RangeError("row indices are out of range")}function Ja(s,e){if(!gr.isAnyArray(e))throw new TypeError("column indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=s.columns)throw new RangeError("column indices are out of range")}function eu(s,e,t,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Do("startRow",e),Do("endRow",t),Do("startColumn",r),Do("endColumn",n),e>t||r>n||e<0||e>=s.rows||t<0||t>=s.rows||r<0||r>=s.columns||n<0||n>=s.columns)throw new RangeError("Submatrix indices are out of range")}function yo(s,e=0){let t=[];for(let r=0;r<s;r++)t.push(e);return t}function Do(s,e){if(typeof e!="number")throw new TypeError(`${s} must be a number`)}function Si(s){if(s.isEmpty())throw new Error("Empty matrix has no elements to index")}function uy(s){let e=yo(s.rows);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[t]+=s.get(t,r);return e}function ly(s){let e=yo(s.columns);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[r]+=s.get(t,r);return e}function cy(s){let e=0;for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)e+=s.get(t,r);return e}function fy(s){let e=yo(s.rows,1);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[t]*=s.get(t,r);return e}function hy(s){let e=yo(s.columns,1);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[r]*=s.get(t,r);return e}function dy(s){let e=1;for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)e*=s.get(t,r);return e}function py(s,e,t){const r=s.rows,n=s.columns,i=[];for(let a=0;a<r;a++){let u=0,f=0,c=0;for(let h=0;h<n;h++)c=s.get(a,h)-t[a],u+=c,f+=c*c;e?i.push((f-u*u/n)/(n-1)):i.push((f-u*u/n)/n)}return i}function _y(s,e,t){const r=s.rows,n=s.columns,i=[];for(let a=0;a<n;a++){let u=0,f=0,c=0;for(let h=0;h<r;h++)c=s.get(h,a)-t[a],u+=c,f+=c*c;e?i.push((f-u*u/r)/(r-1)):i.push((f-u*u/r)/r)}return i}function vy(s,e,t){const r=s.rows,n=s.columns,i=r*n;let a=0,u=0,f=0;for(let c=0;c<r;c++)for(let h=0;h<n;h++)f=s.get(c,h)-t,a+=f,u+=f*f;return e?(u-a*a/i)/(i-1):(u-a*a/i)/i}function gy(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e[t])}function my(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e[r])}function xy(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e)}function yy(s){const e=[];for(let t=0;t<s.rows;t++){let r=0;for(let n=0;n<s.columns;n++)r+=Math.pow(s.get(t,n),2)/(s.columns-1);e.push(Math.sqrt(r))}return e}function Dy(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e[t])}function wy(s){const e=[];for(let t=0;t<s.columns;t++){let r=0;for(let n=0;n<s.rows;n++)r+=Math.pow(s.get(n,t),2)/(s.rows-1);e.push(Math.sqrt(r))}return e}function by(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e[r])}function Ey(s){const e=s.size-1;let t=0;for(let r=0;r<s.columns;r++)for(let n=0;n<s.rows;n++)t+=Math.pow(s.get(n,r),2)/e;return Math.sqrt(t)}function Ay(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e)}class ke{static from1DArray(e,t,r){if(e*t!==r.length)throw new RangeError("data length does not match given dimensions");let i=new ve(e,t);for(let a=0;a<e;a++)for(let u=0;u<t;u++)i.set(a,u,r[a*t+u]);return i}static rowVector(e){let t=new ve(1,e.length);for(let r=0;r<e.length;r++)t.set(0,r,e[r]);return t}static columnVector(e){let t=new ve(e.length,1);for(let r=0;r<e.length;r++)t.set(r,0,e[r]);return t}static zeros(e,t){return new ve(e,t)}static ones(e,t){return new ve(e,t).fill(1)}static rand(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let i=new ve(e,t);for(let a=0;a<e;a++)for(let u=0;u<t;u++)i.set(a,u,n());return i}static randInt(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:i=1e3,random:a=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(i))throw new TypeError("max must be an integer");if(n>=i)throw new RangeError("min must be smaller than max");let u=i-n,f=new ve(e,t);for(let c=0;c<e;c++)for(let h=0;h<t;h++){let d=n+Math.round(a()*u);f.set(c,h,d)}return f}static eye(e,t,r){t===void 0&&(t=e),r===void 0&&(r=1);let n=Math.min(e,t),i=this.zeros(e,t);for(let a=0;a<n;a++)i.set(a,a,r);return i}static diag(e,t,r){let n=e.length;t===void 0&&(t=n),r===void 0&&(r=t);let i=Math.min(n,t,r),a=this.zeros(t,r);for(let u=0;u<i;u++)a.set(u,u,e[u]);return a}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,n=e.columns,i=new ve(r,n);for(let a=0;a<r;a++)for(let u=0;u<n;u++)i.set(a,u,Math.min(e.get(a,u),t.get(a,u)));return i}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,n=e.columns,i=new this(r,n);for(let a=0;a<r;a++)for(let u=0;u<n;u++)i.set(a,u,Math.max(e.get(a,u),t.get(a,u)));return i}static checkMatrix(e){return ke.isMatrix(e)?e:new ve(e)}static isMatrix(e){return e!=null&&e.klass==="Matrix"}get size(){return this.rows*this.columns}apply(e){if(typeof e!="function")throw new TypeError("callback must be a function");for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.call(this,t,r);return this}to1DArray(){let e=[];for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}to2DArray(){let e=[];for(let t=0;t<this.rows;t++){e.push([]);for(let r=0;r<this.columns;r++)e[t].push(this.get(t,r))}return e}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let e=0;e<this.rows;e++)for(let t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let e=0;e<this.rows;e++)if(this.get(e,e)!==0)return!1;return!0}isEchelonForm(){let e=0,t=0,r=-1,n=!0,i=!1;for(;e<this.rows&&n;){for(t=0,i=!1;t<this.columns&&i===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(i=!0,r=t):(n=!1,i=!0);e++}return n}isReducedEchelonForm(){let e=0,t=0,r=-1,n=!0,i=!1;for(;e<this.rows&&n;){for(t=0,i=!1;t<this.columns&&i===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(i=!0,r=t):(n=!1,i=!0);for(let a=t+1;a<this.rows;a++)this.get(e,a)!==0&&(n=!1);e++}return n}echelonForm(){let e=this.clone(),t=0,r=0;for(;t<e.rows&&r<e.columns;){let n=t;for(let i=t;i<e.rows;i++)e.get(i,r)>e.get(n,r)&&(n=i);if(e.get(n,r)===0)r++;else{e.swapRows(t,n);let i=e.get(t,r);for(let a=r;a<e.columns;a++)e.set(t,a,e.get(t,a)/i);for(let a=t+1;a<e.rows;a++){let u=e.get(a,r)/e.get(t,r);e.set(a,r,0);for(let f=r+1;f<e.columns;f++)e.set(a,f,e.get(a,f)-e.get(t,f)*u)}t++,r++}}return e}reducedEchelonForm(){let e=this.echelonForm(),t=e.columns,r=e.rows,n=r-1;for(;n>=0;)if(e.maxRow(n)===0)n--;else{let i=0,a=!1;for(;i<r&&a===!1;)e.get(n,i)===1?a=!0:i++;for(let u=0;u<n;u++){let f=e.get(u,i);for(let c=i;c<t;c++){let h=e.get(u,c)-f*e.get(n,c);e.set(u,c,h)}}n--}return e}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{rows:t=1,columns:r=1}=e;if(!Number.isInteger(t)||t<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new ve(this.rows*t,this.columns*r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*i,this.columns*a);return n}fill(e){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,e);return this}neg(){return this.mulS(-1)}getRow(e){$r(this,e);let t=[];for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}getRowVector(e){return ve.rowVector(this.getRow(e))}setRow(e,t){$r(this,e),t=Mi(this,t);for(let r=0;r<this.columns;r++)this.set(e,r,t[r]);return this}swapRows(e,t){$r(this,e),$r(this,t);for(let r=0;r<this.columns;r++){let n=this.get(e,r);this.set(e,r,this.get(t,r)),this.set(t,r,n)}return this}getColumn(e){Rr(this,e);let t=[];for(let r=0;r<this.rows;r++)t.push(this.get(r,e));return t}getColumnVector(e){return ve.columnVector(this.getColumn(e))}setColumn(e,t){Rr(this,e),t=Ni(this,t);for(let r=0;r<this.rows;r++)this.set(r,e,t[r]);return this}swapColumns(e,t){Rr(this,e),Rr(this,t);for(let r=0;r<this.rows;r++){let n=this.get(r,e);this.set(r,e,this.get(r,t)),this.set(r,t,n)}return this}addRowVector(e){e=Mi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[r]);return this}subRowVector(e){e=Mi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[r]);return this}mulRowVector(e){e=Mi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[r]);return this}divRowVector(e){e=Mi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[r]);return this}addColumnVector(e){e=Ni(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[t]);return this}subColumnVector(e){e=Ni(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[t]);return this}mulColumnVector(e){e=Ni(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[t]);return this}divColumnVector(e){e=Ni(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[t]);return this}mulRow(e,t){$r(this,e);for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this}mulColumn(e,t){Rr(this,e);for(let r=0;r<this.rows;r++)this.set(r,e,this.get(r,e)*t);return this}max(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t[r]&&(t[r]=this.get(r,n));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t[n]&&(t[n]=this.get(r,n));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n));return t}default:throw new Error(`invalid option: ${e}`)}}maxIndex(){Si(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n),t[0]=r,t[1]=n);return t}min(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t[r]&&(t[r]=this.get(r,n));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t[n]&&(t[n]=this.get(r,n));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n));return t}default:throw new Error(`invalid option: ${e}`)}}minIndex(){Si(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e&&(e=this.get(r,n),t[0]=r,t[1]=n);return t}maxRow(e){if($r(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxRowIndex(e){$r(this,e),Si(this);let t=this.get(e,0),r=[e,0];for(let n=1;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[1]=n);return r}minRow(e){if($r(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minRowIndex(e){$r(this,e),Si(this);let t=this.get(e,0),r=[e,0];for(let n=1;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[1]=n);return r}maxColumn(e){if(Rr(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)>t&&(t=this.get(r,e));return t}maxColumnIndex(e){Rr(this,e),Si(this);let t=this.get(0,e),r=[0,e];for(let n=1;n<this.rows;n++)this.get(n,e)>t&&(t=this.get(n,e),r[0]=n);return r}minColumn(e){if(Rr(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)<t&&(t=this.get(r,e));return t}minColumnIndex(e){Rr(this,e),Si(this);let t=this.get(0,e),r=[0,e];for(let n=1;n<this.rows;n++)this.get(n,e)<t&&(t=this.get(n,e),r[0]=n);return r}diag(){let e=Math.min(this.rows,this.columns),t=[];for(let r=0;r<e;r++)t.push(this.get(r,r));return t}norm(e="frobenius"){switch(e){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${e}`)}}cumulativeSum(){let e=0;for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r),this.set(t,r,e);return this}dot(e){ke.isMatrix(e)&&(e=e.to1DArray());let t=this.to1DArray();if(t.length!==e.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<t.length;n++)r+=t[n]*e[n];return r}mmul(e){e=ve.checkMatrix(e);let t=this.rows,r=this.columns,n=e.columns,i=new ve(t,n),a=new Float64Array(r);for(let u=0;u<n;u++){for(let f=0;f<r;f++)a[f]=e.get(f,u);for(let f=0;f<t;f++){let c=0;for(let h=0;h<r;h++)c+=this.get(f,h)*a[h];i.set(f,u,c)}}return i}strassen2x2(e){e=ve.checkMatrix(e);let t=new ve(2,2);const r=this.get(0,0),n=e.get(0,0),i=this.get(0,1),a=e.get(0,1),u=this.get(1,0),f=e.get(1,0),c=this.get(1,1),h=e.get(1,1),d=(r+c)*(n+h),p=(u+c)*n,v=r*(a-h),x=c*(f-n),_=(r+i)*h,y=(u-r)*(n+a),m=(i-c)*(f+h),w=d+x-_+m,D=v+_,C=p+x,b=d-p+v+y;return t.set(0,0,w),t.set(0,1,D),t.set(1,0,C),t.set(1,1,b),t}strassen3x3(e){e=ve.checkMatrix(e);let t=new ve(3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),a=this.get(1,0),u=this.get(1,1),f=this.get(1,2),c=this.get(2,0),h=this.get(2,1),d=this.get(2,2),p=e.get(0,0),v=e.get(0,1),x=e.get(0,2),_=e.get(1,0),y=e.get(1,1),m=e.get(1,2),w=e.get(2,0),D=e.get(2,1),C=e.get(2,2),b=(r+n+i-a-u-h-d)*y,F=(r-a)*(-v+y),B=u*(-p+v+_-y-m-w+C),M=(-r+a+u)*(p-v+y),O=(a+u)*(-p+v),A=r*p,N=(-r+c+h)*(p-x+m),T=(-r+c)*(x-m),R=(c+h)*(-p+x),k=(r+n+i-u-f-c-h)*m,z=h*(-p+x+_-y-m-w+D),L=(-i+h+d)*(y+w-D),G=(i-d)*(y-D),H=i*w,ee=(h+d)*(-w+D),te=(-i+u+f)*(m+w-C),j=(i-f)*(m-C),X=(u+f)*(-w+C),Y=n*_,Q=f*D,pe=a*x,De=c*v,we=d*C,be=A+H+Y,Oe=b+M+O+A+L+H+ee,Fe=A+N+R+k+H+te+X,nt=F+B+M+A+H+te+j,Ye=F+M+O+A+Q,Te=H+te+j+X+pe,Re=A+N+T+z+L+G+H,xt=L+G+H+ee+De,Ut=A+N+T+R+we;return t.set(0,0,be),t.set(0,1,Oe),t.set(0,2,Fe),t.set(1,0,nt),t.set(1,1,Ye),t.set(1,2,Te),t.set(2,0,Re),t.set(2,1,xt),t.set(2,2,Ut),t}mmulStrassen(e){e=ve.checkMatrix(e);let t=this.clone(),r=t.rows,n=t.columns,i=e.rows,a=e.columns;n!==i&&console.warn(`Multiplying ${r} x ${n} and ${i} x ${a} matrix: dimensions do not match.`);function u(d,p,v){let x=d.rows,_=d.columns;if(x===p&&_===v)return d;{let y=ke.zeros(p,v);return y=y.setSubMatrix(d,0,0),y}}let f=Math.max(r,i),c=Math.max(n,a);t=u(t,f,c),e=u(e,f,c);function h(d,p,v,x){if(v<=512||x<=512)return d.mmul(p);v%2===1&&x%2===1?(d=u(d,v+1,x+1),p=u(p,v+1,x+1)):v%2===1?(d=u(d,v+1,x),p=u(p,v+1,x)):x%2===1&&(d=u(d,v,x+1),p=u(p,v,x+1));let _=parseInt(d.rows/2,10),y=parseInt(d.columns/2,10),m=d.subMatrix(0,_-1,0,y-1),w=p.subMatrix(0,_-1,0,y-1),D=d.subMatrix(0,_-1,y,d.columns-1),C=p.subMatrix(0,_-1,y,p.columns-1),b=d.subMatrix(_,d.rows-1,0,y-1),F=p.subMatrix(_,p.rows-1,0,y-1),B=d.subMatrix(_,d.rows-1,y,d.columns-1),M=p.subMatrix(_,p.rows-1,y,p.columns-1),O=h(ke.add(m,B),ke.add(w,M),_,y),A=h(ke.add(b,B),w,_,y),N=h(m,ke.sub(C,M),_,y),T=h(B,ke.sub(F,w),_,y),R=h(ke.add(m,D),M,_,y),k=h(ke.sub(b,m),ke.add(w,C),_,y),z=h(ke.sub(D,B),ke.add(F,M),_,y),L=ke.add(O,T);L.sub(R),L.add(z);let G=ke.add(N,R),H=ke.add(A,T),ee=ke.sub(O,A);ee.add(N),ee.add(k);let te=ke.zeros(2*L.rows,2*L.columns);return te=te.setSubMatrix(L,0,0),te=te.setSubMatrix(G,L.rows,0),te=te.setSubMatrix(H,0,L.columns),te=te.setSubMatrix(ee,L.rows,L.columns),te.subMatrix(0,v-1,0,x-1)}return h(t,e,f,c)}scaleRows(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let n=new ve(this.rows,this.columns);for(let i=0;i<this.rows;i++){const a=this.getRow(i);a.length>0&&Cf(a,{min:t,max:r,output:a}),n.setRow(i,a)}return n}scaleColumns(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let n=new ve(this.rows,this.columns);for(let i=0;i<this.columns;i++){const a=this.getColumn(i);a.length&&Cf(a,{min:t,max:r,output:a}),n.setColumn(i,a)}return n}flipRows(){const e=Math.ceil(this.columns/2);for(let t=0;t<this.rows;t++)for(let r=0;r<e;r++){let n=this.get(t,r),i=this.get(t,this.columns-1-r);this.set(t,r,i),this.set(t,this.columns-1-r,n)}return this}flipColumns(){const e=Math.ceil(this.rows/2);for(let t=0;t<this.columns;t++)for(let r=0;r<e;r++){let n=this.get(r,t),i=this.get(this.rows-1-r,t);this.set(r,t,i),this.set(this.rows-1-r,t,n)}return this}kroneckerProduct(e){e=ve.checkMatrix(e);let t=this.rows,r=this.columns,n=e.rows,i=e.columns,a=new ve(t*n,r*i);for(let u=0;u<t;u++)for(let f=0;f<r;f++)for(let c=0;c<n;c++)for(let h=0;h<i;h++)a.set(n*u+c,i*f+h,this.get(u,f)*e.get(c,h));return a}kroneckerSum(e){if(e=ve.checkMatrix(e),!this.isSquare()||!e.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let t=this.rows,r=e.rows,n=this.kroneckerProduct(ve.eye(r,r)),i=ve.eye(t,t).kroneckerProduct(e);return n.add(i)}transpose(){let e=new ve(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.set(r,t,this.get(t,r));return e}sortRows(e=Nf){for(let t=0;t<this.rows;t++)this.setRow(t,this.getRow(t).sort(e));return this}sortColumns(e=Nf){for(let t=0;t<this.columns;t++)this.setColumn(t,this.getColumn(t).sort(e));return this}subMatrix(e,t,r,n){eu(this,e,t,r,n);let i=new ve(t-e+1,n-r+1);for(let a=e;a<=t;a++)for(let u=r;u<=n;u++)i.set(a-e,u-r,this.get(a,u));return i}subMatrixRow(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.columns-1),t>r||t<0||t>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new ve(e.length,r-t+1);for(let i=0;i<e.length;i++)for(let a=t;a<=r;a++){if(e[i]<0||e[i]>=this.rows)throw new RangeError(`Row index out of range: ${e[i]}`);n.set(i,a-t,this.get(e[i],a))}return n}subMatrixColumn(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.rows-1),t>r||t<0||t>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new ve(r-t+1,e.length);for(let i=0;i<e.length;i++)for(let a=t;a<=r;a++){if(e[i]<0||e[i]>=this.columns)throw new RangeError(`Column index out of range: ${e[i]}`);n.set(a-t,i,this.get(a,e[i]))}return n}setSubMatrix(e,t,r){if(e=ve.checkMatrix(e),e.isEmpty())return this;let n=t+e.rows-1,i=r+e.columns-1;eu(this,t,n,r,i);for(let a=0;a<e.rows;a++)for(let u=0;u<e.columns;u++)this.set(t+a,r+u,e.get(a,u));return this}selection(e,t){Qa(this,e),Ja(this,t);let r=new ve(e.length,t.length);for(let n=0;n<e.length;n++){let i=e[n];for(let a=0;a<t.length;a++){let u=t[a];r.set(n,a,this.get(i,u))}}return r}trace(){let e=Math.min(this.rows,this.columns),t=0;for(let r=0;r<e;r++)t+=this.get(r,r);return t}clone(){return this.constructor.copy(this,new ve(this.rows,this.columns))}static copy(e,t){for(const[r,n,i]of e.entries())t.set(r,n,i);return t}sum(e){switch(e){case"row":return uy(this);case"column":return ly(this);case void 0:return cy(this);default:throw new Error(`invalid option: ${e}`)}}product(e){switch(e){case"row":return fy(this);case"column":return hy(this);case void 0:return dy(this);default:throw new Error(`invalid option: ${e}`)}}mean(e){const t=this.sum(e);switch(e){case"row":{for(let r=0;r<this.rows;r++)t[r]/=this.columns;return t}case"column":{for(let r=0;r<this.columns;r++)t[r]/=this.rows;return t}case void 0:return t/this.size;default:throw new Error(`invalid option: ${e}`)}}variance(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(e)}=t;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(e){case"row":{if(!gr.isAnyArray(n))throw new TypeError("mean must be an array");return py(this,r,n)}case"column":{if(!gr.isAnyArray(n))throw new TypeError("mean must be an array");return _y(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return vy(this,r,n)}default:throw new Error(`invalid option: ${e}`)}}standardDeviation(e,t){typeof e=="object"&&(t=e,e=void 0);const r=this.variance(e,t);if(e===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{center:r=this.mean(e)}=t;switch(e){case"row":{if(!gr.isAnyArray(r))throw new TypeError("center must be an array");return gy(this,r),this}case"column":{if(!gr.isAnyArray(r))throw new TypeError("center must be an array");return my(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return xy(this,r),this}default:throw new Error(`invalid option: ${e}`)}}scale(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");let r=t.scale;switch(e){case"row":{if(r===void 0)r=yy(this);else if(!gr.isAnyArray(r))throw new TypeError("scale must be an array");return Dy(this,r),this}case"column":{if(r===void 0)r=wy(this);else if(!gr.isAnyArray(r))throw new TypeError("scale must be an array");return by(this,r),this}case void 0:{if(r===void 0)r=Ey(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return Ay(this,r),this}default:throw new Error(`invalid option: ${e}`)}}toString(e){return Bf(this,e)}[Symbol.iterator](){return this.entries()}*entries(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield[e,t,this.get(e,t)]}*values(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield this.get(e,t)}}ke.prototype.klass="Matrix",typeof Symbol<"u"&&(ke.prototype[Symbol.for("nodejs.util.inspect.custom")]=iy);function Nf(s,e){return s-e}function Cy(s){return s.every(e=>typeof e=="number")}ke.random=ke.rand,ke.randomInt=ke.randInt,ke.diagonal=ke.diag,ke.prototype.diagonal=ke.prototype.diag,ke.identity=ke.eye,ke.prototype.negate=ke.prototype.neg,ke.prototype.tensorProduct=ke.prototype.kroneckerProduct;let ve=(Ri=class extends ke{constructor(t,r){super();_l(this,_s);U(this,"data");if(Ri.isMatrix(t))vl(this,_s,gl).call(this,t.rows,t.columns),Ri.copy(t,this);else if(Number.isInteger(t)&&t>=0)vl(this,_s,gl).call(this,t,r);else if(gr.isAnyArray(t)){const n=t;if(t=n.length,r=t?n[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let i=0;i<t;i++){if(n[i].length!==r)throw new RangeError("Inconsistent array dimensions");if(!Cy(n[i]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[i]))}this.rows=t,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(t,r,n){return this.data[t][r]=n,this}get(t,r){return this.data[t][r]}removeRow(t){return $r(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,r){return r===void 0&&(r=t,t=this.rows),$r(this,t,!0),r=Float64Array.from(Mi(this,r)),this.data.splice(t,0,r),this.rows+=1,this}removeColumn(t){Rr(this,t);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let i=0;i<t;i++)n[i]=this.data[r][i];for(let i=t+1;i<this.columns;i++)n[i-1]=this.data[r][i];this.data[r]=n}return this.columns-=1,this}addColumn(t,r){typeof r>"u"&&(r=t,t=this.columns),Rr(this,t,!0),r=Ni(this,r);for(let n=0;n<this.rows;n++){const i=new Float64Array(this.columns+1);let a=0;for(;a<t;a++)i[a]=this.data[n][a];for(i[a++]=r[n];a<this.columns+1;a++)i[a]=this.data[n][a-1];this.data[n]=i}return this.columns+=1,this}},_s=new WeakSet,gl=function(t,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<t;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=t,this.columns=r},Ri);ay(ke,ve);const $o=class $o extends ke{constructor(t){super();_l(this,tr,void 0);if(ve.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");Ea(this,tr,ve.copy(t,new ve(t.rows,t.rows)))}else if(Number.isInteger(t)&&t>=0)Ea(this,tr,new ve(t,t));else if(Ea(this,tr,new ve(t)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return on(this,tr).size}get rows(){return on(this,tr).rows}get columns(){return on(this,tr).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return ve.isMatrix(t)&&t.klassType==="SymmetricMatrix"}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}clone(){const t=new $o(this.diagonalSize);for(const[r,n,i]of this.upperRightEntries())t.set(r,n,i);return t}toMatrix(){return new ve(this)}get(t,r){return on(this,tr).get(t,r)}set(t,r,n){return on(this,tr).set(t,r,n),on(this,tr).set(r,t,n),this}removeCross(t){return on(this,tr).removeRow(t),on(this,tr).removeColumn(t),this}addCross(t,r){r===void 0&&(r=t,t=this.diagonalSize);const n=r.slice();return n.splice(t,1),on(this,tr).addRow(t,n),on(this,tr).addColumn(t,r),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,i]of t.entries())i||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:t}=this,r=new Array(t*(t+1)/2);for(let n=0,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=t&&(n=++i);return r}static fromCompact(t){const r=t.length,n=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const i=new $o(n);for(let a=0,u=0,f=0;f<r;f++)i.set(a,u,t[f]),++a>=n&&(a=++u);return i}*upperRightEntries(){for(let t=0,r=0;t<this.diagonalSize;void 0){const n=this.get(t,r);yield[t,r,n],++r>=this.diagonalSize&&(r=++t)}}*upperRightValues(){for(let t=0,r=0;t<this.diagonalSize;void 0)yield this.get(t,r),++r>=this.diagonalSize&&(r=++t)}};tr=new WeakMap;let ii=$o;ii.prototype.klassType="SymmetricMatrix";class wo extends ii{static isDistanceMatrix(e){return ii.isSymmetricMatrix(e)&&e.klassSubType==="DistanceMatrix"}constructor(e){if(super(e),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(e,t,r){return e===t&&(r=0),super.set(e,t,r)}addCross(e,t){return t===void 0&&(t=e,e=this.diagonalSize),t=t.slice(),t[e]=0,super.addCross(e,t)}toSymmetricMatrix(){return new ii(this)}clone(){const e=new wo(this.diagonalSize);for(const[t,r,n]of this.upperRightEntries())t!==r&&e.set(t,r,n);return e}toCompact(){const{diagonalSize:e}=this,t=(e-1)*e/2,r=new Array(t);for(let n=1,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=e&&(n=++i+1);return r}static fromCompact(e){const t=e.length,r=(Math.sqrt(8*t+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(e)}`);const n=new this(r);for(let i=1,a=0,u=0;u<t;u++)n.set(i,a,e[u]),++i>=r&&(i=++a+1);return n}}wo.prototype.klassSubType="DistanceMatrix";class xn extends ke{constructor(e,t,r){super(),this.matrix=e,this.rows=t,this.columns=r}}class Fy extends xn{constructor(e,t){Rr(e,t),super(e,e.rows,1),this.column=t}set(e,t,r){return this.matrix.set(e,this.column,r),this}get(e){return this.matrix.get(e,this.column)}}class By extends xn{constructor(e,t){Ja(e,t),super(e,e.rows,t.length),this.columnIndices=t}set(e,t,r){return this.matrix.set(e,this.columnIndices[t],r),this}get(e,t){return this.matrix.get(e,this.columnIndices[t])}}class My extends xn{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(e,this.columns-t-1,r),this}get(e,t){return this.matrix.get(e,this.columns-t-1)}}class Ny extends xn{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(this.rows-e-1,t,r),this}get(e,t){return this.matrix.get(this.rows-e-1,t)}}class Sy extends xn{constructor(e,t){$r(e,t),super(e,1,e.columns),this.row=t}set(e,t,r){return this.matrix.set(this.row,t,r),this}get(e,t){return this.matrix.get(this.row,t)}}class Oy extends xn{constructor(e,t){Qa(e,t),super(e,t.length,e.columns),this.rowIndices=t}set(e,t,r){return this.matrix.set(this.rowIndices[e],t,r),this}get(e,t){return this.matrix.get(this.rowIndices[e],t)}}class bo extends xn{constructor(e,t,r){Qa(e,t),Ja(e,r),super(e,t.length,r.length),this.rowIndices=t,this.columnIndices=r}set(e,t,r){return this.matrix.set(this.rowIndices[e],this.columnIndices[t],r),this}get(e,t){return this.matrix.get(this.rowIndices[e],this.columnIndices[t])}}class Ty extends xn{constructor(e,t,r,n,i){eu(e,t,r,n,i),super(e,r-t+1,i-n+1),this.startRow=t,this.startColumn=n}set(e,t,r){return this.matrix.set(this.startRow+e,this.startColumn+t,r),this}get(e,t){return this.matrix.get(this.startRow+e,this.startColumn+t)}}class Iy extends xn{constructor(e){super(e,e.columns,e.rows)}set(e,t,r){return this.matrix.set(t,e,r),this}get(e,t){return this.matrix.get(t,e)}}class Sf extends ke{constructor(e,t={}){const{rows:r=1}=t;if(e.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=e.length/r,this.data=e}set(e,t,r){let n=this._calculateIndex(e,t);return this.data[n]=r,this}get(e,t){let r=this._calculateIndex(e,t);return this.data[r]}_calculateIndex(e,t){return e*this.columns+t}}class Ar extends ke{constructor(e){super(),this.data=e,this.rows=e.length,this.columns=e[0].length}set(e,t,r){return this.data[e][t]=r,this}get(e,t){return this.data[e][t]}}function $y(s,e){if(gr.isAnyArray(s))return s[0]&&gr.isAnyArray(s[0])?new Ar(s):new Sf(s,e);throw new Error("the argument is not an array")}class Eo{constructor(e){e=Ar.checkMatrix(e);let t=e.clone(),r=t.rows,n=t.columns,i=new Float64Array(r),a=1,u,f,c,h,d,p,v,x,_;for(u=0;u<r;u++)i[u]=u;for(x=new Float64Array(r),f=0;f<n;f++){for(u=0;u<r;u++)x[u]=t.get(u,f);for(u=0;u<r;u++){for(_=Math.min(u,f),d=0,c=0;c<_;c++)d+=t.get(u,c)*x[c];x[u]-=d,t.set(u,f,x[u])}for(h=f,u=f+1;u<r;u++)Math.abs(x[u])>Math.abs(x[h])&&(h=u);if(h!==f){for(c=0;c<n;c++)p=t.get(h,c),t.set(h,c,t.get(f,c)),t.set(f,c,p);v=i[h],i[h]=i[f],i[f]=v,a=-a}if(f<r&&t.get(f,f)!==0)for(u=f+1;u<r;u++)t.set(u,f,t.get(u,f)/t.get(f,f))}this.LU=t,this.pivotVector=i,this.pivotSign=a}isSingular(){let e=this.LU,t=e.columns;for(let r=0;r<t;r++)if(e.get(r,r)===0)return!0;return!1}solve(e){e=ve.checkMatrix(e);let t=this.LU;if(t.rows!==e.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=e.columns,i=e.subMatrixRow(this.pivotVector,0,n-1),a=t.columns,u,f,c;for(c=0;c<a;c++)for(u=c+1;u<a;u++)for(f=0;f<n;f++)i.set(u,f,i.get(u,f)-i.get(c,f)*t.get(u,c));for(c=a-1;c>=0;c--){for(f=0;f<n;f++)i.set(c,f,i.get(c,f)/t.get(c,c));for(u=0;u<c;u++)for(f=0;f<n;f++)i.set(u,f,i.get(u,f)-i.get(c,f)*t.get(u,c))}return i}get determinant(){let e=this.LU;if(!e.isSquare())throw new Error("Matrix must be square");let t=this.pivotSign,r=e.columns;for(let n=0;n<r;n++)t*=e.get(n,n);return t}get lowerTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,n=new ve(t,r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)i>a?n.set(i,a,e.get(i,a)):i===a?n.set(i,a,1):n.set(i,a,0);return n}get upperTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,n=new ve(t,r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)i<=a?n.set(i,a,e.get(i,a)):n.set(i,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function yn(s,e){let t=0;return Math.abs(s)>Math.abs(e)?(t=e/s,Math.abs(s)*Math.sqrt(1+t*t)):e!==0?(t=s/e,Math.abs(e)*Math.sqrt(1+t*t)):0}class tu{constructor(e){e=Ar.checkMatrix(e);let t=e.clone(),r=e.rows,n=e.columns,i=new Float64Array(n),a,u,f,c;for(f=0;f<n;f++){let h=0;for(a=f;a<r;a++)h=yn(h,t.get(a,f));if(h!==0){for(t.get(f,f)<0&&(h=-h),a=f;a<r;a++)t.set(a,f,t.get(a,f)/h);for(t.set(f,f,t.get(f,f)+1),u=f+1;u<n;u++){for(c=0,a=f;a<r;a++)c+=t.get(a,f)*t.get(a,u);for(c=-c/t.get(f,f),a=f;a<r;a++)t.set(a,u,t.get(a,u)+c*t.get(a,f))}}i[f]=-h}this.QR=t,this.Rdiag=i}solve(e){e=ve.checkMatrix(e);let t=this.QR,r=t.rows;if(e.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=e.columns,i=e.clone(),a=t.columns,u,f,c,h;for(c=0;c<a;c++)for(f=0;f<n;f++){for(h=0,u=c;u<r;u++)h+=t.get(u,c)*i.get(u,f);for(h=-h/t.get(c,c),u=c;u<r;u++)i.set(u,f,i.get(u,f)+h*t.get(u,c))}for(c=a-1;c>=0;c--){for(f=0;f<n;f++)i.set(c,f,i.get(c,f)/this.Rdiag[c]);for(u=0;u<c;u++)for(f=0;f<n;f++)i.set(u,f,i.get(u,f)-i.get(c,f)*t.get(u,c))}return i.subMatrix(0,a-1,0,n-1)}isFullRank(){let e=this.QR.columns;for(let t=0;t<e;t++)if(this.Rdiag[t]===0)return!1;return!0}get upperTriangularMatrix(){let e=this.QR,t=e.columns,r=new ve(t,t),n,i;for(n=0;n<t;n++)for(i=0;i<t;i++)n<i?r.set(n,i,e.get(n,i)):n===i?r.set(n,i,this.Rdiag[n]):r.set(n,i,0);return r}get orthogonalMatrix(){let e=this.QR,t=e.rows,r=e.columns,n=new ve(t,r),i,a,u,f;for(u=r-1;u>=0;u--){for(i=0;i<t;i++)n.set(i,u,0);for(n.set(u,u,1),a=u;a<r;a++)if(e.get(u,u)!==0){for(f=0,i=u;i<t;i++)f+=e.get(i,u)*n.get(i,a);for(f=-f/e.get(u,u),i=u;i<t;i++)n.set(i,a,n.get(i,a)+f*e.get(i,u))}}return n}}class Oi{constructor(e,t={}){if(e=Ar.checkMatrix(e),e.isEmpty())throw new Error("Matrix must be non-empty");let r=e.rows,n=e.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:a=!0,autoTranspose:u=!1}=t;let f=!!i,c=!!a,h=!1,d;if(r<n)if(!u)d=e.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{d=e.transpose(),r=d.rows,n=d.columns,h=!0;let A=f;f=c,c=A}else d=e.clone();let p=Math.min(r,n),v=Math.min(r+1,n),x=new Float64Array(v),_=new ve(r,p),y=new ve(n,n),m=new Float64Array(n),w=new Float64Array(r),D=new Float64Array(v);for(let A=0;A<v;A++)D[A]=A;let C=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),F=Math.max(C,b);for(let A=0;A<F;A++){if(A<C){x[A]=0;for(let N=A;N<r;N++)x[A]=yn(x[A],d.get(N,A));if(x[A]!==0){d.get(A,A)<0&&(x[A]=-x[A]);for(let N=A;N<r;N++)d.set(N,A,d.get(N,A)/x[A]);d.set(A,A,d.get(A,A)+1)}x[A]=-x[A]}for(let N=A+1;N<n;N++){if(A<C&&x[A]!==0){let T=0;for(let R=A;R<r;R++)T+=d.get(R,A)*d.get(R,N);T=-T/d.get(A,A);for(let R=A;R<r;R++)d.set(R,N,d.get(R,N)+T*d.get(R,A))}m[N]=d.get(A,N)}if(f&&A<C)for(let N=A;N<r;N++)_.set(N,A,d.get(N,A));if(A<b){m[A]=0;for(let N=A+1;N<n;N++)m[A]=yn(m[A],m[N]);if(m[A]!==0){m[A+1]<0&&(m[A]=0-m[A]);for(let N=A+1;N<n;N++)m[N]/=m[A];m[A+1]+=1}if(m[A]=-m[A],A+1<r&&m[A]!==0){for(let N=A+1;N<r;N++)w[N]=0;for(let N=A+1;N<r;N++)for(let T=A+1;T<n;T++)w[N]+=m[T]*d.get(N,T);for(let N=A+1;N<n;N++){let T=-m[N]/m[A+1];for(let R=A+1;R<r;R++)d.set(R,N,d.get(R,N)+T*w[R])}}if(c)for(let N=A+1;N<n;N++)y.set(N,A,m[N])}}let B=Math.min(n,r+1);if(C<n&&(x[C]=d.get(C,C)),r<B&&(x[B-1]=0),b+1<B&&(m[b]=d.get(b,B-1)),m[B-1]=0,f){for(let A=C;A<p;A++){for(let N=0;N<r;N++)_.set(N,A,0);_.set(A,A,1)}for(let A=C-1;A>=0;A--)if(x[A]!==0){for(let N=A+1;N<p;N++){let T=0;for(let R=A;R<r;R++)T+=_.get(R,A)*_.get(R,N);T=-T/_.get(A,A);for(let R=A;R<r;R++)_.set(R,N,_.get(R,N)+T*_.get(R,A))}for(let N=A;N<r;N++)_.set(N,A,-_.get(N,A));_.set(A,A,1+_.get(A,A));for(let N=0;N<A-1;N++)_.set(N,A,0)}else{for(let N=0;N<r;N++)_.set(N,A,0);_.set(A,A,1)}}if(c)for(let A=n-1;A>=0;A--){if(A<b&&m[A]!==0)for(let N=A+1;N<n;N++){let T=0;for(let R=A+1;R<n;R++)T+=y.get(R,A)*y.get(R,N);T=-T/y.get(A+1,A);for(let R=A+1;R<n;R++)y.set(R,N,y.get(R,N)+T*y.get(R,A))}for(let N=0;N<n;N++)y.set(N,A,0);y.set(A,A,1)}let M=B-1,O=Number.EPSILON;for(;B>0;){let A,N;for(A=B-2;A>=-1&&A!==-1;A--){const T=Number.MIN_VALUE+O*Math.abs(x[A]+Math.abs(x[A+1]));if(Math.abs(m[A])<=T||Number.isNaN(m[A])){m[A]=0;break}}if(A===B-2)N=4;else{let T;for(T=B-1;T>=A&&T!==A;T--){let R=(T!==B?Math.abs(m[T]):0)+(T!==A+1?Math.abs(m[T-1]):0);if(Math.abs(x[T])<=O*R){x[T]=0;break}}T===A?N=3:T===B-1?N=1:(N=2,A=T)}switch(A++,N){case 1:{let T=m[B-2];m[B-2]=0;for(let R=B-2;R>=A;R--){let k=yn(x[R],T),z=x[R]/k,L=T/k;if(x[R]=k,R!==A&&(T=-L*m[R-1],m[R-1]=z*m[R-1]),c)for(let G=0;G<n;G++)k=z*y.get(G,R)+L*y.get(G,B-1),y.set(G,B-1,-L*y.get(G,R)+z*y.get(G,B-1)),y.set(G,R,k)}break}case 2:{let T=m[A-1];m[A-1]=0;for(let R=A;R<B;R++){let k=yn(x[R],T),z=x[R]/k,L=T/k;if(x[R]=k,T=-L*m[R],m[R]=z*m[R],f)for(let G=0;G<r;G++)k=z*_.get(G,R)+L*_.get(G,A-1),_.set(G,A-1,-L*_.get(G,R)+z*_.get(G,A-1)),_.set(G,R,k)}break}case 3:{const T=Math.max(Math.abs(x[B-1]),Math.abs(x[B-2]),Math.abs(m[B-2]),Math.abs(x[A]),Math.abs(m[A])),R=x[B-1]/T,k=x[B-2]/T,z=m[B-2]/T,L=x[A]/T,G=m[A]/T,H=((k+R)*(k-R)+z*z)/2,ee=R*z*(R*z);let te=0;(H!==0||ee!==0)&&(H<0?te=0-Math.sqrt(H*H+ee):te=Math.sqrt(H*H+ee),te=ee/(H+te));let j=(L+R)*(L-R)+te,X=L*G;for(let Y=A;Y<B-1;Y++){let Q=yn(j,X);Q===0&&(Q=Number.MIN_VALUE);let pe=j/Q,De=X/Q;if(Y!==A&&(m[Y-1]=Q),j=pe*x[Y]+De*m[Y],m[Y]=pe*m[Y]-De*x[Y],X=De*x[Y+1],x[Y+1]=pe*x[Y+1],c)for(let we=0;we<n;we++)Q=pe*y.get(we,Y)+De*y.get(we,Y+1),y.set(we,Y+1,-De*y.get(we,Y)+pe*y.get(we,Y+1)),y.set(we,Y,Q);if(Q=yn(j,X),Q===0&&(Q=Number.MIN_VALUE),pe=j/Q,De=X/Q,x[Y]=Q,j=pe*m[Y]+De*x[Y+1],x[Y+1]=-De*m[Y]+pe*x[Y+1],X=De*m[Y+1],m[Y+1]=pe*m[Y+1],f&&Y<r-1)for(let we=0;we<r;we++)Q=pe*_.get(we,Y)+De*_.get(we,Y+1),_.set(we,Y+1,-De*_.get(we,Y)+pe*_.get(we,Y+1)),_.set(we,Y,Q)}m[B-2]=j;break}case 4:{if(x[A]<=0&&(x[A]=x[A]<0?-x[A]:0,c))for(let T=0;T<=M;T++)y.set(T,A,-y.get(T,A));for(;A<M&&!(x[A]>=x[A+1]);){let T=x[A];if(x[A]=x[A+1],x[A+1]=T,c&&A<n-1)for(let R=0;R<n;R++)T=y.get(R,A+1),y.set(R,A+1,y.get(R,A)),y.set(R,A,T);if(f&&A<r-1)for(let R=0;R<r;R++)T=_.get(R,A+1),_.set(R,A+1,_.get(R,A)),_.set(R,A,T);A++}B--;break}}}if(h){let A=y;y=_,_=A}this.m=r,this.n=n,this.s=x,this.U=_,this.V=y}solve(e){let t=e,r=this.threshold,n=this.s.length,i=ve.zeros(n,n);for(let p=0;p<n;p++)Math.abs(this.s[p])<=r?i.set(p,p,0):i.set(p,p,1/this.s[p]);let a=this.U,u=this.rightSingularVectors,f=u.mmul(i),c=u.rows,h=a.rows,d=ve.zeros(c,h);for(let p=0;p<c;p++)for(let v=0;v<h;v++){let x=0;for(let _=0;_<n;_++)x+=f.get(p,_)*a.get(v,_);d.set(p,v,x)}return d.mmul(t)}solveForDiagonal(e){return this.solve(ve.diag(e))}inverse(){let e=this.V,t=this.threshold,r=e.rows,n=e.columns,i=new ve(r,this.s.length);for(let h=0;h<r;h++)for(let d=0;d<n;d++)Math.abs(this.s[d])>t&&i.set(h,d,e.get(h,d)/this.s[d]);let a=this.U,u=a.rows,f=a.columns,c=new ve(r,u);for(let h=0;h<r;h++)for(let d=0;d<u;d++){let p=0;for(let v=0;v<f;v++)p+=i.get(h,v)*a.get(d,v);c.set(h,d,p)}return c}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let e=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,t=0,r=this.s;for(let n=0,i=r.length;n<i;n++)r[n]>e&&t++;return t}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return ve.diag(this.s)}}function Ry(s,e=!1){return s=Ar.checkMatrix(s),e?new Oi(s).inverse():Of(s,ve.eye(s.rows))}function Of(s,e,t=!1){return s=Ar.checkMatrix(s),e=Ar.checkMatrix(e),t?new Oi(s).solve(e):s.isSquare()?new Eo(s).solve(e):new tu(s).solve(e)}function Ao(s){if(s=ve.checkMatrix(s),s.isSquare()){if(s.columns===0)return 1;let e,t,r,n;if(s.columns===2)return e=s.get(0,0),t=s.get(0,1),r=s.get(1,0),n=s.get(1,1),e*n-t*r;if(s.columns===3){let i,a,u;return i=new bo(s,[1,2],[1,2]),a=new bo(s,[1,2],[0,2]),u=new bo(s,[1,2],[0,1]),e=s.get(0,0),t=s.get(0,1),r=s.get(0,2),e*Ao(i)-t*Ao(a)+r*Ao(u)}else return new Eo(s).determinant}else throw Error("determinant can only be calculated for a square matrix")}function Ly(s,e){let t=[];for(let r=0;r<s;r++)r!==e&&t.push(r);return t}function Py(s,e,t,r=1e-9,n=1e-9){if(s>n)return new Array(e.rows+1).fill(0);{let i=e.addRow(t,[0]);for(let a=0;a<i.rows;a++)Math.abs(i.get(a,0))<r&&i.set(a,0,0);return i.to1DArray()}}function ky(s,e={}){const{thresholdValue:t=1e-9,thresholdError:r=1e-9}=e;s=ve.checkMatrix(s);let n=s.rows,i=new ve(n,n);for(let a=0;a<n;a++){let u=ve.columnVector(s.getRow(a)),f=s.subMatrixRow(Ly(n,a)).transpose(),h=new Oi(f).solve(u),d=ve.sub(u,f.mmul(h)).abs().max();i.setRow(a,Py(d,h,a,t,r))}return i}function zy(s,e=Number.EPSILON){if(s=ve.checkMatrix(s),s.isEmpty())return s.transpose();let t=new Oi(s,{autoTranspose:!0}),r=t.leftSingularVectors,n=t.rightSingularVectors,i=t.diagonal;for(let a=0;a<i.length;a++)Math.abs(i[a])>e?i[a]=1/i[a]:i[a]=0;return n.mmul(ve.diag(i).mmul(r.transpose()))}function qy(s,e=s,t={}){s=new ve(s);let r=!1;if(typeof e=="object"&&!ve.isMatrix(e)&&!gr.isAnyArray(e)?(t=e,e=s,r=!0):e=new ve(e),s.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=t;n&&(s=s.center("column"),r||(e=e.center("column")));const i=s.transpose().mmul(e);for(let a=0;a<i.rows;a++)for(let u=0;u<i.columns;u++)i.set(a,u,i.get(a,u)*(1/(s.rows-1)));return i}function Uy(s,e=s,t={}){s=new ve(s);let r=!1;if(typeof e=="object"&&!ve.isMatrix(e)&&!gr.isAnyArray(e)?(t=e,e=s,r=!0):e=new ve(e),s.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=t;n&&(s.center("column"),r||e.center("column")),i&&(s.scale("column"),r||e.scale("column"));const a=s.standardDeviation("column",{unbiased:!0}),u=r?a:e.standardDeviation("column",{unbiased:!0}),f=s.transpose().mmul(e);for(let c=0;c<f.rows;c++)for(let h=0;h<f.columns;h++)f.set(c,h,f.get(c,h)*(1/(a[c]*u[h]))*(1/(s.rows-1)));return f}let Tf=class{constructor(e,t={}){const{assumeSymmetric:r=!1}=t;if(e=Ar.checkMatrix(e),!e.isSquare())throw new Error("Matrix is not a square matrix");if(e.isEmpty())throw new Error("Matrix must be non-empty");let n=e.columns,i=new ve(n,n),a=new Float64Array(n),u=new Float64Array(n),f=e,c,h,d=!1;if(r?d=!0:d=e.isSymmetric(),d){for(c=0;c<n;c++)for(h=0;h<n;h++)i.set(c,h,f.get(c,h));Wy(n,u,a,i),Hy(n,u,a,i)}else{let p=new ve(n,n),v=new Float64Array(n);for(h=0;h<n;h++)for(c=0;c<n;c++)p.set(c,h,f.get(c,h));jy(n,p,v,i),Yy(n,u,a,i,p)}this.n=n,this.e=u,this.d=a,this.V=i}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let e=this.n,t=this.e,r=this.d,n=new ve(e,e),i,a;for(i=0;i<e;i++){for(a=0;a<e;a++)n.set(i,a,0);n.set(i,i,r[i]),t[i]>0?n.set(i,i+1,t[i]):t[i]<0&&n.set(i,i-1,t[i])}return n}};function Wy(s,e,t,r){let n,i,a,u,f,c,h,d;for(f=0;f<s;f++)t[f]=r.get(s-1,f);for(u=s-1;u>0;u--){for(d=0,a=0,c=0;c<u;c++)d=d+Math.abs(t[c]);if(d===0)for(e[u]=t[u-1],f=0;f<u;f++)t[f]=r.get(u-1,f),r.set(u,f,0),r.set(f,u,0);else{for(c=0;c<u;c++)t[c]/=d,a+=t[c]*t[c];for(n=t[u-1],i=Math.sqrt(a),n>0&&(i=-i),e[u]=d*i,a=a-n*i,t[u-1]=n-i,f=0;f<u;f++)e[f]=0;for(f=0;f<u;f++){for(n=t[f],r.set(f,u,n),i=e[f]+r.get(f,f)*n,c=f+1;c<=u-1;c++)i+=r.get(c,f)*t[c],e[c]+=r.get(c,f)*n;e[f]=i}for(n=0,f=0;f<u;f++)e[f]/=a,n+=e[f]*t[f];for(h=n/(a+a),f=0;f<u;f++)e[f]-=h*t[f];for(f=0;f<u;f++){for(n=t[f],i=e[f],c=f;c<=u-1;c++)r.set(c,f,r.get(c,f)-(n*e[c]+i*t[c]));t[f]=r.get(u-1,f),r.set(u,f,0)}}t[u]=a}for(u=0;u<s-1;u++){if(r.set(s-1,u,r.get(u,u)),r.set(u,u,1),a=t[u+1],a!==0){for(c=0;c<=u;c++)t[c]=r.get(c,u+1)/a;for(f=0;f<=u;f++){for(i=0,c=0;c<=u;c++)i+=r.get(c,u+1)*r.get(c,f);for(c=0;c<=u;c++)r.set(c,f,r.get(c,f)-i*t[c])}}for(c=0;c<=u;c++)r.set(c,u+1,0)}for(f=0;f<s;f++)t[f]=r.get(s-1,f),r.set(s-1,f,0);r.set(s-1,s-1,1),e[0]=0}function Hy(s,e,t,r){let n,i,a,u,f,c,h,d,p,v,x,_,y,m,w,D;for(a=1;a<s;a++)e[a-1]=e[a];e[s-1]=0;let C=0,b=0,F=Number.EPSILON;for(c=0;c<s;c++){for(b=Math.max(b,Math.abs(t[c])+Math.abs(e[c])),h=c;h<s&&!(Math.abs(e[h])<=F*b);)h++;if(h>c)do{for(n=t[c],d=(t[c+1]-n)/(2*e[c]),p=yn(d,1),d<0&&(p=-p),t[c]=e[c]/(d+p),t[c+1]=e[c]*(d+p),v=t[c+1],i=n-t[c],a=c+2;a<s;a++)t[a]-=i;for(C=C+i,d=t[h],x=1,_=x,y=x,m=e[c+1],w=0,D=0,a=h-1;a>=c;a--)for(y=_,_=x,D=w,n=x*e[a],i=x*d,p=yn(d,e[a]),e[a+1]=w*p,w=e[a]/p,x=d/p,d=x*t[a]-w*n,t[a+1]=i+w*(x*n+w*t[a]),f=0;f<s;f++)i=r.get(f,a+1),r.set(f,a+1,w*r.get(f,a)+x*i),r.set(f,a,x*r.get(f,a)-w*i);d=-w*D*y*m*e[c]/v,e[c]=w*d,t[c]=x*d}while(Math.abs(e[c])>F*b);t[c]=t[c]+C,e[c]=0}for(a=0;a<s-1;a++){for(f=a,d=t[a],u=a+1;u<s;u++)t[u]<d&&(f=u,d=t[u]);if(f!==a)for(t[f]=t[a],t[a]=d,u=0;u<s;u++)d=r.get(u,a),r.set(u,a,r.get(u,f)),r.set(u,f,d)}}function jy(s,e,t,r){let n=0,i=s-1,a,u,f,c,h,d,p;for(d=n+1;d<=i-1;d++){for(p=0,c=d;c<=i;c++)p=p+Math.abs(e.get(c,d-1));if(p!==0){for(f=0,c=i;c>=d;c--)t[c]=e.get(c,d-1)/p,f+=t[c]*t[c];for(u=Math.sqrt(f),t[d]>0&&(u=-u),f=f-t[d]*u,t[d]=t[d]-u,h=d;h<s;h++){for(a=0,c=i;c>=d;c--)a+=t[c]*e.get(c,h);for(a=a/f,c=d;c<=i;c++)e.set(c,h,e.get(c,h)-a*t[c])}for(c=0;c<=i;c++){for(a=0,h=i;h>=d;h--)a+=t[h]*e.get(c,h);for(a=a/f,h=d;h<=i;h++)e.set(c,h,e.get(c,h)-a*t[h])}t[d]=p*t[d],e.set(d,d-1,p*u)}}for(c=0;c<s;c++)for(h=0;h<s;h++)r.set(c,h,c===h?1:0);for(d=i-1;d>=n+1;d--)if(e.get(d,d-1)!==0){for(c=d+1;c<=i;c++)t[c]=e.get(c,d-1);for(h=d;h<=i;h++){for(u=0,c=d;c<=i;c++)u+=t[c]*r.get(c,h);for(u=u/t[d]/e.get(d,d-1),c=d;c<=i;c++)r.set(c,h,r.get(c,h)+u*t[c])}}}function Yy(s,e,t,r,n){let i=s-1,a=0,u=s-1,f=Number.EPSILON,c=0,h=0,d=0,p=0,v=0,x=0,_=0,y=0,m,w,D,C,b,F,B,M,O,A,N,T,R,k,z;for(m=0;m<s;m++)for((m<a||m>u)&&(t[m]=n.get(m,m),e[m]=0),w=Math.max(m-1,0);w<s;w++)h=h+Math.abs(n.get(m,w));for(;i>=a;){for(C=i;C>a&&(x=Math.abs(n.get(C-1,C-1))+Math.abs(n.get(C,C)),x===0&&(x=h),!(Math.abs(n.get(C,C-1))<f*x));)C--;if(C===i)n.set(i,i,n.get(i,i)+c),t[i]=n.get(i,i),e[i]=0,i--,y=0;else if(C===i-1){if(B=n.get(i,i-1)*n.get(i-1,i),d=(n.get(i-1,i-1)-n.get(i,i))/2,p=d*d+B,_=Math.sqrt(Math.abs(p)),n.set(i,i,n.get(i,i)+c),n.set(i-1,i-1,n.get(i-1,i-1)+c),M=n.get(i,i),p>=0){for(_=d>=0?d+_:d-_,t[i-1]=M+_,t[i]=t[i-1],_!==0&&(t[i]=M-B/_),e[i-1]=0,e[i]=0,M=n.get(i,i-1),x=Math.abs(M)+Math.abs(_),d=M/x,p=_/x,v=Math.sqrt(d*d+p*p),d=d/v,p=p/v,w=i-1;w<s;w++)_=n.get(i-1,w),n.set(i-1,w,p*_+d*n.get(i,w)),n.set(i,w,p*n.get(i,w)-d*_);for(m=0;m<=i;m++)_=n.get(m,i-1),n.set(m,i-1,p*_+d*n.get(m,i)),n.set(m,i,p*n.get(m,i)-d*_);for(m=a;m<=u;m++)_=r.get(m,i-1),r.set(m,i-1,p*_+d*r.get(m,i)),r.set(m,i,p*r.get(m,i)-d*_)}else t[i-1]=M+d,t[i]=M+d,e[i-1]=_,e[i]=-_;i=i-2,y=0}else{if(M=n.get(i,i),O=0,B=0,C<i&&(O=n.get(i-1,i-1),B=n.get(i,i-1)*n.get(i-1,i)),y===10){for(c+=M,m=a;m<=i;m++)n.set(m,m,n.get(m,m)-M);x=Math.abs(n.get(i,i-1))+Math.abs(n.get(i-1,i-2)),M=O=.75*x,B=-.4375*x*x}if(y===30&&(x=(O-M)/2,x=x*x+B,x>0)){for(x=Math.sqrt(x),O<M&&(x=-x),x=M-B/((O-M)/2+x),m=a;m<=i;m++)n.set(m,m,n.get(m,m)-x);c+=x,M=O=B=.964}for(y=y+1,b=i-2;b>=C&&(_=n.get(b,b),v=M-_,x=O-_,d=(v*x-B)/n.get(b+1,b)+n.get(b,b+1),p=n.get(b+1,b+1)-_-v-x,v=n.get(b+2,b+1),x=Math.abs(d)+Math.abs(p)+Math.abs(v),d=d/x,p=p/x,v=v/x,!(b===C||Math.abs(n.get(b,b-1))*(Math.abs(p)+Math.abs(v))<f*(Math.abs(d)*(Math.abs(n.get(b-1,b-1))+Math.abs(_)+Math.abs(n.get(b+1,b+1))))));)b--;for(m=b+2;m<=i;m++)n.set(m,m-2,0),m>b+2&&n.set(m,m-3,0);for(D=b;D<=i-1&&(k=D!==i-1,D!==b&&(d=n.get(D,D-1),p=n.get(D+1,D-1),v=k?n.get(D+2,D-1):0,M=Math.abs(d)+Math.abs(p)+Math.abs(v),M!==0&&(d=d/M,p=p/M,v=v/M)),M!==0);D++)if(x=Math.sqrt(d*d+p*p+v*v),d<0&&(x=-x),x!==0){for(D!==b?n.set(D,D-1,-x*M):C!==b&&n.set(D,D-1,-n.get(D,D-1)),d=d+x,M=d/x,O=p/x,_=v/x,p=p/d,v=v/d,w=D;w<s;w++)d=n.get(D,w)+p*n.get(D+1,w),k&&(d=d+v*n.get(D+2,w),n.set(D+2,w,n.get(D+2,w)-d*_)),n.set(D,w,n.get(D,w)-d*M),n.set(D+1,w,n.get(D+1,w)-d*O);for(m=0;m<=Math.min(i,D+3);m++)d=M*n.get(m,D)+O*n.get(m,D+1),k&&(d=d+_*n.get(m,D+2),n.set(m,D+2,n.get(m,D+2)-d*v)),n.set(m,D,n.get(m,D)-d),n.set(m,D+1,n.get(m,D+1)-d*p);for(m=a;m<=u;m++)d=M*r.get(m,D)+O*r.get(m,D+1),k&&(d=d+_*r.get(m,D+2),r.set(m,D+2,r.get(m,D+2)-d*v)),r.set(m,D,r.get(m,D)-d),r.set(m,D+1,r.get(m,D+1)-d*p)}}}if(h!==0){for(i=s-1;i>=0;i--)if(d=t[i],p=e[i],p===0)for(C=i,n.set(i,i,1),m=i-1;m>=0;m--){for(B=n.get(m,m)-d,v=0,w=C;w<=i;w++)v=v+n.get(m,w)*n.get(w,i);if(e[m]<0)_=B,x=v;else if(C=m,e[m]===0?n.set(m,i,B!==0?-v/B:-v/(f*h)):(M=n.get(m,m+1),O=n.get(m+1,m),p=(t[m]-d)*(t[m]-d)+e[m]*e[m],F=(M*x-_*v)/p,n.set(m,i,F),n.set(m+1,i,Math.abs(M)>Math.abs(_)?(-v-B*F)/M:(-x-O*F)/_)),F=Math.abs(n.get(m,i)),f*F*F>1)for(w=m;w<=i;w++)n.set(w,i,n.get(w,i)/F)}else if(p<0)for(C=i-1,Math.abs(n.get(i,i-1))>Math.abs(n.get(i-1,i))?(n.set(i-1,i-1,p/n.get(i,i-1)),n.set(i-1,i,-(n.get(i,i)-d)/n.get(i,i-1))):(z=Co(0,-n.get(i-1,i),n.get(i-1,i-1)-d,p),n.set(i-1,i-1,z[0]),n.set(i-1,i,z[1])),n.set(i,i-1,0),n.set(i,i,1),m=i-2;m>=0;m--){for(A=0,N=0,w=C;w<=i;w++)A=A+n.get(m,w)*n.get(w,i-1),N=N+n.get(m,w)*n.get(w,i);if(B=n.get(m,m)-d,e[m]<0)_=B,v=A,x=N;else if(C=m,e[m]===0?(z=Co(-A,-N,B,p),n.set(m,i-1,z[0]),n.set(m,i,z[1])):(M=n.get(m,m+1),O=n.get(m+1,m),T=(t[m]-d)*(t[m]-d)+e[m]*e[m]-p*p,R=(t[m]-d)*2*p,T===0&&R===0&&(T=f*h*(Math.abs(B)+Math.abs(p)+Math.abs(M)+Math.abs(O)+Math.abs(_))),z=Co(M*v-_*A+p*N,M*x-_*N-p*A,T,R),n.set(m,i-1,z[0]),n.set(m,i,z[1]),Math.abs(M)>Math.abs(_)+Math.abs(p)?(n.set(m+1,i-1,(-A-B*n.get(m,i-1)+p*n.get(m,i))/M),n.set(m+1,i,(-N-B*n.get(m,i)-p*n.get(m,i-1))/M)):(z=Co(-v-O*n.get(m,i-1),-x-O*n.get(m,i),_,p),n.set(m+1,i-1,z[0]),n.set(m+1,i,z[1]))),F=Math.max(Math.abs(n.get(m,i-1)),Math.abs(n.get(m,i))),f*F*F>1)for(w=m;w<=i;w++)n.set(w,i-1,n.get(w,i-1)/F),n.set(w,i,n.get(w,i)/F)}for(m=0;m<s;m++)if(m<a||m>u)for(w=m;w<s;w++)r.set(m,w,n.get(m,w));for(w=s-1;w>=a;w--)for(m=a;m<=u;m++){for(_=0,D=a;D<=Math.min(w,u);D++)_=_+r.get(m,D)*n.get(D,w);r.set(m,w,_)}}}function Co(s,e,t,r){let n,i;return Math.abs(t)>Math.abs(r)?(n=r/t,i=t+n*r,[(s+n*e)/i,(e-n*s)/i]):(n=t/r,i=r+n*t,[(n*s+e)/i,(n*e-s)/i])}class If{constructor(e){if(e=Ar.checkMatrix(e),!e.isSymmetric())throw new Error("Matrix is not symmetric");let t=e,r=t.rows,n=new ve(r,r),i=!0,a,u,f;for(u=0;u<r;u++){let c=0;for(f=0;f<u;f++){let h=0;for(a=0;a<f;a++)h+=n.get(f,a)*n.get(u,a);h=(t.get(u,f)-h)/n.get(f,f),n.set(u,f,h),c=c+h*h}for(c=t.get(u,u)-c,i&=c>0,n.set(u,u,Math.sqrt(Math.max(c,0))),f=u+1;f<r;f++)n.set(u,f,0)}this.L=n,this.positiveDefinite=!!i}isPositiveDefinite(){return this.positiveDefinite}solve(e){e=Ar.checkMatrix(e);let t=this.L,r=t.rows;if(e.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=e.columns,i=e.clone(),a,u,f;for(f=0;f<r;f++)for(u=0;u<n;u++){for(a=0;a<f;a++)i.set(f,u,i.get(f,u)-i.get(a,u)*t.get(f,a));i.set(f,u,i.get(f,u)/t.get(f,f))}for(f=r-1;f>=0;f--)for(u=0;u<n;u++){for(a=f+1;a<r;a++)i.set(f,u,i.get(f,u)-i.get(a,u)*t.get(a,f));i.set(f,u,i.get(f,u)/t.get(f,f))}return i}get lowerTriangularMatrix(){return this.L}}class $f{constructor(e,t={}){e=Ar.checkMatrix(e);let{Y:r}=t;const{scaleScores:n=!1,maxIterations:i=1e3,terminationCriteria:a=1e-10}=t;let u;if(r){if(gr.isAnyArray(r)&&typeof r[0]=="number"?r=ve.columnVector(r):r=Ar.checkMatrix(r),r.rows!==e.rows)throw new Error("Y should have the same number of rows as X");u=r.getColumnVector(0)}else u=e.getColumnVector(0);let f=1,c,h,d,p;for(let v=0;v<i&&f>a;v++)d=e.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),d=d.div(d.norm()),c=e.mmul(d).div(d.transpose().mmul(d).get(0,0)),v>0&&(f=c.clone().sub(p).pow(2).sum()),p=c.clone(),r?(h=r.transpose().mmul(c).div(c.transpose().mmul(c).get(0,0)),h=h.div(h.norm()),u=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):u=c;if(r){let v=e.transpose().mmul(c).div(c.transpose().mmul(c).get(0,0));v=v.div(v.norm());let x=e.clone().sub(c.clone().mmul(v.transpose())),_=u.transpose().mmul(c).div(c.transpose().mmul(c).get(0,0)),y=r.clone().sub(c.clone().mulS(_.get(0,0)).mmul(h.transpose()));this.t=c,this.p=v.transpose(),this.w=d.transpose(),this.q=h,this.u=u,this.s=c.transpose().mmul(c),this.xResidual=x,this.yResidual=y,this.betas=_}else this.w=d.transpose(),this.s=c.transpose().mmul(c).sqrt(),n?this.t=c.clone().div(this.s.get(0,0)):this.t=c,this.xResidual=e.sub(c.mmul(d.transpose()))}}We.AbstractMatrix=ke,We.CHO=If,We.CholeskyDecomposition=If,We.DistanceMatrix=wo,We.EVD=Tf;var Zy=We.EigenvalueDecomposition=Tf;We.LU=Eo,We.LuDecomposition=Eo;var Rf=We.Matrix=ve;We.MatrixColumnSelectionView=By,We.MatrixColumnView=Fy,We.MatrixFlipColumnView=My,We.MatrixFlipRowView=Ny,We.MatrixRowSelectionView=Oy,We.MatrixRowView=Sy,We.MatrixSelectionView=bo,We.MatrixSubView=Ty,We.MatrixTransposeView=Iy,We.NIPALS=$f,We.Nipals=$f,We.QR=tu,We.QrDecomposition=tu,We.SVD=Oi,We.SingularValueDecomposition=Oi,We.SymmetricMatrix=ii,We.WrapperMatrix1D=Sf,We.WrapperMatrix2D=Ar,We.correlation=Uy,We.covariance=qy;var Lf=We.default=ve;We.determinant=Ao,We.inverse=Ry,We.linearDependencies=ky,We.pseudoInverse=zy,We.solve=Of,We.wrap=$y;const Pf=Zy,kf=Rf;Lf.Matrix&&Lf.Matrix;class Vy{constructor(e){U(this,"_errorListener");this._errorListener=e}new({rows:e,columns:t,initial_value:r}={}){return new ru(e,t,r,this._errorListener)}avg({id:e}){return e==null?void 0:e.avg()}col({id:e,column:t}){return e==null?void 0:e.col({column:t})}det({id:e}){return e==null?void 0:e.det()}get({id:e,row:t,column:r}){return e==null?void 0:e.get({row:t,column:r})}inv({id:e}){return e==null?void 0:e.inv()}max({id:e}){return e==null?void 0:e.max()}min({id:e}){return e==null?void 0:e.min()}pow({id:e,power:t}){return e==null?void 0:e.pow({power:t})}row({id:e,row:t}){return e==null?void 0:e.row({row:t})}set({id:e,row:t,column:r,value:n}){e==null||e.set({row:t,column:r,value:n})}sum({id1:e,id2:t}){return e==null?void 0:e.sum({id2:t})}copy({id:e}){return e==null?void 0:e.copy()}diff({id1:e,id2:t}){return e==null?void 0:e.diff({id2:t})}rows({id:e}){return e==null?void 0:e.rows()}columns({id:e}){return e==null?void 0:e.columns()}fill({id:e,value:t,from_row:r,to_row:n,from_column:i,to_column:a}){e==null||e.fill({value:t,from_row:r,to_row:n,from_column:i,to_column:a})}kron({id1:e,id2:t}){return e==null?void 0:e.kron({id2:t})}mode({id:e}){return e==null?void 0:e.mode()}mult({id1:e,id2:t}){return e==null?void 0:e.mult({id2:t})}pinv({id:e}){return e==null?void 0:e.pinv()}rank({id:e}){return e==null?void 0:e.rank()}sort({id:e,column:t,order:r}){e==null||e.sort({column:t,order:r})}trace({id:e}){return e==null?void 0:e.trace()}concat({id1:e,id2:t}){return e==null?void 0:e.concat({id2:t})}median({id:e}){return e==null?void 0:e.median()}add_col({id:e,column:t,array_id:r}){e==null||e.add_col({column:t,array_id:r})}add_row({id:e,row:t,array_id:r}){e==null||e.add_row({row:t,array_id:r})}is_zero({id:e}){return e==null?void 0:e.is_zero()}reshape({id:e,rows:t,columns:r},n){return e==null?void 0:e.reshape({rows:t,columns:r},n)}reverse({id:e}){e==null||e.reverse()}is_binary({id:e}){return e==null?void 0:e.is_binary()}is_square({id:e}){return e==null?void 0:e.is_square()}submatrix({id:e,from_row:t,to_row:r,from_column:n,to_column:i}){return e==null?void 0:e.submatrix({from_row:t,to_row:r,from_column:n,to_column:i})}swap_rows({id:e,row1:t,row2:r}){e==null||e.swap_rows({row1:t,row2:r})}transpose({id:e}){return e==null?void 0:e.transpose()}remove_col({id:e,column:t}){return e==null?void 0:e.remove_col({column:t})}remove_row({id:e,row:t}){return e==null?void 0:e.remove_row({row:t})}eigenvalues({id:e}){return e==null?void 0:e.eigenvalues()}is_diagonal({id:e}){return e==null?void 0:e.is_diagonal()}is_identity({id:e}){return e==null?void 0:e.is_identity()}eigenvectors({id:e}){return e==null?void 0:e.eigenvectors()}is_symmetric({id:e}){return e==null?void 0:e.is_symmetric()}swap_columns({id:e,column1:t,column2:r}){e==null||e.swap_columns({column1:t,column2:r})}is_stochastic({id:e}){return e==null?void 0:e.is_stochastic()}is_triangular({id:e}){return e==null?void 0:e.is_triangular()}elements_count({id:e}){return e==null?void 0:e.elements_count()}is_antidiagonal({id:e}){return e==null?void 0:e.is_antidiagonal()}is_antisymmetric({id:e}){return e==null?void 0:e.is_antisymmetric()}}class ru{constructor(e=0,t=0,r=void 0,n){U(this,"_matrixInstance");U(this,"_errorListener");this._matrixInstance=this._createMatrix(e,t,r),this._errorListener=n}get _matrixArray(){return this._matrixInstance.map(e=>[...e._value])}get _value(){return this._matrixInstance}set _value(e){this._matrixInstance=e}get isMatrix(){return!0}_createMatrix(e,t,r){return Array.from(new Array(e),()=>new it(t,r,this._errorListener))}avg(){let e=0,t=0;for(const n of this._matrixInstance)for(const i of n._value)e+=me(i)?0:i,t+=1;return e/t}col({column:e}){const t=[],r=new it(0,void 0,this._errorListener);if(me(e))return r;for(const n of this._matrixInstance)t.push(n._value[e]);return r._value=t,r}det(){return Ef(this._matrixArray)}get({row:e,column:t}){var r,n;if(!(me(e)||me(t)))return(n=(r=this._matrixInstance[e])==null?void 0:r._value)==null?void 0:n[t]}inv(){const e=mo(this._matrixArray);return this._newMatrix(e)}max(){return zx(this._matrixArray)}min(){return Xa(this._matrixArray)}pow({power:e}){const t=me(e)?this._matrixArray:Ux(this._matrixArray,e);return this._newMatrix(t)}row({row:e}){return me(e)?new it(0,void 0,this._errorListener):this._matrixInstance[e]}set({row:e,column:t,value:r}){me(e)||me(t)||this._matrixInstance[e].set({index:t,value:r})}sum({id2:e}){const t=cs(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:e}){const t=Ix(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:e,from_row:t,to_row:r,from_column:n,to_column:i}={}){me(t)&&(t=0),me(r)&&(r=this.rows()),me(n)&&(n=0),me(i)&&(i=this.columns());for(const[a,u]of this._matrixInstance.entries())for(const[f]of u._value.entries())a<r&&a>=t&&f>=n&&f<i&&u.set({index:f,value:e})}kron({id2:e}){const t=Ox(this._matrixArray,e._matrixArray);return this._newMatrix(t)}mode(){return Xa(gf(this._matrixArray))}mult({id2:e}){const t=typeof e=="number"?e:e._matrixArray?e._matrixArray:e._value,r=Bi(this._matrixArray,t);return this._newMatrix(r)}pinv(){const e=qx(this._matrixArray);return this._newMatrix(e)}rank(){return this._matrixRank(this._matrixArray)}sort({column:e,order:t=Qn.ascending}={}){me(e)&&(e=0),this._matrixInstance.sort((r,n)=>{const i=r._value[e],a=n._value[e];return t!==Qn.descending?i-a:a-i})}trace(){return kx(this._matrixArray)}concat({id2:e}){for(const t of e._value)this._matrixInstance.push(t);return this}median(){return Af(this._matrixArray)}add_col({column:e,array_id:t}={}){me(e)&&(e=this.columns());for(const[r,n]of this._matrixInstance.entries())n.insert({index:e,value:t?t._value[r]:void 0})}add_row({row:e,array_id:t}){me(e)&&(e=this.rows()),this._matrixInstance.splice(e,0,t||new it(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(e=>e.every(t=>t===0))}reshape({rows:e=0,columns:t=0},r){if(e*t!==this.columns()*this.rows()){this._errorListener.addError("New matrix must be of same area as original matrix",r,Ve.Error);return}const n=Bx(this._matrixArray,[e,t]);this._matrixInstance=n.map(i=>{const a=new it(0,void 0,this._errorListener);return a._value=[...i],a})}reverse(){this._matrixInstance.reverse();for(const e of this._matrixInstance)e.reverse()}is_binary(){return this._matrixArray.every(e=>e.every(t=>t===0||t===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:e,to_row:t,from_column:r,to_column:n}={}){me(e)&&(e=0),me(t)&&(t=this.rows()),me(r)&&(r=0),me(n)&&(n=this.columns());const i=this._matrixArray.splice(e,t),a=[];for(const u of i)a.push(u.splice(r,n));return this._newMatrix(a)}swap_rows({row1:e,row2:t}){if(me(e)||me(t))return;const r=this._matrixInstance[e],n=this._matrixInstance[t];this._matrixInstance[e]=n,this._matrixInstance[t]=r}transpose(){const e=xf(this._matrixArray);return this._newMatrix(e)}remove_col({column:e}={}){me(e)&&(e=this.columns());const t=[];for(const n of this._matrixInstance){const i=n._value.splice(e,1);t.push(i[0])}const r=new it(0,void 0,this._errorListener);return r._value=t,r}remove_row({row:e}={}){return me(e)&&(e=this.rows()),this._matrixInstance.splice(e,1)[0]}eigenvalues(){const e=new Pf(new kf(this._matrixArray)),t=new it(0,void 0,this._errorListener);return t._value=e.realEigenvalues,t}is_diagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<t;i++)if(n!==i&&r[n][i]!==0)return!1;return!0}is_identity(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<t;i++)if(n!==i&&r[n][i]!==0||n===i&&r[n][i]!==1)return!1;return!0}eigenvectors(){const e=new Pf(new kf(this._matrixArray));return this._newMatrix(e.eigenvectorMatrix.to2DArray())}is_symmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=n+1;i<t;i++)if(r[n][i]!==r[i][n])return!1;return!0}swap_columns({column1:e,column2:t}){if(!(me(e)||me(t)))for(const r of this._matrixInstance){const n=r._value[e],i=r._value[t];r.set({index:e,value:i}),r.set({index:t,value:n})}}is_stochastic(){const e=this._matrixArray;for(let t=0;t<e.length;t++){let r=0;for(let n=0;n<e[t].length;n++){if(e[t][n]<0)return!1;r+=e[t][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const e=this.rows(),t=this.columns();return e!==t?!1:this._isUpperTriangular(e)||this._isLowerTriangular(e)}elements_count(){return Mx(this._matrixArray)}is_antidiagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<e;i++)if(n+i!==e-1&&r[n][i]!==0)return!1;return!0}is_antisymmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<e;i++)if(n!==i&&r[n][i]!==-r[i][n])return!1;return!0}_isUpperTriangular(e){const t=this._matrixArray;for(let r=1;r<e;r++)for(let n=0;n<r;n++)if(t[r][n]!==0)return!1;return!0}_isLowerTriangular(e){const t=this._matrixArray;for(let r=0;r<e-1;r++)for(let n=r+1;n<e;n++)if(t[r][n]!==0)return!1;return!0}_newMatrix(e){const t=new ru(0,0,void 0,this._errorListener);return t._value=e.map(r=>{const n=new it(0,void 0,this._errorListener);return n._value=[...r],n}),t}_matrixRank(e){let t=0;const r=e.length,n=e[0].length,i=[...e].map(a=>[...a]);for(let a=0;a<r&&!(a>=n);a++){let u=a;for(;u<r&&i[u][a]===0;)u++;if(u===r)continue;if(u!==a){const c=i[u];i[u]=i[a],i[a]=c}const f=i[a][a];for(let c=0;c<n;c++)i[a][c]/=f;for(let c=a+1;c<r;c++){const h=i[c][a];i[c]=i[c].map((d,p)=>d-h*i[a][p]),i[c][a]=0}}for(let a=0;a<r;a++)i[a].some(u=>Number(u.toFixed(8))!==0)&&t++;return t}}class Gy{constructor(e){U(this,"_variables");U(this,"_cacheData");this._variables=e,this._cacheData={}}change({timeframe:e},t){if(!e)return!0;const r=pn(e),n=pn(this._variables.timeframe.period);if(r<n)return!0;const i=`change_${t}`,a=this._cacheData[i],u=this._variables.time;if(a){if(a.offset){if(a.currentTime+a.offset<=u)return this._cacheData[i]={currentTime:u,offset:0},!0}else if(a.currentTime+r*1e3<=u)return this._cacheData[i]={currentTime:u,offset:0},!0}else{const f=this._calcTimeOffset(u,e);return this._cacheData[i]={currentTime:u,offset:f},!1}return!1}in_seconds({timeframe:e}={}){return pn(e||this._variables.timeframe.period)}from_seconds({seconds:e=0}){const t=e*1e3,r=ot.duration(t);if(r.years())return"12M";const i=r.asMonths();if(vo(i))return`${i}M`;const a=r.asWeeks();if(vo(a))return`${a}M`;const u=r.asDays();if(u>=1)return`${Math.ceil(u)}D`;const f=r.asMinutes();if(f>=1)return`${Math.ceil(f)}`;const c=r.asSeconds();return c<=1?"1S":c<=5?"5S":c<=10?"10S":c<=15?"15S":c<=30?"30S":"1"}_calcTimeOffset(e,t){let r=0;if(t.includes("W")){const u=ot(e).day();t="1D",u!==1&&(r=(8-u)*60*60*24*1e3)}else if(t.includes("M")){const u=ot(e).date();t="1D";const f=ot(e).daysInMonth();u!==1&&(r=(f-u+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(e,t),i=pn(t)*1e3,a=e-n-Math.floor((e-n)/i)*i;return r?r-a:a}}class Ky{constructor(e,t){U(this,"_errorListener");U(this,"_intlNumberFormatter");U(this,"_precision");this._errorListener=e,this._precision=t,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact"})}pos({source:e="",str:t=""}){return e==null?void 0:e.indexOf(t)}trim({source:e=""}){return e==null?void 0:e.trim()}lower({source:e=""}){return e==null?void 0:e.toLocaleLowerCase()}match({source:e="",regex:t=""}){const r=e==null?void 0:e.match(new RegExp(t));return r?r[0]:""}split({string:e="",separator:t=""}){const r=e==null?void 0:e.split(t),n=new it;return n._value=r||[],n}upper({source:e=""}){return e==null?void 0:e.toLocaleUpperCase()}format({formatString:e=""},t){return this._strFormat(e,t)}length({string:e=""}){return e==null?void 0:e.length}repeat({source:e="",repeat:t,separator:r=""},n){if(me(t)){this._errorListener.addError("Invalid array length",n,Ve.Error);return}return Array.from(new Array(t),()=>e).join(r)}replace({source:e="",target:t="",replacement:r="",occurrence:n}){me(n)&&(n=0);let i=-1;for(let a=0;a<n+1&&(i=e.indexOf(t,i+1),i!==-1);a++);return i!==-1?e.substring(0,i)+r+e.substring(i+t.length):e}contains({source:e="",str:t=""}){return e==null?void 0:e.includes(t)}endswith({source:e="",str:t=""}){return e==null?void 0:e.endsWith(t)}tonumber({string:e=""}){if(/[^\d.]/.test(e))return;const t=parseFloat(e);return isNaN(t)?void 0:t}tostring({value:e,format:t}){if(e===void 0)return"NaN";if(typeof e=="object"){if(e.isArray)return this._arrToStr(e._value,t);if(e.isMatrix){const r=[];for(const n of e._matrixArray)r.push(this._arrToStr(n,t));return r.join(`
62
- `)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t))}_arrToStr(e,t){return`[${e.map(n=>typeof n=="number"?this._toStringFormat(n,t):n).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return me(t)&&(t=0),me(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return me(e)&&(e=0),Zr(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return e;switch(t){case Je.mintick:return e.toFixed(this._precision);case Je.price:return`${e}%`;case Je.volume:return this._intlNumberFormatter.format(Math.round(e));default:const[r,n]=t.split(".");let[i,a=""]=String(e).split(".");if(r.includes("#")?i=r.replace(/#/,i).replace(/#/g,""):i=`${r}${i}`,n&&n.includes("#")){const u=n.split("#").length-1;a=`${a.substring(0,u)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${i}.${a}`:i}}_formatNumber(e,t){if(!t)return e;switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:const r=t.split(".")[1],n=r?r.length:0;return parseFloat(e.toFixed(n))}}_strFormat(e,t){let r=e;return t.forEach((n,i)=>{if(typeof n=="number"){const a=`\\{\\s*${i}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,u=e.match(new RegExp(a));if(u){const f=u[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,f)))}else r=r.replace(new RegExp(`\\{${i}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${i}\\}`,"g"),n)}),r}}class Xy{constructor(e){U(this,"_errorListener");this._errorListener=e}new(){return new nu(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class nu{constructor(e){U(this,"_errorListener");U(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}_copyMap(e){const t=new nu(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new it(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new it(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class Qy{constructor(e){U(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new si(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new si(e,r,t)}copy({id:e}){const{price:t,time:r,index:n}=e||{};return new si(t,n,r)}from_index({price:e,index:t}){return new si(e,t)}from_time({price:e,time:t}){return new si(e,void 0,t)}}class si{constructor(e,t,r){U(this,"_index");U(this,"_price");U(this,"_time");this._index=t,this._price=e,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new si(this._price,this._index,this._time)}}class Jy{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultLabel",{text:"",xloc:wt.bar_index,yloc:Kr.price,size:ar.normal,style:vt.styleLabelDown,textalign:je.alignCenter});this._variables=e,this._errorListener=t}new(e,t){const{time:r,high:n,low:i,bar_index:a}=this._variables,u=`label_${t}_${a}`,f={...this._defaultLabel,...e,id:u,time:r};e.point&&(f.x=f.xloc===wt.bar_index?e.point.index:e.point.time,f.y=e.point.price),f.yloc===Kr.abovebar?f.y=n:f.yloc===Kr.belowbar&&(f.y=i),this._verfiyArgs(e,t);const c=new hs(u,this._variables,this._errorListener);return t.startsWith("export")||this._variables.label.add(u,f,c),c}_verfiyArgs(e,t){const{xloc:r,yloc:n,style:i,size:a,textalign:u,text_font_family:f}=e,c="label.new";this._paramVerfiy(i,t,c,Object.values(vt),"style"),this._paramVerfiy(r,t,c,Object.values(wt),"xloc"),this._paramVerfiy(n,t,c,Object.values(Kr),"yloc"),this._paramVerfiy(a,t,c,Object.values(ar),"size"),this._paramVerfiy(u,t,c,[je.alignLeft,je.alignCenter,je.alignRight],"textalign"),this._paramVerfiy(f,t,c,Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}label(e,t){return e.x?e.x:new hs(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e}){e==null||e.delete()}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class hs{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}copy(e){const t=`label_${e}_${this._variables.bar_index}`,r=this._getLabel(e),n=new hs(t,this._variables,this._errorListener);if(r){const i={...r,id:t};this._variables.label.add(t,i,n)}return n}get_x(e){var t;return(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){const r=this._getLabel(t);r&&(r.x=e)}set_y({y:e},t){const r=this._getLabel(t);r&&(r.y=e)}delete(){this._variables.label.delete(this._id)}set_xy({x:e,y:t},r){const n=this._getLabel(r);n&&(n.x=e,n.y=t)}get_text(e){var t;return(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(ar),"size")}set_text({text:e},t){const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){const n=this._getLabel(r);n&&(n.x=e,n.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(wt),"xloc"))}set_yloc({yloc:e},t){const r=this._getLabel(t),{high:n,low:i}=this._variables;r&&(r.yloc=e,e===Kr.abovebar?r.y=n:e===Kr.belowbar&&(r.y=i),this._paramVerfiy(e,t,"label.set_yloc",Object.values(Kr),"yloc"))}set_color({color:e},t){const r=this._getLabel(t);r&&(r.color=e)}set_point({point:e},t){const r=this._getLabel(t);r&&(r.x=r.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(vt),"style")}set_tooltip({tooltip:e},t){const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[je.alignLeft,je.alignCenter,je.alignRight],"textalign")}set_textcolor({textcolor:e},t){const r=this._getLabel(t);r&&(r.textcolor=e)}set_text_font_family({text_font_family:e},t){const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getLabel(e){const t=this._variables.label.get(this._id);return t||console.log(`错误${e}: label 不存在`),t}}const eD={freq_all:Vr.freqAll,freq_once_per_bar:Vr.freqOncePerBar,freq_once_per_bar_close:Vr.freqOncePerBarClose},tD={gaps_off:ns.gapsOff,gaps_on:ns.gapsOn,lookahead_off:ns.lookaheadOff,lookahead_on:ns.lookaheadOn},Ti={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},zf={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},rD={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},qf={all:[Zt.dataWindow,Zt.pane,Zt.priceScale,Zt.statusLine],data_window:[Zt.dataWindow],none:[],pane:[Zt.pane],price_scale:[Zt.priceScale],status_line:[Zt.statusLine]},nD={both:Gr.both,left:Gr.left,none:Gr.none,right:Gr.right},iD={inherit:Je.inherit,mintick:Je.mintick,percent:Je.percent,price:Je.price,volume:Je.volume},sD={style_solid:ks.styleSolid,style_dashed:ks.styleDashed,style_dotted:ks.styleDotted},oD={style_arrowdown:vt.styleArrowdown,style_arrowup:vt.styleArrowup,style_circle:vt.styleCircle,style_cross:vt.styleCross,style_diamond:vt.styleDiamond,style_flag:vt.styleFlag,style_label_center:vt.styleLabelCenter,style_label_down:vt.styleLabelDown,style_label_left:vt.styleLabelLeft,style_label_lower_left:vt.styleLabelLowerLeft,style_label_lower_right:vt.styleLabelLowerRight,style_label_right:vt.styleLabelRight,style_label_up:vt.styleLabelUp,style_label_upper_left:vt.styleLabelUpperLeft,style_label_upper_right:vt.styleLabelUpperRight,style_none:vt.styleNone,style_square:vt.styleSquare,style_text_outline:vt.styleTextOutline,style_triangledown:vt.styleTriangledown,style_triangleup:vt.styleTriangleup,style_xcross:vt.styleXcross},aD={style_arrow_both:zt.styleArrowBoth,style_arrow_left:zt.styleArrowLeft,style_arrow_right:zt.styleArrowRight,style_dashed:zt.styleDashed,style_dotted:zt.styleDotted,style_solid:zt.styleSolid},uD={abovebar:_n.abovebar,absolute:_n.absolute,belowbar:_n.belowbar,bottom:_n.bottom,top:_n.top},lD={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},cD={style_area:Or.styleArea,style_areabr:Or.styleAreabr,style_circles:Or.styleCircles,style_columns:Or.styleColumns,style_cross:Or.styleCross,style_histogram:Or.styleHistogram,style_line:Or.styleLine,style_linebr:Or.styleLinebr,style_stepline:Or.styleStepline,style_stepline_diamond:Or.styleSteplineDiamond,style_steplinebr:Or.styleSteplinebr},fD={bottom_center:br.bottomCenter,bottom_left:br.bottomLeft,bottom_right:br.bottomRight,middle_center:br.middleCenter,middle_left:br.middleLeft,middle_right:br.middleRight,top_center:br.topCenter,top_left:br.topLeft,top_right:br.topRight},hD={left:zs.left,none:zs.none,right:zs.right},dD={arrowdown:_r.arrowdown,arrowup:_r.arrowup,circle:_r.circle,cross:_r.cross,diamond:_r.diamond,flag:_r.flag,labeldown:_r.labeldown,labelup:_r.labelup,square:_r.square,triangledown:_r.triangledown,triangleup:_r.triangleup,xcross:_r.xcross},pD={auto:ar.auto,huge:ar.huge,large:ar.large,normal:ar.normal,small:ar.small,tiny:ar.tiny},_D={cash:Rt.cash,fixed:Rt.fixed,percent_of_equity:Rt.percentOfEquity,commission:{cash_per_contract:Tr.cashPerContract,cash_per_order:Tr.cashPerOrder,percent:Tr.percent},direction:{all:gt.all,long:gt.long,short:gt.short},oca:{cancel:vn.cancel,none:vn.none,reduce:vn.reduce}},vD={align_bottom:je.alignBottom,align_center:je.alignCenter,align_left:je.alignLeft,align_right:je.alignRight,align_top:je.alignTop,wrap_auto:je.wrapAuto,wrap_none:je.wrapNone},gD={bar_index:wt.bar_index,bar_time:wt.bar_time},mD={abovebar:Kr.abovebar,belowbar:Kr.belowbar,price:Kr.price},xD={actual:Us.actual,estimate:Us.estimate,standardized:Us.standardized};class Uf{constructor(){U(this,"adjustment",{dividends:Ps.dividends,none:Ps.none,splits:Ps.splits});U(this,"alert",eD);U(this,"barmerge",tD);U(this,"color",Ti);U(this,"currency",zf);U(this,"dayofweek",rD);U(this,"earnings",xD);U(this,"display",qf);U(this,"extend",nD);U(this,"font",{family_default:Jn.familyDefault,family_monospace:Jn.familyMonospace});U(this,"format",iD);U(this,"hline",sD);U(this,"label",oD);U(this,"line",aD);U(this,"location",uD);U(this,"math",lD);U(this,"order",{ascending:Qn.ascending,descending:Qn.descending});U(this,"plot",cD);U(this,"position",fD);U(this,"scale",hD);U(this,"session",{extended:qs.extended,regular:qs.regular});U(this,"shape",dD);U(this,"size",pD);U(this,"splits",{denominator:"denominator",numerator:"numerator"});U(this,"strategy",_D);U(this,"text",vD);U(this,"xloc",gD);U(this,"yloc",mD)}updateData(){}}class yD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:wt.bar_index,line_color:Ti.blue,line_style:zt.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var a;const r=`polyline_${t}_${this._variables.bar_index}`,n=Object.assign({},this._defaultPolyline,e,{id:r,points:(a=e.points)==null?void 0:a._value.map(u=>({time:u.time,index:u.index,price:u.price}))}),i=new Wf(r,this._variables);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(r,n,i),i}_verfiyArgs(e,t){const{line_style:r,xloc:n}=e,i="polyline.new";this._paramVerfiy(r,t,i,Object.values(zt),"line_style"),this._paramVerfiy(n,t,i,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}delete({id:e}){e&&e.delete()}}class Wf{constructor(e,t){U(this,"_id");U(this,"_variables");this._variables=t,this._id=e}delete(){this._variables.polyline.delete(this._id)}}class DD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultLine",{xloc:wt.bar_index,extend:Gr.none,style:zt.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},n){const i=`line_${n}_${this._variables.bar_index}`,a={...this._defaultLine,...r,id:i};if(e&&t){const f=a.xloc===wt.bar_index?e.index:e.time,c=a.xloc===wt.bar_index?t.index:t.time;Object.assign(a,{x1:f,y1:e.price,x2:c,y2:t.price})}this._verfiyArgs(r,n);const u=new ds(i,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(i,a,u),u}_verfiyArgs(e,t){const{extend:r,xloc:n,style:i}=e,a="line.new";this._paramVerfiy(i,t,a,Object.values(zt),"style"),this._paramVerfiy(r,t,a,Object.values(Gr),"extend"),this._paramVerfiy(n,t,a,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}line(e,t){return e.x?e.x:new ds(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class ds{constructor(e,t,r){U(this,"_variables");U(this,"_id");U(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}get data(){return this._variables.line.get(this._id)}copy(e){const t=`line_${e}_${this._variables.bar_index}`,r=this._getLine(e),n=new ds(t,this._variables,this._errorListener);return r&&this._variables.line.add(t,{...r,id:t},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:e},t){const r=this._getLine(t);if(e===void 0)return e;if(r&&r.xloc===wt.bar_index){const{x1:n,y1:i,x2:a,y2:u}=r;return n===void 0||a===void 0||i===void 0||u===void 0?void 0:(u-i)/(a-n)*(e-n)+i}}get_x1(e){var t;return(t=this._getLine(e))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t);r&&(r.x1=e)}set_x2({x:e},t){const r=this._getLine(t);r&&(r.x2=e)}set_y1({y:e},t){const r=this._getLine(t);r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t);r&&(r.y2=e)}set_xy1({x:e,y:t},r){const n=this._getLine(r);n&&(n.x1=e,n.y1=t)}set_xy2({x:e,y:t},r){const n=this._getLine(r);n&&(n.x2=e,n.y2=t)}set_xloc({xloc:e,x1:t,x2:r},n){const i=this._getLine(n);i&&(i.xloc=e,i.x1=t,i.x2=r,this._paramVerfiy(e,n,"line.set_xloc",Object.values(wt),"xloc"))}set_color({color:e},t){const r=this._getLine(t);r&&(r.color=e)}set_style({style:e},t){const r=this._getLine(t);r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(zt),"style"))}set_width({width:e},t){const r=this._getLine(t);r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t);r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(Gr),"extend"))}set_first_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},u=r.xloc===wt.bar_index?n:i,f=a;u&&(r.x1=u),f&&(r.y1=f)}}set_second_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},u=r.xloc===wt.bar_index?n:i,f=a;u&&(r.x2=u),f&&(r.y2=f)}}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getLine(e){const t=this._variables.line.get(this._id);return t||console.log(`${e}: line 不存在`),t}}class wD{constructor(e){U(this,"_variables");this._variables=e}new({line1:e,line2:t,color:r},n){const i=`linefill_${n}_${this._variables.bar_index}`,a=e==null?void 0:e.data,u=t==null?void 0:t.data;a&&(a.linefills=a.linefills||[],a.linefills.push(i)),u&&(u.linefills=u.linefills||[],u.linefills.push(i));const f=new Fo(this._variables,i,e,t);return n.startsWith("export")||(a||u)&&this._variables.linefill.add(i,{line1:a,line2:u,color:r,id:i},f),f}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class Fo{constructor(e,t,r,n){U(this,"_id");U(this,"_line1");U(this,"_line2");U(this,"_variables");this._variables=e,this._id=t,this._line1=r,this._line2=n}linefill(e,t){return e.x?e.x:new Fo(this._variables,t)}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:n,line2:i}=e;n&&(n.linefills=(t=n.linefills)==null?void 0:t.filter(a=>a!==this._id)),i&&(i.linefills=(r=i.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color({color:e}){const t=this._variables.linefill.get(this._id);t&&(t.color=e)}}class bD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultBox",{border_color:Ti.blue,border_width:1,bgcolor:Ti.blue,xloc:wt.bar_index,extend:Gr.none,style:zt.styleSolid,text:"",text_size:ar.auto,text_color:Ti.black,text_halign:je.alignCenter,text_valign:je.alignCenter,text_wrap:je.wrapNone});this._variables=e,this._errorListener=t}box({x:e},t){return e===void 0?new ps(this._variables,t,this._errorListener):e}new({top_left:e,bottom_right:t,...r},n){const i=`box_${n}_${this._variables.bar_index}`,a={...this._defaultBox,...r,id:i};if(e){const{price:f,time:c,index:h}=e;a.top=f,a.left=a.xloc===wt.bar_index?h:c}if(t){const{price:f,time:c,index:h}=t;a.bottom=f,a.right=a.xloc===wt.bar_index?h:c}this._verfiyArgs(r,n);const u=new ps(this._variables,i,this._errorListener);return n.startsWith("export")||this._variables.box.add(i,a,u),u}_verfiyArgs(e,t){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:u,text_valign:f,text_wrap:c,text_font_family:h}=e,d="box.new";this._paramVerfiy(r,t,d,[zt.styleDashed,zt.styleDotted,zt.styleSolid],"border_style"),this._paramVerfiy(n,t,d,Object.values(Gr),"extend"),this._paramVerfiy(i,t,d,Object.values(wt),"xloc"),this._paramVerfiy(a,t,d,Object.values(ar),"text_size"),this._paramVerfiy(u,t,d,[je.alignLeft,je.alignCenter,je.alignRight],"text_halign"),this._paramVerfiy(f,t,d,[je.alignBottom,je.alignCenter,je.alignTop],"text_valign"),this._paramVerfiy(c,t,d,[je.wrapAuto,je.wrapNone],"text_wrap"),this._paramVerfiy(h,t,d,Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_top({id:e}){return e==null?void 0:e.get_top()}get_bottom({id:e}){return e==null?void 0:e.get_bottom()}get_left({id:e}){return e==null?void 0:e.get_left()}get_right({id:e}){return e==null?void 0:e.get_right()}set_top({id:e,...t}){e==null||e.set_top(t)}set_bottom({id:e,...t}){e==null||e.set_bottom(t)}set_left({id:e,...t}){e==null||e.set_left(t)}set_right({id:e,...t}){e==null||e.set_right(t)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({id:e,...t}){e==null||e.set_border_color(t)}set_border_width({id:e,...t}){e==null||e.set_border_width(t)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t}){e==null||e.set_lefttop(t)}set_rightbottom({id:e,...t}){e==null||e.set_rightbottom(t)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t}){e==null||e.set_text_color(t)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t}){e==null||e.set_top_left_point(t)}set_bottom_right_point({id:e,...t}){e==null||e.set_bottom_right_point(t)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ps{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");this._variables=e,this._id=t,this._errorListener=r}copy(e){const t=`box_${e}_${this._variables.bar_index}`,r=this._getBox(),n=new ps(this._variables,t,this._errorListener);return r&&this._variables.box.add(t,{...r,id:t},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const e=this._getBox();return e&&e.top}set_top({top:e}){const t=this._getBox();t&&(t.top=e)}get_left(){const e=this._getBox();return e&&e.left}set_left({left:e}){const t=this._getBox();t&&(t.left=e)}set_text({text:e}){const t=this._getBox();t&&(t.text=e)}get_right(){const e=this._getBox();return e&&e.right}set_right({right:e}){const t=this._getBox();t&&(t.right=e)}get_bottom(){const e=this._getBox();return e&&e.bottom}set_bottom({bottom:e}){const t=this._getBox();t&&(t.bottom=e)}set_extend({extend:e},t){const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(Gr),"extend"))}set_bgcolor({color:e}){const t=this._getBox();t&&(t.bgcolor=e)}set_lefttop({left:e,top:t}){const r=this._getBox();r&&(r.left=e,r.top=t)}set_text_size({text_size:e},t){const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(ar),"text_size"))}set_text_wrap({text_wrap:e},t){const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[je.wrapAuto,je.wrapNone],"text_wrap"))}set_text_color({text_color:e}){const t=this._getBox();t&&(t.text_color=e)}set_rightbottom({right:e,bottom:t}){const r=this._getBox();r&&(r.right=e,r.bottom=t)}set_text_halign({text_halign:e},t){const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[je.alignLeft,je.alignCenter,je.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[je.alignBottom,je.alignCenter,je.alignTop],"text_valign"))}set_top_left_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.top=n,t.left=t.xloc===wt.bar_index?r:i}}set_border_color({color:e}){const t=this._getBox();t&&(t.border_color=e)}set_border_style({style:e},t){const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[zt.styleDashed,zt.styleDotted,zt.styleSolid],"style"))}set_border_width({width:e}){const t=this._getBox();t&&(t.border_width=e)}set_bottom_right_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.bottom=n,t.right=t.xloc===wt.bar_index?r:i}}set_text_font_family({text_font_family:e},t){const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(Jn),"text_font_family"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getBox(){return this._variables.box.get(this._id)}}class ED{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultTable",{position:br.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e},t){return e||new iu(this._variables,t,this._errorListener)}new(e,t){const r=`table_${t}_${this._variables.bar_index}`,n={...this._defaultTable,...e,cell:[],id:r},i=new iu(this._variables,r,this._errorListener);return this._paramVerfiy(e.position,t,"table.new",Object.values(br),"position"),t.startsWith("export")||this._variables.table.add(r,n,i),i}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}cell({table_id:e,...t}){e==null||e.cell(t)}cell_set_bgcolor({table_id:e,...t}){e==null||e.cell_set_bgcolor(t)}cell_set_height({table_id:e,...t}){e==null||e.cell_set_height(t)}cell_set_text({table_id:e,...t}){e==null||e.cell_set_text(t)}cell_set_text_color({table_id:e,...t}){e==null||e.cell_set_text_color(t)}cell_set_text_font_family({table_id:e,...t}){e==null||e.cell_set_text_font_family(t)}cell_set_text_halign({table_id:e,...t}){e==null||e.cell_set_text_halign(t)}cell_set_text_valign({table_id:e,...t}){e==null||e.cell_set_text_valign(t)}cell_set_text_size({table_id:e,...t}){e==null||e.cell_set_text_size(t)}cell_set_tooltip({table_id:e,...t}){e==null||e.cell_set_tooltip(t)}cell_set_width({table_id:e,...t}){e==null||e.cell_set_width(t)}clear({table_id:e,...t}){e==null||e.clear(t)}delete({table_id:e}){e==null||e.delete()}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({table_id:e,...t}){e==null||e.set_border_color(t)}set_border_width({table_id:e,...t}){e==null||e.set_border_width(t)}set_frame_color({table_id:e,...t}){e==null||e.set_frame_color(t)}set_frame_width({table_id:e,...t}){e==null||e.set_frame_width(t)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class iu{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");U(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ti.black,text_halign:je.alignCenter,text_valign:je.alignCenter,text_size:ar.normal});this._variables=e,this._id=t,this._errorListener=r}cell(e){const t={...this._defaultCell,...e},{column:r=0,row:n=0}=t,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],u=a[n]||[];u[r]=t,a[n]=u,i.cell=a}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r}){const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r}){const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r}){const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r}){const n=this._getTableItem(e,t);n&&(n.text_color=r)}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r}){const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r}){const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r}){const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r}){const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r}){const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r}){const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0}){const i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let u=t;u<=n;u++)for(let f=e;f<=r;f++){const c=a[u];c&&(c[f]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0},i){if(e>r||t>n){console.log(`error ${i}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(e,t);if(!a)return;this.clear({start_column:e,start_row:t,end_column:r,end_row:n});const u=this._variables.table.get(this._id);u.cell[t][e]={...a,isMerge:!0,merge_columns:r-e+1,merge_rows:n-t+1}}set_bgcolor({bgcolor:e}){const t=this._variables.table.get(this._id);t&&(t.bgcolor=e)}set_border_color({border_color:e}){const t=this._variables.table.get(this._id);t&&(t.border_color=e)}set_border_width({border_width:e}){const t=this._variables.table.get(this._id);t&&(t.border_width=e)}set_frame_color({frame_color:e}){const t=this._variables.table.get(this._id);t&&(t.frame_color=e)}set_frame_width({frame_width:e}){const t=this._variables.table.get(this._id);t&&(t.frame_width=e)}set_position({position:e},t){const r=this._variables.table.get(this._id);r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(br),"position"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getTableItem(e,t){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[t][e]:void 0}}}class AD{constructor(e){U(this,"_strategy");this._strategy=e}commission({trade_num:e}){return this._verifyTradeNum(e)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.historyOrders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_time}exit_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{out_qty:t=0,direction:r}=this._strategy.historyOrders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.historyOrders.length;return!(e>=t)}}class CD{constructor(e){U(this,"_strategy");this._strategy=e}commission({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,original_qty:r=0,commission:n=0}=this._strategy.orders[e];return n*t/r}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.orders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,direction:r}=this._strategy.orders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.orders.length;return!(e>=t)}}class FD{constructor(e,t){U(this,"_strategy");U(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(gt),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e}){this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[Rt.percentOfEquity,Rt.cash],"type"),t===Rt.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e}){this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[Rt.percentOfEquity,Rt.cash],"type"),t===Rt.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e}){this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}}let BD=class{constructor(e,t,r,n){U(this,"_variables");U(this,"_options");U(this,"_totalChangeCapital");U(this,"_historyOrder");U(this,"_orders");U(this,"_pendingOrders");U(this,"_mintick");U(this,"_funcOptions");U(this,"_pendingCloseOrders");U(this,"_errorListener");U(this,"_risk");U(this,"_opentrades");U(this,"_closedtrades");U(this,"_riskNamespace");this._variables=e,this._errorListener=n,this._options={overlay:!1,format:Je.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Rt.fixed,default_qty_value:1,initial_capital:1e6,currency:zf.NONE,slippage:0,commission_type:Tr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new CD(this),this._closedtrades=new AD(this),this._riskNamespace=new FD(this,n)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((e,t)=>e+(t.profit||0),0)}get _freezeCapital(){const{close:e}=this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(e){Object.assign(this._options,e),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var v;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{high:n,low:i,time_tradingday:a,time:u,strategy:{netprofit:f,initial_capital:c}}=this._variables;let{preNetprofit:h=0}=this._risk;u===a&&(h=f,this._risk.preNetprofit=f,this._risk.isTemporaryBan=!1);let d=h-f;d+=this._orders.reduce((x,_)=>{const{in_price:y,direction:m,qty:w=0,commission:D=0,original_qty:C=0}=_,b=m===gt.long?1:-1,F=(n-y)*w,B=(i-y)*w,M=b===1?-B:F;return x+M+w/C*D},0);let p=!1;switch(t){case Rt.cash:p=e<d;break;case Rt.percentOfEquity:const x=d/(c+f)*100;p=e<x;break}if(p){this._risk.isTemporaryBan=!0;const x=(v=this._orders[0])==null?void 0:v.direction;this._closeOrders(this._orders,x===gt.long?i:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(e===void 0||r)return;const{time:i,time_tradingday:a,strategy:u,open:f}=this._variables;let c=t;if(i===a){const h=u.netprofit+u.openprofit;h<n?c=0:c++,Object.assign(this._risk,{lossDays:c,totalProfit:h})}e<=c&&this._riskTouchOff(f,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(!r&&e!==void 0&&t){const{max_drawdown:i,max_drawdown_percent:a}=this._variables.strategy;let u=!1;switch(t){case Rt.percentOfEquity:u=a<i;break;case Rt.cash:u=e<i;break}if(u){const{high:f,low:c}=this._variables,h=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(h===gt.long?f:c,"Close Position (Max Drawdown)")}}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,e,t),this._pendingOrders=[]}strategy(e,t){this._variables.bar_index||(this._paramVerfiy(e.format,t,"strategy",[Je.inherit,Je.price,Je.percent,Je.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(Rt),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(Tr),"commission_type"),this._options={...e},this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"}))}order(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(vn),"oca_type"),this._orderHandle(e))}entry(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(vn),"oca_type"),this._entryHandle(e))}close(e){if(!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close"}):this._pendingOrders.push({...e,place_order_type:"close"})}close_all(e){if(typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e}){this._pendingOrders=this._pendingOrders.filter(t=>!(t.id===e&&t.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(e=>e.place_order_type==="close_all")}exit(e,t){this._exit(e,t)}convert_to_account({value:e}){return e}convert_to_symbol({value:e}){return e}default_entry_qty({fill_price:e}){return e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=Rt.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(t){case Rt.fixed:return r;case Rt.cash:return r/e;case Rt.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/e}}_getCapital(e,t){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:n<=100&&n>0&&e===-1&&(t=t*100/n),t}_calcProfitAndLoss(){const{high:e,low:t,close:r}=this._variables;for(const n of this._orders){const{in_price:i,qty:a=0,direction:u}=n,f=u===gt.long?1:-1,c=(r-i)*f*a,h=(e-i)*a,d=(t-i)*a,p=f===1?h:-d,v=f===1?-d:h;this._calcOrderPercent(n,c,p,v)}}_calcOrderPercent(e,t,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:u=0,qty:f=0,in_price:c,max_profit:h=0,trading_loss:d=0}=e;let{commission:p=0}=e;const v=c*f;if(i){const x=this._getCommission(a,f);t=t-x,p=p*f/u,r-=p,n+=p}r=Math.max(r,h),n=Math.min(n,d),Object.assign(e,{profit:t-p,total_profit:this._totalChangeCapital+t,max_profit:r,trading_loss:n,profit_percent:t/v*100,max_profit_percent:r/v*100,trading_loss_percent:n/v*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:e,low:t}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:i=0,commission_value:a=0}=this._options,u=this._orders[0].direction===gt.long?1:-1,f=u===1?t:e,c=(u===1?n:i)/100;if(c<=0)return;const[h,d,p]=this._orders.reduce((m,w)=>{let[D,C,b]=m;const{in_price:F,qty:B=0,original_qty:M=0,commission:O=0}=w,A=F*B,N=f*B;if(D+=A,C+=N,a){const T=this._getCommission(f,B);b+=T+B/M*O}return[D,C,b]},[0,0,0]),v=u*(d-h),_=r+this._totalChangeCapital+v-p-d*c;if(_>=0)return;const y=Math.trunc(_/c/f)*4;this._marginCallOrders(f,y,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r);return}for(const i of this.orders)this._processOrder(i,e,t,r,r);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(e){const{process_orders_on_close:t,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:u,price:f,activePrice:c}=this._orderArgsParse(e),h=e.direction===gt.long?1:-1;if(a<=0)return;let d=a;if(i&&t){if(n.length){const _=this._processOrders(n,u,d,e.id,e.comment);if(_<=0)return;d=_}const v=u+h*r*this._mintick;if(!this._judgeCapitalEnough(d,v,h))return;this._ocaGroupVerify(d,e.oca_name,e.oca_type),this._calcCurrentOrder({...e,in_price:v,in_index:this._variables.bar_index,in_time:this._variables.time,qty:d,place_order_type:"order"});return}this._judgeCapitalEnough(a,f,h)&&this._addPendingOrders(e,f,d,i,c)}_judgeCapitalEnough(e,t,r){if(e<=0)return!1;const{margin_long:n=0,margin_short:i=0}=this._options;if((n===0||n===100)&&r===1||i===0&&r===-1)return!0;const u=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return e*t<=u}_ocaGroupVerify(e,t,r){if(!t||!r||r===vn.none)return!1;let n=!1;switch(r){case vn.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===t)i.isCancel=!0,n=!0;else return!0});break;case vn.reduce:this._pendingOrders=this._pendingOrders.filter(i=>{const{qty:a=0,oca_name:u}=i;if(t===u){const f=a-e;return n=!0,f<=0?(i.isCancel=!0,!1):(i.qty=f,!0)}else return!0});break}return n}_processOrders(e,t,r,n,i){let a=r;for(const u of e)if(a=this._processOrder(u,t,a,n,i),a<=0)break;return this._orders=this._orders.filter(u=>!u.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(e,t,r,n,i){const a=this._pendingOrders.find(u=>u.id===e.id&&!u.isMarketPrice);if(a)Object.assign(a,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else{const u={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(u)}}_orderArgsParse(e){const{direction:t,qty:r,stop:n}=e;let i=e.limit||0;const{close:a}=this._variables;let u=a,f=!1,c;const h=t===gt.long?1:-1,d=n&&(n-a)*h>0,{backtest_fill_limits_assumption:p=0}=this._options;p>0&&i&&(i-=p*this._mintick*h);const v=i&&(i-a)*h<0;d&&v?(c=n,u=i):d?u=n:v?u=i:f=!0;const x=r||this._calcDefaultQty(u)||1;return{orders:this._orders.filter(y=>y.direction!==t),isMarketPrice:f,activePrice:c,quantities:x,close:a,price:u}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:u,activePrice:f}=this._orderArgsParse(e);if(i<=0)return;if(r.length&&n&&t){this._entryOrder(r,a,i,e);return}this._judgeCapitalEnough(i,a,e.direction===gt.long?1:-1)&&this._addPendingEntry(e,u,i,n,f)}_entryOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{oca_name:f,oca_type:c,direction:h,comment:d,isMarketPrice:p,id:v}=n,x=h===gt.long?1:-1;if(this._closeOrders(e,t,v,d),r=this._getAvailablePositionSize(r,h),r<=0)return;t=t+u*this._mintick*x;const _={...n,in_price:t,original_qty:r,qty:r,in_index:a,in_time:i,place_order_type:"entry"};if(p){this._calcCurrentOrder(_);return}const{pendingOrders:y,orders:m}=this._getEntryOrders(h),w=y.length+m.length;w&&w>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,t,x)||(this._ocaGroupVerify(r,f,c),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==gt.all&&n!==t)return 0;if(r===void 0)return e;const i=this._orders.reduce((a,u)=>a+(u.qty||0),0);return i?i+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===e),r=this._orders.filter(n=>n.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,n,i){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:a,orders:u}=this._getEntryOrders(e.direction),f=a.length+u.length,c=a.find(h=>h.id===e.id&&h.place_order_type==="entry");if(c)Object.assign(c,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else if(!f||f<(this._options.pyramiding||1)){const h={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(e,t){const{comment:r}=e,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,t,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,n){for(const i of e)this._closeOrder(i,t,r,n);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{in_price:f,qty:c=0,direction:h}=e,d=h===gt.long?1:-1;t=t-d*u*this._mintick,e.isDeal=!0;const p=(t-f)*d*c,v={...e,out_price:t,out_id:r,out_index:a,out_time:i,out_comment:n,out_qty:c,profit:p};this._calcPercent(v),this._risk.intradayOrders+=1,this._historyOrder.push(v),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const e=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!e.length)return;const{open:t,low:r,high:n,close:i}=this._variables;for(const a of e){const{stop:u,limit:f,trail_stop_price:c,isMarketPriceLimit:h,isMarketPriceStop:d,direction:p,id:v,out_comment:x,active_price:_,trail_offset:y=0,out_qty:m,comment_loss:w,comment_profit:D,comment_trailing:C}=a;let b=c;const F=p===gt.long?1:-1;let B,M=x;if(h||d?B=t:(f&&r<=f&&n>=f&&(M=D||x,B=f),u&&r<=u&&n>=u&&(B=b?(u-b)*F>0?u:b:u,M=(b===B?C:w)||x)),B)this._processExitOnClose(a,B,{from_entry:v,comment:M,qty:m});else{let O=!1;if(_&&_<=n&&_>=r&&(b=_-y*F*this._mintick,(b-i)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(B=b)),O=!0,a.trail_stop_price=b),b)if((b-t)*F>=0&&!O)B=b;else{const A=(F===1?n:r)-y*F*this._mintick;F===1?b<t&&b>=r&&A>b&&A<i?B=b:A>b?(b=A,A>=i&&(B=A)):b<=n&&r<=b&&(B=b):b>t&&b<=n&&A<b&&A>i?B=b:A<b?(b=A,A<=i&&(B=A)):b<=n&&r<=b&&(B=b),a.trail_stop_price=b}B&&this._processExitOnClose(a,B,{from_entry:v,comment:C||x,qty:m})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of r)switch(n.place_order_type){case"close":this._closeOrderHandle(n);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of this._pendingOrders){const{isCancel:i,place_order_type:a}=n;if(i)continue;let u;switch(a){case"entry":u=this._entryOrderHandle(n);break;case"order":u=this._orderOrderHandle(n);break}u&&e.push(u)}for(const n of t){const i=this._exitOrderHandle(n);i&&e.push(i)}this._pendingOrders=e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const e=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),t=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of t)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of e){const{from_entry:i}=n,a=this._orders.filter(u=>!i||u.id===i&&(u.isMarketPriceLimit||u.isMarketPriceStop));for(const u of a)this._processExitOnClose(u,u.limit||u.stop||u.trail_stop_price||r,n)}this._pendingCloseOrders=[]}_entryOrderHandle(e){const{open:t,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:u,direction:f,active_price:c}=e;if(c&&n>=c&&r<=c)return delete e.active_price,e;let h=u;if(i&&(h=t),h<=n&&h>=r){const d=this._orders.filter(p=>p.direction!==f);this._entryOrder(d,h,a,e)}else return e}_orderOrderHandle(e){const{open:t,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{isMarketPrice:f,qty:c=0,in_price:h,direction:d,comment:p,oca_name:v,oca_type:x,active_price:_,id:y}=e;if(_&&n>=_&&r<=_)return delete e.active_price,e;let m=h,w=c;if(f&&(m=t),m<=n&&m>=r){const D=this._orders.filter(b=>b.direction!==d);if(D.length&&(w=this._processOrders(D,m,c,y,p),w<=0))return;const C=d===gt.long?1:-1;this._ocaGroupVerify(w,v,x),this._calcCurrentOrder({...e,in_price:m+C*u*this._mintick,in_index:a,in_time:i,qty:w});return}else return e}_closeOrderHandle(e,t){const{id:r,qty:n,qty_percent:i=100,comment:a}=e,{bar_index:u}=this._variables,f=this._orders.filter(v=>v.id===r&&v.in_index!==u&&(!v.close_qty||v.close_qty<(v.qty||0)));if(!f.length)return;let c=0;if(n?c=n:(c=f.reduce((v,x)=>v+(x.qty||0),c),c=i/100*c),c<=0)return;const{open:h,close:d}=this._variables;let p=c;for(const v of f){const{qty:x=0}=v;p<x?v.close_qty=p:(v.close_qty=x,p-=x)}this._processOrders(this._options.close_entries_rule==="ANY"?f:this._orders,t?d:h,c,`Close entry(s) order ${r}`,a)}_exitOrderHandle(e){const{from_entry:t}=e,r=this._orders.filter(n=>(!t||t===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,e)))return e}_exit(e,t){const{profit:r,loss:n,stop:i,limit:a,trail_offset:u,trail_price:f,trail_points:c,from_entry:h="",id:d}=e;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(u)||this._isNaN(c)&&this._isNaN(f))){this._errorListener.addError("strategy.exit must have at least one of the following parameters: 'profit', 'limit', 'loss', 'stop' or one of the following pairs: 'trail_offset' and 'trail_price' / 'trail_points'. To close the position at market price, use 'strategy.close'",t,Ve.Error);return}const p={...e,place_order_type:"exit"},v=this._orders.filter(y=>(!h||h===y.id)&&!y.hasExit),x=this._pendingOrders.filter(y=>!h||h===y.id);if(v.length){if(!this._ordersToExit(v,p))return}else if(!x.length)return;const _=this._pendingOrders.find(y=>y.id===d);_?Object.assign(_,{...e}):this._pendingOrders.push(p)}_ordersToExit(e,t){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:u,comment_profit:f,comment_trailing:c}=t;let h=r,d=!1;t.comment=a||i;for(const p of e){const{qty:v=0}=p,x=p.direction===gt.long?1:-1;h=r?r>=v?v:r:n/100*v,p.out_qty=h,h<v&&(d=!0),Object.assign(p,{out_comment:a||i,comment_loss:u,comment_profit:f,comment_trailing:c}),!(this._stopProfit(p,x,{...t,qty:h})||this._stopLoss(p,x,{...t,qty:h})||this._trailStopLoss(p,x,{...t,qty:h}))&&(p.place_order_type="exit")}return d}_addExitPendingCloseOrders(e){e.place_order_type="exit";const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r){const{limit:n,profit:i,comment_profit:a,comment:u}=r;let f=n;const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(f=h+t*i*this._mintick),e.limit=f,f&&(f-c)*t<=0&&(e.isMarketPriceLimit=!0,r.comment=a||u,Object.assign(e,{out_comment:r.comment}),f=c,d))return this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r){const{stop:n,loss:i,comment_loss:a,comment:u}=r;let f=n;const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(f=h-t*i*this._mintick),e.stop=f,f&&(f-c)*t>=0&&(e.isMarketPriceStop=!0,r.comment=a||u,Object.assign(e,{out_comment:r.comment}),f=c,d))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:u,comment:f}=r;if(!this._isNaN(n)){const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;let p;if(this._isNaN(i)?this._isNaN(a)||(p=h+a*t*this._mintick):p=i,e.trail_offset=n,p&&(p-c)*t<=0){const v=c-n*t*this._mintick;if((v-c)*t>=0&&(e.trail_stop_price=c,e.isMarketPriceStop=!0,r.comment=u||f,Object.assign(e,{out_comment:r.comment}),d))return this._addExitPendingCloseOrders(r),!0;e.trail_stop_price=v}e.active_price=p}}_processExitOnClose(e,t,r){const{qty:n=0,comment:i,id:a}=r,{close_entries_rule:u="FIFO"}=this._options;if(u==="FIFO"){const f=this._processExitOrders(this._orders,t,n,a,i);f&&!f.hasExit?(f.hasExit=!0,Object.assign(e,{trail_stop_price:f.trail_stop_price,stop:f.stop,limit:f.limit,trail_offset:f.trail_offset,active_price:f.active_price})):f&&(e.hasExit=!0)}else e.hasExit=!0,this._processOrders([e],t,n,a,i)}_processExitOrders(e,t,r,n,i){let a=r,u;for(const f of e)if(u=f,a=this._processOrder(f,t,a,n,i),a<=0||!f.hasExit)break;return this._orders=this._orders.filter(f=>!f.isDeal),this._variables.strategy.updateOrders(this._orders),u}_processOrder(e,t,r,n,i){const{time:a,bar_index:u}=this._variables,{slippage:f=0}=this._options,{in_price:c,qty:h=0,max_profit:d=0,trading_loss:p=0,direction:v,commission:x=0,original_qty:_=0}=e,y=v===gt.long?1:-1;if(t=t-y*f*this._mintick,r<h){const m=h-r,w=(t-c)*y*r,D=d/h*r,C=p/h*r;this._calcPercent({...e,out_price:t,out_id:n,out_index:u,out_time:a,out_comment:i,profit:w,out_qty:r,max_profit:D,trading_loss:C});const b=(t-c)*y*m-x*m/_;Object.assign(e,{qty:m,profit:b,max_profit:d-D,trading_loss:p-C,total_profit:this._totalChangeCapital+b}),r=0}else{e.isDeal=!0;const m=(t-c)*y*h;this._calcPercent({...e,out_price:t,out_id:n,out_index:u,out_time:a,out_comment:i,out_qty:h,profit:m}),r-=h}return r}_calcPercent(e){const{commission_value:t}=this._options,{in_price:r,out_qty:n=0,out_price:i=0,original_qty:a=0}=e;let{profit:u=0,max_profit:f=0,trading_loss:c=0,commission:h=0}=e;f=f<0?0:f;const d=r*n;if(this._totalChangeCapital+=u,t){const p=this._getCommission(i,n);this._totalChangeCapital-=p,h=h*n/a+p,u=u-h,Object.assign(e,{commission:h,profit:u,max_profit:f})}Object.assign(e,{total_profit:this._totalChangeCapital,profit_percent:u/d*100,max_profit_percent:f/d*100,trading_loss_percent:c/d*100}),this._risk.intradayOrders+=1,this._historyOrder.push(e),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(e,t){const{commission_value:r=0,commission_type:n}=this._options,i=e*t;let a=0;switch(n){case Tr.percent:a=i*r/100;break;case Tr.cashPerContract:a=t*r;break;case Tr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=e;let{profit:u=0}=e;const f=r*n;if(t){const c=this._getCommission(r,n);this._totalChangeCapital-=c,u=u-c,Object.assign(e,{commission:c,profit:u,total_profit:this._totalChangeCapital})}Object.assign(e,{original_qty:n,profit_percent:u/f*100,max_profit_percent:i/f*100,trading_loss_percent:a/f*100}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders)}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}};var Hf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){return function(t,r,n){r.prototype.isBetween=function(i,a,u,f){var c=n(i),h=n(a),d=(f=f||"()")[0]==="(",p=f[1]===")";return(d?this.isAfter(c,u):!this.isBefore(c,u))&&(p?this.isBefore(h,u):!this.isAfter(h,u))||(d?this.isBefore(c,u):!this.isAfter(c,u))&&(p?this.isAfter(h,u):!this.isBefore(h,u))}}})})(Hf);var MD=Hf.exports,ND=tt(MD),jf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){return function(t,r,n){var i=r.prototype,a=function(p){var v,x=p.date,_=p.utc,y={};if(!((v=x)===null||v instanceof Date||v instanceof Array||i.$utils().u(v)||v.constructor.name!=="Object")){if(!Object.keys(x).length)return new Date;var m=_?n.utc():n();Object.keys(x).forEach(function(O){var A,N;y[A=O,N=i.$utils().p(A),N==="date"?"day":N]=x[O]});var w=y.day||(y.year||y.month>=0?1:m.date()),D=y.year||m.year(),C=y.month>=0?y.month:y.year||y.day?0:m.month(),b=y.hour||0,F=y.minute||0,B=y.second||0,M=y.millisecond||0;return _?new Date(Date.UTC(D,C,w,b,F,B,M)):new Date(D,C,w,b,F,B,M)}return x},u=i.parse;i.parse=function(p){p.date=a.bind(this)(p),u.bind(this)(p)};var f=i.set,c=i.add,h=i.subtract,d=function(p,v,x,_){_===void 0&&(_=1);var y=Object.keys(v),m=this;return y.forEach(function(w){m=p.bind(m)(v[w]*_,w)}),m};i.set=function(p,v){return v=v===void 0?p:v,p.constructor.name==="Object"?d.bind(this)(function(x,_){return f.bind(this)(_,x)},v,p):f.bind(this)(p,v)},i.add=function(p,v){return p.constructor.name==="Object"?d.bind(this)(c,p,v):c.bind(this)(p,v)},i.subtract=function(p,v){return p.constructor.name==="Object"?d.bind(this)(c,p,v,-1):h.bind(this)(p,v)}}})})(jf);var SD=jf.exports,OD=tt(SD),Yf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){var t,r,n=1e3,i=6e4,a=36e5,u=864e5,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,h=2628e6,d=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,p={years:c,months:h,days:u,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},v=function(F){return F instanceof C},x=function(F,B,M){return new C(F,M,B.$l)},_=function(F){return r.p(F)+"s"},y=function(F){return F<0},m=function(F){return y(F)?Math.ceil(F):Math.floor(F)},w=function(F){return Math.abs(F)},D=function(F,B){return F?y(F)?{negative:!0,format:""+w(F)+B}:{negative:!1,format:""+F+B}:{negative:!1,format:""}},C=function(){function F(M,O,A){var N=this;if(this.$d={},this.$l=A,M===void 0&&(this.$ms=0,this.parseFromMilliseconds()),O)return x(M*p[_(O)],this);if(typeof M=="number")return this.$ms=M,this.parseFromMilliseconds(),this;if(typeof M=="object")return Object.keys(M).forEach(function(k){N.$d[_(k)]=M[k]}),this.calMilliseconds(),this;if(typeof M=="string"){var T=M.match(d);if(T){var R=T.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=R[0],this.$d.months=R[1],this.$d.weeks=R[2],this.$d.days=R[3],this.$d.hours=R[4],this.$d.minutes=R[5],this.$d.seconds=R[6],this.calMilliseconds(),this}}return this}var B=F.prototype;return B.calMilliseconds=function(){var M=this;this.$ms=Object.keys(this.$d).reduce(function(O,A){return O+(M.$d[A]||0)*p[A]},0)},B.parseFromMilliseconds=function(){var M=this.$ms;this.$d.years=m(M/c),M%=c,this.$d.months=m(M/h),M%=h,this.$d.days=m(M/u),M%=u,this.$d.hours=m(M/a),M%=a,this.$d.minutes=m(M/i),M%=i,this.$d.seconds=m(M/n),M%=n,this.$d.milliseconds=M},B.toISOString=function(){var M=D(this.$d.years,"Y"),O=D(this.$d.months,"M"),A=+this.$d.days||0;this.$d.weeks&&(A+=7*this.$d.weeks);var N=D(A,"D"),T=D(this.$d.hours,"H"),R=D(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var z=D(k,"S"),L=M.negative||O.negative||N.negative||T.negative||R.negative||z.negative,G=T.format||R.format||z.format?"T":"",H=(L?"-":"")+"P"+M.format+O.format+N.format+G+T.format+R.format+z.format;return H==="P"||H==="-P"?"P0D":H},B.toJSON=function(){return this.toISOString()},B.format=function(M){var O=M||"YYYY-MM-DDTHH:mm:ss",A={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return O.replace(f,function(N,T){return T||String(A[N])})},B.as=function(M){return this.$ms/p[_(M)]},B.get=function(M){var O=this.$ms,A=_(M);return A==="milliseconds"?O%=1e3:O=A==="weeks"?m(O/p[A]):this.$d[A],O||0},B.add=function(M,O,A){var N;return N=O?M*p[_(O)]:v(M)?M.$ms:x(M,this).$ms,x(this.$ms+N*(A?-1:1),this)},B.subtract=function(M,O){return this.add(M,O,!0)},B.locale=function(M){var O=this.clone();return O.$l=M,O},B.clone=function(){return x(this.$ms,this)},B.humanize=function(M){return t().add(this.$ms,"ms").locale(this.$l).fromNow(!M)},B.valueOf=function(){return this.asMilliseconds()},B.milliseconds=function(){return this.get("milliseconds")},B.asMilliseconds=function(){return this.as("milliseconds")},B.seconds=function(){return this.get("seconds")},B.asSeconds=function(){return this.as("seconds")},B.minutes=function(){return this.get("minutes")},B.asMinutes=function(){return this.as("minutes")},B.hours=function(){return this.get("hours")},B.asHours=function(){return this.as("hours")},B.days=function(){return this.get("days")},B.asDays=function(){return this.as("days")},B.weeks=function(){return this.get("weeks")},B.asWeeks=function(){return this.as("weeks")},B.months=function(){return this.get("months")},B.asMonths=function(){return this.as("months")},B.years=function(){return this.get("years")},B.asYears=function(){return this.as("years")},F}(),b=function(F,B,M){return F.add(B.years()*M,"y").add(B.months()*M,"M").add(B.days()*M,"d").add(B.hours()*M,"h").add(B.minutes()*M,"m").add(B.seconds()*M,"s").add(B.milliseconds()*M,"ms")};return function(F,B,M){t=M,r=M().$utils(),M.duration=function(N,T){var R=M.locale();return x(N,{$l:R},T)},M.isDuration=v;var O=B.prototype.add,A=B.prototype.subtract;B.prototype.add=function(N,T){return v(N)?b(this,N,1):O.bind(this)(N,T)},B.prototype.subtract=function(N,T){return v(N)?b(this,N,-1):A.bind(this)(N,T)}}})})(Yf);var TD=Yf.exports,ID=tt(TD);ot.extend(yl),ot.extend(ND),ot.extend(OD),ot.extend(ID);class Zf{constructor(e,t,r){U(this,"array");U(this,"color");U(this,"math");U(this,"str");U(this,"map");U(this,"matrix");U(this,"timeframe");U(this,"ta");U(this,"input");U(this,"_variables");U(this,"_cacheData");U(this,"_options");U(this,"_errorListener");U(this,"_plots");U(this,"_plotshapes");U(this,"_plotbars");U(this,"_plotchars");U(this,"_plotarrows");U(this,"_plotcandles");U(this,"_alerts");U(this,"_bgColors");U(this,"_hlines");U(this,"_fills");U(this,"chart");U(this,"line");U(this,"label");U(this,"polyline");U(this,"box");U(this,"table");U(this,"linefill");U(this,"log");U(this,"runtime");U(this,"strategy");U(this,"request");U(this,"syminfo");U(this,"_count",0);var i;const n=((i=e.toString().split(".")[1])==null?void 0:i.length)||4;this._variables=t,this._errorListener=new fw,this.array=new g1(this._errorListener),this.math=new m1(n,this._errorListener),this.color=new Gx,this.str=new Ky(this._errorListener,n),this.map=new Xy(this._errorListener),this.timeframe=new Gy(t),this.matrix=new Vy(this._errorListener),this.ta=new Hx(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new Vx(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Qy(t)},this.line=new DD(t,this._errorListener),this.label=new Jy(t,this._errorListener),this.polyline=new yD(t,this._errorListener),this.box=new bD(t,this._errorListener),this.table=new ED(t,this._errorListener),this.linefill=new wD(t),this.log=new lw(t),this.runtime=new cw(this._errorListener),this.strategy=new BD(this._variables,this._options,e,this._errorListener),this.request=new aw(this._variables,r),this.syminfo=new uw}get errors(){return this._errorListener.errors}options(e){if(e.length)return this._getDataOfBarindex(e);const t=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let i;if(n.length){i={};for(const y of n)i[y]=[...this._bgColors[y].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,u=this._fills.size?[...this._fills.values()]:void 0,f=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._plots.size>0?[...this._plots.values()]:void 0,h=this._plotbars.size>0?[...this._plotbars.values()]:void 0,d=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,p=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,v=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,x=this._plotchars.size>0?[...this._plotchars.values()]:void 0,_=this._getDraws();return Object.assign(this._options,{inputs:t,plots:c,draws:_,alerts:r,colors:i,hlines:a,fills:u,logs:f,plotshapes:d,plotarrows:p,plotcandles:v,plotchars:x,plotbars:h})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const d of r)n[d]=[...this._bgColors[d].values()].map(p=>{const v=[];for(const x of e){const _=p.colors[x];_&&v.push(_)}return p.colors=v,p})}const i=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,u=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const f=this._getDataFromBarindex(e,[...this._plots.values()]),c=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,h=this._getDrawsFromBarindex(e);return Object.assign(this._options,{plots:f,draws:h,alerts:t,colors:n,hlines:i,fills:a,logs:u,plotshapes:c})}_getDataFromBarindex(e,t){return t.map(r=>{const n=[];for(const i of e){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:n,polyline:i,label:a}=this._variables,u={};return e.data.length&&(u.lines=e.data),t.data.length&&(u.linefills=t.data),r.data.length&&(u.tables=r.data),n.data.length&&(u.boxes=n.data),i.data.length&&(u.polylines=i.data),a.data.length&&(u.labels=a.data),Object.keys(u).length?u:void 0}_getDrawsFromBarindex(e){const{line:t,linefill:r,table:n,box:i,polyline:a,label:u}=this._variables,f={};return t.data.length&&(f.lines=t.getValOfBarIndex(e)),r.data.length&&(f.linefills=r.getValOfBarIndex(e)),n.data.length&&(f.tables=n.getValOfBarIndex(e)),i.data.length&&(f.boxes=i.getValOfBarIndex(e)),a.data.length&&(f.polylines=a.getValOfBarIndex(e)),u.data.length&&(f.labels=u.getValOfBarIndex(e)),Object.keys(f).length?f:void 0}updateOptions(e){const{inputs:t}=e;t&&t.length&&this.input.update(t)}update(e){const{barIndex:t}=e;this.strategy.updateOptions(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=e;r.test(n)?(Zx.includes(n)||Yx.includes(n))&&this._errorListener.addError(or(Kt.libraryTitleIsKeywordErr,{name:n}),t,Ve.Error):this._errorListener.addError(Kt.libraryTitleErr,t,Ve.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r}=e;this._paramVerfiy(r,t,"indicator",[Je.inherit,Je.percent,Je.price,Je.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,n,i="format"){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}plot(e,t){const{series:r,color:n,...i}=e,{bar_index:a,time:u}=this._variables,f=`plot_${t}`,c=this._plots.get(f),h=(c==null?void 0:c.data)||[],d=r!==void 0&&isNaN(r)?void 0:r;if(h[a]={value:[u,d],itemStyle:{color:n}},this._seriesColorHandle(e,["color"],c),!c){this._count++,this._paramVerfiy(e.format,t,"plot",[Je.percent,Je.price,Je.volume]);const p=n?[n]:void 0;this._plots.set(f,{editable:!0,...i,colors:p,data:h,id:f,zIndex:this._count})}return{type:"plot",key:f}}plotbar(e,t){const{open:r,close:n,low:i,high:a,color:u,...f}=e,{bar_index:c,time:h}=this._variables,d=`plotbar_${t}`,p=this._plotbars.get(d),v=(p==null?void 0:p.data)||[],x=n!==void 0&&isNaN(n)?void 0:n,_=r!==void 0&&isNaN(r)?void 0:r,y=i!==void 0&&isNaN(i)?void 0:i,m=a!==void 0&&isNaN(a)?void 0:a,w=[h,_,x,y,m];if(v[c]={value:w,itemStyle:{color:u}},this._seriesColorHandle(e,["color"],p),!p){this._count++,this._paramVerfiy(e.format,t,"plotbar",[Je.percent,Je.price,Je.volume]);const D=u?[u]:void 0;this._plotbars.set(d,{editable:!0,...f,colors:D,data:v,id:d,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:n,format:i,location:a,style:u}=e;this._paramVerfiy(u,r,t,Object.values(_r),"style"),this._paramVerfiy(a,r,t,Object.values(_n),"location"),this._paramVerfiy(n,r,t,Object.values(ar),"size"),this._paramVerfiy(i,r,t,[Je.percent,Je.price,Je.volume],"format")}plotchar(e,t){const{series:r,color:n,textcolor:i,location:a=_n.abovebar,...u}=e,{bar_index:f,time:c,high:h,low:d}=this._variables,p=`plotchar_${t}`,v=this._plotchars.get(p),x=(v==null?void 0:v.data)||[],_={value:[c,r],itemStyle:{color:n,textcolor:i},low:d,high:h};x[f]=_,this._seriesColorHandle(e,["color","textcolor"],v),v||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(p,{editable:!0,...u,location:a,data:x,id:p,zIndex:this._count}))}plotarrow(e,t){const{series:r,colorup:n,colordown:i,...a}=e,{bar_index:u,time:f}=this._variables,c=`plotarrow_${t}`,h=this._plotarrows.get(c),d=(h==null?void 0:h.data)||[];d[u]={value:[f,r!==void 0&&isNaN(r)?void 0:r],itemStyle:{colorup:n,colordown:i}},this._seriesColorHandle(e,["colorup","colordown"],h),h||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[Je.percent,Je.price,Je.volume]),this._plotarrows.set(c,{editable:!0,...a,data:d,id:c,zIndex:this._count}))}plotshape(e,t){const{series:r,color:n,textcolor:i,location:a=_n.abovebar,...u}=e,{bar_index:f,time:c,low:h,high:d}=this._variables,p=`plotshape_${t}`,v=this._plotshapes.get(p),x=(v==null?void 0:v.data)||[],_={value:r,color:n,textcolor:i,time:c,low:h,high:d};if(x[f]=_,this._seriesColorHandle(e,["color","textcolor"],v),!v){this._count++;const y=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(p,{editable:!0,...u,data:x,location:a,id:p,colors:y,zIndex:this._count})}}plotcandle(e,t){const{wickcolor:r,bordercolor:n,color:i,close:a,open:u,low:f,high:c,...h}=e,{bar_index:d,time:p}=this._variables,v=`plotcandle_${t}`,x=this._plotcandles.get(v),_=(x==null?void 0:x.data)||[],y=a!==void 0&&isNaN(a)?void 0:a,m=u!==void 0&&isNaN(u)?void 0:u,w=f!==void 0&&isNaN(f)?void 0:f,D=c!==void 0&&isNaN(c)?void 0:c,C=[p,m,y,w,D];_[d]={value:C,wickcolor:r,bordercolor:n,color:i},this._seriesColorHandle(e,["wickcolor","bordercolor","color"],x),x||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[Je.percent,Je.price,Je.volume]),this._plotcandles.set(v,{editable:!0,...h,data:_,id:v,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?Zt.none:Zt.all;return this._hlines.has(r)||(this._count++,this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var b,F,B,M,O,A,N,T,R,k;const{color:r,top_color:n,bottom_color:i,seriesColors:a,hline1:u,hline2:f,plot1:c,plot2:h,...d}=e,{bar_index:p,time:v}=this._variables,x=`fill_${t}`,_=this._fills.get(x),y=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const m=e.display&&!e.display.length?Zt.none:Zt.all;let w,D,C="plot";if(u&&f)w=(b=this._hlines.get(u==null?void 0:u.key))==null?void 0:b.price,D=(F=this._hlines.get(f==null?void 0:f.key))==null?void 0:F.price,C="hline";else{const z=((B=this._plots.get(c==null?void 0:c.key))==null?void 0:B.data)||[],L=((M=this._plots.get(h==null?void 0:h.key))==null?void 0:M.data)||[];w=(A=(O=z[p])==null?void 0:O.value)==null?void 0:A[1],D=(T=(N=L[p])==null?void 0:N.value)==null?void 0:T[1]}if(y[p]={time:v,color:r,top_color:n,bottom_color:i,plot1:w,plot2:D},this._seriesColorHandle(e,["color","top_color","bottom_color"],_),!_){this._count++;const z=((R=this._options.indicator)==null?void 0:R.explicit_plot_zorder)||((k=this._options.strategy)==null?void 0:k.explicit_plot_zorder),L=r?[r]:void 0,G=n?[n]:void 0,H=i?[i]:void 0;this._fills.set(x,{id:x,colors:L,top_colors:G,bottom_colors:H,display:m,data:y,type:C,editable:!0,fillgaps:!1,hline1:u,hline2:f,plot1:c,plot2:h,...d,zIndex:z?this._count:void 0})}}alert({message:e,freq:t=Vr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,u=`alert_${r}`,f=this._cacheData[u].barIndex;if(this._paramVerfiy(t,r,"alert",[Vr.freqAll,Vr.freqOncePerBar,Vr.freqOncePerBarClose]),t===Vr.freqOncePerBar&&n===f){this._alerts.delete(u);return}const c={message:e,freq:t,id:u,type:"alert"};if(i){t!==Vr.freqOncePerBarClose&&this._alerts.set(u,c),this._cacheData[u].barIndex=n;return}if(!i&&t===Vr.freqOncePerBarClose&&n===f&&a===n-1){this._alerts.set(u,c),this._cacheData[u].barIndex=n;return}this._alerts.delete(u)}alertcondition({condition:e,message:t,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&e?this._alerts.set(a,{message:t,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=qf.all,t,r){e.length&&e.length<4&&this._errorListener.addError(or(Kt.displayErr,{func:t,values:"[display.none, display.all]"}),r,Ve.Error)}_setColors(e,t,r){const{color:n,seriesColors:i,...a}=e;this._verifyDisplay(a.display,t,r);const u=e.display&&!e.display.length?Zt.none:Zt.all,{bar_index:f,time:c}=this._variables,h=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const d=this._bgColors[t].get(h),p=(d==null?void 0:d.colors)||[],v=(d==null?void 0:d.setColors)||[];v.includes(n)||v.push(n),p[f]={color:n,time:c},d||this._bgColors[t].set(h,{...a,display:u,colors:p,setColors:v,id:h})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return e===void 0}fixnan({source:e},t){return e===void 0||isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!isNaN(e)?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,e,t,r,n)}time_close({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,e,t,r,n)}timestamp(e){const{dateString:t,timezone:r,year:n,month:i,day:a,hour:u=0,minute:f=0,second:c=0}=e;if(t)return ot(t).utc(!/GMT|UTC/.test(t)).valueOf();let h=i-1,d=n;if(h<0){const v=Math.ceil(Math.abs(h/12));h=12*v+h,d=n-v}let p=ot({year:d,month:h,day:a,hour:u,minute:f,second:c});return r&&(p=Zr(p.utc(!0).valueOf(),r)),p.utc(!0).valueOf()}weekofyear({time:e,timezone:t}){return Zr(e,t).week()}year({time:e,timezone:t}){return Zr(e,t).year()}second({time:e,timezone:t}){return Zr(e,t).second()}month({time:e,timezone:t}){return Zr(e,t).month()+1}minute({time:e,timezone:t}){return Zr(e,t).minute()}hour({time:e,timezone:t}){return Zr(e,t).hour()}dayofweek({time:e,timezone:t}){return Zr(e,t).day()+1}dayofmonth({time:e,timezone:t}){return Zr(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,t),n=pn(t)*1e3;return e-r-Math.floor((e-r)/n)*n}_timeHandle(e,t,r="",n,i,a=0){const u=r||this._variables.timeframe.period,f=pn(u),c=pn(this._variables.timeframe.period);let h;if(f<=c)h=e;else{const d=`time_${t}`,p=this._cacheData[d];if(p)p.currentTime+f*1e3-p.offset<=e?(h=e,this._cacheData[d]={currentTime:e,offset:0}):h=p;else{const v=this._calcTimeOffset(e,u);this._cacheData[d]={currentTime:e,offset:v},h=e}}if(n){const{timePeriods:d,weeks:p}=this._parserSession(n,t),v=ot(e).format("YYYY-MM-DD"),x=h;h=void 0;for(const y of d){const[m,w]=y;if(ot(e).isBetween(`${v} ${m}`,`${v} ${w}`,"hour")){ot(x).isBetween(`${v} ${m}`,`${v} ${w}`,"hour")?h=x:h=ot(`${v} ${m}`).valueOf();break}}const _=this._variables.dayofweek;h&&!p.includes(_)&&(h=void 0)}return i&&(h=h&&Zr(h,i).valueOf()),h&&h-a*c*1e3}_seriesColorHandle(e,t,r){var n;if(r&&t!=null&&t.length)for(const i of t){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=e[i];if(!a)continue;const u=r[`${i}s`]||[];u.includes(a)||(u.push(a),r[`${i}s`]=u,u.length>5&&(r[`${i}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(i)))}}_parserSession(e,t){const r=e.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(f=>{const c=parseInt(f,10);if(c<1||c>7){this._errorListener.addError(`Invalid day of week: ${f}`,t,Ve.Error);return}return c});return{timePeriods:n.split(",").map(f=>{const c=f.split("-");return c.length!==2?(this._errorListener.addError(`Invalid time period: ${f}`,t,Ve.Error),[]):[this._processTime(c[0],t),this._processTime(c[1],t)]}),weeks:a}}_processTime(e,t){const r=parseInt(e.slice(0,2),10),n=parseInt(e.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,Ve.Error);return}return`${r}:${n}`}}var Vf={exports:{}};function $D(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var su={exports:{}},Gf;function Ge(){return Gf||(Gf=1,function(s,e){(function(t,r){s.exports=r()})(ye,function(){var t=t||function(r,n){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof ye<"u"&&ye.crypto&&(i=ye.crypto),!i&&typeof $D=="function")try{i=bx}catch{}var a=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},u=Object.create||function(){function w(){}return function(D){var C;return w.prototype=D,C=new w,w.prototype=null,C}}(),f={},c=f.lib={},h=c.Base=function(){return{extend:function(w){var D=u(this);return w&&D.mixIn(w),(!D.hasOwnProperty("init")||this.init===D.init)&&(D.init=function(){D.$super.init.apply(this,arguments)}),D.init.prototype=D,D.$super=this,D},create:function(){var w=this.extend();return w.init.apply(w,arguments),w},init:function(){},mixIn:function(w){for(var D in w)w.hasOwnProperty(D)&&(this[D]=w[D]);w.hasOwnProperty("toString")&&(this.toString=w.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),d=c.WordArray=h.extend({init:function(w,D){w=this.words=w||[],D!=n?this.sigBytes=D:this.sigBytes=w.length*4},toString:function(w){return(w||v).stringify(this)},concat:function(w){var D=this.words,C=w.words,b=this.sigBytes,F=w.sigBytes;if(this.clamp(),b%4)for(var B=0;B<F;B++){var M=C[B>>>2]>>>24-B%4*8&255;D[b+B>>>2]|=M<<24-(b+B)%4*8}else for(var O=0;O<F;O+=4)D[b+O>>>2]=C[O>>>2];return this.sigBytes+=F,this},clamp:function(){var w=this.words,D=this.sigBytes;w[D>>>2]&=4294967295<<32-D%4*8,w.length=r.ceil(D/4)},clone:function(){var w=h.clone.call(this);return w.words=this.words.slice(0),w},random:function(w){for(var D=[],C=0;C<w;C+=4)D.push(a());return new d.init(D,w)}}),p=f.enc={},v=p.Hex={stringify:function(w){for(var D=w.words,C=w.sigBytes,b=[],F=0;F<C;F++){var B=D[F>>>2]>>>24-F%4*8&255;b.push((B>>>4).toString(16)),b.push((B&15).toString(16))}return b.join("")},parse:function(w){for(var D=w.length,C=[],b=0;b<D;b+=2)C[b>>>3]|=parseInt(w.substr(b,2),16)<<24-b%8*4;return new d.init(C,D/2)}},x=p.Latin1={stringify:function(w){for(var D=w.words,C=w.sigBytes,b=[],F=0;F<C;F++){var B=D[F>>>2]>>>24-F%4*8&255;b.push(String.fromCharCode(B))}return b.join("")},parse:function(w){for(var D=w.length,C=[],b=0;b<D;b++)C[b>>>2]|=(w.charCodeAt(b)&255)<<24-b%4*8;return new d.init(C,D)}},_=p.Utf8={stringify:function(w){try{return decodeURIComponent(escape(x.stringify(w)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(w){return x.parse(unescape(encodeURIComponent(w)))}},y=c.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(w){typeof w=="string"&&(w=_.parse(w)),this._data.concat(w),this._nDataBytes+=w.sigBytes},_process:function(w){var D,C=this._data,b=C.words,F=C.sigBytes,B=this.blockSize,M=B*4,O=F/M;w?O=r.ceil(O):O=r.max((O|0)-this._minBufferSize,0);var A=O*B,N=r.min(A*4,F);if(A){for(var T=0;T<A;T+=B)this._doProcessBlock(b,T);D=b.splice(0,A),C.sigBytes-=N}return new d.init(D,N)},clone:function(){var w=h.clone.call(this);return w._data=this._data.clone(),w},_minBufferSize:0});c.Hasher=y.extend({cfg:h.extend(),init:function(w){this.cfg=this.cfg.extend(w),this.reset()},reset:function(){y.reset.call(this),this._doReset()},update:function(w){return this._append(w),this._process(),this},finalize:function(w){w&&this._append(w);var D=this._doFinalize();return D},blockSize:16,_createHelper:function(w){return function(D,C){return new w.init(C).finalize(D)}},_createHmacHelper:function(w){return function(D,C){return new m.HMAC.init(w,C).finalize(D)}}});var m=f.algo={};return f}(Math);return t})}(su)),su.exports}var ou={exports:{}},Kf;function Bo(){return Kf||(Kf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.Base,u=i.WordArray,f=n.x64={};f.Word=a.extend({init:function(c,h){this.high=c,this.low=h}}),f.WordArray=a.extend({init:function(c,h){c=this.words=c||[],h!=r?this.sigBytes=h:this.sigBytes=c.length*8},toX32:function(){for(var c=this.words,h=c.length,d=[],p=0;p<h;p++){var v=c[p];d.push(v.high),d.push(v.low)}return u.create(d,this.sigBytes)},clone:function(){for(var c=a.clone.call(this),h=c.words=this.words.slice(0),d=h.length,p=0;p<d;p++)h[p]=h[p].clone();return c}})}(),t})}(ou)),ou.exports}var au={exports:{}},Xf;function RD(){return Xf||(Xf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){if(typeof ArrayBuffer=="function"){var r=t,n=r.lib,i=n.WordArray,a=i.init,u=i.init=function(f){if(f instanceof ArrayBuffer&&(f=new Uint8Array(f)),(f instanceof Int8Array||typeof Uint8ClampedArray<"u"&&f instanceof Uint8ClampedArray||f instanceof Int16Array||f instanceof Uint16Array||f instanceof Int32Array||f instanceof Uint32Array||f instanceof Float32Array||f instanceof Float64Array)&&(f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength)),f instanceof Uint8Array){for(var c=f.byteLength,h=[],d=0;d<c;d++)h[d>>>2]|=f[d]<<24-d%4*8;a.call(this,h,c)}else a.apply(this,arguments)};u.prototype=i}}(),t.lib.WordArray})}(au)),au.exports}var uu={exports:{}},Qf;function LD(){return Qf||(Qf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Utf16=a.Utf16BE={stringify:function(f){for(var c=f.words,h=f.sigBytes,d=[],p=0;p<h;p+=2){var v=c[p>>>2]>>>16-p%4*8&65535;d.push(String.fromCharCode(v))}return d.join("")},parse:function(f){for(var c=f.length,h=[],d=0;d<c;d++)h[d>>>1]|=f.charCodeAt(d)<<16-d%2*16;return i.create(h,c*2)}},a.Utf16LE={stringify:function(f){for(var c=f.words,h=f.sigBytes,d=[],p=0;p<h;p+=2){var v=u(c[p>>>2]>>>16-p%4*8&65535);d.push(String.fromCharCode(v))}return d.join("")},parse:function(f){for(var c=f.length,h=[],d=0;d<c;d++)h[d>>>1]|=u(f.charCodeAt(d)<<16-d%2*16);return i.create(h,c*2)}};function u(f){return f<<8&4278255360|f>>>8&16711935}}(),t.enc.Utf16})}(uu)),uu.exports}var lu={exports:{}},Jf;function oi(){return Jf||(Jf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Base64={stringify:function(f){var c=f.words,h=f.sigBytes,d=this._map;f.clamp();for(var p=[],v=0;v<h;v+=3)for(var x=c[v>>>2]>>>24-v%4*8&255,_=c[v+1>>>2]>>>24-(v+1)%4*8&255,y=c[v+2>>>2]>>>24-(v+2)%4*8&255,m=x<<16|_<<8|y,w=0;w<4&&v+w*.75<h;w++)p.push(d.charAt(m>>>6*(3-w)&63));var D=d.charAt(64);if(D)for(;p.length%4;)p.push(D);return p.join("")},parse:function(f){var c=f.length,h=this._map,d=this._reverseMap;if(!d){d=this._reverseMap=[];for(var p=0;p<h.length;p++)d[h.charCodeAt(p)]=p}var v=h.charAt(64);if(v){var x=f.indexOf(v);x!==-1&&(c=x)}return u(f,c,d)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};function u(f,c,h){for(var d=[],p=0,v=0;v<c;v++)if(v%4){var x=h[f.charCodeAt(v-1)]<<v%4*2,_=h[f.charCodeAt(v)]>>>6-v%4*2,y=x|_;d[p>>>2]|=y<<24-p%4*8,p++}return i.create(d,p)}}(),t.enc.Base64})}(lu)),lu.exports}var cu={exports:{}},eh;function PD(){return eh||(eh=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Base64url={stringify:function(f,c){c===void 0&&(c=!0);var h=f.words,d=f.sigBytes,p=c?this._safe_map:this._map;f.clamp();for(var v=[],x=0;x<d;x+=3)for(var _=h[x>>>2]>>>24-x%4*8&255,y=h[x+1>>>2]>>>24-(x+1)%4*8&255,m=h[x+2>>>2]>>>24-(x+2)%4*8&255,w=_<<16|y<<8|m,D=0;D<4&&x+D*.75<d;D++)v.push(p.charAt(w>>>6*(3-D)&63));var C=p.charAt(64);if(C)for(;v.length%4;)v.push(C);return v.join("")},parse:function(f,c){c===void 0&&(c=!0);var h=f.length,d=c?this._safe_map:this._map,p=this._reverseMap;if(!p){p=this._reverseMap=[];for(var v=0;v<d.length;v++)p[d.charCodeAt(v)]=v}var x=d.charAt(64);if(x){var _=f.indexOf(x);_!==-1&&(h=_)}return u(f,h,p)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function u(f,c,h){for(var d=[],p=0,v=0;v<c;v++)if(v%4){var x=h[f.charCodeAt(v-1)]<<v%4*2,_=h[f.charCodeAt(v)]>>>6-v%4*2,y=x|_;d[p>>>2]|=y<<24-p%4*8,p++}return i.create(d,p)}}(),t.enc.Base64url})}(cu)),cu.exports}var fu={exports:{}},th;function ai(){return th||(th=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.algo,c=[];(function(){for(var _=0;_<64;_++)c[_]=r.abs(r.sin(_+1))*4294967296|0})();var h=f.MD5=u.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(_,y){for(var m=0;m<16;m++){var w=y+m,D=_[w];_[w]=(D<<8|D>>>24)&16711935|(D<<24|D>>>8)&4278255360}var C=this._hash.words,b=_[y+0],F=_[y+1],B=_[y+2],M=_[y+3],O=_[y+4],A=_[y+5],N=_[y+6],T=_[y+7],R=_[y+8],k=_[y+9],z=_[y+10],L=_[y+11],G=_[y+12],H=_[y+13],ee=_[y+14],te=_[y+15],j=C[0],X=C[1],Y=C[2],Q=C[3];j=d(j,X,Y,Q,b,7,c[0]),Q=d(Q,j,X,Y,F,12,c[1]),Y=d(Y,Q,j,X,B,17,c[2]),X=d(X,Y,Q,j,M,22,c[3]),j=d(j,X,Y,Q,O,7,c[4]),Q=d(Q,j,X,Y,A,12,c[5]),Y=d(Y,Q,j,X,N,17,c[6]),X=d(X,Y,Q,j,T,22,c[7]),j=d(j,X,Y,Q,R,7,c[8]),Q=d(Q,j,X,Y,k,12,c[9]),Y=d(Y,Q,j,X,z,17,c[10]),X=d(X,Y,Q,j,L,22,c[11]),j=d(j,X,Y,Q,G,7,c[12]),Q=d(Q,j,X,Y,H,12,c[13]),Y=d(Y,Q,j,X,ee,17,c[14]),X=d(X,Y,Q,j,te,22,c[15]),j=p(j,X,Y,Q,F,5,c[16]),Q=p(Q,j,X,Y,N,9,c[17]),Y=p(Y,Q,j,X,L,14,c[18]),X=p(X,Y,Q,j,b,20,c[19]),j=p(j,X,Y,Q,A,5,c[20]),Q=p(Q,j,X,Y,z,9,c[21]),Y=p(Y,Q,j,X,te,14,c[22]),X=p(X,Y,Q,j,O,20,c[23]),j=p(j,X,Y,Q,k,5,c[24]),Q=p(Q,j,X,Y,ee,9,c[25]),Y=p(Y,Q,j,X,M,14,c[26]),X=p(X,Y,Q,j,R,20,c[27]),j=p(j,X,Y,Q,H,5,c[28]),Q=p(Q,j,X,Y,B,9,c[29]),Y=p(Y,Q,j,X,T,14,c[30]),X=p(X,Y,Q,j,G,20,c[31]),j=v(j,X,Y,Q,A,4,c[32]),Q=v(Q,j,X,Y,R,11,c[33]),Y=v(Y,Q,j,X,L,16,c[34]),X=v(X,Y,Q,j,ee,23,c[35]),j=v(j,X,Y,Q,F,4,c[36]),Q=v(Q,j,X,Y,O,11,c[37]),Y=v(Y,Q,j,X,T,16,c[38]),X=v(X,Y,Q,j,z,23,c[39]),j=v(j,X,Y,Q,H,4,c[40]),Q=v(Q,j,X,Y,b,11,c[41]),Y=v(Y,Q,j,X,M,16,c[42]),X=v(X,Y,Q,j,N,23,c[43]),j=v(j,X,Y,Q,k,4,c[44]),Q=v(Q,j,X,Y,G,11,c[45]),Y=v(Y,Q,j,X,te,16,c[46]),X=v(X,Y,Q,j,B,23,c[47]),j=x(j,X,Y,Q,b,6,c[48]),Q=x(Q,j,X,Y,T,10,c[49]),Y=x(Y,Q,j,X,ee,15,c[50]),X=x(X,Y,Q,j,A,21,c[51]),j=x(j,X,Y,Q,G,6,c[52]),Q=x(Q,j,X,Y,M,10,c[53]),Y=x(Y,Q,j,X,z,15,c[54]),X=x(X,Y,Q,j,F,21,c[55]),j=x(j,X,Y,Q,R,6,c[56]),Q=x(Q,j,X,Y,te,10,c[57]),Y=x(Y,Q,j,X,N,15,c[58]),X=x(X,Y,Q,j,H,21,c[59]),j=x(j,X,Y,Q,O,6,c[60]),Q=x(Q,j,X,Y,L,10,c[61]),Y=x(Y,Q,j,X,B,15,c[62]),X=x(X,Y,Q,j,k,21,c[63]),C[0]=C[0]+j|0,C[1]=C[1]+X|0,C[2]=C[2]+Y|0,C[3]=C[3]+Q|0},_doFinalize:function(){var _=this._data,y=_.words,m=this._nDataBytes*8,w=_.sigBytes*8;y[w>>>5]|=128<<24-w%32;var D=r.floor(m/4294967296),C=m;y[(w+64>>>9<<4)+15]=(D<<8|D>>>24)&16711935|(D<<24|D>>>8)&4278255360,y[(w+64>>>9<<4)+14]=(C<<8|C>>>24)&16711935|(C<<24|C>>>8)&4278255360,_.sigBytes=(y.length+1)*4,this._process();for(var b=this._hash,F=b.words,B=0;B<4;B++){var M=F[B];F[B]=(M<<8|M>>>24)&16711935|(M<<24|M>>>8)&4278255360}return b},clone:function(){var _=u.clone.call(this);return _._hash=this._hash.clone(),_}});function d(_,y,m,w,D,C,b){var F=_+(y&m|~y&w)+D+b;return(F<<C|F>>>32-C)+y}function p(_,y,m,w,D,C,b){var F=_+(y&w|m&~w)+D+b;return(F<<C|F>>>32-C)+y}function v(_,y,m,w,D,C,b){var F=_+(y^m^w)+D+b;return(F<<C|F>>>32-C)+y}function x(_,y,m,w,D,C,b){var F=_+(m^(y|~w))+D+b;return(F<<C|F>>>32-C)+y}n.MD5=u._createHelper(h),n.HmacMD5=u._createHmacHelper(h)}(Math),t.MD5})}(fu)),fu.exports}var hu={exports:{}},rh;function nh(){return rh||(rh=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=n.Hasher,u=r.algo,f=[],c=u.SHA1=a.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(h,d){for(var p=this._hash.words,v=p[0],x=p[1],_=p[2],y=p[3],m=p[4],w=0;w<80;w++){if(w<16)f[w]=h[d+w]|0;else{var D=f[w-3]^f[w-8]^f[w-14]^f[w-16];f[w]=D<<1|D>>>31}var C=(v<<5|v>>>27)+m+f[w];w<20?C+=(x&_|~x&y)+1518500249:w<40?C+=(x^_^y)+1859775393:w<60?C+=(x&_|x&y|_&y)-1894007588:C+=(x^_^y)-899497514,m=y,y=_,_=x<<30|x>>>2,x=v,v=C}p[0]=p[0]+v|0,p[1]=p[1]+x|0,p[2]=p[2]+_|0,p[3]=p[3]+y|0,p[4]=p[4]+m|0},_doFinalize:function(){var h=this._data,d=h.words,p=this._nDataBytes*8,v=h.sigBytes*8;return d[v>>>5]|=128<<24-v%32,d[(v+64>>>9<<4)+14]=Math.floor(p/4294967296),d[(v+64>>>9<<4)+15]=p,h.sigBytes=d.length*4,this._process(),this._hash},clone:function(){var h=a.clone.call(this);return h._hash=this._hash.clone(),h}});r.SHA1=a._createHelper(c),r.HmacSHA1=a._createHmacHelper(c)}(),t.SHA1})}(hu)),hu.exports}var du={exports:{}},ih;function pu(){return ih||(ih=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.algo,c=[],h=[];(function(){function v(m){for(var w=r.sqrt(m),D=2;D<=w;D++)if(!(m%D))return!1;return!0}function x(m){return(m-(m|0))*4294967296|0}for(var _=2,y=0;y<64;)v(_)&&(y<8&&(c[y]=x(r.pow(_,1/2))),h[y]=x(r.pow(_,1/3)),y++),_++})();var d=[],p=f.SHA256=u.extend({_doReset:function(){this._hash=new a.init(c.slice(0))},_doProcessBlock:function(v,x){for(var _=this._hash.words,y=_[0],m=_[1],w=_[2],D=_[3],C=_[4],b=_[5],F=_[6],B=_[7],M=0;M<64;M++){if(M<16)d[M]=v[x+M]|0;else{var O=d[M-15],A=(O<<25|O>>>7)^(O<<14|O>>>18)^O>>>3,N=d[M-2],T=(N<<15|N>>>17)^(N<<13|N>>>19)^N>>>10;d[M]=A+d[M-7]+T+d[M-16]}var R=C&b^~C&F,k=y&m^y&w^m&w,z=(y<<30|y>>>2)^(y<<19|y>>>13)^(y<<10|y>>>22),L=(C<<26|C>>>6)^(C<<21|C>>>11)^(C<<7|C>>>25),G=B+L+R+h[M]+d[M],H=z+k;B=F,F=b,b=C,C=D+G|0,D=w,w=m,m=y,y=G+H|0}_[0]=_[0]+y|0,_[1]=_[1]+m|0,_[2]=_[2]+w|0,_[3]=_[3]+D|0,_[4]=_[4]+C|0,_[5]=_[5]+b|0,_[6]=_[6]+F|0,_[7]=_[7]+B|0},_doFinalize:function(){var v=this._data,x=v.words,_=this._nDataBytes*8,y=v.sigBytes*8;return x[y>>>5]|=128<<24-y%32,x[(y+64>>>9<<4)+14]=r.floor(_/4294967296),x[(y+64>>>9<<4)+15]=_,v.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var v=u.clone.call(this);return v._hash=this._hash.clone(),v}});n.SHA256=u._createHelper(p),n.HmacSHA256=u._createHmacHelper(p)}(Math),t.SHA256})}(du)),du.exports}var _u={exports:{}},sh;function kD(){return sh||(sh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),pu())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.algo,u=a.SHA256,f=a.SHA224=u.extend({_doReset:function(){this._hash=new i.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var c=u._doFinalize.call(this);return c.sigBytes-=4,c}});r.SHA224=u._createHelper(f),r.HmacSHA224=u._createHmacHelper(f)}(),t.SHA224})}(_u)),_u.exports}var vu={exports:{}},oh;function ah(){return oh||(oh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.Hasher,a=r.x64,u=a.Word,f=a.WordArray,c=r.algo;function h(){return u.create.apply(u,arguments)}var d=[h(1116352408,3609767458),h(1899447441,602891725),h(3049323471,3964484399),h(3921009573,2173295548),h(961987163,4081628472),h(1508970993,3053834265),h(2453635748,2937671579),h(2870763221,3664609560),h(3624381080,2734883394),h(310598401,1164996542),h(607225278,1323610764),h(1426881987,3590304994),h(1925078388,4068182383),h(2162078206,991336113),h(2614888103,633803317),h(3248222580,3479774868),h(3835390401,2666613458),h(4022224774,944711139),h(264347078,2341262773),h(604807628,2007800933),h(770255983,1495990901),h(1249150122,1856431235),h(1555081692,3175218132),h(1996064986,2198950837),h(2554220882,3999719339),h(2821834349,766784016),h(2952996808,2566594879),h(3210313671,3203337956),h(3336571891,1034457026),h(3584528711,2466948901),h(113926993,3758326383),h(338241895,168717936),h(666307205,1188179964),h(773529912,1546045734),h(1294757372,1522805485),h(1396182291,2643833823),h(1695183700,2343527390),h(1986661051,1014477480),h(2177026350,1206759142),h(2456956037,344077627),h(2730485921,1290863460),h(2820302411,3158454273),h(3259730800,3505952657),h(3345764771,106217008),h(3516065817,3606008344),h(3600352804,1432725776),h(4094571909,1467031594),h(275423344,851169720),h(430227734,3100823752),h(506948616,1363258195),h(659060556,3750685593),h(883997877,3785050280),h(958139571,3318307427),h(1322822218,3812723403),h(1537002063,2003034995),h(1747873779,3602036899),h(1955562222,1575990012),h(2024104815,1125592928),h(2227730452,2716904306),h(2361852424,442776044),h(2428436474,593698344),h(2756734187,3733110249),h(3204031479,2999351573),h(3329325298,3815920427),h(3391569614,3928383900),h(3515267271,566280711),h(3940187606,3454069534),h(4118630271,4000239992),h(116418474,1914138554),h(174292421,2731055270),h(289380356,3203993006),h(460393269,320620315),h(685471733,587496836),h(852142971,1086792851),h(1017036298,365543100),h(1126000580,2618297676),h(1288033470,3409855158),h(1501505948,4234509866),h(1607167915,987167468),h(1816402316,1246189591)],p=[];(function(){for(var x=0;x<80;x++)p[x]=h()})();var v=c.SHA512=i.extend({_doReset:function(){this._hash=new f.init([new u.init(1779033703,4089235720),new u.init(3144134277,2227873595),new u.init(1013904242,4271175723),new u.init(2773480762,1595750129),new u.init(1359893119,2917565137),new u.init(2600822924,725511199),new u.init(528734635,4215389547),new u.init(1541459225,327033209)])},_doProcessBlock:function(x,_){for(var y=this._hash.words,m=y[0],w=y[1],D=y[2],C=y[3],b=y[4],F=y[5],B=y[6],M=y[7],O=m.high,A=m.low,N=w.high,T=w.low,R=D.high,k=D.low,z=C.high,L=C.low,G=b.high,H=b.low,ee=F.high,te=F.low,j=B.high,X=B.low,Y=M.high,Q=M.low,pe=O,De=A,we=N,be=T,Oe=R,Fe=k,nt=z,Ye=L,Te=G,Re=H,xt=ee,Ut=te,Et=j,lr=X,Lr=Y,cr=Q,yt=0;yt<80;yt++){var Ot,P,V=p[yt];if(yt<16)P=V.high=x[_+yt*2]|0,Ot=V.low=x[_+yt*2+1]|0;else{var J=p[yt-15],ie=J.high,ue=J.low,se=(ie>>>1|ue<<31)^(ie>>>8|ue<<24)^ie>>>7,_e=(ue>>>1|ie<<31)^(ue>>>8|ie<<24)^(ue>>>7|ie<<25),he=p[yt-2],de=he.high,fe=he.low,Xe=(de>>>19|fe<<13)^(de<<3|fe>>>29)^de>>>6,et=(fe>>>19|de<<13)^(fe<<3|de>>>29)^(fe>>>6|de<<26),ht=p[yt-7],kt=ht.high,Tt=ht.low,rr=p[yt-16],fr=rr.high,en=rr.low;Ot=_e+Tt,P=se+kt+(Ot>>>0<_e>>>0?1:0),Ot=Ot+et,P=P+Xe+(Ot>>>0<et>>>0?1:0),Ot=Ot+en,P=P+fr+(Ot>>>0<en>>>0?1:0),V.high=P,V.low=Ot}var Dn=Te&xt^~Te&Et,li=Re&Ut^~Re&lr,vs=pe&we^pe&Oe^we&Oe,gs=De&be^De&Fe^be&Fe,ms=(pe>>>28|De<<4)^(pe<<30|De>>>2)^(pe<<25|De>>>7),Li=(De>>>28|pe<<4)^(De<<30|pe>>>2)^(De<<25|pe>>>7),Pi=(Te>>>14|Re<<18)^(Te>>>18|Re<<14)^(Te<<23|Re>>>9),xs=(Re>>>14|Te<<18)^(Re>>>18|Te<<14)^(Re<<23|Te>>>9),ki=d[yt],ys=ki.high,zn=ki.low,Xt=cr+xs,mr=Lr+Pi+(Xt>>>0<cr>>>0?1:0),Xt=Xt+li,mr=mr+Dn+(Xt>>>0<li>>>0?1:0),Xt=Xt+zn,mr=mr+ys+(Xt>>>0<zn>>>0?1:0),Xt=Xt+Ot,mr=mr+P+(Xt>>>0<Ot>>>0?1:0),zi=Li+gs,Ds=ms+vs+(zi>>>0<Li>>>0?1:0);Lr=Et,cr=lr,Et=xt,lr=Ut,xt=Te,Ut=Re,Re=Ye+Xt|0,Te=nt+mr+(Re>>>0<Ye>>>0?1:0)|0,nt=Oe,Ye=Fe,Oe=we,Fe=be,we=pe,be=De,De=Xt+zi|0,pe=mr+Ds+(De>>>0<Xt>>>0?1:0)|0}A=m.low=A+De,m.high=O+pe+(A>>>0<De>>>0?1:0),T=w.low=T+be,w.high=N+we+(T>>>0<be>>>0?1:0),k=D.low=k+Fe,D.high=R+Oe+(k>>>0<Fe>>>0?1:0),L=C.low=L+Ye,C.high=z+nt+(L>>>0<Ye>>>0?1:0),H=b.low=H+Re,b.high=G+Te+(H>>>0<Re>>>0?1:0),te=F.low=te+Ut,F.high=ee+xt+(te>>>0<Ut>>>0?1:0),X=B.low=X+lr,B.high=j+Et+(X>>>0<lr>>>0?1:0),Q=M.low=Q+cr,M.high=Y+Lr+(Q>>>0<cr>>>0?1:0)},_doFinalize:function(){var x=this._data,_=x.words,y=this._nDataBytes*8,m=x.sigBytes*8;_[m>>>5]|=128<<24-m%32,_[(m+128>>>10<<5)+30]=Math.floor(y/4294967296),_[(m+128>>>10<<5)+31]=y,x.sigBytes=_.length*4,this._process();var w=this._hash.toX32();return w},clone:function(){var x=i.clone.call(this);return x._hash=this._hash.clone(),x},blockSize:1024/32});r.SHA512=i._createHelper(v),r.HmacSHA512=i._createHmacHelper(v)}(),t.SHA512})}(vu)),vu.exports}var gu={exports:{}},uh;function zD(){return uh||(uh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo(),ah())})(ye,function(t){return function(){var r=t,n=r.x64,i=n.Word,a=n.WordArray,u=r.algo,f=u.SHA512,c=u.SHA384=f.extend({_doReset:function(){this._hash=new a.init([new i.init(3418070365,3238371032),new i.init(1654270250,914150663),new i.init(2438529370,812702999),new i.init(355462360,4144912697),new i.init(1731405415,4290775857),new i.init(2394180231,1750603025),new i.init(3675008525,1694076839),new i.init(1203062813,3204075428)])},_doFinalize:function(){var h=f._doFinalize.call(this);return h.sigBytes-=16,h}});r.SHA384=f._createHelper(c),r.HmacSHA384=f._createHmacHelper(c)}(),t.SHA384})}(gu)),gu.exports}var mu={exports:{}},lh;function qD(){return lh||(lh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.x64,c=f.Word,h=n.algo,d=[],p=[],v=[];(function(){for(var y=1,m=0,w=0;w<24;w++){d[y+5*m]=(w+1)*(w+2)/2%64;var D=m%5,C=(2*y+3*m)%5;y=D,m=C}for(var y=0;y<5;y++)for(var m=0;m<5;m++)p[y+5*m]=m+(2*y+3*m)%5*5;for(var b=1,F=0;F<24;F++){for(var B=0,M=0,O=0;O<7;O++){if(b&1){var A=(1<<O)-1;A<32?M^=1<<A:B^=1<<A-32}b&128?b=b<<1^113:b<<=1}v[F]=c.create(B,M)}})();var x=[];(function(){for(var y=0;y<25;y++)x[y]=c.create()})();var _=h.SHA3=u.extend({cfg:u.cfg.extend({outputLength:512}),_doReset:function(){for(var y=this._state=[],m=0;m<25;m++)y[m]=new c.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(y,m){for(var w=this._state,D=this.blockSize/2,C=0;C<D;C++){var b=y[m+2*C],F=y[m+2*C+1];b=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360,F=(F<<8|F>>>24)&16711935|(F<<24|F>>>8)&4278255360;var B=w[C];B.high^=F,B.low^=b}for(var M=0;M<24;M++){for(var O=0;O<5;O++){for(var A=0,N=0,T=0;T<5;T++){var B=w[O+5*T];A^=B.high,N^=B.low}var R=x[O];R.high=A,R.low=N}for(var O=0;O<5;O++)for(var k=x[(O+4)%5],z=x[(O+1)%5],L=z.high,G=z.low,A=k.high^(L<<1|G>>>31),N=k.low^(G<<1|L>>>31),T=0;T<5;T++){var B=w[O+5*T];B.high^=A,B.low^=N}for(var H=1;H<25;H++){var A,N,B=w[H],ee=B.high,te=B.low,j=d[H];j<32?(A=ee<<j|te>>>32-j,N=te<<j|ee>>>32-j):(A=te<<j-32|ee>>>64-j,N=ee<<j-32|te>>>64-j);var X=x[p[H]];X.high=A,X.low=N}var Y=x[0],Q=w[0];Y.high=Q.high,Y.low=Q.low;for(var O=0;O<5;O++)for(var T=0;T<5;T++){var H=O+5*T,B=w[H],pe=x[H],De=x[(O+1)%5+5*T],we=x[(O+2)%5+5*T];B.high=pe.high^~De.high&we.high,B.low=pe.low^~De.low&we.low}var B=w[0],be=v[M];B.high^=be.high,B.low^=be.low}},_doFinalize:function(){var y=this._data,m=y.words;this._nDataBytes*8;var w=y.sigBytes*8,D=this.blockSize*32;m[w>>>5]|=1<<24-w%32,m[(r.ceil((w+1)/D)*D>>>5)-1]|=128,y.sigBytes=m.length*4,this._process();for(var C=this._state,b=this.cfg.outputLength/8,F=b/8,B=[],M=0;M<F;M++){var O=C[M],A=O.high,N=O.low;A=(A<<8|A>>>24)&16711935|(A<<24|A>>>8)&4278255360,N=(N<<8|N>>>24)&16711935|(N<<24|N>>>8)&4278255360,B.push(N),B.push(A)}return new a.init(B,b)},clone:function(){for(var y=u.clone.call(this),m=y._state=this._state.slice(0),w=0;w<25;w++)m[w]=m[w].clone();return y}});n.SHA3=u._createHelper(_),n.HmacSHA3=u._createHmacHelper(_)}(Math),t.SHA3})}(mu)),mu.exports}var xu={exports:{}},ch;function UD(){return ch||(ch=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){/** @preserve
62
+ `)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t))}_arrToStr(e,t){return`[${e.map(n=>typeof n=="number"?this._toStringFormat(n,t):n).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return me(t)&&(t=0),me(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return me(e)&&(e=0),Zr(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return e;switch(t){case Je.mintick:return e.toFixed(this._precision);case Je.price:return`${e}%`;case Je.volume:return this._intlNumberFormatter.format(Math.round(e));default:const[r,n]=t.split(".");let[i,a=""]=String(e).split(".");if(r.includes("#")?i=r.replace(/#/,i).replace(/#/g,""):i=`${r}${i}`,n&&n.includes("#")){const u=n.split("#").length-1;a=`${a.substring(0,u)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${i}.${a}`:i}}_formatNumber(e,t){if(!t)return e;switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:const r=t.split(".")[1],n=r?r.length:0;return parseFloat(e.toFixed(n))}}_strFormat(e,t){let r=e;return t.forEach((n,i)=>{if(typeof n=="number"){const a=`\\{\\s*${i}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,u=e.match(new RegExp(a));if(u){const f=u[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,f)))}else r=r.replace(new RegExp(`\\{${i}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${i}\\}`,"g"),n)}),r}}class Xy{constructor(e){U(this,"_errorListener");this._errorListener=e}new(){return new nu(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class nu{constructor(e){U(this,"_errorListener");U(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}_copyMap(e){const t=new nu(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new it(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new it(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class Qy{constructor(e){U(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new si(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new si(e,r,t)}copy({id:e}){const{price:t,time:r,index:n}=e||{};return new si(t,n,r)}from_index({price:e,index:t}){return new si(e,t)}from_time({price:e,time:t}){return new si(e,void 0,t)}}class si{constructor(e,t,r){U(this,"_index");U(this,"_price");U(this,"_time");this._index=t,this._price=e,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new si(this._price,this._index,this._time)}}class Jy{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultLabel",{text:"",xloc:wt.bar_index,yloc:Kr.price,size:ar.normal,style:vt.styleLabelDown,textalign:je.alignCenter});this._variables=e,this._errorListener=t}new(e,t){const{time:r,high:n,low:i,bar_index:a}=this._variables,u=`label_${t}_${a}`,f={...this._defaultLabel,...e,id:u,time:r};e.point&&(f.x=f.xloc===wt.bar_index?e.point.index:e.point.time,f.y=e.point.price),f.yloc===Kr.abovebar?f.y=n:f.yloc===Kr.belowbar&&(f.y=i),this._verfiyArgs(e,t);const c=new hs(u,this._variables,this._errorListener);return t.startsWith("export")||this._variables.label.add(u,f,c),c}_verfiyArgs(e,t){const{xloc:r,yloc:n,style:i,size:a,textalign:u,text_font_family:f}=e,c="label.new";this._paramVerfiy(i,t,c,Object.values(vt),"style"),this._paramVerfiy(r,t,c,Object.values(wt),"xloc"),this._paramVerfiy(n,t,c,Object.values(Kr),"yloc"),this._paramVerfiy(a,t,c,Object.values(ar),"size"),this._paramVerfiy(u,t,c,[je.alignLeft,je.alignCenter,je.alignRight],"textalign"),this._paramVerfiy(f,t,c,Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}label(e,t){return e.x?e.x:new hs(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e}){e==null||e.delete()}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class hs{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}copy(e){const t=`label_${e}_${this._variables.bar_index}`,r=this._getLabel(e),n=new hs(t,this._variables,this._errorListener);if(r){const i={...r,id:t};this._variables.label.add(t,i,n)}return n}get_x(e){var t;return(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){const r=this._getLabel(t);r&&(r.x=e)}set_y({y:e},t){const r=this._getLabel(t);r&&(r.y=e)}delete(){this._variables.label.delete(this._id)}set_xy({x:e,y:t},r){const n=this._getLabel(r);n&&(n.x=e,n.y=t)}get_text(e){var t;return(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(ar),"size")}set_text({text:e},t){const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){const n=this._getLabel(r);n&&(n.x=e,n.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(wt),"xloc"))}set_yloc({yloc:e},t){const r=this._getLabel(t),{high:n,low:i}=this._variables;r&&(r.yloc=e,e===Kr.abovebar?r.y=n:e===Kr.belowbar&&(r.y=i),this._paramVerfiy(e,t,"label.set_yloc",Object.values(Kr),"yloc"))}set_color({color:e},t){const r=this._getLabel(t);r&&(r.color=e)}set_point({point:e},t){const r=this._getLabel(t);r&&(r.x=r.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(vt),"style")}set_tooltip({tooltip:e},t){const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[je.alignLeft,je.alignCenter,je.alignRight],"textalign")}set_textcolor({textcolor:e},t){const r=this._getLabel(t);r&&(r.textcolor=e)}set_text_font_family({text_font_family:e},t){const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getLabel(e){const t=this._variables.label.get(this._id);return t||console.log(`错误${e}: label 不存在`),t}}const eD={freq_all:Vr.freqAll,freq_once_per_bar:Vr.freqOncePerBar,freq_once_per_bar_close:Vr.freqOncePerBarClose},tD={gaps_off:ns.gapsOff,gaps_on:ns.gapsOn,lookahead_off:ns.lookaheadOff,lookahead_on:ns.lookaheadOn},Ti={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},zf={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},rD={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},qf={all:[Zt.dataWindow,Zt.pane,Zt.priceScale,Zt.statusLine],data_window:[Zt.dataWindow],none:[],pane:[Zt.pane],price_scale:[Zt.priceScale],status_line:[Zt.statusLine]},nD={both:Gr.both,left:Gr.left,none:Gr.none,right:Gr.right},iD={inherit:Je.inherit,mintick:Je.mintick,percent:Je.percent,price:Je.price,volume:Je.volume},sD={style_solid:ks.styleSolid,style_dashed:ks.styleDashed,style_dotted:ks.styleDotted},oD={style_arrowdown:vt.styleArrowdown,style_arrowup:vt.styleArrowup,style_circle:vt.styleCircle,style_cross:vt.styleCross,style_diamond:vt.styleDiamond,style_flag:vt.styleFlag,style_label_center:vt.styleLabelCenter,style_label_down:vt.styleLabelDown,style_label_left:vt.styleLabelLeft,style_label_lower_left:vt.styleLabelLowerLeft,style_label_lower_right:vt.styleLabelLowerRight,style_label_right:vt.styleLabelRight,style_label_up:vt.styleLabelUp,style_label_upper_left:vt.styleLabelUpperLeft,style_label_upper_right:vt.styleLabelUpperRight,style_none:vt.styleNone,style_square:vt.styleSquare,style_text_outline:vt.styleTextOutline,style_triangledown:vt.styleTriangledown,style_triangleup:vt.styleTriangleup,style_xcross:vt.styleXcross},aD={style_arrow_both:zt.styleArrowBoth,style_arrow_left:zt.styleArrowLeft,style_arrow_right:zt.styleArrowRight,style_dashed:zt.styleDashed,style_dotted:zt.styleDotted,style_solid:zt.styleSolid},uD={abovebar:_n.abovebar,absolute:_n.absolute,belowbar:_n.belowbar,bottom:_n.bottom,top:_n.top},lD={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},cD={style_area:Or.styleArea,style_areabr:Or.styleAreabr,style_circles:Or.styleCircles,style_columns:Or.styleColumns,style_cross:Or.styleCross,style_histogram:Or.styleHistogram,style_line:Or.styleLine,style_linebr:Or.styleLinebr,style_stepline:Or.styleStepline,style_stepline_diamond:Or.styleSteplineDiamond,style_steplinebr:Or.styleSteplinebr},fD={bottom_center:br.bottomCenter,bottom_left:br.bottomLeft,bottom_right:br.bottomRight,middle_center:br.middleCenter,middle_left:br.middleLeft,middle_right:br.middleRight,top_center:br.topCenter,top_left:br.topLeft,top_right:br.topRight},hD={left:zs.left,none:zs.none,right:zs.right},dD={arrowdown:_r.arrowdown,arrowup:_r.arrowup,circle:_r.circle,cross:_r.cross,diamond:_r.diamond,flag:_r.flag,labeldown:_r.labeldown,labelup:_r.labelup,square:_r.square,triangledown:_r.triangledown,triangleup:_r.triangleup,xcross:_r.xcross},pD={auto:ar.auto,huge:ar.huge,large:ar.large,normal:ar.normal,small:ar.small,tiny:ar.tiny},_D={cash:Rt.cash,fixed:Rt.fixed,percent_of_equity:Rt.percentOfEquity,commission:{cash_per_contract:Tr.cashPerContract,cash_per_order:Tr.cashPerOrder,percent:Tr.percent},direction:{all:gt.all,long:gt.long,short:gt.short},oca:{cancel:vn.cancel,none:vn.none,reduce:vn.reduce}},vD={align_bottom:je.alignBottom,align_center:je.alignCenter,align_left:je.alignLeft,align_right:je.alignRight,align_top:je.alignTop,wrap_auto:je.wrapAuto,wrap_none:je.wrapNone},gD={bar_index:wt.bar_index,bar_time:wt.bar_time},mD={abovebar:Kr.abovebar,belowbar:Kr.belowbar,price:Kr.price},xD={actual:Us.actual,estimate:Us.estimate,standardized:Us.standardized};class Uf{constructor(){U(this,"adjustment",{dividends:Ps.dividends,none:Ps.none,splits:Ps.splits});U(this,"alert",eD);U(this,"barmerge",tD);U(this,"color",Ti);U(this,"currency",zf);U(this,"dayofweek",rD);U(this,"earnings",xD);U(this,"display",qf);U(this,"extend",nD);U(this,"font",{family_default:Jn.familyDefault,family_monospace:Jn.familyMonospace});U(this,"format",iD);U(this,"hline",sD);U(this,"label",oD);U(this,"line",aD);U(this,"location",uD);U(this,"math",lD);U(this,"order",{ascending:Qn.ascending,descending:Qn.descending});U(this,"plot",cD);U(this,"position",fD);U(this,"scale",hD);U(this,"session",{extended:qs.extended,regular:qs.regular});U(this,"shape",dD);U(this,"size",pD);U(this,"splits",{denominator:"denominator",numerator:"numerator"});U(this,"strategy",_D);U(this,"text",vD);U(this,"xloc",gD);U(this,"yloc",mD)}updateData(){}}class yD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:wt.bar_index,line_color:Ti.blue,line_style:zt.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var a;const r=`polyline_${t}_${this._variables.bar_index}`,n=Object.assign({},this._defaultPolyline,e,{id:r,points:(a=e.points)==null?void 0:a._value.map(u=>({time:u.time,index:u.index,price:u.price}))}),i=new Wf(r,this._variables);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(r,n,i),i}_verfiyArgs(e,t){const{line_style:r,xloc:n}=e,i="polyline.new";this._paramVerfiy(r,t,i,Object.values(zt),"line_style"),this._paramVerfiy(n,t,i,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}delete({id:e}){e&&e.delete()}}class Wf{constructor(e,t){U(this,"_id");U(this,"_variables");this._variables=t,this._id=e}delete(){this._variables.polyline.delete(this._id)}}class DD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultLine",{xloc:wt.bar_index,extend:Gr.none,style:zt.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},n){const i=`line_${n}_${this._variables.bar_index}`,a={...this._defaultLine,...r,id:i};if(e&&t){const f=a.xloc===wt.bar_index?e.index:e.time,c=a.xloc===wt.bar_index?t.index:t.time;Object.assign(a,{x1:f,y1:e.price,x2:c,y2:t.price})}this._verfiyArgs(r,n);const u=new ds(i,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(i,a,u),u}_verfiyArgs(e,t){const{extend:r,xloc:n,style:i}=e,a="line.new";this._paramVerfiy(i,t,a,Object.values(zt),"style"),this._paramVerfiy(r,t,a,Object.values(Gr),"extend"),this._paramVerfiy(n,t,a,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}line(e,t){return e.x?e.x:new ds(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class ds{constructor(e,t,r){U(this,"_variables");U(this,"_id");U(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}get data(){return this._variables.line.get(this._id)}copy(e){const t=`line_${e}_${this._variables.bar_index}`,r=this._getLine(e),n=new ds(t,this._variables,this._errorListener);return r&&this._variables.line.add(t,{...r,id:t},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:e},t){const r=this._getLine(t);if(e===void 0)return e;if(r&&r.xloc===wt.bar_index){const{x1:n,y1:i,x2:a,y2:u}=r;return n===void 0||a===void 0||i===void 0||u===void 0?void 0:(u-i)/(a-n)*(e-n)+i}}get_x1(e){var t;return(t=this._getLine(e))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t);r&&(r.x1=e)}set_x2({x:e},t){const r=this._getLine(t);r&&(r.x2=e)}set_y1({y:e},t){const r=this._getLine(t);r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t);r&&(r.y2=e)}set_xy1({x:e,y:t},r){const n=this._getLine(r);n&&(n.x1=e,n.y1=t)}set_xy2({x:e,y:t},r){const n=this._getLine(r);n&&(n.x2=e,n.y2=t)}set_xloc({xloc:e,x1:t,x2:r},n){const i=this._getLine(n);i&&(i.xloc=e,i.x1=t,i.x2=r,this._paramVerfiy(e,n,"line.set_xloc",Object.values(wt),"xloc"))}set_color({color:e},t){const r=this._getLine(t);r&&(r.color=e)}set_style({style:e},t){const r=this._getLine(t);r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(zt),"style"))}set_width({width:e},t){const r=this._getLine(t);r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t);r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(Gr),"extend"))}set_first_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},u=r.xloc===wt.bar_index?n:i,f=a;u&&(r.x1=u),f&&(r.y1=f)}}set_second_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},u=r.xloc===wt.bar_index?n:i,f=a;u&&(r.x2=u),f&&(r.y2=f)}}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getLine(e){const t=this._variables.line.get(this._id);return t||console.log(`${e}: line 不存在`),t}}class wD{constructor(e){U(this,"_variables");this._variables=e}new({line1:e,line2:t,color:r},n){const i=`linefill_${n}_${this._variables.bar_index}`,a=e==null?void 0:e.data,u=t==null?void 0:t.data;a&&(a.linefills=a.linefills||[],a.linefills.push(i)),u&&(u.linefills=u.linefills||[],u.linefills.push(i));const f=new Fo(this._variables,i,e,t);return n.startsWith("export")||(a||u)&&this._variables.linefill.add(i,{line1:a,line2:u,color:r,id:i},f),f}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class Fo{constructor(e,t,r,n){U(this,"_id");U(this,"_line1");U(this,"_line2");U(this,"_variables");this._variables=e,this._id=t,this._line1=r,this._line2=n}linefill(e,t){return e.x?e.x:new Fo(this._variables,t)}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:n,line2:i}=e;n&&(n.linefills=(t=n.linefills)==null?void 0:t.filter(a=>a!==this._id)),i&&(i.linefills=(r=i.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color({color:e}){const t=this._variables.linefill.get(this._id);t&&(t.color=e)}}class bD{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultBox",{border_color:Ti.blue,border_width:1,bgcolor:Ti.blue,xloc:wt.bar_index,extend:Gr.none,style:zt.styleSolid,text:"",text_size:ar.auto,text_color:Ti.black,text_halign:je.alignCenter,text_valign:je.alignCenter,text_wrap:je.wrapNone});this._variables=e,this._errorListener=t}box({x:e},t){return e===void 0?new ps(this._variables,t,this._errorListener):e}new({top_left:e,bottom_right:t,...r},n){const i=`box_${n}_${this._variables.bar_index}`,a={...this._defaultBox,...r,id:i};if(e){const{price:f,time:c,index:h}=e;a.top=f,a.left=a.xloc===wt.bar_index?h:c}if(t){const{price:f,time:c,index:h}=t;a.bottom=f,a.right=a.xloc===wt.bar_index?h:c}this._verfiyArgs(r,n);const u=new ps(this._variables,i,this._errorListener);return n.startsWith("export")||this._variables.box.add(i,a,u),u}_verfiyArgs(e,t){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:u,text_valign:f,text_wrap:c,text_font_family:h}=e,d="box.new";this._paramVerfiy(r,t,d,[zt.styleDashed,zt.styleDotted,zt.styleSolid],"border_style"),this._paramVerfiy(n,t,d,Object.values(Gr),"extend"),this._paramVerfiy(i,t,d,Object.values(wt),"xloc"),this._paramVerfiy(a,t,d,Object.values(ar),"text_size"),this._paramVerfiy(u,t,d,[je.alignLeft,je.alignCenter,je.alignRight],"text_halign"),this._paramVerfiy(f,t,d,[je.alignBottom,je.alignCenter,je.alignTop],"text_valign"),this._paramVerfiy(c,t,d,[je.wrapAuto,je.wrapNone],"text_wrap"),this._paramVerfiy(h,t,d,Object.values(Jn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_top({id:e}){return e==null?void 0:e.get_top()}get_bottom({id:e}){return e==null?void 0:e.get_bottom()}get_left({id:e}){return e==null?void 0:e.get_left()}get_right({id:e}){return e==null?void 0:e.get_right()}set_top({id:e,...t}){e==null||e.set_top(t)}set_bottom({id:e,...t}){e==null||e.set_bottom(t)}set_left({id:e,...t}){e==null||e.set_left(t)}set_right({id:e,...t}){e==null||e.set_right(t)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({id:e,...t}){e==null||e.set_border_color(t)}set_border_width({id:e,...t}){e==null||e.set_border_width(t)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t}){e==null||e.set_lefttop(t)}set_rightbottom({id:e,...t}){e==null||e.set_rightbottom(t)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t}){e==null||e.set_text_color(t)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t}){e==null||e.set_top_left_point(t)}set_bottom_right_point({id:e,...t}){e==null||e.set_bottom_right_point(t)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ps{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");this._variables=e,this._id=t,this._errorListener=r}copy(e){const t=`box_${e}_${this._variables.bar_index}`,r=this._getBox(),n=new ps(this._variables,t,this._errorListener);return r&&this._variables.box.add(t,{...r,id:t},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const e=this._getBox();return e&&e.top}set_top({top:e}){const t=this._getBox();t&&(t.top=e)}get_left(){const e=this._getBox();return e&&e.left}set_left({left:e}){const t=this._getBox();t&&(t.left=e)}set_text({text:e}){const t=this._getBox();t&&(t.text=e)}get_right(){const e=this._getBox();return e&&e.right}set_right({right:e}){const t=this._getBox();t&&(t.right=e)}get_bottom(){const e=this._getBox();return e&&e.bottom}set_bottom({bottom:e}){const t=this._getBox();t&&(t.bottom=e)}set_extend({extend:e},t){const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(Gr),"extend"))}set_bgcolor({color:e}){const t=this._getBox();t&&(t.bgcolor=e)}set_lefttop({left:e,top:t}){const r=this._getBox();r&&(r.left=e,r.top=t)}set_text_size({text_size:e},t){const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(ar),"text_size"))}set_text_wrap({text_wrap:e},t){const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[je.wrapAuto,je.wrapNone],"text_wrap"))}set_text_color({text_color:e}){const t=this._getBox();t&&(t.text_color=e)}set_rightbottom({right:e,bottom:t}){const r=this._getBox();r&&(r.right=e,r.bottom=t)}set_text_halign({text_halign:e},t){const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[je.alignLeft,je.alignCenter,je.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[je.alignBottom,je.alignCenter,je.alignTop],"text_valign"))}set_top_left_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.top=n,t.left=t.xloc===wt.bar_index?r:i}}set_border_color({color:e}){const t=this._getBox();t&&(t.border_color=e)}set_border_style({style:e},t){const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[zt.styleDashed,zt.styleDotted,zt.styleSolid],"style"))}set_border_width({width:e}){const t=this._getBox();t&&(t.border_width=e)}set_bottom_right_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.bottom=n,t.right=t.xloc===wt.bar_index?r:i}}set_text_font_family({text_font_family:e},t){const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(Jn),"text_font_family"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getBox(){return this._variables.box.get(this._id)}}class ED{constructor(e,t){U(this,"_variables");U(this,"_errorListener");U(this,"_defaultTable",{position:br.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e},t){return e||new iu(this._variables,t,this._errorListener)}new(e,t){const r=`table_${t}_${this._variables.bar_index}`,n={...this._defaultTable,...e,cell:[],id:r},i=new iu(this._variables,r,this._errorListener);return this._paramVerfiy(e.position,t,"table.new",Object.values(br),"position"),t.startsWith("export")||this._variables.table.add(r,n,i),i}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}cell({table_id:e,...t}){e==null||e.cell(t)}cell_set_bgcolor({table_id:e,...t}){e==null||e.cell_set_bgcolor(t)}cell_set_height({table_id:e,...t}){e==null||e.cell_set_height(t)}cell_set_text({table_id:e,...t}){e==null||e.cell_set_text(t)}cell_set_text_color({table_id:e,...t}){e==null||e.cell_set_text_color(t)}cell_set_text_font_family({table_id:e,...t}){e==null||e.cell_set_text_font_family(t)}cell_set_text_halign({table_id:e,...t}){e==null||e.cell_set_text_halign(t)}cell_set_text_valign({table_id:e,...t}){e==null||e.cell_set_text_valign(t)}cell_set_text_size({table_id:e,...t}){e==null||e.cell_set_text_size(t)}cell_set_tooltip({table_id:e,...t}){e==null||e.cell_set_tooltip(t)}cell_set_width({table_id:e,...t}){e==null||e.cell_set_width(t)}clear({table_id:e,...t}){e==null||e.clear(t)}delete({table_id:e}){e==null||e.delete()}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({table_id:e,...t}){e==null||e.set_border_color(t)}set_border_width({table_id:e,...t}){e==null||e.set_border_width(t)}set_frame_color({table_id:e,...t}){e==null||e.set_frame_color(t)}set_frame_width({table_id:e,...t}){e==null||e.set_frame_width(t)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class iu{constructor(e,t,r){U(this,"_id");U(this,"_variables");U(this,"_errorListener");U(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ti.black,text_halign:je.alignCenter,text_valign:je.alignCenter,text_size:ar.normal});this._variables=e,this._id=t,this._errorListener=r}cell(e){const t={...this._defaultCell,...e},{column:r=0,row:n=0}=t,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],u=a[n]||[];u[r]=t,a[n]=u,i.cell=a}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r}){const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r}){const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r}){const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r}){const n=this._getTableItem(e,t);n&&(n.text_color=r)}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r}){const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r}){const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r}){const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r}){const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r}){const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r}){const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0}){const i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let u=t;u<=n;u++)for(let f=e;f<=r;f++){const c=a[u];c&&(c[f]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0},i){if(e>r||t>n){console.log(`error ${i}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(e,t);if(!a)return;this.clear({start_column:e,start_row:t,end_column:r,end_row:n});const u=this._variables.table.get(this._id);u.cell[t][e]={...a,isMerge:!0,merge_columns:r-e+1,merge_rows:n-t+1}}set_bgcolor({bgcolor:e}){const t=this._variables.table.get(this._id);t&&(t.bgcolor=e)}set_border_color({border_color:e}){const t=this._variables.table.get(this._id);t&&(t.border_color=e)}set_border_width({border_width:e}){const t=this._variables.table.get(this._id);t&&(t.border_width=e)}set_frame_color({frame_color:e}){const t=this._variables.table.get(this._id);t&&(t.frame_color=e)}set_frame_width({frame_width:e}){const t=this._variables.table.get(this._id);t&&(t.frame_width=e)}set_position({position:e},t){const r=this._variables.table.get(this._id);r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(br),"position"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}_getTableItem(e,t){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[t][e]:void 0}}}class AD{constructor(e){U(this,"_strategy");this._strategy=e}commission({trade_num:e}){return this._verifyTradeNum(e)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.historyOrders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_time}exit_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{out_qty:t=0,direction:r}=this._strategy.historyOrders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.historyOrders.length;return!(e>=t)}}class CD{constructor(e){U(this,"_strategy");this._strategy=e}commission({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,original_qty:r=0,commission:n=0}=this._strategy.orders[e];return n*t/r}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.orders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,direction:r}=this._strategy.orders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.orders.length;return!(e>=t)}}class FD{constructor(e,t){U(this,"_strategy");U(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(gt),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e}){this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[Rt.percentOfEquity,Rt.cash],"type"),t===Rt.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e}){this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[Rt.percentOfEquity,Rt.cash],"type"),t===Rt.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e}){this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}}let BD=class{constructor(e,t,r,n){U(this,"_variables");U(this,"_options");U(this,"_totalChangeCapital");U(this,"_historyOrder");U(this,"_orders");U(this,"_pendingOrders");U(this,"_mintick");U(this,"_funcOptions");U(this,"_pendingCloseOrders");U(this,"_errorListener");U(this,"_risk");U(this,"_opentrades");U(this,"_closedtrades");U(this,"_riskNamespace");this._variables=e,this._errorListener=n,this._options={overlay:!1,format:Je.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Rt.fixed,default_qty_value:1,initial_capital:1e6,currency:zf.NONE,slippage:0,commission_type:Tr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new CD(this),this._closedtrades=new AD(this),this._riskNamespace=new FD(this,n)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((e,t)=>e+(t.profit||0),0)}get _freezeCapital(){const{close:e}=this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(e){Object.assign(this._options,e),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var v;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{high:n,low:i,time_tradingday:a,time:u,strategy:{netprofit:f,initial_capital:c}}=this._variables;let{preNetprofit:h=0}=this._risk;u===a&&(h=f,this._risk.preNetprofit=f,this._risk.isTemporaryBan=!1);let d=h-f;d+=this._orders.reduce((x,_)=>{const{in_price:y,direction:m,qty:w=0,commission:D=0,original_qty:C=0}=_,b=m===gt.long?1:-1,F=(n-y)*w,B=(i-y)*w,M=b===1?-B:F;return x+M+w/C*D},0);let p=!1;switch(t){case Rt.cash:p=e<d;break;case Rt.percentOfEquity:const x=d/(c+f)*100;p=e<x;break}if(p){this._risk.isTemporaryBan=!0;const x=(v=this._orders[0])==null?void 0:v.direction;this._closeOrders(this._orders,x===gt.long?i:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(e===void 0||r)return;const{time:i,time_tradingday:a,strategy:u,open:f}=this._variables;let c=t;if(i===a){const h=u.netprofit+u.openprofit;h<n?c=0:c++,Object.assign(this._risk,{lossDays:c,totalProfit:h})}e<=c&&this._riskTouchOff(f,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(!r&&e!==void 0&&t){const{max_drawdown:i,max_drawdown_percent:a}=this._variables.strategy;let u=!1;switch(t){case Rt.percentOfEquity:u=a<i;break;case Rt.cash:u=e<i;break}if(u){const{high:f,low:c}=this._variables,h=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(h===gt.long?f:c,"Close Position (Max Drawdown)")}}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,e,t),this._pendingOrders=[]}strategy(e,t){this._variables.bar_index||(this._paramVerfiy(e.format,t,"strategy",[Je.inherit,Je.price,Je.percent,Je.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(Rt),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(Tr),"commission_type"),this._options={...e},this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"}))}order(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(vn),"oca_type"),this._orderHandle(e))}entry(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(vn),"oca_type"),this._entryHandle(e))}close(e){if(!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close"}):this._pendingOrders.push({...e,place_order_type:"close"})}close_all(e){if(typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e}){this._pendingOrders=this._pendingOrders.filter(t=>!(t.id===e&&t.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(e=>e.place_order_type==="close_all")}exit(e,t){this._exit(e,t)}convert_to_account({value:e}){return e}convert_to_symbol({value:e}){return e}default_entry_qty({fill_price:e}){return e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=Rt.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(t){case Rt.fixed:return r;case Rt.cash:return r/e;case Rt.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/e}}_getCapital(e,t){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:n<=100&&n>0&&e===-1&&(t=t*100/n),t}_calcProfitAndLoss(){const{high:e,low:t,close:r}=this._variables;for(const n of this._orders){const{in_price:i,qty:a=0,direction:u}=n,f=u===gt.long?1:-1,c=(r-i)*f*a,h=(e-i)*a,d=(t-i)*a,p=f===1?h:-d,v=f===1?-d:h;this._calcOrderPercent(n,c,p,v)}}_calcOrderPercent(e,t,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:u=0,qty:f=0,in_price:c,max_profit:h=0,trading_loss:d=0}=e;let{commission:p=0}=e;const v=c*f;if(i){const x=this._getCommission(a,f);t=t-x,p=p*f/u,r-=p,n+=p}r=Math.max(r,h),n=Math.min(n,d),Object.assign(e,{profit:t-p,total_profit:this._totalChangeCapital+t,max_profit:r,trading_loss:n,profit_percent:t/v*100,max_profit_percent:r/v*100,trading_loss_percent:n/v*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:e,low:t}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:i=0,commission_value:a=0}=this._options,u=this._orders[0].direction===gt.long?1:-1,f=u===1?t:e,c=(u===1?n:i)/100;if(c<=0)return;const[h,d,p]=this._orders.reduce((m,w)=>{let[D,C,b]=m;const{in_price:F,qty:B=0,original_qty:M=0,commission:O=0}=w,A=F*B,N=f*B;if(D+=A,C+=N,a){const T=this._getCommission(f,B);b+=T+B/M*O}return[D,C,b]},[0,0,0]),v=u*(d-h),_=r+this._totalChangeCapital+v-p-d*c;if(_>=0)return;const y=Math.trunc(_/c/f)*4;this._marginCallOrders(f,y,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r);return}for(const i of this.orders)this._processOrder(i,e,t,r,r);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(e){const{process_orders_on_close:t,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:u,price:f,activePrice:c}=this._orderArgsParse(e),h=e.direction===gt.long?1:-1;if(a<=0)return;let d=a;if(i&&t){if(n.length){const _=this._processOrders(n,u,d,e.id,e.comment);if(_<=0)return;d=_}const v=u+h*r*this._mintick;if(!this._judgeCapitalEnough(d,v,h))return;this._ocaGroupVerify(d,e.oca_name,e.oca_type),this._calcCurrentOrder({...e,in_price:v,in_index:this._variables.bar_index,in_time:this._variables.time,qty:d,place_order_type:"order"});return}this._judgeCapitalEnough(a,f,h)&&this._addPendingOrders(e,f,d,i,c)}_judgeCapitalEnough(e,t,r){if(e<=0)return!1;const{margin_long:n=0,margin_short:i=0}=this._options;if((n===0||n===100)&&r===1||i===0&&r===-1)return!0;const u=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return e*t<=u}_ocaGroupVerify(e,t,r){if(!t||!r||r===vn.none)return!1;let n=!1;switch(r){case vn.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===t)i.isCancel=!0,n=!0;else return!0});break;case vn.reduce:this._pendingOrders=this._pendingOrders.filter(i=>{const{qty:a=0,oca_name:u}=i;if(t===u){const f=a-e;return n=!0,f<=0?(i.isCancel=!0,!1):(i.qty=f,!0)}else return!0});break}return n}_processOrders(e,t,r,n,i){let a=r;for(const u of e)if(a=this._processOrder(u,t,a,n,i),a<=0)break;return this._orders=this._orders.filter(u=>!u.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(e,t,r,n,i){const a=this._pendingOrders.find(u=>u.id===e.id&&!u.isMarketPrice);if(a)Object.assign(a,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else{const u={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(u)}}_orderArgsParse(e){const{direction:t,qty:r,stop:n}=e;let i=e.limit||0;const{close:a}=this._variables;let u=a,f=!1,c;const h=t===gt.long?1:-1,d=n&&(n-a)*h>0,{backtest_fill_limits_assumption:p=0}=this._options;p>0&&i&&(i-=p*this._mintick*h);const v=i&&(i-a)*h<0;d&&v?(c=n,u=i):d?u=n:v?u=i:f=!0;const x=r||this._calcDefaultQty(u)||1;return{orders:this._orders.filter(y=>y.direction!==t),isMarketPrice:f,activePrice:c,quantities:x,close:a,price:u}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:u,activePrice:f}=this._orderArgsParse(e);if(i<=0)return;if(r.length&&n&&t){this._entryOrder(r,a,i,e);return}this._judgeCapitalEnough(i,a,e.direction===gt.long?1:-1)&&this._addPendingEntry(e,u,i,n,f)}_entryOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{oca_name:f,oca_type:c,direction:h,comment:d,isMarketPrice:p,id:v}=n,x=h===gt.long?1:-1;if(this._closeOrders(e,t,v,d),r=this._getAvailablePositionSize(r,h),r<=0)return;t=t+u*this._mintick*x;const _={...n,in_price:t,original_qty:r,qty:r,in_index:a,in_time:i,place_order_type:"entry"};if(p){this._calcCurrentOrder(_);return}const{pendingOrders:y,orders:m}=this._getEntryOrders(h),w=y.length+m.length;w&&w>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,t,x)||(this._ocaGroupVerify(r,f,c),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==gt.all&&n!==t)return 0;if(r===void 0)return e;const i=this._orders.reduce((a,u)=>a+(u.qty||0),0);return i?i+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===e),r=this._orders.filter(n=>n.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,n,i){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:a,orders:u}=this._getEntryOrders(e.direction),f=a.length+u.length,c=a.find(h=>h.id===e.id&&h.place_order_type==="entry");if(c)Object.assign(c,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else if(!f||f<(this._options.pyramiding||1)){const h={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(e,t){const{comment:r}=e,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,t,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,n){for(const i of e)this._closeOrder(i,t,r,n);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{in_price:f,qty:c=0,direction:h}=e,d=h===gt.long?1:-1;t=t-d*u*this._mintick,e.isDeal=!0;const p=(t-f)*d*c,v={...e,out_price:t,out_id:r,out_index:a,out_time:i,out_comment:n,out_qty:c,profit:p};this._calcPercent(v),this._risk.intradayOrders+=1,this._historyOrder.push(v),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const e=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!e.length)return;const{open:t,low:r,high:n,close:i}=this._variables;for(const a of e){const{stop:u,limit:f,trail_stop_price:c,isMarketPriceLimit:h,isMarketPriceStop:d,direction:p,id:v,out_comment:x,active_price:_,trail_offset:y=0,out_qty:m,comment_loss:w,comment_profit:D,comment_trailing:C}=a;let b=c;const F=p===gt.long?1:-1;let B,M=x;if(h||d?B=t:(f&&r<=f&&n>=f&&(M=D||x,B=f),u&&r<=u&&n>=u&&(B=b?(u-b)*F>0?u:b:u,M=(b===B?C:w)||x)),B)this._processExitOnClose(a,B,{from_entry:v,comment:M,qty:m});else{let O=!1;if(_&&_<=n&&_>=r&&(b=_-y*F*this._mintick,(b-i)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(B=b)),O=!0,a.trail_stop_price=b),b)if((b-t)*F>=0&&!O)B=b;else{const A=(F===1?n:r)-y*F*this._mintick;F===1?b<t&&b>=r&&A>b&&A<i?B=b:A>b?(b=A,A>=i&&(B=A)):b<=n&&r<=b&&(B=b):b>t&&b<=n&&A<b&&A>i?B=b:A<b?(b=A,A<=i&&(B=A)):b<=n&&r<=b&&(B=b),a.trail_stop_price=b}B&&this._processExitOnClose(a,B,{from_entry:v,comment:C||x,qty:m})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of r)switch(n.place_order_type){case"close":this._closeOrderHandle(n);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of this._pendingOrders){const{isCancel:i,place_order_type:a}=n;if(i)continue;let u;switch(a){case"entry":u=this._entryOrderHandle(n);break;case"order":u=this._orderOrderHandle(n);break}u&&e.push(u)}for(const n of t){const i=this._exitOrderHandle(n);i&&e.push(i)}this._pendingOrders=e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const e=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),t=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of t)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of e){const{from_entry:i}=n,a=this._orders.filter(u=>!i||u.id===i&&(u.isMarketPriceLimit||u.isMarketPriceStop));for(const u of a)this._processExitOnClose(u,u.limit||u.stop||u.trail_stop_price||r,n)}this._pendingCloseOrders=[]}_entryOrderHandle(e){const{open:t,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:u,direction:f,active_price:c}=e;if(c&&n>=c&&r<=c)return delete e.active_price,e;let h=u;if(i&&(h=t),h<=n&&h>=r){const d=this._orders.filter(p=>p.direction!==f);this._entryOrder(d,h,a,e)}else return e}_orderOrderHandle(e){const{open:t,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:u=0}=this._options,{isMarketPrice:f,qty:c=0,in_price:h,direction:d,comment:p,oca_name:v,oca_type:x,active_price:_,id:y}=e;if(_&&n>=_&&r<=_)return delete e.active_price,e;let m=h,w=c;if(f&&(m=t),m<=n&&m>=r){const D=this._orders.filter(b=>b.direction!==d);if(D.length&&(w=this._processOrders(D,m,c,y,p),w<=0))return;const C=d===gt.long?1:-1;this._ocaGroupVerify(w,v,x),this._calcCurrentOrder({...e,in_price:m+C*u*this._mintick,in_index:a,in_time:i,qty:w});return}else return e}_closeOrderHandle(e,t){const{id:r,qty:n,qty_percent:i=100,comment:a}=e,{bar_index:u}=this._variables,f=this._orders.filter(v=>v.id===r&&v.in_index!==u&&(!v.close_qty||v.close_qty<(v.qty||0)));if(!f.length)return;let c=0;if(n?c=n:(c=f.reduce((v,x)=>v+(x.qty||0),c),c=i/100*c),c<=0)return;const{open:h,close:d}=this._variables;let p=c;for(const v of f){const{qty:x=0}=v;p<x?v.close_qty=p:(v.close_qty=x,p-=x)}this._processOrders(this._options.close_entries_rule==="ANY"?f:this._orders,t?d:h,c,`Close entry(s) order ${r}`,a)}_exitOrderHandle(e){const{from_entry:t}=e,r=this._orders.filter(n=>(!t||t===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,e)))return e}_exit(e,t){const{profit:r,loss:n,stop:i,limit:a,trail_offset:u,trail_price:f,trail_points:c,from_entry:h="",id:d}=e;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(u)||this._isNaN(c)&&this._isNaN(f))){this._errorListener.addError("strategy.exit must have at least one of the following parameters: 'profit', 'limit', 'loss', 'stop' or one of the following pairs: 'trail_offset' and 'trail_price' / 'trail_points'. To close the position at market price, use 'strategy.close'",t,Ve.Error);return}const p={...e,place_order_type:"exit"},v=this._orders.filter(y=>(!h||h===y.id)&&!y.hasExit),x=this._pendingOrders.filter(y=>!h||h===y.id);if(v.length){if(!this._ordersToExit(v,p))return}else if(!x.length)return;const _=this._pendingOrders.find(y=>y.id===d);_?Object.assign(_,{...e}):this._pendingOrders.push(p)}_ordersToExit(e,t){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:u,comment_profit:f,comment_trailing:c}=t;let h=r,d=!1;t.comment=a||i;for(const p of e){const{qty:v=0}=p,x=p.direction===gt.long?1:-1;h=r?r>=v?v:r:n/100*v,p.out_qty=h,h<v&&(d=!0),Object.assign(p,{out_comment:a||i,comment_loss:u,comment_profit:f,comment_trailing:c}),!(this._stopProfit(p,x,{...t,qty:h})||this._stopLoss(p,x,{...t,qty:h})||this._trailStopLoss(p,x,{...t,qty:h}))&&(p.place_order_type="exit")}return d}_addExitPendingCloseOrders(e){e.place_order_type="exit";const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r){const{limit:n,profit:i,comment_profit:a,comment:u}=r;let f=n;const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(f=h+t*i*this._mintick),e.limit=f,f&&(f-c)*t<=0&&(e.isMarketPriceLimit=!0,r.comment=a||u,Object.assign(e,{out_comment:r.comment}),f=c,d))return this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r){const{stop:n,loss:i,comment_loss:a,comment:u}=r;let f=n;const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(f=h-t*i*this._mintick),e.stop=f,f&&(f-c)*t>=0&&(e.isMarketPriceStop=!0,r.comment=a||u,Object.assign(e,{out_comment:r.comment}),f=c,d))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:u,comment:f}=r;if(!this._isNaN(n)){const{close:c}=this._variables,{in_price:h}=e,{process_orders_on_close:d}=this._options;let p;if(this._isNaN(i)?this._isNaN(a)||(p=h+a*t*this._mintick):p=i,e.trail_offset=n,p&&(p-c)*t<=0){const v=c-n*t*this._mintick;if((v-c)*t>=0&&(e.trail_stop_price=c,e.isMarketPriceStop=!0,r.comment=u||f,Object.assign(e,{out_comment:r.comment}),d))return this._addExitPendingCloseOrders(r),!0;e.trail_stop_price=v}e.active_price=p}}_processExitOnClose(e,t,r){const{qty:n=0,comment:i,id:a}=r,{close_entries_rule:u="FIFO"}=this._options;if(u==="FIFO"){const f=this._processExitOrders(this._orders,t,n,a,i);f&&!f.hasExit?(f.hasExit=!0,Object.assign(e,{trail_stop_price:f.trail_stop_price,stop:f.stop,limit:f.limit,trail_offset:f.trail_offset,active_price:f.active_price})):f&&(e.hasExit=!0)}else e.hasExit=!0,this._processOrders([e],t,n,a,i)}_processExitOrders(e,t,r,n,i){let a=r,u;for(const f of e)if(u=f,a=this._processOrder(f,t,a,n,i),a<=0||!f.hasExit)break;return this._orders=this._orders.filter(f=>!f.isDeal),this._variables.strategy.updateOrders(this._orders),u}_processOrder(e,t,r,n,i){const{time:a,bar_index:u}=this._variables,{slippage:f=0}=this._options,{in_price:c,qty:h=0,max_profit:d=0,trading_loss:p=0,direction:v,commission:x=0,original_qty:_=0}=e,y=v===gt.long?1:-1;if(t=t-y*f*this._mintick,r<h){const m=h-r,w=(t-c)*y*r,D=d/h*r,C=p/h*r;this._calcPercent({...e,out_price:t,out_id:n,out_index:u,out_time:a,out_comment:i,profit:w,out_qty:r,max_profit:D,trading_loss:C});const b=(t-c)*y*m-x*m/_;Object.assign(e,{qty:m,profit:b,max_profit:d-D,trading_loss:p-C,total_profit:this._totalChangeCapital+b}),r=0}else{e.isDeal=!0;const m=(t-c)*y*h;this._calcPercent({...e,out_price:t,out_id:n,out_index:u,out_time:a,out_comment:i,out_qty:h,profit:m}),r-=h}return r}_calcPercent(e){const{commission_value:t}=this._options,{in_price:r,out_qty:n=0,out_price:i=0,original_qty:a=0}=e;let{profit:u=0,max_profit:f=0,trading_loss:c=0,commission:h=0}=e;f=f<0?0:f;const d=r*n;if(this._totalChangeCapital+=u,t){const p=this._getCommission(i,n);this._totalChangeCapital-=p,h=h*n/a+p,u=u-h,Object.assign(e,{commission:h,profit:u,max_profit:f})}Object.assign(e,{total_profit:this._totalChangeCapital,profit_percent:u/d*100,max_profit_percent:f/d*100,trading_loss_percent:c/d*100}),this._risk.intradayOrders+=1,this._historyOrder.push(e),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(e,t){const{commission_value:r=0,commission_type:n}=this._options,i=e*t;let a=0;switch(n){case Tr.percent:a=i*r/100;break;case Tr.cashPerContract:a=t*r;break;case Tr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=e;let{profit:u=0}=e;const f=r*n;if(t){const c=this._getCommission(r,n);this._totalChangeCapital-=c,u=u-c,Object.assign(e,{commission:c,profit:u,total_profit:this._totalChangeCapital})}Object.assign(e,{original_qty:n,profit_percent:u/f*100,max_profit_percent:i/f*100,trading_loss_percent:a/f*100}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders)}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}};var Hf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){return function(t,r,n){r.prototype.isBetween=function(i,a,u,f){var c=n(i),h=n(a),d=(f=f||"()")[0]==="(",p=f[1]===")";return(d?this.isAfter(c,u):!this.isBefore(c,u))&&(p?this.isBefore(h,u):!this.isAfter(h,u))||(d?this.isBefore(c,u):!this.isAfter(c,u))&&(p?this.isAfter(h,u):!this.isBefore(h,u))}}})})(Hf);var MD=Hf.exports,ND=tt(MD),jf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){return function(t,r,n){var i=r.prototype,a=function(p){var v,x=p.date,_=p.utc,y={};if(!((v=x)===null||v instanceof Date||v instanceof Array||i.$utils().u(v)||v.constructor.name!=="Object")){if(!Object.keys(x).length)return new Date;var m=_?n.utc():n();Object.keys(x).forEach(function(O){var A,N;y[A=O,N=i.$utils().p(A),N==="date"?"day":N]=x[O]});var w=y.day||(y.year||y.month>=0?1:m.date()),D=y.year||m.year(),C=y.month>=0?y.month:y.year||y.day?0:m.month(),b=y.hour||0,F=y.minute||0,B=y.second||0,M=y.millisecond||0;return _?new Date(Date.UTC(D,C,w,b,F,B,M)):new Date(D,C,w,b,F,B,M)}return x},u=i.parse;i.parse=function(p){p.date=a.bind(this)(p),u.bind(this)(p)};var f=i.set,c=i.add,h=i.subtract,d=function(p,v,x,_){_===void 0&&(_=1);var y=Object.keys(v),m=this;return y.forEach(function(w){m=p.bind(m)(v[w]*_,w)}),m};i.set=function(p,v){return v=v===void 0?p:v,p.constructor.name==="Object"?d.bind(this)(function(x,_){return f.bind(this)(_,x)},v,p):f.bind(this)(p,v)},i.add=function(p,v){return p.constructor.name==="Object"?d.bind(this)(c,p,v):c.bind(this)(p,v)},i.subtract=function(p,v){return p.constructor.name==="Object"?d.bind(this)(c,p,v,-1):h.bind(this)(p,v)}}})})(jf);var SD=jf.exports,OD=tt(SD),Yf={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(ye,function(){var t,r,n=1e3,i=6e4,a=36e5,u=864e5,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,h=2628e6,d=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,p={years:c,months:h,days:u,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},v=function(F){return F instanceof C},x=function(F,B,M){return new C(F,M,B.$l)},_=function(F){return r.p(F)+"s"},y=function(F){return F<0},m=function(F){return y(F)?Math.ceil(F):Math.floor(F)},w=function(F){return Math.abs(F)},D=function(F,B){return F?y(F)?{negative:!0,format:""+w(F)+B}:{negative:!1,format:""+F+B}:{negative:!1,format:""}},C=function(){function F(M,O,A){var N=this;if(this.$d={},this.$l=A,M===void 0&&(this.$ms=0,this.parseFromMilliseconds()),O)return x(M*p[_(O)],this);if(typeof M=="number")return this.$ms=M,this.parseFromMilliseconds(),this;if(typeof M=="object")return Object.keys(M).forEach(function(k){N.$d[_(k)]=M[k]}),this.calMilliseconds(),this;if(typeof M=="string"){var T=M.match(d);if(T){var R=T.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=R[0],this.$d.months=R[1],this.$d.weeks=R[2],this.$d.days=R[3],this.$d.hours=R[4],this.$d.minutes=R[5],this.$d.seconds=R[6],this.calMilliseconds(),this}}return this}var B=F.prototype;return B.calMilliseconds=function(){var M=this;this.$ms=Object.keys(this.$d).reduce(function(O,A){return O+(M.$d[A]||0)*p[A]},0)},B.parseFromMilliseconds=function(){var M=this.$ms;this.$d.years=m(M/c),M%=c,this.$d.months=m(M/h),M%=h,this.$d.days=m(M/u),M%=u,this.$d.hours=m(M/a),M%=a,this.$d.minutes=m(M/i),M%=i,this.$d.seconds=m(M/n),M%=n,this.$d.milliseconds=M},B.toISOString=function(){var M=D(this.$d.years,"Y"),O=D(this.$d.months,"M"),A=+this.$d.days||0;this.$d.weeks&&(A+=7*this.$d.weeks);var N=D(A,"D"),T=D(this.$d.hours,"H"),R=D(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var z=D(k,"S"),L=M.negative||O.negative||N.negative||T.negative||R.negative||z.negative,G=T.format||R.format||z.format?"T":"",H=(L?"-":"")+"P"+M.format+O.format+N.format+G+T.format+R.format+z.format;return H==="P"||H==="-P"?"P0D":H},B.toJSON=function(){return this.toISOString()},B.format=function(M){var O=M||"YYYY-MM-DDTHH:mm:ss",A={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return O.replace(f,function(N,T){return T||String(A[N])})},B.as=function(M){return this.$ms/p[_(M)]},B.get=function(M){var O=this.$ms,A=_(M);return A==="milliseconds"?O%=1e3:O=A==="weeks"?m(O/p[A]):this.$d[A],O||0},B.add=function(M,O,A){var N;return N=O?M*p[_(O)]:v(M)?M.$ms:x(M,this).$ms,x(this.$ms+N*(A?-1:1),this)},B.subtract=function(M,O){return this.add(M,O,!0)},B.locale=function(M){var O=this.clone();return O.$l=M,O},B.clone=function(){return x(this.$ms,this)},B.humanize=function(M){return t().add(this.$ms,"ms").locale(this.$l).fromNow(!M)},B.valueOf=function(){return this.asMilliseconds()},B.milliseconds=function(){return this.get("milliseconds")},B.asMilliseconds=function(){return this.as("milliseconds")},B.seconds=function(){return this.get("seconds")},B.asSeconds=function(){return this.as("seconds")},B.minutes=function(){return this.get("minutes")},B.asMinutes=function(){return this.as("minutes")},B.hours=function(){return this.get("hours")},B.asHours=function(){return this.as("hours")},B.days=function(){return this.get("days")},B.asDays=function(){return this.as("days")},B.weeks=function(){return this.get("weeks")},B.asWeeks=function(){return this.as("weeks")},B.months=function(){return this.get("months")},B.asMonths=function(){return this.as("months")},B.years=function(){return this.get("years")},B.asYears=function(){return this.as("years")},F}(),b=function(F,B,M){return F.add(B.years()*M,"y").add(B.months()*M,"M").add(B.days()*M,"d").add(B.hours()*M,"h").add(B.minutes()*M,"m").add(B.seconds()*M,"s").add(B.milliseconds()*M,"ms")};return function(F,B,M){t=M,r=M().$utils(),M.duration=function(N,T){var R=M.locale();return x(N,{$l:R},T)},M.isDuration=v;var O=B.prototype.add,A=B.prototype.subtract;B.prototype.add=function(N,T){return v(N)?b(this,N,1):O.bind(this)(N,T)},B.prototype.subtract=function(N,T){return v(N)?b(this,N,-1):A.bind(this)(N,T)}}})})(Yf);var TD=Yf.exports,ID=tt(TD);ot.extend(yl),ot.extend(ND),ot.extend(OD),ot.extend(ID);class Zf{constructor(e,t,r){U(this,"array");U(this,"color");U(this,"math");U(this,"str");U(this,"map");U(this,"matrix");U(this,"timeframe");U(this,"ta");U(this,"input");U(this,"_variables");U(this,"_cacheData");U(this,"_options");U(this,"_errorListener");U(this,"_plots");U(this,"_plotshapes");U(this,"_plotbars");U(this,"_plotchars");U(this,"_plotarrows");U(this,"_plotcandles");U(this,"_alerts");U(this,"_bgColors");U(this,"_hlines");U(this,"_fills");U(this,"chart");U(this,"line");U(this,"label");U(this,"polyline");U(this,"box");U(this,"table");U(this,"linefill");U(this,"log");U(this,"runtime");U(this,"strategy");U(this,"request");U(this,"syminfo");U(this,"_count",0);var i;const n=((i=e.toString().split(".")[1])==null?void 0:i.length)||4;this._variables=t,this._errorListener=new fw,this.array=new g1(this._errorListener),this.math=new m1(n,this._errorListener),this.color=new Gx,this.str=new Ky(this._errorListener,n),this.map=new Xy(this._errorListener),this.timeframe=new Gy(t),this.matrix=new Vy(this._errorListener),this.ta=new Hx(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new Vx(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Qy(t)},this.line=new DD(t,this._errorListener),this.label=new Jy(t,this._errorListener),this.polyline=new yD(t,this._errorListener),this.box=new bD(t,this._errorListener),this.table=new ED(t,this._errorListener),this.linefill=new wD(t),this.log=new lw(t),this.runtime=new cw(this._errorListener),this.strategy=new BD(this._variables,this._options,e,this._errorListener),this.request=new aw(this._variables,r),this.syminfo=new uw}get errors(){return this._errorListener.errors}options(e){if(e.length)return this._getDataOfBarindex(e);const t=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let i;if(n.length){i={};for(const y of n)i[y]=[...this._bgColors[y].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,u=this._fills.size?[...this._fills.values()]:void 0,f=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._plots.size>0?[...this._plots.values()]:void 0,h=this._plotbars.size>0?[...this._plotbars.values()]:void 0,d=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,p=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,v=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,x=this._plotchars.size>0?[...this._plotchars.values()]:void 0,_=this._getDraws();return Object.assign(this._options,{inputs:t,plots:c,draws:_,alerts:r,colors:i,hlines:a,fills:u,logs:f,plotshapes:d,plotarrows:p,plotcandles:v,plotchars:x,plotbars:h})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const d of r)n[d]=[...this._bgColors[d].values()].map(p=>{const v=[];for(const x of e){const _=p.colors[x];_&&v.push(_)}return p.colors=v,p})}const i=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,u=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const f=this._getDataFromBarindex(e,[...this._plots.values()]),c=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,h=this._getDrawsFromBarindex(e);return Object.assign(this._options,{plots:f,draws:h,alerts:t,colors:n,hlines:i,fills:a,logs:u,plotshapes:c})}_getDataFromBarindex(e,t){return t.map(r=>{const n=[];for(const i of e){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:n,polyline:i,label:a}=this._variables,u={};return e.data.length&&(u.lines=e.data),t.data.length&&(u.linefills=t.data),r.data.length&&(u.tables=r.data),n.data.length&&(u.boxes=n.data),i.data.length&&(u.polylines=i.data),a.data.length&&(u.labels=a.data),Object.keys(u).length?u:void 0}_getDrawsFromBarindex(e){const{line:t,linefill:r,table:n,box:i,polyline:a,label:u}=this._variables,f={};return t.data.length&&(f.lines=t.getValOfBarIndex(e)),r.data.length&&(f.linefills=r.getValOfBarIndex(e)),n.data.length&&(f.tables=n.getValOfBarIndex(e)),i.data.length&&(f.boxes=i.getValOfBarIndex(e)),a.data.length&&(f.polylines=a.getValOfBarIndex(e)),u.data.length&&(f.labels=u.getValOfBarIndex(e)),Object.keys(f).length?f:void 0}updateOptions(e){const{inputs:t}=e;t&&t.length&&this.input.update(t)}update(e){const{barIndex:t}=e;this.strategy.updateOptions(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=e;r.test(n)?(Zx.includes(n)||Yx.includes(n))&&this._errorListener.addError(or(Kt.libraryTitleIsKeywordErr,{name:n}),t,Ve.Error):this._errorListener.addError(Kt.libraryTitleErr,t,Ve.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r}=e;this._paramVerfiy(r,t,"indicator",[Je.inherit,Je.percent,Je.price,Je.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,n,i="format"){e&&!n.includes(e)&&this._errorListener.addError(or(Kt.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,Ve.Error)}plot(e,t){const{series:r,color:n,...i}=e,{bar_index:a,time:u}=this._variables,f=`plot_${t}`,c=this._plots.get(f),h=(c==null?void 0:c.data)||[],d=r!==void 0&&isNaN(r)?void 0:r;if(h[a]={value:[u,d],itemStyle:{color:n}},this._seriesColorHandle(e,["color"],c),!c){this._count++,this._paramVerfiy(e.format,t,"plot",[Je.percent,Je.price,Je.volume]);const p=n?[n]:void 0;this._plots.set(f,{editable:!0,...i,colors:p,data:h,id:f,zIndex:this._count})}return{type:"plot",key:f}}plotbar(e,t){const{open:r,close:n,low:i,high:a,color:u,...f}=e,{bar_index:c,time:h}=this._variables,d=`plotbar_${t}`,p=this._plotbars.get(d),v=(p==null?void 0:p.data)||[],x=n!==void 0&&isNaN(n)?void 0:n,_=r!==void 0&&isNaN(r)?void 0:r,y=i!==void 0&&isNaN(i)?void 0:i,m=a!==void 0&&isNaN(a)?void 0:a,w=[h,_,x,y,m];if(v[c]={value:w,itemStyle:{color:u}},this._seriesColorHandle(e,["color"],p),!p){this._count++,this._paramVerfiy(e.format,t,"plotbar",[Je.percent,Je.price,Je.volume]);const D=u?[u]:void 0;this._plotbars.set(d,{editable:!0,...f,colors:D,data:v,id:d,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:n,format:i,location:a,style:u}=e;this._paramVerfiy(u,r,t,Object.values(_r),"style"),this._paramVerfiy(a,r,t,Object.values(_n),"location"),this._paramVerfiy(n,r,t,Object.values(ar),"size"),this._paramVerfiy(i,r,t,[Je.percent,Je.price,Je.volume],"format")}plotchar(e,t){const{series:r,color:n,textcolor:i,location:a=_n.abovebar,...u}=e,{bar_index:f,time:c,high:h,low:d}=this._variables,p=`plotchar_${t}`,v=this._plotchars.get(p),x=(v==null?void 0:v.data)||[],_={value:[c,r],itemStyle:{color:n,textcolor:i},low:d,high:h};x[f]=_,this._seriesColorHandle(e,["color","textcolor"],v),v||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(p,{editable:!0,...u,location:a,data:x,id:p,zIndex:this._count}))}plotarrow(e,t){const{series:r,colorup:n,colordown:i,...a}=e,{bar_index:u,time:f}=this._variables,c=`plotarrow_${t}`,h=this._plotarrows.get(c),d=(h==null?void 0:h.data)||[];d[u]={value:[f,r!==void 0&&isNaN(r)?void 0:r],itemStyle:{colorup:n,colordown:i}},this._seriesColorHandle(e,["colorup","colordown"],h),h||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[Je.percent,Je.price,Je.volume]),this._plotarrows.set(c,{editable:!0,...a,data:d,id:c,zIndex:this._count}))}plotshape(e,t){const{series:r,color:n,textcolor:i,location:a=_n.abovebar,...u}=e,{bar_index:f,time:c,low:h,high:d}=this._variables,p=`plotshape_${t}`,v=this._plotshapes.get(p),x=(v==null?void 0:v.data)||[],_={value:r,color:n,textcolor:i,time:c,low:h,high:d};if(x[f]=_,this._seriesColorHandle(e,["color","textcolor"],v),!v){this._count++;const y=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(p,{editable:!0,...u,data:x,location:a,id:p,colors:y,zIndex:this._count})}}plotcandle(e,t){const{wickcolor:r,bordercolor:n,color:i,close:a,open:u,low:f,high:c,...h}=e,{bar_index:d,time:p}=this._variables,v=`plotcandle_${t}`,x=this._plotcandles.get(v),_=(x==null?void 0:x.data)||[],y=a!==void 0&&isNaN(a)?void 0:a,m=u!==void 0&&isNaN(u)?void 0:u,w=f!==void 0&&isNaN(f)?void 0:f,D=c!==void 0&&isNaN(c)?void 0:c,C=[p,m,y,w,D];_[d]={value:C,wickcolor:r,bordercolor:n,color:i},this._seriesColorHandle(e,["wickcolor","bordercolor","color"],x),x||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[Je.percent,Je.price,Je.volume]),this._plotcandles.set(v,{editable:!0,...h,data:_,id:v,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?Zt.none:Zt.all;return this._hlines.has(r)||(this._count++,this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var b,F,B,M,O,A,N,T,R,k;const{color:r,top_color:n,bottom_color:i,seriesColors:a,hline1:u,hline2:f,plot1:c,plot2:h,...d}=e,{bar_index:p,time:v}=this._variables,x=`fill_${t}`,_=this._fills.get(x),y=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const m=e.display&&!e.display.length?Zt.none:Zt.all;let w,D,C="plot";if(u&&f)w=(b=this._hlines.get(u==null?void 0:u.key))==null?void 0:b.price,D=(F=this._hlines.get(f==null?void 0:f.key))==null?void 0:F.price,C="hline";else{const z=((B=this._plots.get(c==null?void 0:c.key))==null?void 0:B.data)||[],L=((M=this._plots.get(h==null?void 0:h.key))==null?void 0:M.data)||[];w=(A=(O=z[p])==null?void 0:O.value)==null?void 0:A[1],D=(T=(N=L[p])==null?void 0:N.value)==null?void 0:T[1]}if(y[p]={time:v,color:r,top_color:n,bottom_color:i,plot1:w,plot2:D},this._seriesColorHandle(e,["color","top_color","bottom_color"],_),!_){this._count++;const z=((R=this._options.indicator)==null?void 0:R.explicit_plot_zorder)||((k=this._options.strategy)==null?void 0:k.explicit_plot_zorder),L=r?[r]:void 0,G=n?[n]:void 0,H=i?[i]:void 0;this._fills.set(x,{id:x,colors:L,top_colors:G,bottom_colors:H,display:m,data:y,type:C,editable:!0,fillgaps:!1,hline1:u,hline2:f,plot1:c,plot2:h,...d,zIndex:z?this._count:void 0})}}alert({message:e,freq:t=Vr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,u=`alert_${r}`,f=this._cacheData[u].barIndex;if(this._paramVerfiy(t,r,"alert",[Vr.freqAll,Vr.freqOncePerBar,Vr.freqOncePerBarClose]),t===Vr.freqOncePerBar&&n===f){this._alerts.delete(u);return}const c={message:e,freq:t,id:u,type:"alert"};if(i){t!==Vr.freqOncePerBarClose&&this._alerts.set(u,c),this._cacheData[u].barIndex=n;return}if(!i&&t===Vr.freqOncePerBarClose&&n===f&&a===n-1){this._alerts.set(u,c),this._cacheData[u].barIndex=n;return}this._alerts.delete(u)}alertcondition({condition:e,message:t,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&e?this._alerts.set(a,{message:t,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=qf.all,t,r){e.length&&e.length<4&&this._errorListener.addError(or(Kt.displayErr,{func:t,values:"[display.none, display.all]"}),r,Ve.Error)}_setColors(e,t,r){const{color:n,seriesColors:i,...a}=e;this._verifyDisplay(a.display,t,r);const u=e.display&&!e.display.length?Zt.none:Zt.all,{bar_index:f,time:c}=this._variables,h=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const d=this._bgColors[t].get(h),p=(d==null?void 0:d.colors)||[],v=(d==null?void 0:d.setColors)||[];n&&!v.includes(n)&&v.push(n),p[f]={color:n,time:c},d||this._bgColors[t].set(h,{...a,display:u,colors:p,setColors:v,id:h})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return e===void 0}fixnan({source:e},t){return e===void 0||isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!isNaN(e)?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,e,t,r,n)}time_close({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,e,t,r,n)}timestamp(e){const{dateString:t,timezone:r,year:n,month:i,day:a,hour:u=0,minute:f=0,second:c=0}=e;if(t)return ot(t).utc(!/GMT|UTC/.test(t)).valueOf();let h=i-1,d=n;if(h<0){const v=Math.ceil(Math.abs(h/12));h=12*v+h,d=n-v}let p=ot({year:d,month:h,day:a,hour:u,minute:f,second:c});return r&&(p=Zr(p.utc(!0).valueOf(),r)),p.utc(!0).valueOf()}weekofyear({time:e,timezone:t}){return Zr(e,t).week()}year({time:e,timezone:t}){return Zr(e,t).year()}second({time:e,timezone:t}){return Zr(e,t).second()}month({time:e,timezone:t}){return Zr(e,t).month()+1}minute({time:e,timezone:t}){return Zr(e,t).minute()}hour({time:e,timezone:t}){return Zr(e,t).hour()}dayofweek({time:e,timezone:t}){return Zr(e,t).day()+1}dayofmonth({time:e,timezone:t}){return Zr(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,t),n=pn(t)*1e3;return e-r-Math.floor((e-r)/n)*n}_timeHandle(e,t,r="",n,i,a=0){const u=r||this._variables.timeframe.period,f=pn(u),c=pn(this._variables.timeframe.period);let h;if(f<=c)h=e;else{const d=`time_${t}`,p=this._cacheData[d];if(p)p.currentTime+f*1e3-p.offset<=e?(h=e,this._cacheData[d]={currentTime:e,offset:0}):h=p;else{const v=this._calcTimeOffset(e,u);this._cacheData[d]={currentTime:e,offset:v},h=e}}if(n){const{timePeriods:d,weeks:p}=this._parserSession(n,t),v=ot(e).format("YYYY-MM-DD"),x=h;h=void 0;for(const y of d){const[m,w]=y;if(ot(e).isBetween(`${v} ${m}`,`${v} ${w}`,"hour")){ot(x).isBetween(`${v} ${m}`,`${v} ${w}`,"hour")?h=x:h=ot(`${v} ${m}`).valueOf();break}}const _=this._variables.dayofweek;h&&!p.includes(_)&&(h=void 0)}return i&&(h=h&&Zr(h,i).valueOf()),h&&h-a*c*1e3}_seriesColorHandle(e,t,r){var n;if(r&&t!=null&&t.length)for(const i of t){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=e[i];if(!a)continue;const u=r[`${i}s`]||[];u.includes(a)||(u.push(a),r[`${i}s`]=u,u.length>5&&(r[`${i}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(i)))}}_parserSession(e,t){const r=e.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(f=>{const c=parseInt(f,10);if(c<1||c>7){this._errorListener.addError(`Invalid day of week: ${f}`,t,Ve.Error);return}return c});return{timePeriods:n.split(",").map(f=>{const c=f.split("-");return c.length!==2?(this._errorListener.addError(`Invalid time period: ${f}`,t,Ve.Error),[]):[this._processTime(c[0],t),this._processTime(c[1],t)]}),weeks:a}}_processTime(e,t){const r=parseInt(e.slice(0,2),10),n=parseInt(e.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,Ve.Error);return}return`${r}:${n}`}}var Vf={exports:{}};function $D(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var su={exports:{}},Gf;function Ge(){return Gf||(Gf=1,function(s,e){(function(t,r){s.exports=r()})(ye,function(){var t=t||function(r,n){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof ye<"u"&&ye.crypto&&(i=ye.crypto),!i&&typeof $D=="function")try{i=bx}catch{}var a=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},u=Object.create||function(){function w(){}return function(D){var C;return w.prototype=D,C=new w,w.prototype=null,C}}(),f={},c=f.lib={},h=c.Base=function(){return{extend:function(w){var D=u(this);return w&&D.mixIn(w),(!D.hasOwnProperty("init")||this.init===D.init)&&(D.init=function(){D.$super.init.apply(this,arguments)}),D.init.prototype=D,D.$super=this,D},create:function(){var w=this.extend();return w.init.apply(w,arguments),w},init:function(){},mixIn:function(w){for(var D in w)w.hasOwnProperty(D)&&(this[D]=w[D]);w.hasOwnProperty("toString")&&(this.toString=w.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),d=c.WordArray=h.extend({init:function(w,D){w=this.words=w||[],D!=n?this.sigBytes=D:this.sigBytes=w.length*4},toString:function(w){return(w||v).stringify(this)},concat:function(w){var D=this.words,C=w.words,b=this.sigBytes,F=w.sigBytes;if(this.clamp(),b%4)for(var B=0;B<F;B++){var M=C[B>>>2]>>>24-B%4*8&255;D[b+B>>>2]|=M<<24-(b+B)%4*8}else for(var O=0;O<F;O+=4)D[b+O>>>2]=C[O>>>2];return this.sigBytes+=F,this},clamp:function(){var w=this.words,D=this.sigBytes;w[D>>>2]&=4294967295<<32-D%4*8,w.length=r.ceil(D/4)},clone:function(){var w=h.clone.call(this);return w.words=this.words.slice(0),w},random:function(w){for(var D=[],C=0;C<w;C+=4)D.push(a());return new d.init(D,w)}}),p=f.enc={},v=p.Hex={stringify:function(w){for(var D=w.words,C=w.sigBytes,b=[],F=0;F<C;F++){var B=D[F>>>2]>>>24-F%4*8&255;b.push((B>>>4).toString(16)),b.push((B&15).toString(16))}return b.join("")},parse:function(w){for(var D=w.length,C=[],b=0;b<D;b+=2)C[b>>>3]|=parseInt(w.substr(b,2),16)<<24-b%8*4;return new d.init(C,D/2)}},x=p.Latin1={stringify:function(w){for(var D=w.words,C=w.sigBytes,b=[],F=0;F<C;F++){var B=D[F>>>2]>>>24-F%4*8&255;b.push(String.fromCharCode(B))}return b.join("")},parse:function(w){for(var D=w.length,C=[],b=0;b<D;b++)C[b>>>2]|=(w.charCodeAt(b)&255)<<24-b%4*8;return new d.init(C,D)}},_=p.Utf8={stringify:function(w){try{return decodeURIComponent(escape(x.stringify(w)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(w){return x.parse(unescape(encodeURIComponent(w)))}},y=c.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(w){typeof w=="string"&&(w=_.parse(w)),this._data.concat(w),this._nDataBytes+=w.sigBytes},_process:function(w){var D,C=this._data,b=C.words,F=C.sigBytes,B=this.blockSize,M=B*4,O=F/M;w?O=r.ceil(O):O=r.max((O|0)-this._minBufferSize,0);var A=O*B,N=r.min(A*4,F);if(A){for(var T=0;T<A;T+=B)this._doProcessBlock(b,T);D=b.splice(0,A),C.sigBytes-=N}return new d.init(D,N)},clone:function(){var w=h.clone.call(this);return w._data=this._data.clone(),w},_minBufferSize:0});c.Hasher=y.extend({cfg:h.extend(),init:function(w){this.cfg=this.cfg.extend(w),this.reset()},reset:function(){y.reset.call(this),this._doReset()},update:function(w){return this._append(w),this._process(),this},finalize:function(w){w&&this._append(w);var D=this._doFinalize();return D},blockSize:16,_createHelper:function(w){return function(D,C){return new w.init(C).finalize(D)}},_createHmacHelper:function(w){return function(D,C){return new m.HMAC.init(w,C).finalize(D)}}});var m=f.algo={};return f}(Math);return t})}(su)),su.exports}var ou={exports:{}},Kf;function Bo(){return Kf||(Kf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.Base,u=i.WordArray,f=n.x64={};f.Word=a.extend({init:function(c,h){this.high=c,this.low=h}}),f.WordArray=a.extend({init:function(c,h){c=this.words=c||[],h!=r?this.sigBytes=h:this.sigBytes=c.length*8},toX32:function(){for(var c=this.words,h=c.length,d=[],p=0;p<h;p++){var v=c[p];d.push(v.high),d.push(v.low)}return u.create(d,this.sigBytes)},clone:function(){for(var c=a.clone.call(this),h=c.words=this.words.slice(0),d=h.length,p=0;p<d;p++)h[p]=h[p].clone();return c}})}(),t})}(ou)),ou.exports}var au={exports:{}},Xf;function RD(){return Xf||(Xf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){if(typeof ArrayBuffer=="function"){var r=t,n=r.lib,i=n.WordArray,a=i.init,u=i.init=function(f){if(f instanceof ArrayBuffer&&(f=new Uint8Array(f)),(f instanceof Int8Array||typeof Uint8ClampedArray<"u"&&f instanceof Uint8ClampedArray||f instanceof Int16Array||f instanceof Uint16Array||f instanceof Int32Array||f instanceof Uint32Array||f instanceof Float32Array||f instanceof Float64Array)&&(f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength)),f instanceof Uint8Array){for(var c=f.byteLength,h=[],d=0;d<c;d++)h[d>>>2]|=f[d]<<24-d%4*8;a.call(this,h,c)}else a.apply(this,arguments)};u.prototype=i}}(),t.lib.WordArray})}(au)),au.exports}var uu={exports:{}},Qf;function LD(){return Qf||(Qf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Utf16=a.Utf16BE={stringify:function(f){for(var c=f.words,h=f.sigBytes,d=[],p=0;p<h;p+=2){var v=c[p>>>2]>>>16-p%4*8&65535;d.push(String.fromCharCode(v))}return d.join("")},parse:function(f){for(var c=f.length,h=[],d=0;d<c;d++)h[d>>>1]|=f.charCodeAt(d)<<16-d%2*16;return i.create(h,c*2)}},a.Utf16LE={stringify:function(f){for(var c=f.words,h=f.sigBytes,d=[],p=0;p<h;p+=2){var v=u(c[p>>>2]>>>16-p%4*8&65535);d.push(String.fromCharCode(v))}return d.join("")},parse:function(f){for(var c=f.length,h=[],d=0;d<c;d++)h[d>>>1]|=u(f.charCodeAt(d)<<16-d%2*16);return i.create(h,c*2)}};function u(f){return f<<8&4278255360|f>>>8&16711935}}(),t.enc.Utf16})}(uu)),uu.exports}var lu={exports:{}},Jf;function oi(){return Jf||(Jf=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Base64={stringify:function(f){var c=f.words,h=f.sigBytes,d=this._map;f.clamp();for(var p=[],v=0;v<h;v+=3)for(var x=c[v>>>2]>>>24-v%4*8&255,_=c[v+1>>>2]>>>24-(v+1)%4*8&255,y=c[v+2>>>2]>>>24-(v+2)%4*8&255,m=x<<16|_<<8|y,w=0;w<4&&v+w*.75<h;w++)p.push(d.charAt(m>>>6*(3-w)&63));var D=d.charAt(64);if(D)for(;p.length%4;)p.push(D);return p.join("")},parse:function(f){var c=f.length,h=this._map,d=this._reverseMap;if(!d){d=this._reverseMap=[];for(var p=0;p<h.length;p++)d[h.charCodeAt(p)]=p}var v=h.charAt(64);if(v){var x=f.indexOf(v);x!==-1&&(c=x)}return u(f,c,d)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};function u(f,c,h){for(var d=[],p=0,v=0;v<c;v++)if(v%4){var x=h[f.charCodeAt(v-1)]<<v%4*2,_=h[f.charCodeAt(v)]>>>6-v%4*2,y=x|_;d[p>>>2]|=y<<24-p%4*8,p++}return i.create(d,p)}}(),t.enc.Base64})}(lu)),lu.exports}var cu={exports:{}},eh;function PD(){return eh||(eh=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.enc;a.Base64url={stringify:function(f,c){c===void 0&&(c=!0);var h=f.words,d=f.sigBytes,p=c?this._safe_map:this._map;f.clamp();for(var v=[],x=0;x<d;x+=3)for(var _=h[x>>>2]>>>24-x%4*8&255,y=h[x+1>>>2]>>>24-(x+1)%4*8&255,m=h[x+2>>>2]>>>24-(x+2)%4*8&255,w=_<<16|y<<8|m,D=0;D<4&&x+D*.75<d;D++)v.push(p.charAt(w>>>6*(3-D)&63));var C=p.charAt(64);if(C)for(;v.length%4;)v.push(C);return v.join("")},parse:function(f,c){c===void 0&&(c=!0);var h=f.length,d=c?this._safe_map:this._map,p=this._reverseMap;if(!p){p=this._reverseMap=[];for(var v=0;v<d.length;v++)p[d.charCodeAt(v)]=v}var x=d.charAt(64);if(x){var _=f.indexOf(x);_!==-1&&(h=_)}return u(f,h,p)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function u(f,c,h){for(var d=[],p=0,v=0;v<c;v++)if(v%4){var x=h[f.charCodeAt(v-1)]<<v%4*2,_=h[f.charCodeAt(v)]>>>6-v%4*2,y=x|_;d[p>>>2]|=y<<24-p%4*8,p++}return i.create(d,p)}}(),t.enc.Base64url})}(cu)),cu.exports}var fu={exports:{}},th;function ai(){return th||(th=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.algo,c=[];(function(){for(var _=0;_<64;_++)c[_]=r.abs(r.sin(_+1))*4294967296|0})();var h=f.MD5=u.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(_,y){for(var m=0;m<16;m++){var w=y+m,D=_[w];_[w]=(D<<8|D>>>24)&16711935|(D<<24|D>>>8)&4278255360}var C=this._hash.words,b=_[y+0],F=_[y+1],B=_[y+2],M=_[y+3],O=_[y+4],A=_[y+5],N=_[y+6],T=_[y+7],R=_[y+8],k=_[y+9],z=_[y+10],L=_[y+11],G=_[y+12],H=_[y+13],ee=_[y+14],te=_[y+15],j=C[0],X=C[1],Y=C[2],Q=C[3];j=d(j,X,Y,Q,b,7,c[0]),Q=d(Q,j,X,Y,F,12,c[1]),Y=d(Y,Q,j,X,B,17,c[2]),X=d(X,Y,Q,j,M,22,c[3]),j=d(j,X,Y,Q,O,7,c[4]),Q=d(Q,j,X,Y,A,12,c[5]),Y=d(Y,Q,j,X,N,17,c[6]),X=d(X,Y,Q,j,T,22,c[7]),j=d(j,X,Y,Q,R,7,c[8]),Q=d(Q,j,X,Y,k,12,c[9]),Y=d(Y,Q,j,X,z,17,c[10]),X=d(X,Y,Q,j,L,22,c[11]),j=d(j,X,Y,Q,G,7,c[12]),Q=d(Q,j,X,Y,H,12,c[13]),Y=d(Y,Q,j,X,ee,17,c[14]),X=d(X,Y,Q,j,te,22,c[15]),j=p(j,X,Y,Q,F,5,c[16]),Q=p(Q,j,X,Y,N,9,c[17]),Y=p(Y,Q,j,X,L,14,c[18]),X=p(X,Y,Q,j,b,20,c[19]),j=p(j,X,Y,Q,A,5,c[20]),Q=p(Q,j,X,Y,z,9,c[21]),Y=p(Y,Q,j,X,te,14,c[22]),X=p(X,Y,Q,j,O,20,c[23]),j=p(j,X,Y,Q,k,5,c[24]),Q=p(Q,j,X,Y,ee,9,c[25]),Y=p(Y,Q,j,X,M,14,c[26]),X=p(X,Y,Q,j,R,20,c[27]),j=p(j,X,Y,Q,H,5,c[28]),Q=p(Q,j,X,Y,B,9,c[29]),Y=p(Y,Q,j,X,T,14,c[30]),X=p(X,Y,Q,j,G,20,c[31]),j=v(j,X,Y,Q,A,4,c[32]),Q=v(Q,j,X,Y,R,11,c[33]),Y=v(Y,Q,j,X,L,16,c[34]),X=v(X,Y,Q,j,ee,23,c[35]),j=v(j,X,Y,Q,F,4,c[36]),Q=v(Q,j,X,Y,O,11,c[37]),Y=v(Y,Q,j,X,T,16,c[38]),X=v(X,Y,Q,j,z,23,c[39]),j=v(j,X,Y,Q,H,4,c[40]),Q=v(Q,j,X,Y,b,11,c[41]),Y=v(Y,Q,j,X,M,16,c[42]),X=v(X,Y,Q,j,N,23,c[43]),j=v(j,X,Y,Q,k,4,c[44]),Q=v(Q,j,X,Y,G,11,c[45]),Y=v(Y,Q,j,X,te,16,c[46]),X=v(X,Y,Q,j,B,23,c[47]),j=x(j,X,Y,Q,b,6,c[48]),Q=x(Q,j,X,Y,T,10,c[49]),Y=x(Y,Q,j,X,ee,15,c[50]),X=x(X,Y,Q,j,A,21,c[51]),j=x(j,X,Y,Q,G,6,c[52]),Q=x(Q,j,X,Y,M,10,c[53]),Y=x(Y,Q,j,X,z,15,c[54]),X=x(X,Y,Q,j,F,21,c[55]),j=x(j,X,Y,Q,R,6,c[56]),Q=x(Q,j,X,Y,te,10,c[57]),Y=x(Y,Q,j,X,N,15,c[58]),X=x(X,Y,Q,j,H,21,c[59]),j=x(j,X,Y,Q,O,6,c[60]),Q=x(Q,j,X,Y,L,10,c[61]),Y=x(Y,Q,j,X,B,15,c[62]),X=x(X,Y,Q,j,k,21,c[63]),C[0]=C[0]+j|0,C[1]=C[1]+X|0,C[2]=C[2]+Y|0,C[3]=C[3]+Q|0},_doFinalize:function(){var _=this._data,y=_.words,m=this._nDataBytes*8,w=_.sigBytes*8;y[w>>>5]|=128<<24-w%32;var D=r.floor(m/4294967296),C=m;y[(w+64>>>9<<4)+15]=(D<<8|D>>>24)&16711935|(D<<24|D>>>8)&4278255360,y[(w+64>>>9<<4)+14]=(C<<8|C>>>24)&16711935|(C<<24|C>>>8)&4278255360,_.sigBytes=(y.length+1)*4,this._process();for(var b=this._hash,F=b.words,B=0;B<4;B++){var M=F[B];F[B]=(M<<8|M>>>24)&16711935|(M<<24|M>>>8)&4278255360}return b},clone:function(){var _=u.clone.call(this);return _._hash=this._hash.clone(),_}});function d(_,y,m,w,D,C,b){var F=_+(y&m|~y&w)+D+b;return(F<<C|F>>>32-C)+y}function p(_,y,m,w,D,C,b){var F=_+(y&w|m&~w)+D+b;return(F<<C|F>>>32-C)+y}function v(_,y,m,w,D,C,b){var F=_+(y^m^w)+D+b;return(F<<C|F>>>32-C)+y}function x(_,y,m,w,D,C,b){var F=_+(m^(y|~w))+D+b;return(F<<C|F>>>32-C)+y}n.MD5=u._createHelper(h),n.HmacMD5=u._createHmacHelper(h)}(Math),t.MD5})}(fu)),fu.exports}var hu={exports:{}},rh;function nh(){return rh||(rh=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=n.Hasher,u=r.algo,f=[],c=u.SHA1=a.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(h,d){for(var p=this._hash.words,v=p[0],x=p[1],_=p[2],y=p[3],m=p[4],w=0;w<80;w++){if(w<16)f[w]=h[d+w]|0;else{var D=f[w-3]^f[w-8]^f[w-14]^f[w-16];f[w]=D<<1|D>>>31}var C=(v<<5|v>>>27)+m+f[w];w<20?C+=(x&_|~x&y)+1518500249:w<40?C+=(x^_^y)+1859775393:w<60?C+=(x&_|x&y|_&y)-1894007588:C+=(x^_^y)-899497514,m=y,y=_,_=x<<30|x>>>2,x=v,v=C}p[0]=p[0]+v|0,p[1]=p[1]+x|0,p[2]=p[2]+_|0,p[3]=p[3]+y|0,p[4]=p[4]+m|0},_doFinalize:function(){var h=this._data,d=h.words,p=this._nDataBytes*8,v=h.sigBytes*8;return d[v>>>5]|=128<<24-v%32,d[(v+64>>>9<<4)+14]=Math.floor(p/4294967296),d[(v+64>>>9<<4)+15]=p,h.sigBytes=d.length*4,this._process(),this._hash},clone:function(){var h=a.clone.call(this);return h._hash=this._hash.clone(),h}});r.SHA1=a._createHelper(c),r.HmacSHA1=a._createHmacHelper(c)}(),t.SHA1})}(hu)),hu.exports}var du={exports:{}},ih;function pu(){return ih||(ih=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.algo,c=[],h=[];(function(){function v(m){for(var w=r.sqrt(m),D=2;D<=w;D++)if(!(m%D))return!1;return!0}function x(m){return(m-(m|0))*4294967296|0}for(var _=2,y=0;y<64;)v(_)&&(y<8&&(c[y]=x(r.pow(_,1/2))),h[y]=x(r.pow(_,1/3)),y++),_++})();var d=[],p=f.SHA256=u.extend({_doReset:function(){this._hash=new a.init(c.slice(0))},_doProcessBlock:function(v,x){for(var _=this._hash.words,y=_[0],m=_[1],w=_[2],D=_[3],C=_[4],b=_[5],F=_[6],B=_[7],M=0;M<64;M++){if(M<16)d[M]=v[x+M]|0;else{var O=d[M-15],A=(O<<25|O>>>7)^(O<<14|O>>>18)^O>>>3,N=d[M-2],T=(N<<15|N>>>17)^(N<<13|N>>>19)^N>>>10;d[M]=A+d[M-7]+T+d[M-16]}var R=C&b^~C&F,k=y&m^y&w^m&w,z=(y<<30|y>>>2)^(y<<19|y>>>13)^(y<<10|y>>>22),L=(C<<26|C>>>6)^(C<<21|C>>>11)^(C<<7|C>>>25),G=B+L+R+h[M]+d[M],H=z+k;B=F,F=b,b=C,C=D+G|0,D=w,w=m,m=y,y=G+H|0}_[0]=_[0]+y|0,_[1]=_[1]+m|0,_[2]=_[2]+w|0,_[3]=_[3]+D|0,_[4]=_[4]+C|0,_[5]=_[5]+b|0,_[6]=_[6]+F|0,_[7]=_[7]+B|0},_doFinalize:function(){var v=this._data,x=v.words,_=this._nDataBytes*8,y=v.sigBytes*8;return x[y>>>5]|=128<<24-y%32,x[(y+64>>>9<<4)+14]=r.floor(_/4294967296),x[(y+64>>>9<<4)+15]=_,v.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var v=u.clone.call(this);return v._hash=this._hash.clone(),v}});n.SHA256=u._createHelper(p),n.HmacSHA256=u._createHmacHelper(p)}(Math),t.SHA256})}(du)),du.exports}var _u={exports:{}},sh;function kD(){return sh||(sh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),pu())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.WordArray,a=r.algo,u=a.SHA256,f=a.SHA224=u.extend({_doReset:function(){this._hash=new i.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var c=u._doFinalize.call(this);return c.sigBytes-=4,c}});r.SHA224=u._createHelper(f),r.HmacSHA224=u._createHmacHelper(f)}(),t.SHA224})}(_u)),_u.exports}var vu={exports:{}},oh;function ah(){return oh||(oh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo())})(ye,function(t){return function(){var r=t,n=r.lib,i=n.Hasher,a=r.x64,u=a.Word,f=a.WordArray,c=r.algo;function h(){return u.create.apply(u,arguments)}var d=[h(1116352408,3609767458),h(1899447441,602891725),h(3049323471,3964484399),h(3921009573,2173295548),h(961987163,4081628472),h(1508970993,3053834265),h(2453635748,2937671579),h(2870763221,3664609560),h(3624381080,2734883394),h(310598401,1164996542),h(607225278,1323610764),h(1426881987,3590304994),h(1925078388,4068182383),h(2162078206,991336113),h(2614888103,633803317),h(3248222580,3479774868),h(3835390401,2666613458),h(4022224774,944711139),h(264347078,2341262773),h(604807628,2007800933),h(770255983,1495990901),h(1249150122,1856431235),h(1555081692,3175218132),h(1996064986,2198950837),h(2554220882,3999719339),h(2821834349,766784016),h(2952996808,2566594879),h(3210313671,3203337956),h(3336571891,1034457026),h(3584528711,2466948901),h(113926993,3758326383),h(338241895,168717936),h(666307205,1188179964),h(773529912,1546045734),h(1294757372,1522805485),h(1396182291,2643833823),h(1695183700,2343527390),h(1986661051,1014477480),h(2177026350,1206759142),h(2456956037,344077627),h(2730485921,1290863460),h(2820302411,3158454273),h(3259730800,3505952657),h(3345764771,106217008),h(3516065817,3606008344),h(3600352804,1432725776),h(4094571909,1467031594),h(275423344,851169720),h(430227734,3100823752),h(506948616,1363258195),h(659060556,3750685593),h(883997877,3785050280),h(958139571,3318307427),h(1322822218,3812723403),h(1537002063,2003034995),h(1747873779,3602036899),h(1955562222,1575990012),h(2024104815,1125592928),h(2227730452,2716904306),h(2361852424,442776044),h(2428436474,593698344),h(2756734187,3733110249),h(3204031479,2999351573),h(3329325298,3815920427),h(3391569614,3928383900),h(3515267271,566280711),h(3940187606,3454069534),h(4118630271,4000239992),h(116418474,1914138554),h(174292421,2731055270),h(289380356,3203993006),h(460393269,320620315),h(685471733,587496836),h(852142971,1086792851),h(1017036298,365543100),h(1126000580,2618297676),h(1288033470,3409855158),h(1501505948,4234509866),h(1607167915,987167468),h(1816402316,1246189591)],p=[];(function(){for(var x=0;x<80;x++)p[x]=h()})();var v=c.SHA512=i.extend({_doReset:function(){this._hash=new f.init([new u.init(1779033703,4089235720),new u.init(3144134277,2227873595),new u.init(1013904242,4271175723),new u.init(2773480762,1595750129),new u.init(1359893119,2917565137),new u.init(2600822924,725511199),new u.init(528734635,4215389547),new u.init(1541459225,327033209)])},_doProcessBlock:function(x,_){for(var y=this._hash.words,m=y[0],w=y[1],D=y[2],C=y[3],b=y[4],F=y[5],B=y[6],M=y[7],O=m.high,A=m.low,N=w.high,T=w.low,R=D.high,k=D.low,z=C.high,L=C.low,G=b.high,H=b.low,ee=F.high,te=F.low,j=B.high,X=B.low,Y=M.high,Q=M.low,pe=O,De=A,we=N,be=T,Oe=R,Fe=k,nt=z,Ye=L,Te=G,Re=H,xt=ee,Ut=te,Et=j,lr=X,Lr=Y,cr=Q,yt=0;yt<80;yt++){var Ot,P,V=p[yt];if(yt<16)P=V.high=x[_+yt*2]|0,Ot=V.low=x[_+yt*2+1]|0;else{var J=p[yt-15],ie=J.high,ue=J.low,se=(ie>>>1|ue<<31)^(ie>>>8|ue<<24)^ie>>>7,_e=(ue>>>1|ie<<31)^(ue>>>8|ie<<24)^(ue>>>7|ie<<25),he=p[yt-2],de=he.high,fe=he.low,Xe=(de>>>19|fe<<13)^(de<<3|fe>>>29)^de>>>6,et=(fe>>>19|de<<13)^(fe<<3|de>>>29)^(fe>>>6|de<<26),ht=p[yt-7],kt=ht.high,Tt=ht.low,rr=p[yt-16],fr=rr.high,en=rr.low;Ot=_e+Tt,P=se+kt+(Ot>>>0<_e>>>0?1:0),Ot=Ot+et,P=P+Xe+(Ot>>>0<et>>>0?1:0),Ot=Ot+en,P=P+fr+(Ot>>>0<en>>>0?1:0),V.high=P,V.low=Ot}var Dn=Te&xt^~Te&Et,li=Re&Ut^~Re&lr,vs=pe&we^pe&Oe^we&Oe,gs=De&be^De&Fe^be&Fe,ms=(pe>>>28|De<<4)^(pe<<30|De>>>2)^(pe<<25|De>>>7),Li=(De>>>28|pe<<4)^(De<<30|pe>>>2)^(De<<25|pe>>>7),Pi=(Te>>>14|Re<<18)^(Te>>>18|Re<<14)^(Te<<23|Re>>>9),xs=(Re>>>14|Te<<18)^(Re>>>18|Te<<14)^(Re<<23|Te>>>9),ki=d[yt],ys=ki.high,zn=ki.low,Xt=cr+xs,mr=Lr+Pi+(Xt>>>0<cr>>>0?1:0),Xt=Xt+li,mr=mr+Dn+(Xt>>>0<li>>>0?1:0),Xt=Xt+zn,mr=mr+ys+(Xt>>>0<zn>>>0?1:0),Xt=Xt+Ot,mr=mr+P+(Xt>>>0<Ot>>>0?1:0),zi=Li+gs,Ds=ms+vs+(zi>>>0<Li>>>0?1:0);Lr=Et,cr=lr,Et=xt,lr=Ut,xt=Te,Ut=Re,Re=Ye+Xt|0,Te=nt+mr+(Re>>>0<Ye>>>0?1:0)|0,nt=Oe,Ye=Fe,Oe=we,Fe=be,we=pe,be=De,De=Xt+zi|0,pe=mr+Ds+(De>>>0<Xt>>>0?1:0)|0}A=m.low=A+De,m.high=O+pe+(A>>>0<De>>>0?1:0),T=w.low=T+be,w.high=N+we+(T>>>0<be>>>0?1:0),k=D.low=k+Fe,D.high=R+Oe+(k>>>0<Fe>>>0?1:0),L=C.low=L+Ye,C.high=z+nt+(L>>>0<Ye>>>0?1:0),H=b.low=H+Re,b.high=G+Te+(H>>>0<Re>>>0?1:0),te=F.low=te+Ut,F.high=ee+xt+(te>>>0<Ut>>>0?1:0),X=B.low=X+lr,B.high=j+Et+(X>>>0<lr>>>0?1:0),Q=M.low=Q+cr,M.high=Y+Lr+(Q>>>0<cr>>>0?1:0)},_doFinalize:function(){var x=this._data,_=x.words,y=this._nDataBytes*8,m=x.sigBytes*8;_[m>>>5]|=128<<24-m%32,_[(m+128>>>10<<5)+30]=Math.floor(y/4294967296),_[(m+128>>>10<<5)+31]=y,x.sigBytes=_.length*4,this._process();var w=this._hash.toX32();return w},clone:function(){var x=i.clone.call(this);return x._hash=this._hash.clone(),x},blockSize:1024/32});r.SHA512=i._createHelper(v),r.HmacSHA512=i._createHmacHelper(v)}(),t.SHA512})}(vu)),vu.exports}var gu={exports:{}},uh;function zD(){return uh||(uh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo(),ah())})(ye,function(t){return function(){var r=t,n=r.x64,i=n.Word,a=n.WordArray,u=r.algo,f=u.SHA512,c=u.SHA384=f.extend({_doReset:function(){this._hash=new a.init([new i.init(3418070365,3238371032),new i.init(1654270250,914150663),new i.init(2438529370,812702999),new i.init(355462360,4144912697),new i.init(1731405415,4290775857),new i.init(2394180231,1750603025),new i.init(3675008525,1694076839),new i.init(1203062813,3204075428)])},_doFinalize:function(){var h=f._doFinalize.call(this);return h.sigBytes-=16,h}});r.SHA384=f._createHelper(c),r.HmacSHA384=f._createHmacHelper(c)}(),t.SHA384})}(gu)),gu.exports}var mu={exports:{}},lh;function qD(){return lh||(lh=1,function(s,e){(function(t,r,n){s.exports=r(Ge(),Bo())})(ye,function(t){return function(r){var n=t,i=n.lib,a=i.WordArray,u=i.Hasher,f=n.x64,c=f.Word,h=n.algo,d=[],p=[],v=[];(function(){for(var y=1,m=0,w=0;w<24;w++){d[y+5*m]=(w+1)*(w+2)/2%64;var D=m%5,C=(2*y+3*m)%5;y=D,m=C}for(var y=0;y<5;y++)for(var m=0;m<5;m++)p[y+5*m]=m+(2*y+3*m)%5*5;for(var b=1,F=0;F<24;F++){for(var B=0,M=0,O=0;O<7;O++){if(b&1){var A=(1<<O)-1;A<32?M^=1<<A:B^=1<<A-32}b&128?b=b<<1^113:b<<=1}v[F]=c.create(B,M)}})();var x=[];(function(){for(var y=0;y<25;y++)x[y]=c.create()})();var _=h.SHA3=u.extend({cfg:u.cfg.extend({outputLength:512}),_doReset:function(){for(var y=this._state=[],m=0;m<25;m++)y[m]=new c.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(y,m){for(var w=this._state,D=this.blockSize/2,C=0;C<D;C++){var b=y[m+2*C],F=y[m+2*C+1];b=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360,F=(F<<8|F>>>24)&16711935|(F<<24|F>>>8)&4278255360;var B=w[C];B.high^=F,B.low^=b}for(var M=0;M<24;M++){for(var O=0;O<5;O++){for(var A=0,N=0,T=0;T<5;T++){var B=w[O+5*T];A^=B.high,N^=B.low}var R=x[O];R.high=A,R.low=N}for(var O=0;O<5;O++)for(var k=x[(O+4)%5],z=x[(O+1)%5],L=z.high,G=z.low,A=k.high^(L<<1|G>>>31),N=k.low^(G<<1|L>>>31),T=0;T<5;T++){var B=w[O+5*T];B.high^=A,B.low^=N}for(var H=1;H<25;H++){var A,N,B=w[H],ee=B.high,te=B.low,j=d[H];j<32?(A=ee<<j|te>>>32-j,N=te<<j|ee>>>32-j):(A=te<<j-32|ee>>>64-j,N=ee<<j-32|te>>>64-j);var X=x[p[H]];X.high=A,X.low=N}var Y=x[0],Q=w[0];Y.high=Q.high,Y.low=Q.low;for(var O=0;O<5;O++)for(var T=0;T<5;T++){var H=O+5*T,B=w[H],pe=x[H],De=x[(O+1)%5+5*T],we=x[(O+2)%5+5*T];B.high=pe.high^~De.high&we.high,B.low=pe.low^~De.low&we.low}var B=w[0],be=v[M];B.high^=be.high,B.low^=be.low}},_doFinalize:function(){var y=this._data,m=y.words;this._nDataBytes*8;var w=y.sigBytes*8,D=this.blockSize*32;m[w>>>5]|=1<<24-w%32,m[(r.ceil((w+1)/D)*D>>>5)-1]|=128,y.sigBytes=m.length*4,this._process();for(var C=this._state,b=this.cfg.outputLength/8,F=b/8,B=[],M=0;M<F;M++){var O=C[M],A=O.high,N=O.low;A=(A<<8|A>>>24)&16711935|(A<<24|A>>>8)&4278255360,N=(N<<8|N>>>24)&16711935|(N<<24|N>>>8)&4278255360,B.push(N),B.push(A)}return new a.init(B,b)},clone:function(){for(var y=u.clone.call(this),m=y._state=this._state.slice(0),w=0;w<25;w++)m[w]=m[w].clone();return y}});n.SHA3=u._createHelper(_),n.HmacSHA3=u._createHmacHelper(_)}(Math),t.SHA3})}(mu)),mu.exports}var xu={exports:{}},ch;function UD(){return ch||(ch=1,function(s,e){(function(t,r){s.exports=r(Ge())})(ye,function(t){/** @preserve
63
63
  (c) 2012 by Cédric Mesnil. All rights reserved.
64
64
 
65
65
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: