@guihz/trading-vue-editor-tes 0.0.55 → 0.0.57
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/assets/{parserTccWorker-HvN6ZSID.js → parserTccWorker-DwIXERLL.js} +52 -52
- package/lib/assets/{scriptsRunWorker-DBOrPbdQ.js → scriptsRunWorker-CjCbw7bj.js} +2 -2
- package/lib/components/editor/parseScript/constants.d.ts +8 -0
- package/lib/components/editor/parseScript/enum.d.ts +5 -0
- package/lib/components/editor/parseScript/parseToLibJs.d.ts +48 -0
- package/lib/components/editor/parseScript/visitorParser.d.ts +22 -2
- package/lib/components/editor/type/index.d.ts +1 -0
- package/lib/components/editor/utils/parserTccWorker.d.ts +3 -3
- package/lib/packages/index.d.ts +1 -1
- package/lib/trading-vue-editor.js +936 -931
- package/lib/trading-vue-editor.umd.cjs +13 -13
- package/package.json +1 -1
@@ -51,7 +51,7 @@ Example:
|
|
51
51
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
52
52
|
**/(function(i,t){(function(e){var r=2e3,n={s:1,n:0,d:1};function s(v,E){if(isNaN(v=parseInt(v,10)))throw m();return v*E}function a(v,E){if(E===0)throw w();var b=Object.create(g.prototype);b.s=v<0?-1:1,v=v<0?-v:v;var N=d(v,E);return b.n=v/N,b.d=E/N,b}function l(v){for(var E={},b=v,N=2,x=4;x<=b;){for(;b%N===0;)b/=N,E[N]=(E[N]||0)+1;x+=1+2*N++}return b!==v?b>1&&(E[b]=(E[b]||0)+1):E[v]=(E[v]||0)+1,E}var c=function(v,E){var b=0,N=1,x=1,F=0,M=0,S=0,I=1,C=1,T=0,L=1,U=1,k=1,W=1e7,P;if(v!=null)if(E!==void 0){if(b=v,N=E,x=b*N,b%1!==0||N%1!==0)throw D()}else switch(typeof v){case"object":{if("d"in v&&"n"in v)b=v.n,N=v.d,"s"in v&&(b*=v.s);else if(0 in v)b=v[0],1 in v&&(N=v[1]);else throw m();x=b*N;break}case"number":{if(v<0&&(x=v,v=-v),v%1===0)b=v;else if(v>0){for(v>=1&&(C=Math.pow(10,Math.floor(1+Math.log(v)/Math.LN10)),v/=C);L<=W&&k<=W;)if(P=(T+U)/(L+k),v===P){L+k<=W?(b=T+U,N=L+k):k>L?(b=U,N=k):(b=T,N=L);break}else v>P?(T+=U,L+=k):(U+=T,k+=L),L>W?(b=U,N=k):(b=T,N=L);b*=C}else(isNaN(v)||isNaN(E))&&(N=b=NaN);break}case"string":{if(L=v.match(/\d+|./g),L===null)throw m();if(L[T]==="-"?(x=-1,T++):L[T]==="+"&&T++,L.length===T+1?M=s(L[T++],x):L[T+1]==="."||L[T]==="."?(L[T]!=="."&&(F=s(L[T++],x)),T++,(T+1===L.length||L[T+1]==="("&&L[T+3]===")"||L[T+1]==="'"&&L[T+3]==="'")&&(M=s(L[T],x),I=Math.pow(10,L[T].length),T++),(L[T]==="("&&L[T+2]===")"||L[T]==="'"&&L[T+2]==="'")&&(S=s(L[T+1],x),C=Math.pow(10,L[T+1].length)-1,T+=3)):L[T+1]==="/"||L[T+1]===":"?(M=s(L[T],x),I=s(L[T+2],1),T+=3):L[T+3]==="/"&&L[T+1]===" "&&(F=s(L[T],x),M=s(L[T+2],x),I=s(L[T+4],1),T+=5),L.length<=T){N=I*C,x=b=S+N*F+C*M;break}}default:throw m()}if(N===0)throw w();n.s=x<0?-1:1,n.n=Math.abs(b),n.d=Math.abs(N)};function h(v,E,b){for(var N=1;E>0;v=v*v%b,E>>=1)E&1&&(N=N*v%b);return N}function p(v,E){for(;E%2===0;E/=2);for(;E%5===0;E/=5);if(E===1)return 0;for(var b=10%E,N=1;b!==1;N++)if(b=b*10%E,N>r)return 0;return N}function f(v,E,b){for(var N=1,x=h(10,b,E),F=0;F<300;F++){if(N===x)return F;N=N*10%E,x=x*10%E}return 0}function d(v,E){if(!v)return E;if(!E)return v;for(;;){if(v%=E,!v)return E;if(E%=v,!E)return v}}function g(v,E){if(c(v,E),this instanceof g)v=d(n.d,n.n),this.s=n.s,this.n=n.n/v,this.d=n.d/v;else return a(n.s*n.n,n.d)}var w=function(){return new Error("Division by Zero")},m=function(){return new Error("Invalid argument")},D=function(){return new Error("Parameters must be integer")};g.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(v,E){return c(v,E),a(this.s*this.n*n.d+n.s*this.d*n.n,this.d*n.d)},sub:function(v,E){return c(v,E),a(this.s*this.n*n.d-n.s*this.d*n.n,this.d*n.d)},mul:function(v,E){return c(v,E),a(this.s*n.s*this.n*n.n,this.d*n.d)},div:function(v,E){return c(v,E),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(v,E){if(isNaN(this.n)||isNaN(this.d))return new g(NaN);if(v===void 0)return a(this.s*this.n%this.d,1);if(c(v,E),n.n===0&&this.d===0)throw w();return a(this.s*(n.d*this.n)%(n.n*this.d),n.d*this.d)},gcd:function(v,E){return c(v,E),a(d(n.n,this.n)*d(n.d,this.d),n.d*this.d)},lcm:function(v,E){return c(v,E),n.n===0&&this.n===0?a(0,1):a(n.n*this.n,d(n.n,this.n)*d(n.d,this.d))},ceil:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new g(NaN):a(Math.ceil(v*this.s*this.n/this.d),v)},floor:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new g(NaN):a(Math.floor(v*this.s*this.n/this.d),v)},round:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new g(NaN):a(Math.round(v*this.s*this.n/this.d),v)},inverse:function(){return a(this.s*this.d,this.n)},pow:function(v,E){if(c(v,E),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 b=l(this.n),N=l(this.d),x=1,F=1;for(var M in b)if(M!=="1"){if(M==="0"){x=0;break}if(b[M]*=n.n,b[M]%n.d===0)b[M]/=n.d;else return null;x*=Math.pow(M,b[M])}for(var M in N)if(M!=="1"){if(N[M]*=n.n,N[M]%n.d===0)N[M]/=n.d;else return null;F*=Math.pow(M,N[M])}return n.s<0?a(F,x):a(x,F)},equals:function(v,E){return c(v,E),this.s*this.n*n.d===n.s*n.n*this.d},compare:function(v,E){c(v,E);var b=this.s*this.n*n.d-n.s*n.n*this.d;return(0<b)-(b<0)},simplify:function(v){if(isNaN(this.n)||isNaN(this.d))return this;v=v||.001;for(var E=this.abs(),b=E.toContinued(),N=1;N<b.length;N++){for(var x=a(b[N-1],1),F=N-2;F>=0;F--)x=x.inverse().add(b[F]);if(Math.abs(x.sub(E).valueOf())<v)return x.mul(this.s)}return this},divisible:function(v,E){return c(v,E),!(!(n.n*this.d)||this.n*n.d%(n.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(v){var E,b="",N=this.n,x=this.d;return this.s<0&&(b+="-"),x===1?b+=N:(v&&(E=Math.floor(N/x))>0&&(b+=E,b+=" ",N%=x),b+=N,b+="/",b+=x),b},toLatex:function(v){var E,b="",N=this.n,x=this.d;return this.s<0&&(b+="-"),x===1?b+=N:(v&&(E=Math.floor(N/x))>0&&(b+=E,N%=x),b+="\\frac{",b+=N,b+="}{",b+=x,b+="}"),b},toContinued:function(){var v,E=this.n,b=this.d,N=[];if(isNaN(E)||isNaN(b))return N;do N.push(Math.floor(E/b)),v=E%b,E=b,b=v;while(E!==1);return N},toString:function(v){var E=this.n,b=this.d;if(isNaN(E)||isNaN(b))return"NaN";v=v||15;var N=p(E,b),x=f(E,b,N),F=this.s<0?"-":"";if(F+=E/b|0,E%=b,E*=10,E&&(F+="."),N){for(var M=x;M--;)F+=E/b|0,E%=b,E*=10;F+="(";for(var M=N;M--;)F+=E/b|0,E%=b,E*=10;F+=")"}else for(var M=v;E&&M--;)F+=E/b|0,E%=b,E*=10;return F}},Object.defineProperty(g,"__esModule",{value:!0}),g.default=g,g.Fraction=g,i.exports=g})()})(yc);var G_=yc.exports,tn=Zt(G_),K_="Fraction",H_=[],X_=mt(K_,H_,()=>(Object.defineProperty(tn,"name",{value:"Fraction"}),tn.prototype.constructor=tn,tn.prototype.type="Fraction",tn.prototype.isFraction=!0,tn.prototype.toJSON=function(){return{mathjs:"Fraction",n:this.s*this.n,d:this.d}},tn.fromJSON=function(i){return new tn(i)},tn),{isClass:!0}),J_="Matrix",Q_=[],V_=mt(J_,Q_,()=>{function i(){if(!(this instanceof i))throw new SyntaxError("Constructor must be called with the new operator")}return i.prototype.type="Matrix",i.prototype.isMatrix=!0,i.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},i.prototype.datatype=function(){throw new Error("Cannot invoke datatype on a Matrix interface")},i.prototype.create=function(t,e){throw new Error("Cannot invoke create on a Matrix interface")},i.prototype.subset=function(t,e,r){throw new Error("Cannot invoke subset on a Matrix interface")},i.prototype.get=function(t){throw new Error("Cannot invoke get on a Matrix interface")},i.prototype.set=function(t,e,r){throw new Error("Cannot invoke set on a Matrix interface")},i.prototype.resize=function(t,e){throw new Error("Cannot invoke resize on a Matrix interface")},i.prototype.reshape=function(t,e){throw new Error("Cannot invoke reshape on a Matrix interface")},i.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},i.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},i.prototype.map=function(t,e){throw new Error("Cannot invoke map on a Matrix interface")},i.prototype.forEach=function(t){throw new Error("Cannot invoke forEach on a Matrix interface")},i.prototype[Symbol.iterator]=function(){throw new Error("Cannot iterate a Matrix interface")},i.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},i.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},i.prototype.format=function(t){throw new Error("Cannot invoke format on a Matrix interface")},i.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},i},{isClass:!0});function Dc(i){return Object.keys(i.signatures||{}).reduce(function(t,e){var r=(e.match(/,/g)||[]).length+1;return Math.max(t,r)},-1)}var tm="DenseMatrix",em=["Matrix"],rm=mt(tm,em,i=>{var{Matrix:t}=i;function e(p,f){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(f&&!Zr(f))throw new Error("Invalid datatype: "+f);if(fe(p))p.type==="DenseMatrix"?(this._data=re(p._data),this._size=re(p._size),this._datatype=f||p._datatype):(this._data=p.toArray(),this._size=p.size(),this._datatype=f||p._datatype);else if(p&&ve(p.data)&&ve(p.size))this._data=p.data,this._size=p.size,Hl(this._data,this._size),this._datatype=f||p.datatype;else if(ve(p))this._data=h(p),this._size=Fe(this._data),Hl(this._data,this._size),this._datatype=f;else{if(p)throw new TypeError("Unsupported type of data ("+mn(p)+")");this._data=[],this._size=[0],this._datatype=f}}e.prototype=new t,e.prototype.createDenseMatrix=function(p,f){return new e(p,f)},Object.defineProperty(e,"name",{value:"DenseMatrix"}),e.prototype.constructor=e,e.prototype.type="DenseMatrix",e.prototype.isDenseMatrix=!0,e.prototype.getDataType=function(){return As(this._data,mn)},e.prototype.storage=function(){return"dense"},e.prototype.datatype=function(){return this._datatype},e.prototype.create=function(p,f){return new e(p,f)},e.prototype.subset=function(p,f,d){switch(arguments.length){case 1:return r(this,p);case 2:case 3:return s(this,p,f,d);default:throw new SyntaxError("Wrong number of arguments")}},e.prototype.get=function(p){if(!ve(p))throw new TypeError("Array expected");if(p.length!==this._size.length)throw new Gt(p.length,this._size.length);for(var f=0;f<p.length;f++)we(p[f],this._size[f]);for(var d=this._data,g=0,w=p.length;g<w;g++){var m=p[g];we(m,d.length),d=d[m]}return d},e.prototype.set=function(p,f,d){if(!ve(p))throw new TypeError("Array expected");if(p.length<this._size.length)throw new Gt(p.length,this._size.length,"<");var g,w,m,D=p.map(function(E){return E+1});c(this,D,d);var v=this._data;for(g=0,w=p.length-1;g<w;g++)m=p[g],we(m,v.length),v=v[m];return m=p[p.length-1],we(m,v.length),v[m]=f,this};function r(p,f){if(!sa(f))throw new TypeError("Invalid index");var d=f.isScalar();if(d)return p.get(f.min());var g=f.size();if(g.length!==p._size.length)throw new Gt(g.length,p._size.length);for(var w=f.min(),m=f.max(),D=0,v=p._size.length;D<v;D++)we(w[D],p._size[D]),we(m[D],p._size[D]);return new e(n(p._data,f,g.length,0),p._datatype)}function n(p,f,d,g){var w=g===d-1,m=f.dimension(g);return w?m.map(function(D){return we(D,p.length),p[D]}).valueOf():m.map(function(D){we(D,p.length);var v=p[D];return n(v,f,d,g+1)}).valueOf()}function s(p,f,d,g){if(!f||f.isIndex!==!0)throw new TypeError("Invalid index");var w=f.size(),m=f.isScalar(),D;if(fe(d)?(D=d.size(),d=d.valueOf()):D=Fe(d),m){if(D.length!==0)throw new TypeError("Scalar expected");p.set(f.min(),d,g)}else{if(!ai(D,w))try{D.length===0?d=ec([d],w):d=ec(d,w),D=Fe(d)}catch{}if(w.length<p._size.length)throw new Gt(w.length,p._size.length,"<");if(D.length<w.length){for(var v=0,E=0;w[v]===1&&D[v]===1;)v++;for(;w[v]===1;)E++,v++;d=Jl(d,w.length,E,D)}if(!ai(w,D))throw new Gt(w,D,">");var b=f.max().map(function(F){return F+1});c(p,b,g);var N=w.length,x=0;a(p._data,f,d,N,x)}return p}function a(p,f,d,g,w){var m=w===g-1,D=f.dimension(w);m?D.forEach(function(v,E){we(v),p[v]=d[E[0]]}):D.forEach(function(v,E){we(v),a(p[v],f,d[E[0]],g,w+1)})}e.prototype.resize=function(p,f,d){if(!Ui(p))throw new TypeError("Array or Matrix expected");var g=p.valueOf().map(m=>Array.isArray(m)&&m.length===1?m[0]:m),w=d?this.clone():this;return l(w,g,f)};function l(p,f,d){if(f.length===0){for(var g=p._data;ve(g);)g=g[0];return g}return p._size=f.slice(0),p._data=ca(p._data,p._size,d),p}e.prototype.reshape=function(p,f){var d=f?this.clone():this;d._data=ha(d._data,p);var g=d._size.reduce((w,m)=>w*m);return d._size=pa(p,g),d};function c(p,f,d){for(var g=p._size.slice(0),w=!1;g.length<f.length;)g.push(0),w=!0;for(var m=0,D=f.length;m<D;m++)f[m]>g[m]&&(g[m]=f[m],w=!0);w&&l(p,g,d)}e.prototype.clone=function(){var p=new e({data:re(this._data),size:re(this._size),datatype:this._datatype});return p},e.prototype.size=function(){return this._size.slice(0)},e.prototype.map=function(p){var f=this,d=Dc(p),g=function D(v,E){return ve(v)?v.map(function(b,N){return D(b,E.concat(N))}):d===1?p(v):d===2?p(v,E):p(v,E,f)},w=g(this._data,[]),m=this._datatype!==void 0?As(w,mn):void 0;return new e(w,m)},e.prototype.forEach=function(p){var f=this,d=function g(w,m){ve(w)?w.forEach(function(D,v){g(D,m.concat(v))}):p(w,m,f)};d(this._data,[])},e.prototype[Symbol.iterator]=function*(){var p=function*f(d,g){if(ve(d))for(var w=0;w<d.length;w++)yield*f(d[w],g.concat(w));else yield{value:d,index:g}};yield*p(this._data,[])},e.prototype.rows=function(){var p=[],f=this.size();if(f.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");var d=this._data;for(var g of d)p.push(new e([g],this._datatype));return p},e.prototype.columns=function(){var p=this,f=[],d=this.size();if(d.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");for(var g=this._data,w=function(v){var E=g.map(b=>[b[v]]);f.push(new e(E,p._datatype))},m=0;m<d[1];m++)w(m);return f},e.prototype.toArray=function(){return re(this._data)},e.prototype.valueOf=function(){return this._data},e.prototype.format=function(p){return oe(this._data,p)},e.prototype.toString=function(){return oe(this._data)},e.prototype.toJSON=function(){return{mathjs:"DenseMatrix",data:this._data,size:this._size,datatype:this._datatype}},e.prototype.diagonal=function(p){if(p){if(xe(p)&&(p=p.toNumber()),!le(p)||!de(p))throw new TypeError("The parameter k must be an integer number")}else p=0;for(var f=p>0?p:0,d=p<0?-p:0,g=this._size[0],w=this._size[1],m=Math.min(g-d,w-f),D=[],v=0;v<m;v++)D[v]=this._data[v+d][v+f];return new e({data:D,size:[m],datatype:this._datatype})},e.diagonal=function(p,f,d,g){if(!ve(p))throw new TypeError("Array expected, size parameter");if(p.length!==2)throw new Error("Only two dimensions matrix are supported");if(p=p.map(function(M){if(xe(M)&&(M=M.toNumber()),!le(M)||!de(M)||M<1)throw new Error("Size values must be positive integers");return M}),d){if(xe(d)&&(d=d.toNumber()),!le(d)||!de(d))throw new TypeError("The parameter k must be an integer number")}else d=0;var w=d>0?d:0,m=d<0?-d:0,D=p[0],v=p[1],E=Math.min(D-m,v-w),b;if(ve(f)){if(f.length!==E)throw new Error("Invalid value array length");b=function(S){return f[S]}}else if(fe(f)){var N=f.size();if(N.length!==1||N[0]!==E)throw new Error("Invalid matrix length");b=function(S){return f.get([S])}}else b=function(){return f};g||(g=xe(b(0))?b(0).mul(0):0);var x=[];if(p.length>0){x=ca(x,p,g);for(var F=0;F<E;F++)x[F+m][F+w]=b(F)}return new e({data:x,size:[D,v]})},e.fromJSON=function(p){return new e(p)},e.prototype.swapRows=function(p,f){if(!le(p)||!de(p)||!le(f)||!de(f))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return we(p,this._size[0]),we(f,this._size[0]),e._swapRows(p,f,this._data),this},e._swapRows=function(p,f,d){var g=d[p];d[p]=d[f],d[f]=g};function h(p){return fe(p)?h(p.valueOf()):ve(p)?p.map(h):p}return e},{isClass:!0});function nm(i){var t=i.length,e=i[0].length,r,n,s=[];for(n=0;n<e;n++){var a=[];for(r=0;r<t;r++)a.push(i[r][n]);s.push(a)}return s}function $s(i){for(var t=0;t<i.length;t++)if(Ui(i[t]))return!0;return!1}function Yi(i,t){fe(i)&&(i=i.valueOf());for(var e=0,r=i.length;e<r;e++){var n=i[e];Array.isArray(n)?Yi(n,t):t(n)}}function Rr(i,t,e){return i&&typeof i.map=="function"?i.map(function(r){return Rr(r,t)}):t(i)}function Ea(i,t,e){var r=Array.isArray(i)?Fe(i):i.size();if(t<0||t>=r.length)throw new gn(t,r.length);return fe(i)?i.create(Ls(i.valueOf(),t,e)):Ls(i,t,e)}function Ls(i,t,e){var r,n,s,a;if(t<=0)if(Array.isArray(i[0])){for(a=nm(i),n=[],r=0;r<a.length;r++)n[r]=Ls(a[r],t-1,e);return n}else{for(s=i[0],r=1;r<i.length;r++)s=e(s,i[r]);return s}else{for(n=[],r=0;r<i.length;r++)n[r]=Ls(i[r],t-1,e);return n}}var bc="isInteger",im=["typed"],sm=mt(bc,im,i=>{var{typed:t}=i;return t(bc,{number:de,BigNumber:function(r){return r.isInt()},Fraction:function(r){return r.d===1&&isFinite(r.n)},"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Ec="number",Rs="number, number";function xc(i){return Math.abs(i)}xc.signature=Ec;function Ac(i,t){return i+t}Ac.signature=Rs;function Cc(i,t){return i-t}Cc.signature=Rs;function Fc(i,t){return i*t}Fc.signature=Rs;function Mc(i){return-i}Mc.signature=Ec;function Nc(i,t){return i*i<1&&t===1/0||i*i>1&&t===-1/0?0:Math.pow(i,t)}Nc.signature=Rs;var Sc="number";function Bc(i){return i===0}Bc.signature=Sc;function Tc(i){return Number.isNaN(i)}Tc.signature=Sc;var Oc="isNumeric",om=["typed"],am=mt(Oc,om,i=>{var{typed:t}=i;return t(Oc,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Ic="isZero",um=["typed"],lm=mt(Ic,um,i=>{var{typed:t}=i;return t(Ic,{number:Bc,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:t.referToSelf(e=>r=>t.find(e,r.valueType())(r.value)),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),$c="isNaN",cm=["typed"],fm=mt($c,cm,i=>{var{typed:t}=i;return t($c,{number:Tc,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 Rr(r,Number.isNaN)}})});function Ps(i,t,e){if(e==null)return i.eq(t);if(i.eq(t))return!0;if(i.isNaN()||t.isNaN())return!1;if(i.isFinite()&&t.isFinite()){var r=i.minus(t).abs();if(r.isZero())return!0;var n=i.constructor.max(i.abs(),t.abs());return r.lte(n.times(e))}return!1}function hm(i,t,e){return Wn(i.re,t.re,e)&&Wn(i.im,t.im,e)}var zs=mt("compareUnits",["typed"],i=>{var{typed:t}=i;return{"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return t.find(e,[r.valueType(),n.valueType()])(r.value,n.value)})}}),qs="equalScalar",pm=["typed","config"],dm=mt(qs,pm,i=>{var{typed:t,config:e}=i,r=zs({typed:t});return t(qs,{"boolean, boolean":function(s,a){return s===a},"number, number":function(s,a){return Wn(s,a,e.epsilon)},"BigNumber, BigNumber":function(s,a){return s.eq(a)||Ps(s,a,e.epsilon)},"Fraction, Fraction":function(s,a){return s.equals(a)},"Complex, Complex":function(s,a){return hm(s,a,e.epsilon)}},r)});mt(qs,["typed","config"],i=>{var{typed:t,config:e}=i;return t(qs,{"number, number":function(n,s){return Wn(n,s,e.epsilon)}})});var _m="SparseMatrix",mm=["typed","equalScalar","Matrix"],gm=mt(_m,mm,i=>{var{typed:t,equalScalar:e,Matrix:r}=i;function n(m,D){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(D&&!Zr(D))throw new Error("Invalid datatype: "+D);if(fe(m))s(this,m,D);else if(m&&ve(m.index)&&ve(m.ptr)&&ve(m.size))this._values=m.values,this._index=m.index,this._ptr=m.ptr,this._size=m.size,this._datatype=D||m.datatype;else if(ve(m))a(this,m,D);else{if(m)throw new TypeError("Unsupported type of data ("+mn(m)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=D}}function s(m,D,v){D.type==="SparseMatrix"?(m._values=D._values?re(D._values):void 0,m._index=re(D._index),m._ptr=re(D._ptr),m._size=re(D._size),m._datatype=v||D._datatype):a(m,D.valueOf(),v||D._datatype)}function a(m,D,v){m._values=[],m._index=[],m._ptr=[],m._datatype=v;var E=D.length,b=0,N=e,x=0;if(Zr(v)&&(N=t.find(e,[v,v])||e,x=t.convert(0,v)),E>0){var F=0;do{m._ptr.push(m._index.length);for(var M=0;M<E;M++){var S=D[M];if(ve(S)){if(F===0&&b<S.length&&(b=S.length),F<S.length){var I=S[F];N(I,x)||(m._values.push(I),m._index.push(M))}}else F===0&&b<1&&(b=1),N(S,x)||(m._values.push(S),m._index.push(M))}F++}while(F<b)}m._ptr.push(m._index.length),m._size=[E,b]}n.prototype=new r,n.prototype.createSparseMatrix=function(m,D){return new n(m,D)},Object.defineProperty(n,"name",{value:"SparseMatrix"}),n.prototype.constructor=n,n.prototype.type="SparseMatrix",n.prototype.isSparseMatrix=!0,n.prototype.getDataType=function(){return As(this._values,mn)},n.prototype.storage=function(){return"sparse"},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(m,D){return new n(m,D)},n.prototype.density=function(){var m=this._size[0],D=this._size[1];return m!==0&&D!==0?this._index.length/(m*D):0},n.prototype.subset=function(m,D,v){if(!this._values)throw new Error("Cannot invoke subset on a Pattern only matrix");switch(arguments.length){case 1:return l(this,m);case 2:case 3:return c(this,m,D,v);default:throw new SyntaxError("Wrong number of arguments")}};function l(m,D){if(!sa(D))throw new TypeError("Invalid index");var v=D.isScalar();if(v)return m.get(D.min());var E=D.size();if(E.length!==m._size.length)throw new Gt(E.length,m._size.length);var b,N,x,F,M=D.min(),S=D.max();for(b=0,N=m._size.length;b<N;b++)we(M[b],m._size[b]),we(S[b],m._size[b]);var I=m._values,C=m._index,T=m._ptr,L=D.dimension(0),U=D.dimension(1),k=[],W=[];L.forEach(function(Q,tt){W[Q]=tt[0],k[Q]=!0});var P=I?[]:void 0,K=[],G=[];return U.forEach(function(Q){for(G.push(K.length),x=T[Q],F=T[Q+1];x<F;x++)b=C[x],k[b]===!0&&(K.push(W[b]),P&&P.push(I[x]))}),G.push(K.length),new n({values:P,index:K,ptr:G,size:E,datatype:m._datatype})}function c(m,D,v,E){if(!D||D.isIndex!==!0)throw new TypeError("Invalid index");var b=D.size(),N=D.isScalar(),x;if(fe(v)?(x=v.size(),v=v.toArray()):x=Fe(v),N){if(x.length!==0)throw new TypeError("Scalar expected");m.set(D.min(),v,E)}else{if(b.length!==1&&b.length!==2)throw new Gt(b.length,m._size.length,"<");if(x.length<b.length){for(var F=0,M=0;b[F]===1&&x[F]===1;)F++;for(;b[F]===1;)M++,F++;v=Jl(v,b.length,M,x)}if(!ai(b,x))throw new Gt(b,x,">");if(b.length===1){var S=D.dimension(0);S.forEach(function(T,L){we(T),m.set([T,0],v[L[0]],E)})}else{var I=D.dimension(0),C=D.dimension(1);I.forEach(function(T,L){we(T),C.forEach(function(U,k){we(U),m.set([T,U],v[L[0]][k[0]],E)})})}}return m}n.prototype.get=function(m){if(!ve(m))throw new TypeError("Array expected");if(m.length!==this._size.length)throw new Gt(m.length,this._size.length);if(!this._values)throw new Error("Cannot invoke get on a Pattern only matrix");var D=m[0],v=m[1];we(D,this._size[0]),we(v,this._size[1]);var E=h(D,this._ptr[v],this._ptr[v+1],this._index);return E<this._ptr[v+1]&&this._index[E]===D?this._values[E]:0},n.prototype.set=function(m,D,v){if(!ve(m))throw new TypeError("Array expected");if(m.length!==this._size.length)throw new Gt(m.length,this._size.length);if(!this._values)throw new Error("Cannot invoke set on a Pattern only matrix");var E=m[0],b=m[1],N=this._size[0],x=this._size[1],F=e,M=0;Zr(this._datatype)&&(F=t.find(e,[this._datatype,this._datatype])||e,M=t.convert(0,this._datatype)),(E>N-1||b>x-1)&&(d(this,Math.max(E+1,N),Math.max(b+1,x),v),N=this._size[0],x=this._size[1]),we(E,N),we(b,x);var S=h(E,this._ptr[b],this._ptr[b+1],this._index);return S<this._ptr[b+1]&&this._index[S]===E?F(D,M)?p(S,b,this._values,this._index,this._ptr):this._values[S]=D:F(D,M)||f(S,E,b,D,this._values,this._index,this._ptr),this};function h(m,D,v,E){if(v-D===0)return v;for(var b=D;b<v;b++)if(E[b]===m)return b;return D}function p(m,D,v,E,b){v.splice(m,1),E.splice(m,1);for(var N=D+1;N<b.length;N++)b[N]--}function f(m,D,v,E,b,N,x){b.splice(m,0,E),N.splice(m,0,D);for(var F=v+1;F<x.length;F++)x[F]++}n.prototype.resize=function(m,D,v){if(!Ui(m))throw new TypeError("Array or Matrix expected");var E=m.valueOf().map(N=>Array.isArray(N)&&N.length===1?N[0]:N);if(E.length!==2)throw new Error("Only two dimensions matrix are supported");E.forEach(function(N){if(!le(N)||!de(N)||N<0)throw new TypeError("Invalid size, must contain positive integers (size: "+oe(E)+")")});var b=v?this.clone():this;return d(b,E[0],E[1],D)};function d(m,D,v,E){var b=E||0,N=e,x=0;Zr(m._datatype)&&(N=t.find(e,[m._datatype,m._datatype])||e,x=t.convert(0,m._datatype),b=t.convert(b,m._datatype));var F=!N(b,x),M=m._size[0],S=m._size[1],I,C,T;if(v>S){for(C=S;C<v;C++)if(m._ptr[C]=m._values.length,F)for(I=0;I<M;I++)m._values.push(b),m._index.push(I);m._ptr[v]=m._values.length}else v<S&&(m._ptr.splice(v+1,S-v),m._values.splice(m._ptr[v],m._values.length),m._index.splice(m._ptr[v],m._index.length));if(S=v,D>M){if(F){var L=0;for(C=0;C<S;C++){m._ptr[C]=m._ptr[C]+L,T=m._ptr[C+1]+L;var U=0;for(I=M;I<D;I++,U++)m._values.splice(T+U,0,b),m._index.splice(T+U,0,I),L++}m._ptr[S]=m._values.length}}else if(D<M){var k=0;for(C=0;C<S;C++){m._ptr[C]=m._ptr[C]-k;var W=m._ptr[C],P=m._ptr[C+1]-k;for(T=W;T<P;T++)I=m._index[T],I>D-1&&(m._values.splice(T,1),m._index.splice(T,1),k++)}m._ptr[C]=m._values.length}return m._size[0]=D,m._size[1]=v,m}n.prototype.reshape=function(m,D){if(!ve(m))throw new TypeError("Array expected");if(m.length!==2)throw new Error("Sparse matrices can only be reshaped in two dimensions");m.forEach(function(Q){if(!le(Q)||!de(Q)||Q<=-2||Q===0)throw new TypeError("Invalid size, must contain positive integers or -1 (size: "+oe(m)+")")});var v=this._size[0]*this._size[1];m=pa(m,v);var E=m[0]*m[1];if(v!==E)throw new Error("Reshaping sparse matrix will result in the wrong number of elements");var b=D?this.clone():this;if(this._size[0]===m[0]&&this._size[1]===m[1])return b;for(var N=[],x=0;x<b._ptr.length;x++)for(var F=0;F<b._ptr[x+1]-b._ptr[x];F++)N.push(x);for(var M=b._values.slice(),S=b._index.slice(),I=0;I<b._index.length;I++){var C=S[I],T=N[I],L=C*b._size[1]+T;N[I]=L%m[1],S[I]=Math.floor(L/m[1])}b._values.length=0,b._index.length=0,b._ptr.length=m[1]+1,b._size=m.slice();for(var U=0;U<b._ptr.length;U++)b._ptr[U]=0;for(var k=0;k<M.length;k++){var W=S[k],P=N[k],K=M[k],G=h(W,b._ptr[P],b._ptr[P+1],b._index);f(G,W,P,K,b._values,b._index,b._ptr)}return b},n.prototype.clone=function(){var m=new n({values:this._values?re(this._values):void 0,index:re(this._index),ptr:re(this._ptr),size:re(this._size),datatype:this._datatype});return m},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(m,D){if(!this._values)throw new Error("Cannot invoke map on a Pattern only matrix");var v=this,E=this._size[0],b=this._size[1],N=Dc(m),x=function(M,S,I){return N===1?m(M):N===2?m(M,[S,I]):m(M,[S,I],v)};return g(this,0,E-1,0,b-1,x,D)};function g(m,D,v,E,b,N,x){var F=[],M=[],S=[],I=e,C=0;Zr(m._datatype)&&(I=t.find(e,[m._datatype,m._datatype])||e,C=t.convert(0,m._datatype));for(var T=function(lt,yt,bt){lt=N(lt,yt,bt),I(lt,C)||(F.push(lt),M.push(yt))},L=E;L<=b;L++){S.push(F.length);var U=m._ptr[L],k=m._ptr[L+1];if(x)for(var W=U;W<k;W++){var P=m._index[W];P>=D&&P<=v&&T(m._values[W],P-D,L-E)}else{for(var K={},G=U;G<k;G++){var Q=m._index[G];K[Q]=m._values[G]}for(var tt=D;tt<=v;tt++){var ct=tt in K?K[tt]:0;T(ct,tt-D,L-E)}}}return S.push(F.length),new n({values:F,index:M,ptr:S,size:[v-D+1,b-E+1]})}n.prototype.forEach=function(m,D){if(!this._values)throw new Error("Cannot invoke forEach on a Pattern only matrix");for(var v=this,E=this._size[0],b=this._size[1],N=0;N<b;N++){var x=this._ptr[N],F=this._ptr[N+1];if(D)for(var M=x;M<F;M++){var S=this._index[M];m(this._values[M],[S,N],v)}else{for(var I={},C=x;C<F;C++){var T=this._index[C];I[T]=this._values[C]}for(var L=0;L<E;L++){var U=L in I?I[L]:0;m(U,[L,N],v)}}}},n.prototype[Symbol.iterator]=function*(){if(!this._values)throw new Error("Cannot iterate a Pattern only matrix");for(var m=this._size[1],D=0;D<m;D++)for(var v=this._ptr[D],E=this._ptr[D+1],b=v;b<E;b++){var N=this._index[b];yield{value:this._values[b],index:[N,D]}}},n.prototype.toArray=function(){return w(this._values,this._index,this._ptr,this._size,!0)},n.prototype.valueOf=function(){return w(this._values,this._index,this._ptr,this._size,!1)};function w(m,D,v,E,b){var N=E[0],x=E[1],F=[],M,S;for(M=0;M<N;M++)for(F[M]=[],S=0;S<x;S++)F[M][S]=0;for(S=0;S<x;S++)for(var I=v[S],C=v[S+1],T=I;T<C;T++)M=D[T],F[M][S]=m?b?re(m[T]):m[T]:1;return F}return n.prototype.format=function(m){for(var D=this._size[0],v=this._size[1],E=this.density(),b="Sparse Matrix ["+oe(D,m)+" x "+oe(v,m)+"] density: "+oe(E,m)+`
|
53
53
|
`,N=0;N<v;N++)for(var x=this._ptr[N],F=this._ptr[N+1],M=x;M<F;M++){var S=this._index[M];b+=`
|
54
|
-
(`+oe(S,m)+", "+oe(N,m)+") ==> "+(this._values?oe(this._values[M],m):"X")}return b},n.prototype.toString=function(){return oe(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(m){if(m){if(xe(m)&&(m=m.toNumber()),!le(m)||!de(m))throw new TypeError("The parameter k must be an integer number")}else m=0;var D=m>0?m:0,v=m<0?-m:0,E=this._size[0],b=this._size[1],N=Math.min(E-v,b-D),x=[],F=[],M=[];M[0]=0;for(var S=D;S<b&&x.length<N;S++)for(var I=this._ptr[S],C=this._ptr[S+1],T=I;T<C;T++){var L=this._index[T];if(L===S-D+v){x.push(this._values[T]),F[x.length-1]=L-v;break}}return M.push(x.length),new n({values:x,index:F,ptr:M,size:[N,1]})},n.fromJSON=function(m){return new n(m)},n.diagonal=function(m,D,v,E,b){if(!ve(m))throw new TypeError("Array expected, size parameter");if(m.length!==2)throw new Error("Only two dimensions matrix are supported");if(m=m.map(function(Q){if(xe(Q)&&(Q=Q.toNumber()),!le(Q)||!de(Q)||Q<1)throw new Error("Size values must be positive integers");return Q}),v){if(xe(v)&&(v=v.toNumber()),!le(v)||!de(v))throw new TypeError("The parameter k must be an integer number")}else v=0;var N=e,x=0;Zr(b)&&(N=t.find(e,[b,b])||e,x=t.convert(0,b));var F=v>0?v:0,M=v<0?-v:0,S=m[0],I=m[1],C=Math.min(S-M,I-F),T;if(ve(D)){if(D.length!==C)throw new Error("Invalid value array length");T=function(tt){return D[tt]}}else if(fe(D)){var L=D.size();if(L.length!==1||L[0]!==C)throw new Error("Invalid matrix length");T=function(tt){return D.get([tt])}}else T=function(){return D};for(var U=[],k=[],W=[],P=0;P<I;P++){W.push(U.length);var K=P-F;if(K>=0&&K<C){var G=T(K);N(G,x)||(k.push(K+M),U.push(G))}}return W.push(U.length),new n({values:U,index:k,ptr:W,size:[S,I]})},n.prototype.swapRows=function(m,D){if(!le(m)||!de(m)||!le(D)||!de(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 we(m,this._size[0]),we(D,this._size[0]),n._swapRows(m,D,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(m,D,v,E,b){for(var N=E[m],x=E[m+1],F=N;F<x;F++)b(v[F],D[F])},n._swapRows=function(m,D,v,E,b,N){for(var x=0;x<v;x++){var F=N[x],M=N[x+1],S=h(m,F,M,b),I=h(D,F,M,b);if(S<M&&I<M&&b[S]===m&&b[I]===D){if(E){var C=E[S];E[S]=E[I],E[I]=C}continue}if(S<M&&b[S]===m&&(I>=M||b[I]!==D)){var T=E?E[S]:void 0;b.splice(I,0,D),E&&E.splice(I,0,T),b.splice(I<=S?S+1:S,1),E&&E.splice(I<=S?S+1:S,1);continue}if(I<M&&b[I]===D&&(S>=M||b[S]!==m)){var L=E?E[I]:void 0;b.splice(S,0,m),E&&E.splice(S,0,L),b.splice(S<=I?I+1:I,1),E&&E.splice(S<=I?I+1:I,1)}}},n},{isClass:!0}),vm="number",wm=["typed"];function ym(i){var t=i.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(t){var e={"0b":2,"0o":8,"0x":16}[t[1]],r=t[2],n=t[3];return{input:i,radix:e,integerPart:r,fractionalPart:n}}else return null}function Dm(i){for(var t=parseInt(i.integerPart,i.radix),e=0,r=0;r<i.fractionalPart.length;r++){var n=parseInt(i.fractionalPart[r],i.radix);e+=n/Math.pow(i.radix,r+1)}var s=t+e;if(isNaN(s))throw new SyntaxError('String "'+i.input+'" is not a valid number');return s}var bm=mt(vm,wm,i=>{var{typed:t}=i,e=t("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var s=ym(n);if(s)return Dm(s);var a=0,l=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);l&&(a=Number(l[2]),n=l[1]);var c=Number(n);if(isNaN(c))throw new SyntaxError('String "'+n+'" is not a valid number');if(l){if(c>2**a-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));c>=2**(a-1)&&(c=c-2**a)}return c},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),null:function(n){return 0},"Unit, string | Unit":function(n,s){return n.toNumber(s)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))});return e.fromJSON=function(r){return parseFloat(r.value)},e}),Em="bignumber",xm=["typed","BigNumber"],Am=mt(Em,xm,i=>{var{typed:t,BigNumber:e}=i;return t("bignumber",{"":function(){return new e(0)},number:function(n){return new e(n+"")},string:function(n){var s=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(s){var a=s[2],l=e(s[1]),c=new e(2).pow(Number(a));if(l.gt(c.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var h=new e(2).pow(Number(a)-1);return l.gte(h)?l.sub(c):l}return new e(n)},BigNumber:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Fraction:function(n){return new e(n.n).div(n.d).times(n.s)},null:function(n){return new e(0)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))})}),Cm="fraction",Fm=["typed","Fraction"],Mm=mt(Cm,Fm,i=>{var{typed:t,Fraction:e}=i;return t("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new e(n)},string:function(n){return new e(n)},"number, number":function(n,s){return new e(n,s)},null:function(n){return new e(0)},BigNumber:function(n){return new e(n.toString())},Fraction:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Object:function(n){return new e(n)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))})}),Lc="matrix",Nm=["typed","Matrix","DenseMatrix","SparseMatrix"],Sm=mt(Lc,Nm,i=>{var{typed:t,Matrix:e,DenseMatrix:r,SparseMatrix:n}=i;return t(Lc,{"":function(){return s([])},string:function(l){return s([],l)},"string, string":function(l,c){return s([],l,c)},Array:function(l){return s(l)},Matrix:function(l){return s(l,l.storage())},"Array | Matrix, string":s,"Array | Matrix, string, string":s});function s(a,l,c){if(l==="dense"||l==="default"||l===void 0)return new r(a,c);if(l==="sparse")return new n(a,c);throw new TypeError("Unknown matrix type "+JSON.stringify(l)+".")}}),Rc="unaryMinus",Bm=["typed"],Tm=mt(Rc,Bm,i=>{var{typed:t}=i;return t(Rc,{number:Mc,"Complex | BigNumber | Fraction":e=>e.neg(),Unit:t.referToSelf(e=>r=>{var n=r.clone();return n.value=t.find(e,n.valueType())(r.value),n}),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Pc="abs",Om=["typed"],Im=mt(Pc,Om,i=>{var{typed:t}=i;return t(Pc,{number:xc,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),zc="addScalar",$m=["typed"],Lm=mt(zc,$m,i=>{var{typed:t}=i;return t(zc,{"number, number":Ac,"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":t.referToSelf(e=>(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 s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),qc="subtractScalar",Rm=["typed"],Pm=mt(qc,Rm,i=>{var{typed:t}=i;return t(qc,{"number, number":Cc,"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":t.referToSelf(e=>(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 s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),zm="matAlgo11xS0s",qm=["typed","equalScalar"],xa=mt(zm,qm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=e,v=0,E=a;typeof d=="string"&&(m=d,D=t.find(e,[m,m]),v=t.convert(0,m),s=t.convert(s,m),E=t.find(a,[m,m]));for(var b=[],N=[],x=[],F=0;F<w;F++){x[F]=N.length;for(var M=p[F],S=p[F+1],I=M;I<S;I++){var C=h[I],T=l?E(s,c[I]):E(c[I],s);D(T,v)||(N.push(C),b.push(T))}}return x[w]=N.length,n.createSparseMatrix({values:b,index:N,ptr:x,size:[g,w],datatype:m})}}),km="matAlgo12xSfs",Um=["typed","DenseMatrix"],pi=mt(km,Um,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=a;typeof d=="string"&&(m=d,s=t.convert(s,m),D=t.find(a,[m,m]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=p[N],M=p[N+1],S=F;S<M;S++){var I=h[S];E[I]=c[S],b[I]=x}for(var C=0;C<g;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?D(s,E[C]):D(E[C],s):v[C][N]=l?D(s,0):D(0,s)}return new e({data:v,size:[g,w],datatype:m})}}),Wm="matAlgo14xDs",jm=["typed"],Aa=mt(Wm,jm,i=>{var{typed:t}=i;return function(n,s,a,l){var c=n._data,h=n._size,p=n._datatype,f,d=a;typeof p=="string"&&(f=p,s=t.convert(s,f),d=t.find(a,[f,f]));var g=h.length>0?e(d,0,h,h[0],c,s,l):[];return n.createDenseMatrix({data:g,size:re(h),datatype:f})};function e(r,n,s,a,l,c,h){var p=[];if(n===s.length-1)for(var f=0;f<a;f++)p[f]=h?r(c,l[f]):r(l[f],c);else for(var d=0;d<a;d++)p[d]=e(r,n+1,s,s[n+1],l[d],c,h);return p}}),Ym="matAlgo02xDS0",Zm=["typed","equalScalar"],Gm=mt(Ym,Zm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a,l){var c=n._data,h=n._size,p=n._datatype||n.getDataType(),f=s._values,d=s._index,g=s._ptr,w=s._size,m=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==w.length)throw new Gt(h.length,w.length);if(h[0]!==w[0]||h[1]!==w[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+w+")");if(!f)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var D=h[0],v=h[1],E,b=e,N=0,x=a;typeof p=="string"&&p===m&&p!=="mixed"&&(E=p,b=t.find(e,[E,E]),N=t.convert(0,E),x=t.find(a,[E,E]));for(var F=[],M=[],S=[],I=0;I<v;I++){S[I]=M.length;for(var C=g[I],T=g[I+1],L=C;L<T;L++){var U=d[L],k=l?x(f[L],c[U][I]):x(c[U][I],f[L]);b(k,N)||(M.push(U),F.push(k))}}return S[v]=M.length,s.createSparseMatrix({values:F,index:M,ptr:S,size:[D,v],datatype:p===n._datatype&&m===s._datatype?E:void 0})}}),Km="matAlgo03xDSf",Hm=["typed"],di=mt(Km,Hm,i=>{var{typed:t}=i;return function(r,n,s,a){var l=r._data,c=r._size,h=r._datatype||r.getDataType(),p=n._values,f=n._index,d=n._ptr,g=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==g.length)throw new Gt(c.length,g.length);if(c[0]!==g[0]||c[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+g+")");if(!p)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var m=c[0],D=c[1],v,E=0,b=s;typeof h=="string"&&h===w&&h!=="mixed"&&(v=h,E=t.convert(0,v),b=t.find(s,[v,v]));for(var N=[],x=0;x<m;x++)N[x]=[];for(var F=[],M=[],S=0;S<D;S++){for(var I=S+1,C=d[S],T=d[S+1],L=C;L<T;L++){var U=f[L];F[U]=a?b(p[L],l[U][S]):b(l[U][S],p[L]),M[U]=I}for(var k=0;k<m;k++)M[k]===I?N[k][S]=F[k]:N[k][S]=a?b(E,l[k][S]):b(l[k][S],E)}return r.createDenseMatrix({data:N,size:[m,D],datatype:h===r._datatype&&w===n._datatype?v:void 0})}}),Xm="matAlgo05xSfSf",Jm=["typed","equalScalar"],kc=mt(Xm,Jm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a){var l=n._values,c=n._index,h=n._ptr,p=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType(),d=s._values,g=s._index,w=s._ptr,m=s._size,D=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==m.length)throw new Gt(p.length,m.length);if(p[0]!==m[0]||p[1]!==m[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+m+")");var v=p[0],E=p[1],b,N=e,x=0,F=a;typeof f=="string"&&f===D&&f!=="mixed"&&(b=f,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(a,[b,b]));var M=l&&d?[]:void 0,S=[],I=[],C=M?[]:void 0,T=M?[]:void 0,L=[],U=[],k,W,P,K;for(W=0;W<E;W++){I[W]=S.length;var G=W+1;for(P=h[W],K=h[W+1];P<K;P++)k=c[P],S.push(k),L[k]=G,C&&(C[k]=l[P]);for(P=w[W],K=w[W+1];P<K;P++)k=g[P],L[k]!==G&&S.push(k),U[k]=G,T&&(T[k]=d[P]);if(M)for(P=I[W];P<S.length;){k=S[P];var Q=L[k],tt=U[k];if(Q===G||tt===G){var ct=Q===G?C[k]:x,vt=tt===G?T[k]:x,lt=F(ct,vt);N(lt,x)?S.splice(P,1):(M.push(lt),P++)}}}return I[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:I,size:[v,E],datatype:f===n._datatype&&D===s._datatype?b:void 0})}}),Qm="matAlgo13xDD",Vm=["typed"],tg=mt(Qm,Vm,i=>{var{typed:t}=i;return function(n,s,a){var l=n._data,c=n._size,h=n._datatype,p=s._data,f=s._size,d=s._datatype,g=[];if(c.length!==f.length)throw new Gt(c.length,f.length);for(var w=0;w<c.length;w++){if(c[w]!==f[w])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+f+")");g[w]=c[w]}var m,D=a;typeof h=="string"&&h===d&&(m=h,D=t.find(a,[m,m]));var v=g.length>0?e(D,0,g,g[0],l,p):[];return n.createDenseMatrix({data:v,size:g,datatype:m})};function e(r,n,s,a,l,c){var h=[];if(n===s.length-1)for(var p=0;p<a;p++)h[p]=r(l[p],c[p]);else for(var f=0;f<a;f++)h[f]=e(r,n+1,s,s[n+1],l[f],c[f]);return h}}),eg="broadcast",rg=["concat"],ng=mt(eg,rg,i=>{var{concat:t}=i;return function(n,s){var a=Math.max(n._size.length,s._size.length);if(n._size.length===s._size.length&&n._size.every((w,m)=>w===s._size[m]))return[n,s];for(var l=e(n._size,a,0),c=e(s._size,a,0),h=[],p=0;p<a;p++)h[p]=Math.max(l[p],c[p]);Cs(l,h),Cs(c,h);var f=n.clone(),d=s.clone();f._size.length<a?f.reshape(e(f._size,a,1)):d._size.length<a&&d.reshape(e(d._size,a,1));for(var g=0;g<a;g++)f._size[g]<h[g]&&(f=r(f,h[g],g)),d._size[g]<h[g]&&(d=r(d,h[g],g));return[f,d]};function e(n,s,a){return[...Array(s-n.length).fill(a),...n]}function r(n,s,a){return t(...Array(s).fill(n),a)}}),ig="matrixAlgorithmSuite",sg=["typed","matrix","concat"],jn=mt(ig,sg,i=>{var{typed:t,matrix:e,concat:r}=i,n=tg({typed:t}),s=Aa({typed:t}),a=ng({concat:r});return function(c){var h=c.elop,p=c.SD||c.DS,f;h?(f={"DenseMatrix, DenseMatrix":(m,D)=>n(...a(m,D),h),"Array, Array":(m,D)=>n(...a(e(m),e(D)),h).valueOf(),"Array, DenseMatrix":(m,D)=>n(...a(e(m),D),h),"DenseMatrix, Array":(m,D)=>n(...a(m,e(D)),h)},c.SS&&(f["SparseMatrix, SparseMatrix"]=(m,D)=>c.SS(...a(m,D),h,!1)),c.DS&&(f["DenseMatrix, SparseMatrix"]=(m,D)=>c.DS(...a(m,D),h,!1),f["Array, SparseMatrix"]=(m,D)=>c.DS(...a(e(m),D),h,!1)),p&&(f["SparseMatrix, DenseMatrix"]=(m,D)=>p(...a(D,m),h,!0),f["SparseMatrix, Array"]=(m,D)=>p(...a(e(D),m),h,!0))):(f={"DenseMatrix, DenseMatrix":t.referToSelf(m=>(D,v)=>n(...a(D,v),m)),"Array, Array":t.referToSelf(m=>(D,v)=>n(...a(e(D),e(v)),m).valueOf()),"Array, DenseMatrix":t.referToSelf(m=>(D,v)=>n(...a(e(D),v),m)),"DenseMatrix, Array":t.referToSelf(m=>(D,v)=>n(...a(D,e(v)),m))},c.SS&&(f["SparseMatrix, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.SS(...a(D,v),m,!1))),c.DS&&(f["DenseMatrix, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.DS(...a(D,v),m,!1)),f["Array, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.DS(...a(e(D),v),m,!1))),p&&(f["SparseMatrix, DenseMatrix"]=t.referToSelf(m=>(D,v)=>p(...a(v,D),m,!0)),f["SparseMatrix, Array"]=t.referToSelf(m=>(D,v)=>p(...a(e(v),D),m,!0))));var d=c.scalar||"any",g=c.Ds||c.Ss;g&&(h?(f["DenseMatrix,"+d]=(m,D)=>s(m,D,h,!1),f[d+", DenseMatrix"]=(m,D)=>s(D,m,h,!0),f["Array,"+d]=(m,D)=>s(e(m),D,h,!1).valueOf(),f[d+", Array"]=(m,D)=>s(e(D),m,h,!0).valueOf()):(f["DenseMatrix,"+d]=t.referToSelf(m=>(D,v)=>s(D,v,m,!1)),f[d+", DenseMatrix"]=t.referToSelf(m=>(D,v)=>s(v,D,m,!0)),f["Array,"+d]=t.referToSelf(m=>(D,v)=>s(e(D),v,m,!1).valueOf()),f[d+", Array"]=t.referToSelf(m=>(D,v)=>s(e(v),D,m,!0).valueOf())));var w=c.sS!==void 0?c.sS:c.Ss;return h?(c.Ss&&(f["SparseMatrix,"+d]=(m,D)=>c.Ss(m,D,h,!1)),w&&(f[d+", SparseMatrix"]=(m,D)=>w(D,m,h,!0))):(c.Ss&&(f["SparseMatrix,"+d]=t.referToSelf(m=>(D,v)=>c.Ss(D,v,m,!1))),w&&(f[d+", SparseMatrix"]=t.referToSelf(m=>(D,v)=>w(v,D,m,!0)))),h&&h.signatures&&Il(f,h.signatures),f}}),og="matAlgo01xDSid",ag=["typed"],Uc=mt(og,ag,i=>{var{typed:t}=i;return function(r,n,s,a){var l=r._data,c=r._size,h=r._datatype||r.getDataType(),p=n._values,f=n._index,d=n._ptr,g=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==g.length)throw new Gt(c.length,g.length);if(c[0]!==g[0]||c[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+g+")");if(!p)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var m=c[0],D=c[1],v=typeof h=="string"&&h!=="mixed"&&h===w?h:void 0,E=v?t.find(s,[v,v]):s,b,N,x=[];for(b=0;b<m;b++)x[b]=[];var F=[],M=[];for(N=0;N<D;N++){for(var S=N+1,I=d[N],C=d[N+1],T=I;T<C;T++)b=f[T],F[b]=a?E(p[T],l[b][N]):E(l[b][N],p[T]),M[b]=S;for(b=0;b<m;b++)M[b]===S?x[b][N]=F[b]:x[b][N]=l[b][N]}return r.createDenseMatrix({data:x,size:[m,D],datatype:h===r._datatype&&w===n._datatype?v:void 0})}}),ug="matAlgo04xSidSid",lg=["typed","equalScalar"],cg=mt(ug,lg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a){var l=n._values,c=n._index,h=n._ptr,p=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType(),d=s._values,g=s._index,w=s._ptr,m=s._size,D=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==m.length)throw new Gt(p.length,m.length);if(p[0]!==m[0]||p[1]!==m[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+m+")");var v=p[0],E=p[1],b,N=e,x=0,F=a;typeof f=="string"&&f===D&&f!=="mixed"&&(b=f,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(a,[b,b]));var M=l&&d?[]:void 0,S=[],I=[],C=l&&d?[]:void 0,T=l&&d?[]:void 0,L=[],U=[],k,W,P,K,G;for(W=0;W<E;W++){I[W]=S.length;var Q=W+1;for(K=h[W],G=h[W+1],P=K;P<G;P++)k=c[P],S.push(k),L[k]=Q,C&&(C[k]=l[P]);for(K=w[W],G=w[W+1],P=K;P<G;P++)if(k=g[P],L[k]===Q){if(C){var tt=F(C[k],d[P]);N(tt,x)?L[k]=null:C[k]=tt}}else S.push(k),U[k]=Q,T&&(T[k]=d[P]);if(C&&T)for(P=I[W];P<S.length;)k=S[P],L[k]===Q?(M[P]=C[k],P++):U[k]===Q?(M[P]=T[k],P++):S.splice(P,1)}return I[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:I,size:[v,E],datatype:f===n._datatype&&D===s._datatype?b:void 0})}}),fg="matAlgo10xSids",hg=["typed","DenseMatrix"],Wc=mt(fg,hg,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=a;typeof d=="string"&&(m=d,s=t.convert(s,m),D=t.find(a,[m,m]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=p[N],M=p[N+1],S=F;S<M;S++){var I=h[S];E[I]=c[S],b[I]=x}for(var C=0;C<g;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?D(s,E[C]):D(E[C],s):v[C][N]=s}return new e({data:v,size:[g,w],datatype:m})}}),pg="multiplyScalar",dg=["typed"],_g=mt(pg,dg,i=>{var{typed:t}=i;return t("multiplyScalar",{"number, number":Fc,"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":(e,r)=>r.multiply(e),"Unit, number | Fraction | BigNumber | Complex | Unit":(e,r)=>e.multiply(r)})}),jc="multiply",mg=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],gg=mt(jc,mg,i=>{var{typed:t,matrix:e,addScalar:r,multiplyScalar:n,equalScalar:s,dot:a}=i,l=xa({typed:t,equalScalar:s}),c=Aa({typed:t});function h(x,F){switch(x.length){case 1:switch(F.length){case 1:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+x[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(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+x[1]+") must match Vector length ("+F[0]+")");break;case 2:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+x[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 "+x.length+" dimensions)")}}function p(x,F,M){if(M===0)throw new Error("Cannot multiply two empty vectors");return a(x,F)}function f(x,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return d(x,F)}function d(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._size,L=F._datatype||F.getDataType(),U=S[0],k=T[1],W,P=r,K=n;I&&L&&I===L&&typeof I=="string"&&I!=="mixed"&&(W=I,P=t.find(r,[W,W]),K=t.find(n,[W,W]));for(var G=[],Q=0;Q<k;Q++){for(var tt=K(M[0],C[0][Q]),ct=1;ct<U;ct++)tt=P(tt,K(M[ct],C[ct][Q]));G[Q]=tt}return x.createDenseMatrix({data:G,size:[k],datatype:I===x._datatype&&L===F._datatype?W:void 0})}var g=t("_multiplyMatrixVector",{"DenseMatrix, any":m,"SparseMatrix, any":E}),w=t("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":D,"DenseMatrix, SparseMatrix":v,"SparseMatrix, DenseMatrix":b,"SparseMatrix, SparseMatrix":N});function m(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._datatype||F.getDataType(),L=S[0],U=S[1],k,W=r,P=n;I&&T&&I===T&&typeof I=="string"&&I!=="mixed"&&(k=I,W=t.find(r,[k,k]),P=t.find(n,[k,k]));for(var K=[],G=0;G<L;G++){for(var Q=M[G],tt=P(Q[0],C[0]),ct=1;ct<U;ct++)tt=W(tt,P(Q[ct],C[ct]));K[G]=tt}return x.createDenseMatrix({data:K,size:[L],datatype:I===x._datatype&&T===F._datatype?k:void 0})}function D(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._size,L=F._datatype||F.getDataType(),U=S[0],k=S[1],W=T[1],P,K=r,G=n;I&&L&&I===L&&typeof I=="string"&&I!=="mixed"&&I!=="mixed"&&(P=I,K=t.find(r,[P,P]),G=t.find(n,[P,P]));for(var Q=[],tt=0;tt<U;tt++){var ct=M[tt];Q[tt]=[];for(var vt=0;vt<W;vt++){for(var lt=G(ct[0],C[0][vt]),yt=1;yt<k;yt++)lt=K(lt,G(ct[yt],C[yt][vt]));Q[tt][vt]=lt}}return x.createDenseMatrix({data:Q,size:[U,W],datatype:I===x._datatype&&L===F._datatype?P:void 0})}function v(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._values,T=F._index,L=F._ptr,U=F._size,k=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!C)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var W=S[0],P=U[1],K,G=r,Q=n,tt=s,ct=0;I&&k&&I===k&&typeof I=="string"&&I!=="mixed"&&(K=I,G=t.find(r,[K,K]),Q=t.find(n,[K,K]),tt=t.find(s,[K,K]),ct=t.convert(0,K));for(var vt=[],lt=[],yt=[],bt=F.createSparseMatrix({values:vt,index:lt,ptr:yt,size:[W,P],datatype:I===x._datatype&&k===F._datatype?K:void 0}),Bt=0;Bt<P;Bt++){yt[Bt]=lt.length;var Et=L[Bt],ne=L[Bt+1];if(ne>Et)for(var Ot=0,Nt=0;Nt<W;Nt++){for(var se=Nt+1,Vt=void 0,qt=Et;qt<ne;qt++){var Kt=T[qt];Ot!==se?(Vt=Q(M[Nt][Kt],C[qt]),Ot=se):Vt=G(Vt,Q(M[Nt][Kt],C[qt]))}Ot===se&&!tt(Vt,ct)&&(lt.push(Nt),vt.push(Vt))}}return yt[P]=lt.length,bt}function E(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var T=F._data,L=F._datatype||F.getDataType(),U=x._size[0],k=F._size[0],W=[],P=[],K=[],G,Q=r,tt=n,ct=s,vt=0;C&&L&&C===L&&typeof C=="string"&&C!=="mixed"&&(G=C,Q=t.find(r,[G,G]),tt=t.find(n,[G,G]),ct=t.find(s,[G,G]),vt=t.convert(0,G));var lt=[],yt=[];K[0]=0;for(var bt=0;bt<k;bt++){var Bt=T[bt];if(!ct(Bt,vt))for(var Et=I[bt],ne=I[bt+1],Ot=Et;Ot<ne;Ot++){var Nt=S[Ot];yt[Nt]?lt[Nt]=Q(lt[Nt],tt(Bt,M[Ot])):(yt[Nt]=!0,P.push(Nt),lt[Nt]=tt(Bt,M[Ot]))}}for(var se=P.length,Vt=0;Vt<se;Vt++){var qt=P[Vt];W[Vt]=lt[qt]}return K[1]=P.length,x.createSparseMatrix({values:W,index:P,ptr:K,size:[U,1],datatype:C===x._datatype&&L===F._datatype?G:void 0})}function b(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var T=F._data,L=F._datatype||F.getDataType(),U=x._size[0],k=F._size[0],W=F._size[1],P,K=r,G=n,Q=s,tt=0;C&&L&&C===L&&typeof C=="string"&&C!=="mixed"&&(P=C,K=t.find(r,[P,P]),G=t.find(n,[P,P]),Q=t.find(s,[P,P]),tt=t.convert(0,P));for(var ct=[],vt=[],lt=[],yt=x.createSparseMatrix({values:ct,index:vt,ptr:lt,size:[U,W],datatype:C===x._datatype&&L===F._datatype?P:void 0}),bt=[],Bt=[],Et=0;Et<W;Et++){lt[Et]=vt.length;for(var ne=Et+1,Ot=0;Ot<k;Ot++){var Nt=T[Ot][Et];if(!Q(Nt,tt))for(var se=I[Ot],Vt=I[Ot+1],qt=se;qt<Vt;qt++){var Kt=S[qt];Bt[Kt]!==ne?(Bt[Kt]=ne,vt.push(Kt),bt[Kt]=G(Nt,M[qt])):bt[Kt]=K(bt[Kt],G(Nt,M[qt]))}}for(var Ne=lt[Et],lr=vt.length,Be=Ne;Be<lr;Be++){var nn=vt[Be];ct[Be]=bt[nn]}}return lt[W]=vt.length,yt}function N(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType(),T=F._values,L=F._index,U=F._ptr,k=F._datatype||F._data===void 0?F._datatype:F.getDataType(),W=x._size[0],P=F._size[1],K=M&&T,G,Q=r,tt=n;C&&k&&C===k&&typeof C=="string"&&C!=="mixed"&&(G=C,Q=t.find(r,[G,G]),tt=t.find(n,[G,G]));for(var ct=K?[]:void 0,vt=[],lt=[],yt=x.createSparseMatrix({values:ct,index:vt,ptr:lt,size:[W,P],datatype:C===x._datatype&&k===F._datatype?G:void 0}),bt=K?[]:void 0,Bt=[],Et,ne,Ot,Nt,se,Vt,qt,Kt,Ne=0;Ne<P;Ne++){lt[Ne]=vt.length;var lr=Ne+1;for(se=U[Ne],Vt=U[Ne+1],Nt=se;Nt<Vt;Nt++)if(Kt=L[Nt],K)for(ne=I[Kt],Ot=I[Kt+1],Et=ne;Et<Ot;Et++)qt=S[Et],Bt[qt]!==lr?(Bt[qt]=lr,vt.push(qt),bt[qt]=tt(T[Nt],M[Et])):bt[qt]=Q(bt[qt],tt(T[Nt],M[Et]));else for(ne=I[Kt],Ot=I[Kt+1],Et=ne;Et<Ot;Et++)qt=S[Et],Bt[qt]!==lr&&(Bt[qt]=lr,vt.push(qt));if(K)for(var Be=lt[Ne],nn=vt.length,xn=Be;xn<nn;xn++){var sn=vt[xn];ct[xn]=bt[sn]}}return lt[P]=vt.length,yt}return t(jc,n,{"Array, Array":t.referTo("Matrix, Matrix",x=>(F,M)=>{h(Fe(F),Fe(M));var S=x(e(F),e(M));return fe(S)?S.valueOf():S}),"Matrix, Matrix":function(F,M){var S=F.size(),I=M.size();return h(S,I),S.length===1?I.length===1?p(F,M,S[0]):f(F,M):I.length===1?g(F,M):w(F,M)},"Matrix, Array":t.referTo("Matrix,Matrix",x=>(F,M)=>x(F,e(M))),"Array, Matrix":t.referToSelf(x=>(F,M)=>x(e(F,M.storage()),M)),"SparseMatrix, any":function(F,M){return l(F,M,n,!1)},"DenseMatrix, any":function(F,M){return c(F,M,n,!1)},"any, SparseMatrix":function(F,M){return l(M,F,n,!0)},"any, DenseMatrix":function(F,M){return c(M,F,n,!0)},"Array, any":function(F,M){return c(e(F),M,n,!1).valueOf()},"any, Array":function(F,M){return c(e(M),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":t.referToSelf(x=>(F,M,S)=>{for(var I=x(F,M),C=0;C<S.length;C++)I=x(I,S[C]);return I})})}),Yc="subtract",vg=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],wg=mt(Yc,vg,i=>{var{typed:t,matrix:e,equalScalar:r,subtractScalar:n,unaryMinus:s,DenseMatrix:a,concat:l}=i,c=Uc({typed:t}),h=di({typed:t}),p=kc({typed:t,equalScalar:r}),f=Wc({typed:t,DenseMatrix:a}),d=pi({typed:t,DenseMatrix:a}),g=jn({typed:t,matrix:e,concat:l});return t(Yc,{"any, any":n},g({elop:n,SS:p,DS:c,SD:h,Ss:d,sS:f}))}),yg="matAlgo07xSSf",Dg=["typed","DenseMatrix"],ks=mt(yg,Dg,i=>{var{typed:t,DenseMatrix:e}=i;return function(s,a,l){var c=s._size,h=s._datatype||s._data===void 0?s._datatype:s.getDataType(),p=a._size,f=a._datatype||a._data===void 0?a._datatype:a.getDataType();if(c.length!==p.length)throw new Gt(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+p+")");var d=c[0],g=c[1],w,m=0,D=l;typeof h=="string"&&h===f&&h!=="mixed"&&(w=h,m=t.convert(0,w),D=t.find(l,[w,w]));var v,E,b=[];for(v=0;v<d;v++)b[v]=[];var N=[],x=[],F=[],M=[];for(E=0;E<g;E++){var S=E+1;for(r(s,E,F,N,S),r(a,E,M,x,S),v=0;v<d;v++){var I=F[v]===S?N[v]:m,C=M[v]===S?x[v]:m;b[v][E]=D(I,C)}}return new e({data:b,size:[d,g],datatype:h===s._datatype&&f===a._datatype?w:void 0})};function r(n,s,a,l,c){for(var h=n._values,p=n._index,f=n._ptr,d=f[s],g=f[s+1];d<g;d++){var w=p[d];a[w]=c,l[w]=h[d]}}}),Zc="conj",bg=["typed"],Eg=mt(Zc,bg,i=>{var{typed:t}=i;return t(Zc,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.conjugate(),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Gc="concat",xg=["typed","matrix","isInteger"],Ag=mt(Gc,xg,i=>{var{typed:t,matrix:e,isInteger:r}=i;return t(Gc,{"...Array | Matrix | number | BigNumber":function(s){var a,l=s.length,c=-1,h,p=!1,f=[];for(a=0;a<l;a++){var d=s[a];if(fe(d)&&(p=!0),le(d)||xe(d)){if(a!==l-1)throw new Error("Dimension must be specified as last argument");if(h=c,c=d.valueOf(),!r(c))throw new TypeError("Integer number expected for dimension");if(c<0||a>0&&c>h)throw new gn(c,h+1)}else{var g=re(d).valueOf(),w=Fe(g);if(f[a]=g,h=c,c=w.length-1,a>0&&c!==h)throw new Gt(h+1,c+1)}}if(f.length===0)throw new SyntaxError("At least one matrix expected");for(var m=f.shift();f.length;)m=tc(m,f.shift(),c);return p?e(m):m},"...string":function(s){return s.join("")}})}),Kc="count",Cg=["typed","size","prod"],Fg=mt(Kc,Cg,i=>{var{typed:t,size:e,prod:r}=i;return t(Kc,{string:function(s){return s.length},"Matrix | Array":function(s){return r(e(s))}})}),Hc="identity",Mg=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Ng=mt(Hc,Mg,i=>{var{typed:t,config:e,matrix:r,BigNumber:n,DenseMatrix:s,SparseMatrix:a}=i;return t(Hc,{"":function(){return e.matrix==="Matrix"?r([]):[]},string:function(p){return r(p)},"number | BigNumber":function(p){return c(p,p,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(p,f){return c(p,p,f)},"number | BigNumber, number | BigNumber":function(p,f){return c(p,f,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(p,f,d){return c(p,f,d)},Array:function(p){return l(p)},"Array, string":function(p,f){return l(p,f)},Matrix:function(p){return l(p.valueOf(),p.storage())},"Matrix, string":function(p,f){return l(p.valueOf(),f)}});function l(h,p){switch(h.length){case 0:return p?r(p):[];case 1:return c(h[0],h[0],p);case 2:return c(h[0],h[1],p);default:throw new Error("Vector containing two values expected")}}function c(h,p,f){var d=xe(h)||xe(p)?n:null;if(xe(h)&&(h=h.toNumber()),xe(p)&&(p=p.toNumber()),!de(h)||h<1)throw new Error("Parameters in function identity must be positive integers");if(!de(p)||p<1)throw new Error("Parameters in function identity must be positive integers");var g=d?new n(1):1,w=d?new d(0):0,m=[h,p];if(f){if(f==="sparse")return a.diagonal(m,g,0,w);if(f==="dense")return s.diagonal(m,g,0,w);throw new TypeError('Unknown matrix type "'.concat(f,'"'))}for(var D=ca([],m,w),v=h<p?h:p,E=0;E<v;E++)D[E][E]=g;return D}}),Xc="kron",Sg=["typed","matrix","multiplyScalar"],Bg=mt(Xc,Sg,i=>{var{typed:t,matrix:e,multiplyScalar:r}=i;return t(Xc,{"Matrix, Matrix":function(a,l){return e(n(a.toArray(),l.toArray()))},"Matrix, Array":function(a,l){return e(n(a.toArray(),l))},"Array, Matrix":function(a,l){return e(n(a,l.toArray()))},"Array, Array":n});function n(s,a){if(Fe(s).length===1&&(s=[s]),Fe(a).length===1&&(a=[a]),Fe(s).length>2||Fe(a).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(s.length)+", y = "+JSON.stringify(a.length)+")");var l=[],c=[];return s.map(function(h){return a.map(function(p){return c=[],l.push(c),h.map(function(f){return p.map(function(d){return c.push(r(f,d))})})})})&&l}});function Tg(){throw new Error('No "bignumber" implementation available')}function Og(){throw new Error('No "fraction" implementation available')}function Ig(){throw new Error('No "matrix" implementation available')}var Jc="reshape",$g=["typed","isInteger","matrix"],Lg=mt(Jc,$g,i=>{var{typed:t,isInteger:e}=i;return t(Jc,{"Matrix, Array":function(n,s){return n.reshape(s,!0)},"Array, Array":function(n,s){return s.forEach(function(a){if(!e(a))throw new TypeError("Invalid size for dimension: "+a)}),ha(n,s)}})}),Qc="size",Rg=["typed","config","?matrix"],Pg=mt(Qc,Rg,i=>{var{typed:t,config:e,matrix:r}=i;return t(Qc,{Matrix:function(s){return s.create(s.size())},Array:Fe,string:function(s){return e.matrix==="Array"?[s.length]:r([s.length])},"number | Complex | BigNumber | Unit | boolean | null":function(s){return e.matrix==="Array"?[]:r?r([]):Ig()}})}),Vc="transpose",zg=["typed","matrix"],qg=mt(Vc,zg,i=>{var{typed:t,matrix:e}=i;return t(Vc,{Array:a=>r(e(a)).valueOf(),Matrix:r,any:re});function r(a){var l=a.size(),c;switch(l.length){case 1:c=a.clone();break;case 2:{var h=l[0],p=l[1];if(p===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+oe(l)+")");switch(a.storage()){case"dense":c=n(a,h,p);break;case"sparse":c=s(a,h,p);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+oe(l)+")")}return c}function n(a,l,c){for(var h=a._data,p=[],f,d=0;d<c;d++){f=p[d]=[];for(var g=0;g<l;g++)f[g]=re(h[g][d])}return a.createDenseMatrix({data:p,size:[c,l],datatype:a._datatype})}function s(a,l,c){for(var h=a._values,p=a._index,f=a._ptr,d=h?[]:void 0,g=[],w=[],m=[],D=0;D<l;D++)m[D]=0;var v,E,b;for(v=0,E=p.length;v<E;v++)m[p[v]]++;for(var N=0,x=0;x<l;x++)w.push(N),N+=m[x],m[x]=w[x];for(w.push(N),b=0;b<c;b++)for(var F=f[b],M=f[b+1],S=F;S<M;S++){var I=m[p[S]]++;g[I]=b,h&&(d[I]=re(h[S]))}return a.createSparseMatrix({values:d,index:g,ptr:w,size:[c,l],datatype:a._datatype})}}),tf="ctranspose",kg=["typed","transpose","conj"],Ug=mt(tf,kg,i=>{var{typed:t,transpose:e,conj:r}=i;return t(tf,{any:function(s){return r(e(s))}})}),ef="mode",Wg=["typed","isNaN","isNumeric"],jg=mt(ef,Wg,i=>{var{typed:t,isNaN:e,isNumeric:r}=i;return t(ef,{"Array | Matrix":n,"...":function(a){return n(a)}});function n(s){s=da(s.valueOf());var a=s.length;if(a===0)throw new Error("Cannot calculate mode of an empty array");for(var l={},c=[],h=0,p=0;p<s.length;p++){var f=s[p];if(r(f)&&e(f))throw new Error("Cannot calculate mode of an array containing NaN values");f in l||(l[f]=0),l[f]++,l[f]===h?c.push(f):l[f]>h&&(h=l[f],c=[f])}return c}});function bn(i,t,e){var r;return String(i).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+mn(e)+", value: "+JSON.stringify(e)+")":" (type: "+i.data.actual+")",new TypeError("Cannot calculate "+t+", unexpected type of argument"+r)):String(i).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+mn(e)+", value: "+JSON.stringify(e)+")":"",new TypeError("Cannot calculate "+t+", no ordering relation is defined for complex numbers"+r)):i}var rf="prod",Yg=["typed","config","multiplyScalar","numeric"],Zg=mt(rf,Yg,i=>{var{typed:t,config:e,multiplyScalar:r,numeric:n}=i;return t(rf,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(l,c){throw new Error("prod(A, dim) is not yet supported")},"...":function(l){return s(l)}});function s(a){var l;if(Yi(a,function(c){try{l=l===void 0?c:r(l,c)}catch(h){throw bn(h,"prod",c)}}),typeof l=="string"&&(l=n(l,e.number)),l===void 0)throw new Error("Cannot calculate prod of an empty array");return l}}),Gg="numeric",Kg=["number","?bignumber","?fraction"],Hg=mt(Gg,Kg,i=>{var{number:t,bignumber:e,fraction:r}=i,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},s={number:a=>t(a),BigNumber:e?a=>e(a):Tg,Fraction:r?a=>r(a):Og};return function(l){var c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",h=arguments.length>2?arguments[2]:void 0;if(h!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var p=mn(l);if(!(p in n))throw new TypeError("Cannot convert "+l+' of type "'+p+'"; valid input types are '+Object.keys(n).join(", "));if(!(c in s))throw new TypeError("Cannot convert "+l+' to type "'+c+'"; valid output types are '+Object.keys(s).join(", "));return c===p?l:s[c](l)}}),nf="divideScalar",Xg=["typed","numeric"],Jg=mt(nf,Xg,i=>{var{typed:t,numeric:e}=i;return t(nf,{"number, number":function(n,s){return n/s},"Complex, Complex":function(n,s){return n.div(s)},"BigNumber, BigNumber":function(n,s){return n.div(s)},"Fraction, Fraction":function(n,s){return n.div(s)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),sf="pow",Qg=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Vg=mt(sf,Qg,i=>{var{typed:t,config:e,identity:r,multiply:n,matrix:s,inv:a,number:l,fraction:c,Complex:h}=i;return t(sf,{"number, number":p,"Complex, Complex":function(w,m){return w.pow(m)},"BigNumber, BigNumber":function(w,m){return m.isInteger()||w>=0||e.predictable?w.pow(m):new h(w.toNumber(),0).pow(m.toNumber(),0)},"Fraction, Fraction":function(w,m){var D=w.pow(m);if(D!=null)return D;if(e.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return p(w.valueOf(),m.valueOf())},"Array, number":f,"Array, BigNumber":function(w,m){return f(w,m.toNumber())},"Matrix, number":d,"Matrix, BigNumber":function(w,m){return d(w,m.toNumber())},"Unit, number | BigNumber":function(w,m){return w.pow(m)}});function p(g,w){if(e.predictable&&!de(w)&&g<0)try{var m=c(w),D=l(m);if((w===D||Math.abs((w-D)/w)<1e-14)&&m.d%2===1)return(m.n%2===0?1:-1)*Math.pow(-g,w)}catch{}return e.predictable&&(g<-1&&w===1/0||g>-1&&g<0&&w===-1/0)?NaN:de(w)||g>=0||e.predictable?Nc(g,w):g*g<1&&w===1/0||g*g>1&&w===-1/0?0:new h(g,0).pow(w,0)}function f(g,w){if(!de(w))throw new TypeError("For A^b, b must be an integer (value is "+w+")");var m=Fe(g);if(m.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+m.length+" dimensions)");if(m[0]!==m[1])throw new Error("For A^b, A must be square (size is "+m[0]+"x"+m[1]+")");if(w<0)try{return f(a(g),-w)}catch(E){throw E.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 "+w+")"):E}for(var D=r(m[0]).valueOf(),v=g;w>=1;)(w&1)===1&&(D=n(v,D)),w>>=1,v=n(v,v);return D}function d(g,w){return s(f(g.valueOf(),w))}}),of="dotDivide",tv=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],ev=mt(of,tv,i=>{var{typed:t,matrix:e,equalScalar:r,divideScalar:n,DenseMatrix:s,concat:a}=i,l=Gm({typed:t,equalScalar:r}),c=di({typed:t}),h=ks({typed:t,DenseMatrix:s}),p=xa({typed:t,equalScalar:r}),f=pi({typed:t,DenseMatrix:s}),d=jn({typed:t,matrix:e,concat:a});return t(of,d({elop:n,SS:h,DS:c,SD:l,Ss:p,sS:f}))}),Us="compare",rv=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],nv=mt(Us,rv,i=>{var{typed:t,config:e,equalScalar:r,matrix:n,BigNumber:s,Fraction:a,DenseMatrix:l,concat:c}=i,h=di({typed:t}),p=kc({typed:t,equalScalar:r}),f=pi({typed:t,DenseMatrix:l}),d=jn({typed:t,matrix:n,concat:c}),g=zs({typed:t});return t(Us,iv({typed:t,config:e}),{"boolean, boolean":function(m,D){return m===D?0:m>D?1:-1},"BigNumber, BigNumber":function(m,D){return Ps(m,D,e.epsilon)?new s(0):new s(m.cmp(D))},"Fraction, Fraction":function(m,D){return new a(m.compare(D))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},g,d({SS:p,DS:h,Ss:f}))}),iv=mt(Us,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Us,{"number, number":function(n,s){return Wn(n,s,e.epsilon)?0:n>s?1:-1}})}),Ws="equal",sv=["typed","matrix","equalScalar","DenseMatrix","concat"],ov=mt(Ws,sv,i=>{var{typed:t,matrix:e,equalScalar:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:e,concat:s});return t(Ws,av({typed:t,equalScalar:r}),h({elop:r,SS:l,DS:a,Ss:c}))}),av=mt(Ws,["typed","equalScalar"],i=>{var{typed:t,equalScalar:e}=i;return t(Ws,{"any, any":function(n,s){return n===null?s===null:s===null?n===null:n===void 0?s===void 0:s===void 0?n===void 0:e(n,s)}})}),js="smaller",uv=["typed","config","matrix","DenseMatrix","concat"],lv=mt(js,uv,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:r,concat:s}),p=zs({typed:t});return t(js,cv({typed:t,config:e}),{"boolean, boolean":(f,d)=>f<d,"BigNumber, BigNumber":function(d,g){return d.lt(g)&&!Ps(d,g,e.epsilon)},"Fraction, Fraction":(f,d)=>f.compare(d)===-1,"Complex, Complex":function(d,g){throw new TypeError("No ordering relation is defined for complex numbers")}},p,h({SS:l,DS:a,Ss:c}))}),cv=mt(js,["typed","config"],i=>{var{typed:t,config:e}=i;return t(js,{"number, number":function(n,s){return n<s&&!Wn(n,s,e.epsilon)}})}),Ys="larger",fv=["typed","config","matrix","DenseMatrix","concat"],hv=mt(Ys,fv,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:r,concat:s}),p=zs({typed:t});return t(Ys,pv({typed:t,config:e}),{"boolean, boolean":(f,d)=>f>d,"BigNumber, BigNumber":function(d,g){return d.gt(g)&&!Ps(d,g,e.epsilon)},"Fraction, Fraction":(f,d)=>f.compare(d)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},p,h({SS:l,DS:a,Ss:c}))}),pv=mt(Ys,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Ys,{"number, number":function(n,s){return n>s&&!Wn(n,s,e.epsilon)}})}),af="deepEqual",dv=["typed","equal"],_v=mt(af,dv,i=>{var{typed:t,equal:e}=i;return t(af,{"any, any":function(s,a){return r(s.valueOf(),a.valueOf())}});function r(n,s){if(Array.isArray(n))if(Array.isArray(s)){var a=n.length;if(a!==s.length)return!1;for(var l=0;l<a;l++)if(!r(n[l],s[l]))return!1;return!0}else return!1;else return Array.isArray(s)?!1:e(n,s)}}),uf="partitionSelect",mv=["typed","isNumeric","isNaN","compare"],gv=mt(uf,mv,i=>{var{typed:t,isNumeric:e,isNaN:r,compare:n}=i,s=n,a=(h,p)=>-n(h,p);return t(uf,{"Array | Matrix, number":function(p,f){return l(p,f,s)},"Array | Matrix, number, string":function(p,f,d){if(d==="asc")return l(p,f,s);if(d==="desc")return l(p,f,a);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":l});function l(h,p,f){if(!de(p)||p<0)throw new Error("k must be a non-negative integer");if(fe(h)){var d=h.size();if(d.length>1)throw new Error("Only one dimensional matrices supported");return c(h.valueOf(),p,f)}if(Array.isArray(h))return c(h,p,f)}function c(h,p,f){if(p>=h.length)throw new Error("k out of bounds");for(var d=0;d<h.length;d++)if(e(h[d])&&r(h[d]))return h[d];for(var g=0,w=h.length-1;g<w;){for(var m=g,D=w,v=h[Math.floor(Math.random()*(w-g+1))+g];m<D;)if(f(h[m],v)>=0){var E=h[D];h[D]=h[m],h[m]=E,--D}else++m;f(h[m],v)>0&&--m,p<=m?w=m:g=m+1}return h[p]}}),lf="max",vv=["typed","config","numeric","larger"],wv=mt(lf,vv,i=>{var{typed:t,config:e,numeric:r,larger:n}=i;return t(lf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(c,h){return Ea(c,h.valueOf(),s)},"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function max");return a(c)}});function s(l,c){try{return n(l,c)?l:c}catch(h){throw bn(h,"max",c)}}function a(l){var c;if(Yi(l,function(h){try{isNaN(h)&&typeof h=="number"?c=NaN:(c===void 0||n(h,c))&&(c=h)}catch(p){throw bn(p,"max",h)}}),c===void 0)throw new Error("Cannot calculate max of an empty array");return typeof c=="string"&&(c=r(c,e.number)),c}}),cf="min",yv=["typed","config","numeric","smaller"],Dv=mt(cf,yv,i=>{var{typed:t,config:e,numeric:r,smaller:n}=i;return t(cf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(c,h){return Ea(c,h.valueOf(),s)},"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function min");return a(c)}});function s(l,c){try{return n(l,c)?l:c}catch(h){throw bn(h,"min",c)}}function a(l){var c;if(Yi(l,function(h){try{isNaN(h)&&typeof h=="number"?c=NaN:(c===void 0||n(h,c))&&(c=h)}catch(p){throw bn(p,"min",h)}}),c===void 0)throw new Error("Cannot calculate min of an empty array");return typeof c=="string"&&(c=r(c,e.number)),c}}),ff="add",bv=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],Ev=mt(ff,bv,i=>{var{typed:t,matrix:e,addScalar:r,equalScalar:n,DenseMatrix:s,SparseMatrix:a,concat:l}=i,c=Uc({typed:t}),h=cg({typed:t,equalScalar:n}),p=Wc({typed:t,DenseMatrix:s}),f=jn({typed:t,matrix:e,concat:l});return t(ff,{"any, any":r,"any, any, ...any":t.referToSelf(d=>(g,w,m)=>{for(var D=d(g,w),v=0;v<m.length;v++)D=d(D,m[v]);return D})},f({elop:r,DS:c,SS:h,Ss:p}))}),hf="dot",xv=["typed","addScalar","multiplyScalar","conj","size"],Av=mt(hf,xv,i=>{var{typed:t,addScalar:e,multiplyScalar:r,conj:n,size:s}=i;return t(hf,{"Array | DenseMatrix, Array | DenseMatrix":l,"SparseMatrix, SparseMatrix":c});function a(p,f){var d=h(p),g=h(f),w,m;if(d.length===1)w=d[0];else if(d.length===2&&d[1]===1)w=d[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+d.join(", ")+")");if(g.length===1)m=g[0];else if(g.length===2&&g[1]===1)m=g[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+g.join(", ")+")");if(w!==m)throw new RangeError("Vectors must have equal length ("+w+" != "+m+")");if(w===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return w}function l(p,f){var d=a(p,f),g=fe(p)?p._data:p,w=fe(p)?p._datatype||p.getDataType():void 0,m=fe(f)?f._data:f,D=fe(f)?f._datatype||f.getDataType():void 0,v=h(p).length===2,E=h(f).length===2,b=e,N=r;if(w&&D&&w===D&&typeof w=="string"&&w!=="mixed"){var x=w;b=t.find(e,[x,x]),N=t.find(r,[x,x])}if(!v&&!E){for(var F=N(n(g[0]),m[0]),M=1;M<d;M++)F=b(F,N(n(g[M]),m[M]));return F}if(!v&&E){for(var S=N(n(g[0]),m[0][0]),I=1;I<d;I++)S=b(S,N(n(g[I]),m[I][0]));return S}if(v&&!E){for(var C=N(n(g[0][0]),m[0]),T=1;T<d;T++)C=b(C,N(n(g[T][0]),m[T]));return C}if(v&&E){for(var L=N(n(g[0][0]),m[0][0]),U=1;U<d;U++)L=b(L,N(n(g[U][0]),m[U][0]));return L}}function c(p,f){a(p,f);for(var d=p._index,g=p._values,w=f._index,m=f._values,D=0,v=e,E=r,b=0,N=0;b<d.length&&N<w.length;){var x=d[b],F=w[N];if(x<F){b++;continue}if(x>F){N++;continue}x===F&&(D=v(D,E(g[b],m[N])),b++,N++)}return D}function h(p){return fe(p)?p.size():s(p)}}),Cv="trace",Fv=["typed","matrix","add"],Mv=mt(Cv,Fv,i=>{var{typed:t,matrix:e,add:r}=i;return t("trace",{Array:function(l){return n(e(l))},SparseMatrix:s,DenseMatrix:n,any:re});function n(a){var l=a._size,c=a._data;switch(l.length){case 1:if(l[0]===1)return re(c[0]);throw new RangeError("Matrix must be square (size: "+oe(l)+")");case 2:{var h=l[0],p=l[1];if(h===p){for(var f=0,d=0;d<h;d++)f=r(f,c[d][d]);return f}else throw new RangeError("Matrix must be square (size: "+oe(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(l)+")")}}function s(a){var l=a._values,c=a._index,h=a._ptr,p=a._size,f=p[0],d=p[1];if(f===d){var g=0;if(l.length>0)for(var w=0;w<d;w++)for(var m=h[w],D=h[w+1],v=m;v<D;v++){var E=c[v];if(E===w){g=r(g,l[v]);break}if(E>w)break}return g}throw new RangeError("Matrix must be square (size: "+oe(p)+")")}}),pf="det",Nv=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],Sv=mt(pf,Nv,i=>{var{typed:t,matrix:e,subtractScalar:r,multiply:n,divideScalar:s,isZero:a,unaryMinus:l}=i;return t(pf,{any:function(p){return re(p)},"Array | Matrix":function(p){var f;switch(fe(p)?f=p.size():Array.isArray(p)?(p=e(p),f=p.size()):f=[],f.length){case 0:return re(p);case 1:if(f[0]===1)return re(p.valueOf()[0]);if(f[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+oe(f)+")");case 2:{var d=f[0],g=f[1];if(d===g)return c(p.clone().valueOf(),d);if(g===0)return 1;throw new RangeError("Matrix must be square (size: "+oe(f)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(f)+")")}}});function c(h,p,f){if(p===1)return re(h[0][0]);if(p===2)return r(n(h[0][0],h[1][1]),n(h[1][0],h[0][1]));for(var d=!1,g=new Array(p).fill(0).map((M,S)=>S),w=0;w<p;w++){var m=g[w];if(a(h[m][w])){var D=void 0;for(D=w+1;D<p;D++)if(!a(h[g[D]][w])){m=g[D],g[D]=g[w],g[w]=m,d=!d;break}if(D===p)return h[m][w]}for(var v=h[m][w],E=w===0?1:h[g[w-1]][w-1],b=w+1;b<p;b++)for(var N=g[b],x=w+1;x<p;x++)h[N][x]=s(r(n(h[N][x],v),n(h[N][w],h[m][x])),E)}var F=h[g[p-1]][p-1];return d?l(F):F}}),df="inv",Bv=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],Tv=mt(df,Bv,i=>{var{typed:t,matrix:e,divideScalar:r,addScalar:n,multiply:s,unaryMinus:a,det:l,identity:c,abs:h}=i;return t(df,{"Array | Matrix":function(d){var g=fe(d)?d.size():Fe(d);switch(g.length){case 1:if(g[0]===1)return fe(d)?e([r(1,d.valueOf()[0])]):[r(1,d[0])];throw new RangeError("Matrix must be square (size: "+oe(g)+")");case 2:{var w=g[0],m=g[1];if(w===m)return fe(d)?e(p(d.valueOf(),w,m),d.storage()):p(d,w,m);throw new RangeError("Matrix must be square (size: "+oe(g)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(g)+")")}},any:function(d){return r(1,d)}});function p(f,d,g){var w,m,D,v,E;if(d===1){if(v=f[0][0],v===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,v)]]}else if(d===2){var b=l(f);if(b===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(f[1][1],b),r(a(f[0][1]),b)],[r(a(f[1][0]),b),r(f[0][0],b)]]}else{var N=f.concat();for(w=0;w<d;w++)N[w]=N[w].concat();for(var x=c(d).valueOf(),F=0;F<g;F++){var M=h(N[F][F]),S=F;for(w=F+1;w<d;)h(N[w][F])>M&&(M=h(N[w][F]),S=w),w++;if(M===0)throw Error("Cannot calculate inverse, determinant is zero");w=S,w!==F&&(E=N[F],N[F]=N[w],N[w]=E,E=x[F],x[F]=x[w],x[w]=E);var I=N[F],C=x[F];for(w=0;w<d;w++){var T=N[w],L=x[w];if(w!==F){if(T[F]!==0){for(D=r(a(T[F]),I[F]),m=F;m<g;m++)T[m]=n(T[m],s(D,I[m]));for(m=0;m<g;m++)L[m]=n(L[m],s(D,C[m]))}}else{for(D=I[F],m=F;m<g;m++)T[m]=r(T[m],D);for(m=0;m<g;m++)L[m]=r(L[m],D)}}}return x}}}),_f="pinv",Ov=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],Iv=mt(_f,Ov,i=>{var{typed:t,matrix:e,inv:r,deepEqual:n,equal:s,dotDivide:a,dot:l,ctranspose:c,divideScalar:h,multiply:p,add:f,Complex:d}=i;return t(_f,{"Array | Matrix":function(b){var N=fe(b)?b.size():Fe(b);switch(N.length){case 1:return v(b)?c(b):N[0]===1?r(b):a(c(b),l(b,b));case 2:{if(v(b))return c(b);var x=N[0],F=N[1];if(x===F)try{return r(b)}catch(M){if(!(M instanceof Error&&M.message.match(/Cannot calculate inverse, determinant is zero/)))throw M}return fe(b)?e(g(b.valueOf(),x,F),b.storage()):g(b,x,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(N)+")")}},any:function(b){return s(b,0)?re(b):h(1,b)}});function g(E,b,N){var{C:x,F}=m(E,b,N),M=p(r(p(c(x),x)),c(x)),S=p(c(F),r(p(F,c(F))));return p(S,M)}function w(E,b,N){for(var x=re(E),F=0,M=0;M<b;M++){if(N<=F)return x;for(var S=M;D(x[S][F]);)if(S++,b===S&&(S=M,F++,N===F))return x;[x[S],x[M]]=[x[M],x[S]];for(var I=x[M][F],C=0;C<N;C++)x[M][C]=a(x[M][C],I);for(var T=0;T<b;T++)if(T!==M){I=x[T][F];for(var L=0;L<N;L++)x[T][L]=f(x[T][L],p(-1,p(I,x[M][L])))}F++}return x}function m(E,b,N){var x=w(E,b,N),F=E.map((S,I)=>S.filter((C,T)=>T<b&&!D(l(x[T],x[T])))),M=x.filter((S,I)=>!D(l(x[I],x[I])));return{C:F,F:M}}function D(E){return s(f(E,d(1,1)),f(0,d(1,1)))}function v(E){return n(f(E,d(1,1)),f(p(E,0),d(1,1)))}}),$v="divide",Lv=["typed","matrix","multiply","equalScalar","divideScalar","inv"],Rv=mt($v,Lv,i=>{var{typed:t,matrix:e,multiply:r,equalScalar:n,divideScalar:s,inv:a}=i,l=xa({typed:t,equalScalar:n}),c=Aa({typed:t});return t("divide",Il({"Array | Matrix, Array | Matrix":function(p,f){return r(p,a(f))},"DenseMatrix, any":function(p,f){return c(p,f,s,!1)},"SparseMatrix, any":function(p,f){return l(p,f,s,!1)},"Array, any":function(p,f){return c(e(p),f,s,!1).valueOf()},"any, Array | Matrix":function(p,f){return r(p,a(f))}},s.signatures))}),mf="sum",Pv=["typed","config","add","numeric"],zv=mt(mf,Pv,i=>{var{typed:t,config:e,add:r,numeric:n}=i;return t(mf,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":a,"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function sum");return s(c)}});function s(l){var c;return Yi(l,function(h){try{c=c===void 0?h:r(c,h)}catch(p){throw bn(p,"sum",h)}}),c===void 0&&(c=n(0,e.number)),typeof c=="string"&&(c=n(c,e.number)),c}function a(l,c){try{var h=Ea(l,c,r);return h}catch(p){throw bn(p,"sum")}}}),gf="median",qv=["typed","add","divide","compare","partitionSelect"],kv=mt(gf,qv,i=>{var{typed:t,add:e,divide:r,compare:n,partitionSelect:s}=i;function a(h){try{h=da(h.valueOf());var p=h.length;if(p===0)throw new Error("Cannot calculate median of an empty array");if(p%2===0){for(var f=p/2-1,d=s(h,f+1),g=h[f],w=0;w<f;++w)n(h[w],g)>0&&(g=h[w]);return c(g,d)}else{var m=s(h,(p-1)/2);return l(m)}}catch(D){throw bn(D,"median")}}var l=t({"number | BigNumber | Complex | Unit":function(p){return p}}),c=t({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(p,f){return r(e(p,f),2)}});return t(gf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(p,f){throw new Error("median(A, dim) is not yet supported")},"...":function(p){if($s(p))throw new TypeError("Scalar values expected in function median");return a(p)}})}),Zs=U_({config:ar}),Ca=Z_({}),Fa=X_({}),Ma=V_({}),Kr=rm({Matrix:Ma}),Mt=Yd({BigNumber:Zs,Complex:Ca,DenseMatrix:Kr,Fraction:Fa}),Uv=Im({typed:Mt}),Gs=Lm({typed:Mt}),Wv=Am({BigNumber:Zs,typed:Mt}),vf=Eg({typed:Mt}),En=dm({config:ar,typed:Mt}),Ks=sm({typed:Mt}),jv=lm({typed:Mt}),Hs=_g({typed:Mt}),wf=bm({typed:Mt}),Na=gm({Matrix:Ma,equalScalar:En,typed:Mt}),yf=Pm({typed:Mt}),Df=fm({typed:Mt}),Sa=Tm({typed:Mt}),bf=Mm({Fraction:Fa,typed:Mt}),Ef=am({typed:Mt}),Me=Sm({DenseMatrix:Kr,Matrix:Ma,SparseMatrix:Na,typed:Mt}),xf=jg({isNaN:Df,isNumeric:Ef,typed:Mt}),Zi=Hg({bignumber:Wv,fraction:bf,number:wf}),Yv=Zg({config:ar,multiplyScalar:Hs,numeric:Zi,typed:Mt}),Zv=Lg({isInteger:Ks,matrix:Me,typed:Mt}),Af=Pg({matrix:Me,config:ar,typed:Mt}),Cf=qg({matrix:Me,typed:Mt}),Yn=Ag({isInteger:Ks,matrix:Me,typed:Mt}),Gv=Fg({prod:Yv,size:Af,typed:Mt}),Kv=Ug({conj:vf,transpose:Cf,typed:Mt}),Gi=Jg({numeric:Zi,typed:Mt}),Hv=ev({DenseMatrix:Kr,concat:Yn,divideScalar:Gi,equalScalar:En,matrix:Me,typed:Mt}),Ff=ov({DenseMatrix:Kr,concat:Yn,equalScalar:En,matrix:Me,typed:Mt}),Mf=Ng({BigNumber:Zs,DenseMatrix:Kr,SparseMatrix:Na,config:ar,matrix:Me,typed:Mt}),Xv=Bg({matrix:Me,multiplyScalar:Hs,typed:Mt}),Jv=lv({DenseMatrix:Kr,concat:Yn,config:ar,matrix:Me,typed:Mt}),Qv=wg({DenseMatrix:Kr,concat:Yn,equalScalar:En,matrix:Me,subtractScalar:yf,typed:Mt,unaryMinus:Sa}),Ki=Ev({DenseMatrix:Kr,SparseMatrix:Na,addScalar:Gs,concat:Yn,equalScalar:En,matrix:Me,typed:Mt}),Nf=nv({BigNumber:Zs,DenseMatrix:Kr,Fraction:Fa,concat:Yn,config:ar,equalScalar:En,matrix:Me,typed:Mt}),Vv=_v({equal:Ff,typed:Mt}),Sf=Av({addScalar:Gs,conj:vf,multiplyScalar:Hs,size:Af,typed:Mt}),t1=hv({DenseMatrix:Kr,concat:Yn,config:ar,matrix:Me,typed:Mt}),Ba=Dv({config:ar,numeric:Zi,smaller:Jv,typed:Mt}),_i=gg({addScalar:Gs,dot:Sf,equalScalar:En,matrix:Me,multiplyScalar:Hs,typed:Mt}),e1=gv({compare:Nf,isNaN:Df,isNumeric:Ef,typed:Mt}),r1=zv({add:Ki,config:ar,numeric:Zi,typed:Mt}),n1=Mv({add:Ki,matrix:Me,typed:Mt}),Bf=Sv({divideScalar:Gi,isZero:jv,matrix:Me,multiply:_i,subtractScalar:yf,typed:Mt,unaryMinus:Sa}),i1=wv({config:ar,larger:t1,numeric:Zi,typed:Mt}),Xs=Tv({abs:Uv,addScalar:Gs,det:Bf,divideScalar:Gi,identity:Mf,matrix:Me,multiply:_i,typed:Mt,unaryMinus:Sa}),s1=Iv({Complex:Ca,add:Ki,ctranspose:Kv,deepEqual:Vv,divideScalar:Gi,dot:Sf,dotDivide:Hv,equal:Ff,inv:Xs,matrix:Me,multiply:_i,typed:Mt}),o1=Vg({Complex:Ca,config:ar,fraction:bf,identity:Mf,inv:Xs,matrix:Me,multiply:_i,number:wf,typed:Mt}),a1=Rv({divideScalar:Gi,equalScalar:En,inv:Xs,matrix:Me,multiply:_i,typed:Mt}),Tf=kv({add:Ki,compare:Nf,divide:a1,partitionSelect:e1,typed:Mt});class u1{constructor(t,e,r){z(this,"_cacheData");z(this,"_variables");z(this,"_math");z(this,"_timeframe");this._cacheData={},this._variables=t,this._math=e,this._timeframe=r}alma({series:t,length:e,offset:r,sigma:n,floor:s},a){if(e===void 0||r===void 0||n===void 0)return;const l=this._cacheDataList(t,e,`alma_${a}`);if(l===void 0)return;let c=r*(e-1);s&&(c=Math.floor(c));const h=e/n;let p=0,f=0;for(let d=0;d<=e-1;d++){const g=Math.exp(-1*Math.pow(d-c,2)/(2*Math.pow(h,2)));p+=g,f+=l[l.length-1-(e-d-1)]*g}return f/p}sma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;let n=0;const s=this._cacheDataList(t,e,`sma_${r}`);if(s===void 0)return;const a=s.slice(-e);return n=r1(...a)/e,n}rma({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`sma_${r}`]=n;const{sum:s}=this._cacheData[`rma_${r}`]||{},a=1/e,l=s===void 0?this.sma({source:t,length:e},r):a*t+(1-a)*(s||0);return this._cacheDataHandle(`rma_${r}`,{sum:l}),l}atr({length:t},e){const{high:r,close:n}=this._cacheData[`atr_${e}`]||{},{high:s,close:a,low:l}=this._variables,c=r===void 0?s-l:Math.max(Math.max(s-l,Math.abs(s-n)),Math.abs(l-n));return this._cacheDataHandle(`atr_${e}`,{high:s,close:a}),this.rma({source:c,length:t},e)}barssince({condition:t},e){let{count:r}=this._cacheData[`barssince_${e}`]||{};if(t)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${e}`,{count:r}),r}stdev({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0)return;const s=this._cacheDataList(t,e,`stdev_${n}`),a=this.sma({source:t,length:e},n);if(s===void 0)return;let l=0;for(let c=0;c<e;c++){const h=this._sum(s[s.length-1-c],-(a||0));l+=h*h}return r||e<=1?Math.sqrt(l/e):Math.sqrt(l/(e-1))}_sum(t,e){let n=t+e;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[];const s=this.sma({source:t,length:e},n),a=this.stdev({source:t,length:e},n);if(s===void 0||a===void 0)return[];const l=r*a;return[s,s+l,s-l]}bbw({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.sma({source:t,length:e},n),a=this.stdev({source:t,length:e},n);if(s===void 0||a===void 0)return;const l=r*a;return(s+l-(s-l))/s}cci({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r),s=this.dev({source:t,length:e},r);if(!(n===void 0||s===void 0))return(t-n)/(.015*s)}change({source:t,length:e=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`change_${r}`]=n;const s=n[n.length-1-e];if(!(t===void 0||isNaN(t)))return s===void 0?s:typeof t=="boolean"?s!==t:t-s}cmo({series:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.change({source:t},r);if(n===void 0)return;const s=this._math.sum({source:n>=0?n:0,length:e},`sm1_${r}`),a=this._math.sum({source:n>=0?0:-n,length:e},`sm2_${r}`);if(!(s===void 0||a===void 0))return 100*(s-a)/(s+a)}cog({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this._cacheDataList(t,e,`cog_${r}`),s=this._math.sum({source:t,length:e},r);if(s===void 0||n===void 0)return;let a=0;for(let l=0;l<e;l++){const c=n[n.length-1-l];a+=c*(l+1)}return-a/s}correlation({source1:t,source2:e,length:r},n){if(t===void 0||isNaN(t)||e===void 0||isNaN(e)||r===void 0)return;const s=this._cacheDataList([t,e],r,`correlation_${n}`),a=this.sma({source:t,length:r},`sma1_${n}`),l=this.sma({source:e,length:r},`sma2_${n}`);if(a===void 0||l===void 0||s===void 0)return;let c=0,h=0,p=0;for(let d=0;d<r;d++){const[g,w]=s[s.length-1-d],m=g-a,D=w-l;c+=m*D,h+=m*m,p+=D*D}return isNaN(h)||isNaN(c)||isNaN(p)?void 0:c/Math.sqrt(h*p)}cross({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e||n<=s&&t>e}crossover({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n<=s&&t>e}crossunder({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e}cum({source:t=0},e){t=isNaN(t)?0:t;let{sum:r}=this._cacheData[`cum_${e}`]||{};return r=r||0,r+=t,this._cacheDataHandle(`cum_${e}`,{sum:r}),r}dev({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r);let s=0;const a=this._cacheDataList(t,e,`dev_${r}`);if(!(!a||n===void 0)){for(let l=0;l<e;l++){const c=a[a.length-1-l];s+=Math.abs(c-n)}return s/e}}dmi({diLength:t,adxSmoothing:e},r){if(t===void 0||e===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:s,high:a,close:l,PDMS:c,NDMS:h,TRS:p,ADX:f,count:d=0}=this._cacheData[n]||{},{low:g,high:w,close:m}=this._variables;if(s===void 0||a===void 0||l===void 0)return this._cacheData[n]={low:g,high:w,close:m,PDMS:c,NDMS:h,TRS:w-g,count:1},[void 0,void 0,void 0];let D=w-a,v=s-g;D=D>v&&D>0?D:0,v=v>D&&v>0?v:0,D===v&&(D=v=0);const E=Math.max(w-g,Math.abs(w-l),Math.abs(g-l));if(d<t)return this._cacheDataHandle(n,{low:g,high:w,close:m,PDMS:(c||0)+D,NDMS:(h||0)+v,TRS:(p||0)+E,count:d+1}),[void 0,void 0,void 0];{const b=c-c/t+D,N=h-h/t+v,x=p-p/t+E,F=b/x*100,M=N/x*100,S=Math.abs((F-M)/(F+M))*100;let I=S,C=[F,M,void 0];if(d+1-t<e){const T=d+1-t;I=((f||0)*(T-1)+S)/T}else I=(f*(e-1)+S)/e,C=[F,M,I];return this._cacheDataHandle(n,{low:g,high:w,close:m,PDMS:b,NDMS:N,TRS:x,ADX:I,count:d+1}),C}}ema({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;let{sum:n,count:s=1}=this._cacheData[`ema_${r}`]||{};const a=this.sma({source:t,length:e},r);if(s>e){const l=2/(e+1);n=n===void 0?t:l*t+(1-l)*(n||0)}else n=a;return s+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:s}),n}falling({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,fallings:s=[]}=this._cacheData[`falling_${r}`]||{};s.push(n>t);const a=s.slice(-e);return this._cacheDataHandle(`falling_${r}`,{source:t,fallings:a}),a.length<e?!1:a.every(l=>l)}rising({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,risings:s=[]}=this._cacheData[`rising_${r}`]||{};s.push(n<t);const a=s.slice(-e);return this._cacheDataHandle(`rising_${r}`,{source:t,risings:a}),a.length<e?!1:a.every(l=>l)}highest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`highest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.max(...l.slice(-e))}highestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`highestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((h,p,f,d)=>p>=d[h]?f:h,0)-e+1}wma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`wma_${r}`);if(!n)return;let s=0,a=0;for(let l=0;l<e;l++){const c=(e-l)*e;s+=c,a+=n[n.length-1-l]*c}return a/s}hma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this.wma({source:t,length:e},r),s=this.wma({source:t,length:Math.round(e/2)},r);return n===void 0||s===void 0?void 0:this.wma({source:2*s-n,length:Math.floor(Math.sqrt(e))},`hma_${r}`)}kc({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[void 0,void 0,void 0];const a=this.ema({source:t,length:e},s),{ta:l,high:c,low:h}=this._variables,p=n?l.tr:c-h,f=this.ema({source:p,length:e},`range_${s}`);return[a,a+f*r,a-f*r]}kcw({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const a=this.ema({source:t,length:e},s),{ta:l,high:c,low:h}=this._variables,p=n?l.tr:c-h,f=this.ema({source:p,length:e},`range_${s}`);return(a+f*r-(a-f*r))/a}linreg({source:t,length:e,offset:r},n){if(e===void 0||r===void 0)return;const s=this._cacheDataList(t,e,`dev_${n}`);if(!s)return;const a=s.slice(-e).filter(g=>g!==void 0);let l=0,c=0,h=0,p=0;for(const[g,w]of a.entries())l+=g,c+=w,h+=g*w,p+=g*g;const f=(e*h-l*c)/(e*p-l*l);return(c-f*l)/e+f*(e-1-r)}lowest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`lowest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.min(...l.slice(-e))}lowestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`lowestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((h,p,f,d)=>p<=d[h]?f:h,0)-e+1}macd({source:t,fastlen:e,slowlen:r,siglen:n},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const a=this.ema({source:t,length:e},`ema1_${s}`),l=this.ema({source:t,length:r},`ema2_${s}`);if(a===void 0||l===void 0)return[void 0,void 0,void 0];const c=a-l,h=this.ema({source:c,length:n},`macd_${s}`);if(h===void 0)return[c,h,void 0];const p=c-h;return[c,h,p]}max({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`max_${e}`]||0;return t>r&&(r=t),this._cacheData[`max_${e}`]=r,r}min({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`min_${e}`]||1/0;return t<r&&(r=t),this._cacheData[`min_${e}`]=r,r}median({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`dev_${r}`);if(n)return Tf(n.slice(-e))}mfi({series:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const{volume:n}=this._variables,s=this.change({source:t},r),a=this._math.sum({source:n*(s>=0?0:t),length:e},`lower_${r}`),l=this._math.sum({source:n*(s<=0?0:t),length:e},`upper_${r}`);if(!(l===void 0||a===void 0))return 100-100/(1+l/a)}mode({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`mode_${r}`);if(n)return Ba(xf(n.slice(-e)))}mom({source:t,length:e},r){if(e===void 0||e<0)return;const n=`mom_${r}`,s=this._cacheData[n]||[];if(s[this._variables.bar_index]=t,this._cacheData[n]=s,s.length<=e||t===void 0||isNaN(t))return;let a=s.length-e-1,l;for(;l===void 0&&a>=0;)l=s[a],a--;return l===void 0?l:t-l}percentile_linear_interpolation({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e+1,`percentile_linear_interpolation_${n}`);if(!s)return;const a=this._sort(s.slice(-(e+1))),l=a.length;r/=100;const c=1/(l*2);if(r<=c)return a[0];if(r>=1-1/(l*2))return a[l-1];for(const[h,p]of a.entries()){const f=a[h-1];if(r<(h+.5)/l)return f===void 0||p===void 0?void 0:f+(p-f)*(r-(h-.5)/l)/(1/l)}}percentile_nearest_rank({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||t===void 0||isNaN(t)||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e,`percentile_nearest_rank_${n}`);if(!s)return;const a=this._sort(s.slice(-e)),l=r/100*a.length,c=Math.ceil(l)-1;return a[c>=a.length?a.length-1:c]}percentrank({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`percentile_nearest_rank_${r}`);if(!n)return;const s=n.slice(-(e+1)),a=t;if(a===void 0)return;let l=0;for(let c=0;c<s.length;c++)s[c]!==void 0&&(s[c]<a||s[c]===a&&c<e)&&l++;return l/(s.length-1)*100}pivot_point_levels({type:t,anchor:e,developing:r},n){const s=new Xt;let{close:a,open:l,low:c,high:h}=this._variables;const p=`pivot_point_levels_${n}`,{close:f,low:d,high:g,open:w,result:m}=this._cacheData[p]||{};if(!e&&(g&&d&&(h=Math.max(g,h),c=Math.min(d,c)),this._cacheDataHandle(p,{close:a,open:l,low:c,high:h,result:m}),!r))return s._value=m||[],s;const D={close:a,open:l,low:c,high:h};e===!0&&!r&&(a=f,l=w,c=d,h=g);const v=this._getPivotPointLevels(h,c,a,l,r,t);return this._cacheDataHandle(p,{...D,result:v}),s._value=v,s}_getPivotPointLevels(t,e,r,n,s,a){if(r===void 0||n===void 0||e===void 0||t===void 0)return[];switch(a){case Un.traditional:return this._traditional(t,e,r);case Un.fibonacci:return this._fibonacci(t,e,r);case Un.woodie:return s?[]:this._woodie(t,e);case Un.classic:return this._classic(t,e,r);case Un.dm:return this._DM(t,e,r,n);case Un.camarilla:return this._camarilla(t,e,r);default:return[]}}_traditional(t,e,r){const n=(t+e+r)/3,s=n*2-e,a=n+(t-e),l=n*2+(t-2*e),c=n*3+(t-3*e),h=n*4+(t-4*e),p=n*2-t,f=n-(t-e),d=n*2-(2*t-e),g=n*3-(3*t-e),w=n*4-(4*t-e);return[n,s,p,a,f,l,d,c,g,h,w]}_fibonacci(t,e,r){const n=(t+e+r)/3,s=n+.382*(t-e),a=n-.382*(t-e),l=n+.618*(t-e),c=n-.618*(t-e),h=n+(t-e),p=n-(t-e);return[n,s,a,l,c,h,p]}_woodie(t,e){const{open:r}=this._variables,n=(t+e+2*r)/4,s=2*n-e,a=2*n-t,l=n+(t-e),c=n-(t-e),h=t+2*(n-e),p=e-2*(t-n),f=h+(t-e),d=p-(t-e);return[n,s,a,l,c,h,p,f,d]}_classic(t,e,r){const n=(t+e+r)/3,s=2*n-e,a=2*n-t,l=n+(t-e),c=n-(t-e),h=n+2*(t-e),p=n-2*(t-e),f=n+3*(t-e),d=n-3*(t-e);return[n,s,a,l,c,h,p,f,d]}_DM(t,e,r,n){let s;n===r?s=t+e+2*r:r>n?s=2*t+e+r:s=2*e+t+r;const a=s/4,l=s/2-e,c=s/2-t;return[a,l,c]}_camarilla(t,e,r){const n=(t+e+r)/3,s=r+1.1*(t-e)/12,a=r-1.1*(t-e)/12,l=r+1.1*(t-e)/6,c=r-1.1*(t-e)/6,h=r+1.1*(t-e)/4,p=r-1.1*(t-e)/4,f=r+1.1*(t-e)/2,d=r-1.1*(t-e)/2,g=t/e*r,w=r-(g-r);return[n,s,a,l,c,h,p,f,d,g,w]}pivothigh({source:t=this._variables.high,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivothigh_${n}`);if(!s)return;const a=s.slice(-(e+r+1)),l=a[e];return Math.max(...a)===l?l:void 0}pivotlow({source:t=this._variables.low,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivotlow_${n}`);if(!s)return;const a=s.slice(-(e+r+1)),l=a[e];return Math.min(...a)===l?l:void 0}range({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const n=this._cacheDataList(t,e,`range_${r}`);if(!n)return;const s=n.filter(c=>c!==void 0).slice(-e),a=Math.max(...s),l=Math.min(...s);return a-l}roc({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`roc_${r}`),s=this.change({source:t,length:e},r);if(n)return 100*s/n[n.length-1-e]}rsi({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},s=Math.max(t-n,0),a=Math.max(n-t,0),l=this.rma({source:s,length:e},`rma1_${r}`),c=this.rma({source:a,length:e},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:t}),!(l===void 0||c===void 0))return 100-100/(1+l/c)}sar({start:t,inc:e,max:r},n){if(t===void 0||e===void 0||r===void 0)return;const{close:s,low:a,high:l,preLow:c,preHigh:h,data:p={}}=this._cacheData[`sar_${n}`]||{};let{result:f,maxMin:d,acceleration:g,isBelow:w}=p,m=!1;const{close:D,low:v,high:E,bar_index:b}=this._variables;return b===1&&(D>s?(w=!0,d=E,f=a):(w=!1,d=v,f=l),m=!0,g=t),f=f+g*(d-f),w?f>v&&(m=!0,w=!1,f=Math.max(E,d||0),d=v,g=t):f<E&&(m=!0,w=!0,f=Math.min(v,d||0),d=E,g=t),m||(w?E>(d||0)&&(d=E,g=Math.min((g||0)+e,r)):v<(d||0)&&(d=v,g=Math.min((g||0)+e,r))),w?(f=Math.min(f,a),b>1&&(f=Math.min(f,c))):(f=Math.max(f,l),b>1&&(f=Math.max(f,h))),this._cacheDataHandle(`sar_${n}`,{high:E,close:D,low:v,preLow:a,preHigh:l,data:Object.assign(p,{result:f,maxMin:d,acceleration:g,isBelow:w})}),f}stoch({source:t,high:e,low:r,length:n},s){if(n===void 0||e===void 0||r===void 0||t===void 0||isNaN(t)||n<0)return;const a=this.lowest({source:r,length:n},s),l=this.highest({source:e,length:n},s);if(!(a===void 0||l===void 0))return 100*(this._variables.close-a)/(l-a)}supertrend({factor:t,atrPeriod:e},r){if(t===void 0||e===void 0)return[void 0,void 0];const{hl2:n,close:s}=this._variables,a=`supertrend_${r}`,{upperBand:l,lowerBand:c,superTrend:h,atr:p,close:f}=this._cacheData[a]||{},d=this.atr({length:e},r);if(d===void 0)return this._cacheDataHandle(a,{close:s}),[void 0,void 0];let g=n+t*d,w=n-t*d;const m=l||0,D=c||0;w=w>D||f<D?w:D,g=g<m||f>m?g:m;let v;p===void 0?v=1:h===m?v=s>g?-1:1:v=s<w?1:-1;const E=v===-1?w:g;return this._cacheDataHandle(a,{upperBand:g,lowerBand:w,superTrend:E,atr:d,close:s}),[E,v]}swma({source:t},e){let{list:r}=this._cacheData[`swma_${e}`]||{};if(r||(r=[]),r.push(t),r=r.slice(-4),this._cacheDataHandle(`swma_${e}`,{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:t=!1},e){const{close:r,low:n,high:s}=this._variables,{close:a}=this._cacheData[`tr_${e}`]||{};return this._cacheDataHandle(`tr_${e}`,{close:r}),a===void 0?t?s-n:void 0:Math.max(s-n,Math.abs(s-a),Math.abs(n-a))}tsi({source:t,short_length:e,long_length:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.change({source:t},n);if(s===void 0)return;const a=this.ema({source:Math.abs(s),length:e},`absema1_${n}`),l=this.ema({source:s,length:e},`ema1_${n}`);if(l===void 0)return;const c=this.ema({source:l,length:r},`ema2_${n}`),h=this.ema({source:a,length:e},`absema2_${n}`);if(c!==void 0)return c/h}valuewhen({condition:t,source:e,occurrence:r},n){if(e===void 0||r===void 0||r<0)return;let{list:s}=this._cacheData[`valuewhen_${n}`]||{};return s||(s=[]),t&&s.push(e),this._cacheDataHandle(`valuewhen_${n}`,{list:s}),s[s.length-1-r]}variance({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0||e<0)return;const s=this.sma({source:t,length:e},n),a=this._cacheDataList(t,e,`mode_${n}`);if(!a||s===void 0)return;const l=a.filter(h=>h!==void 0&&!isNaN(h)).slice(-e);if(l.length<e)return;const c=l.reduce((h,p)=>h+Math.pow(p-s,2),0);if(c!==void 0)return r||e<=1?c/e:c/(e-1)}vwap({source:t,anchor:e,stdev_mult:r},n){if(t===void 0)return;e=e===void 0?this._timeframe.change({timeframe:"1D"},n):e;const{volume:s}=this._variables;let{sum:a=0,sumV:l=0,count:c=0,isReset:h,sumS:p=0}=this._cacheData[`vwap_${n}`]||{};if(e&&(a=l=c=p=0,h=!0),!h)return r!==void 0?[]:void 0;const f=t*s+a,d=s+l,g=f/d;return c++,r!==void 0?(p=s*Math.pow(t,2)+p,this._cacheDataHandle(`vwap_${n}`,{sum:f,sumV:d,count:c,isReset:h,sumS:p}),this._computeBands(p,d,r,g)):(this._cacheDataHandle(`vwap_${n}`,{sum:f,sumV:d,count:c,isReset:h}),g)}_computeBands(t,e,r,n){let s=t/e-Math.pow(n,2);s=s<0?0:s;const a=Math.sqrt(s),l=a!==void 0&&!isNaN(a)?n+r*a:void 0,c=a!==void 0&&!isNaN(a)?n-r*a:void 0;return[n,l,c]}vwma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0||e<=0)return;const{volume:n}=this._variables,s=this.sma({source:t*n,length:e},`sma1_${r}`),a=this.sma({source:n,length:e},`sma2_${r}`);if(!(s===void 0||a===void 0))return s/a}wpr({length:t},e){if(t===void 0||t<=0)return;const r=this.highest({length:t},e),n=this.lowest({length:t},e),{close:s}=this._variables;if(!(r===void 0||n===void 0))return(r-s)/(r-n)*-100}_sort(t){const e=t.length;for(let r=0;r<e;r++){let n={};for(let s=0;s<e-r;s++){const{currentVal:a,currentIndex:l}=n,c=t[s];if(c!==void 0){if(a!==void 0&&c<a){t.splice(s,1),t.splice(l,0,c),n={currentIndex:l+1,currentVal:a};continue}n={currentIndex:s,currentVal:c}}}}return t}_cacheDataList(t,e,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=t,this._cacheData[r]=n;const s=n.filter(()=>!0);if(!(s.length<e))return s}_cacheDataHandle(t,e){const{barIndex:r}=this._cacheData[t]||{};r!==this._variables.bar_index&&(this._cacheData[t]=Object.assign(e,{barIndex:this._variables.bar_index}))}}const Of={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",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",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 undefined 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."};Wr.SERIES,Wr.SIMPLE,Wr.INPUT,Wr.CONST,Wr.INT,Wr.FLOAT,Wr.BOOL,Wr.COLOR,Wr.STRING;const l1=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"];class c1{constructor(t,e){z(this,"_cacheData");z(this,"_variables");z(this,"_errorListener");z(this,"_count");z(this,"_historyInputs");z(this,"_name");this._cacheData={},this._variables=t,this._errorListener=e,this._count=-1,this._name=`inputs_${Lp()}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(t){for(const e of t){const r=e.id;if(!this._cacheData[r])return;Object.assign(this._cacheData[r],{...e,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${e.index}`,{modifyDefval:e.sourceTypeName||e.defval})}}input(t,e){return this._cacheHandle(t,e)}int(t,e){return this._cacheHandle(t,e,Qe.INT)}bool(t,e){return this._cacheHandle(t,e,Qe.BOOL)}color(t,e){return this._cacheHandle(t,e,Qe.COLOR)}time(t,e){return this._cacheHandle(t,e,Qe.TIME)}float(t,e){return this._cacheHandle(t,e,Qe.FLOAT)}price(t,e){return this._cacheHandle(t,e,Qe.PRICE)}source(t,e){return this._cacheHandle(t,e,Qe.SOURCE)}string(t,e){return this._cacheHandle(t,e,Qe.STRING)}symbol(t,e){return this._cacheHandle(t,e,Qe.SYMBOL)}session(t,e){return this._cacheHandle(t,e,Qe.SESSION)}text_area(t,e){return this._cacheHandle(t,e,Qe.TEXT_AREA)}timeframe(t,e){return this._cacheHandle(t,e,Qe.TIMEFRAME)}_cacheHandle(t,e,r){const n=`${r||"input"}_${e}`,s=this._cacheData[n];if(t.defval===void 0&&this._errorListener.addError(Of.inputDefvalErr,e,Ee.Error),s)s.isModify?s.sourceTypeName&&(this._cacheData[n].defval=this._variables[s.sourceTypeName]):Object.assign(this._cacheData[n],t);else{const{defval:a,display:l}=t;this._displayVerify(e,l),this._count++,t={inputType:r,...t,index:this._count},this._cacheData[n]=t,this._judgeHistoryInputs(t),(r||t.inputType)===Qe.SOURCE?this._cacheData[n].options=l1:t.options&&!t.options.includes(a)&&this._errorListener.addError(`input's defval should be in options, but '${a}' is not in [${t.options.toString()}]`,e,Ee.Error)}return this._cacheData[n].defval}_judgeHistoryInputs(t){const{defval:e,sourceTypeName:r,index:n}=t;let s=r||e;const a=`in_${n}`,l=this._historyInputs[a];if(!l)self.workerStorage.setValue(this._name,a,{defval:s});else{const{defval:c,modifyDefval:h}=l;c===s?s=h||s:self.workerStorage.setValue(this._name,a,{defval:s})}r?t.sourceTypeName=s:t.defval=s}_displayVerify(t,e){!e||!e.length||e.includes(sr.dataWindow)||e.includes(sr.statusLine)||this._errorListener.addError("Invalid argument 'display' in 'input' call. Possible values: [display.none, display.data_window, display.status_line, display.all]",t,Ee.Error)}getInputs(){const t=Object.keys(this._cacheData),e=[];for(const r of t){const n=this._cacheData[r];n.id=r,e.push(n)}return e}_getGroups(t){const e=[];for(const[r,n]of t)e.push({name:r,inputs:n});return e}}class f1{color({x:t}){return t}new({color:t,transp:e=100}){_t(e)&&(e=100);const{r,g:n,b:s}=this._parseColor(t||"");return`rgba(${Math.round(r)}, ${Math.round(n)}, ${Math.round(s)}, ${(100-e)/100})`}rgb({red:t=0,green:e=0,blue:r=0,transp:n=0}){return _t(n)&&(n=0),_t(t)&&(t=0),_t(e)&&(e=0),_t(r)&&(r=0),`rgba(${t}, ${e}, ${r}, ${(100-n)/100})`}g({color:t}){return t?this._parseColor(t).g:0}r({color:t}){return t?this._parseColor(t).r:0}b({color:t}){return t?this._parseColor(t).b:0}t({color:t}){return t?Math.round(this._parseColor(t).a*100):0}from_gradient({value:t,bottom_value:e,top_value:r,bottom_color:n,top_color:s}){if(_t(t)||_t(e)||_t(r))return"rgba(0,0,0,1)";const a=(t-e)/(r-e),l=Math.min(Math.max(a,0),1),{r:c,g:h,b:p,a:f}=this._parseColor(n||"rgba(0,0,0,0)"),{r:d,g,b:w,a:m}=this._parseColor(s||"rgba(0,0,0,0)"),D=c+l*(d-c),v=h+l*(g-h),E=p+l*(w-p),b=f+l*(m-f);return`rgba(${Math.round(D)}, ${Math.round(v)}, ${Math.round(E)}, ${b.toFixed(2)})`}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=(255-parseInt(a,16))/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}}var zt={};const h1=Object.prototype.toString;function Hi(i){const t=h1.call(i);return t.endsWith("Array]")&&!t.includes("Big")}var p1=Object.freeze({__proto__:null,isAnyArray:Hi}),d1=be(p1);function _1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Hi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=i[r],l=r+1;l<s;l++)i[l]>a&&(a=i[l]);return a}function m1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Hi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=i[r],l=r+1;l<s;l++)i[l]<a&&(a=i[l]);return a}function g1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(Hi(i)){if(i.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var e;if(t.output!==void 0){if(!Hi(t.output))throw new TypeError("output option must be an array if specified");e=t.output}else e=new Array(i.length);var r=m1(i),n=_1(i);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=t.min,a=s===void 0?t.autoMinMax?r:0:s,l=t.max,c=l===void 0?t.autoMinMax?n:1:l;if(a>=c)throw new RangeError("min option must be smaller than max option");for(var h=(c-a)/(n-r),p=0;p<i.length;p++)e[p]=(i[p]-r)*h+a;return e}var v1=Object.freeze({__proto__:null,default:g1}),w1=be(v1);Object.defineProperty(zt,"__esModule",{value:!0});var tr=d1,If=w1;const Js=" ".repeat(2),$f=" ".repeat(4);function y1(){return Lf(this)}function Lf(i,t={}){const{maxRows:e=15,maxColumns:r=10,maxNumSize:n=8,padMinus:s="auto"}=t;return`${i.constructor.name} {
|
54
|
+
(`+oe(S,m)+", "+oe(N,m)+") ==> "+(this._values?oe(this._values[M],m):"X")}return b},n.prototype.toString=function(){return oe(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(m){if(m){if(xe(m)&&(m=m.toNumber()),!le(m)||!de(m))throw new TypeError("The parameter k must be an integer number")}else m=0;var D=m>0?m:0,v=m<0?-m:0,E=this._size[0],b=this._size[1],N=Math.min(E-v,b-D),x=[],F=[],M=[];M[0]=0;for(var S=D;S<b&&x.length<N;S++)for(var I=this._ptr[S],C=this._ptr[S+1],T=I;T<C;T++){var L=this._index[T];if(L===S-D+v){x.push(this._values[T]),F[x.length-1]=L-v;break}}return M.push(x.length),new n({values:x,index:F,ptr:M,size:[N,1]})},n.fromJSON=function(m){return new n(m)},n.diagonal=function(m,D,v,E,b){if(!ve(m))throw new TypeError("Array expected, size parameter");if(m.length!==2)throw new Error("Only two dimensions matrix are supported");if(m=m.map(function(Q){if(xe(Q)&&(Q=Q.toNumber()),!le(Q)||!de(Q)||Q<1)throw new Error("Size values must be positive integers");return Q}),v){if(xe(v)&&(v=v.toNumber()),!le(v)||!de(v))throw new TypeError("The parameter k must be an integer number")}else v=0;var N=e,x=0;Zr(b)&&(N=t.find(e,[b,b])||e,x=t.convert(0,b));var F=v>0?v:0,M=v<0?-v:0,S=m[0],I=m[1],C=Math.min(S-M,I-F),T;if(ve(D)){if(D.length!==C)throw new Error("Invalid value array length");T=function(tt){return D[tt]}}else if(fe(D)){var L=D.size();if(L.length!==1||L[0]!==C)throw new Error("Invalid matrix length");T=function(tt){return D.get([tt])}}else T=function(){return D};for(var U=[],k=[],W=[],P=0;P<I;P++){W.push(U.length);var K=P-F;if(K>=0&&K<C){var G=T(K);N(G,x)||(k.push(K+M),U.push(G))}}return W.push(U.length),new n({values:U,index:k,ptr:W,size:[S,I]})},n.prototype.swapRows=function(m,D){if(!le(m)||!de(m)||!le(D)||!de(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 we(m,this._size[0]),we(D,this._size[0]),n._swapRows(m,D,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(m,D,v,E,b){for(var N=E[m],x=E[m+1],F=N;F<x;F++)b(v[F],D[F])},n._swapRows=function(m,D,v,E,b,N){for(var x=0;x<v;x++){var F=N[x],M=N[x+1],S=h(m,F,M,b),I=h(D,F,M,b);if(S<M&&I<M&&b[S]===m&&b[I]===D){if(E){var C=E[S];E[S]=E[I],E[I]=C}continue}if(S<M&&b[S]===m&&(I>=M||b[I]!==D)){var T=E?E[S]:void 0;b.splice(I,0,D),E&&E.splice(I,0,T),b.splice(I<=S?S+1:S,1),E&&E.splice(I<=S?S+1:S,1);continue}if(I<M&&b[I]===D&&(S>=M||b[S]!==m)){var L=E?E[I]:void 0;b.splice(S,0,m),E&&E.splice(S,0,L),b.splice(S<=I?I+1:I,1),E&&E.splice(S<=I?I+1:I,1)}}},n},{isClass:!0}),vm="number",wm=["typed"];function ym(i){var t=i.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(t){var e={"0b":2,"0o":8,"0x":16}[t[1]],r=t[2],n=t[3];return{input:i,radix:e,integerPart:r,fractionalPart:n}}else return null}function Dm(i){for(var t=parseInt(i.integerPart,i.radix),e=0,r=0;r<i.fractionalPart.length;r++){var n=parseInt(i.fractionalPart[r],i.radix);e+=n/Math.pow(i.radix,r+1)}var s=t+e;if(isNaN(s))throw new SyntaxError('String "'+i.input+'" is not a valid number');return s}var bm=mt(vm,wm,i=>{var{typed:t}=i,e=t("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var s=ym(n);if(s)return Dm(s);var a=0,l=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);l&&(a=Number(l[2]),n=l[1]);var c=Number(n);if(isNaN(c))throw new SyntaxError('String "'+n+'" is not a valid number');if(l){if(c>2**a-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));c>=2**(a-1)&&(c=c-2**a)}return c},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),null:function(n){return 0},"Unit, string | Unit":function(n,s){return n.toNumber(s)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))});return e.fromJSON=function(r){return parseFloat(r.value)},e}),Em="bignumber",xm=["typed","BigNumber"],Am=mt(Em,xm,i=>{var{typed:t,BigNumber:e}=i;return t("bignumber",{"":function(){return new e(0)},number:function(n){return new e(n+"")},string:function(n){var s=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(s){var a=s[2],l=e(s[1]),c=new e(2).pow(Number(a));if(l.gt(c.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var h=new e(2).pow(Number(a)-1);return l.gte(h)?l.sub(c):l}return new e(n)},BigNumber:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Fraction:function(n){return new e(n.n).div(n.d).times(n.s)},null:function(n){return new e(0)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))})}),Cm="fraction",Fm=["typed","Fraction"],Mm=mt(Cm,Fm,i=>{var{typed:t,Fraction:e}=i;return t("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new e(n)},string:function(n){return new e(n)},"number, number":function(n,s){return new e(n,s)},null:function(n){return new e(0)},BigNumber:function(n){return new e(n.toString())},Fraction:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Object:function(n){return new e(n)},"Array | Matrix":t.referToSelf(r=>n=>Rr(n,r))})}),Lc="matrix",Nm=["typed","Matrix","DenseMatrix","SparseMatrix"],Sm=mt(Lc,Nm,i=>{var{typed:t,Matrix:e,DenseMatrix:r,SparseMatrix:n}=i;return t(Lc,{"":function(){return s([])},string:function(l){return s([],l)},"string, string":function(l,c){return s([],l,c)},Array:function(l){return s(l)},Matrix:function(l){return s(l,l.storage())},"Array | Matrix, string":s,"Array | Matrix, string, string":s});function s(a,l,c){if(l==="dense"||l==="default"||l===void 0)return new r(a,c);if(l==="sparse")return new n(a,c);throw new TypeError("Unknown matrix type "+JSON.stringify(l)+".")}}),Rc="unaryMinus",Bm=["typed"],Tm=mt(Rc,Bm,i=>{var{typed:t}=i;return t(Rc,{number:Mc,"Complex | BigNumber | Fraction":e=>e.neg(),Unit:t.referToSelf(e=>r=>{var n=r.clone();return n.value=t.find(e,n.valueType())(r.value),n}),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Pc="abs",Om=["typed"],Im=mt(Pc,Om,i=>{var{typed:t}=i;return t(Pc,{number:xc,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),zc="addScalar",$m=["typed"],Lm=mt(zc,$m,i=>{var{typed:t}=i;return t(zc,{"number, number":Ac,"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":t.referToSelf(e=>(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 s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),qc="subtractScalar",Rm=["typed"],Pm=mt(qc,Rm,i=>{var{typed:t}=i;return t(qc,{"number, number":Cc,"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":t.referToSelf(e=>(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 s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),zm="matAlgo11xS0s",qm=["typed","equalScalar"],xa=mt(zm,qm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=e,v=0,E=a;typeof d=="string"&&(m=d,D=t.find(e,[m,m]),v=t.convert(0,m),s=t.convert(s,m),E=t.find(a,[m,m]));for(var b=[],N=[],x=[],F=0;F<w;F++){x[F]=N.length;for(var M=p[F],S=p[F+1],I=M;I<S;I++){var C=h[I],T=l?E(s,c[I]):E(c[I],s);D(T,v)||(N.push(C),b.push(T))}}return x[w]=N.length,n.createSparseMatrix({values:b,index:N,ptr:x,size:[g,w],datatype:m})}}),km="matAlgo12xSfs",Um=["typed","DenseMatrix"],pi=mt(km,Um,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=a;typeof d=="string"&&(m=d,s=t.convert(s,m),D=t.find(a,[m,m]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=p[N],M=p[N+1],S=F;S<M;S++){var I=h[S];E[I]=c[S],b[I]=x}for(var C=0;C<g;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?D(s,E[C]):D(E[C],s):v[C][N]=l?D(s,0):D(0,s)}return new e({data:v,size:[g,w],datatype:m})}}),Wm="matAlgo14xDs",jm=["typed"],Aa=mt(Wm,jm,i=>{var{typed:t}=i;return function(n,s,a,l){var c=n._data,h=n._size,p=n._datatype,f,d=a;typeof p=="string"&&(f=p,s=t.convert(s,f),d=t.find(a,[f,f]));var g=h.length>0?e(d,0,h,h[0],c,s,l):[];return n.createDenseMatrix({data:g,size:re(h),datatype:f})};function e(r,n,s,a,l,c,h){var p=[];if(n===s.length-1)for(var f=0;f<a;f++)p[f]=h?r(c,l[f]):r(l[f],c);else for(var d=0;d<a;d++)p[d]=e(r,n+1,s,s[n+1],l[d],c,h);return p}}),Ym="matAlgo02xDS0",Zm=["typed","equalScalar"],Gm=mt(Ym,Zm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a,l){var c=n._data,h=n._size,p=n._datatype||n.getDataType(),f=s._values,d=s._index,g=s._ptr,w=s._size,m=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==w.length)throw new Gt(h.length,w.length);if(h[0]!==w[0]||h[1]!==w[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+w+")");if(!f)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var D=h[0],v=h[1],E,b=e,N=0,x=a;typeof p=="string"&&p===m&&p!=="mixed"&&(E=p,b=t.find(e,[E,E]),N=t.convert(0,E),x=t.find(a,[E,E]));for(var F=[],M=[],S=[],I=0;I<v;I++){S[I]=M.length;for(var C=g[I],T=g[I+1],L=C;L<T;L++){var U=d[L],k=l?x(f[L],c[U][I]):x(c[U][I],f[L]);b(k,N)||(M.push(U),F.push(k))}}return S[v]=M.length,s.createSparseMatrix({values:F,index:M,ptr:S,size:[D,v],datatype:p===n._datatype&&m===s._datatype?E:void 0})}}),Km="matAlgo03xDSf",Hm=["typed"],di=mt(Km,Hm,i=>{var{typed:t}=i;return function(r,n,s,a){var l=r._data,c=r._size,h=r._datatype||r.getDataType(),p=n._values,f=n._index,d=n._ptr,g=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==g.length)throw new Gt(c.length,g.length);if(c[0]!==g[0]||c[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+g+")");if(!p)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var m=c[0],D=c[1],v,E=0,b=s;typeof h=="string"&&h===w&&h!=="mixed"&&(v=h,E=t.convert(0,v),b=t.find(s,[v,v]));for(var N=[],x=0;x<m;x++)N[x]=[];for(var F=[],M=[],S=0;S<D;S++){for(var I=S+1,C=d[S],T=d[S+1],L=C;L<T;L++){var U=f[L];F[U]=a?b(p[L],l[U][S]):b(l[U][S],p[L]),M[U]=I}for(var k=0;k<m;k++)M[k]===I?N[k][S]=F[k]:N[k][S]=a?b(E,l[k][S]):b(l[k][S],E)}return r.createDenseMatrix({data:N,size:[m,D],datatype:h===r._datatype&&w===n._datatype?v:void 0})}}),Xm="matAlgo05xSfSf",Jm=["typed","equalScalar"],kc=mt(Xm,Jm,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a){var l=n._values,c=n._index,h=n._ptr,p=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType(),d=s._values,g=s._index,w=s._ptr,m=s._size,D=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==m.length)throw new Gt(p.length,m.length);if(p[0]!==m[0]||p[1]!==m[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+m+")");var v=p[0],E=p[1],b,N=e,x=0,F=a;typeof f=="string"&&f===D&&f!=="mixed"&&(b=f,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(a,[b,b]));var M=l&&d?[]:void 0,S=[],I=[],C=M?[]:void 0,T=M?[]:void 0,L=[],U=[],k,W,P,K;for(W=0;W<E;W++){I[W]=S.length;var G=W+1;for(P=h[W],K=h[W+1];P<K;P++)k=c[P],S.push(k),L[k]=G,C&&(C[k]=l[P]);for(P=w[W],K=w[W+1];P<K;P++)k=g[P],L[k]!==G&&S.push(k),U[k]=G,T&&(T[k]=d[P]);if(M)for(P=I[W];P<S.length;){k=S[P];var Q=L[k],tt=U[k];if(Q===G||tt===G){var ct=Q===G?C[k]:x,vt=tt===G?T[k]:x,lt=F(ct,vt);N(lt,x)?S.splice(P,1):(M.push(lt),P++)}}}return I[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:I,size:[v,E],datatype:f===n._datatype&&D===s._datatype?b:void 0})}}),Qm="matAlgo13xDD",Vm=["typed"],tg=mt(Qm,Vm,i=>{var{typed:t}=i;return function(n,s,a){var l=n._data,c=n._size,h=n._datatype,p=s._data,f=s._size,d=s._datatype,g=[];if(c.length!==f.length)throw new Gt(c.length,f.length);for(var w=0;w<c.length;w++){if(c[w]!==f[w])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+f+")");g[w]=c[w]}var m,D=a;typeof h=="string"&&h===d&&(m=h,D=t.find(a,[m,m]));var v=g.length>0?e(D,0,g,g[0],l,p):[];return n.createDenseMatrix({data:v,size:g,datatype:m})};function e(r,n,s,a,l,c){var h=[];if(n===s.length-1)for(var p=0;p<a;p++)h[p]=r(l[p],c[p]);else for(var f=0;f<a;f++)h[f]=e(r,n+1,s,s[n+1],l[f],c[f]);return h}}),eg="broadcast",rg=["concat"],ng=mt(eg,rg,i=>{var{concat:t}=i;return function(n,s){var a=Math.max(n._size.length,s._size.length);if(n._size.length===s._size.length&&n._size.every((w,m)=>w===s._size[m]))return[n,s];for(var l=e(n._size,a,0),c=e(s._size,a,0),h=[],p=0;p<a;p++)h[p]=Math.max(l[p],c[p]);Cs(l,h),Cs(c,h);var f=n.clone(),d=s.clone();f._size.length<a?f.reshape(e(f._size,a,1)):d._size.length<a&&d.reshape(e(d._size,a,1));for(var g=0;g<a;g++)f._size[g]<h[g]&&(f=r(f,h[g],g)),d._size[g]<h[g]&&(d=r(d,h[g],g));return[f,d]};function e(n,s,a){return[...Array(s-n.length).fill(a),...n]}function r(n,s,a){return t(...Array(s).fill(n),a)}}),ig="matrixAlgorithmSuite",sg=["typed","matrix","concat"],jn=mt(ig,sg,i=>{var{typed:t,matrix:e,concat:r}=i,n=tg({typed:t}),s=Aa({typed:t}),a=ng({concat:r});return function(c){var h=c.elop,p=c.SD||c.DS,f;h?(f={"DenseMatrix, DenseMatrix":(m,D)=>n(...a(m,D),h),"Array, Array":(m,D)=>n(...a(e(m),e(D)),h).valueOf(),"Array, DenseMatrix":(m,D)=>n(...a(e(m),D),h),"DenseMatrix, Array":(m,D)=>n(...a(m,e(D)),h)},c.SS&&(f["SparseMatrix, SparseMatrix"]=(m,D)=>c.SS(...a(m,D),h,!1)),c.DS&&(f["DenseMatrix, SparseMatrix"]=(m,D)=>c.DS(...a(m,D),h,!1),f["Array, SparseMatrix"]=(m,D)=>c.DS(...a(e(m),D),h,!1)),p&&(f["SparseMatrix, DenseMatrix"]=(m,D)=>p(...a(D,m),h,!0),f["SparseMatrix, Array"]=(m,D)=>p(...a(e(D),m),h,!0))):(f={"DenseMatrix, DenseMatrix":t.referToSelf(m=>(D,v)=>n(...a(D,v),m)),"Array, Array":t.referToSelf(m=>(D,v)=>n(...a(e(D),e(v)),m).valueOf()),"Array, DenseMatrix":t.referToSelf(m=>(D,v)=>n(...a(e(D),v),m)),"DenseMatrix, Array":t.referToSelf(m=>(D,v)=>n(...a(D,e(v)),m))},c.SS&&(f["SparseMatrix, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.SS(...a(D,v),m,!1))),c.DS&&(f["DenseMatrix, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.DS(...a(D,v),m,!1)),f["Array, SparseMatrix"]=t.referToSelf(m=>(D,v)=>c.DS(...a(e(D),v),m,!1))),p&&(f["SparseMatrix, DenseMatrix"]=t.referToSelf(m=>(D,v)=>p(...a(v,D),m,!0)),f["SparseMatrix, Array"]=t.referToSelf(m=>(D,v)=>p(...a(e(v),D),m,!0))));var d=c.scalar||"any",g=c.Ds||c.Ss;g&&(h?(f["DenseMatrix,"+d]=(m,D)=>s(m,D,h,!1),f[d+", DenseMatrix"]=(m,D)=>s(D,m,h,!0),f["Array,"+d]=(m,D)=>s(e(m),D,h,!1).valueOf(),f[d+", Array"]=(m,D)=>s(e(D),m,h,!0).valueOf()):(f["DenseMatrix,"+d]=t.referToSelf(m=>(D,v)=>s(D,v,m,!1)),f[d+", DenseMatrix"]=t.referToSelf(m=>(D,v)=>s(v,D,m,!0)),f["Array,"+d]=t.referToSelf(m=>(D,v)=>s(e(D),v,m,!1).valueOf()),f[d+", Array"]=t.referToSelf(m=>(D,v)=>s(e(v),D,m,!0).valueOf())));var w=c.sS!==void 0?c.sS:c.Ss;return h?(c.Ss&&(f["SparseMatrix,"+d]=(m,D)=>c.Ss(m,D,h,!1)),w&&(f[d+", SparseMatrix"]=(m,D)=>w(D,m,h,!0))):(c.Ss&&(f["SparseMatrix,"+d]=t.referToSelf(m=>(D,v)=>c.Ss(D,v,m,!1))),w&&(f[d+", SparseMatrix"]=t.referToSelf(m=>(D,v)=>w(v,D,m,!0)))),h&&h.signatures&&Il(f,h.signatures),f}}),og="matAlgo01xDSid",ag=["typed"],Uc=mt(og,ag,i=>{var{typed:t}=i;return function(r,n,s,a){var l=r._data,c=r._size,h=r._datatype||r.getDataType(),p=n._values,f=n._index,d=n._ptr,g=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==g.length)throw new Gt(c.length,g.length);if(c[0]!==g[0]||c[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+g+")");if(!p)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var m=c[0],D=c[1],v=typeof h=="string"&&h!=="mixed"&&h===w?h:void 0,E=v?t.find(s,[v,v]):s,b,N,x=[];for(b=0;b<m;b++)x[b]=[];var F=[],M=[];for(N=0;N<D;N++){for(var S=N+1,I=d[N],C=d[N+1],T=I;T<C;T++)b=f[T],F[b]=a?E(p[T],l[b][N]):E(l[b][N],p[T]),M[b]=S;for(b=0;b<m;b++)M[b]===S?x[b][N]=F[b]:x[b][N]=l[b][N]}return r.createDenseMatrix({data:x,size:[m,D],datatype:h===r._datatype&&w===n._datatype?v:void 0})}}),ug="matAlgo04xSidSid",lg=["typed","equalScalar"],cg=mt(ug,lg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,a){var l=n._values,c=n._index,h=n._ptr,p=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType(),d=s._values,g=s._index,w=s._ptr,m=s._size,D=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==m.length)throw new Gt(p.length,m.length);if(p[0]!==m[0]||p[1]!==m[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+m+")");var v=p[0],E=p[1],b,N=e,x=0,F=a;typeof f=="string"&&f===D&&f!=="mixed"&&(b=f,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(a,[b,b]));var M=l&&d?[]:void 0,S=[],I=[],C=l&&d?[]:void 0,T=l&&d?[]:void 0,L=[],U=[],k,W,P,K,G;for(W=0;W<E;W++){I[W]=S.length;var Q=W+1;for(K=h[W],G=h[W+1],P=K;P<G;P++)k=c[P],S.push(k),L[k]=Q,C&&(C[k]=l[P]);for(K=w[W],G=w[W+1],P=K;P<G;P++)if(k=g[P],L[k]===Q){if(C){var tt=F(C[k],d[P]);N(tt,x)?L[k]=null:C[k]=tt}}else S.push(k),U[k]=Q,T&&(T[k]=d[P]);if(C&&T)for(P=I[W];P<S.length;)k=S[P],L[k]===Q?(M[P]=C[k],P++):U[k]===Q?(M[P]=T[k],P++):S.splice(P,1)}return I[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:I,size:[v,E],datatype:f===n._datatype&&D===s._datatype?b:void 0})}}),fg="matAlgo10xSids",hg=["typed","DenseMatrix"],Wc=mt(fg,hg,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,a,l){var c=n._values,h=n._index,p=n._ptr,f=n._size,d=n._datatype;if(!c)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var g=f[0],w=f[1],m,D=a;typeof d=="string"&&(m=d,s=t.convert(s,m),D=t.find(a,[m,m]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=p[N],M=p[N+1],S=F;S<M;S++){var I=h[S];E[I]=c[S],b[I]=x}for(var C=0;C<g;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?D(s,E[C]):D(E[C],s):v[C][N]=s}return new e({data:v,size:[g,w],datatype:m})}}),pg="multiplyScalar",dg=["typed"],_g=mt(pg,dg,i=>{var{typed:t}=i;return t("multiplyScalar",{"number, number":Fc,"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":(e,r)=>r.multiply(e),"Unit, number | Fraction | BigNumber | Complex | Unit":(e,r)=>e.multiply(r)})}),jc="multiply",mg=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],gg=mt(jc,mg,i=>{var{typed:t,matrix:e,addScalar:r,multiplyScalar:n,equalScalar:s,dot:a}=i,l=xa({typed:t,equalScalar:s}),c=Aa({typed:t});function h(x,F){switch(x.length){case 1:switch(F.length){case 1:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+x[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(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+x[1]+") must match Vector length ("+F[0]+")");break;case 2:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+x[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 "+x.length+" dimensions)")}}function p(x,F,M){if(M===0)throw new Error("Cannot multiply two empty vectors");return a(x,F)}function f(x,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return d(x,F)}function d(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._size,L=F._datatype||F.getDataType(),U=S[0],k=T[1],W,P=r,K=n;I&&L&&I===L&&typeof I=="string"&&I!=="mixed"&&(W=I,P=t.find(r,[W,W]),K=t.find(n,[W,W]));for(var G=[],Q=0;Q<k;Q++){for(var tt=K(M[0],C[0][Q]),ct=1;ct<U;ct++)tt=P(tt,K(M[ct],C[ct][Q]));G[Q]=tt}return x.createDenseMatrix({data:G,size:[k],datatype:I===x._datatype&&L===F._datatype?W:void 0})}var g=t("_multiplyMatrixVector",{"DenseMatrix, any":m,"SparseMatrix, any":E}),w=t("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":D,"DenseMatrix, SparseMatrix":v,"SparseMatrix, DenseMatrix":b,"SparseMatrix, SparseMatrix":N});function m(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._datatype||F.getDataType(),L=S[0],U=S[1],k,W=r,P=n;I&&T&&I===T&&typeof I=="string"&&I!=="mixed"&&(k=I,W=t.find(r,[k,k]),P=t.find(n,[k,k]));for(var K=[],G=0;G<L;G++){for(var Q=M[G],tt=P(Q[0],C[0]),ct=1;ct<U;ct++)tt=W(tt,P(Q[ct],C[ct]));K[G]=tt}return x.createDenseMatrix({data:K,size:[L],datatype:I===x._datatype&&T===F._datatype?k:void 0})}function D(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._data,T=F._size,L=F._datatype||F.getDataType(),U=S[0],k=S[1],W=T[1],P,K=r,G=n;I&&L&&I===L&&typeof I=="string"&&I!=="mixed"&&I!=="mixed"&&(P=I,K=t.find(r,[P,P]),G=t.find(n,[P,P]));for(var Q=[],tt=0;tt<U;tt++){var ct=M[tt];Q[tt]=[];for(var vt=0;vt<W;vt++){for(var lt=G(ct[0],C[0][vt]),yt=1;yt<k;yt++)lt=K(lt,G(ct[yt],C[yt][vt]));Q[tt][vt]=lt}}return x.createDenseMatrix({data:Q,size:[U,W],datatype:I===x._datatype&&L===F._datatype?P:void 0})}function v(x,F){var M=x._data,S=x._size,I=x._datatype||x.getDataType(),C=F._values,T=F._index,L=F._ptr,U=F._size,k=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!C)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var W=S[0],P=U[1],K,G=r,Q=n,tt=s,ct=0;I&&k&&I===k&&typeof I=="string"&&I!=="mixed"&&(K=I,G=t.find(r,[K,K]),Q=t.find(n,[K,K]),tt=t.find(s,[K,K]),ct=t.convert(0,K));for(var vt=[],lt=[],yt=[],bt=F.createSparseMatrix({values:vt,index:lt,ptr:yt,size:[W,P],datatype:I===x._datatype&&k===F._datatype?K:void 0}),Bt=0;Bt<P;Bt++){yt[Bt]=lt.length;var Et=L[Bt],ne=L[Bt+1];if(ne>Et)for(var Ot=0,Nt=0;Nt<W;Nt++){for(var se=Nt+1,Vt=void 0,qt=Et;qt<ne;qt++){var Kt=T[qt];Ot!==se?(Vt=Q(M[Nt][Kt],C[qt]),Ot=se):Vt=G(Vt,Q(M[Nt][Kt],C[qt]))}Ot===se&&!tt(Vt,ct)&&(lt.push(Nt),vt.push(Vt))}}return yt[P]=lt.length,bt}function E(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var T=F._data,L=F._datatype||F.getDataType(),U=x._size[0],k=F._size[0],W=[],P=[],K=[],G,Q=r,tt=n,ct=s,vt=0;C&&L&&C===L&&typeof C=="string"&&C!=="mixed"&&(G=C,Q=t.find(r,[G,G]),tt=t.find(n,[G,G]),ct=t.find(s,[G,G]),vt=t.convert(0,G));var lt=[],yt=[];K[0]=0;for(var bt=0;bt<k;bt++){var Bt=T[bt];if(!ct(Bt,vt))for(var Et=I[bt],ne=I[bt+1],Ot=Et;Ot<ne;Ot++){var Nt=S[Ot];yt[Nt]?lt[Nt]=Q(lt[Nt],tt(Bt,M[Ot])):(yt[Nt]=!0,P.push(Nt),lt[Nt]=tt(Bt,M[Ot]))}}for(var se=P.length,Vt=0;Vt<se;Vt++){var qt=P[Vt];W[Vt]=lt[qt]}return K[1]=P.length,x.createSparseMatrix({values:W,index:P,ptr:K,size:[U,1],datatype:C===x._datatype&&L===F._datatype?G:void 0})}function b(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var T=F._data,L=F._datatype||F.getDataType(),U=x._size[0],k=F._size[0],W=F._size[1],P,K=r,G=n,Q=s,tt=0;C&&L&&C===L&&typeof C=="string"&&C!=="mixed"&&(P=C,K=t.find(r,[P,P]),G=t.find(n,[P,P]),Q=t.find(s,[P,P]),tt=t.convert(0,P));for(var ct=[],vt=[],lt=[],yt=x.createSparseMatrix({values:ct,index:vt,ptr:lt,size:[U,W],datatype:C===x._datatype&&L===F._datatype?P:void 0}),bt=[],Bt=[],Et=0;Et<W;Et++){lt[Et]=vt.length;for(var ne=Et+1,Ot=0;Ot<k;Ot++){var Nt=T[Ot][Et];if(!Q(Nt,tt))for(var se=I[Ot],Vt=I[Ot+1],qt=se;qt<Vt;qt++){var Kt=S[qt];Bt[Kt]!==ne?(Bt[Kt]=ne,vt.push(Kt),bt[Kt]=G(Nt,M[qt])):bt[Kt]=K(bt[Kt],G(Nt,M[qt]))}}for(var Ne=lt[Et],lr=vt.length,Be=Ne;Be<lr;Be++){var nn=vt[Be];ct[Be]=bt[nn]}}return lt[W]=vt.length,yt}function N(x,F){var M=x._values,S=x._index,I=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType(),T=F._values,L=F._index,U=F._ptr,k=F._datatype||F._data===void 0?F._datatype:F.getDataType(),W=x._size[0],P=F._size[1],K=M&&T,G,Q=r,tt=n;C&&k&&C===k&&typeof C=="string"&&C!=="mixed"&&(G=C,Q=t.find(r,[G,G]),tt=t.find(n,[G,G]));for(var ct=K?[]:void 0,vt=[],lt=[],yt=x.createSparseMatrix({values:ct,index:vt,ptr:lt,size:[W,P],datatype:C===x._datatype&&k===F._datatype?G:void 0}),bt=K?[]:void 0,Bt=[],Et,ne,Ot,Nt,se,Vt,qt,Kt,Ne=0;Ne<P;Ne++){lt[Ne]=vt.length;var lr=Ne+1;for(se=U[Ne],Vt=U[Ne+1],Nt=se;Nt<Vt;Nt++)if(Kt=L[Nt],K)for(ne=I[Kt],Ot=I[Kt+1],Et=ne;Et<Ot;Et++)qt=S[Et],Bt[qt]!==lr?(Bt[qt]=lr,vt.push(qt),bt[qt]=tt(T[Nt],M[Et])):bt[qt]=Q(bt[qt],tt(T[Nt],M[Et]));else for(ne=I[Kt],Ot=I[Kt+1],Et=ne;Et<Ot;Et++)qt=S[Et],Bt[qt]!==lr&&(Bt[qt]=lr,vt.push(qt));if(K)for(var Be=lt[Ne],nn=vt.length,xn=Be;xn<nn;xn++){var sn=vt[xn];ct[xn]=bt[sn]}}return lt[P]=vt.length,yt}return t(jc,n,{"Array, Array":t.referTo("Matrix, Matrix",x=>(F,M)=>{h(Fe(F),Fe(M));var S=x(e(F),e(M));return fe(S)?S.valueOf():S}),"Matrix, Matrix":function(F,M){var S=F.size(),I=M.size();return h(S,I),S.length===1?I.length===1?p(F,M,S[0]):f(F,M):I.length===1?g(F,M):w(F,M)},"Matrix, Array":t.referTo("Matrix,Matrix",x=>(F,M)=>x(F,e(M))),"Array, Matrix":t.referToSelf(x=>(F,M)=>x(e(F,M.storage()),M)),"SparseMatrix, any":function(F,M){return l(F,M,n,!1)},"DenseMatrix, any":function(F,M){return c(F,M,n,!1)},"any, SparseMatrix":function(F,M){return l(M,F,n,!0)},"any, DenseMatrix":function(F,M){return c(M,F,n,!0)},"Array, any":function(F,M){return c(e(F),M,n,!1).valueOf()},"any, Array":function(F,M){return c(e(M),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":t.referToSelf(x=>(F,M,S)=>{for(var I=x(F,M),C=0;C<S.length;C++)I=x(I,S[C]);return I})})}),Yc="subtract",vg=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],wg=mt(Yc,vg,i=>{var{typed:t,matrix:e,equalScalar:r,subtractScalar:n,unaryMinus:s,DenseMatrix:a,concat:l}=i,c=Uc({typed:t}),h=di({typed:t}),p=kc({typed:t,equalScalar:r}),f=Wc({typed:t,DenseMatrix:a}),d=pi({typed:t,DenseMatrix:a}),g=jn({typed:t,matrix:e,concat:l});return t(Yc,{"any, any":n},g({elop:n,SS:p,DS:c,SD:h,Ss:d,sS:f}))}),yg="matAlgo07xSSf",Dg=["typed","DenseMatrix"],ks=mt(yg,Dg,i=>{var{typed:t,DenseMatrix:e}=i;return function(s,a,l){var c=s._size,h=s._datatype||s._data===void 0?s._datatype:s.getDataType(),p=a._size,f=a._datatype||a._data===void 0?a._datatype:a.getDataType();if(c.length!==p.length)throw new Gt(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+p+")");var d=c[0],g=c[1],w,m=0,D=l;typeof h=="string"&&h===f&&h!=="mixed"&&(w=h,m=t.convert(0,w),D=t.find(l,[w,w]));var v,E,b=[];for(v=0;v<d;v++)b[v]=[];var N=[],x=[],F=[],M=[];for(E=0;E<g;E++){var S=E+1;for(r(s,E,F,N,S),r(a,E,M,x,S),v=0;v<d;v++){var I=F[v]===S?N[v]:m,C=M[v]===S?x[v]:m;b[v][E]=D(I,C)}}return new e({data:b,size:[d,g],datatype:h===s._datatype&&f===a._datatype?w:void 0})};function r(n,s,a,l,c){for(var h=n._values,p=n._index,f=n._ptr,d=f[s],g=f[s+1];d<g;d++){var w=p[d];a[w]=c,l[w]=h[d]}}}),Zc="conj",bg=["typed"],Eg=mt(Zc,bg,i=>{var{typed:t}=i;return t(Zc,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.conjugate(),"Array | Matrix":t.referToSelf(e=>r=>Rr(r,e))})}),Gc="concat",xg=["typed","matrix","isInteger"],Ag=mt(Gc,xg,i=>{var{typed:t,matrix:e,isInteger:r}=i;return t(Gc,{"...Array | Matrix | number | BigNumber":function(s){var a,l=s.length,c=-1,h,p=!1,f=[];for(a=0;a<l;a++){var d=s[a];if(fe(d)&&(p=!0),le(d)||xe(d)){if(a!==l-1)throw new Error("Dimension must be specified as last argument");if(h=c,c=d.valueOf(),!r(c))throw new TypeError("Integer number expected for dimension");if(c<0||a>0&&c>h)throw new gn(c,h+1)}else{var g=re(d).valueOf(),w=Fe(g);if(f[a]=g,h=c,c=w.length-1,a>0&&c!==h)throw new Gt(h+1,c+1)}}if(f.length===0)throw new SyntaxError("At least one matrix expected");for(var m=f.shift();f.length;)m=tc(m,f.shift(),c);return p?e(m):m},"...string":function(s){return s.join("")}})}),Kc="count",Cg=["typed","size","prod"],Fg=mt(Kc,Cg,i=>{var{typed:t,size:e,prod:r}=i;return t(Kc,{string:function(s){return s.length},"Matrix | Array":function(s){return r(e(s))}})}),Hc="identity",Mg=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Ng=mt(Hc,Mg,i=>{var{typed:t,config:e,matrix:r,BigNumber:n,DenseMatrix:s,SparseMatrix:a}=i;return t(Hc,{"":function(){return e.matrix==="Matrix"?r([]):[]},string:function(p){return r(p)},"number | BigNumber":function(p){return c(p,p,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(p,f){return c(p,p,f)},"number | BigNumber, number | BigNumber":function(p,f){return c(p,f,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(p,f,d){return c(p,f,d)},Array:function(p){return l(p)},"Array, string":function(p,f){return l(p,f)},Matrix:function(p){return l(p.valueOf(),p.storage())},"Matrix, string":function(p,f){return l(p.valueOf(),f)}});function l(h,p){switch(h.length){case 0:return p?r(p):[];case 1:return c(h[0],h[0],p);case 2:return c(h[0],h[1],p);default:throw new Error("Vector containing two values expected")}}function c(h,p,f){var d=xe(h)||xe(p)?n:null;if(xe(h)&&(h=h.toNumber()),xe(p)&&(p=p.toNumber()),!de(h)||h<1)throw new Error("Parameters in function identity must be positive integers");if(!de(p)||p<1)throw new Error("Parameters in function identity must be positive integers");var g=d?new n(1):1,w=d?new d(0):0,m=[h,p];if(f){if(f==="sparse")return a.diagonal(m,g,0,w);if(f==="dense")return s.diagonal(m,g,0,w);throw new TypeError('Unknown matrix type "'.concat(f,'"'))}for(var D=ca([],m,w),v=h<p?h:p,E=0;E<v;E++)D[E][E]=g;return D}}),Xc="kron",Sg=["typed","matrix","multiplyScalar"],Bg=mt(Xc,Sg,i=>{var{typed:t,matrix:e,multiplyScalar:r}=i;return t(Xc,{"Matrix, Matrix":function(a,l){return e(n(a.toArray(),l.toArray()))},"Matrix, Array":function(a,l){return e(n(a.toArray(),l))},"Array, Matrix":function(a,l){return e(n(a,l.toArray()))},"Array, Array":n});function n(s,a){if(Fe(s).length===1&&(s=[s]),Fe(a).length===1&&(a=[a]),Fe(s).length>2||Fe(a).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(s.length)+", y = "+JSON.stringify(a.length)+")");var l=[],c=[];return s.map(function(h){return a.map(function(p){return c=[],l.push(c),h.map(function(f){return p.map(function(d){return c.push(r(f,d))})})})})&&l}});function Tg(){throw new Error('No "bignumber" implementation available')}function Og(){throw new Error('No "fraction" implementation available')}function Ig(){throw new Error('No "matrix" implementation available')}var Jc="reshape",$g=["typed","isInteger","matrix"],Lg=mt(Jc,$g,i=>{var{typed:t,isInteger:e}=i;return t(Jc,{"Matrix, Array":function(n,s){return n.reshape(s,!0)},"Array, Array":function(n,s){return s.forEach(function(a){if(!e(a))throw new TypeError("Invalid size for dimension: "+a)}),ha(n,s)}})}),Qc="size",Rg=["typed","config","?matrix"],Pg=mt(Qc,Rg,i=>{var{typed:t,config:e,matrix:r}=i;return t(Qc,{Matrix:function(s){return s.create(s.size())},Array:Fe,string:function(s){return e.matrix==="Array"?[s.length]:r([s.length])},"number | Complex | BigNumber | Unit | boolean | null":function(s){return e.matrix==="Array"?[]:r?r([]):Ig()}})}),Vc="transpose",zg=["typed","matrix"],qg=mt(Vc,zg,i=>{var{typed:t,matrix:e}=i;return t(Vc,{Array:a=>r(e(a)).valueOf(),Matrix:r,any:re});function r(a){var l=a.size(),c;switch(l.length){case 1:c=a.clone();break;case 2:{var h=l[0],p=l[1];if(p===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+oe(l)+")");switch(a.storage()){case"dense":c=n(a,h,p);break;case"sparse":c=s(a,h,p);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+oe(l)+")")}return c}function n(a,l,c){for(var h=a._data,p=[],f,d=0;d<c;d++){f=p[d]=[];for(var g=0;g<l;g++)f[g]=re(h[g][d])}return a.createDenseMatrix({data:p,size:[c,l],datatype:a._datatype})}function s(a,l,c){for(var h=a._values,p=a._index,f=a._ptr,d=h?[]:void 0,g=[],w=[],m=[],D=0;D<l;D++)m[D]=0;var v,E,b;for(v=0,E=p.length;v<E;v++)m[p[v]]++;for(var N=0,x=0;x<l;x++)w.push(N),N+=m[x],m[x]=w[x];for(w.push(N),b=0;b<c;b++)for(var F=f[b],M=f[b+1],S=F;S<M;S++){var I=m[p[S]]++;g[I]=b,h&&(d[I]=re(h[S]))}return a.createSparseMatrix({values:d,index:g,ptr:w,size:[c,l],datatype:a._datatype})}}),tf="ctranspose",kg=["typed","transpose","conj"],Ug=mt(tf,kg,i=>{var{typed:t,transpose:e,conj:r}=i;return t(tf,{any:function(s){return r(e(s))}})}),ef="mode",Wg=["typed","isNaN","isNumeric"],jg=mt(ef,Wg,i=>{var{typed:t,isNaN:e,isNumeric:r}=i;return t(ef,{"Array | Matrix":n,"...":function(a){return n(a)}});function n(s){s=da(s.valueOf());var a=s.length;if(a===0)throw new Error("Cannot calculate mode of an empty array");for(var l={},c=[],h=0,p=0;p<s.length;p++){var f=s[p];if(r(f)&&e(f))throw new Error("Cannot calculate mode of an array containing NaN values");f in l||(l[f]=0),l[f]++,l[f]===h?c.push(f):l[f]>h&&(h=l[f],c=[f])}return c}});function bn(i,t,e){var r;return String(i).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+mn(e)+", value: "+JSON.stringify(e)+")":" (type: "+i.data.actual+")",new TypeError("Cannot calculate "+t+", unexpected type of argument"+r)):String(i).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+mn(e)+", value: "+JSON.stringify(e)+")":"",new TypeError("Cannot calculate "+t+", no ordering relation is defined for complex numbers"+r)):i}var rf="prod",Yg=["typed","config","multiplyScalar","numeric"],Zg=mt(rf,Yg,i=>{var{typed:t,config:e,multiplyScalar:r,numeric:n}=i;return t(rf,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(l,c){throw new Error("prod(A, dim) is not yet supported")},"...":function(l){return s(l)}});function s(a){var l;if(Yi(a,function(c){try{l=l===void 0?c:r(l,c)}catch(h){throw bn(h,"prod",c)}}),typeof l=="string"&&(l=n(l,e.number)),l===void 0)throw new Error("Cannot calculate prod of an empty array");return l}}),Gg="numeric",Kg=["number","?bignumber","?fraction"],Hg=mt(Gg,Kg,i=>{var{number:t,bignumber:e,fraction:r}=i,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},s={number:a=>t(a),BigNumber:e?a=>e(a):Tg,Fraction:r?a=>r(a):Og};return function(l){var c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",h=arguments.length>2?arguments[2]:void 0;if(h!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var p=mn(l);if(!(p in n))throw new TypeError("Cannot convert "+l+' of type "'+p+'"; valid input types are '+Object.keys(n).join(", "));if(!(c in s))throw new TypeError("Cannot convert "+l+' to type "'+c+'"; valid output types are '+Object.keys(s).join(", "));return c===p?l:s[c](l)}}),nf="divideScalar",Xg=["typed","numeric"],Jg=mt(nf,Xg,i=>{var{typed:t,numeric:e}=i;return t(nf,{"number, number":function(n,s){return n/s},"Complex, Complex":function(n,s){return n.div(s)},"BigNumber, BigNumber":function(n,s){return n.div(s)},"Fraction, Fraction":function(n,s){return n.div(s)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),sf="pow",Qg=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Vg=mt(sf,Qg,i=>{var{typed:t,config:e,identity:r,multiply:n,matrix:s,inv:a,number:l,fraction:c,Complex:h}=i;return t(sf,{"number, number":p,"Complex, Complex":function(w,m){return w.pow(m)},"BigNumber, BigNumber":function(w,m){return m.isInteger()||w>=0||e.predictable?w.pow(m):new h(w.toNumber(),0).pow(m.toNumber(),0)},"Fraction, Fraction":function(w,m){var D=w.pow(m);if(D!=null)return D;if(e.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return p(w.valueOf(),m.valueOf())},"Array, number":f,"Array, BigNumber":function(w,m){return f(w,m.toNumber())},"Matrix, number":d,"Matrix, BigNumber":function(w,m){return d(w,m.toNumber())},"Unit, number | BigNumber":function(w,m){return w.pow(m)}});function p(g,w){if(e.predictable&&!de(w)&&g<0)try{var m=c(w),D=l(m);if((w===D||Math.abs((w-D)/w)<1e-14)&&m.d%2===1)return(m.n%2===0?1:-1)*Math.pow(-g,w)}catch{}return e.predictable&&(g<-1&&w===1/0||g>-1&&g<0&&w===-1/0)?NaN:de(w)||g>=0||e.predictable?Nc(g,w):g*g<1&&w===1/0||g*g>1&&w===-1/0?0:new h(g,0).pow(w,0)}function f(g,w){if(!de(w))throw new TypeError("For A^b, b must be an integer (value is "+w+")");var m=Fe(g);if(m.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+m.length+" dimensions)");if(m[0]!==m[1])throw new Error("For A^b, A must be square (size is "+m[0]+"x"+m[1]+")");if(w<0)try{return f(a(g),-w)}catch(E){throw E.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 "+w+")"):E}for(var D=r(m[0]).valueOf(),v=g;w>=1;)(w&1)===1&&(D=n(v,D)),w>>=1,v=n(v,v);return D}function d(g,w){return s(f(g.valueOf(),w))}}),of="dotDivide",tv=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],ev=mt(of,tv,i=>{var{typed:t,matrix:e,equalScalar:r,divideScalar:n,DenseMatrix:s,concat:a}=i,l=Gm({typed:t,equalScalar:r}),c=di({typed:t}),h=ks({typed:t,DenseMatrix:s}),p=xa({typed:t,equalScalar:r}),f=pi({typed:t,DenseMatrix:s}),d=jn({typed:t,matrix:e,concat:a});return t(of,d({elop:n,SS:h,DS:c,SD:l,Ss:p,sS:f}))}),Us="compare",rv=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],nv=mt(Us,rv,i=>{var{typed:t,config:e,equalScalar:r,matrix:n,BigNumber:s,Fraction:a,DenseMatrix:l,concat:c}=i,h=di({typed:t}),p=kc({typed:t,equalScalar:r}),f=pi({typed:t,DenseMatrix:l}),d=jn({typed:t,matrix:n,concat:c}),g=zs({typed:t});return t(Us,iv({typed:t,config:e}),{"boolean, boolean":function(m,D){return m===D?0:m>D?1:-1},"BigNumber, BigNumber":function(m,D){return Ps(m,D,e.epsilon)?new s(0):new s(m.cmp(D))},"Fraction, Fraction":function(m,D){return new a(m.compare(D))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},g,d({SS:p,DS:h,Ss:f}))}),iv=mt(Us,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Us,{"number, number":function(n,s){return Wn(n,s,e.epsilon)?0:n>s?1:-1}})}),Ws="equal",sv=["typed","matrix","equalScalar","DenseMatrix","concat"],ov=mt(Ws,sv,i=>{var{typed:t,matrix:e,equalScalar:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:e,concat:s});return t(Ws,av({typed:t,equalScalar:r}),h({elop:r,SS:l,DS:a,Ss:c}))}),av=mt(Ws,["typed","equalScalar"],i=>{var{typed:t,equalScalar:e}=i;return t(Ws,{"any, any":function(n,s){return n===null?s===null:s===null?n===null:n===void 0?s===void 0:s===void 0?n===void 0:e(n,s)}})}),js="smaller",uv=["typed","config","matrix","DenseMatrix","concat"],lv=mt(js,uv,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:r,concat:s}),p=zs({typed:t});return t(js,cv({typed:t,config:e}),{"boolean, boolean":(f,d)=>f<d,"BigNumber, BigNumber":function(d,g){return d.lt(g)&&!Ps(d,g,e.epsilon)},"Fraction, Fraction":(f,d)=>f.compare(d)===-1,"Complex, Complex":function(d,g){throw new TypeError("No ordering relation is defined for complex numbers")}},p,h({SS:l,DS:a,Ss:c}))}),cv=mt(js,["typed","config"],i=>{var{typed:t,config:e}=i;return t(js,{"number, number":function(n,s){return n<s&&!Wn(n,s,e.epsilon)}})}),Ys="larger",fv=["typed","config","matrix","DenseMatrix","concat"],hv=mt(Ys,fv,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,a=di({typed:t}),l=ks({typed:t,DenseMatrix:n}),c=pi({typed:t,DenseMatrix:n}),h=jn({typed:t,matrix:r,concat:s}),p=zs({typed:t});return t(Ys,pv({typed:t,config:e}),{"boolean, boolean":(f,d)=>f>d,"BigNumber, BigNumber":function(d,g){return d.gt(g)&&!Ps(d,g,e.epsilon)},"Fraction, Fraction":(f,d)=>f.compare(d)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},p,h({SS:l,DS:a,Ss:c}))}),pv=mt(Ys,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Ys,{"number, number":function(n,s){return n>s&&!Wn(n,s,e.epsilon)}})}),af="deepEqual",dv=["typed","equal"],_v=mt(af,dv,i=>{var{typed:t,equal:e}=i;return t(af,{"any, any":function(s,a){return r(s.valueOf(),a.valueOf())}});function r(n,s){if(Array.isArray(n))if(Array.isArray(s)){var a=n.length;if(a!==s.length)return!1;for(var l=0;l<a;l++)if(!r(n[l],s[l]))return!1;return!0}else return!1;else return Array.isArray(s)?!1:e(n,s)}}),uf="partitionSelect",mv=["typed","isNumeric","isNaN","compare"],gv=mt(uf,mv,i=>{var{typed:t,isNumeric:e,isNaN:r,compare:n}=i,s=n,a=(h,p)=>-n(h,p);return t(uf,{"Array | Matrix, number":function(p,f){return l(p,f,s)},"Array | Matrix, number, string":function(p,f,d){if(d==="asc")return l(p,f,s);if(d==="desc")return l(p,f,a);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":l});function l(h,p,f){if(!de(p)||p<0)throw new Error("k must be a non-negative integer");if(fe(h)){var d=h.size();if(d.length>1)throw new Error("Only one dimensional matrices supported");return c(h.valueOf(),p,f)}if(Array.isArray(h))return c(h,p,f)}function c(h,p,f){if(p>=h.length)throw new Error("k out of bounds");for(var d=0;d<h.length;d++)if(e(h[d])&&r(h[d]))return h[d];for(var g=0,w=h.length-1;g<w;){for(var m=g,D=w,v=h[Math.floor(Math.random()*(w-g+1))+g];m<D;)if(f(h[m],v)>=0){var E=h[D];h[D]=h[m],h[m]=E,--D}else++m;f(h[m],v)>0&&--m,p<=m?w=m:g=m+1}return h[p]}}),lf="max",vv=["typed","config","numeric","larger"],wv=mt(lf,vv,i=>{var{typed:t,config:e,numeric:r,larger:n}=i;return t(lf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(c,h){return Ea(c,h.valueOf(),s)},"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function max");return a(c)}});function s(l,c){try{return n(l,c)?l:c}catch(h){throw bn(h,"max",c)}}function a(l){var c;if(Yi(l,function(h){try{isNaN(h)&&typeof h=="number"?c=NaN:(c===void 0||n(h,c))&&(c=h)}catch(p){throw bn(p,"max",h)}}),c===void 0)throw new Error("Cannot calculate max of an empty array");return typeof c=="string"&&(c=r(c,e.number)),c}}),cf="min",yv=["typed","config","numeric","smaller"],Dv=mt(cf,yv,i=>{var{typed:t,config:e,numeric:r,smaller:n}=i;return t(cf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(c,h){return Ea(c,h.valueOf(),s)},"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function min");return a(c)}});function s(l,c){try{return n(l,c)?l:c}catch(h){throw bn(h,"min",c)}}function a(l){var c;if(Yi(l,function(h){try{isNaN(h)&&typeof h=="number"?c=NaN:(c===void 0||n(h,c))&&(c=h)}catch(p){throw bn(p,"min",h)}}),c===void 0)throw new Error("Cannot calculate min of an empty array");return typeof c=="string"&&(c=r(c,e.number)),c}}),ff="add",bv=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],Ev=mt(ff,bv,i=>{var{typed:t,matrix:e,addScalar:r,equalScalar:n,DenseMatrix:s,SparseMatrix:a,concat:l}=i,c=Uc({typed:t}),h=cg({typed:t,equalScalar:n}),p=Wc({typed:t,DenseMatrix:s}),f=jn({typed:t,matrix:e,concat:l});return t(ff,{"any, any":r,"any, any, ...any":t.referToSelf(d=>(g,w,m)=>{for(var D=d(g,w),v=0;v<m.length;v++)D=d(D,m[v]);return D})},f({elop:r,DS:c,SS:h,Ss:p}))}),hf="dot",xv=["typed","addScalar","multiplyScalar","conj","size"],Av=mt(hf,xv,i=>{var{typed:t,addScalar:e,multiplyScalar:r,conj:n,size:s}=i;return t(hf,{"Array | DenseMatrix, Array | DenseMatrix":l,"SparseMatrix, SparseMatrix":c});function a(p,f){var d=h(p),g=h(f),w,m;if(d.length===1)w=d[0];else if(d.length===2&&d[1]===1)w=d[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+d.join(", ")+")");if(g.length===1)m=g[0];else if(g.length===2&&g[1]===1)m=g[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+g.join(", ")+")");if(w!==m)throw new RangeError("Vectors must have equal length ("+w+" != "+m+")");if(w===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return w}function l(p,f){var d=a(p,f),g=fe(p)?p._data:p,w=fe(p)?p._datatype||p.getDataType():void 0,m=fe(f)?f._data:f,D=fe(f)?f._datatype||f.getDataType():void 0,v=h(p).length===2,E=h(f).length===2,b=e,N=r;if(w&&D&&w===D&&typeof w=="string"&&w!=="mixed"){var x=w;b=t.find(e,[x,x]),N=t.find(r,[x,x])}if(!v&&!E){for(var F=N(n(g[0]),m[0]),M=1;M<d;M++)F=b(F,N(n(g[M]),m[M]));return F}if(!v&&E){for(var S=N(n(g[0]),m[0][0]),I=1;I<d;I++)S=b(S,N(n(g[I]),m[I][0]));return S}if(v&&!E){for(var C=N(n(g[0][0]),m[0]),T=1;T<d;T++)C=b(C,N(n(g[T][0]),m[T]));return C}if(v&&E){for(var L=N(n(g[0][0]),m[0][0]),U=1;U<d;U++)L=b(L,N(n(g[U][0]),m[U][0]));return L}}function c(p,f){a(p,f);for(var d=p._index,g=p._values,w=f._index,m=f._values,D=0,v=e,E=r,b=0,N=0;b<d.length&&N<w.length;){var x=d[b],F=w[N];if(x<F){b++;continue}if(x>F){N++;continue}x===F&&(D=v(D,E(g[b],m[N])),b++,N++)}return D}function h(p){return fe(p)?p.size():s(p)}}),Cv="trace",Fv=["typed","matrix","add"],Mv=mt(Cv,Fv,i=>{var{typed:t,matrix:e,add:r}=i;return t("trace",{Array:function(l){return n(e(l))},SparseMatrix:s,DenseMatrix:n,any:re});function n(a){var l=a._size,c=a._data;switch(l.length){case 1:if(l[0]===1)return re(c[0]);throw new RangeError("Matrix must be square (size: "+oe(l)+")");case 2:{var h=l[0],p=l[1];if(h===p){for(var f=0,d=0;d<h;d++)f=r(f,c[d][d]);return f}else throw new RangeError("Matrix must be square (size: "+oe(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(l)+")")}}function s(a){var l=a._values,c=a._index,h=a._ptr,p=a._size,f=p[0],d=p[1];if(f===d){var g=0;if(l.length>0)for(var w=0;w<d;w++)for(var m=h[w],D=h[w+1],v=m;v<D;v++){var E=c[v];if(E===w){g=r(g,l[v]);break}if(E>w)break}return g}throw new RangeError("Matrix must be square (size: "+oe(p)+")")}}),pf="det",Nv=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],Sv=mt(pf,Nv,i=>{var{typed:t,matrix:e,subtractScalar:r,multiply:n,divideScalar:s,isZero:a,unaryMinus:l}=i;return t(pf,{any:function(p){return re(p)},"Array | Matrix":function(p){var f;switch(fe(p)?f=p.size():Array.isArray(p)?(p=e(p),f=p.size()):f=[],f.length){case 0:return re(p);case 1:if(f[0]===1)return re(p.valueOf()[0]);if(f[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+oe(f)+")");case 2:{var d=f[0],g=f[1];if(d===g)return c(p.clone().valueOf(),d);if(g===0)return 1;throw new RangeError("Matrix must be square (size: "+oe(f)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(f)+")")}}});function c(h,p,f){if(p===1)return re(h[0][0]);if(p===2)return r(n(h[0][0],h[1][1]),n(h[1][0],h[0][1]));for(var d=!1,g=new Array(p).fill(0).map((M,S)=>S),w=0;w<p;w++){var m=g[w];if(a(h[m][w])){var D=void 0;for(D=w+1;D<p;D++)if(!a(h[g[D]][w])){m=g[D],g[D]=g[w],g[w]=m,d=!d;break}if(D===p)return h[m][w]}for(var v=h[m][w],E=w===0?1:h[g[w-1]][w-1],b=w+1;b<p;b++)for(var N=g[b],x=w+1;x<p;x++)h[N][x]=s(r(n(h[N][x],v),n(h[N][w],h[m][x])),E)}var F=h[g[p-1]][p-1];return d?l(F):F}}),df="inv",Bv=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],Tv=mt(df,Bv,i=>{var{typed:t,matrix:e,divideScalar:r,addScalar:n,multiply:s,unaryMinus:a,det:l,identity:c,abs:h}=i;return t(df,{"Array | Matrix":function(d){var g=fe(d)?d.size():Fe(d);switch(g.length){case 1:if(g[0]===1)return fe(d)?e([r(1,d.valueOf()[0])]):[r(1,d[0])];throw new RangeError("Matrix must be square (size: "+oe(g)+")");case 2:{var w=g[0],m=g[1];if(w===m)return fe(d)?e(p(d.valueOf(),w,m),d.storage()):p(d,w,m);throw new RangeError("Matrix must be square (size: "+oe(g)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(g)+")")}},any:function(d){return r(1,d)}});function p(f,d,g){var w,m,D,v,E;if(d===1){if(v=f[0][0],v===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,v)]]}else if(d===2){var b=l(f);if(b===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(f[1][1],b),r(a(f[0][1]),b)],[r(a(f[1][0]),b),r(f[0][0],b)]]}else{var N=f.concat();for(w=0;w<d;w++)N[w]=N[w].concat();for(var x=c(d).valueOf(),F=0;F<g;F++){var M=h(N[F][F]),S=F;for(w=F+1;w<d;)h(N[w][F])>M&&(M=h(N[w][F]),S=w),w++;if(M===0)throw Error("Cannot calculate inverse, determinant is zero");w=S,w!==F&&(E=N[F],N[F]=N[w],N[w]=E,E=x[F],x[F]=x[w],x[w]=E);var I=N[F],C=x[F];for(w=0;w<d;w++){var T=N[w],L=x[w];if(w!==F){if(T[F]!==0){for(D=r(a(T[F]),I[F]),m=F;m<g;m++)T[m]=n(T[m],s(D,I[m]));for(m=0;m<g;m++)L[m]=n(L[m],s(D,C[m]))}}else{for(D=I[F],m=F;m<g;m++)T[m]=r(T[m],D);for(m=0;m<g;m++)L[m]=r(L[m],D)}}}return x}}}),_f="pinv",Ov=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],Iv=mt(_f,Ov,i=>{var{typed:t,matrix:e,inv:r,deepEqual:n,equal:s,dotDivide:a,dot:l,ctranspose:c,divideScalar:h,multiply:p,add:f,Complex:d}=i;return t(_f,{"Array | Matrix":function(b){var N=fe(b)?b.size():Fe(b);switch(N.length){case 1:return v(b)?c(b):N[0]===1?r(b):a(c(b),l(b,b));case 2:{if(v(b))return c(b);var x=N[0],F=N[1];if(x===F)try{return r(b)}catch(M){if(!(M instanceof Error&&M.message.match(/Cannot calculate inverse, determinant is zero/)))throw M}return fe(b)?e(g(b.valueOf(),x,F),b.storage()):g(b,x,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+oe(N)+")")}},any:function(b){return s(b,0)?re(b):h(1,b)}});function g(E,b,N){var{C:x,F}=m(E,b,N),M=p(r(p(c(x),x)),c(x)),S=p(c(F),r(p(F,c(F))));return p(S,M)}function w(E,b,N){for(var x=re(E),F=0,M=0;M<b;M++){if(N<=F)return x;for(var S=M;D(x[S][F]);)if(S++,b===S&&(S=M,F++,N===F))return x;[x[S],x[M]]=[x[M],x[S]];for(var I=x[M][F],C=0;C<N;C++)x[M][C]=a(x[M][C],I);for(var T=0;T<b;T++)if(T!==M){I=x[T][F];for(var L=0;L<N;L++)x[T][L]=f(x[T][L],p(-1,p(I,x[M][L])))}F++}return x}function m(E,b,N){var x=w(E,b,N),F=E.map((S,I)=>S.filter((C,T)=>T<b&&!D(l(x[T],x[T])))),M=x.filter((S,I)=>!D(l(x[I],x[I])));return{C:F,F:M}}function D(E){return s(f(E,d(1,1)),f(0,d(1,1)))}function v(E){return n(f(E,d(1,1)),f(p(E,0),d(1,1)))}}),$v="divide",Lv=["typed","matrix","multiply","equalScalar","divideScalar","inv"],Rv=mt($v,Lv,i=>{var{typed:t,matrix:e,multiply:r,equalScalar:n,divideScalar:s,inv:a}=i,l=xa({typed:t,equalScalar:n}),c=Aa({typed:t});return t("divide",Il({"Array | Matrix, Array | Matrix":function(p,f){return r(p,a(f))},"DenseMatrix, any":function(p,f){return c(p,f,s,!1)},"SparseMatrix, any":function(p,f){return l(p,f,s,!1)},"Array, any":function(p,f){return c(e(p),f,s,!1).valueOf()},"any, Array | Matrix":function(p,f){return r(p,a(f))}},s.signatures))}),mf="sum",Pv=["typed","config","add","numeric"],zv=mt(mf,Pv,i=>{var{typed:t,config:e,add:r,numeric:n}=i;return t(mf,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":a,"...":function(c){if($s(c))throw new TypeError("Scalar values expected in function sum");return s(c)}});function s(l){var c;return Yi(l,function(h){try{c=c===void 0?h:r(c,h)}catch(p){throw bn(p,"sum",h)}}),c===void 0&&(c=n(0,e.number)),typeof c=="string"&&(c=n(c,e.number)),c}function a(l,c){try{var h=Ea(l,c,r);return h}catch(p){throw bn(p,"sum")}}}),gf="median",qv=["typed","add","divide","compare","partitionSelect"],kv=mt(gf,qv,i=>{var{typed:t,add:e,divide:r,compare:n,partitionSelect:s}=i;function a(h){try{h=da(h.valueOf());var p=h.length;if(p===0)throw new Error("Cannot calculate median of an empty array");if(p%2===0){for(var f=p/2-1,d=s(h,f+1),g=h[f],w=0;w<f;++w)n(h[w],g)>0&&(g=h[w]);return c(g,d)}else{var m=s(h,(p-1)/2);return l(m)}}catch(D){throw bn(D,"median")}}var l=t({"number | BigNumber | Complex | Unit":function(p){return p}}),c=t({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(p,f){return r(e(p,f),2)}});return t(gf,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(p,f){throw new Error("median(A, dim) is not yet supported")},"...":function(p){if($s(p))throw new TypeError("Scalar values expected in function median");return a(p)}})}),Zs=U_({config:ar}),Ca=Z_({}),Fa=X_({}),Ma=V_({}),Kr=rm({Matrix:Ma}),Mt=Yd({BigNumber:Zs,Complex:Ca,DenseMatrix:Kr,Fraction:Fa}),Uv=Im({typed:Mt}),Gs=Lm({typed:Mt}),Wv=Am({BigNumber:Zs,typed:Mt}),vf=Eg({typed:Mt}),En=dm({config:ar,typed:Mt}),Ks=sm({typed:Mt}),jv=lm({typed:Mt}),Hs=_g({typed:Mt}),wf=bm({typed:Mt}),Na=gm({Matrix:Ma,equalScalar:En,typed:Mt}),yf=Pm({typed:Mt}),Df=fm({typed:Mt}),Sa=Tm({typed:Mt}),bf=Mm({Fraction:Fa,typed:Mt}),Ef=am({typed:Mt}),Me=Sm({DenseMatrix:Kr,Matrix:Ma,SparseMatrix:Na,typed:Mt}),xf=jg({isNaN:Df,isNumeric:Ef,typed:Mt}),Zi=Hg({bignumber:Wv,fraction:bf,number:wf}),Yv=Zg({config:ar,multiplyScalar:Hs,numeric:Zi,typed:Mt}),Zv=Lg({isInteger:Ks,matrix:Me,typed:Mt}),Af=Pg({matrix:Me,config:ar,typed:Mt}),Cf=qg({matrix:Me,typed:Mt}),Yn=Ag({isInteger:Ks,matrix:Me,typed:Mt}),Gv=Fg({prod:Yv,size:Af,typed:Mt}),Kv=Ug({conj:vf,transpose:Cf,typed:Mt}),Gi=Jg({numeric:Zi,typed:Mt}),Hv=ev({DenseMatrix:Kr,concat:Yn,divideScalar:Gi,equalScalar:En,matrix:Me,typed:Mt}),Ff=ov({DenseMatrix:Kr,concat:Yn,equalScalar:En,matrix:Me,typed:Mt}),Mf=Ng({BigNumber:Zs,DenseMatrix:Kr,SparseMatrix:Na,config:ar,matrix:Me,typed:Mt}),Xv=Bg({matrix:Me,multiplyScalar:Hs,typed:Mt}),Jv=lv({DenseMatrix:Kr,concat:Yn,config:ar,matrix:Me,typed:Mt}),Qv=wg({DenseMatrix:Kr,concat:Yn,equalScalar:En,matrix:Me,subtractScalar:yf,typed:Mt,unaryMinus:Sa}),Ki=Ev({DenseMatrix:Kr,SparseMatrix:Na,addScalar:Gs,concat:Yn,equalScalar:En,matrix:Me,typed:Mt}),Nf=nv({BigNumber:Zs,DenseMatrix:Kr,Fraction:Fa,concat:Yn,config:ar,equalScalar:En,matrix:Me,typed:Mt}),Vv=_v({equal:Ff,typed:Mt}),Sf=Av({addScalar:Gs,conj:vf,multiplyScalar:Hs,size:Af,typed:Mt}),t1=hv({DenseMatrix:Kr,concat:Yn,config:ar,matrix:Me,typed:Mt}),Ba=Dv({config:ar,numeric:Zi,smaller:Jv,typed:Mt}),_i=gg({addScalar:Gs,dot:Sf,equalScalar:En,matrix:Me,multiplyScalar:Hs,typed:Mt}),e1=gv({compare:Nf,isNaN:Df,isNumeric:Ef,typed:Mt}),r1=zv({add:Ki,config:ar,numeric:Zi,typed:Mt}),n1=Mv({add:Ki,matrix:Me,typed:Mt}),Bf=Sv({divideScalar:Gi,isZero:jv,matrix:Me,multiply:_i,subtractScalar:yf,typed:Mt,unaryMinus:Sa}),i1=wv({config:ar,larger:t1,numeric:Zi,typed:Mt}),Xs=Tv({abs:Uv,addScalar:Gs,det:Bf,divideScalar:Gi,identity:Mf,matrix:Me,multiply:_i,typed:Mt,unaryMinus:Sa}),s1=Iv({Complex:Ca,add:Ki,ctranspose:Kv,deepEqual:Vv,divideScalar:Gi,dot:Sf,dotDivide:Hv,equal:Ff,inv:Xs,matrix:Me,multiply:_i,typed:Mt}),o1=Vg({Complex:Ca,config:ar,fraction:bf,identity:Mf,inv:Xs,matrix:Me,multiply:_i,number:wf,typed:Mt}),a1=Rv({divideScalar:Gi,equalScalar:En,inv:Xs,matrix:Me,multiply:_i,typed:Mt}),Tf=kv({add:Ki,compare:Nf,divide:a1,partitionSelect:e1,typed:Mt});class u1{constructor(t,e,r){z(this,"_cacheData");z(this,"_variables");z(this,"_math");z(this,"_timeframe");this._cacheData={},this._variables=t,this._math=e,this._timeframe=r}alma({series:t,length:e,offset:r,sigma:n,floor:s},a){if(e===void 0||r===void 0||n===void 0)return;const l=this._cacheDataList(t,e,`alma_${a}`);if(l===void 0)return;let c=r*(e-1);s&&(c=Math.floor(c));const h=e/n;let p=0,f=0;for(let d=0;d<=e-1;d++){const g=Math.exp(-1*Math.pow(d-c,2)/(2*Math.pow(h,2)));p+=g,f+=l[l.length-1-(e-d-1)]*g}return f/p}sma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;let n=0;const s=this._cacheDataList(t,e,`sma_${r}`);if(s===void 0)return;const a=s.slice(-e);return n=r1(...a)/e,n}rma({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`sma_${r}`]=n;const{sum:s}=this._cacheData[`rma_${r}`]||{},a=1/e,l=s===void 0?this.sma({source:t,length:e},r):a*t+(1-a)*(s||0);return this._cacheDataHandle(`rma_${r}`,{sum:l}),l}atr({length:t},e){const{high:r,close:n}=this._cacheData[`atr_${e}`]||{},{high:s,close:a,low:l}=this._variables,c=r===void 0?s-l:Math.max(Math.max(s-l,Math.abs(s-n)),Math.abs(l-n));return this._cacheDataHandle(`atr_${e}`,{high:s,close:a}),this.rma({source:c,length:t},e)}barssince({condition:t},e){let{count:r}=this._cacheData[`barssince_${e}`]||{};if(t)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${e}`,{count:r}),r}stdev({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0)return;const s=this._cacheDataList(t,e,`stdev_${n}`),a=this.sma({source:t,length:e},n);if(s===void 0)return;let l=0;for(let c=0;c<e;c++){const h=this._sum(s[s.length-1-c],-(a||0));l+=h*h}return r||e<=1?Math.sqrt(l/e):Math.sqrt(l/(e-1))}_sum(t,e){let n=t+e;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[];const s=this.sma({source:t,length:e},n),a=this.stdev({source:t,length:e},n);if(s===void 0||a===void 0)return[];const l=r*a;return[s,s+l,s-l]}bbw({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.sma({source:t,length:e},n),a=this.stdev({source:t,length:e},n);if(s===void 0||a===void 0)return;const l=r*a;return(s+l-(s-l))/s}cci({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r),s=this.dev({source:t,length:e},r);if(!(n===void 0||s===void 0))return(t-n)/(.015*s)}change({source:t,length:e=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`change_${r}`]=n;const s=n[n.length-1-e];if(!(t===void 0||isNaN(t)))return s===void 0?s:typeof t=="boolean"?s!==t:t-s}cmo({series:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.change({source:t},r);if(n===void 0)return;const s=this._math.sum({source:n>=0?n:0,length:e},`sm1_${r}`),a=this._math.sum({source:n>=0?0:-n,length:e},`sm2_${r}`);if(!(s===void 0||a===void 0))return 100*(s-a)/(s+a)}cog({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this._cacheDataList(t,e,`cog_${r}`),s=this._math.sum({source:t,length:e},r);if(s===void 0||n===void 0)return;let a=0;for(let l=0;l<e;l++){const c=n[n.length-1-l];a+=c*(l+1)}return-a/s}correlation({source1:t,source2:e,length:r},n){if(t===void 0||isNaN(t)||e===void 0||isNaN(e)||r===void 0)return;const s=this._cacheDataList([t,e],r,`correlation_${n}`),a=this.sma({source:t,length:r},`sma1_${n}`),l=this.sma({source:e,length:r},`sma2_${n}`);if(a===void 0||l===void 0||s===void 0)return;let c=0,h=0,p=0;for(let d=0;d<r;d++){const[g,w]=s[s.length-1-d],m=g-a,D=w-l;c+=m*D,h+=m*m,p+=D*D}return isNaN(h)||isNaN(c)||isNaN(p)?void 0:c/Math.sqrt(h*p)}cross({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e||n<=s&&t>e}crossover({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n<=s&&t>e}crossunder({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e}cum({source:t=0},e){t=isNaN(t)?0:t;let{sum:r}=this._cacheData[`cum_${e}`]||{};return r=r||0,r+=t,this._cacheDataHandle(`cum_${e}`,{sum:r}),r}dev({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r);let s=0;const a=this._cacheDataList(t,e,`dev_${r}`);if(!(!a||n===void 0)){for(let l=0;l<e;l++){const c=a[a.length-1-l];s+=Math.abs(c-n)}return s/e}}dmi({diLength:t,adxSmoothing:e},r){if(t===void 0||e===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:s,high:a,close:l,PDMS:c,NDMS:h,TRS:p,ADX:f,count:d=0}=this._cacheData[n]||{},{low:g,high:w,close:m}=this._variables;if(s===void 0||a===void 0||l===void 0)return this._cacheData[n]={low:g,high:w,close:m,PDMS:c,NDMS:h,TRS:w-g,count:1},[void 0,void 0,void 0];let D=w-a,v=s-g;D=D>v&&D>0?D:0,v=v>D&&v>0?v:0,D===v&&(D=v=0);const E=Math.max(w-g,Math.abs(w-l),Math.abs(g-l));if(d<t)return this._cacheDataHandle(n,{low:g,high:w,close:m,PDMS:(c||0)+D,NDMS:(h||0)+v,TRS:(p||0)+E,count:d+1}),[void 0,void 0,void 0];{const b=c-c/t+D,N=h-h/t+v,x=p-p/t+E,F=b/x*100,M=N/x*100,S=Math.abs((F-M)/(F+M))*100;let I=S,C=[F,M,void 0];if(d+1-t<e){const T=d+1-t;I=((f||0)*(T-1)+S)/T}else I=(f*(e-1)+S)/e,C=[F,M,I];return this._cacheDataHandle(n,{low:g,high:w,close:m,PDMS:b,NDMS:N,TRS:x,ADX:I,count:d+1}),C}}ema({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;let{sum:n,count:s=1}=this._cacheData[`ema_${r}`]||{};const a=this.sma({source:t,length:e},r);if(s>e){const l=2/(e+1);n=n===void 0?t:l*t+(1-l)*(n||0)}else n=a;return s+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:s}),n}falling({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,fallings:s=[]}=this._cacheData[`falling_${r}`]||{};s.push(n>t);const a=s.slice(-e);return this._cacheDataHandle(`falling_${r}`,{source:t,fallings:a}),a.length<e?!1:a.every(l=>l)}rising({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,risings:s=[]}=this._cacheData[`rising_${r}`]||{};s.push(n<t);const a=s.slice(-e);return this._cacheDataHandle(`rising_${r}`,{source:t,risings:a}),a.length<e?!1:a.every(l=>l)}highest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`highest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.max(...l.slice(-e))}highestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`highestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((h,p,f,d)=>p>=d[h]?f:h,0)-e+1}wma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`wma_${r}`);if(!n)return;let s=0,a=0;for(let l=0;l<e;l++){const c=(e-l)*e;s+=c,a+=n[n.length-1-l]*c}return a/s}hma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this.wma({source:t,length:e},r),s=this.wma({source:t,length:Math.round(e/2)},r);return n===void 0||s===void 0?void 0:this.wma({source:2*s-n,length:Math.floor(Math.sqrt(e))},`hma_${r}`)}kc({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[void 0,void 0,void 0];const a=this.ema({source:t,length:e},s),{ta:l,high:c,low:h}=this._variables,p=n?l.tr:c-h,f=this.ema({source:p,length:e},`range_${s}`);return[a,a+f*r,a-f*r]}kcw({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const a=this.ema({source:t,length:e},s),{ta:l,high:c,low:h}=this._variables,p=n?l.tr:c-h,f=this.ema({source:p,length:e},`range_${s}`);return(a+f*r-(a-f*r))/a}linreg({source:t,length:e,offset:r},n){if(e===void 0||r===void 0)return;const s=this._cacheDataList(t,e,`dev_${n}`);if(!s)return;const a=s.slice(-e).filter(g=>g!==void 0);let l=0,c=0,h=0,p=0;for(const[g,w]of a.entries())l+=g,c+=w,h+=g*w,p+=g*g;const f=(e*h-l*c)/(e*p-l*l);return(c-f*l)/e+f*(e-1-r)}lowest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`lowest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.min(...l.slice(-e))}lowestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:s,bar_index:a}=this._variables;typeof t!="number"?n[a]=s:n[a]=t,this._cacheData[`lowestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((h,p,f,d)=>p<=d[h]?f:h,0)-e+1}macd({source:t,fastlen:e,slowlen:r,siglen:n},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const a=this.ema({source:t,length:e},`ema1_${s}`),l=this.ema({source:t,length:r},`ema2_${s}`);if(a===void 0||l===void 0)return[void 0,void 0,void 0];const c=a-l,h=this.ema({source:c,length:n},`macd_${s}`);if(h===void 0)return[c,h,void 0];const p=c-h;return[c,h,p]}max({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`max_${e}`]||0;return t>r&&(r=t),this._cacheData[`max_${e}`]=r,r}min({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`min_${e}`]||1/0;return t<r&&(r=t),this._cacheData[`min_${e}`]=r,r}median({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`dev_${r}`);if(n)return Tf(n.slice(-e))}mfi({series:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const{volume:n}=this._variables,s=this.change({source:t},r),a=this._math.sum({source:n*(s>=0?0:t),length:e},`lower_${r}`),l=this._math.sum({source:n*(s<=0?0:t),length:e},`upper_${r}`);if(!(l===void 0||a===void 0))return 100-100/(1+l/a)}mode({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`mode_${r}`);if(n)return Ba(xf(n.slice(-e)))}mom({source:t,length:e},r){if(e===void 0||e<0)return;const n=`mom_${r}`,s=this._cacheData[n]||[];if(s[this._variables.bar_index]=t,this._cacheData[n]=s,s.length<=e||t===void 0||isNaN(t))return;let a=s.length-e-1,l;for(;l===void 0&&a>=0;)l=s[a],a--;return l===void 0?l:t-l}percentile_linear_interpolation({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e+1,`percentile_linear_interpolation_${n}`);if(!s)return;const a=this._sort(s.slice(-(e+1))),l=a.length;r/=100;const c=1/(l*2);if(r<=c)return a[0];if(r>=1-1/(l*2))return a[l-1];for(const[h,p]of a.entries()){const f=a[h-1];if(r<(h+.5)/l)return f===void 0||p===void 0?void 0:f+(p-f)*(r-(h-.5)/l)/(1/l)}}percentile_nearest_rank({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||t===void 0||isNaN(t)||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e,`percentile_nearest_rank_${n}`);if(!s)return;const a=this._sort(s.slice(-e)),l=r/100*a.length,c=Math.ceil(l)-1;return a[c>=a.length?a.length-1:c]}percentrank({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`percentile_nearest_rank_${r}`);if(!n)return;const s=n.slice(-(e+1)),a=t;if(a===void 0)return;let l=0;for(let c=0;c<s.length;c++)s[c]!==void 0&&(s[c]<a||s[c]===a&&c<e)&&l++;return l/(s.length-1)*100}pivot_point_levels({type:t,anchor:e,developing:r},n){const s=new Xt;let{close:a,open:l,low:c,high:h}=this._variables;const p=`pivot_point_levels_${n}`,{close:f,low:d,high:g,open:w,result:m}=this._cacheData[p]||{};if(!e&&(g&&d&&(h=Math.max(g,h),c=Math.min(d,c)),this._cacheDataHandle(p,{close:a,open:l,low:c,high:h,result:m}),!r))return s._value=m||[],s;const D={close:a,open:l,low:c,high:h};e===!0&&!r&&(a=f,l=w,c=d,h=g);const v=this._getPivotPointLevels(h,c,a,l,r,t);return this._cacheDataHandle(p,{...D,result:v}),s._value=v,s}_getPivotPointLevels(t,e,r,n,s,a){if(r===void 0||n===void 0||e===void 0||t===void 0)return[];switch(a){case Un.traditional:return this._traditional(t,e,r);case Un.fibonacci:return this._fibonacci(t,e,r);case Un.woodie:return s?[]:this._woodie(t,e);case Un.classic:return this._classic(t,e,r);case Un.dm:return this._DM(t,e,r,n);case Un.camarilla:return this._camarilla(t,e,r);default:return[]}}_traditional(t,e,r){const n=(t+e+r)/3,s=n*2-e,a=n+(t-e),l=n*2+(t-2*e),c=n*3+(t-3*e),h=n*4+(t-4*e),p=n*2-t,f=n-(t-e),d=n*2-(2*t-e),g=n*3-(3*t-e),w=n*4-(4*t-e);return[n,s,p,a,f,l,d,c,g,h,w]}_fibonacci(t,e,r){const n=(t+e+r)/3,s=n+.382*(t-e),a=n-.382*(t-e),l=n+.618*(t-e),c=n-.618*(t-e),h=n+(t-e),p=n-(t-e);return[n,s,a,l,c,h,p]}_woodie(t,e){const{open:r}=this._variables,n=(t+e+2*r)/4,s=2*n-e,a=2*n-t,l=n+(t-e),c=n-(t-e),h=t+2*(n-e),p=e-2*(t-n),f=h+(t-e),d=p-(t-e);return[n,s,a,l,c,h,p,f,d]}_classic(t,e,r){const n=(t+e+r)/3,s=2*n-e,a=2*n-t,l=n+(t-e),c=n-(t-e),h=n+2*(t-e),p=n-2*(t-e),f=n+3*(t-e),d=n-3*(t-e);return[n,s,a,l,c,h,p,f,d]}_DM(t,e,r,n){let s;n===r?s=t+e+2*r:r>n?s=2*t+e+r:s=2*e+t+r;const a=s/4,l=s/2-e,c=s/2-t;return[a,l,c]}_camarilla(t,e,r){const n=(t+e+r)/3,s=r+1.1*(t-e)/12,a=r-1.1*(t-e)/12,l=r+1.1*(t-e)/6,c=r-1.1*(t-e)/6,h=r+1.1*(t-e)/4,p=r-1.1*(t-e)/4,f=r+1.1*(t-e)/2,d=r-1.1*(t-e)/2,g=t/e*r,w=r-(g-r);return[n,s,a,l,c,h,p,f,d,g,w]}pivothigh({source:t=this._variables.high,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivothigh_${n}`);if(!s)return;const a=s.slice(-(e+r+1)),l=a[e];return Math.max(...a)===l?l:void 0}pivotlow({source:t=this._variables.low,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivotlow_${n}`);if(!s)return;const a=s.slice(-(e+r+1)),l=a[e];return Math.min(...a)===l?l:void 0}range({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const n=this._cacheDataList(t,e,`range_${r}`);if(!n)return;const s=n.filter(c=>c!==void 0).slice(-e),a=Math.max(...s),l=Math.min(...s);return a-l}roc({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`roc_${r}`),s=this.change({source:t,length:e},r);if(n)return 100*s/n[n.length-1-e]}rsi({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},s=Math.max(t-n,0),a=Math.max(n-t,0),l=this.rma({source:s,length:e},`rma1_${r}`),c=this.rma({source:a,length:e},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:t}),!(l===void 0||c===void 0))return 100-100/(1+l/c)}sar({start:t,inc:e,max:r},n){if(t===void 0||e===void 0||r===void 0)return;const{close:s,low:a,high:l,preLow:c,preHigh:h,data:p={}}=this._cacheData[`sar_${n}`]||{};let{result:f,maxMin:d,acceleration:g,isBelow:w}=p,m=!1;const{close:D,low:v,high:E,bar_index:b}=this._variables;return b===1&&(D>s?(w=!0,d=E,f=a):(w=!1,d=v,f=l),m=!0,g=t),f=f+g*(d-f),w?f>v&&(m=!0,w=!1,f=Math.max(E,d||0),d=v,g=t):f<E&&(m=!0,w=!0,f=Math.min(v,d||0),d=E,g=t),m||(w?E>(d||0)&&(d=E,g=Math.min((g||0)+e,r)):v<(d||0)&&(d=v,g=Math.min((g||0)+e,r))),w?(f=Math.min(f,a),b>1&&(f=Math.min(f,c))):(f=Math.max(f,l),b>1&&(f=Math.max(f,h))),this._cacheDataHandle(`sar_${n}`,{high:E,close:D,low:v,preLow:a,preHigh:l,data:Object.assign(p,{result:f,maxMin:d,acceleration:g,isBelow:w})}),f}stoch({source:t,high:e,low:r,length:n},s){if(n===void 0||e===void 0||r===void 0||t===void 0||isNaN(t)||n<0)return;const a=this.lowest({source:r,length:n},s),l=this.highest({source:e,length:n},s);if(!(a===void 0||l===void 0))return 100*(this._variables.close-a)/(l-a)}supertrend({factor:t,atrPeriod:e},r){if(t===void 0||e===void 0)return[void 0,void 0];const{hl2:n,close:s}=this._variables,a=`supertrend_${r}`,{upperBand:l,lowerBand:c,superTrend:h,atr:p,close:f}=this._cacheData[a]||{},d=this.atr({length:e},r);if(d===void 0)return this._cacheDataHandle(a,{close:s}),[void 0,void 0];let g=n+t*d,w=n-t*d;const m=l||0,D=c||0;w=w>D||f<D?w:D,g=g<m||f>m?g:m;let v;p===void 0?v=1:h===m?v=s>g?-1:1:v=s<w?1:-1;const E=v===-1?w:g;return this._cacheDataHandle(a,{upperBand:g,lowerBand:w,superTrend:E,atr:d,close:s}),[E,v]}swma({source:t},e){let{list:r}=this._cacheData[`swma_${e}`]||{};if(r||(r=[]),r.push(t),r=r.slice(-4),this._cacheDataHandle(`swma_${e}`,{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:t=!1},e){const{close:r,low:n,high:s}=this._variables,{close:a}=this._cacheData[`tr_${e}`]||{};return this._cacheDataHandle(`tr_${e}`,{close:r}),a===void 0?t?s-n:void 0:Math.max(s-n,Math.abs(s-a),Math.abs(n-a))}tsi({source:t,short_length:e,long_length:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.change({source:t},n);if(s===void 0)return;const a=this.ema({source:Math.abs(s),length:e},`absema1_${n}`),l=this.ema({source:s,length:e},`ema1_${n}`);if(l===void 0)return;const c=this.ema({source:l,length:r},`ema2_${n}`),h=this.ema({source:a,length:e},`absema2_${n}`);if(c!==void 0)return c/h}valuewhen({condition:t,source:e,occurrence:r},n){if(e===void 0||r===void 0||r<0)return;let{list:s}=this._cacheData[`valuewhen_${n}`]||{};return s||(s=[]),t&&s.push(e),this._cacheDataHandle(`valuewhen_${n}`,{list:s}),s[s.length-1-r]}variance({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0||e<0)return;const s=this.sma({source:t,length:e},n),a=this._cacheDataList(t,e,`mode_${n}`);if(!a||s===void 0)return;const l=a.filter(h=>h!==void 0&&!isNaN(h)).slice(-e);if(l.length<e)return;const c=l.reduce((h,p)=>h+Math.pow(p-s,2),0);if(c!==void 0)return r||e<=1?c/e:c/(e-1)}vwap({source:t,anchor:e,stdev_mult:r},n){if(t===void 0)return;e=e===void 0?this._timeframe.change({timeframe:"1D"},n):e;const{volume:s}=this._variables;let{sum:a=0,sumV:l=0,count:c=0,isReset:h,sumS:p=0}=this._cacheData[`vwap_${n}`]||{};if(e&&(a=l=c=p=0,h=!0),!h)return r!==void 0?[]:void 0;const f=t*s+a,d=s+l,g=f/d;return c++,r!==void 0?(p=s*Math.pow(t,2)+p,this._cacheDataHandle(`vwap_${n}`,{sum:f,sumV:d,count:c,isReset:h,sumS:p}),this._computeBands(p,d,r,g)):(this._cacheDataHandle(`vwap_${n}`,{sum:f,sumV:d,count:c,isReset:h}),g)}_computeBands(t,e,r,n){let s=t/e-Math.pow(n,2);s=s<0?0:s;const a=Math.sqrt(s),l=a!==void 0&&!isNaN(a)?n+r*a:void 0,c=a!==void 0&&!isNaN(a)?n-r*a:void 0;return[n,l,c]}vwma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0||e<=0)return;const{volume:n}=this._variables,s=this.sma({source:t*n,length:e},`sma1_${r}`),a=this.sma({source:n,length:e},`sma2_${r}`);if(!(s===void 0||a===void 0))return s/a}wpr({length:t},e){if(t===void 0||t<=0)return;const r=this.highest({length:t},e),n=this.lowest({length:t},e),{close:s}=this._variables;if(!(r===void 0||n===void 0))return(r-s)/(r-n)*-100}_sort(t){const e=t.length;for(let r=0;r<e;r++){let n={};for(let s=0;s<e-r;s++){const{currentVal:a,currentIndex:l}=n,c=t[s];if(c!==void 0){if(a!==void 0&&c<a){t.splice(s,1),t.splice(l,0,c),n={currentIndex:l+1,currentVal:a};continue}n={currentIndex:s,currentVal:c}}}}return t}_cacheDataList(t,e,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=t,this._cacheData[r]=n;const s=n.filter(()=>!0);if(!(s.length<e))return s}_cacheDataHandle(t,e){const{barIndex:r}=this._cacheData[t]||{};r!==this._variables.bar_index&&(this._cacheData[t]=Object.assign(e,{barIndex:this._variables.bar_index}))}}const Of={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",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",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 undefined 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."};Wr.SERIES,Wr.SIMPLE,Wr.INPUT,Wr.CONST,Wr.INT,Wr.FLOAT,Wr.BOOL,Wr.COLOR,Wr.STRING;const l1=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"];class c1{constructor(t,e){z(this,"_cacheData");z(this,"_variables");z(this,"_errorListener");z(this,"_count");z(this,"_historyInputs");z(this,"_name");this._cacheData={},this._variables=t,this._errorListener=e,this._count=-1,this._name=`inputs_${Lp()}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(t){for(const e of t){const r=e.id;if(!this._cacheData[r])return;Object.assign(this._cacheData[r],{...e,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${e.index}`,{modifyDefval:e.sourceTypeName||e.defval})}}input(t,e){return this._cacheHandle(t,e)}int(t,e){return this._cacheHandle(t,e,Qe.INT)}bool(t,e){return this._cacheHandle(t,e,Qe.BOOL)}color(t,e){return this._cacheHandle(t,e,Qe.COLOR)}time(t,e){return this._cacheHandle(t,e,Qe.TIME)}float(t,e){return this._cacheHandle(t,e,Qe.FLOAT)}price(t,e){return this._cacheHandle(t,e,Qe.PRICE)}source(t,e){return this._cacheHandle(t,e,Qe.SOURCE)}string(t,e){return this._cacheHandle(t,e,Qe.STRING)}symbol(t,e){return this._cacheHandle(t,e,Qe.SYMBOL)}session(t,e){return this._cacheHandle(t,e,Qe.SESSION)}text_area(t,e){return this._cacheHandle(t,e,Qe.TEXT_AREA)}timeframe(t,e){return this._cacheHandle(t,e,Qe.TIMEFRAME)}_cacheHandle(t,e,r){const n=`${r||"input"}_${e}`,s=this._cacheData[n];if(t.defval===void 0&&this._errorListener.addError(Of.inputDefvalErr,e,Ee.Error),s)s.isModify?s.sourceTypeName&&(this._cacheData[n].defval=this._variables[s.sourceTypeName]):Object.assign(this._cacheData[n],t);else{const{defval:a,display:l}=t;this._displayVerify(e,l),this._count++,t={inputType:r,...t,index:this._count},this._cacheData[n]=t,this._judgeHistoryInputs(t),(r||t.inputType)===Qe.SOURCE?this._cacheData[n].options=l1:t.options&&!t.options.includes(a)&&this._errorListener.addError(`input's defval should be in options, but '${a}' is not in [${t.options.toString()}]`,e,Ee.Error)}return this._cacheData[n].defval}_judgeHistoryInputs(t){const{defval:e,sourceTypeName:r,index:n}=t;let s=r||e;const a=`in_${n}`,l=this._historyInputs[a];if(!l)self.workerStorage.setValue(this._name,a,{defval:s});else{const{defval:c,modifyDefval:h}=l;c===s?s=h||s:self.workerStorage.setValue(this._name,a,{defval:s})}r?t.sourceTypeName=s:t.defval=s}_displayVerify(t,e){!e||!e.length||e.includes(sr.dataWindow)||e.includes(sr.statusLine)||this._errorListener.addError("Invalid argument 'display' in 'input' call. Possible values: [display.none, display.data_window, display.status_line, display.all]",t,Ee.Error)}getInputs(){const t=Object.keys(this._cacheData),e=[];for(const r of t){const n=this._cacheData[r];n.id=r,e.push(n)}return e}_getGroups(t){const e=[];for(const[r,n]of t)e.push({name:r,inputs:n});return e}}class f1{color({x:t}){return t}new({color:t,transp:e=100}){_t(e)&&(e=100);const{r,g:n,b:s}=this._parseColor(t||"");return`rgba(${Math.round(r)}, ${Math.round(n)}, ${Math.round(s)}, ${(100-e)/100})`}rgb({red:t=0,green:e=0,blue:r=0,transp:n=0}){return _t(n)&&(n=0),_t(t)&&(t=0),_t(e)&&(e=0),_t(r)&&(r=0),`rgba(${t}, ${e}, ${r}, ${(100-n)/100})`}g({color:t}){return t?this._parseColor(t).g:0}r({color:t}){return t?this._parseColor(t).r:0}b({color:t}){return t?this._parseColor(t).b:0}t({color:t}){return t?Math.round(this._parseColor(t).a*100):0}from_gradient({value:t,bottom_value:e,top_value:r,bottom_color:n,top_color:s}){if(_t(t)||_t(e)||_t(r))return"rgba(0,0,0,1)";const a=(t-e)/(r-e),l=Math.min(Math.max(a,0),1),{r:c,g:h,b:p,a:f}=this._parseColor(n||"rgba(0,0,0,0)"),{r:d,g,b:w,a:m}=this._parseColor(s||"rgba(0,0,0,0)"),D=c+l*(d-c),v=h+l*(g-h),E=p+l*(w-p),b=f+l*(m-f);return`rgba(${Math.round(D)}, ${Math.round(v)}, ${Math.round(E)}, ${b.toFixed(2)})`}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=(255-parseInt(a,16))/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}}var zt={};const h1=Object.prototype.toString;function Hi(i){const t=h1.call(i);return t.endsWith("Array]")&&!t.includes("Big")}var p1=Object.freeze({__proto__:null,isAnyArray:Hi}),d1=be(p1);function _1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Hi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=i[r],l=r+1;l<s;l++)i[l]>a&&(a=i[l]);return a}function m1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Hi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=i[r],l=r+1;l<s;l++)i[l]<a&&(a=i[l]);return a}function g1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(Hi(i)){if(i.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var e;if(t.output!==void 0){if(!Hi(t.output))throw new TypeError("output option must be an array if specified");e=t.output}else e=new Array(i.length);var r=m1(i),n=_1(i);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=t.min,a=s===void 0?t.autoMinMax?r:0:s,l=t.max,c=l===void 0?t.autoMinMax?n:1:l;if(a>=c)throw new RangeError("min option must be smaller than max option");for(var h=(c-a)/(n-r),p=0;p<i.length;p++)e[p]=(i[p]-r)*h+a;return e}var v1=Object.freeze({__proto__:null,default:g1}),w1=be(v1);Object.defineProperty(zt,"__esModule",{value:!0});var tr=d1,If=w1;const Js=" ".repeat(2),$f=" ".repeat(4);function y1(){return Lf(this)}function Lf(i,t={}){const{maxRows:e=15,maxColumns:r=10,maxNumSize:n=8,padMinus:s="auto"}=t;return`${i.constructor.name} {
|
55
55
|
${Js}[
|
56
56
|
${$f}${D1(i,e,r,n,s)}
|
57
57
|
${Js}]
|
@@ -59,7 +59,7 @@ ${Js}rows: ${i.rows}
|
|
59
59
|
${Js}columns: ${i.columns}
|
60
60
|
}`}function D1(i,t,e,r,n){const{rows:s,columns:a}=i,l=Math.min(s,t),c=Math.min(a,e),h=[];if(n==="auto"){n=!1;t:for(let p=0;p<l;p++)for(let f=0;f<c;f++)if(i.get(p,f)<0){n=!0;break t}}for(let p=0;p<l;p++){let f=[];for(let d=0;d<c;d++)f.push(b1(i.get(p,d),r,n));h.push(`${f.join(" ")}`)}return c!==a&&(h[h.length-1]+=` ... ${a-e} more columns`),l!==s&&h.push(`... ${s-t} more rows`),h.join(`
|
61
61
|
${$f}`)}function b1(i,t,e){return(i>=0&&e?` ${Rf(i,t-1)}`:Rf(i,t)).padEnd(t)}function Rf(i,t){let e=i.toString();if(e.length<=t)return e;let r=i.toFixed(t);if(r.length>t&&(r=i.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=i.toExponential(t);return n.length>t&&(n=i.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function E1(i,t){i.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},i.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r);return this},i.prototype.addM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r.get(n,s));return this},i.add=function(r,n){return new t(r).add(n)},i.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},i.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r);return this},i.prototype.subM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r.get(n,s));return this},i.sub=function(r,n){return new t(r).sub(n)},i.prototype.subtract=i.prototype.sub,i.prototype.subtractS=i.prototype.subS,i.prototype.subtractM=i.prototype.subM,i.subtract=i.sub,i.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},i.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r);return this},i.prototype.mulM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r.get(n,s));return this},i.mul=function(r,n){return new t(r).mul(n)},i.prototype.multiply=i.prototype.mul,i.prototype.multiplyS=i.prototype.mulS,i.prototype.multiplyM=i.prototype.mulM,i.multiply=i.mul,i.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},i.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r);return this},i.prototype.divM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r.get(n,s));return this},i.div=function(r,n){return new t(r).div(n)},i.prototype.divide=i.prototype.div,i.prototype.divideS=i.prototype.divS,i.prototype.divideM=i.prototype.divM,i.divide=i.div,i.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},i.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r);return this},i.prototype.modM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r.get(n,s));return this},i.mod=function(r,n){return new t(r).mod(n)},i.prototype.modulus=i.prototype.mod,i.prototype.modulusS=i.prototype.modS,i.prototype.modulusM=i.prototype.modM,i.modulus=i.mod,i.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},i.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r);return this},i.prototype.andM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r.get(n,s));return this},i.and=function(r,n){return new t(r).and(n)},i.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},i.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r);return this},i.prototype.orM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r.get(n,s));return this},i.or=function(r,n){return new t(r).or(n)},i.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},i.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r);return this},i.prototype.xorM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r.get(n,s));return this},i.xor=function(r,n){return new t(r).xor(n)},i.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},i.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r);return this},i.prototype.leftShiftM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r.get(n,s));return this},i.leftShift=function(r,n){return new t(r).leftShift(n)},i.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},i.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r);return this},i.prototype.signPropagatingRightShiftM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r.get(n,s));return this},i.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},i.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},i.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r);return this},i.prototype.rightShiftM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r.get(n,s));return this},i.rightShift=function(r,n){return new t(r).rightShift(n)},i.prototype.zeroFillRightShift=i.prototype.rightShift,i.prototype.zeroFillRightShiftS=i.prototype.rightShiftS,i.prototype.zeroFillRightShiftM=i.prototype.rightShiftM,i.zeroFillRightShift=i.rightShift,i.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},i.not=function(r){return new t(r).not()},i.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},i.abs=function(r){return new t(r).abs()},i.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},i.acos=function(r){return new t(r).acos()},i.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},i.acosh=function(r){return new t(r).acosh()},i.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},i.asin=function(r){return new t(r).asin()},i.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},i.asinh=function(r){return new t(r).asinh()},i.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},i.atan=function(r){return new t(r).atan()},i.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},i.atanh=function(r){return new t(r).atanh()},i.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},i.cbrt=function(r){return new t(r).cbrt()},i.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},i.ceil=function(r){return new t(r).ceil()},i.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},i.clz32=function(r){return new t(r).clz32()},i.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},i.cos=function(r){return new t(r).cos()},i.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},i.cosh=function(r){return new t(r).cosh()},i.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},i.exp=function(r){return new t(r).exp()},i.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},i.expm1=function(r){return new t(r).expm1()},i.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},i.floor=function(r){return new t(r).floor()},i.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},i.fround=function(r){return new t(r).fround()},i.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},i.log=function(r){return new t(r).log()},i.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},i.log1p=function(r){return new t(r).log1p()},i.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},i.log10=function(r){return new t(r).log10()},i.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},i.log2=function(r){return new t(r).log2()},i.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},i.round=function(r){return new t(r).round()},i.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},i.sign=function(r){return new t(r).sign()},i.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},i.sin=function(r){return new t(r).sin()},i.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},i.sinh=function(r){return new t(r).sinh()},i.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},i.sqrt=function(r){return new t(r).sqrt()},i.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},i.tan=function(r){return new t(r).tan()},i.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},i.tanh=function(r){return new t(r).tanh()},i.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},i.trunc=function(r){return new t(r).trunc()},i.pow=function(r,n){return new t(r).pow(n)},i.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},i.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r));return this},i.prototype.powM=function(r){if(r=t.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 s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r.get(n,s)));return this}}function Dr(i,t,e){let r=e?i.rows:i.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function br(i,t,e){let r=e?i.columns:i.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function mi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function gi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function Ta(i,t){if(!tr.isAnyArray(t))throw new TypeError("row indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.rows)throw new RangeError("row indices are out of range")}function Oa(i,t){if(!tr.isAnyArray(t))throw new TypeError("column indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.columns)throw new RangeError("column indices are out of range")}function Ia(i,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Vs("startRow",t),Vs("endRow",e),Vs("startColumn",r),Vs("endColumn",n),t>e||r>n||t<0||t>=i.rows||e<0||e>=i.rows||r<0||r>=i.columns||n<0||n>=i.columns)throw new RangeError("Submatrix indices are out of range")}function Qs(i,t=0){let e=[];for(let r=0;r<i;r++)e.push(t);return e}function Vs(i,t){if(typeof t!="number")throw new TypeError(`${i} must be a number`)}function vi(i){if(i.isEmpty())throw new Error("Empty matrix has no elements to index")}function x1(i){let t=Qs(i.rows);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]+=i.get(e,r);return t}function A1(i){let t=Qs(i.columns);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]+=i.get(e,r);return t}function C1(i){let t=0;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t+=i.get(e,r);return t}function F1(i){let t=Qs(i.rows,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]*=i.get(e,r);return t}function M1(i){let t=Qs(i.columns,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]*=i.get(e,r);return t}function N1(i){let t=1;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t*=i.get(e,r);return t}function S1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<r;a++){let l=0,c=0,h=0;for(let p=0;p<n;p++)h=i.get(a,p)-e[a],l+=h,c+=h*h;t?s.push((c-l*l/n)/(n-1)):s.push((c-l*l/n)/n)}return s}function B1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<n;a++){let l=0,c=0,h=0;for(let p=0;p<r;p++)h=i.get(p,a)-e[a],l+=h,c+=h*h;t?s.push((c-l*l/r)/(r-1)):s.push((c-l*l/r)/r)}return s}function T1(i,t,e){const r=i.rows,n=i.columns,s=r*n;let a=0,l=0,c=0;for(let h=0;h<r;h++)for(let p=0;p<n;p++)c=i.get(h,p)-e,a+=c,l+=c*c;return t?(l-a*a/s)/(s-1):(l-a*a/s)/s}function O1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[e])}function I1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[r])}function $1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t)}function L1(i){const t=[];for(let e=0;e<i.rows;e++){let r=0;for(let n=0;n<i.columns;n++)r+=Math.pow(i.get(e,n),2)/(i.columns-1);t.push(Math.sqrt(r))}return t}function R1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[e])}function P1(i){const t=[];for(let e=0;e<i.columns;e++){let r=0;for(let n=0;n<i.rows;n++)r+=Math.pow(i.get(n,e),2)/(i.rows-1);t.push(Math.sqrt(r))}return t}function z1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[r])}function q1(i){const t=i.size-1;let e=0;for(let r=0;r<i.columns;r++)for(let n=0;n<i.rows;n++)e+=Math.pow(i.get(n,r),2)/t;return Math.sqrt(e)}function k1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t)}class $t{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,r[a*e+l]);return s}static rowVector(t){let e=new pt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new pt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new pt(t,e)}static ones(t,e){return new pt(t,e).fill(1)}static rand(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,n());return s}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:a=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let l=s-n,c=new pt(t,e);for(let h=0;h<t;h++)for(let p=0;p<e;p++){let f=n+Math.round(a()*l);c.set(h,p,f)}return c}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let a=0;a<n;a++)s.set(a,a,r);return s}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let s=Math.min(n,e,r),a=this.zeros(e,r);for(let l=0;l<s;l++)a.set(l,l,t[l]);return a}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new pt(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.min(t.get(a,l),e.get(a,l)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.max(t.get(a,l),e.get(a,l)));return s}static checkMatrix(t){return $t.isMatrix(t)?t:new pt(t)}static isMatrix(t){return t!=null&&t.klass==="Matrix"}get size(){return this.rows*this.columns}apply(t){if(typeof t!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}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 t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(this.get(t,t)!==0)return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let a=e+1;a<this.rows;a++)this.get(t,a)!==0&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let a=r;a<t.columns;a++)t.set(e,a,t.get(e,a)/s);for(let a=e+1;a<t.rows;a++){let l=t.get(a,r)/t.get(e,r);t.set(a,r,0);for(let c=r+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(e,c)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let s=0,a=!1;for(;s<r&&a===!1;)t.get(n,s)===1?a=!0:s++;for(let l=0;l<n;l++){let c=t.get(l,s);for(let h=s;h<e;h++){let p=t.get(l,h)-c*t.get(n,h);t.set(l,h,p)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=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 pt(this.rows*e,this.columns*r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*s,this.columns*a);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Dr(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return pt.rowVector(this.getRow(t))}setRow(t,e){Dr(this,t),e=mi(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Dr(this,t),Dr(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){br(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return pt.columnVector(this.getColumn(t))}setColumn(t,e){br(this,t),e=gi(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){br(this,t),br(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=gi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=gi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=gi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=gi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Dr(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){br(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=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)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=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)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(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));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){vi(this);let t=this.get(0,0),e=[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),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=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)<e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=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)<e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(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));return e}default:throw new Error(`invalid option: ${t}`)}}minIndex(){vi(this);let t=this.get(0,0),e=[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),e[0]=r,e[1]=n);return e}maxRow(t){if(Dr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Dr(this,t),vi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Dr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Dr(this,t),vi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(br(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){br(this,t),vi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(br(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){br(this,t),vi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){$t.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new pt(e,n),a=new Float64Array(r);for(let l=0;l<n;l++){for(let c=0;c<r;c++)a[c]=t.get(c,l);for(let c=0;c<e;c++){let h=0;for(let p=0;p<r;p++)h+=this.get(c,p)*a[p];s.set(c,l,h)}}return s}strassen2x2(t){t=pt.checkMatrix(t);let e=new pt(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),a=t.get(0,1),l=this.get(1,0),c=t.get(1,0),h=this.get(1,1),p=t.get(1,1),f=(r+h)*(n+p),d=(l+h)*n,g=r*(a-p),w=h*(c-n),m=(r+s)*p,D=(l-r)*(n+a),v=(s-h)*(c+p),E=f+w-m+v,b=g+m,N=d+w,x=f-d+g+D;return e.set(0,0,E),e.set(0,1,b),e.set(1,0,N),e.set(1,1,x),e}strassen3x3(t){t=pt.checkMatrix(t);let e=new pt(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),a=this.get(1,0),l=this.get(1,1),c=this.get(1,2),h=this.get(2,0),p=this.get(2,1),f=this.get(2,2),d=t.get(0,0),g=t.get(0,1),w=t.get(0,2),m=t.get(1,0),D=t.get(1,1),v=t.get(1,2),E=t.get(2,0),b=t.get(2,1),N=t.get(2,2),x=(r+n+s-a-l-p-f)*D,F=(r-a)*(-g+D),M=l*(-d+g+m-D-v-E+N),S=(-r+a+l)*(d-g+D),I=(a+l)*(-d+g),C=r*d,T=(-r+h+p)*(d-w+v),L=(-r+h)*(w-v),U=(h+p)*(-d+w),k=(r+n+s-l-c-h-p)*v,W=p*(-d+w+m-D-v-E+b),P=(-s+p+f)*(D+E-b),K=(s-f)*(D-b),G=s*E,Q=(p+f)*(-E+b),tt=(-s+l+c)*(v+E-N),ct=(s-c)*(v-N),vt=(l+c)*(-E+N),lt=n*m,yt=c*b,bt=a*w,Bt=h*g,Et=f*N,ne=C+G+lt,Ot=x+S+I+C+P+G+Q,Nt=C+T+U+k+G+tt+vt,se=F+M+S+C+G+tt+ct,Vt=F+S+I+C+yt,qt=G+tt+ct+vt+bt,Kt=C+T+L+W+P+K+G,Ne=P+K+G+Q+Bt,lr=C+T+L+U+Et;return e.set(0,0,ne),e.set(0,1,Ot),e.set(0,2,Nt),e.set(1,0,se),e.set(1,1,Vt),e.set(1,2,qt),e.set(2,0,Kt),e.set(2,1,Ne),e.set(2,2,lr),e}mmulStrassen(t){t=pt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,a=t.columns;n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${a} matrix: dimensions do not match.`);function l(f,d,g){let w=f.rows,m=f.columns;if(w===d&&m===g)return f;{let D=$t.zeros(d,g);return D=D.setSubMatrix(f,0,0),D}}let c=Math.max(r,s),h=Math.max(n,a);e=l(e,c,h),t=l(t,c,h);function p(f,d,g,w){if(g<=512||w<=512)return f.mmul(d);g%2===1&&w%2===1?(f=l(f,g+1,w+1),d=l(d,g+1,w+1)):g%2===1?(f=l(f,g+1,w),d=l(d,g+1,w)):w%2===1&&(f=l(f,g,w+1),d=l(d,g,w+1));let m=parseInt(f.rows/2,10),D=parseInt(f.columns/2,10),v=f.subMatrix(0,m-1,0,D-1),E=d.subMatrix(0,m-1,0,D-1),b=f.subMatrix(0,m-1,D,f.columns-1),N=d.subMatrix(0,m-1,D,d.columns-1),x=f.subMatrix(m,f.rows-1,0,D-1),F=d.subMatrix(m,d.rows-1,0,D-1),M=f.subMatrix(m,f.rows-1,D,f.columns-1),S=d.subMatrix(m,d.rows-1,D,d.columns-1),I=p($t.add(v,M),$t.add(E,S),m,D),C=p($t.add(x,M),E,m,D),T=p(v,$t.sub(N,S),m,D),L=p(M,$t.sub(F,E),m,D),U=p($t.add(v,b),S,m,D),k=p($t.sub(x,v),$t.add(E,N),m,D),W=p($t.sub(b,M),$t.add(F,S),m,D),P=$t.add(I,L);P.sub(U),P.add(W);let K=$t.add(T,U),G=$t.add(C,L),Q=$t.sub(I,C);Q.add(T),Q.add(k);let tt=$t.zeros(2*P.rows,2*P.columns);return tt=tt.setSubMatrix(P,0,0),tt=tt.setSubMatrix(K,P.rows,0),tt=tt.setSubMatrix(G,0,P.columns),tt=tt.setSubMatrix(Q,P.rows,P.columns),tt.subMatrix(0,g-1,0,w-1)}return p(e,t,c,h)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.rows;s++){const a=this.getRow(s);a.length>0&&If(a,{min:e,max:r,output:a}),n.setRow(s,a)}return n}scaleColumns(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.columns;s++){const a=this.getColumn(s);a.length&&If(a,{min:e,max:r,output:a}),n.setColumn(s,a)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let n=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,n)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let n=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,n)}return this}kroneckerProduct(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,a=new pt(e*n,r*s);for(let l=0;l<e;l++)for(let c=0;c<r;c++)for(let h=0;h<n;h++)for(let p=0;p<s;p++)a.set(n*l+h,s*c+p,this.get(l,c)*t.get(h,p));return a}kroneckerSum(t){if(t=pt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(pt.eye(r,r)),s=pt.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new pt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=Pf){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=Pf){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ia(this,t,e,r,n);let s=new pt(e-t+1,n-r+1);for(let a=t;a<=e;a++)for(let l=r;l<=n;l++)s.set(a-t,l-r,this.get(a,l));return s}subMatrixRow(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new pt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,a-e,this.get(t[s],a))}return n}subMatrixColumn(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new pt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(a-e,s,this.get(a,t[s]))}return n}setSubMatrix(t,e,r){if(t=pt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,s=r+t.columns-1;Ia(this,e,n,r,s);for(let a=0;a<t.rows;a++)for(let l=0;l<t.columns;l++)this.set(e+a,r+l,t.get(a,l));return this}selection(t,e){Ta(this,t),Oa(this,e);let r=new pt(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let a=0;a<e.length;a++){let l=e[a];r.set(n,a,this.get(s,l))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new pt(this.rows,this.columns))}static copy(t,e){for(const[r,n,s]of t.entries())e.set(r,n,s);return e}sum(t){switch(t){case"row":return x1(this);case"column":return A1(this);case void 0:return C1(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return F1(this);case"column":return M1(this);case void 0:return N1(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":{for(let r=0;r<this.rows;r++)e[r]/=this.columns;return e}case"column":{for(let r=0;r<this.columns;r++)e[r]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(t){case"row":{if(!tr.isAnyArray(n))throw new TypeError("mean must be an array");return S1(this,r,n)}case"column":{if(!tr.isAnyArray(n))throw new TypeError("mean must be an array");return B1(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return T1(this,r,n)}default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){typeof t=="object"&&(e=t,t=void 0);const r=this.variance(t,e);if(t===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":{if(!tr.isAnyArray(r))throw new TypeError("center must be an array");return O1(this,r),this}case"column":{if(!tr.isAnyArray(r))throw new TypeError("center must be an array");return I1(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return $1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":{if(r===void 0)r=L1(this);else if(!tr.isAnyArray(r))throw new TypeError("scale must be an array");return R1(this,r),this}case"column":{if(r===void 0)r=P1(this);else if(!tr.isAnyArray(r))throw new TypeError("scale must be an array");return z1(this,r),this}case void 0:{if(r===void 0)r=q1(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return k1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return Lf(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}$t.prototype.klass="Matrix",typeof Symbol<"u"&&($t.prototype[Symbol.for("nodejs.util.inspect.custom")]=y1);function Pf(i,t){return i-t}function U1(i){return i.every(t=>typeof t=="number")}$t.random=$t.rand,$t.randomInt=$t.randInt,$t.diagonal=$t.diag,$t.prototype.diagonal=$t.prototype.diag,$t.identity=$t.eye,$t.prototype.negate=$t.prototype.neg,$t.prototype.tensorProduct=$t.prototype.kroneckerProduct;let pt=(Ei=class extends $t{constructor(e,r){super();bl(this,Vi);z(this,"data");if(Ei.isMatrix(e))El(this,Vi,xl).call(this,e.rows,e.columns),Ei.copy(e,this);else if(Number.isInteger(e)&&e>=0)El(this,Vi,xl).call(this,e,r);else if(tr.isAnyArray(e)){const n=e;if(e=n.length,r=e?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 s=0;s<e;s++){if(n[s].length!==r)throw new RangeError("Inconsistent array dimensions");if(!U1(n[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[s]))}this.rows=e,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(e,r,n){return this.data[e][r]=n,this}get(e,r){return this.data[e][r]}removeRow(e){return Dr(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),Dr(this,e,!0),r=Float64Array.from(mi(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){br(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let s=0;s<e;s++)n[s]=this.data[r][s];for(let s=e+1;s<this.columns;s++)n[s-1]=this.data[r][s];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),br(this,e,!0),r=gi(this,r);for(let n=0;n<this.rows;n++){const s=new Float64Array(this.columns+1);let a=0;for(;a<e;a++)s[a]=this.data[n][a];for(s[a++]=r[n];a<this.columns+1;a++)s[a]=this.data[n][a-1];this.data[n]=s}return this.columns+=1,this}},Vi=new WeakSet,xl=function(e,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=r},Ei);E1($t,pt);const fo=class fo extends $t{constructor(e){super();bl(this,We,void 0);if(pt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");na(this,We,pt.copy(e,new pt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)na(this,We,new pt(e,e));else if(na(this,We,new pt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Ur(this,We).size}get rows(){return Ur(this,We).rows}get columns(){return Ur(this,We).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return pt.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new fo(this.diagonalSize);for(const[r,n,s]of this.upperRightEntries())e.set(r,n,s);return e}toMatrix(){return new pt(this)}get(e,r){return Ur(this,We).get(e,r)}set(e,r,n){return Ur(this,We).set(e,r,n),Ur(this,We).set(r,e,n),this}removeCross(e){return Ur(this,We).removeRow(e),Ur(this,We).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Ur(this,We).addRow(e,n),Ur(this,We).addColumn(e,r),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,s]of e.entries())s||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,r=new Array(e*(e+1)/2);for(let n=0,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=e&&(n=++s);return r}static fromCompact(e){const r=e.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(e)}`);const s=new fo(n);for(let a=0,l=0,c=0;c<r;c++)s.set(a,l,e[c]),++a>=n&&(a=++l);return s}*upperRightEntries(){for(let e=0,r=0;e<this.diagonalSize;void 0){const n=this.get(e,r);yield[e,r,n],++r>=this.diagonalSize&&(r=++e)}}*upperRightValues(){for(let e=0,r=0;e<this.diagonalSize;void 0)yield this.get(e,r),++r>=this.diagonalSize&&(r=++e)}};We=new WeakMap;let Zn=fo;Zn.prototype.klassType="SymmetricMatrix";class to extends Zn{static isDistanceMatrix(t){return Zn.isSymmetricMatrix(t)&&t.klassSubType==="DistanceMatrix"}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return e===void 0&&(e=t,t=this.diagonalSize),e=e.slice(),e[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new Zn(this)}clone(){const t=new to(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=(t-1)*t/2,r=new Array(e);for(let n=1,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=t&&(n=++s+1);return r}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let s=1,a=0,l=0;l<e;l++)n.set(s,a,t[l]),++s>=r&&(s=++a+1);return n}}to.prototype.klassSubType="DistanceMatrix";class en extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class W1 extends en{constructor(t,e){br(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class j1 extends en{constructor(t,e){Oa(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class Y1 extends en{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class Z1 extends en{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class G1 extends en{constructor(t,e){Dr(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class K1 extends en{constructor(t,e){Ta(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class eo extends en{constructor(t,e,r){Ta(t,e),Oa(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class H1 extends en{constructor(t,e,r,n,s){Ia(t,e,r,n,s),super(t,r-e+1,s-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class X1 extends en{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class zf extends $t{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class ur extends $t{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function J1(i,t){if(tr.isAnyArray(i))return i[0]&&tr.isAnyArray(i[0])?new ur(i):new zf(i,t);throw new Error("the argument is not an array")}class ro{constructor(t){t=ur.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,s=new Float64Array(r),a=1,l,c,h,p,f,d,g,w,m;for(l=0;l<r;l++)s[l]=l;for(w=new Float64Array(r),c=0;c<n;c++){for(l=0;l<r;l++)w[l]=e.get(l,c);for(l=0;l<r;l++){for(m=Math.min(l,c),f=0,h=0;h<m;h++)f+=e.get(l,h)*w[h];w[l]-=f,e.set(l,c,w[l])}for(p=c,l=c+1;l<r;l++)Math.abs(w[l])>Math.abs(w[p])&&(p=l);if(p!==c){for(h=0;h<n;h++)d=e.get(p,h),e.set(p,h,e.get(c,h)),e.set(c,h,d);g=s[p],s[p]=s[c],s[c]=g,a=-a}if(c<r&&e.get(c,c)!==0)for(l=c+1;l<r;l++)e.set(l,c,e.get(l,c)/e.get(c,c))}this.LU=e,this.pivotVector=s,this.pivotSign=a}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(t.get(r,r)===0)return!0;return!1}solve(t){t=pt.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=t.columns,s=t.subMatrixRow(this.pivotVector,0,n-1),a=e.columns,l,c,h;for(h=0;h<a;h++)for(l=h+1;l<a;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h));for(h=a-1;h>=0;h--){for(c=0;c<n;c++)s.set(h,c,s.get(h,c)/e.get(h,h));for(l=0;l<h;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h))}return s}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s>a?n.set(s,a,t.get(s,a)):s===a?n.set(s,a,1):n.set(s,a,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s<=a?n.set(s,a,t.get(s,a)):n.set(s,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function rn(i,t){let e=0;return Math.abs(i)>Math.abs(t)?(e=t/i,Math.abs(i)*Math.sqrt(1+e*e)):t!==0?(e=i/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class $a{constructor(t){t=ur.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,s=new Float64Array(n),a,l,c,h;for(c=0;c<n;c++){let p=0;for(a=c;a<r;a++)p=rn(p,e.get(a,c));if(p!==0){for(e.get(c,c)<0&&(p=-p),a=c;a<r;a++)e.set(a,c,e.get(a,c)/p);for(e.set(c,c,e.get(c,c)+1),l=c+1;l<n;l++){for(h=0,a=c;a<r;a++)h+=e.get(a,c)*e.get(a,l);for(h=-h/e.get(c,c),a=c;a<r;a++)e.set(a,l,e.get(a,l)+h*e.get(a,c))}}s[c]=-p}this.QR=e,this.Rdiag=s}solve(t){t=pt.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=t.columns,s=t.clone(),a=e.columns,l,c,h,p;for(h=0;h<a;h++)for(c=0;c<n;c++){for(p=0,l=h;l<r;l++)p+=e.get(l,h)*s.get(l,c);for(p=-p/e.get(h,h),l=h;l<r;l++)s.set(l,c,s.get(l,c)+p*e.get(l,h))}for(h=a-1;h>=0;h--){for(c=0;c<n;c++)s.set(h,c,s.get(h,c)/this.Rdiag[h]);for(l=0;l<h;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h))}return s.subMatrix(0,a-1,0,n-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let t=this.QR,e=t.columns,r=new pt(e,e),n,s;for(n=0;n<e;n++)for(s=0;s<e;s++)n<s?r.set(n,s,t.get(n,s)):n===s?r.set(n,s,this.Rdiag[n]):r.set(n,s,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new pt(e,r),s,a,l,c;for(l=r-1;l>=0;l--){for(s=0;s<e;s++)n.set(s,l,0);for(n.set(l,l,1),a=l;a<r;a++)if(t.get(l,l)!==0){for(c=0,s=l;s<e;s++)c+=t.get(s,l)*n.get(s,a);for(c=-c/t.get(l,l),s=l;s<e;s++)n.set(s,a,n.get(s,a)+c*t.get(s,l))}}return n}}class wi{constructor(t,e={}){if(t=ur.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:a=!0,autoTranspose:l=!1}=e;let c=!!s,h=!!a,p=!1,f;if(r<n)if(!l)f=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{f=t.transpose(),r=f.rows,n=f.columns,p=!0;let C=c;c=h,h=C}else f=t.clone();let d=Math.min(r,n),g=Math.min(r+1,n),w=new Float64Array(g),m=new pt(r,d),D=new pt(n,n),v=new Float64Array(n),E=new Float64Array(r),b=new Float64Array(g);for(let C=0;C<g;C++)b[C]=C;let N=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),F=Math.max(N,x);for(let C=0;C<F;C++){if(C<N){w[C]=0;for(let T=C;T<r;T++)w[C]=rn(w[C],f.get(T,C));if(w[C]!==0){f.get(C,C)<0&&(w[C]=-w[C]);for(let T=C;T<r;T++)f.set(T,C,f.get(T,C)/w[C]);f.set(C,C,f.get(C,C)+1)}w[C]=-w[C]}for(let T=C+1;T<n;T++){if(C<N&&w[C]!==0){let L=0;for(let U=C;U<r;U++)L+=f.get(U,C)*f.get(U,T);L=-L/f.get(C,C);for(let U=C;U<r;U++)f.set(U,T,f.get(U,T)+L*f.get(U,C))}v[T]=f.get(C,T)}if(c&&C<N)for(let T=C;T<r;T++)m.set(T,C,f.get(T,C));if(C<x){v[C]=0;for(let T=C+1;T<n;T++)v[C]=rn(v[C],v[T]);if(v[C]!==0){v[C+1]<0&&(v[C]=0-v[C]);for(let T=C+1;T<n;T++)v[T]/=v[C];v[C+1]+=1}if(v[C]=-v[C],C+1<r&&v[C]!==0){for(let T=C+1;T<r;T++)E[T]=0;for(let T=C+1;T<r;T++)for(let L=C+1;L<n;L++)E[T]+=v[L]*f.get(T,L);for(let T=C+1;T<n;T++){let L=-v[T]/v[C+1];for(let U=C+1;U<r;U++)f.set(U,T,f.get(U,T)+L*E[U])}}if(h)for(let T=C+1;T<n;T++)D.set(T,C,v[T])}}let M=Math.min(n,r+1);if(N<n&&(w[N]=f.get(N,N)),r<M&&(w[M-1]=0),x+1<M&&(v[x]=f.get(x,M-1)),v[M-1]=0,c){for(let C=N;C<d;C++){for(let T=0;T<r;T++)m.set(T,C,0);m.set(C,C,1)}for(let C=N-1;C>=0;C--)if(w[C]!==0){for(let T=C+1;T<d;T++){let L=0;for(let U=C;U<r;U++)L+=m.get(U,C)*m.get(U,T);L=-L/m.get(C,C);for(let U=C;U<r;U++)m.set(U,T,m.get(U,T)+L*m.get(U,C))}for(let T=C;T<r;T++)m.set(T,C,-m.get(T,C));m.set(C,C,1+m.get(C,C));for(let T=0;T<C-1;T++)m.set(T,C,0)}else{for(let T=0;T<r;T++)m.set(T,C,0);m.set(C,C,1)}}if(h)for(let C=n-1;C>=0;C--){if(C<x&&v[C]!==0)for(let T=C+1;T<n;T++){let L=0;for(let U=C+1;U<n;U++)L+=D.get(U,C)*D.get(U,T);L=-L/D.get(C+1,C);for(let U=C+1;U<n;U++)D.set(U,T,D.get(U,T)+L*D.get(U,C))}for(let T=0;T<n;T++)D.set(T,C,0);D.set(C,C,1)}let S=M-1,I=Number.EPSILON;for(;M>0;){let C,T;for(C=M-2;C>=-1&&C!==-1;C--){const L=Number.MIN_VALUE+I*Math.abs(w[C]+Math.abs(w[C+1]));if(Math.abs(v[C])<=L||Number.isNaN(v[C])){v[C]=0;break}}if(C===M-2)T=4;else{let L;for(L=M-1;L>=C&&L!==C;L--){let U=(L!==M?Math.abs(v[L]):0)+(L!==C+1?Math.abs(v[L-1]):0);if(Math.abs(w[L])<=I*U){w[L]=0;break}}L===C?T=3:L===M-1?T=1:(T=2,C=L)}switch(C++,T){case 1:{let L=v[M-2];v[M-2]=0;for(let U=M-2;U>=C;U--){let k=rn(w[U],L),W=w[U]/k,P=L/k;if(w[U]=k,U!==C&&(L=-P*v[U-1],v[U-1]=W*v[U-1]),h)for(let K=0;K<n;K++)k=W*D.get(K,U)+P*D.get(K,M-1),D.set(K,M-1,-P*D.get(K,U)+W*D.get(K,M-1)),D.set(K,U,k)}break}case 2:{let L=v[C-1];v[C-1]=0;for(let U=C;U<M;U++){let k=rn(w[U],L),W=w[U]/k,P=L/k;if(w[U]=k,L=-P*v[U],v[U]=W*v[U],c)for(let K=0;K<r;K++)k=W*m.get(K,U)+P*m.get(K,C-1),m.set(K,C-1,-P*m.get(K,U)+W*m.get(K,C-1)),m.set(K,U,k)}break}case 3:{const L=Math.max(Math.abs(w[M-1]),Math.abs(w[M-2]),Math.abs(v[M-2]),Math.abs(w[C]),Math.abs(v[C])),U=w[M-1]/L,k=w[M-2]/L,W=v[M-2]/L,P=w[C]/L,K=v[C]/L,G=((k+U)*(k-U)+W*W)/2,Q=U*W*(U*W);let tt=0;(G!==0||Q!==0)&&(G<0?tt=0-Math.sqrt(G*G+Q):tt=Math.sqrt(G*G+Q),tt=Q/(G+tt));let ct=(P+U)*(P-U)+tt,vt=P*K;for(let lt=C;lt<M-1;lt++){let yt=rn(ct,vt);yt===0&&(yt=Number.MIN_VALUE);let bt=ct/yt,Bt=vt/yt;if(lt!==C&&(v[lt-1]=yt),ct=bt*w[lt]+Bt*v[lt],v[lt]=bt*v[lt]-Bt*w[lt],vt=Bt*w[lt+1],w[lt+1]=bt*w[lt+1],h)for(let Et=0;Et<n;Et++)yt=bt*D.get(Et,lt)+Bt*D.get(Et,lt+1),D.set(Et,lt+1,-Bt*D.get(Et,lt)+bt*D.get(Et,lt+1)),D.set(Et,lt,yt);if(yt=rn(ct,vt),yt===0&&(yt=Number.MIN_VALUE),bt=ct/yt,Bt=vt/yt,w[lt]=yt,ct=bt*v[lt]+Bt*w[lt+1],w[lt+1]=-Bt*v[lt]+bt*w[lt+1],vt=Bt*v[lt+1],v[lt+1]=bt*v[lt+1],c&<<r-1)for(let Et=0;Et<r;Et++)yt=bt*m.get(Et,lt)+Bt*m.get(Et,lt+1),m.set(Et,lt+1,-Bt*m.get(Et,lt)+bt*m.get(Et,lt+1)),m.set(Et,lt,yt)}v[M-2]=ct;break}case 4:{if(w[C]<=0&&(w[C]=w[C]<0?-w[C]:0,h))for(let L=0;L<=S;L++)D.set(L,C,-D.get(L,C));for(;C<S&&!(w[C]>=w[C+1]);){let L=w[C];if(w[C]=w[C+1],w[C+1]=L,h&&C<n-1)for(let U=0;U<n;U++)L=D.get(U,C+1),D.set(U,C+1,D.get(U,C)),D.set(U,C,L);if(c&&C<r-1)for(let U=0;U<r;U++)L=m.get(U,C+1),m.set(U,C+1,m.get(U,C)),m.set(U,C,L);C++}M--;break}}}if(p){let C=D;D=m,m=C}this.m=r,this.n=n,this.s=w,this.U=m,this.V=D}solve(t){let e=t,r=this.threshold,n=this.s.length,s=pt.zeros(n,n);for(let d=0;d<n;d++)Math.abs(this.s[d])<=r?s.set(d,d,0):s.set(d,d,1/this.s[d]);let a=this.U,l=this.rightSingularVectors,c=l.mmul(s),h=l.rows,p=a.rows,f=pt.zeros(h,p);for(let d=0;d<h;d++)for(let g=0;g<p;g++){let w=0;for(let m=0;m<n;m++)w+=c.get(d,m)*a.get(g,m);f.set(d,g,w)}return f.mmul(e)}solveForDiagonal(t){return this.solve(pt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new pt(r,this.s.length);for(let p=0;p<r;p++)for(let f=0;f<n;f++)Math.abs(this.s[f])>e&&s.set(p,f,t.get(p,f)/this.s[f]);let a=this.U,l=a.rows,c=a.columns,h=new pt(r,l);for(let p=0;p<r;p++)for(let f=0;f<l;f++){let d=0;for(let g=0;g<c;g++)d+=s.get(p,g)*a.get(f,g);h.set(p,f,d)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}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 pt.diag(this.s)}}function Q1(i,t=!1){return i=ur.checkMatrix(i),t?new wi(i).inverse():qf(i,pt.eye(i.rows))}function qf(i,t,e=!1){return i=ur.checkMatrix(i),t=ur.checkMatrix(t),e?new wi(i).solve(t):i.isSquare()?new ro(i).solve(t):new $a(i).solve(t)}function no(i){if(i=pt.checkMatrix(i),i.isSquare()){if(i.columns===0)return 1;let t,e,r,n;if(i.columns===2)return t=i.get(0,0),e=i.get(0,1),r=i.get(1,0),n=i.get(1,1),t*n-e*r;if(i.columns===3){let s,a,l;return s=new eo(i,[1,2],[1,2]),a=new eo(i,[1,2],[0,2]),l=new eo(i,[1,2],[0,1]),t=i.get(0,0),e=i.get(0,1),r=i.get(0,2),t*no(s)-e*no(a)+r*no(l)}else return new ro(i).determinant}else throw Error("determinant can only be calculated for a square matrix")}function V1(i,t){let e=[];for(let r=0;r<i;r++)r!==t&&e.push(r);return e}function tw(i,t,e,r=1e-9,n=1e-9){if(i>n)return new Array(t.rows+1).fill(0);{let s=t.addRow(e,[0]);for(let a=0;a<s.rows;a++)Math.abs(s.get(a,0))<r&&s.set(a,0,0);return s.to1DArray()}}function ew(i,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;i=pt.checkMatrix(i);let n=i.rows,s=new pt(n,n);for(let a=0;a<n;a++){let l=pt.columnVector(i.getRow(a)),c=i.subMatrixRow(V1(n,a)).transpose(),p=new wi(c).solve(l),f=pt.sub(l,c.mmul(p)).abs().max();s.setRow(a,tw(f,p,a,e,r))}return s}function rw(i,t=Number.EPSILON){if(i=pt.checkMatrix(i),i.isEmpty())return i.transpose();let e=new wi(i,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,s=e.diagonal;for(let a=0;a<s.length;a++)Math.abs(s[a])>t?s[a]=1/s[a]:s[a]=0;return n.mmul(pt.diag(s).mmul(r.transpose()))}function nw(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!tr.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(i=i.center("column"),r||(t=t.center("column")));const s=i.transpose().mmul(t);for(let a=0;a<s.rows;a++)for(let l=0;l<s.columns;l++)s.set(a,l,s.get(a,l)*(1/(i.rows-1)));return s}function iw(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!tr.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=e;n&&(i.center("column"),r||t.center("column")),s&&(i.scale("column"),r||t.scale("column"));const a=i.standardDeviation("column",{unbiased:!0}),l=r?a:t.standardDeviation("column",{unbiased:!0}),c=i.transpose().mmul(t);for(let h=0;h<c.rows;h++)for(let p=0;p<c.columns;p++)c.set(h,p,c.get(h,p)*(1/(a[h]*l[p]))*(1/(i.rows-1)));return c}let kf=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=ur.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n=t.columns,s=new pt(n,n),a=new Float64Array(n),l=new Float64Array(n),c=t,h,p,f=!1;if(r?f=!0:f=t.isSymmetric(),f){for(h=0;h<n;h++)for(p=0;p<n;p++)s.set(h,p,c.get(h,p));sw(n,l,a,s),ow(n,l,a,s)}else{let d=new pt(n,n),g=new Float64Array(n);for(p=0;p<n;p++)for(h=0;h<n;h++)d.set(h,p,c.get(h,p));aw(n,d,g,s),uw(n,l,a,s,d)}this.n=n,this.e=l,this.d=a,this.V=s}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new pt(t,t),s,a;for(s=0;s<t;s++){for(a=0;a<t;a++)n.set(s,a,0);n.set(s,s,r[s]),e[s]>0?n.set(s,s+1,e[s]):e[s]<0&&n.set(s,s-1,e[s])}return n}};function sw(i,t,e,r){let n,s,a,l,c,h,p,f;for(c=0;c<i;c++)e[c]=r.get(i-1,c);for(l=i-1;l>0;l--){for(f=0,a=0,h=0;h<l;h++)f=f+Math.abs(e[h]);if(f===0)for(t[l]=e[l-1],c=0;c<l;c++)e[c]=r.get(l-1,c),r.set(l,c,0),r.set(c,l,0);else{for(h=0;h<l;h++)e[h]/=f,a+=e[h]*e[h];for(n=e[l-1],s=Math.sqrt(a),n>0&&(s=-s),t[l]=f*s,a=a-n*s,e[l-1]=n-s,c=0;c<l;c++)t[c]=0;for(c=0;c<l;c++){for(n=e[c],r.set(c,l,n),s=t[c]+r.get(c,c)*n,h=c+1;h<=l-1;h++)s+=r.get(h,c)*e[h],t[h]+=r.get(h,c)*n;t[c]=s}for(n=0,c=0;c<l;c++)t[c]/=a,n+=t[c]*e[c];for(p=n/(a+a),c=0;c<l;c++)t[c]-=p*e[c];for(c=0;c<l;c++){for(n=e[c],s=t[c],h=c;h<=l-1;h++)r.set(h,c,r.get(h,c)-(n*t[h]+s*e[h]));e[c]=r.get(l-1,c),r.set(l,c,0)}}e[l]=a}for(l=0;l<i-1;l++){if(r.set(i-1,l,r.get(l,l)),r.set(l,l,1),a=e[l+1],a!==0){for(h=0;h<=l;h++)e[h]=r.get(h,l+1)/a;for(c=0;c<=l;c++){for(s=0,h=0;h<=l;h++)s+=r.get(h,l+1)*r.get(h,c);for(h=0;h<=l;h++)r.set(h,c,r.get(h,c)-s*e[h])}}for(h=0;h<=l;h++)r.set(h,l+1,0)}for(c=0;c<i;c++)e[c]=r.get(i-1,c),r.set(i-1,c,0);r.set(i-1,i-1,1),t[0]=0}function ow(i,t,e,r){let n,s,a,l,c,h,p,f,d,g,w,m,D,v,E,b;for(a=1;a<i;a++)t[a-1]=t[a];t[i-1]=0;let N=0,x=0,F=Number.EPSILON;for(h=0;h<i;h++){for(x=Math.max(x,Math.abs(e[h])+Math.abs(t[h])),p=h;p<i&&!(Math.abs(t[p])<=F*x);)p++;if(p>h)do{for(n=e[h],f=(e[h+1]-n)/(2*t[h]),d=rn(f,1),f<0&&(d=-d),e[h]=t[h]/(f+d),e[h+1]=t[h]*(f+d),g=e[h+1],s=n-e[h],a=h+2;a<i;a++)e[a]-=s;for(N=N+s,f=e[p],w=1,m=w,D=w,v=t[h+1],E=0,b=0,a=p-1;a>=h;a--)for(D=m,m=w,b=E,n=w*t[a],s=w*f,d=rn(f,t[a]),t[a+1]=E*d,E=t[a]/d,w=f/d,f=w*e[a]-E*n,e[a+1]=s+E*(w*n+E*e[a]),c=0;c<i;c++)s=r.get(c,a+1),r.set(c,a+1,E*r.get(c,a)+w*s),r.set(c,a,w*r.get(c,a)-E*s);f=-E*b*D*v*t[h]/g,t[h]=E*f,e[h]=w*f}while(Math.abs(t[h])>F*x);e[h]=e[h]+N,t[h]=0}for(a=0;a<i-1;a++){for(c=a,f=e[a],l=a+1;l<i;l++)e[l]<f&&(c=l,f=e[l]);if(c!==a)for(e[c]=e[a],e[a]=f,l=0;l<i;l++)f=r.get(l,a),r.set(l,a,r.get(l,c)),r.set(l,c,f)}}function aw(i,t,e,r){let n=0,s=i-1,a,l,c,h,p,f,d;for(f=n+1;f<=s-1;f++){for(d=0,h=f;h<=s;h++)d=d+Math.abs(t.get(h,f-1));if(d!==0){for(c=0,h=s;h>=f;h--)e[h]=t.get(h,f-1)/d,c+=e[h]*e[h];for(l=Math.sqrt(c),e[f]>0&&(l=-l),c=c-e[f]*l,e[f]=e[f]-l,p=f;p<i;p++){for(a=0,h=s;h>=f;h--)a+=e[h]*t.get(h,p);for(a=a/c,h=f;h<=s;h++)t.set(h,p,t.get(h,p)-a*e[h])}for(h=0;h<=s;h++){for(a=0,p=s;p>=f;p--)a+=e[p]*t.get(h,p);for(a=a/c,p=f;p<=s;p++)t.set(h,p,t.get(h,p)-a*e[p])}e[f]=d*e[f],t.set(f,f-1,d*l)}}for(h=0;h<i;h++)for(p=0;p<i;p++)r.set(h,p,h===p?1:0);for(f=s-1;f>=n+1;f--)if(t.get(f,f-1)!==0){for(h=f+1;h<=s;h++)e[h]=t.get(h,f-1);for(p=f;p<=s;p++){for(l=0,h=f;h<=s;h++)l+=e[h]*r.get(h,p);for(l=l/e[f]/t.get(f,f-1),h=f;h<=s;h++)r.set(h,p,r.get(h,p)+l*e[h])}}}function uw(i,t,e,r,n){let s=i-1,a=0,l=i-1,c=Number.EPSILON,h=0,p=0,f=0,d=0,g=0,w=0,m=0,D=0,v,E,b,N,x,F,M,S,I,C,T,L,U,k,W;for(v=0;v<i;v++)for((v<a||v>l)&&(e[v]=n.get(v,v),t[v]=0),E=Math.max(v-1,0);E<i;E++)p=p+Math.abs(n.get(v,E));for(;s>=a;){for(N=s;N>a&&(w=Math.abs(n.get(N-1,N-1))+Math.abs(n.get(N,N)),w===0&&(w=p),!(Math.abs(n.get(N,N-1))<c*w));)N--;if(N===s)n.set(s,s,n.get(s,s)+h),e[s]=n.get(s,s),t[s]=0,s--,D=0;else if(N===s-1){if(M=n.get(s,s-1)*n.get(s-1,s),f=(n.get(s-1,s-1)-n.get(s,s))/2,d=f*f+M,m=Math.sqrt(Math.abs(d)),n.set(s,s,n.get(s,s)+h),n.set(s-1,s-1,n.get(s-1,s-1)+h),S=n.get(s,s),d>=0){for(m=f>=0?f+m:f-m,e[s-1]=S+m,e[s]=e[s-1],m!==0&&(e[s]=S-M/m),t[s-1]=0,t[s]=0,S=n.get(s,s-1),w=Math.abs(S)+Math.abs(m),f=S/w,d=m/w,g=Math.sqrt(f*f+d*d),f=f/g,d=d/g,E=s-1;E<i;E++)m=n.get(s-1,E),n.set(s-1,E,d*m+f*n.get(s,E)),n.set(s,E,d*n.get(s,E)-f*m);for(v=0;v<=s;v++)m=n.get(v,s-1),n.set(v,s-1,d*m+f*n.get(v,s)),n.set(v,s,d*n.get(v,s)-f*m);for(v=a;v<=l;v++)m=r.get(v,s-1),r.set(v,s-1,d*m+f*r.get(v,s)),r.set(v,s,d*r.get(v,s)-f*m)}else e[s-1]=S+f,e[s]=S+f,t[s-1]=m,t[s]=-m;s=s-2,D=0}else{if(S=n.get(s,s),I=0,M=0,N<s&&(I=n.get(s-1,s-1),M=n.get(s,s-1)*n.get(s-1,s)),D===10){for(h+=S,v=a;v<=s;v++)n.set(v,v,n.get(v,v)-S);w=Math.abs(n.get(s,s-1))+Math.abs(n.get(s-1,s-2)),S=I=.75*w,M=-.4375*w*w}if(D===30&&(w=(I-S)/2,w=w*w+M,w>0)){for(w=Math.sqrt(w),I<S&&(w=-w),w=S-M/((I-S)/2+w),v=a;v<=s;v++)n.set(v,v,n.get(v,v)-w);h+=w,S=I=M=.964}for(D=D+1,x=s-2;x>=N&&(m=n.get(x,x),g=S-m,w=I-m,f=(g*w-M)/n.get(x+1,x)+n.get(x,x+1),d=n.get(x+1,x+1)-m-g-w,g=n.get(x+2,x+1),w=Math.abs(f)+Math.abs(d)+Math.abs(g),f=f/w,d=d/w,g=g/w,!(x===N||Math.abs(n.get(x,x-1))*(Math.abs(d)+Math.abs(g))<c*(Math.abs(f)*(Math.abs(n.get(x-1,x-1))+Math.abs(m)+Math.abs(n.get(x+1,x+1))))));)x--;for(v=x+2;v<=s;v++)n.set(v,v-2,0),v>x+2&&n.set(v,v-3,0);for(b=x;b<=s-1&&(k=b!==s-1,b!==x&&(f=n.get(b,b-1),d=n.get(b+1,b-1),g=k?n.get(b+2,b-1):0,S=Math.abs(f)+Math.abs(d)+Math.abs(g),S!==0&&(f=f/S,d=d/S,g=g/S)),S!==0);b++)if(w=Math.sqrt(f*f+d*d+g*g),f<0&&(w=-w),w!==0){for(b!==x?n.set(b,b-1,-w*S):N!==x&&n.set(b,b-1,-n.get(b,b-1)),f=f+w,S=f/w,I=d/w,m=g/w,d=d/f,g=g/f,E=b;E<i;E++)f=n.get(b,E)+d*n.get(b+1,E),k&&(f=f+g*n.get(b+2,E),n.set(b+2,E,n.get(b+2,E)-f*m)),n.set(b,E,n.get(b,E)-f*S),n.set(b+1,E,n.get(b+1,E)-f*I);for(v=0;v<=Math.min(s,b+3);v++)f=S*n.get(v,b)+I*n.get(v,b+1),k&&(f=f+m*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-f*g)),n.set(v,b,n.get(v,b)-f),n.set(v,b+1,n.get(v,b+1)-f*d);for(v=a;v<=l;v++)f=S*r.get(v,b)+I*r.get(v,b+1),k&&(f=f+m*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-f*g)),r.set(v,b,r.get(v,b)-f),r.set(v,b+1,r.get(v,b+1)-f*d)}}}if(p!==0){for(s=i-1;s>=0;s--)if(f=e[s],d=t[s],d===0)for(N=s,n.set(s,s,1),v=s-1;v>=0;v--){for(M=n.get(v,v)-f,g=0,E=N;E<=s;E++)g=g+n.get(v,E)*n.get(E,s);if(t[v]<0)m=M,w=g;else if(N=v,t[v]===0?n.set(v,s,M!==0?-g/M:-g/(c*p)):(S=n.get(v,v+1),I=n.get(v+1,v),d=(e[v]-f)*(e[v]-f)+t[v]*t[v],F=(S*w-m*g)/d,n.set(v,s,F),n.set(v+1,s,Math.abs(S)>Math.abs(m)?(-g-M*F)/S:(-w-I*F)/m)),F=Math.abs(n.get(v,s)),c*F*F>1)for(E=v;E<=s;E++)n.set(E,s,n.get(E,s)/F)}else if(d<0)for(N=s-1,Math.abs(n.get(s,s-1))>Math.abs(n.get(s-1,s))?(n.set(s-1,s-1,d/n.get(s,s-1)),n.set(s-1,s,-(n.get(s,s)-f)/n.get(s,s-1))):(W=io(0,-n.get(s-1,s),n.get(s-1,s-1)-f,d),n.set(s-1,s-1,W[0]),n.set(s-1,s,W[1])),n.set(s,s-1,0),n.set(s,s,1),v=s-2;v>=0;v--){for(C=0,T=0,E=N;E<=s;E++)C=C+n.get(v,E)*n.get(E,s-1),T=T+n.get(v,E)*n.get(E,s);if(M=n.get(v,v)-f,t[v]<0)m=M,g=C,w=T;else if(N=v,t[v]===0?(W=io(-C,-T,M,d),n.set(v,s-1,W[0]),n.set(v,s,W[1])):(S=n.get(v,v+1),I=n.get(v+1,v),L=(e[v]-f)*(e[v]-f)+t[v]*t[v]-d*d,U=(e[v]-f)*2*d,L===0&&U===0&&(L=c*p*(Math.abs(M)+Math.abs(d)+Math.abs(S)+Math.abs(I)+Math.abs(m))),W=io(S*g-m*C+d*T,S*w-m*T-d*C,L,U),n.set(v,s-1,W[0]),n.set(v,s,W[1]),Math.abs(S)>Math.abs(m)+Math.abs(d)?(n.set(v+1,s-1,(-C-M*n.get(v,s-1)+d*n.get(v,s))/S),n.set(v+1,s,(-T-M*n.get(v,s)-d*n.get(v,s-1))/S)):(W=io(-g-I*n.get(v,s-1),-w-I*n.get(v,s),m,d),n.set(v+1,s-1,W[0]),n.set(v+1,s,W[1]))),F=Math.max(Math.abs(n.get(v,s-1)),Math.abs(n.get(v,s))),c*F*F>1)for(E=v;E<=s;E++)n.set(E,s-1,n.get(E,s-1)/F),n.set(E,s,n.get(E,s)/F)}for(v=0;v<i;v++)if(v<a||v>l)for(E=v;E<i;E++)r.set(v,E,n.get(v,E));for(E=i-1;E>=a;E--)for(v=a;v<=l;v++){for(m=0,b=a;b<=Math.min(E,l);b++)m=m+r.get(v,b)*n.get(b,E);r.set(v,E,m)}}}function io(i,t,e,r){let n,s;return Math.abs(e)>Math.abs(r)?(n=r/e,s=e+n*r,[(i+n*t)/s,(t-n*i)/s]):(n=e/r,s=r+n*e,[(n*i+t)/s,(n*t-i)/s])}class Uf{constructor(t){if(t=ur.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new pt(r,r),s=!0,a,l,c;for(l=0;l<r;l++){let h=0;for(c=0;c<l;c++){let p=0;for(a=0;a<c;a++)p+=n.get(c,a)*n.get(l,a);p=(e.get(l,c)-p)/n.get(c,c),n.set(l,c,p),h=h+p*p}for(h=e.get(l,l)-h,s&=h>0,n.set(l,l,Math.sqrt(Math.max(h,0))),c=l+1;c<r;c++)n.set(l,c,0)}this.L=n,this.positiveDefinite=!!s}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=ur.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=t.columns,s=t.clone(),a,l,c;for(c=0;c<r;c++)for(l=0;l<n;l++){for(a=0;a<c;a++)s.set(c,l,s.get(c,l)-s.get(a,l)*e.get(c,a));s.set(c,l,s.get(c,l)/e.get(c,c))}for(c=r-1;c>=0;c--)for(l=0;l<n;l++){for(a=c+1;a<r;a++)s.set(c,l,s.get(c,l)-s.get(a,l)*e.get(a,c));s.set(c,l,s.get(c,l)/e.get(c,c))}return s}get lowerTriangularMatrix(){return this.L}}class Wf{constructor(t,e={}){t=ur.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:s=1e3,terminationCriteria:a=1e-10}=e;let l;if(r){if(tr.isAnyArray(r)&&typeof r[0]=="number"?r=pt.columnVector(r):r=ur.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let c=1,h,p,f,d;for(let g=0;g<s&&c>a;g++)f=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),f=f.div(f.norm()),h=t.mmul(f).div(f.transpose().mmul(f).get(0,0)),g>0&&(c=h.clone().sub(d).pow(2).sum()),d=h.clone(),r?(p=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),p=p.div(p.norm()),l=r.mmul(p).div(p.transpose().mmul(p).get(0,0))):l=h;if(r){let g=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));g=g.div(g.norm());let w=t.clone().sub(h.clone().mmul(g.transpose())),m=l.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),D=r.clone().sub(h.clone().mulS(m.get(0,0)).mmul(p.transpose()));this.t=h,this.p=g.transpose(),this.w=f.transpose(),this.q=p,this.u=l,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=D,this.betas=m}else this.w=f.transpose(),this.s=h.transpose().mmul(h).sqrt(),n?this.t=h.clone().div(this.s.get(0,0)):this.t=h,this.xResidual=t.sub(h.mmul(f.transpose()))}}zt.AbstractMatrix=$t,zt.CHO=Uf,zt.CholeskyDecomposition=Uf,zt.DistanceMatrix=to,zt.EVD=kf;var lw=zt.EigenvalueDecomposition=kf;zt.LU=ro,zt.LuDecomposition=ro;var jf=zt.Matrix=pt;zt.MatrixColumnSelectionView=j1,zt.MatrixColumnView=W1,zt.MatrixFlipColumnView=Y1,zt.MatrixFlipRowView=Z1,zt.MatrixRowSelectionView=K1,zt.MatrixRowView=G1,zt.MatrixSelectionView=eo,zt.MatrixSubView=H1,zt.MatrixTransposeView=X1,zt.NIPALS=Wf,zt.Nipals=Wf,zt.QR=$a,zt.QrDecomposition=$a,zt.SVD=wi,zt.SingularValueDecomposition=wi,zt.SymmetricMatrix=Zn,zt.WrapperMatrix1D=zf,zt.WrapperMatrix2D=ur,zt.correlation=iw,zt.covariance=nw;var Yf=zt.default=pt;zt.determinant=no,zt.inverse=Q1,zt.linearDependencies=ew,zt.pseudoInverse=rw,zt.solve=qf,zt.wrap=J1;const Zf=lw,Gf=jf;Yf.Matrix&&Yf.Matrix;class cw{constructor(t){z(this,"_errorListener");this._errorListener=t}new({rows:t,columns:e,initial_value:r}={}){return new La(t,e,r,this._errorListener)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id1:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id1:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:s,to_column:a}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:s,to_column:a})}kron({id1:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id1:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id1:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r},n){return t==null?void 0:t.reshape({rows:e,columns:r},n)}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:s}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:s})}swap_rows({id:t,row1:e,row2:r}){t==null||t.swap_rows({row1:e,row2:r})}transpose({id:t}){return t==null?void 0:t.transpose()}remove_col({id:t,column:e}){return t==null?void 0:t.remove_col({column:e})}remove_row({id:t,row:e}){return t==null?void 0:t.remove_row({row:e})}eigenvalues({id:t}){return t==null?void 0:t.eigenvalues()}is_diagonal({id:t}){return t==null?void 0:t.is_diagonal()}is_identity({id:t}){return t==null?void 0:t.is_identity()}eigenvectors({id:t}){return t==null?void 0:t.eigenvectors()}is_symmetric({id:t}){return t==null?void 0:t.is_symmetric()}swap_columns({id:t,column1:e,column2:r}){t==null||t.swap_columns({column1:e,column2:r})}is_stochastic({id:t}){return t==null?void 0:t.is_stochastic()}is_triangular({id:t}){return t==null?void 0:t.is_triangular()}elements_count({id:t}){return t==null?void 0:t.elements_count()}is_antidiagonal({id:t}){return t==null?void 0:t.is_antidiagonal()}is_antisymmetric({id:t}){return t==null?void 0:t.is_antisymmetric()}}class La{constructor(t=0,e=0,r=void 0,n){z(this,"_matrixInstance");z(this,"_errorListener");this._matrixInstance=this._createMatrix(t,e,r),this._errorListener=n}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Xt(e,r,this._errorListener))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const s of n._value)t+=_t(s)?0:s,e+=1;return t/e}col({column:t}){const e=[],r=new Xt(0,void 0,this._errorListener);if(_t(t))return r;for(const n of this._matrixInstance)e.push(n._value[t]);return r._value=e,r}det(){return Bf(this._matrixArray)}get({row:t,column:e}){var r,n;if(!(_t(t)||_t(e)))return(n=(r=this._matrixInstance[t])==null?void 0:r._value)==null?void 0:n[e]}inv(){const t=Xs(this._matrixArray);return this._newMatrix(t)}max(){return i1(this._matrixArray)}min(){return Ba(this._matrixArray)}pow({power:t}){const e=_t(t)?this._matrixArray:o1(this._matrixArray,t);return this._newMatrix(e)}row({row:t}){return _t(t)?new Xt(0,void 0,this._errorListener):this._matrixInstance[t]}set({row:t,column:e,value:r}){_t(t)||_t(e)||this._matrixInstance[t].set({index:e,value:r})}sum({id2:t}){const e=Ki(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=Qv(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e,to_row:r,from_column:n,to_column:s}={}){_t(e)&&(e=0),_t(r)&&(r=this.rows()),_t(n)&&(n=0),_t(s)&&(s=this.columns());for(const[a,l]of this._matrixInstance.entries())for(const[c]of l._value.entries())a<r&&a>=e&&c>=n&&c<s&&l.set({index:c,value:t})}kron({id2:t}){const e=Xv(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return Ba(xf(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=_i(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=s1(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t,order:e=qn.ascending}={}){_t(t)&&(t=0),this._matrixInstance.sort((r,n)=>{const s=r._value[t],a=n._value[t];return e!==qn.descending?s-a:a-s})}trace(){return n1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Tf(this._matrixArray)}add_col({column:t,array_id:e}={}){_t(t)&&(t=this.columns());for(const[r,n]of this._matrixInstance.entries())n.insert({index:t,value:e?e._value[r]:void 0})}add_row({row:t,array_id:e}){_t(t)&&(t=this.rows()),this._matrixInstance.splice(t,0,e||new Xt(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t=0,columns:e=0},r){if(t*e!==this.columns()*this.rows()){this._errorListener.addError("New matrix must be of same area as original matrix",r,Ee.Error);return}const n=Zv(this._matrixArray,[t,e]);this._matrixInstance=n.map(s=>{const a=new Xt(0,void 0,this._errorListener);return a._value=[...s],a})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t,to_row:e,from_column:r,to_column:n}={}){_t(t)&&(t=0),_t(e)&&(e=this.rows()),_t(r)&&(r=0),_t(n)&&(n=this.columns());const s=this._matrixArray.splice(t,e),a=[];for(const l of s)a.push(l.splice(r,n));return this._newMatrix(a)}swap_rows({row1:t,row2:e}){if(_t(t)||_t(e))return;const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Cf(this._matrixArray);return this._newMatrix(t)}remove_col({column:t}={}){_t(t)&&(t=this.columns());const e=[];for(const n of this._matrixInstance){const s=n._value.splice(t,1);e.push(s[0])}const r=new Xt(0,void 0,this._errorListener);return r._value=e,r}remove_row({row:t}={}){return _t(t)&&(t=this.rows()),this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new Zf(new Gf(this._matrixArray)),e=new Xt(0,void 0,this._errorListener);return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0)return!1;return!0}is_identity(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0||n===s&&r[n][s]!==1)return!1;return!0}eigenvectors(){const t=new Zf(new Gf(this._matrixArray));return this._newMatrix(t.eigenvectorMatrix.to2DArray())}is_symmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=n+1;s<e;s++)if(r[n][s]!==r[s][n])return!1;return!0}swap_columns({column1:t,column2:e}){if(!(_t(t)||_t(e)))for(const r of this._matrixInstance){const n=r._value[t],s=r._value[e];r.set({index:t,value:s}),r.set({index:e,value:n})}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return Gv(this._matrixArray)}is_antidiagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n+s!==t-1&&r[n][s]!==0)return!1;return!0}is_antisymmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n!==s&&r[n][s]!==-r[s][n])return!1;return!0}_isUpperTriangular(t){const e=this._matrixArray;for(let r=1;r<t;r++)for(let n=0;n<r;n++)if(e[r][n]!==0)return!1;return!0}_isLowerTriangular(t){const e=this._matrixArray;for(let r=0;r<t-1;r++)for(let n=r+1;n<t;n++)if(e[r][n]!==0)return!1;return!0}_newMatrix(t){const e=new La(0,0,void 0,this._errorListener);return e._value=t.map(r=>{const n=new Xt(0,void 0,this._errorListener);return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,s=[...t].map(a=>[...a]);for(let a=0;a<r&&!(a>=n);a++){let l=a;for(;l<r&&s[l][a]===0;)l++;if(l===r)continue;if(l!==a){const h=s[l];s[l]=s[a],s[a]=h}const c=s[a][a];for(let h=0;h<n;h++)s[a][h]/=c;for(let h=a+1;h<r;h++){const p=s[h][a];s[h]=s[h].map((f,d)=>f-p*s[a][d]),s[h][a]=0}}for(let a=0;a<r;a++)s[a].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class fw{constructor(t){z(this,"_variables");z(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){if(!t)return!0;const r=Qr(t),n=Qr(this._variables.timeframe.period);if(r<n)return!0;const s=`change_${e}`,a=this._cacheData[s],l=this._variables.time;if(a){if(a.offset){if(a.currentTime+a.offset<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else if(a.currentTime+r*1e3<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else{const c=this._calcTimeOffset(l,t);return this._cacheData[s]={currentTime:l,offset:c},!1}return!1}in_seconds({timeframe:t}={}){return Qr(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=Qt.duration(e);if(r.years())return"12M";const s=r.asMonths();if(Ks(s))return`${s}M`;const a=r.asWeeks();if(Ks(a))return`${a}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const c=r.asMinutes();if(c>=1)return`${Math.ceil(c)}`;const h=r.asSeconds();return h<=1?"1S":h<=5?"5S":h<=10?"10S":h<=15?"15S":h<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=Qt(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=Qt(t).date();e="1D";const c=Qt(t).daysInMonth();l!==1&&(r=(c-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),s=Qr(e)*1e3,a=t-n-Math.floor((t-n)/s)*s;return r?r-a:a}}class hw{constructor(t){z(this,"_errorListener");this._errorListener=t}pos({source:t="",str:e=""}){return t==null?void 0:t.indexOf(e)}trim({source:t=""}){return t==null?void 0:t.trim()}lower({source:t=""}){return t==null?void 0:t.toLocaleLowerCase()}match({source:t="",regex:e=""}){const r=t==null?void 0:t.match(new RegExp(e));return r?r[0]:""}split({string:t="",separator:e=""}){const r=t==null?void 0:t.split(e),n=new Xt;return n._value=r||[],n}upper({source:t=""}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t=""},e){return this._strFormat(t,e)}length({string:t=""}){return t==null?void 0:t.length}repeat({source:t="",repeat:e,separator:r=""},n){if(_t(e)){this._errorListener.addError("Invalid array length",n,Ee.Error);return}return Array.from(new Array(e),()=>t).join(r)}replace({source:t="",target:e="",replacement:r="",occurrence:n}){_t(n)&&(n=0);let s=-1;for(let a=0;a<n+1&&(s=t.indexOf(e,s+1),s!==-1);a++);return s!==-1?t.substring(0,s)+r+t.substring(s+e.length):t}contains({source:t="",str:e=""}){return t==null?void 0:t.includes(e)}endswith({source:t="",str:e=""}){return t==null?void 0:t.endsWith(e)}tonumber({string:t=""}){if(/[^\d.]/.test(t))return;const e=parseFloat(t);return isNaN(e)?void 0:e}tostring({value:t,format:e}){if(t===void 0)return"NaN";if(typeof t=="object"){if(t.isArray)return this._arrToStr(t._value,e);if(t.isMatrix){const r=[];for(const n of t._matrixArray)r.push(this._arrToStr(n,e));return r.join(`
|
62
|
-
`)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return this._formatNumber(t,e)}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._formatNumber(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),Tr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_formatNumber(t,e){if(!e)return t;switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:const r=e.split(".")[1],n=r?r.length:0;return parseFloat(t.toFixed(n))}}_strFormat(t,e){let r=t;return e.forEach((n,s)=>{if(typeof n=="number"){const a=`\\{\\s*${s}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,c)))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n)}),r}}class pw{constructor(t){z(this,"_errorListener");this._errorListener=t}new(){return new Ra(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Ra{constructor(t){z(this,"_errorListener");z(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Ra(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Xt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Xt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class dw{constructor(t){z(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Gn(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Gn(t,r,e)}copy({id:t}){const{price:e,time:r,index:n}=t||{};return new Gn(e,n,r)}from_index({price:t,index:e}){return new Gn(t,e)}from_time({price:t,time:e}){return new Gn(t,void 0,e)}}class Gn{constructor(t,e,r){z(this,"_index");z(this,"_price");z(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new Gn(this._price,this._index,this._time)}}class _w{constructor(t){z(this,"_variables");z(this,"_defaultLabel",{text:"",xloc:$e.bar_index,yloc:ki.price,size:Yr.normal,style:ge.styleLabelDown,textalign:Je.alignCenter});this._variables=t}new(t,e){const r=`label_${e}`,n={...this._defaultLabel,...t,id:r};t.point&&(n.x=n.xloc===$e.bar_index?t.point.index:t.point.time,n.y=t.point.price);const s=new Xi(r,this._variables);return this._variables.label.add(r,n,s),s}label(t,e){return t.x?t.x:new Xi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class Xi{constructor(t,e){z(this,"_id");z(this,"_variables");this._id=t,this._variables=e}copy(t){const e=`label_${t}`,r=this._getLabel(t),n=new Xi(e,this._variables);return r&&this._variables.label.add(e,{...r,id:e},n),n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t)}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e)}set_yloc({yloc:t},e){const r=this._getLabel(e);r&&(r.yloc=t)}set_color({color:t},e){const r=this._getLabel(e);r&&(r.color=t)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===$e.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t)}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t)}set_textcolor({textcolor:t},e){const r=this._getLabel(e);r&&(r.textcolor=t)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const mw={freq_all:_n.freqAll,freq_once_per_bar:_n.freqOncePerBar,freq_once_per_bar_close:_n.freqOncePerBarClose},gw={gaps_off:qi.gapsOff,gaps_on:qi.gapsOn,lookahead_off:qi.lookaheadOff,lookahead_on:qi.lookaheadOn},yi={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"},Kf={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"},vw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},ww={all:[sr.dataWindow,sr.pane,sr.priceScale,sr.statusLine],data_window:[sr.dataWindow],none:[],pane:[sr.pane],price_scale:[sr.priceScale],status_line:[sr.statusLine]},yw={both:Pn.both,left:Pn.left,none:Pn.none,right:Pn.right},Dw={inherit:zn.inherit,mintick:zn.mintick,percent:zn.percent,price:zn.price,volume:zn.volume},bw={style_solid:ws.styleSolid,style_dashed:ws.styleDashed,style_dotted:ws.styleDotted},Ew={style_arrowdown:ge.styleArrowdown,style_arrowup:ge.styleArrowup,style_circle:ge.styleCircle,style_cross:ge.styleCross,style_diamond:ge.styleDiamond,style_flag:ge.styleFlag,style_label_center:ge.styleLabelCenter,style_label_down:ge.styleLabelDown,style_label_left:ge.styleLabelLeft,style_label_lower_left:ge.styleLabelLowerLeft,style_label_lower_right:ge.styleLabelLowerRight,style_label_right:ge.styleLabelRight,style_label_up:ge.styleLabelUp,style_label_upper_left:ge.styleLabelUpperLeft,style_label_upper_right:ge.styleLabelUpperRight,style_none:ge.styleNone,style_square:ge.styleSquare,style_text_outline:ge.styleTextOutline,style_triangledown:ge.styleTriangledown,style_triangleup:ge.styleTriangleup,style_xcross:ge.styleXcross},xw={style_arrow_both:jr.styleArrowBoth,style_arrow_left:jr.styleArrowLeft,style_arrow_right:jr.styleArrowRight,style_dashed:jr.styleDashed,style_dotted:jr.styleDotted,style_solid:jr.styleSolid},Aw={abovebar:oi.abovebar,absolute:oi.absolute,belowbar:oi.belowbar,bottom:oi.bottom,top:oi.top},Cw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Fw={style_area:wr.styleArea,style_areabr:wr.styleAreabr,style_circles:wr.styleCircles,style_columns:wr.styleColumns,style_cross:wr.styleCross,style_histogram:wr.styleHistogram,style_line:wr.styleLine,style_linebr:wr.styleLinebr,style_stepline:wr.styleStepline,style_stepline_diamond:wr.styleSteplineDiamond,style_steplinebr:wr.styleSteplinebr},Mw={bottom_center:Or.bottomCenter,bottom_left:Or.bottomLeft,bottom_right:Or.bottomRight,middle_center:Or.middleCenter,middle_left:Or.middleLeft,middle_right:Or.middleRight,top_center:Or.topCenter,top_left:Or.topLeft,top_right:Or.topRight},Nw={left:ys.left,none:ys.none,right:ys.right},Sw={arrowdown:or.arrowdown,arrowup:or.arrowup,circle:or.circle,cross:or.cross,diamond:or.diamond,flag:or.flag,labeldown:or.labeldown,labelup:or.labelup,square:or.square,triangledown:or.triangledown,triangleup:or.triangleup,xcross:or.xcross},Bw={auto:Yr.auto,huge:Yr.huge,large:Yr.large,normal:Yr.normal,small:Yr.small,tiny:Yr.tiny},Tw={cash:Ge.cash,fixed:Ge.fixed,percent_of_equity:Ge.percentOfEquity,commission:{cash_per_contract:Ir.cashPerContract,cash_per_order:Ir.cashPerOrder,percent:Ir.percent},direction:{all:pe.all,long:pe.long,short:pe.short},oca:{cancel:kn.cancel,none:kn.none,reduce:kn.reduce}},Ow={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},Iw={bar_index:$e.bar_index,bar_time:$e.bar_time},$w={abovebar:ki.abovebar,belowbar:ki.belowbar,price:ki.price},Lw={actual:Ds.actual,estimate:Ds.estimate,standardized:Ds.standardized};class Rw{constructor(){z(this,"adjustment",{dividends:vs.dividends,none:vs.none,splits:vs.splits});z(this,"alert",mw);z(this,"barmerge",gw);z(this,"color",yi);z(this,"currency",Kf);z(this,"dayofweek",vw);z(this,"earnings",Lw);z(this,"display",ww);z(this,"extend",yw);z(this,"font",{family_default:"SimSun",family_monospace:"Monospace"});z(this,"format",Dw);z(this,"hline",bw);z(this,"label",Ew);z(this,"line",xw);z(this,"location",Aw);z(this,"math",Cw);z(this,"order",{ascending:qn.ascending,descending:qn.descending});z(this,"plot",Fw);z(this,"position",Mw);z(this,"scale",Nw);z(this,"session",{extended:ia.extended,regular:ia.regular});z(this,"shape",Sw);z(this,"size",Bw);z(this,"splits",{denominator:"denominator",numerator:"numerator"});z(this,"strategy",Tw);z(this,"text",Ow);z(this,"xloc",Iw);z(this,"yloc",$w)}updateData(){}}class Pw{constructor(t){z(this,"_variables");z(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:$e.bar_index,line_color:yi.blue,line_style:jr.styleSolid,line_width:1});this._variables=t}new(t,e){const r=`polyline_${e}`,n=Object.assign({},this._defaultPolyline,t,{id:r}),s=new Hf(r,this._variables);return this._variables.polyline.add(r,n,s),s}delete({id:t}){t&&t.delete()}}class Hf{constructor(t,e){z(this,"_id");z(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class zw{constructor(t){z(this,"_variables");z(this,"_defaultLine",{xloc:$e.bar_index,extend:Pn.none,style:jr.styleSolid});this._variables=t}new({first_point:t,second_point:e,...r},n){const s=`line_${n}`,a={...this._defaultLine,...r,id:s};if(t&&e){const c=a.xloc===$e.bar_index?t.index:t.time,h=a.xloc===$e.bar_index?e.index:e.time;Object.assign(a,{x1:c,y1:t.price,x2:h,y2:e.price})}const l=new Ji(s,this._variables);return this._variables.line.add(s,a,l),l}line(t,e){return t.x?t.x:new Ji(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class Ji{constructor(t,e){z(this,"_variables");z(this,"_id");this._id=t,this._variables=e}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}`,r=this._getLine(t),n=new Ji(e,this._variables);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===$e.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r)}set_color({color:t},e){const r=this._getLine(e);r&&(r.color=t)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t)}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t)}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===$e.bar_index?n:s,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===$e.bar_index?n:s,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class qw{constructor(t){z(this,"_variables");this._variables=t}new({line1:t,line2:e,color:r},n){const s=`linefill_${n}`,a=t==null?void 0:t.data,l=e==null?void 0:e.data;a&&(a.linefills=a.linefills||[],a.linefills.push(s)),l&&(l.linefills=l.linefills||[],l.linefills.push(s));const c=new so(this._variables,s,t,e);return(a||l)&&this._variables.linefill.add(s,{line1:a,line2:l,color:r,id:s},c),c}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class so{constructor(t,e,r,n){z(this,"_id");z(this,"_line1");z(this,"_line2");z(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new so(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.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:t}){const e=this._variables.linefill.get(this._id);e&&(e.color=t)}}class kw{constructor(t){z(this,"_variables");z(this,"_defaultBox",{border_color:yi.blue,border_width:1,bgcolor:yi.blue,xloc:$e.bar_index,extend:Pn.none,style:jr.styleSolid,text:"",text_size:Yr.auto,text_color:yi.black,text_halign:Je.alignCenter,text_valign:Je.alignCenter,text_wrap:Je.wrapNone});this._variables=t}box({x:t},e){return t===void 0?new Qi(this._variables,e):t}new({top_left:t,bottom_right:e,...r},n){const s=`box_${n}`,a={...this._defaultBox,...r,id:s};if(t){const{price:c,time:h,index:p}=t;a.top=c,a.left=a.xloc===$e.bar_index?p:h}if(e){const{price:c,time:h,index:p}=e;a.bottom=c,a.right=a.xloc===$e.bar_index?p:h}const l=new Qi(this._variables,s);return this._variables.box.add(s,a,l),l}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e}){t==null||t.set_extend(e)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e}){t==null||t.set_border_style(e)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e}){t==null||t.set_text_size(e)}set_text_wrap({id:t,...e}){t==null||t.set_text_wrap(e)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e}){t==null||t.set_text_halign(e)}set_text_valign({id:t,...e}){t==null||t.set_text_valign(e)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e}){t==null||t.set_text_font_family(e)}}class Qi{constructor(t,e){z(this,"_id");z(this,"_variables");this._variables=t,this._id=e}copy(t){const e=`box_${t}`,r=this._getBox(),n=new Qi(this._variables,e);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t}){const e=this._getBox();e&&(e.extend=t)}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t)}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t}){const e=this._getBox();e&&(e.text_size=t)}set_text_wrap({text_wrap:t}){const e=this._getBox();e&&(e.text_wrap=t)}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t)}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t}){const e=this._getBox();e&&(e.text_halign=t)}set_text_valign({text_valign:t}){const e=this._getBox();e&&(e.text_valign=t)}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===$e.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t)}set_border_style({style:t}){const e=this._getBox();e&&(e.border_style=t)}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===$e.bar_index?r:s}}set_text_font_family({text_font_family:t}){const e=this._getBox();e&&(e.text_font_family=t)}_getBox(){return this._variables.box.get(this._id)}}class Uw{constructor(t){z(this,"_variables");z(this,"_defaultTable",{position:Or.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t}table({x:t},e){return t||new Pa(this._variables,e)}new(t,e){const r=`table_${e}`,n={...this._defaultTable,...t,cell:[],id:r},s=new Pa(this._variables,r);return this._variables.table.add(r,n,s),s}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e}){t==null||t.set_position(e)}}class Pa{constructor(t,e){z(this,"_id");z(this,"_variables");z(this,"_defaultCell",{column:0,row:0,text:"",text_color:yi.black,text_halign:Je.alignCenter,text_valign:Je.alignCenter,text_size:Yr.normal});this._variables=t,this._id=e}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r)}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){console.log(`error ${s}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(t,e);if(!a)return;this.clear({start_column:t,start_row:e,end_column:r,end_row:n});const l=this._variables.table.get(this._id);l.cell[e][t]={...a,isMerge:!0,merge_columns:r-t+1,merge_rows:n-e+1}}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t)}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t)}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t}){const e=this._variables.table.get(this._id);e&&(e.position=t)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Ww{constructor(t){z(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===pe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class jw{constructor(t){z(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===pe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class Yw{constructor(t){z(this,"_strategy");this._strategy=t}allow_entry_in({value:t}){this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e}){e===Ge.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e}){e===Ge.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}}let Zw=class{constructor(t,e,r,n){z(this,"_variables");z(this,"_options");z(this,"_totalChangeCapital");z(this,"_historyOrder");z(this,"_orders");z(this,"_pendingOrders");z(this,"_mintick");z(this,"_funcOptions");z(this,"_pendingCloseOrders");z(this,"_errorListener");z(this,"_risk");z(this,"_opentrades");z(this,"_closedtrades");z(this,"_riskNamespace");this._variables=t,this._errorListener=n,this._options={overlay:!1,format:zn.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:Ge.fixed,default_qty_value:1,initial_capital:1e6,currency:Kf.NONE,slippage:0,commission_type:Ir.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=e,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 jw(this),this._closedtrades=new Ww(this),this._riskNamespace=new Yw(this)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((t,e)=>t+(e.profit||0),0)}get _freezeCapital(){const{close:t}=this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(t){Object.assign(this._options,t),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{high:n,low:s,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:h}}=this._variables;let{preNetprofit:p=0}=this._risk;l===a&&(p=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=p-c;f+=this._orders.reduce((w,m)=>{const{in_price:D,direction:v,qty:E=0,commission:b=0,original_qty:N=0}=m,x=v===pe.long?1:-1,F=(n-D)*E,M=(s-D)*E,S=x===1?-M:F;return w+S+E/N*b},0);let d=!1;switch(e){case Ge.cash:d=t<f;break;case Ge.percentOfEquity:const w=f/(h+c)*100;d=t<w;break}if(d){this._risk.isTemporaryBan=!0;const w=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,w===pe.long?s:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:s,open:a}=this._variables;n===s&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(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:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:s,time_tradingday:a,strategy:l,open:c}=this._variables;let h=e;if(s===a){const p=l.netprofit+l.openprofit;p<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:p})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(!r&&t!==void 0&&e){const{max_drawdown:s,max_drawdown_percent:a}=this._variables.strategy;let l=!1;switch(e){case Ge.percentOfEquity:l=a<s;break;case Ge.cash:l=t<s;break}if(l){const{high:c,low:h}=this._variables,p=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(p===pe.long?c:h,"Close Position (Max Drawdown)")}}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,t,e),this._pendingOrders=[]}strategy(t){this._options={...t},Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"})}order(t){this._risk.isDisabledOpen||this._orderHandle(t)}entry(t){this._risk.isDisabledOpen||this._entryHandle(t)}close(t){if(!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close"}):this._pendingOrders.push({...t,place_order_type:"close"})}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Ge.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(e){case Ge.fixed:return r;case Ge.cash:return r/t;case Ge.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/t}}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{high:t,low:e,close:r}=this._variables;for(const n of this._orders){const{in_price:s,qty:a=0,direction:l}=n,c=l===pe.long?1:-1,h=(r-s)*c*a,p=(t-s)*a,f=(e-s)*a,d=c===1?p:-f,g=c===1?-f:p;this._calcOrderPercent(n,h,d,g)}}_calcOrderPercent(t,e,r,n){const{commission_value:s}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:p=0,trading_loss:f=0}=t;let{commission:d=0}=t;const g=h*c;if(s){const w=this._getCommission(a,c);e=e-w,d=d*c/l,r-=d,n+=d}r=Math.max(r,p),n=Math.min(n,f),Object.assign(t,{profit:e-d,total_profit:this._totalChangeCapital+e,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:t,low:e}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:s=0,commission_value:a=0}=this._options,l=this._orders[0].direction===pe.long?1:-1,c=l===1?e:t,h=(l===1?n:s)/100;if(h<=0)return;const[p,f,d]=this._orders.reduce((v,E)=>{let[b,N,x]=v;const{in_price:F,qty:M=0,original_qty:S=0,commission:I=0}=E,C=F*M,T=c*M;if(b+=C,N+=T,a){const L=this._getCommission(c,M);x+=L+M/S*I}return[b,N,x]},[0,0,0]),g=l*(f-p),m=r+this._totalChangeCapital+g-d-f*h;if(m>=0)return;const D=Math.trunc(m/h/c)*4;this._marginCallOrders(c,D,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r);return}for(const s of this.orders)this._processOrder(s,t,e,r,r);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:a,close:l,price:c,activePrice:h}=this._orderArgsParse(t),p=t.direction===pe.long?1:-1;if(a<=0)return;let f=a;if(s&&e){if(n.length){const m=this._processOrders(n,l,f,t.id,t.comment);if(m<=0)return;f=m}const g=l+p*r*this._mintick;if(!this._judgeCapitalEnough(f,g,p))return;this._ocaGroupVerify(f,t.oca_name,t.oca_type),this._calcCurrentOrder({...t,in_price:g,in_index:this._variables.bar_index,in_time:this._variables.time,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,p)&&this._addPendingOrders(t,c,f,s,h)}_judgeCapitalEnough(t,e,r){if(t<=0)return!1;const{margin_long:n=0,margin_short:s=0}=this._options;if((n===0||n===100)&&r===1||s===0&&r===-1)return!0;const l=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return t*e<=l}_ocaGroupVerify(t,e,r){if(!e||!r||r===kn.none)return!1;let n=!1;switch(r){case kn.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)s.isCancel=!0,n=!0;else return!0});break;case kn.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:a=0,oca_name:l}=s;if(e===l){const c=a-t;return n=!0,c<=0?(s.isCancel=!0,!1):(s.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,s){let a=r;for(const l of t)if(a=this._processOrder(l,e,a,n,s),a<=0)break;return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(t,e,r,n,s){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:a}=this._variables;let l=a,c=!1,h;const p=e===pe.long?1:-1,f=n&&(n-a)*p>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&s&&(s-=d*this._mintick*p);const g=s&&(s-a)*p<0;f&&g?(h=n,l=s):f?l=n:g?l=s:c=!0;const w=r||this._calcDefaultQty(l)||1;return{orders:this._orders.filter(D=>D.direction!==e),isMarketPrice:c,activePrice:h,quantities:w,close:a,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:a,price:l,activePrice:c}=this._orderArgsParse(t);if(s<=0)return;if(r.length&&n&&e){this._entryOrder(r,a,s,t);return}this._judgeCapitalEnough(s,a,t.direction===pe.long?1:-1)&&this._addPendingEntry(t,l,s,n,c)}_entryOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{oca_name:c,oca_type:h,direction:p,comment:f,isMarketPrice:d,id:g}=n,w=p===pe.long?1:-1;if(this._closeOrders(t,e,g,f),r=this._getAvailablePositionSize(r,p),r<=0)return;e=e+l*this._mintick*w;const m={...n,in_price:e,original_qty:r,qty:r,in_index:a,in_time:s,place_order_type:"entry"};if(d){this._calcCurrentOrder(m);return}const{pendingOrders:D,orders:v}=this._getEntryOrders(p),E=D.length+v.length;E&&E>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,e,w)||(this._ocaGroupVerify(r,c,h),this._calcCurrentOrder(m))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==pe.all&&n!==e)return 0;if(r===void 0)return t;const s=this._orders.reduce((a,l)=>a+(l.qty||0),0);return s?s+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(p=>p.id===t.id&&p.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else if(!c||c<(this._options.pyramiding||1)){const p={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"entry"};this._pendingOrders.push(p)}}_closeAllOrders(t,e){const{comment:r}=t,{bar_index:n}=this._variables,s=this._orders.filter(a=>a.in_index!==n);s.length&&(this._closeOrders(s,e,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n){for(const s of t)this._closeOrder(s,e,r,n);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{in_price:c,qty:h=0,direction:p}=t,f=p===pe.long?1:-1;e=e-f*l*this._mintick,t.isDeal=!0;const d=(e-c)*f*h,g={...t,out_price:e,out_id:r,out_index:a,out_time:s,out_comment:n,out_qty:h,profit:d};this._calcPercent(g),this._risk.intradayOrders+=1,this._historyOrder.push(g),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const t=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!t.length)return;const{open:e,low:r,high:n,close:s}=this._variables;for(const a of t){const{stop:l,limit:c,trail_stop_price:h,isMarketPriceLimit:p,isMarketPriceStop:f,direction:d,id:g,out_comment:w,active_price:m,trail_offset:D=0,out_qty:v,comment_loss:E,comment_profit:b,comment_trailing:N}=a;let x=h;const F=d===pe.long?1:-1;let M,S=w;if(p||f?M=e:(c&&r<=c&&n>=c&&(S=b||w,M=c),l&&r<=l&&n>=l&&(M=x?(l-x)*F>0?l:x:l,S=(x===M?N:E)||w)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let I=!1;if(m&&m<=n&&m>=r&&(x=m-D*F*this._mintick,(x-s)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=x)),I=!0,a.trail_stop_price=x),x)if((x-e)*F>=0&&!I)M=x;else{const C=(F===1?n:r)-D*F*this._mintick;F===1?x<e&&x>=r&&C>x&&C<s?M=x:C>x?(x=C,C>=s&&(M=C)):x<=n&&r<=x&&(M=x):x>e&&x<=n&&C<x&&C>s?M=x:C<x?(x=C,C<=s&&(M=C)):x<=n&&r<=x&&(M=x),a.trail_stop_price=x}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||w,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=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:s,place_order_type:a}=n;if(s)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of e){const s=this._exitOrderHandle(n);s&&t.push(s)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),e=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of e)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of t){const{from_entry:s}=n,a=this._orders.filter(l=>!s||l.id===s&&(l.isMarketPriceLimit||l.isMarketPriceStop));for(const l of a)this._processExitOnClose(l,l.limit||l.stop||l.trail_stop_price||r,n)}this._pendingCloseOrders=[]}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:s,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let p=l;if(s&&(p=e),p<=n&&p>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,p,a,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:p,direction:f,comment:d,oca_name:g,oca_type:w,active_price:m,id:D}=t;if(m&&n>=m&&r<=m)return delete t.active_price,t;let v=p,E=h;if(c&&(v=e),v<=n&&v>=r){const b=this._orders.filter(x=>x.direction!==f);if(b.length&&(E=this._processOrders(b,v,h,D,d),E<=0))return;const N=f===pe.long?1:-1;this._ocaGroupVerify(E,g,w),this._calcCurrentOrder({...t,in_price:v+N*l*this._mintick,in_index:a,in_time:s,qty:E});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:a}=t,{bar_index:l}=this._variables,c=this._orders.filter(g=>g.id===r&&g.in_index!==l&&(!g.close_qty||g.close_qty<(g.qty||0)));if(!c.length)return;let h=0;if(n?h=n:(h=c.reduce((g,w)=>g+(w.qty||0),h),h=s/100*h),h<=0)return;const{open:p,close:f}=this._variables;let d=h;for(const g of c){const{qty:w=0}=g;d<w?g.close_qty=d:(g.close_qty=w,d-=w)}this._processOrders(this._options.close_entries_rule==="ANY"?c:this._orders,e?f:p,h,`Close entry(s) order ${r}`,a)}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t)))return t}_exit(t,e){const{profit:r,loss:n,stop:s,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:p="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c))){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'",e,Ee.Error);return}const d={...t,place_order_type:"exit"},g=this._orders.filter(D=>(!p||p===D.id)&&!D.hasExit),w=this._pendingOrders.filter(D=>!p||p===D.id);if(g.length){if(!this._ordersToExit(g,d))return}else if(!w.length)return;const m=this._pendingOrders.find(D=>D.id===f);m?Object.assign(m,{...t}):this._pendingOrders.push(d)}_ordersToExit(t,e){const{qty:r,qty_percent:n=100,id:s,comment:a,comment_loss:l,comment_profit:c,comment_trailing:h}=e;let p=r,f=!1;e.comment=a||s;for(const d of t){const{qty:g=0}=d,w=d.direction===pe.long?1:-1;p=r?r>=g?g:r:n/100*g,d.out_qty=p,p<g&&(f=!0),Object.assign(d,{out_comment:a||s,comment_loss:l,comment_profit:c,comment_trailing:h}),!(this._stopProfit(d,w,{...e,qty:p})||this._stopLoss(d,w,{...e,qty:p})||this._trailStopLoss(d,w,{...e,qty:p}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(t){t.place_order_type="exit";const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r){const{limit:n,profit:s,comment_profit:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(c=p+e*s*this._mintick),t.limit=c,c&&(c-h)*e<=0&&(t.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r){const{stop:n,loss:s,comment_loss:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(c=p-e*s*this._mintick),t.stop=c,c&&(c-h)*e>=0&&(t.isMarketPriceStop=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:s,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(s)?this._isNaN(a)||(d=p+a*e*this._mintick):d=s,t.trail_offset=n,d&&(d-h)*e<=0){const g=h-n*e*this._mintick;if((g-h)*e>=0&&(t.trail_stop_price=h,t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;t.trail_stop_price=g}t.active_price=d}}_processExitOnClose(t,e,r){const{qty:n=0,comment:s,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO"){const c=this._processExitOrders(this._orders,e,n,a,s);c&&!c.hasExit?(c.hasExit=!0,Object.assign(t,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,a,s)}_processExitOrders(t,e,r,n,s){let a=r,l;for(const c of t)if(l=c,a=this._processOrder(c,e,a,n,s),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),l}_processOrder(t,e,r,n,s){const{time:a,bar_index:l}=this._variables,{slippage:c=0}=this._options,{in_price:h,qty:p=0,max_profit:f=0,trading_loss:d=0,direction:g,commission:w=0,original_qty:m=0}=t,D=g===pe.long?1:-1;if(e=e-D*c*this._mintick,r<p){const v=p-r,E=(e-h)*D*r,b=f/p*r,N=d/p*r;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:s,profit:E,out_qty:r,max_profit:b,trading_loss:N});const x=(e-h)*D*v-w*v/m;Object.assign(t,{qty:v,profit:x,max_profit:f-b,trading_loss:d-N,total_profit:this._totalChangeCapital+x}),r=0}else{t.isDeal=!0;const v=(e-h)*D*p;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:s,out_qty:p,profit:v}),r-=p}return r}_calcPercent(t){const{commission_value:e}=this._options,{in_price:r,out_qty:n=0,out_price:s=0,original_qty:a=0}=t;let{profit:l=0,max_profit:c=0,trading_loss:h=0,commission:p=0}=t;c=c<0?0:c;const f=r*n;if(this._totalChangeCapital+=l,e){const d=this._getCommission(s,n);this._totalChangeCapital-=d,p=p*n/a+d,l=l-p,Object.assign(t,{commission:p,profit:l,max_profit:c})}Object.assign(t,{total_profit:this._totalChangeCapital,profit_percent:l/f*100,max_profit_percent:c/f*100,trading_loss_percent:h/f*100}),this._risk.intradayOrders+=1,this._historyOrder.push(t),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case Ir.percent:a=s*r/100;break;case Ir.cashPerContract:a=e*r;break;case Ir.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:s=0,trading_loss:a=0}=t;let{profit:l=0}=t;const c=r*n;if(e){const h=this._getCommission(r,n);this._totalChangeCapital-=h,l=l-h,Object.assign(t,{commission:h,profit:l,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,profit_percent:l/c*100,max_profit_percent:s/c*100,trading_loss_percent:a/c*100}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders)}_isNaN(t){return t===void 0||isNaN(t)}};class Gw{constructor(t){z(this,"_logs");z(this,"_variables");z(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e){this._addLog(t,e,"info")}error(t,e){this._addLog(t,e,"error")}warning(t,e){this._addLog(t,e,"warning")}_addLog(t,e,r){const{message:n,formatString:s}=t,{time:a,bar_index:l,precision:c}=this._variables;let h=n;s&&Array.isArray(e)&&e.length&&(h=s.replace(/{(\d+)}/g,(p,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(c)))),d!==void 0?d:p})),h&&this._logs.push({message:`[${Qt(a).format()}]: ${h}`,time:a,barIndex:l,type:r})}}class Kw{constructor(t){z(this,"_errorListener");this._errorListener=t}error({message:t},e){this._errorListener.addError(t,e,Ee.Error)}}class Hw{constructor(){z(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Br.flatMap([...this._errors.values()])}addError(t,e,r){const[n,s]=e.split("_").slice(-2),a=this._errors.get(e),l={message:t,endLineNumber:Number(n),startColumn:Number(s)+1,endColumn:Number(s)+1,startLineNumber:Number(n),type:r};a?a.push(l):this._errors.set(e,[l])}}class Xw{constructor(){z(this,"_isMarketOpen");z(this,"_currentBarIndex");z(this,"_totalBarIndex");z(this,"_isRealTimeBar");z(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1:this._currentBarIndex===this._totalBarIndex}}class Jw{constructor(t){z(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class Qw{constructor(t){z(this,"_orders");z(this,"_historyOrders");z(this,"_options");z(this,"_max_contracts_held_all",0);z(this,"_max_contracts_held_long",0);z(this,"_max_contracts_held_short",0);z(this,"_max_drawdown",0);z(this,"_max_runup",0);z(this,"_max_runup_percent",0);z(this,"_max_drawdown_percent",0);z(this,"_variables");z(this,"_netprofit",0);z(this,"_eventrades",0);z(this,"_avg_trade_percent");z(this,"_closedtrades",0);z(this,"_losstrades",0);z(this,"_grossloss",0);z(this,"_grossloss_percent",0);z(this,"_grossprofit",0);z(this,"_grossprofit_percent",0);z(this,"_wintrades",0);z(this,"_opentrades_capital_held",0);z(this,"_position_avg_price",0);z(this,"_position_size",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){let t=0,e=0;const{high:r,low:n}=this._variables;for(const h of this._orders){const{in_price:p,qty:f=0,commission:d=0,original_qty:g=0,direction:w}=h,m=w===pe.long?1:-1,D=(r-p)*f,v=(n-p)*f,E=m===1?D:-v,b=m===1?-v:D;t+=b+d*f/g,e+=E+d*f/g}const[s,a]=this._historyOrders.reduce((h,p)=>{let[f,d]=h;const{profit:g=0,commission:w=0}=p;return f+=g,d+=g-w,[f,d]},[0,0]);t-=s,e+=a;const l=t/(this.initial_capital+this.netprofit)*100;this._max_drawdown<t&&(this._max_drawdown=t),l>this._max_drawdown_percent&&(this._max_drawdown_percent=l);const c=e/(this.initial_capital+this.netprofit)*100;e>this._max_runup&&(this._max_runup=e),c>this._max_runup_percent&&(this._max_runup_percent=c)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t)return;const[e,r,n,s,a,l]=this._orders.reduce(([c,h,p,f,d,g],w)=>{const{direction:m,qty:D=0,in_price:v}=w;return m===pe.long?(c+=D,h+=D,g+=D):(c+=D,p+=D,g-=D),f+=D*v,d+=v,[c,h,p,f,d,g]},[0,0,0,0,0,0]);this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a,l,c]=this._historyOrders.reduce((h,p)=>{let[f,d,g,w,m,D]=h;const{profit:v=0,profit_percent:E=0}=p;return f+=v,d+=E,v<0?(g+=v,w+=E):(m+=v,D+=E),[f,d,g,w,m,D]},[0,0,0,0,0,0]);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r,this._grossloss=s,this._grossloss_percent=a,this._grossprofit=l,this._grossprofit_percent=c,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this.losstrades;return t?Math.abs(this.grossloss/t):void 0}get avg_losing_trade_percent(){const t=this.losstrades;return t?Math.abs(this.grossloss_percent/t):void 0}get avg_trade(){if(this.closedtrades)return Math.abs(this.netprofit/this.closedtrades)}get equity(){return this.initial_capital+this.netprofit+this.openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._orders.reduce((t,e)=>{const{profit:r=0}=e;return t+r},0)}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this.wintrades;return t?Math.abs(this.grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this.wintrades;return t?Math.abs(this.grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss_percent}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit_percent}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===pe.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,p]=this._orders.reduce((f,d)=>{let[g,w]=f;const{in_price:m,qty:D=0,original_qty:v=0}=d,E=m*D;if(g+=E,s){let b=0;switch(n){case Ir.percent:b=(E+D*c)*s/100;break;case Ir.cashPerContract:b=D*s*2;break;case Ir.cashPerOrder:b=D/v*s+s;break}w+=b}return[g,w]},[0,0]);return(h-(t+this.netprofit-p))*a/this.position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this.netprofit/this.initial_capital*100}get openprofit_percent(){return this.openprofit/(this.initial_capital+this.netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}}class Vw{constructor(){z(this,"_preAccdist");z(this,"_preNvi");z(this,"_prePvi");z(this,"_preObv");z(this,"_prePvt");z(this,"_preWad");z(this,"_preVwap");z(this,"_preValue");z(this,"_currentData");z(this,"_preData");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={}}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(self.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin")&&(s=!0,r=n=0),!s)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:s});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class ty{constructor(){z(this,"_period");z(this,"_multiplier");z(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=gs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}Qt.extend($p),Qt.extend(Fl),Qt.extend(Op);class ey{constructor(){z(this,"_cacheData");z(this,"_barIndex");z(this,"_isRealTimeBar");z(this,"_barstate");z(this,"_priceVariables");z(this,"_lastBarIndex");z(this,"_currentBarTime");z(this,"_lastBarTime");z(this,"_period");z(this,"_offsetTime");z(this,"_timeframe");z(this,"_ta");z(this,"_polyline");z(this,"_label");z(this,"_line");z(this,"_linefill");z(this,"_box");z(this,"_table");z(this,"_strategy");z(this,"_precision");z(this,"_session");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new Xw,this._timeframe=new ty,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Vw,this._polyline=new Di,this._label=new Di,this._line=new Di,this._linefill=new Di,this._box=new Di,this._table=new Di,this._strategy=new Qw(this),this._precision=4,this._session=new Jw(this)}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return Qt(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return Qt(this._currentBarTime).minute()}get second(){return Qt(this._currentBarTime).second()}get month(){return Qt(this._currentBarTime).month()+1}get year(){return Qt(this._currentBarTime).year()}get dayofweek(){return Qt(this._currentBarTime).day()+1}get dayofmonth(){return Qt(this._currentBarTime).date()}get weekofyear(){return Qt(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=gs(this._period);return this._isRealTimeBar?void 0:Qt(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get precision(){return this._precision}getTimeTradingday(t,e){const[r,n]=gs(e),s=Qt(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,lastBarIndex:c,time:h,lastBarTime:p,period:f="1D",offsetTime:d=5,precision:g=4}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(s),low:Number(a),volume:Number(l)},e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._precision=g,this._currentBarTime=h*1e3,this._lastBarIndex=c,this._barIndex=e,this._lastBarTime=p*1e3,this._period=f,this._offsetTime=d,this._timeframe.update(f),this._barstate.update(e,c,!1,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){let n=this._cacheData[t]||[];n[this._barIndex]=r,n=n.filter(()=>!0);const s=n[n.length-1-e];return this._cacheData[t]=n,s}setCacheData(t,e){const r=this._cacheData[t]||[];r[this._barIndex]=e,this._cacheData[t]=r}getTypeInstance(t,e){return new Np(t,e)}getVarValue(t,e,r){const n=`${t}_${e}`,s=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(s)return s}setVarValue(t,e,r,n){const s=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=Br.cloneDeep(r);if(this._cacheData.varNewData[s]=l,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=l[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Br.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case Xi.name:case Hf.name:case Qi.name:case Pa.name:case Ji.name:case so.name:t==null||t.delete();break}}}class Di{constructor(t=50){z(this,"_all");z(this,"_allInstance");z(this,"_pseudoArrayAll");z(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Xt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r);const n=[...this._all.keys()];if(n.length>this._maxLength){const s=n.shift();s&&this.delete(s)}}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}var Xf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,c){var h=n(s),p=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(Xf);var ry=Xf.exports,ny=Zt(ry),Jf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){return function(e,r,n){var s=r.prototype,a=function(d){var g,w=d.date,m=d.utc,D={};if(!((g=w)===null||g instanceof Date||g instanceof Array||s.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var v=m?n.utc():n();Object.keys(w).forEach(function(I){var C,T;D[C=I,T=s.$utils().p(C),T==="date"?"day":T]=w[I]});var E=D.day||(D.year||D.month>=0?1:v.date()),b=D.year||v.year(),N=D.month>=0?D.month:D.year||D.day?0:v.month(),x=D.hour||0,F=D.minute||0,M=D.second||0,S=D.millisecond||0;return m?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return w},l=s.parse;s.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=s.set,h=s.add,p=s.subtract,f=function(d,g,w,m){m===void 0&&(m=1);var D=Object.keys(g),v=this;return D.forEach(function(E){v=d.bind(v)(g[E]*m,E)}),v};s.set=function(d,g){return g=g===void 0?d:g,d.constructor.name==="Object"?f.bind(this)(function(w,m){return c.bind(this)(m,w)},g,d):c.bind(this)(d,g)},s.add=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g):h.bind(this)(d,g)},s.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g,-1):p.bind(this)(d,g)}}})})(Jf);var iy=Jf.exports,sy=Zt(iy),Qf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|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,h=31536e6,p=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},g=function(F){return F instanceof N},w=function(F,M,S){return new N(F,S,M.$l)},m=function(F){return r.p(F)+"s"},D=function(F){return F<0},v=function(F){return D(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?D(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,I,C){var T=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return w(S*d[m(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(k){T.$d[m(k)]=S[k]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var U=L.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,C){return I+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/p),S%=p,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),I=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var T=b(C,"D"),L=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var W=b(k,"S"),P=S.negative||I.negative||T.negative||L.negative||U.negative||W.negative,K=L.format||U.format||W.format?"T":"",G=(P?"-":"")+"P"+S.format+I.format+T.format+K+L.format+U.format+W.format;return G==="P"||G==="-P"?"P0D":G},M.toJSON=function(){return this.toISOString()},M.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",C={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 I.replace(c,function(T,L){return L||String(C[T])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var I=this.$ms,C=m(S);return C==="milliseconds"?I%=1e3:I=C==="weeks"?v(I/d[C]):this.$d[C],I||0},M.add=function(S,I,C){var T;return T=I?S*d[m(I)]:g(S)?S.$ms:w(S,this).$ms,w(this.$ms+T*(C?-1:1),this)},M.subtract=function(S,I){return this.add(S,I,!0)},M.locale=function(S){var I=this.clone();return I.$l=S,I},M.clone=function(){return w(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(T,L){var U=S.locale();return w(T,{$l:U},L)},S.isDuration=g;var I=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(T,L){return g(T)?x(this,T,1):I.bind(this)(T,L)},M.prototype.subtract=function(T,L){return g(T)?x(this,T,-1):C.bind(this)(T,L)}}})})(Qf);var oy=Qf.exports,ay=Zt(oy);Qt.extend(Fl),Qt.extend(ny),Qt.extend(sy),Qt.extend(ay);class uy{constructor(t,e){z(this,"array");z(this,"color");z(this,"math");z(this,"str");z(this,"map");z(this,"matrix");z(this,"timeframe");z(this,"ta");z(this,"input");z(this,"_variables");z(this,"_cacheData");z(this,"_options");z(this,"_errorListener");z(this,"_plots");z(this,"_alerts");z(this,"_bgColors");z(this,"_hlines");z(this,"_fills");z(this,"chart");z(this,"line");z(this,"label");z(this,"polyline");z(this,"box");z(this,"table");z(this,"linefill");z(this,"log");z(this,"runtime");z(this,"strategy");this._variables=e,this._errorListener=new Hw,this.array=new Pp(this._errorListener),this.math=new zp(t,this._errorListener),this.color=new f1,this.str=new hw(this._errorListener),this.map=new pw(this._errorListener),this.timeframe=new fw(e),this.matrix=new cw(this._errorListener),this.ta=new u1(e,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 c1(e,this._errorListener),this._plots=new Map,this.chart={point:new dw(e)},this.line=new zw(e),this.label=new _w(e),this.polyline=new Pw(e),this.box=new kw(e),this.table=new Uw(e),this.linefill=new qw(e),this.log=new Gw(e),this.runtime=new Kw(this._errorListener),this.strategy=new Zw(this._variables,this._options,1e-4,this._errorListener)}get errors(){return this._errorListener.errors}get options(){const t=this.input.getInputs(),e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors).length?{...this._bgColors}:void 0,n=this._hlines.size?[...this._hlines.values()]:void 0,s=this._fills.size?[...this._fills.values()]:void 0,a=this.log.logs.length?this.log.logs:void 0;return this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders}),Object.assign(this._options,{inputs:t,plots:[...this._plots.values()],draws:this._getDraws(),alerts:e,colors:r,hlines:n,fills:s,logs:a})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}update(t){const{barIndex:e,inputs:r}=t;r&&r.length&&this.input.update(r),this.strategy.updateOptions(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)||this._errorListener.addError(Of.libraryTitleErr,e,Ee.Error),this._options.scriptType="library",this._options.library=t}}indicator(t){this._variables.bar_index||(this._options.scriptType="indicator",this._options.indicator=t)}plot(t,e){const{series:r,color:n,seriesColors:s,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,p=this._plots.get(h),f=(p==null?void 0:p.data)||[],d=r!==void 0&&isNaN(r)?void 0:r;if(f[l]={value:[c,d]},s!=null&&s.length&&(this._seriesColorHandle(t,h),Object.assign(f[l],{itemStyle:{color:n}})),!p){const g=n?[n]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h})}return{type:"plot",key:h}}plotbar(t,e){const{open:r,close:n,low:s,high:a,color:l,seriesColors:c,...h}=t,{bar_index:p}=this._variables,f=`plotbar_${e}`,d=this._plots.get(f),g=(d==null?void 0:d.data)||[],w=n!==void 0&&isNaN(n)?void 0:n,m=r!==void 0&&isNaN(r)?void 0:r,D=s!==void 0&&isNaN(s)?void 0:s,v=a!==void 0&&isNaN(a)?void 0:a,E=[m,w,D,v];if(g[p]=E,c!=null&&c.length&&(this._seriesColorHandle(t,f),g[p]={value:E,itemStyle:{color:l}}),!d){const b=l?[l]:void 0;this._plots.set(f,{editable:!0,...h,colors:b,data:g,id:f})}}plotchar(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,c=`plotchar_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotarrow(t,e){const{series:r,colorup:n,colordown:s,...a}=t,{bar_index:l}=this._variables,c=`plotarrow_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r!==void 0&&isNaN(r)?void 0:r,colorup:n,colordown:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotshape(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,c=`plotshape_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotcandle(t,e){const{wickcolor:r,bordercolor:n,color:s,close:a,open:l,low:c,high:h,...p}=t,{bar_index:f}=this._variables,d=`plotcandle_${e}`,g=this._plots.get(d),w=(g==null?void 0:g.data)||[],m=a!==void 0&&isNaN(a)?void 0:a,D=l!==void 0&&isNaN(l)?void 0:l,v=c!==void 0&&isNaN(c)?void 0:c,E=h!==void 0&&isNaN(h)?void 0:h,b=[D,m,v,E];w[f]={value:b,wickcolor:r,bordercolor:n,color:s},g||this._plots.set(d,{editable:!0,...p,data:w,id:d})}hline(t,e){const r=`hline_${e}`;return this._hlines.set(r,{linewidth:1,editable:!0,display:sr.all,...t}),{type:"hline",key:r}}fill(t,e){const r=`fill_${e}`;this._fills.set(r,{display:sr.all,editable:!0,fillgaps:!1,...t})}alert({message:t,freq:e=_n.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l].barIndex;if(e===_n.freqOncePerBar&&n===c){this._alerts.delete(l);return}const h={message:t,freq:e,id:l,type:"alert"};if(s){e!==_n.freqOncePerBarClose&&this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}if(!s&&e===_n.freqOncePerBarClose&&n===c&&a===n-1){this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t){this._setColors(t,"barcolor")}bgcolor(t){this._setColors(t,"bgcolor")}_setColors(t,e){var l,c;const{color:r,...n}=t,{bar_index:s}=this._variables,a=((l=this._bgColors[e])==null?void 0:l.colors)||[];if(!a[s]){const h=((c=this._bgColors[e])==null?void 0:c.setColors)||[];h.includes(r)||h.push(r),a[s]=r,this._bgColors[e]={...n,colors:a,setColors:h}}}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return t===void 0}fixnan({source:t},e){return t===void 0||isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!isNaN(t)?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._variables.time_close&&this._timeHandle(this._variables.time_close,s,t,e,r,n)}timestamp(t){const{dateString:e,timezone:r,year:n,month:s,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return Qt(e).utc(!/GMT|UTC/.test(e)).valueOf();let p=s-1,f=n;if(p<0){const g=Math.ceil(Math.abs(p/12));p=12*g+p,f=n-g}let d=Qt({year:f,month:p,day:a,hour:l,minute:c,second:h});return r&&(d=Tr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:t,timezone:e}){return Tr(t,e).week()}year({time:t,timezone:e}){return Tr(t,e).year()}second({time:t,timezone:e}){return Tr(t,e).second()}month({time:t,timezone:e}){return Tr(t,e).month()+1}minute({time:t,timezone:e}){return Tr(t,e).minute()}hour({time:t,timezone:e}){return Tr(t,e).hour()}dayofweek({time:t,timezone:e}){return Tr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return Tr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Qr(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0){const l=r||this._variables.timeframe.period,c=Qr(l),h=Qr(this._variables.timeframe.period);let p;if(c<=h)p=t;else{const f=`time_${e}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=t?(p=t,this._cacheData[f]={currentTime:t,offset:0}):p=d;else{const g=this._calcTimeOffset(t,l);this._cacheData[f]={currentTime:t,offset:g},p=t}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,e),g=Qt(t).format("YYYY-MM-DD"),w=p;p=void 0;for(const D of f){const[v,E]=D;if(Qt(t).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")){Qt(w).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")?p=w:p=Qt(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;p&&!d.includes(m)&&(p=void 0)}return s&&(p=p&&Tr(p,s).valueOf()),p&&p-a*h*1e3}_seriesColorHandle(t,e){var s,a;const{seriesColors:r}=t,n=this._plots.get(e);if(n&&r!=null&&r.length)for(const l of r){if((s=n.gradientColorKeys)!=null&&s.includes(l))continue;const c=t[l],h=n[`${l}s`]||[];h.includes(c)||(h.push(c),n[`${l}s`]=h,h.length>5&&(n[`${l}s`]=[],(a=n.gradientColorKeys)==null||a.push(l)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,Ee.Error);return}return h});return{timePeriods:n.split(",").map(c=>{const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,Ee.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.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",e,Ee.Error);return}return`${r}:${n}`}}/**
|
62
|
+
`)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return this._formatNumber(t,e)}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._formatNumber(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),Tr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_formatNumber(t,e){if(!e)return t;switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:const r=e.split(".")[1],n=r?r.length:0;return parseFloat(t.toFixed(n))}}_strFormat(t,e){let r=t;return e.forEach((n,s)=>{if(typeof n=="number"){const a=`\\{\\s*${s}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,c)))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n)}),r}}class pw{constructor(t){z(this,"_errorListener");this._errorListener=t}new(){return new Ra(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Ra{constructor(t){z(this,"_errorListener");z(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Ra(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Xt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Xt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class dw{constructor(t){z(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Gn(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Gn(t,r,e)}copy({id:t}){const{price:e,time:r,index:n}=t||{};return new Gn(e,n,r)}from_index({price:t,index:e}){return new Gn(t,e)}from_time({price:t,time:e}){return new Gn(t,void 0,e)}}class Gn{constructor(t,e,r){z(this,"_index");z(this,"_price");z(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new Gn(this._price,this._index,this._time)}}class _w{constructor(t){z(this,"_variables");z(this,"_defaultLabel",{text:"",xloc:$e.bar_index,yloc:ki.price,size:Yr.normal,style:ge.styleLabelDown,textalign:Je.alignCenter});this._variables=t}new(t,e){const r=`label_${e}`,n={...this._defaultLabel,...t,id:r};t.point&&(n.x=n.xloc===$e.bar_index?t.point.index:t.point.time,n.y=t.point.price);const s=new Xi(r,this._variables);return this._variables.label.add(r,n,s),s}label(t,e){return t.x?t.x:new Xi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class Xi{constructor(t,e){z(this,"_id");z(this,"_variables");this._id=t,this._variables=e}copy(t){const e=`label_${t}`,r=this._getLabel(t),n=new Xi(e,this._variables);return r&&this._variables.label.add(e,{...r,id:e},n),n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t)}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e)}set_yloc({yloc:t},e){const r=this._getLabel(e);r&&(r.yloc=t)}set_color({color:t},e){const r=this._getLabel(e);r&&(r.color=t)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===$e.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t)}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t)}set_textcolor({textcolor:t},e){const r=this._getLabel(e);r&&(r.textcolor=t)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const mw={freq_all:_n.freqAll,freq_once_per_bar:_n.freqOncePerBar,freq_once_per_bar_close:_n.freqOncePerBarClose},gw={gaps_off:qi.gapsOff,gaps_on:qi.gapsOn,lookahead_off:qi.lookaheadOff,lookahead_on:qi.lookaheadOn},yi={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"},Kf={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"},vw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},ww={all:[sr.dataWindow,sr.pane,sr.priceScale,sr.statusLine],data_window:[sr.dataWindow],none:[],pane:[sr.pane],price_scale:[sr.priceScale],status_line:[sr.statusLine]},yw={both:Pn.both,left:Pn.left,none:Pn.none,right:Pn.right},Dw={inherit:zn.inherit,mintick:zn.mintick,percent:zn.percent,price:zn.price,volume:zn.volume},bw={style_solid:ws.styleSolid,style_dashed:ws.styleDashed,style_dotted:ws.styleDotted},Ew={style_arrowdown:ge.styleArrowdown,style_arrowup:ge.styleArrowup,style_circle:ge.styleCircle,style_cross:ge.styleCross,style_diamond:ge.styleDiamond,style_flag:ge.styleFlag,style_label_center:ge.styleLabelCenter,style_label_down:ge.styleLabelDown,style_label_left:ge.styleLabelLeft,style_label_lower_left:ge.styleLabelLowerLeft,style_label_lower_right:ge.styleLabelLowerRight,style_label_right:ge.styleLabelRight,style_label_up:ge.styleLabelUp,style_label_upper_left:ge.styleLabelUpperLeft,style_label_upper_right:ge.styleLabelUpperRight,style_none:ge.styleNone,style_square:ge.styleSquare,style_text_outline:ge.styleTextOutline,style_triangledown:ge.styleTriangledown,style_triangleup:ge.styleTriangleup,style_xcross:ge.styleXcross},xw={style_arrow_both:jr.styleArrowBoth,style_arrow_left:jr.styleArrowLeft,style_arrow_right:jr.styleArrowRight,style_dashed:jr.styleDashed,style_dotted:jr.styleDotted,style_solid:jr.styleSolid},Aw={abovebar:oi.abovebar,absolute:oi.absolute,belowbar:oi.belowbar,bottom:oi.bottom,top:oi.top},Cw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Fw={style_area:wr.styleArea,style_areabr:wr.styleAreabr,style_circles:wr.styleCircles,style_columns:wr.styleColumns,style_cross:wr.styleCross,style_histogram:wr.styleHistogram,style_line:wr.styleLine,style_linebr:wr.styleLinebr,style_stepline:wr.styleStepline,style_stepline_diamond:wr.styleSteplineDiamond,style_steplinebr:wr.styleSteplinebr},Mw={bottom_center:Or.bottomCenter,bottom_left:Or.bottomLeft,bottom_right:Or.bottomRight,middle_center:Or.middleCenter,middle_left:Or.middleLeft,middle_right:Or.middleRight,top_center:Or.topCenter,top_left:Or.topLeft,top_right:Or.topRight},Nw={left:ys.left,none:ys.none,right:ys.right},Sw={arrowdown:or.arrowdown,arrowup:or.arrowup,circle:or.circle,cross:or.cross,diamond:or.diamond,flag:or.flag,labeldown:or.labeldown,labelup:or.labelup,square:or.square,triangledown:or.triangledown,triangleup:or.triangleup,xcross:or.xcross},Bw={auto:Yr.auto,huge:Yr.huge,large:Yr.large,normal:Yr.normal,small:Yr.small,tiny:Yr.tiny},Tw={cash:Ge.cash,fixed:Ge.fixed,percent_of_equity:Ge.percentOfEquity,commission:{cash_per_contract:Ir.cashPerContract,cash_per_order:Ir.cashPerOrder,percent:Ir.percent},direction:{all:pe.all,long:pe.long,short:pe.short},oca:{cancel:kn.cancel,none:kn.none,reduce:kn.reduce}},Ow={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},Iw={bar_index:$e.bar_index,bar_time:$e.bar_time},$w={abovebar:ki.abovebar,belowbar:ki.belowbar,price:ki.price},Lw={actual:Ds.actual,estimate:Ds.estimate,standardized:Ds.standardized};class Rw{constructor(){z(this,"adjustment",{dividends:vs.dividends,none:vs.none,splits:vs.splits});z(this,"alert",mw);z(this,"barmerge",gw);z(this,"color",yi);z(this,"currency",Kf);z(this,"dayofweek",vw);z(this,"earnings",Lw);z(this,"display",ww);z(this,"extend",yw);z(this,"font",{family_default:"SimSun",family_monospace:"Monospace"});z(this,"format",Dw);z(this,"hline",bw);z(this,"label",Ew);z(this,"line",xw);z(this,"location",Aw);z(this,"math",Cw);z(this,"order",{ascending:qn.ascending,descending:qn.descending});z(this,"plot",Fw);z(this,"position",Mw);z(this,"scale",Nw);z(this,"session",{extended:ia.extended,regular:ia.regular});z(this,"shape",Sw);z(this,"size",Bw);z(this,"splits",{denominator:"denominator",numerator:"numerator"});z(this,"strategy",Tw);z(this,"text",Ow);z(this,"xloc",Iw);z(this,"yloc",$w)}updateData(){}}class Pw{constructor(t){z(this,"_variables");z(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:$e.bar_index,line_color:yi.blue,line_style:jr.styleSolid,line_width:1});this._variables=t}new(t,e){const r=`polyline_${e}`,n=Object.assign({},this._defaultPolyline,t,{id:r}),s=new Hf(r,this._variables);return this._variables.polyline.add(r,n,s),s}delete({id:t}){t&&t.delete()}}class Hf{constructor(t,e){z(this,"_id");z(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class zw{constructor(t){z(this,"_variables");z(this,"_defaultLine",{xloc:$e.bar_index,extend:Pn.none,style:jr.styleSolid});this._variables=t}new({first_point:t,second_point:e,...r},n){const s=`line_${n}`,a={...this._defaultLine,...r,id:s};if(t&&e){const c=a.xloc===$e.bar_index?t.index:t.time,h=a.xloc===$e.bar_index?e.index:e.time;Object.assign(a,{x1:c,y1:t.price,x2:h,y2:e.price})}const l=new Ji(s,this._variables);return this._variables.line.add(s,a,l),l}line(t,e){return t.x?t.x:new Ji(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class Ji{constructor(t,e){z(this,"_variables");z(this,"_id");this._id=t,this._variables=e}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}`,r=this._getLine(t),n=new Ji(e,this._variables);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===$e.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r)}set_color({color:t},e){const r=this._getLine(e);r&&(r.color=t)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t)}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t)}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===$e.bar_index?n:s,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===$e.bar_index?n:s,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class qw{constructor(t){z(this,"_variables");this._variables=t}new({line1:t,line2:e,color:r},n){const s=`linefill_${n}`,a=t==null?void 0:t.data,l=e==null?void 0:e.data;a&&(a.linefills=a.linefills||[],a.linefills.push(s)),l&&(l.linefills=l.linefills||[],l.linefills.push(s));const c=new so(this._variables,s,t,e);return(a||l)&&this._variables.linefill.add(s,{line1:a,line2:l,color:r,id:s},c),c}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class so{constructor(t,e,r,n){z(this,"_id");z(this,"_line1");z(this,"_line2");z(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new so(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.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:t}){const e=this._variables.linefill.get(this._id);e&&(e.color=t)}}class kw{constructor(t){z(this,"_variables");z(this,"_defaultBox",{border_color:yi.blue,border_width:1,bgcolor:yi.blue,xloc:$e.bar_index,extend:Pn.none,style:jr.styleSolid,text:"",text_size:Yr.auto,text_color:yi.black,text_halign:Je.alignCenter,text_valign:Je.alignCenter,text_wrap:Je.wrapNone});this._variables=t}box({x:t},e){return t===void 0?new Qi(this._variables,e):t}new({top_left:t,bottom_right:e,...r},n){const s=`box_${n}`,a={...this._defaultBox,...r,id:s};if(t){const{price:c,time:h,index:p}=t;a.top=c,a.left=a.xloc===$e.bar_index?p:h}if(e){const{price:c,time:h,index:p}=e;a.bottom=c,a.right=a.xloc===$e.bar_index?p:h}const l=new Qi(this._variables,s);return this._variables.box.add(s,a,l),l}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e}){t==null||t.set_extend(e)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e}){t==null||t.set_border_style(e)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e}){t==null||t.set_text_size(e)}set_text_wrap({id:t,...e}){t==null||t.set_text_wrap(e)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e}){t==null||t.set_text_halign(e)}set_text_valign({id:t,...e}){t==null||t.set_text_valign(e)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e}){t==null||t.set_text_font_family(e)}}class Qi{constructor(t,e){z(this,"_id");z(this,"_variables");this._variables=t,this._id=e}copy(t){const e=`box_${t}`,r=this._getBox(),n=new Qi(this._variables,e);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t}){const e=this._getBox();e&&(e.extend=t)}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t)}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t}){const e=this._getBox();e&&(e.text_size=t)}set_text_wrap({text_wrap:t}){const e=this._getBox();e&&(e.text_wrap=t)}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t)}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t}){const e=this._getBox();e&&(e.text_halign=t)}set_text_valign({text_valign:t}){const e=this._getBox();e&&(e.text_valign=t)}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===$e.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t)}set_border_style({style:t}){const e=this._getBox();e&&(e.border_style=t)}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===$e.bar_index?r:s}}set_text_font_family({text_font_family:t}){const e=this._getBox();e&&(e.text_font_family=t)}_getBox(){return this._variables.box.get(this._id)}}class Uw{constructor(t){z(this,"_variables");z(this,"_defaultTable",{position:Or.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t}table({x:t},e){return t||new Pa(this._variables,e)}new(t,e){const r=`table_${e}`,n={...this._defaultTable,...t,cell:[],id:r},s=new Pa(this._variables,r);return this._variables.table.add(r,n,s),s}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e}){t==null||t.set_position(e)}}class Pa{constructor(t,e){z(this,"_id");z(this,"_variables");z(this,"_defaultCell",{column:0,row:0,text:"",text_color:yi.black,text_halign:Je.alignCenter,text_valign:Je.alignCenter,text_size:Yr.normal});this._variables=t,this._id=e}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r)}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){console.log(`error ${s}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(t,e);if(!a)return;this.clear({start_column:t,start_row:e,end_column:r,end_row:n});const l=this._variables.table.get(this._id);l.cell[e][t]={...a,isMerge:!0,merge_columns:r-t+1,merge_rows:n-e+1}}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t)}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t)}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t}){const e=this._variables.table.get(this._id);e&&(e.position=t)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Ww{constructor(t){z(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===pe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class jw{constructor(t){z(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===pe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class Yw{constructor(t){z(this,"_strategy");this._strategy=t}allow_entry_in({value:t}){this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e}){e===Ge.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e}){e===Ge.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}}let Zw=class{constructor(t,e,r,n){z(this,"_variables");z(this,"_options");z(this,"_totalChangeCapital");z(this,"_historyOrder");z(this,"_orders");z(this,"_pendingOrders");z(this,"_mintick");z(this,"_funcOptions");z(this,"_pendingCloseOrders");z(this,"_errorListener");z(this,"_risk");z(this,"_opentrades");z(this,"_closedtrades");z(this,"_riskNamespace");this._variables=t,this._errorListener=n,this._options={overlay:!1,format:zn.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:Ge.fixed,default_qty_value:1,initial_capital:1e6,currency:Kf.NONE,slippage:0,commission_type:Ir.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=e,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 jw(this),this._closedtrades=new Ww(this),this._riskNamespace=new Yw(this)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((t,e)=>t+(e.profit||0),0)}get _freezeCapital(){const{close:t}=this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(t){Object.assign(this._options,t),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{high:n,low:s,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:h}}=this._variables;let{preNetprofit:p=0}=this._risk;l===a&&(p=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=p-c;f+=this._orders.reduce((w,m)=>{const{in_price:D,direction:v,qty:E=0,commission:b=0,original_qty:N=0}=m,x=v===pe.long?1:-1,F=(n-D)*E,M=(s-D)*E,S=x===1?-M:F;return w+S+E/N*b},0);let d=!1;switch(e){case Ge.cash:d=t<f;break;case Ge.percentOfEquity:const w=f/(h+c)*100;d=t<w;break}if(d){this._risk.isTemporaryBan=!0;const w=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,w===pe.long?s:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:s,open:a}=this._variables;n===s&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(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:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:s,time_tradingday:a,strategy:l,open:c}=this._variables;let h=e;if(s===a){const p=l.netprofit+l.openprofit;p<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:p})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(!r&&t!==void 0&&e){const{max_drawdown:s,max_drawdown_percent:a}=this._variables.strategy;let l=!1;switch(e){case Ge.percentOfEquity:l=a<s;break;case Ge.cash:l=t<s;break}if(l){const{high:c,low:h}=this._variables,p=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(p===pe.long?c:h,"Close Position (Max Drawdown)")}}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,t,e),this._pendingOrders=[]}strategy(t){this._options={...t},Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"})}order(t){this._risk.isDisabledOpen||this._orderHandle(t)}entry(t){this._risk.isDisabledOpen||this._entryHandle(t)}close(t){if(!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close"}):this._pendingOrders.push({...t,place_order_type:"close"})}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Ge.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(e){case Ge.fixed:return r;case Ge.cash:return r/t;case Ge.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/t}}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{high:t,low:e,close:r}=this._variables;for(const n of this._orders){const{in_price:s,qty:a=0,direction:l}=n,c=l===pe.long?1:-1,h=(r-s)*c*a,p=(t-s)*a,f=(e-s)*a,d=c===1?p:-f,g=c===1?-f:p;this._calcOrderPercent(n,h,d,g)}}_calcOrderPercent(t,e,r,n){const{commission_value:s}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:p=0,trading_loss:f=0}=t;let{commission:d=0}=t;const g=h*c;if(s){const w=this._getCommission(a,c);e=e-w,d=d*c/l,r-=d,n+=d}r=Math.max(r,p),n=Math.min(n,f),Object.assign(t,{profit:e-d,total_profit:this._totalChangeCapital+e,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:t,low:e}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:s=0,commission_value:a=0}=this._options,l=this._orders[0].direction===pe.long?1:-1,c=l===1?e:t,h=(l===1?n:s)/100;if(h<=0)return;const[p,f,d]=this._orders.reduce((v,E)=>{let[b,N,x]=v;const{in_price:F,qty:M=0,original_qty:S=0,commission:I=0}=E,C=F*M,T=c*M;if(b+=C,N+=T,a){const L=this._getCommission(c,M);x+=L+M/S*I}return[b,N,x]},[0,0,0]),g=l*(f-p),m=r+this._totalChangeCapital+g-d-f*h;if(m>=0)return;const D=Math.trunc(m/h/c)*4;this._marginCallOrders(c,D,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r);return}for(const s of this.orders)this._processOrder(s,t,e,r,r);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:a,close:l,price:c,activePrice:h}=this._orderArgsParse(t),p=t.direction===pe.long?1:-1;if(a<=0)return;let f=a;if(s&&e){if(n.length){const m=this._processOrders(n,l,f,t.id,t.comment);if(m<=0)return;f=m}const g=l+p*r*this._mintick;if(!this._judgeCapitalEnough(f,g,p))return;this._ocaGroupVerify(f,t.oca_name,t.oca_type),this._calcCurrentOrder({...t,in_price:g,in_index:this._variables.bar_index,in_time:this._variables.time,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,p)&&this._addPendingOrders(t,c,f,s,h)}_judgeCapitalEnough(t,e,r){if(t<=0)return!1;const{margin_long:n=0,margin_short:s=0}=this._options;if((n===0||n===100)&&r===1||s===0&&r===-1)return!0;const l=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return t*e<=l}_ocaGroupVerify(t,e,r){if(!e||!r||r===kn.none)return!1;let n=!1;switch(r){case kn.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)s.isCancel=!0,n=!0;else return!0});break;case kn.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:a=0,oca_name:l}=s;if(e===l){const c=a-t;return n=!0,c<=0?(s.isCancel=!0,!1):(s.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,s){let a=r;for(const l of t)if(a=this._processOrder(l,e,a,n,s),a<=0)break;return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(t,e,r,n,s){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:a}=this._variables;let l=a,c=!1,h;const p=e===pe.long?1:-1,f=n&&(n-a)*p>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&s&&(s-=d*this._mintick*p);const g=s&&(s-a)*p<0;f&&g?(h=n,l=s):f?l=n:g?l=s:c=!0;const w=r||this._calcDefaultQty(l)||1;return{orders:this._orders.filter(D=>D.direction!==e),isMarketPrice:c,activePrice:h,quantities:w,close:a,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:a,price:l,activePrice:c}=this._orderArgsParse(t);if(s<=0)return;if(r.length&&n&&e){this._entryOrder(r,a,s,t);return}this._judgeCapitalEnough(s,a,t.direction===pe.long?1:-1)&&this._addPendingEntry(t,l,s,n,c)}_entryOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{oca_name:c,oca_type:h,direction:p,comment:f,isMarketPrice:d,id:g}=n,w=p===pe.long?1:-1;if(this._closeOrders(t,e,g,f),r=this._getAvailablePositionSize(r,p),r<=0)return;e=e+l*this._mintick*w;const m={...n,in_price:e,original_qty:r,qty:r,in_index:a,in_time:s,place_order_type:"entry"};if(d){this._calcCurrentOrder(m);return}const{pendingOrders:D,orders:v}=this._getEntryOrders(p),E=D.length+v.length;E&&E>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,e,w)||(this._ocaGroupVerify(r,c,h),this._calcCurrentOrder(m))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==pe.all&&n!==e)return 0;if(r===void 0)return t;const s=this._orders.reduce((a,l)=>a+(l.qty||0),0);return s?s+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(p=>p.id===t.id&&p.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else if(!c||c<(this._options.pyramiding||1)){const p={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"entry"};this._pendingOrders.push(p)}}_closeAllOrders(t,e){const{comment:r}=t,{bar_index:n}=this._variables,s=this._orders.filter(a=>a.in_index!==n);s.length&&(this._closeOrders(s,e,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n){for(const s of t)this._closeOrder(s,e,r,n);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{in_price:c,qty:h=0,direction:p}=t,f=p===pe.long?1:-1;e=e-f*l*this._mintick,t.isDeal=!0;const d=(e-c)*f*h,g={...t,out_price:e,out_id:r,out_index:a,out_time:s,out_comment:n,out_qty:h,profit:d};this._calcPercent(g),this._risk.intradayOrders+=1,this._historyOrder.push(g),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const t=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!t.length)return;const{open:e,low:r,high:n,close:s}=this._variables;for(const a of t){const{stop:l,limit:c,trail_stop_price:h,isMarketPriceLimit:p,isMarketPriceStop:f,direction:d,id:g,out_comment:w,active_price:m,trail_offset:D=0,out_qty:v,comment_loss:E,comment_profit:b,comment_trailing:N}=a;let x=h;const F=d===pe.long?1:-1;let M,S=w;if(p||f?M=e:(c&&r<=c&&n>=c&&(S=b||w,M=c),l&&r<=l&&n>=l&&(M=x?(l-x)*F>0?l:x:l,S=(x===M?N:E)||w)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let I=!1;if(m&&m<=n&&m>=r&&(x=m-D*F*this._mintick,(x-s)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=x)),I=!0,a.trail_stop_price=x),x)if((x-e)*F>=0&&!I)M=x;else{const C=(F===1?n:r)-D*F*this._mintick;F===1?x<e&&x>=r&&C>x&&C<s?M=x:C>x?(x=C,C>=s&&(M=C)):x<=n&&r<=x&&(M=x):x>e&&x<=n&&C<x&&C>s?M=x:C<x?(x=C,C<=s&&(M=C)):x<=n&&r<=x&&(M=x),a.trail_stop_price=x}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||w,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=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:s,place_order_type:a}=n;if(s)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of e){const s=this._exitOrderHandle(n);s&&t.push(s)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),e=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of e)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of t){const{from_entry:s}=n,a=this._orders.filter(l=>!s||l.id===s&&(l.isMarketPriceLimit||l.isMarketPriceStop));for(const l of a)this._processExitOnClose(l,l.limit||l.stop||l.trail_stop_price||r,n)}this._pendingCloseOrders=[]}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:s,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let p=l;if(s&&(p=e),p<=n&&p>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,p,a,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:s,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:p,direction:f,comment:d,oca_name:g,oca_type:w,active_price:m,id:D}=t;if(m&&n>=m&&r<=m)return delete t.active_price,t;let v=p,E=h;if(c&&(v=e),v<=n&&v>=r){const b=this._orders.filter(x=>x.direction!==f);if(b.length&&(E=this._processOrders(b,v,h,D,d),E<=0))return;const N=f===pe.long?1:-1;this._ocaGroupVerify(E,g,w),this._calcCurrentOrder({...t,in_price:v+N*l*this._mintick,in_index:a,in_time:s,qty:E});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:a}=t,{bar_index:l}=this._variables,c=this._orders.filter(g=>g.id===r&&g.in_index!==l&&(!g.close_qty||g.close_qty<(g.qty||0)));if(!c.length)return;let h=0;if(n?h=n:(h=c.reduce((g,w)=>g+(w.qty||0),h),h=s/100*h),h<=0)return;const{open:p,close:f}=this._variables;let d=h;for(const g of c){const{qty:w=0}=g;d<w?g.close_qty=d:(g.close_qty=w,d-=w)}this._processOrders(this._options.close_entries_rule==="ANY"?c:this._orders,e?f:p,h,`Close entry(s) order ${r}`,a)}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t)))return t}_exit(t,e){const{profit:r,loss:n,stop:s,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:p="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c))){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'",e,Ee.Error);return}const d={...t,place_order_type:"exit"},g=this._orders.filter(D=>(!p||p===D.id)&&!D.hasExit),w=this._pendingOrders.filter(D=>!p||p===D.id);if(g.length){if(!this._ordersToExit(g,d))return}else if(!w.length)return;const m=this._pendingOrders.find(D=>D.id===f);m?Object.assign(m,{...t}):this._pendingOrders.push(d)}_ordersToExit(t,e){const{qty:r,qty_percent:n=100,id:s,comment:a,comment_loss:l,comment_profit:c,comment_trailing:h}=e;let p=r,f=!1;e.comment=a||s;for(const d of t){const{qty:g=0}=d,w=d.direction===pe.long?1:-1;p=r?r>=g?g:r:n/100*g,d.out_qty=p,p<g&&(f=!0),Object.assign(d,{out_comment:a||s,comment_loss:l,comment_profit:c,comment_trailing:h}),!(this._stopProfit(d,w,{...e,qty:p})||this._stopLoss(d,w,{...e,qty:p})||this._trailStopLoss(d,w,{...e,qty:p}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(t){t.place_order_type="exit";const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r){const{limit:n,profit:s,comment_profit:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(c=p+e*s*this._mintick),t.limit=c,c&&(c-h)*e<=0&&(t.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r){const{stop:n,loss:s,comment_loss:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(c=p-e*s*this._mintick),t.stop=c,c&&(c-h)*e>=0&&(t.isMarketPriceStop=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:s,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(s)?this._isNaN(a)||(d=p+a*e*this._mintick):d=s,t.trail_offset=n,d&&(d-h)*e<=0){const g=h-n*e*this._mintick;if((g-h)*e>=0&&(t.trail_stop_price=h,t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;t.trail_stop_price=g}t.active_price=d}}_processExitOnClose(t,e,r){const{qty:n=0,comment:s,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO"){const c=this._processExitOrders(this._orders,e,n,a,s);c&&!c.hasExit?(c.hasExit=!0,Object.assign(t,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,a,s)}_processExitOrders(t,e,r,n,s){let a=r,l;for(const c of t)if(l=c,a=this._processOrder(c,e,a,n,s),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),l}_processOrder(t,e,r,n,s){const{time:a,bar_index:l}=this._variables,{slippage:c=0}=this._options,{in_price:h,qty:p=0,max_profit:f=0,trading_loss:d=0,direction:g,commission:w=0,original_qty:m=0}=t,D=g===pe.long?1:-1;if(e=e-D*c*this._mintick,r<p){const v=p-r,E=(e-h)*D*r,b=f/p*r,N=d/p*r;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:s,profit:E,out_qty:r,max_profit:b,trading_loss:N});const x=(e-h)*D*v-w*v/m;Object.assign(t,{qty:v,profit:x,max_profit:f-b,trading_loss:d-N,total_profit:this._totalChangeCapital+x}),r=0}else{t.isDeal=!0;const v=(e-h)*D*p;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:s,out_qty:p,profit:v}),r-=p}return r}_calcPercent(t){const{commission_value:e}=this._options,{in_price:r,out_qty:n=0,out_price:s=0,original_qty:a=0}=t;let{profit:l=0,max_profit:c=0,trading_loss:h=0,commission:p=0}=t;c=c<0?0:c;const f=r*n;if(this._totalChangeCapital+=l,e){const d=this._getCommission(s,n);this._totalChangeCapital-=d,p=p*n/a+d,l=l-p,Object.assign(t,{commission:p,profit:l,max_profit:c})}Object.assign(t,{total_profit:this._totalChangeCapital,profit_percent:l/f*100,max_profit_percent:c/f*100,trading_loss_percent:h/f*100}),this._risk.intradayOrders+=1,this._historyOrder.push(t),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case Ir.percent:a=s*r/100;break;case Ir.cashPerContract:a=e*r;break;case Ir.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:s=0,trading_loss:a=0}=t;let{profit:l=0}=t;const c=r*n;if(e){const h=this._getCommission(r,n);this._totalChangeCapital-=h,l=l-h,Object.assign(t,{commission:h,profit:l,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,profit_percent:l/c*100,max_profit_percent:s/c*100,trading_loss_percent:a/c*100}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders)}_isNaN(t){return t===void 0||isNaN(t)}};class Gw{constructor(t){z(this,"_logs");z(this,"_variables");z(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e){this._addLog(t,e,"info")}error(t,e){this._addLog(t,e,"error")}warning(t,e){this._addLog(t,e,"warning")}_addLog(t,e,r){const{message:n,formatString:s}=t,{time:a,bar_index:l,precision:c}=this._variables;let h=n;s&&Array.isArray(e)&&e.length&&(h=s.replace(/{(\d+)}/g,(p,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(c)))),d!==void 0?d:p})),h&&this._logs.push({message:`[${Qt(a).format()}]: ${h}`,time:a,barIndex:l,type:r})}}class Kw{constructor(t){z(this,"_errorListener");this._errorListener=t}error({message:t},e){this._errorListener.addError(t,e,Ee.Error)}}class Hw{constructor(){z(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Br.flatMap([...this._errors.values()])}addError(t,e,r){const[n,s]=e.split("_").slice(-2),a=this._errors.get(e),l={message:t,endLineNumber:Number(n),startColumn:Number(s)+1,endColumn:Number(s)+1,startLineNumber:Number(n),type:r};a?a.push(l):this._errors.set(e,[l])}}class Xw{constructor(){z(this,"_isMarketOpen");z(this,"_currentBarIndex");z(this,"_totalBarIndex");z(this,"_isRealTimeBar");z(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1:this._currentBarIndex===this._totalBarIndex}}class Jw{constructor(t){z(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class Qw{constructor(t){z(this,"_orders");z(this,"_historyOrders");z(this,"_options");z(this,"_max_contracts_held_all",0);z(this,"_max_contracts_held_long",0);z(this,"_max_contracts_held_short",0);z(this,"_max_drawdown",0);z(this,"_max_runup",0);z(this,"_max_runup_percent",0);z(this,"_max_drawdown_percent",0);z(this,"_variables");z(this,"_netprofit",0);z(this,"_eventrades",0);z(this,"_avg_trade_percent");z(this,"_closedtrades",0);z(this,"_losstrades",0);z(this,"_grossloss",0);z(this,"_grossloss_percent",0);z(this,"_grossprofit",0);z(this,"_grossprofit_percent",0);z(this,"_wintrades",0);z(this,"_opentrades_capital_held",0);z(this,"_position_avg_price",0);z(this,"_position_size",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){let t=0,e=0;const{high:r,low:n}=this._variables;for(const h of this._orders){const{in_price:p,qty:f=0,commission:d=0,original_qty:g=0,direction:w}=h,m=w===pe.long?1:-1,D=(r-p)*f,v=(n-p)*f,E=m===1?D:-v,b=m===1?-v:D;t+=b+d*f/g,e+=E+d*f/g}const[s,a]=this._historyOrders.reduce((h,p)=>{let[f,d]=h;const{profit:g=0,commission:w=0}=p;return f+=g,d+=g-w,[f,d]},[0,0]);t-=s,e+=a;const l=t/(this.initial_capital+this.netprofit)*100;this._max_drawdown<t&&(this._max_drawdown=t),l>this._max_drawdown_percent&&(this._max_drawdown_percent=l);const c=e/(this.initial_capital+this.netprofit)*100;e>this._max_runup&&(this._max_runup=e),c>this._max_runup_percent&&(this._max_runup_percent=c)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t)return;const[e,r,n,s,a,l]=this._orders.reduce(([c,h,p,f,d,g],w)=>{const{direction:m,qty:D=0,in_price:v}=w;return m===pe.long?(c+=D,h+=D,g+=D):(c+=D,p+=D,g-=D),f+=D*v,d+=v,[c,h,p,f,d,g]},[0,0,0,0,0,0]);this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a,l,c]=this._historyOrders.reduce((h,p)=>{let[f,d,g,w,m,D]=h;const{profit:v=0,profit_percent:E=0}=p;return f+=v,d+=E,v<0?(g+=v,w+=E):(m+=v,D+=E),[f,d,g,w,m,D]},[0,0,0,0,0,0]);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r,this._grossloss=s,this._grossloss_percent=a,this._grossprofit=l,this._grossprofit_percent=c,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this.losstrades;return t?Math.abs(this.grossloss/t):void 0}get avg_losing_trade_percent(){const t=this.losstrades;return t?Math.abs(this.grossloss_percent/t):void 0}get avg_trade(){if(this.closedtrades)return Math.abs(this.netprofit/this.closedtrades)}get equity(){return this.initial_capital+this.netprofit+this.openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._orders.reduce((t,e)=>{const{profit:r=0}=e;return t+r},0)}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this.wintrades;return t?Math.abs(this.grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this.wintrades;return t?Math.abs(this.grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss_percent}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit_percent}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===pe.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,p]=this._orders.reduce((f,d)=>{let[g,w]=f;const{in_price:m,qty:D=0,original_qty:v=0}=d,E=m*D;if(g+=E,s){let b=0;switch(n){case Ir.percent:b=(E+D*c)*s/100;break;case Ir.cashPerContract:b=D*s*2;break;case Ir.cashPerOrder:b=D/v*s+s;break}w+=b}return[g,w]},[0,0]);return(h-(t+this.netprofit-p))*a/this.position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this.netprofit/this.initial_capital*100}get openprofit_percent(){return this.openprofit/(this.initial_capital+this.netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}}class Vw{constructor(){z(this,"_preAccdist");z(this,"_preNvi");z(this,"_prePvi");z(this,"_preObv");z(this,"_prePvt");z(this,"_preWad");z(this,"_preVwap");z(this,"_preValue");z(this,"_currentData");z(this,"_preData");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={}}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(self.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin")&&(s=!0,r=n=0),!s)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:s});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class ty{constructor(){z(this,"_period");z(this,"_multiplier");z(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=gs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}Qt.extend($p),Qt.extend(Fl),Qt.extend(Op);class ey{constructor(){z(this,"_cacheData");z(this,"_barIndex");z(this,"_isRealTimeBar");z(this,"_barstate");z(this,"_priceVariables");z(this,"_lastBarIndex");z(this,"_currentBarTime");z(this,"_lastBarTime");z(this,"_period");z(this,"_offsetTime");z(this,"_timeframe");z(this,"_ta");z(this,"_polyline");z(this,"_label");z(this,"_line");z(this,"_linefill");z(this,"_box");z(this,"_table");z(this,"_strategy");z(this,"_precision");z(this,"_session");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new Xw,this._timeframe=new ty,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Vw,this._polyline=new Di,this._label=new Di,this._line=new Di,this._linefill=new Di,this._box=new Di,this._table=new Di,this._strategy=new Qw(this),this._precision=4,this._session=new Jw(this)}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return Qt(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return Qt(this._currentBarTime).minute()}get second(){return Qt(this._currentBarTime).second()}get month(){return Qt(this._currentBarTime).month()+1}get year(){return Qt(this._currentBarTime).year()}get dayofweek(){return Qt(this._currentBarTime).day()+1}get dayofmonth(){return Qt(this._currentBarTime).date()}get weekofyear(){return Qt(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=gs(this._period);return this._isRealTimeBar?void 0:Qt(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get precision(){return this._precision}getTimeTradingday(t,e){const[r,n]=gs(e),s=Qt(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,lastBarIndex:c,time:h,lastBarTime:p,period:f="1D",offsetTime:d=5,precision:g=4}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(s),low:Number(a),volume:Number(l)},e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._precision=g,this._currentBarTime=h*1e3,this._lastBarIndex=c,this._barIndex=e,this._lastBarTime=p*1e3,this._period=f,this._offsetTime=d,this._timeframe.update(f),this._barstate.update(e,c,!1,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){let n=this._cacheData[t]||[];n[this._barIndex]=r,n=n.filter(()=>!0);const s=n[n.length-1-e];return this._cacheData[t]=n,s}setCacheData(t,e){const r=this._cacheData[t]||[];r[this._barIndex]=e,this._cacheData[t]=r}getTypeInstance(t,e){return new Np(t,e)}getVarValue(t,e,r){const n=`${t}_${e}`,s=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(s)return s}setVarValue(t,e,r,n){const s=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=Br.cloneDeep(r);if(this._cacheData.varNewData[s]=l,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=l[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Br.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case Xi.name:case Hf.name:case Qi.name:case Pa.name:case Ji.name:case so.name:t==null||t.delete();break}}}class Di{constructor(t=50){z(this,"_all");z(this,"_allInstance");z(this,"_pseudoArrayAll");z(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Xt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r);const n=[...this._all.keys()];if(n.length>this._maxLength){const s=n.shift();s&&this.delete(s)}}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}var Xf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,c){var h=n(s),p=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(Xf);var ry=Xf.exports,ny=Zt(ry),Jf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){return function(e,r,n){var s=r.prototype,a=function(d){var g,w=d.date,m=d.utc,D={};if(!((g=w)===null||g instanceof Date||g instanceof Array||s.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var v=m?n.utc():n();Object.keys(w).forEach(function(I){var C,T;D[C=I,T=s.$utils().p(C),T==="date"?"day":T]=w[I]});var E=D.day||(D.year||D.month>=0?1:v.date()),b=D.year||v.year(),N=D.month>=0?D.month:D.year||D.day?0:v.month(),x=D.hour||0,F=D.minute||0,M=D.second||0,S=D.millisecond||0;return m?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return w},l=s.parse;s.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=s.set,h=s.add,p=s.subtract,f=function(d,g,w,m){m===void 0&&(m=1);var D=Object.keys(g),v=this;return D.forEach(function(E){v=d.bind(v)(g[E]*m,E)}),v};s.set=function(d,g){return g=g===void 0?d:g,d.constructor.name==="Object"?f.bind(this)(function(w,m){return c.bind(this)(m,w)},g,d):c.bind(this)(d,g)},s.add=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g):h.bind(this)(d,g)},s.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g,-1):p.bind(this)(d,g)}}})})(Jf);var iy=Jf.exports,sy=Zt(iy),Qf={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(jt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|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,h=31536e6,p=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},g=function(F){return F instanceof N},w=function(F,M,S){return new N(F,S,M.$l)},m=function(F){return r.p(F)+"s"},D=function(F){return F<0},v=function(F){return D(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?D(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,I,C){var T=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return w(S*d[m(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(k){T.$d[m(k)]=S[k]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var U=L.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,C){return I+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/p),S%=p,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),I=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var T=b(C,"D"),L=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var W=b(k,"S"),P=S.negative||I.negative||T.negative||L.negative||U.negative||W.negative,K=L.format||U.format||W.format?"T":"",G=(P?"-":"")+"P"+S.format+I.format+T.format+K+L.format+U.format+W.format;return G==="P"||G==="-P"?"P0D":G},M.toJSON=function(){return this.toISOString()},M.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",C={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 I.replace(c,function(T,L){return L||String(C[T])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var I=this.$ms,C=m(S);return C==="milliseconds"?I%=1e3:I=C==="weeks"?v(I/d[C]):this.$d[C],I||0},M.add=function(S,I,C){var T;return T=I?S*d[m(I)]:g(S)?S.$ms:w(S,this).$ms,w(this.$ms+T*(C?-1:1),this)},M.subtract=function(S,I){return this.add(S,I,!0)},M.locale=function(S){var I=this.clone();return I.$l=S,I},M.clone=function(){return w(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(T,L){var U=S.locale();return w(T,{$l:U},L)},S.isDuration=g;var I=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(T,L){return g(T)?x(this,T,1):I.bind(this)(T,L)},M.prototype.subtract=function(T,L){return g(T)?x(this,T,-1):C.bind(this)(T,L)}}})})(Qf);var oy=Qf.exports,ay=Zt(oy);Qt.extend(Fl),Qt.extend(ny),Qt.extend(sy),Qt.extend(ay);class uy{constructor(t,e){z(this,"array");z(this,"color");z(this,"math");z(this,"str");z(this,"map");z(this,"matrix");z(this,"timeframe");z(this,"ta");z(this,"input");z(this,"_variables");z(this,"_cacheData");z(this,"_options");z(this,"_errorListener");z(this,"_plots");z(this,"_alerts");z(this,"_bgColors");z(this,"_hlines");z(this,"_fills");z(this,"chart");z(this,"line");z(this,"label");z(this,"polyline");z(this,"box");z(this,"table");z(this,"linefill");z(this,"log");z(this,"runtime");z(this,"strategy");this._variables=e,this._errorListener=new Hw,this.array=new Pp(this._errorListener),this.math=new zp(t,this._errorListener),this.color=new f1,this.str=new hw(this._errorListener),this.map=new pw(this._errorListener),this.timeframe=new fw(e),this.matrix=new cw(this._errorListener),this.ta=new u1(e,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 c1(e,this._errorListener),this._plots=new Map,this.chart={point:new dw(e)},this.line=new zw(e),this.label=new _w(e),this.polyline=new Pw(e),this.box=new kw(e),this.table=new Uw(e),this.linefill=new qw(e),this.log=new Gw(e),this.runtime=new Kw(this._errorListener),this.strategy=new Zw(this._variables,this._options,1e-4,this._errorListener)}get errors(){return this._errorListener.errors}get options(){const t=this.input.getInputs(),e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors).length?{...this._bgColors}:void 0,n=this._hlines.size?[...this._hlines.values()]:void 0,s=this._fills.size?[...this._fills.values()]:void 0,a=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 l=[...this._plots.values()],c=this._getDraws();return Object.assign(this._options,{inputs:t,plots:l,draws:c,alerts:e,colors:r,hlines:n,fills:s,logs:a})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}update(t){const{barIndex:e,inputs:r}=t;r&&r.length&&this.input.update(r),this.strategy.updateOptions(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)||this._errorListener.addError(Of.libraryTitleErr,e,Ee.Error),this._options.scriptType="library",this._options.library=t}}indicator(t){this._variables.bar_index||(this._options.scriptType="indicator",this._options.indicator=t)}plot(t,e){const{series:r,color:n,seriesColors:s,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,p=this._plots.get(h),f=(p==null?void 0:p.data)||[],d=r!==void 0&&isNaN(r)?void 0:r;if(f[l]={value:[c,d],itemStyle:{color:n}},s!=null&&s.length&&this._seriesColorHandle(t,h),!p){const g=n?[n]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h})}return{type:"plot",key:h}}plotbar(t,e){const{open:r,close:n,low:s,high:a,color:l,seriesColors:c,...h}=t,{bar_index:p,time:f}=this._variables,d=`plotbar_${e}`,g=this._plots.get(d),w=(g==null?void 0:g.data)||[],m=n!==void 0&&isNaN(n)?void 0:n,D=r!==void 0&&isNaN(r)?void 0:r,v=s!==void 0&&isNaN(s)?void 0:s,E=a!==void 0&&isNaN(a)?void 0:a,b=[f,D,m,v,E];if(w[p]=b,c!=null&&c.length&&(this._seriesColorHandle(t,d),w[p]={value:b,itemStyle:{color:l}}),!g){const N=l?[l]:void 0;this._plots.set(d,{editable:!0,...h,colors:N,data:w,id:d})}}plotchar(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,c=`plotchar_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotarrow(t,e){const{series:r,colorup:n,colordown:s,...a}=t,{bar_index:l}=this._variables,c=`plotarrow_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r!==void 0&&isNaN(r)?void 0:r,colorup:n,colordown:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotshape(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,c=`plotshape_${e}`,h=this._plots.get(c),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(c,{editable:!0,...a,data:p,id:c})}plotcandle(t,e){const{wickcolor:r,bordercolor:n,color:s,close:a,open:l,low:c,high:h,...p}=t,{bar_index:f}=this._variables,d=`plotcandle_${e}`,g=this._plots.get(d),w=(g==null?void 0:g.data)||[],m=a!==void 0&&isNaN(a)?void 0:a,D=l!==void 0&&isNaN(l)?void 0:l,v=c!==void 0&&isNaN(c)?void 0:c,E=h!==void 0&&isNaN(h)?void 0:h,b=[D,m,v,E];w[f]={value:b,wickcolor:r,bordercolor:n,color:s},g||this._plots.set(d,{editable:!0,...p,data:w,id:d})}hline(t,e){const r=`hline_${e}`;return this._hlines.set(r,{linewidth:1,editable:!0,display:sr.all,...t}),{type:"hline",key:r}}fill(t,e){const r=`fill_${e}`;this._fills.set(r,{display:sr.all,editable:!0,fillgaps:!1,...t})}alert({message:t,freq:e=_n.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l].barIndex;if(e===_n.freqOncePerBar&&n===c){this._alerts.delete(l);return}const h={message:t,freq:e,id:l,type:"alert"};if(s){e!==_n.freqOncePerBarClose&&this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}if(!s&&e===_n.freqOncePerBarClose&&n===c&&a===n-1){this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t){this._setColors(t,"barcolor")}bgcolor(t){this._setColors(t,"bgcolor")}_setColors(t,e){var l,c;const{color:r,...n}=t,{bar_index:s}=this._variables,a=((l=this._bgColors[e])==null?void 0:l.colors)||[];if(!a[s]){const h=((c=this._bgColors[e])==null?void 0:c.setColors)||[];h.includes(r)||h.push(r),a[s]=r,this._bgColors[e]={...n,colors:a,setColors:h}}}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return t===void 0}fixnan({source:t},e){return t===void 0||isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!isNaN(t)?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._variables.time_close&&this._timeHandle(this._variables.time_close,s,t,e,r,n)}timestamp(t){const{dateString:e,timezone:r,year:n,month:s,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return Qt(e).utc(!/GMT|UTC/.test(e)).valueOf();let p=s-1,f=n;if(p<0){const g=Math.ceil(Math.abs(p/12));p=12*g+p,f=n-g}let d=Qt({year:f,month:p,day:a,hour:l,minute:c,second:h});return r&&(d=Tr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:t,timezone:e}){return Tr(t,e).week()}year({time:t,timezone:e}){return Tr(t,e).year()}second({time:t,timezone:e}){return Tr(t,e).second()}month({time:t,timezone:e}){return Tr(t,e).month()+1}minute({time:t,timezone:e}){return Tr(t,e).minute()}hour({time:t,timezone:e}){return Tr(t,e).hour()}dayofweek({time:t,timezone:e}){return Tr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return Tr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Qr(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0){const l=r||this._variables.timeframe.period,c=Qr(l),h=Qr(this._variables.timeframe.period);let p;if(c<=h)p=t;else{const f=`time_${e}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=t?(p=t,this._cacheData[f]={currentTime:t,offset:0}):p=d;else{const g=this._calcTimeOffset(t,l);this._cacheData[f]={currentTime:t,offset:g},p=t}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,e),g=Qt(t).format("YYYY-MM-DD"),w=p;p=void 0;for(const D of f){const[v,E]=D;if(Qt(t).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")){Qt(w).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")?p=w:p=Qt(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;p&&!d.includes(m)&&(p=void 0)}return s&&(p=p&&Tr(p,s).valueOf()),p&&p-a*h*1e3}_seriesColorHandle(t,e){var s,a;const{seriesColors:r}=t,n=this._plots.get(e);if(n&&r!=null&&r.length)for(const l of r){if((s=n.gradientColorKeys)!=null&&s.includes(l))continue;const c=t[l],h=n[`${l}s`]||[];h.includes(c)||(h.push(c),n[`${l}s`]=h,h.length>5&&(n[`${l}s`]=[],(a=n.gradientColorKeys)==null||a.push(l)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,Ee.Error);return}return h});return{timePeriods:n.split(",").map(c=>{const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,Ee.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.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",e,Ee.Error);return}return`${r}:${n}`}}/**
|
63
63
|
* @license
|
64
64
|
* Copyright 2019 Google LLC
|
65
65
|
* SPDX-License-Identifier: Apache-2.0
|